blob: 879a8b474bfec1aff31644e08abba9c874ff4479 [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;
Rafael J. Wysockif244d8b2013-12-31 13:39:42 +010054 acpi_handle other_handle;
Dave Airlieafeb3e12010-04-07 13:55:09 +100055 acpi_handle rom_handle;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +100056} nouveau_dsm_priv;
Ben Skeggs6ee73862009-12-11 19:24:15 +100057
Dave Airliec839d742012-11-02 11:04:27 +100058bool nouveau_is_optimus(void) {
59 return nouveau_dsm_priv.optimus_detected;
60}
61
62bool nouveau_is_v1_dsm(void) {
63 return nouveau_dsm_priv.dsm_detected;
64}
65
Dave Airlief19467c2011-03-22 14:10:27 +100066#define NOUVEAU_DSM_HAS_MUX 0x1
67#define NOUVEAU_DSM_HAS_OPT 0x2
68
Dave Airlie6a9ee8a2010-02-01 15:38:10 +100069static const char nouveau_dsm_muid[] = {
70 0xA0, 0xA0, 0x95, 0x9D, 0x60, 0x00, 0x48, 0x4D,
71 0xB3, 0x4D, 0x7E, 0x5F, 0xEA, 0x12, 0x9F, 0xD4,
72};
73
Dave Airlief19467c2011-03-22 14:10:27 +100074static const char nouveau_op_dsm_muid[] = {
75 0xF8, 0xD8, 0x86, 0xA4, 0xDA, 0x0B, 0x1B, 0x47,
76 0xA7, 0x2B, 0x60, 0x42, 0xA6, 0xB5, 0xBE, 0xE0,
77};
78
79static int nouveau_optimus_dsm(acpi_handle handle, int func, int arg, uint32_t *result)
80{
Jiang Liub072e532013-12-19 20:38:22 +080081 int i;
Dave Airlief19467c2011-03-22 14:10:27 +100082 union acpi_object *obj;
Peter Lekensteynd0992302011-12-17 12:54:04 +010083 char args_buff[4];
Jiang Liub072e532013-12-19 20:38:22 +080084 union acpi_object argv4 = {
85 .buffer.type = ACPI_TYPE_BUFFER,
86 .buffer.length = 4,
87 .buffer.pointer = args_buff
88 };
Dave Airlief19467c2011-03-22 14:10:27 +100089
Peter Lekensteynd0992302011-12-17 12:54:04 +010090 /* ACPI is little endian, AABBCCDD becomes {DD,CC,BB,AA} */
91 for (i = 0; i < 4; i++)
92 args_buff[i] = (arg >> i * 8) & 0xFF;
Dave Airlief19467c2011-03-22 14:10:27 +100093
Jiang Liub072e532013-12-19 20:38:22 +080094 *result = 0;
95 obj = acpi_evaluate_dsm_typed(handle, nouveau_op_dsm_muid, 0x00000100,
96 func, &argv4, ACPI_TYPE_BUFFER);
97 if (!obj) {
98 acpi_handle_info(handle, "failed to evaluate _DSM\n");
99 return AE_ERROR;
100 } else {
101 if (obj->buffer.length == 4) {
Dave Airlief19467c2011-03-22 14:10:27 +1000102 *result |= obj->buffer.pointer[0];
103 *result |= (obj->buffer.pointer[1] << 8);
104 *result |= (obj->buffer.pointer[2] << 16);
105 *result |= (obj->buffer.pointer[3] << 24);
106 }
Jiang Liub072e532013-12-19 20:38:22 +0800107 ACPI_FREE(obj);
Dave Airlief19467c2011-03-22 14:10:27 +1000108 }
109
Dave Airlief19467c2011-03-22 14:10:27 +1000110 return 0;
111}
112
Jiang Liub072e532013-12-19 20:38:22 +0800113static int nouveau_dsm(acpi_handle handle, int func, int arg)
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000114{
Jiang Liub072e532013-12-19 20:38:22 +0800115 int ret = 0;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000116 union acpi_object *obj;
Jiang Liub072e532013-12-19 20:38:22 +0800117 union acpi_object argv4 = {
118 .integer.type = ACPI_TYPE_INTEGER,
119 .integer.value = arg,
120 };
Ben Skeggs6ee73862009-12-11 19:24:15 +1000121
Jiang Liub072e532013-12-19 20:38:22 +0800122 obj = acpi_evaluate_dsm_typed(handle, nouveau_dsm_muid, 0x00000102,
123 func, &argv4, ACPI_TYPE_INTEGER);
124 if (!obj) {
125 acpi_handle_info(handle, "failed to evaluate _DSM\n");
126 return AE_ERROR;
127 } else {
128 if (obj->integer.value == 0x80000002)
129 ret = -ENODEV;
130 ACPI_FREE(obj);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000131 }
132
Jiang Liub072e532013-12-19 20:38:22 +0800133 return ret;
Peter Lekensteyn9075e852011-12-17 12:53:43 +0100134}
135
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000136static int nouveau_dsm_switch_mux(acpi_handle handle, int mux_id)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000137{
Dave Airlie000703f2011-05-09 11:40:25 +1000138 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 +1000139 mxm_wmi_call_mxds(mux_id == NOUVEAU_DSM_LED_STAMINA ? MXM_MXDS_ADAPTER_IGD : MXM_MXDS_ADAPTER_0);
Jiang Liub072e532013-12-19 20:38:22 +0800140 return nouveau_dsm(handle, NOUVEAU_DSM_LED, mux_id);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000141}
Ben Skeggs6ee73862009-12-11 19:24:15 +1000142
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000143static int nouveau_dsm_set_discrete_state(acpi_handle handle, enum vga_switcheroo_state state)
144{
145 int arg;
146 if (state == VGA_SWITCHEROO_ON)
147 arg = NOUVEAU_DSM_POWER_SPEED;
148 else
149 arg = NOUVEAU_DSM_POWER_STAMINA;
Jiang Liub072e532013-12-19 20:38:22 +0800150 nouveau_dsm(handle, NOUVEAU_DSM_POWER, arg);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000151 return 0;
152}
153
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000154static int nouveau_dsm_switchto(enum vga_switcheroo_client_id id)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000155{
Dave Airliec839d742012-11-02 11:04:27 +1000156 if (!nouveau_dsm_priv.dsm_detected)
Peter Lekensteynd0992302011-12-17 12:54:04 +0100157 return 0;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000158 if (id == VGA_SWITCHEROO_IGD)
Dave Airliefc5ea292010-05-31 17:10:52 +1000159 return nouveau_dsm_switch_mux(nouveau_dsm_priv.dhandle, NOUVEAU_DSM_LED_STAMINA);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000160 else
Dave Airliefc5ea292010-05-31 17:10:52 +1000161 return nouveau_dsm_switch_mux(nouveau_dsm_priv.dhandle, NOUVEAU_DSM_LED_SPEED);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000162}
Ben Skeggs6ee73862009-12-11 19:24:15 +1000163
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000164static int nouveau_dsm_power_state(enum vga_switcheroo_client_id id,
165 enum vga_switcheroo_state state)
166{
167 if (id == VGA_SWITCHEROO_IGD)
168 return 0;
169
Peter Lekensteynd0992302011-12-17 12:54:04 +0100170 /* Optimus laptops have the card already disabled in
171 * nouveau_switcheroo_set_state */
Dave Airliec839d742012-11-02 11:04:27 +1000172 if (!nouveau_dsm_priv.dsm_detected)
Peter Lekensteynd0992302011-12-17 12:54:04 +0100173 return 0;
174
Dave Airliefc5ea292010-05-31 17:10:52 +1000175 return nouveau_dsm_set_discrete_state(nouveau_dsm_priv.dhandle, state);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000176}
177
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000178static int nouveau_dsm_get_client_id(struct pci_dev *pdev)
179{
Dave Airlied1fbd922010-12-06 12:56:44 +1000180 /* easy option one - intel vendor ID means Integrated */
181 if (pdev->vendor == PCI_VENDOR_ID_INTEL)
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000182 return VGA_SWITCHEROO_IGD;
Dave Airlied1fbd922010-12-06 12:56:44 +1000183
184 /* is this device on Bus 0? - this may need improving */
185 if (pdev->bus->number == 0)
186 return VGA_SWITCHEROO_IGD;
187
188 return VGA_SWITCHEROO_DIS;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000189}
190
191static struct vga_switcheroo_handler nouveau_dsm_handler = {
192 .switchto = nouveau_dsm_switchto,
193 .power_state = nouveau_dsm_power_state,
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000194 .get_client_id = nouveau_dsm_get_client_id,
195};
196
Dave Airlief19467c2011-03-22 14:10:27 +1000197static int nouveau_dsm_pci_probe(struct pci_dev *pdev)
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000198{
Zhang Rui187b5b52013-09-03 08:32:00 +0800199 acpi_handle dhandle;
Peter Lekensteyn9075e852011-12-17 12:53:43 +0100200 int retval = 0;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000201
Rafael J. Wysocki3a83f992013-11-14 23:17:21 +0100202 dhandle = ACPI_HANDLE(&pdev->dev);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000203 if (!dhandle)
204 return false;
Dave Airlieafeb3e12010-04-07 13:55:09 +1000205
Rafael J. Wysockif244d8b2013-12-31 13:39:42 +0100206 if (!acpi_has_method(dhandle, "_DSM")) {
207 nouveau_dsm_priv.other_handle = dhandle;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000208 return false;
Rafael J. Wysockif244d8b2013-12-31 13:39:42 +0100209 }
Jiang Liub072e532013-12-19 20:38:22 +0800210 if (acpi_check_dsm(dhandle, nouveau_dsm_muid, 0x00000102,
211 1 << NOUVEAU_DSM_POWER))
Dave Airlief19467c2011-03-22 14:10:27 +1000212 retval |= NOUVEAU_DSM_HAS_MUX;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000213
Jiang Liub072e532013-12-19 20:38:22 +0800214 if (acpi_check_dsm(dhandle, nouveau_op_dsm_muid, 0x00000100,
215 1 << NOUVEAU_DSM_OPTIMUS_CAPS))
Dave Airlief19467c2011-03-22 14:10:27 +1000216 retval |= NOUVEAU_DSM_HAS_OPT;
217
Dave Airlie5addcf02012-09-10 14:20:51 +1000218 if (retval & NOUVEAU_DSM_HAS_OPT) {
219 uint32_t result;
220 nouveau_optimus_dsm(dhandle, NOUVEAU_DSM_OPTIMUS_CAPS, 0,
221 &result);
222 dev_info(&pdev->dev, "optimus capabilities: %s, status %s%s\n",
223 (result & OPTIMUS_ENABLED) ? "enabled" : "disabled",
224 (result & OPTIMUS_DYNAMIC_PWR_CAP) ? "dynamic power, " : "",
225 (result & OPTIMUS_HDA_CODEC_MASK) ? "hda bios codec supported" : "");
226 }
Dave Airlief19467c2011-03-22 14:10:27 +1000227 if (retval)
228 nouveau_dsm_priv.dhandle = dhandle;
229
230 return retval;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000231}
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000232
233static bool nouveau_dsm_detect(void)
234{
235 char acpi_method_name[255] = { 0 };
236 struct acpi_buffer buffer = {sizeof(acpi_method_name), acpi_method_name};
237 struct pci_dev *pdev = NULL;
238 int has_dsm = 0;
Dave Airlieaddde4e2012-05-02 20:26:24 +0100239 int has_optimus = 0;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000240 int vga_count = 0;
Dave Airlie81161882010-12-06 12:57:45 +1000241 bool guid_valid;
Dave Airlief19467c2011-03-22 14:10:27 +1000242 int retval;
243 bool ret = false;
Dave Airlie81161882010-12-06 12:57:45 +1000244
Dave Airlief19467c2011-03-22 14:10:27 +1000245 /* lookup the MXM GUID */
Dave Airlie81161882010-12-06 12:57:45 +1000246 guid_valid = mxm_wmi_supported();
Dave Airlie81161882010-12-06 12:57:45 +1000247
Dave Airlief19467c2011-03-22 14:10:27 +1000248 if (guid_valid)
249 printk("MXM: GUID detected in BIOS\n");
Dave Airlieafeb3e12010-04-07 13:55:09 +1000250
Dave Airlief19467c2011-03-22 14:10:27 +1000251 /* now do DSM detection */
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000252 while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev)) != NULL) {
253 vga_count++;
254
Dave Airlief19467c2011-03-22 14:10:27 +1000255 retval = nouveau_dsm_pci_probe(pdev);
Dave Airlief19467c2011-03-22 14:10:27 +1000256 if (retval & NOUVEAU_DSM_HAS_MUX)
257 has_dsm |= 1;
258 if (retval & NOUVEAU_DSM_HAS_OPT)
259 has_optimus = 1;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000260 }
261
Emil Velikov4c60fac2013-10-09 08:25:16 +0100262 while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_3D << 8, pdev)) != NULL) {
263 vga_count++;
264
265 retval = nouveau_dsm_pci_probe(pdev);
266 if (retval & NOUVEAU_DSM_HAS_MUX)
267 has_dsm |= 1;
268 if (retval & NOUVEAU_DSM_HAS_OPT)
269 has_optimus = 1;
270 }
271
Dave Airliec839d742012-11-02 11:04:27 +1000272 /* find the optimus DSM or the old v1 DSM */
273 if (has_optimus == 1) {
274 acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
275 &buffer);
276 printk(KERN_INFO "VGA switcheroo: detected Optimus DSM method %s handle\n",
277 acpi_method_name);
278 nouveau_dsm_priv.optimus_detected = true;
279 ret = true;
280 } else if (vga_count == 2 && has_dsm && guid_valid) {
Peter Lekensteynd0992302011-12-17 12:54:04 +0100281 acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
282 &buffer);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000283 printk(KERN_INFO "VGA switcheroo: detected DSM switching method %s handle\n",
Peter Lekensteynd0992302011-12-17 12:54:04 +0100284 acpi_method_name);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000285 nouveau_dsm_priv.dsm_detected = true;
Rafael J. Wysockif244d8b2013-12-31 13:39:42 +0100286 /*
287 * On some systems hotplug events are generated for the device
288 * being switched off when _DSM is executed. They cause ACPI
289 * hotplug to trigger and attempt to remove the device from
290 * the system, which causes it to break down. Prevent that from
291 * happening by setting the no_hotplug flag for the involved
292 * ACPI device objects.
293 */
294 acpi_bus_no_hotplug(nouveau_dsm_priv.dhandle);
295 acpi_bus_no_hotplug(nouveau_dsm_priv.other_handle);
Dave Airlief19467c2011-03-22 14:10:27 +1000296 ret = true;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000297 }
Dave Airlief19467c2011-03-22 14:10:27 +1000298
Dave Airlief19467c2011-03-22 14:10:27 +1000299
300 return ret;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000301}
302
303void nouveau_register_dsm_handler(void)
304{
305 bool r;
306
307 r = nouveau_dsm_detect();
308 if (!r)
309 return;
310
311 vga_switcheroo_register_handler(&nouveau_dsm_handler);
312}
313
Peter Lekensteynd0992302011-12-17 12:54:04 +0100314/* Must be called for Optimus models before the card can be turned off */
315void nouveau_switcheroo_optimus_dsm(void)
316{
317 u32 result = 0;
318 if (!nouveau_dsm_priv.optimus_detected)
319 return;
320
Dave Airlie5addcf02012-09-10 14:20:51 +1000321 nouveau_optimus_dsm(nouveau_dsm_priv.dhandle, NOUVEAU_DSM_OPTIMUS_FLAGS,
322 0x3, &result);
323
324 nouveau_optimus_dsm(nouveau_dsm_priv.dhandle, NOUVEAU_DSM_OPTIMUS_CAPS,
325 NOUVEAU_DSM_OPTIMUS_SET_POWERDOWN, &result);
326
Peter Lekensteynd0992302011-12-17 12:54:04 +0100327}
328
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000329void nouveau_unregister_dsm_handler(void)
330{
Andreas Heider2f3787a2012-05-21 00:14:50 +0100331 if (nouveau_dsm_priv.optimus_detected || nouveau_dsm_priv.dsm_detected)
332 vga_switcheroo_unregister_handler();
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000333}
Dave Airlieafeb3e12010-04-07 13:55:09 +1000334
335/* retrieve the ROM in 4k blocks */
336static int nouveau_rom_call(acpi_handle rom_handle, uint8_t *bios,
337 int offset, int len)
338{
339 acpi_status status;
340 union acpi_object rom_arg_elements[2], *obj;
341 struct acpi_object_list rom_arg;
342 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL};
343
344 rom_arg.count = 2;
345 rom_arg.pointer = &rom_arg_elements[0];
346
347 rom_arg_elements[0].type = ACPI_TYPE_INTEGER;
348 rom_arg_elements[0].integer.value = offset;
349
350 rom_arg_elements[1].type = ACPI_TYPE_INTEGER;
351 rom_arg_elements[1].integer.value = len;
352
353 status = acpi_evaluate_object(rom_handle, NULL, &rom_arg, &buffer);
354 if (ACPI_FAILURE(status)) {
355 printk(KERN_INFO "failed to evaluate ROM got %s\n", acpi_format_exception(status));
356 return -ENODEV;
357 }
358 obj = (union acpi_object *)buffer.pointer;
359 memcpy(bios+offset, obj->buffer.pointer, len);
360 kfree(buffer.pointer);
361 return len;
362}
363
364bool nouveau_acpi_rom_supported(struct pci_dev *pdev)
365{
366 acpi_status status;
367 acpi_handle dhandle, rom_handle;
368
Dave Airlief19467c2011-03-22 14:10:27 +1000369 if (!nouveau_dsm_priv.dsm_detected && !nouveau_dsm_priv.optimus_detected)
Dave Airlieafeb3e12010-04-07 13:55:09 +1000370 return false;
371
Rafael J. Wysocki3a83f992013-11-14 23:17:21 +0100372 dhandle = ACPI_HANDLE(&pdev->dev);
Dave Airlieafeb3e12010-04-07 13:55:09 +1000373 if (!dhandle)
374 return false;
375
376 status = acpi_get_handle(dhandle, "_ROM", &rom_handle);
377 if (ACPI_FAILURE(status))
378 return false;
379
380 nouveau_dsm_priv.rom_handle = rom_handle;
381 return true;
382}
383
384int nouveau_acpi_get_bios_chunk(uint8_t *bios, int offset, int len)
385{
386 return nouveau_rom_call(nouveau_dsm_priv.rom_handle, bios, offset, len);
387}
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000388
Ben Skeggsc0077062012-07-26 08:51:21 +1000389void *
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000390nouveau_acpi_edid(struct drm_device *dev, struct drm_connector *connector)
391{
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000392 struct acpi_device *acpidev;
393 acpi_handle handle;
394 int type, ret;
395 void *edid;
396
397 switch (connector->connector_type) {
398 case DRM_MODE_CONNECTOR_LVDS:
399 case DRM_MODE_CONNECTOR_eDP:
400 type = ACPI_VIDEO_DISPLAY_LCD;
401 break;
402 default:
Ben Skeggsc0077062012-07-26 08:51:21 +1000403 return NULL;
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000404 }
405
Rafael J. Wysocki3a83f992013-11-14 23:17:21 +0100406 handle = ACPI_HANDLE(&dev->pdev->dev);
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000407 if (!handle)
Ben Skeggsc0077062012-07-26 08:51:21 +1000408 return NULL;
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000409
410 ret = acpi_bus_get_device(handle, &acpidev);
411 if (ret)
Ben Skeggsc0077062012-07-26 08:51:21 +1000412 return NULL;
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000413
414 ret = acpi_video_get_edid(acpidev, type, -1, &edid);
415 if (ret < 0)
Ben Skeggsc0077062012-07-26 08:51:21 +1000416 return NULL;
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000417
Ben Skeggsc0077062012-07-26 08:51:21 +1000418 return kmemdup(edid, EDID_LENGTH, GFP_KERNEL);
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000419}