static u8 * nouveau_perf_table(struct drm_device *dev, u8 *ver) { struct drm_nouveau_private *dev_priv = dev->dev_private; struct nvbios *bios = &dev_priv->vbios; struct bit_entry P; if (!bit_table(dev, 'P', &P) && P.version && P.version <= 2) { u8 *perf = ROMPTR(dev, P.data[0]); if (perf) { *ver = perf[0]; return perf; } } if (bios->type == NVBIOS_BMP) { if (bios->data[bios->offset + 6] >= 0x25) { u8 *perf = ROMPTR(dev, bios->data[bios->offset + 0x94]); if (perf) { *ver = perf[1]; return perf; } } } return NULL; }
u8 * nouveau_perf_rammap(struct drm_device *dev, u32 freq, u8 *ver, u8 *hdr, u8 *cnt, u8 *len) { struct drm_nouveau_private *dev_priv = dev->dev_private; struct bit_entry P; u8 *perf, i = 0; if (!bit_table(dev, 'P', &P) && P.version == 2) { u8 *rammap = ROMPTR(dev, P.data[4]); if (rammap) { u8 *ramcfg = rammap + rammap[1]; *ver = rammap[0]; *hdr = rammap[2]; *cnt = rammap[4]; *len = rammap[3]; freq /= 1000; for (i = 0; i < rammap[5]; i++) { if (freq >= ROM16(ramcfg[0]) && freq <= ROM16(ramcfg[2])) return ramcfg; ramcfg += *hdr + (*cnt * *len); } } return NULL; } if (dev_priv->chipset == 0x49 || dev_priv->chipset == 0x4b) freq /= 2; while ((perf = nouveau_perf_entry(dev, i++, ver, hdr, cnt, len))) { if (*ver >= 0x20 && *ver < 0x25) { if (perf[0] != 0xff && freq <= ROM16(perf[11]) * 1000) break; } else if (*ver >= 0x25 && *ver < 0x40) { if (perf[0] != 0xff && freq <= ROM16(perf[12]) * 1000) break; } } if (perf) { u8 *ramcfg = perf + *hdr; *ver = 0x00; *hdr = 0; return ramcfg; } return NULL; }
static void nouveau_perf_voltage(struct drm_device *dev, struct nouveau_pm_level *perflvl) { struct drm_nouveau_private *dev_priv = dev->dev_private; struct bit_entry P; u8 *vmap; int id; id = perflvl->volt_min; perflvl->volt_min = 0; /* boards using voltage table version <0x40 store the voltage * level directly in the perflvl entry as a multiple of 10mV */ if (dev_priv->engine.pm.voltage.version < 0x40) { perflvl->volt_min = id * 10000; perflvl->volt_max = perflvl->volt_min; return; } /* on newer ones, the perflvl stores an index into yet another * vbios table containing a min/max voltage value for the perflvl */ if (bit_table(dev, 'P', &P) || P.version != 2 || P.length < 34) { NV_DEBUG(dev, "where's our volt map table ptr? %d %d\n", P.version, P.length); return; } vmap = ROMPTR(dev, P.data[32]); if (!vmap) { NV_DEBUG(dev, "volt map table pointer invalid\n"); return; } if (id < vmap[3]) { vmap += vmap[1] + (vmap[2] * id); perflvl->volt_min = ROM32(vmap[0]); perflvl->volt_max = ROM32(vmap[4]); } }
u8 * nouveau_perf_timing(struct drm_device *dev, u32 freq, u8 *ver, u8 *len) { struct drm_nouveau_private *dev_priv = dev->dev_private; struct nvbios *bios = &dev_priv->vbios; struct bit_entry P; u8 *perf, *timing = NULL; u8 i = 0, hdr, cnt; if (bios->type == NVBIOS_BMP) { while ((perf = nouveau_perf_entry(dev, i++, ver, &hdr, &cnt, len)) && *ver == 0x15) { if (freq <= ROM32(perf[5]) * 20) { *ver = 0x00; *len = 14; return perf + 41; } } return NULL; } if (!bit_table(dev, 'P', &P)) { if (P.version == 1) timing = ROMPTR(dev, P.data[4]); else if (P.version == 2) timing = ROMPTR(dev, P.data[8]); } if (timing && timing[0] == 0x10) { u8 *ramcfg = nouveau_perf_ramcfg(dev, freq, ver, len); if (ramcfg && ramcfg[1] < timing[2]) { *ver = timing[0]; *len = timing[3]; return timing + timing[1] + (ramcfg[1] * timing[3]); } } return NULL; }
void nouveau_temp_init(struct drm_device *dev) { struct drm_nouveau_private *dev_priv = dev->dev_private; struct nvbios *bios = &dev_priv->vbios; struct bit_entry P; u8 *temp = NULL; if (bios->type == NVBIOS_BIT) { if (bit_table(dev, 'P', &P)) return; if (P.version == 1) temp = ROMPTR(bios, P.data[12]); else if (P.version == 2) temp = ROMPTR(bios, P.data[16]); else NV_WARN(dev, "unknown temp for BIT P %d\n", P.version); nouveau_temp_vbios_parse(dev, temp); } nouveau_temp_probe_i2c(dev); }
void nouveau_perf_init(struct drm_device *dev) { struct drm_nouveau_private *dev_priv = dev->dev_private; struct nouveau_pm_engine *pm = &dev_priv->engine.pm; struct nvbios *bios = &dev_priv->vbios; struct bit_entry P; struct nouveau_pm_memtimings *memtimings = &pm->memtimings; struct nouveau_pm_tbl_header mt_hdr; u8 version, headerlen, recordlen, entries; u8 *perf, *entry; int vid, i; if (bios->type == NVBIOS_BIT) { if (bit_table(dev, 'P', &P)) return; if (P.version != 1 && P.version != 2) { NV_WARN(dev, "unknown perf for BIT P %d\n", P.version); return; } perf = ROMPTR(bios, P.data[0]); version = perf[0]; headerlen = perf[1]; if (version < 0x40) { recordlen = perf[3] + (perf[4] * perf[5]); entries = perf[2]; } else { recordlen = perf[2] + (perf[3] * perf[4]); entries = perf[5]; } } else { if (bios->data[bios->offset + 6] < 0x25) { legacy_perf_init(dev); return; } perf = ROMPTR(bios, bios->data[bios->offset + 0x94]); if (!perf) { NV_DEBUG(dev, "perf table pointer invalid\n"); return; } version = perf[1]; headerlen = perf[0]; recordlen = perf[3]; entries = perf[2]; } if (entries > NOUVEAU_PM_MAX_LEVEL) { NV_DEBUG(dev, "perf table has too many entries - buggy vbios?\n"); entries = NOUVEAU_PM_MAX_LEVEL; } entry = perf + headerlen; /* For version 0x15, initialize memtiming table */ if(version == 0x15) { memtimings->timing = kcalloc(entries, sizeof(*memtimings->timing), GFP_KERNEL); if(!memtimings) { NV_WARN(dev,"Could not allocate memtiming table\n"); return; } mt_hdr.entry_cnt = entries; mt_hdr.entry_len = 14; mt_hdr.version = version; mt_hdr.header_len = 4; } for (i = 0; i < entries; i++) { struct nouveau_pm_level *perflvl = &pm->perflvl[pm->nr_perflvl]; perflvl->timing = NULL; if (entry[0] == 0xff) { entry += recordlen; continue; } switch (version) { case 0x12: case 0x13: case 0x15: perflvl->fanspeed = entry[55]; if (recordlen > 56) perflvl->volt_min = entry[56]; perflvl->core = ROM32(entry[1]) * 10; perflvl->memory = ROM32(entry[5]) * 20; break; case 0x21: case 0x23: case 0x24: perflvl->fanspeed = entry[4]; perflvl->volt_min = entry[5]; perflvl->shader = ROM16(entry[6]) * 1000; perflvl->core = perflvl->shader; perflvl->core += (signed char)entry[8] * 1000; if (dev_priv->chipset == 0x49 || dev_priv->chipset == 0x4b) perflvl->memory = ROM16(entry[11]) * 1000; else perflvl->memory = ROM16(entry[11]) * 2000; break; case 0x25: perflvl->fanspeed = entry[4]; perflvl->volt_min = entry[5]; perflvl->core = ROM16(entry[6]) * 1000; perflvl->shader = ROM16(entry[10]) * 1000; perflvl->memory = ROM16(entry[12]) * 1000; break; case 0x30: perflvl->memscript = ROM16(entry[2]); case 0x35: perflvl->fanspeed = entry[6]; perflvl->volt_min = entry[7]; perflvl->core = ROM16(entry[8]) * 1000; perflvl->shader = ROM16(entry[10]) * 1000; perflvl->memory = ROM16(entry[12]) * 1000; /*XXX: confirm on 0x35 */ perflvl->unk05 = ROM16(entry[16]) * 1000; break; case 0x40: #define subent(n) (ROM16(entry[perf[2] + ((n) * perf[3])]) & 0xfff) * 1000 perflvl->fanspeed = 0; /*XXX*/ perflvl->volt_min = entry[2]; if (dev_priv->card_type == NV_50) { perflvl->core = subent(0); perflvl->shader = subent(1); perflvl->memory = subent(2); perflvl->vdec = subent(3); perflvl->unka0 = subent(4); } else { perflvl->hub06 = subent(0); perflvl->hub01 = subent(1); perflvl->copy = subent(2); perflvl->shader = subent(3); perflvl->rop = subent(4); perflvl->memory = subent(5); perflvl->vdec = subent(6); perflvl->daemon = subent(10); perflvl->hub07 = subent(11); perflvl->core = perflvl->shader / 2; } break; } /* make sure vid is valid */ nouveau_perf_voltage(dev, &P, perflvl); if (pm->voltage.supported && perflvl->volt_min) { vid = nouveau_volt_vid_lookup(dev, perflvl->volt_min); if (vid < 0) { NV_DEBUG(dev, "drop perflvl %d, bad vid\n", i); entry += recordlen; continue; } } /* get the corresponding memory timings */ if (version == 0x15) { memtimings->timing[i].id = i; nv30_mem_timing_entry(dev,&mt_hdr,(struct nouveau_pm_tbl_entry*) &entry[41],0,&memtimings->timing[i]); perflvl->timing = &memtimings->timing[i]; } else if (version > 0x15) { /* last 3 args are for < 0x40, ignored for >= 0x40 */ perflvl->timing = nouveau_perf_timing(dev, &P, perflvl->memory / 1000, entry + perf[3], perf[5], perf[4]); } snprintf(perflvl->name, sizeof(perflvl->name), "performance_level_%d", i); perflvl->id = i; pm->nr_perflvl++; entry += recordlen; } }
void nouveau_perf_init(struct drm_device *dev) { struct drm_nouveau_private *dev_priv = dev->dev_private; struct nouveau_pm_engine *pm = &dev_priv->engine.pm; struct nvbios *bios = &dev_priv->vbios; struct bit_entry P; u8 version, headerlen, recordlen, entries; u8 *perf, *entry; int vid, i; if (bios->type == NVBIOS_BIT) { if (bit_table(dev, 'P', &P)) return; if (P.version != 1 && P.version != 2) { NV_WARN(dev, "unknown perf for BIT P %d\n", P.version); return; } perf = ROMPTR(bios, P.data[0]); version = perf[0]; headerlen = perf[1]; if (version < 0x40) { recordlen = perf[3] + (perf[4] * perf[5]); entries = perf[2]; } else { recordlen = perf[2] + (perf[3] * perf[4]); entries = perf[5]; } } else { if (bios->data[bios->offset + 6] < 0x25) { legacy_perf_init(dev); return; } perf = ROMPTR(bios, bios->data[bios->offset + 0x94]); if (!perf) { NV_DEBUG(dev, "perf table pointer invalid\n"); return; } version = perf[1]; headerlen = perf[0]; recordlen = perf[3]; entries = perf[2]; } entry = perf + headerlen; for (i = 0; i < entries; i++) { struct nouveau_pm_level *perflvl = &pm->perflvl[pm->nr_perflvl]; if (entry[0] == 0xff) { entry += recordlen; continue; } switch (version) { case 0x12: case 0x13: case 0x15: perflvl->fanspeed = entry[55]; perflvl->voltage = entry[56]; perflvl->core = ROM32(entry[1]) * 10; perflvl->memory = ROM32(entry[5]) * 20; break; case 0x21: case 0x23: case 0x24: perflvl->fanspeed = entry[4]; perflvl->voltage = entry[5]; perflvl->core = ROM16(entry[6]) * 1000; if (dev_priv->chipset == 0x49 || dev_priv->chipset == 0x4b) perflvl->memory = ROM16(entry[11]) * 1000; else perflvl->memory = ROM16(entry[11]) * 2000; break; case 0x25: perflvl->fanspeed = entry[4]; perflvl->voltage = entry[5]; perflvl->core = ROM16(entry[6]) * 1000; perflvl->shader = ROM16(entry[10]) * 1000; perflvl->memory = ROM16(entry[12]) * 1000; break; case 0x30: perflvl->memscript = ROM16(entry[2]); case 0x35: perflvl->fanspeed = entry[6]; perflvl->voltage = entry[7]; perflvl->core = ROM16(entry[8]) * 1000; perflvl->shader = ROM16(entry[10]) * 1000; perflvl->memory = ROM16(entry[12]) * 1000; /*XXX: confirm on 0x35 */ perflvl->unk05 = ROM16(entry[16]) * 1000; break; case 0x40: #define subent(n) entry[perf[2] + ((n) * perf[3])] perflvl->fanspeed = 0; /*XXX*/ perflvl->voltage = entry[2]; perflvl->core = (ROM16(subent(0)) & 0xfff) * 1000; perflvl->shader = (ROM16(subent(1)) & 0xfff) * 1000; perflvl->memory = (ROM16(subent(2)) & 0xfff) * 1000; break; } /* make sure vid is valid */ if (pm->voltage.supported && perflvl->voltage) { vid = nouveau_volt_vid_lookup(dev, perflvl->voltage); if (vid < 0) { NV_DEBUG(dev, "drop perflvl %d, bad vid\n", i); entry += recordlen; continue; } } snprintf(perflvl->name, sizeof(perflvl->name), "performance_level_%d", i); perflvl->id = i; pm->nr_perflvl++; entry += recordlen; } }
void nouveau_volt_init(struct drm_device *dev) { struct drm_nouveau_private *dev_priv = dev->dev_private; struct nouveau_pm_engine *pm = &dev_priv->engine.pm; struct nouveau_pm_voltage *voltage = &pm->voltage; struct nvbios *bios = &dev_priv->vbios; struct bit_entry P; u8 *volt = NULL, *entry; int i, headerlen, recordlen, entries, vidmask, vidshift; if (bios->type == NVBIOS_BIT) { if (bit_table(dev, 'P', &P)) return; if (P.version == 1) volt = ROMPTR(dev, P.data[16]); else if (P.version == 2) volt = ROMPTR(dev, P.data[12]); else { NV_WARN(dev, "unknown volt for BIT P %d\n", P.version); } } else { if (bios->data[bios->offset + 6] < 0x27) { NV_DEBUG(dev, "BMP version too old for voltage\n"); return; } volt = ROMPTR(dev, bios->data[bios->offset + 0x98]); } if (!volt) { NV_DEBUG(dev, "voltage table pointer invalid\n"); return; } switch (volt[0]) { case 0x10: case 0x11: case 0x12: headerlen = 5; recordlen = volt[1]; entries = volt[2]; vidshift = 0; vidmask = volt[4]; break; case 0x20: headerlen = volt[1]; recordlen = volt[3]; entries = volt[2]; vidshift = 0; /* could be vidshift like 0x30? */ vidmask = volt[5]; break; case 0x30: headerlen = volt[1]; recordlen = volt[2]; entries = volt[3]; vidmask = volt[4]; /* no longer certain what volt[5] is, if it's related to * the vid shift then it's definitely not a function of * how many bits are set. * * after looking at a number of nva3+ vbios images, they * all seem likely to have a static shift of 2.. lets * go with that for now until proven otherwise. */ vidshift = 2; break; case 0x40: headerlen = volt[1]; recordlen = volt[2]; entries = volt[3]; /* not a clue what the entries are for.. */ vidmask = volt[11]; /* guess.. */ vidshift = 0; break; default: NV_WARN(dev, "voltage table 0x%02x unknown\n", volt[0]); return; } /* validate vid mask */ voltage->vid_mask = vidmask; if (!voltage->vid_mask) return; i = 0; while (vidmask) { if (i > nr_vidtag) { NV_DEBUG(dev, "vid bit %d unknown\n", i); return; } if (!nouveau_gpio_func_valid(dev, vidtag[i])) { NV_DEBUG(dev, "vid bit %d has no gpio tag\n", i); return; } vidmask >>= 1; i++; } /* parse vbios entries into common format */ voltage->version = volt[0]; if (voltage->version < 0x40) { voltage->nr_level = entries; voltage->level = kcalloc(entries, sizeof(*voltage->level), GFP_KERNEL); if (!voltage->level) return; entry = volt + headerlen; for (i = 0; i < entries; i++, entry += recordlen) { voltage->level[i].voltage = entry[0] * 10000; voltage->level[i].vid = entry[1] >> vidshift; } } else {