1/*
2 * Copyright (c) 1995, 1996, 1999
3 *     Christopher G. Demetriou.  All rights reserved.
4 * Copyright (c) 1994, 1996 Charles M. Hannum.  All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 *    must display the following acknowledgement:
16 *	This product includes software developed by Charles M. Hannum.
17 * 4. The name of the author may not be used to endorse or promote products
18 *    derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#ifndef _DEV_PCI_PCIREG_H_
33#define	_DEV_PCI_PCIREG_H_
34
35/*
36 * Standardized PCI configuration register definitions and macros.
37 * Derived from information found in the ``PCI Local Bus Specification,
38 * Revision 2.2, December 18, 1998.''
39 *
40 * Note: Register and field definitions assume 32-bit register accesses.
41 */
42
43#if !defined(__ASSEMBLER__)
44typedef uint16_t pci_vendor_id_t;
45typedef uint16_t pci_product_id_t;
46
47typedef uint8_t pci_class_t;
48typedef uint8_t pci_subclass_t;
49typedef uint8_t pci_interface_t;
50typedef uint8_t pci_revision_t;
51
52typedef uint8_t pci_intr_latency_t;
53typedef uint8_t pci_intr_grant_t;
54typedef uint8_t pci_intr_pin_t;
55typedef uint8_t pci_intr_line_t;
56#endif
57
58/* some PCI bus constants */
59
60#define PCI_BUSMAX	255
61#define PCI_DEVMAX	31
62#define PCI_FUNCMAX	7
63#define PCI_REGMAX	255
64
65/*
66 * Common PCI header
67 */
68
69/*
70 * Device identification register; contains a vendor ID and a device ID.
71 */
72#define	PCI_ID_REG			0x00
73
74#define	PCI_VENDOR_SHIFT			0
75#define	PCI_VENDOR_MASK				0xffff
76#define	PCI_VENDOR(id) \
77	    (((id) >> PCI_VENDOR_SHIFT) & PCI_VENDOR_MASK)
78
79#define	PCI_PRODUCT_SHIFT			16
80#define	PCI_PRODUCT_MASK			0xffff
81#define	PCI_PRODUCT(id) \
82	    (((id) >> PCI_PRODUCT_SHIFT) & PCI_PRODUCT_MASK)
83
84/*
85 * Command and status register.
86 */
87#define	PCI_COMMAND_STATUS_REG		0x04
88
89#define	PCI_COMMAND_SHIFT			0
90#define	PCI_COMMAND_MASK			0xffff
91#define PCI_COMMAND(csr) \
92	    (((csr) >> PCI_COMMAND_SHIFT) & PCI_COMMAND_MASK)
93
94#define	PCI_STATUS_SHIFT			16
95#define	PCI_STATUS_MASK				0xffff
96#define PCI_STATUS(csr) \
97	    (((csr) >> PCI_STATUS_SHIFT) & PCI_STATUS_MASK)
98
99#define	PCI_COMMAND_IO_ENABLE			0x00000001
100#define	PCI_COMMAND_MEM_ENABLE			0x00000002
101#define	PCI_COMMAND_MASTER_ENABLE		0x00000004
102#define	PCI_COMMAND_SPECIAL_ENABLE		0x00000008
103#define	PCI_COMMAND_INVALIDATE_ENABLE		0x00000010
104#define	PCI_COMMAND_PALETTE_ENABLE		0x00000020
105#define	PCI_COMMAND_PARITY_ENABLE		0x00000040
106#define	PCI_COMMAND_STEPPING_ENABLE		0x00000080
107#define	PCI_COMMAND_SERR_ENABLE			0x00000100
108#define	PCI_COMMAND_BACKTOBACK_ENABLE		0x00000200
109
110#define	PCI_STATUS_CAPLIST_SUPPORT		0x00100000
111#define	PCI_STATUS_66MHZ_SUPPORT		0x00200000
112#define	PCI_STATUS_UDF_SUPPORT			0x00400000
113#define	PCI_STATUS_BACKTOBACK_SUPPORT		0x00800000
114#define	PCI_STATUS_PARITY_ERROR			0x01000000
115#define	PCI_STATUS_DEVSEL_FAST			0x00000000
116#define	PCI_STATUS_DEVSEL_MEDIUM		0x02000000
117#define	PCI_STATUS_DEVSEL_SLOW			0x04000000
118#define	PCI_STATUS_DEVSEL_MASK			0x06000000
119#define	PCI_STATUS_DEVSEL_SHIFT			25
120#define PCI_STATUS_DEVSEL(scr) \
121	    (((scr) & PCI_STATUS_DEVSEL_MASK) >> PCI_STATUS_DEVSEL_SHIFT)
122#define	PCI_STATUS_TARGET_TARGET_ABORT		0x08000000
123#define	PCI_STATUS_MASTER_TARGET_ABORT		0x10000000
124#define	PCI_STATUS_MASTER_ABORT			0x20000000
125#define	PCI_STATUS_SYSTEM_ERROR			0x40000000
126#define	PCI_STATUS_PARITY_DETECT		0x80000000
127
128/*
129 * PCI Class and Revision Register; defines type and revision of device.
130 */
131#define	PCI_CLASS_REG			0x08
132
133#define	PCI_CLASS_SHIFT				24
134#define	PCI_CLASS_MASK				0xff
135#define	PCI_CLASS(cr) \
136	    (((cr) >> PCI_CLASS_SHIFT) & PCI_CLASS_MASK)
137
138#define	PCI_SUBCLASS_SHIFT			16
139#define	PCI_SUBCLASS_MASK			0xff
140#define	PCI_SUBCLASS(cr) \
141	    (((cr) >> PCI_SUBCLASS_SHIFT) & PCI_SUBCLASS_MASK)
142
143#define	PCI_INTERFACE_SHIFT			8
144#define	PCI_INTERFACE_MASK			0xff
145#define	PCI_INTERFACE(cr) \
146	    (((cr) >> PCI_INTERFACE_SHIFT) & PCI_INTERFACE_MASK)
147
148#define	PCI_REVISION_SHIFT			0
149#define	PCI_REVISION_MASK			0xff
150#define	PCI_REVISION(cr) \
151	    (((cr) >> PCI_REVISION_SHIFT) & PCI_REVISION_MASK)
152
153#define	PCI_CLASS_CODE(class, subclass, interface) \
154	    ((((class) & PCI_CLASS_MASK) << PCI_CLASS_SHIFT) | \
155	     (((subclass) & PCI_SUBCLASS_MASK) << PCI_SUBCLASS_SHIFT) | \
156	     (((interface) & PCI_INTERFACE_MASK) << PCI_INTERFACE_SHIFT))
157
158/* base classes */
159#define	PCI_CLASS_PREHISTORIC			0x00
160#define	PCI_CLASS_MASS_STORAGE			0x01
161#define	PCI_CLASS_NETWORK			0x02
162#define	PCI_CLASS_DISPLAY			0x03
163#define	PCI_CLASS_MULTIMEDIA			0x04
164#define	PCI_CLASS_MEMORY			0x05
165#define	PCI_CLASS_BRIDGE			0x06
166#define	PCI_CLASS_COMMUNICATIONS		0x07
167#define	PCI_CLASS_SYSTEM			0x08
168#define	PCI_CLASS_INPUT				0x09
169#define	PCI_CLASS_DOCK				0x0a
170#define	PCI_CLASS_PROCESSOR			0x0b
171#define	PCI_CLASS_SERIALBUS			0x0c
172#define	PCI_CLASS_WIRELESS			0x0d
173#define	PCI_CLASS_I2O				0x0e
174#define	PCI_CLASS_SATCOM			0x0f
175#define	PCI_CLASS_CRYPTO			0x10
176#define	PCI_CLASS_DASP				0x11
177#define	PCI_CLASS_UNDEFINED			0xff
178
179/* 0x00 prehistoric subclasses */
180#define	PCI_SUBCLASS_PREHISTORIC_MISC		0x00
181#define	PCI_SUBCLASS_PREHISTORIC_VGA		0x01
182
183/* 0x01 mass storage subclasses */
184#define	PCI_SUBCLASS_MASS_STORAGE_SCSI		0x00
185#define	PCI_SUBCLASS_MASS_STORAGE_IDE		0x01
186#define	PCI_SUBCLASS_MASS_STORAGE_FLOPPY	0x02
187#define	PCI_SUBCLASS_MASS_STORAGE_IPI		0x03
188#define	PCI_SUBCLASS_MASS_STORAGE_RAID		0x04
189#define	PCI_SUBCLASS_MASS_STORAGE_MISC		0x80
190
191/* 0x02 network subclasses */
192#define	PCI_SUBCLASS_NETWORK_ETHERNET		0x00
193#define	PCI_SUBCLASS_NETWORK_TOKENRING		0x01
194#define	PCI_SUBCLASS_NETWORK_FDDI		0x02
195#define	PCI_SUBCLASS_NETWORK_ATM		0x03
196#define	PCI_SUBCLASS_NETWORK_ISDN		0x04
197#define	PCI_SUBCLASS_NETWORK_WORLDFIP		0x05
198#define	PCI_SUBCLASS_NETWORK_PCIMGMULTICOMP	0x06
199#define	PCI_SUBCLASS_NETWORK_MISC		0x80
200
201/* 0x03 display subclasses */
202#define	PCI_SUBCLASS_DISPLAY_VGA		0x00
203#define	PCI_SUBCLASS_DISPLAY_XGA		0x01
204#define	PCI_SUBCLASS_DISPLAY_3D			0x02
205#define	PCI_SUBCLASS_DISPLAY_MISC		0x80
206
207/* 0x04 multimedia subclasses */
208#define	PCI_SUBCLASS_MULTIMEDIA_VIDEO		0x00
209#define	PCI_SUBCLASS_MULTIMEDIA_AUDIO		0x01
210#define	PCI_SUBCLASS_MULTIMEDIA_TELEPHONY	0x02
211#define	PCI_SUBCLASS_MULTIMEDIA_MISC		0x80
212
213/* 0x05 memory subclasses */
214#define	PCI_SUBCLASS_MEMORY_RAM			0x00
215#define	PCI_SUBCLASS_MEMORY_FLASH		0x01
216#define	PCI_SUBCLASS_MEMORY_MISC		0x80
217
218/* 0x06 bridge subclasses */
219#define	PCI_SUBCLASS_BRIDGE_HOST		0x00
220#define	PCI_SUBCLASS_BRIDGE_ISA			0x01
221#define	PCI_SUBCLASS_BRIDGE_EISA		0x02
222#define	PCI_SUBCLASS_BRIDGE_MCA			0x03
223#define	PCI_SUBCLASS_BRIDGE_PCI			0x04
224#define	PCI_SUBCLASS_BRIDGE_PCMCIA		0x05
225#define	PCI_SUBCLASS_BRIDGE_NUBUS		0x06
226#define	PCI_SUBCLASS_BRIDGE_CARDBUS		0x07
227#define	PCI_SUBCLASS_BRIDGE_RACEWAY		0x08
228#define	PCI_SUBCLASS_BRIDGE_STPCI		0x09
229#define	PCI_SUBCLASS_BRIDGE_INFINIBAND		0x0a
230#define	PCI_SUBCLASS_BRIDGE_MISC		0x80
231
232/* 0x07 communications subclasses */
233#define	PCI_SUBCLASS_COMMUNICATIONS_SERIAL	0x00
234#define	PCI_SUBCLASS_COMMUNICATIONS_PARALLEL	0x01
235#define	PCI_SUBCLASS_COMMUNICATIONS_MPSERIAL	0x02
236#define	PCI_SUBCLASS_COMMUNICATIONS_MODEM	0x03
237#define	PCI_SUBCLASS_COMMUNICATIONS_MISC	0x80
238
239/* 0x08 system subclasses */
240#define	PCI_SUBCLASS_SYSTEM_PIC			0x00
241#define	PCI_SUBCLASS_SYSTEM_DMA			0x01
242#define	PCI_SUBCLASS_SYSTEM_TIMER		0x02
243#define	PCI_SUBCLASS_SYSTEM_RTC			0x03
244#define	PCI_SUBCLASS_SYSTEM_PCIHOTPLUG		0x04
245#define	PCI_SUBCLASS_SYSTEM_MISC		0x80
246
247/* 0x09 input subclasses */
248#define	PCI_SUBCLASS_INPUT_KEYBOARD		0x00
249#define	PCI_SUBCLASS_INPUT_DIGITIZER		0x01
250#define	PCI_SUBCLASS_INPUT_MOUSE		0x02
251#define	PCI_SUBCLASS_INPUT_SCANNER		0x03
252#define	PCI_SUBCLASS_INPUT_GAMEPORT		0x04
253#define	PCI_SUBCLASS_INPUT_MISC			0x80
254
255/* 0x0a dock subclasses */
256#define	PCI_SUBCLASS_DOCK_GENERIC		0x00
257#define	PCI_SUBCLASS_DOCK_MISC			0x80
258
259/* 0x0b processor subclasses */
260#define	PCI_SUBCLASS_PROCESSOR_386		0x00
261#define	PCI_SUBCLASS_PROCESSOR_486		0x01
262#define	PCI_SUBCLASS_PROCESSOR_PENTIUM		0x02
263#define	PCI_SUBCLASS_PROCESSOR_ALPHA		0x10
264#define	PCI_SUBCLASS_PROCESSOR_POWERPC		0x20
265#define	PCI_SUBCLASS_PROCESSOR_MIPS		0x30
266#define	PCI_SUBCLASS_PROCESSOR_COPROC		0x40
267
268/* 0x0c serial bus subclasses */
269#define	PCI_SUBCLASS_SERIALBUS_FIREWIRE		0x00
270#define	PCI_SUBCLASS_SERIALBUS_ACCESS		0x01
271#define	PCI_SUBCLASS_SERIALBUS_SSA		0x02
272#define	PCI_SUBCLASS_SERIALBUS_USB		0x03
273#define	PCI_SUBCLASS_SERIALBUS_FIBER		0x04	/* XXX _FIBRECHANNEL */
274#define	PCI_SUBCLASS_SERIALBUS_SMBUS		0x05
275#define	PCI_SUBCLASS_SERIALBUS_INFINIBAND	0x06
276#define	PCI_SUBCLASS_SERIALBUS_IPMI		0x07
277#define	PCI_SUBCLASS_SERIALBUS_SERCOS		0x08
278#define	PCI_SUBCLASS_SERIALBUS_CANBUS		0x09
279
280/* 0x0d wireless subclasses */
281#define	PCI_SUBCLASS_WIRELESS_IRDA		0x00
282#define	PCI_SUBCLASS_WIRELESS_CONSUMERIR	0x01
283#define	PCI_SUBCLASS_WIRELESS_RF		0x10
284#define	PCI_SUBCLASS_WIRELESS_MISC		0x80
285
286/* 0x0e I2O (Intelligent I/O) subclasses */
287#define	PCI_SUBCLASS_I2O_STANDARD		0x00
288
289/* 0x0f satellite communication subclasses */
290/*	PCI_SUBCLASS_SATCOM_???			0x00	/ * XXX ??? */
291#define	PCI_SUBCLASS_SATCOM_TV			0x01
292#define	PCI_SUBCLASS_SATCOM_AUDIO		0x02
293#define	PCI_SUBCLASS_SATCOM_VOICE		0x03
294#define	PCI_SUBCLASS_SATCOM_DATA		0x04
295
296/* 0x10 encryption/decryption subclasses */
297#define	PCI_SUBCLASS_CRYPTO_NETCOMP		0x00
298#define	PCI_SUBCLASS_CRYPTO_ENTERTAINMENT	0x10
299#define	PCI_SUBCLASS_CRYPTO_MISC		0x80
300
301/* 0x11 data acquisition and signal processing subclasses */
302#define	PCI_SUBCLASS_DASP_DPIO			0x00
303#define PCI_SUBCLASS_DASP_TIMERFREQ		0x01
304#define	PCI_SUBCLASS_DASP_MISC			0x80
305
306/*
307 * PCI BIST/Header Type/Latency Timer/Cache Line Size Register.
308 */
309#define	PCI_BHLC_REG			0x0c
310
311#define	PCI_BIST_SHIFT				24
312#define	PCI_BIST_MASK				0xff
313#define	PCI_BIST(bhlcr) \
314	    (((bhlcr) >> PCI_BIST_SHIFT) & PCI_BIST_MASK)
315
316#define	PCI_HDRTYPE_SHIFT			16
317#define	PCI_HDRTYPE_MASK			0xff
318#define	PCI_HDRTYPE(bhlcr) \
319	    (((bhlcr) >> PCI_HDRTYPE_SHIFT) & PCI_HDRTYPE_MASK)
320
321#define	PCI_HDRTYPE_TYPE(bhlcr) \
322	    (PCI_HDRTYPE(bhlcr) & 0x7f)
323#define	PCI_HDRTYPE_MULTIFN(bhlcr) \
324	    ((PCI_HDRTYPE(bhlcr) & 0x80) != 0)
325
326#define	PCI_LATTIMER_SHIFT			8
327#define	PCI_LATTIMER_MASK			0xff
328#define	PCI_LATTIMER(bhlcr) \
329	    (((bhlcr) >> PCI_LATTIMER_SHIFT) & PCI_LATTIMER_MASK)
330#define	PCI_LATTIMER_SET(bhlcr,v) \
331	    (bhlcr) = ((bhlcr) & ~(PCI_LATTIMER_MASK << PCI_LATTIMER_SHIFT)) | \
332		((v) << PCI_LATTIMER_SHIFT)
333
334#define	PCI_CACHELINE_SHIFT			0
335#define	PCI_CACHELINE_MASK			0xff
336#define	PCI_CACHELINE(bhlcr) \
337	    (((bhlcr) >> PCI_CACHELINE_SHIFT) & PCI_CACHELINE_MASK)
338#define	PCI_CACHELINE_SET(bhlcr,v) \
339	    (bhlcr) = ((bhlcr) & ~(PCI_CACHELINE_MASK << PCI_CACHELINE_SHIFT)) | \
340		((v) << PCI_CACHELINE_SHIFT)
341
342/*
343 * The currently defined header types are
344 *    00h   prefix PCI_ below
345 *    01h   prefix PPB_ below (PCI-to-PCI bridges)
346 *    02h   prefix PCB_ below (Cardbus bridges)
347 */
348
349/*
350 * Type 00h Configuration Space extensions.
351 */
352
353/*
354 * Mapping registers
355 */
356#define	PCI_MAPREG_START		0x10
357#define	PCI_MAPREG_END			0x28
358
359#define	PCI_MAPREG_PPB_END		0x18
360#define PCI_MAPREG_PPB_ROM              0x38
361#define	PCI_MAPREG_PCB_END		0x14
362#define PCI_MAPREG_NONE                 0x00
363
364#define	PCI_MAPREG_TYPE(mr)						\
365	    ((mr) & PCI_MAPREG_TYPE_MASK)
366#define	PCI_MAPREG_TYPE_MASK			0x00000001
367
368#define	PCI_MAPREG_TYPE_MEM			0x00000000
369#define	PCI_MAPREG_TYPE_IO			0x00000001
370
371#define	PCI_MAPREG_MEM_TYPE(mr)						\
372	    ((mr) & PCI_MAPREG_MEM_TYPE_MASK)
373#define	PCI_MAPREG_MEM_TYPE_MASK		0x00000006
374
375#define	PCI_MAPREG_MEM_TYPE_32BIT		0x00000000
376#define	PCI_MAPREG_MEM_TYPE_32BIT_1M		0x00000002
377#define	PCI_MAPREG_MEM_TYPE_64BIT		0x00000004
378
379#define	PCI_MAPREG_MEM_PREFETCHABLE(mr)				\
380	    (((mr) & PCI_MAPREG_MEM_PREFETCHABLE_MASK) != 0)
381#define	PCI_MAPREG_MEM_PREFETCHABLE_MASK	0x00000008
382
383#define	PCI_MAPREG_MEM_ADDR(mr)						\
384	    ((mr) & PCI_MAPREG_MEM_ADDR_MASK)
385#define	PCI_MAPREG_MEM_SIZE(mr)						\
386	    (PCI_MAPREG_MEM_ADDR(mr) & -PCI_MAPREG_MEM_ADDR(mr))
387#define	PCI_MAPREG_MEM_ADDR_MASK		0xfffffff0
388
389#define	PCI_MAPREG_MEM64_ADDR(mr)					\
390	    ((mr) & PCI_MAPREG_MEM64_ADDR_MASK)
391#define	PCI_MAPREG_MEM64_SIZE(mr)					\
392	    (PCI_MAPREG_MEM64_ADDR(mr) & -PCI_MAPREG_MEM64_ADDR(mr))
393#define	PCI_MAPREG_MEM64_ADDR_MASK		0xfffffffffffffff0ULL
394
395#define	PCI_MAPREG_IO_ADDR(mr)						\
396	    ((mr) & PCI_MAPREG_IO_ADDR_MASK)
397#define	PCI_MAPREG_IO_SIZE(mr)						\
398	    (PCI_MAPREG_IO_ADDR(mr) & -PCI_MAPREG_IO_ADDR(mr))
399#define	PCI_MAPREG_IO_ADDR_MASK			0xfffffffc
400
401#define PCI_MAPREG_SIZE_TO_MASK(size)					\
402	    (-(size))
403
404#define PCI_MAPREG(num)                 (PCI_MAPREG_START + 4*(num))
405#define PCI_MAPREG_NUM(offset)						\
406	    (((unsigned)(offset)-PCI_MAPREG_START)/4)
407
408/*
409 * Cardbus CIS pointer (PCI rev. 2.1)
410 */
411#define PCI_CARDBUS_CIS_REG		0x28
412
413/*
414 * Subsystem identification register; contains a vendor ID and a device ID.
415 * Types/macros for PCI_ID_REG apply.
416 * (PCI rev. 2.1)
417 */
418#define PCI_SUBSYS_ID_REG 0x2c
419
420/*
421 * Expansion ROM base address register; contains an address and enable bit.
422 */
423#define	PCI_MAPREG_ROM			0x30
424#define PCI_MAPREG_ROM_ADDR(mr)                                         \
425	    ((mr) & PCI_MAPREG_ROM_ADDR_MASK)
426#define	PCI_MAPREG_ROM_ADDR_MASK		0xfffff800
427#define	PCI_MAPREG_ROM_ENABLE			0x00000001
428
429/*
430 * Capabilities list origin (PCI rev. 2.2)
431 */
432#define PCI_CAPLISTPTR_REG		0x34	/* header types 0,1 */
433#define PCB_CAPLISTPTR_REG		0x14	/* header type  2 */
434#define PCI_CAPLIST_PTR(cpr)			((cpr) & 0xff)
435
436/*
437 * Bus Parameter and Interrupt Configuration Register;
438 * contains interrupt pin and line.
439 */
440#define	PCI_BPARAM_INTERRUPT_REG	0x3c
441
442#define	PCI_BPARAM_LATENCY_SHIFT		24
443#define	PCI_BPARAM_LATENCY_MASK			0xff
444#define	PCI_BPARAM_LATENCY(bpir) \
445	    (((bpir) >> PCI_BPARAM_LATENCY_SHIFT) & PCI_BPARAM_LATENCY_MASK)
446
447#define	PCI_BPARAM_GRANT_SHIFT			16
448#define	PCI_BPARAM_GRANT_MASK			0xff
449#define	PCI_BPARAM_GRANT(bpir) \
450	    (((bpir) >> PCI_BPARAM_GRANT_SHIFT) & PCI_BPARAM_GRANT_MASK)
451
452#define	PCI_INTERRUPT_PIN_SHIFT			8
453#define	PCI_INTERRUPT_PIN_MASK			0xff
454#define	PCI_INTERRUPT_PIN(bpir) \
455	    (((bpir) >> PCI_INTERRUPT_PIN_SHIFT) & PCI_INTERRUPT_PIN_MASK)
456
457#define	PCI_INTERRUPT_LINE_SHIFT		0
458#define	PCI_INTERRUPT_LINE_MASK			0xff
459#define	PCI_INTERRUPT_LINE(bpir) \
460	    (((bpir) >> PCI_INTERRUPT_LINE_SHIFT) & PCI_INTERRUPT_LINE_MASK)
461
462#define	PCI_INTERRUPT_PIN_NONE			0x00
463#define	PCI_INTERRUPT_PIN_A			0x01
464#define	PCI_INTERRUPT_PIN_B			0x02
465#define	PCI_INTERRUPT_PIN_C			0x03
466#define	PCI_INTERRUPT_PIN_D			0x04
467#define	PCI_INTERRUPT_PIN_MAX			0x04
468
469
470/*
471 * Type 01h Configuration Space extension:
472 * PCI to PCI Bridge registers (cf ppbreg.h)
473 * Derived from information found in the ``PCI to PCI Bridge
474 * Architecture Specification, Revision 1.1, December 18, 1998.''
475 */
476
477#define	PPB_MAPREG_START		0x10
478#define	PPB_MAPREG_END			0x18
479
480/*
481 * Bus Information Register; contains bus hierarchy and secondary latency.
482 */
483#define PPB_BUSINFO_REG			0x18
484
485#define PPB_BUSINFO_LATENCY_SHIFT			24
486#define PPB_BUSINFO_LATENCY_MASK			0xff
487#define PPB_BUSINFO_LATENCY(br) \
488	    (((br) >> PPB_BUSINFO_LATENCY_SHIFT) & PPB_BUSINFO_LATENCY_MASK)
489
490#define PPB_BUSINFO_SUBORD_SHIFT			16
491#define PPB_BUSINFO_SUBORD_MASK				0xff
492#define PPB_BUSINFO_SUBORD(br) \
493	    (((br) >> PPB_BUSINFO_SUBORD_SHIFT) & PPB_BUSINFO_SUBORD_MASK)
494
495#define PPB_BUSINFO_SECONDARY_SHIFT			8
496#define PPB_BUSINFO_SECONDARY_MASK			0xff
497#define PPB_BUSINFO_SECONDARY(br) \
498	    (((br) >> PPB_BUSINFO_SECONDARY_SHIFT) & PPB_BUSINFO_SECONDARY_MASK)
499
500#define PPB_BUSINFO_PRIMARY_SHIFT			0
501#define PPB_BUSINFO_PRIMARY_MASK			0xff
502#define PPB_BUSINFO_PRIMARY(br) \
503	    (((br) >> PPB_BUSINFO_PRIMARY_SHIFT) & PPB_BUSINFO_PRIMARY_MASK)
504
505/*
506 * IO Status Register; contains I/O base + limit and secondary status.
507 * Masks/macros for PCI_STATUS apply to Secondary Status.
508 */
509#define	PPB_IO_STATUS_REG		0x1C
510
511#define PPB_IO_BASE_MASK			0x000000ff
512#define PPB_IO_LIMIT_MASK			0x0000ff00
513#define PPB_IO_ADDR_CAP_MASK    		0x00000f0f
514#define PPB_IO_ADDR_CAP_16      		0x00000000
515#define PPB_IO_ADDR_CAP_32      		0x00000101
516#define PPB_IO_BASE(iosr) \
517	    (((iosr) >> 0) & 0xff)
518#define PPB_IO_LIMIT(iosr) \
519	    (((iosr) >> 8) & 0xff)
520
521#define PPB_SECSTATUS_SHIFT			16
522#define PPB_SECSTATUS_MASK			0xffff
523#define PPB_SECSTATUS(iosr) \
524	    (((iosr) >> PPB_SECSTATUS_SHIFT) & PPB_SECSTATUS_MASK)
525
526/*
527 * Base and limit values for address ranges have common packing.
528 */
529#define PPB_BASE_SHIFT			0
530#define PPB_BASE_MASK			0xffff
531#define PPB_BASE(blr) \
532	    (((blr) >> PPB_BASE_SHIFT) & PPB_BASE_MASK)
533
534#define PPB_LIMIT_SHIFT			16
535#define PPB_LIMIT_MASK			0xffff
536#define PPB_LIMIT(blr) \
537	    (((blr) >> PPB_LIMIT_SHIFT) & PPB_LIMIT_MASK)
538
539/*
540 * Memory Registers; contains memory base + limit.
541 */
542#define	PPB_MEM_REG			0x20
543#define PPB_PREFMEM_REG			0x24
544
545#define PPB_MEM_BASE_MASK			0x0000ffff
546#define PPB_MEM_LIMIT_MASK			0xffff0000
547
548/*
549 * Prefetchable Memory Upper Registers; contain high bits
550 */
551#define PPB_PREFMEM_BASE_UPPER_REG	0x28
552#define PPB_PREFMEM_LIMIT_UPPER_REG	0x2c
553
554/*
555 * IO Upper Register; contains I/O base + limit high bits
556 */
557#define PPB_IO_UPPER_REG 		0x30
558
559#define PPB_IO_UPPER_BASE_MASK			0x0000ffff
560#define PPB_IO_UPPER_LIMIT_MASK			0xffff0000
561
562/*
563 * Expansion ROM Base Address Register.
564 */
565#define PPB_MAPREG_ROM			0x38
566
567/*
568 * Bridge Control and Interrupt Register
569 * Masks/macros for PCI_INTERRUPT apply to Interrupt
570 */
571#define PPB_BRCTL_INTERRUPT_REG		0x3C
572
573#define PPB_BRCTL_SHIFT			16
574#define PPB_BRCTL_MASK			0xffff
575#define PPB_BRCTL(bcir) \
576	    (((bcir) >> PPB_BRCTL_SHIFT) & PPB_BRCTL_MASK)
577
578#define PPB_BRCTL_PARITY_ENABLE			0x00010000
579#define PPB_BRCTL_SERR_ENABLE			0x00020000
580#define PPB_BRCTL_ISA_ENABLE			0x00040000
581#define PPB_BRCTL_VGA_ENABLE			0x00080000
582#define PPB_BRCTL_MASTER_ABORT_MODE		0x00200000
583#define PPB_BRCTL_SECONDARY_RESET		0x00400000
584#define PPB_BRCTL_BACKTOBACK_ENABLE		0x00800000
585#define PPB_BRCTL_PRIMARY_DISCARD_TIMER		0x01000000
586#define PPB_BRCTL_SECONDARY_DISCARD_TIMER	0x02000000
587#define PPB_BRCTL_DISCARD_TIMER_STATUS		0x04000000
588#define PPB_BRCTL_DISCARD_SERR_ENABLE		0x08000000
589
590
591/*
592 * Capabilities linked list (PCI rev. 2.2)
593 */
594#define PCI_CAPLIST_CAP(cr)	((cr) & 0xff)
595#define PCI_CAPLIST_NEXT(cr)	(((cr) >> 8) & 0xff)
596
597#define	PCI_CAP_RESERVED0	0x00
598#define	PCI_CAP_PWRMGMT		0x01
599#define	PCI_CAP_AGP		0x02
600#define	PCI_CAP_VPD		0x03
601#define	PCI_CAP_SLOTID		0x04
602#define	PCI_CAP_MSI		0x05
603#define	PCI_CAP_CPCI_HOTSWAP	0x06
604#define	PCI_CAP_PCIX		0x07
605#define	PCI_CAP_LDT		0x08
606#define	PCI_CAP_VENDSPEC	0x09
607#define	PCI_CAP_DEBUGPORT	0x0a
608#define	PCI_CAP_CPCI_RSRCCTL	0x0b
609#define	PCI_CAP_HOTPLUG		0x0c
610
611/*
612 * Power Management Control Status Register; access via capability pointer.
613 */
614#define PCI_PMCSR_STATE_MASK	                0x03
615#define PCI_PMCSR_STATE_D0                      0x00
616#define PCI_PMCSR_STATE_D1                      0x01
617#define PCI_PMCSR_STATE_D2                      0x02
618#define PCI_PMCSR_STATE_D3                      0x03
619
620/*
621 * Message Signaled Interrupt Capability
622 */
623#define PCI_MSICTL_OFF                  0x00
624#define PCI_MSICTL_64B                          0x00800000
625#define PCI_MSICTL_MM_ENABLE_SHIFT              (16+4)
626#define PCI_MSICTL_MM_ENABLE_MASK               0x00700000
627#define PCI_MSICTL_MM_CAP_SHIFT                 (16+1)
628#define PCI_MSICTL_MM_CAP_MASK                  0x000E0000
629#define PCI_MSICTL_ENABLE                       0x00010000
630
631#define PCI_MSIADDR_OFF                 0x04
632#define PCI_MSIADDR_HI_OFF              0x08
633
634#define PCI_MSIDATA32_OFF               0x08
635#define PCI_MSIDATA64_OFF               0x0C
636#define PCI_MSIDATA_SHIFT                       0
637#define PCI_MSIDATA_MASK                        0xFFFF
638
639#endif /* _DEV_PCI_PCIREG_H_ */
640