From bf8cbae47559170d2f2947dd547492714f195dd3 Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Fri, 13 Apr 2007 15:34:07 -0700 Subject: PCI: rpaphp: Cleanup flow of control for rpaphp_add_slot Cleanup the flow of control for rpaphp_add_slot(), so as to make it easier to read. The ext patch will fix a bug in this same code. Signed-off-by: Linas Vepstas Cc: John Rose Signed-off-by: Kristen Carlson Accardi Signed-off-by: Greg Kroah-Hartman --- drivers/pci/hotplug/rpaphp_core.c | 40 +++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'drivers/pci/hotplug/rpaphp_core.c') diff --git a/drivers/pci/hotplug/rpaphp_core.c b/drivers/pci/hotplug/rpaphp_core.c index 71a2cb8baa4..f6c05f3621c 100644 --- a/drivers/pci/hotplug/rpaphp_core.c +++ b/drivers/pci/hotplug/rpaphp_core.c @@ -299,32 +299,32 @@ int rpaphp_add_slot(struct device_node *dn) const int *indexes, *names, *types, *power_domains; char *name, *type; + if (!dn->name || strcmp(dn->name, "pci")) + return 0; + + if (!is_php_dn(dn, &indexes, &names, &types, &power_domains)) + return 0; + dbg("Entry %s: dn->full_name=%s\n", __FUNCTION__, dn->full_name); /* register PCI devices */ - if (dn->name != 0 && strcmp(dn->name, "pci") == 0) { - if (!is_php_dn(dn, &indexes, &names, &types, &power_domains)) - goto exit; - - name = (char *) &names[1]; - type = (char *) &types[1]; - for (i = 0; i < indexes[0]; i++, - name += (strlen(name) + 1), type += (strlen(type) + 1)) { - - if (!(slot = alloc_slot_struct(dn, indexes[i + 1], name, - power_domains[i + 1]))) { - retval = -ENOMEM; - goto exit; - } - slot->type = simple_strtoul(type, NULL, 10); + name = (char *) &names[1]; + type = (char *) &types[1]; + for (i = 0; i < indexes[0]; i++) { + + slot = alloc_slot_struct(dn, indexes[i + 1], name, power_domains[i + 1]); + if (!slot) + return -ENOMEM; + + slot->type = simple_strtoul(type, NULL, 10); - dbg("Found drc-index:0x%x drc-name:%s drc-type:%s\n", - indexes[i + 1], name, type); + dbg("Found drc-index:0x%x drc-name:%s drc-type:%s\n", + indexes[i + 1], name, type); - retval = rpaphp_register_pci_slot(slot); - } + retval = rpaphp_register_pci_slot(slot); + name += strlen(name) + 1; + type += strlen(type) + 1; } -exit: dbg("%s - Exit: num_slots=%d rc[%d]\n", __FUNCTION__, num_slots, retval); return retval; -- cgit v1.2.3-70-g09d2 From fa1891596ca252e48e8803738fd8ead5b3082217 Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Fri, 13 Apr 2007 15:34:08 -0700 Subject: PCI: rpaphp: Remove global num_slots variable Cleanup cruft: remove the global "num_slots" variable; although scattered across multiple files, it is used only once, in a debug statement. Signed-off-by: Linas Vepstas Cc: John Rose Signed-off-by: Kristen Carlson Accardi Signed-off-by: Greg Kroah-Hartman --- drivers/pci/hotplug/rpaphp.h | 1 - drivers/pci/hotplug/rpaphp_core.c | 4 +--- drivers/pci/hotplug/rpaphp_slot.c | 3 --- 3 files changed, 1 insertion(+), 7 deletions(-) (limited to 'drivers/pci/hotplug/rpaphp_core.c') diff --git a/drivers/pci/hotplug/rpaphp.h b/drivers/pci/hotplug/rpaphp.h index 2e7accf0f73..2ccbe8d4229 100644 --- a/drivers/pci/hotplug/rpaphp.h +++ b/drivers/pci/hotplug/rpaphp.h @@ -83,7 +83,6 @@ struct slot { extern struct hotplug_slot_ops rpaphp_hotplug_slot_ops; extern struct list_head rpaphp_slot_head; -extern int num_slots; /* function prototypes */ diff --git a/drivers/pci/hotplug/rpaphp_core.c b/drivers/pci/hotplug/rpaphp_core.c index f6c05f3621c..3afd154bf54 100644 --- a/drivers/pci/hotplug/rpaphp_core.c +++ b/drivers/pci/hotplug/rpaphp_core.c @@ -41,7 +41,6 @@ int debug; static struct semaphore rpaphp_sem; LIST_HEAD(rpaphp_slot_head); -int num_slots; #define DRIVER_VERSION "0.1" #define DRIVER_AUTHOR "Linda Xie " @@ -325,8 +324,7 @@ int rpaphp_add_slot(struct device_node *dn) name += strlen(name) + 1; type += strlen(type) + 1; } - dbg("%s - Exit: num_slots=%d rc[%d]\n", - __FUNCTION__, num_slots, retval); + dbg("%s - Exit: rc[%d]\n", __FUNCTION__, retval); return retval; } diff --git a/drivers/pci/hotplug/rpaphp_slot.c b/drivers/pci/hotplug/rpaphp_slot.c index 3009193f005..907f1301f84 100644 --- a/drivers/pci/hotplug/rpaphp_slot.c +++ b/drivers/pci/hotplug/rpaphp_slot.c @@ -140,8 +140,6 @@ int rpaphp_deregister_slot(struct slot *slot) retval = pci_hp_deregister(php_slot); if (retval) err("Problem unregistering a slot %s\n", slot->name); - else - num_slots--; dbg("%s - Exit: rc[%d]\n", __FUNCTION__, retval); return retval; @@ -181,7 +179,6 @@ int rpaphp_register_slot(struct slot *slot) list_add(&slot->rpaphp_slot_list, &rpaphp_slot_head); info("Slot [%s](PCI location=%s) registered\n", slot->name, slot->location); - num_slots++; return 0; sysfs_fail: -- cgit v1.2.3-70-g09d2 From 31be7586d1122538747519d786408f142f59dd46 Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Fri, 13 Apr 2007 15:34:09 -0700 Subject: PCI: rpaphp: match up alloc and free in same routine The routine that called an alloc should be the same routine that calles the mathcing free, if anything in the middle failed. Signed-off-by: Linas Vepstas Cc: John Rose Signed-off-by: Kristen Carlson Accardi Signed-off-by: Greg Kroah-Hartman --- drivers/pci/hotplug/rpaphp_core.c | 5 +++++ drivers/pci/hotplug/rpaphp_pci.c | 1 - drivers/pci/hotplug/rpaphp_slot.c | 1 - 3 files changed, 5 insertions(+), 2 deletions(-) (limited to 'drivers/pci/hotplug/rpaphp_core.c') diff --git a/drivers/pci/hotplug/rpaphp_core.c b/drivers/pci/hotplug/rpaphp_core.c index 3afd154bf54..ca95e1515d6 100644 --- a/drivers/pci/hotplug/rpaphp_core.c +++ b/drivers/pci/hotplug/rpaphp_core.c @@ -321,10 +321,15 @@ int rpaphp_add_slot(struct device_node *dn) indexes[i + 1], name, type); retval = rpaphp_register_pci_slot(slot); + if (retval) + dealloc_slot_struct(slot); + name += strlen(name) + 1; type += strlen(type) + 1; } dbg("%s - Exit: rc[%d]\n", __FUNCTION__, retval); + + /* XXX FIXME: reports a failure only if last entry in loop failed */ return retval; } diff --git a/drivers/pci/hotplug/rpaphp_pci.c b/drivers/pci/hotplug/rpaphp_pci.c index 6f6cbede513..a669ba3f29c 100644 --- a/drivers/pci/hotplug/rpaphp_pci.c +++ b/drivers/pci/hotplug/rpaphp_pci.c @@ -195,7 +195,6 @@ static int setup_pci_slot(struct slot *slot) } return 0; exit_rc: - dealloc_slot_struct(slot); return -EINVAL; } diff --git a/drivers/pci/hotplug/rpaphp_slot.c b/drivers/pci/hotplug/rpaphp_slot.c index 907f1301f84..dd1e275a82c 100644 --- a/drivers/pci/hotplug/rpaphp_slot.c +++ b/drivers/pci/hotplug/rpaphp_slot.c @@ -184,7 +184,6 @@ int rpaphp_register_slot(struct slot *slot) sysfs_fail: pci_hp_deregister(php_slot); register_fail: - rpaphp_release_slot(php_slot); return retval; } -- cgit v1.2.3-70-g09d2 From 427310ff02e80cc80826407c0121cec3694c9e7d Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Fri, 13 Apr 2007 15:34:13 -0700 Subject: PCI: rpaphp: Remve another call that is a wrapper Remove another stovepipe: a call which wraps another call, and just adds printks. Signed-off-by: Linas Vepstas Cc: John Rose Signed-off-by: Kristen Carlson Accardi Signed-off-by: Greg Kroah-Hartman --- drivers/pci/hotplug/rpaphp.h | 1 - drivers/pci/hotplug/rpaphp_core.c | 6 ++++-- drivers/pci/hotplug/rpaphp_pci.c | 7 ++++++- drivers/pci/hotplug/rpaphp_slot.c | 18 ------------------ 4 files changed, 10 insertions(+), 22 deletions(-) (limited to 'drivers/pci/hotplug/rpaphp_core.c') diff --git a/drivers/pci/hotplug/rpaphp.h b/drivers/pci/hotplug/rpaphp.h index 2ccbe8d4229..fdd99b2ebe5 100644 --- a/drivers/pci/hotplug/rpaphp.h +++ b/drivers/pci/hotplug/rpaphp.h @@ -103,7 +103,6 @@ extern void dealloc_slot_struct(struct slot *slot); extern struct slot *alloc_slot_struct(struct device_node *dn, int drc_index, char *drc_name, int power_domain); extern int rpaphp_register_slot(struct slot *slot); extern int rpaphp_deregister_slot(struct slot *slot); -extern int rpaphp_get_power_status(struct slot *slot, u8 * value); extern int rpaphp_set_attention_status(struct slot *slot, u8 status); #endif /* _PPC64PHP_H */ diff --git a/drivers/pci/hotplug/rpaphp_core.c b/drivers/pci/hotplug/rpaphp_core.c index ca95e1515d6..2d919fb1931 100644 --- a/drivers/pci/hotplug/rpaphp_core.c +++ b/drivers/pci/hotplug/rpaphp_core.c @@ -100,11 +100,13 @@ static int set_attention_status(struct hotplug_slot *hotplug_slot, u8 value) */ static int get_power_status(struct hotplug_slot *hotplug_slot, u8 * value) { - int retval; + int retval, level; struct slot *slot = (struct slot *)hotplug_slot->private; down(&rpaphp_sem); - retval = rpaphp_get_power_status(slot, value); + retval = rtas_get_power_level (slot->power_domain, &level); + if (!retval) + *value = level; up(&rpaphp_sem); return retval; } diff --git a/drivers/pci/hotplug/rpaphp_pci.c b/drivers/pci/hotplug/rpaphp_pci.c index 881e8073c80..ba8c83770ab 100644 --- a/drivers/pci/hotplug/rpaphp_pci.c +++ b/drivers/pci/hotplug/rpaphp_pci.c @@ -183,9 +183,14 @@ exit_rc: int rpaphp_register_pci_slot(struct slot *slot) { + int rc, level; struct hotplug_slot_info *info = slot->hotplug_slot->info; - rpaphp_get_power_status(slot, &info->power_status); + rc = rtas_get_power_level(slot->power_domain, &level); + if (rc) + return rc; + info->power_status = level; + rpaphp_get_pci_adapter_status(slot, 1, &info->adapter_status); if (info->adapter_status == NOT_VALID) { diff --git a/drivers/pci/hotplug/rpaphp_slot.c b/drivers/pci/hotplug/rpaphp_slot.c index 9b940072798..30c9dc98e4e 100644 --- a/drivers/pci/hotplug/rpaphp_slot.c +++ b/drivers/pci/hotplug/rpaphp_slot.c @@ -184,24 +184,6 @@ sysfs_fail: return retval; } -int rpaphp_get_power_status(struct slot *slot, u8 * value) -{ - int rc = 0, level; - - rc = rtas_get_power_level(slot->power_domain, &level); - if (rc < 0) { - err("failed to get power-level for slot(%s), rc=0x%x\n", - slot->location, rc); - return rc; - } - - dbg("%s the power level of slot %s(pwd-domain:0x%x) is %d\n", - __FUNCTION__, slot->name, slot->power_domain, level); - *value = level; - - return rc; -} - int rpaphp_set_attention_status(struct slot *slot, u8 status) { int rc; -- cgit v1.2.3-70-g09d2 From bf0af511fcc856649a2a39c627828695b580d124 Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Fri, 13 Apr 2007 15:34:14 -0700 Subject: PCI: rpaphp: Remove another wrappered function Remove another stove-pipe; this funcion was called from two different places, with a compile-time const that is then run-time checked to perform two different things. Signed-off-by: Linas Vepstas Cc: John Rose Signed-off-by: Kristen Carlson Accardi Signed-off-by: Greg Kroah-Hartman --- drivers/pci/hotplug/rpaphp.h | 1 - drivers/pci/hotplug/rpaphp_core.c | 16 +++++++++-- drivers/pci/hotplug/rpaphp_pci.c | 59 +++++++++++---------------------------- 3 files changed, 29 insertions(+), 47 deletions(-) (limited to 'drivers/pci/hotplug/rpaphp_core.c') diff --git a/drivers/pci/hotplug/rpaphp.h b/drivers/pci/hotplug/rpaphp.h index fdd99b2ebe5..a2b22575cf7 100644 --- a/drivers/pci/hotplug/rpaphp.h +++ b/drivers/pci/hotplug/rpaphp.h @@ -89,7 +89,6 @@ extern struct list_head rpaphp_slot_head; /* rpaphp_pci.c */ extern int rpaphp_enable_pci_slot(struct slot *slot); extern int rpaphp_register_pci_slot(struct slot *slot); -extern int rpaphp_get_pci_adapter_status(struct slot *slot, int is_init, u8 * value); extern int rpaphp_get_sensor_state(struct slot *slot, int *state); /* rpaphp_core.c */ diff --git a/drivers/pci/hotplug/rpaphp_core.c b/drivers/pci/hotplug/rpaphp_core.c index 2d919fb1931..cab7cee6574 100644 --- a/drivers/pci/hotplug/rpaphp_core.c +++ b/drivers/pci/hotplug/rpaphp_core.c @@ -130,12 +130,22 @@ static int get_attention_status(struct hotplug_slot *hotplug_slot, u8 * value) static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 * value) { struct slot *slot = (struct slot *)hotplug_slot->private; - int retval = 0; + int rc, state; down(&rpaphp_sem); - retval = rpaphp_get_pci_adapter_status(slot, 0, value); + rc = rpaphp_get_sensor_state(slot, &state); up(&rpaphp_sem); - return retval; + + *value = NOT_VALID; + if (rc) + return rc; + + if (state == EMPTY) + *value = EMPTY; + else if (state == PRESENT) + *value = slot->state; + + return 0; } static int get_max_bus_speed(struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value) diff --git a/drivers/pci/hotplug/rpaphp_pci.c b/drivers/pci/hotplug/rpaphp_pci.c index ba8c83770ab..b6a991ab9b7 100644 --- a/drivers/pci/hotplug/rpaphp_pci.c +++ b/drivers/pci/hotplug/rpaphp_pci.c @@ -64,43 +64,6 @@ int rpaphp_get_sensor_state(struct slot *slot, int *state) return rc; } -/** - * get_pci_adapter_status - get the status of a slot - * - * 0-- slot is empty - * 1-- adapter is configured - * 2-- adapter is not configured - * 3-- not valid - */ -int rpaphp_get_pci_adapter_status(struct slot *slot, int is_init, u8 * value) -{ - struct pci_bus *bus; - int state, rc; - - *value = NOT_VALID; - rc = rpaphp_get_sensor_state(slot, &state); - if (rc) - goto exit; - - if (state == EMPTY) - *value = EMPTY; - else if (state == PRESENT) { - if (!is_init) { - /* at run-time slot->state can be changed by */ - /* config/unconfig adapter */ - *value = slot->state; - } else { - bus = pcibios_find_pci_bus(slot->dn); - if (bus && !list_empty(&bus->devices)) - *value = CONFIGURED; - else - *value = NOT_CONFIGURED; - } - } -exit: - return rc; -} - static void print_slot_pci_funcs(struct pci_bus *bus) { struct device_node *dn; @@ -183,20 +146,30 @@ exit_rc: int rpaphp_register_pci_slot(struct slot *slot) { - int rc, level; + int rc, level, state; + struct pci_bus *bus; struct hotplug_slot_info *info = slot->hotplug_slot->info; + /* Find out if the power is turned on for the slot */ rc = rtas_get_power_level(slot->power_domain, &level); if (rc) return rc; info->power_status = level; - rpaphp_get_pci_adapter_status(slot, 1, &info->adapter_status); + /* Figure out if there is an adapter in the slot */ + info->adapter_status = NOT_VALID; + rc = rpaphp_get_sensor_state(slot, &state); + if (rc) + return rc; - if (info->adapter_status == NOT_VALID) { - err("%s: NOT_VALID: skip dn->full_name=%s\n", - __FUNCTION__, slot->dn->full_name); - return -EINVAL; + if (state == EMPTY) + info->adapter_status = EMPTY; + else if (state == PRESENT) { + bus = pcibios_find_pci_bus(slot->dn); + if (bus && !list_empty(&bus->devices)) + info->adapter_status = CONFIGURED; + else + info->adapter_status = NOT_CONFIGURED; } if (setup_pci_slot(slot)) -- cgit v1.2.3-70-g09d2 From ebf42c0edd5ee325043d4ae8fbb8caebd707e791 Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Fri, 13 Apr 2007 15:34:15 -0700 Subject: PCI: rpaphp: remove a call that does nothing but a pointer lookup Delete another stovepipe: a call to a routine which does nothing. Remove un-needed semaphore as well. Signed-off-by: Linas Vepstas Cc: John Rose Signed-off-by: Kristen Carlson Accardi Signed-off-by: Greg Kroah-Hartman --- drivers/pci/hotplug/rpaphp_core.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) (limited to 'drivers/pci/hotplug/rpaphp_core.c') diff --git a/drivers/pci/hotplug/rpaphp_core.c b/drivers/pci/hotplug/rpaphp_core.c index cab7cee6574..3970cacc0b8 100644 --- a/drivers/pci/hotplug/rpaphp_core.c +++ b/drivers/pci/hotplug/rpaphp_core.c @@ -54,11 +54,6 @@ MODULE_LICENSE("GPL"); module_param(debug, bool, 0644); -static int rpaphp_get_attention_status(struct slot *slot) -{ - return slot->hotplug_slot->info->attention_status; -} - /** * set_attention_status - set attention LED * echo 0 > attention -- set LED OFF @@ -95,8 +90,6 @@ static int set_attention_status(struct hotplug_slot *hotplug_slot, u8 value) * get_power_status - get power status of a slot * @hotplug_slot: slot to get status * @value: pointer to store status - * - * */ static int get_power_status(struct hotplug_slot *hotplug_slot, u8 * value) { @@ -113,18 +106,12 @@ static int get_power_status(struct hotplug_slot *hotplug_slot, u8 * value) /** * get_attention_status - get attention LED status - * - * */ static int get_attention_status(struct hotplug_slot *hotplug_slot, u8 * value) { - int retval = 0; struct slot *slot = (struct slot *)hotplug_slot->private; - - down(&rpaphp_sem); - *value = rpaphp_get_attention_status(slot); - up(&rpaphp_sem); - return retval; + *value = slot->hotplug_slot->info->attention_status; + return 0; } static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 * value) -- cgit v1.2.3-70-g09d2 From c02929c278f2bca68635e4c2daa00b7825d71061 Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Fri, 13 Apr 2007 15:34:18 -0700 Subject: PCI: rpaphp: remove rpaphp_set_attention_status() The rpaphp_set_attention_status() routine seems to be a wrapper around a single rtas call. Abolish it. Signed-off-by: Linas Vepstas Cc: John Rose Signed-off-by: Kristen Carlson Accardi Signed-off-by: Greg Kroah-Hartman --- drivers/pci/hotplug/rpaphp.h | 1 - drivers/pci/hotplug/rpaphp_core.c | 21 ++++++++++----------- drivers/pci/hotplug/rpaphp_slot.c | 12 ------------ 3 files changed, 10 insertions(+), 24 deletions(-) (limited to 'drivers/pci/hotplug/rpaphp_core.c') diff --git a/drivers/pci/hotplug/rpaphp.h b/drivers/pci/hotplug/rpaphp.h index a2b22575cf7..e28e93cd00f 100644 --- a/drivers/pci/hotplug/rpaphp.h +++ b/drivers/pci/hotplug/rpaphp.h @@ -102,6 +102,5 @@ extern void dealloc_slot_struct(struct slot *slot); extern struct slot *alloc_slot_struct(struct device_node *dn, int drc_index, char *drc_name, int power_domain); extern int rpaphp_register_slot(struct slot *slot); extern int rpaphp_deregister_slot(struct slot *slot); -extern int rpaphp_set_attention_status(struct slot *slot, u8 status); #endif /* _PPC64PHP_H */ diff --git a/drivers/pci/hotplug/rpaphp_core.c b/drivers/pci/hotplug/rpaphp_core.c index 3970cacc0b8..e9c157d30e8 100644 --- a/drivers/pci/hotplug/rpaphp_core.c +++ b/drivers/pci/hotplug/rpaphp_core.c @@ -63,27 +63,26 @@ module_param(debug, bool, 0644); */ static int set_attention_status(struct hotplug_slot *hotplug_slot, u8 value) { - int retval = 0; + int rc; struct slot *slot = (struct slot *)hotplug_slot->private; down(&rpaphp_sem); switch (value) { case 0: - retval = rpaphp_set_attention_status(slot, LED_OFF); - hotplug_slot->info->attention_status = 0; - break; case 1: - default: - retval = rpaphp_set_attention_status(slot, LED_ON); - hotplug_slot->info->attention_status = 1; - break; case 2: - retval = rpaphp_set_attention_status(slot, LED_ID); - hotplug_slot->info->attention_status = 2; + break; + default: + value = 1; break; } up(&rpaphp_sem); - return retval; + + rc = rtas_set_indicator(DR_INDICATOR, slot->index, value); + if (!rc) + hotplug_slot->info->attention_status = value; + + return rc; } /** diff --git a/drivers/pci/hotplug/rpaphp_slot.c b/drivers/pci/hotplug/rpaphp_slot.c index 30c9dc98e4e..d4ee8723fcb 100644 --- a/drivers/pci/hotplug/rpaphp_slot.c +++ b/drivers/pci/hotplug/rpaphp_slot.c @@ -184,15 +184,3 @@ sysfs_fail: return retval; } -int rpaphp_set_attention_status(struct slot *slot, u8 status) -{ - int rc; - - /* status: LED_OFF or LED_ON */ - rc = rtas_set_indicator(DR_INDICATOR, slot->index, status); - if (rc < 0) - err("slot(name=%s location=%s index=0x%x) set attention-status(%d) failed! rc=0x%x\n", - slot->name, slot->location, slot->index, status, rc); - - return rc; -} -- cgit v1.2.3-70-g09d2 From 6f79eb749df7f1eea76c947f31603ade7d2b5f6d Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Fri, 13 Apr 2007 15:34:19 -0700 Subject: PCI: rpaphp: refactor tail call to rpaphp_register_slot() Eliminate the tail call to rpaphp_register_slot() by placing it in the caller. This will help later dis-entanglement. Signed-off-by: Linas Vepstas Cc: John Rose Signed-off-by: Kristen Carlson Accardi Signed-off-by: Greg Kroah-Hartman --- drivers/pci/hotplug/rpaphp_core.c | 3 +++ drivers/pci/hotplug/rpaphp_pci.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'drivers/pci/hotplug/rpaphp_core.c') diff --git a/drivers/pci/hotplug/rpaphp_core.c b/drivers/pci/hotplug/rpaphp_core.c index e9c157d30e8..d8e5f9fd357 100644 --- a/drivers/pci/hotplug/rpaphp_core.c +++ b/drivers/pci/hotplug/rpaphp_core.c @@ -319,6 +319,9 @@ int rpaphp_add_slot(struct device_node *dn) indexes[i + 1], name, type); retval = rpaphp_register_pci_slot(slot); + if (!retval) + retval = rpaphp_register_slot(slot); + if (retval) dealloc_slot_struct(slot); diff --git a/drivers/pci/hotplug/rpaphp_pci.c b/drivers/pci/hotplug/rpaphp_pci.c index 6271be8b155..2e297b9ffa7 100644 --- a/drivers/pci/hotplug/rpaphp_pci.c +++ b/drivers/pci/hotplug/rpaphp_pci.c @@ -136,6 +136,6 @@ int rpaphp_register_pci_slot(struct slot *slot) } } - return rpaphp_register_slot(slot); + return 0; } -- cgit v1.2.3-70-g09d2 From fea54b8cc9c8290b4c99d481c3e600c46eb18fd5 Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Fri, 13 Apr 2007 15:34:20 -0700 Subject: PCI: rpaphp: Rename rpaphp_register_pci_slot() to rpaphp_enable_slot() Rename rpaphp_register_pci_slot() because its easy to confuse with rpaphp_register_slot() even though it does something completely different. Rename it to rpaphp_enable_slot() because its almost identical to enbale_slot(). Signed-off-by: Linas Vepstas Cc: John Rose Signed-off-by: Kristen Carlson Accardi Signed-off-by: Greg Kroah-Hartman --- drivers/pci/hotplug/rpaphp.h | 4 +--- drivers/pci/hotplug/rpaphp_core.c | 2 +- drivers/pci/hotplug/rpaphp_pci.c | 10 +++++++++- 3 files changed, 11 insertions(+), 5 deletions(-) (limited to 'drivers/pci/hotplug/rpaphp_core.c') diff --git a/drivers/pci/hotplug/rpaphp.h b/drivers/pci/hotplug/rpaphp.h index e28e93cd00f..c822a779653 100644 --- a/drivers/pci/hotplug/rpaphp.h +++ b/drivers/pci/hotplug/rpaphp.h @@ -87,13 +87,11 @@ extern struct list_head rpaphp_slot_head; /* function prototypes */ /* rpaphp_pci.c */ -extern int rpaphp_enable_pci_slot(struct slot *slot); -extern int rpaphp_register_pci_slot(struct slot *slot); +extern int rpaphp_enable_slot(struct slot *slot); extern int rpaphp_get_sensor_state(struct slot *slot, int *state); /* rpaphp_core.c */ extern int rpaphp_add_slot(struct device_node *dn); -extern int rpaphp_remove_slot(struct slot *slot); extern int rpaphp_get_drc_props(struct device_node *dn, int *drc_index, char **drc_name, char **drc_type, int *drc_power_domain); diff --git a/drivers/pci/hotplug/rpaphp_core.c b/drivers/pci/hotplug/rpaphp_core.c index d8e5f9fd357..75113d9e84e 100644 --- a/drivers/pci/hotplug/rpaphp_core.c +++ b/drivers/pci/hotplug/rpaphp_core.c @@ -318,7 +318,7 @@ int rpaphp_add_slot(struct device_node *dn) dbg("Found drc-index:0x%x drc-name:%s drc-type:%s\n", indexes[i + 1], name, type); - retval = rpaphp_register_pci_slot(slot); + retval = rpaphp_enable_slot(slot); if (!retval) retval = rpaphp_register_slot(slot); diff --git a/drivers/pci/hotplug/rpaphp_pci.c b/drivers/pci/hotplug/rpaphp_pci.c index 2e297b9ffa7..54ca8650d51 100644 --- a/drivers/pci/hotplug/rpaphp_pci.c +++ b/drivers/pci/hotplug/rpaphp_pci.c @@ -77,7 +77,15 @@ static void set_slot_name(struct slot *slot) bus->number); } -int rpaphp_register_pci_slot(struct slot *slot) +/** + * rpaphp_enable_slot - record slot state, config pci device + * + * Initialize values in the slot, and the hotplug_slot info + * structures to indicate if there is a pci card plugged into + * the slot. If the slot is not empty, run the pcibios routine + * to get pcibios stuff correctly set up. + */ +int rpaphp_enable_slot(struct slot *slot) { int rc, level, state; struct pci_bus *bus; -- cgit v1.2.3-70-g09d2 From da65944be2441191539f50ce71cd1f8030699be1 Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Fri, 13 Apr 2007 15:34:22 -0700 Subject: PCI: rpaphp: Document is_php_dn() Fix up the documentation: the rpaphp_add_slot() does not actually handle embedded slots: in fact, it ignores them. Fix the flow of control in the routine that checks for embedded slots. Signed-off-by: Linas Vepstas Cc: John Rose Signed-off-by: Kristen Carlson Accardi Signed-off-by: Greg Kroah-Hartman --- drivers/pci/hotplug/rpaphp_core.c | 42 +++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 13 deletions(-) (limited to 'drivers/pci/hotplug/rpaphp_core.c') diff --git a/drivers/pci/hotplug/rpaphp_core.c b/drivers/pci/hotplug/rpaphp_core.c index 75113d9e84e..aa8d9a60d0a 100644 --- a/drivers/pci/hotplug/rpaphp_core.c +++ b/drivers/pci/hotplug/rpaphp_core.c @@ -262,6 +262,14 @@ static int is_php_type(char *drc_type) return 1; } +/** + * is_php_dn() - return 1 if this is a hotpluggable pci slot, else 0 + * + * This routine will return true only if the device node is + * a hotpluggable slot. This routine will return false + * for built-in pci slots (even when the built-in slots are + * dlparable.) + */ static int is_php_dn(struct device_node *dn, const int **indexes, const int **names, const int **types, const int **power_domains) { @@ -269,24 +277,31 @@ static int is_php_dn(struct device_node *dn, const int **indexes, int rc; rc = get_children_props(dn, indexes, names, &drc_types, power_domains); - if (rc >= 0) { - if (is_php_type((char *) &drc_types[1])) { - *types = drc_types; - return 1; - } - } + if (rc < 0) + return 0; - return 0; + if (!is_php_type((char *) &drc_types[1])) + return 0; + + *types = drc_types; + return 1; } /** - * rpaphp_add_slot -- add hotplug or dlpar slot + * rpaphp_add_slot -- declare a hotplug slot to the hotplug subsystem. + * @dn device node of slot + * + * This subroutine will register a hotplugable slot with the + * PCI hotplug infrastructure. This routine is typicaly called + * during boot time, if the hotplug slots are present at boot time, + * or is called later, by the dlpar add code, if the slot is + * being dynamically added during runtime. + * + * If the device node points at an embedded (built-in) slot, this + * routine will just return without doing anything, since embedded + * slots cannot be hotplugged. * - * rpaphp not only registers PCI hotplug slots(HOTPLUG), - * but also logical DR slots(EMBEDDED). - * HOTPLUG slot: An adapter can be physically added/removed. - * EMBEDDED slot: An adapter can be logically removed/added - * from/to a partition with the slot. + * To remove a slot, it suffices to call rpaphp_deregister_slot() */ int rpaphp_add_slot(struct device_node *dn) { @@ -299,6 +314,7 @@ int rpaphp_add_slot(struct device_node *dn) if (!dn->name || strcmp(dn->name, "pci")) return 0; + /* If this is not a hotplug slot, return without doing anything. */ if (!is_php_dn(dn, &indexes, &names, &types, &power_domains)) return 0; -- cgit v1.2.3-70-g09d2 From e70ea2634afe7d04ffaf7417df7bfdbfdc460e10 Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Fri, 13 Apr 2007 15:34:23 -0700 Subject: PCI: rpaphp: Use pcibios_remove_pci_devices() symmetrically At first blush, the disable_slot() routine does not look at all like its symmetric with the enable_slot() routine; as it seems to call a very different set of routines. However, this is easily fixed: pcibios_remove_pci_devices() does the right thing. Signed-off-by: Linas Vepstas Cc: John Rose Signed-off-by: Kristen Carlson Accardi Signed-off-by: Greg Kroah-Hartman --- drivers/pci/hotplug/rpaphp_core.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'drivers/pci/hotplug/rpaphp_core.c') diff --git a/drivers/pci/hotplug/rpaphp_core.c b/drivers/pci/hotplug/rpaphp_core.c index aa8d9a60d0a..4efdaa19e8f 100644 --- a/drivers/pci/hotplug/rpaphp_core.c +++ b/drivers/pci/hotplug/rpaphp_core.c @@ -424,18 +424,12 @@ static int enable_slot(struct hotplug_slot *hotplug_slot) return retval; } -static int __disable_slot(struct slot *slot) +static inline int __disable_slot(struct slot *slot) { - struct pci_dev *dev, *tmp; - if (slot->state == NOT_CONFIGURED) return -EINVAL; - list_for_each_entry_safe(dev, tmp, &slot->bus->devices, bus_list) { - eeh_remove_bus_device(dev); - pci_remove_bus_device(dev); - } - + pcibios_remove_pci_devices(slot->bus); slot->state = NOT_CONFIGURED; return 0; } -- cgit v1.2.3-70-g09d2 From ac1f0e9923356652f21756526e194a4a1a37dd38 Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Fri, 13 Apr 2007 15:34:25 -0700 Subject: PCI: rpaphp: Remove semaphores Remove the semaphores from the get routine. These do not appear to be protecting anything that I can make out, and they also do not seem to be required by the hotplug driver. Signed-off-by: Linas Vepstas Cc: John Rose Signed-off-by: Kristen Carlson Accardi Signed-off-by: Greg Kroah-Hartman --- drivers/pci/hotplug/rpaphp_core.c | 38 +++----------------------------------- 1 file changed, 3 insertions(+), 35 deletions(-) (limited to 'drivers/pci/hotplug/rpaphp_core.c') diff --git a/drivers/pci/hotplug/rpaphp_core.c b/drivers/pci/hotplug/rpaphp_core.c index 4efdaa19e8f..847936fe327 100644 --- a/drivers/pci/hotplug/rpaphp_core.c +++ b/drivers/pci/hotplug/rpaphp_core.c @@ -39,7 +39,6 @@ #include "rpaphp.h" int debug; -static struct semaphore rpaphp_sem; LIST_HEAD(rpaphp_slot_head); #define DRIVER_VERSION "0.1" @@ -66,7 +65,6 @@ static int set_attention_status(struct hotplug_slot *hotplug_slot, u8 value) int rc; struct slot *slot = (struct slot *)hotplug_slot->private; - down(&rpaphp_sem); switch (value) { case 0: case 1: @@ -76,7 +74,6 @@ static int set_attention_status(struct hotplug_slot *hotplug_slot, u8 value) value = 1; break; } - up(&rpaphp_sem); rc = rtas_set_indicator(DR_INDICATOR, slot->index, value); if (!rc) @@ -95,11 +92,9 @@ static int get_power_status(struct hotplug_slot *hotplug_slot, u8 * value) int retval, level; struct slot *slot = (struct slot *)hotplug_slot->private; - down(&rpaphp_sem); retval = rtas_get_power_level (slot->power_domain, &level); if (!retval) *value = level; - up(&rpaphp_sem); return retval; } @@ -118,9 +113,7 @@ static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 * value) struct slot *slot = (struct slot *)hotplug_slot->private; int rc, state; - down(&rpaphp_sem); rc = rpaphp_get_sensor_state(slot, &state); - up(&rpaphp_sem); *value = NOT_VALID; if (rc) @@ -138,7 +131,6 @@ static int get_max_bus_speed(struct hotplug_slot *hotplug_slot, enum pci_bus_spe { struct slot *slot = (struct slot *)hotplug_slot->private; - down(&rpaphp_sem); switch (slot->type) { case 1: case 2: @@ -169,7 +161,6 @@ static int get_max_bus_speed(struct hotplug_slot *hotplug_slot, enum pci_bus_spe break; } - up(&rpaphp_sem); return 0; } @@ -374,7 +365,6 @@ static int __init rpaphp_init(void) struct device_node *dn = NULL; info(DRIVER_DESC " version: " DRIVER_VERSION "\n"); - init_MUTEX(&rpaphp_sem); while ((dn = of_find_node_by_name(dn, "pci"))) rpaphp_add_slot(dn); @@ -387,8 +377,9 @@ static void __exit rpaphp_exit(void) cleanup_slots(); } -static int __enable_slot(struct slot *slot) +static int enable_slot(struct hotplug_slot *hotplug_slot) { + struct slot *slot = (struct slot *)hotplug_slot->private; int state; int retval; @@ -412,20 +403,9 @@ static int __enable_slot(struct slot *slot) return 0; } -static int enable_slot(struct hotplug_slot *hotplug_slot) +static int disable_slot(struct hotplug_slot *hotplug_slot) { - int retval; struct slot *slot = (struct slot *)hotplug_slot->private; - - down(&rpaphp_sem); - retval = __enable_slot(slot); - up(&rpaphp_sem); - - return retval; -} - -static inline int __disable_slot(struct slot *slot) -{ if (slot->state == NOT_CONFIGURED) return -EINVAL; @@ -434,18 +414,6 @@ static inline int __disable_slot(struct slot *slot) return 0; } -static int disable_slot(struct hotplug_slot *hotplug_slot) -{ - struct slot *slot = (struct slot *)hotplug_slot->private; - int retval; - - down(&rpaphp_sem); - retval = __disable_slot (slot); - up(&rpaphp_sem); - - return retval; -} - struct hotplug_slot_ops rpaphp_hotplug_slot_ops = { .owner = THIS_MODULE, .enable_slot = enable_slot, -- cgit v1.2.3-70-g09d2