• 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/boost.h>
28 
29 u16
nvbios_boostTe(struct nouveau_bios * bios,u8 * ver,u8 * hdr,u8 * cnt,u8 * len,u8 * snr,u8 * ssz)30 nvbios_boostTe(struct nouveau_bios *bios,
31 	       u8 *ver, u8 *hdr, u8 *cnt, u8 *len, u8 *snr, u8 *ssz)
32 {
33 	struct bit_entry bit_P;
34 	u16 boost = 0x0000;
35 
36 	if (!bit_entry(bios, 'P', &bit_P)) {
37 		if (bit_P.version == 2)
38 			boost = nv_ro16(bios, bit_P.offset + 0x30);
39 
40 		if (boost) {
41 			*ver = nv_ro08(bios, boost + 0);
42 			switch (*ver) {
43 			case 0x11:
44 				*hdr = nv_ro08(bios, boost + 1);
45 				*cnt = nv_ro08(bios, boost + 5);
46 				*len = nv_ro08(bios, boost + 2);
47 				*snr = nv_ro08(bios, boost + 4);
48 				*ssz = nv_ro08(bios, boost + 3);
49 				return boost;
50 			default:
51 				break;
52 			}
53 		}
54 	}
55 
56 	return 0x0000;
57 }
58 
59 u16
nvbios_boostEe(struct nouveau_bios * bios,int idx,u8 * ver,u8 * hdr,u8 * cnt,u8 * len)60 nvbios_boostEe(struct nouveau_bios *bios, int idx,
61 	       u8 *ver, u8 *hdr, u8 *cnt, u8 *len)
62 {
63 	u8  snr, ssz;
64 	u16 data = nvbios_boostTe(bios, ver, hdr, cnt, len, &snr, &ssz);
65 	if (data && idx < *cnt) {
66 		data = data + *hdr + (idx * (*len + (snr * ssz)));
67 		*hdr = *len;
68 		*cnt = snr;
69 		*len = ssz;
70 		return data;
71 	}
72 	return 0x0000;
73 }
74 
75 u16
nvbios_boostEp(struct nouveau_bios * bios,int idx,u8 * ver,u8 * hdr,u8 * cnt,u8 * len,struct nvbios_boostE * info)76 nvbios_boostEp(struct nouveau_bios *bios, int idx,
77 	       u8 *ver, u8 *hdr, u8 *cnt, u8 *len, struct nvbios_boostE *info)
78 {
79 	u16 data = nvbios_boostEe(bios, idx, ver, hdr, cnt, len);
80 	memset(info, 0x00, sizeof(*info));
81 	if (data) {
82 		info->pstate = (nv_ro16(bios, data + 0x00) & 0x01e0) >> 5;
83 		info->min    =  nv_ro16(bios, data + 0x02) * 1000;
84 		info->max    =  nv_ro16(bios, data + 0x04) * 1000;
85 	}
86 	return data;
87 }
88 
89 u16
nvbios_boostEm(struct nouveau_bios * bios,u8 pstate,u8 * ver,u8 * hdr,u8 * cnt,u8 * len,struct nvbios_boostE * info)90 nvbios_boostEm(struct nouveau_bios *bios, u8 pstate,
91 	       u8 *ver, u8 *hdr, u8 *cnt, u8 *len, struct nvbios_boostE *info)
92 {
93 	u32 data, idx = 0;
94 	while ((data = nvbios_boostEp(bios, idx++, ver, hdr, cnt, len, info))) {
95 		if (info->pstate == pstate)
96 			break;
97 	}
98 	return data;
99 }
100 
101 u16
nvbios_boostSe(struct nouveau_bios * bios,int idx,u16 data,u8 * ver,u8 * hdr,u8 cnt,u8 len)102 nvbios_boostSe(struct nouveau_bios *bios, int idx,
103 	       u16 data, u8 *ver, u8 *hdr, u8 cnt, u8 len)
104 {
105 	if (data && idx < cnt) {
106 		data = data + *hdr + (idx * len);
107 		*hdr = len;
108 		return data;
109 	}
110 	return 0x0000;
111 }
112 
113 u16
nvbios_boostSp(struct nouveau_bios * bios,int idx,u16 data,u8 * ver,u8 * hdr,u8 cnt,u8 len,struct nvbios_boostS * info)114 nvbios_boostSp(struct nouveau_bios *bios, int idx,
115 	       u16 data, u8 *ver, u8 *hdr, u8 cnt, u8 len,
116 	       struct nvbios_boostS *info)
117 {
118 	data = nvbios_boostSe(bios, idx, data, ver, hdr, cnt, len);
119 	memset(info, 0x00, sizeof(*info));
120 	if (data) {
121 		info->domain  = nv_ro08(bios, data + 0x00);
122 		info->percent = nv_ro08(bios, data + 0x01);
123 		info->min     = nv_ro16(bios, data + 0x02) * 1000;
124 		info->max     = nv_ro16(bios, data + 0x04) * 1000;
125 	}
126 	return data;
127 }
128