diff options
Diffstat (limited to 'drivers/pci/pci-driver.c')
-rw-r--r-- | drivers/pci/pci-driver.c | 448 |
1 files changed, 280 insertions, 168 deletions
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index b4cdd690ae71..c697f2680856 100644 --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c | |||
@@ -16,6 +16,7 @@ | |||
16 | #include <linux/string.h> | 16 | #include <linux/string.h> |
17 | #include <linux/slab.h> | 17 | #include <linux/slab.h> |
18 | #include <linux/sched.h> | 18 | #include <linux/sched.h> |
19 | #include <linux/cpu.h> | ||
19 | #include "pci.h" | 20 | #include "pci.h" |
20 | 21 | ||
21 | /* | 22 | /* |
@@ -48,7 +49,7 @@ store_new_id(struct device_driver *driver, const char *buf, size_t count) | |||
48 | subdevice=PCI_ANY_ID, class=0, class_mask=0; | 49 | subdevice=PCI_ANY_ID, class=0, class_mask=0; |
49 | unsigned long driver_data=0; | 50 | unsigned long driver_data=0; |
50 | int fields=0; | 51 | int fields=0; |
51 | int retval; | 52 | int retval=0; |
52 | 53 | ||
53 | fields = sscanf(buf, "%x %x %x %x %x %x %lx", | 54 | fields = sscanf(buf, "%x %x %x %x %x %x %lx", |
54 | &vendor, &device, &subvendor, &subdevice, | 55 | &vendor, &device, &subvendor, &subdevice, |
@@ -58,16 +59,18 @@ store_new_id(struct device_driver *driver, const char *buf, size_t count) | |||
58 | 59 | ||
59 | /* Only accept driver_data values that match an existing id_table | 60 | /* Only accept driver_data values that match an existing id_table |
60 | entry */ | 61 | entry */ |
61 | retval = -EINVAL; | 62 | if (ids) { |
62 | while (ids->vendor || ids->subvendor || ids->class_mask) { | 63 | retval = -EINVAL; |
63 | if (driver_data == ids->driver_data) { | 64 | while (ids->vendor || ids->subvendor || ids->class_mask) { |
64 | retval = 0; | 65 | if (driver_data == ids->driver_data) { |
65 | break; | 66 | retval = 0; |
67 | break; | ||
68 | } | ||
69 | ids++; | ||
66 | } | 70 | } |
67 | ids++; | 71 | if (retval) /* No match */ |
72 | return retval; | ||
68 | } | 73 | } |
69 | if (retval) /* No match */ | ||
70 | return retval; | ||
71 | 74 | ||
72 | dynid = kzalloc(sizeof(*dynid), GFP_KERNEL); | 75 | dynid = kzalloc(sizeof(*dynid), GFP_KERNEL); |
73 | if (!dynid) | 76 | if (!dynid) |
@@ -183,32 +186,43 @@ static const struct pci_device_id *pci_match_device(struct pci_driver *drv, | |||
183 | return pci_match_id(drv->id_table, dev); | 186 | return pci_match_id(drv->id_table, dev); |
184 | } | 187 | } |
185 | 188 | ||
189 | struct drv_dev_and_id { | ||
190 | struct pci_driver *drv; | ||
191 | struct pci_dev *dev; | ||
192 | const struct pci_device_id *id; | ||
193 | }; | ||
194 | |||
195 | static long local_pci_probe(void *_ddi) | ||
196 | { | ||
197 | struct drv_dev_and_id *ddi = _ddi; | ||
198 | |||
199 | return ddi->drv->probe(ddi->dev, ddi->id); | ||
200 | } | ||
201 | |||
186 | static int pci_call_probe(struct pci_driver *drv, struct pci_dev *dev, | 202 | static int pci_call_probe(struct pci_driver *drv, struct pci_dev *dev, |
187 | const struct pci_device_id *id) | 203 | const struct pci_device_id *id) |
188 | { | 204 | { |
189 | int error; | 205 | int error, node; |
190 | #ifdef CONFIG_NUMA | 206 | struct drv_dev_and_id ddi = { drv, dev, id }; |
191 | /* Execute driver initialization on node where the | ||
192 | device's bus is attached to. This way the driver likely | ||
193 | allocates its local memory on the right node without | ||
194 | any need to change it. */ | ||
195 | struct mempolicy *oldpol; | ||
196 | cpumask_t oldmask = current->cpus_allowed; | ||
197 | int node = dev_to_node(&dev->dev); | ||
198 | 207 | ||
208 | /* Execute driver initialization on node where the device's | ||
209 | bus is attached to. This way the driver likely allocates | ||
210 | its local memory on the right node without any need to | ||
211 | change it. */ | ||
212 | node = dev_to_node(&dev->dev); | ||
199 | if (node >= 0) { | 213 | if (node >= 0) { |
214 | int cpu; | ||
200 | node_to_cpumask_ptr(nodecpumask, node); | 215 | node_to_cpumask_ptr(nodecpumask, node); |
201 | set_cpus_allowed_ptr(current, nodecpumask); | 216 | |
202 | } | 217 | get_online_cpus(); |
203 | /* And set default memory allocation policy */ | 218 | cpu = cpumask_any_and(nodecpumask, cpu_online_mask); |
204 | oldpol = current->mempolicy; | 219 | if (cpu < nr_cpu_ids) |
205 | current->mempolicy = NULL; /* fall back to system default policy */ | 220 | error = work_on_cpu(cpu, local_pci_probe, &ddi); |
206 | #endif | 221 | else |
207 | error = drv->probe(dev, id); | 222 | error = local_pci_probe(&ddi); |
208 | #ifdef CONFIG_NUMA | 223 | put_online_cpus(); |
209 | set_cpus_allowed_ptr(current, &oldmask); | 224 | } else |
210 | current->mempolicy = oldpol; | 225 | error = local_pci_probe(&ddi); |
211 | #endif | ||
212 | return error; | 226 | return error; |
213 | } | 227 | } |
214 | 228 | ||
@@ -302,11 +316,10 @@ static void pci_device_shutdown(struct device *dev) | |||
302 | 316 | ||
303 | /* | 317 | /* |
304 | * Default "suspend" method for devices that have no driver provided suspend, | 318 | * Default "suspend" method for devices that have no driver provided suspend, |
305 | * or not even a driver at all. | 319 | * or not even a driver at all (second part). |
306 | */ | 320 | */ |
307 | static void pci_default_pm_suspend(struct pci_dev *pci_dev) | 321 | static void pci_pm_set_unknown_state(struct pci_dev *pci_dev) |
308 | { | 322 | { |
309 | pci_save_state(pci_dev); | ||
310 | /* | 323 | /* |
311 | * mark its power state as "unknown", since we don't know if | 324 | * mark its power state as "unknown", since we don't know if |
312 | * e.g. the BIOS will change its device state when we suspend. | 325 | * e.g. the BIOS will change its device state when we suspend. |
@@ -317,14 +330,12 @@ static void pci_default_pm_suspend(struct pci_dev *pci_dev) | |||
317 | 330 | ||
318 | /* | 331 | /* |
319 | * Default "resume" method for devices that have no driver provided resume, | 332 | * Default "resume" method for devices that have no driver provided resume, |
320 | * or not even a driver at all. | 333 | * or not even a driver at all (second part). |
321 | */ | 334 | */ |
322 | static int pci_default_pm_resume(struct pci_dev *pci_dev) | 335 | static int pci_pm_reenable_device(struct pci_dev *pci_dev) |
323 | { | 336 | { |
324 | int retval = 0; | 337 | int retval; |
325 | 338 | ||
326 | /* restore the PCI config space */ | ||
327 | pci_restore_state(pci_dev); | ||
328 | /* if the device was enabled before suspend, reenable */ | 339 | /* if the device was enabled before suspend, reenable */ |
329 | retval = pci_reenable_device(pci_dev); | 340 | retval = pci_reenable_device(pci_dev); |
330 | /* | 341 | /* |
@@ -347,8 +358,16 @@ static int pci_legacy_suspend(struct device *dev, pm_message_t state) | |||
347 | i = drv->suspend(pci_dev, state); | 358 | i = drv->suspend(pci_dev, state); |
348 | suspend_report_result(drv->suspend, i); | 359 | suspend_report_result(drv->suspend, i); |
349 | } else { | 360 | } else { |
350 | pci_default_pm_suspend(pci_dev); | 361 | pci_save_state(pci_dev); |
362 | /* | ||
363 | * This is for compatibility with existing code with legacy PM | ||
364 | * support. | ||
365 | */ | ||
366 | pci_pm_set_unknown_state(pci_dev); | ||
351 | } | 367 | } |
368 | |||
369 | pci_fixup_device(pci_fixup_suspend, pci_dev); | ||
370 | |||
352 | return i; | 371 | return i; |
353 | } | 372 | } |
354 | 373 | ||
@@ -365,30 +384,130 @@ static int pci_legacy_suspend_late(struct device *dev, pm_message_t state) | |||
365 | return i; | 384 | return i; |
366 | } | 385 | } |
367 | 386 | ||
387 | static int pci_legacy_resume_early(struct device *dev) | ||
388 | { | ||
389 | int error = 0; | ||
390 | struct pci_dev * pci_dev = to_pci_dev(dev); | ||
391 | struct pci_driver * drv = pci_dev->driver; | ||
392 | |||
393 | pci_fixup_device(pci_fixup_resume_early, pci_dev); | ||
394 | |||
395 | if (drv && drv->resume_early) | ||
396 | error = drv->resume_early(pci_dev); | ||
397 | return error; | ||
398 | } | ||
399 | |||
368 | static int pci_legacy_resume(struct device *dev) | 400 | static int pci_legacy_resume(struct device *dev) |
369 | { | 401 | { |
370 | int error; | 402 | int error; |
371 | struct pci_dev * pci_dev = to_pci_dev(dev); | 403 | struct pci_dev * pci_dev = to_pci_dev(dev); |
372 | struct pci_driver * drv = pci_dev->driver; | 404 | struct pci_driver * drv = pci_dev->driver; |
373 | 405 | ||
374 | if (drv && drv->resume) | 406 | pci_fixup_device(pci_fixup_resume, pci_dev); |
407 | |||
408 | if (drv && drv->resume) { | ||
375 | error = drv->resume(pci_dev); | 409 | error = drv->resume(pci_dev); |
376 | else | 410 | } else { |
377 | error = pci_default_pm_resume(pci_dev); | 411 | /* restore the PCI config space */ |
412 | pci_restore_state(pci_dev); | ||
413 | error = pci_pm_reenable_device(pci_dev); | ||
414 | } | ||
378 | return error; | 415 | return error; |
379 | } | 416 | } |
380 | 417 | ||
381 | static int pci_legacy_resume_early(struct device *dev) | 418 | /* Auxiliary functions used by the new power management framework */ |
419 | |||
420 | static int pci_restore_standard_config(struct pci_dev *pci_dev) | ||
382 | { | 421 | { |
422 | struct pci_dev *parent = pci_dev->bus->self; | ||
383 | int error = 0; | 423 | int error = 0; |
384 | struct pci_dev * pci_dev = to_pci_dev(dev); | ||
385 | struct pci_driver * drv = pci_dev->driver; | ||
386 | 424 | ||
387 | if (drv && drv->resume_early) | 425 | /* Check if the device's bus is operational */ |
388 | error = drv->resume_early(pci_dev); | 426 | if (!parent || parent->current_state == PCI_D0) { |
427 | pci_restore_state(pci_dev); | ||
428 | pci_update_current_state(pci_dev, PCI_D0); | ||
429 | } else { | ||
430 | dev_warn(&pci_dev->dev, "unable to restore config, " | ||
431 | "bridge %s in low power state D%d\n", pci_name(parent), | ||
432 | parent->current_state); | ||
433 | pci_dev->current_state = PCI_UNKNOWN; | ||
434 | error = -EAGAIN; | ||
435 | } | ||
436 | |||
389 | return error; | 437 | return error; |
390 | } | 438 | } |
391 | 439 | ||
440 | static bool pci_is_bridge(struct pci_dev *pci_dev) | ||
441 | { | ||
442 | return !!(pci_dev->subordinate); | ||
443 | } | ||
444 | |||
445 | static void pci_pm_default_resume_noirq(struct pci_dev *pci_dev) | ||
446 | { | ||
447 | if (pci_restore_standard_config(pci_dev)) | ||
448 | pci_fixup_device(pci_fixup_resume_early, pci_dev); | ||
449 | } | ||
450 | |||
451 | static int pci_pm_default_resume(struct pci_dev *pci_dev) | ||
452 | { | ||
453 | /* | ||
454 | * pci_restore_standard_config() should have been called once already, | ||
455 | * but it would have failed if the device's parent bridge had not been | ||
456 | * in power state D0 at that time. Check it and try again if necessary. | ||
457 | */ | ||
458 | if (pci_dev->current_state == PCI_UNKNOWN) { | ||
459 | int error = pci_restore_standard_config(pci_dev); | ||
460 | if (error) | ||
461 | return error; | ||
462 | } | ||
463 | |||
464 | pci_fixup_device(pci_fixup_resume, pci_dev); | ||
465 | |||
466 | if (!pci_is_bridge(pci_dev)) | ||
467 | pci_enable_wake(pci_dev, PCI_D0, false); | ||
468 | |||
469 | return pci_pm_reenable_device(pci_dev); | ||
470 | } | ||
471 | |||
472 | static void pci_pm_default_suspend_generic(struct pci_dev *pci_dev) | ||
473 | { | ||
474 | /* If device is enabled at this point, disable it */ | ||
475 | pci_disable_enabled_device(pci_dev); | ||
476 | /* | ||
477 | * Save state with interrupts enabled, because in principle the bus the | ||
478 | * device is on may be put into a low power state after this code runs. | ||
479 | */ | ||
480 | pci_save_state(pci_dev); | ||
481 | } | ||
482 | |||
483 | static void pci_pm_default_suspend(struct pci_dev *pci_dev) | ||
484 | { | ||
485 | pci_pm_default_suspend_generic(pci_dev); | ||
486 | |||
487 | if (!pci_is_bridge(pci_dev)) | ||
488 | pci_prepare_to_sleep(pci_dev); | ||
489 | |||
490 | pci_fixup_device(pci_fixup_suspend, pci_dev); | ||
491 | } | ||
492 | |||
493 | static bool pci_has_legacy_pm_support(struct pci_dev *pci_dev) | ||
494 | { | ||
495 | struct pci_driver *drv = pci_dev->driver; | ||
496 | bool ret = drv && (drv->suspend || drv->suspend_late || drv->resume | ||
497 | || drv->resume_early); | ||
498 | |||
499 | /* | ||
500 | * Legacy PM support is used by default, so warn if the new framework is | ||
501 | * supported as well. Drivers are supposed to support either the | ||
502 | * former, or the latter, but not both at the same time. | ||
503 | */ | ||
504 | WARN_ON(ret && drv->driver.pm); | ||
505 | |||
506 | return ret; | ||
507 | } | ||
508 | |||
509 | /* New power management framework */ | ||
510 | |||
392 | static int pci_pm_prepare(struct device *dev) | 511 | static int pci_pm_prepare(struct device *dev) |
393 | { | 512 | { |
394 | struct device_driver *drv = dev->driver; | 513 | struct device_driver *drv = dev->driver; |
@@ -416,17 +535,16 @@ static int pci_pm_suspend(struct device *dev) | |||
416 | struct device_driver *drv = dev->driver; | 535 | struct device_driver *drv = dev->driver; |
417 | int error = 0; | 536 | int error = 0; |
418 | 537 | ||
419 | if (drv && drv->pm) { | 538 | if (pci_has_legacy_pm_support(pci_dev)) |
420 | if (drv->pm->suspend) { | 539 | return pci_legacy_suspend(dev, PMSG_SUSPEND); |
421 | error = drv->pm->suspend(dev); | 540 | |
422 | suspend_report_result(drv->pm->suspend, error); | 541 | if (drv && drv->pm && drv->pm->suspend) { |
423 | } else { | 542 | error = drv->pm->suspend(dev); |
424 | pci_default_pm_suspend(pci_dev); | 543 | suspend_report_result(drv->pm->suspend, error); |
425 | } | ||
426 | } else { | ||
427 | error = pci_legacy_suspend(dev, PMSG_SUSPEND); | ||
428 | } | 544 | } |
429 | pci_fixup_device(pci_fixup_suspend, pci_dev); | 545 | |
546 | if (!error) | ||
547 | pci_pm_default_suspend(pci_dev); | ||
430 | 548 | ||
431 | return error; | 549 | return error; |
432 | } | 550 | } |
@@ -434,53 +552,53 @@ static int pci_pm_suspend(struct device *dev) | |||
434 | static int pci_pm_suspend_noirq(struct device *dev) | 552 | static int pci_pm_suspend_noirq(struct device *dev) |
435 | { | 553 | { |
436 | struct pci_dev *pci_dev = to_pci_dev(dev); | 554 | struct pci_dev *pci_dev = to_pci_dev(dev); |
437 | struct pci_driver *drv = pci_dev->driver; | 555 | struct device_driver *drv = dev->driver; |
438 | int error = 0; | 556 | int error = 0; |
439 | 557 | ||
440 | if (drv && drv->pm) { | 558 | if (pci_has_legacy_pm_support(pci_dev)) |
441 | if (drv->pm->suspend_noirq) { | 559 | return pci_legacy_suspend_late(dev, PMSG_SUSPEND); |
442 | error = drv->pm->suspend_noirq(dev); | 560 | |
443 | suspend_report_result(drv->pm->suspend_noirq, error); | 561 | if (drv && drv->pm && drv->pm->suspend_noirq) { |
444 | } | 562 | error = drv->pm->suspend_noirq(dev); |
445 | } else { | 563 | suspend_report_result(drv->pm->suspend_noirq, error); |
446 | error = pci_legacy_suspend_late(dev, PMSG_SUSPEND); | ||
447 | } | 564 | } |
448 | 565 | ||
566 | if (!error) | ||
567 | pci_pm_set_unknown_state(pci_dev); | ||
568 | |||
449 | return error; | 569 | return error; |
450 | } | 570 | } |
451 | 571 | ||
452 | static int pci_pm_resume(struct device *dev) | 572 | static int pci_pm_resume_noirq(struct device *dev) |
453 | { | 573 | { |
454 | struct pci_dev *pci_dev = to_pci_dev(dev); | 574 | struct pci_dev *pci_dev = to_pci_dev(dev); |
455 | struct device_driver *drv = dev->driver; | 575 | struct device_driver *drv = dev->driver; |
456 | int error; | 576 | int error = 0; |
457 | 577 | ||
458 | pci_fixup_device(pci_fixup_resume, pci_dev); | 578 | if (pci_has_legacy_pm_support(pci_dev)) |
579 | return pci_legacy_resume_early(dev); | ||
459 | 580 | ||
460 | if (drv && drv->pm) { | 581 | pci_pm_default_resume_noirq(pci_dev); |
461 | error = drv->pm->resume ? drv->pm->resume(dev) : | 582 | |
462 | pci_default_pm_resume(pci_dev); | 583 | if (drv && drv->pm && drv->pm->resume_noirq) |
463 | } else { | 584 | error = drv->pm->resume_noirq(dev); |
464 | error = pci_legacy_resume(dev); | ||
465 | } | ||
466 | 585 | ||
467 | return error; | 586 | return error; |
468 | } | 587 | } |
469 | 588 | ||
470 | static int pci_pm_resume_noirq(struct device *dev) | 589 | static int pci_pm_resume(struct device *dev) |
471 | { | 590 | { |
472 | struct pci_dev *pci_dev = to_pci_dev(dev); | 591 | struct pci_dev *pci_dev = to_pci_dev(dev); |
473 | struct pci_driver *drv = pci_dev->driver; | 592 | struct device_driver *drv = dev->driver; |
474 | int error = 0; | 593 | int error = 0; |
475 | 594 | ||
476 | pci_fixup_device(pci_fixup_resume_early, pci_dev); | 595 | if (pci_has_legacy_pm_support(pci_dev)) |
596 | return pci_legacy_resume(dev); | ||
477 | 597 | ||
478 | if (drv && drv->pm) { | 598 | error = pci_pm_default_resume(pci_dev); |
479 | if (drv->pm->resume_noirq) | 599 | |
480 | error = drv->pm->resume_noirq(dev); | 600 | if (!error && drv && drv->pm && drv->pm->resume) |
481 | } else { | 601 | error = drv->pm->resume(dev); |
482 | error = pci_legacy_resume_early(dev); | ||
483 | } | ||
484 | 602 | ||
485 | return error; | 603 | return error; |
486 | } | 604 | } |
@@ -502,141 +620,140 @@ static int pci_pm_freeze(struct device *dev) | |||
502 | struct device_driver *drv = dev->driver; | 620 | struct device_driver *drv = dev->driver; |
503 | int error = 0; | 621 | int error = 0; |
504 | 622 | ||
505 | if (drv && drv->pm) { | 623 | if (pci_has_legacy_pm_support(pci_dev)) |
506 | if (drv->pm->freeze) { | 624 | return pci_legacy_suspend(dev, PMSG_FREEZE); |
507 | error = drv->pm->freeze(dev); | 625 | |
508 | suspend_report_result(drv->pm->freeze, error); | 626 | if (drv && drv->pm && drv->pm->freeze) { |
509 | } else { | 627 | error = drv->pm->freeze(dev); |
510 | pci_default_pm_suspend(pci_dev); | 628 | suspend_report_result(drv->pm->freeze, error); |
511 | } | ||
512 | } else { | ||
513 | error = pci_legacy_suspend(dev, PMSG_FREEZE); | ||
514 | pci_fixup_device(pci_fixup_suspend, pci_dev); | ||
515 | } | 629 | } |
516 | 630 | ||
631 | if (!error) | ||
632 | pci_pm_default_suspend_generic(pci_dev); | ||
633 | |||
517 | return error; | 634 | return error; |
518 | } | 635 | } |
519 | 636 | ||
520 | static int pci_pm_freeze_noirq(struct device *dev) | 637 | static int pci_pm_freeze_noirq(struct device *dev) |
521 | { | 638 | { |
522 | struct pci_dev *pci_dev = to_pci_dev(dev); | 639 | struct pci_dev *pci_dev = to_pci_dev(dev); |
523 | struct pci_driver *drv = pci_dev->driver; | 640 | struct device_driver *drv = dev->driver; |
524 | int error = 0; | 641 | int error = 0; |
525 | 642 | ||
526 | if (drv && drv->pm) { | 643 | if (pci_has_legacy_pm_support(pci_dev)) |
527 | if (drv->pm->freeze_noirq) { | 644 | return pci_legacy_suspend_late(dev, PMSG_FREEZE); |
528 | error = drv->pm->freeze_noirq(dev); | 645 | |
529 | suspend_report_result(drv->pm->freeze_noirq, error); | 646 | if (drv && drv->pm && drv->pm->freeze_noirq) { |
530 | } | 647 | error = drv->pm->freeze_noirq(dev); |
531 | } else { | 648 | suspend_report_result(drv->pm->freeze_noirq, error); |
532 | error = pci_legacy_suspend_late(dev, PMSG_FREEZE); | ||
533 | } | 649 | } |
534 | 650 | ||
651 | if (!error) | ||
652 | pci_pm_set_unknown_state(pci_dev); | ||
653 | |||
535 | return error; | 654 | return error; |
536 | } | 655 | } |
537 | 656 | ||
538 | static int pci_pm_thaw(struct device *dev) | 657 | static int pci_pm_thaw_noirq(struct device *dev) |
539 | { | 658 | { |
659 | struct pci_dev *pci_dev = to_pci_dev(dev); | ||
540 | struct device_driver *drv = dev->driver; | 660 | struct device_driver *drv = dev->driver; |
541 | int error = 0; | 661 | int error = 0; |
542 | 662 | ||
543 | if (drv && drv->pm) { | 663 | if (pci_has_legacy_pm_support(pci_dev)) |
544 | if (drv->pm->thaw) | 664 | return pci_legacy_resume_early(dev); |
545 | error = drv->pm->thaw(dev); | 665 | |
546 | } else { | 666 | pci_update_current_state(pci_dev, PCI_D0); |
547 | pci_fixup_device(pci_fixup_resume, to_pci_dev(dev)); | 667 | |
548 | error = pci_legacy_resume(dev); | 668 | if (drv && drv->pm && drv->pm->thaw_noirq) |
549 | } | 669 | error = drv->pm->thaw_noirq(dev); |
550 | 670 | ||
551 | return error; | 671 | return error; |
552 | } | 672 | } |
553 | 673 | ||
554 | static int pci_pm_thaw_noirq(struct device *dev) | 674 | static int pci_pm_thaw(struct device *dev) |
555 | { | 675 | { |
556 | struct pci_dev *pci_dev = to_pci_dev(dev); | 676 | struct pci_dev *pci_dev = to_pci_dev(dev); |
557 | struct pci_driver *drv = pci_dev->driver; | 677 | struct device_driver *drv = dev->driver; |
558 | int error = 0; | 678 | int error = 0; |
559 | 679 | ||
560 | if (drv && drv->pm) { | 680 | if (pci_has_legacy_pm_support(pci_dev)) |
561 | if (drv->pm->thaw_noirq) | 681 | return pci_legacy_resume(dev); |
562 | error = drv->pm->thaw_noirq(dev); | 682 | |
563 | } else { | 683 | pci_pm_reenable_device(pci_dev); |
564 | pci_fixup_device(pci_fixup_resume_early, pci_dev); | 684 | |
565 | error = pci_legacy_resume_early(dev); | 685 | if (drv && drv->pm && drv->pm->thaw) |
566 | } | 686 | error = drv->pm->thaw(dev); |
567 | 687 | ||
568 | return error; | 688 | return error; |
569 | } | 689 | } |
570 | 690 | ||
571 | static int pci_pm_poweroff(struct device *dev) | 691 | static int pci_pm_poweroff(struct device *dev) |
572 | { | 692 | { |
693 | struct pci_dev *pci_dev = to_pci_dev(dev); | ||
573 | struct device_driver *drv = dev->driver; | 694 | struct device_driver *drv = dev->driver; |
574 | int error = 0; | 695 | int error = 0; |
575 | 696 | ||
576 | pci_fixup_device(pci_fixup_suspend, to_pci_dev(dev)); | 697 | if (pci_has_legacy_pm_support(pci_dev)) |
698 | return pci_legacy_suspend(dev, PMSG_HIBERNATE); | ||
577 | 699 | ||
578 | if (drv && drv->pm) { | 700 | if (drv && drv->pm && drv->pm->poweroff) { |
579 | if (drv->pm->poweroff) { | 701 | error = drv->pm->poweroff(dev); |
580 | error = drv->pm->poweroff(dev); | 702 | suspend_report_result(drv->pm->poweroff, error); |
581 | suspend_report_result(drv->pm->poweroff, error); | ||
582 | } | ||
583 | } else { | ||
584 | error = pci_legacy_suspend(dev, PMSG_HIBERNATE); | ||
585 | } | 703 | } |
586 | 704 | ||
705 | if (!error) | ||
706 | pci_pm_default_suspend(pci_dev); | ||
707 | |||
587 | return error; | 708 | return error; |
588 | } | 709 | } |
589 | 710 | ||
590 | static int pci_pm_poweroff_noirq(struct device *dev) | 711 | static int pci_pm_poweroff_noirq(struct device *dev) |
591 | { | 712 | { |
592 | struct pci_dev *pci_dev = to_pci_dev(dev); | 713 | struct device_driver *drv = dev->driver; |
593 | struct pci_driver *drv = pci_dev->driver; | ||
594 | int error = 0; | 714 | int error = 0; |
595 | 715 | ||
596 | if (drv && drv->pm) { | 716 | if (pci_has_legacy_pm_support(to_pci_dev(dev))) |
597 | if (drv->pm->poweroff_noirq) { | 717 | return pci_legacy_suspend_late(dev, PMSG_HIBERNATE); |
598 | error = drv->pm->poweroff_noirq(dev); | 718 | |
599 | suspend_report_result(drv->pm->poweroff_noirq, error); | 719 | if (drv && drv->pm && drv->pm->poweroff_noirq) { |
600 | } | 720 | error = drv->pm->poweroff_noirq(dev); |
601 | } else { | 721 | suspend_report_result(drv->pm->poweroff_noirq, error); |
602 | error = pci_legacy_suspend_late(dev, PMSG_HIBERNATE); | ||
603 | } | 722 | } |
604 | 723 | ||
605 | return error; | 724 | return error; |
606 | } | 725 | } |
607 | 726 | ||
608 | static int pci_pm_restore(struct device *dev) | 727 | static int pci_pm_restore_noirq(struct device *dev) |
609 | { | 728 | { |
610 | struct pci_dev *pci_dev = to_pci_dev(dev); | 729 | struct pci_dev *pci_dev = to_pci_dev(dev); |
611 | struct device_driver *drv = dev->driver; | 730 | struct device_driver *drv = dev->driver; |
612 | int error; | 731 | int error = 0; |
613 | 732 | ||
614 | if (drv && drv->pm) { | 733 | if (pci_has_legacy_pm_support(pci_dev)) |
615 | error = drv->pm->restore ? drv->pm->restore(dev) : | 734 | return pci_legacy_resume_early(dev); |
616 | pci_default_pm_resume(pci_dev); | 735 | |
617 | } else { | 736 | pci_pm_default_resume_noirq(pci_dev); |
618 | error = pci_legacy_resume(dev); | 737 | |
619 | } | 738 | if (drv && drv->pm && drv->pm->restore_noirq) |
620 | pci_fixup_device(pci_fixup_resume, pci_dev); | 739 | error = drv->pm->restore_noirq(dev); |
621 | 740 | ||
622 | return error; | 741 | return error; |
623 | } | 742 | } |
624 | 743 | ||
625 | static int pci_pm_restore_noirq(struct device *dev) | 744 | static int pci_pm_restore(struct device *dev) |
626 | { | 745 | { |
627 | struct pci_dev *pci_dev = to_pci_dev(dev); | 746 | struct pci_dev *pci_dev = to_pci_dev(dev); |
628 | struct pci_driver *drv = pci_dev->driver; | 747 | struct device_driver *drv = dev->driver; |
629 | int error = 0; | 748 | int error = 0; |
630 | 749 | ||
631 | pci_fixup_device(pci_fixup_resume, pci_dev); | 750 | if (pci_has_legacy_pm_support(pci_dev)) |
751 | return pci_legacy_resume(dev); | ||
632 | 752 | ||
633 | if (drv && drv->pm) { | 753 | error = pci_pm_default_resume(pci_dev); |
634 | if (drv->pm->restore_noirq) | 754 | |
635 | error = drv->pm->restore_noirq(dev); | 755 | if (!error && drv && drv->pm && drv->pm->restore) |
636 | } else { | 756 | error = drv->pm->restore(dev); |
637 | error = pci_legacy_resume_early(dev); | ||
638 | } | ||
639 | pci_fixup_device(pci_fixup_resume_early, pci_dev); | ||
640 | 757 | ||
641 | return error; | 758 | return error; |
642 | } | 759 | } |
@@ -654,17 +771,15 @@ static int pci_pm_restore_noirq(struct device *dev) | |||
654 | 771 | ||
655 | #endif /* !CONFIG_HIBERNATION */ | 772 | #endif /* !CONFIG_HIBERNATION */ |
656 | 773 | ||
657 | struct pm_ext_ops pci_pm_ops = { | 774 | struct dev_pm_ops pci_dev_pm_ops = { |
658 | .base = { | 775 | .prepare = pci_pm_prepare, |
659 | .prepare = pci_pm_prepare, | 776 | .complete = pci_pm_complete, |
660 | .complete = pci_pm_complete, | 777 | .suspend = pci_pm_suspend, |
661 | .suspend = pci_pm_suspend, | 778 | .resume = pci_pm_resume, |
662 | .resume = pci_pm_resume, | 779 | .freeze = pci_pm_freeze, |
663 | .freeze = pci_pm_freeze, | 780 | .thaw = pci_pm_thaw, |
664 | .thaw = pci_pm_thaw, | 781 | .poweroff = pci_pm_poweroff, |
665 | .poweroff = pci_pm_poweroff, | 782 | .restore = pci_pm_restore, |
666 | .restore = pci_pm_restore, | ||
667 | }, | ||
668 | .suspend_noirq = pci_pm_suspend_noirq, | 783 | .suspend_noirq = pci_pm_suspend_noirq, |
669 | .resume_noirq = pci_pm_resume_noirq, | 784 | .resume_noirq = pci_pm_resume_noirq, |
670 | .freeze_noirq = pci_pm_freeze_noirq, | 785 | .freeze_noirq = pci_pm_freeze_noirq, |
@@ -673,7 +788,7 @@ struct pm_ext_ops pci_pm_ops = { | |||
673 | .restore_noirq = pci_pm_restore_noirq, | 788 | .restore_noirq = pci_pm_restore_noirq, |
674 | }; | 789 | }; |
675 | 790 | ||
676 | #define PCI_PM_OPS_PTR &pci_pm_ops | 791 | #define PCI_PM_OPS_PTR (&pci_dev_pm_ops) |
677 | 792 | ||
678 | #else /* !CONFIG_PM_SLEEP */ | 793 | #else /* !CONFIG_PM_SLEEP */ |
679 | 794 | ||
@@ -703,9 +818,6 @@ int __pci_register_driver(struct pci_driver *drv, struct module *owner, | |||
703 | drv->driver.owner = owner; | 818 | drv->driver.owner = owner; |
704 | drv->driver.mod_name = mod_name; | 819 | drv->driver.mod_name = mod_name; |
705 | 820 | ||
706 | if (drv->pm) | ||
707 | drv->driver.pm = &drv->pm->base; | ||
708 | |||
709 | spin_lock_init(&drv->dynids.lock); | 821 | spin_lock_init(&drv->dynids.lock); |
710 | INIT_LIST_HEAD(&drv->dynids.list); | 822 | INIT_LIST_HEAD(&drv->dynids.list); |
711 | 823 | ||