vga_switcheroo: initial implementation (v11)
Subsystems (8)
Dave Airlie
maintainerPATCH 1/1 vga_switcheroo: initial implementation (v11)
From: Dave Airlie <[email protected]>
Many new laptops now come with 2 gpus, one to be used for low power modes and one for gaming/on-ac applications. These GPUs are typically wired to the laptop panel and VGA ports via a multiplexer unit which is controlled via ACPI methods.
4 combinations of systems typically exist - with 2 ACPI methods. Intel/ATI - Lenovo W500/T500 - use ATPX ACPI method ATI/ATI - some ASUS - use ATPX ACPI Method Intel/Nvidia - - use _DSM ACPI method
Nvidia/Nvidia - - use _DSM ACPI method.
TODO:
This patch adds support for the ATPX method and initial bits for the _DSM methods that need to written by someone with access to the hardware.
Add a proper non-debugfs interface - need to get some proper testing first.
v2: add power up/down support for both devices
on W500 puts i915/radeon into D3 and cuts power to radeon.
v3: redo probing methods, no DMI list, drm devices call to register with switcheroo, it tries to find an ATPX method on any device and once there is two devices + ATPX it inits the switcher.
v4: ATPX msg handling using buffers - should work on more machines
v5: rearchitect after more mjg59 discussion - move ATPX handling to
radeon driver.
v6: add file headers + initial nouveau bits (to be filled out).
v7: merge delayed switcher code.
v8: avoid suspend/resume of gpu that is off
v9: rearchitect - mjg59 is always right. - move all ATPX code to radeon, should allow simpler DSM also proper ATRM handling
v10: add ATRM support for radeon BIOS, add mutex to lock vgasr_priv
v11: fix bug in resuming Intel for 2nd time.
mount debugfs
/sys/kernel/debug/vgaswitcheroo/switch - should exist if ATPX detected
+ 2 cards.
DIS - immediate change to discrete
IGD - immediate change to IGD
DDIS - delayed change to discrete
DIGD - delayed change to IGD
ON - turn on not in use
OFF - turn off not in use
Tested on W500 (Intel/ATI) and T500 (Intel/ATI)
--- drivers/gpu/drm/i915/i915_dma.c | 33 ++ drivers/gpu/drm/i915/i915_drv.c | 5 +- drivers/gpu/drm/i915/i915_drv.h | 2 + drivers/gpu/drm/i915/intel_fb.c | 2 + drivers/gpu/drm/nouveau/nouveau_acpi.c | 40 +++ drivers/gpu/drm/nouveau/nouveau_drv.c | 4 +- drivers/gpu/drm/nouveau/nouveau_drv.h | 3 + drivers/gpu/drm/nouveau/nouveau_fbcon.c | 2 + drivers/gpu/drm/nouveau/nouveau_state.c | 27 ++ drivers/gpu/drm/radeon/Makefile | 3 +- drivers/gpu/drm/radeon/r600_audio.c | 3 + drivers/gpu/drm/radeon/radeon.h | 8 + drivers/gpu/drm/radeon/radeon_atpx_handler.c | 258 +++++++++++++++ drivers/gpu/drm/radeon/radeon_bios.c | 45 +++- drivers/gpu/drm/radeon/radeon_device.c | 42 +++ drivers/gpu/drm/radeon/radeon_drv.c | 4 +- drivers/gpu/drm/radeon/radeon_drv.h | 3 + drivers/gpu/drm/radeon/radeon_fb.c | 3 + drivers/gpu/drm/radeon/radeon_kms.c | 3 + drivers/gpu/vga/Kconfig | 11 + drivers/gpu/vga/Makefile | 1 + drivers/gpu/vga/vga_switcheroo.c | 454 ++++++++++++++++++++++++++ drivers/video/console/fbcon.c | 18 + include/linux/fb.h | 2 + include/linux/vga_switcheroo.h | 58 ++++ 25 files changed, 1023 insertions(+), 11 deletions(-) create mode 100644 drivers/gpu/drm/radeon/radeon_atpx_handler.c create mode 100644 drivers/gpu/vga/vga_switcheroo.c create mode 100644 include/linux/vga_switcheroo.h
drivers/gpu/drm/i915/i915_dma.c +33 -0
@@ -35,6 +35,7 @@#include "i915_drv.h" #include "i915_trace.h" #include <linux/vgaarb.h> +#include <linux/vga_switcheroo.h> /* Really want an OS-independent resettable timer. Would like to have * this loop run for (eg) 3 sec, but have the timer reset every time
@@ -1199,6 +1200,30 @@ static unsigned int i915_vga_set_decode(void *cookie, bool state)return VGA_RSRC_NORMAL_IO |VGA_RSRC_NORMAL_MEM ; } +static void i915_switcheroo_set_state (struct pci_dev *pdev,enum vga_switcheroo_state state) +{ +struct drm_device *dev =pci_get_drvdata (pdev); +pm_message_t pmm = { .event =PM_EVENT_SUSPEND }; +if (state =VGA_SWITCHEROO_ON ) { +printk (KERN_ERR "VGA switched i915 on\n" ); +i915_resume (dev); + }else { +printk (KERN_ERR "VGA switched i915 off\n" ); +i915_suspend (dev, pmm); + } +} + +static bool i915_switcheroo_can_switch (struct pci_dev *pdev) +{ +struct drm_device *dev =pci_get_drvdata (pdev); +bool can_switch; + +spin_lock (&dev->count_lock); + can_switch = (dev->open_count =0 ); +spin_unlock (&dev->count_lock); +return can_switch; +} + static int i915_load_modeset_init(struct drm_device *dev, unsigned long prealloc_start, unsigned long prealloc_size,
@@ -1260,6 +1285,12 @@ static int i915_load_modeset_init(struct drm_device *dev,if (ret) goto destroy_ringbuffer; + ret =vga_switcheroo_register_client (dev->pdev, + i915_switcheroo_set_state, + i915_switcheroo_can_switch); +if (ret) + goto destroy_ringbuffer; +intel_modeset_init (dev); ret =drm_irq_install (dev);
@@ -1544,6 +1575,7 @@ int i915_driver_unload(struct drm_device *dev) dev_priv->child_dev_num =0 ; }drm_irq_uninstall (dev); +vga_switcheroo_unregister_client (dev->pdev);vga_client_register (dev->pdev,NULL ,NULL ,NULL ); }
@@ -1611,6 +1643,7 @@ void i915_driver_lastclose(struct drm_device * dev)if (!dev_priv ||drm_core_check_feature (dev,DRIVER_MODESET )) {drm_fb_helper_restore (); +vga_switcheroo_process_delayed_switch ();return ; }
drivers/gpu/drm/i915/i915_drv.c +3 -2
@@ -201,7 +201,7 @@ static int i915_drm_freeze(struct drm_device *dev)return 0 ; } -static int i915_suspend (struct drm_device *dev,pm_message_t state) +int i915_suspend (struct drm_device *dev,pm_message_t state) {int error;
@@ -255,8 +255,9 @@ static int i915_drm_thaw(struct drm_device *dev)return error; } -static int i915_resume (struct drm_device *dev) +int i915_resume (struct drm_device *dev) { +pci_set_power_state (dev->pdev,PCI_D0 );if (pci_enable_device (dev->pdev))return -EIO ;
drivers/gpu/drm/i915/i915_drv.h +2 -0
@@ -736,6 +736,8 @@ extern unsigned int i915_fbpercrtc;extern unsigned int i915_powersave;extern unsigned int i915_lvds_downclock; +extern int i915_suspend (struct drm_device *dev,pm_message_t state); +extern int i915_resume (struct drm_device *dev);extern void i915_save_display (struct drm_device *dev);extern void i915_restore_display (struct drm_device *dev);extern int i915_master_create (struct drm_device *dev,struct drm_master *master);
drivers/gpu/drm/i915/intel_fb.c +2 -0
@@ -35,6 +35,7 @@#include <linux/delay.h> #include <linux/fb.h> #include <linux/init.h> +#include <linux/vga_switcheroo.h> #include "drmP.h" #include "drm.h"
@@ -235,6 +236,7 @@ static int intelfb_create(struct drm_device *dev, uint32_t fb_width, obj_priv->gtt_offset, fbo);mutex_unlock (&dev->struct_mutex); +vga_switcheroo_client_fb_set (dev->pdev, info);return 0 ; out_unpin:
drivers/gpu/drm/nouveau/nouveau_acpi.c +40 -0
@@ -11,6 +11,8 @@#include "nouveau_drm.h" #include "nv50_display.h" +#include <linux/vga_switcheroo.h> +#define NOUVEAU_DSM_SUPPORTED 0x00#define NOUVEAU_DSM_SUPPORTED_FUNCTIONS 0x00
@@ -123,3 +125,41 @@ bool nouveau_dsm_probe(struct drm_device *dev)return true; } + +static int nouveau_dsm_switchto (enum vga_switcheroo_client_id id) +{ +return 0 ; +} + +static int nouveau_dsm_power_state (enum vga_switcheroo_client_id id, +enum vga_switcheroo_state state) +{ +return 0 ; +} + +static int nouveau_dsm_init (void ) +{ +return 0 ; +} + +static int nouveau_dsm_get_client_id (struct pci_dev *pdev) +{ +return VGA_SWITCHEROO_IGD ; +} + +static struct vga_switcheroo_handler nouveau_dsm_handler = { + .switchto = nouveau_dsm_switchto, + .power_state = nouveau_dsm_power_state, + .init = nouveau_dsm_init, + .get_client_id = nouveau_dsm_get_client_id, +}; + +void nouveau_register_dsm_handler (void ) +{ +vga_switcheroo_register_handler (&nouveau_dsm_handler); +} + +void nouveau_unregister_dsm_handler (void ) +{ +vga_switcheroo_unregister_handler (); +}
drivers/gpu/drm/nouveau/nouveau_drv.c +2 -2
@@ -135,7 +135,7 @@ nouveau_pci_remove(struct pci_dev *pdev)drm_put_dev (dev); } -static int +int nouveau_pci_suspend (struct pci_dev *pdev,pm_message_t pm_state) {struct drm_device *dev =pci_get_drvdata (pdev);
@@ -233,7 +233,7 @@ out_abort:return ret; } -static int +int nouveau_pci_resume (struct pci_dev *pdev) {struct drm_device *dev =pci_get_drvdata (pdev);
drivers/gpu/drm/nouveau/nouveau_drv.h +3 -0
@@ -682,6 +682,9 @@ extern int nouveau_ignorelid;extern int nouveau_nofbaccel;extern int nouveau_noaccel; +extern int nouveau_pci_suspend (struct pci_dev *pdev,pm_message_t pm_state); +extern int nouveau_pci_resume (struct pci_dev *pdev); +/* nouveau_state.c */ extern void nouveau_preclose (struct drm_device *dev,struct drm_file *);extern int nouveau_load (struct drm_device *,unsigned long flags);
drivers/gpu/drm/nouveau/nouveau_fbcon.c +2 -0
@@ -36,6 +36,7 @@#include <linux/fb.h> #include <linux/init.h> #include <linux/screen_info.h> +#include <linux/vga_switcheroo.h> #include "drmP.h" #include "drm.h"
@@ -370,6 +371,7 @@ nouveau_fbcon_create(struct drm_device *dev, uint32_t fb_width, nvbo->bo.offset, nvbo);mutex_unlock (&dev->struct_mutex); +vga_switcheroo_client_fb_set (dev->pdev, info);return 0 ; out_unref:
drivers/gpu/drm/nouveau/nouveau_state.c +27 -0
@@ -29,6 +29,7 @@#include "drm_sarea.h" #include "drm_crtc_helper.h" #include <linux/vgaarb.h> +#include <linux/vga_switcheroo.h> #include "nouveau_drv.h" #include "nouveau_drm.h"
@@ -371,6 +372,30 @@ out_err:return ret; } +static void nouveau_switcheroo_set_state (struct pci_dev *pdev, +enum vga_switcheroo_state state) +{ +pm_message_t pmm = { .event =PM_EVENT_SUSPEND }; +if (state =VGA_SWITCHEROO_ON ) { +printk (KERN_ERR "VGA switcheroo: switched nouveau on\n" ); +nouveau_pci_resume (pdev); + }else { +printk (KERN_ERR "VGA switcheroo: switched nouveau off\n" ); +nouveau_pci_suspend (pdev, pmm); + } +} + +static bool nouveau_switcheroo_can_switch (struct pci_dev *pdev) +{ +struct drm_device *dev =pci_get_drvdata (pdev); +bool can_switch; + +spin_lock (&dev->count_lock); + can_switch = (dev->open_count =0 ); +spin_unlock (&dev->count_lock); +return can_switch; +} +int nouveau_card_init (struct drm_device *dev) {
@@ -384,6 +409,8 @@ nouveau_card_init(struct drm_device *dev)return 0 ;vga_client_register (dev->pdev, dev,NULL , nouveau_vga_set_decode); +vga_switcheroo_register_client (dev->pdev, nouveau_switcheroo_set_state, + nouveau_switcheroo_can_switch);/* Initialise internal driver API hooks */ ret =nouveau_init_engine_ptrs (dev);
drivers/gpu/drm/radeon/Makefile +2 -1
@@ -54,7 +54,8 @@ radeon-y += radeon_device.o radeon_kms.o \ radeon_cs.o radeon_bios.o radeon_benchmark.o r100.o r300.o r420.o \ rs400.o rs600.o rs690.o rv515.o r520.o r600.o rv770.o radeon_test.o \ r200.o radeon_legacy_tv.o r600_cs.o r600_blit.o r600_blit_shaders.o \ - r600_blit_kms.o radeon_pm.o atombios_dp.o r600_audio.o r600_hdmi.o + r600_blit_kms.o radeon_pm.o atombios_dp.o r600_audio.o r600_hdmi.o \ + radeon_atpx_handler.o radeon-$(CONFIG_COMPAT) += radeon_ioc32.o
drivers/gpu/drm/radeon/r600_audio.c +3 -0
@@ -163,6 +163,9 @@ int r600_audio_init(struct radeon_device *rdev) rdev->audio_status_bits =0 ; rdev->audio_category_code =0 ; +if (!radeon_audio) +return 0 ; + setup_timer( &rdev->audio_timer, r600_audio_update_hdmi,
drivers/gpu/drm/radeon/radeon.h +8 -0
@@ -118,6 +118,10 @@ struct radeon_device;/* * BIOS. */ +#define ATRM_BIOS_PAGE 4096 + +bool radeon_atrm_supported (struct pci_dev *pdev); +int radeon_atrm_get_bios_chunk (uint8_t *bios,int offset,int len);bool radeon_get_bios (struct radeon_device *rdev);
@@ -838,6 +842,8 @@ struct radeon_device {int audio_bits_per_sample;uint8_t audio_status_bits;uint8_t audio_category_code; + +bool powered_down; }; int radeon_device_init(struct radeon_device *rdev,
@@ -1042,6 +1048,8 @@ extern void radeon_legacy_set_clock_gating(struct radeon_device *rdev, int enablextern void radeon_atom_set_clock_gating (struct radeon_device *rdev,int enable);extern void radeon_ttm_placement_from_domain (struct radeon_bo *rbo,u32 domain);extern bool radeon_ttm_bo_is_radeon_bo (struct ttm_buffer_object *bo); +extern int radeon_resume_kms (struct drm_device *dev); +extern int radeon_suspend_kms (struct drm_device *dev,pm_message_t state);/* r100,rv100,rs100,rv200,rs200,r200,rv250,rs300,rv280 */ struct r100_mc_save {
drivers/gpu/drm/radeon/radeon_atpx_handler.c new file +258 -0
258 lines not on this page · raw message
drivers/gpu/drm/radeon/radeon_bios.c +40 -5
87 lines not on this page · raw message
drivers/gpu/drm/radeon/radeon_device.c +42 -0
78 lines not on this page · raw message
drivers/gpu/drm/radeon/radeon_drv.c +3 -1
@@ -87,7 +87,7 @@ int radeon_testing = 0;int radeon_connector_table =0 ;int radeon_tv =1 ;int radeon_new_pll =1 ; -int radeon_audio =1 ; +int radeon_audio =0 ;MODULE_PARM_DESC (no_wb,"Disable AGP writeback for scratch registers" );module_param_named (no_wb, radeon_no_wb, int,0444 );
@@ -339,6 +339,7 @@ static int __init radeon_init(void) driver = &kms_driver; driver->driver_features |=DRIVER_MODESET ; driver->num_ioctls = radeon_max_kms_ioctl; +radeon_register_atpx_handler (); }/* if the vga console setting is enabled still * let modprobe override it */
@@ -348,6 +349,7 @@ static int __init radeon_init(void) static void __exit radeon_exit(void) {drm_exit (driver); +radeon_unregister_atpx_handler (); }module_init (radeon_init);
drivers/gpu/drm/radeon/radeon_drv.h +3 -0
@@ -455,6 +455,9 @@ extern void r600_blit_swap(struct drm_device *dev, int sx, int sy, int dx, int dy, int w, int h, int src_pitch, int dst_pitch, int cpp); +/* atpx handler */ +void radeon_register_atpx_handler (void ); +void radeon_unregister_atpx_handler (void );/* Flags for stats.boxes */ #define RADEON_BOX_DMA_IDLE 0x1
drivers/gpu/drm/radeon/radeon_fb.c +3 -0
@@ -39,6 +39,8 @@#include "drm_fb_helper.h" +#include <linux/vga_switcheroo.h> +struct radeon_fb_device {struct drm_fb_helper helper;struct radeon_framebuffer *rfb;
@@ -291,6 +293,7 @@ int radeonfb_create(struct drm_device *dev, rfbdev->rdev = rdev;mutex_unlock (&rdev->ddev->struct_mutex); +vga_switcheroo_client_fb_set (rdev->ddev->pdev, info);return 0 ; out_unref:
drivers/gpu/drm/radeon/radeon_kms.c +3 -0
@@ -30,6 +30,8 @@#include "radeon.h" #include "radeon_drm.h" +#include <linux/vga_switcheroo.h> +int radeon_driver_unload_kms (struct drm_device *dev) {struct radeon_device *rdev = dev->dev_private;
@@ -136,6 +138,7 @@ int radeon_driver_firstopen_kms(struct drm_device *dev)void radeon_driver_lastclose_kms (struct drm_device *dev) { +vga_switcheroo_process_delayed_switch (); }int radeon_driver_open_kms (struct drm_device *dev,struct drm_file *file_priv)
drivers/gpu/vga/Kconfig +11 -0
@@ -8,3 +8,14 @@ config VGA_ARB are accessed at same time they need some kind of coordination. Please see Documentation/vgaarbiter.txt for more details. Select this to enable VGA arbiter. + +config VGA_SWITCHEROO + bool "Laptop GPU switching support" + default y + depends on X86 + depends on ACPI + help + Many laptops released in 2008/9/10 have two gpus with a multiplxer + to switch between them. This adds support for dynamic switching when + X isn't running and delayed switching until the next logoff. +
drivers/gpu/vga/Makefile +1 -0
@@ -1 +1,2 @@ obj-$(CONFIG_VGA_ARB) += vgaarb.o +obj-$(CONFIG_VGA_SWITCHEROO) += vga_switcheroo.o
drivers/gpu/vga/vga_switcheroo.c new file +454 -0
454 lines not on this page · raw message
drivers/video/console/fbcon.c +18 -0
@@ -3025,6 +3025,20 @@ static int fbcon_fb_unregistered(struct fb_info *info)return 0 ; } +static void fbcon_remap_all (int idx) +{ +int i; +for (i = first_fb_vc; i <= last_fb_vc; i++) +set_con2fb_map (i, idx,0 ); + +if (con_is_bound (&fb_con)) { +printk (KERN_INFO "fbcon: Remapping primary device, " +"fb%i, to tty %i-%i\n" , idx, + first_fb_vc +1 , last_fb_vc +1 ); + info_idx = idx; + } +} +#ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY static void fbcon_select_primary (struct fb_info *info) {
@@ -3225,6 +3239,10 @@ static int fbcon_event_notify(struct notifier_block *self, caps = event->data;fbcon_get_requirement (info, caps);break ; +case FB_EVENT_REMAP_ALL_CONSOLE : + idx = info->node; +fbcon_remap_all (idx); +break ; } done:return ret;
include/linux/fb.h +2 -0
@@ -543,6 +543,8 @@ struct fb_cursor_user {#define FB_EVENT_GET_REQ 0x0D/* Unbind from the console if possible */ #define FB_EVENT_FB_UNBIND 0x0E +/* CONSOLE-SPECIFIC: remap all consoles to new fb - for vga switcheroo */ +#define FB_EVENT_REMAP_ALL_CONSOLE 0x0Fstruct fb_event {struct fb_info *info;
include/linux/vga_switcheroo.h new file +58 -0
58 lines not on this page · raw message
Signature · 1 line
1.6.5.2
2010/2/26 Dave Airlie <[email protected]>:
Quoted 1 line
v11: fix bug in resuming Intel for 2nd time.
NACK. You totally ignored my previous audio comments.
Signature · 1 line
Rafał
2010/2/26 Dave Airlie <[email protected]>:
Quoted 1 line
v11: fix bug in resuming Intel for 2nd time.
NACK. You totally ignored my previous audio comments.
Signature · 13 lines
Rafał ------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev -- _______________________________________________ Dri-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/dri-devel