Rev 2479 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2479 | Rev 2927 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * The PCI Library |
2 | * The PCI Library |
3 | * |
3 | * |
4 | * Copyright (c) 1997--2005 Martin Mares <mj@ucw.cz> |
4 | * Copyright (c) 1997--2005 Martin Mares <mj@ucw.cz> |
5 | * |
5 | * |
6 | * May 8, 2006 - Modified and ported to HelenOS by Jakub Jermar. |
6 | * May 8, 2006 - Modified and ported to HelenOS by Jakub Jermar. |
7 | * |
7 | * |
8 | * Can be freely distributed and used under the terms of the GNU GPL. |
8 | * Can be freely distributed and used under the terms of the GNU GPL. |
9 | */ |
9 | */ |
10 | 10 | ||
11 | #ifndef _PCI_LIB_H |
11 | #ifndef _PCI_LIB_H |
12 | #define _PCI_LIB_H |
12 | #define _PCI_LIB_H |
13 | 13 | ||
14 | #include "header.h" |
14 | #include "header.h" |
15 | #include "types.h" |
15 | #include "types.h" |
16 | 16 | ||
17 | #define PCI_LIB_VERSION 0x020200 |
17 | #define PCI_LIB_VERSION 0x020200 |
18 | 18 | ||
19 | /* |
19 | /* |
20 | * PCI Access Structure |
20 | * PCI Access Structure |
21 | */ |
21 | */ |
22 | 22 | ||
23 | struct pci_methods; |
23 | struct pci_methods; |
24 | 24 | ||
25 | enum pci_access_type { |
25 | enum pci_access_type { |
26 | /* Known access methods, remember to update access.c as well */ |
26 | /* Known access methods, remember to update access.c as well */ |
27 | PCI_ACCESS_I386_TYPE1, /* i386 ports, type 1 (params: none) */ |
27 | PCI_ACCESS_I386_TYPE1, /* i386 ports, type 1 (params: none) */ |
28 | PCI_ACCESS_I386_TYPE2, /* i386 ports, type 2 (params: none) */ |
28 | PCI_ACCESS_I386_TYPE2, /* i386 ports, type 2 (params: none) */ |
29 | PCI_ACCESS_MAX |
29 | PCI_ACCESS_MAX |
30 | }; |
30 | }; |
31 | 31 | ||
32 | struct pci_access { |
32 | struct pci_access { |
33 | /* Options you can change: */ |
33 | /* Options you can change: */ |
34 | unsigned int method; /* Access method */ |
34 | unsigned int method; /* Access method */ |
35 | char *method_params[PCI_ACCESS_MAX]; /* Parameters for the methods */ |
35 | char *method_params[PCI_ACCESS_MAX]; /* Parameters for the methods */ |
36 | int writeable; /* Open in read/write mode */ |
36 | int writeable; /* Open in read/write mode */ |
37 | int buscentric; /* Bus-centric view of the world */ |
37 | int buscentric; /* Bus-centric view of the world */ |
38 | int numeric_ids; /* Don't resolve device IDs to names */ |
38 | int numeric_ids; /* Don't resolve device IDs to names */ |
39 | int debugging; /* Turn on debugging messages */ |
39 | int debugging; /* Turn on debugging messages */ |
40 | 40 | ||
41 | /* Functions you can override: */ |
41 | /* Functions you can override: */ |
42 | void (*error) (char *msg, ...); /* Write error message and quit */ |
42 | void (*error) (char *msg, ...); /* Write error message and quit */ |
43 | void (*warning) (char *msg, ...); /* Write a warning message */ |
43 | void (*warning) (char *msg, ...); /* Write a warning message */ |
44 | void (*debug) (char *msg, ...); /* Write a debugging message */ |
44 | void (*debug) (char *msg, ...); /* Write a debugging message */ |
45 | 45 | ||
46 | struct pci_dev *devices; /* Devices found on this bus */ |
46 | struct pci_dev *devices; /* Devices found on this bus */ |
47 | 47 | ||
48 | /* Fields used internally: */ |
48 | /* Fields used internally: */ |
49 | struct pci_methods *methods; |
49 | struct pci_methods *methods; |
50 | struct id_entry **id_hash; /* names.c */ |
50 | struct id_entry **id_hash; /* names.c */ |
51 | struct id_bucket *current_id_bucket; |
51 | struct id_bucket *current_id_bucket; |
52 | }; |
52 | }; |
53 | 53 | ||
54 | /* Initialize PCI access */ |
54 | /* Initialize PCI access */ |
55 | struct pci_access *pci_alloc(void); |
55 | struct pci_access *pci_alloc(void); |
56 | void pci_init(struct pci_access *); |
56 | void pci_init(struct pci_access *); |
57 | void pci_cleanup(struct pci_access *); |
57 | void pci_cleanup(struct pci_access *); |
58 | 58 | ||
59 | /* Scanning of devices */ |
59 | /* Scanning of devices */ |
60 | void pci_scan_bus(struct pci_access *acc); |
60 | void pci_scan_bus(struct pci_access *acc); |
61 | struct pci_dev *pci_get_dev(struct pci_access *acc, int domain, int bus, int dev, int func); /* Raw access to specified device */ |
61 | struct pci_dev *pci_get_dev(struct pci_access *acc, int domain, int bus, int dev, int func); /* Raw access to specified device */ |
62 | void pci_free_dev(struct pci_dev *); |
62 | void pci_free_dev(struct pci_dev *); |
63 | 63 | ||
64 | /* |
64 | /* |
65 | * Devices |
65 | * Devices |
66 | */ |
66 | */ |
67 | 67 | ||
68 | struct pci_dev { |
68 | struct pci_dev { |
69 | struct pci_dev *next; /* Next device in the chain */ |
69 | struct pci_dev *next; /* Next device in the chain */ |
70 | u16 domain; /* PCI domain (host bridge) */ |
70 | u16 domain; /* PCI domain (host bridge) */ |
71 | u8 bus, dev, func; /* Bus inside domain, device and function */ |
71 | u8 bus, dev, func; /* Bus inside domain, device and function */ |
72 | 72 | ||
73 | /* These fields are set by pci_fill_info() */ |
73 | /* These fields are set by pci_fill_info() */ |
74 | int known_fields; /* Set of info fields already known */ |
74 | int known_fields; /* Set of info fields already known */ |
75 | u16 vendor_id, device_id; /* Identity of the device */ |
75 | u16 vendor_id, device_id; /* Identity of the device */ |
76 | int irq; /* IRQ number */ |
76 | int irq; /* IRQ number */ |
77 | pciaddr_t base_addr[6]; /* Base addresses */ |
77 | pciaddr_t base_addr[6]; /* Base addresses */ |
78 | pciaddr_t size[6]; /* Region sizes */ |
78 | pciaddr_t size[6]; /* Region sizes */ |
79 | pciaddr_t rom_base_addr; /* Expansion ROM base address */ |
79 | pciaddr_t rom_base_addr; /* Expansion ROM base address */ |
80 | pciaddr_t rom_size; /* Expansion ROM size */ |
80 | pciaddr_t rom_size; /* Expansion ROM size */ |
81 | 81 | ||
82 | /* Fields used internally: */ |
82 | /* Fields used internally: */ |
83 | struct pci_access *access; |
83 | struct pci_access *access; |
84 | struct pci_methods *methods; |
84 | struct pci_methods *methods; |
85 | u8 *cache; /* Cached config registers */ |
85 | u8 *cache; /* Cached config registers */ |
86 | int cache_len; |
86 | int cache_len; |
87 | int hdrtype; /* Cached low 7 bits of header type, -1 if unknown */ |
87 | int hdrtype; /* Cached low 7 bits of header type, -1 if unknown */ |
88 | void *aux; /* Auxillary data */ |
88 | void *aux; /* Auxillary data */ |
89 | }; |
89 | }; |
90 | 90 | ||
91 | #define PCI_ADDR_IO_MASK (~(pciaddr_t) 0x3) |
91 | #define PCI_ADDR_IO_MASK (~(pciaddr_t) 0x3) |
92 | #define PCI_ADDR_MEM_MASK (~(pciaddr_t) 0xf) |
92 | #define PCI_ADDR_MEM_MASK (~(pciaddr_t) 0xf) |
93 | 93 | ||
94 | u8 pci_read_byte(struct pci_dev *, int pos); /* Access to configuration space */ |
94 | u8 pci_read_byte(struct pci_dev *, int pos); /* Access to configuration space */ |
95 | u16 pci_read_word(struct pci_dev *, int pos); |
95 | u16 pci_read_word(struct pci_dev *, int pos); |
96 | u32 pci_read_long(struct pci_dev *, int pos); |
96 | u32 pci_read_long(struct pci_dev *, int pos); |
97 | int pci_read_block(struct pci_dev *, int pos, u8 * buf, int len); |
97 | int pci_read_block(struct pci_dev *, int pos, u8 * buf, int len); |
98 | int pci_write_byte(struct pci_dev *, int pos, u8 data); |
98 | int pci_write_byte(struct pci_dev *, int pos, u8 data); |
99 | int pci_write_word(struct pci_dev *, int pos, u16 data); |
99 | int pci_write_word(struct pci_dev *, int pos, u16 data); |
100 | int pci_write_long(struct pci_dev *, int pos, u32 data); |
100 | int pci_write_long(struct pci_dev *, int pos, u32 data); |
101 | int pci_write_block(struct pci_dev *, int pos, u8 * buf, int len); |
101 | int pci_write_block(struct pci_dev *, int pos, u8 * buf, int len); |
102 | 102 | ||
103 | int pci_fill_info(struct pci_dev *, int flags); /* Fill in device information */ |
103 | int pci_fill_info(struct pci_dev *, int flags); /* Fill in device information */ |
104 | 104 | ||
105 | #define PCI_FILL_IDENT 1 |
105 | #define PCI_FILL_IDENT 1 |
106 | #define PCI_FILL_IRQ 2 |
106 | #define PCI_FILL_IRQ 2 |
107 | #define PCI_FILL_BASES 4 |
107 | #define PCI_FILL_BASES 4 |
108 | #define PCI_FILL_ROM_BASE 8 |
108 | #define PCI_FILL_ROM_BASE 8 |
109 | #define PCI_FILL_SIZES 16 |
109 | #define PCI_FILL_SIZES 16 |
110 | #define PCI_FILL_RESCAN 0x10000 |
110 | #define PCI_FILL_RESCAN 0x10000 |
111 | 111 | ||
112 | void pci_setup_cache(struct pci_dev *, u8 * cache, int len); |
112 | void pci_setup_cache(struct pci_dev *, u8 * cache, int len); |
113 | 113 | ||
114 | /* |
114 | /* |
115 | * Conversion of PCI ID's to names (according to the pci.ids file) |
115 | * Conversion of PCI ID's to names (according to the pci.ids file) |
116 | * |
116 | * |
117 | * Call pci_lookup_name() to identify different types of ID's: |
117 | * Call pci_lookup_name() to identify different types of ID's: |
118 | * |
118 | * |
119 | * VENDOR (vendorID) -> vendor |
119 | * VENDOR (vendorID) -> vendor |
120 | * DEVICE (vendorID, deviceID) -> device |
120 | * DEVICE (vendorID, deviceID) -> device |
121 | * VENDOR | DEVICE (vendorID, deviceID) -> combined vendor and device |
121 | * VENDOR | DEVICE (vendorID, deviceID) -> combined vendor and device |
122 | * SUBSYSTEM | VENDOR (subvendorID) -> subsystem vendor |
122 | * SUBSYSTEM | VENDOR (subvendorID) -> subsystem vendor |
123 | * SUBSYSTEM | DEVICE (vendorID, deviceID, subvendorID, subdevID) -> subsystem device |
123 | * SUBSYSTEM | DEVICE (vendorID, deviceID, subvendorID, subdevID) -> subsystem device |
124 | * SUBSYSTEM | VENDOR | DEVICE (vendorID, deviceID, subvendorID, subdevID) -> combined subsystem v+d |
124 | * SUBSYSTEM | VENDOR | DEVICE (vendorID, deviceID, subvendorID, subdevID) -> combined subsystem v+d |
125 | * SUBSYSTEM | ... (-1, -1, subvendorID, subdevID) -> generic subsystem |
125 | * SUBSYSTEM | ... (-1, -1, subvendorID, subdevID) -> generic subsystem |
126 | * CLASS (classID) -> class |
126 | * CLASS (classID) -> class |
127 | * PROGIF (classID, progif) -> programming interface |
127 | * PROGIF (classID, progif) -> programming interface |
128 | */ |
128 | */ |
129 | 129 | ||
130 | char *pci_lookup_name(struct pci_access *a, char *buf, int size, int flags, |
130 | char *pci_lookup_name(struct pci_access *a, char *buf, int size, int flags, |
131 | ...); |
131 | ...); |
132 | 132 | ||
133 | int pci_load_name_list(struct pci_access *a); /* Called automatically by pci_lookup_*() when needed; returns success */ |
133 | int pci_load_name_list(struct pci_access *a); /* Called automatically by pci_lookup_*() when needed; returns success */ |
134 | void pci_free_name_list(struct pci_access *a); /* Called automatically by pci_cleanup() */ |
134 | void pci_free_name_list(struct pci_access *a); /* Called automatically by pci_cleanup() */ |
135 | 135 | ||
136 | enum pci_lookup_mode { |
136 | enum pci_lookup_mode { |
137 | PCI_LOOKUP_VENDOR = 1, /* Vendor name (args: vendorID) */ |
137 | PCI_LOOKUP_VENDOR = 1, /* Vendor name (args: vendorID) */ |
138 | PCI_LOOKUP_DEVICE = 2, /* Device name (args: vendorID, deviceID) */ |
138 | PCI_LOOKUP_DEVICE = 2, /* Device name (args: vendorID, deviceID) */ |
139 | PCI_LOOKUP_CLASS = 4, /* Device class (args: classID) */ |
139 | PCI_LOOKUP_CLASS = 4, /* Device class (args: classID) */ |
140 | PCI_LOOKUP_SUBSYSTEM = 8, |
140 | PCI_LOOKUP_SUBSYSTEM = 8, |
141 | PCI_LOOKUP_PROGIF = 16, /* Programming interface (args: classID, prog_if) */ |
141 | PCI_LOOKUP_PROGIF = 16, /* Programming interface (args: classID, prog_if) */ |
142 | PCI_LOOKUP_NUMERIC = 0x10000, /* Want only formatted numbers; default if access->numeric_ids is set */ |
142 | PCI_LOOKUP_NUMERIC = 0x10000, /* Want only formatted numbers; default if access->numeric_ids is set */ |
143 | PCI_LOOKUP_NO_NUMBERS = 0x20000 /* Return NULL if not found in the database; default is to print numerically */ |
143 | PCI_LOOKUP_NO_NUMBERS = 0x20000 /* Return NULL if not found in the database; default is to print numerically */ |
144 | }; |
144 | }; |
145 | 145 | ||
146 | #endif |
146 | #endif |
147 | 147 |