Path: blob/master/drivers/gpu/drm/nouveau/nouveau_perf.c
15112 views
/*1* Copyright 2010 Red Hat Inc.2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice shall be included in11* all copies or substantial portions of the Software.12*13* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR14* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL16* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR17* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,18* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR19* OTHER DEALINGS IN THE SOFTWARE.20*21* Authors: Ben Skeggs22*/2324#include "drmP.h"2526#include "nouveau_drv.h"27#include "nouveau_pm.h"2829static void30legacy_perf_init(struct drm_device *dev)31{32struct drm_nouveau_private *dev_priv = dev->dev_private;33struct nvbios *bios = &dev_priv->vbios;34struct nouveau_pm_engine *pm = &dev_priv->engine.pm;35char *perf, *entry, *bmp = &bios->data[bios->offset];36int headerlen, use_straps;3738if (bmp[5] < 0x5 || bmp[6] < 0x14) {39NV_DEBUG(dev, "BMP version too old for perf\n");40return;41}4243perf = ROMPTR(bios, bmp[0x73]);44if (!perf) {45NV_DEBUG(dev, "No memclock table pointer found.\n");46return;47}4849switch (perf[0]) {50case 0x12:51case 0x14:52case 0x18:53use_straps = 0;54headerlen = 1;55break;56case 0x01:57use_straps = perf[1] & 1;58headerlen = (use_straps ? 8 : 2);59break;60default:61NV_WARN(dev, "Unknown memclock table version %x.\n", perf[0]);62return;63}6465entry = perf + headerlen;66if (use_straps)67entry += (nv_rd32(dev, NV_PEXTDEV_BOOT_0) & 0x3c) >> 1;6869sprintf(pm->perflvl[0].name, "performance_level_0");70pm->perflvl[0].memory = ROM16(entry[0]) * 20;71pm->nr_perflvl = 1;72}7374static struct nouveau_pm_memtiming *75nouveau_perf_timing(struct drm_device *dev, struct bit_entry *P,76u16 memclk, u8 *entry, u8 recordlen, u8 entries)77{78struct drm_nouveau_private *dev_priv = dev->dev_private;79struct nouveau_pm_engine *pm = &dev_priv->engine.pm;80struct nvbios *bios = &dev_priv->vbios;81u8 ramcfg;82int i;8384/* perf v2 has a separate "timing map" table, we have to match85* the target memory clock to a specific entry, *then* use86* ramcfg to select the correct subentry87*/88if (P->version == 2) {89u8 *tmap = ROMPTR(bios, P->data[4]);90if (!tmap) {91NV_DEBUG(dev, "no timing map pointer\n");92return NULL;93}9495if (tmap[0] != 0x10) {96NV_WARN(dev, "timing map 0x%02x unknown\n", tmap[0]);97return NULL;98}99100entry = tmap + tmap[1];101recordlen = tmap[2] + (tmap[4] * tmap[3]);102for (i = 0; i < tmap[5]; i++, entry += recordlen) {103if (memclk >= ROM16(entry[0]) &&104memclk <= ROM16(entry[2]))105break;106}107108if (i == tmap[5]) {109NV_WARN(dev, "no match in timing map table\n");110return NULL;111}112113entry += tmap[2];114recordlen = tmap[3];115entries = tmap[4];116}117118ramcfg = (nv_rd32(dev, NV_PEXTDEV_BOOT_0) & 0x0000003c) >> 2;119if (bios->ram_restrict_tbl_ptr)120ramcfg = bios->data[bios->ram_restrict_tbl_ptr + ramcfg];121122if (ramcfg >= entries) {123NV_WARN(dev, "ramcfg strap out of bounds!\n");124return NULL;125}126127entry += ramcfg * recordlen;128if (entry[1] >= pm->memtimings.nr_timing) {129NV_WARN(dev, "timingset %d does not exist\n", entry[1]);130return NULL;131}132133return &pm->memtimings.timing[entry[1]];134}135136void137nouveau_perf_init(struct drm_device *dev)138{139struct drm_nouveau_private *dev_priv = dev->dev_private;140struct nouveau_pm_engine *pm = &dev_priv->engine.pm;141struct nvbios *bios = &dev_priv->vbios;142struct bit_entry P;143u8 version, headerlen, recordlen, entries;144u8 *perf, *entry;145int vid, i;146147if (bios->type == NVBIOS_BIT) {148if (bit_table(dev, 'P', &P))149return;150151if (P.version != 1 && P.version != 2) {152NV_WARN(dev, "unknown perf for BIT P %d\n", P.version);153return;154}155156perf = ROMPTR(bios, P.data[0]);157version = perf[0];158headerlen = perf[1];159if (version < 0x40) {160recordlen = perf[3] + (perf[4] * perf[5]);161entries = perf[2];162} else {163recordlen = perf[2] + (perf[3] * perf[4]);164entries = perf[5];165}166} else {167if (bios->data[bios->offset + 6] < 0x25) {168legacy_perf_init(dev);169return;170}171172perf = ROMPTR(bios, bios->data[bios->offset + 0x94]);173if (!perf) {174NV_DEBUG(dev, "perf table pointer invalid\n");175return;176}177178version = perf[1];179headerlen = perf[0];180recordlen = perf[3];181entries = perf[2];182}183184if (entries > NOUVEAU_PM_MAX_LEVEL) {185NV_DEBUG(dev, "perf table has too many entries - buggy vbios?\n");186entries = NOUVEAU_PM_MAX_LEVEL;187}188189entry = perf + headerlen;190for (i = 0; i < entries; i++) {191struct nouveau_pm_level *perflvl = &pm->perflvl[pm->nr_perflvl];192193perflvl->timing = NULL;194195if (entry[0] == 0xff) {196entry += recordlen;197continue;198}199200switch (version) {201case 0x12:202case 0x13:203case 0x15:204perflvl->fanspeed = entry[55];205perflvl->voltage = (recordlen > 56) ? entry[56] : 0;206perflvl->core = ROM32(entry[1]) * 10;207perflvl->memory = ROM32(entry[5]) * 20;208break;209case 0x21:210case 0x23:211case 0x24:212perflvl->fanspeed = entry[4];213perflvl->voltage = entry[5];214perflvl->core = ROM16(entry[6]) * 1000;215216if (dev_priv->chipset == 0x49 ||217dev_priv->chipset == 0x4b)218perflvl->memory = ROM16(entry[11]) * 1000;219else220perflvl->memory = ROM16(entry[11]) * 2000;221222break;223case 0x25:224perflvl->fanspeed = entry[4];225perflvl->voltage = entry[5];226perflvl->core = ROM16(entry[6]) * 1000;227perflvl->shader = ROM16(entry[10]) * 1000;228perflvl->memory = ROM16(entry[12]) * 1000;229break;230case 0x30:231perflvl->memscript = ROM16(entry[2]);232case 0x35:233perflvl->fanspeed = entry[6];234perflvl->voltage = entry[7];235perflvl->core = ROM16(entry[8]) * 1000;236perflvl->shader = ROM16(entry[10]) * 1000;237perflvl->memory = ROM16(entry[12]) * 1000;238/*XXX: confirm on 0x35 */239perflvl->unk05 = ROM16(entry[16]) * 1000;240break;241case 0x40:242#define subent(n) entry[perf[2] + ((n) * perf[3])]243perflvl->fanspeed = 0; /*XXX*/244perflvl->voltage = entry[2];245if (dev_priv->card_type == NV_50) {246perflvl->core = ROM16(subent(0)) & 0xfff;247perflvl->shader = ROM16(subent(1)) & 0xfff;248perflvl->memory = ROM16(subent(2)) & 0xfff;249} else {250perflvl->shader = ROM16(subent(3)) & 0xfff;251perflvl->core = perflvl->shader / 2;252perflvl->unk0a = ROM16(subent(4)) & 0xfff;253perflvl->memory = ROM16(subent(5)) & 0xfff;254}255256perflvl->core *= 1000;257perflvl->shader *= 1000;258perflvl->memory *= 1000;259perflvl->unk0a *= 1000;260break;261}262263/* make sure vid is valid */264if (pm->voltage.supported && perflvl->voltage) {265vid = nouveau_volt_vid_lookup(dev, perflvl->voltage);266if (vid < 0) {267NV_DEBUG(dev, "drop perflvl %d, bad vid\n", i);268entry += recordlen;269continue;270}271}272273/* get the corresponding memory timings */274if (version > 0x15) {275/* last 3 args are for < 0x40, ignored for >= 0x40 */276perflvl->timing =277nouveau_perf_timing(dev, &P,278perflvl->memory / 1000,279entry + perf[3],280perf[5], perf[4]);281}282283snprintf(perflvl->name, sizeof(perflvl->name),284"performance_level_%d", i);285perflvl->id = i;286pm->nr_perflvl++;287288entry += recordlen;289}290}291292void293nouveau_perf_fini(struct drm_device *dev)294{295}296297298