Commit | Line | Data |
---|---|---|
aea481da DE |
1 | /* Copyright (C) 1998, Cygnus Solutions */ |
2 | ||
3 | #ifndef H_PKE_H | |
4 | #define H_PKE_H | |
5 | ||
6 | #include "sim-main.h" | |
803f52b9 | 7 | #include "sky-device.h" |
aea481da DE |
8 | |
9 | ||
fba9bfed FCE |
10 | /* Debugguing PKE? */ |
11 | ||
12 | #define PKE_DEBUG | |
13 | ||
14 | ||
aea481da DE |
15 | /* External functions */ |
16 | ||
17 | void pke0_attach(SIM_DESC sd); | |
52793fab | 18 | void pke0_issue(void); |
aea481da | 19 | void pke1_attach(SIM_DESC sd); |
52793fab | 20 | void pke1_issue(void); |
aea481da DE |
21 | |
22 | /* Quadword data type */ | |
23 | ||
fba9bfed | 24 | typedef unsigned_4 quadword[4]; |
aea481da DE |
25 | |
26 | /* truncate address to quadword */ | |
27 | #define ADDR_TRUNC_QW(addr) ((addr) & ~0x0f) | |
28 | /* extract offset in quadword */ | |
29 | #define ADDR_OFFSET_QW(addr) ((addr) & 0x0f) | |
30 | ||
31 | ||
32 | /* SCEI memory mapping information */ | |
33 | ||
34 | #define PKE0_REGISTER_WINDOW_START 0x10000800 | |
35 | #define PKE1_REGISTER_WINDOW_START 0x10000A00 | |
fba9bfed FCE |
36 | #define PKE0_FIFO_ADDR 0x10008000 |
37 | #define PKE1_FIFO_ADDR 0x10008010 | |
aea481da DE |
38 | |
39 | ||
40 | /* Quadword indices of PKE registers. Actual registers sit at bottom | |
41 | 32 bits of each quadword. */ | |
42 | #define PKE_REG_STAT 0x00 | |
43 | #define PKE_REG_FBRST 0x01 | |
44 | #define PKE_REG_ERR 0x02 | |
45 | #define PKE_REG_MARK 0x03 | |
46 | #define PKE_REG_CYCLE 0x04 | |
47 | #define PKE_REG_MODE 0x05 | |
48 | #define PKE_REG_NUM 0x06 | |
49 | #define PKE_REG_MASK 0x07 | |
50 | #define PKE_REG_CODE 0x08 | |
51 | #define PKE_REG_ITOPS 0x09 | |
52 | #define PKE_REG_BASE 0x0a /* pke1 only */ | |
53 | #define PKE_REG_OFST 0x0b /* pke1 only */ | |
54 | #define PKE_REG_TOPS 0x0c /* pke1 only */ | |
55 | #define PKE_REG_ITOP 0x0d | |
56 | #define PKE_REG_TOP 0x0e /* pke1 only */ | |
57 | #define PKE_REG_DBF 0x0f /* pke1 only */ | |
fba9bfed | 58 | #define PKE_REG_R0 0x10 /* R0 .. R3 must be contiguous */ |
aea481da DE |
59 | #define PKE_REG_R1 0x11 |
60 | #define PKE_REG_R2 0x12 | |
61 | #define PKE_REG_R3 0x13 | |
fba9bfed | 62 | #define PKE_REG_C0 0x14 /* C0 .. C3 must be contiguous */ |
aea481da DE |
63 | #define PKE_REG_C1 0x15 |
64 | #define PKE_REG_C2 0x16 | |
65 | #define PKE_REG_C3 0x17 | |
66 | /* one plus last index */ | |
67 | #define PKE_NUM_REGS 0x18 | |
68 | ||
69 | #define PKE_REGISTER_WINDOW_SIZE (sizeof(quadword) * PKE_NUM_REGS) | |
70 | ||
fba9bfed | 71 | |
aea481da DE |
72 | /* virtual addresses for source-addr tracking */ |
73 | #define PKE0_SRCADDR 0x20000020 | |
74 | #define PKE1_SRCADDR 0x20000024 | |
75 | ||
76 | ||
fba9bfed FCE |
77 | /* PKE commands */ |
78 | ||
79 | #define PKE_CMD_PKENOP_MASK 0x7F | |
80 | #define PKE_CMD_PKENOP_BITS 0x00 | |
81 | #define PKE_CMD_STCYCL_MASK 0x7F | |
82 | #define PKE_CMD_STCYCL_BITS 0x01 | |
83 | #define PKE_CMD_OFFSET_MASK 0x7F | |
84 | #define PKE_CMD_OFFSET_BITS 0x02 | |
85 | #define PKE_CMD_BASE_MASK 0x7F | |
86 | #define PKE_CMD_BASE_BITS 0x03 | |
87 | #define PKE_CMD_ITOP_MASK 0x7F | |
88 | #define PKE_CMD_ITOP_BITS 0x04 | |
89 | #define PKE_CMD_STMOD_MASK 0x7F | |
90 | #define PKE_CMD_STMOD_BITS 0x05 | |
91 | #define PKE_CMD_MSKPATH3_MASK 0x7F | |
92 | #define PKE_CMD_MSKPATH3_BITS 0x06 | |
93 | #define PKE_CMD_PKEMARK_MASK 0x7F | |
94 | #define PKE_CMD_PKEMARK_BITS 0x07 | |
95 | #define PKE_CMD_FLUSHE_MASK 0x7F | |
96 | #define PKE_CMD_FLUSHE_BITS 0x10 | |
97 | #define PKE_CMD_FLUSH_MASK 0x7F | |
98 | #define PKE_CMD_FLUSH_BITS 0x11 | |
99 | #define PKE_CMD_FLUSHA_MASK 0x7F | |
100 | #define PKE_CMD_FLUSHA_BITS 0x13 | |
101 | #define PKE_CMD_PKEMSCAL_MASK 0x7F /* CAL == "call" */ | |
102 | #define PKE_CMD_PKEMSCAL_BITS 0x14 | |
103 | #define PKE_CMD_PKEMSCNT_MASK 0x7F /* CNT == "continue" */ | |
104 | #define PKE_CMD_PKEMSCNT_BITS 0x17 | |
105 | #define PKE_CMD_PKEMSCALF_MASK 0x7F /* CALF == "call after flush" */ | |
106 | #define PKE_CMD_PKEMSCALF_BITS 0x15 | |
107 | #define PKE_CMD_STMASK_MASK 0x7F | |
108 | #define PKE_CMD_STMASK_BITS 0x20 | |
109 | #define PKE_CMD_STROW_MASK 0x7F | |
110 | #define PKE_CMD_STROW_BITS 0x30 | |
111 | #define PKE_CMD_STCOL_MASK 0x7F | |
112 | #define PKE_CMD_STCOL_BITS 0x31 | |
113 | #define PKE_CMD_MPG_MASK 0x7F | |
114 | #define PKE_CMD_MPG_BITS 0x4A | |
115 | #define PKE_CMD_DIRECT_MASK 0x7F | |
116 | #define PKE_CMD_DIRECT_BITS 0x50 | |
117 | #define PKE_CMD_DIRECTHL_MASK 0x7F | |
118 | #define PKE_CMD_DIRECTHL_BITS 0x51 | |
119 | #define PKE_CMD_UNPACK_MASK 0x60 | |
120 | #define PKE_CMD_UNPACK_BITS 0x60 | |
121 | ||
122 | /* test given word for particular PKE command bit pattern */ | |
123 | #define IS_PKE_CMD(word,cmd) (((word) & PKE_CMD_##cmd##_MASK) == PKE_CMD_##cmd##_BITS) | |
124 | ||
125 | ||
126 | /* register bitmasks: bit numbers for end and beginning of fields */ | |
127 | ||
128 | /* PKE opcode */ | |
129 | #define PKE_OPCODE_I_E 31 | |
130 | #define PKE_OPCODE_I_B 31 | |
131 | #define PKE_OPCODE_CMD_E 30 | |
132 | #define PKE_OPCODE_CMD_B 24 | |
133 | #define PKE_OPCODE_NUM_E 23 | |
134 | #define PKE_OPCODE_NUM_B 16 | |
135 | #define PKE_OPCODE_IMM_E 15 | |
136 | #define PKE_OPCODE_IMM_B 0 | |
137 | ||
138 | /* STAT register */ | |
139 | #define PKE_REG_STAT_FQC_E 28 | |
140 | #define PKE_REG_STAT_FQC_B 24 | |
141 | #define PKE_REG_STAT_FDR_E 23 | |
142 | #define PKE_REG_STAT_FDR_B 23 | |
143 | #define PKE_REG_STAT_ER1_E 13 | |
144 | #define PKE_REG_STAT_ER1_B 13 | |
145 | #define PKE_REG_STAT_ER0_E 12 | |
146 | #define PKE_REG_STAT_ER0_B 12 | |
147 | #define PKE_REG_STAT_INT_E 11 | |
148 | #define PKE_REG_STAT_INT_B 11 | |
149 | #define PKE_REG_STAT_PIS_E 10 | |
150 | #define PKE_REG_STAT_PIS_B 10 | |
151 | #define PKE_REG_STAT_PFS_E 9 | |
152 | #define PKE_REG_STAT_PFS_B 9 | |
153 | #define PKE_REG_STAT_PSS_E 8 | |
154 | #define PKE_REG_STAT_PSS_B 8 | |
155 | #define PKE_REG_STAT_DBF_E 7 | |
156 | #define PKE_REG_STAT_DBF_B 7 | |
157 | #define PKE_REG_STAT_MRK_E 6 | |
158 | #define PKE_REG_STAT_MRK_B 6 | |
159 | #define PKE_REG_STAT_PGW_E 3 | |
160 | #define PKE_REG_STAT_PGW_B 3 | |
161 | #define PKE_REG_STAT_PEW_E 2 | |
162 | #define PKE_REG_STAT_PEW_B 2 | |
163 | #define PKE_REG_STAT_PPS_E 1 | |
164 | #define PKE_REG_STAT_PPS_B 0 | |
165 | ||
166 | #define PKE_REG_STAT_PPS_IDLE 0x00 | |
167 | #define PKE_REG_STAT_PPS_WAIT 0x01 | |
168 | #define PKE_REG_STAT_PPS_DECODE 0x02 | |
169 | #define PKE_REG_STAT_PPS_XFER 0x03 | |
170 | ||
171 | /* DBF register */ | |
172 | #define PKE_REG_DBF_DF_E 0 | |
173 | #define PKE_REG_DBF_DF_B 0 | |
174 | ||
175 | /* OFST register */ | |
176 | #define PKE_REG_OFST_OFFSET_E 9 | |
177 | #define PKE_REG_OFST_OFFSET_B 0 | |
178 | ||
179 | /* OFST register */ | |
180 | #define PKE_REG_TOPS_TOPS_E 9 | |
181 | #define PKE_REG_TOPS_TOPS_B 0 | |
182 | ||
183 | /* BASE register */ | |
184 | #define PKE_REG_BASE_BASE_E 9 | |
185 | #define PKE_REG_BASE_BASE_B 0 | |
186 | ||
187 | /* ITOPS register */ | |
188 | #define PKE_REG_ITOPS_ITOPS_E 9 | |
189 | #define PKE_REG_ITOPS_ITOPS_B 0 | |
190 | ||
191 | /* MODE register */ | |
192 | #define PKE_REG_MODE_MDE_E 1 | |
193 | #define PKE_REG_MODE_MDE_B 0 | |
194 | ||
195 | /* MARK register */ | |
196 | #define PKE_REG_MARK_MARK_E 15 | |
197 | #define PKE_REG_MARK_MARK_B 0 | |
198 | ||
199 | /* ITOP register */ | |
200 | #define PKE_REG_ITOP_ITOP_E 9 | |
201 | #define PKE_REG_ITOP_ITOP_B 0 | |
202 | ||
203 | /* TOP register */ | |
204 | #define PKE_REG_TOP_TOP_E 9 | |
205 | #define PKE_REG_TOP_TOP_B 0 | |
206 | ||
207 | /* MASK register */ | |
208 | #define PKE_REG_MASK_MASK_E 31 | |
209 | #define PKE_REG_MASK_MASK_B 0 | |
210 | ||
211 | /* CYCLE register */ | |
212 | #define PKE_REG_CYCLE_WL_E 15 | |
213 | #define PKE_REG_CYCLE_WL_B 8 | |
214 | #define PKE_REG_CYCLE_CL_E 7 | |
215 | #define PKE_REG_CYCLE_CL_B 0 | |
216 | ||
217 | /* ERR register */ | |
218 | #define PKE_REG_ERR_ME1_E 2 | |
219 | #define PKE_REG_ERR_ME1_B 2 | |
220 | #define PKE_REG_ERR_ME0_E 1 | |
221 | #define PKE_REG_ERR_ME0_B 1 | |
222 | #define PKE_REG_ERR_MII_E 0 | |
223 | #define PKE_REG_ERR_MII_B 0 | |
224 | ||
225 | ||
226 | /* source-addr for words written to VU/GPUIF ports */ | |
227 | #define PKE0_SRCADDR 0x20000020 /* from 1998-01-22 e-mail plans */ | |
228 | #define PKE1_SRCADDR 0x20000024 /* from 1998-01-22 e-mail plans */ | |
229 | ||
230 | ||
231 | /* UNPACK opcodes */ | |
232 | #define PKE_UNPACK(vn,vl) ((vn) << 2 | (vl)) | |
233 | #define PKE_UNPACK_S_32 PKE_UNPACK(0, 0) | |
234 | #define PKE_UNPACK_S_16 PKE_UNPACK(0, 1) | |
235 | #define PKE_UNPACK_S_8 PKE_UNPACK(0, 2) | |
236 | #define PKE_UNPACK_V2_32 PKE_UNPACK(1, 0) | |
237 | #define PKE_UNPACK_V2_16 PKE_UNPACK(1, 1) | |
238 | #define PKE_UNPACK_V2_8 PKE_UNPACK(1, 2) | |
239 | #define PKE_UNPACK_V3_32 PKE_UNPACK(2, 0) | |
240 | #define PKE_UNPACK_V3_16 PKE_UNPACK(2, 1) | |
241 | #define PKE_UNPACK_V3_8 PKE_UNPACK(2, 2) | |
242 | #define PKE_UNPACK_V4_32 PKE_UNPACK(3, 0) | |
243 | #define PKE_UNPACK_V4_16 PKE_UNPACK(3, 1) | |
244 | #define PKE_UNPACK_V4_8 PKE_UNPACK(3, 2) | |
245 | #define PKE_UNPACK_V4_5 PKE_UNPACK(3, 3) | |
246 | ||
247 | ||
248 | /* MASK register sub-field definitions */ | |
249 | #define PKE_MASKREG_INPUT 0 | |
250 | #define PKE_MASKREG_ROW 1 | |
251 | #define PKE_MASKREG_COLUMN 2 | |
252 | #define PKE_MASKREG_NOTHING 3 | |
253 | ||
254 | ||
255 | /* STMOD register field definitions */ | |
256 | #define PKE_MODE_INPUT 0 | |
257 | #define PKE_MODE_ADDROW 1 | |
258 | #define PKE_MODE_ACCROW 2 | |
259 | ||
260 | ||
261 | /* extract a MASK register sub-field for row [0..3] and column [0..3] */ | |
262 | /* MASK register is laid out of 2-bit values in this r-c order */ | |
263 | /* m33 m32 m31 m30 m23 m22 m21 m20 m13 m12 m11 m10 m03 m02 m01 m00 */ | |
264 | #define PKE_MASKREG_GET(me,row,col) \ | |
265 | ((((me)->regs[PKE_REG_MASK][0]) >> (8*(row) + 2*(col))) & 0x03) | |
266 | ||
267 | ||
268 | /* and now a few definitions that rightfully belong elsewhere */ | |
269 | #ifdef PKE_DEBUG | |
270 | ||
271 | /* GPUIF addresses */ | |
272 | #define GPUIF_PATH3_FIFO_ADDR 0x10008020 /* data from CORE */ | |
273 | #define GPUIF_PATH1_FIFO_ADDR 0x10008030 /* data from VU1 */ | |
274 | #define GPUIF_PATH2_FIFO_ADDR 0x10008040 /* data from PKE1 */ | |
275 | ||
276 | /* VU STAT register */ | |
277 | #define VU_REG_STAT_VGW_E 4 | |
278 | #define VU_REG_STAT_VGW_B 4 | |
279 | #define VU_REG_STAT_VBS_E 0 | |
280 | #define VU_REG_STAT_VBS_B 0 | |
281 | ||
282 | /* VU PC pseudo-registers */ /* omitted from 1998-01-22 e-mail plans */ | |
283 | #define VU0_PC_START 0x20025000 | |
284 | #define VU1_PC_START 0x20026000 | |
285 | ||
286 | /* VU source-addr tracking tables */ /* changed from 1998-01-22 e-mail plans */ | |
287 | #define VU0_MEM0_SRCADDR_START 0x21000000 | |
288 | #define VU0_MEM1_SRCADDR_START 0x21004000 | |
289 | #define VU1_MEM0_SRCADDR_START 0x21008000 | |
290 | #define VU1_MEM1_SRCADDR_START 0x2100C000 | |
291 | ||
292 | #endif /* PKE_DEBUG */ | |
293 | ||
294 | ||
295 | /* operations */ | |
296 | /* unsigned 32-bit mask of given width */ | |
52793fab IC |
297 | #define BIT_MASK(width) (width == 31 ? 0xffffffff : (((unsigned_4)1) << (width+1)) - 1) |
298 | /* e.g.: BIT_MASK(4) = 00011111 */ | |
fba9bfed FCE |
299 | |
300 | /* mask between given given bits numbers (MSB) */ | |
301 | #define BIT_MASK_BTW(begin,end) (BIT_MASK(end) & ~BIT_MASK(begin)) | |
302 | /* e.g.: BIT_MASK_BTW(4,11) = 0000111111110000 */ | |
303 | ||
304 | /* set bitfield value */ | |
305 | #define BIT_MASK_SET(lvalue,begin,end,value) \ | |
306 | do { \ | |
307 | lvalue &= ~BIT_MASK_BTW(begin,end); \ | |
308 | lvalue |= (((value) << (begin)) & BIT_MASK_BTW(begin,end)); \ | |
309 | } while(0) | |
310 | ||
311 | /* get bitfield value */ | |
312 | #define BIT_MASK_GET(rvalue,begin,end) \ | |
313 | (((rvalue) & BIT_MASK_BTW(begin,end)) >> (begin)) | |
314 | /* e.g., BIT_MASK_GET(0000111100001111, 2, 8) = 0000000100001100 */ | |
315 | ||
316 | /* get bitfield value, sign-extended to given bit number */ | |
317 | #define BIT_MASK_GET_SX(rvalue,begin,end,sx) \ | |
318 | (BIT_MASK_GET(rvalue,begin,end) | ((BIT_MASK_GET(rvalue,begin,end) & BIT_MASK_BTW(end,end)) ? BIT_MASK_BTW(end,sx) : 0)) | |
319 | /* e.g., BIT_MASK_GET_SX(0000111100001111, 2, 8, 15) = 1111111100001100 */ | |
320 | ||
321 | ||
322 | /* These ugly macro hacks allow succinct bitfield accesses */ | |
323 | /* set a bitfield in a register by "name" */ | |
324 | #define PKE_REG_MASK_SET(me,reg,flag,value) \ | |
325 | BIT_MASK_SET(((me)->regs[PKE_REG_##reg][0]), \ | |
326 | PKE_REG_##reg##_##flag##_B, PKE_REG_##reg##_##flag##_E, \ | |
327 | (value)) | |
328 | ||
329 | /* get a bitfield from a register by "name" */ | |
330 | #define PKE_REG_MASK_GET(me,reg,flag) \ | |
331 | BIT_MASK_GET(((me)->regs[PKE_REG_##reg][0]), \ | |
332 | PKE_REG_##reg##_##flag##_B, PKE_REG_##reg##_##flag##_E) | |
333 | ||
334 | ||
335 | #define PKE_LIMIT(value,max) ((value) > (max) ? (max) : (value)) | |
336 | ||
337 | ||
aea481da DE |
338 | /* One row in the FIFO */ |
339 | struct fifo_quadword | |
340 | { | |
341 | /* 128 bits of data */ | |
342 | quadword data; | |
343 | /* source main memory address (or 0: unknown) */ | |
344 | address_word source_address; | |
fba9bfed FCE |
345 | /* DMA tag present in lower 64 bits */ |
346 | unsigned_4 dma_tag_present; | |
aea481da DE |
347 | }; |
348 | ||
349 | ||
350 | /* PKE internal state: FIFOs, registers, handle to VU friend */ | |
351 | struct pke_device | |
352 | { | |
353 | /* common device info */ | |
354 | device dev; | |
355 | ||
356 | /* identity: 0=PKE0, 1=PKE1 */ | |
357 | int pke_number; | |
358 | int flags; | |
359 | ||
aea481da DE |
360 | /* quadword registers */ |
361 | quadword regs[PKE_NUM_REGS]; | |
362 | ||
363 | /* FIFO */ | |
364 | struct fifo_quadword* fifo; | |
365 | int fifo_num_elements; /* no. of quadwords occupied in FIFO */ | |
366 | int fifo_buffer_size; /* no. of quadwords of space in FIFO */ | |
367 | FILE* fifo_trace_file; /* or 0 for no trace */ | |
fba9bfed | 368 | /* XXX: assumes FIFOs grow indefinately */ |
aea481da | 369 | |
fba9bfed FCE |
370 | /* PC */ |
371 | int fifo_pc; /* 0 .. (fifo_num_elements-1): quadword index of next instruction */ | |
372 | int qw_pc; /* 0 .. 3: word index of next instruction */ | |
aea481da DE |
373 | }; |
374 | ||
375 | ||
376 | /* Flags for PKE.flags */ | |
377 | ||
378 | #define PKE_FLAG_NONE 0 | |
379 | /* none at present */ | |
380 | ||
381 | ||
aea481da | 382 | #endif /* H_PKE_H */ |