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.
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.
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]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #ifndef _SYS_PCI_CAP_H
27 #define _SYS_PCI_CAP_H
33 #define PCI_CAP_XCFG_FLAG_SHIFT 31
34 #define PCI_CAP_XCFG_FLAG (1u << PCI_CAP_XCFG_FLAG_SHIFT)
36 /* Function Prototypes */
37 int pci_xcap_locate(ddi_acc_handle_t h
, uint16_t id
, uint16_t *base_p
);
38 int pci_lcap_locate(ddi_acc_handle_t h
, uint8_t id
, uint16_t *base_p
);
39 int pci_htcap_locate(ddi_acc_handle_t h
, uint16_t reg_mask
, uint16_t reg_val
,
43 /* Extract the lower 16 bits Extended CFG SPACE */
44 #define PCI_CAP_XID_MASK 0xffff
46 /* Extract the lower 8 bits Extended CFG SPACE */
47 #define PCI_CAP_ID_MASK 0xff
49 #define PCI_CAP_XCFG_SPC(i) ((i) ? (i) | PCI_CAP_XCFG_FLAG : 0)
52 #define PCI_CAP_DBG if (pci_cap_debug) printf
54 #define PCI_CAP_DBG _NOTE(CONSTANTCONDITION) if (0) printf
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
63 * Supported Config Size Reads/Writes
70 } pci_cap_config_size_t
;
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))
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))
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))
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))
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))
107 extern int pci_cap_probe(ddi_acc_handle_t h
, uint16_t index
,
108 uint32_t *id_p
, uint16_t *base_p
);
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
);
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
);
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
);
123 #endif /* _SYS_PCI_CAP_H */