2 #include <linux/acpi.h>
3 #include <acpi/acpi_drivers.h>
4 #include <acpi/acpi_bus.h>
9 #include "drm_crtc_helper.h"
10 #include "nouveau_drv.h"
11 #include "nouveau_drm.h"
12 #include "nv50_display.h"
14 #define NOUVEAU_DSM_SUPPORTED 0x00
15 #define NOUVEAU_DSM_SUPPORTED_FUNCTIONS 0x00
17 #define NOUVEAU_DSM_ACTIVE 0x01
18 #define NOUVEAU_DSM_ACTIVE_QUERY 0x00
20 #define NOUVEAU_DSM_LED 0x02
21 #define NOUVEAU_DSM_LED_STATE 0x00
22 #define NOUVEAU_DSM_LED_OFF 0x10
23 #define NOUVEAU_DSM_LED_STAMINA 0x11
24 #define NOUVEAU_DSM_LED_SPEED 0x12
26 #define NOUVEAU_DSM_POWER 0x03
27 #define NOUVEAU_DSM_POWER_STATE 0x00
28 #define NOUVEAU_DSM_POWER_SPEED 0x01
29 #define NOUVEAU_DSM_POWER_STAMINA 0x02
31 static int nouveau_dsm(struct drm_device
*dev
, int func
, int arg
, int *result
)
33 static char muid
[] = {
34 0xA0, 0xA0, 0x95, 0x9D, 0x60, 0x00, 0x48, 0x4D,
35 0xB3, 0x4D, 0x7E, 0x5F, 0xEA, 0x12, 0x9F, 0xD4,
38 struct pci_dev
*pdev
= dev
->pdev
;
39 struct acpi_handle
*handle
;
40 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
41 struct acpi_object_list input
;
42 union acpi_object params
[4];
43 union acpi_object
*obj
;
46 handle
= DEVICE_ACPI_HANDLE(&pdev
->dev
);
52 input
.pointer
= params
;
53 params
[0].type
= ACPI_TYPE_BUFFER
;
54 params
[0].buffer
.length
= sizeof(muid
);
55 params
[0].buffer
.pointer
= (char *)muid
;
56 params
[1].type
= ACPI_TYPE_INTEGER
;
57 params
[1].integer
.value
= 0x00000102;
58 params
[2].type
= ACPI_TYPE_INTEGER
;
59 params
[2].integer
.value
= func
;
60 params
[3].type
= ACPI_TYPE_INTEGER
;
61 params
[3].integer
.value
= arg
;
63 err
= acpi_evaluate_object(handle
, "_DSM", &input
, &output
);
65 NV_INFO(dev
, "failed to evaluate _DSM: %d\n", err
);
69 obj
= (union acpi_object
*)output
.pointer
;
71 if (obj
->type
== ACPI_TYPE_INTEGER
)
72 if (obj
->integer
.value
== 0x80000002)
75 if (obj
->type
== ACPI_TYPE_BUFFER
) {
76 if (obj
->buffer
.length
== 4 && result
) {
78 *result
|= obj
->buffer
.pointer
[0];
79 *result
|= (obj
->buffer
.pointer
[1] << 8);
80 *result
|= (obj
->buffer
.pointer
[2] << 16);
81 *result
|= (obj
->buffer
.pointer
[3] << 24);
85 kfree(output
.pointer
);
89 int nouveau_hybrid_setup(struct drm_device
*dev
)
93 if (nouveau_dsm(dev
, NOUVEAU_DSM_ACTIVE
, NOUVEAU_DSM_ACTIVE_QUERY
,
97 NV_INFO(dev
, "_DSM hardware status gave 0x%x\n", result
);
99 if (result
& 0x1) { /* Stamina mode - disable the external GPU */
100 nouveau_dsm(dev
, NOUVEAU_DSM_LED
, NOUVEAU_DSM_LED_STAMINA
,
102 nouveau_dsm(dev
, NOUVEAU_DSM_POWER
, NOUVEAU_DSM_POWER_STAMINA
,
104 } else { /* Ensure that the external GPU is enabled */
105 nouveau_dsm(dev
, NOUVEAU_DSM_LED
, NOUVEAU_DSM_LED_SPEED
, NULL
);
106 nouveau_dsm(dev
, NOUVEAU_DSM_POWER
, NOUVEAU_DSM_POWER_SPEED
,
113 bool nouveau_dsm_probe(struct drm_device
*dev
)
117 if (nouveau_dsm(dev
, NOUVEAU_DSM_SUPPORTED
,
118 NOUVEAU_DSM_SUPPORTED_FUNCTIONS
, &support
))