]> mj.ucw.cz Git - pciutils.git/blob - lib/pci.h
Include file splits and namespace cleanups.
[pciutils.git] / lib / pci.h
1 /*
2  *      The PCI Library
3  *
4  *      Copyright (c) 1997--2004 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 /*
17  *      PCI Access Structure
18  */
19
20 struct pci_methods;
21 struct nl_entry;
22
23 enum pci_access_type {
24   /* Known access methods, remember to update access.c as well */
25   PCI_ACCESS_AUTO,                      /* Autodetection (params: none) */
26   PCI_ACCESS_SYS_BUS_PCI,               /* Linux /sys/bus/pci (params: path) */
27   PCI_ACCESS_PROC_BUS_PCI,              /* Linux /proc/bus/pci (params: path) */
28   PCI_ACCESS_I386_TYPE1,                /* i386 ports, type 1 (params: none) */
29   PCI_ACCESS_I386_TYPE2,                /* i386 ports, type 2 (params: none) */
30   PCI_ACCESS_FBSD_DEVICE,               /* FreeBSD /dev/pci (params: path) */
31   PCI_ACCESS_AIX_DEVICE,                /* /dev/pci0, /dev/bus0, etc. */
32   PCI_ACCESS_NBSD_LIBPCI,               /* NetBSD libpci */
33   PCI_ACCESS_DUMP,                      /* Dump file (params: filename) */
34   PCI_ACCESS_MAX
35 };
36
37 struct pci_access {
38   /* Options you can change: */
39   unsigned int method;                  /* Access method */
40   char *method_params[PCI_ACCESS_MAX];  /* Parameters for the methods */
41   int writeable;                        /* Open in read/write mode */
42   int buscentric;                       /* Bus-centric view of the world */
43   char *id_file_name;                   /* Name of ID list file */
44   int numeric_ids;                      /* Don't resolve device IDs to names */
45   int debugging;                        /* Turn on debugging messages */
46
47   /* Functions you can override: */
48   void (*error)(char *msg, ...);        /* Write error message and quit */
49   void (*warning)(char *msg, ...);      /* Write a warning message */
50   void (*debug)(char *msg, ...);        /* Write a debugging message */
51
52   struct pci_dev *devices;              /* Devices found on this bus */
53
54   /* Fields used internally: */
55   struct pci_methods *methods;
56   char *nl_list;                        /* Name list cache */
57   struct nl_entry **nl_hash;
58   int fd;                               /* proc: fd */
59   int fd_rw;                            /* proc: fd opened read-write */
60   struct pci_dev *cached_dev;           /* proc: device the fd is for */
61   int fd_pos;                           /* proc: current position */
62 };
63
64 /* Initialize PCI access */
65 struct pci_access *pci_alloc(void);
66 void pci_init(struct pci_access *);
67 void pci_cleanup(struct pci_access *);
68
69 /* Scanning of devices */
70 void pci_scan_bus(struct pci_access *acc);
71 struct pci_dev *pci_get_dev(struct pci_access *acc, int domain, int bus, int dev, int func); /* Raw access to specified device */
72 void pci_free_dev(struct pci_dev *);
73
74 /*
75  *      Devices
76  */
77
78 struct pci_dev {
79   struct pci_dev *next;                 /* Next device in the chain */
80   u16 domain;                           /* PCI domain (host bridge) */
81   byte bus, dev, func;                  /* Bus inside domain, device and function */
82
83   /* These fields are set by pci_fill_info() */
84   int known_fields;                     /* Set of info fields already known */
85   word vendor_id, device_id;            /* Identity of the device */
86   int irq;                              /* IRQ number */
87   pciaddr_t base_addr[6];               /* Base addresses */
88   pciaddr_t size[6];                    /* Region sizes */
89   pciaddr_t rom_base_addr;              /* Expansion ROM base address */
90   pciaddr_t rom_size;                   /* Expansion ROM size */
91
92   /* Fields used internally: */
93   struct pci_access *access;
94   struct pci_methods *methods;
95   byte *cache;                          /* Cached config registers */
96   int cache_len;
97   int hdrtype;                          /* Cached low 7 bits of header type, -1 if unknown */
98   void *aux;                            /* Auxillary data */
99 };
100
101 #define PCI_ADDR_IO_MASK (~(pciaddr_t) 0x3)
102 #define PCI_ADDR_MEM_MASK (~(pciaddr_t) 0xf)
103
104 byte pci_read_byte(struct pci_dev *, int pos); /* Access to configuration space */
105 word pci_read_word(struct pci_dev *, int pos);
106 u32  pci_read_long(struct pci_dev *, int pos);
107 int pci_read_block(struct pci_dev *, int pos, byte *buf, int len);
108 int pci_write_byte(struct pci_dev *, int pos, byte data);
109 int pci_write_word(struct pci_dev *, int pos, word data);
110 int pci_write_long(struct pci_dev *, int pos, u32 data);
111 int pci_write_block(struct pci_dev *, int pos, byte *buf, int len);
112
113 int pci_fill_info(struct pci_dev *, int flags); /* Fill in device information */
114
115 #define PCI_FILL_IDENT          1
116 #define PCI_FILL_IRQ            2
117 #define PCI_FILL_BASES          4
118 #define PCI_FILL_ROM_BASE       8
119 #define PCI_FILL_SIZES          16
120 #define PCI_FILL_RESCAN         0x10000
121
122 void pci_setup_cache(struct pci_dev *, byte *cache, int len);
123
124 /*
125  *      Filters
126  */
127
128 struct pci_filter {
129   int domain, bus, slot, func;                  /* -1 = ANY */
130   int vendor, device;
131 };
132
133 void pci_filter_init(struct pci_access *, struct pci_filter *);
134 char *pci_filter_parse_slot(struct pci_filter *, char *);
135 char *pci_filter_parse_id(struct pci_filter *, char *);
136 int pci_filter_match(struct pci_filter *, struct pci_dev *);
137
138 /*
139  *      Device names
140  */
141
142 char *pci_lookup_name(struct pci_access *a, char *buf, int size, int flags, u32 arg1, u32 arg2, u32 arg3, u32 arg4);
143 void pci_free_name_list(struct pci_access *a);
144
145 #define PCI_LOOKUP_VENDOR 1
146 #define PCI_LOOKUP_DEVICE 2
147 #define PCI_LOOKUP_CLASS 4
148 #define PCI_LOOKUP_SUBSYSTEM 8
149 #define PCI_LOOKUP_PROGIF 16
150 #define PCI_LOOKUP_NUMERIC 0x10000
151
152 #endif