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.
26 #include <core/option.h>
27 #include <subdev/bios.h>
28 #include <subdev/bios/mxm.h>
29 #include <subdev/i2c.h>
32 mxm_shadow_rom_fetch(struct nvkm_i2c_bus
*bus
, u8 addr
,
33 u8 offset
, u8 size
, u8
*data
)
35 struct i2c_msg msgs
[] = {
36 { .addr
= addr
, .flags
= 0, .len
= 1, .buf
= &offset
},
37 { .addr
= addr
, .flags
= I2C_M_RD
, .len
= size
, .buf
= data
, },
40 return i2c_transfer(&bus
->i2c
, msgs
, 2) == 2;
44 mxm_shadow_rom(struct nvkm_mxm
*mxm
, u8 version
)
46 struct nvkm_device
*device
= mxm
->subdev
.device
;
47 struct nvkm_bios
*bios
= device
->bios
;
48 struct nvkm_i2c
*i2c
= device
->i2c
;
49 struct nvkm_i2c_bus
*bus
= NULL
;
50 u8 i2cidx
, mxms
[6], addr
, size
;
52 i2cidx
= mxm_ddc_map(bios
, 1 /* LVDS_DDC */) & 0x0f;
54 bus
= nvkm_i2c_bus_find(i2c
, i2cidx
);
59 if (!mxm_shadow_rom_fetch(bus
, addr
, 0, 6, mxms
)) {
61 if (!mxm_shadow_rom_fetch(bus
, addr
, 0, 6, mxms
))
66 size
= mxms_headerlen(mxm
) + mxms_structlen(mxm
);
67 mxm
->mxms
= kmalloc(size
, GFP_KERNEL
);
70 mxm_shadow_rom_fetch(bus
, addr
, 0, size
, mxm
->mxms
))
78 #if defined(CONFIG_ACPI)
80 mxm_shadow_dsm(struct nvkm_mxm
*mxm
, u8 version
)
82 struct nvkm_subdev
*subdev
= &mxm
->subdev
;
83 struct nvkm_device
*device
= subdev
->device
;
85 GUID_INIT(0x4004A400, 0x917D, 0x4CF2,
86 0xB8, 0x9C, 0x79, 0xB6, 0x2F, 0xD5, 0x56, 0x65);
87 u32 mxms_args
[] = { 0x00000000 };
88 union acpi_object argv4
= {
89 .buffer
.type
= ACPI_TYPE_BUFFER
,
90 .buffer
.length
= sizeof(mxms_args
),
91 .buffer
.pointer
= (char *)mxms_args
,
93 union acpi_object
*obj
;
97 handle
= ACPI_HANDLE(device
->dev
);
102 * spec says this can be zero to mean "highest revision", but
103 * of course there's at least one bios out there which fails
104 * unless you pass in exactly the version it supports..
106 rev
= (version
& 0xf0) << 4 | (version
& 0x0f);
107 obj
= acpi_evaluate_dsm(handle
, &muid
, rev
, 0x00000010, &argv4
);
109 nvkm_debug(subdev
, "DSM MXMS failed\n");
113 if (obj
->type
== ACPI_TYPE_BUFFER
) {
114 mxm
->mxms
= kmemdup(obj
->buffer
.pointer
,
115 obj
->buffer
.length
, GFP_KERNEL
);
116 } else if (obj
->type
== ACPI_TYPE_INTEGER
) {
117 nvkm_debug(subdev
, "DSM MXMS returned 0x%llx\n",
122 return mxm
->mxms
!= NULL
;
126 #if defined(CONFIG_ACPI_WMI) || defined(CONFIG_ACPI_WMI_MODULE)
128 #define WMI_WMMX_GUID "F6CB5C3C-9CAE-4EBD-B577-931EA32A2CC0"
131 wmi_wmmx_mxmi(struct nvkm_mxm
*mxm
, u8 version
)
133 struct nvkm_subdev
*subdev
= &mxm
->subdev
;
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 nvkm_debug(subdev
, "WMMX MXMI returned %d\n", status
);
147 if (obj
->type
== ACPI_TYPE_INTEGER
) {
148 version
= obj
->integer
.value
;
149 nvkm_debug(subdev
, "WMMX MXMI version %d.%d\n",
150 (version
>> 4), version
& 0x0f);
153 nvkm_debug(subdev
, "WMMX MXMI returned non-integer\n");
161 mxm_shadow_wmi(struct nvkm_mxm
*mxm
, u8 version
)
163 struct nvkm_subdev
*subdev
= &mxm
->subdev
;
164 u32 mxms_args
[] = { 0x534D584D /* MXMS */, version
, 0 };
165 struct acpi_buffer args
= { sizeof(mxms_args
), mxms_args
};
166 struct acpi_buffer retn
= { ACPI_ALLOCATE_BUFFER
, NULL
};
167 union acpi_object
*obj
;
170 if (!wmi_has_guid(WMI_WMMX_GUID
)) {
171 nvkm_debug(subdev
, "WMMX GUID not found\n");
175 mxms_args
[1] = wmi_wmmx_mxmi(mxm
, 0x00);
177 mxms_args
[1] = wmi_wmmx_mxmi(mxm
, version
);
181 status
= wmi_evaluate_method(WMI_WMMX_GUID
, 0, 0, &args
, &retn
);
182 if (ACPI_FAILURE(status
)) {
183 nvkm_debug(subdev
, "WMMX MXMS returned %d\n", status
);
188 if (obj
->type
== ACPI_TYPE_BUFFER
) {
189 mxm
->mxms
= kmemdup(obj
->buffer
.pointer
,
190 obj
->buffer
.length
, GFP_KERNEL
);
194 return mxm
->mxms
!= NULL
;
198 static struct mxm_shadow_h
{
200 bool (*exec
)(struct nvkm_mxm
*, u8 version
);
202 { "ROM", mxm_shadow_rom
},
203 #if defined(CONFIG_ACPI)
204 { "DSM", mxm_shadow_dsm
},
206 #if defined(CONFIG_ACPI_WMI) || defined(CONFIG_ACPI_WMI_MODULE)
207 { "WMI", mxm_shadow_wmi
},
213 mxm_shadow(struct nvkm_mxm
*mxm
, u8 version
)
215 struct mxm_shadow_h
*shadow
= _mxm_shadow
;
217 nvkm_debug(&mxm
->subdev
, "checking %s\n", shadow
->name
);
218 if (shadow
->exec(mxm
, version
)) {
224 } while ((++shadow
)->name
);
228 static const struct nvkm_subdev_func
233 nvkm_mxm_new_(struct nvkm_device
*device
, int index
, struct nvkm_mxm
**pmxm
)
235 struct nvkm_bios
*bios
= device
->bios
;
236 struct nvkm_mxm
*mxm
;
240 if (!(mxm
= *pmxm
= kzalloc(sizeof(*mxm
), GFP_KERNEL
)))
243 nvkm_subdev_ctor(&nvkm_mxm
, device
, index
, &mxm
->subdev
);
245 data
= mxm_table(bios
, &ver
, &len
);
246 if (!data
|| !(ver
= nvbios_rd08(bios
, data
))) {
247 nvkm_debug(&mxm
->subdev
, "no VBIOS data, nothing to do\n");
251 nvkm_info(&mxm
->subdev
, "BIOS version %d.%d\n", ver
>> 4, ver
& 0x0f);
252 nvkm_debug(&mxm
->subdev
, "module flags: %02x\n",
253 nvbios_rd08(bios
, data
+ 0x01));
254 nvkm_debug(&mxm
->subdev
, "config flags: %02x\n",
255 nvbios_rd08(bios
, data
+ 0x02));
257 if (mxm_shadow(mxm
, ver
)) {
258 nvkm_warn(&mxm
->subdev
, "failed to locate valid SIS\n");
260 /* we should, perhaps, fall back to some kind of limited
261 * mode here if the x86 vbios hasn't already done the
262 * work for us (so we prevent loading with completely
263 * whacked vbios tables).
271 nvkm_debug(&mxm
->subdev
, "MXMS Version %d.%d\n",
272 mxms_version(mxm
) >> 8, mxms_version(mxm
) & 0xff);
273 mxms_foreach(mxm
, 0, NULL
, NULL
);
275 if (nvkm_boolopt(device
->cfgopt
, "NvMXMDCB", true))
276 mxm
->action
|= MXM_SANITISE_DCB
;