2 * Copyright 2010 Red Hat Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
27 #include "nouveau_drv.h"
28 #include "nouveau_pm.h"
31 legacy_perf_init(struct drm_device *dev)
33 struct drm_nouveau_private *dev_priv = dev->dev_private;
34 struct nvbios *bios = &dev_priv->vbios;
35 struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
36 char *perf, *entry, *bmp = &bios->data[bios->offset];
37 int headerlen, use_straps;
39 if (bmp[5] < 0x5 || bmp[6] < 0x14) {
40 NV_DEBUG(dev, "BMP version too old for perf\n");
44 perf = ROMPTR(bios, bmp[0x73]);
46 NV_DEBUG(dev, "No memclock table pointer found.\n");
58 use_straps = perf[1] & 1;
59 headerlen = (use_straps ? 8 : 2);
62 NV_WARN(dev, "Unknown memclock table version %x.\n", perf[0]);
66 entry = perf + headerlen;
68 entry += (nv_rd32(dev, NV_PEXTDEV_BOOT_0) & 0x3c) >> 1;
70 sprintf(pm->perflvl[0].name, "performance_level_0");
71 pm->perflvl[0].memory = ROM16(entry[0]) * 20;
76 nouveau_perf_init(struct drm_device *dev)
78 struct drm_nouveau_private *dev_priv = dev->dev_private;
79 struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
80 struct nvbios *bios = &dev_priv->vbios;
82 u8 version, headerlen, recordlen, entries;
85 u8 ramcfg = (nv_rd32(dev, NV_PEXTDEV_BOOT_0) & 0x3c) >> 2;
87 if (bios->type == NVBIOS_BIT) {
88 if (bit_table(dev, 'P', &P))
91 if (P.version != 1 && P.version != 2) {
92 NV_WARN(dev, "unknown perf for BIT P %d\n", P.version);
96 perf = ROMPTR(bios, P.data[0]);
100 recordlen = perf[3] + (perf[4] * perf[5]);
103 recordlen = perf[2] + (perf[3] * perf[4]);
107 if (bios->data[bios->offset + 6] < 0x25) {
108 legacy_perf_init(dev);
112 perf = ROMPTR(bios, bios->data[bios->offset + 0x94]);
114 NV_DEBUG(dev, "perf table pointer invalid\n");
124 entry = perf + headerlen;
125 for (i = 0; i < entries; i++) {
126 struct nouveau_pm_level *perflvl = &pm->perflvl[pm->nr_perflvl];
128 perflvl->timing = NULL;
130 if (entry[0] == 0xff) {
139 perflvl->fanspeed = entry[55];
140 perflvl->voltage = (recordlen > 56) ? entry[56] : 0;
141 perflvl->core = ROM32(entry[1]) * 10;
142 perflvl->memory = ROM32(entry[5]) * 20;
147 perflvl->fanspeed = entry[4];
148 perflvl->voltage = entry[5];
149 perflvl->core = ROM16(entry[6]) * 1000;
151 if (dev_priv->chipset == 0x49 ||
152 dev_priv->chipset == 0x4b)
153 perflvl->memory = ROM16(entry[11]) * 1000;
155 perflvl->memory = ROM16(entry[11]) * 2000;
159 perflvl->fanspeed = entry[4];
160 perflvl->voltage = entry[5];
161 perflvl->core = ROM16(entry[6]) * 1000;
162 perflvl->shader = ROM16(entry[10]) * 1000;
163 perflvl->memory = ROM16(entry[12]) * 1000;
166 perflvl->memscript = ROM16(entry[2]);
168 perflvl->fanspeed = entry[6];
169 perflvl->voltage = entry[7];
170 perflvl->core = ROM16(entry[8]) * 1000;
171 perflvl->shader = ROM16(entry[10]) * 1000;
172 perflvl->memory = ROM16(entry[12]) * 1000;
173 /*XXX: confirm on 0x35 */
174 perflvl->unk05 = ROM16(entry[16]) * 1000;
177 #define subent(n) entry[perf[2] + ((n) * perf[3])]
178 perflvl->fanspeed = 0; /*XXX*/
179 perflvl->voltage = entry[2];
180 perflvl->core = (ROM16(subent(0)) & 0xfff) * 1000;
181 perflvl->shader = (ROM16(subent(1)) & 0xfff) * 1000;
182 perflvl->memory = (ROM16(subent(2)) & 0xfff) * 1000;
186 /* make sure vid is valid */
187 if (pm->voltage.supported && perflvl->voltage) {
188 vid = nouveau_volt_vid_lookup(dev, perflvl->voltage);
190 NV_DEBUG(dev, "drop perflvl %d, bad vid\n", i);
196 /* get the corresponding memory timings */
197 if (pm->memtimings.supported) {
201 if (version > 0x15 && version < 0x40 &&
203 extra_data = perf[3] + (ramcfg * perf[5]);
204 timing_id = entry[extra_data + 1];
207 if (pm->memtimings.nr_timing > timing_id)
209 &pm->memtimings.timing[timing_id];
212 snprintf(perflvl->name, sizeof(perflvl->name),
213 "performance_level_%d", i);
222 nouveau_perf_fini(struct drm_device *dev)