1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include <subdev/bios.h>
25#include <subdev/bios/dcb.h>
26
27u16
28dcb_table(struct nvkm_bios *bios, u8 *ver, u8 *hdr, u8 *cnt, u8 *len)
29{
30 struct nvkm_subdev *subdev = &bios->subdev;
31 struct nvkm_device *device = subdev->device;
32 u16 dcb = 0x0000;
33
34 if (device->card_type > NV_04)
35 dcb = nvbios_rd16(bios, 0x36);
36 if (!dcb) {
37 nvkm_warn(subdev, "DCB table not found\n");
38 return dcb;
39 }
40
41 *ver = nvbios_rd08(bios, dcb);
42
43 if (*ver >= 0x42) {
44 nvkm_warn(subdev, "DCB version 0x%02x unknown\n", *ver);
45 return 0x0000;
46 } else
47 if (*ver >= 0x30) {
48 if (nvbios_rd32(bios, dcb + 6) == 0x4edcbdcb) {
49 *hdr = nvbios_rd08(bios, dcb + 1);
50 *cnt = nvbios_rd08(bios, dcb + 2);
51 *len = nvbios_rd08(bios, dcb + 3);
52 return dcb;
53 }
54 } else
55 if (*ver >= 0x20) {
56 if (nvbios_rd32(bios, dcb + 4) == 0x4edcbdcb) {
57 u16 i2c = nvbios_rd16(bios, dcb + 2);
58 *hdr = 8;
59 *cnt = (i2c - dcb) / 8;
60 *len = 8;
61 return dcb;
62 }
63 } else
64 if (*ver >= 0x15) {
65 if (!nvbios_memcmp(bios, dcb - 7, "DEV_REC", 7)) {
66 u16 i2c = nvbios_rd16(bios, dcb + 2);
67 *hdr = 4;
68 *cnt = (i2c - dcb) / 10;
69 *len = 10;
70 return dcb;
71 }
72 } else {
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90 nvkm_debug(subdev, "DCB contains no useful data\n");
91 return 0x0000;
92 }
93
94 nvkm_warn(subdev, "DCB header validation failed\n");
95 return 0x0000;
96}
97
98u16
99dcb_outp(struct nvkm_bios *bios, u8 idx, u8 *ver, u8 *len)
100{
101 u8 hdr, cnt;
102 u16 dcb = dcb_table(bios, ver, &hdr, &cnt, len);
103 if (dcb && idx < cnt)
104 return dcb + hdr + (idx * *len);
105 return 0x0000;
106}
107
108static inline u16
109dcb_outp_hasht(struct dcb_output *outp)
110{
111 return (outp->extdev << 8) | (outp->location << 4) | outp->type;
112}
113
114static inline u16
115dcb_outp_hashm(struct dcb_output *outp)
116{
117 return (outp->heads << 8) | (outp->link << 6) | outp->or;
118}
119
120u16
121dcb_outp_parse(struct nvkm_bios *bios, u8 idx, u8 *ver, u8 *len,
122 struct dcb_output *outp)
123{
124 u16 dcb = dcb_outp(bios, idx, ver, len);
125 memset(outp, 0x00, sizeof(*outp));
126 if (dcb) {
127 if (*ver >= 0x20) {
128 u32 conn = nvbios_rd32(bios, dcb + 0x00);
129 outp->or = (conn & 0x0f000000) >> 24;
130 outp->location = (conn & 0x00300000) >> 20;
131 outp->bus = (conn & 0x000f0000) >> 16;
132 outp->connector = (conn & 0x0000f000) >> 12;
133 outp->heads = (conn & 0x00000f00) >> 8;
134 outp->i2c_index = (conn & 0x000000f0) >> 4;
135 outp->type = (conn & 0x0000000f);
136 outp->link = 0;
137 } else {
138 dcb = 0x0000;
139 }
140
141 if (*ver >= 0x40) {
142 u32 conf = nvbios_rd32(bios, dcb + 0x04);
143 switch (outp->type) {
144 case DCB_OUTPUT_DP:
145 switch (conf & 0x00e00000) {
146 case 0x00000000:
147 outp->dpconf.link_bw = 0x06;
148 break;
149 case 0x00200000:
150 outp->dpconf.link_bw = 0x0a;
151 break;
152 case 0x00400000:
153 outp->dpconf.link_bw = 0x14;
154 break;
155 case 0x00600000:
156 default:
157 outp->dpconf.link_bw = 0x1e;
158 break;
159 }
160
161 switch ((conf & 0x0f000000) >> 24) {
162 case 0xf:
163 case 0x4:
164 outp->dpconf.link_nr = 4;
165 break;
166 case 0x3:
167 case 0x2:
168 outp->dpconf.link_nr = 2;
169 break;
170 case 0x1:
171 default:
172 outp->dpconf.link_nr = 1;
173 break;
174 }
175
176
177 case DCB_OUTPUT_TMDS:
178 case DCB_OUTPUT_LVDS:
179 outp->link = (conf & 0x00000030) >> 4;
180 outp->sorconf.link = outp->link;
181 outp->extdev = 0x00;
182 if (outp->location != 0)
183 outp->extdev = (conf & 0x0000ff00) >> 8;
184 break;
185 default:
186 break;
187 }
188 }
189
190 outp->hasht = dcb_outp_hasht(outp);
191 outp->hashm = dcb_outp_hashm(outp);
192 }
193 return dcb;
194}
195
196u16
197dcb_outp_match(struct nvkm_bios *bios, u16 type, u16 mask,
198 u8 *ver, u8 *len, struct dcb_output *outp)
199{
200 u16 dcb, idx = 0;
201 while ((dcb = dcb_outp_parse(bios, idx++, ver, len, outp))) {
202 if ((dcb_outp_hasht(outp) & 0x00ff) == (type & 0x00ff)) {
203 if ((dcb_outp_hashm(outp) & mask) == mask)
204 break;
205 }
206 }
207 return dcb;
208}
209
210int
211dcb_outp_foreach(struct nvkm_bios *bios, void *data,
212 int (*exec)(struct nvkm_bios *, void *, int, u16))
213{
214 int ret, idx = -1;
215 u8 ver, len;
216 u16 outp;
217
218 while ((outp = dcb_outp(bios, ++idx, &ver, &len))) {
219 if (nvbios_rd32(bios, outp) == 0x00000000)
220 break;
221 if (nvbios_rd32(bios, outp) == 0xffffffff)
222 break;
223
224 if (nvbios_rd08(bios, outp) == DCB_OUTPUT_UNUSED)
225 continue;
226 if (nvbios_rd08(bios, outp) == DCB_OUTPUT_EOL)
227 break;
228
229 ret = exec(bios, data, idx, outp);
230 if (ret)
231 return ret;
232 }
233
234 return 0;
235}
236