1c39f472eSBen Skeggs /*
2c39f472eSBen Skeggs * Copyright 2013 Red Hat Inc.
3c39f472eSBen Skeggs *
4c39f472eSBen Skeggs * Permission is hereby granted, free of charge, to any person obtaining a
5c39f472eSBen Skeggs * copy of this software and associated documentation files (the "Software"),
6c39f472eSBen Skeggs * to deal in the Software without restriction, including without limitation
7c39f472eSBen Skeggs * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8c39f472eSBen Skeggs * and/or sell copies of the Software, and to permit persons to whom the
9c39f472eSBen Skeggs * Software is furnished to do so, subject to the following conditions:
10c39f472eSBen Skeggs *
11c39f472eSBen Skeggs * The above copyright notice and this permission notice shall be included in
12c39f472eSBen Skeggs * all copies or substantial portions of the Software.
13c39f472eSBen Skeggs *
14c39f472eSBen Skeggs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15c39f472eSBen Skeggs * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16c39f472eSBen Skeggs * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17c39f472eSBen Skeggs * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18c39f472eSBen Skeggs * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19c39f472eSBen Skeggs * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20c39f472eSBen Skeggs * OTHER DEALINGS IN THE SOFTWARE.
21c39f472eSBen Skeggs *
22c39f472eSBen Skeggs * Authors: Ben Skeggs
23c39f472eSBen Skeggs */
24c39f472eSBen Skeggs #include <subdev/bios.h>
25c39f472eSBen Skeggs #include <subdev/bios/bit.h>
26c39f472eSBen Skeggs #include <subdev/bios/boost.h>
27c39f472eSBen Skeggs
2858786017SBen Skeggs u32
nvbios_boostTe(struct nvkm_bios * bios,u8 * ver,u8 * hdr,u8 * cnt,u8 * len,u8 * snr,u8 * ssz)29d390b480SBen Skeggs nvbios_boostTe(struct nvkm_bios *bios,
30c39f472eSBen Skeggs u8 *ver, u8 *hdr, u8 *cnt, u8 *len, u8 *snr, u8 *ssz)
31c39f472eSBen Skeggs {
32c39f472eSBen Skeggs struct bit_entry bit_P;
3358786017SBen Skeggs u32 boost = 0;
34c39f472eSBen Skeggs
35c39f472eSBen Skeggs if (!bit_entry(bios, 'P', &bit_P)) {
36*a7cb78baSBen Skeggs if (bit_P.version == 2 && bit_P.length >= 0x34)
3758786017SBen Skeggs boost = nvbios_rd32(bios, bit_P.offset + 0x30);
38c39f472eSBen Skeggs
39c39f472eSBen Skeggs if (boost) {
407f5f518fSBen Skeggs *ver = nvbios_rd08(bios, boost + 0);
41c39f472eSBen Skeggs switch (*ver) {
42c39f472eSBen Skeggs case 0x11:
437f5f518fSBen Skeggs *hdr = nvbios_rd08(bios, boost + 1);
447f5f518fSBen Skeggs *cnt = nvbios_rd08(bios, boost + 5);
457f5f518fSBen Skeggs *len = nvbios_rd08(bios, boost + 2);
467f5f518fSBen Skeggs *snr = nvbios_rd08(bios, boost + 4);
477f5f518fSBen Skeggs *ssz = nvbios_rd08(bios, boost + 3);
48c39f472eSBen Skeggs return boost;
49c39f472eSBen Skeggs default:
50c39f472eSBen Skeggs break;
51c39f472eSBen Skeggs }
52c39f472eSBen Skeggs }
53c39f472eSBen Skeggs }
54c39f472eSBen Skeggs
5558786017SBen Skeggs return 0;
56c39f472eSBen Skeggs }
57c39f472eSBen Skeggs
5858786017SBen Skeggs u32
nvbios_boostEe(struct nvkm_bios * bios,int idx,u8 * ver,u8 * hdr,u8 * cnt,u8 * len)59d390b480SBen Skeggs nvbios_boostEe(struct nvkm_bios *bios, int idx,
60c39f472eSBen Skeggs u8 *ver, u8 *hdr, u8 *cnt, u8 *len)
61c39f472eSBen Skeggs {
62c39f472eSBen Skeggs u8 snr, ssz;
6358786017SBen Skeggs u32 data = nvbios_boostTe(bios, ver, hdr, cnt, len, &snr, &ssz);
64c39f472eSBen Skeggs if (data && idx < *cnt) {
65c39f472eSBen Skeggs data = data + *hdr + (idx * (*len + (snr * ssz)));
66c39f472eSBen Skeggs *hdr = *len;
67c39f472eSBen Skeggs *cnt = snr;
68c39f472eSBen Skeggs *len = ssz;
69c39f472eSBen Skeggs return data;
70c39f472eSBen Skeggs }
7158786017SBen Skeggs return 0;
72c39f472eSBen Skeggs }
73c39f472eSBen Skeggs
7458786017SBen Skeggs u32
nvbios_boostEp(struct nvkm_bios * bios,int idx,u8 * ver,u8 * hdr,u8 * cnt,u8 * len,struct nvbios_boostE * info)75d390b480SBen Skeggs nvbios_boostEp(struct nvkm_bios *bios, int idx,
76c39f472eSBen Skeggs u8 *ver, u8 *hdr, u8 *cnt, u8 *len, struct nvbios_boostE *info)
77c39f472eSBen Skeggs {
7858786017SBen Skeggs u32 data = nvbios_boostEe(bios, idx, ver, hdr, cnt, len);
79c39f472eSBen Skeggs memset(info, 0x00, sizeof(*info));
80c39f472eSBen Skeggs if (data) {
817f5f518fSBen Skeggs info->pstate = (nvbios_rd16(bios, data + 0x00) & 0x01e0) >> 5;
827f5f518fSBen Skeggs info->min = nvbios_rd16(bios, data + 0x02) * 1000;
837f5f518fSBen Skeggs info->max = nvbios_rd16(bios, data + 0x04) * 1000;
84c39f472eSBen Skeggs }
85c39f472eSBen Skeggs return data;
86c39f472eSBen Skeggs }
87c39f472eSBen Skeggs
8858786017SBen Skeggs u32
nvbios_boostEm(struct nvkm_bios * bios,u8 pstate,u8 * ver,u8 * hdr,u8 * cnt,u8 * len,struct nvbios_boostE * info)89d390b480SBen Skeggs nvbios_boostEm(struct nvkm_bios *bios, u8 pstate,
90c39f472eSBen Skeggs u8 *ver, u8 *hdr, u8 *cnt, u8 *len, struct nvbios_boostE *info)
91c39f472eSBen Skeggs {
92c39f472eSBen Skeggs u32 data, idx = 0;
93c39f472eSBen Skeggs while ((data = nvbios_boostEp(bios, idx++, ver, hdr, cnt, len, info))) {
94c39f472eSBen Skeggs if (info->pstate == pstate)
95c39f472eSBen Skeggs break;
96c39f472eSBen Skeggs }
97c39f472eSBen Skeggs return data;
98c39f472eSBen Skeggs }
99c39f472eSBen Skeggs
10058786017SBen Skeggs u32
nvbios_boostSe(struct nvkm_bios * bios,int idx,u32 data,u8 * ver,u8 * hdr,u8 cnt,u8 len)101d390b480SBen Skeggs nvbios_boostSe(struct nvkm_bios *bios, int idx,
10258786017SBen Skeggs u32 data, u8 *ver, u8 *hdr, u8 cnt, u8 len)
103c39f472eSBen Skeggs {
104c39f472eSBen Skeggs if (data && idx < cnt) {
105c39f472eSBen Skeggs data = data + *hdr + (idx * len);
106c39f472eSBen Skeggs *hdr = len;
107c39f472eSBen Skeggs return data;
108c39f472eSBen Skeggs }
10958786017SBen Skeggs return 0;
110c39f472eSBen Skeggs }
111c39f472eSBen Skeggs
11258786017SBen Skeggs u32
nvbios_boostSp(struct nvkm_bios * bios,int idx,u32 data,u8 * ver,u8 * hdr,u8 cnt,u8 len,struct nvbios_boostS * info)113d390b480SBen Skeggs nvbios_boostSp(struct nvkm_bios *bios, int idx,
11458786017SBen Skeggs u32 data, u8 *ver, u8 *hdr, u8 cnt, u8 len,
115c39f472eSBen Skeggs struct nvbios_boostS *info)
116c39f472eSBen Skeggs {
117c39f472eSBen Skeggs data = nvbios_boostSe(bios, idx, data, ver, hdr, cnt, len);
118c39f472eSBen Skeggs memset(info, 0x00, sizeof(*info));
119c39f472eSBen Skeggs if (data) {
1207f5f518fSBen Skeggs info->domain = nvbios_rd08(bios, data + 0x00);
1217f5f518fSBen Skeggs info->percent = nvbios_rd08(bios, data + 0x01);
1227f5f518fSBen Skeggs info->min = nvbios_rd16(bios, data + 0x02) * 1000;
1237f5f518fSBen Skeggs info->max = nvbios_rd16(bios, data + 0x04) * 1000;
124c39f472eSBen Skeggs }
125c39f472eSBen Skeggs return data;
126c39f472eSBen Skeggs }
127