Eric Anholt | 29777a5 | 2009-03-27 10:59:09 -0700 | [diff] [blame] | 1 | /* |
| 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 Wilson | d75f263 | 2011-02-10 11:20:20 +0000 | [diff] [blame] | 35 | #include "intel_gpu_tools.h" |
| 36 | |
| 37 | static void |
Daniel Vetter | bd811d2 | 2012-01-09 23:37:36 +0100 | [diff] [blame^] | 38 | print_clock(const char *name, int clock) { |
Chris Wilson | d75f263 | 2011-02-10 11:20:20 +0000 | [diff] [blame] | 39 | if (clock == -1) |
| 40 | printf("%s clock: unknown", name); |
| 41 | else |
| 42 | printf("%s clock: %d Mhz", name, clock); |
| 43 | } |
| 44 | |
| 45 | static int |
| 46 | print_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 Anholt | 29777a5 | 2009-03-27 10:59:09 -0700 | [diff] [blame] | 166 | |
| 167 | int main(int argc, char **argv) |
| 168 | { |
| 169 | struct pci_device *dev, *bridge; |
Daniel Vetter | bd811d2 | 2012-01-09 23:37:36 +0100 | [diff] [blame^] | 170 | int error; |
Eric Anholt | 29777a5 | 2009-03-27 10:59:09 -0700 | [diff] [blame] | 171 | uint8_t stepping; |
Daniel Vetter | bd811d2 | 2012-01-09 23:37:36 +0100 | [diff] [blame^] | 172 | const char *step_desc = "??"; |
Eric Anholt | 29777a5 | 2009-03-27 10:59:09 -0700 | [diff] [blame] | 173 | |
Daniel Vetter | bd811d2 | 2012-01-09 23:37:36 +0100 | [diff] [blame^] | 174 | error = pci_system_init(); |
| 175 | if (error != 0) { |
Eric Anholt | 29777a5 | 2009-03-27 10:59:09 -0700 | [diff] [blame] | 176 | fprintf(stderr, "Couldn't initialize PCI system: %s\n", |
Daniel Vetter | bd811d2 | 2012-01-09 23:37:36 +0100 | [diff] [blame^] | 177 | strerror(error)); |
Eric Anholt | 29777a5 | 2009-03-27 10:59:09 -0700 | [diff] [blame] | 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 | |
Daniel Vetter | bd811d2 | 2012-01-09 23:37:36 +0100 | [diff] [blame^] | 186 | error = pci_device_probe(dev); |
| 187 | if (error != 0) { |
Eric Anholt | 29777a5 | 2009-03-27 10:59:09 -0700 | [diff] [blame] | 188 | fprintf(stderr, "Couldn't probe graphics card: %s\n", |
Daniel Vetter | bd811d2 | 2012-01-09 23:37:36 +0100 | [diff] [blame^] | 189 | strerror(error)); |
Eric Anholt | 29777a5 | 2009-03-27 10:59:09 -0700 | [diff] [blame] | 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 | |
Daniel Vetter | bd811d2 | 2012-01-09 23:37:36 +0100 | [diff] [blame^] | 200 | error = pci_device_cfg_read_u8(bridge, &stepping, 8); |
| 201 | if (error != 0) { |
Eric Anholt | 29777a5 | 2009-03-27 10:59:09 -0700 | [diff] [blame] | 202 | fprintf(stderr, "Couldn't read revision ID: %s\n", |
Daniel Vetter | bd811d2 | 2012-01-09 23:37:36 +0100 | [diff] [blame^] | 203 | strerror(error)); |
Eric Anholt | 29777a5 | 2009-03-27 10:59:09 -0700 | [diff] [blame] | 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 Anholt | 8727130 | 2009-03-27 11:07:33 -0700 | [diff] [blame] | 263 | 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 Anholt | 29777a5 | 2009-03-27 10:59:09 -0700 | [diff] [blame] | 283 | } |
| 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 Wilson | d75f263 | 2011-02-10 11:20:20 +0000 | [diff] [blame] | 290 | |
| 291 | print_clock_info(dev); |
| 292 | |
Eric Anholt | 29777a5 | 2009-03-27 10:59:09 -0700 | [diff] [blame] | 293 | return 0; |
| 294 | } |