2 * Copyright 2012 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 #define ROM16(x) le16_to_cpu(*(u16 *)&(x))
27 #define ROM32(x) le32_to_cpu(*(u32 *)&(x))
30 mxms_data(struct nvkm_mxm *mxm)
37 mxms_version(struct nvkm_mxm *mxm)
39 u8 *mxms = mxms_data(mxm);
40 u16 version = (mxms[4] << 8) | mxms[5];
50 nv_debug(mxm, "unknown version %d.%d\n", mxms[4], mxms[5]);
55 mxms_headerlen(struct nvkm_mxm *mxm)
61 mxms_structlen(struct nvkm_mxm *mxm)
63 return *(u16 *)&mxms_data(mxm)[6];
67 mxms_checksum(struct nvkm_mxm *mxm)
69 u16 size = mxms_headerlen(mxm) + mxms_structlen(mxm);
70 u8 *mxms = mxms_data(mxm), sum = 0;
74 nv_debug(mxm, "checksum invalid\n");
81 mxms_valid(struct nvkm_mxm *mxm)
83 u8 *mxms = mxms_data(mxm);
84 if (*(u32 *)mxms != 0x5f4d584d) {
85 nv_debug(mxm, "signature invalid\n");
89 if (!mxms_version(mxm) || !mxms_checksum(mxm))
96 mxms_foreach(struct nvkm_mxm *mxm, u8 types,
97 bool (*exec)(struct nvkm_mxm *, u8 *, void *), void *info)
99 u8 *mxms = mxms_data(mxm);
100 u8 *desc = mxms + mxms_headerlen(mxm);
101 u8 *fini = desc + mxms_structlen(mxm) - 1;
102 while (desc < fini) {
103 u8 type = desc[0] & 0x0f;
109 case 0: /* Output Device Structure */
110 if (mxms_version(mxm) >= 0x0300)
115 case 1: /* System Cooling Capability Structure */
116 case 2: /* Thermal Structure */
117 case 3: /* Input Power Structure */
120 case 4: /* GPIO Device Structure */
123 entries = (ROM32(desc[0]) & 0x01f00000) >> 20;
125 case 5: /* Vendor Specific Structure */
128 case 6: /* Backlight Control Structure */
129 if (mxms_version(mxm) >= 0x0300) {
132 entries = (desc[1] & 0xf0) >> 4;
137 case 7: /* Fan Control Structure */
140 entries = desc[1] & 0x07;
143 nv_debug(mxm, "unknown descriptor type %d\n", type);
147 if (nv_subdev(mxm)->debug >= NV_DBG_DEBUG && (exec == NULL)) {
148 static const char * mxms_desc_name[] = {
149 "ODS", "SCCS", "TS", "IPS",
150 "GSD", "VSS", "BCS", "FCS",
155 nv_debug(mxm, "%4s: ", mxms_desc_name[type]);
156 for (j = headerlen - 1; j >= 0; j--)
157 pr_cont("%02x", dump[j]);
161 for (i = 0; i < entries; i++, dump += recordlen) {
163 for (j = recordlen - 1; j >= 0; j--)
164 pr_cont("%02x", dump[j]);
169 if (types & (1 << type)) {
170 if (!exec(mxm, desc, info))
174 desc += headerlen + (entries * recordlen);
181 mxms_output_device(struct nvkm_mxm *mxm, u8 *pdata, struct mxms_odev *desc)
183 u64 data = ROM32(pdata[0]);
184 if (mxms_version(mxm) >= 0x0300)
185 data |= (u64)ROM16(pdata[4]) << 32;
187 desc->outp_type = (data & 0x00000000000000f0ULL) >> 4;
188 desc->ddc_port = (data & 0x0000000000000f00ULL) >> 8;
189 desc->conn_type = (data & 0x000000000001f000ULL) >> 12;
190 desc->dig_conn = (data & 0x0000000000780000ULL) >> 19;