drm/nouveau: make sure display hardware is reinitialised on runtime resume

Linus commit 05c63c2ff23a80b654d6c088ac3ba21628db0173 modified the
runtime suspend/resume paths to skip over display-related tasks to
avoid locking issues on resume.

Unfortunately, this resulted in the display hardware being left in
a partially initialised state, preventing subsequent modesets from
completing.

This commit unifies the (many) suspend/resume paths, bringing back
display (and fbcon) handling in the runtime paths.

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>

+26 -53
+11 -12
drivers/gpu/drm/nouveau/nouveau_display.c
··· 550 } 551 552 int 553 - nouveau_display_suspend(struct drm_device *dev) 554 { 555 - struct nouveau_drm *drm = nouveau_drm(dev); 556 struct drm_crtc *crtc; 557 558 nouveau_display_fini(dev); 559 560 - NV_INFO(drm, "unpinning framebuffer(s)...\n"); 561 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { 562 struct nouveau_framebuffer *nouveau_fb; 563 ··· 577 } 578 579 void 580 - nouveau_display_repin(struct drm_device *dev) 581 { 582 struct nouveau_drm *drm = nouveau_drm(dev); 583 struct drm_crtc *crtc; 584 - int ret; 585 586 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { 587 struct nouveau_framebuffer *nouveau_fb; 588 ··· 605 if (ret) 606 NV_ERROR(drm, "Could not pin/map cursor.\n"); 607 } 608 - } 609 - 610 - void 611 - nouveau_display_resume(struct drm_device *dev) 612 - { 613 - struct drm_crtc *crtc; 614 - int head; 615 616 nouveau_display_init(dev); 617 ··· 618 /* Make sure that drm and hw vblank irqs get resumed if needed. */ 619 for (head = 0; head < dev->mode_config.num_crtc; head++) 620 drm_vblank_on(dev, head); 621 622 drm_helper_resume_force_mode(dev); 623
··· 550 } 551 552 int 553 + nouveau_display_suspend(struct drm_device *dev, bool runtime) 554 { 555 struct drm_crtc *crtc; 556 557 nouveau_display_fini(dev); 558 559 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { 560 struct nouveau_framebuffer *nouveau_fb; 561 ··· 579 } 580 581 void 582 + nouveau_display_resume(struct drm_device *dev, bool runtime) 583 { 584 struct nouveau_drm *drm = nouveau_drm(dev); 585 struct drm_crtc *crtc; 586 + int ret, head; 587 588 + /* re-pin fb/cursors */ 589 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { 590 struct nouveau_framebuffer *nouveau_fb; 591 ··· 606 if (ret) 607 NV_ERROR(drm, "Could not pin/map cursor.\n"); 608 } 609 610 nouveau_display_init(dev); 611 ··· 626 /* Make sure that drm and hw vblank irqs get resumed if needed. */ 627 for (head = 0; head < dev->mode_config.num_crtc; head++) 628 drm_vblank_on(dev, head); 629 + 630 + /* This should ensure we don't hit a locking problem when someone 631 + * wakes us up via a connector. We should never go into suspend 632 + * while the display is on anyways. 633 + */ 634 + if (runtime) 635 + return; 636 637 drm_helper_resume_force_mode(dev); 638
+2 -3
drivers/gpu/drm/nouveau/nouveau_display.h
··· 63 void nouveau_display_destroy(struct drm_device *dev); 64 int nouveau_display_init(struct drm_device *dev); 65 void nouveau_display_fini(struct drm_device *dev); 66 - int nouveau_display_suspend(struct drm_device *dev); 67 - void nouveau_display_repin(struct drm_device *dev); 68 - void nouveau_display_resume(struct drm_device *dev); 69 int nouveau_display_vblank_enable(struct drm_device *, int); 70 void nouveau_display_vblank_disable(struct drm_device *, int); 71 int nouveau_display_scanoutpos(struct drm_device *, int, unsigned int,
··· 63 void nouveau_display_destroy(struct drm_device *dev); 64 int nouveau_display_init(struct drm_device *dev); 65 void nouveau_display_fini(struct drm_device *dev); 66 + int nouveau_display_suspend(struct drm_device *dev, bool runtime); 67 + void nouveau_display_resume(struct drm_device *dev, bool runtime); 68 int nouveau_display_vblank_enable(struct drm_device *, int); 69 void nouveau_display_vblank_disable(struct drm_device *, int); 70 int nouveau_display_scanoutpos(struct drm_device *, int, unsigned int,
+13 -38
drivers/gpu/drm/nouveau/nouveau_drm.c
··· 547 struct nouveau_cli *cli; 548 int ret; 549 550 - if (dev->mode_config.num_crtc && !runtime) { 551 NV_INFO(drm, "suspending display...\n"); 552 - ret = nouveau_display_suspend(dev); 553 if (ret) 554 return ret; 555 } ··· 605 fail_display: 606 if (dev->mode_config.num_crtc) { 607 NV_INFO(drm, "resuming display...\n"); 608 - nouveau_display_resume(dev); 609 } 610 return ret; 611 } ··· 620 drm_dev->switch_power_state == DRM_SWITCH_POWER_DYNAMIC_OFF) 621 return 0; 622 623 - if (drm_dev->mode_config.num_crtc) 624 - nouveau_fbcon_set_suspend(drm_dev, 1); 625 - 626 ret = nouveau_do_suspend(drm_dev, false); 627 if (ret) 628 return ret; ··· 632 } 633 634 static int 635 - nouveau_do_resume(struct drm_device *dev) 636 { 637 struct nouveau_drm *drm = nouveau_drm(dev); 638 struct nouveau_cli *cli; ··· 657 658 if (dev->mode_config.num_crtc) { 659 NV_INFO(drm, "resuming display...\n"); 660 - nouveau_display_repin(dev); 661 } 662 663 return 0; ··· 682 return ret; 683 pci_set_master(pdev); 684 685 - ret = nouveau_do_resume(drm_dev); 686 - if (ret) 687 - return ret; 688 - 689 - if (drm_dev->mode_config.num_crtc) { 690 - nouveau_display_resume(drm_dev); 691 - nouveau_fbcon_set_suspend(drm_dev, 0); 692 - } 693 - 694 - return 0; 695 } 696 697 static int nouveau_pmops_freeze(struct device *dev) 698 { 699 struct pci_dev *pdev = to_pci_dev(dev); 700 struct drm_device *drm_dev = pci_get_drvdata(pdev); 701 - int ret; 702 - 703 - if (drm_dev->mode_config.num_crtc) 704 - nouveau_fbcon_set_suspend(drm_dev, 1); 705 - 706 - ret = nouveau_do_suspend(drm_dev, false); 707 - return ret; 708 } 709 710 static int nouveau_pmops_thaw(struct device *dev) 711 { 712 struct pci_dev *pdev = to_pci_dev(dev); 713 struct drm_device *drm_dev = pci_get_drvdata(pdev); 714 - int ret; 715 - 716 - ret = nouveau_do_resume(drm_dev); 717 - if (ret) 718 - return ret; 719 - 720 - if (drm_dev->mode_config.num_crtc) { 721 - nouveau_display_resume(drm_dev); 722 - nouveau_fbcon_set_suspend(drm_dev, 0); 723 - } 724 - 725 - return 0; 726 } 727 728 ··· 952 return ret; 953 pci_set_master(pdev); 954 955 - ret = nouveau_do_resume(drm_dev); 956 drm_kms_helper_poll_enable(drm_dev); 957 /* do magic */ 958 nvif_mask(device, 0x88488, (1 << 25), (1 << 25));
··· 547 struct nouveau_cli *cli; 548 int ret; 549 550 + if (dev->mode_config.num_crtc) { 551 + NV_INFO(drm, "suspending console...\n"); 552 + nouveau_fbcon_set_suspend(dev, 1); 553 NV_INFO(drm, "suspending display...\n"); 554 + ret = nouveau_display_suspend(dev, runtime); 555 if (ret) 556 return ret; 557 } ··· 603 fail_display: 604 if (dev->mode_config.num_crtc) { 605 NV_INFO(drm, "resuming display...\n"); 606 + nouveau_display_resume(dev, runtime); 607 } 608 return ret; 609 } ··· 618 drm_dev->switch_power_state == DRM_SWITCH_POWER_DYNAMIC_OFF) 619 return 0; 620 621 ret = nouveau_do_suspend(drm_dev, false); 622 if (ret) 623 return ret; ··· 633 } 634 635 static int 636 + nouveau_do_resume(struct drm_device *dev, bool runtime) 637 { 638 struct nouveau_drm *drm = nouveau_drm(dev); 639 struct nouveau_cli *cli; ··· 658 659 if (dev->mode_config.num_crtc) { 660 NV_INFO(drm, "resuming display...\n"); 661 + nouveau_display_resume(dev, runtime); 662 + NV_INFO(drm, "resuming console...\n"); 663 + nouveau_fbcon_set_suspend(dev, 0); 664 } 665 666 return 0; ··· 681 return ret; 682 pci_set_master(pdev); 683 684 + return nouveau_do_resume(drm_dev, false); 685 } 686 687 static int nouveau_pmops_freeze(struct device *dev) 688 { 689 struct pci_dev *pdev = to_pci_dev(dev); 690 struct drm_device *drm_dev = pci_get_drvdata(pdev); 691 + return nouveau_do_suspend(drm_dev, false); 692 } 693 694 static int nouveau_pmops_thaw(struct device *dev) 695 { 696 struct pci_dev *pdev = to_pci_dev(dev); 697 struct drm_device *drm_dev = pci_get_drvdata(pdev); 698 + return nouveau_do_resume(drm_dev, false); 699 } 700 701 ··· 977 return ret; 978 pci_set_master(pdev); 979 980 + ret = nouveau_do_resume(drm_dev, true); 981 drm_kms_helper_poll_enable(drm_dev); 982 /* do magic */ 983 nvif_mask(device, 0x88488, (1 << 25), (1 << 25));