home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / doc / pciutils / examples / example.c
Encoding:
C/C++ Source or Header  |  2006-07-12  |  1.1 KB  |  33 lines

  1. /*
  2.  *    The PCI Library -- Example of use (simplistic lister of PCI devices)
  3.  *
  4.  *    Written by Martin Mares and put to public domain. You can do
  5.  *    with it anything you want, but I don't give you any warranty.
  6.  */
  7.  
  8. #include <stdio.h>
  9.  
  10. #include "pci/pci.h"
  11.  
  12. int main(void)
  13. {
  14.   struct pci_access *pacc;
  15.   struct pci_dev *dev;
  16.   unsigned int c;
  17.  
  18.   pacc = pci_alloc();        /* Get the pci_access structure */
  19.   /* Set all options you want -- here we stick with the defaults */
  20.   pci_init(pacc);        /* Initialize the PCI library */
  21.   pci_scan_bus(pacc);        /* We want to get the list of devices */
  22.   for(dev=pacc->devices; dev; dev=dev->next)    /* Iterate over all devices */
  23.     {
  24.       pci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_BASES);    /* Fill in header info we need */
  25.       c = pci_read_word(dev, PCI_CLASS_DEVICE);    /* Read config register directly */
  26.       printf("%02x:%02x.%d vendor=%04x device=%04x class=%04x irq=%d base0=%lx\n",
  27.          dev->bus, dev->dev, dev->func, dev->vendor_id, dev->device_id,
  28.          c, dev->irq, dev->base_addr[0]);
  29.     }
  30.   pci_cleanup(pacc);        /* Close everything */
  31.   return 0;
  32. }
  33.