1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
|
/* Copyright (C) 2006, 2008, 2009 Free Software Foundation, Inc.
This file is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your option)
any later version.
This file is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
Under Section 7 of GPL version 3, you are granted additional
permissions described in the GCC Runtime Library Exception, version
3.1, as published by the Free Software Foundation.
You should have received a copy of the GNU General Public License and
a copy of the GCC Runtime Library Exception along with this program;
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
<http://www.gnu.org/licenses/>. */
#ifndef __SPU_MFCIO_H__
#define __SPU_MFCIO_H__ 1
#include <spu_intrinsics.h>
#ifdef __IN_LIBGCC2
typedef unsigned long long uint64_t;
#else
#include <stdint.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
/****************************************************************/
/* DMA list element structure*/
/****************************************************************/
#ifdef __GNUC__
__extension__
#endif
typedef struct mfc_list_element {
uint64_t notify : 1; /** Stall-and-notify bit */
uint64_t reserved : 16;
uint64_t size : 15; /** Transfer size */
uint64_t eal : 32; /** Lower word of effective address */
} mfc_list_element_t;
/****************************************************************/
/* DMA max/min size definitions. */
/****************************************************************/
#define MFC_MIN_DMA_SIZE_SHIFT 4 /* 16 bytes */
#define MFC_MAX_DMA_SIZE_SHIFT 14 /* 16384 bytes */
#define MFC_MIN_DMA_SIZE (1 << MFC_MIN_DMA_SIZE_SHIFT)
#define MFC_MAX_DMA_SIZE (1 << MFC_MAX_DMA_SIZE_SHIFT)
#define MFC_MIN_DMA_SIZE_MASK (MFC_MIN_DMA_SIZE - 1)
#define MFC_MAX_DMA_SIZE_MASK (MFC_MAX_DMA_SIZE - 1)
#define MFC_MIN_DMA_LIST_ELEMENTS 1
#define MFC_MAX_DMA_LIST_ELEMENTS 2048
#define MFC_MIN_DMA_LIST_SIZE (MFC_MIN_DMA_LIST_ELEMENTS << 3) /* 8 bytes */
#define MFC_MAX_DMA_LIST_SIZE (MFC_MAX_DMA_LIST_ELEMENTS << 3) /* 16K bytes */
/****************************************************************/
/* MFC DMA command modifiers to identify classes of operations. */
/****************************************************************/
/* Note: These commands modifier may be used in conjunction with the base
command types (i.e. MFC_PUT_CMD, MFC_GET_CMD, and MFC_SNDSIG_CMD)
to construct the various command permutations. */
#define MFC_BARRIER_ENABLE 0x0001
#define MFC_FENCE_ENABLE 0x0002
#define MFC_LIST_ENABLE 0x0004
#define MFC_RESULT_ENABLE 0x0010
/****************************************************************/
/* MFC DMA Put Commands */
/****************************************************************/
#define MFC_PUT_CMD 0x0020
#define MFC_PUTB_CMD (MFC_PUT_CMD | MFC_BARRIER_ENABLE)
#define MFC_PUTF_CMD (MFC_PUT_CMD | MFC_FENCE_ENABLE)
#define MFC_PUTL_CMD (MFC_PUT_CMD | MFC_LIST_ENABLE)
#define MFC_PUTLB_CMD (MFC_PUTL_CMD | MFC_BARRIER_ENABLE)
#define MFC_PUTLF_CMD (MFC_PUTL_CMD | MFC_FENCE_ENABLE)
#define MFC_PUTR_CMD (MFC_PUT_CMD | MFC_RESULT_ENABLE)
#define MFC_PUTRB_CMD (MFC_PUTR_CMD | MFC_BARRIER_ENABLE)
#define MFC_PUTRF_CMD (MFC_PUTR_CMD | MFC_FENCE_ENABLE)
#define MFC_PUTRL_CMD (MFC_PUTR_CMD | MFC_LIST_ENABLE)
#define MFC_PUTRLB_CMD (MFC_PUTRL_CMD | MFC_BARRIER_ENABLE)
#define MFC_PUTRLF_CMD (MFC_PUTRL_CMD | MFC_FENCE_ENABLE)
/****************************************************************/
/* MFC DMA Get Commands */
/****************************************************************/
#define MFC_GET_CMD 0x0040
#define MFC_GETB_CMD (MFC_GET_CMD | MFC_BARRIER_ENABLE)
#define MFC_GETF_CMD (MFC_GET_CMD | MFC_FENCE_ENABLE)
#define MFC_GETL_CMD (MFC_GET_CMD | MFC_LIST_ENABLE)
#define MFC_GETLB_CMD (MFC_GETL_CMD | MFC_BARRIER_ENABLE)
#define MFC_GETLF_CMD (MFC_GETL_CMD | MFC_FENCE_ENABLE)
/****************************************************************/
/* MFC Synchronization Commands */
/****************************************************************/
#define MFC_SNDSIG_CMD 0x00A0
#define MFC_SNDSIGB_CMD (MFC_SNDSIG_CMD | MFC_BARRIER_ENABLE)
#define MFC_SNDSIGF_CMD (MFC_SNDSIG_CMD | MFC_FENCE_ENABLE)
#define MFC_BARRIER_CMD 0x00C0
#define MFC_EIEIO_CMD 0x00C8
#define MFC_SYNC_CMD 0x00CC
/****************************************************************/
/* MFC Atomic Commands */
/****************************************************************/
#define MFC_GETLLAR_CMD 0x00D0
#define MFC_PUTLLC_CMD 0x00B4
#define MFC_PUTLLUC_CMD 0x00B0
#define MFC_PUTQLLUC_CMD 0x00B8
/****************************************************************/
/* MFC SL1 Storage Control Commands */
/****************************************************************/
#define MFC_SDCRT_CMD 0x0080
#define MFC_SDCRTST_CMD 0x0081
#define MFC_SDCRZ_CMD 0x0089
#define MFC_SDCRST_CMD 0x008D
#define MFC_SDCRF_CMD 0x008F
/****************************************************************/
/* Channel Defines */
/****************************************************************/
/* Events Defines for channels
* 0 (SPU_RdEventStat),
* 1 (SPU_WrEventMask), and
* 2 (SPU_WrEventAck).
*/
#define MFC_TAG_STATUS_UPDATE_EVENT 0x00000001
#define MFC_LIST_STALL_NOTIFY_EVENT 0x00000002
#define MFC_COMMAND_QUEUE_AVAILABLE_EVENT 0x00000008
#define MFC_IN_MBOX_AVAILABLE_EVENT 0x00000010
#define MFC_DECREMENTER_EVENT 0x00000020
#define MFC_OUT_INTR_MBOX_AVAILABLE_EVENT 0x00000040
#define MFC_OUT_MBOX_AVAILABLE_EVENT 0x00000080
#define MFC_SIGNAL_NOTIFY_2_EVENT 0x00000100
#define MFC_SIGNAL_NOTIFY_1_EVENT 0x00000200
#define MFC_LLR_LOST_EVENT 0x00000400
#define MFC_PRIV_ATTN_EVENT 0x00000800
#define MFC_MULTI_SRC_SYNC_EVENT 0x00001000
/* Tag Status Update defines for channel 23 (MFC_WrTagUpdate) */
#define MFC_TAG_UPDATE_IMMEDIATE 0x0
#define MFC_TAG_UPDATE_ANY 0x1
#define MFC_TAG_UPDATE_ALL 0x2
/* Atomic Command Status defines for channel 27 (MFC_RdAtomicStat) */
#define MFC_PUTLLC_STATUS 0x00000001
#define MFC_PUTLLUC_STATUS 0x00000002
#define MFC_GETLLAR_STATUS 0x00000004
/****************************************************************/
/* Definitions for constructing a 32-bit command word */
/* including the transfer and replacement class id and the */
/* command opcode. */
/****************************************************************/
#define MFC_CMD_WORD(_tid, _rid, _cmd) (((_tid)<<24)|((_rid)<<16)|(_cmd))
/* Addressing Utilities */
#define mfc_ea2h(ea) (unsigned int)((unsigned long long)(ea)>>32)
#define mfc_ea2l(ea) (unsigned int)(ea)
#define mfc_hl2ea(h,l) si_to_ullong(si_selb(si_from_uint(h),\
si_rotqbyi(si_from_uint(l), -4),\
si_fsmbi(0x0f0f)))
#define mfc_ceil128(v) (((v) + 127) & ~127)
/* MFC DMA */
#define mfc_put( ls,ea,size,tag,tid,rid) spu_mfcdma64(ls,mfc_ea2h(ea),mfc_ea2l(ea),size,tag,MFC_CMD_WORD(tid,rid,MFC_PUT_CMD))
#define mfc_putf( ls,ea,size,tag,tid,rid) spu_mfcdma64(ls,mfc_ea2h(ea),mfc_ea2l(ea),size,tag,MFC_CMD_WORD(tid,rid,MFC_PUTF_CMD))
#define mfc_putb( ls,ea,size,tag,tid,rid) spu_mfcdma64(ls,mfc_ea2h(ea),mfc_ea2l(ea),size,tag,MFC_CMD_WORD(tid,rid,MFC_PUTB_CMD))
#define mfc_get( ls,ea,size,tag,tid,rid) spu_mfcdma64(ls,mfc_ea2h(ea),mfc_ea2l(ea),size,tag,MFC_CMD_WORD(tid,rid,MFC_GET_CMD))
#define mfc_getf( ls,ea,size,tag,tid,rid) spu_mfcdma64(ls,mfc_ea2h(ea),mfc_ea2l(ea),size,tag,MFC_CMD_WORD(tid,rid,MFC_GETF_CMD))
#define mfc_getb( ls,ea,size,tag,tid,rid) spu_mfcdma64(ls,mfc_ea2h(ea),mfc_ea2l(ea),size,tag,MFC_CMD_WORD(tid,rid,MFC_GETB_CMD))
/* MFC list DMA */
#define mfc_putl( ls,ea,lsa,size,tag,tid,rid) spu_mfcdma64(ls,mfc_ea2h(ea),(unsigned int)(lsa),size,tag,MFC_CMD_WORD(tid,rid,MFC_PUTL_CMD))
#define mfc_putlf( ls,ea,lsa,size,tag,tid,rid) spu_mfcdma64(ls,mfc_ea2h(ea),(unsigned int)(lsa),size,tag,MFC_CMD_WORD(tid,rid,MFC_PUTLF_CMD))
#define mfc_putlb( ls,ea,lsa,size,tag,tid,rid) spu_mfcdma64(ls,mfc_ea2h(ea),(unsigned int)(lsa),size,tag,MFC_CMD_WORD(tid,rid,MFC_PUTLB_CMD))
#define mfc_getl( ls,ea,lsa,size,tag,tid,rid) spu_mfcdma64(ls,mfc_ea2h(ea),(unsigned int)(lsa),size,tag,MFC_CMD_WORD(tid,rid,MFC_GETL_CMD))
#define mfc_getlf( ls,ea,lsa,size,tag,tid,rid) spu_mfcdma64(ls,mfc_ea2h(ea),(unsigned int)(lsa),size,tag,MFC_CMD_WORD(tid,rid,MFC_GETLF_CMD))
#define mfc_getlb( ls,ea,lsa,size,tag,tid,rid) spu_mfcdma64(ls,mfc_ea2h(ea),(unsigned int)(lsa),size,tag,MFC_CMD_WORD(tid,rid,MFC_GETLB_CMD))
/* MFC Atomic Update DMA */
#define mfc_getllar( ls,ea,tid,rid) spu_mfcdma64(ls,mfc_ea2h(ea),mfc_ea2l(ea),128, 0,MFC_CMD_WORD(tid,rid,MFC_GETLLAR_CMD))
#define mfc_putllc( ls,ea,tid,rid) spu_mfcdma64(ls,mfc_ea2h(ea),mfc_ea2l(ea),128, 0,MFC_CMD_WORD(tid,rid,MFC_PUTLLC_CMD))
#define mfc_putlluc( ls,ea,tid,rid) spu_mfcdma64(ls,mfc_ea2h(ea),mfc_ea2l(ea),128, 0,MFC_CMD_WORD(tid,rid,MFC_PUTLLUC_CMD))
#define mfc_putqlluc(ls,ea,tag,tid,rid) spu_mfcdma64(ls,mfc_ea2h(ea),mfc_ea2l(ea),128,tag,MFC_CMD_WORD(tid,rid,MFC_PUTQLLUC_CMD))
/* MFC Synchronization Commands */
#define mfc_sndsig( ls,ea,tag,tid,rid) spu_mfcdma64(ls,mfc_ea2h(ea),mfc_ea2l(ea),4,tag,MFC_CMD_WORD(tid,rid,MFC_SNDSIG_CMD))
#define mfc_sndsigb(ls,ea,tag,tid,rid) spu_mfcdma64(ls,mfc_ea2h(ea),mfc_ea2l(ea),4,tag,MFC_CMD_WORD(tid,rid,MFC_SNDSIGB_CMD))
#define mfc_sndsigf(ls,ea,tag,tid,rid) spu_mfcdma64(ls,mfc_ea2h(ea),mfc_ea2l(ea),4,tag,MFC_CMD_WORD(tid,rid,MFC_SNDSIGF_CMD))
#define mfc_barrier(tag) spu_mfcdma32(0,0,0,tag,MFC_BARRIER_CMD)
#define mfc_eieio(tag,tid,rid) spu_mfcdma32(0,0,0,tag,MFC_CMD_WORD(tid,rid,MFC_EIEIO_CMD))
#define mfc_sync(tag) spu_mfcdma32(0,0,0,tag,MFC_SYNC_CMD)
/* MFC SL1 Storage Control Commands */
#define mfc_sdcrt( ea,size,tag,tid,rid) spu_mfcdma64(0,mfc_ea2h(ea),mfc_ea2l(ea),size,tag,MFC_CMD_WORD(tid,rid,MFC_SDCRT_CMD))
#define mfc_sdcrtst(ea,size,tag,tid,rid) spu_mfcdma64(0,mfc_ea2h(ea),mfc_ea2l(ea),size,tag,MFC_CMD_WORD(tid,rid,MFC_SDCRTST_CMD))
#define mfc_sdcrz( ea,size,tag,tid,rid) spu_mfcdma64(0,mfc_ea2h(ea),mfc_ea2l(ea),size,tag,MFC_CMD_WORD(tid,rid,MFC_SDCRZ_CMD))
#define mfc_sdcrst( ea,size,tag,tid,rid) spu_mfcdma64(0,mfc_ea2h(ea),mfc_ea2l(ea),size,tag,MFC_CMD_WORD(tid,rid,MFC_SDCRST_CMD))
#define mfc_sdcrf( ea,size,tag,tid,rid) spu_mfcdma64(0,mfc_ea2h(ea),mfc_ea2l(ea),size,tag,MFC_CMD_WORD(tid,rid,MFC_SDCRF_CMD))
/* DMA Queue */
#define mfc_stat_cmd_queue() spu_readchcnt(MFC_Cmd)
/* MFC Tag-Status */
#define mfc_write_tag_mask(mask) spu_writech(MFC_WrTagMask,mask)
#define mfc_read_tag_mask() spu_readch(MFC_RdTagMask)
#define mfc_write_tag_update(ts) spu_writech(MFC_WrTagUpdate,ts)
#define mfc_write_tag_update_immediate() mfc_write_tag_update(MFC_TAG_UPDATE_IMMEDIATE)
#define mfc_write_tag_update_any() mfc_write_tag_update(MFC_TAG_UPDATE_ANY)
#define mfc_write_tag_update_all() mfc_write_tag_update(MFC_TAG_UPDATE_ALL)
#define mfc_stat_tag_update() spu_readchcnt(MFC_WrTagUpdate)
#define mfc_read_tag_status() spu_readch(MFC_RdTagStat)
#define mfc_read_tag_status_immediate() (mfc_write_tag_update_immediate(), mfc_read_tag_status())
#define mfc_read_tag_status_any() (mfc_write_tag_update_any(), mfc_read_tag_status())
#define mfc_read_tag_status_all() (mfc_write_tag_update_all(), mfc_read_tag_status())
#define mfc_stat_tag_status() spu_readchcnt(MFC_RdTagStat)
/* MFC List Stall-and-Notify Tag */
#define mfc_read_list_stall_status() spu_readch(MFC_RdListStallStat)
#define mfc_stat_list_stall_status() spu_readchcnt(MFC_RdListStallStat)
#define mfc_write_list_stall_ack(tag) spu_writech(MFC_WrListStallAck,tag)
/* Atomic DMA */
#define mfc_read_atomic_status() spu_readch(MFC_RdAtomicStat)
#define mfc_stat_atomic_status() spu_readchcnt(MFC_RdAtomicStat)
/* MFC Multi-source Synchronization */
#define mfc_write_multi_src_sync_request() spu_writech(MFC_WrMSSyncReq,0)
#define mfc_stat_multi_src_sync_request() spu_readchcnt(MFC_WrMSSyncReq)
/* SPU Signal */
#define spu_read_signal1() spu_readch(SPU_RdSigNotify1)
#define spu_stat_signal1() spu_readchcnt(SPU_RdSigNotify1)
#define spu_read_signal2() spu_readch(SPU_RdSigNotify2)
#define spu_stat_signal2() spu_readchcnt(SPU_RdSigNotify2)
/* SPU/PPE Mailbox */
#define spu_read_in_mbox() spu_readch(SPU_RdInMbox)
#define spu_stat_in_mbox() spu_readchcnt(SPU_RdInMbox)
#define spu_write_out_mbox(a) spu_writech(SPU_WrOutMbox,a)
#define spu_stat_out_mbox() spu_readchcnt(SPU_WrOutMbox)
#define spu_write_out_intr_mbox(a) spu_writech(SPU_WrOutIntrMbox,a)
#define spu_stat_out_intr_mbox() spu_readchcnt(SPU_WrOutIntrMbox)
/* SPU Decrementer */
#define spu_read_decrementer() spu_readch(SPU_RdDec)
#define spu_write_decrementer(cnt) spu_writech(SPU_WrDec,(cnt))
/* SPU Event */
#define spu_read_event_status() spu_readch(SPU_RdEventStat)
#define spu_stat_event_status() spu_readchcnt(SPU_RdEventStat)
#define spu_write_event_mask(mask) spu_writech(SPU_WrEventMask,(mask))
#define spu_write_event_ack(ack) spu_writech(SPU_WrEventAck,(ack))
#define spu_read_event_mask() spu_readch(SPU_RdEventMask)
/* SPU State Management */
#define spu_read_machine_status() spu_readch(SPU_RdMachStat)
#define spu_write_srr0(srr0) spu_writech(SPU_WrSRR0,srr0)
#define spu_read_srr0() spu_readch(SPU_RdSRR0)
/* Interrupt-Safe Critical Sections */
static __inline__ unsigned int mfc_begin_critical_section (void)
__attribute__ ((__always_inline__));
static __inline__ unsigned int
mfc_begin_critical_section (void)
{
#ifdef SPU_MFCIO_INTERRUPT_SAFE
unsigned int __status = spu_read_machine_status ();
spu_idisable ();
return __status;
#else
return 0;
#endif
}
static __inline__ void mfc_end_critical_section (unsigned int)
__attribute__ ((__always_inline__));
static __inline__ void
mfc_end_critical_section (unsigned int __status __attribute__ ((__unused__)))
{
#ifdef SPU_MFCIO_INTERRUPT_SAFE
if (__status & 1)
spu_ienable ();
#endif
}
/* MFC Tag Manager */
#define MFC_TAG_INVALID 0xFFFFFFFF
#define MFC_TAG_VALID 0x00000000
#define mfc_tag_reserve() \
__mfc_tag_reserve()
#define mfc_tag_release(tag) \
__mfc_tag_release((tag))
#define mfc_multi_tag_reserve(nr_tags) \
__mfc_multi_tag_reserve((nr_tags))
#define mfc_multi_tag_release(tag, nr_tags) \
__mfc_multi_tag_release((tag),(nr_tags))
extern unsigned int __mfc_tag_reserve (void);
extern unsigned int __mfc_tag_release (unsigned int);
extern unsigned int __mfc_multi_tag_reserve (unsigned int);
extern unsigned int __mfc_multi_tag_release (unsigned int, unsigned int);
#ifdef __cplusplus
}
#endif
#endif /* __SPU_MFCIO_H__ */
|