1 | /* $NetBSD: nouveau_subdev_bios_dp.c,v 1.1.1.1 2014/08/06 12:36:28 riastradh Exp $ */ |
2 | |
3 | /* |
4 | * Copyright 2012 Red Hat Inc. |
5 | * |
6 | * Permission is hereby granted, free of charge, to any person obtaining a |
7 | * copy of this software and associated documentation files (the "Software"), |
8 | * to deal in the Software without restriction, including without limitation |
9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
10 | * and/or sell copies of the Software, and to permit persons to whom the |
11 | * Software is furnished to do so, subject to the following conditions: |
12 | * |
13 | * The above copyright notice and this permission notice shall be included in |
14 | * all copies or substantial portions of the Software. |
15 | * |
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
19 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR |
20 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
21 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
22 | * OTHER DEALINGS IN THE SOFTWARE. |
23 | * |
24 | * Authors: Ben Skeggs |
25 | */ |
26 | |
27 | |
28 | #include <sys/cdefs.h> |
29 | __KERNEL_RCSID(0, "$NetBSD: nouveau_subdev_bios_dp.c,v 1.1.1.1 2014/08/06 12:36:28 riastradh Exp $" ); |
30 | |
31 | #include "subdev/bios.h" |
32 | #include "subdev/bios/bit.h" |
33 | #include "subdev/bios/dp.h" |
34 | |
35 | static u16 |
36 | nvbios_dp_table(struct nouveau_bios *bios, u8 *ver, u8 *hdr, u8 *cnt, u8 *len) |
37 | { |
38 | struct bit_entry d; |
39 | |
40 | if (!bit_entry(bios, 'd', &d)) { |
41 | if (d.version == 1 && d.length >= 2) { |
42 | u16 data = nv_ro16(bios, d.offset); |
43 | if (data) { |
44 | *ver = nv_ro08(bios, data + 0x00); |
45 | switch (*ver) { |
46 | case 0x21: |
47 | case 0x30: |
48 | case 0x40: |
49 | *hdr = nv_ro08(bios, data + 0x01); |
50 | *len = nv_ro08(bios, data + 0x02); |
51 | *cnt = nv_ro08(bios, data + 0x03); |
52 | return data; |
53 | default: |
54 | break; |
55 | } |
56 | } |
57 | } |
58 | } |
59 | |
60 | return 0x0000; |
61 | } |
62 | |
63 | static u16 |
64 | nvbios_dpout_entry(struct nouveau_bios *bios, u8 idx, |
65 | u8 *ver, u8 *hdr, u8 *cnt, u8 *len) |
66 | { |
67 | u16 data = nvbios_dp_table(bios, ver, hdr, cnt, len); |
68 | if (data && idx < *cnt) { |
69 | u16 outp = nv_ro16(bios, data + *hdr + idx * *len); |
70 | switch (*ver * !!outp) { |
71 | case 0x21: |
72 | case 0x30: |
73 | *hdr = nv_ro08(bios, data + 0x04); |
74 | *len = nv_ro08(bios, data + 0x05); |
75 | *cnt = nv_ro08(bios, outp + 0x04); |
76 | break; |
77 | case 0x40: |
78 | *hdr = nv_ro08(bios, data + 0x04); |
79 | *cnt = 0; |
80 | *len = 0; |
81 | break; |
82 | default: |
83 | break; |
84 | } |
85 | return outp; |
86 | } |
87 | *ver = 0x00; |
88 | return 0x0000; |
89 | } |
90 | |
91 | u16 |
92 | nvbios_dpout_parse(struct nouveau_bios *bios, u8 idx, |
93 | u8 *ver, u8 *hdr, u8 *cnt, u8 *len, |
94 | struct nvbios_dpout *info) |
95 | { |
96 | u16 data = nvbios_dpout_entry(bios, idx, ver, hdr, cnt, len); |
97 | memset(info, 0x00, sizeof(*info)); |
98 | if (data && *ver) { |
99 | info->type = nv_ro16(bios, data + 0x00); |
100 | info->mask = nv_ro16(bios, data + 0x02); |
101 | switch (*ver) { |
102 | case 0x21: |
103 | case 0x30: |
104 | info->flags = nv_ro08(bios, data + 0x05); |
105 | info->script[0] = nv_ro16(bios, data + 0x06); |
106 | info->script[1] = nv_ro16(bios, data + 0x08); |
107 | info->lnkcmp = nv_ro16(bios, data + 0x0a); |
108 | if (*len >= 0x0f) { |
109 | info->script[2] = nv_ro16(bios, data + 0x0c); |
110 | info->script[3] = nv_ro16(bios, data + 0x0e); |
111 | } |
112 | if (*len >= 0x11) |
113 | info->script[4] = nv_ro16(bios, data + 0x10); |
114 | break; |
115 | case 0x40: |
116 | info->flags = nv_ro08(bios, data + 0x04); |
117 | info->script[0] = nv_ro16(bios, data + 0x05); |
118 | info->script[1] = nv_ro16(bios, data + 0x07); |
119 | info->lnkcmp = nv_ro16(bios, data + 0x09); |
120 | info->script[2] = nv_ro16(bios, data + 0x0b); |
121 | info->script[3] = nv_ro16(bios, data + 0x0d); |
122 | info->script[4] = nv_ro16(bios, data + 0x0f); |
123 | break; |
124 | default: |
125 | data = 0x0000; |
126 | break; |
127 | } |
128 | } |
129 | return data; |
130 | } |
131 | |
132 | u16 |
133 | nvbios_dpout_match(struct nouveau_bios *bios, u16 type, u16 mask, |
134 | u8 *ver, u8 *hdr, u8 *cnt, u8 *len, |
135 | struct nvbios_dpout *info) |
136 | { |
137 | u16 data, idx = 0; |
138 | while ((data = nvbios_dpout_parse(bios, idx++, ver, hdr, cnt, len, info)) || *ver) { |
139 | if (data && info->type == type) { |
140 | if ((info->mask & mask) == mask) |
141 | break; |
142 | } |
143 | } |
144 | return data; |
145 | } |
146 | |
147 | static u16 |
148 | nvbios_dpcfg_entry(struct nouveau_bios *bios, u16 outp, u8 idx, |
149 | u8 *ver, u8 *hdr, u8 *cnt, u8 *len) |
150 | { |
151 | if (*ver >= 0x40) { |
152 | outp = nvbios_dp_table(bios, ver, hdr, cnt, len); |
153 | *hdr = *hdr + (*len * * cnt); |
154 | *len = nv_ro08(bios, outp + 0x06); |
155 | *cnt = nv_ro08(bios, outp + 0x07); |
156 | } |
157 | |
158 | if (idx < *cnt) |
159 | return outp + *hdr + (idx * *len); |
160 | |
161 | return 0x0000; |
162 | } |
163 | |
164 | u16 |
165 | nvbios_dpcfg_parse(struct nouveau_bios *bios, u16 outp, u8 idx, |
166 | u8 *ver, u8 *hdr, u8 *cnt, u8 *len, |
167 | struct nvbios_dpcfg *info) |
168 | { |
169 | u16 data = nvbios_dpcfg_entry(bios, outp, idx, ver, hdr, cnt, len); |
170 | if (data) { |
171 | switch (*ver) { |
172 | case 0x21: |
173 | info->drv = nv_ro08(bios, data + 0x02); |
174 | info->pre = nv_ro08(bios, data + 0x03); |
175 | info->unk = nv_ro08(bios, data + 0x04); |
176 | break; |
177 | case 0x30: |
178 | case 0x40: |
179 | info->drv = nv_ro08(bios, data + 0x01); |
180 | info->pre = nv_ro08(bios, data + 0x02); |
181 | info->unk = nv_ro08(bios, data + 0x03); |
182 | break; |
183 | default: |
184 | data = 0x0000; |
185 | break; |
186 | } |
187 | } |
188 | return data; |
189 | } |
190 | |
191 | u16 |
192 | nvbios_dpcfg_match(struct nouveau_bios *bios, u16 outp, u8 un, u8 vs, u8 pe, |
193 | u8 *ver, u8 *hdr, u8 *cnt, u8 *len, |
194 | struct nvbios_dpcfg *info) |
195 | { |
196 | u8 idx = 0xff; |
197 | u16 data; |
198 | |
199 | if (*ver >= 0x30) { |
200 | const u8 vsoff[] = { 0, 4, 7, 9 }; |
201 | idx = (un * 10) + vsoff[vs] + pe; |
202 | } else { |
203 | while ((data = nvbios_dpcfg_entry(bios, outp, idx, |
204 | ver, hdr, cnt, len))) { |
205 | if (nv_ro08(bios, data + 0x00) == vs && |
206 | nv_ro08(bios, data + 0x01) == pe) |
207 | break; |
208 | idx++; |
209 | } |
210 | } |
211 | |
212 | return nvbios_dpcfg_parse(bios, outp, pe, ver, hdr, cnt, len, info); |
213 | } |
214 | |