Commit 8c8079c3 authored by Linda Xie's avatar Linda Xie Committed by Greg Kroah-Hartman

[PATCH] PCI Hotplug: php_phy_location.patch

Adds a file to show the pci hotplug slot location for the ppc64 driver
only.
parent e4705596
...@@ -79,25 +79,18 @@ static struct device_node *find_php_slot_pci_node(char *drc_name) ...@@ -79,25 +79,18 @@ static struct device_node *find_php_slot_pci_node(char *drc_name)
return np; return np;
} }
static inline struct hotplug_slot *find_php_slot(char *drc_name)
{
struct kobject *k;
k = kset_find_obj(&pci_hotplug_slots_subsys.kset, drc_name);
if (!k)
return NULL;
return to_hotplug_slot(k);
}
static struct slot *find_slot(char *drc_name) static struct slot *find_slot(char *drc_name)
{ {
struct hotplug_slot *php_slot = find_php_slot(drc_name); struct list_head *tmp, *n;
struct slot *slot;
if (!php_slot) list_for_each_safe(tmp, n, &rpaphp_slot_head) {
return NULL; slot = list_entry(tmp, struct slot, rpaphp_slot_list);
if (strcmp(slot->location, drc_name) == 0)
return slot;
}
return (struct slot *) php_slot->private; return NULL;
} }
static void rpadlpar_claim_one_bus(struct pci_bus *b) static void rpadlpar_claim_one_bus(struct pci_bus *b)
......
...@@ -85,6 +85,7 @@ struct slot { ...@@ -85,6 +85,7 @@ struct slot {
u32 type; u32 type;
u32 power_domain; u32 power_domain;
char *name; char *name;
char *location;
struct device_node *dn; /* slot's device_node in OFDT */ struct device_node *dn; /* slot's device_node in OFDT */
/* dn has phb info */ /* dn has phb info */
struct pci_dev *bridge; /* slot's pci_dev in pci_devices */ struct pci_dev *bridge; /* slot's pci_dev in pci_devices */
...@@ -129,5 +130,6 @@ extern struct slot *alloc_slot_struct(struct device_node *dn, int drc_index, cha ...@@ -129,5 +130,6 @@ extern struct slot *alloc_slot_struct(struct device_node *dn, int drc_index, cha
extern int register_slot(struct slot *slot); extern int register_slot(struct slot *slot);
extern int rpaphp_get_power_status(struct slot *slot, u8 * value); extern int rpaphp_get_power_status(struct slot *slot, u8 * value);
extern int rpaphp_set_attention_status(struct slot *slot, u8 status); extern int rpaphp_set_attention_status(struct slot *slot, u8 status);
extern void rpaphp_sysfs_remove_attr_location(struct hotplug_slot *slot);
#endif /* _PPC64PHP_H */ #endif /* _PPC64PHP_H */
...@@ -246,17 +246,14 @@ static int get_cur_bus_speed(struct hotplug_slot *hotplug_slot, enum pci_bus_spe ...@@ -246,17 +246,14 @@ static int get_cur_bus_speed(struct hotplug_slot *hotplug_slot, enum pci_bus_spe
int rpaphp_remove_slot(struct slot *slot) int rpaphp_remove_slot(struct slot *slot)
{ {
int retval = 0; int retval = 0;
char *rm_link; struct hotplug_slot *php_slot = slot->hotplug_slot;
dbg("%s - Entry: slot[%s]\n", __FUNCTION__, slot->name);
if (slot->dev_type == PCI_DEV)
rm_link = pci_name(slot->bridge);
else
rm_link = strstr(slot->dn->full_name, "@");
sysfs_remove_link(slot->hotplug_slot->kobj.parent, rm_link);
list_del(&slot->rpaphp_slot_list); list_del(&slot->rpaphp_slot_list);
retval = pci_hp_deregister(slot->hotplug_slot);
/* remove "php_location" file */
rpaphp_sysfs_remove_attr_location(php_slot);
retval = pci_hp_deregister(php_slot);
if (retval) if (retval)
err("Problem unregistering a slot %s\n", slot->name); err("Problem unregistering a slot %s\n", slot->name);
...@@ -380,14 +377,7 @@ static void cleanup_slots(void) ...@@ -380,14 +377,7 @@ static void cleanup_slots(void)
*/ */
list_for_each_safe(tmp, n, &rpaphp_slot_head) { list_for_each_safe(tmp, n, &rpaphp_slot_head) {
char *rm_link;
slot = list_entry(tmp, struct slot, rpaphp_slot_list); slot = list_entry(tmp, struct slot, rpaphp_slot_list);
if (slot->dev_type == PCI_DEV)
rm_link = pci_name(slot->bridge);
else
rm_link = strstr(slot->dn->full_name, "@");
sysfs_remove_link(slot->hotplug_slot->kobj.parent, rm_link);
list_del(&slot->rpaphp_slot_list); list_del(&slot->rpaphp_slot_list);
pci_hp_deregister(slot->hotplug_slot); pci_hp_deregister(slot->hotplug_slot);
} }
...@@ -478,3 +468,4 @@ module_exit(rpaphp_exit); ...@@ -478,3 +468,4 @@ module_exit(rpaphp_exit);
EXPORT_SYMBOL_GPL(rpaphp_add_slot); EXPORT_SYMBOL_GPL(rpaphp_add_slot);
EXPORT_SYMBOL_GPL(rpaphp_remove_slot); EXPORT_SYMBOL_GPL(rpaphp_remove_slot);
EXPORT_SYMBOL_GPL(rpaphp_slot_head);
...@@ -29,8 +29,36 @@ ...@@ -29,8 +29,36 @@
#include <linux/pci.h> #include <linux/pci.h>
#include "rpaphp.h" #include "rpaphp.h"
/* free up the memory user by a slot */ static ssize_t location_read_file (struct hotplug_slot *php_slot, char *buf)
{
char *value;
int retval = -ENOENT;
struct slot *slot = (struct slot *)php_slot->private;
if (!slot)
return retval;
value = slot->location;
retval = sprintf (buf, "%s\n", value);
return retval;
}
static struct hotplug_slot_attribute hotplug_slot_attr_location = {
.attr = {.name = "phy_location", .mode = S_IFREG | S_IRUGO},
.show = location_read_file,
};
static void rpaphp_sysfs_add_attr_location (struct hotplug_slot *slot)
{
sysfs_create_file(&slot->kobj, &hotplug_slot_attr_location.attr);
}
void rpaphp_sysfs_remove_attr_location (struct hotplug_slot *slot)
{
sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_location.attr);
}
/* free up the memory user by a slot */
static void rpaphp_release_slot(struct hotplug_slot *hotplug_slot) static void rpaphp_release_slot(struct hotplug_slot *hotplug_slot)
{ {
struct slot *slot = hotplug_slot? (struct slot *) hotplug_slot->private:NULL; struct slot *slot = hotplug_slot? (struct slot *) hotplug_slot->private:NULL;
...@@ -76,17 +104,25 @@ struct slot *alloc_slot_struct(struct device_node *dn, int drc_index, char *drc_ ...@@ -76,17 +104,25 @@ struct slot *alloc_slot_struct(struct device_node *dn, int drc_index, char *drc_
return (NULL); return (NULL);
} }
memset(slot->hotplug_slot->info, 0, sizeof (struct hotplug_slot_info)); memset(slot->hotplug_slot->info, 0, sizeof (struct hotplug_slot_info));
slot->hotplug_slot->name = kmalloc(strlen(drc_name) + 1, GFP_KERNEL); slot->hotplug_slot->name = kmalloc(BUS_ID_SIZE + 1, GFP_KERNEL);
if (!slot->hotplug_slot->name) { if (!slot->hotplug_slot->name) {
kfree(slot->hotplug_slot->info); kfree(slot->hotplug_slot->info);
kfree(slot->hotplug_slot); kfree(slot->hotplug_slot);
kfree(slot); kfree(slot);
return (NULL); return (NULL);
} }
slot->location = kmalloc(strlen(drc_name) + 1, GFP_KERNEL);
if (!slot->location) {
kfree(slot->hotplug_slot->info);
kfree(slot->hotplug_slot->name);
kfree(slot->hotplug_slot);
kfree(slot);
return (NULL);
}
slot->name = slot->hotplug_slot->name; slot->name = slot->hotplug_slot->name;
slot->dn = dn; slot->dn = dn;
slot->index = drc_index; slot->index = drc_index;
strcpy(slot->name, drc_name); strcpy(slot->location, drc_name);
slot->power_domain = power_domain; slot->power_domain = power_domain;
slot->magic = SLOT_MAGIC; slot->magic = SLOT_MAGIC;
slot->hotplug_slot->private = slot; slot->hotplug_slot->private = slot;
...@@ -110,41 +146,9 @@ int register_slot(struct slot *slot) ...@@ -110,41 +146,9 @@ int register_slot(struct slot *slot)
rpaphp_release_slot(slot->hotplug_slot); rpaphp_release_slot(slot->hotplug_slot);
return (retval); return (retval);
} }
switch (slot->dev_type) {
case PCI_DEV: /* create "phy_locatoin" file */
/* create symlink between slot->name and it's bus_id */ rpaphp_sysfs_add_attr_location(slot->hotplug_slot);
dbg("%s: sysfs_create_link: %s --> %s\n", __FUNCTION__,
pci_name(slot->bridge), slot->name);
retval = sysfs_create_link(slot->hotplug_slot->kobj.parent,
&slot->hotplug_slot->kobj,
pci_name(slot->bridge));
if (retval) {
err("sysfs_create_link failed with error %d\n", retval);
rpaphp_release_slot(slot->hotplug_slot);
return (retval);
}
break;
case VIO_DEV:
/* create symlink between slot->name and it's uni-address */
vio_uni_addr = strchr(slot->dn->full_name, '@');
if (!vio_uni_addr)
return (1);
dbg("%s: sysfs_create_link: %s --> %s\n", __FUNCTION__,
vio_uni_addr, slot->name);
retval = sysfs_create_link(slot->hotplug_slot->kobj.parent,
&slot->hotplug_slot->kobj,
vio_uni_addr);
if (retval) {
err("sysfs_create_link failed with error %d\n", retval);
rpaphp_release_slot(slot->hotplug_slot);
return (retval);
}
break;
default:
return (1);
}
/* add slot to our internal list */ /* add slot to our internal list */
dbg("%s adding slot[%s] to rpaphp_slot_list\n", dbg("%s adding slot[%s] to rpaphp_slot_list\n",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment