home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / pci / pci.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-09-09  |  6.3 KB  |  178 lines

  1. /*
  2.  *    The PCI Library
  3.  *
  4.  *    Copyright (c) 1997--2006 Martin Mares <mj@ucw.cz>
  5.  *
  6.  *    Can be freely distributed and used under the terms of the GNU GPL.
  7.  */
  8.  
  9. #ifndef _PCI_LIB_H
  10. #define _PCI_LIB_H
  11.  
  12. #include "config.h"
  13. #include "header.h"
  14. #include "types.h"
  15.  
  16. #define PCI_LIB_VERSION 0x020204
  17.  
  18. /*
  19.  *    PCI Access Structure
  20.  */
  21.  
  22. struct pci_methods;
  23.  
  24. enum pci_access_type {
  25.   /* Known access methods, remember to update access.c as well */
  26.   PCI_ACCESS_AUTO,            /* Autodetection (params: none) */
  27.   PCI_ACCESS_SYS_BUS_PCI,        /* Linux /sys/bus/pci (params: path) */
  28.   PCI_ACCESS_PROC_BUS_PCI,        /* Linux /proc/bus/pci (params: path) */
  29.   PCI_ACCESS_I386_TYPE1,        /* i386 ports, type 1 (params: none) */
  30.   PCI_ACCESS_I386_TYPE2,        /* i386 ports, type 2 (params: none) */
  31.   PCI_ACCESS_FBSD_DEVICE,        /* FreeBSD /dev/pci (params: path) */
  32.   PCI_ACCESS_AIX_DEVICE,        /* /dev/pci0, /dev/bus0, etc. */
  33.   PCI_ACCESS_NBSD_LIBPCI,        /* NetBSD libpci */
  34.   PCI_ACCESS_OBSD_DEVICE,        /* OpenBSD /dev/pci */
  35.   PCI_ACCESS_DUMP,            /* Dump file (params: filename) */
  36.   PCI_ACCESS_MAX
  37. };
  38.  
  39. struct pci_access {
  40.   /* Options you can change: */
  41.   unsigned int method;            /* Access method */
  42.   char *method_params[PCI_ACCESS_MAX];    /* Parameters for the methods */
  43.   int writeable;            /* Open in read/write mode */
  44.   int buscentric;            /* Bus-centric view of the world */
  45.   char *id_file_name;            /* Name of ID list file */
  46.   int free_id_name;            /* Set if id_file_name is malloced */
  47.   int numeric_ids;            /* Enforce PCI_LOOKUP_NUMERIC (>1 => PCI_LOOKUP_MIXED) */
  48.   int debugging;            /* Turn on debugging messages */
  49.  
  50.   /* Functions you can override: */
  51.   void (*error)(char *msg, ...);    /* Write error message and quit */
  52.   void (*warning)(char *msg, ...);    /* Write a warning message */
  53.   void (*debug)(char *msg, ...);    /* Write a debugging message */
  54.  
  55.   struct pci_dev *devices;        /* Devices found on this bus */
  56.  
  57.   /* Fields used internally: */
  58.   struct pci_methods *methods;
  59.   struct id_entry **id_hash;        /* names.c */
  60.   struct id_bucket *current_id_bucket;
  61.   int hash_load_failed;
  62.   int fd;                /* proc: fd */
  63.   int fd_rw;                /* proc: fd opened read-write */
  64.   struct pci_dev *cached_dev;        /* proc: device the fd is for */
  65.   int fd_pos;                /* proc: current position */
  66. };
  67.  
  68. /* Initialize PCI access */
  69. struct pci_access *pci_alloc(void);
  70. void pci_init(struct pci_access *);
  71. void pci_cleanup(struct pci_access *);
  72.  
  73. /* Scanning of devices */
  74. void pci_scan_bus(struct pci_access *acc);
  75. struct pci_dev *pci_get_dev(struct pci_access *acc, int domain, int bus, int dev, int func); /* Raw access to specified device */
  76. void pci_free_dev(struct pci_dev *);
  77.  
  78. /*
  79.  *    Devices
  80.  */
  81.  
  82. struct pci_dev {
  83.   struct pci_dev *next;            /* Next device in the chain */
  84.   u16 domain;                /* PCI domain (host bridge) */
  85.   u8 bus, dev, func;            /* Bus inside domain, device and function */
  86.  
  87.   /* These fields are set by pci_fill_info() */
  88.   int known_fields;            /* Set of info fields already known */
  89.   u16 vendor_id, device_id;        /* Identity of the device */
  90.   u16 device_class;            /* PCI device class */
  91.   int irq;                /* IRQ number */
  92.   pciaddr_t base_addr[6];        /* Base addresses */
  93.   pciaddr_t size[6];            /* Region sizes */
  94.   pciaddr_t rom_base_addr;        /* Expansion ROM base address */
  95.   pciaddr_t rom_size;            /* Expansion ROM size */
  96.  
  97.   /* Fields used internally: */
  98.   struct pci_access *access;
  99.   struct pci_methods *methods;
  100.   u8 *cache;                /* Cached config registers */
  101.   int cache_len;
  102.   int hdrtype;                /* Cached low 7 bits of header type, -1 if unknown */
  103.   void *aux;                /* Auxillary data */
  104. };
  105.  
  106. #define PCI_ADDR_IO_MASK (~(pciaddr_t) 0x3)
  107. #define PCI_ADDR_MEM_MASK (~(pciaddr_t) 0xf)
  108.  
  109. u8 pci_read_byte(struct pci_dev *, int pos); /* Access to configuration space */
  110. u16 pci_read_word(struct pci_dev *, int pos);
  111. u32  pci_read_long(struct pci_dev *, int pos);
  112. int pci_read_block(struct pci_dev *, int pos, u8 *buf, int len);
  113. int pci_write_byte(struct pci_dev *, int pos, u8 data);
  114. int pci_write_word(struct pci_dev *, int pos, u16 data);
  115. int pci_write_long(struct pci_dev *, int pos, u32 data);
  116. int pci_write_block(struct pci_dev *, int pos, u8 *buf, int len);
  117.  
  118. int pci_fill_info(struct pci_dev *, int flags); /* Fill in device information */
  119.  
  120. #define PCI_FILL_IDENT        1
  121. #define PCI_FILL_IRQ        2
  122. #define PCI_FILL_BASES        4
  123. #define PCI_FILL_ROM_BASE    8
  124. #define PCI_FILL_SIZES        16
  125. #define PCI_FILL_CLASS        32
  126. #define PCI_FILL_RESCAN        0x10000
  127.  
  128. void pci_setup_cache(struct pci_dev *, u8 *cache, int len);
  129.  
  130. /*
  131.  *    Filters
  132.  */
  133.  
  134. struct pci_filter {
  135.   int domain, bus, slot, func;            /* -1 = ANY */
  136.   int vendor, device;
  137. };
  138.  
  139. void pci_filter_init(struct pci_access *, struct pci_filter *);
  140. char *pci_filter_parse_slot(struct pci_filter *, char *);
  141. char *pci_filter_parse_id(struct pci_filter *, char *);
  142. int pci_filter_match(struct pci_filter *, struct pci_dev *);
  143.  
  144. /*
  145.  *    Conversion of PCI ID's to names (according to the pci.ids file)
  146.  *
  147.  *    Call pci_lookup_name() to identify different types of ID's:
  148.  *
  149.  *    VENDOR                (vendorID) -> vendor
  150.  *    DEVICE                (vendorID, deviceID) -> device
  151.  *    VENDOR | DEVICE            (vendorID, deviceID) -> combined vendor and device
  152.  *    SUBSYSTEM | VENDOR        (subvendorID) -> subsystem vendor
  153.  *    SUBSYSTEM | DEVICE        (vendorID, deviceID, subvendorID, subdevID) -> subsystem device
  154.  *    SUBSYSTEM | VENDOR | DEVICE    (vendorID, deviceID, subvendorID, subdevID) -> combined subsystem v+d
  155.  *    SUBSYSTEM | ...            (-1, -1, subvendorID, subdevID) -> generic subsystem
  156.  *    CLASS                (classID) -> class
  157.  *    PROGIF                (classID, progif) -> programming interface
  158.  */
  159.  
  160. char *pci_lookup_name(struct pci_access *a, char *buf, int size, int flags, ...);
  161.  
  162. int pci_load_name_list(struct pci_access *a);    /* Called automatically by pci_lookup_*() when needed; returns success */
  163. void pci_free_name_list(struct pci_access *a);    /* Called automatically by pci_cleanup() */
  164. void pci_set_name_list_path(struct pci_access *a, char *name, int to_be_freed);
  165.  
  166. enum pci_lookup_mode {
  167.   PCI_LOOKUP_VENDOR = 1,        /* Vendor name (args: vendorID) */
  168.   PCI_LOOKUP_DEVICE = 2,        /* Device name (args: vendorID, deviceID) */
  169.   PCI_LOOKUP_CLASS = 4,            /* Device class (args: classID) */
  170.   PCI_LOOKUP_SUBSYSTEM = 8,
  171.   PCI_LOOKUP_PROGIF = 16,        /* Programming interface (args: classID, prog_if) */
  172.   PCI_LOOKUP_NUMERIC = 0x10000,        /* Want only formatted numbers; default if access->numeric_ids is set */
  173.   PCI_LOOKUP_NO_NUMBERS = 0x20000,    /* Return NULL if not found in the database; default is to print numerically */
  174.   PCI_LOOKUP_MIXED = 0x40000,        /* Include both numbers and names */
  175. };
  176.  
  177. #endif
  178.