00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <linux/pci.h>
00012 #include <linux/module.h>
00013 #include <linux/init.h>
00014 #include <linux/device.h>
00015 #include <linux/mempolicy.h>
00016 #include <linux/string.h>
00017 #include <linux/slab.h>
00018 #include <linux/sched.h>
00019 #include <linux/cpu.h>
00020 #include "pci.h"
00021
00022 #ifdef DDE_LINUX
00023 #include "local.h"
00024 #endif
00025
00026
00027
00028
00029
00030 struct pci_dynid {
00031 struct list_head node;
00032 struct pci_device_id id;
00033 };
00034
00035 #ifdef CONFIG_HOTPLUG
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 static ssize_t
00047 store_new_id(struct device_driver *driver, const char *buf, size_t count)
00048 {
00049 struct pci_dynid *dynid;
00050 struct pci_driver *pdrv = to_pci_driver(driver);
00051 const struct pci_device_id *ids = pdrv->id_table;
00052 __u32 vendor, device, subvendor=PCI_ANY_ID,
00053 subdevice=PCI_ANY_ID, class=0, class_mask=0;
00054 unsigned long driver_data=0;
00055 int fields=0;
00056 int retval=0;
00057
00058 fields = sscanf(buf, "%x %x %x %x %x %x %lx",
00059 &vendor, &device, &subvendor, &subdevice,
00060 &class, &class_mask, &driver_data);
00061 if (fields < 2)
00062 return -EINVAL;
00063
00064
00065
00066 if (ids) {
00067 retval = -EINVAL;
00068 while (ids->vendor || ids->subvendor || ids->class_mask) {
00069 if (driver_data == ids->driver_data) {
00070 retval = 0;
00071 break;
00072 }
00073 ids++;
00074 }
00075 if (retval)
00076 return retval;
00077 }
00078
00079 dynid = kzalloc(sizeof(*dynid), GFP_KERNEL);
00080 if (!dynid)
00081 return -ENOMEM;
00082
00083 dynid->id.vendor = vendor;
00084 dynid->id.device = device;
00085 dynid->id.subvendor = subvendor;
00086 dynid->id.subdevice = subdevice;
00087 dynid->id.class = class;
00088 dynid->id.class_mask = class_mask;
00089 dynid->id.driver_data = driver_data;
00090
00091 spin_lock(&pdrv->dynids.lock);
00092 list_add_tail(&dynid->node, &pdrv->dynids.list);
00093 spin_unlock(&pdrv->dynids.lock);
00094
00095 if (get_driver(&pdrv->driver)) {
00096 retval = driver_attach(&pdrv->driver);
00097 put_driver(&pdrv->driver);
00098 }
00099
00100 if (retval)
00101 return retval;
00102 return count;
00103 }
00104 static DRIVER_ATTR(new_id, S_IWUSR, NULL, store_new_id);
00105
00106 static void
00107 pci_free_dynids(struct pci_driver *drv)
00108 {
00109 struct pci_dynid *dynid, *n;
00110
00111 spin_lock(&drv->dynids.lock);
00112 list_for_each_entry_safe(dynid, n, &drv->dynids.list, node) {
00113 list_del(&dynid->node);
00114 kfree(dynid);
00115 }
00116 spin_unlock(&drv->dynids.lock);
00117 }
00118
00119 static int
00120 pci_create_newid_file(struct pci_driver *drv)
00121 {
00122 int error = 0;
00123 if (drv->probe != NULL)
00124 error = driver_create_file(&drv->driver, &driver_attr_new_id);
00125 return error;
00126 }
00127
00128 static void pci_remove_newid_file(struct pci_driver *drv)
00129 {
00130 driver_remove_file(&drv->driver, &driver_attr_new_id);
00131 }
00132 #else
00133 static inline void pci_free_dynids(struct pci_driver *drv) {}
00134 static inline int pci_create_newid_file(struct pci_driver *drv)
00135 {
00136 return 0;
00137 }
00138 static inline void pci_remove_newid_file(struct pci_driver *drv) {}
00139 #endif
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153 const struct pci_device_id *pci_match_id(const struct pci_device_id *ids,
00154 struct pci_dev *dev)
00155 {
00156 if (ids) {
00157 while (ids->vendor || ids->subvendor || ids->class_mask) {
00158 if (pci_match_one_device(ids, dev))
00159 return ids;
00160 ids++;
00161 }
00162 }
00163 return NULL;
00164 }
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175 static const struct pci_device_id *pci_match_device(struct pci_driver *drv,
00176 struct pci_dev *dev)
00177 {
00178 struct pci_dynid *dynid;
00179
00180
00181 spin_lock(&drv->dynids.lock);
00182 list_for_each_entry(dynid, &drv->dynids.list, node) {
00183 if (pci_match_one_device(&dynid->id, dev)) {
00184 spin_unlock(&drv->dynids.lock);
00185 return &dynid->id;
00186 }
00187 }
00188 spin_unlock(&drv->dynids.lock);
00189
00190 return pci_match_id(drv->id_table, dev);
00191 }
00192
00193 struct drv_dev_and_id {
00194 struct pci_driver *drv;
00195 struct pci_dev *dev;
00196 const struct pci_device_id *id;
00197 };
00198
00199 static long local_pci_probe(void *_ddi)
00200 {
00201 struct drv_dev_and_id *ddi = _ddi;
00202
00203 return ddi->drv->probe(ddi->dev, ddi->id);
00204 }
00205
00206 static int pci_call_probe(struct pci_driver *drv, struct pci_dev *dev,
00207 const struct pci_device_id *id)
00208 {
00209 int error, node;
00210 struct drv_dev_and_id ddi = { drv, dev, id };
00211
00212
00213
00214
00215
00216 node = dev_to_node(&dev->dev);
00217 if (node >= 0) {
00218 int cpu;
00219 node_to_cpumask_ptr(nodecpumask, node);
00220
00221 get_online_cpus();
00222 cpu = cpumask_any_and(nodecpumask, cpu_online_mask);
00223 if (cpu < nr_cpu_ids)
00224 error = work_on_cpu(cpu, local_pci_probe, &ddi);
00225 else
00226 error = local_pci_probe(&ddi);
00227 put_online_cpus();
00228 } else
00229 error = local_pci_probe(&ddi);
00230 return error;
00231 }
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241 static int
00242 __pci_device_probe(struct pci_driver *drv, struct pci_dev *pci_dev)
00243 {
00244 const struct pci_device_id *id;
00245 int error = 0;
00246
00247 if (!pci_dev->driver && drv->probe) {
00248 error = -ENODEV;
00249
00250 id = pci_match_device(drv, pci_dev);
00251 if (id)
00252 error = pci_call_probe(drv, pci_dev, id);
00253 if (error >= 0) {
00254 pci_dev->driver = drv;
00255 error = 0;
00256 }
00257 }
00258 return error;
00259 }
00260
00261 static int pci_device_probe(struct device * dev)
00262 {
00263 int error = 0;
00264 struct pci_driver *drv;
00265 struct pci_dev *pci_dev;
00266
00267 drv = to_pci_driver(dev->driver);
00268 pci_dev = to_pci_dev(dev);
00269 pci_dev_get(pci_dev);
00270 error = __pci_device_probe(drv, pci_dev);
00271 if (error)
00272 pci_dev_put(pci_dev);
00273
00274 return error;
00275 }
00276
00277 static int pci_device_remove(struct device * dev)
00278 {
00279 struct pci_dev * pci_dev = to_pci_dev(dev);
00280 struct pci_driver * drv = pci_dev->driver;
00281
00282 if (drv) {
00283 if (drv->remove)
00284 drv->remove(pci_dev);
00285 pci_dev->driver = NULL;
00286 }
00287
00288
00289
00290
00291
00292 if (pci_dev->current_state == PCI_D0)
00293 pci_dev->current_state = PCI_UNKNOWN;
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304 pci_dev_put(pci_dev);
00305 return 0;
00306 }
00307
00308 static void pci_device_shutdown(struct device *dev)
00309 {
00310 struct pci_dev *pci_dev = to_pci_dev(dev);
00311 struct pci_driver *drv = pci_dev->driver;
00312
00313 if (drv && drv->shutdown)
00314 drv->shutdown(pci_dev);
00315 pci_msi_shutdown(pci_dev);
00316 pci_msix_shutdown(pci_dev);
00317 }
00318
00319 #ifdef CONFIG_PM_SLEEP
00320
00321
00322
00323
00324
00325 static void pci_pm_set_unknown_state(struct pci_dev *pci_dev)
00326 {
00327
00328
00329
00330
00331 if (pci_dev->current_state == PCI_D0)
00332 pci_dev->current_state = PCI_UNKNOWN;
00333 }
00334
00335
00336
00337
00338
00339 static int pci_pm_reenable_device(struct pci_dev *pci_dev)
00340 {
00341 int retval;
00342
00343
00344 retval = pci_reenable_device(pci_dev);
00345
00346
00347
00348
00349 if (pci_dev->is_busmaster)
00350 pci_set_master(pci_dev);
00351
00352 return retval;
00353 }
00354
00355 static int pci_legacy_suspend(struct device *dev, pm_message_t state)
00356 {
00357 #ifndef DDE_LINUX
00358 struct pci_dev * pci_dev = to_pci_dev(dev);
00359 struct pci_driver * drv = pci_dev->driver;
00360 int i = 0;
00361
00362 if (drv && drv->suspend) {
00363 pci_power_t prev = pci_dev->current_state;
00364
00365 pci_dev->state_saved = false;
00366
00367 i = drv->suspend(pci_dev, state);
00368 suspend_report_result(drv->suspend, i);
00369 if (i)
00370 return i;
00371
00372 if (pci_dev->state_saved)
00373 goto Fixup;
00374
00375 if (pci_dev->current_state != PCI_D0
00376 && pci_dev->current_state != PCI_UNKNOWN) {
00377 WARN_ONCE(pci_dev->current_state != prev,
00378 "PCI PM: Device state not saved by %pF\n",
00379 drv->suspend);
00380 goto Fixup;
00381 }
00382 }
00383
00384 pci_save_state(pci_dev);
00385
00386
00387
00388 pci_pm_set_unknown_state(pci_dev);
00389
00390 Fixup:
00391 pci_fixup_device(pci_fixup_suspend, pci_dev);
00392
00393 return i;
00394 #else
00395 WARN_UNIMPL;
00396 return 0;
00397 #endif
00398 }
00399
00400 static int pci_legacy_suspend_late(struct device *dev, pm_message_t state)
00401 {
00402 #ifndef DDE_LINUX
00403 struct pci_dev * pci_dev = to_pci_dev(dev);
00404 struct pci_driver * drv = pci_dev->driver;
00405 int i = 0;
00406
00407 if (drv && drv->suspend_late) {
00408 i = drv->suspend_late(pci_dev, state);
00409 suspend_report_result(drv->suspend_late, i);
00410 }
00411 return i;
00412 #else
00413 WARN_UNIMPL;
00414 return 0;
00415 #endif
00416 }
00417
00418 static int pci_legacy_resume_early(struct device *dev)
00419 {
00420 struct pci_dev * pci_dev = to_pci_dev(dev);
00421 struct pci_driver * drv = pci_dev->driver;
00422
00423 return drv && drv->resume_early ?
00424 drv->resume_early(pci_dev) : 0;
00425 }
00426
00427 static int pci_legacy_resume(struct device *dev)
00428 {
00429 struct pci_dev * pci_dev = to_pci_dev(dev);
00430 struct pci_driver * drv = pci_dev->driver;
00431
00432 pci_fixup_device(pci_fixup_resume, pci_dev);
00433
00434 return drv && drv->resume ?
00435 drv->resume(pci_dev) : pci_pm_reenable_device(pci_dev);
00436 }
00437
00438
00439
00440 static void pci_pm_default_resume_noirq(struct pci_dev *pci_dev)
00441 {
00442 pci_restore_standard_config(pci_dev);
00443 pci_dev->state_saved = false;
00444 pci_fixup_device(pci_fixup_resume_early, pci_dev);
00445 }
00446
00447 static void pci_pm_default_resume(struct pci_dev *pci_dev)
00448 {
00449 pci_fixup_device(pci_fixup_resume, pci_dev);
00450
00451 if (!pci_is_bridge(pci_dev))
00452 pci_enable_wake(pci_dev, PCI_D0, false);
00453 }
00454
00455 static void pci_pm_default_suspend(struct pci_dev *pci_dev)
00456 {
00457
00458 if (!pci_is_bridge(pci_dev))
00459 pci_disable_enabled_device(pci_dev);
00460 pci_save_state(pci_dev);
00461 }
00462
00463 static bool pci_has_legacy_pm_support(struct pci_dev *pci_dev)
00464 {
00465 struct pci_driver *drv = pci_dev->driver;
00466 bool ret = drv && (drv->suspend || drv->suspend_late || drv->resume
00467 || drv->resume_early);
00468
00469
00470
00471
00472
00473
00474 WARN_ON(ret && drv->driver.pm);
00475
00476 return ret;
00477 }
00478
00479
00480
00481 static int pci_pm_prepare(struct device *dev)
00482 {
00483 struct device_driver *drv = dev->driver;
00484 int error = 0;
00485
00486 if (drv && drv->pm && drv->pm->prepare)
00487 error = drv->pm->prepare(dev);
00488
00489 return error;
00490 }
00491
00492 static void pci_pm_complete(struct device *dev)
00493 {
00494 struct device_driver *drv = dev->driver;
00495
00496 if (drv && drv->pm && drv->pm->complete)
00497 drv->pm->complete(dev);
00498 }
00499
00500 #ifdef CONFIG_SUSPEND
00501
00502 static int pci_pm_suspend(struct device *dev)
00503 {
00504 struct pci_dev *pci_dev = to_pci_dev(dev);
00505 struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
00506
00507 if (pci_has_legacy_pm_support(pci_dev))
00508 return pci_legacy_suspend(dev, PMSG_SUSPEND);
00509
00510 if (!pm) {
00511 pci_pm_default_suspend(pci_dev);
00512 goto Fixup;
00513 }
00514
00515 pci_dev->state_saved = false;
00516
00517 if (pm->suspend) {
00518 pci_power_t prev = pci_dev->current_state;
00519 int error;
00520
00521 error = pm->suspend(dev);
00522 suspend_report_result(pm->suspend, error);
00523 if (error)
00524 return error;
00525
00526 if (pci_dev->state_saved)
00527 goto Fixup;
00528
00529 if (pci_dev->current_state != PCI_D0
00530 && pci_dev->current_state != PCI_UNKNOWN) {
00531 WARN_ONCE(pci_dev->current_state != prev,
00532 "PCI PM: State of device not saved by %pF\n",
00533 pm->suspend);
00534 goto Fixup;
00535 }
00536 }
00537
00538 if (!pci_dev->state_saved) {
00539 pci_save_state(pci_dev);
00540 if (!pci_is_bridge(pci_dev))
00541 pci_prepare_to_sleep(pci_dev);
00542 }
00543
00544 Fixup:
00545 pci_fixup_device(pci_fixup_suspend, pci_dev);
00546
00547 return 0;
00548 }
00549
00550 static int pci_pm_suspend_noirq(struct device *dev)
00551 {
00552 struct pci_dev *pci_dev = to_pci_dev(dev);
00553 struct device_driver *drv = dev->driver;
00554 int error = 0;
00555
00556 if (pci_has_legacy_pm_support(pci_dev))
00557 return pci_legacy_suspend_late(dev, PMSG_SUSPEND);
00558
00559 if (drv && drv->pm && drv->pm->suspend_noirq) {
00560 error = drv->pm->suspend_noirq(dev);
00561 suspend_report_result(drv->pm->suspend_noirq, error);
00562 }
00563
00564 if (!error)
00565 pci_pm_set_unknown_state(pci_dev);
00566
00567 return error;
00568 }
00569
00570 static int pci_pm_resume_noirq(struct device *dev)
00571 {
00572 struct pci_dev *pci_dev = to_pci_dev(dev);
00573 struct device_driver *drv = dev->driver;
00574 int error = 0;
00575
00576 pci_pm_default_resume_noirq(pci_dev);
00577
00578 if (pci_has_legacy_pm_support(pci_dev))
00579 return pci_legacy_resume_early(dev);
00580
00581 if (drv && drv->pm && drv->pm->resume_noirq)
00582 error = drv->pm->resume_noirq(dev);
00583
00584 return error;
00585 }
00586
00587 static int pci_pm_resume(struct device *dev)
00588 {
00589 struct pci_dev *pci_dev = to_pci_dev(dev);
00590 struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
00591 int error = 0;
00592
00593
00594
00595
00596
00597 if (pci_dev->state_saved)
00598 pci_restore_standard_config(pci_dev);
00599
00600 if (pci_has_legacy_pm_support(pci_dev))
00601 return pci_legacy_resume(dev);
00602
00603 pci_pm_default_resume(pci_dev);
00604
00605 if (pm) {
00606 if (pm->resume)
00607 error = pm->resume(dev);
00608 } else {
00609 pci_pm_reenable_device(pci_dev);
00610 }
00611
00612 return 0;
00613 }
00614
00615 #else
00616
00617 #define pci_pm_suspend NULL
00618 #define pci_pm_suspend_noirq NULL
00619 #define pci_pm_resume NULL
00620 #define pci_pm_resume_noirq NULL
00621
00622 #endif
00623
00624 #ifdef CONFIG_HIBERNATION
00625
00626 static int pci_pm_freeze(struct device *dev)
00627 {
00628 struct pci_dev *pci_dev = to_pci_dev(dev);
00629 struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
00630
00631 if (pci_has_legacy_pm_support(pci_dev))
00632 return pci_legacy_suspend(dev, PMSG_FREEZE);
00633
00634 if (!pm) {
00635 pci_pm_default_suspend(pci_dev);
00636 return 0;
00637 }
00638
00639 pci_dev->state_saved = false;
00640
00641 if (pm->freeze) {
00642 int error;
00643
00644 error = pm->freeze(dev);
00645 suspend_report_result(pm->freeze, error);
00646 if (error)
00647 return error;
00648 }
00649
00650 if (!pci_dev->state_saved)
00651 pci_save_state(pci_dev);
00652
00653 return 0;
00654 }
00655
00656 static int pci_pm_freeze_noirq(struct device *dev)
00657 {
00658 struct pci_dev *pci_dev = to_pci_dev(dev);
00659 struct device_driver *drv = dev->driver;
00660 int error = 0;
00661
00662 if (pci_has_legacy_pm_support(pci_dev))
00663 return pci_legacy_suspend_late(dev, PMSG_FREEZE);
00664
00665 if (drv && drv->pm && drv->pm->freeze_noirq) {
00666 error = drv->pm->freeze_noirq(dev);
00667 suspend_report_result(drv->pm->freeze_noirq, error);
00668 }
00669
00670 if (!error)
00671 pci_pm_set_unknown_state(pci_dev);
00672
00673 return error;
00674 }
00675
00676 static int pci_pm_thaw_noirq(struct device *dev)
00677 {
00678 struct pci_dev *pci_dev = to_pci_dev(dev);
00679 struct device_driver *drv = dev->driver;
00680 int error = 0;
00681
00682 if (pci_has_legacy_pm_support(pci_dev))
00683 return pci_legacy_resume_early(dev);
00684
00685 pci_update_current_state(pci_dev, PCI_D0);
00686
00687 if (drv && drv->pm && drv->pm->thaw_noirq)
00688 error = drv->pm->thaw_noirq(dev);
00689
00690 return error;
00691 }
00692
00693 static int pci_pm_thaw(struct device *dev)
00694 {
00695 struct pci_dev *pci_dev = to_pci_dev(dev);
00696 struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
00697 int error = 0;
00698
00699 if (pci_has_legacy_pm_support(pci_dev))
00700 return pci_legacy_resume(dev);
00701
00702 if (pm) {
00703 if (pm->thaw)
00704 error = pm->thaw(dev);
00705 } else {
00706 pci_pm_reenable_device(pci_dev);
00707 }
00708
00709 return error;
00710 }
00711
00712 static int pci_pm_poweroff(struct device *dev)
00713 {
00714 struct pci_dev *pci_dev = to_pci_dev(dev);
00715 struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
00716 int error = 0;
00717
00718 if (pci_has_legacy_pm_support(pci_dev))
00719 return pci_legacy_suspend(dev, PMSG_HIBERNATE);
00720
00721 if (!pm) {
00722 pci_pm_default_suspend(pci_dev);
00723 goto Fixup;
00724 }
00725
00726 pci_dev->state_saved = false;
00727
00728 if (pm->poweroff) {
00729 error = pm->poweroff(dev);
00730 suspend_report_result(pm->poweroff, error);
00731 }
00732
00733 if (!pci_dev->state_saved && !pci_is_bridge(pci_dev))
00734 pci_prepare_to_sleep(pci_dev);
00735
00736 Fixup:
00737 pci_fixup_device(pci_fixup_suspend, pci_dev);
00738
00739 return error;
00740 }
00741
00742 static int pci_pm_poweroff_noirq(struct device *dev)
00743 {
00744 struct device_driver *drv = dev->driver;
00745 int error = 0;
00746
00747 if (pci_has_legacy_pm_support(to_pci_dev(dev)))
00748 return pci_legacy_suspend_late(dev, PMSG_HIBERNATE);
00749
00750 if (drv && drv->pm && drv->pm->poweroff_noirq) {
00751 error = drv->pm->poweroff_noirq(dev);
00752 suspend_report_result(drv->pm->poweroff_noirq, error);
00753 }
00754
00755 return error;
00756 }
00757
00758 static int pci_pm_restore_noirq(struct device *dev)
00759 {
00760 struct pci_dev *pci_dev = to_pci_dev(dev);
00761 struct device_driver *drv = dev->driver;
00762 int error = 0;
00763
00764 pci_pm_default_resume_noirq(pci_dev);
00765
00766 if (pci_has_legacy_pm_support(pci_dev))
00767 return pci_legacy_resume_early(dev);
00768
00769 if (drv && drv->pm && drv->pm->restore_noirq)
00770 error = drv->pm->restore_noirq(dev);
00771
00772 return error;
00773 }
00774
00775 static int pci_pm_restore(struct device *dev)
00776 {
00777 struct pci_dev *pci_dev = to_pci_dev(dev);
00778 struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
00779 int error = 0;
00780
00781
00782
00783
00784
00785 if (pci_dev->state_saved)
00786 pci_restore_standard_config(pci_dev);
00787
00788 if (pci_has_legacy_pm_support(pci_dev))
00789 return pci_legacy_resume(dev);
00790
00791 pci_pm_default_resume(pci_dev);
00792
00793 if (pm) {
00794 if (pm->restore)
00795 error = pm->restore(dev);
00796 } else {
00797 pci_pm_reenable_device(pci_dev);
00798 }
00799
00800 return error;
00801 }
00802
00803 #else
00804
00805 #define pci_pm_freeze NULL
00806 #define pci_pm_freeze_noirq NULL
00807 #define pci_pm_thaw NULL
00808 #define pci_pm_thaw_noirq NULL
00809 #define pci_pm_poweroff NULL
00810 #define pci_pm_poweroff_noirq NULL
00811 #define pci_pm_restore NULL
00812 #define pci_pm_restore_noirq NULL
00813
00814 #endif
00815
00816 struct dev_pm_ops pci_dev_pm_ops = {
00817 .prepare = pci_pm_prepare,
00818 .complete = pci_pm_complete,
00819 .suspend = pci_pm_suspend,
00820 .resume = pci_pm_resume,
00821 .freeze = pci_pm_freeze,
00822 .thaw = pci_pm_thaw,
00823 .poweroff = pci_pm_poweroff,
00824 .restore = pci_pm_restore,
00825 .suspend_noirq = pci_pm_suspend_noirq,
00826 .resume_noirq = pci_pm_resume_noirq,
00827 .freeze_noirq = pci_pm_freeze_noirq,
00828 .thaw_noirq = pci_pm_thaw_noirq,
00829 .poweroff_noirq = pci_pm_poweroff_noirq,
00830 .restore_noirq = pci_pm_restore_noirq,
00831 };
00832
00833 #define PCI_PM_OPS_PTR (&pci_dev_pm_ops)
00834
00835 #else
00836
00837 #define PCI_PM_OPS_PTR NULL
00838
00839 #endif
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852 int __pci_register_driver(struct pci_driver *drv, struct module *owner,
00853 const char *mod_name)
00854 {
00855 int error;
00856
00857
00858 drv->driver.name = drv->name;
00859 drv->driver.bus = &pci_bus_type;
00860 drv->driver.owner = owner;
00861 drv->driver.mod_name = mod_name;
00862
00863 spin_lock_init(&drv->dynids.lock);
00864 INIT_LIST_HEAD(&drv->dynids.list);
00865
00866
00867 error = driver_register(&drv->driver);
00868 if (error)
00869 return error;
00870
00871 error = pci_create_newid_file(drv);
00872 if (error)
00873 driver_unregister(&drv->driver);
00874
00875 return error;
00876 }
00877
00878
00879
00880
00881
00882
00883
00884
00885
00886
00887
00888 void
00889 pci_unregister_driver(struct pci_driver *drv)
00890 {
00891 pci_remove_newid_file(drv);
00892 driver_unregister(&drv->driver);
00893 pci_free_dynids(drv);
00894 }
00895
00896 static struct pci_driver pci_compat_driver = {
00897 .name = "compat"
00898 };
00899
00900
00901
00902
00903
00904
00905
00906
00907 struct pci_driver *
00908 pci_dev_driver(const struct pci_dev *dev)
00909 {
00910 if (dev->driver)
00911 return dev->driver;
00912 else {
00913 int i;
00914 for(i=0; i<=PCI_ROM_RESOURCE; i++)
00915 if (dev->resource[i].flags & IORESOURCE_BUSY)
00916 return &pci_compat_driver;
00917 }
00918 return NULL;
00919 }
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930 static int pci_bus_match(struct device *dev, struct device_driver *drv)
00931 {
00932 struct pci_dev *pci_dev = to_pci_dev(dev);
00933 struct pci_driver *pci_drv = to_pci_driver(drv);
00934 const struct pci_device_id *found_id;
00935
00936 found_id = pci_match_device(pci_drv, pci_dev);
00937 if (found_id)
00938 return 1;
00939
00940 return 0;
00941 }
00942
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952
00953
00954
00955 struct pci_dev *pci_dev_get(struct pci_dev *dev)
00956 {
00957 if (dev)
00958 get_device(&dev->dev);
00959 return dev;
00960 }
00961
00962
00963
00964
00965
00966
00967
00968
00969 void pci_dev_put(struct pci_dev *dev)
00970 {
00971 if (dev)
00972 put_device(&dev->dev);
00973 }
00974
00975 #ifndef CONFIG_HOTPLUG
00976 int pci_uevent(struct device *dev, struct kobj_uevent_env *env)
00977 {
00978 return -ENODEV;
00979 }
00980 #endif
00981
00982 struct bus_type pci_bus_type = {
00983 .name = "pci",
00984 .match = pci_bus_match,
00985 .uevent = pci_uevent,
00986 .probe = pci_device_probe,
00987 .remove = pci_device_remove,
00988 .shutdown = pci_device_shutdown,
00989 #ifndef DDE_LINUX
00990 .dev_attrs = pci_dev_attrs,
00991 #endif
00992 .pm = PCI_PM_OPS_PTR,
00993 };
00994
00995 static int __init pci_driver_init(void)
00996 {
00997 return bus_register(&pci_bus_type);
00998 }
00999
01000 postcore_initcall(pci_driver_init);
01001
01002 EXPORT_SYMBOL(pci_match_id);
01003 EXPORT_SYMBOL(__pci_register_driver);
01004 EXPORT_SYMBOL(pci_unregister_driver);
01005 EXPORT_SYMBOL(pci_dev_driver);
01006 EXPORT_SYMBOL(pci_bus_type);
01007 EXPORT_SYMBOL(pci_dev_get);
01008 EXPORT_SYMBOL(pci_dev_put);