blob: dd7d2e18271940ea3e9f6d9a90b09140c767e73e [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>
Ben Skeggs6ee73862009-12-11 19:24:15 +10004#include <acpi/acpi_drivers.h>
5#include <acpi/acpi_bus.h>
Ben Skeggsa6ed76d2010-07-12 15:33:07 +10006#include <acpi/video.h>
Dave Airlie81161882010-12-06 12:57:45 +10007#include <acpi/acpi.h>
8#include <linux/mxm-wmi.h>
Ben Skeggs6ee73862009-12-11 19:24:15 +10009
Dave Airlie6a9ee8a2010-02-01 15:38:10 +100010#include <linux/vga_switcheroo.h>
11
Linus Torvalds612a9aa2012-10-03 23:29:23 -070012#include <drm/drm_edid.h>
Ben Skeggsc0077062012-07-26 08:51:21 +100013
14#include "nouveau_drm.h"
15#include "nouveau_acpi.h"
16
Ben Skeggs6ee73862009-12-11 19:24:15 +100017#define NOUVEAU_DSM_LED 0x02
18#define NOUVEAU_DSM_LED_STATE 0x00
19#define NOUVEAU_DSM_LED_OFF 0x10
20#define NOUVEAU_DSM_LED_STAMINA 0x11
21#define NOUVEAU_DSM_LED_SPEED 0x12
22
23#define NOUVEAU_DSM_POWER 0x03
24#define NOUVEAU_DSM_POWER_STATE 0x00
25#define NOUVEAU_DSM_POWER_SPEED 0x01
26#define NOUVEAU_DSM_POWER_STAMINA 0x02
27
Dave Airlie5addcf02012-09-10 14:20:51 +100028#define NOUVEAU_DSM_OPTIMUS_CAPS 0x1A
29#define NOUVEAU_DSM_OPTIMUS_FLAGS 0x1B
30
31#define NOUVEAU_DSM_OPTIMUS_POWERDOWN_PS3 (3 << 24)
32#define NOUVEAU_DSM_OPTIMUS_NO_POWERDOWN_PS3 (2 << 24)
33#define NOUVEAU_DSM_OPTIMUS_FLAGS_CHANGED (1)
34
35#define NOUVEAU_DSM_OPTIMUS_SET_POWERDOWN (NOUVEAU_DSM_OPTIMUS_POWERDOWN_PS3 | NOUVEAU_DSM_OPTIMUS_FLAGS_CHANGED)
36
37/* result of the optimus caps function */
38#define OPTIMUS_ENABLED (1 << 0)
39#define OPTIMUS_STATUS_MASK (3 << 3)
40#define OPTIMUS_STATUS_OFF (0 << 3)
41#define OPTIMUS_STATUS_ON_ENABLED (1 << 3)
42#define OPTIMUS_STATUS_PWR_STABLE (3 << 3)
43#define OPTIMUS_DISPLAY_HOTPLUG (1 << 6)
44#define OPTIMUS_CAPS_MASK (7 << 24)
45#define OPTIMUS_DYNAMIC_PWR_CAP (1 << 24)
46
47#define OPTIMUS_AUDIO_CAPS_MASK (3 << 27)
48#define OPTIMUS_HDA_CODEC_MASK (2 << 27) /* hda bios control */
Peter Lekensteynd0992302011-12-17 12:54:04 +010049
Dave Airlie6a9ee8a2010-02-01 15:38:10 +100050static struct nouveau_dsm_priv {
51 bool dsm_detected;
Dave Airlief19467c2011-03-22 14:10:27 +100052 bool optimus_detected;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +100053 acpi_handle dhandle;
Dave Airlieafeb3e12010-04-07 13:55:09 +100054 acpi_handle rom_handle;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +100055} nouveau_dsm_priv;
Ben Skeggs6ee73862009-12-11 19:24:15 +100056
Dave Airliec839d742012-11-02 11:04:27 +100057bool nouveau_is_optimus(void) {
58 return nouveau_dsm_priv.optimus_detected;
59}
60
61bool nouveau_is_v1_dsm(void) {
62 return nouveau_dsm_priv.dsm_detected;
63}
64
Dave Airlief19467c2011-03-22 14:10:27 +100065#define NOUVEAU_DSM_HAS_MUX 0x1
66#define NOUVEAU_DSM_HAS_OPT 0x2
67
Dave Airlie6a9ee8a2010-02-01 15:38:10 +100068static const char nouveau_dsm_muid[] = {
69 0xA0, 0xA0, 0x95, 0x9D, 0x60, 0x00, 0x48, 0x4D,
70 0xB3, 0x4D, 0x7E, 0x5F, 0xEA, 0x12, 0x9F, 0xD4,
71};
72
Dave Airlief19467c2011-03-22 14:10:27 +100073static const char nouveau_op_dsm_muid[] = {
74 0xF8, 0xD8, 0x86, 0xA4, 0xDA, 0x0B, 0x1B, 0x47,
75 0xA7, 0x2B, 0x60, 0x42, 0xA6, 0xB5, 0xBE, 0xE0,
76};
77
78static int nouveau_optimus_dsm(acpi_handle handle, int func, int arg, uint32_t *result)
79{
80 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
81 struct acpi_object_list input;
82 union acpi_object params[4];
83 union acpi_object *obj;
Peter Lekensteynd0992302011-12-17 12:54:04 +010084 int i, err;
85 char args_buff[4];
Dave Airlief19467c2011-03-22 14:10:27 +100086
87 input.count = 4;
88 input.pointer = params;
89 params[0].type = ACPI_TYPE_BUFFER;
90 params[0].buffer.length = sizeof(nouveau_op_dsm_muid);
91 params[0].buffer.pointer = (char *)nouveau_op_dsm_muid;
92 params[1].type = ACPI_TYPE_INTEGER;
93 params[1].integer.value = 0x00000100;
94 params[2].type = ACPI_TYPE_INTEGER;
95 params[2].integer.value = func;
96 params[3].type = ACPI_TYPE_BUFFER;
Peter Lekensteynd0992302011-12-17 12:54:04 +010097 params[3].buffer.length = 4;
98 /* ACPI is little endian, AABBCCDD becomes {DD,CC,BB,AA} */
99 for (i = 0; i < 4; i++)
100 args_buff[i] = (arg >> i * 8) & 0xFF;
101 params[3].buffer.pointer = args_buff;
Dave Airlief19467c2011-03-22 14:10:27 +1000102
103 err = acpi_evaluate_object(handle, "_DSM", &input, &output);
104 if (err) {
105 printk(KERN_INFO "failed to evaluate _DSM: %d\n", err);
106 return err;
107 }
108
109 obj = (union acpi_object *)output.pointer;
110
111 if (obj->type == ACPI_TYPE_INTEGER)
112 if (obj->integer.value == 0x80000002) {
113 return -ENODEV;
114 }
115
116 if (obj->type == ACPI_TYPE_BUFFER) {
117 if (obj->buffer.length == 4 && result) {
118 *result = 0;
119 *result |= obj->buffer.pointer[0];
120 *result |= (obj->buffer.pointer[1] << 8);
121 *result |= (obj->buffer.pointer[2] << 16);
122 *result |= (obj->buffer.pointer[3] << 24);
123 }
124 }
125
126 kfree(output.pointer);
127 return 0;
128}
129
Francisco Jerez6e86e042010-07-03 18:36:39 +0200130static int nouveau_dsm(acpi_handle handle, int func, int arg, uint32_t *result)
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000131{
Ben Skeggs6ee73862009-12-11 19:24:15 +1000132 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
133 struct acpi_object_list input;
134 union acpi_object params[4];
135 union acpi_object *obj;
136 int err;
137
Ben Skeggs6ee73862009-12-11 19:24:15 +1000138 input.count = 4;
139 input.pointer = params;
140 params[0].type = ACPI_TYPE_BUFFER;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000141 params[0].buffer.length = sizeof(nouveau_dsm_muid);
142 params[0].buffer.pointer = (char *)nouveau_dsm_muid;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000143 params[1].type = ACPI_TYPE_INTEGER;
144 params[1].integer.value = 0x00000102;
145 params[2].type = ACPI_TYPE_INTEGER;
146 params[2].integer.value = func;
147 params[3].type = ACPI_TYPE_INTEGER;
148 params[3].integer.value = arg;
149
150 err = acpi_evaluate_object(handle, "_DSM", &input, &output);
151 if (err) {
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000152 printk(KERN_INFO "failed to evaluate _DSM: %d\n", err);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000153 return err;
154 }
155
156 obj = (union acpi_object *)output.pointer;
157
158 if (obj->type == ACPI_TYPE_INTEGER)
159 if (obj->integer.value == 0x80000002)
160 return -ENODEV;
161
162 if (obj->type == ACPI_TYPE_BUFFER) {
163 if (obj->buffer.length == 4 && result) {
164 *result = 0;
165 *result |= obj->buffer.pointer[0];
166 *result |= (obj->buffer.pointer[1] << 8);
167 *result |= (obj->buffer.pointer[2] << 16);
168 *result |= (obj->buffer.pointer[3] << 24);
169 }
170 }
171
172 kfree(output.pointer);
173 return 0;
174}
175
Peter Lekensteyn9075e852011-12-17 12:53:43 +0100176/* Returns 1 if a DSM function is usable and 0 otherwise */
177static int nouveau_test_dsm(acpi_handle test_handle,
178 int (*dsm_func)(acpi_handle, int, int, uint32_t *),
179 int sfnc)
180{
181 u32 result = 0;
182
183 /* Function 0 returns a Buffer containing available functions. The args
184 * parameter is ignored for function 0, so just put 0 in it */
185 if (dsm_func(test_handle, 0, 0, &result))
186 return 0;
187
188 /* ACPI Spec v4 9.14.1: if bit 0 is zero, no function is supported. If
189 * the n-th bit is enabled, function n is supported */
190 return result & 1 && result & (1 << sfnc);
191}
192
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000193static int nouveau_dsm_switch_mux(acpi_handle handle, int mux_id)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000194{
Dave Airlie000703f2011-05-09 11:40:25 +1000195 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 +1000196 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 +1000197 return nouveau_dsm(handle, NOUVEAU_DSM_LED, mux_id, NULL);
198}
Ben Skeggs6ee73862009-12-11 19:24:15 +1000199
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000200static int nouveau_dsm_set_discrete_state(acpi_handle handle, enum vga_switcheroo_state state)
201{
202 int arg;
203 if (state == VGA_SWITCHEROO_ON)
204 arg = NOUVEAU_DSM_POWER_SPEED;
205 else
206 arg = NOUVEAU_DSM_POWER_STAMINA;
207 nouveau_dsm(handle, NOUVEAU_DSM_POWER, arg, NULL);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000208 return 0;
209}
210
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000211static int nouveau_dsm_switchto(enum vga_switcheroo_client_id id)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000212{
Dave Airliec839d742012-11-02 11:04:27 +1000213 if (!nouveau_dsm_priv.dsm_detected)
Peter Lekensteynd0992302011-12-17 12:54:04 +0100214 return 0;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000215 if (id == VGA_SWITCHEROO_IGD)
Dave Airliefc5ea292010-05-31 17:10:52 +1000216 return nouveau_dsm_switch_mux(nouveau_dsm_priv.dhandle, NOUVEAU_DSM_LED_STAMINA);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000217 else
Dave Airliefc5ea292010-05-31 17:10:52 +1000218 return nouveau_dsm_switch_mux(nouveau_dsm_priv.dhandle, NOUVEAU_DSM_LED_SPEED);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000219}
Ben Skeggs6ee73862009-12-11 19:24:15 +1000220
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000221static int nouveau_dsm_power_state(enum vga_switcheroo_client_id id,
222 enum vga_switcheroo_state state)
223{
224 if (id == VGA_SWITCHEROO_IGD)
225 return 0;
226
Peter Lekensteynd0992302011-12-17 12:54:04 +0100227 /* Optimus laptops have the card already disabled in
228 * nouveau_switcheroo_set_state */
Dave Airliec839d742012-11-02 11:04:27 +1000229 if (!nouveau_dsm_priv.dsm_detected)
Peter Lekensteynd0992302011-12-17 12:54:04 +0100230 return 0;
231
Dave Airliefc5ea292010-05-31 17:10:52 +1000232 return nouveau_dsm_set_discrete_state(nouveau_dsm_priv.dhandle, state);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000233}
234
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000235static int nouveau_dsm_get_client_id(struct pci_dev *pdev)
236{
Dave Airlied1fbd922010-12-06 12:56:44 +1000237 /* easy option one - intel vendor ID means Integrated */
238 if (pdev->vendor == PCI_VENDOR_ID_INTEL)
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000239 return VGA_SWITCHEROO_IGD;
Dave Airlied1fbd922010-12-06 12:56:44 +1000240
241 /* is this device on Bus 0? - this may need improving */
242 if (pdev->bus->number == 0)
243 return VGA_SWITCHEROO_IGD;
244
245 return VGA_SWITCHEROO_DIS;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000246}
247
248static struct vga_switcheroo_handler nouveau_dsm_handler = {
249 .switchto = nouveau_dsm_switchto,
250 .power_state = nouveau_dsm_power_state,
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000251 .get_client_id = nouveau_dsm_get_client_id,
252};
253
Dave Airlief19467c2011-03-22 14:10:27 +1000254static int nouveau_dsm_pci_probe(struct pci_dev *pdev)
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000255{
256 acpi_handle dhandle, nvidia_handle;
257 acpi_status status;
Peter Lekensteyn9075e852011-12-17 12:53:43 +0100258 int retval = 0;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000259
260 dhandle = DEVICE_ACPI_HANDLE(&pdev->dev);
261 if (!dhandle)
262 return false;
Dave Airlieafeb3e12010-04-07 13:55:09 +1000263
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000264 status = acpi_get_handle(dhandle, "_DSM", &nvidia_handle);
265 if (ACPI_FAILURE(status)) {
266 return false;
267 }
268
Peter Lekensteyn9075e852011-12-17 12:53:43 +0100269 if (nouveau_test_dsm(dhandle, nouveau_dsm, NOUVEAU_DSM_POWER))
Dave Airlief19467c2011-03-22 14:10:27 +1000270 retval |= NOUVEAU_DSM_HAS_MUX;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000271
Peter Lekensteyn9075e852011-12-17 12:53:43 +0100272 if (nouveau_test_dsm(dhandle, nouveau_optimus_dsm,
Dave Airlie5addcf02012-09-10 14:20:51 +1000273 NOUVEAU_DSM_OPTIMUS_CAPS))
Dave Airlief19467c2011-03-22 14:10:27 +1000274 retval |= NOUVEAU_DSM_HAS_OPT;
275
Dave Airlie5addcf02012-09-10 14:20:51 +1000276 if (retval & NOUVEAU_DSM_HAS_OPT) {
277 uint32_t result;
278 nouveau_optimus_dsm(dhandle, NOUVEAU_DSM_OPTIMUS_CAPS, 0,
279 &result);
280 dev_info(&pdev->dev, "optimus capabilities: %s, status %s%s\n",
281 (result & OPTIMUS_ENABLED) ? "enabled" : "disabled",
282 (result & OPTIMUS_DYNAMIC_PWR_CAP) ? "dynamic power, " : "",
283 (result & OPTIMUS_HDA_CODEC_MASK) ? "hda bios codec supported" : "");
284 }
Dave Airlief19467c2011-03-22 14:10:27 +1000285 if (retval)
286 nouveau_dsm_priv.dhandle = dhandle;
287
288 return retval;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000289}
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000290
291static bool nouveau_dsm_detect(void)
292{
293 char acpi_method_name[255] = { 0 };
294 struct acpi_buffer buffer = {sizeof(acpi_method_name), acpi_method_name};
295 struct pci_dev *pdev = NULL;
296 int has_dsm = 0;
Dave Airlieaddde4e2012-05-02 20:26:24 +0100297 int has_optimus = 0;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000298 int vga_count = 0;
Dave Airlie81161882010-12-06 12:57:45 +1000299 bool guid_valid;
Dave Airlief19467c2011-03-22 14:10:27 +1000300 int retval;
301 bool ret = false;
Dave Airlie81161882010-12-06 12:57:45 +1000302
Dave Airlief19467c2011-03-22 14:10:27 +1000303 /* lookup the MXM GUID */
Dave Airlie81161882010-12-06 12:57:45 +1000304 guid_valid = mxm_wmi_supported();
Dave Airlie81161882010-12-06 12:57:45 +1000305
Dave Airlief19467c2011-03-22 14:10:27 +1000306 if (guid_valid)
307 printk("MXM: GUID detected in BIOS\n");
Dave Airlieafeb3e12010-04-07 13:55:09 +1000308
Dave Airlief19467c2011-03-22 14:10:27 +1000309 /* now do DSM detection */
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000310 while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev)) != NULL) {
311 vga_count++;
312
Dave Airlief19467c2011-03-22 14:10:27 +1000313 retval = nouveau_dsm_pci_probe(pdev);
Dave Airlief19467c2011-03-22 14:10:27 +1000314 if (retval & NOUVEAU_DSM_HAS_MUX)
315 has_dsm |= 1;
316 if (retval & NOUVEAU_DSM_HAS_OPT)
317 has_optimus = 1;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000318 }
319
Dave Airliec839d742012-11-02 11:04:27 +1000320 /* find the optimus DSM or the old v1 DSM */
321 if (has_optimus == 1) {
322 acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
323 &buffer);
324 printk(KERN_INFO "VGA switcheroo: detected Optimus DSM method %s handle\n",
325 acpi_method_name);
326 nouveau_dsm_priv.optimus_detected = true;
327 ret = true;
328 } else if (vga_count == 2 && has_dsm && guid_valid) {
Peter Lekensteynd0992302011-12-17 12:54:04 +0100329 acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
330 &buffer);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000331 printk(KERN_INFO "VGA switcheroo: detected DSM switching method %s handle\n",
Peter Lekensteynd0992302011-12-17 12:54:04 +0100332 acpi_method_name);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000333 nouveau_dsm_priv.dsm_detected = true;
Dave Airlief19467c2011-03-22 14:10:27 +1000334 ret = true;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000335 }
Dave Airlief19467c2011-03-22 14:10:27 +1000336
Dave Airlief19467c2011-03-22 14:10:27 +1000337
338 return ret;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000339}
340
341void nouveau_register_dsm_handler(void)
342{
343 bool r;
344
345 r = nouveau_dsm_detect();
346 if (!r)
347 return;
348
349 vga_switcheroo_register_handler(&nouveau_dsm_handler);
350}
351
Peter Lekensteynd0992302011-12-17 12:54:04 +0100352/* Must be called for Optimus models before the card can be turned off */
353void nouveau_switcheroo_optimus_dsm(void)
354{
355 u32 result = 0;
356 if (!nouveau_dsm_priv.optimus_detected)
357 return;
358
Dave Airlie5addcf02012-09-10 14:20:51 +1000359 nouveau_optimus_dsm(nouveau_dsm_priv.dhandle, NOUVEAU_DSM_OPTIMUS_FLAGS,
360 0x3, &result);
361
362 nouveau_optimus_dsm(nouveau_dsm_priv.dhandle, NOUVEAU_DSM_OPTIMUS_CAPS,
363 NOUVEAU_DSM_OPTIMUS_SET_POWERDOWN, &result);
364
Peter Lekensteynd0992302011-12-17 12:54:04 +0100365}
366
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000367void nouveau_unregister_dsm_handler(void)
368{
Andreas Heider2f3787a2012-05-21 00:14:50 +0100369 if (nouveau_dsm_priv.optimus_detected || nouveau_dsm_priv.dsm_detected)
370 vga_switcheroo_unregister_handler();
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000371}
Dave Airlieafeb3e12010-04-07 13:55:09 +1000372
373/* retrieve the ROM in 4k blocks */
374static int nouveau_rom_call(acpi_handle rom_handle, uint8_t *bios,
375 int offset, int len)
376{
377 acpi_status status;
378 union acpi_object rom_arg_elements[2], *obj;
379 struct acpi_object_list rom_arg;
380 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL};
381
382 rom_arg.count = 2;
383 rom_arg.pointer = &rom_arg_elements[0];
384
385 rom_arg_elements[0].type = ACPI_TYPE_INTEGER;
386 rom_arg_elements[0].integer.value = offset;
387
388 rom_arg_elements[1].type = ACPI_TYPE_INTEGER;
389 rom_arg_elements[1].integer.value = len;
390
391 status = acpi_evaluate_object(rom_handle, NULL, &rom_arg, &buffer);
392 if (ACPI_FAILURE(status)) {
393 printk(KERN_INFO "failed to evaluate ROM got %s\n", acpi_format_exception(status));
394 return -ENODEV;
395 }
396 obj = (union acpi_object *)buffer.pointer;
397 memcpy(bios+offset, obj->buffer.pointer, len);
398 kfree(buffer.pointer);
399 return len;
400}
401
402bool nouveau_acpi_rom_supported(struct pci_dev *pdev)
403{
404 acpi_status status;
405 acpi_handle dhandle, rom_handle;
406
Dave Airlief19467c2011-03-22 14:10:27 +1000407 if (!nouveau_dsm_priv.dsm_detected && !nouveau_dsm_priv.optimus_detected)
Dave Airlieafeb3e12010-04-07 13:55:09 +1000408 return false;
409
410 dhandle = DEVICE_ACPI_HANDLE(&pdev->dev);
411 if (!dhandle)
412 return false;
413
414 status = acpi_get_handle(dhandle, "_ROM", &rom_handle);
415 if (ACPI_FAILURE(status))
416 return false;
417
418 nouveau_dsm_priv.rom_handle = rom_handle;
419 return true;
420}
421
422int nouveau_acpi_get_bios_chunk(uint8_t *bios, int offset, int len)
423{
424 return nouveau_rom_call(nouveau_dsm_priv.rom_handle, bios, offset, len);
425}
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000426
Ben Skeggsc0077062012-07-26 08:51:21 +1000427void *
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000428nouveau_acpi_edid(struct drm_device *dev, struct drm_connector *connector)
429{
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000430 struct acpi_device *acpidev;
431 acpi_handle handle;
432 int type, ret;
433 void *edid;
434
435 switch (connector->connector_type) {
436 case DRM_MODE_CONNECTOR_LVDS:
437 case DRM_MODE_CONNECTOR_eDP:
438 type = ACPI_VIDEO_DISPLAY_LCD;
439 break;
440 default:
Ben Skeggsc0077062012-07-26 08:51:21 +1000441 return NULL;
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000442 }
443
444 handle = DEVICE_ACPI_HANDLE(&dev->pdev->dev);
445 if (!handle)
Ben Skeggsc0077062012-07-26 08:51:21 +1000446 return NULL;
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000447
448 ret = acpi_bus_get_device(handle, &acpidev);
449 if (ret)
Ben Skeggsc0077062012-07-26 08:51:21 +1000450 return NULL;
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000451
452 ret = acpi_video_get_edid(acpidev, type, -1, &edid);
453 if (ret < 0)
Ben Skeggsc0077062012-07-26 08:51:21 +1000454 return NULL;
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000455
Ben Skeggsc0077062012-07-26 08:51:21 +1000456 return kmemdup(edid, EDID_LENGTH, GFP_KERNEL);
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000457}