pcireg.h revision 1.7
1/*	$OpenBSD: pcireg.h,v 1.7 1998/02/03 19:47:13 deraadt Exp $	*/
2/*	$NetBSD: pcireg.h,v 1.11 1996/08/10 15:42:33 mycroft Exp $	*/
3
4/*
5 * Copyright (c) 1995, 1996 Christopher G. Demetriou.  All rights reserved.
6 * Copyright (c) 1994, 1996 Charles Hannum.  All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 *    must display the following acknowledgement:
18 *	This product includes software developed by Charles Hannum.
19 * 4. The name of the author may not be used to endorse or promote products
20 *    derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34#ifndef _DEV_PCI_PCIREG_H_
35#define	_DEV_PCI_PCIREG_H_
36
37/*
38 * Standardized PCI configuration information
39 *
40 * XXX This is not complete.
41 */
42
43/*
44 * Device identification register; contains a vendor ID and a device ID.
45 */
46#define	PCI_ID_REG			0x00
47
48typedef u_int16_t pci_vendor_id_t;
49typedef u_int16_t pci_product_id_t;
50
51#define	PCI_VENDOR_SHIFT			0
52#define	PCI_VENDOR_MASK				0xffff
53#define	PCI_VENDOR(id) \
54	    (((id) >> PCI_VENDOR_SHIFT) & PCI_VENDOR_MASK)
55
56#define	PCI_PRODUCT_SHIFT			16
57#define	PCI_PRODUCT_MASK			0xffff
58#define	PCI_PRODUCT(id) \
59	    (((id) >> PCI_PRODUCT_SHIFT) & PCI_PRODUCT_MASK)
60
61/*
62 * Command and status register.
63 */
64#define	PCI_COMMAND_STATUS_REG			0x04
65
66#define	PCI_COMMAND_IO_ENABLE			0x00000001
67#define	PCI_COMMAND_MEM_ENABLE			0x00000002
68#define	PCI_COMMAND_MASTER_ENABLE		0x00000004
69#define	PCI_COMMAND_SPECIAL_ENABLE		0x00000008
70#define	PCI_COMMAND_INVALIDATE_ENABLE		0x00000010
71#define	PCI_COMMAND_PALETTE_ENABLE		0x00000020
72#define	PCI_COMMAND_PARITY_ENABLE		0x00000040
73#define	PCI_COMMAND_STEPPING_ENABLE		0x00000080
74#define	PCI_COMMAND_SERR_ENABLE			0x00000100
75#define	PCI_COMMAND_BACKTOBACK_ENABLE		0x00000200
76
77#define	PCI_STATUS_BACKTOBACK_OKAY		0x00800000
78#define	PCI_STATUS_PARITY_ERROR			0x01000000
79#define	PCI_STATUS_DEVSEL_FAST			0x00000000
80#define	PCI_STATUS_DEVSEL_MEDIUM		0x02000000
81#define	PCI_STATUS_DEVSEL_SLOW			0x04000000
82#define	PCI_STATUS_DEVSEL_MASK			0x06000000
83#define	PCI_STATUS_TARGET_TARGET_ABORT		0x08000000
84#define	PCI_STATUS_MASTER_TARGET_ABORT		0x10000000
85#define	PCI_STATUS_MASTER_ABORT			0x20000000
86#define	PCI_STATUS_SPECIAL_ERROR		0x40000000
87#define	PCI_STATUS_PARITY_DETECT		0x80000000
88
89/*
90 * PCI Class and Revision Register; defines type and revision of device.
91 */
92#define	PCI_CLASS_REG			0x08
93
94typedef u_int8_t pci_class_t;
95typedef u_int8_t pci_subclass_t;
96typedef u_int8_t pci_interface_t;
97typedef u_int8_t pci_revision_t;
98
99#define	PCI_CLASS_SHIFT				24
100#define	PCI_CLASS_MASK				0xff
101#define	PCI_CLASS(cr) \
102	    (((cr) >> PCI_CLASS_SHIFT) & PCI_CLASS_MASK)
103
104#define	PCI_SUBCLASS_SHIFT			16
105#define	PCI_SUBCLASS_MASK			0xff
106#define	PCI_SUBCLASS(cr) \
107	    (((cr) >> PCI_SUBCLASS_SHIFT) & PCI_SUBCLASS_MASK)
108
109#define	PCI_INTERFACE_SHIFT			8
110#define	PCI_INTERFACE_MASK			0xff
111#define	PCI_INTERFACE(cr) \
112	    (((cr) >> PCI_INTERFACE_SHIFT) & PCI_INTERFACE_MASK)
113
114#define	PCI_REVISION_SHIFT			0
115#define	PCI_REVISION_MASK			0xff
116#define	PCI_REVISION(cr) \
117	    (((cr) >> PCI_REVISION_SHIFT) & PCI_REVISION_MASK)
118
119/* base classes */
120#define	PCI_CLASS_PREHISTORIC			0x00
121#define	PCI_CLASS_MASS_STORAGE			0x01
122#define	PCI_CLASS_NETWORK			0x02
123#define	PCI_CLASS_DISPLAY			0x03
124#define	PCI_CLASS_MULTIMEDIA			0x04
125#define	PCI_CLASS_MEMORY			0x05
126#define	PCI_CLASS_BRIDGE			0x06
127#define	PCI_CLASS_COMMUNICATIONS		0x07
128#define	PCI_CLASS_SYSTEM			0x08
129#define	PCI_CLASS_INPUT				0x09
130#define	PCI_CLASS_DOCK				0x0a
131#define	PCI_CLASS_PROCESSOR			0x0b
132#define	PCI_CLASS_SERIALBUS			0x0c
133#define	PCI_CLASS_UNDEFINED			0xff
134
135/* 0x00 prehistoric subclasses */
136#define	PCI_SUBCLASS_PREHISTORIC_MISC		0x00
137#define	PCI_SUBCLASS_PREHISTORIC_VGA		0x01
138
139/* 0x01 mass storage subclasses */
140#define	PCI_SUBCLASS_MASS_STORAGE_SCSI		0x00
141#define	PCI_SUBCLASS_MASS_STORAGE_IDE		0x01
142#define	PCI_SUBCLASS_MASS_STORAGE_FLOPPY	0x02
143#define	PCI_SUBCLASS_MASS_STORAGE_IPI		0x03
144#define	PCI_SUBCLASS_MASS_STORAGE_RAID		0x04
145#define	PCI_SUBCLASS_MASS_STORAGE_MISC		0x80
146
147/* 0x02 network subclasses */
148#define	PCI_SUBCLASS_NETWORK_ETHERNET		0x00
149#define	PCI_SUBCLASS_NETWORK_TOKENRING		0x01
150#define	PCI_SUBCLASS_NETWORK_FDDI		0x02
151#define	PCI_SUBCLASS_NETWORK_ATM		0x03
152#define	PCI_SUBCLASS_NETWORK_MISC		0x80
153
154/* 0x03 display subclasses */
155#define	PCI_SUBCLASS_DISPLAY_VGA		0x00
156#define	PCI_SUBCLASS_DISPLAY_XGA		0x01
157#define	PCI_SUBCLASS_DISPLAY_MISC		0x80
158
159/* 0x04 multimedia subclasses */
160#define	PCI_SUBCLASS_MULTIMEDIA_VIDEO		0x00
161#define	PCI_SUBCLASS_MULTIMEDIA_AUDIO		0x01
162#define	PCI_SUBCLASS_MULTIMEDIA_MISC		0x80
163
164/* 0x05 memory subclasses */
165#define	PCI_SUBCLASS_MEMORY_RAM			0x00
166#define	PCI_SUBCLASS_MEMORY_FLASH		0x01
167#define	PCI_SUBCLASS_MEMORY_MISC		0x80
168
169/* 0x06 bridge subclasses */
170#define	PCI_SUBCLASS_BRIDGE_HOST		0x00
171#define	PCI_SUBCLASS_BRIDGE_ISA			0x01
172#define	PCI_SUBCLASS_BRIDGE_EISA		0x02
173#define	PCI_SUBCLASS_BRIDGE_MC			0x03
174#define	PCI_SUBCLASS_BRIDGE_PCI			0x04
175#define	PCI_SUBCLASS_BRIDGE_PCMCIA		0x05
176#define	PCI_SUBCLASS_BRIDGE_NUBUS		0x06
177#define	PCI_SUBCLASS_BRIDGE_CARDBUS		0x07
178#define	PCI_SUBCLASS_BRIDGE_MISC		0x80
179
180/* 0x07 communications subclasses */
181#define	PCI_SUBCLASS_COMMUNICATIONS_SERIAL	0x00
182#define	PCI_SUBCLASS_COMMUNICATIONS_PARALLEL	0x01
183#define	PCI_SUBCLASS_COMMUNICATIONS_MISC	0x80
184
185/* 0x08 system subclasses */
186#define	PCI_SUBCLASS_SYSTEM_PIC			0x00
187#define	PCI_SUBCLASS_SYSTEM_DMA			0x01
188#define	PCI_SUBCLASS_SYSTEM_TIMER		0x02
189#define	PCI_SUBCLASS_SYSTEM_RTC			0x03
190#define	PCI_SUBCLASS_SYSTEM_MISC		0x80
191
192/* 0x09 input subclasses */
193#define	PCI_SUBCLASS_INPUT_KEYBOARD		0x00
194#define	PCI_SUBCLASS_INPUT_DIGITIZER		0x01
195#define	PCI_SUBCLASS_INPUT_MOUSE		0x02
196#define	PCI_SUBCLASS_INPUT_MISC			0x80
197
198/* 0x0a dock subclasses */
199#define	PCI_SUBCLASS_DOCK_GENERIC		0x00
200#define	PCI_SUBCLASS_DOCK_MISC			0x80
201
202/* 0x0b processor subclasses */
203#define	PCI_SUBCLASS_PROCESSOR_386		0x00
204#define	PCI_SUBCLASS_PROCESSOR_486		0x01
205#define	PCI_SUBCLASS_PROCESSOR_PENTIUM		0x02
206#define	PCI_SUBCLASS_PROCESSOR_ALPHA		0x10
207#define	PCI_SUBCLASS_PROCESSOR_POWERPC		0x20
208#define	PCI_SUBCLASS_PROCESSOR_COPROC		0x40
209
210/* 0x0c serial bus subclasses */
211#define	PCI_SUBCLASS_SERIALBUS_FIREWIRE		0x00
212#define	PCI_SUBCLASS_SERIALBUS_ACCESS		0x01
213#define	PCI_SUBCLASS_SERIALBUS_SSA		0x02
214#define	PCI_SUBCLASS_SERIALBUS_USB		0x03
215#define	PCI_SUBCLASS_SERIALBUS_FIBER		0x04
216
217/*
218 * PCI BIST/Header Type/Latency Timer/Cache Line Size Register.
219 */
220#define	PCI_BHLC_REG			0x0c
221
222#define	PCI_BIST_SHIFT				24
223#define	PCI_BIST_MASK				0xff
224#define	PCI_BIST(bhlcr) \
225	    (((bhlcr) >> PCI_BIST_SHIFT) & PCI_BIST_MASK)
226
227#define	PCI_HDRTYPE_SHIFT			24
228#define	PCI_HDRTYPE_MASK			0xff
229#define	PCI_HDRTYPE(bhlcr) \
230	    (((bhlcr) >> PCI_HDRTYPE_SHIFT) & PCI_HDRTYPE_MASK)
231
232#define	PCI_HDRTYPE_MULTIFN(bhlcr) \
233	    ((PCI_HDRTYPE(bhlcr) & 0x80) != 0)
234
235#define	PCI_LATTIMER_SHIFT			24
236#define	PCI_LATTIMER_MASK			0xff
237#define	PCI_LATTIMER(bhlcr) \
238	    (((bhlcr) >> PCI_LATTIMER_SHIFT) & PCI_LATTIMER_MASK)
239
240#define	PCI_CACHELINE_SHIFT			24
241#define	PCI_CACHELINE_MASK			0xff
242#define	PCI_CACHELINE(bhlcr) \
243	    (((bhlcr) >> PCI_CACHELINE_SHIFT) & PCI_CACHELINE_MASK)
244
245/*
246 * Mapping registers
247 */
248#define	PCI_MAPREG_START		0x10
249#define	PCI_MAPREG_END			0x28
250
251#define	PCI_MAPREG_TYPE(mr)						\
252	    ((mr) & PCI_MAPREG_TYPE_MASK)
253#define	PCI_MAPREG_TYPE_MASK			0x00000001
254
255#define	PCI_MAPREG_TYPE_MEM			0x00000000
256#define	PCI_MAPREG_TYPE_IO			0x00000001
257
258#define	PCI_MAPREG_MEM_TYPE(mr)						\
259	    ((mr) & PCI_MAPREG_MEM_TYPE_MASK)
260#define	PCI_MAPREG_MEM_TYPE_MASK		0x00000006
261
262#define	PCI_MAPREG_MEM_TYPE_32BIT		0x00000000
263#define	PCI_MAPREG_MEM_TYPE_32BIT_1M		0x00000002
264#define	PCI_MAPREG_MEM_TYPE_64BIT		0x00000004
265
266#define	PCI_MAPREG_MEM_CACHEABLE(mr)					\
267	    (((mr) & PCI_MAPREG_MEM_CACHEABLE_MASK) != 0)
268#define	PCI_MAPREG_MEM_CACHEABLE_MASK		0x00000008
269
270#define	PCI_MAPREG_MEM_ADDR(mr)						\
271	    ((mr) & PCI_MAPREG_MEM_ADDR_MASK)
272#define	PCI_MAPREG_MEM_SIZE(mr)						\
273	    (PCI_MAPREG_MEM_ADDR(mr) & -PCI_MAPREG_MEM_ADDR(mr))
274#define	PCI_MAPREG_MEM_ADDR_MASK		0xfffffff0
275
276#define	PCI_MAPREG_IO_ADDR(mr)						\
277	    ((mr) & PCI_MAPREG_IO_ADDR_MASK)
278#define	PCI_MAPREG_IO_SIZE(mr)						\
279	    (PCI_MAPREG_IO_ADDR(mr) & -PCI_MAPREG_IO_ADDR(mr))
280#define	PCI_MAPREG_IO_ADDR_MASK			0xfffffffe
281
282/*
283 * Interrupt Configuration Register; contains interrupt pin and line.
284 */
285#define	PCI_INTERRUPT_REG		0x3c
286
287typedef u_int8_t pci_intr_pin_t;
288typedef u_int8_t pci_intr_line_t;
289
290#define	PCI_INTERRUPT_PIN_SHIFT			8
291#define	PCI_INTERRUPT_PIN_MASK			0xff
292#define	PCI_INTERRUPT_PIN(icr) \
293	    (((icr) >> PCI_INTERRUPT_PIN_SHIFT) & PCI_INTERRUPT_PIN_MASK)
294
295#define	PCI_INTERRUPT_LINE_SHIFT		0
296#define	PCI_INTERRUPT_LINE_MASK			0xff
297#define	PCI_INTERRUPT_LINE(icr) \
298	    (((icr) >> PCI_INTERRUPT_LINE_SHIFT) & PCI_INTERRUPT_LINE_MASK)
299
300#define	PCI_INTERRUPT_PIN_NONE			0x00
301#define	PCI_INTERRUPT_PIN_A			0x01
302#define	PCI_INTERRUPT_PIN_B			0x02
303#define	PCI_INTERRUPT_PIN_C			0x03
304#define	PCI_INTERRUPT_PIN_D			0x04
305
306#endif /* _DEV_PCI_PCIREG_H_ */
307