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.
25 #include <subdev/bios.h>
26 #include <subdev/bios/bit.h>
27 #include <subdev/bios/disp.h>
30 nvbios_disp_table(struct nouveau_bios *bios,
31 u8 *ver, u8 *hdr, u8 *cnt, u8 *len, u8 *sub)
35 if (!bit_entry(bios, 'U', &U)) {
37 u16 data = nv_ro16(bios, U.offset);
39 *ver = nv_ro08(bios, data + 0x00);
43 *hdr = nv_ro08(bios, data + 0x01);
44 *len = nv_ro08(bios, data + 0x02);
45 *cnt = nv_ro08(bios, data + 0x03);
46 *sub = nv_ro08(bios, data + 0x04);
59 nvbios_disp_entry(struct nouveau_bios *bios, u8 idx,
60 u8 *ver, u8 *len, u8 *sub)
63 u16 data = nvbios_disp_table(bios, ver, &hdr, &cnt, len, sub);
64 if (data && idx < cnt)
65 return data + hdr + (idx * *len);
71 nvbios_disp_parse(struct nouveau_bios *bios, u8 idx,
72 u8 *ver, u8 *len, u8 *sub,
73 struct nvbios_disp *info)
75 u16 data = nvbios_disp_entry(bios, idx, ver, len, sub);
76 if (data && *len >= 2) {
77 info->data = nv_ro16(bios, data + 0);
84 nvbios_outp_entry(struct nouveau_bios *bios, u8 idx,
85 u8 *ver, u8 *hdr, u8 *cnt, u8 *len)
87 struct nvbios_disp info;
88 u16 data = nvbios_disp_parse(bios, idx, ver, len, hdr, &info);
90 *cnt = nv_ro08(bios, info.data + 0x05);
98 nvbios_outp_parse(struct nouveau_bios *bios, u8 idx,
99 u8 *ver, u8 *hdr, u8 *cnt, u8 *len,
100 struct nvbios_outp *info)
102 u16 data = nvbios_outp_entry(bios, idx, ver, hdr, cnt, len);
103 if (data && *hdr >= 0x0a) {
104 info->type = nv_ro16(bios, data + 0x00);
105 info->mask = nv_ro32(bios, data + 0x02);
106 if (*ver <= 0x20) /* match any link */
107 info->mask |= 0x00c0;
108 info->script[0] = nv_ro16(bios, data + 0x06);
109 info->script[1] = nv_ro16(bios, data + 0x08);
110 info->script[2] = 0x0000;
112 info->script[2] = nv_ro16(bios, data + 0x0a);
119 nvbios_outp_match(struct nouveau_bios *bios, u16 type, u16 mask,
120 u8 *ver, u8 *hdr, u8 *cnt, u8 *len,
121 struct nvbios_outp *info)
124 while ((data = nvbios_outp_parse(bios, idx++, ver, hdr, cnt, len, info)) || *ver) {
125 if (data && info->type == type) {
126 if ((info->mask & mask) == mask)
134 nvbios_ocfg_entry(struct nouveau_bios *bios, u16 outp, u8 idx,
135 u8 *ver, u8 *hdr, u8 *cnt, u8 *len)
138 return outp + *hdr + (idx * *len);
143 nvbios_ocfg_parse(struct nouveau_bios *bios, u16 outp, u8 idx,
144 u8 *ver, u8 *hdr, u8 *cnt, u8 *len,
145 struct nvbios_ocfg *info)
147 u16 data = nvbios_ocfg_entry(bios, outp, idx, ver, hdr, cnt, len);
149 info->match = nv_ro16(bios, data + 0x00);
150 info->clkcmp[0] = nv_ro16(bios, data + 0x02);
151 info->clkcmp[1] = nv_ro16(bios, data + 0x04);
157 nvbios_ocfg_match(struct nouveau_bios *bios, u16 outp, u16 type,
158 u8 *ver, u8 *hdr, u8 *cnt, u8 *len,
159 struct nvbios_ocfg *info)
162 while ((data = nvbios_ocfg_parse(bios, outp, idx++, ver, hdr, cnt, len, info))) {
163 if (info->match == type)
170 nvbios_oclk_match(struct nouveau_bios *bios, u16 cmp, u32 khz)
173 if (khz / 10 >= nv_ro16(bios, cmp + 0x00))
174 return nv_ro16(bios, cmp + 0x02);