blob: ea8eecbba2ab5660c8a6756853c06ca29dba0cd0 [file] [log] [blame]
Eric Anholt29777a52009-03-27 10:59:09 -07001/*
2 * Copyright © 2007 Intel Corporation
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 (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
25 *
26 */
27
28#include <stdio.h>
29#include <stdlib.h>
30#include <string.h>
31#include <stdarg.h>
32#include <pciaccess.h>
33#include <err.h>
34#include "intel_chipset.h"
Chris Wilsond75f2632011-02-10 11:20:20 +000035#include "intel_gpu_tools.h"
36
37static void
38print_clock(char *name, int clock) {
39 if (clock == -1)
40 printf("%s clock: unknown", name);
41 else
42 printf("%s clock: %d Mhz", name, clock);
43}
44
45static int
46print_clock_info(struct pci_device *pci_dev)
47{
48 uint32_t devid = pci_dev->device_id;
49 uint16_t gcfgc;
50
51 if (IS_GM45(devid)) {
52 int core_clock = -1;
53
54 pci_device_cfg_read_u16(pci_dev, &gcfgc, I915_GCFGC);
55
56 switch (gcfgc & 0xf) {
57 case 8:
58 core_clock = 266;
59 break;
60 case 9:
61 core_clock = 320;
62 break;
63 case 11:
64 core_clock = 400;
65 break;
66 case 13:
67 core_clock = 533;
68 break;
69 }
70 print_clock("core", core_clock);
71 } else if (IS_965(devid) && IS_MOBILE(devid)) {
72 int render_clock = -1, sampler_clock = -1;
73
74 pci_device_cfg_read_u16(pci_dev, &gcfgc, I915_GCFGC);
75
76 switch (gcfgc & 0xf) {
77 case 2:
78 render_clock = 250; sampler_clock = 267;
79 break;
80 case 3:
81 render_clock = 320; sampler_clock = 333;
82 break;
83 case 4:
84 render_clock = 400; sampler_clock = 444;
85 break;
86 case 5:
87 render_clock = 500; sampler_clock = 533;
88 break;
89 }
90
91 print_clock("render", render_clock);
92 printf(" ");
93 print_clock("sampler", sampler_clock);
94 } else if (IS_945(devid) && IS_MOBILE(devid)) {
95 int render_clock = -1, display_clock = -1;
96
97 pci_device_cfg_read_u16(pci_dev, &gcfgc, I915_GCFGC);
98
99 switch (gcfgc & 0x7) {
100 case 0:
101 render_clock = 166;
102 break;
103 case 1:
104 render_clock = 200;
105 break;
106 case 3:
107 render_clock = 250;
108 break;
109 case 5:
110 render_clock = 400;
111 break;
112 }
113
114 switch (gcfgc & 0x70) {
115 case 0:
116 display_clock = 200;
117 break;
118 case 4:
119 display_clock = 320;
120 break;
121 }
122 if (gcfgc & (1 << 7))
123 display_clock = 133;
124
125 print_clock("render", render_clock);
126 printf(" ");
127 print_clock("display", display_clock);
128 } else if (IS_915(devid) && IS_MOBILE(devid)) {
129 int render_clock = -1, display_clock = -1;
130
131 pci_device_cfg_read_u16(pci_dev, &gcfgc, I915_GCFGC);
132
133 switch (gcfgc & 0x7) {
134 case 0:
135 render_clock = 160;
136 break;
137 case 1:
138 render_clock = 190;
139 break;
140 case 4:
141 render_clock = 333;
142 break;
143 }
144 if (gcfgc & (1 << 13))
145 render_clock = 133;
146
147 switch (gcfgc & 0x70) {
148 case 0:
149 display_clock = 190;
150 break;
151 case 4:
152 display_clock = 333;
153 break;
154 }
155 if (gcfgc & (1 << 7))
156 display_clock = 133;
157
158 print_clock("render", render_clock);
159 printf(" ");
160 print_clock("display", display_clock);
161 }
162
163 printf("\n");
164 return -1;
165}
Eric Anholt29777a52009-03-27 10:59:09 -0700166
167int main(int argc, char **argv)
168{
169 struct pci_device *dev, *bridge;
170 int err;
171 uint8_t stepping;
172 char *step_desc = "??";
173
174 err = pci_system_init();
175 if (err != 0) {
176 fprintf(stderr, "Couldn't initialize PCI system: %s\n",
177 strerror(err));
178 exit(1);
179 }
180
181 /* Grab the graphics card */
182 dev = pci_device_find_by_slot(0, 0, 2, 0);
183 if (dev == NULL)
184 errx(1, "Couldn't find graphics card");
185
186 err = pci_device_probe(dev);
187 if (err != 0) {
188 fprintf(stderr, "Couldn't probe graphics card: %s\n",
189 strerror(err));
190 exit(1);
191 }
192
193 if (dev->vendor_id != 0x8086)
194 errx(1, "Graphics card is non-intel");
195
196 bridge = pci_device_find_by_slot(0, 0, 0, 0);
197 if (dev == NULL)
198 errx(1, "Couldn't bridge");
199
200 err = pci_device_cfg_read_u8(bridge, &stepping, 8);
201 if (err != 0) {
202 fprintf(stderr, "Couldn't read revision ID: %s\n",
203 strerror(err));
204 exit(1);
205 }
206
207 switch (dev->device_id) {
208 case PCI_CHIP_I915_G:
209 if (stepping < 0x04)
210 step_desc = "<B1";
211 else if (stepping == 0x04)
212 step_desc = "B1";
213 else if (stepping == 0x0e)
214 step_desc = "C2";
215 else if (stepping > 0x0e)
216 step_desc = ">C2";
217 else
218 step_desc = ">B1 <C2";
219 break;
220 case PCI_CHIP_I915_GM:
221 if (stepping < 0x03)
222 step_desc = "<B1";
223 else if (stepping == 0x03)
224 step_desc = "B1/C0";
225 else if (stepping == 0x04)
226 step_desc = "C1/C2";
227 else
228 step_desc = ">C2";
229 break;
230 case PCI_CHIP_I945_GM:
231 if (stepping < 0x03)
232 step_desc = "<A3";
233 else if (stepping == 0x03)
234 step_desc = "A3";
235 else
236 step_desc = ">A3";
237 break;
238 case PCI_CHIP_I965_G:
239 case PCI_CHIP_I965_Q:
240 if (stepping < 0x02)
241 step_desc = "<C1";
242 else if (stepping == 0x02)
243 step_desc = "C1/C2";
244 else
245 step_desc = ">C2";
246 break;
247 case PCI_CHIP_I965_GM:
248 if (stepping < 0x03)
249 step_desc = "<C0";
250 else if (stepping == 0x03)
251 step_desc = "C0";
252 else
253 step_desc = ">C0";
254 break;
255 case PCI_CHIP_I965_G_1:
256 if (stepping < 0x03)
257 step_desc = "<E0";
258 else if (stepping == 0x03)
259 step_desc = "E0";
260 else
261 step_desc = ">E0";
262 break;
Eric Anholt87271302009-03-27 11:07:33 -0700263 case PCI_CHIP_GM45_GM:
264 if (stepping < 0x07)
265 step_desc = "<B3";
266 else if (stepping == 0x03)
267 step_desc = "B3";
268 else
269 step_desc = ">B3";
270 break;
271 case PCI_CHIP_G45_G:
272 case PCI_CHIP_Q45_G:
273 case PCI_CHIP_G41_G:
274 if (stepping < 0x02)
275 step_desc = "<A2";
276 else if (stepping == 0x02)
277 step_desc = "A2";
278 else if (stepping == 0x03)
279 step_desc = "A3";
280 else
281 step_desc = ">A3";
282 break;
Eric Anholt29777a52009-03-27 10:59:09 -0700283 }
284
285 printf("Vendor: 0x%04x, Device: 0x%04x, Revision: 0x%02x (%s)\n",
286 dev->vendor_id,
287 dev->device_id,
288 stepping,
289 step_desc);
Chris Wilsond75f2632011-02-10 11:20:20 +0000290
291 print_clock_info(dev);
292
Eric Anholt29777a52009-03-27 10:59:09 -0700293 return 0;
294}