1/* 2 * Copyright © 2008 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 * Jesse Barnes <jesse.barnes@intel.com> 26 * 27 */ 28 29#include <stdio.h> 30#include <stdlib.h> 31#include <string.h> 32#include <stdarg.h> 33#include <sys/stat.h> 34#include <fcntl.h> 35#include <unistd.h> 36#include <errno.h> 37#include <pciaccess.h> 38#include <err.h> 39 40#include "../i810_reg.h" 41#include "../i830_bios.h" 42 43#ifndef DEFFILEMODE 44#define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) /* 0666*/ 45#endif 46 47static uint32_t read32(void *base, int reg) 48{ 49 uint32_t *addr = (uint32_t *)((unsigned char *)(base) + reg); 50 51 return *addr; 52} 53 54#if 0 55static void write32(void *base, int reg, uint32_t val) 56{ 57 uint32_t *addr = (uint32_t *)((unsigned char *)(base) + reg); 58 *addr = val; 59} 60#endif 61 62static void usage(void) 63{ 64 fprintf(stderr, "usage: swf_dumper\n"); 65 exit(1); 66} 67 68int main(int argc, char **argv) 69{ 70 struct pci_device *dev; 71 int err; 72 void *addr; 73 74 if (argc != 1) 75 usage(); 76 77 err = pci_system_init(); 78 if (err != 0) { 79 fprintf(stderr, "Couldn't initialize PCI system: %s\n", strerror(err)); 80 exit(1); 81 } 82 83 /* Grab the graphics card */ 84 dev = pci_device_find_by_slot(0, 0, 2, 0); 85 if (dev == NULL) 86 errx(1, "Couldn't find graphics card"); 87 88 err = pci_device_probe(dev); 89 if (err != 0) { 90 fprintf(stderr, "Couldn't probe graphics card: %s\n", strerror(err)); 91 exit(1); 92 } 93 94 if (dev->vendor_id != 0x8086) 95 errx(1, "Graphics card is non-intel"); 96 97 err = pci_device_map_range(dev, dev->regions[0].base_addr, 98 dev->regions[0].size, 99 PCI_DEV_MAP_FLAG_WRITABLE, &addr); 100 if (err) { 101 fprintf(stderr, "Couldn't map MMIO space: %s\n", strerror(err)); 102 exit(1); 103 } 104 105 printf("SWF14: 0x%08x\n", read32(addr, SWF14)); 106 107 pci_system_cleanup(); 108 109 return 0; 110} 111