xref: /illumos-gate/usr/src/uts/common/sys/pci_cfgacc.h (revision c0da627439dfb642fb41ab7d78406fc69d2c64b2)
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 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_PCI_CFGACC_H
27 #define	_PCI_CFGACC_H
28 
29 #include <sys/dditypes.h>
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 #ifndef _ASM
36 
37 #define	PCI_GETBDF(b, d, f)	\
38 	((d != 0) ?		\
39 	((((uint16_t)b & 0xff) << 8) + (((uint8_t)d & 0x1f) << 3) + \
40 	((uint8_t)f & 0x7)) :	\
41 	((((uint16_t)b & 0xff) << 8) + ((uint8_t)f & 0xff)))
42 
43 typedef union pci_cfg_data {
44 	uint8_t b;
45 	uint16_t w;
46 	uint32_t dw;
47 	uint64_t qw;
48 } pci_cfg_data_t;
49 
50 typedef enum pci_config_size {
51 	PCI_CFG_SIZE_BYTE = 1,
52 	PCI_CFG_SIZE_WORD = 2,
53 	PCI_CFG_SIZE_DWORD = 4,
54 	PCI_CFG_SIZE_QWORD = 8
55 } pci_config_size_t;
56 
57 typedef struct pci_cfgacc_req {
58 	dev_info_t	*rcdip;
59 	uint16_t	bdf;
60 	uint16_t	offset;
61 	uint8_t		size;
62 	boolean_t	write;
63 	pci_cfg_data_t	value;
64 	boolean_t	ioacc;
65 } pci_cfgacc_req_t;
66 #define	VAL8(req)	((req)->value.b)
67 #define	VAL16(req)	((req)->value.w)
68 #define	VAL32(req)	((req)->value.dw)
69 #define	VAL64(req)	((req)->value.qw)
70 
71 extern uint8_t	pci_cfgacc_get8(dev_info_t *, uint16_t, uint16_t);
72 extern uint16_t	pci_cfgacc_get16(dev_info_t *, uint16_t, uint16_t);
73 extern uint32_t	pci_cfgacc_get32(dev_info_t *, uint16_t, uint16_t);
74 extern uint64_t	pci_cfgacc_get64(dev_info_t *, uint16_t, uint16_t);
75 extern void	pci_cfgacc_put8(dev_info_t *, uint16_t, uint16_t, uint8_t);
76 extern void	pci_cfgacc_put16(dev_info_t *, uint16_t, uint16_t, uint16_t);
77 extern void	pci_cfgacc_put32(dev_info_t *, uint16_t, uint16_t, uint32_t);
78 extern void	pci_cfgacc_put64(dev_info_t *, uint16_t, uint16_t, uint64_t);
79 extern void	pci_cfgacc_acc(pci_cfgacc_req_t *);
80 
81 #endif /* _ASM */
82 
83 #ifdef	__cplusplus
84 }
85 #endif
86 
87 #endif /* _PCI_CFGACC_H */
88