blob: 1f0b6d238cfaa01a4527e4b02ee0caf8229aa269 [file] [log] [blame]
Ben Skeggs6ee73862009-12-11 19:24:15 +10001#include <linux/pci.h>
2#include <linux/acpi.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09003#include <linux/slab.h>
Dave Airlie81161882010-12-06 12:57:45 +10004#include <linux/mxm-wmi.h>
Dave Airlie6a9ee8a2010-02-01 15:38:10 +10005#include <linux/vga_switcheroo.h>
Linus Torvalds612a9aa2012-10-03 23:29:23 -07006#include <drm/drm_edid.h>
Lv Zheng8b484632013-12-03 08:49:16 +08007#include <acpi/video.h>
Ben Skeggsc0077062012-07-26 08:51:21 +10008
9#include "nouveau_drm.h"
10#include "nouveau_acpi.h"
11
Ben Skeggs6ee73862009-12-11 19:24:15 +100012#define NOUVEAU_DSM_LED 0x02
13#define NOUVEAU_DSM_LED_STATE 0x00
14#define NOUVEAU_DSM_LED_OFF 0x10
15#define NOUVEAU_DSM_LED_STAMINA 0x11
16#define NOUVEAU_DSM_LED_SPEED 0x12
17
18#define NOUVEAU_DSM_POWER 0x03
19#define NOUVEAU_DSM_POWER_STATE 0x00
20#define NOUVEAU_DSM_POWER_SPEED 0x01
21#define NOUVEAU_DSM_POWER_STAMINA 0x02
22
Dave Airlie5addcf02012-09-10 14:20:51 +100023#define NOUVEAU_DSM_OPTIMUS_CAPS 0x1A
24#define NOUVEAU_DSM_OPTIMUS_FLAGS 0x1B
25
26#define NOUVEAU_DSM_OPTIMUS_POWERDOWN_PS3 (3 << 24)
27#define NOUVEAU_DSM_OPTIMUS_NO_POWERDOWN_PS3 (2 << 24)
28#define NOUVEAU_DSM_OPTIMUS_FLAGS_CHANGED (1)
29
30#define NOUVEAU_DSM_OPTIMUS_SET_POWERDOWN (NOUVEAU_DSM_OPTIMUS_POWERDOWN_PS3 | NOUVEAU_DSM_OPTIMUS_FLAGS_CHANGED)
31
32/* result of the optimus caps function */
33#define OPTIMUS_ENABLED (1 << 0)
34#define OPTIMUS_STATUS_MASK (3 << 3)
35#define OPTIMUS_STATUS_OFF (0 << 3)
36#define OPTIMUS_STATUS_ON_ENABLED (1 << 3)
37#define OPTIMUS_STATUS_PWR_STABLE (3 << 3)
38#define OPTIMUS_DISPLAY_HOTPLUG (1 << 6)
39#define OPTIMUS_CAPS_MASK (7 << 24)
40#define OPTIMUS_DYNAMIC_PWR_CAP (1 << 24)
41
42#define OPTIMUS_AUDIO_CAPS_MASK (3 << 27)
43#define OPTIMUS_HDA_CODEC_MASK (2 << 27) /* hda bios control */
Peter Lekensteynd0992302011-12-17 12:54:04 +010044
Dave Airlie6a9ee8a2010-02-01 15:38:10 +100045static struct nouveau_dsm_priv {
46 bool dsm_detected;
Dave Airlief19467c2011-03-22 14:10:27 +100047 bool optimus_detected;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +100048 acpi_handle dhandle;
Dave Airlieafeb3e12010-04-07 13:55:09 +100049 acpi_handle rom_handle;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +100050} nouveau_dsm_priv;
Ben Skeggs6ee73862009-12-11 19:24:15 +100051
Dave Airliec839d742012-11-02 11:04:27 +100052bool nouveau_is_optimus(void) {
53 return nouveau_dsm_priv.optimus_detected;
54}
55
56bool nouveau_is_v1_dsm(void) {
57 return nouveau_dsm_priv.dsm_detected;
58}
59
Dave Airlief19467c2011-03-22 14:10:27 +100060#define NOUVEAU_DSM_HAS_MUX 0x1
61#define NOUVEAU_DSM_HAS_OPT 0x2
62
Dave Airlie6a9ee8a2010-02-01 15:38:10 +100063static const char nouveau_dsm_muid[] = {
64 0xA0, 0xA0, 0x95, 0x9D, 0x60, 0x00, 0x48, 0x4D,
65 0xB3, 0x4D, 0x7E, 0x5F, 0xEA, 0x12, 0x9F, 0xD4,
66};
67
Dave Airlief19467c2011-03-22 14:10:27 +100068static const char nouveau_op_dsm_muid[] = {
69 0xF8, 0xD8, 0x86, 0xA4, 0xDA, 0x0B, 0x1B, 0x47,
70 0xA7, 0x2B, 0x60, 0x42, 0xA6, 0xB5, 0xBE, 0xE0,
71};
72
73static int nouveau_optimus_dsm(acpi_handle handle, int func, int arg, uint32_t *result)
74{
75 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
76 struct acpi_object_list input;
77 union acpi_object params[4];
78 union acpi_object *obj;
Peter Lekensteynd0992302011-12-17 12:54:04 +010079 int i, err;
80 char args_buff[4];
Dave Airlief19467c2011-03-22 14:10:27 +100081
82 input.count = 4;
83 input.pointer = params;
84 params[0].type = ACPI_TYPE_BUFFER;
85 params[0].buffer.length = sizeof(nouveau_op_dsm_muid);
86 params[0].buffer.pointer = (char *)nouveau_op_dsm_muid;
87 params[1].type = ACPI_TYPE_INTEGER;
88 params[1].integer.value = 0x00000100;
89 params[2].type = ACPI_TYPE_INTEGER;
90 params[2].integer.value = func;
91 params[3].type = ACPI_TYPE_BUFFER;
Peter Lekensteynd0992302011-12-17 12:54:04 +010092 params[3].buffer.length = 4;
93 /* ACPI is little endian, AABBCCDD becomes {DD,CC,BB,AA} */
94 for (i = 0; i < 4; i++)
95 args_buff[i] = (arg >> i * 8) & 0xFF;
96 params[3].buffer.pointer = args_buff;
Dave Airlief19467c2011-03-22 14:10:27 +100097
98 err = acpi_evaluate_object(handle, "_DSM", &input, &output);
99 if (err) {
100 printk(KERN_INFO "failed to evaluate _DSM: %d\n", err);
101 return err;
102 }
103
104 obj = (union acpi_object *)output.pointer;
105
106 if (obj->type == ACPI_TYPE_INTEGER)
107 if (obj->integer.value == 0x80000002) {
108 return -ENODEV;
109 }
110
111 if (obj->type == ACPI_TYPE_BUFFER) {
112 if (obj->buffer.length == 4 && result) {
113 *result = 0;
114 *result |= obj->buffer.pointer[0];
115 *result |= (obj->buffer.pointer[1] << 8);
116 *result |= (obj->buffer.pointer[2] << 16);
117 *result |= (obj->buffer.pointer[3] << 24);
118 }
119 }
120
121 kfree(output.pointer);
122 return 0;
123}
124
Francisco Jerez6e86e042010-07-03 18:36:39 +0200125static int nouveau_dsm(acpi_handle handle, int func, int arg, uint32_t *result)
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000126{
Ben Skeggs6ee73862009-12-11 19:24:15 +1000127 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
128 struct acpi_object_list input;
129 union acpi_object params[4];
130 union acpi_object *obj;
131 int err;
132
Ben Skeggs6ee73862009-12-11 19:24:15 +1000133 input.count = 4;
134 input.pointer = params;
135 params[0].type = ACPI_TYPE_BUFFER;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000136 params[0].buffer.length = sizeof(nouveau_dsm_muid);
137 params[0].buffer.pointer = (char *)nouveau_dsm_muid;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000138 params[1].type = ACPI_TYPE_INTEGER;
139 params[1].integer.value = 0x00000102;
140 params[2].type = ACPI_TYPE_INTEGER;
141 params[2].integer.value = func;
142 params[3].type = ACPI_TYPE_INTEGER;
143 params[3].integer.value = arg;
144
145 err = acpi_evaluate_object(handle, "_DSM", &input, &output);
146 if (err) {
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000147 printk(KERN_INFO "failed to evaluate _DSM: %d\n", err);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000148 return err;
149 }
150
151 obj = (union acpi_object *)output.pointer;
152
153 if (obj->type == ACPI_TYPE_INTEGER)
154 if (obj->integer.value == 0x80000002)
155 return -ENODEV;
156
157 if (obj->type == ACPI_TYPE_BUFFER) {
158 if (obj->buffer.length == 4 && result) {
159 *result = 0;
160 *result |= obj->buffer.pointer[0];
161 *result |= (obj->buffer.pointer[1] << 8);
162 *result |= (obj->buffer.pointer[2] << 16);
163 *result |= (obj->buffer.pointer[3] << 24);
164 }
165 }
166
167 kfree(output.pointer);
168 return 0;
169}
170
Peter Lekensteyn9075e852011-12-17 12:53:43 +0100171/* Returns 1 if a DSM function is usable and 0 otherwise */
172static int nouveau_test_dsm(acpi_handle test_handle,
173 int (*dsm_func)(acpi_handle, int, int, uint32_t *),
174 int sfnc)
175{
176 u32 result = 0;
177
178 /* Function 0 returns a Buffer containing available functions. The args
179 * parameter is ignored for function 0, so just put 0 in it */
180 if (dsm_func(test_handle, 0, 0, &result))
181 return 0;
182
183 /* ACPI Spec v4 9.14.1: if bit 0 is zero, no function is supported. If
184 * the n-th bit is enabled, function n is supported */
185 return result & 1 && result & (1 << sfnc);
186}
187
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000188static int nouveau_dsm_switch_mux(acpi_handle handle, int mux_id)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000189{
Dave Airlie000703f2011-05-09 11:40:25 +1000190 mxm_wmi_call_mxmx(mux_id == NOUVEAU_DSM_LED_STAMINA ? MXM_MXDS_ADAPTER_IGD : MXM_MXDS_ADAPTER_0);
Dave Airlie81161882010-12-06 12:57:45 +1000191 mxm_wmi_call_mxds(mux_id == NOUVEAU_DSM_LED_STAMINA ? MXM_MXDS_ADAPTER_IGD : MXM_MXDS_ADAPTER_0);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000192 return nouveau_dsm(handle, NOUVEAU_DSM_LED, mux_id, NULL);
193}
Ben Skeggs6ee73862009-12-11 19:24:15 +1000194
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000195static int nouveau_dsm_set_discrete_state(acpi_handle handle, enum vga_switcheroo_state state)
196{
197 int arg;
198 if (state == VGA_SWITCHEROO_ON)
199 arg = NOUVEAU_DSM_POWER_SPEED;
200 else
201 arg = NOUVEAU_DSM_POWER_STAMINA;
202 nouveau_dsm(handle, NOUVEAU_DSM_POWER, arg, NULL);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000203 return 0;
204}
205
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000206static int nouveau_dsm_switchto(enum vga_switcheroo_client_id id)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000207{
Dave Airliec839d742012-11-02 11:04:27 +1000208 if (!nouveau_dsm_priv.dsm_detected)
Peter Lekensteynd0992302011-12-17 12:54:04 +0100209 return 0;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000210 if (id == VGA_SWITCHEROO_IGD)
Dave Airliefc5ea292010-05-31 17:10:52 +1000211 return nouveau_dsm_switch_mux(nouveau_dsm_priv.dhandle, NOUVEAU_DSM_LED_STAMINA);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000212 else
Dave Airliefc5ea292010-05-31 17:10:52 +1000213 return nouveau_dsm_switch_mux(nouveau_dsm_priv.dhandle, NOUVEAU_DSM_LED_SPEED);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000214}
Ben Skeggs6ee73862009-12-11 19:24:15 +1000215
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000216static int nouveau_dsm_power_state(enum vga_switcheroo_client_id id,
217 enum vga_switcheroo_state state)
218{
219 if (id == VGA_SWITCHEROO_IGD)
220 return 0;
221
Peter Lekensteynd0992302011-12-17 12:54:04 +0100222 /* Optimus laptops have the card already disabled in
223 * nouveau_switcheroo_set_state */
Dave Airliec839d742012-11-02 11:04:27 +1000224 if (!nouveau_dsm_priv.dsm_detected)
Peter Lekensteynd0992302011-12-17 12:54:04 +0100225 return 0;
226
Dave Airliefc5ea292010-05-31 17:10:52 +1000227 return nouveau_dsm_set_discrete_state(nouveau_dsm_priv.dhandle, state);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000228}
229
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000230static int nouveau_dsm_get_client_id(struct pci_dev *pdev)
231{
Dave Airlied1fbd9232010-12-06 12:56:44 +1000232 /* easy option one - intel vendor ID means Integrated */
233 if (pdev->vendor == PCI_VENDOR_ID_INTEL)
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000234 return VGA_SWITCHEROO_IGD;
Dave Airlied1fbd9232010-12-06 12:56:44 +1000235
236 /* is this device on Bus 0? - this may need improving */
237 if (pdev->bus->number == 0)
238 return VGA_SWITCHEROO_IGD;
239
240 return VGA_SWITCHEROO_DIS;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000241}
242
243static struct vga_switcheroo_handler nouveau_dsm_handler = {
244 .switchto = nouveau_dsm_switchto,
245 .power_state = nouveau_dsm_power_state,
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000246 .get_client_id = nouveau_dsm_get_client_id,
247};
248
Dave Airlief19467c2011-03-22 14:10:27 +1000249static int nouveau_dsm_pci_probe(struct pci_dev *pdev)
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000250{
Zhang Rui187b5b52013-09-03 08:32:00 +0800251 acpi_handle dhandle;
Peter Lekensteyn9075e852011-12-17 12:53:43 +0100252 int retval = 0;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000253
Rafael J. Wysocki3a83f992013-11-14 23:17:21 +0100254 dhandle = ACPI_HANDLE(&pdev->dev);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000255 if (!dhandle)
256 return false;
Dave Airlieafeb3e12010-04-07 13:55:09 +1000257
Zhang Rui187b5b52013-09-03 08:32:00 +0800258 if (!acpi_has_method(dhandle, "_DSM"))
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000259 return false;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000260
Peter Lekensteyn9075e852011-12-17 12:53:43 +0100261 if (nouveau_test_dsm(dhandle, nouveau_dsm, NOUVEAU_DSM_POWER))
Dave Airlief19467c2011-03-22 14:10:27 +1000262 retval |= NOUVEAU_DSM_HAS_MUX;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000263
Peter Lekensteyn9075e852011-12-17 12:53:43 +0100264 if (nouveau_test_dsm(dhandle, nouveau_optimus_dsm,
Dave Airlie5addcf02012-09-10 14:20:51 +1000265 NOUVEAU_DSM_OPTIMUS_CAPS))
Dave Airlief19467c2011-03-22 14:10:27 +1000266 retval |= NOUVEAU_DSM_HAS_OPT;
267
Dave Airlie5addcf02012-09-10 14:20:51 +1000268 if (retval & NOUVEAU_DSM_HAS_OPT) {
269 uint32_t result;
270 nouveau_optimus_dsm(dhandle, NOUVEAU_DSM_OPTIMUS_CAPS, 0,
271 &result);
272 dev_info(&pdev->dev, "optimus capabilities: %s, status %s%s\n",
273 (result & OPTIMUS_ENABLED) ? "enabled" : "disabled",
274 (result & OPTIMUS_DYNAMIC_PWR_CAP) ? "dynamic power, " : "",
275 (result & OPTIMUS_HDA_CODEC_MASK) ? "hda bios codec supported" : "");
276 }
Dave Airlief19467c2011-03-22 14:10:27 +1000277 if (retval)
278 nouveau_dsm_priv.dhandle = dhandle;
279
280 return retval;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000281}
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000282
283static bool nouveau_dsm_detect(void)
284{
285 char acpi_method_name[255] = { 0 };
286 struct acpi_buffer buffer = {sizeof(acpi_method_name), acpi_method_name};
287 struct pci_dev *pdev = NULL;
288 int has_dsm = 0;
Dave Airlieaddde4e2012-05-02 20:26:24 +0100289 int has_optimus = 0;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000290 int vga_count = 0;
Dave Airlie81161882010-12-06 12:57:45 +1000291 bool guid_valid;
Dave Airlief19467c2011-03-22 14:10:27 +1000292 int retval;
293 bool ret = false;
Dave Airlie81161882010-12-06 12:57:45 +1000294
Dave Airlief19467c2011-03-22 14:10:27 +1000295 /* lookup the MXM GUID */
Dave Airlie81161882010-12-06 12:57:45 +1000296 guid_valid = mxm_wmi_supported();
Dave Airlie81161882010-12-06 12:57:45 +1000297
Dave Airlief19467c2011-03-22 14:10:27 +1000298 if (guid_valid)
299 printk("MXM: GUID detected in BIOS\n");
Dave Airlieafeb3e12010-04-07 13:55:09 +1000300
Dave Airlief19467c2011-03-22 14:10:27 +1000301 /* now do DSM detection */
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000302 while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev)) != NULL) {
303 vga_count++;
304
Dave Airlief19467c2011-03-22 14:10:27 +1000305 retval = nouveau_dsm_pci_probe(pdev);
Dave Airlief19467c2011-03-22 14:10:27 +1000306 if (retval & NOUVEAU_DSM_HAS_MUX)
307 has_dsm |= 1;
308 if (retval & NOUVEAU_DSM_HAS_OPT)
309 has_optimus = 1;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000310 }
311
Emil Velikov4c60fac2013-10-09 08:25:16 +0100312 while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_3D << 8, pdev)) != NULL) {
313 vga_count++;
314
315 retval = nouveau_dsm_pci_probe(pdev);
316 if (retval & NOUVEAU_DSM_HAS_MUX)
317 has_dsm |= 1;
318 if (retval & NOUVEAU_DSM_HAS_OPT)
319 has_optimus = 1;
320 }
321
Dave Airliec839d742012-11-02 11:04:27 +1000322 /* find the optimus DSM or the old v1 DSM */
323 if (has_optimus == 1) {
324 acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
325 &buffer);
326 printk(KERN_INFO "VGA switcheroo: detected Optimus DSM method %s handle\n",
327 acpi_method_name);
328 nouveau_dsm_priv.optimus_detected = true;
329 ret = true;
330 } else if (vga_count == 2 && has_dsm && guid_valid) {
Peter Lekensteynd0992302011-12-17 12:54:04 +0100331 acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
332 &buffer);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000333 printk(KERN_INFO "VGA switcheroo: detected DSM switching method %s handle\n",
Peter Lekensteynd0992302011-12-17 12:54:04 +0100334 acpi_method_name);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000335 nouveau_dsm_priv.dsm_detected = true;
Dave Airlief19467c2011-03-22 14:10:27 +1000336 ret = true;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000337 }
Dave Airlief19467c2011-03-22 14:10:27 +1000338
Dave Airlief19467c2011-03-22 14:10:27 +1000339
340 return ret;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000341}
342
343void nouveau_register_dsm_handler(void)
344{
345 bool r;
346
347 r = nouveau_dsm_detect();
348 if (!r)
349 return;
350
351 vga_switcheroo_register_handler(&nouveau_dsm_handler);
352}
353
Peter Lekensteynd0992302011-12-17 12:54:04 +0100354/* Must be called for Optimus models before the card can be turned off */
355void nouveau_switcheroo_optimus_dsm(void)
356{
357 u32 result = 0;
358 if (!nouveau_dsm_priv.optimus_detected)
359 return;
360
Dave Airlie5addcf02012-09-10 14:20:51 +1000361 nouveau_optimus_dsm(nouveau_dsm_priv.dhandle, NOUVEAU_DSM_OPTIMUS_FLAGS,
362 0x3, &result);
363
364 nouveau_optimus_dsm(nouveau_dsm_priv.dhandle, NOUVEAU_DSM_OPTIMUS_CAPS,
365 NOUVEAU_DSM_OPTIMUS_SET_POWERDOWN, &result);
366
Peter Lekensteynd0992302011-12-17 12:54:04 +0100367}
368
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000369void nouveau_unregister_dsm_handler(void)
370{
Andreas Heider2f3787a2012-05-21 00:14:50 +0100371 if (nouveau_dsm_priv.optimus_detected || nouveau_dsm_priv.dsm_detected)
372 vga_switcheroo_unregister_handler();
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000373}
Dave Airlieafeb3e12010-04-07 13:55:09 +1000374
375/* retrieve the ROM in 4k blocks */
376static int nouveau_rom_call(acpi_handle rom_handle, uint8_t *bios,
377 int offset, int len)
378{
379 acpi_status status;
380 union acpi_object rom_arg_elements[2], *obj;
381 struct acpi_object_list rom_arg;
382 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL};
383
384 rom_arg.count = 2;
385 rom_arg.pointer = &rom_arg_elements[0];
386
387 rom_arg_elements[0].type = ACPI_TYPE_INTEGER;
388 rom_arg_elements[0].integer.value = offset;
389
390 rom_arg_elements[1].type = ACPI_TYPE_INTEGER;
391 rom_arg_elements[1].integer.value = len;
392
393 status = acpi_evaluate_object(rom_handle, NULL, &rom_arg, &buffer);
394 if (ACPI_FAILURE(status)) {
395 printk(KERN_INFO "failed to evaluate ROM got %s\n", acpi_format_exception(status));
396 return -ENODEV;
397 }
398 obj = (union acpi_object *)buffer.pointer;
399 memcpy(bios+offset, obj->buffer.pointer, len);
400 kfree(buffer.pointer);
401 return len;
402}
403
404bool nouveau_acpi_rom_supported(struct pci_dev *pdev)
405{
406 acpi_status status;
407 acpi_handle dhandle, rom_handle;
408
Dave Airlief19467c2011-03-22 14:10:27 +1000409 if (!nouveau_dsm_priv.dsm_detected && !nouveau_dsm_priv.optimus_detected)
Dave Airlieafeb3e12010-04-07 13:55:09 +1000410 return false;
411
Rafael J. Wysocki3a83f992013-11-14 23:17:21 +0100412 dhandle = ACPI_HANDLE(&pdev->dev);
Dave Airlieafeb3e12010-04-07 13:55:09 +1000413 if (!dhandle)
414 return false;
415
416 status = acpi_get_handle(dhandle, "_ROM", &rom_handle);
417 if (ACPI_FAILURE(status))
418 return false;
419
420 nouveau_dsm_priv.rom_handle = rom_handle;
421 return true;
422}
423
424int nouveau_acpi_get_bios_chunk(uint8_t *bios, int offset, int len)
425{
426 return nouveau_rom_call(nouveau_dsm_priv.rom_handle, bios, offset, len);
427}
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000428
Ben Skeggsc0077062012-07-26 08:51:21 +1000429void *
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000430nouveau_acpi_edid(struct drm_device *dev, struct drm_connector *connector)
431{
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000432 struct acpi_device *acpidev;
433 acpi_handle handle;
434 int type, ret;
435 void *edid;
436
437 switch (connector->connector_type) {
438 case DRM_MODE_CONNECTOR_LVDS:
439 case DRM_MODE_CONNECTOR_eDP:
440 type = ACPI_VIDEO_DISPLAY_LCD;
441 break;
442 default:
Ben Skeggsc0077062012-07-26 08:51:21 +1000443 return NULL;
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000444 }
445
Rafael J. Wysocki3a83f992013-11-14 23:17:21 +0100446 handle = ACPI_HANDLE(&dev->pdev->dev);
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000447 if (!handle)
Ben Skeggsc0077062012-07-26 08:51:21 +1000448 return NULL;
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000449
450 ret = acpi_bus_get_device(handle, &acpidev);
451 if (ret)
Ben Skeggsc0077062012-07-26 08:51:21 +1000452 return NULL;
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000453
454 ret = acpi_video_get_edid(acpidev, type, -1, &edid);
455 if (ret < 0)
Ben Skeggsc0077062012-07-26 08:51:21 +1000456 return NULL;
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000457
Ben Skeggsc0077062012-07-26 08:51:21 +1000458 return kmemdup(edid, EDID_LENGTH, GFP_KERNEL);
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000459}