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 nouveau_perf_table(struct drm_device
*dev
, u8
*ver
)
33 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
34 struct nvbios
*bios
= &dev_priv
->vbios
;
37 if (!bit_table(dev
, 'P', &P
) && P
.version
&& P
.version
<= 2) {
38 u8
*perf
= ROMPTR(dev
, P
.data
[0]);
45 if (bios
->type
== NVBIOS_BMP
) {
46 if (bios
->data
[bios
->offset
+ 6] >= 0x25) {
47 u8
*perf
= ROMPTR(dev
, bios
->data
[bios
->offset
+ 0x94]);
59 nouveau_perf_entry(struct drm_device
*dev
, int idx
,
60 u8
*ver
, u8
*hdr
, u8
*cnt
, u8
*len
)
62 u8
*perf
= nouveau_perf_table(dev
, ver
);
64 if (*ver
>= 0x12 && *ver
< 0x20 && idx
< perf
[2]) {
68 return perf
+ perf
[0] + idx
* perf
[3];
70 if (*ver
>= 0x20 && *ver
< 0x40 && idx
< perf
[2]) {
74 return perf
+ perf
[1] + idx
* (*hdr
+ (*cnt
* *len
));
76 if (*ver
>= 0x40 && *ver
< 0x41 && idx
< perf
[5]) {
80 return perf
+ perf
[1] + idx
* (*hdr
+ (*cnt
* *len
));
87 nouveau_perf_rammap(struct drm_device
*dev
, u32 freq
,
88 u8
*ver
, u8
*hdr
, u8
*cnt
, u8
*len
)
90 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
94 if (!bit_table(dev
, 'P', &P
) && P
.version
== 2) {
95 u8
*rammap
= ROMPTR(dev
, P
.data
[4]);
97 u8
*ramcfg
= rammap
+ rammap
[1];
105 for (i
= 0; i
< rammap
[5]; i
++) {
106 if (freq
>= ROM16(ramcfg
[0]) &&
107 freq
<= ROM16(ramcfg
[2]))
110 ramcfg
+= *hdr
+ (*cnt
* *len
);
117 if (dev_priv
->chipset
== 0x49 ||
118 dev_priv
->chipset
== 0x4b)
121 while ((perf
= nouveau_perf_entry(dev
, i
++, ver
, hdr
, cnt
, len
))) {
122 if (*ver
>= 0x20 && *ver
< 0x25) {
123 if (perf
[0] != 0xff && freq
<= ROM16(perf
[11]) * 1000)
126 if (*ver
>= 0x25 && *ver
< 0x40) {
127 if (perf
[0] != 0xff && freq
<= ROM16(perf
[12]) * 1000)
133 u8
*ramcfg
= perf
+ *hdr
;
143 nouveau_perf_ramcfg(struct drm_device
*dev
, u32 freq
, u8
*ver
, u8
*len
)
145 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
146 struct nvbios
*bios
= &dev_priv
->vbios
;
150 strap
= (nv_rd32(dev
, 0x101000) & 0x0000003c) >> 2;
151 if (bios
->ram_restrict_tbl_ptr
)
152 strap
= bios
->data
[bios
->ram_restrict_tbl_ptr
+ strap
];
154 rammap
= nouveau_perf_rammap(dev
, freq
, ver
, &hdr
, &cnt
, len
);
155 if (rammap
&& strap
< cnt
)
156 return rammap
+ hdr
+ (strap
* *len
);
162 nouveau_perf_timing(struct drm_device
*dev
, u32 freq
, u8
*ver
, u8
*len
)
164 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
165 struct nvbios
*bios
= &dev_priv
->vbios
;
167 u8
*perf
, *timing
= NULL
;
170 if (bios
->type
== NVBIOS_BMP
) {
171 while ((perf
= nouveau_perf_entry(dev
, i
++, ver
, &hdr
, &cnt
,
172 len
)) && *ver
== 0x15) {
173 if (freq
<= ROM32(perf
[5]) * 20) {
182 if (!bit_table(dev
, 'P', &P
)) {
184 timing
= ROMPTR(dev
, P
.data
[4]);
187 timing
= ROMPTR(dev
, P
.data
[8]);
190 if (timing
&& timing
[0] == 0x10) {
191 u8
*ramcfg
= nouveau_perf_ramcfg(dev
, freq
, ver
, len
);
192 if (ramcfg
&& ramcfg
[1] < timing
[2]) {
195 return timing
+ timing
[1] + (ramcfg
[1] * timing
[3]);
203 legacy_perf_init(struct drm_device
*dev
)
205 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
206 struct nvbios
*bios
= &dev_priv
->vbios
;
207 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
208 char *perf
, *entry
, *bmp
= &bios
->data
[bios
->offset
];
209 int headerlen
, use_straps
;
211 if (bmp
[5] < 0x5 || bmp
[6] < 0x14) {
212 NV_DEBUG(dev
, "BMP version too old for perf\n");
216 perf
= ROMPTR(dev
, bmp
[0x73]);
218 NV_DEBUG(dev
, "No memclock table pointer found.\n");
230 use_straps
= perf
[1] & 1;
231 headerlen
= (use_straps
? 8 : 2);
234 NV_WARN(dev
, "Unknown memclock table version %x.\n", perf
[0]);
238 entry
= perf
+ headerlen
;
240 entry
+= (nv_rd32(dev
, NV_PEXTDEV_BOOT_0
) & 0x3c) >> 1;
242 sprintf(pm
->perflvl
[0].name
, "performance_level_0");
243 pm
->perflvl
[0].memory
= ROM16(entry
[0]) * 20;
248 nouveau_perf_voltage(struct drm_device
*dev
, struct nouveau_pm_level
*perflvl
)
250 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
255 id
= perflvl
->volt_min
;
256 perflvl
->volt_min
= 0;
258 /* boards using voltage table version <0x40 store the voltage
259 * level directly in the perflvl entry as a multiple of 10mV
261 if (dev_priv
->engine
.pm
.voltage
.version
< 0x40) {
262 perflvl
->volt_min
= id
* 10000;
263 perflvl
->volt_max
= perflvl
->volt_min
;
267 /* on newer ones, the perflvl stores an index into yet another
268 * vbios table containing a min/max voltage value for the perflvl
270 if (bit_table(dev
, 'P', &P
) || P
.version
!= 2 || P
.length
< 34) {
271 NV_DEBUG(dev
, "where's our volt map table ptr? %d %d\n",
272 P
.version
, P
.length
);
276 vmap
= ROMPTR(dev
, P
.data
[32]);
278 NV_DEBUG(dev
, "volt map table pointer invalid\n");
283 vmap
+= vmap
[1] + (vmap
[2] * id
);
284 perflvl
->volt_min
= ROM32(vmap
[0]);
285 perflvl
->volt_max
= ROM32(vmap
[4]);
290 nouveau_perf_init(struct drm_device
*dev
)
292 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
293 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
294 struct nvbios
*bios
= &dev_priv
->vbios
;
295 u8
*perf
, ver
, hdr
, cnt
, len
;
296 int ret
, vid
, i
= -1;
298 if (bios
->type
== NVBIOS_BMP
&& bios
->data
[bios
->offset
+ 6] < 0x25) {
299 legacy_perf_init(dev
);
303 perf
= nouveau_perf_table(dev
, &ver
);
304 if (ver
>= 0x20 && ver
< 0x40)
305 pm
->fan
.pwm_divisor
= ROM16(perf
[6]);
307 while ((perf
= nouveau_perf_entry(dev
, ++i
, &ver
, &hdr
, &cnt
, &len
))) {
308 struct nouveau_pm_level
*perflvl
= &pm
->perflvl
[pm
->nr_perflvl
];
317 perflvl
->fanspeed
= perf
[55];
319 perflvl
->volt_min
= perf
[56];
320 perflvl
->core
= ROM32(perf
[1]) * 10;
321 perflvl
->memory
= ROM32(perf
[5]) * 20;
326 perflvl
->fanspeed
= perf
[4];
327 perflvl
->volt_min
= perf
[5];
328 perflvl
->shader
= ROM16(perf
[6]) * 1000;
329 perflvl
->core
= perflvl
->shader
;
330 perflvl
->core
+= (signed char)perf
[8] * 1000;
331 if (dev_priv
->chipset
== 0x49 ||
332 dev_priv
->chipset
== 0x4b)
333 perflvl
->memory
= ROM16(perf
[11]) * 1000;
335 perflvl
->memory
= ROM16(perf
[11]) * 2000;
338 perflvl
->fanspeed
= perf
[4];
339 perflvl
->volt_min
= perf
[5];
340 perflvl
->core
= ROM16(perf
[6]) * 1000;
341 perflvl
->shader
= ROM16(perf
[10]) * 1000;
342 perflvl
->memory
= ROM16(perf
[12]) * 1000;
345 perflvl
->memscript
= ROM16(perf
[2]);
347 perflvl
->fanspeed
= perf
[6];
348 perflvl
->volt_min
= perf
[7];
349 perflvl
->core
= ROM16(perf
[8]) * 1000;
350 perflvl
->shader
= ROM16(perf
[10]) * 1000;
351 perflvl
->memory
= ROM16(perf
[12]) * 1000;
352 perflvl
->vdec
= ROM16(perf
[16]) * 1000;
353 perflvl
->dom6
= ROM16(perf
[20]) * 1000;
356 #define subent(n) ((ROM16(perf[hdr + (n) * len]) & 0xfff) * 1000)
357 perflvl
->fanspeed
= 0; /*XXX*/
358 perflvl
->volt_min
= perf
[2];
359 if (dev_priv
->card_type
== NV_50
) {
360 perflvl
->core
= subent(0);
361 perflvl
->shader
= subent(1);
362 perflvl
->memory
= subent(2);
363 perflvl
->vdec
= subent(3);
364 perflvl
->unka0
= subent(4);
366 perflvl
->hub06
= subent(0);
367 perflvl
->hub01
= subent(1);
368 perflvl
->copy
= subent(2);
369 perflvl
->shader
= subent(3);
370 perflvl
->rop
= subent(4);
371 perflvl
->memory
= subent(5);
372 perflvl
->vdec
= subent(6);
373 perflvl
->daemon
= subent(10);
374 perflvl
->hub07
= subent(11);
375 perflvl
->core
= perflvl
->shader
/ 2;
380 /* make sure vid is valid */
381 nouveau_perf_voltage(dev
, perflvl
);
382 if (pm
->voltage
.supported
&& perflvl
->volt_min
) {
383 vid
= nouveau_volt_vid_lookup(dev
, perflvl
->volt_min
);
385 NV_DEBUG(dev
, "perflvl %d, bad vid\n", i
);
390 /* get the corresponding memory timings */
391 ret
= nouveau_mem_timing_calc(dev
, perflvl
->memory
,
394 NV_DEBUG(dev
, "perflvl %d, bad timing: %d\n", i
, ret
);
398 snprintf(perflvl
->name
, sizeof(perflvl
->name
),
399 "performance_level_%d", i
);
402 snprintf(perflvl
->profile
.name
, sizeof(perflvl
->profile
.name
),
404 perflvl
->profile
.func
= &nouveau_pm_static_profile_func
;
405 list_add_tail(&perflvl
->profile
.head
, &pm
->profiles
);
413 nouveau_perf_fini(struct drm_device
*dev
)