blob: 7628fe7592206b5b33da955bb0115aaa7fe5ca14 [file] [log] [blame]
Ben Skeggscb75d972012-07-11 10:44:20 +10001/*
2 * Copyright 2012 Red Hat Inc.
3 *
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:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
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.
21 *
22 * Authors: Ben Skeggs
23 */
24
25
26#include "subdev/bios.h"
27#include "subdev/bios/bit.h"
Ben Skeggscb75d972012-07-11 10:44:20 +100028#include "subdev/bios/dp.h"
29
Ben Skeggs65c78662012-11-06 16:03:51 +100030static u16
31nvbios_dp_table(struct nouveau_bios *bios, u8 *ver, u8 *hdr, u8 *cnt, u8 *len)
Ben Skeggscb75d972012-07-11 10:44:20 +100032{
Ben Skeggs65c78662012-11-06 16:03:51 +100033 struct bit_entry d;
Ben Skeggscb75d972012-07-11 10:44:20 +100034
Ben Skeggs65c78662012-11-06 16:03:51 +100035 if (!bit_entry(bios, 'd', &d)) {
36 if (d.version == 1 && d.length >= 2) {
37 u16 data = nv_ro16(bios, d.offset);
Ben Skeggscb75d972012-07-11 10:44:20 +100038 if (data) {
Ben Skeggs65c78662012-11-06 16:03:51 +100039 *ver = nv_ro08(bios, data + 0x00);
40 switch (*ver) {
41 case 0x21:
42 case 0x30:
43 case 0x40:
44 *hdr = nv_ro08(bios, data + 0x01);
45 *len = nv_ro08(bios, data + 0x02);
46 *cnt = nv_ro08(bios, data + 0x03);
47 return data;
48 default:
49 break;
50 }
Ben Skeggscb75d972012-07-11 10:44:20 +100051 }
52 }
53 }
54
55 return 0x0000;
56}
57
Ben Skeggs65c78662012-11-06 16:03:51 +100058static u16
59nvbios_dpout_entry(struct nouveau_bios *bios, u8 idx,
60 u8 *ver, u8 *hdr, u8 *cnt, u8 *len)
Ben Skeggscb75d972012-07-11 10:44:20 +100061{
Ben Skeggs65c78662012-11-06 16:03:51 +100062 u16 data = nvbios_dp_table(bios, ver, hdr, cnt, len);
63 if (data && idx < *cnt) {
64 u16 outp = nv_ro16(bios, data + *hdr + idx * *len);
65 switch (*ver * !!outp) {
66 case 0x21:
67 case 0x30:
68 *hdr = nv_ro08(bios, data + 0x04);
69 *len = nv_ro08(bios, data + 0x05);
70 *cnt = nv_ro08(bios, outp + 0x04);
71 break;
72 case 0x40:
73 *hdr = nv_ro08(bios, data + 0x04);
74 *cnt = 0;
75 *len = 0;
76 break;
77 default:
78 break;
79 }
80 return outp;
81 }
82 *ver = 0x00;
83 return 0x0000;
Ben Skeggscb75d972012-07-11 10:44:20 +100084}
85
86u16
Ben Skeggs65c78662012-11-06 16:03:51 +100087nvbios_dpout_parse(struct nouveau_bios *bios, u8 idx,
88 u8 *ver, u8 *hdr, u8 *cnt, u8 *len,
89 struct nvbios_dpout *info)
Ben Skeggscb75d972012-07-11 10:44:20 +100090{
Ben Skeggs65c78662012-11-06 16:03:51 +100091 u16 data = nvbios_dpout_entry(bios, idx, ver, hdr, cnt, len);
Ben Skeggs4767fae2013-11-04 13:40:03 +100092 memset(info, 0x00, sizeof(*info));
Ben Skeggs65c78662012-11-06 16:03:51 +100093 if (data && *ver) {
94 info->type = nv_ro16(bios, data + 0x00);
95 info->mask = nv_ro16(bios, data + 0x02);
96 switch (*ver) {
97 case 0x21:
98 case 0x30:
99 info->flags = nv_ro08(bios, data + 0x05);
100 info->script[0] = nv_ro16(bios, data + 0x06);
101 info->script[1] = nv_ro16(bios, data + 0x08);
102 info->lnkcmp = nv_ro16(bios, data + 0x0a);
Ben Skeggs4767fae2013-11-04 13:40:03 +1000103 if (*len >= 0x0f) {
104 info->script[2] = nv_ro16(bios, data + 0x0c);
105 info->script[3] = nv_ro16(bios, data + 0x0e);
106 }
107 if (*len >= 0x11)
108 info->script[4] = nv_ro16(bios, data + 0x10);
Ben Skeggs65c78662012-11-06 16:03:51 +1000109 break;
110 case 0x40:
111 info->flags = nv_ro08(bios, data + 0x04);
112 info->script[0] = nv_ro16(bios, data + 0x05);
113 info->script[1] = nv_ro16(bios, data + 0x07);
114 info->lnkcmp = nv_ro16(bios, data + 0x09);
115 info->script[2] = nv_ro16(bios, data + 0x0b);
116 info->script[3] = nv_ro16(bios, data + 0x0d);
117 info->script[4] = nv_ro16(bios, data + 0x0f);
118 break;
119 default:
120 data = 0x0000;
121 break;
Ben Skeggscb75d972012-07-11 10:44:20 +1000122 }
123 }
Ben Skeggs65c78662012-11-06 16:03:51 +1000124 return data;
125}
126
127u16
128nvbios_dpout_match(struct nouveau_bios *bios, u16 type, u16 mask,
129 u8 *ver, u8 *hdr, u8 *cnt, u8 *len,
130 struct nvbios_dpout *info)
131{
132 u16 data, idx = 0;
133 while ((data = nvbios_dpout_parse(bios, idx++, ver, hdr, cnt, len, info)) || *ver) {
134 if (data && info->type == type) {
135 if ((info->mask & mask) == mask)
136 break;
137 }
138 }
139 return data;
140}
141
142static u16
143nvbios_dpcfg_entry(struct nouveau_bios *bios, u16 outp, u8 idx,
144 u8 *ver, u8 *hdr, u8 *cnt, u8 *len)
145{
146 if (*ver >= 0x40) {
147 outp = nvbios_dp_table(bios, ver, hdr, cnt, len);
148 *hdr = *hdr + (*len * * cnt);
149 *len = nv_ro08(bios, outp + 0x06);
150 *cnt = nv_ro08(bios, outp + 0x07);
151 }
152
153 if (idx < *cnt)
154 return outp + *hdr + (idx * *len);
155
Ben Skeggscb75d972012-07-11 10:44:20 +1000156 return 0x0000;
157}
Ben Skeggs65c78662012-11-06 16:03:51 +1000158
159u16
160nvbios_dpcfg_parse(struct nouveau_bios *bios, u16 outp, u8 idx,
161 u8 *ver, u8 *hdr, u8 *cnt, u8 *len,
162 struct nvbios_dpcfg *info)
163{
164 u16 data = nvbios_dpcfg_entry(bios, outp, idx, ver, hdr, cnt, len);
165 if (data) {
166 switch (*ver) {
167 case 0x21:
168 info->drv = nv_ro08(bios, data + 0x02);
169 info->pre = nv_ro08(bios, data + 0x03);
170 info->unk = nv_ro08(bios, data + 0x04);
171 break;
172 case 0x30:
173 case 0x40:
174 info->drv = nv_ro08(bios, data + 0x01);
175 info->pre = nv_ro08(bios, data + 0x02);
176 info->unk = nv_ro08(bios, data + 0x03);
177 break;
178 default:
179 data = 0x0000;
180 break;
181 }
182 }
183 return data;
184}
185
186u16
187nvbios_dpcfg_match(struct nouveau_bios *bios, u16 outp, u8 un, u8 vs, u8 pe,
188 u8 *ver, u8 *hdr, u8 *cnt, u8 *len,
189 struct nvbios_dpcfg *info)
190{
191 u8 idx = 0xff;
192 u16 data;
193
194 if (*ver >= 0x30) {
195 const u8 vsoff[] = { 0, 4, 7, 9 };
196 idx = (un * 10) + vsoff[vs] + pe;
197 } else {
198 while ((data = nvbios_dpcfg_entry(bios, outp, idx,
199 ver, hdr, cnt, len))) {
200 if (nv_ro08(bios, data + 0x00) == vs &&
201 nv_ro08(bios, data + 0x01) == pe)
202 break;
203 idx++;
204 }
205 }
206
207 return nvbios_dpcfg_parse(bios, outp, pe, ver, hdr, cnt, len, info);
208}