diff options
author | Ben Skeggs <bskeggs@redhat.com> | 2010-09-16 01:39:49 -0400 |
---|---|---|
committer | Ben Skeggs <bskeggs@redhat.com> | 2010-09-24 02:27:00 -0400 |
commit | 330c5988ee78045e6a731c3693251aaa5b0d14e3 (patch) | |
tree | f5313d35a321f665f2fa0e805a0317e1f97d3c28 /drivers/gpu/drm/nouveau/nouveau_perf.c | |
parent | 4709bff02adcb0d05d2d1a397e60581baa562de9 (diff) |
drm/nouveau: import initial work on vbios performance table parsing
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
Diffstat (limited to 'drivers/gpu/drm/nouveau/nouveau_perf.c')
-rw-r--r-- | drivers/gpu/drm/nouveau/nouveau_perf.c | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/drivers/gpu/drm/nouveau/nouveau_perf.c b/drivers/gpu/drm/nouveau/nouveau_perf.c new file mode 100644 index 00000000000..a882a366487 --- /dev/null +++ b/drivers/gpu/drm/nouveau/nouveau_perf.c | |||
@@ -0,0 +1,159 @@ | |||
1 | /* | ||
2 | * Copyright 2010 Red Hat Inc. | ||
3 | * | ||
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: | ||
10 | * | ||
11 | * The above copyright notice and this permission notice shall be included in | ||
12 | * all copies or substantial portions of the Software. | ||
13 | * | ||
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. | ||
21 | * | ||
22 | * Authors: Ben Skeggs | ||
23 | */ | ||
24 | |||
25 | #include "drmP.h" | ||
26 | |||
27 | #include "nouveau_drv.h" | ||
28 | #include "nouveau_pm.h" | ||
29 | |||
30 | void | ||
31 | nouveau_perf_init(struct drm_device *dev) | ||
32 | { | ||
33 | struct drm_nouveau_private *dev_priv = dev->dev_private; | ||
34 | struct nouveau_pm_engine *pm = &dev_priv->engine.pm; | ||
35 | struct nvbios *bios = &dev_priv->vbios; | ||
36 | struct bit_entry P; | ||
37 | u8 version, headerlen, recordlen, entries; | ||
38 | u8 *perf, *entry; | ||
39 | int vid, i; | ||
40 | |||
41 | if (bios->type == NVBIOS_BIT) { | ||
42 | if (bit_table(dev, 'P', &P)) | ||
43 | return; | ||
44 | |||
45 | if (P.version != 1 && P.version != 2) { | ||
46 | NV_WARN(dev, "unknown perf for BIT P %d\n", P.version); | ||
47 | return; | ||
48 | } | ||
49 | |||
50 | perf = ROMPTR(bios, P.data[0]); | ||
51 | version = perf[0]; | ||
52 | headerlen = perf[1]; | ||
53 | if (version < 0x40) { | ||
54 | recordlen = perf[3] + (perf[4] * perf[5]); | ||
55 | entries = perf[2]; | ||
56 | } else { | ||
57 | recordlen = perf[2] + (perf[3] * perf[4]); | ||
58 | entries = perf[5]; | ||
59 | } | ||
60 | } else { | ||
61 | if (bios->data[bios->offset + 6] < 0x27) { | ||
62 | NV_DEBUG(dev, "BMP version too old for perf\n"); | ||
63 | return; | ||
64 | } | ||
65 | |||
66 | perf = ROMPTR(bios, bios->data[bios->offset + 0x94]); | ||
67 | if (!perf) { | ||
68 | NV_DEBUG(dev, "perf table pointer invalid\n"); | ||
69 | return; | ||
70 | } | ||
71 | |||
72 | version = perf[1]; | ||
73 | headerlen = perf[0]; | ||
74 | recordlen = perf[3]; | ||
75 | entries = perf[2]; | ||
76 | } | ||
77 | |||
78 | entry = perf + headerlen; | ||
79 | for (i = 0; i < entries; i++) { | ||
80 | struct nouveau_pm_level *perflvl = &pm->perflvl[pm->nr_perflvl]; | ||
81 | |||
82 | if (entry[0] == 0xff) { | ||
83 | entry += recordlen; | ||
84 | continue; | ||
85 | } | ||
86 | |||
87 | switch (version) { | ||
88 | case 0x12: | ||
89 | case 0x13: | ||
90 | case 0x15: | ||
91 | perflvl->fanspeed = entry[55]; | ||
92 | perflvl->voltage = entry[56]; | ||
93 | perflvl->core = ROM32(entry[1]) / 100; | ||
94 | perflvl->memory = ROM32(entry[5]) / 100; | ||
95 | break; | ||
96 | case 0x21: | ||
97 | case 0x23: | ||
98 | case 0x24: | ||
99 | perflvl->fanspeed = entry[4]; | ||
100 | perflvl->voltage = entry[5]; | ||
101 | perflvl->core = ROM16(entry[6]); | ||
102 | perflvl->memory = ROM16(entry[11]); | ||
103 | break; | ||
104 | case 0x25: | ||
105 | perflvl->fanspeed = entry[4]; | ||
106 | perflvl->voltage = entry[5]; | ||
107 | perflvl->core = ROM16(entry[6]); | ||
108 | perflvl->shader = ROM16(entry[10]); | ||
109 | perflvl->memory = ROM16(entry[12]); | ||
110 | break; | ||
111 | case 0x30: | ||
112 | case 0x35: | ||
113 | perflvl->fanspeed = entry[6]; | ||
114 | perflvl->voltage = entry[7]; | ||
115 | perflvl->core = ROM16(entry[8]); | ||
116 | perflvl->shader = ROM16(entry[10]); | ||
117 | perflvl->memory = ROM16(entry[12]); | ||
118 | /*XXX: confirm on 0x35 */ | ||
119 | perflvl->unk05 = ROM16(entry[16]); | ||
120 | break; | ||
121 | case 0x40: | ||
122 | #define subent(n) entry[perf[2] + ((n) * perf[3])] | ||
123 | perflvl->fanspeed = 0; /*XXX*/ | ||
124 | perflvl->voltage = 0; /*XXX: entry[2] */; | ||
125 | perflvl->core = ROM16(subent(0)) & 0xfff; | ||
126 | perflvl->shader = ROM16(subent(1)) & 0xfff; | ||
127 | perflvl->memory = ROM16(subent(2)) & 0xfff; | ||
128 | break; | ||
129 | } | ||
130 | |||
131 | /* convert MHz -> KHz, it's more convenient */ | ||
132 | perflvl->core *= 1000; | ||
133 | perflvl->memory *= 1000; | ||
134 | perflvl->shader *= 1000; | ||
135 | perflvl->unk05 *= 1000; | ||
136 | |||
137 | /* make sure vid is valid */ | ||
138 | if (pm->voltage.supported && perflvl->voltage) { | ||
139 | vid = nouveau_volt_vid_lookup(dev, perflvl->voltage); | ||
140 | if (vid < 0) { | ||
141 | NV_DEBUG(dev, "drop perflvl %d, bad vid\n", i); | ||
142 | entry += recordlen; | ||
143 | continue; | ||
144 | } | ||
145 | } | ||
146 | |||
147 | snprintf(perflvl->name, sizeof(perflvl->name), | ||
148 | "performance_level_%d", i); | ||
149 | perflvl->id = i; | ||
150 | pm->nr_perflvl++; | ||
151 | |||
152 | entry += recordlen; | ||
153 | } | ||
154 | } | ||
155 | |||
156 | void | ||
157 | nouveau_perf_fini(struct drm_device *dev) | ||
158 | { | ||
159 | } | ||