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

drm/i915: split out i915_switcheroo.[ch] from i915_drv.c

Split out code related to vga switcheroo register/unregister and state
handling from i915_drv.c into new i915_switcheroo.[ch] files.

It's a bit difficult to draw the line how much to move to the new file
from i915_drv.c, but it seemed to me keeping i915_suspend_switcheroo()
and i915_resume_switcheroo() in place was the cleanest.

No functional changes.

Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20191004122019.12009-2-jani.nikula@intel.com

+92 -56
+1
drivers/gpu/drm/i915/Makefile
··· 46 46 i915_pci.o \ 47 47 i915_scatterlist.o \ 48 48 i915_suspend.o \ 49 + i915_switcheroo.o \ 49 50 i915_sysfs.o \ 50 51 i915_utils.o \ 51 52 intel_csr.o \
+7 -56
drivers/gpu/drm/i915/i915_drv.c
··· 72 72 #include "i915_perf.h" 73 73 #include "i915_query.h" 74 74 #include "i915_suspend.h" 75 + #include "i915_switcheroo.h" 75 76 #include "i915_sysfs.h" 76 77 #include "i915_trace.h" 77 78 #include "i915_vgpu.h" ··· 270 269 release_resource(&dev_priv->mch_res); 271 270 } 272 271 273 - static int i915_resume_switcheroo(struct drm_i915_private *i915); 274 - static int i915_suspend_switcheroo(struct drm_i915_private *i915, 275 - pm_message_t state); 276 - 277 - static void i915_switcheroo_set_state(struct pci_dev *pdev, enum vga_switcheroo_state state) 278 - { 279 - struct drm_i915_private *i915 = pdev_to_i915(pdev); 280 - pm_message_t pmm = { .event = PM_EVENT_SUSPEND }; 281 - 282 - if (!i915) { 283 - dev_err(&pdev->dev, "DRM not initialized, aborting switch.\n"); 284 - return; 285 - } 286 - 287 - if (state == VGA_SWITCHEROO_ON) { 288 - pr_info("switched on\n"); 289 - i915->drm.switch_power_state = DRM_SWITCH_POWER_CHANGING; 290 - /* i915 resume handler doesn't set to D0 */ 291 - pci_set_power_state(pdev, PCI_D0); 292 - i915_resume_switcheroo(i915); 293 - i915->drm.switch_power_state = DRM_SWITCH_POWER_ON; 294 - } else { 295 - pr_info("switched off\n"); 296 - i915->drm.switch_power_state = DRM_SWITCH_POWER_CHANGING; 297 - i915_suspend_switcheroo(i915, pmm); 298 - i915->drm.switch_power_state = DRM_SWITCH_POWER_OFF; 299 - } 300 - } 301 - 302 - static bool i915_switcheroo_can_switch(struct pci_dev *pdev) 303 - { 304 - struct drm_i915_private *i915 = pdev_to_i915(pdev); 305 - 306 - /* 307 - * FIXME: open_count is protected by drm_global_mutex but that would lead to 308 - * locking inversion with the driver load path. And the access here is 309 - * completely racy anyway. So don't bother with locking for now. 310 - */ 311 - return i915 && i915->drm.open_count == 0; 312 - } 313 - 314 - static const struct vga_switcheroo_client_ops i915_switcheroo_ops = { 315 - .set_gpu_state = i915_switcheroo_set_state, 316 - .reprobe = NULL, 317 - .can_switch = i915_switcheroo_can_switch, 318 - }; 319 - 320 272 static int i915_driver_modeset_probe(struct drm_i915_private *i915) 321 273 { 322 - struct pci_dev *pdev = i915->drm.pdev; 323 274 int ret; 324 275 325 276 if (i915_inject_probe_failure(i915)) ··· 292 339 293 340 intel_register_dsm_handler(); 294 341 295 - ret = vga_switcheroo_register_client(pdev, &i915_switcheroo_ops, false); 342 + ret = i915_switcheroo_register(i915); 296 343 if (ret) 297 344 goto cleanup_vga_client; 298 345 ··· 347 394 cleanup_csr: 348 395 intel_csr_ucode_fini(i915); 349 396 intel_power_domains_driver_remove(i915); 350 - vga_switcheroo_unregister_client(pdev); 397 + i915_switcheroo_unregister(i915); 351 398 cleanup_vga_client: 352 399 intel_vga_unregister(i915); 353 400 out: ··· 381 428 382 429 static void i915_driver_modeset_remove(struct drm_i915_private *i915) 383 430 { 384 - struct pci_dev *pdev = i915->drm.pdev; 385 - 386 431 intel_modeset_driver_remove(i915); 387 432 388 433 intel_bios_driver_remove(i915); 389 434 390 - vga_switcheroo_unregister_client(pdev); 435 + i915_switcheroo_unregister(i915); 436 + 391 437 intel_vga_unregister(i915); 392 438 393 439 intel_csr_ucode_fini(i915); ··· 1812 1860 return ret; 1813 1861 } 1814 1862 1815 - static int 1816 - i915_suspend_switcheroo(struct drm_i915_private *i915, pm_message_t state) 1863 + int i915_suspend_switcheroo(struct drm_i915_private *i915, pm_message_t state) 1817 1864 { 1818 1865 int error; 1819 1866 ··· 1978 2027 return ret; 1979 2028 } 1980 2029 1981 - static int i915_resume_switcheroo(struct drm_i915_private *i915) 2030 + int i915_resume_switcheroo(struct drm_i915_private *i915) 1982 2031 { 1983 2032 int ret; 1984 2033
+3
drivers/gpu/drm/i915/i915_drv.h
··· 2189 2189 int i915_driver_probe(struct pci_dev *pdev, const struct pci_device_id *ent); 2190 2190 void i915_driver_remove(struct drm_i915_private *i915); 2191 2191 2192 + int i915_resume_switcheroo(struct drm_i915_private *i915); 2193 + int i915_suspend_switcheroo(struct drm_i915_private *i915, pm_message_t state); 2194 + 2192 2195 void intel_engine_init_hangcheck(struct intel_engine_cs *engine); 2193 2196 int vlv_force_gfx_clock(struct drm_i915_private *dev_priv, bool on); 2194 2197
+67
drivers/gpu/drm/i915/i915_switcheroo.c
··· 1 + // SPDX-License-Identifier: MIT 2 + /* 3 + * Copyright © 2019 Intel Corporation 4 + */ 5 + 6 + #include <linux/vga_switcheroo.h> 7 + 8 + #include "i915_drv.h" 9 + #include "i915_switcheroo.h" 10 + 11 + static void i915_switcheroo_set_state(struct pci_dev *pdev, 12 + enum vga_switcheroo_state state) 13 + { 14 + struct drm_i915_private *i915 = pdev_to_i915(pdev); 15 + pm_message_t pmm = { .event = PM_EVENT_SUSPEND }; 16 + 17 + if (!i915) { 18 + dev_err(&pdev->dev, "DRM not initialized, aborting switch.\n"); 19 + return; 20 + } 21 + 22 + if (state == VGA_SWITCHEROO_ON) { 23 + pr_info("switched on\n"); 24 + i915->drm.switch_power_state = DRM_SWITCH_POWER_CHANGING; 25 + /* i915 resume handler doesn't set to D0 */ 26 + pci_set_power_state(pdev, PCI_D0); 27 + i915_resume_switcheroo(i915); 28 + i915->drm.switch_power_state = DRM_SWITCH_POWER_ON; 29 + } else { 30 + pr_info("switched off\n"); 31 + i915->drm.switch_power_state = DRM_SWITCH_POWER_CHANGING; 32 + i915_suspend_switcheroo(i915, pmm); 33 + i915->drm.switch_power_state = DRM_SWITCH_POWER_OFF; 34 + } 35 + } 36 + 37 + static bool i915_switcheroo_can_switch(struct pci_dev *pdev) 38 + { 39 + struct drm_i915_private *i915 = pdev_to_i915(pdev); 40 + 41 + /* 42 + * FIXME: open_count is protected by drm_global_mutex but that would lead to 43 + * locking inversion with the driver load path. And the access here is 44 + * completely racy anyway. So don't bother with locking for now. 45 + */ 46 + return i915 && i915->drm.open_count == 0; 47 + } 48 + 49 + static const struct vga_switcheroo_client_ops i915_switcheroo_ops = { 50 + .set_gpu_state = i915_switcheroo_set_state, 51 + .reprobe = NULL, 52 + .can_switch = i915_switcheroo_can_switch, 53 + }; 54 + 55 + int i915_switcheroo_register(struct drm_i915_private *i915) 56 + { 57 + struct pci_dev *pdev = i915->drm.pdev; 58 + 59 + return vga_switcheroo_register_client(pdev, &i915_switcheroo_ops, false); 60 + } 61 + 62 + void i915_switcheroo_unregister(struct drm_i915_private *i915) 63 + { 64 + struct pci_dev *pdev = i915->drm.pdev; 65 + 66 + vga_switcheroo_unregister_client(pdev); 67 + }
+14
drivers/gpu/drm/i915/i915_switcheroo.h
··· 1 + /* SPDX-License-Identifier: MIT */ 2 + /* 3 + * Copyright © 2019 Intel Corporation 4 + */ 5 + 6 + #ifndef __I915_SWITCHEROO__ 7 + #define __I915_SWITCHEROO__ 8 + 9 + struct drm_i915_private; 10 + 11 + int i915_switcheroo_register(struct drm_i915_private *i915); 12 + void i915_switcheroo_unregister(struct drm_i915_private *i915); 13 + 14 + #endif /* __I915_SWITCHEROO__ */