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 "common.h" 35 36int 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", strerror(err)); 46 exit(1); 47 } 48 49 /* Grab the graphics card */ 50 dev = pci_device_find_by_slot(0, 0, 2, 0); 51 if (dev == NULL) 52 errx(1, "Couldn't find graphics card"); 53 54 err = pci_device_probe(dev); 55 if (err != 0) { 56 fprintf(stderr, "Couldn't probe graphics card: %s\n", strerror(err)); 57 exit(1); 58 } 59 60 if (dev->vendor_id != 0x8086) 61 errx(1, "Graphics card is non-intel"); 62 63 bridge = pci_device_find_by_slot(0, 0, 0, 0); 64 if (dev == NULL) 65 errx(1, "Couldn't bridge"); 66 67 err = pci_device_cfg_read_u8(bridge, &stepping, 8); 68 if (err != 0) { 69 fprintf(stderr, "Couldn't read revision ID: %s\n", strerror(err)); 70 exit(1); 71 } 72 73 switch (dev->device_id) { 74 case PCI_CHIP_I915_G: 75 if (stepping < 0x04) 76 step_desc = "<B1"; 77 else if (stepping == 0x04) 78 step_desc = "B1"; 79 else if (stepping == 0x0e) 80 step_desc = "C2"; 81 else if (stepping > 0x0e) 82 step_desc = ">C2"; 83 else 84 step_desc = ">B1 <C2"; 85 break; 86 case PCI_CHIP_I915_GM: 87 if (stepping < 0x03) 88 step_desc = "<B1"; 89 else if (stepping == 0x03) 90 step_desc = "B1/C0"; 91 else if (stepping == 0x04) 92 step_desc = "C1/C2"; 93 else 94 step_desc = ">C2"; 95 break; 96 case PCI_CHIP_I945_GM: 97 if (stepping < 0x03) 98 step_desc = "<A3"; 99 else if (stepping == 0x03) 100 step_desc = "A3"; 101 else 102 step_desc = ">A3"; 103 break; 104 case PCI_CHIP_I965_G: 105 case PCI_CHIP_I965_Q: 106 if (stepping < 0x02) 107 step_desc = "<C1"; 108 else if (stepping == 0x02) 109 step_desc = "C1/C2"; 110 else 111 step_desc = ">C2"; 112 break; 113 case PCI_CHIP_I965_GM: 114 if (stepping < 0x03) 115 step_desc = "<C0"; 116 else if (stepping == 0x03) 117 step_desc = "C0"; 118 else 119 step_desc = ">C0"; 120 break; 121 case PCI_CHIP_G35_G: 122 if (stepping < 0x03) 123 step_desc = "<E0"; 124 else if (stepping == 0x03) 125 step_desc = "E0"; 126 else 127 step_desc = ">E0"; 128 break; 129 } 130 131 printf("Vendor: 0x%04x, Device: 0x%04x, Revision: 0x%02x (%s)\n", 132 dev->vendor_id, 133 dev->device_id, 134 stepping, 135 step_desc); 136 return 0; 137} 138