blob: 572ac309d23cfaad45d4ae6eb8996284b5d2e52c [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 */
Peter Wua12e78d2016-07-15 15:12:16 +0200110static int nouveau_dsm_get_optimus_functions(acpi_handle handle)
Jiang Liue2841752014-02-20 17:23:16 +0800111{
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 */
Peter Wua12e78d2016-07-15 15:12:16 +0200125 if (result & 1 && result & (1 << NOUVEAU_DSM_OPTIMUS_CAPS))
126 return result;
127 return 0;
Jiang Liue2841752014-02-20 17:23:16 +0800128}
129
Jiang Liub072e532013-12-19 20:38:22 +0800130static int nouveau_dsm(acpi_handle handle, int func, int arg)
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000131{
Jiang Liub072e532013-12-19 20:38:22 +0800132 int ret = 0;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000133 union acpi_object *obj;
Jiang Liub072e532013-12-19 20:38:22 +0800134 union acpi_object argv4 = {
135 .integer.type = ACPI_TYPE_INTEGER,
136 .integer.value = arg,
137 };
Ben Skeggs6ee73862009-12-11 19:24:15 +1000138
Jiang Liub072e532013-12-19 20:38:22 +0800139 obj = acpi_evaluate_dsm_typed(handle, nouveau_dsm_muid, 0x00000102,
140 func, &argv4, ACPI_TYPE_INTEGER);
141 if (!obj) {
142 acpi_handle_info(handle, "failed to evaluate _DSM\n");
143 return AE_ERROR;
144 } else {
Ben Skeggs6ee73862009-12-11 19:24:15 +1000145 if (obj->integer.value == 0x80000002)
Jiang Liub072e532013-12-19 20:38:22 +0800146 ret = -ENODEV;
147 ACPI_FREE(obj);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000148 }
149
Jiang Liub072e532013-12-19 20:38:22 +0800150 return ret;
Peter Lekensteyn9075e852011-12-17 12:53:43 +0100151}
152
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000153static int nouveau_dsm_switch_mux(acpi_handle handle, int mux_id)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000154{
Dave Airlie000703f2011-05-09 11:40:25 +1000155 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 +1000156 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 +0800157 return nouveau_dsm(handle, NOUVEAU_DSM_LED, mux_id);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000158}
Ben Skeggs6ee73862009-12-11 19:24:15 +1000159
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000160static int nouveau_dsm_set_discrete_state(acpi_handle handle, enum vga_switcheroo_state state)
161{
162 int arg;
163 if (state == VGA_SWITCHEROO_ON)
164 arg = NOUVEAU_DSM_POWER_SPEED;
165 else
166 arg = NOUVEAU_DSM_POWER_STAMINA;
Jiang Liub072e532013-12-19 20:38:22 +0800167 nouveau_dsm(handle, NOUVEAU_DSM_POWER, arg);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000168 return 0;
169}
170
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000171static int nouveau_dsm_switchto(enum vga_switcheroo_client_id id)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000172{
Dave Airliec839d742012-11-02 11:04:27 +1000173 if (!nouveau_dsm_priv.dsm_detected)
Peter Lekensteynd0992302011-12-17 12:54:04 +0100174 return 0;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000175 if (id == VGA_SWITCHEROO_IGD)
Dave Airliefc5ea292010-05-31 17:10:52 +1000176 return nouveau_dsm_switch_mux(nouveau_dsm_priv.dhandle, NOUVEAU_DSM_LED_STAMINA);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000177 else
Dave Airliefc5ea292010-05-31 17:10:52 +1000178 return nouveau_dsm_switch_mux(nouveau_dsm_priv.dhandle, NOUVEAU_DSM_LED_SPEED);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000179}
Ben Skeggs6ee73862009-12-11 19:24:15 +1000180
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000181static int nouveau_dsm_power_state(enum vga_switcheroo_client_id id,
182 enum vga_switcheroo_state state)
183{
184 if (id == VGA_SWITCHEROO_IGD)
185 return 0;
186
Peter Lekensteynd0992302011-12-17 12:54:04 +0100187 /* Optimus laptops have the card already disabled in
188 * nouveau_switcheroo_set_state */
Dave Airliec839d742012-11-02 11:04:27 +1000189 if (!nouveau_dsm_priv.dsm_detected)
Peter Lekensteynd0992302011-12-17 12:54:04 +0100190 return 0;
191
Dave Airliefc5ea292010-05-31 17:10:52 +1000192 return nouveau_dsm_set_discrete_state(nouveau_dsm_priv.dhandle, state);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000193}
194
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000195static int nouveau_dsm_get_client_id(struct pci_dev *pdev)
196{
Dave Airlied1fbd9232010-12-06 12:56:44 +1000197 /* easy option one - intel vendor ID means Integrated */
198 if (pdev->vendor == PCI_VENDOR_ID_INTEL)
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000199 return VGA_SWITCHEROO_IGD;
Dave Airlied1fbd9232010-12-06 12:56:44 +1000200
201 /* is this device on Bus 0? - this may need improving */
202 if (pdev->bus->number == 0)
203 return VGA_SWITCHEROO_IGD;
204
205 return VGA_SWITCHEROO_DIS;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000206}
207
Lukas Wunner5d170132015-10-18 13:05:40 +0200208static const struct vga_switcheroo_handler nouveau_dsm_handler = {
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000209 .switchto = nouveau_dsm_switchto,
210 .power_state = nouveau_dsm_power_state,
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000211 .get_client_id = nouveau_dsm_get_client_id,
212};
213
Peter Wudf421942016-07-15 15:12:15 +0200214static void nouveau_dsm_pci_probe(struct pci_dev *pdev, acpi_handle *dhandle_out,
215 bool *has_mux, bool *has_opt)
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000216{
Zhang Rui187b5b52013-09-03 08:32:00 +0800217 acpi_handle dhandle;
Peter Wudf421942016-07-15 15:12:15 +0200218 bool supports_mux;
Peter Wua12e78d2016-07-15 15:12:16 +0200219 int optimus_funcs;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000220
Rafael J. Wysocki3a83f992013-11-14 23:17:21 +0100221 dhandle = ACPI_HANDLE(&pdev->dev);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000222 if (!dhandle)
Peter Wudf421942016-07-15 15:12:15 +0200223 return;
Dave Airlieafeb3e12010-04-07 13:55:09 +1000224
Bjorn Helgaasf91ce352014-09-10 15:30:08 -0600225 if (!acpi_has_method(dhandle, "_DSM"))
Peter Wudf421942016-07-15 15:12:15 +0200226 return;
Bjorn Helgaasf91ce352014-09-10 15:30:08 -0600227
Peter Wudf421942016-07-15 15:12:15 +0200228 supports_mux = acpi_check_dsm(dhandle, nouveau_dsm_muid, 0x00000102,
229 1 << NOUVEAU_DSM_POWER);
Peter Wua12e78d2016-07-15 15:12:16 +0200230 optimus_funcs = nouveau_dsm_get_optimus_functions(dhandle);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000231
Peter Wudf421942016-07-15 15:12:15 +0200232 /* Does not look like a Nvidia device. */
Peter Wua12e78d2016-07-15 15:12:16 +0200233 if (!supports_mux && !optimus_funcs)
Peter Wudf421942016-07-15 15:12:15 +0200234 return;
Dave Airlief19467c2011-03-22 14:10:27 +1000235
Peter Wudf421942016-07-15 15:12:15 +0200236 *dhandle_out = dhandle;
237 *has_mux = supports_mux;
Peter Wua12e78d2016-07-15 15:12:16 +0200238 *has_opt = !!optimus_funcs;
Peter Wudf421942016-07-15 15:12:15 +0200239
Peter Wua12e78d2016-07-15 15:12:16 +0200240 if (optimus_funcs) {
Dave Airlie5addcf02012-09-10 14:20:51 +1000241 uint32_t result;
242 nouveau_optimus_dsm(dhandle, NOUVEAU_DSM_OPTIMUS_CAPS, 0,
243 &result);
244 dev_info(&pdev->dev, "optimus capabilities: %s, status %s%s\n",
245 (result & OPTIMUS_ENABLED) ? "enabled" : "disabled",
246 (result & OPTIMUS_DYNAMIC_PWR_CAP) ? "dynamic power, " : "",
247 (result & OPTIMUS_HDA_CODEC_MASK) ? "hda bios codec supported" : "");
248 }
Ben Skeggs6ee73862009-12-11 19:24:15 +1000249}
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000250
251static bool nouveau_dsm_detect(void)
252{
253 char acpi_method_name[255] = { 0 };
254 struct acpi_buffer buffer = {sizeof(acpi_method_name), acpi_method_name};
255 struct pci_dev *pdev = NULL;
Peter Wudf421942016-07-15 15:12:15 +0200256 acpi_handle dhandle = NULL;
257 bool has_mux = false;
258 bool has_optimus = false;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000259 int vga_count = 0;
Dave Airlie81161882010-12-06 12:57:45 +1000260 bool guid_valid;
Dave Airlief19467c2011-03-22 14:10:27 +1000261 bool ret = false;
Dave Airlie81161882010-12-06 12:57:45 +1000262
Dave Airlief19467c2011-03-22 14:10:27 +1000263 /* lookup the MXM GUID */
Dave Airlie81161882010-12-06 12:57:45 +1000264 guid_valid = mxm_wmi_supported();
Dave Airlie81161882010-12-06 12:57:45 +1000265
Dave Airlief19467c2011-03-22 14:10:27 +1000266 if (guid_valid)
267 printk("MXM: GUID detected in BIOS\n");
Dave Airlieafeb3e12010-04-07 13:55:09 +1000268
Dave Airlief19467c2011-03-22 14:10:27 +1000269 /* now do DSM detection */
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000270 while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev)) != NULL) {
271 vga_count++;
272
Peter Wudf421942016-07-15 15:12:15 +0200273 nouveau_dsm_pci_probe(pdev, &dhandle, &has_mux, &has_optimus);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000274 }
275
Emil Velikov4c60fac2013-10-09 08:25:16 +0100276 while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_3D << 8, pdev)) != NULL) {
277 vga_count++;
278
Peter Wudf421942016-07-15 15:12:15 +0200279 nouveau_dsm_pci_probe(pdev, &dhandle, &has_mux, &has_optimus);
Emil Velikov4c60fac2013-10-09 08:25:16 +0100280 }
281
Dave Airliec839d742012-11-02 11:04:27 +1000282 /* find the optimus DSM or the old v1 DSM */
Peter Wudf421942016-07-15 15:12:15 +0200283 if (has_optimus) {
284 nouveau_dsm_priv.dhandle = dhandle;
Dave Airliec839d742012-11-02 11:04:27 +1000285 acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
286 &buffer);
287 printk(KERN_INFO "VGA switcheroo: detected Optimus DSM method %s handle\n",
288 acpi_method_name);
289 nouveau_dsm_priv.optimus_detected = true;
290 ret = true;
Peter Wudf421942016-07-15 15:12:15 +0200291 } else if (vga_count == 2 && has_mux && guid_valid) {
292 nouveau_dsm_priv.dhandle = dhandle;
Peter Lekensteynd0992302011-12-17 12:54:04 +0100293 acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
294 &buffer);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000295 printk(KERN_INFO "VGA switcheroo: detected DSM switching method %s handle\n",
Peter Lekensteynd0992302011-12-17 12:54:04 +0100296 acpi_method_name);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000297 nouveau_dsm_priv.dsm_detected = true;
Dave Airlief19467c2011-03-22 14:10:27 +1000298 ret = true;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000299 }
Dave Airlief19467c2011-03-22 14:10:27 +1000300
Dave Airlief19467c2011-03-22 14:10:27 +1000301
302 return ret;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000303}
304
305void nouveau_register_dsm_handler(void)
306{
307 bool r;
308
309 r = nouveau_dsm_detect();
310 if (!r)
311 return;
312
Lukas Wunner156d7d42016-01-11 20:09:20 +0100313 vga_switcheroo_register_handler(&nouveau_dsm_handler, 0);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000314}
315
Peter Lekensteynd0992302011-12-17 12:54:04 +0100316/* Must be called for Optimus models before the card can be turned off */
317void nouveau_switcheroo_optimus_dsm(void)
318{
319 u32 result = 0;
320 if (!nouveau_dsm_priv.optimus_detected)
321 return;
322
Dave Airlie5addcf02012-09-10 14:20:51 +1000323 nouveau_optimus_dsm(nouveau_dsm_priv.dhandle, NOUVEAU_DSM_OPTIMUS_FLAGS,
324 0x3, &result);
325
326 nouveau_optimus_dsm(nouveau_dsm_priv.dhandle, NOUVEAU_DSM_OPTIMUS_CAPS,
327 NOUVEAU_DSM_OPTIMUS_SET_POWERDOWN, &result);
328
Peter Lekensteynd0992302011-12-17 12:54:04 +0100329}
330
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000331void nouveau_unregister_dsm_handler(void)
332{
Andreas Heider2f3787a2012-05-21 00:14:50 +0100333 if (nouveau_dsm_priv.optimus_detected || nouveau_dsm_priv.dsm_detected)
334 vga_switcheroo_unregister_handler();
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000335}
Jeff Mahoneyd0ce7b8562014-01-21 14:34:52 -0800336#else
337void nouveau_register_dsm_handler(void) {}
338void nouveau_unregister_dsm_handler(void) {}
339void nouveau_switcheroo_optimus_dsm(void) {}
340#endif
Dave Airlieafeb3e12010-04-07 13:55:09 +1000341
342/* retrieve the ROM in 4k blocks */
343static int nouveau_rom_call(acpi_handle rom_handle, uint8_t *bios,
344 int offset, int len)
345{
346 acpi_status status;
347 union acpi_object rom_arg_elements[2], *obj;
348 struct acpi_object_list rom_arg;
349 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL};
350
351 rom_arg.count = 2;
352 rom_arg.pointer = &rom_arg_elements[0];
353
354 rom_arg_elements[0].type = ACPI_TYPE_INTEGER;
355 rom_arg_elements[0].integer.value = offset;
356
357 rom_arg_elements[1].type = ACPI_TYPE_INTEGER;
358 rom_arg_elements[1].integer.value = len;
359
360 status = acpi_evaluate_object(rom_handle, NULL, &rom_arg, &buffer);
361 if (ACPI_FAILURE(status)) {
362 printk(KERN_INFO "failed to evaluate ROM got %s\n", acpi_format_exception(status));
363 return -ENODEV;
364 }
365 obj = (union acpi_object *)buffer.pointer;
Ben Skeggs95432942015-11-19 13:18:34 +1000366 len = min(len, (int)obj->buffer.length);
Dave Airlieafeb3e12010-04-07 13:55:09 +1000367 memcpy(bios+offset, obj->buffer.pointer, len);
368 kfree(buffer.pointer);
369 return len;
370}
371
Ben Skeggs26c9e8e2015-08-20 14:54:23 +1000372bool nouveau_acpi_rom_supported(struct device *dev)
Dave Airlieafeb3e12010-04-07 13:55:09 +1000373{
374 acpi_status status;
375 acpi_handle dhandle, rom_handle;
376
Ben Skeggs26c9e8e2015-08-20 14:54:23 +1000377 dhandle = ACPI_HANDLE(dev);
Dave Airlieafeb3e12010-04-07 13:55:09 +1000378 if (!dhandle)
379 return false;
380
381 status = acpi_get_handle(dhandle, "_ROM", &rom_handle);
382 if (ACPI_FAILURE(status))
383 return false;
384
385 nouveau_dsm_priv.rom_handle = rom_handle;
386 return true;
387}
388
389int nouveau_acpi_get_bios_chunk(uint8_t *bios, int offset, int len)
390{
391 return nouveau_rom_call(nouveau_dsm_priv.rom_handle, bios, offset, len);
392}
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000393
Ben Skeggsc0077062012-07-26 08:51:21 +1000394void *
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000395nouveau_acpi_edid(struct drm_device *dev, struct drm_connector *connector)
396{
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000397 struct acpi_device *acpidev;
398 acpi_handle handle;
399 int type, ret;
400 void *edid;
401
402 switch (connector->connector_type) {
403 case DRM_MODE_CONNECTOR_LVDS:
404 case DRM_MODE_CONNECTOR_eDP:
405 type = ACPI_VIDEO_DISPLAY_LCD;
406 break;
407 default:
Ben Skeggsc0077062012-07-26 08:51:21 +1000408 return NULL;
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000409 }
410
Rafael J. Wysocki3a83f992013-11-14 23:17:21 +0100411 handle = ACPI_HANDLE(&dev->pdev->dev);
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000412 if (!handle)
Ben Skeggsc0077062012-07-26 08:51:21 +1000413 return NULL;
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000414
415 ret = acpi_bus_get_device(handle, &acpidev);
416 if (ret)
Ben Skeggsc0077062012-07-26 08:51:21 +1000417 return NULL;
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000418
419 ret = acpi_video_get_edid(acpidev, type, -1, &edid);
420 if (ret < 0)
Ben Skeggsc0077062012-07-26 08:51:21 +1000421 return NULL;
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000422
Ben Skeggsc0077062012-07-26 08:51:21 +1000423 return kmemdup(edid, EDID_LENGTH, GFP_KERNEL);
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000424}