2 * Copyright 2011 Red Hat Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
25 #include <core/option.h>
27 #include <subdev/i2c.h>
28 #include <subdev/mxm.h>
29 #include <subdev/bios.h>
30 #include <subdev/bios/mxm.h>
35 mxm_shadow_rom_fetch(struct nouveau_i2c_port *i2c, u8 addr,
36 u8 offset, u8 size, u8 *data)
38 struct i2c_msg msgs[] = {
39 { .addr = addr, .flags = 0, .len = 1, .buf = &offset },
40 { .addr = addr, .flags = I2C_M_RD, .len = size, .buf = data, },
43 return i2c_transfer(&i2c->adapter, msgs, 2) == 2;
47 mxm_shadow_rom(struct nouveau_mxm *mxm, u8 version)
49 struct nouveau_bios *bios = nouveau_bios(mxm);
50 struct nouveau_i2c *i2c = nouveau_i2c(mxm);
51 struct nouveau_i2c_port *port = NULL;
52 u8 i2cidx, mxms[6], addr, size;
54 i2cidx = mxm_ddc_map(bios, 1 /* LVDS_DDC */) & 0x0f;
56 port = i2c->find(i2c, i2cidx);
61 if (!mxm_shadow_rom_fetch(port, addr, 0, 6, mxms)) {
63 if (!mxm_shadow_rom_fetch(port, addr, 0, 6, mxms))
68 size = mxms_headerlen(mxm) + mxms_structlen(mxm);
69 mxm->mxms = kmalloc(size, GFP_KERNEL);
72 mxm_shadow_rom_fetch(port, addr, 0, size, mxm->mxms))
80 #if defined(CONFIG_ACPI)
82 mxm_shadow_dsm(struct nouveau_mxm *mxm, u8 version)
84 struct nouveau_device *device = nv_device(mxm);
85 static char muid[] = {
86 0x00, 0xA4, 0x04, 0x40, 0x7D, 0x91, 0xF2, 0x4C,
87 0xB8, 0x9C, 0x79, 0xB6, 0x2F, 0xD5, 0x56, 0x65
89 u32 mxms_args[] = { 0x00000000 };
90 union acpi_object argv4 = {
91 .buffer.type = ACPI_TYPE_BUFFER,
92 .buffer.length = sizeof(mxms_args),
93 .buffer.pointer = (char *)mxms_args,
95 union acpi_object *obj;
99 handle = ACPI_HANDLE(&device->pdev->dev);
104 * spec says this can be zero to mean "highest revision", but
105 * of course there's at least one bios out there which fails
106 * unless you pass in exactly the version it supports..
108 rev = (version & 0xf0) << 4 | (version & 0x0f);
109 obj = acpi_evaluate_dsm(handle, muid, rev, 0x00000010, &argv4);
111 nv_debug(mxm, "DSM MXMS failed\n");
115 if (obj->type == ACPI_TYPE_BUFFER) {
116 mxm->mxms = kmemdup(obj->buffer.pointer,
117 obj->buffer.length, GFP_KERNEL);
118 } else if (obj->type == ACPI_TYPE_INTEGER) {
119 nv_debug(mxm, "DSM MXMS returned 0x%llx\n", obj->integer.value);
123 return mxm->mxms != NULL;
127 #if defined(CONFIG_ACPI_WMI) || defined(CONFIG_ACPI_WMI_MODULE)
129 #define WMI_WMMX_GUID "F6CB5C3C-9CAE-4EBD-B577-931EA32A2CC0"
132 wmi_wmmx_mxmi(struct nouveau_mxm *mxm, u8 version)
134 u32 mxmi_args[] = { 0x494D584D /* MXMI */, version, 0 };
135 struct acpi_buffer args = { sizeof(mxmi_args), mxmi_args };
136 struct acpi_buffer retn = { ACPI_ALLOCATE_BUFFER, NULL };
137 union acpi_object *obj;
140 status = wmi_evaluate_method(WMI_WMMX_GUID, 0, 0, &args, &retn);
141 if (ACPI_FAILURE(status)) {
142 nv_debug(mxm, "WMMX MXMI returned %d\n", status);
147 if (obj->type == ACPI_TYPE_INTEGER) {
148 version = obj->integer.value;
149 nv_debug(mxm, "WMMX MXMI version %d.%d\n",
150 (version >> 4), version & 0x0f);
153 nv_debug(mxm, "WMMX MXMI returned non-integer\n");
161 mxm_shadow_wmi(struct nouveau_mxm *mxm, u8 version)
163 u32 mxms_args[] = { 0x534D584D /* MXMS */, version, 0 };
164 struct acpi_buffer args = { sizeof(mxms_args), mxms_args };
165 struct acpi_buffer retn = { ACPI_ALLOCATE_BUFFER, NULL };
166 union acpi_object *obj;
169 if (!wmi_has_guid(WMI_WMMX_GUID)) {
170 nv_debug(mxm, "WMMX GUID not found\n");
174 mxms_args[1] = wmi_wmmx_mxmi(mxm, 0x00);
176 mxms_args[1] = wmi_wmmx_mxmi(mxm, version);
180 status = wmi_evaluate_method(WMI_WMMX_GUID, 0, 0, &args, &retn);
181 if (ACPI_FAILURE(status)) {
182 nv_debug(mxm, "WMMX MXMS returned %d\n", status);
187 if (obj->type == ACPI_TYPE_BUFFER) {
188 mxm->mxms = kmemdup(obj->buffer.pointer,
189 obj->buffer.length, GFP_KERNEL);
193 return mxm->mxms != NULL;
197 static struct mxm_shadow_h {
199 bool (*exec)(struct nouveau_mxm *, u8 version);
201 { "ROM", mxm_shadow_rom },
202 #if defined(CONFIG_ACPI)
203 { "DSM", mxm_shadow_dsm },
205 #if defined(CONFIG_ACPI_WMI) || defined(CONFIG_ACPI_WMI_MODULE)
206 { "WMI", mxm_shadow_wmi },
212 mxm_shadow(struct nouveau_mxm *mxm, u8 version)
214 struct mxm_shadow_h *shadow = _mxm_shadow;
216 nv_debug(mxm, "checking %s\n", shadow->name);
217 if (shadow->exec(mxm, version)) {
223 } while ((++shadow)->name);
228 nouveau_mxm_create_(struct nouveau_object *parent,
229 struct nouveau_object *engine,
230 struct nouveau_oclass *oclass, int length, void **pobject)
232 struct nouveau_device *device = nv_device(parent);
233 struct nouveau_bios *bios = nouveau_bios(device);
234 struct nouveau_mxm *mxm;
239 ret = nouveau_subdev_create_(parent, engine, oclass, 0, "MXM", "mxm",
245 data = mxm_table(bios, &ver, &len);
246 if (!data || !(ver = nv_ro08(bios, data))) {
247 nv_debug(mxm, "no VBIOS data, nothing to do\n");
251 nv_info(mxm, "BIOS version %d.%d\n", ver >> 4, ver & 0x0f);
253 if (mxm_shadow(mxm, ver)) {
254 nv_info(mxm, "failed to locate valid SIS\n");
256 /* we should, perhaps, fall back to some kind of limited
257 * mode here if the x86 vbios hasn't already done the
258 * work for us (so we prevent loading with completely
259 * whacked vbios tables).
267 nv_info(mxm, "MXMS Version %d.%d\n",
268 mxms_version(mxm) >> 8, mxms_version(mxm) & 0xff);
269 mxms_foreach(mxm, 0, NULL, NULL);
271 if (nouveau_boolopt(device->cfgopt, "NvMXMDCB", true))
272 mxm->action |= MXM_SANITISE_DCB;