1 #include <linux/vgaarb.h>
2 #include <linux/vga_switcheroo.h>
5 #include <drm/drm_crtc_helper.h>
7 #include "nouveau_drm.h"
8 #include "nouveau_acpi.h"
9 #include "nouveau_fbcon.h"
10 #include "nouveau_vga.h"
13 nouveau_vga_set_decode(void *priv
, bool state
)
15 struct nouveau_device
*device
= nouveau_dev(priv
);
17 if (device
->chipset
>= 0x40)
18 nv_wr32(device
, 0x088054, state
);
20 nv_wr32(device
, 0x001854, state
);
23 return VGA_RSRC_LEGACY_IO
| VGA_RSRC_LEGACY_MEM
|
24 VGA_RSRC_NORMAL_IO
| VGA_RSRC_NORMAL_MEM
;
26 return VGA_RSRC_NORMAL_IO
| VGA_RSRC_NORMAL_MEM
;
30 nouveau_switcheroo_set_state(struct pci_dev
*pdev
,
31 enum vga_switcheroo_state state
)
33 struct drm_device
*dev
= pci_get_drvdata(pdev
);
35 if (state
== VGA_SWITCHEROO_ON
) {
36 printk(KERN_ERR
"VGA switcheroo: switched nouveau on\n");
37 dev
->switch_power_state
= DRM_SWITCH_POWER_CHANGING
;
38 nouveau_pmops_resume(&pdev
->dev
);
39 drm_kms_helper_poll_enable(dev
);
40 dev
->switch_power_state
= DRM_SWITCH_POWER_ON
;
42 printk(KERN_ERR
"VGA switcheroo: switched nouveau off\n");
43 dev
->switch_power_state
= DRM_SWITCH_POWER_CHANGING
;
44 drm_kms_helper_poll_disable(dev
);
45 nouveau_switcheroo_optimus_dsm();
46 nouveau_pmops_suspend(&pdev
->dev
);
47 dev
->switch_power_state
= DRM_SWITCH_POWER_OFF
;
52 nouveau_switcheroo_reprobe(struct pci_dev
*pdev
)
54 struct drm_device
*dev
= pci_get_drvdata(pdev
);
55 nouveau_fbcon_output_poll_changed(dev
);
59 nouveau_switcheroo_can_switch(struct pci_dev
*pdev
)
61 struct drm_device
*dev
= pci_get_drvdata(pdev
);
64 spin_lock(&dev
->count_lock
);
65 can_switch
= (dev
->open_count
== 0);
66 spin_unlock(&dev
->count_lock
);
70 static const struct vga_switcheroo_client_ops
71 nouveau_switcheroo_ops
= {
72 .set_gpu_state
= nouveau_switcheroo_set_state
,
73 .reprobe
= nouveau_switcheroo_reprobe
,
74 .can_switch
= nouveau_switcheroo_can_switch
,
78 nouveau_vga_init(struct nouveau_drm
*drm
)
80 struct drm_device
*dev
= drm
->dev
;
81 vga_client_register(dev
->pdev
, dev
, NULL
, nouveau_vga_set_decode
);
82 vga_switcheroo_register_client(dev
->pdev
, &nouveau_switcheroo_ops
);
86 nouveau_vga_fini(struct nouveau_drm
*drm
)
88 struct drm_device
*dev
= drm
->dev
;
89 vga_switcheroo_unregister_client(dev
->pdev
);
90 vga_client_register(dev
->pdev
, NULL
, NULL
, NULL
);
95 nouveau_vga_lastclose(struct drm_device
*dev
)
97 vga_switcheroo_process_delayed_switch();