]> mj.ucw.cz Git - pciutils.git/blob - lib/pci.h
Capability list parser now recognizes all AGP and all PCI Power Management
[pciutils.git] / lib / pci.h
1 /*
2  *      $Id: pci.h,v 1.2 1999/01/24 21:35:36 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 #include <linux/types.h>
27
28 typedef __u8 byte;
29 typedef __u8 u8;
30 typedef __u16 word;
31 typedef __u16 u16;
32 typedef __u32 u32;
33
34 /*
35  *      PCI Access Structure
36  */
37
38 struct pci_methods;
39 struct nl_entry;
40
41 #define PCI_ACCESS_AUTO                 0       /* Autodetection (params: none) */
42 #define PCI_ACCESS_PROC_BUS_PCI         1       /* Linux /proc/bus/pci (params: path) */
43 #define PCI_ACCESS_SYSCALLS             2       /* pciconfig_read() syscalls (params: none) */
44 #define PCI_ACCESS_I386_TYPE1           3       /* i386 ports, type 1 (params: none) */
45 #define PCI_ACCESS_I386_TYPE2           4       /* i386 ports, type 2 (params: none) */
46 #define PCI_ACCESS_DUMP                 5       /* Dump file (params: filename) */
47 #define PCI_ACCESS_MAX                  6
48
49 struct pci_access {
50   /* Options you can change: */
51   unsigned int method;                  /* Access method */
52   char *method_params[PCI_ACCESS_MAX];  /* Parameters for the methods */
53   int writeable;                        /* Open in read/write mode */
54   int buscentric;                       /* Bus-centric view of the world */
55   char *id_file_name;                   /* Name of ID list file */
56   int numeric_ids;                      /* Don't resolve device IDs to names */
57   int debugging;                        /* Turn on debugging messages */
58
59   /* Functions you can override: */
60   void (*error)(char *msg, ...);        /* Write error message and quit */
61   void (*warning)(char *msg, ...);      /* Write a warning message */
62   void (*debug)(char *msg, ...);        /* Write a debugging message */
63
64   struct pci_dev *devices;              /* Devices found on this bus */
65
66   /* Fields used internally: */
67   struct pci_methods *methods;
68   char *nl_list;                        /* Name list cache */
69   struct nl_entry **nl_hash;
70   int fd;                               /* proc: fd */
71   int fd_rw;                            /* proc: fd opened read-write */
72   struct pci_dev *cached_dev;           /* proc: device the fd is for */
73 };
74
75 /* Initialize PCI access */
76 struct pci_access *pci_alloc(void);
77 void pci_init(struct pci_access *);
78 void pci_cleanup(struct pci_access *);
79
80 /* Scanning of devices */
81 void pci_scan_bus(struct pci_access *acc);
82 struct pci_dev *pci_get_dev(struct pci_access *acc, int bus, int dev, int func); /* Raw access to specified device */
83 void pci_free_dev(struct pci_dev *);
84
85 /*
86  *      Devices
87  */
88
89 struct pci_dev {
90   struct pci_dev *next;                 /* Next device in the chain */
91   word bus;                             /* Higher byte can select host bridges */
92   byte dev, func;                       /* Device and function */
93
94   /* These fields are set by pci_fill_info() */
95   word vendor_id, device_id;            /* Identity of the device */
96   int irq;                              /* IRQ number */
97   unsigned long base_addr[6];           /* Base addresses */
98   unsigned long rom_base_addr;          /* Expansion ROM base address */
99
100   /* Fields used internally: */
101   struct pci_access *access;
102   struct pci_methods *methods;
103   byte *cache;                          /* Cached information */
104   int cache_len;
105   int known_fields;                     /* Set of info fields that is already known */
106   int hdrtype;                          /* Direct methods: header type */
107   void *aux;                            /* Auxillary data */
108 };
109
110 byte pci_read_byte(struct pci_dev *, int pos); /* Access to configuration space */
111 word pci_read_word(struct pci_dev *, int pos);
112 u32  pci_read_long(struct pci_dev *, int pos);
113 int pci_read_block(struct pci_dev *, int pos, byte *buf, int len);
114 int pci_write_byte(struct pci_dev *, int pos, byte data);
115 int pci_write_word(struct pci_dev *, int pos, word data);
116 int pci_write_long(struct pci_dev *, int pos, u32 data);
117 int pci_write_block(struct pci_dev *, int pos, byte *buf, int len);
118
119 void pci_fill_info(struct pci_dev *, int flags); /* Fill in device information */
120
121 #define PCI_FILL_IDENT          1
122 #define PCI_FILL_IRQ            2
123 #define PCI_FILL_BASES          4
124 #define PCI_FILL_ROM_BASE       8
125 #define PCI_FILL_RESCAN         0x10000
126
127 void pci_setup_cache(struct pci_dev *, byte *cache, int len);
128
129 /*
130  *      Filters
131  */
132
133 struct pci_filter {
134   int bus, slot, func;                  /* -1 = ANY */
135   int vendor, device;
136 };
137
138 void pci_filter_init(struct pci_access *, struct pci_filter *);
139 char *pci_filter_parse_slot(struct pci_filter *, char *);
140 char *pci_filter_parse_id(struct pci_filter *, char *);
141 int pci_filter_match(struct pci_filter *, struct pci_dev *);
142
143 /*
144  *      Device names
145  */
146
147 char *pci_lookup_name(struct pci_access *a, char *buf, int size, int flags, u32 arg1, u32 arg2);
148 void pci_free_name_list(struct pci_access *a);
149
150 #define PCI_LOOKUP_VENDOR 1
151 #define PCI_LOOKUP_DEVICE 2
152 #define PCI_LOOKUP_CLASS 4
153 #define PCI_LOOKUP_SUBSYSTEM 8
154 #define PCI_LOOKUP_NUMERIC 0x10000
155
156 #endif