xref: /titanic_50/usr/src/uts/common/sys/pci_cap.h (revision 7eea693d6b672899726e75993fddc4e95b52647f)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_PCI_CAP_H
27 #define	_SYS_PCI_CAP_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 #define	PCI_CAP_XCFG_FLAG_SHIFT	31
36 #define	PCI_CAP_XCFG_FLAG	(1u << PCI_CAP_XCFG_FLAG_SHIFT)
37 
38 /* Function Prototypes */
39 int pci_xcap_locate(ddi_acc_handle_t h, uint16_t id, uint16_t *base_p);
40 int pci_lcap_locate(ddi_acc_handle_t h, uint8_t id, uint16_t *base_p);
41 
42 
43 /* Extract the lower 16 bits Extended CFG SPACE */
44 #define	PCI_CAP_XID_MASK		0xffff
45 
46 /* Extract the lower 8 bits Extended CFG SPACE */
47 #define	PCI_CAP_ID_MASK		0xff
48 
49 #define	PCI_CAP_XCFG_SPC(i) 	((i) ? (i) | PCI_CAP_XCFG_FLAG : 0)
50 
51 #ifdef DEBUG
52 #define	PCI_CAP_DBG		if (pci_cap_debug) printf
53 #else
54 #define PCI_CAP_DBG		_NOTE(CONSTANTCONDITION) if (0) printf
55 #endif /* DEBUG */
56 
57 /* 2's complement of -1, added here to ameliorate testing for invalid data */
58 #define	PCI_CAP_EINVAL8		0xff
59 #define	PCI_CAP_EINVAL16	0xffff
60 #define	PCI_CAP_EINVAL32	0xffffffff
61 
62 /*
63  * Supported Config Size Reads/Writes
64  */
65 
66 typedef enum {
67 	PCI_CAP_CFGSZ_8 	= 0,
68 	PCI_CAP_CFGSZ_16	= 1,
69 	PCI_CAP_CFGSZ_32	= 2
70 } pci_cap_config_size_t;
71 
72 /* Define Macros */
73 
74 #define	PCI_CAP_LOCATE(h, id, base_p) ((id) & PCI_CAP_XCFG_FLAG ? \
75 	pci_xcap_locate(h, (uint16_t)((id) & PCI_CAP_XID_MASK), base_p) : \
76 	pci_lcap_locate(h, (uint8_t)((id) & PCI_CAP_ID_MASK), base_p))
77 
78 #define	PCI_CAP_GET8(h, i, b, o) ((uint8_t) \
79 	pci_cap_get(h, PCI_CAP_CFGSZ_8, i, b, o))
80 #define	PCI_CAP_GET16(h, i, b, o) ((uint16_t) \
81 	pci_cap_get(h, PCI_CAP_CFGSZ_16, i, b, o))
82 #define	PCI_CAP_GET32(h, i, b, o) ((uint32_t) \
83 	pci_cap_get(h, PCI_CAP_CFGSZ_32, i, b, o))
84 
85 #define	PCI_CAP_PUT8(h, i, b, o, d) ((uint8_t) \
86 	pci_cap_put(h, PCI_CAP_CFGSZ_8, i, b, o, d))
87 #define	PCI_CAP_PUT16(h, i, b, o, d) ((uint16_t) \
88 	pci_cap_put(h, PCI_CAP_CFGSZ_16, i, b, o, d))
89 #define	PCI_CAP_PUT32(h, i, b, o, d) ((uint32_t) \
90 	pci_cap_put(h, PCI_CAP_CFGSZ_32, i, b, o, d))
91 
92 #define	PCI_XCAP_GET8(h, i, b, o) ((uint8_t) \
93 	pci_cap_get(h, PCI_CAP_CFGSZ_8, PCI_CAP_XCFG_SPC(i), b, o))
94 #define	PCI_XCAP_GET16(h, i, b, o) ((uint16_t) \
95 	pci_cap_get(h, PCI_CAP_CFGSZ_16, PCI_CAP_XCFG_SPC(i), b, o))
96 #define	PCI_XCAP_GET32(h, i, b, o) ((uint32_t) \
97 	pci_cap_get(h, PCI_CAP_CFGSZ_32, PCI_CAP_XCFG_SPC(i), b, o))
98 
99 #define	PCI_XCAP_PUT8(h, i, b, o, d) ((uint8_t) \
100 	pci_cap_put(h, PCI_CAP_CFGSZ_8, PCI_CAP_XCFG_SPC(i), b, o, d))
101 #define	PCI_XCAP_PUT16(h, i, b, o, d) ((uint16_t) \
102 	pci_cap_put(h, PCI_CAP_CFGSZ_16, PCI_CAP_XCFG_SPC(i), b, o, d))
103 #define	PCI_XCAP_PUT32(h, i, b, o, d) ((uint32_t) \
104 	pci_cap_put(h, PCI_CAP_CFGSZ_32, PCI_CAP_XCFG_SPC(i), b, o, d))
105 
106 
107 extern int pci_cap_probe(ddi_acc_handle_t h, uint16_t index,
108 		uint32_t *id_p, uint16_t *base_p);
109 
110 extern uint32_t pci_cap_get(ddi_acc_handle_t h, pci_cap_config_size_t size,
111 		uint32_t id, uint16_t base, uint16_t offset);
112 
113 extern int pci_cap_put(ddi_acc_handle_t h, pci_cap_config_size_t size,
114 		uint32_t id, uint16_t base, uint16_t offset, uint32_t data);
115 
116 extern int pci_cap_read(ddi_acc_handle_t h, uint32_t id, uint16_t base,
117 		uint32_t *buf_p, uint32_t nwords);
118 
119 #ifdef __cplusplus
120 }
121 #endif
122 
123 #endif	/* _SYS_PCI_CAP_H */
124