2 * $Id: pci.h,v 1.6 1999/07/20 14:01:35 mj Exp $
6 * Copyright (c) 1997--1999 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
8 * Can be freely distributed and used under the terms of the GNU GPL.
16 #ifdef HAVE_OWN_HEADER_H
19 #include <linux/pci.h>
27 #include <linux/types.h>
37 #include <sys/types.h>
39 typedef u_int8_t byte;
41 typedef u_int16_t word;
42 typedef u_int16_t u16;
43 typedef u_int32_t u32;
46 #ifdef HAVE_LONG_ADDRESS
47 typedef unsigned long long pciaddr_t;
49 typedef unsigned long pciaddr_t;
53 * PCI Access Structure
59 #define PCI_ACCESS_AUTO 0 /* Autodetection (params: none) */
60 #define PCI_ACCESS_PROC_BUS_PCI 1 /* Linux /proc/bus/pci (params: path) */
61 #define PCI_ACCESS_SYSCALLS 2 /* pciconfig_read() syscalls (params: none) */
62 #define PCI_ACCESS_I386_TYPE1 3 /* i386 ports, type 1 (params: none) */
63 #define PCI_ACCESS_I386_TYPE2 4 /* i386 ports, type 2 (params: none) */
64 #define PCI_ACCESS_FBSD_DEVICE 5 /* FreeBSD /dev/pci (params: path) */
65 #define PCI_ACCESS_DUMP 6 /* Dump file (params: filename) */
66 #define PCI_ACCESS_MAX 7
69 /* Options you can change: */
70 unsigned int method; /* Access method */
71 char *method_params[PCI_ACCESS_MAX]; /* Parameters for the methods */
72 int writeable; /* Open in read/write mode */
73 int buscentric; /* Bus-centric view of the world */
74 char *id_file_name; /* Name of ID list file */
75 int numeric_ids; /* Don't resolve device IDs to names */
76 int debugging; /* Turn on debugging messages */
78 /* Functions you can override: */
79 void (*error)(char *msg, ...); /* Write error message and quit */
80 void (*warning)(char *msg, ...); /* Write a warning message */
81 void (*debug)(char *msg, ...); /* Write a debugging message */
83 struct pci_dev *devices; /* Devices found on this bus */
85 /* Fields used internally: */
86 struct pci_methods *methods;
87 char *nl_list; /* Name list cache */
88 struct nl_entry **nl_hash;
89 int fd; /* proc: fd */
90 int fd_rw; /* proc: fd opened read-write */
91 struct pci_dev *cached_dev; /* proc: device the fd is for */
92 int fd_pos; /* proc: current position */
95 /* Initialize PCI access */
96 struct pci_access *pci_alloc(void);
97 void pci_init(struct pci_access *);
98 void pci_cleanup(struct pci_access *);
100 /* Scanning of devices */
101 void pci_scan_bus(struct pci_access *acc);
102 struct pci_dev *pci_get_dev(struct pci_access *acc, int bus, int dev, int func); /* Raw access to specified device */
103 void pci_free_dev(struct pci_dev *);
110 struct pci_dev *next; /* Next device in the chain */
111 word bus; /* Higher byte can select host bridges */
112 byte dev, func; /* Device and function */
114 /* These fields are set by pci_fill_info() */
115 int known_fields; /* Set of info fields already known */
116 word vendor_id, device_id; /* Identity of the device */
117 int irq; /* IRQ number */
118 pciaddr_t base_addr[6]; /* Base addresses */
119 pciaddr_t size[6]; /* Region sizes */
120 pciaddr_t rom_base_addr; /* Expansion ROM base address */
121 pciaddr_t rom_size; /* Expansion ROM size */
123 /* Fields used internally: */
124 struct pci_access *access;
125 struct pci_methods *methods;
126 byte *cache; /* Cached information */
128 int hdrtype; /* Direct methods: header type */
129 void *aux; /* Auxillary data */
132 #define PCI_ADDR_IO_MASK (~(pciaddr_t) 0x3)
133 #define PCI_ADDR_MEM_MASK (~(pciaddr_t) 0xf)
135 byte pci_read_byte(struct pci_dev *, int pos); /* Access to configuration space */
136 word pci_read_word(struct pci_dev *, int pos);
137 u32 pci_read_long(struct pci_dev *, int pos);
138 int pci_read_block(struct pci_dev *, int pos, byte *buf, int len);
139 int pci_write_byte(struct pci_dev *, int pos, byte data);
140 int pci_write_word(struct pci_dev *, int pos, word data);
141 int pci_write_long(struct pci_dev *, int pos, u32 data);
142 int pci_write_block(struct pci_dev *, int pos, byte *buf, int len);
144 int pci_fill_info(struct pci_dev *, int flags); /* Fill in device information */
146 #define PCI_FILL_IDENT 1
147 #define PCI_FILL_IRQ 2
148 #define PCI_FILL_BASES 4
149 #define PCI_FILL_ROM_BASE 8
150 #define PCI_FILL_SIZES 16
151 #define PCI_FILL_RESCAN 0x10000
153 void pci_setup_cache(struct pci_dev *, byte *cache, int len);
160 int bus, slot, func; /* -1 = ANY */
164 void pci_filter_init(struct pci_access *, struct pci_filter *);
165 char *pci_filter_parse_slot(struct pci_filter *, char *);
166 char *pci_filter_parse_id(struct pci_filter *, char *);
167 int pci_filter_match(struct pci_filter *, struct pci_dev *);
173 char *pci_lookup_name(struct pci_access *a, char *buf, int size, int flags, u32 arg1, u32 arg2);
174 void pci_free_name_list(struct pci_access *a);
176 #define PCI_LOOKUP_VENDOR 1
177 #define PCI_LOOKUP_DEVICE 2
178 #define PCI_LOOKUP_CLASS 4
179 #define PCI_LOOKUP_SUBSYSTEM 8
180 #define PCI_LOOKUP_NUMERIC 0x10000