xref: /onnv-gate/usr/src/uts/common/sys/pci_cfgacc.h (revision 11245:28613b254aad)
1*11245SZhijun.Fu@Sun.COM /*
2*11245SZhijun.Fu@Sun.COM  * CDDL HEADER START
3*11245SZhijun.Fu@Sun.COM  *
4*11245SZhijun.Fu@Sun.COM  * The contents of this file are subject to the terms of the
5*11245SZhijun.Fu@Sun.COM  * Common Development and Distribution License (the "License").
6*11245SZhijun.Fu@Sun.COM  * You may not use this file except in compliance with the License.
7*11245SZhijun.Fu@Sun.COM  *
8*11245SZhijun.Fu@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*11245SZhijun.Fu@Sun.COM  * or http://www.opensolaris.org/os/licensing.
10*11245SZhijun.Fu@Sun.COM  * See the License for the specific language governing permissions
11*11245SZhijun.Fu@Sun.COM  * and limitations under the License.
12*11245SZhijun.Fu@Sun.COM  *
13*11245SZhijun.Fu@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
14*11245SZhijun.Fu@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*11245SZhijun.Fu@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
16*11245SZhijun.Fu@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
17*11245SZhijun.Fu@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
18*11245SZhijun.Fu@Sun.COM  *
19*11245SZhijun.Fu@Sun.COM  * CDDL HEADER END
20*11245SZhijun.Fu@Sun.COM  */
21*11245SZhijun.Fu@Sun.COM /*
22*11245SZhijun.Fu@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23*11245SZhijun.Fu@Sun.COM  * Use is subject to license terms.
24*11245SZhijun.Fu@Sun.COM  */
25*11245SZhijun.Fu@Sun.COM 
26*11245SZhijun.Fu@Sun.COM #ifndef	_PCI_CFGACC_H
27*11245SZhijun.Fu@Sun.COM #define	_PCI_CFGACC_H
28*11245SZhijun.Fu@Sun.COM 
29*11245SZhijun.Fu@Sun.COM #include <sys/dditypes.h>
30*11245SZhijun.Fu@Sun.COM 
31*11245SZhijun.Fu@Sun.COM #ifdef	__cplusplus
32*11245SZhijun.Fu@Sun.COM extern "C" {
33*11245SZhijun.Fu@Sun.COM #endif
34*11245SZhijun.Fu@Sun.COM 
35*11245SZhijun.Fu@Sun.COM #ifndef _ASM
36*11245SZhijun.Fu@Sun.COM 
37*11245SZhijun.Fu@Sun.COM #define	PCI_GETBDF(b, d, f)	\
38*11245SZhijun.Fu@Sun.COM 	((d != 0) ?		\
39*11245SZhijun.Fu@Sun.COM 	((((uint16_t)b & 0xff) << 8) + (((uint8_t)d & 0x1f) << 3) + \
40*11245SZhijun.Fu@Sun.COM 	((uint8_t)f & 0x7)) :	\
41*11245SZhijun.Fu@Sun.COM 	((((uint16_t)b & 0xff) << 8) + ((uint8_t)f & 0xff)))
42*11245SZhijun.Fu@Sun.COM 
43*11245SZhijun.Fu@Sun.COM typedef union pci_cfg_data {
44*11245SZhijun.Fu@Sun.COM 	uint8_t b;
45*11245SZhijun.Fu@Sun.COM 	uint16_t w;
46*11245SZhijun.Fu@Sun.COM 	uint32_t dw;
47*11245SZhijun.Fu@Sun.COM 	uint64_t qw;
48*11245SZhijun.Fu@Sun.COM } pci_cfg_data_t;
49*11245SZhijun.Fu@Sun.COM 
50*11245SZhijun.Fu@Sun.COM typedef enum pci_config_size {
51*11245SZhijun.Fu@Sun.COM 	PCI_CFG_SIZE_BYTE = 1,
52*11245SZhijun.Fu@Sun.COM 	PCI_CFG_SIZE_WORD = 2,
53*11245SZhijun.Fu@Sun.COM 	PCI_CFG_SIZE_DWORD = 4,
54*11245SZhijun.Fu@Sun.COM 	PCI_CFG_SIZE_QWORD = 8
55*11245SZhijun.Fu@Sun.COM } pci_config_size_t;
56*11245SZhijun.Fu@Sun.COM 
57*11245SZhijun.Fu@Sun.COM typedef struct pci_cfgacc_req {
58*11245SZhijun.Fu@Sun.COM 	dev_info_t	*rcdip;
59*11245SZhijun.Fu@Sun.COM 	uint16_t	bdf;
60*11245SZhijun.Fu@Sun.COM 	uint16_t	offset;
61*11245SZhijun.Fu@Sun.COM 	uint8_t		size;
62*11245SZhijun.Fu@Sun.COM 	boolean_t	write;
63*11245SZhijun.Fu@Sun.COM 	pci_cfg_data_t	value;
64*11245SZhijun.Fu@Sun.COM 	boolean_t	ioacc;
65*11245SZhijun.Fu@Sun.COM } pci_cfgacc_req_t;
66*11245SZhijun.Fu@Sun.COM #define	VAL8(req)	((req)->value.b)
67*11245SZhijun.Fu@Sun.COM #define	VAL16(req)	((req)->value.w)
68*11245SZhijun.Fu@Sun.COM #define	VAL32(req)	((req)->value.dw)
69*11245SZhijun.Fu@Sun.COM #define	VAL64(req)	((req)->value.qw)
70*11245SZhijun.Fu@Sun.COM 
71*11245SZhijun.Fu@Sun.COM extern uint8_t	pci_cfgacc_get8(dev_info_t *, uint16_t, uint16_t);
72*11245SZhijun.Fu@Sun.COM extern uint16_t	pci_cfgacc_get16(dev_info_t *, uint16_t, uint16_t);
73*11245SZhijun.Fu@Sun.COM extern uint32_t	pci_cfgacc_get32(dev_info_t *, uint16_t, uint16_t);
74*11245SZhijun.Fu@Sun.COM extern uint64_t	pci_cfgacc_get64(dev_info_t *, uint16_t, uint16_t);
75*11245SZhijun.Fu@Sun.COM extern void	pci_cfgacc_put8(dev_info_t *, uint16_t, uint16_t, uint8_t);
76*11245SZhijun.Fu@Sun.COM extern void	pci_cfgacc_put16(dev_info_t *, uint16_t, uint16_t, uint16_t);
77*11245SZhijun.Fu@Sun.COM extern void	pci_cfgacc_put32(dev_info_t *, uint16_t, uint16_t, uint32_t);
78*11245SZhijun.Fu@Sun.COM extern void	pci_cfgacc_put64(dev_info_t *, uint16_t, uint16_t, uint64_t);
79*11245SZhijun.Fu@Sun.COM extern void	pci_cfgacc_acc(pci_cfgacc_req_t *);
80*11245SZhijun.Fu@Sun.COM 
81*11245SZhijun.Fu@Sun.COM #endif /* _ASM */
82*11245SZhijun.Fu@Sun.COM 
83*11245SZhijun.Fu@Sun.COM #ifdef	__cplusplus
84*11245SZhijun.Fu@Sun.COM }
85*11245SZhijun.Fu@Sun.COM #endif
86*11245SZhijun.Fu@Sun.COM 
87*11245SZhijun.Fu@Sun.COM #endif /* _PCI_CFGACC_H */
88