diff options
Diffstat (limited to 'drivers/pci/pci-driver.c')
-rw-r--r-- | drivers/pci/pci-driver.c | 420 |
1 files changed, 255 insertions, 165 deletions
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index 99d867bcf22a..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 | ||
@@ -300,21 +314,12 @@ static void pci_device_shutdown(struct device *dev) | |||
300 | 314 | ||
301 | #ifdef CONFIG_PM_SLEEP | 315 | #ifdef CONFIG_PM_SLEEP |
302 | 316 | ||
303 | static bool pci_has_legacy_pm_support(struct pci_dev *pci_dev) | ||
304 | { | ||
305 | struct pci_driver *drv = pci_dev->driver; | ||
306 | |||
307 | return drv && (drv->suspend || drv->suspend_late || drv->resume | ||
308 | || drv->resume_early); | ||
309 | } | ||
310 | |||
311 | /* | 317 | /* |
312 | * Default "suspend" method for devices that have no driver provided suspend, | 318 | * Default "suspend" method for devices that have no driver provided suspend, |
313 | * or not even a driver at all. | 319 | * or not even a driver at all (second part). |
314 | */ | 320 | */ |
315 | static void pci_default_pm_suspend(struct pci_dev *pci_dev) | 321 | static void pci_pm_set_unknown_state(struct pci_dev *pci_dev) |
316 | { | 322 | { |
317 | pci_save_state(pci_dev); | ||
318 | /* | 323 | /* |
319 | * 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 |
320 | * 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. |
@@ -325,19 +330,9 @@ static void pci_default_pm_suspend(struct pci_dev *pci_dev) | |||
325 | 330 | ||
326 | /* | 331 | /* |
327 | * Default "resume" method for devices that have no driver provided resume, | 332 | * Default "resume" method for devices that have no driver provided resume, |
328 | * or not even a driver at all (first part). | ||
329 | */ | ||
330 | static void pci_default_pm_resume_early(struct pci_dev *pci_dev) | ||
331 | { | ||
332 | /* restore the PCI config space */ | ||
333 | pci_restore_state(pci_dev); | ||
334 | } | ||
335 | |||
336 | /* | ||
337 | * Default "resume" method for devices that have no driver provided resume, | ||
338 | * or not even a driver at all (second part). | 333 | * or not even a driver at all (second part). |
339 | */ | 334 | */ |
340 | static int pci_default_pm_resume_late(struct pci_dev *pci_dev) | 335 | static int pci_pm_reenable_device(struct pci_dev *pci_dev) |
341 | { | 336 | { |
342 | int retval; | 337 | int retval; |
343 | 338 | ||
@@ -363,8 +358,16 @@ static int pci_legacy_suspend(struct device *dev, pm_message_t state) | |||
363 | i = drv->suspend(pci_dev, state); | 358 | i = drv->suspend(pci_dev, state); |
364 | suspend_report_result(drv->suspend, i); | 359 | suspend_report_result(drv->suspend, i); |
365 | } else { | 360 | } else { |
366 | 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); | ||
367 | } | 367 | } |
368 | |||
369 | pci_fixup_device(pci_fixup_suspend, pci_dev); | ||
370 | |||
368 | return i; | 371 | return i; |
369 | } | 372 | } |
370 | 373 | ||
@@ -381,32 +384,130 @@ static int pci_legacy_suspend_late(struct device *dev, pm_message_t state) | |||
381 | return i; | 384 | return i; |
382 | } | 385 | } |
383 | 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 | |||
384 | static int pci_legacy_resume(struct device *dev) | 400 | static int pci_legacy_resume(struct device *dev) |
385 | { | 401 | { |
386 | int error; | 402 | int error; |
387 | struct pci_dev * pci_dev = to_pci_dev(dev); | 403 | struct pci_dev * pci_dev = to_pci_dev(dev); |
388 | struct pci_driver * drv = pci_dev->driver; | 404 | struct pci_driver * drv = pci_dev->driver; |
389 | 405 | ||
406 | pci_fixup_device(pci_fixup_resume, pci_dev); | ||
407 | |||
390 | if (drv && drv->resume) { | 408 | if (drv && drv->resume) { |
391 | error = drv->resume(pci_dev); | 409 | error = drv->resume(pci_dev); |
392 | } else { | 410 | } else { |
393 | pci_default_pm_resume_early(pci_dev); | 411 | /* restore the PCI config space */ |
394 | error = pci_default_pm_resume_late(pci_dev); | 412 | pci_restore_state(pci_dev); |
413 | error = pci_pm_reenable_device(pci_dev); | ||
395 | } | 414 | } |
396 | return error; | 415 | return error; |
397 | } | 416 | } |
398 | 417 | ||
399 | 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) | ||
400 | { | 421 | { |
422 | struct pci_dev *parent = pci_dev->bus->self; | ||
401 | int error = 0; | 423 | int error = 0; |
402 | struct pci_dev * pci_dev = to_pci_dev(dev); | ||
403 | struct pci_driver * drv = pci_dev->driver; | ||
404 | 424 | ||
405 | if (drv && drv->resume_early) | 425 | /* Check if the device's bus is operational */ |
406 | 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 | |||
407 | return error; | 437 | return error; |
408 | } | 438 | } |
409 | 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 | |||
410 | static int pci_pm_prepare(struct device *dev) | 511 | static int pci_pm_prepare(struct device *dev) |
411 | { | 512 | { |
412 | struct device_driver *drv = dev->driver; | 513 | struct device_driver *drv = dev->driver; |
@@ -434,15 +535,16 @@ static int pci_pm_suspend(struct device *dev) | |||
434 | struct device_driver *drv = dev->driver; | 535 | struct device_driver *drv = dev->driver; |
435 | int error = 0; | 536 | int error = 0; |
436 | 537 | ||
437 | if (drv && drv->pm) { | 538 | if (pci_has_legacy_pm_support(pci_dev)) |
438 | if (drv->pm->suspend) { | 539 | return pci_legacy_suspend(dev, PMSG_SUSPEND); |
439 | error = drv->pm->suspend(dev); | 540 | |
440 | suspend_report_result(drv->pm->suspend, error); | 541 | if (drv && drv->pm && drv->pm->suspend) { |
441 | } | 542 | error = drv->pm->suspend(dev); |
442 | } else if (pci_has_legacy_pm_support(pci_dev)) { | 543 | suspend_report_result(drv->pm->suspend, error); |
443 | error = pci_legacy_suspend(dev, PMSG_SUSPEND); | ||
444 | } | 544 | } |
445 | pci_fixup_device(pci_fixup_suspend, pci_dev); | 545 | |
546 | if (!error) | ||
547 | pci_pm_default_suspend(pci_dev); | ||
446 | 548 | ||
447 | return error; | 549 | return error; |
448 | } | 550 | } |
@@ -453,56 +555,50 @@ static int pci_pm_suspend_noirq(struct device *dev) | |||
453 | struct device_driver *drv = dev->driver; | 555 | struct device_driver *drv = dev->driver; |
454 | int error = 0; | 556 | int error = 0; |
455 | 557 | ||
456 | if (drv && drv->pm) { | 558 | if (pci_has_legacy_pm_support(pci_dev)) |
457 | if (drv->pm->suspend_noirq) { | 559 | return pci_legacy_suspend_late(dev, PMSG_SUSPEND); |
458 | error = drv->pm->suspend_noirq(dev); | 560 | |
459 | suspend_report_result(drv->pm->suspend_noirq, error); | 561 | if (drv && drv->pm && drv->pm->suspend_noirq) { |
460 | } | 562 | error = drv->pm->suspend_noirq(dev); |
461 | } else if (pci_has_legacy_pm_support(pci_dev)) { | 563 | suspend_report_result(drv->pm->suspend_noirq, error); |
462 | error = pci_legacy_suspend_late(dev, PMSG_SUSPEND); | ||
463 | } else { | ||
464 | pci_default_pm_suspend(pci_dev); | ||
465 | } | 564 | } |
466 | 565 | ||
566 | if (!error) | ||
567 | pci_pm_set_unknown_state(pci_dev); | ||
568 | |||
467 | return error; | 569 | return error; |
468 | } | 570 | } |
469 | 571 | ||
470 | static int pci_pm_resume(struct device *dev) | 572 | static int pci_pm_resume_noirq(struct device *dev) |
471 | { | 573 | { |
472 | struct pci_dev *pci_dev = to_pci_dev(dev); | 574 | struct pci_dev *pci_dev = to_pci_dev(dev); |
473 | struct device_driver *drv = dev->driver; | 575 | struct device_driver *drv = dev->driver; |
474 | int error = 0; | 576 | int error = 0; |
475 | 577 | ||
476 | pci_fixup_device(pci_fixup_resume, pci_dev); | 578 | if (pci_has_legacy_pm_support(pci_dev)) |
579 | return pci_legacy_resume_early(dev); | ||
477 | 580 | ||
478 | if (drv && drv->pm) { | 581 | pci_pm_default_resume_noirq(pci_dev); |
479 | if (drv->pm->resume) | 582 | |
480 | error = drv->pm->resume(dev); | 583 | if (drv && drv->pm && drv->pm->resume_noirq) |
481 | } else if (pci_has_legacy_pm_support(pci_dev)) { | 584 | error = drv->pm->resume_noirq(dev); |
482 | error = pci_legacy_resume(dev); | ||
483 | } else { | ||
484 | error = pci_default_pm_resume_late(pci_dev); | ||
485 | } | ||
486 | 585 | ||
487 | return error; | 586 | return error; |
488 | } | 587 | } |
489 | 588 | ||
490 | static int pci_pm_resume_noirq(struct device *dev) | 589 | static int pci_pm_resume(struct device *dev) |
491 | { | 590 | { |
492 | struct pci_dev *pci_dev = to_pci_dev(dev); | 591 | struct pci_dev *pci_dev = to_pci_dev(dev); |
493 | struct device_driver *drv = dev->driver; | 592 | struct device_driver *drv = dev->driver; |
494 | int error = 0; | 593 | int error = 0; |
495 | 594 | ||
496 | pci_fixup_device(pci_fixup_resume_early, to_pci_dev(dev)); | 595 | if (pci_has_legacy_pm_support(pci_dev)) |
596 | return pci_legacy_resume(dev); | ||
497 | 597 | ||
498 | if (drv && drv->pm) { | 598 | error = pci_pm_default_resume(pci_dev); |
499 | if (drv->pm->resume_noirq) | 599 | |
500 | error = drv->pm->resume_noirq(dev); | 600 | if (!error && drv && drv->pm && drv->pm->resume) |
501 | } else if (pci_has_legacy_pm_support(pci_dev)) { | 601 | error = drv->pm->resume(dev); |
502 | error = pci_legacy_resume_early(dev); | ||
503 | } else { | ||
504 | pci_default_pm_resume_early(pci_dev); | ||
505 | } | ||
506 | 602 | ||
507 | return error; | 603 | return error; |
508 | } | 604 | } |
@@ -524,16 +620,17 @@ static int pci_pm_freeze(struct device *dev) | |||
524 | struct device_driver *drv = dev->driver; | 620 | struct device_driver *drv = dev->driver; |
525 | int error = 0; | 621 | int error = 0; |
526 | 622 | ||
527 | if (drv && drv->pm) { | 623 | if (pci_has_legacy_pm_support(pci_dev)) |
528 | if (drv->pm->freeze) { | 624 | return pci_legacy_suspend(dev, PMSG_FREEZE); |
529 | error = drv->pm->freeze(dev); | 625 | |
530 | suspend_report_result(drv->pm->freeze, error); | 626 | if (drv && drv->pm && drv->pm->freeze) { |
531 | } | 627 | error = drv->pm->freeze(dev); |
532 | } else if (pci_has_legacy_pm_support(pci_dev)) { | 628 | suspend_report_result(drv->pm->freeze, error); |
533 | error = pci_legacy_suspend(dev, PMSG_FREEZE); | ||
534 | pci_fixup_device(pci_fixup_suspend, pci_dev); | ||
535 | } | 629 | } |
536 | 630 | ||
631 | if (!error) | ||
632 | pci_pm_default_suspend_generic(pci_dev); | ||
633 | |||
537 | return error; | 634 | return error; |
538 | } | 635 | } |
539 | 636 | ||
@@ -543,50 +640,50 @@ static int pci_pm_freeze_noirq(struct device *dev) | |||
543 | struct device_driver *drv = dev->driver; | 640 | struct device_driver *drv = dev->driver; |
544 | int error = 0; | 641 | int error = 0; |
545 | 642 | ||
546 | if (drv && drv->pm) { | 643 | if (pci_has_legacy_pm_support(pci_dev)) |
547 | if (drv->pm->freeze_noirq) { | 644 | return pci_legacy_suspend_late(dev, PMSG_FREEZE); |
548 | error = drv->pm->freeze_noirq(dev); | 645 | |
549 | suspend_report_result(drv->pm->freeze_noirq, error); | 646 | if (drv && drv->pm && drv->pm->freeze_noirq) { |
550 | } | 647 | error = drv->pm->freeze_noirq(dev); |
551 | } else if (pci_has_legacy_pm_support(pci_dev)) { | 648 | suspend_report_result(drv->pm->freeze_noirq, error); |
552 | error = pci_legacy_suspend_late(dev, PMSG_FREEZE); | ||
553 | } else { | ||
554 | pci_default_pm_suspend(pci_dev); | ||
555 | } | 649 | } |
556 | 650 | ||
651 | if (!error) | ||
652 | pci_pm_set_unknown_state(pci_dev); | ||
653 | |||
557 | return error; | 654 | return error; |
558 | } | 655 | } |
559 | 656 | ||
560 | static int pci_pm_thaw(struct device *dev) | 657 | static int pci_pm_thaw_noirq(struct device *dev) |
561 | { | 658 | { |
562 | struct pci_dev *pci_dev = to_pci_dev(dev); | 659 | struct pci_dev *pci_dev = to_pci_dev(dev); |
563 | struct device_driver *drv = dev->driver; | 660 | struct device_driver *drv = dev->driver; |
564 | int error = 0; | 661 | int error = 0; |
565 | 662 | ||
566 | if (drv && drv->pm) { | 663 | if (pci_has_legacy_pm_support(pci_dev)) |
567 | if (drv->pm->thaw) | 664 | return pci_legacy_resume_early(dev); |
568 | error = drv->pm->thaw(dev); | 665 | |
569 | } else if (pci_has_legacy_pm_support(pci_dev)) { | 666 | pci_update_current_state(pci_dev, PCI_D0); |
570 | pci_fixup_device(pci_fixup_resume, pci_dev); | 667 | |
571 | error = pci_legacy_resume(dev); | 668 | if (drv && drv->pm && drv->pm->thaw_noirq) |
572 | } | 669 | error = drv->pm->thaw_noirq(dev); |
573 | 670 | ||
574 | return error; | 671 | return error; |
575 | } | 672 | } |
576 | 673 | ||
577 | static int pci_pm_thaw_noirq(struct device *dev) | 674 | static int pci_pm_thaw(struct device *dev) |
578 | { | 675 | { |
579 | struct pci_dev *pci_dev = to_pci_dev(dev); | 676 | struct pci_dev *pci_dev = to_pci_dev(dev); |
580 | struct device_driver *drv = dev->driver; | 677 | struct device_driver *drv = dev->driver; |
581 | int error = 0; | 678 | int error = 0; |
582 | 679 | ||
583 | if (drv && drv->pm) { | 680 | if (pci_has_legacy_pm_support(pci_dev)) |
584 | if (drv->pm->thaw_noirq) | 681 | return pci_legacy_resume(dev); |
585 | error = drv->pm->thaw_noirq(dev); | 682 | |
586 | } else if (pci_has_legacy_pm_support(pci_dev)) { | 683 | pci_pm_reenable_device(pci_dev); |
587 | pci_fixup_device(pci_fixup_resume_early, to_pci_dev(dev)); | 684 | |
588 | error = pci_legacy_resume_early(dev); | 685 | if (drv && drv->pm && drv->pm->thaw) |
589 | } | 686 | error = drv->pm->thaw(dev); |
590 | 687 | ||
591 | return error; | 688 | return error; |
592 | } | 689 | } |
@@ -597,17 +694,17 @@ static int pci_pm_poweroff(struct device *dev) | |||
597 | struct device_driver *drv = dev->driver; | 694 | struct device_driver *drv = dev->driver; |
598 | int error = 0; | 695 | int error = 0; |
599 | 696 | ||
600 | pci_fixup_device(pci_fixup_suspend, pci_dev); | 697 | if (pci_has_legacy_pm_support(pci_dev)) |
698 | return pci_legacy_suspend(dev, PMSG_HIBERNATE); | ||
601 | 699 | ||
602 | if (drv && drv->pm) { | 700 | if (drv && drv->pm && drv->pm->poweroff) { |
603 | if (drv->pm->poweroff) { | 701 | error = drv->pm->poweroff(dev); |
604 | error = drv->pm->poweroff(dev); | 702 | suspend_report_result(drv->pm->poweroff, error); |
605 | suspend_report_result(drv->pm->poweroff, error); | ||
606 | } | ||
607 | } else if (pci_has_legacy_pm_support(pci_dev)) { | ||
608 | error = pci_legacy_suspend(dev, PMSG_HIBERNATE); | ||
609 | } | 703 | } |
610 | 704 | ||
705 | if (!error) | ||
706 | pci_pm_default_suspend(pci_dev); | ||
707 | |||
611 | return error; | 708 | return error; |
612 | } | 709 | } |
613 | 710 | ||
@@ -616,54 +713,47 @@ static int pci_pm_poweroff_noirq(struct device *dev) | |||
616 | struct device_driver *drv = dev->driver; | 713 | struct device_driver *drv = dev->driver; |
617 | int error = 0; | 714 | int error = 0; |
618 | 715 | ||
619 | if (drv && drv->pm) { | 716 | if (pci_has_legacy_pm_support(to_pci_dev(dev))) |
620 | if (drv->pm->poweroff_noirq) { | 717 | return pci_legacy_suspend_late(dev, PMSG_HIBERNATE); |
621 | error = drv->pm->poweroff_noirq(dev); | 718 | |
622 | suspend_report_result(drv->pm->poweroff_noirq, error); | 719 | if (drv && drv->pm && drv->pm->poweroff_noirq) { |
623 | } | 720 | error = drv->pm->poweroff_noirq(dev); |
624 | } else if (pci_has_legacy_pm_support(to_pci_dev(dev))) { | 721 | suspend_report_result(drv->pm->poweroff_noirq, error); |
625 | error = pci_legacy_suspend_late(dev, PMSG_HIBERNATE); | ||
626 | } | 722 | } |
627 | 723 | ||
628 | return error; | 724 | return error; |
629 | } | 725 | } |
630 | 726 | ||
631 | static int pci_pm_restore(struct device *dev) | 727 | static int pci_pm_restore_noirq(struct device *dev) |
632 | { | 728 | { |
633 | struct pci_dev *pci_dev = to_pci_dev(dev); | 729 | struct pci_dev *pci_dev = to_pci_dev(dev); |
634 | struct device_driver *drv = dev->driver; | 730 | struct device_driver *drv = dev->driver; |
635 | int error = 0; | 731 | int error = 0; |
636 | 732 | ||
637 | if (drv && drv->pm) { | 733 | if (pci_has_legacy_pm_support(pci_dev)) |
638 | if (drv->pm->restore) | 734 | return pci_legacy_resume_early(dev); |
639 | error = drv->pm->restore(dev); | 735 | |
640 | } else if (pci_has_legacy_pm_support(pci_dev)) { | 736 | pci_pm_default_resume_noirq(pci_dev); |
641 | error = pci_legacy_resume(dev); | 737 | |
642 | } else { | 738 | if (drv && drv->pm && drv->pm->restore_noirq) |
643 | error = pci_default_pm_resume_late(pci_dev); | 739 | error = drv->pm->restore_noirq(dev); |
644 | } | ||
645 | pci_fixup_device(pci_fixup_resume, pci_dev); | ||
646 | 740 | ||
647 | return error; | 741 | return error; |
648 | } | 742 | } |
649 | 743 | ||
650 | static int pci_pm_restore_noirq(struct device *dev) | 744 | static int pci_pm_restore(struct device *dev) |
651 | { | 745 | { |
652 | struct pci_dev *pci_dev = to_pci_dev(dev); | 746 | struct pci_dev *pci_dev = to_pci_dev(dev); |
653 | struct device_driver *drv = dev->driver; | 747 | struct device_driver *drv = dev->driver; |
654 | int error = 0; | 748 | int error = 0; |
655 | 749 | ||
656 | pci_fixup_device(pci_fixup_resume, pci_dev); | 750 | if (pci_has_legacy_pm_support(pci_dev)) |
751 | return pci_legacy_resume(dev); | ||
657 | 752 | ||
658 | if (drv && drv->pm) { | 753 | error = pci_pm_default_resume(pci_dev); |
659 | if (drv->pm->restore_noirq) | 754 | |
660 | error = drv->pm->restore_noirq(dev); | 755 | if (!error && drv && drv->pm && drv->pm->restore) |
661 | } else if (pci_has_legacy_pm_support(pci_dev)) { | 756 | error = drv->pm->restore(dev); |
662 | error = pci_legacy_resume_early(dev); | ||
663 | } else { | ||
664 | pci_default_pm_resume_early(pci_dev); | ||
665 | } | ||
666 | pci_fixup_device(pci_fixup_resume_early, pci_dev); | ||
667 | 757 | ||
668 | return error; | 758 | return error; |
669 | } | 759 | } |