19 #ifndef __GRU_INSTRUCTIONS_H__
20 #define __GRU_INSTRUCTIONS_H__
32 #if defined(CONFIG_IA64)
33 #include <linux/compiler.h>
34 #include <asm/intrinsics.h>
35 #define __flush_cache(p) ia64_fc((unsigned long)p)
37 #define gru_ordered_store_ulong(p, v) \
40 *((volatile unsigned long *)(p)) = v; \
42 #elif defined(CONFIG_X86_64)
43 #include <asm/cacheflush.h>
44 #define __flush_cache(p) clflush(p)
45 #define gru_ordered_store_ulong(p, v) \
48 *(unsigned long *)p = v; \
51 #error "Unsupported architecture"
58 #define CBS_EXCEPTION 1
63 #define CBSS_MSG_QUEUE_MASK 7
64 #define CBSS_IMPLICIT_ABORT_ACTIVE_MASK 8
67 #define CBSS_NO_ERROR 0
68 #define CBSS_LB_OVERFLOWED 1
69 #define CBSS_QLIMIT_REACHED 2
70 #define CBSS_PAGE_OVERFLOW 3
71 #define CBSS_AMO_NACKED 4
72 #define CBSS_PUT_NACKED 5
150 #define GRU_CB_ICMD_SHFT 0
151 #define GRU_CB_ICMD_MASK 0x1
152 #define GRU_CB_XTYPE_SHFT 8
153 #define GRU_CB_XTYPE_MASK 0x7
154 #define GRU_CB_IAA0_SHFT 11
155 #define GRU_CB_IAA0_MASK 0x3
156 #define GRU_CB_IAA1_SHFT 13
157 #define GRU_CB_IAA1_MASK 0x3
158 #define GRU_CB_IMA_SHFT 1
159 #define GRU_CB_IMA_MASK 0x3
160 #define GRU_CB_OPC_SHFT 16
161 #define GRU_CB_OPC_MASK 0xff
162 #define GRU_CB_EXOPC_SHFT 24
163 #define GRU_CB_EXOPC_MASK 0xff
164 #define GRU_IDEF2_SHFT 32
165 #define GRU_IDEF2_MASK 0x3ffff
166 #define GRU_ISTATUS_SHFT 56
167 #define GRU_ISTATUS_MASK 0x3
171 #define OP_BCOPY 0x01
172 #define OP_VLOAD 0x02
173 #define OP_IVLOAD 0x03
174 #define OP_VSTORE 0x04
175 #define OP_IVSTORE 0x05
177 #define OP_IVSET 0x07
179 #define OP_GAMXR 0x09
180 #define OP_GAMIR 0x0a
181 #define OP_GAMIRR 0x0b
182 #define OP_GAMER 0x0c
183 #define OP_GAMERR 0x0d
184 #define OP_BSTORE 0x0e
185 #define OP_VFLUSH 0x0f
191 #define EOP_IR_FETCH 0x01
192 #define EOP_IR_CLR 0x02
193 #define EOP_IR_INC 0x05
194 #define EOP_IR_DEC 0x07
195 #define EOP_IR_QCHK1 0x0d
196 #define EOP_IR_QCHK2 0x0e
199 #define EOP_IRR_FETCH 0x01
200 #define EOP_IRR_CLR 0x02
201 #define EOP_IRR_INC 0x05
202 #define EOP_IRR_DEC 0x07
203 #define EOP_IRR_DECZ 0x0f
206 #define EOP_ER_SWAP 0x00
207 #define EOP_ER_OR 0x01
208 #define EOP_ER_AND 0x02
209 #define EOP_ER_XOR 0x03
210 #define EOP_ER_ADD 0x04
211 #define EOP_ER_CSWAP 0x08
212 #define EOP_ER_CADD 0x0c
215 #define EOP_ERR_SWAP 0x00
216 #define EOP_ERR_OR 0x01
217 #define EOP_ERR_AND 0x02
218 #define EOP_ERR_XOR 0x03
219 #define EOP_ERR_ADD 0x04
220 #define EOP_ERR_CSWAP 0x08
221 #define EOP_ERR_EPOLL 0x09
222 #define EOP_ERR_NPOLL 0x0a
225 #define EOP_XR_CSWAP 0x0b
238 #define IAA_NCRAM 0x2
240 #define IAA_REGISTER 0x3
244 #define IMA_MAPPED 0x0
245 #define IMA_CB_DELAY 0x1
246 #define IMA_UNMAPPED 0x2
247 #define IMA_INTERRUPT 0x4
250 #define CBE_CAUSE_RI (1 << 0)
251 #define CBE_CAUSE_INVALID_INSTRUCTION (1 << 1)
252 #define CBE_CAUSE_UNMAPPED_MODE_FORBIDDEN (1 << 2)
253 #define CBE_CAUSE_PE_CHECK_DATA_ERROR (1 << 3)
254 #define CBE_CAUSE_IAA_GAA_MISMATCH (1 << 4)
255 #define CBE_CAUSE_DATA_SEGMENT_LIMIT_EXCEPTION (1 << 5)
256 #define CBE_CAUSE_OS_FATAL_TLB_FAULT (1 << 6)
257 #define CBE_CAUSE_EXECUTION_HW_ERROR (1 << 7)
258 #define CBE_CAUSE_TLBHW_ERROR (1 << 8)
259 #define CBE_CAUSE_RA_REQUEST_TIMEOUT (1 << 9)
260 #define CBE_CAUSE_HA_REQUEST_TIMEOUT (1 << 10)
261 #define CBE_CAUSE_RA_RESPONSE_FATAL (1 << 11)
262 #define CBE_CAUSE_RA_RESPONSE_NON_FATAL (1 << 12)
263 #define CBE_CAUSE_HA_RESPONSE_FATAL (1 << 13)
264 #define CBE_CAUSE_HA_RESPONSE_NON_FATAL (1 << 14)
265 #define CBE_CAUSE_ADDRESS_SPACE_DECODE_ERROR (1 << 15)
266 #define CBE_CAUSE_PROTOCOL_STATE_DATA_ERROR (1 << 16)
267 #define CBE_CAUSE_RA_RESPONSE_DATA_ERROR (1 << 17)
268 #define CBE_CAUSE_HA_RESPONSE_DATA_ERROR (1 << 18)
269 #define CBE_CAUSE_FORCED_ERROR (1 << 19)
272 #define CBR_EXS_ABORT_OCC_BIT 0
273 #define CBR_EXS_INT_OCC_BIT 1
274 #define CBR_EXS_PENDING_BIT 2
275 #define CBR_EXS_QUEUED_BIT 3
276 #define CBR_EXS_TLB_INVAL_BIT 4
277 #define CBR_EXS_EXCEPTION_BIT 5
278 #define CBR_EXS_CB_INT_PENDING_BIT 6
280 #define CBR_EXS_ABORT_OCC (1 << CBR_EXS_ABORT_OCC_BIT)
281 #define CBR_EXS_INT_OCC (1 << CBR_EXS_INT_OCC_BIT)
282 #define CBR_EXS_PENDING (1 << CBR_EXS_PENDING_BIT)
283 #define CBR_EXS_QUEUED (1 << CBR_EXS_QUEUED_BIT)
284 #define CBR_EXS_TLB_INVAL (1 << CBR_EXS_TLB_INVAL_BIT)
285 #define CBR_EXS_EXCEPTION (1 << CBR_EXS_EXCEPTION_BIT)
286 #define CBR_EXS_CB_INT_PENDING (1 << CBR_EXS_CB_INT_PENDING_BIT)
292 #define EXCEPTION_RETRY_BITS (CBE_CAUSE_EXECUTION_HW_ERROR | \
293 CBE_CAUSE_TLBHW_ERROR | \
294 CBE_CAUSE_RA_REQUEST_TIMEOUT | \
295 CBE_CAUSE_RA_RESPONSE_NON_FATAL | \
296 CBE_CAUSE_HA_RESPONSE_NON_FATAL | \
297 CBE_CAUSE_RA_RESPONSE_DATA_ERROR | \
298 CBE_CAUSE_HA_RESPONSE_DATA_ERROR \
312 static inline unsigned long
313 __opdword(
unsigned char opcode,
unsigned char exopc,
unsigned char xtype,
314 unsigned char iaa0,
unsigned char iaa1,
315 unsigned long idef2,
unsigned char ima)
331 static inline void gru_flush_cache(
void *
p)
340 static inline void gru_start_instruction(
struct gru_instruction *
ins,
unsigned long op64)
342 gru_ordered_store_ulong(ins, op64);
344 gru_flush_cache(ins);
349 #define CB_IMA(h) ((h) | IMA_UNMAPPED)
352 #define GRU_DINDEX(i) ((i) * GRU_CACHE_LINE_BYTES)
359 static inline void gru_vload_phys(
void *
cb,
unsigned long gpa,
360 unsigned int tri0,
int iaa,
unsigned long hints)
364 ins->
baddr0 = (
long)gpa | ((
unsigned long)iaa << 62);
368 (
unsigned long)tri0,
CB_IMA(hints)));
371 static inline void gru_vstore_phys(
void *
cb,
unsigned long gpa,
372 unsigned int tri0,
int iaa,
unsigned long hints)
376 ins->
baddr0 = (
long)gpa | ((
unsigned long)iaa << 62);
380 (
unsigned long)tri0,
CB_IMA(hints)));
383 static inline void gru_vload(
void *cb,
unsigned long mem_addr,
384 unsigned int tri0,
unsigned char xtype,
unsigned long nelem,
385 unsigned long stride,
unsigned long hints)
393 (
unsigned long)tri0,
CB_IMA(hints)));
396 static inline void gru_vstore(
void *cb,
unsigned long mem_addr,
397 unsigned int tri0,
unsigned char xtype,
unsigned long nelem,
398 unsigned long stride,
unsigned long hints)
409 static inline void gru_ivload(
void *cb,
unsigned long mem_addr,
410 unsigned int tri0,
unsigned int tri1,
unsigned char xtype,
411 unsigned long nelem,
unsigned long hints)
422 static inline void gru_ivstore(
void *cb,
unsigned long mem_addr,
423 unsigned int tri0,
unsigned int tri1,
424 unsigned char xtype,
unsigned long nelem,
unsigned long hints)
435 static inline void gru_vset(
void *cb,
unsigned long mem_addr,
436 unsigned long value,
unsigned char xtype,
unsigned long nelem,
437 unsigned long stride,
unsigned long hints)
445 gru_start_instruction(ins, __opdword(
OP_VSET, 0, xtype,
IAA_RAM, 0,
449 static inline void gru_ivset(
void *cb,
unsigned long mem_addr,
450 unsigned int tri1,
unsigned long value,
unsigned char xtype,
451 unsigned long nelem,
unsigned long hints)
463 static inline void gru_vflush(
void *cb,
unsigned long mem_addr,
464 unsigned long nelem,
unsigned char xtype,
unsigned long stride,
476 static inline void gru_nop(
void *cb,
int hints)
480 gru_start_instruction(ins, __opdword(
OP_NOP, 0, 0, 0, 0, 0,
CB_IMA(hints)));
484 static inline void gru_bcopy(
void *cb,
const unsigned long src,
486 unsigned int tri0,
unsigned int xtype,
unsigned long nelem,
487 unsigned int bufsize,
unsigned long hints)
499 static inline void gru_bstore(
void *cb,
const unsigned long src,
500 unsigned long dest,
unsigned int tri0,
unsigned int xtype,
501 unsigned long nelem,
unsigned long hints)
512 static inline void gru_gamir(
void *cb,
int exopc,
unsigned long src,
513 unsigned int xtype,
unsigned long hints)
518 gru_start_instruction(ins, __opdword(
OP_GAMIR, exopc, xtype,
IAA_RAM, 0,
522 static inline void gru_gamirr(
void *cb,
int exopc,
unsigned long src,
523 unsigned int xtype,
unsigned long hints)
532 static inline void gru_gamer(
void *cb,
int exopc,
unsigned long src,
534 unsigned long operand1,
unsigned long operand2,
542 gru_start_instruction(ins, __opdword(
OP_GAMER, exopc, xtype,
IAA_RAM, 0,
546 static inline void gru_gamerr(
void *cb,
int exopc,
unsigned long src,
547 unsigned int xtype,
unsigned long operand1,
548 unsigned long operand2,
unsigned long hints)
559 static inline void gru_gamxr(
void *cb,
unsigned long src,
560 unsigned int tri0,
unsigned long hints)
570 static inline void gru_mesq(
void *cb,
unsigned long queue,
571 unsigned long tri0,
unsigned long nelem,
582 static inline unsigned long gru_get_amo_value(
void *cb)
589 static inline int gru_get_amo_value_head(
void *cb)
593 return ins->
avalue & 0xffffffff;
596 static inline int gru_get_amo_value_limit(
void *cb)
618 #define GRU_EXC_STR_SIZE 256
636 static inline int gru_get_cb_status(
void *cb)
644 static inline int gru_get_cb_message_queue_substatus(
void *cb)
652 static inline int gru_get_cb_substatus(
void *cb)
665 static inline int gru_check_status(
void *cb)
683 static inline int gru_wait(
void *cb)
693 static inline void gru_wait_abort(
void *cb)
702 static inline void *gru_get_gseg_pointer (
void *
p)
704 return (
void *)((
unsigned long)p & ~(GRU_GSEG_PAGESIZE - 1));
712 static inline void *gru_get_cb_pointer(
void *gseg,
723 static inline void *gru_get_data_pointer(
void *gseg,
int index)
732 static inline int gru_get_tri(
void *
vaddr)
734 return ((
unsigned long)vaddr & (GRU_GSEG_PAGESIZE - 1)) -
GRU_DS_BASE;