• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2013 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 #include <subdev/bios.h>
26 #include <subdev/bios/bit.h>
27 #include <subdev/bios/cstep.h>
28 
29 u16
nvbios_cstepTe(struct nouveau_bios * bios,u8 * ver,u8 * hdr,u8 * cnt,u8 * len,u8 * xnr,u8 * xsz)30 nvbios_cstepTe(struct nouveau_bios *bios,
31 	       u8 *ver, u8 *hdr, u8 *cnt, u8 *len, u8 *xnr, u8 *xsz)
32 {
33 	struct bit_entry bit_P;
34 	u16 cstep = 0x0000;
35 
36 	if (!bit_entry(bios, 'P', &bit_P)) {
37 		if (bit_P.version == 2)
38 			cstep = nv_ro16(bios, bit_P.offset + 0x34);
39 
40 		if (cstep) {
41 			*ver = nv_ro08(bios, cstep + 0);
42 			switch (*ver) {
43 			case 0x10:
44 				*hdr = nv_ro08(bios, cstep + 1);
45 				*cnt = nv_ro08(bios, cstep + 3);
46 				*len = nv_ro08(bios, cstep + 2);
47 				*xnr = nv_ro08(bios, cstep + 5);
48 				*xsz = nv_ro08(bios, cstep + 4);
49 				return cstep;
50 			default:
51 				break;
52 			}
53 		}
54 	}
55 
56 	return 0x0000;
57 }
58 
59 u16
nvbios_cstepEe(struct nouveau_bios * bios,int idx,u8 * ver,u8 * hdr)60 nvbios_cstepEe(struct nouveau_bios *bios, int idx, u8 *ver, u8 *hdr)
61 {
62 	u8  cnt, len, xnr, xsz;
63 	u16 data = nvbios_cstepTe(bios, ver, hdr, &cnt, &len, &xnr, &xsz);
64 	if (data && idx < cnt) {
65 		data = data + *hdr + (idx * len);
66 		*hdr = len;
67 		return data;
68 	}
69 	return 0x0000;
70 }
71 
72 u16
nvbios_cstepEp(struct nouveau_bios * bios,int idx,u8 * ver,u8 * hdr,struct nvbios_cstepE * info)73 nvbios_cstepEp(struct nouveau_bios *bios, int idx, u8 *ver, u8 *hdr,
74 	       struct nvbios_cstepE *info)
75 {
76 	u16 data = nvbios_cstepEe(bios, idx, ver, hdr);
77 	memset(info, 0x00, sizeof(*info));
78 	if (data) {
79 		info->pstate = (nv_ro16(bios, data + 0x00) & 0x01e0) >> 5;
80 		info->index   = nv_ro08(bios, data + 0x03);
81 	}
82 	return data;
83 }
84 
85 u16
nvbios_cstepEm(struct nouveau_bios * bios,u8 pstate,u8 * ver,u8 * hdr,struct nvbios_cstepE * info)86 nvbios_cstepEm(struct nouveau_bios *bios, u8 pstate, u8 *ver, u8 *hdr,
87 	       struct nvbios_cstepE *info)
88 {
89 	u32 data, idx = 0;
90 	while ((data = nvbios_cstepEp(bios, idx++, ver, hdr, info))) {
91 		if (info->pstate == pstate)
92 			break;
93 	}
94 	return data;
95 }
96 
97 u16
nvbios_cstepXe(struct nouveau_bios * bios,int idx,u8 * ver,u8 * hdr)98 nvbios_cstepXe(struct nouveau_bios *bios, int idx, u8 *ver, u8 *hdr)
99 {
100 	u8  cnt, len, xnr, xsz;
101 	u16 data = nvbios_cstepTe(bios, ver, hdr, &cnt, &len, &xnr, &xsz);
102 	if (data && idx < xnr) {
103 		data = data + *hdr + (cnt * len) + (idx * xsz);
104 		*hdr = xsz;
105 		return data;
106 	}
107 	return 0x0000;
108 }
109 
110 u16
nvbios_cstepXp(struct nouveau_bios * bios,int idx,u8 * ver,u8 * hdr,struct nvbios_cstepX * info)111 nvbios_cstepXp(struct nouveau_bios *bios, int idx, u8 *ver, u8 *hdr,
112 	       struct nvbios_cstepX *info)
113 {
114 	u16 data = nvbios_cstepXe(bios, idx, ver, hdr);
115 	memset(info, 0x00, sizeof(*info));
116 	if (data) {
117 		info->freq    = nv_ro16(bios, data + 0x00) * 1000;
118 		info->unkn[0] = nv_ro08(bios, data + 0x02);
119 		info->unkn[1] = nv_ro08(bios, data + 0x03);
120 		info->voltage = nv_ro08(bios, data + 0x04);
121 	}
122 	return data;
123 }
124