xref: /illumos-gate/usr/src/uts/common/sys/pci_cap.h (revision d4990cfc)
127255037Spjha /*
227255037Spjha  * CDDL HEADER START
327255037Spjha  *
427255037Spjha  * The contents of this file are subject to the terms of the
527255037Spjha  * Common Development and Distribution License (the "License").
627255037Spjha  * You may not use this file except in compliance with the License.
727255037Spjha  *
827255037Spjha  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
927255037Spjha  * or http://www.opensolaris.org/os/licensing.
1027255037Spjha  * See the License for the specific language governing permissions
1127255037Spjha  * and limitations under the License.
1227255037Spjha  *
1327255037Spjha  * When distributing Covered Code, include this CDDL HEADER in each
1427255037Spjha  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1527255037Spjha  * If applicable, add the following below this CDDL HEADER, with the
1627255037Spjha  * fields enclosed by brackets "[]" replaced with your own identifying
1727255037Spjha  * information: Portions Copyright [yyyy] [name of copyright owner]
1827255037Spjha  *
1927255037Spjha  * CDDL HEADER END
2027255037Spjha  */
2127255037Spjha /*
22cb7ea99dSJimmy Vetayases  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
2327255037Spjha  * Use is subject to license terms.
2427255037Spjha  */
2527255037Spjha 
2627255037Spjha #ifndef	_SYS_PCI_CAP_H
2727255037Spjha #define	_SYS_PCI_CAP_H
2827255037Spjha 
2927255037Spjha #ifdef __cplusplus
3027255037Spjha extern "C" {
3127255037Spjha #endif
3227255037Spjha 
3327255037Spjha #define	PCI_CAP_XCFG_FLAG_SHIFT	31
3427255037Spjha #define	PCI_CAP_XCFG_FLAG	(1u << PCI_CAP_XCFG_FLAG_SHIFT)
3527255037Spjha 
3627255037Spjha /* Function Prototypes */
3727255037Spjha int pci_xcap_locate(ddi_acc_handle_t h, uint16_t id, uint16_t *base_p);
3827255037Spjha int pci_lcap_locate(ddi_acc_handle_t h, uint8_t id, uint16_t *base_p);
39cb7ea99dSJimmy Vetayases int pci_htcap_locate(ddi_acc_handle_t h, uint16_t reg_mask, uint16_t reg_val,
40cb7ea99dSJimmy Vetayases     uint16_t *base_p);
4127255037Spjha 
4227255037Spjha 
4327255037Spjha /* Extract the lower 16 bits Extended CFG SPACE */
4427255037Spjha #define	PCI_CAP_XID_MASK		0xffff
4527255037Spjha 
4627255037Spjha /* Extract the lower 8 bits Extended CFG SPACE */
4727255037Spjha #define	PCI_CAP_ID_MASK		0xff
4827255037Spjha 
49*d4990cfcSHans Rosenfeld #define	PCI_CAP_XCFG_SPC(i)	((i) ? (i) | PCI_CAP_XCFG_FLAG : 0)
5027255037Spjha 
5127255037Spjha #ifdef DEBUG
5227255037Spjha #define	PCI_CAP_DBG		if (pci_cap_debug) printf
5327255037Spjha #else
5427255037Spjha #define PCI_CAP_DBG		_NOTE(CONSTANTCONDITION) if (0) printf
5527255037Spjha #endif /* DEBUG */
5627255037Spjha 
57dc5d169bSpjha /* 2's complement of -1, added here to ameliorate testing for invalid data */
58dc5d169bSpjha #define	PCI_CAP_EINVAL8		0xff
59dc5d169bSpjha #define	PCI_CAP_EINVAL16	0xffff
60dc5d169bSpjha #define	PCI_CAP_EINVAL32	0xffffffff
61dc5d169bSpjha 
6227255037Spjha /*
6327255037Spjha  * Supported Config Size Reads/Writes
6427255037Spjha  */
6527255037Spjha 
6627255037Spjha typedef enum {
67*d4990cfcSHans Rosenfeld 	PCI_CAP_CFGSZ_8		= 0,
6827255037Spjha 	PCI_CAP_CFGSZ_16	= 1,
6927255037Spjha 	PCI_CAP_CFGSZ_32	= 2
703c4226f9Spjha } pci_cap_config_size_t;
7127255037Spjha 
7227255037Spjha /* Define Macros */
7327255037Spjha 
7427255037Spjha #define	PCI_CAP_LOCATE(h, id, base_p) ((id) & PCI_CAP_XCFG_FLAG ? \
7527255037Spjha 	pci_xcap_locate(h, (uint16_t)((id) & PCI_CAP_XID_MASK), base_p) : \
7627255037Spjha 	pci_lcap_locate(h, (uint8_t)((id) & PCI_CAP_ID_MASK), base_p))
7727255037Spjha 
7827255037Spjha #define	PCI_CAP_GET8(h, i, b, o) ((uint8_t) \
7927255037Spjha 	pci_cap_get(h, PCI_CAP_CFGSZ_8, i, b, o))
8027255037Spjha #define	PCI_CAP_GET16(h, i, b, o) ((uint16_t) \
8127255037Spjha 	pci_cap_get(h, PCI_CAP_CFGSZ_16, i, b, o))
8227255037Spjha #define	PCI_CAP_GET32(h, i, b, o) ((uint32_t) \
8327255037Spjha 	pci_cap_get(h, PCI_CAP_CFGSZ_32, i, b, o))
8427255037Spjha 
85*d4990cfcSHans Rosenfeld #define	PCI_CAP_PUT8(h, i, b, o, d) \
86*d4990cfcSHans Rosenfeld 	pci_cap_put(h, PCI_CAP_CFGSZ_8, i, b, o, d)
87*d4990cfcSHans Rosenfeld #define	PCI_CAP_PUT16(h, i, b, o, d) \
88*d4990cfcSHans Rosenfeld 	pci_cap_put(h, PCI_CAP_CFGSZ_16, i, b, o, d)
89*d4990cfcSHans Rosenfeld #define	PCI_CAP_PUT32(h, i, b, o, d) \
90*d4990cfcSHans Rosenfeld 	pci_cap_put(h, PCI_CAP_CFGSZ_32, i, b, o, d)
9127255037Spjha 
9227255037Spjha #define	PCI_XCAP_GET8(h, i, b, o) ((uint8_t) \
9327255037Spjha 	pci_cap_get(h, PCI_CAP_CFGSZ_8, PCI_CAP_XCFG_SPC(i), b, o))
9427255037Spjha #define	PCI_XCAP_GET16(h, i, b, o) ((uint16_t) \
9527255037Spjha 	pci_cap_get(h, PCI_CAP_CFGSZ_16, PCI_CAP_XCFG_SPC(i), b, o))
9627255037Spjha #define	PCI_XCAP_GET32(h, i, b, o) ((uint32_t) \
9727255037Spjha 	pci_cap_get(h, PCI_CAP_CFGSZ_32, PCI_CAP_XCFG_SPC(i), b, o))
9827255037Spjha 
99*d4990cfcSHans Rosenfeld #define	PCI_XCAP_PUT8(h, i, b, o, d) \
100*d4990cfcSHans Rosenfeld 	pci_cap_put(h, PCI_CAP_CFGSZ_8, PCI_CAP_XCFG_SPC(i), b, o, d)
101*d4990cfcSHans Rosenfeld #define	PCI_XCAP_PUT16(h, i, b, o, d) \
102*d4990cfcSHans Rosenfeld 	pci_cap_put(h, PCI_CAP_CFGSZ_16, PCI_CAP_XCFG_SPC(i), b, o, d)
103*d4990cfcSHans Rosenfeld #define	PCI_XCAP_PUT32(h, i, b, o, d) \
104*d4990cfcSHans Rosenfeld 	pci_cap_put(h, PCI_CAP_CFGSZ_32, PCI_CAP_XCFG_SPC(i), b, o, d)
10527255037Spjha 
10627255037Spjha 
10727255037Spjha extern int pci_cap_probe(ddi_acc_handle_t h, uint16_t index,
10827255037Spjha 		uint32_t *id_p, uint16_t *base_p);
10927255037Spjha 
1103c4226f9Spjha extern uint32_t pci_cap_get(ddi_acc_handle_t h, pci_cap_config_size_t size,
11127255037Spjha 		uint32_t id, uint16_t base, uint16_t offset);
11227255037Spjha 
1133c4226f9Spjha extern int pci_cap_put(ddi_acc_handle_t h, pci_cap_config_size_t size,
11427255037Spjha 		uint32_t id, uint16_t base, uint16_t offset, uint32_t data);
11527255037Spjha 
11627255037Spjha extern int pci_cap_read(ddi_acc_handle_t h, uint32_t id, uint16_t base,
11727255037Spjha 		uint32_t *buf_p, uint32_t nwords);
11827255037Spjha 
11927255037Spjha #ifdef __cplusplus
12027255037Spjha }
12127255037Spjha #endif
12227255037Spjha 
12327255037Spjha #endif	/* _SYS_PCI_CAP_H */
124