~peter-pearse/ubuntu/natty/pciutils/prop001

« back to all changes in this revision

Viewing changes to lib/pci.h

  • Committer: Bazaar Package Importer
  • Author(s): Remco van de Meent
  • Date: 2002-03-11 13:26:04 UTC
  • Revision ID: james.westby@ubuntu.com-20020311132604-7way9hqnt42hgmxd
Tags: upstream-2.1.9
ImportĀ upstreamĀ versionĀ 2.1.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *      $Id: pci.h,v 1.8 2000/04/21 11:58:00 mj Exp $
 
3
 *
 
4
 *      The PCI Library
 
5
 *
 
6
 *      Copyright (c) 1997--1999 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
 
7
 *
 
8
 *      Can be freely distributed and used under the terms of the GNU GPL.
 
9
 */
 
10
 
 
11
#ifndef _PCI_LIB_H
 
12
#define _PCI_LIB_H
 
13
 
 
14
#include "config.h"
 
15
 
 
16
#ifdef HAVE_OWN_HEADER_H
 
17
#include "header.h"
 
18
#else
 
19
#include <linux/pci.h>
 
20
#endif
 
21
 
 
22
/*
 
23
 *      Types
 
24
 */
 
25
 
 
26
#ifdef OS_LINUX
 
27
#include <linux/types.h>
 
28
 
 
29
typedef __u8 byte;
 
30
typedef __u8 u8;
 
31
typedef __u16 word;
 
32
typedef __u16 u16;
 
33
typedef __u32 u32;
 
34
#endif
 
35
 
 
36
#ifdef OS_FREEBSD
 
37
#include <sys/types.h>
 
38
 
 
39
typedef u_int8_t byte;
 
40
typedef u_int8_t u8;
 
41
typedef u_int16_t word;
 
42
typedef u_int16_t u16;
 
43
typedef u_int32_t u32;
 
44
#endif
 
45
 
 
46
#ifdef OS_AIX
 
47
#include <sys/param.h>
 
48
 
 
49
typedef u_int8_t byte;
 
50
typedef u_int8_t u8;
 
51
typedef u_int16_t word;
 
52
typedef u_int16_t u16;
 
53
typedef u_int32_t u32;
 
54
#endif
 
55
 
 
56
#ifdef HAVE_LONG_ADDRESS
 
57
typedef unsigned long long pciaddr_t;
 
58
#else
 
59
typedef unsigned long pciaddr_t;
 
60
#endif
 
61
 
 
62
/*
 
63
 *      PCI Access Structure
 
64
 */
 
65
 
 
66
struct pci_methods;
 
67
struct nl_entry;
 
68
 
 
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
 
78
 
 
79
struct pci_access {
 
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 */
 
88
 
 
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 */
 
93
 
 
94
  struct pci_dev *devices;              /* Devices found on this bus */
 
95
 
 
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 */
 
104
};
 
105
 
 
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 *);
 
110
 
 
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 *);
 
115
 
 
116
/*
 
117
 *      Devices
 
118
 */
 
119
 
 
120
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 */
 
124
 
 
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 */
 
133
 
 
134
  /* Fields used internally: */
 
135
  struct pci_access *access;
 
136
  struct pci_methods *methods;
 
137
  byte *cache;                          /* Cached information */
 
138
  int cache_len;
 
139
  int hdrtype;                          /* Direct methods: header type */
 
140
  void *aux;                            /* Auxillary data */
 
141
};
 
142
 
 
143
#define PCI_ADDR_IO_MASK (~(pciaddr_t) 0x3)
 
144
#define PCI_ADDR_MEM_MASK (~(pciaddr_t) 0xf)
 
145
 
 
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);
 
154
 
 
155
int pci_fill_info(struct pci_dev *, int flags); /* Fill in device information */
 
156
 
 
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
 
163
 
 
164
void pci_setup_cache(struct pci_dev *, byte *cache, int len);
 
165
 
 
166
/*
 
167
 *      Filters
 
168
 */
 
169
 
 
170
struct pci_filter {
 
171
  int bus, slot, func;                  /* -1 = ANY */
 
172
  int vendor, device;
 
173
};
 
174
 
 
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 *);
 
179
 
 
180
/*
 
181
 *      Device names
 
182
 */
 
183
 
 
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);
 
186
 
 
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
 
193
 
 
194
#endif