aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci
diff options
context:
space:
mode:
authorPaul Mackerras <paulus@samba.org>2008-01-30 19:25:51 -0500
committerPaul Mackerras <paulus@samba.org>2008-01-30 19:25:51 -0500
commitbd45ac0c5daae35e7c71138172e63df5cf644cf6 (patch)
tree5eb5a599bf6a9d7a8a34e802db932aa9e9555de4 /drivers/pci
parent4eece4ccf997c0e6d8fdad3d842e37b16b8d705f (diff)
parent5bdeae46be6dfe9efa44a548bd622af325f4bdb4 (diff)
Merge branch 'linux-2.6'
Diffstat (limited to 'drivers/pci')
-rw-r--r--drivers/pci/hotplug/acpiphp_ibm.c4
-rw-r--r--drivers/pci/hotplug/pci_hotplug_core.c39
-rw-r--r--drivers/pci/hotplug/rpadlpar_sysfs.c113
-rw-r--r--drivers/pci/pci-driver.c59
-rw-r--r--drivers/pci/probe.c11
5 files changed, 85 insertions, 141 deletions
diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
index 47d26b65e99a..750ebd7a4c10 100644
--- a/drivers/pci/hotplug/acpiphp_ibm.c
+++ b/drivers/pci/hotplug/acpiphp_ibm.c
@@ -429,7 +429,7 @@ static int __init ibm_acpiphp_init(void)
429 int retval = 0; 429 int retval = 0;
430 acpi_status status; 430 acpi_status status;
431 struct acpi_device *device; 431 struct acpi_device *device;
432 struct kobject *sysdir = &pci_hotplug_slots_subsys.kobj; 432 struct kobject *sysdir = &pci_hotplug_slots_kset->kobj;
433 433
434 dbg("%s\n", __FUNCTION__); 434 dbg("%s\n", __FUNCTION__);
435 435
@@ -476,7 +476,7 @@ init_return:
476static void __exit ibm_acpiphp_exit(void) 476static void __exit ibm_acpiphp_exit(void)
477{ 477{
478 acpi_status status; 478 acpi_status status;
479 struct kobject *sysdir = &pci_hotplug_slots_subsys.kobj; 479 struct kobject *sysdir = &pci_hotplug_slots_kset->kobj;
480 480
481 dbg("%s\n", __FUNCTION__); 481 dbg("%s\n", __FUNCTION__);
482 482
diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
index 01c351c176ac..47bb0e1ff3fa 100644
--- a/drivers/pci/hotplug/pci_hotplug_core.c
+++ b/drivers/pci/hotplug/pci_hotplug_core.c
@@ -61,7 +61,7 @@ static int debug;
61 61
62static LIST_HEAD(pci_hotplug_slot_list); 62static LIST_HEAD(pci_hotplug_slot_list);
63 63
64struct kset pci_hotplug_slots_subsys; 64struct kset *pci_hotplug_slots_kset;
65 65
66static ssize_t hotplug_slot_attr_show(struct kobject *kobj, 66static ssize_t hotplug_slot_attr_show(struct kobject *kobj,
67 struct attribute *attr, char *buf) 67 struct attribute *attr, char *buf)
@@ -96,8 +96,6 @@ static struct kobj_type hotplug_slot_ktype = {
96 .release = &hotplug_slot_release, 96 .release = &hotplug_slot_release,
97}; 97};
98 98
99decl_subsys_name(pci_hotplug_slots, slots, &hotplug_slot_ktype, NULL);
100
101/* these strings match up with the values in pci_bus_speed */ 99/* these strings match up with the values in pci_bus_speed */
102static char *pci_bus_speed_strings[] = { 100static char *pci_bus_speed_strings[] = {
103 "33 MHz PCI", /* 0x00 */ 101 "33 MHz PCI", /* 0x00 */
@@ -632,18 +630,19 @@ int pci_hp_register (struct hotplug_slot *slot)
632 return -EINVAL; 630 return -EINVAL;
633 } 631 }
634 632
635 kobject_set_name(&slot->kobj, "%s", slot->name);
636 kobj_set_kset_s(slot, pci_hotplug_slots_subsys);
637
638 /* this can fail if we have already registered a slot with the same name */ 633 /* this can fail if we have already registered a slot with the same name */
639 if (kobject_register(&slot->kobj)) { 634 slot->kobj.kset = pci_hotplug_slots_kset;
640 err("Unable to register kobject"); 635 result = kobject_init_and_add(&slot->kobj, &hotplug_slot_ktype, NULL,
636 "%s", slot->name);
637 if (result) {
638 err("Unable to register kobject '%s'", slot->name);
641 return -EINVAL; 639 return -EINVAL;
642 } 640 }
643 641
644 list_add (&slot->slot_list, &pci_hotplug_slot_list); 642 list_add (&slot->slot_list, &pci_hotplug_slot_list);
645 643
646 result = fs_add_slot (slot); 644 result = fs_add_slot (slot);
645 kobject_uevent(&slot->kobj, KOBJ_ADD);
647 dbg ("Added slot %s to the list\n", slot->name); 646 dbg ("Added slot %s to the list\n", slot->name);
648 return result; 647 return result;
649} 648}
@@ -672,7 +671,7 @@ int pci_hp_deregister (struct hotplug_slot *slot)
672 671
673 fs_remove_slot (slot); 672 fs_remove_slot (slot);
674 dbg ("Removed slot %s from the list\n", slot->name); 673 dbg ("Removed slot %s from the list\n", slot->name);
675 kobject_unregister(&slot->kobj); 674 kobject_put(&slot->kobj);
676 return 0; 675 return 0;
677} 676}
678 677
@@ -700,11 +699,15 @@ int __must_check pci_hp_change_slot_info(struct hotplug_slot *slot,
700static int __init pci_hotplug_init (void) 699static int __init pci_hotplug_init (void)
701{ 700{
702 int result; 701 int result;
702 struct kset *pci_bus_kset;
703 703
704 kobj_set_kset_s(&pci_hotplug_slots_subsys, pci_bus_type.subsys); 704 pci_bus_kset = bus_get_kset(&pci_bus_type);
705 result = subsystem_register(&pci_hotplug_slots_subsys); 705
706 if (result) { 706 pci_hotplug_slots_kset = kset_create_and_add("slots", NULL,
707 err("Register subsys with error %d\n", result); 707 &pci_bus_kset->kobj);
708 if (!pci_hotplug_slots_kset) {
709 result = -ENOMEM;
710 err("Register subsys error\n");
708 goto exit; 711 goto exit;
709 } 712 }
710 result = cpci_hotplug_init(debug); 713 result = cpci_hotplug_init(debug);
@@ -715,9 +718,9 @@ static int __init pci_hotplug_init (void)
715 718
716 info (DRIVER_DESC " version: " DRIVER_VERSION "\n"); 719 info (DRIVER_DESC " version: " DRIVER_VERSION "\n");
717 goto exit; 720 goto exit;
718 721
719err_subsys: 722err_subsys:
720 subsystem_unregister(&pci_hotplug_slots_subsys); 723 kset_unregister(pci_hotplug_slots_kset);
721exit: 724exit:
722 return result; 725 return result;
723} 726}
@@ -725,7 +728,7 @@ exit:
725static void __exit pci_hotplug_exit (void) 728static void __exit pci_hotplug_exit (void)
726{ 729{
727 cpci_hotplug_exit(); 730 cpci_hotplug_exit();
728 subsystem_unregister(&pci_hotplug_slots_subsys); 731 kset_unregister(pci_hotplug_slots_kset);
729} 732}
730 733
731module_init(pci_hotplug_init); 734module_init(pci_hotplug_init);
@@ -737,7 +740,7 @@ MODULE_LICENSE("GPL");
737module_param(debug, bool, 0644); 740module_param(debug, bool, 0644);
738MODULE_PARM_DESC(debug, "Debugging mode enabled or not"); 741MODULE_PARM_DESC(debug, "Debugging mode enabled or not");
739 742
740EXPORT_SYMBOL_GPL(pci_hotplug_slots_subsys); 743EXPORT_SYMBOL_GPL(pci_hotplug_slots_kset);
741EXPORT_SYMBOL_GPL(pci_hp_register); 744EXPORT_SYMBOL_GPL(pci_hp_register);
742EXPORT_SYMBOL_GPL(pci_hp_deregister); 745EXPORT_SYMBOL_GPL(pci_hp_deregister);
743EXPORT_SYMBOL_GPL(pci_hp_change_slot_info); 746EXPORT_SYMBOL_GPL(pci_hp_change_slot_info);
diff --git a/drivers/pci/hotplug/rpadlpar_sysfs.c b/drivers/pci/hotplug/rpadlpar_sysfs.c
index a080fedf0332..e32148a8fa12 100644
--- a/drivers/pci/hotplug/rpadlpar_sysfs.c
+++ b/drivers/pci/hotplug/rpadlpar_sysfs.c
@@ -23,44 +23,13 @@
23 23
24#define MAX_DRC_NAME_LEN 64 24#define MAX_DRC_NAME_LEN 64
25 25
26/* Store return code of dlpar operation in attribute struct */
27struct dlpar_io_attr {
28 int rc;
29 struct attribute attr;
30 ssize_t (*store)(struct dlpar_io_attr *dlpar_attr, const char *buf,
31 size_t nbytes);
32};
33 26
34/* Common show callback for all attrs, display the return code 27static ssize_t add_slot_store(struct kobject *kobj, struct kobj_attribute *attr,
35 * of the dlpar op */ 28 const char *buf, size_t nbytes)
36static ssize_t
37dlpar_attr_show(struct kobject * kobj, struct attribute * attr, char * buf)
38{
39 struct dlpar_io_attr *dlpar_attr = container_of(attr,
40 struct dlpar_io_attr, attr);
41 return sprintf(buf, "%d\n", dlpar_attr->rc);
42}
43
44static ssize_t
45dlpar_attr_store(struct kobject * kobj, struct attribute * attr,
46 const char *buf, size_t nbytes)
47{
48 struct dlpar_io_attr *dlpar_attr = container_of(attr,
49 struct dlpar_io_attr, attr);
50 return dlpar_attr->store ?
51 dlpar_attr->store(dlpar_attr, buf, nbytes) : -EIO;
52}
53
54static struct sysfs_ops dlpar_attr_sysfs_ops = {
55 .show = dlpar_attr_show,
56 .store = dlpar_attr_store,
57};
58
59static ssize_t add_slot_store(struct dlpar_io_attr *dlpar_attr,
60 const char *buf, size_t nbytes)
61{ 29{
62 char drc_name[MAX_DRC_NAME_LEN]; 30 char drc_name[MAX_DRC_NAME_LEN];
63 char *end; 31 char *end;
32 int rc;
64 33
65 if (nbytes >= MAX_DRC_NAME_LEN) 34 if (nbytes >= MAX_DRC_NAME_LEN)
66 return 0; 35 return 0;
@@ -72,15 +41,25 @@ static ssize_t add_slot_store(struct dlpar_io_attr *dlpar_attr,
72 end = &drc_name[nbytes]; 41 end = &drc_name[nbytes];
73 *end = '\0'; 42 *end = '\0';
74 43
75 dlpar_attr->rc = dlpar_add_slot(drc_name); 44 rc = dlpar_add_slot(drc_name);
45 if (rc)
46 return rc;
76 47
77 return nbytes; 48 return nbytes;
78} 49}
79 50
80static ssize_t remove_slot_store(struct dlpar_io_attr *dlpar_attr, 51static ssize_t add_slot_show(struct kobject *kobj,
81 const char *buf, size_t nbytes) 52 struct kobj_attribute *attr, char *buf)
53{
54 return sprintf(buf, "0\n");
55}
56
57static ssize_t remove_slot_store(struct kobject *kobj,
58 struct kobj_attribute *attr,
59 const char *buf, size_t nbytes)
82{ 60{
83 char drc_name[MAX_DRC_NAME_LEN]; 61 char drc_name[MAX_DRC_NAME_LEN];
62 int rc;
84 char *end; 63 char *end;
85 64
86 if (nbytes >= MAX_DRC_NAME_LEN) 65 if (nbytes >= MAX_DRC_NAME_LEN)
@@ -93,22 +72,24 @@ static ssize_t remove_slot_store(struct dlpar_io_attr *dlpar_attr,
93 end = &drc_name[nbytes]; 72 end = &drc_name[nbytes];
94 *end = '\0'; 73 *end = '\0';
95 74
96 dlpar_attr->rc = dlpar_remove_slot(drc_name); 75 rc = dlpar_remove_slot(drc_name);
76 if (rc)
77 return rc;
97 78
98 return nbytes; 79 return nbytes;
99} 80}
100 81
101static struct dlpar_io_attr add_slot_attr = { 82static ssize_t remove_slot_show(struct kobject *kobj,
102 .rc = 0, 83 struct kobj_attribute *attr, char *buf)
103 .attr = { .name = ADD_SLOT_ATTR_NAME, .mode = 0644, }, 84{
104 .store = add_slot_store, 85 return sprintf(buf, "0\n");
105}; 86}
106 87
107static struct dlpar_io_attr remove_slot_attr = { 88static struct kobj_attribute add_slot_attr =
108 .rc = 0, 89 __ATTR(ADD_SLOT_ATTR_NAME, 0644, add_slot_show, add_slot_store);
109 .attr = { .name = REMOVE_SLOT_ATTR_NAME, .mode = 0644}, 90
110 .store = remove_slot_store, 91static struct kobj_attribute remove_slot_attr =
111}; 92 __ATTR(REMOVE_SLOT_ATTR_NAME, 0644, remove_slot_show, remove_slot_store);
112 93
113static struct attribute *default_attrs[] = { 94static struct attribute *default_attrs[] = {
114 &add_slot_attr.attr, 95 &add_slot_attr.attr,
@@ -116,37 +97,29 @@ static struct attribute *default_attrs[] = {
116 NULL, 97 NULL,
117}; 98};
118 99
119static void dlpar_io_release(struct kobject *kobj) 100static struct attribute_group dlpar_attr_group = {
120{ 101 .attrs = default_attrs,
121 /* noop */
122 return;
123}
124
125struct kobj_type ktype_dlpar_io = {
126 .release = dlpar_io_release,
127 .sysfs_ops = &dlpar_attr_sysfs_ops,
128 .default_attrs = default_attrs,
129}; 102};
130 103
131struct kset dlpar_io_kset = { 104static struct kobject *dlpar_kobj;
132 .kobj = {.ktype = &ktype_dlpar_io,
133 .parent = &pci_hotplug_slots_subsys.kobj},
134 .ktype = &ktype_dlpar_io,
135};
136 105
137int dlpar_sysfs_init(void) 106int dlpar_sysfs_init(void)
138{ 107{
139 kobject_set_name(&dlpar_io_kset.kobj, DLPAR_KOBJ_NAME); 108 int error;
140 if (kset_register(&dlpar_io_kset)) { 109
141 printk(KERN_ERR "rpadlpar_io: cannot register kset for %s\n", 110 dlpar_kobj = kobject_create_and_add(DLPAR_KOBJ_NAME,
142 kobject_name(&dlpar_io_kset.kobj)); 111 &pci_hotplug_slots_kset->kobj);
112 if (!dlpar_kobj)
143 return -EINVAL; 113 return -EINVAL;
144 }
145 114
146 return 0; 115 error = sysfs_create_group(dlpar_kobj, &dlpar_attr_group);
116 if (error)
117 kobject_put(dlpar_kobj);
118 return error;
147} 119}
148 120
149void dlpar_sysfs_exit(void) 121void dlpar_sysfs_exit(void)
150{ 122{
151 kset_unregister(&dlpar_io_kset); 123 sysfs_remove_group(dlpar_kobj, &dlpar_attr_group);
124 kobject_put(dlpar_kobj);
152} 125}
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index 6d1a21611818..c4fa35d1dd77 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -1,6 +1,11 @@
1/* 1/*
2 * drivers/pci/pci-driver.c 2 * drivers/pci/pci-driver.c
3 * 3 *
4 * (C) Copyright 2002-2004, 2007 Greg Kroah-Hartman <greg@kroah.com>
5 * (C) Copyright 2007 Novell Inc.
6 *
7 * Released under the GPL v2 only.
8 *
4 */ 9 */
5 10
6#include <linux/pci.h> 11#include <linux/pci.h>
@@ -96,17 +101,21 @@ pci_create_newid_file(struct pci_driver *drv)
96{ 101{
97 int error = 0; 102 int error = 0;
98 if (drv->probe != NULL) 103 if (drv->probe != NULL)
99 error = sysfs_create_file(&drv->driver.kobj, 104 error = driver_create_file(&drv->driver, &driver_attr_new_id);
100 &driver_attr_new_id.attr);
101 return error; 105 return error;
102} 106}
103 107
108static void pci_remove_newid_file(struct pci_driver *drv)
109{
110 driver_remove_file(&drv->driver, &driver_attr_new_id);
111}
104#else /* !CONFIG_HOTPLUG */ 112#else /* !CONFIG_HOTPLUG */
105static inline void pci_free_dynids(struct pci_driver *drv) {} 113static inline void pci_free_dynids(struct pci_driver *drv) {}
106static inline int pci_create_newid_file(struct pci_driver *drv) 114static inline int pci_create_newid_file(struct pci_driver *drv)
107{ 115{
108 return 0; 116 return 0;
109} 117}
118static inline void pci_remove_newid_file(struct pci_driver *drv) {}
110#endif 119#endif
111 120
112/** 121/**
@@ -352,50 +361,6 @@ static void pci_device_shutdown(struct device *dev)
352 drv->shutdown(pci_dev); 361 drv->shutdown(pci_dev);
353} 362}
354 363
355#define kobj_to_pci_driver(obj) container_of(obj, struct device_driver, kobj)
356#define attr_to_driver_attribute(obj) container_of(obj, struct driver_attribute, attr)
357
358static ssize_t
359pci_driver_attr_show(struct kobject * kobj, struct attribute *attr, char *buf)
360{
361 struct device_driver *driver = kobj_to_pci_driver(kobj);
362 struct driver_attribute *dattr = attr_to_driver_attribute(attr);
363 ssize_t ret;
364
365 if (!get_driver(driver))
366 return -ENODEV;
367
368 ret = dattr->show ? dattr->show(driver, buf) : -EIO;
369
370 put_driver(driver);
371 return ret;
372}
373
374static ssize_t
375pci_driver_attr_store(struct kobject * kobj, struct attribute *attr,
376 const char *buf, size_t count)
377{
378 struct device_driver *driver = kobj_to_pci_driver(kobj);
379 struct driver_attribute *dattr = attr_to_driver_attribute(attr);
380 ssize_t ret;
381
382 if (!get_driver(driver))
383 return -ENODEV;
384
385 ret = dattr->store ? dattr->store(driver, buf, count) : -EIO;
386
387 put_driver(driver);
388 return ret;
389}
390
391static struct sysfs_ops pci_driver_sysfs_ops = {
392 .show = pci_driver_attr_show,
393 .store = pci_driver_attr_store,
394};
395static struct kobj_type pci_driver_kobj_type = {
396 .sysfs_ops = &pci_driver_sysfs_ops,
397};
398
399/** 364/**
400 * __pci_register_driver - register a new pci driver 365 * __pci_register_driver - register a new pci driver
401 * @drv: the driver structure to register 366 * @drv: the driver structure to register
@@ -417,7 +382,6 @@ int __pci_register_driver(struct pci_driver *drv, struct module *owner,
417 drv->driver.bus = &pci_bus_type; 382 drv->driver.bus = &pci_bus_type;
418 drv->driver.owner = owner; 383 drv->driver.owner = owner;
419 drv->driver.mod_name = mod_name; 384 drv->driver.mod_name = mod_name;
420 drv->driver.kobj.ktype = &pci_driver_kobj_type;
421 385
422 spin_lock_init(&drv->dynids.lock); 386 spin_lock_init(&drv->dynids.lock);
423 INIT_LIST_HEAD(&drv->dynids.list); 387 INIT_LIST_HEAD(&drv->dynids.list);
@@ -447,6 +411,7 @@ int __pci_register_driver(struct pci_driver *drv, struct module *owner,
447void 411void
448pci_unregister_driver(struct pci_driver *drv) 412pci_unregister_driver(struct pci_driver *drv)
449{ 413{
414 pci_remove_newid_file(drv);
450 driver_unregister(&drv->driver); 415 driver_unregister(&drv->driver);
451 pci_free_dynids(drv); 416 pci_free_dynids(drv);
452} 417}
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index c5ca3134513a..5fd585293e79 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -1210,16 +1210,19 @@ static void __init pci_sort_breadthfirst_klist(void)
1210 struct klist_node *n; 1210 struct klist_node *n;
1211 struct device *dev; 1211 struct device *dev;
1212 struct pci_dev *pdev; 1212 struct pci_dev *pdev;
1213 struct klist *device_klist;
1213 1214
1214 spin_lock(&pci_bus_type.klist_devices.k_lock); 1215 device_klist = bus_get_device_klist(&pci_bus_type);
1215 list_for_each_safe(pos, tmp, &pci_bus_type.klist_devices.k_list) { 1216
1217 spin_lock(&device_klist->k_lock);
1218 list_for_each_safe(pos, tmp, &device_klist->k_list) {
1216 n = container_of(pos, struct klist_node, n_node); 1219 n = container_of(pos, struct klist_node, n_node);
1217 dev = container_of(n, struct device, knode_bus); 1220 dev = container_of(n, struct device, knode_bus);
1218 pdev = to_pci_dev(dev); 1221 pdev = to_pci_dev(dev);
1219 pci_insertion_sort_klist(pdev, &sorted_devices); 1222 pci_insertion_sort_klist(pdev, &sorted_devices);
1220 } 1223 }
1221 list_splice(&sorted_devices, &pci_bus_type.klist_devices.k_list); 1224 list_splice(&sorted_devices, &device_klist->k_list);
1222 spin_unlock(&pci_bus_type.klist_devices.k_lock); 1225 spin_unlock(&device_klist->k_lock);
1223} 1226}
1224 1227
1225static void __init pci_insertion_sort_devices(struct pci_dev *a, struct list_head *list) 1228static void __init pci_insertion_sort_devices(struct pci_dev *a, struct list_head *list)