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>

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