xref: /illumos-gate/usr/src/uts/sun4/io/px/px_lib.h (revision d1e631af56641f21cde1f1efe3a9623ff9d6ee7c)
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 (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23  */
24 
25 #ifndef	_SYS_PX_LIB_H
26 #define	_SYS_PX_LIB_H
27 
28 #ifdef	__cplusplus
29 extern "C" {
30 #endif
31 
32 /*
33  * Include all data structures and definitions in this file that are
34  * required between the common and hardware specific code.
35  */
36 
37 #define	DIP_TO_HANDLE(dip)	((px_t *)DIP_TO_STATE(dip))->px_dev_hdl
38 
39 /*
40  * The following macros define	the mmu page size and related operations.
41  */
42 #define	MMU_PAGE_SHIFT		13
43 #define	MMU_PAGE_SIZE		(1 << MMU_PAGE_SHIFT)
44 #define	MMU_PAGE_MASK		~(MMU_PAGE_SIZE - 1)
45 #define	MMU_PAGE_OFFSET		(MMU_PAGE_SIZE - 1)
46 #define	MMU_PTOB(x)		(((uint64_t)(x)) << MMU_PAGE_SHIFT)
47 #define	MMU_BTOP(x)		((x) >> MMU_PAGE_SHIFT)
48 #define	MMU_BTOPR(x)		MMU_BTOP((x) + MMU_PAGE_OFFSET)
49 
50 /* MMU map flags */
51 #define	MMU_MAP_PFN		1
52 #define	MMU_MAP_BUF		2
53 
54 typedef struct px px_t;
55 typedef struct px_msiq px_msiq_t;
56 
57 extern int px_lib_dev_init(dev_info_t *dip, devhandle_t *dev_hdl);
58 extern int px_lib_dev_fini(dev_info_t *dip);
59 extern int px_lib_map_vconfig(dev_info_t *dip, ddi_map_req_t *mp,
60     pci_config_offset_t off, pci_regspec_t *rp, caddr_t *addrp);
61 extern void px_lib_map_attr_check(ddi_map_req_t *mp);
62 
63 extern int px_lib_intr_devino_to_sysino(dev_info_t *dip, devino_t devino,
64     sysino_t *sysino);
65 extern int px_lib_intr_getvalid(dev_info_t *dip, sysino_t sysino,
66     intr_valid_state_t *intr_valid_state);
67 extern int px_lib_intr_setvalid(dev_info_t *dip, sysino_t sysino,
68     intr_valid_state_t intr_valid_state);
69 extern int px_lib_intr_getstate(dev_info_t *dip, sysino_t sysino,
70     intr_state_t *intr_state);
71 extern int px_lib_intr_setstate(dev_info_t *dip, sysino_t sysino,
72     intr_state_t intr_state);
73 extern int px_lib_intr_gettarget(dev_info_t *dip, sysino_t sysino,
74     cpuid_t *cpuid);
75 extern int px_lib_intr_settarget(dev_info_t *dip, sysino_t sysino,
76     cpuid_t cpuid);
77 extern int px_lib_intr_reset(dev_info_t *dip);
78 
79 #ifdef FMA
80 extern void px_fill_rc_status(px_fault_t *px_fault_p,
81     pciex_rc_error_regs_t *rc_status);
82 #endif
83 
84 extern int px_lib_iommu_map(dev_info_t *dip, tsbid_t tsbid, pages_t pages,
85     io_attributes_t attr, void *addr, size_t pfn_index, int flags);
86 extern int px_lib_iommu_demap(dev_info_t *dip, tsbid_t tsbid, pages_t pages);
87 extern int px_lib_iommu_getmap(dev_info_t *dip, tsbid_t tsbid,
88     io_attributes_t *attr_p, r_addr_t *r_addr_p);
89 extern int px_lib_dma_bypass_rngchk(dev_info_t *dip, ddi_dma_attr_t *attr_p,
90     uint64_t *lo_p, uint64_t *hi_p);
91 extern int px_lib_iommu_getbypass(dev_info_t *dip, r_addr_t ra,
92     io_attributes_t attr, io_addr_t *io_addr_p);
93 extern int px_lib_iommu_detach(px_t *px_p);
94 extern uint64_t px_lib_ro_bypass(dev_info_t *dip, io_attributes_t attr,
95     uint64_t io_addr);
96 extern int px_lib_dma_sync(dev_info_t *dip, dev_info_t *rdip,
97     ddi_dma_handle_t handle, off_t off, size_t len, uint_t cache_flags);
98 
99 /*
100  * MSIQ Functions:
101  */
102 extern int px_lib_msiq_init(dev_info_t *dip);
103 extern int px_lib_msiq_fini(dev_info_t *dip);
104 extern int px_lib_msiq_info(dev_info_t *dip, msiqid_t msiq_id,
105     r_addr_t *ra_p, uint_t *msiq_rec_cnt_p);
106 extern int px_lib_msiq_getvalid(dev_info_t *dip, msiqid_t msiq_id,
107     pci_msiq_valid_state_t *msiq_valid_state);
108 extern int px_lib_msiq_setvalid(dev_info_t *dip, msiqid_t msiq_id,
109     pci_msiq_valid_state_t msiq_valid_state);
110 extern int px_lib_msiq_getstate(dev_info_t *dip, msiqid_t msiq_id,
111     pci_msiq_state_t *msiq_state);
112 extern int px_lib_msiq_setstate(dev_info_t *dip, msiqid_t msiq_id,
113     pci_msiq_state_t msiq_state);
114 extern int px_lib_msiq_gethead(dev_info_t *dip, msiqid_t msiq_id,
115     msiqhead_t *msiq_head);
116 extern int px_lib_msiq_sethead(dev_info_t *dip, msiqid_t msiq_id,
117     msiqhead_t msiq_head);
118 extern int px_lib_msiq_gettail(dev_info_t *dip, msiqid_t msiq_id,
119     msiqtail_t *msiq_tail);
120 extern void px_lib_get_msiq_rec(dev_info_t *dip, msiqhead_t *msiq_head_p,
121     msiq_rec_t *msiq_rec_p);
122 extern void px_lib_clr_msiq_rec(dev_info_t *dip, msiqhead_t *msiq_head_p);
123 
124 /*
125  * MSI Functions:
126  */
127 extern int px_lib_msi_init(dev_info_t *dip);
128 extern int px_lib_msi_getmsiq(dev_info_t *dip, msinum_t msi_num,
129     msiqid_t *msiq_id);
130 extern int px_lib_msi_setmsiq(dev_info_t *dip, msinum_t msi_num,
131     msiqid_t msiq_id, msi_type_t msitype);
132 extern int px_lib_msi_getvalid(dev_info_t *dip, msinum_t msi_num,
133     pci_msi_valid_state_t *msi_valid_state);
134 extern int px_lib_msi_setvalid(dev_info_t *dip, msinum_t msi_num,
135     pci_msi_valid_state_t msi_valid_state);
136 extern int px_lib_msi_getstate(dev_info_t *dip, msinum_t msi_num,
137     pci_msi_state_t *msi_state);
138 extern int px_lib_msi_setstate(dev_info_t *dip, msinum_t msi_num,
139     pci_msi_state_t msi_state);
140 
141 /*
142  * MSG Functions:
143  */
144 extern int px_lib_msg_getmsiq(dev_info_t *dip, pcie_msg_type_t msg_type,
145     msiqid_t *msiq_id);
146 extern int px_lib_msg_setmsiq(dev_info_t *dip, pcie_msg_type_t msg_type,
147     msiqid_t msiq_id);
148 extern int px_lib_msg_getvalid(dev_info_t *dip, pcie_msg_type_t msg_type,
149     pcie_msg_valid_state_t *msg_valid_state);
150 extern int px_lib_msg_setvalid(dev_info_t *dip, pcie_msg_type_t msg_type,
151     pcie_msg_valid_state_t msg_valid_state);
152 
153 /*
154  * PM/CPR Functions:
155  */
156 extern int px_lib_suspend(dev_info_t *dip);
157 extern void px_lib_resume(dev_info_t *dip);
158 extern void px_cpr_add_callb(px_t *);
159 extern void px_cpr_rem_callb(px_t *);
160 extern int px_lib_pmctl(int cmd, px_t *px_p);
161 extern uint_t px_pmeq_intr(caddr_t arg);
162 
163 /*
164  * Common range property functions and definitions.
165  */
166 #define	PX_RANGE_PROP_MASK	0x7ff
167 extern uint64_t px_get_rng_parent_hi_mask(px_t *px_p);
168 
169 /*
170  * Peek and poke access ddi_ctlops helper functions
171  */
172 extern int px_lib_ctlops_poke(dev_info_t *dip, dev_info_t *rdip,
173     peekpoke_ctlops_t *in_args);
174 extern int px_lib_ctlops_peek(dev_info_t *dip, dev_info_t *rdip,
175     peekpoke_ctlops_t *in_args, void *result);
176 
177 /*
178  * Error handling functions
179  */
180 #define	PX_INTR_PAYLOAD_SIZE	8	/* 64 bit words */
181 typedef struct px_fault {
182 	dev_info_t	*px_fh_dip;
183 	sysino_t	px_fh_sysino;
184 	uint_t		(*px_err_func)(caddr_t px_fault);
185 	devino_t	px_intr_ino;
186 	uint64_t	px_intr_payload[PX_INTR_PAYLOAD_SIZE];
187 } px_fault_t;
188 
189 extern int px_err_add_intr(px_fault_t *px_fault_p);
190 extern void px_err_rem_intr(px_fault_t *px_fault_p);
191 extern int px_cb_add_intr(px_fault_t *);
192 extern void px_cb_rem_intr(px_fault_t *);
193 extern void px_panic_domain(px_t *px_p, pcie_req_id_t bdf);
194 
195 /*
196  * CPR callback
197  */
198 extern void px_cpr_add_callb(px_t *);
199 extern void px_cpr_rem_callb(px_t *);
200 
201 /*
202  * Hotplug functions
203  */
204 extern int px_lib_hotplug_init(dev_info_t *dip, void *regops);
205 extern void px_lib_hotplug_uninit(dev_info_t *dip);
206 extern void px_hp_intr_redist(px_t *px_p);
207 
208 extern boolean_t px_lib_is_in_drain_state(px_t *px_p);
209 extern pcie_req_id_t px_lib_get_bdf(px_t *px_p);
210 
211 extern int px_lib_get_root_complex_mps(px_t *px_p, dev_info_t *dip, int *mps);
212 extern int px_lib_set_root_complex_mps(px_t *px_p,  dev_info_t *dip, int mps);
213 
214 /*
215  * Config space access
216  */
217 extern uint64_t px_lib_get_cfgacc_base(dev_info_t *dip);
218 
219 /*
220  * PCI IOV SDIO functions
221  */
222 extern int px_lib_fabric_sync(dev_info_t *dip);
223 
224 #ifdef	__cplusplus
225 }
226 #endif
227 
228 #endif	/* _SYS_PX_LIB_H */
229