xref: /illumos-gate/usr/src/uts/i86pc/io/pci/pci_common.h (revision ddb365bfc9e868ad24ccdcb0dc91af18b10df082)
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 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright 2019 Joyent, Inc.
27  */
28 
29 #ifndef	_PCI_PCI_COMMON_H
30 #define	_PCI_PCI_COMMON_H
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 /*
37  *	Common header file with definitions shared between
38  *	pci(4D) and npe(4D)
39  */
40 
41 /* State structure. */
42 typedef struct pci_state {
43 	dev_info_t *pci_dip;
44 	int pci_fmcap;
45 	uint_t pci_soft_state;
46 	ddi_iblock_cookie_t pci_fm_ibc;
47 	kmutex_t pci_mutex;
48 	kmutex_t pci_peek_poke_mutex;
49 	kmutex_t pci_err_mutex;
50 
51 	/*
52 	 * The following members are only used by npe(4D).
53 	 * See uts/i86pc/io/pciex/npe.c for more information.
54 	 */
55 	ndi_event_hdl_t pci_ndi_event_hdl;
56 } pci_state_t;
57 
58 /*
59  * These are the access routines.
60  * The pci_bus_map sets the handle to point to these in pci(4D).
61  * The npe_bus_map sets the handle to point to these in npe(4D).
62  */
63 uint8_t		pci_config_rd8(ddi_acc_impl_t *hdlp, uint8_t *addr);
64 uint16_t	pci_config_rd16(ddi_acc_impl_t *hdlp, uint16_t *addr);
65 uint32_t	pci_config_rd32(ddi_acc_impl_t *hdlp, uint32_t *addr);
66 uint64_t	pci_config_rd64(ddi_acc_impl_t *hdlp, uint64_t *addr);
67 
68 void		pci_config_wr8(ddi_acc_impl_t *hdlp, uint8_t *addr,
69 		    uint8_t value);
70 void		pci_config_wr16(ddi_acc_impl_t *hdlp, uint16_t *addr,
71 		    uint16_t value);
72 void		pci_config_wr32(ddi_acc_impl_t *hdlp, uint32_t *addr,
73 		    uint32_t value);
74 void		pci_config_wr64(ddi_acc_impl_t *hdlp, uint64_t *addr,
75 		    uint64_t value);
76 
77 void		pci_config_rep_rd8(ddi_acc_impl_t *hdlp, uint8_t *host_addr,
78 		    uint8_t *dev_addr, size_t repcount, uint_t flags);
79 void		pci_config_rep_rd16(ddi_acc_impl_t *hdlp, uint16_t *host_addr,
80 		    uint16_t *dev_addr, size_t repcount, uint_t flags);
81 void		pci_config_rep_rd32(ddi_acc_impl_t *hdlp, uint32_t *host_addr,
82 		    uint32_t *dev_addr, size_t repcount, uint_t flags);
83 void		pci_config_rep_rd64(ddi_acc_impl_t *hdlp, uint64_t *host_addr,
84 		    uint64_t *dev_addr, size_t repcount, uint_t flags);
85 
86 void		pci_config_rep_wr8(ddi_acc_impl_t *hdlp, uint8_t *host_addr,
87 		    uint8_t *dev_addr, size_t repcount, uint_t flags);
88 void		pci_config_rep_wr16(ddi_acc_impl_t *hdlp, uint16_t *host_addr,
89 		    uint16_t *dev_addr, size_t repcount, uint_t flags);
90 void		pci_config_rep_wr32(ddi_acc_impl_t *hdlp, uint32_t *host_addr,
91 		    uint32_t *dev_addr, size_t repcount, uint_t flags);
92 void		pci_config_rep_wr64(ddi_acc_impl_t *hdlp, uint64_t *host_addr,
93 		    uint64_t *dev_addr, size_t repcount, uint_t flags);
94 
95 /*
96  * PCI tool related declarations
97  */
98 int	pci_common_ioctl(dev_info_t *dip, dev_t dev, int cmd,
99 	    intptr_t arg, int mode, cred_t *credp, int *rvalp);
100 
101 /*
102  * Interrupt related declaration
103  */
104 int	pci_common_intr_ops(dev_info_t *, dev_info_t *, ddi_intr_op_t,
105 	    ddi_intr_handle_impl_t *, void *);
106 void	pci_common_set_parent_private_data(dev_info_t *);
107 
108 /*
109  * Miscellaneous library functions
110  */
111 int	pci_common_get_reg_prop(dev_info_t *dip, pci_regspec_t *pci_rp);
112 int	pci_common_name_child(dev_info_t *child, char *name, int namelen);
113 int	pci_common_peekpoke(dev_info_t *dip, dev_info_t *rdip,
114 	ddi_ctl_enum_t ctlop, void *arg, void *result);
115 int	pci_fm_acc_setup(ddi_acc_hdl_t *hp, off_t offset, off_t len);
116 
117 #ifdef	__cplusplus
118 }
119 #endif
120 
121 #endif	/* _PCI_PCI_COMMON_H */
122