Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/nouveau: replace multiple open-coded runpm support checks with function

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

+18 -32
+15 -19
drivers/gpu/drm/nouveau/nouveau_drm.c
··· 80 80 module_param_named(modeset, nouveau_modeset, int, 0400); 81 81 82 82 MODULE_PARM_DESC(runpm, "disable (0), force enable (1), optimus only default (-1)"); 83 - int nouveau_runtime_pm = -1; 83 + static int nouveau_runtime_pm = -1; 84 84 module_param_named(runpm, nouveau_runtime_pm, int, 0400); 85 85 86 86 static struct drm_driver driver_stub; ··· 726 726 return nouveau_do_resume(drm_dev, false); 727 727 } 728 728 729 + bool 730 + nouveau_pmops_runtime() 731 + { 732 + if (nouveau_runtime_pm == -1) 733 + return nouveau_is_optimus() || nouveau_is_v1_dsm(); 734 + return nouveau_runtime_pm == 1; 735 + } 736 + 729 737 static int 730 738 nouveau_pmops_runtime_suspend(struct device *dev) 731 739 { ··· 741 733 struct drm_device *drm_dev = pci_get_drvdata(pdev); 742 734 int ret; 743 735 744 - if (nouveau_runtime_pm == 0) { 745 - pm_runtime_forbid(dev); 746 - return -EBUSY; 747 - } 748 - 749 - /* are we optimus enabled? */ 750 - if (nouveau_runtime_pm == -1 && !nouveau_is_optimus() && !nouveau_is_v1_dsm()) { 751 - DRM_DEBUG_DRIVER("failing to power off - not optimus\n"); 736 + if (!nouveau_pmops_runtime()) { 752 737 pm_runtime_forbid(dev); 753 738 return -EBUSY; 754 739 } ··· 766 765 struct nvif_device *device = &nouveau_drm(drm_dev)->client.device; 767 766 int ret; 768 767 769 - if (nouveau_runtime_pm == 0) 770 - return -EINVAL; 768 + if (!nouveau_pmops_runtime()) { 769 + pm_runtime_forbid(dev); 770 + return -EBUSY; 771 + } 771 772 772 773 pci_set_power_state(pdev, PCI_D0); 773 774 pci_restore_state(pdev); ··· 799 796 struct nouveau_drm *drm = nouveau_drm(drm_dev); 800 797 struct drm_crtc *crtc; 801 798 802 - if (nouveau_runtime_pm == 0) { 803 - pm_runtime_forbid(dev); 804 - return -EBUSY; 805 - } 806 - 807 - /* are we optimus enabled? */ 808 - if (nouveau_runtime_pm == -1 && !nouveau_is_optimus() && !nouveau_is_v1_dsm()) { 809 - DRM_DEBUG_DRIVER("failing to power off - not optimus\n"); 799 + if (!nouveau_pmops_runtime()) { 810 800 pm_runtime_forbid(dev); 811 801 return -EBUSY; 812 802 }
+1 -2
drivers/gpu/drm/nouveau/nouveau_drv.h
··· 108 108 #include <nvif/object.h> 109 109 #include <nvif/device.h> 110 110 111 - extern int nouveau_runtime_pm; 112 - 113 111 struct nouveau_drm { 114 112 struct nouveau_cli client; 115 113 struct drm_device *dev; ··· 193 195 194 196 int nouveau_pmops_suspend(struct device *); 195 197 int nouveau_pmops_resume(struct device *); 198 + bool nouveau_pmops_runtime(void); 196 199 197 200 #include <nvkm/core/tegra.h> 198 201
+2 -11
drivers/gpu/drm/nouveau/nouveau_vga.c
··· 87 87 nouveau_vga_init(struct nouveau_drm *drm) 88 88 { 89 89 struct drm_device *dev = drm->dev; 90 - bool runtime = false; 90 + bool runtime = nouveau_pmops_runtime(); 91 91 92 92 /* only relevant for PCI devices */ 93 93 if (!dev->pdev) ··· 99 99 if (pci_is_thunderbolt_attached(dev->pdev)) 100 100 return; 101 101 102 - if (nouveau_runtime_pm == 1) 103 - runtime = true; 104 - if ((nouveau_runtime_pm == -1) && (nouveau_is_optimus() || nouveau_is_v1_dsm())) 105 - runtime = true; 106 102 vga_switcheroo_register_client(dev->pdev, &nouveau_switcheroo_ops, runtime); 107 103 108 104 if (runtime && nouveau_is_v1_dsm() && !nouveau_is_optimus()) ··· 109 113 nouveau_vga_fini(struct nouveau_drm *drm) 110 114 { 111 115 struct drm_device *dev = drm->dev; 112 - bool runtime = false; 116 + bool runtime = nouveau_pmops_runtime(); 113 117 114 118 vga_client_register(dev->pdev, NULL, NULL, NULL); 115 119 116 120 if (pci_is_thunderbolt_attached(dev->pdev)) 117 121 return; 118 - 119 - if (nouveau_runtime_pm == 1) 120 - runtime = true; 121 - if ((nouveau_runtime_pm == -1) && (nouveau_is_optimus() || nouveau_is_v1_dsm())) 122 - runtime = true; 123 122 124 123 vga_switcheroo_unregister_client(dev->pdev); 125 124 if (runtime && nouveau_is_v1_dsm() && !nouveau_is_optimus())