static size_t drm_intel_probe_agp_aperture_size(int fd) { struct pci_device *pci_dev; size_t size = 0; int ret; ret = pci_system_init(); if (ret) goto err; /* XXX handle multiple adaptors? */ pci_dev = pci_device_find_by_slot(0, 0, 2, 0); if (pci_dev == NULL) goto err; ret = pci_device_probe(pci_dev); if (ret) goto err; size = pci_dev->regions[2].size; err: pci_system_cleanup (); return size; }
struct pci_device * intel_get_pci_device(void) { struct pci_device *pci_dev; int err; err = pci_system_init(); if (err != 0) { fprintf(stderr, "Couldn't initialize PCI system: %s\n", strerror(err)); exit(1); } /* Grab the graphics card */ pci_dev = pci_device_find_by_slot(0, 0, 2, 0); if (pci_dev == NULL) errx(1, "Couldn't find graphics card"); err = pci_device_probe(pci_dev); if (err != 0) { fprintf(stderr, "Couldn't probe graphics card: %s\n", strerror(err)); exit(1); } if (pci_dev->vendor_id != 0x8086) errx(1, "Graphics card is non-intel"); return pci_dev; }
static struct pci_device* ati_device_get_from_busid(int bus, int dev, int func) { return pci_device_find_by_slot(PCI_DOM_FROM_BUS(bus), PCI_BUS_NO_DOMAIN(bus), dev, func); }
void intel_check_pch(void) { struct pci_device *pch_dev; pch_dev = pci_device_find_by_slot(0, 0, 31, 0); if (pch_dev == NULL) return; if (pch_dev->vendor_id == 0x8086 && (((pch_dev->device_id & 0xff00) == 0x1c00) || (pch_dev->device_id & 0xff00) == 0x1e00)) pch = PCH_CPT; }
int pci_device_vgaarb_init(void) { struct pci_device *dev = pci_sys->vga_target; struct pci_device_iterator *iter; struct pci_id_match vga_match = { PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, (PCI_CLASS_DISPLAY << 16) | (PCI_SUBCLASS_DISPLAY_VGA << 8), 0x00ffff00 }; struct pci_vga pv; int err; #ifdef CPU_ALLOWAPERTURE int mib[2]; int allowaperture; size_t len; mib[0] = CTL_MACHDEP; mib[1] = CPU_ALLOWAPERTURE; len = sizeof(allowaperture); if (sysctl(mib, 2, &allowaperture, &len, NULL, 0) == 0 && allowaperture == 0) { /* No direct hardware access allowed. */ pci_sys->vga_count = 0; return 0; } #endif pv.pv_sel.pc_bus = 0; pv.pv_sel.pc_dev = 0; pv.pv_sel.pc_func = 0; err = ioctl(pcifd[0], PCIOCGETVGA, &pv); if (err) return err; pci_sys->vga_target = pci_device_find_by_slot(0, pv.pv_sel.pc_bus, pv.pv_sel.pc_dev, pv.pv_sel.pc_func); /* Count the number of VGA devices in domain 0. */ iter = pci_id_match_iterator_create(&vga_match); if (iter == NULL) return -1; pci_sys->vga_count = 0; while ((dev = pci_device_next(iter)) != NULL) { if (dev->domain == 0) { pci_sys->vga_count++; pv.pv_sel.pc_bus = dev->bus; pv.pv_sel.pc_dev = dev->dev; pv.pv_sel.pc_func = dev->func; if (ioctl(pcifd[0], PCIOCGETVGA, &pv)) continue; if (pv.pv_decode) dev->vgaarb_rsrc = VGA_ARB_RSRC_LEGACY_IO | VGA_ARB_RSRC_LEGACY_MEM; } } pci_iterator_destroy(iter); return 0; }
int main(int argc, char **argv) { struct pci_device *dev; void *bios; int err, fd; if (argc != 2) usage(); err = pci_system_init(); if (err != 0) { fprintf(stderr, "Couldn't initialize PCI system: %s\n", strerror(err)); exit(1); } /* Grab the graphics card */ dev = pci_device_find_by_slot(0, 0, 2, 0); if (dev == NULL) errx(1, "Couldn't find graphics card"); err = pci_device_probe(dev); if (err != 0) { fprintf(stderr, "Couldn't probe graphics card: %s\n", strerror(err)); exit(1); } if (dev->vendor_id != 0x8086) errx(1, "Graphics card is non-intel"); /* Some versions of libpciaccess correct this automatically, but some * don't. */ if (dev->rom_size == 0) dev->rom_size = 64 * 1024; bios = malloc(dev->rom_size); if (bios == NULL) errx(1, "Couldn't allocate memory for BIOS data\n"); err = pci_device_read_rom(dev, bios); if (err != 0) { fprintf(stderr, "Couldn't read graphics card ROM: %s\n", strerror(err)); exit(1); } fd = open(argv[1], O_RDWR | O_CREAT | O_TRUNC, DEFFILEMODE); if (fd < 0) { fprintf(stderr, "Couldn't open output: %s\n", strerror(errno)); exit(1); } if (write(fd, bios, dev->rom_size) < dev->rom_size) { fprintf(stderr, "Couldn't write BIOS data: %s\n", strerror(errno)); exit(1); } close(fd); pci_system_cleanup(); return 0; }
int main(int argc, char **argv) { struct pci_device *dev; I830Rec i830; I830Ptr pI830 = &i830; ScrnInfoRec scrn; int err, mmio_bar; void *mmio; int i; err = pci_system_init(); if (err != 0) { fprintf(stderr, "Couldn't initialize PCI system: %s\n", strerror(err)); exit(1); } /* Grab the graphics card */ dev = pci_device_find_by_slot(0, 0, 2, 0); if (dev == NULL) errx(1, "Couldn't find graphics card"); err = pci_device_probe(dev); if (err != 0) { fprintf(stderr, "Couldn't probe graphics card: %s\n", strerror(err)); exit(1); } if (dev->vendor_id != 0x8086) errx(1, "Graphics card is non-intel"); i830.PciInfo = dev; mmio_bar = IS_I9XX((&i830)) ? 0 : 1; err = pci_device_map_range(dev, dev->regions[mmio_bar].base_addr, dev->regions[mmio_bar].size, PCI_DEV_MAP_FLAG_WRITABLE, &mmio); if (err != 0) { fprintf(stderr, "Couldn't map MMIO region: %s\n", strerror(err)); exit(1); } i830.mmio = mmio; scrn.scrnIndex = 0; scrn.pI830 = &i830; OUTREG(SDVOB, (0x0 << 10)); OUTREG(SDVOC, (0x0 << 10)); OUTREG(PORT_HOTPLUG_EN, (1 << 29) | (1 << 28) | (1 << 27) | SDVOB_HOTPLUG_INT_EN | SDVOC_HOTPLUG_INT_EN | (1 << 24) | CRT_HOTPLUG_INT_EN | TV_HOTPLUG_INT_EN | CRT_HOTPLUG_INT_EN); for (i = 0;; i++) { OUTREG(PORT_HOTPLUG_STAT, (1 << 20) | (1 << 19) | (1 << 18) | (1 << 17) | CRT_HOTPLUG_INT_STATUS | TV_HOTPLUG_INT_STATUS | SDVOC_HOTPLUG_INT_STATUS | SDVOB_HOTPLUG_INT_STATUS); INREG(PORT_HOTPLUG_STAT); usleep(500 * 1000); printf("%5d: 0x%08x\n", i, INREG(PORT_HOTPLUG_STAT)); sleep(1); } return 0; }
int main(int argc, char **argv) { struct pci_device *dev, *bridge; int error; uint8_t stepping; const char *step_desc = "??"; error = pci_system_init(); if (error != 0) { fprintf(stderr, "Couldn't initialize PCI system: %s\n", strerror(error)); exit(1); } /* Grab the graphics card */ dev = pci_device_find_by_slot(0, 0, 2, 0); if (dev == NULL) errx(1, "Couldn't find graphics card"); error = pci_device_probe(dev); if (error != 0) { fprintf(stderr, "Couldn't probe graphics card: %s\n", strerror(error)); exit(1); } if (dev->vendor_id != 0x8086) errx(1, "Graphics card is non-intel"); bridge = pci_device_find_by_slot(0, 0, 0, 0); if (dev == NULL) errx(1, "Couldn't bridge"); error = pci_device_cfg_read_u8(bridge, &stepping, 8); if (error != 0) { fprintf(stderr, "Couldn't read revision ID: %s\n", strerror(error)); exit(1); } switch (dev->device_id) { case PCI_CHIP_I915_G: if (stepping < 0x04) step_desc = "<B1"; else if (stepping == 0x04) step_desc = "B1"; else if (stepping == 0x0e) step_desc = "C2"; else if (stepping > 0x0e) step_desc = ">C2"; else step_desc = ">B1 <C2"; break; case PCI_CHIP_I915_GM: if (stepping < 0x03) step_desc = "<B1"; else if (stepping == 0x03) step_desc = "B1/C0"; else if (stepping == 0x04) step_desc = "C1/C2"; else step_desc = ">C2"; break; case PCI_CHIP_I945_GM: if (stepping < 0x03) step_desc = "<A3"; else if (stepping == 0x03) step_desc = "A3"; else step_desc = ">A3"; break; case PCI_CHIP_I965_G: case PCI_CHIP_I965_Q: if (stepping < 0x02) step_desc = "<C1"; else if (stepping == 0x02) step_desc = "C1/C2"; else step_desc = ">C2"; break; case PCI_CHIP_I965_GM: if (stepping < 0x03) step_desc = "<C0"; else if (stepping == 0x03) step_desc = "C0"; else step_desc = ">C0"; break; case PCI_CHIP_I965_G_1: if (stepping < 0x03) step_desc = "<E0"; else if (stepping == 0x03) step_desc = "E0"; else step_desc = ">E0"; break; case PCI_CHIP_GM45_GM: if (stepping < 0x07) step_desc = "<B3"; else if (stepping == 0x03) step_desc = "B3"; else step_desc = ">B3"; break; case PCI_CHIP_G45_G: case PCI_CHIP_Q45_G: case PCI_CHIP_G41_G: if (stepping < 0x02) step_desc = "<A2"; else if (stepping == 0x02) step_desc = "A2"; else if (stepping == 0x03) step_desc = "A3"; else step_desc = ">A3"; break; } printf("Vendor: 0x%04x, Device: 0x%04x, Revision: 0x%02x (%s)\n", dev->vendor_id, dev->device_id, stepping, step_desc); print_clock_info(dev); return 0; }
int main( int argc, char ** argv ) { struct pci_device * dev; uint8_t val; int newval; int mode; int argp; setuid(0); if( pci_system_init() ) { fprintf( stderr, "ERROR: PCI bus init failed. No root?\n" ); exit( 1 ); } dev = pci_device_find_by_slot( 0, 0, 2, 1 ); if( !isNc10( dev ) ) { fprintf( stderr, "ERROR: This device does not look not like a Samsung NC10.\n" ); exit( 1 ); } mode = 0; argp = 1; switch( argc ) { case 1: mode = 0; break; case 2: if( !strcmp( "-get", argv[argp] ) ) { mode=0; argp++; } else { usage(); exit( 1 ); } break; case 3: if( !strcmp( "-set", argv[argp] ) || !strcmp( "=", argv[argp] ) ) { mode = 1; argp++; } else if( !strcmp( "-inc", argv[argp] ) || !strcmp( "+", argv[argp] ) ) { mode = 2; argp++; } else if( !strcmp( "-dec", argv[argp] ) || !strcmp( "-", argv[argp] ) ) { mode = 3; argp++; } else { usage(); exit( 1 ); } break; default: usage(); exit( 1 ); } switch( mode ) { case 0: /* get */ val = getBrightness( dev ); printf("%d\n", val); break; case 1: /* set */ val = (uint8_t) atoi( argv[argp] ); setBrightness( dev, val ); break; case 2: /* inc */ val = getBrightness( dev ); newval = val + atoi( argv[argp] ); if( newval > 255 ) newval = 255; setBrightness( dev, (uint8_t) newval ); break; case 3: /* dec */ val = getBrightness( dev ); newval = val - atoi( argv[argp] ); if( newval < 0 ) newval = 0; setBrightness( dev, (uint8_t) newval ); break; } pci_system_cleanup(); return 0; }