xref: /titanic_44/usr/src/uts/sun4u/sys/zulumod.h (revision 9df12a23948bd40cbe37ce88d84e272c3894e675)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_ZULUMOD_H
28 #define	_ZULUMOD_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #include <sys/int_const.h>
37 #include <sys/zuluvm.h>
38 
39 #ifndef _ASM
40 
41 #include <sys/zulu_hat.h>
42 #include <sys/sysmacros.h>
43 
44 #define	ZULUVM_VERSION_STR(a)	#a
45 #define	ZULUVM_VERSION(a)	ZULUVM_VERSION_STR(a)
46 #define	ZULUVM_MOD_VERSION \
47 	ZULUVM_VERSION(XHAT_PROVIDER_VERSION) "." \
48 	ZULUVM_VERSION(ZULUVM_INTERFACE_VERSION)
49 
50 #define	ZULUDCHKFUNC(_p1, _p2, _p3) \
51 	((_p1) != NULL && (_p1)->_p2 != NULL) ? \
52 	(_p1)->_p2 _p3 : ZULUVM_NO_SUPPORT
53 #define	ZULUDCHKPROC(_p1, _p2, _p3) \
54 	if ((_p1) != NULL && (_p1)->_p2 != NULL) (_p1)->_p2 _p3
55 
56 #define	zulud_set_itlb_pc(_devp, _a, _b) \
57 	ZULUDCHKPROC((_devp)->dops, set_itlb_pc, (_a, _b))
58 #define	zulud_set_dtlb_pc(_devp, _a, _b) \
59 	ZULUDCHKPROC((_devp)->dops, set_dtlb_pc, (_a, _b))
60 #define	zulud_write_tte(_devp, _a, _b, _c, _d, _e, _f) \
61 	ZULUDCHKFUNC((_devp)->dops, write_tte, (_a, _b, _c, _d, _e, _f))
62 #define	zulud_tlb_done(_devp, _a, _b, _c) \
63 	ZULUDCHKPROC((_devp)->dops, tlb_done, (_a, _b, _c))
64 #define	zulud_demap_page(_devp, _a, _b, _c) \
65 	ZULUDCHKPROC((_devp)->dops, demap_page, (_a, _b, _c))
66 #define	zulud_demap_ctx(_devp, _a, _b) \
67 	ZULUDCHKPROC((_devp)->dops, demap_ctx, (_a, _b))
68 
69 #endif
70 
71 #define	ZULUVM_DATA0_IDX	0
72 #define	ZULUVM_DATA1_IDX	1
73 #define	ZULUVM_DATA2_IDX	2
74 #define	ZULUVM_DATA3_IDX	3
75 #define	ZULUVM_DATA4_IDX	4
76 #define	ZULUVM_DATA5_IDX	5
77 #define	ZULUVM_DATA6_IDX	6
78 #define	ZULUVM_DATA7_IDX	7
79 
80 #define	ZULUVM_IDX2FLAG(i)	(1 << (7 - i))
81 #define	ZULUVM_DATA0_FLAG	ZULUVM_IDX2FLAG(ZULUVM_DATA0_IDX)
82 #define	ZULUVM_DATA1_FLAG	ZULUVM_IDX2FLAG(ZULUVM_DATA1_IDX)
83 #define	ZULUVM_DATA2_FLAG	ZULUVM_IDX2FLAG(ZULUVM_DATA2_IDX)
84 #define	ZULUVM_DATA3_FLAG	ZULUVM_IDX2FLAG(ZULUVM_DATA3_IDX)
85 #define	ZULUVM_DATA4_FLAG	ZULUVM_IDX2FLAG(ZULUVM_DATA4_IDX)
86 #define	ZULUVM_DATA5_FLAG	ZULUVM_IDX2FLAG(ZULUVM_DATA5_IDX)
87 #define	ZULUVM_DATA6_FLAG	ZULUVM_IDX2FLAG(ZULUVM_DATA6_IDX)
88 #define	ZULUVM_DATA7_FLAG	ZULUVM_IDX2FLAG(ZULUVM_DATA7_IDX)
89 
90 #define	ZULUVM_TLB_ADDR_IDX	ZULUVM_DATA0_IDX
91 #define	ZULUVM_TLB_TYPE_IDX	ZULUVM_DATA1_IDX
92 #define	ZULUVM_TLB_TTE_IDX	ZULUVM_DATA2_IDX
93 #define	ZULUVM_TLB_ERRCODE_IDX	ZULUVM_DATA3_IDX
94 
95 #define	ZULUVM_DATA_FLAGS	(ZULUVM_DATA1_FLAG | \
96 				ZULUVM_DATA6_FLAG)
97 
98 #define	ZULUVM_GET_TLB_TTE(devp) \
99 		(devp)->zvm.idata[ZULUVM_TLB_TTE_IDX]
100 #define	ZULUVM_GET_TLB_ADDR(devp) \
101 		(devp)->zvm.idata[ZULUVM_TLB_ADDR_IDX]
102 #define	ZULUVM_GET_TLB_TYPE(devp) (ZULUVM_DMA_MASK & \
103 		(devp)->zvm.idata[ZULUVM_TLB_TYPE_IDX])
104 #define	ZULUVM_GET_TLB_ERRCODE(devp) (int)(0xffffffff & \
105 		(devp)->zvm.idata[ZULUVM_TLB_ERRCODE_IDX])
106 
107 #define	ZULUVM_MAX_DEV		2
108 #define	ZULUVM_PIL		PIL_2
109 #define	ZULUVM_NUM_PGSZS	4
110 
111 #define	ZULUVM_STATE_IDLE		0
112 #define	ZULUVM_STATE_STOPPED		1
113 #define	ZULUVM_STATE_CANCELED		2
114 #define	ZULUVM_STATE_TLB_PENDING	3
115 #define	ZULUVM_STATE_INTR_QUEUED	4
116 #define	ZULUVM_STATE_INTR_PENDING	5
117 #define	ZULUVM_STATE_WRITE_TTE		6
118 
119 #ifndef _ASM
120 
121 typedef struct {
122 	uint64_t	idata[4];	/* mondo pkt copy area */
123 	void		*arg;		/* arg for device calls */
124 	uint64_t	mmu_pa;		/* phy. addr of MMU regs */
125 	struct zuluvm_proc *proc1;
126 	struct zuluvm_proc *proc2;
127 	volatile uint32_t state;	/* state of tlb miss handling */
128 	short		intr_num;	/* our soft intr number */
129 	short		dmv_intr;	/* dmv interrupt handle */
130 #ifdef ZULUVM_STATS
131 	int 		cancel;
132 	int		tlb_miss[ZULUVM_NUM_PGSZS];
133 	int		pagefault;
134 	int		no_mapping;
135 	int		preload;
136 	int		migrate;
137 	int		pagesize;
138 	int		itlb1miss;
139 	int		dtlb1miss;
140 	int		itlb2miss;
141 	int		dtlb2miss;
142 	int		demap_page;
143 	int		demap_ctx;
144 #endif
145 	uint64_t	pfnbuf[50];
146 	int		pfncnt;
147 } zuluvm_miss_t;
148 
149 #ifdef ZULUVM_STATS
150 #define	ZULUVM_STATS_MISS(devp, sz)	(devp)->zvm.tlb_miss[sz]++
151 #define	ZULUVM_STATS_PAGEFAULT(devp)	(devp)->zvm.pagefault++
152 #define	ZULUVM_STATS_NOMAP(devp)	(devp)->zvm.no_mapping++
153 #define	ZULUVM_STATS_PRELOAD(devp)	(devp)->zvm.preload++
154 #define	ZULUVM_STATS_MIGRATE(devp)	(devp)->zvm.migrate++
155 #define	ZULUVM_STATS_PAGEZISE(devp)	(devp)->zvm.pagesize++
156 #define	ZULUVM_STATS_CANCEL(devp)	(devp)->zvm.cancel++
157 #define	ZULUVM_STATS_DEMAP_PAGE(devp)	(devp)->zvm.demap_page++
158 #define	ZULUVM_STATS_DEMAP_CTX(devp)	(devp)->zvm.demap_ctx++
159 #else
160 #define	ZULUVM_STATS_MISS(devp, sz)
161 #define	ZULUVM_STATS_PAGEFAULT(devp)
162 #define	ZULUVM_STATS_NOMAP(devp)
163 #define	ZULUVM_STATS_PRELOAD(devp)
164 #define	ZULUVM_STATS_MIGRATE(devp)
165 #define	ZULUVM_STATS_PAGEZISE(devp)
166 #define	ZULUVM_STATS_CANCEL(devp)
167 #define	ZULUVM_STATS_DEMAP_PAGE(devp)
168 #define	ZULUVM_STATS_DEMAP_CTX(devp)
169 #endif
170 
171 #define	ZULUVM_MAX_INTR 32
172 
173 typedef struct {
174 	short offset;
175 	short ino;
176 } zuluvm_intr_t;
177 
178 /*
179  * This structure contains per device data.
180  * It is protected by dev_lck.
181  */
182 typedef struct {
183 	zuluvm_miss_t		zvm;		/* tlb miss state */
184 	volatile uint64_t	*imr;		/* intr mapping regs */
185 	struct zuluvm_proc 	*procs; 	/* protected by proc_lck */
186 	dev_info_t		*dip;		/* device driver instance */
187 	zulud_ops_t		*dops;		/* device drv operations */
188 	kmutex_t		load_lck;	/* protects in_intr */
189 	kmutex_t		dev_lck;	/* protects this struct */
190 	kmutex_t 		proc_lck;	/* protects active procs */
191 	kcondvar_t 		intr_wait;	/* sync for as_free */
192 	int			intr_flags;
193 	int			in_intr;
194 	kmutex_t		park_lck;	/* page fault thread */
195 	kcondvar_t		park_cv;
196 	int			parking;
197 	int			agentid;	/* zulu's agent id */
198 	zuluvm_intr_t		interrupts[ZULUVM_MAX_INTR];
199 } zuluvm_state_t;
200 
201 #define	ZULUVM_INTR_OFFSET	offsetof(zuluvm_state_t, interrupts)
202 #define	ZULUVM_INTR2INO(addr)	(((zuluvm_intr_t *)(addr))->ino)
203 #define	ZULUVM_INTR2ZDEV(addr) \
204 	(zuluvm_state_t *)((caddr_t)addr - (ZULUVM_INTR2INO(addr) * \
205 	sizeof (zuluvm_intr_t)) - ZULUVM_INTR_OFFSET)
206 
207 typedef struct zuluvm_proc {
208 	struct zulu_hat	*zhat;
209 	zuluvm_state_t  *zdev;  /* back ptr to dev instance */
210 	unsigned short	refcnt;	/* keep this until ref == 0 */
211 	short		valid;	/* if valid is 0 then don't use */
212 	struct zuluvm_proc *next;
213 	struct zuluvm_proc *prev;
214 } zuluvm_proc_t;
215 
216 #define	ZULUVM_DO_INTR1		INT32_C(1)
217 #define	ZULUVM_WAIT_INTR1	INT32_C(2)
218 #define	ZULUVM_DO_INTR2		INT32_C(4)
219 #define	ZULUVM_WAIT_INTR2	INT32_C(8)
220 
221 int zuluvm_change_state(uint32_t *state_pa, int new, int assume);
222 void zuluvm_demap_page(void *, struct hat *, short, caddr_t, uint_t);
223 void zuluvm_demap_ctx(void *, short);
224 void zuluvm_dmv_tlbmiss_tl1(void);
225 void zuluvm_load_tte(struct zulu_hat *zhat, caddr_t addr, uint64_t pfn,
226 		int perm, int size);
227 
228 
229 #endif
230 
231 /*
232  * The following defines are copied from the ZFB and ZULU
233  * workspaces. We re-define them here since we can't have
234  * a dependency onto files outside our consolidation
235  */
236 #define	ZULUVM_IMR_V_MASK	UINT64_C(0x0000000080000000)
237 #define	ZULUVM_IMR_TARGET_SHIFT INT32_C(26)
238 #define	ZULUVM_IMR_MAX		INT32_C(0x3f)
239 
240 #define	ZULUVM_ZFB_MMU_TLB_D_V_MASK	  0x8000000000000000
241 #define	ZULUVM_ZFB_MMU_TLB_D_PA_SHIFT	  0xD	/* 13 bits */
242 #define	ZULUVM_ZFB_MMU_TLB_D_C_MASK	  0x20
243 #define	ZULUVM_ZFB_MMU_TLB_D_SZ_SHIFT	  0x3D	/* 61 */
244 #define	ZULUVM_ZFB_MMU_TLB_D_SZ_MASK	  0x6000000000000000
245 #define	ZULUVM_ZFB_MMU_TLB_D_W_MASK	  0x2
246 #define	ZULUVM_ZFB_MMU_TLB_CR_IMISS_MASK  0x2
247 #define	ZULUVM_ZFB_MMU_TLB_CR_DMISS_MASK  0x1
248 #define	ZULUVM_ZFB_MMU_DTLB_PAGE_SZ_2_MASK  0xc /* DTLB2 Page size */
249 #define	ZULUVM_ZFB_MMU_DTLB_PAGE_SZ_2_SHIFT 2
250 #define	ZULUVM_DTLB_PAGE_SZ	0x8
251 #define	ZULUVM_ITLB_DATA_IN	0x18
252 #define	ZULUVM_DTLB_DATA_IN	0x28
253 #define	ZULUVM_TLB_CONTROL	0
254 #define	ZULUVM_ITLB_MISS_ICR	0x0
255 #define	ZULUVM_DTLB_MISS_ICR	0x8
256 #define	ZULUVM_DMA1_TSB_BASE	0x50
257 #define	ZULUVM_DMA2_TSB_BASE	0x68
258 
259 #ifdef	__cplusplus
260 }
261 #endif
262 
263 #endif	/* _ZULUMOD_H */
264