00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 #ifndef LIBPCI_H_
00012 # define LIBPCI_H_
00013 
00014 #include <libc.h>
00015 #include <pcireg.h>
00016 
00017 typedef u_int16_t pci_tag_t;
00018 
00019 #define PCI_WAIT_TIMEOUT                        5
00020 
00021 #define MAX_BUS                                 256
00022 #define MAX_DEV_PER_BUS                         32
00023 #define MAX_FUN_PER_DEV                         8
00024 
00025 #define PCI_BUS(pci_tag)                        ((pci_tag >> 8) & (MAX_BUS - 1))
00026 #define PCI_DEV(pci_tag)                        ((pci_tag >> 3) & (MAX_DEV_PER_BUS - 1))
00027 #define PCI_FUN(pci_tag)                        (pci_tag & (MAX_FUN_PER_DEV - 1))
00028 
00029 typedef struct          s_pci_device
00030 {
00031   pci_tag_t             pci_tag;
00032   pci_reg_t             pci_id;
00033   pci_reg_t             pci_class;
00034 } pci_dev_t;
00035 
00036 
00037 
00038 
00039 
00040 const char      *pci_vendor_name(pci_vendor_t pci_vendor);
00041 const char      *pci_product_name(pci_vendor_t  pci_vendor,
00042                                   pci_product_t pci_product);
00043 
00044 typedef int (*t_pci_find_fun)(pci_dev_t *);
00045 int             pci_find_device(pci_dev_t       *device,
00046                                 t_pci_find_fun  find_fun);
00047 
00048 
00049 
00050 
00051 
00052 #define SYSPCI_DEVICES          0
00053 #define SYSPCI_READ_REG         1
00054 #define SYSPCI_WRITE_REG        2
00055 
00056 int     pci_devices(paddr_t *list_addr, int *list_size);
00057 
00058 int     pci_read_reg(pci_tag_t pci_tag, int reg_addr, int bytes, pci_reg_t *value);
00059 
00060 int     pci_write_reg(pci_tag_t pci_tag, int reg_addr, int bytes, pci_reg_t value);
00061 
00062 int     pci_map_reg(pci_tag_t   pci_tag,
00063                     int         reg_addr);
00064 
00065 #endif