aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci/pci-driver.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/pci/pci-driver.c')
-rw-r--r--drivers/pci/pci-driver.c59
1 files changed, 12 insertions, 47 deletions
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}