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.
24 #include <subdev/bios.h>
25 #include <subdev/bios/dcb.h>
28 dcb_table(struct nvkm_bios
*bios
, u8
*ver
, u8
*hdr
, u8
*cnt
, u8
*len
)
30 struct nvkm_subdev
*subdev
= &bios
->subdev
;
31 struct nvkm_device
*device
= subdev
->device
;
34 if (device
->card_type
> NV_04
)
35 dcb
= nvbios_rd16(bios
, 0x36);
37 nvkm_warn(subdev
, "DCB table not found\n");
41 *ver
= nvbios_rd08(bios
, dcb
);
44 nvkm_warn(subdev
, "DCB version 0x%02x unknown\n", *ver
);
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);
56 if (nvbios_rd32(bios
, dcb
+ 4) == 0x4edcbdcb) {
57 u16 i2c
= nvbios_rd16(bios
, dcb
+ 2);
59 *cnt
= (i2c
- dcb
) / 8;
65 if (!nvbios_memcmp(bios
, dcb
- 7, "DEV_REC", 7)) {
66 u16 i2c
= nvbios_rd16(bios
, dcb
+ 2);
68 *cnt
= (i2c
- dcb
) / 10;
74 * v1.4 (some NV15/16, NV11+) seems the same as v1.5, but
75 * always has the same single (crt) entry, even when tv-out
76 * present, so the conclusion is this version cannot really
79 * v1.2 tables (some NV6/10, and NV15+) normally have the
80 * same 5 entries, which are not specific to the card and so
83 * v1.2 does have an I2C table that read_dcb_i2c_table can
84 * handle, but cards exist (nv11 in #14821) with a bad i2c
85 * table pointer, so use the indices parsed in
86 * parse_bmp_structure.
88 * v1.1 (NV5+, maybe some NV4) is entirely unhelpful
90 nvkm_debug(subdev
, "DCB contains no useful data\n");
94 nvkm_warn(subdev
, "DCB header validation failed\n");
99 dcb_outp(struct nvkm_bios
*bios
, u8 idx
, u8
*ver
, u8
*len
)
102 u16 dcb
= dcb_table(bios
, ver
, &hdr
, &cnt
, len
);
103 if (dcb
&& idx
< cnt
)
104 return dcb
+ hdr
+ (idx
* *len
);
109 dcb_outp_hasht(struct dcb_output
*outp
)
111 return (outp
->extdev
<< 8) | (outp
->location
<< 4) | outp
->type
;
115 dcb_outp_hashm(struct dcb_output
*outp
)
117 return (outp
->heads
<< 8) | (outp
->link
<< 6) | outp
->or;
121 dcb_outp_parse(struct nvkm_bios
*bios
, u8 idx
, u8
*ver
, u8
*len
,
122 struct dcb_output
*outp
)
124 u16 dcb
= dcb_outp(bios
, idx
, ver
, len
);
125 memset(outp
, 0x00, sizeof(*outp
));
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);
142 u32 conf
= nvbios_rd32(bios
, dcb
+ 0x04);
143 switch (outp
->type
) {
145 switch (conf
& 0x00e00000) {
146 case 0x00000000: /* 1.62 */
147 outp
->dpconf
.link_bw
= 0x06;
149 case 0x00200000: /* 2.7 */
150 outp
->dpconf
.link_bw
= 0x0a;
152 case 0x00400000: /* 5.4 */
153 outp
->dpconf
.link_bw
= 0x14;
155 case 0x00600000: /* 8.1 */
157 outp
->dpconf
.link_bw
= 0x1e;
161 switch ((conf
& 0x0f000000) >> 24) {
164 outp
->dpconf
.link_nr
= 4;
168 outp
->dpconf
.link_nr
= 2;
172 outp
->dpconf
.link_nr
= 1;
177 case DCB_OUTPUT_TMDS
:
178 case DCB_OUTPUT_LVDS
:
179 outp
->link
= (conf
& 0x00000030) >> 4;
180 outp
->sorconf
.link
= outp
->link
; /*XXX*/
182 if (outp
->location
!= 0)
183 outp
->extdev
= (conf
& 0x0000ff00) >> 8;
190 outp
->hasht
= dcb_outp_hasht(outp
);
191 outp
->hashm
= dcb_outp_hashm(outp
);
197 dcb_outp_match(struct nvkm_bios
*bios
, u16 type
, u16 mask
,
198 u8
*ver
, u8
*len
, struct dcb_output
*outp
)
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
)
211 dcb_outp_foreach(struct nvkm_bios
*bios
, void *data
,
212 int (*exec
)(struct nvkm_bios
*, void *, int, u16
))
218 while ((outp
= dcb_outp(bios
, ++idx
, &ver
, &len
))) {
219 if (nvbios_rd32(bios
, outp
) == 0x00000000)
220 break; /* seen on an NV11 with DCB v1.5 */
221 if (nvbios_rd32(bios
, outp
) == 0xffffffff)
222 break; /* seen on an NV17 with DCB v2.0 */
224 if (nvbios_rd08(bios
, outp
) == DCB_OUTPUT_UNUSED
)
226 if (nvbios_rd08(bios
, outp
) == DCB_OUTPUT_EOL
)
229 ret
= exec(bios
, data
, idx
, outp
);