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" |
| 35 | |
| 36 | int main(int argc, char **argv) |
| 37 | { |
| 38 | struct pci_device *dev, *bridge; |
| 39 | int err; |
| 40 | uint8_t stepping; |
| 41 | char *step_desc = "??"; |
| 42 | |
| 43 | err = pci_system_init(); |
| 44 | if (err != 0) { |
| 45 | fprintf(stderr, "Couldn't initialize PCI system: %s\n", |
| 46 | strerror(err)); |
| 47 | exit(1); |
| 48 | } |
| 49 | |
| 50 | /* Grab the graphics card */ |
| 51 | dev = pci_device_find_by_slot(0, 0, 2, 0); |
| 52 | if (dev == NULL) |
| 53 | errx(1, "Couldn't find graphics card"); |
| 54 | |
| 55 | err = pci_device_probe(dev); |
| 56 | if (err != 0) { |
| 57 | fprintf(stderr, "Couldn't probe graphics card: %s\n", |
| 58 | strerror(err)); |
| 59 | exit(1); |
| 60 | } |
| 61 | |
| 62 | if (dev->vendor_id != 0x8086) |
| 63 | errx(1, "Graphics card is non-intel"); |
| 64 | |
| 65 | bridge = pci_device_find_by_slot(0, 0, 0, 0); |
| 66 | if (dev == NULL) |
| 67 | errx(1, "Couldn't bridge"); |
| 68 | |
| 69 | err = pci_device_cfg_read_u8(bridge, &stepping, 8); |
| 70 | if (err != 0) { |
| 71 | fprintf(stderr, "Couldn't read revision ID: %s\n", |
| 72 | strerror(err)); |
| 73 | exit(1); |
| 74 | } |
| 75 | |
| 76 | switch (dev->device_id) { |
| 77 | case PCI_CHIP_I915_G: |
| 78 | if (stepping < 0x04) |
| 79 | step_desc = "<B1"; |
| 80 | else if (stepping == 0x04) |
| 81 | step_desc = "B1"; |
| 82 | else if (stepping == 0x0e) |
| 83 | step_desc = "C2"; |
| 84 | else if (stepping > 0x0e) |
| 85 | step_desc = ">C2"; |
| 86 | else |
| 87 | step_desc = ">B1 <C2"; |
| 88 | break; |
| 89 | case PCI_CHIP_I915_GM: |
| 90 | if (stepping < 0x03) |
| 91 | step_desc = "<B1"; |
| 92 | else if (stepping == 0x03) |
| 93 | step_desc = "B1/C0"; |
| 94 | else if (stepping == 0x04) |
| 95 | step_desc = "C1/C2"; |
| 96 | else |
| 97 | step_desc = ">C2"; |
| 98 | break; |
| 99 | case PCI_CHIP_I945_GM: |
| 100 | if (stepping < 0x03) |
| 101 | step_desc = "<A3"; |
| 102 | else if (stepping == 0x03) |
| 103 | step_desc = "A3"; |
| 104 | else |
| 105 | step_desc = ">A3"; |
| 106 | break; |
| 107 | case PCI_CHIP_I965_G: |
| 108 | case PCI_CHIP_I965_Q: |
| 109 | if (stepping < 0x02) |
| 110 | step_desc = "<C1"; |
| 111 | else if (stepping == 0x02) |
| 112 | step_desc = "C1/C2"; |
| 113 | else |
| 114 | step_desc = ">C2"; |
| 115 | break; |
| 116 | case PCI_CHIP_I965_GM: |
| 117 | if (stepping < 0x03) |
| 118 | step_desc = "<C0"; |
| 119 | else if (stepping == 0x03) |
| 120 | step_desc = "C0"; |
| 121 | else |
| 122 | step_desc = ">C0"; |
| 123 | break; |
| 124 | case PCI_CHIP_I965_G_1: |
| 125 | if (stepping < 0x03) |
| 126 | step_desc = "<E0"; |
| 127 | else if (stepping == 0x03) |
| 128 | step_desc = "E0"; |
| 129 | else |
| 130 | step_desc = ">E0"; |
| 131 | break; |
Eric Anholt | 8727130 | 2009-03-27 11:07:33 -0700 | [diff] [blame^] | 132 | case PCI_CHIP_GM45_GM: |
| 133 | if (stepping < 0x07) |
| 134 | step_desc = "<B3"; |
| 135 | else if (stepping == 0x03) |
| 136 | step_desc = "B3"; |
| 137 | else |
| 138 | step_desc = ">B3"; |
| 139 | break; |
| 140 | case PCI_CHIP_G45_G: |
| 141 | case PCI_CHIP_Q45_G: |
| 142 | case PCI_CHIP_G41_G: |
| 143 | if (stepping < 0x02) |
| 144 | step_desc = "<A2"; |
| 145 | else if (stepping == 0x02) |
| 146 | step_desc = "A2"; |
| 147 | else if (stepping == 0x03) |
| 148 | step_desc = "A3"; |
| 149 | else |
| 150 | step_desc = ">A3"; |
| 151 | break; |
Eric Anholt | 29777a5 | 2009-03-27 10:59:09 -0700 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | printf("Vendor: 0x%04x, Device: 0x%04x, Revision: 0x%02x (%s)\n", |
| 155 | dev->vendor_id, |
| 156 | dev->device_id, |
| 157 | stepping, |
| 158 | step_desc); |
| 159 | return 0; |
| 160 | } |