blob: 886a67c18a6c7ec5918f25670f5a1cb2873dbf48 [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
Ben Skeggs4dc28132016-05-20 09:22:55 +10009#include "nouveau_drv.h"
Ben Skeggsc0077062012-07-26 08:51:21 +100010#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
Jeff Mahoneyd0ce7b8562014-01-21 14:34:52 -080060#ifdef CONFIG_VGA_SWITCHEROO
Dave Airlie6a9ee8a2010-02-01 15:38:10 +100061static const char nouveau_dsm_muid[] = {
62 0xA0, 0xA0, 0x95, 0x9D, 0x60, 0x00, 0x48, 0x4D,
63 0xB3, 0x4D, 0x7E, 0x5F, 0xEA, 0x12, 0x9F, 0xD4,
64};
65
Dave Airlief19467c2011-03-22 14:10:27 +100066static const char nouveau_op_dsm_muid[] = {
67 0xF8, 0xD8, 0x86, 0xA4, 0xDA, 0x0B, 0x1B, 0x47,
68 0xA7, 0x2B, 0x60, 0x42, 0xA6, 0xB5, 0xBE, 0xE0,
69};
70
71static int nouveau_optimus_dsm(acpi_handle handle, int func, int arg, uint32_t *result)
72{
Jiang Liub072e532013-12-19 20:38:22 +080073 int i;
Dave Airlief19467c2011-03-22 14:10:27 +100074 union acpi_object *obj;
Peter Lekensteynd0992302011-12-17 12:54:04 +010075 char args_buff[4];
Jiang Liub072e532013-12-19 20:38:22 +080076 union acpi_object argv4 = {
77 .buffer.type = ACPI_TYPE_BUFFER,
78 .buffer.length = 4,
79 .buffer.pointer = args_buff
80 };
Dave Airlief19467c2011-03-22 14:10:27 +100081
Peter Lekensteynd0992302011-12-17 12:54:04 +010082 /* ACPI is little endian, AABBCCDD becomes {DD,CC,BB,AA} */
83 for (i = 0; i < 4; i++)
84 args_buff[i] = (arg >> i * 8) & 0xFF;
Dave Airlief19467c2011-03-22 14:10:27 +100085
Jiang Liub072e532013-12-19 20:38:22 +080086 *result = 0;
87 obj = acpi_evaluate_dsm_typed(handle, nouveau_op_dsm_muid, 0x00000100,
88 func, &argv4, ACPI_TYPE_BUFFER);
89 if (!obj) {
90 acpi_handle_info(handle, "failed to evaluate _DSM\n");
91 return AE_ERROR;
92 } else {
93 if (obj->buffer.length == 4) {
Dave Airlief19467c2011-03-22 14:10:27 +100094 *result |= obj->buffer.pointer[0];
95 *result |= (obj->buffer.pointer[1] << 8);
96 *result |= (obj->buffer.pointer[2] << 16);
97 *result |= (obj->buffer.pointer[3] << 24);
98 }
Jiang Liub072e532013-12-19 20:38:22 +080099 ACPI_FREE(obj);
Dave Airlief19467c2011-03-22 14:10:27 +1000100 }
101
Dave Airlief19467c2011-03-22 14:10:27 +1000102 return 0;
103}
104
Jiang Liue2841752014-02-20 17:23:16 +0800105/*
106 * On some platforms, _DSM(nouveau_op_dsm_muid, func0) has special
107 * requirements on the fourth parameter, so a private implementation
108 * instead of using acpi_check_dsm().
109 */
110static int nouveau_check_optimus_dsm(acpi_handle handle)
111{
112 int result;
113
114 /*
115 * Function 0 returns a Buffer containing available functions.
116 * The args parameter is ignored for function 0, so just put 0 in it
117 */
118 if (nouveau_optimus_dsm(handle, 0, 0, &result))
119 return 0;
120
121 /*
122 * ACPI Spec v4 9.14.1: if bit 0 is zero, no function is supported.
123 * If the n-th bit is enabled, function n is supported
124 */
125 return result & 1 && result & (1 << NOUVEAU_DSM_OPTIMUS_CAPS);
126}
127
Jiang Liub072e532013-12-19 20:38:22 +0800128static int nouveau_dsm(acpi_handle handle, int func, int arg)
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000129{
Jiang Liub072e532013-12-19 20:38:22 +0800130 int ret = 0;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000131 union acpi_object *obj;
Jiang Liub072e532013-12-19 20:38:22 +0800132 union acpi_object argv4 = {
133 .integer.type = ACPI_TYPE_INTEGER,
134 .integer.value = arg,
135 };
Ben Skeggs6ee73862009-12-11 19:24:15 +1000136
Jiang Liub072e532013-12-19 20:38:22 +0800137 obj = acpi_evaluate_dsm_typed(handle, nouveau_dsm_muid, 0x00000102,
138 func, &argv4, ACPI_TYPE_INTEGER);
139 if (!obj) {
140 acpi_handle_info(handle, "failed to evaluate _DSM\n");
141 return AE_ERROR;
142 } else {
Ben Skeggs6ee73862009-12-11 19:24:15 +1000143 if (obj->integer.value == 0x80000002)
Jiang Liub072e532013-12-19 20:38:22 +0800144 ret = -ENODEV;
145 ACPI_FREE(obj);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000146 }
147
Jiang Liub072e532013-12-19 20:38:22 +0800148 return ret;
Peter Lekensteyn9075e852011-12-17 12:53:43 +0100149}
150
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000151static int nouveau_dsm_switch_mux(acpi_handle handle, int mux_id)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000152{
Dave Airlie000703f2011-05-09 11:40:25 +1000153 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 +1000154 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 +0800155 return nouveau_dsm(handle, NOUVEAU_DSM_LED, mux_id);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000156}
Ben Skeggs6ee73862009-12-11 19:24:15 +1000157
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000158static int nouveau_dsm_set_discrete_state(acpi_handle handle, enum vga_switcheroo_state state)
159{
160 int arg;
161 if (state == VGA_SWITCHEROO_ON)
162 arg = NOUVEAU_DSM_POWER_SPEED;
163 else
164 arg = NOUVEAU_DSM_POWER_STAMINA;
Jiang Liub072e532013-12-19 20:38:22 +0800165 nouveau_dsm(handle, NOUVEAU_DSM_POWER, arg);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000166 return 0;
167}
168
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000169static int nouveau_dsm_switchto(enum vga_switcheroo_client_id id)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000170{
Dave Airliec839d742012-11-02 11:04:27 +1000171 if (!nouveau_dsm_priv.dsm_detected)
Peter Lekensteynd0992302011-12-17 12:54:04 +0100172 return 0;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000173 if (id == VGA_SWITCHEROO_IGD)
Dave Airliefc5ea292010-05-31 17:10:52 +1000174 return nouveau_dsm_switch_mux(nouveau_dsm_priv.dhandle, NOUVEAU_DSM_LED_STAMINA);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000175 else
Dave Airliefc5ea292010-05-31 17:10:52 +1000176 return nouveau_dsm_switch_mux(nouveau_dsm_priv.dhandle, NOUVEAU_DSM_LED_SPEED);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000177}
Ben Skeggs6ee73862009-12-11 19:24:15 +1000178
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000179static int nouveau_dsm_power_state(enum vga_switcheroo_client_id id,
180 enum vga_switcheroo_state state)
181{
182 if (id == VGA_SWITCHEROO_IGD)
183 return 0;
184
Peter Lekensteynd0992302011-12-17 12:54:04 +0100185 /* Optimus laptops have the card already disabled in
186 * nouveau_switcheroo_set_state */
Dave Airliec839d742012-11-02 11:04:27 +1000187 if (!nouveau_dsm_priv.dsm_detected)
Peter Lekensteynd0992302011-12-17 12:54:04 +0100188 return 0;
189
Dave Airliefc5ea292010-05-31 17:10:52 +1000190 return nouveau_dsm_set_discrete_state(nouveau_dsm_priv.dhandle, state);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000191}
192
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000193static int nouveau_dsm_get_client_id(struct pci_dev *pdev)
194{
Dave Airlied1fbd9232010-12-06 12:56:44 +1000195 /* easy option one - intel vendor ID means Integrated */
196 if (pdev->vendor == PCI_VENDOR_ID_INTEL)
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000197 return VGA_SWITCHEROO_IGD;
Dave Airlied1fbd9232010-12-06 12:56:44 +1000198
199 /* is this device on Bus 0? - this may need improving */
200 if (pdev->bus->number == 0)
201 return VGA_SWITCHEROO_IGD;
202
203 return VGA_SWITCHEROO_DIS;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000204}
205
Lukas Wunner5d170132015-10-18 13:05:40 +0200206static const struct vga_switcheroo_handler nouveau_dsm_handler = {
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000207 .switchto = nouveau_dsm_switchto,
208 .power_state = nouveau_dsm_power_state,
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000209 .get_client_id = nouveau_dsm_get_client_id,
210};
211
Peter Wudf421942016-07-15 15:12:15 +0200212static void nouveau_dsm_pci_probe(struct pci_dev *pdev, acpi_handle *dhandle_out,
213 bool *has_mux, bool *has_opt)
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000214{
Zhang Rui187b5b52013-09-03 08:32:00 +0800215 acpi_handle dhandle;
Peter Wudf421942016-07-15 15:12:15 +0200216 bool supports_mux;
217 bool supports_opt;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000218
Rafael J. Wysocki3a83f992013-11-14 23:17:21 +0100219 dhandle = ACPI_HANDLE(&pdev->dev);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000220 if (!dhandle)
Peter Wudf421942016-07-15 15:12:15 +0200221 return;
Dave Airlieafeb3e12010-04-07 13:55:09 +1000222
Bjorn Helgaasf91ce352014-09-10 15:30:08 -0600223 if (!acpi_has_method(dhandle, "_DSM"))
Peter Wudf421942016-07-15 15:12:15 +0200224 return;
Bjorn Helgaasf91ce352014-09-10 15:30:08 -0600225
Peter Wudf421942016-07-15 15:12:15 +0200226 supports_mux = acpi_check_dsm(dhandle, nouveau_dsm_muid, 0x00000102,
227 1 << NOUVEAU_DSM_POWER);
228 supports_opt = nouveau_check_optimus_dsm(dhandle);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000229
Peter Wudf421942016-07-15 15:12:15 +0200230 /* Does not look like a Nvidia device. */
231 if (!supports_mux && !supports_opt)
232 return;
Dave Airlief19467c2011-03-22 14:10:27 +1000233
Peter Wudf421942016-07-15 15:12:15 +0200234 *dhandle_out = dhandle;
235 *has_mux = supports_mux;
236 *has_opt = supports_opt;
237
238 if (supports_opt) {
Dave Airlie5addcf02012-09-10 14:20:51 +1000239 uint32_t result;
240 nouveau_optimus_dsm(dhandle, NOUVEAU_DSM_OPTIMUS_CAPS, 0,
241 &result);
242 dev_info(&pdev->dev, "optimus capabilities: %s, status %s%s\n",
243 (result & OPTIMUS_ENABLED) ? "enabled" : "disabled",
244 (result & OPTIMUS_DYNAMIC_PWR_CAP) ? "dynamic power, " : "",
245 (result & OPTIMUS_HDA_CODEC_MASK) ? "hda bios codec supported" : "");
246 }
Ben Skeggs6ee73862009-12-11 19:24:15 +1000247}
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000248
249static bool nouveau_dsm_detect(void)
250{
251 char acpi_method_name[255] = { 0 };
252 struct acpi_buffer buffer = {sizeof(acpi_method_name), acpi_method_name};
253 struct pci_dev *pdev = NULL;
Peter Wudf421942016-07-15 15:12:15 +0200254 acpi_handle dhandle = NULL;
255 bool has_mux = false;
256 bool has_optimus = false;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000257 int vga_count = 0;
Dave Airlie81161882010-12-06 12:57:45 +1000258 bool guid_valid;
Dave Airlief19467c2011-03-22 14:10:27 +1000259 bool ret = false;
Dave Airlie81161882010-12-06 12:57:45 +1000260
Dave Airlief19467c2011-03-22 14:10:27 +1000261 /* lookup the MXM GUID */
Dave Airlie81161882010-12-06 12:57:45 +1000262 guid_valid = mxm_wmi_supported();
Dave Airlie81161882010-12-06 12:57:45 +1000263
Dave Airlief19467c2011-03-22 14:10:27 +1000264 if (guid_valid)
265 printk("MXM: GUID detected in BIOS\n");
Dave Airlieafeb3e12010-04-07 13:55:09 +1000266
Dave Airlief19467c2011-03-22 14:10:27 +1000267 /* now do DSM detection */
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000268 while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev)) != NULL) {
269 vga_count++;
270
Peter Wudf421942016-07-15 15:12:15 +0200271 nouveau_dsm_pci_probe(pdev, &dhandle, &has_mux, &has_optimus);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000272 }
273
Emil Velikov4c60fac2013-10-09 08:25:16 +0100274 while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_3D << 8, pdev)) != NULL) {
275 vga_count++;
276
Peter Wudf421942016-07-15 15:12:15 +0200277 nouveau_dsm_pci_probe(pdev, &dhandle, &has_mux, &has_optimus);
Emil Velikov4c60fac2013-10-09 08:25:16 +0100278 }
279
Dave Airliec839d742012-11-02 11:04:27 +1000280 /* find the optimus DSM or the old v1 DSM */
Peter Wudf421942016-07-15 15:12:15 +0200281 if (has_optimus) {
282 nouveau_dsm_priv.dhandle = dhandle;
Dave Airliec839d742012-11-02 11:04:27 +1000283 acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
284 &buffer);
285 printk(KERN_INFO "VGA switcheroo: detected Optimus DSM method %s handle\n",
286 acpi_method_name);
287 nouveau_dsm_priv.optimus_detected = true;
288 ret = true;
Peter Wudf421942016-07-15 15:12:15 +0200289 } else if (vga_count == 2 && has_mux && guid_valid) {
290 nouveau_dsm_priv.dhandle = dhandle;
Peter Lekensteynd0992302011-12-17 12:54:04 +0100291 acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
292 &buffer);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000293 printk(KERN_INFO "VGA switcheroo: detected DSM switching method %s handle\n",
Peter Lekensteynd0992302011-12-17 12:54:04 +0100294 acpi_method_name);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000295 nouveau_dsm_priv.dsm_detected = true;
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
Lukas Wunner156d7d42016-01-11 20:09:20 +0100311 vga_switcheroo_register_handler(&nouveau_dsm_handler, 0);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000312}
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}
Jeff Mahoneyd0ce7b8562014-01-21 14:34:52 -0800334#else
335void nouveau_register_dsm_handler(void) {}
336void nouveau_unregister_dsm_handler(void) {}
337void nouveau_switcheroo_optimus_dsm(void) {}
338#endif
Dave Airlieafeb3e12010-04-07 13:55:09 +1000339
340/* retrieve the ROM in 4k blocks */
341static int nouveau_rom_call(acpi_handle rom_handle, uint8_t *bios,
342 int offset, int len)
343{
344 acpi_status status;
345 union acpi_object rom_arg_elements[2], *obj;
346 struct acpi_object_list rom_arg;
347 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL};
348
349 rom_arg.count = 2;
350 rom_arg.pointer = &rom_arg_elements[0];
351
352 rom_arg_elements[0].type = ACPI_TYPE_INTEGER;
353 rom_arg_elements[0].integer.value = offset;
354
355 rom_arg_elements[1].type = ACPI_TYPE_INTEGER;
356 rom_arg_elements[1].integer.value = len;
357
358 status = acpi_evaluate_object(rom_handle, NULL, &rom_arg, &buffer);
359 if (ACPI_FAILURE(status)) {
360 printk(KERN_INFO "failed to evaluate ROM got %s\n", acpi_format_exception(status));
361 return -ENODEV;
362 }
363 obj = (union acpi_object *)buffer.pointer;
Ben Skeggs95432942015-11-19 13:18:34 +1000364 len = min(len, (int)obj->buffer.length);
Dave Airlieafeb3e12010-04-07 13:55:09 +1000365 memcpy(bios+offset, obj->buffer.pointer, len);
366 kfree(buffer.pointer);
367 return len;
368}
369
Ben Skeggs26c9e8e2015-08-20 14:54:23 +1000370bool nouveau_acpi_rom_supported(struct device *dev)
Dave Airlieafeb3e12010-04-07 13:55:09 +1000371{
372 acpi_status status;
373 acpi_handle dhandle, rom_handle;
374
Ben Skeggs26c9e8e2015-08-20 14:54:23 +1000375 dhandle = ACPI_HANDLE(dev);
Dave Airlieafeb3e12010-04-07 13:55:09 +1000376 if (!dhandle)
377 return false;
378
379 status = acpi_get_handle(dhandle, "_ROM", &rom_handle);
380 if (ACPI_FAILURE(status))
381 return false;
382
383 nouveau_dsm_priv.rom_handle = rom_handle;
384 return true;
385}
386
387int nouveau_acpi_get_bios_chunk(uint8_t *bios, int offset, int len)
388{
389 return nouveau_rom_call(nouveau_dsm_priv.rom_handle, bios, offset, len);
390}
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000391
Ben Skeggsc0077062012-07-26 08:51:21 +1000392void *
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000393nouveau_acpi_edid(struct drm_device *dev, struct drm_connector *connector)
394{
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000395 struct acpi_device *acpidev;
396 acpi_handle handle;
397 int type, ret;
398 void *edid;
399
400 switch (connector->connector_type) {
401 case DRM_MODE_CONNECTOR_LVDS:
402 case DRM_MODE_CONNECTOR_eDP:
403 type = ACPI_VIDEO_DISPLAY_LCD;
404 break;
405 default:
Ben Skeggsc0077062012-07-26 08:51:21 +1000406 return NULL;
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000407 }
408
Rafael J. Wysocki3a83f992013-11-14 23:17:21 +0100409 handle = ACPI_HANDLE(&dev->pdev->dev);
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000410 if (!handle)
Ben Skeggsc0077062012-07-26 08:51:21 +1000411 return NULL;
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000412
413 ret = acpi_bus_get_device(handle, &acpidev);
414 if (ret)
Ben Skeggsc0077062012-07-26 08:51:21 +1000415 return NULL;
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000416
417 ret = acpi_video_get_edid(acpidev, type, -1, &edid);
418 if (ret < 0)
Ben Skeggsc0077062012-07-26 08:51:21 +1000419 return NULL;
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000420
Ben Skeggsc0077062012-07-26 08:51:21 +1000421 return kmemdup(edid, EDID_LENGTH, GFP_KERNEL);
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000422}