2
* $Id: pci.h,v 1.8 2000/04/21 11:58:00 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;
47
#include <sys/param.h>
49
typedef u_int8_t byte;
51
typedef u_int16_t word;
52
typedef u_int16_t u16;
53
typedef u_int32_t u32;
56
#ifdef HAVE_LONG_ADDRESS
57
typedef unsigned long long pciaddr_t;
59
typedef unsigned long pciaddr_t;
63
* PCI Access Structure
69
#define PCI_ACCESS_AUTO 0 /* Autodetection (params: none) */
70
#define PCI_ACCESS_PROC_BUS_PCI 1 /* Linux /proc/bus/pci (params: path) */
71
#define PCI_ACCESS_SYSCALLS 2 /* pciconfig_read() syscalls (params: none) */
72
#define PCI_ACCESS_I386_TYPE1 3 /* i386 ports, type 1 (params: none) */
73
#define PCI_ACCESS_I386_TYPE2 4 /* i386 ports, type 2 (params: none) */
74
#define PCI_ACCESS_FBSD_DEVICE 5 /* FreeBSD /dev/pci (params: path) */
75
#define PCI_ACCESS_AIX_DEVICE 6 /* /dev/pci0, /dev/bus0, etc. */
76
#define PCI_ACCESS_DUMP 7 /* Dump file (params: filename) */
77
#define PCI_ACCESS_MAX 8
80
/* Options you can change: */
81
unsigned int method; /* Access method */
82
char *method_params[PCI_ACCESS_MAX]; /* Parameters for the methods */
83
int writeable; /* Open in read/write mode */
84
int buscentric; /* Bus-centric view of the world */
85
char *id_file_name; /* Name of ID list file */
86
int numeric_ids; /* Don't resolve device IDs to names */
87
int debugging; /* Turn on debugging messages */
89
/* Functions you can override: */
90
void (*error)(char *msg, ...); /* Write error message and quit */
91
void (*warning)(char *msg, ...); /* Write a warning message */
92
void (*debug)(char *msg, ...); /* Write a debugging message */
94
struct pci_dev *devices; /* Devices found on this bus */
96
/* Fields used internally: */
97
struct pci_methods *methods;
98
char *nl_list; /* Name list cache */
99
struct nl_entry **nl_hash;
100
int fd; /* proc: fd */
101
int fd_rw; /* proc: fd opened read-write */
102
struct pci_dev *cached_dev; /* proc: device the fd is for */
103
int fd_pos; /* proc: current position */
106
/* Initialize PCI access */
107
struct pci_access *pci_alloc(void);
108
void pci_init(struct pci_access *);
109
void pci_cleanup(struct pci_access *);
111
/* Scanning of devices */
112
void pci_scan_bus(struct pci_access *acc);
113
struct pci_dev *pci_get_dev(struct pci_access *acc, int bus, int dev, int func); /* Raw access to specified device */
114
void pci_free_dev(struct pci_dev *);
121
struct pci_dev *next; /* Next device in the chain */
122
word bus; /* Higher byte can select host bridges */
123
byte dev, func; /* Device and function */
125
/* These fields are set by pci_fill_info() */
126
int known_fields; /* Set of info fields already known */
127
word vendor_id, device_id; /* Identity of the device */
128
int irq; /* IRQ number */
129
pciaddr_t base_addr[6]; /* Base addresses */
130
pciaddr_t size[6]; /* Region sizes */
131
pciaddr_t rom_base_addr; /* Expansion ROM base address */
132
pciaddr_t rom_size; /* Expansion ROM size */
134
/* Fields used internally: */
135
struct pci_access *access;
136
struct pci_methods *methods;
137
byte *cache; /* Cached information */
139
int hdrtype; /* Direct methods: header type */
140
void *aux; /* Auxillary data */
143
#define PCI_ADDR_IO_MASK (~(pciaddr_t) 0x3)
144
#define PCI_ADDR_MEM_MASK (~(pciaddr_t) 0xf)
146
byte pci_read_byte(struct pci_dev *, int pos); /* Access to configuration space */
147
word pci_read_word(struct pci_dev *, int pos);
148
u32 pci_read_long(struct pci_dev *, int pos);
149
int pci_read_block(struct pci_dev *, int pos, byte *buf, int len);
150
int pci_write_byte(struct pci_dev *, int pos, byte data);
151
int pci_write_word(struct pci_dev *, int pos, word data);
152
int pci_write_long(struct pci_dev *, int pos, u32 data);
153
int pci_write_block(struct pci_dev *, int pos, byte *buf, int len);
155
int pci_fill_info(struct pci_dev *, int flags); /* Fill in device information */
157
#define PCI_FILL_IDENT 1
158
#define PCI_FILL_IRQ 2
159
#define PCI_FILL_BASES 4
160
#define PCI_FILL_ROM_BASE 8
161
#define PCI_FILL_SIZES 16
162
#define PCI_FILL_RESCAN 0x10000
164
void pci_setup_cache(struct pci_dev *, byte *cache, int len);
171
int bus, slot, func; /* -1 = ANY */
175
void pci_filter_init(struct pci_access *, struct pci_filter *);
176
char *pci_filter_parse_slot(struct pci_filter *, char *);
177
char *pci_filter_parse_id(struct pci_filter *, char *);
178
int pci_filter_match(struct pci_filter *, struct pci_dev *);
184
char *pci_lookup_name(struct pci_access *a, char *buf, int size, int flags, u32 arg1, u32 arg2, u32 arg3, u32 arg4);
185
void pci_free_name_list(struct pci_access *a);
187
#define PCI_LOOKUP_VENDOR 1
188
#define PCI_LOOKUP_DEVICE 2
189
#define PCI_LOOKUP_CLASS 4
190
#define PCI_LOOKUP_SUBSYSTEM 8
191
#define PCI_LOOKUP_PROGIF 16
192
#define PCI_LOOKUP_NUMERIC 0x10000