11 #include <linux/pci.h>
12 #include <linux/module.h>
14 #include <linux/device.h>
15 #include <linux/mempolicy.h>
16 #include <linux/string.h>
17 #include <linux/slab.h>
18 #include <linux/sched.h>
64 dynid->
id.device = device;
67 dynid->
id.class =
class;
68 dynid->
id.class_mask = class_mask;
69 dynid->
id.driver_data = driver_data;
71 spin_lock(&drv->
dynids.lock);
73 spin_unlock(&drv->
dynids.lock);
80 static void pci_free_dynids(
struct pci_driver *drv)
84 spin_lock(&drv->
dynids.lock);
89 spin_unlock(&drv->
dynids.lock);
115 fields =
sscanf(buf,
"%x %x %x %x %x %x %lx",
116 &vendor, &device, &subvendor, &subdevice,
136 retval =
pci_add_dynid(pdrv, vendor, device, subvendor, subdevice,
152 store_remove_id(
struct device_driver *driver,
const char *buf,
size_t count)
157 subdevice =
PCI_ANY_ID,
class = 0, class_mask = 0;
161 fields =
sscanf(buf,
"%x %x %x %x %x %x",
162 &vendor, &device, &subvendor, &subdevice,
163 &
class, &class_mask);
167 spin_lock(&pdrv->
dynids.lock);
170 if ((id->
vendor == vendor) &&
181 spin_unlock(&pdrv->
dynids.lock);
195 #define pci_drv_attrs NULL
215 if (pci_match_one_device(ids, dev))
238 spin_lock(&drv->
dynids.lock);
240 if (pci_match_one_device(&dynid->
id, dev)) {
241 spin_unlock(&drv->
dynids.lock);
245 spin_unlock(&drv->
dynids.lock);
256 static long local_pci_probe(
void *_ddi)
259 struct device *dev = &ddi->
dev->dev;
265 pm_runtime_get_sync(parent);
272 pm_runtime_get_noresume(dev);
273 pm_runtime_set_active(dev);
276 rc = ddi->
drv->probe(ddi->
dev, ddi->
id);
278 pm_runtime_disable(dev);
279 pm_runtime_set_suspended(dev);
280 pm_runtime_put_noidle(dev);
283 pm_runtime_put(parent);
297 node = dev_to_node(&dev->
dev);
303 if (cpu < nr_cpu_ids)
304 error = work_on_cpu(cpu, local_pci_probe, &ddi);
306 error = local_pci_probe(&ddi);
309 error = local_pci_probe(&ddi);
330 id = pci_match_device(drv, pci_dev);
332 error = pci_call_probe(drv, pci_dev,
id);
341 static int pci_device_probe(
struct device * dev)
350 error = __pci_device_probe(drv, pci_dev);
357 static int pci_device_remove(
struct device * dev)
364 pm_runtime_get_sync(dev);
366 pm_runtime_put_noidle(dev);
372 pm_runtime_disable(dev);
373 pm_runtime_set_suspended(dev);
374 pm_runtime_put_noidle(dev);
396 static void pci_device_shutdown(
struct device *dev)
401 pm_runtime_resume(dev);
423 static int pci_restore_standard_config(
struct pci_dev *pci_dev)
439 #ifdef CONFIG_PM_SLEEP
441 static void pci_pm_default_resume_early(
struct pci_dev *pci_dev)
452 static void pci_pm_set_unknown_state(
struct pci_dev *pci_dev)
466 static int pci_pm_reenable_device(
struct pci_dev *pci_dev)
491 error = drv->
suspend(pci_dev, state);
499 "PCI PM: Device state not saved by %pF\n",
509 static int pci_legacy_suspend_late(
struct device *dev,
pm_message_t state)
526 "PCI PM: Device state not saved by %pF\n",
535 pci_pm_set_unknown_state(pci_dev);
540 static int pci_legacy_resume_early(
struct device *dev)
549 static int pci_legacy_resume(
struct device *dev)
556 return drv && drv->
resume ?
557 drv->
resume(pci_dev) : pci_pm_reenable_device(pci_dev);
562 static void pci_pm_default_resume(
struct pci_dev *pci_dev)
566 if (!pci_is_bridge(pci_dev))
567 pci_enable_wake(pci_dev,
PCI_D0,
false);
570 static void pci_pm_default_suspend(
struct pci_dev *pci_dev)
573 if (!pci_is_bridge(pci_dev))
577 static bool pci_has_legacy_pm_support(
struct pci_dev *pci_dev)
588 WARN(ret && drv->
driver.pm,
"driver %s device %04x:%04x\n",
610 pm_runtime_resume(dev);
612 if (drv && drv->
pm && drv->
pm->prepare)
613 error = drv->
pm->prepare(dev);
622 if (drv && drv->
pm && drv->
pm->complete)
623 drv->
pm->complete(dev);
628 #define pci_pm_prepare NULL
629 #define pci_pm_complete NULL
633 #ifdef CONFIG_SUSPEND
640 if (pci_has_legacy_pm_support(pci_dev))
644 pci_pm_default_suspend(pci_dev);
660 "PCI PM: State of device not saved by %pF\n",
676 if (pci_has_legacy_pm_support(pci_dev))
696 "PCI PM: State of device not saved by %pF\n",
704 if (!pci_is_bridge(pci_dev))
708 pci_pm_set_unknown_state(pci_dev);
731 pci_pm_default_resume_early(pci_dev);
733 if (pci_has_legacy_pm_support(pci_dev))
734 return pci_legacy_resume_early(dev);
736 if (drv && drv->
pm && drv->
pm->resume_noirq)
737 error = drv->
pm->resume_noirq(dev);
753 pci_restore_standard_config(pci_dev);
755 if (pci_has_legacy_pm_support(pci_dev))
756 return pci_legacy_resume(dev);
758 pci_pm_default_resume(pci_dev);
764 pci_pm_reenable_device(pci_dev);
772 #define pci_pm_suspend NULL
773 #define pci_pm_suspend_noirq NULL
774 #define pci_pm_resume NULL
775 #define pci_pm_resume_noirq NULL
779 #ifdef CONFIG_HIBERNATE_CALLBACKS
786 if (pci_has_legacy_pm_support(pci_dev))
790 pci_pm_default_suspend(pci_dev);
811 if (pci_has_legacy_pm_support(pci_dev))
814 if (drv && drv->
pm && drv->
pm->freeze_noirq) {
817 error = drv->
pm->freeze_noirq(dev);
826 pci_pm_set_unknown_state(pci_dev);
837 if (pci_has_legacy_pm_support(pci_dev))
838 return pci_legacy_resume_early(dev);
842 if (drv && drv->
pm && drv->
pm->thaw_noirq)
843 error = drv->
pm->thaw_noirq(dev);
854 if (pci_has_legacy_pm_support(pci_dev))
855 return pci_legacy_resume(dev);
859 error = pm->
thaw(dev);
861 pci_pm_reenable_device(pci_dev);
874 if (pci_has_legacy_pm_support(pci_dev))
878 pci_pm_default_suspend(pci_dev);
902 if (pci_has_legacy_pm_support(
to_pci_dev(dev)))
905 if (!drv || !drv->
pm)
908 if (drv->
pm->poweroff_noirq) {
911 error = drv->
pm->poweroff_noirq(dev);
917 if (!pci_dev->
state_saved && !pci_is_bridge(pci_dev))
936 pci_pm_default_resume_early(pci_dev);
938 if (pci_has_legacy_pm_support(pci_dev))
939 return pci_legacy_resume_early(dev);
941 if (drv && drv->
pm && drv->
pm->restore_noirq)
942 error = drv->
pm->restore_noirq(dev);
958 pci_restore_standard_config(pci_dev);
960 if (pci_has_legacy_pm_support(pci_dev))
961 return pci_legacy_resume(dev);
963 pci_pm_default_resume(pci_dev);
969 pci_pm_reenable_device(pci_dev);
977 #define pci_pm_freeze NULL
978 #define pci_pm_freeze_noirq NULL
979 #define pci_pm_thaw NULL
980 #define pci_pm_thaw_noirq NULL
981 #define pci_pm_poweroff NULL
982 #define pci_pm_poweroff_noirq NULL
983 #define pci_pm_restore NULL
984 #define pci_pm_restore_noirq NULL
988 #ifdef CONFIG_PM_RUNTIME
1013 "PCI PM: State of device not saved by %pF\n",
1035 pci_restore_standard_config(pci_dev);
1060 pm_runtime_suspend(dev);
1067 #define pci_pm_runtime_suspend NULL
1068 #define pci_pm_runtime_resume NULL
1069 #define pci_pm_runtime_idle NULL
1095 #define PCI_PM_OPS_PTR (&pci_dev_pm_ops)
1099 #define PCI_PM_OPS_PTR NULL
1115 const char *mod_name)
1121 drv->
driver.mod_name = mod_name;
1124 INIT_LIST_HEAD(&drv->
dynids.list);
1144 pci_free_dynids(drv);
1147 static struct pci_driver pci_compat_driver = {
1167 return &pci_compat_driver;
1181 static int pci_bus_match(
struct device *dev,
struct device_driver *drv)
1187 found_id = pci_match_device(pci_drv, pci_dev);
1226 #ifndef CONFIG_HOTPLUG
1235 .match = pci_bus_match,
1237 .probe = pci_device_probe,
1238 .remove = pci_device_remove,
1239 .shutdown = pci_device_shutdown,
1246 static int __init pci_driver_init(
void)