14c921d4dSJack Steiner /*
24c921d4dSJack Steiner * Copyright (c) 2008 Silicon Graphics, Inc. All Rights Reserved.
34c921d4dSJack Steiner *
44c921d4dSJack Steiner * This program is free software; you can redistribute it and/or modify
54c921d4dSJack Steiner * it under the terms of the GNU Lesser General Public License as published by
64c921d4dSJack Steiner * the Free Software Foundation; either version 2.1 of the License, or
74c921d4dSJack Steiner * (at your option) any later version.
84c921d4dSJack Steiner *
94c921d4dSJack Steiner * This program is distributed in the hope that it will be useful,
104c921d4dSJack Steiner * but WITHOUT ANY WARRANTY; without even the implied warranty of
114c921d4dSJack Steiner * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
124c921d4dSJack Steiner * GNU Lesser General Public License for more details.
134c921d4dSJack Steiner *
144c921d4dSJack Steiner * You should have received a copy of the GNU Lesser General Public License
154c921d4dSJack Steiner * along with this program; if not, write to the Free Software
164c921d4dSJack Steiner * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
174c921d4dSJack Steiner */
184c921d4dSJack Steiner
194c921d4dSJack Steiner #ifndef __GRU_INSTRUCTIONS_H__
204c921d4dSJack Steiner #define __GRU_INSTRUCTIONS_H__
214c921d4dSJack Steiner
22fe5bb6b0SJack Steiner extern int gru_check_status_proc(void *cb);
23fe5bb6b0SJack Steiner extern int gru_wait_proc(void *cb);
24fe5bb6b0SJack Steiner extern void gru_wait_abort_proc(void *cb);
25fe5bb6b0SJack Steiner
26fe5bb6b0SJack Steiner
274c921d4dSJack Steiner
284c921d4dSJack Steiner /*
294c921d4dSJack Steiner * Architecture dependent functions
304c921d4dSJack Steiner */
314c921d4dSJack Steiner
32923f7f69SJack Steiner #if defined(CONFIG_IA64)
334c921d4dSJack Steiner #include <linux/compiler.h>
344c921d4dSJack Steiner #include <asm/intrinsics.h>
35fe5bb6b0SJack Steiner #define __flush_cache(p) ia64_fc((unsigned long)p)
364c921d4dSJack Steiner /* Use volatile on IA64 to ensure ordering via st4.rel */
3757ebb034SJack Steiner #define gru_ordered_store_ulong(p, v) \
384c921d4dSJack Steiner do { \
394c921d4dSJack Steiner barrier(); \
4057ebb034SJack Steiner *((volatile unsigned long *)(p)) = v; /* force st.rel */ \
414c921d4dSJack Steiner } while (0)
42923f7f69SJack Steiner #elif defined(CONFIG_X86_64)
43*96f951edSDavid Howells #include <asm/cacheflush.h>
444c921d4dSJack Steiner #define __flush_cache(p) clflush(p)
4557ebb034SJack Steiner #define gru_ordered_store_ulong(p, v) \
464c921d4dSJack Steiner do { \
474c921d4dSJack Steiner barrier(); \
4857ebb034SJack Steiner *(unsigned long *)p = v; \
494c921d4dSJack Steiner } while (0)
504c921d4dSJack Steiner #else
514c921d4dSJack Steiner #error "Unsupported architecture"
524c921d4dSJack Steiner #endif
534c921d4dSJack Steiner
544c921d4dSJack Steiner /*
554c921d4dSJack Steiner * Control block status and exception codes
564c921d4dSJack Steiner */
574c921d4dSJack Steiner #define CBS_IDLE 0
584c921d4dSJack Steiner #define CBS_EXCEPTION 1
594c921d4dSJack Steiner #define CBS_ACTIVE 2
604c921d4dSJack Steiner #define CBS_CALL_OS 3
614c921d4dSJack Steiner
624c921d4dSJack Steiner /* CB substatus bitmasks */
634c921d4dSJack Steiner #define CBSS_MSG_QUEUE_MASK 7
644c921d4dSJack Steiner #define CBSS_IMPLICIT_ABORT_ACTIVE_MASK 8
654c921d4dSJack Steiner
664c921d4dSJack Steiner /* CB substatus message queue values (low 3 bits of substatus) */
674c921d4dSJack Steiner #define CBSS_NO_ERROR 0
684c921d4dSJack Steiner #define CBSS_LB_OVERFLOWED 1
694c921d4dSJack Steiner #define CBSS_QLIMIT_REACHED 2
704c921d4dSJack Steiner #define CBSS_PAGE_OVERFLOW 3
714c921d4dSJack Steiner #define CBSS_AMO_NACKED 4
724c921d4dSJack Steiner #define CBSS_PUT_NACKED 5
734c921d4dSJack Steiner
744c921d4dSJack Steiner /*
754c921d4dSJack Steiner * Structure used to fetch exception detail for CBs that terminate with
764c921d4dSJack Steiner * CBS_EXCEPTION
774c921d4dSJack Steiner */
784c921d4dSJack Steiner struct control_block_extended_exc_detail {
794c921d4dSJack Steiner unsigned long cb;
804c921d4dSJack Steiner int opc;
814c921d4dSJack Steiner int ecause;
824c921d4dSJack Steiner int exopc;
834c921d4dSJack Steiner long exceptdet0;
844c921d4dSJack Steiner int exceptdet1;
85cd1334f0SJack Steiner int cbrstate;
86cd1334f0SJack Steiner int cbrexecstatus;
874c921d4dSJack Steiner };
884c921d4dSJack Steiner
894c921d4dSJack Steiner /*
904c921d4dSJack Steiner * Instruction formats
914c921d4dSJack Steiner */
924c921d4dSJack Steiner
934c921d4dSJack Steiner /*
944c921d4dSJack Steiner * Generic instruction format.
954c921d4dSJack Steiner * This definition has precise bit field definitions.
964c921d4dSJack Steiner */
974c921d4dSJack Steiner struct gru_instruction_bits {
984c921d4dSJack Steiner /* DW 0 - low */
994c921d4dSJack Steiner unsigned int icmd: 1;
1004c921d4dSJack Steiner unsigned char ima: 3; /* CB_DelRep, unmapped mode */
1014c921d4dSJack Steiner unsigned char reserved0: 4;
1024c921d4dSJack Steiner unsigned int xtype: 3;
1034c921d4dSJack Steiner unsigned int iaa0: 2;
1044c921d4dSJack Steiner unsigned int iaa1: 2;
1054c921d4dSJack Steiner unsigned char reserved1: 1;
1064c921d4dSJack Steiner unsigned char opc: 8; /* opcode */
1074c921d4dSJack Steiner unsigned char exopc: 8; /* extended opcode */
1084c921d4dSJack Steiner /* DW 0 - high */
1094c921d4dSJack Steiner unsigned int idef2: 22; /* TRi0 */
1104c921d4dSJack Steiner unsigned char reserved2: 2;
1114c921d4dSJack Steiner unsigned char istatus: 2;
1124c921d4dSJack Steiner unsigned char isubstatus:4;
113cd1334f0SJack Steiner unsigned char reserved3: 1;
114cd1334f0SJack Steiner unsigned char tlb_fault_color: 1;
1154c921d4dSJack Steiner /* DW 1 */
1164c921d4dSJack Steiner unsigned long idef4; /* 42 bits: TRi1, BufSize */
1174c921d4dSJack Steiner /* DW 2-6 */
1184c921d4dSJack Steiner unsigned long idef1; /* BAddr0 */
1194c921d4dSJack Steiner unsigned long idef5; /* Nelem */
1204c921d4dSJack Steiner unsigned long idef6; /* Stride, Operand1 */
1214c921d4dSJack Steiner unsigned long idef3; /* BAddr1, Value, Operand2 */
1224c921d4dSJack Steiner unsigned long reserved4;
1234c921d4dSJack Steiner /* DW 7 */
1244c921d4dSJack Steiner unsigned long avalue; /* AValue */
1254c921d4dSJack Steiner };
1264c921d4dSJack Steiner
1274c921d4dSJack Steiner /*
1284c921d4dSJack Steiner * Generic instruction with friendlier names. This format is used
1294c921d4dSJack Steiner * for inline instructions.
1304c921d4dSJack Steiner */
1314c921d4dSJack Steiner struct gru_instruction {
1324c921d4dSJack Steiner /* DW 0 */
13357ebb034SJack Steiner union {
13457ebb034SJack Steiner unsigned long op64; /* icmd,xtype,iaa0,ima,opc,tri0 */
13557ebb034SJack Steiner struct {
13657ebb034SJack Steiner unsigned int op32;
1374c921d4dSJack Steiner unsigned int tri0;
13857ebb034SJack Steiner };
13957ebb034SJack Steiner };
1404c921d4dSJack Steiner unsigned long tri1_bufsize; /* DW 1 */
1414c921d4dSJack Steiner unsigned long baddr0; /* DW 2 */
1424c921d4dSJack Steiner unsigned long nelem; /* DW 3 */
1434c921d4dSJack Steiner unsigned long op1_stride; /* DW 4 */
1444c921d4dSJack Steiner unsigned long op2_value_baddr1; /* DW 5 */
1454c921d4dSJack Steiner unsigned long reserved0; /* DW 6 */
1464c921d4dSJack Steiner unsigned long avalue; /* DW 7 */
1474c921d4dSJack Steiner };
1484c921d4dSJack Steiner
14957ebb034SJack Steiner /* Some shifts and masks for the low 64 bits of a GRU command */
1504c921d4dSJack Steiner #define GRU_CB_ICMD_SHFT 0
1514c921d4dSJack Steiner #define GRU_CB_ICMD_MASK 0x1
1524c921d4dSJack Steiner #define GRU_CB_XTYPE_SHFT 8
1534c921d4dSJack Steiner #define GRU_CB_XTYPE_MASK 0x7
1544c921d4dSJack Steiner #define GRU_CB_IAA0_SHFT 11
1554c921d4dSJack Steiner #define GRU_CB_IAA0_MASK 0x3
1564c921d4dSJack Steiner #define GRU_CB_IAA1_SHFT 13
1574c921d4dSJack Steiner #define GRU_CB_IAA1_MASK 0x3
1584c921d4dSJack Steiner #define GRU_CB_IMA_SHFT 1
1594c921d4dSJack Steiner #define GRU_CB_IMA_MASK 0x3
1604c921d4dSJack Steiner #define GRU_CB_OPC_SHFT 16
1614c921d4dSJack Steiner #define GRU_CB_OPC_MASK 0xff
1624c921d4dSJack Steiner #define GRU_CB_EXOPC_SHFT 24
1634c921d4dSJack Steiner #define GRU_CB_EXOPC_MASK 0xff
16457ebb034SJack Steiner #define GRU_IDEF2_SHFT 32
16557ebb034SJack Steiner #define GRU_IDEF2_MASK 0x3ffff
16657ebb034SJack Steiner #define GRU_ISTATUS_SHFT 56
16757ebb034SJack Steiner #define GRU_ISTATUS_MASK 0x3
1684c921d4dSJack Steiner
1694c921d4dSJack Steiner /* GRU instruction opcodes (opc field) */
1704c921d4dSJack Steiner #define OP_NOP 0x00
1714c921d4dSJack Steiner #define OP_BCOPY 0x01
1724c921d4dSJack Steiner #define OP_VLOAD 0x02
1734c921d4dSJack Steiner #define OP_IVLOAD 0x03
1744c921d4dSJack Steiner #define OP_VSTORE 0x04
1754c921d4dSJack Steiner #define OP_IVSTORE 0x05
1764c921d4dSJack Steiner #define OP_VSET 0x06
1774c921d4dSJack Steiner #define OP_IVSET 0x07
1784c921d4dSJack Steiner #define OP_MESQ 0x08
1794c921d4dSJack Steiner #define OP_GAMXR 0x09
1804c921d4dSJack Steiner #define OP_GAMIR 0x0a
1814c921d4dSJack Steiner #define OP_GAMIRR 0x0b
1824c921d4dSJack Steiner #define OP_GAMER 0x0c
1834c921d4dSJack Steiner #define OP_GAMERR 0x0d
1844c921d4dSJack Steiner #define OP_BSTORE 0x0e
1854c921d4dSJack Steiner #define OP_VFLUSH 0x0f
1864c921d4dSJack Steiner
1874c921d4dSJack Steiner
1884c921d4dSJack Steiner /* Extended opcodes values (exopc field) */
1894c921d4dSJack Steiner
1904c921d4dSJack Steiner /* GAMIR - AMOs with implicit operands */
1914c921d4dSJack Steiner #define EOP_IR_FETCH 0x01 /* Plain fetch of memory */
1924c921d4dSJack Steiner #define EOP_IR_CLR 0x02 /* Fetch and clear */
1934c921d4dSJack Steiner #define EOP_IR_INC 0x05 /* Fetch and increment */
1944c921d4dSJack Steiner #define EOP_IR_DEC 0x07 /* Fetch and decrement */
1954c921d4dSJack Steiner #define EOP_IR_QCHK1 0x0d /* Queue check, 64 byte msg */
1964c921d4dSJack Steiner #define EOP_IR_QCHK2 0x0e /* Queue check, 128 byte msg */
1974c921d4dSJack Steiner
1984c921d4dSJack Steiner /* GAMIRR - Registered AMOs with implicit operands */
1994c921d4dSJack Steiner #define EOP_IRR_FETCH 0x01 /* Registered fetch of memory */
2004c921d4dSJack Steiner #define EOP_IRR_CLR 0x02 /* Registered fetch and clear */
2014c921d4dSJack Steiner #define EOP_IRR_INC 0x05 /* Registered fetch and increment */
2024c921d4dSJack Steiner #define EOP_IRR_DEC 0x07 /* Registered fetch and decrement */
2034c921d4dSJack Steiner #define EOP_IRR_DECZ 0x0f /* Registered fetch and decrement, update on zero*/
2044c921d4dSJack Steiner
2054c921d4dSJack Steiner /* GAMER - AMOs with explicit operands */
2064c921d4dSJack Steiner #define EOP_ER_SWAP 0x00 /* Exchange argument and memory */
2074c921d4dSJack Steiner #define EOP_ER_OR 0x01 /* Logical OR with memory */
2084c921d4dSJack Steiner #define EOP_ER_AND 0x02 /* Logical AND with memory */
2094c921d4dSJack Steiner #define EOP_ER_XOR 0x03 /* Logical XOR with memory */
2104c921d4dSJack Steiner #define EOP_ER_ADD 0x04 /* Add value to memory */
2114c921d4dSJack Steiner #define EOP_ER_CSWAP 0x08 /* Compare with operand2, write operand1 if match*/
2124c921d4dSJack Steiner #define EOP_ER_CADD 0x0c /* Queue check, operand1*64 byte msg */
2134c921d4dSJack Steiner
2144c921d4dSJack Steiner /* GAMERR - Registered AMOs with explicit operands */
2154c921d4dSJack Steiner #define EOP_ERR_SWAP 0x00 /* Exchange argument and memory */
2164c921d4dSJack Steiner #define EOP_ERR_OR 0x01 /* Logical OR with memory */
2174c921d4dSJack Steiner #define EOP_ERR_AND 0x02 /* Logical AND with memory */
2184c921d4dSJack Steiner #define EOP_ERR_XOR 0x03 /* Logical XOR with memory */
2194c921d4dSJack Steiner #define EOP_ERR_ADD 0x04 /* Add value to memory */
2204c921d4dSJack Steiner #define EOP_ERR_CSWAP 0x08 /* Compare with operand2, write operand1 if match*/
2214c921d4dSJack Steiner #define EOP_ERR_EPOLL 0x09 /* Poll for equality */
2224c921d4dSJack Steiner #define EOP_ERR_NPOLL 0x0a /* Poll for inequality */
2234c921d4dSJack Steiner
2244c921d4dSJack Steiner /* GAMXR - SGI Arithmetic unit */
2254c921d4dSJack Steiner #define EOP_XR_CSWAP 0x0b /* Masked compare exchange */
2264c921d4dSJack Steiner
2274c921d4dSJack Steiner
2284c921d4dSJack Steiner /* Transfer types (xtype field) */
2294c921d4dSJack Steiner #define XTYPE_B 0x0 /* byte */
2304c921d4dSJack Steiner #define XTYPE_S 0x1 /* short (2-byte) */
2314c921d4dSJack Steiner #define XTYPE_W 0x2 /* word (4-byte) */
2324c921d4dSJack Steiner #define XTYPE_DW 0x3 /* doubleword (8-byte) */
2334c921d4dSJack Steiner #define XTYPE_CL 0x6 /* cacheline (64-byte) */
2344c921d4dSJack Steiner
2354c921d4dSJack Steiner
2364c921d4dSJack Steiner /* Instruction access attributes (iaa0, iaa1 fields) */
2374c921d4dSJack Steiner #define IAA_RAM 0x0 /* normal cached RAM access */
2384c921d4dSJack Steiner #define IAA_NCRAM 0x2 /* noncoherent RAM access */
2394c921d4dSJack Steiner #define IAA_MMIO 0x1 /* noncoherent memory-mapped I/O space */
2404c921d4dSJack Steiner #define IAA_REGISTER 0x3 /* memory-mapped registers, etc. */
2414c921d4dSJack Steiner
2424c921d4dSJack Steiner
2434c921d4dSJack Steiner /* Instruction mode attributes (ima field) */
2444c921d4dSJack Steiner #define IMA_MAPPED 0x0 /* Virtual mode */
2454c921d4dSJack Steiner #define IMA_CB_DELAY 0x1 /* hold read responses until status changes */
2464c921d4dSJack Steiner #define IMA_UNMAPPED 0x2 /* bypass the TLBs (OS only) */
2474c921d4dSJack Steiner #define IMA_INTERRUPT 0x4 /* Interrupt when instruction completes */
2484c921d4dSJack Steiner
2494c921d4dSJack Steiner /* CBE ecause bits */
2504c921d4dSJack Steiner #define CBE_CAUSE_RI (1 << 0)
2514c921d4dSJack Steiner #define CBE_CAUSE_INVALID_INSTRUCTION (1 << 1)
2524c921d4dSJack Steiner #define CBE_CAUSE_UNMAPPED_MODE_FORBIDDEN (1 << 2)
2534c921d4dSJack Steiner #define CBE_CAUSE_PE_CHECK_DATA_ERROR (1 << 3)
2544c921d4dSJack Steiner #define CBE_CAUSE_IAA_GAA_MISMATCH (1 << 4)
2554c921d4dSJack Steiner #define CBE_CAUSE_DATA_SEGMENT_LIMIT_EXCEPTION (1 << 5)
2564c921d4dSJack Steiner #define CBE_CAUSE_OS_FATAL_TLB_FAULT (1 << 6)
2574c921d4dSJack Steiner #define CBE_CAUSE_EXECUTION_HW_ERROR (1 << 7)
2584c921d4dSJack Steiner #define CBE_CAUSE_TLBHW_ERROR (1 << 8)
2594c921d4dSJack Steiner #define CBE_CAUSE_RA_REQUEST_TIMEOUT (1 << 9)
2604c921d4dSJack Steiner #define CBE_CAUSE_HA_REQUEST_TIMEOUT (1 << 10)
2614c921d4dSJack Steiner #define CBE_CAUSE_RA_RESPONSE_FATAL (1 << 11)
2624c921d4dSJack Steiner #define CBE_CAUSE_RA_RESPONSE_NON_FATAL (1 << 12)
2634c921d4dSJack Steiner #define CBE_CAUSE_HA_RESPONSE_FATAL (1 << 13)
2644c921d4dSJack Steiner #define CBE_CAUSE_HA_RESPONSE_NON_FATAL (1 << 14)
2654c921d4dSJack Steiner #define CBE_CAUSE_ADDRESS_SPACE_DECODE_ERROR (1 << 15)
266270952a9SJack Steiner #define CBE_CAUSE_PROTOCOL_STATE_DATA_ERROR (1 << 16)
267270952a9SJack Steiner #define CBE_CAUSE_RA_RESPONSE_DATA_ERROR (1 << 17)
268270952a9SJack Steiner #define CBE_CAUSE_HA_RESPONSE_DATA_ERROR (1 << 18)
2695658366aSJack Steiner #define CBE_CAUSE_FORCED_ERROR (1 << 19)
2704c921d4dSJack Steiner
271cd1334f0SJack Steiner /* CBE cbrexecstatus bits */
272cd1334f0SJack Steiner #define CBR_EXS_ABORT_OCC_BIT 0
273cd1334f0SJack Steiner #define CBR_EXS_INT_OCC_BIT 1
274cd1334f0SJack Steiner #define CBR_EXS_PENDING_BIT 2
275cd1334f0SJack Steiner #define CBR_EXS_QUEUED_BIT 3
276270952a9SJack Steiner #define CBR_EXS_TLB_INVAL_BIT 4
277cd1334f0SJack Steiner #define CBR_EXS_EXCEPTION_BIT 5
2785658366aSJack Steiner #define CBR_EXS_CB_INT_PENDING_BIT 6
279cd1334f0SJack Steiner
280cd1334f0SJack Steiner #define CBR_EXS_ABORT_OCC (1 << CBR_EXS_ABORT_OCC_BIT)
281cd1334f0SJack Steiner #define CBR_EXS_INT_OCC (1 << CBR_EXS_INT_OCC_BIT)
282cd1334f0SJack Steiner #define CBR_EXS_PENDING (1 << CBR_EXS_PENDING_BIT)
283cd1334f0SJack Steiner #define CBR_EXS_QUEUED (1 << CBR_EXS_QUEUED_BIT)
2845658366aSJack Steiner #define CBR_EXS_TLB_INVAL (1 << CBR_EXS_TLB_INVAL_BIT)
285cd1334f0SJack Steiner #define CBR_EXS_EXCEPTION (1 << CBR_EXS_EXCEPTION_BIT)
2865658366aSJack Steiner #define CBR_EXS_CB_INT_PENDING (1 << CBR_EXS_CB_INT_PENDING_BIT)
287cd1334f0SJack Steiner
2884c921d4dSJack Steiner /*
2894c921d4dSJack Steiner * Exceptions are retried for the following cases. If any OTHER bits are set
2904c921d4dSJack Steiner * in ecause, the exception is not retryable.
2914c921d4dSJack Steiner */
292270952a9SJack Steiner #define EXCEPTION_RETRY_BITS (CBE_CAUSE_EXECUTION_HW_ERROR | \
2934c921d4dSJack Steiner CBE_CAUSE_TLBHW_ERROR | \
294270952a9SJack Steiner CBE_CAUSE_RA_REQUEST_TIMEOUT | \
295270952a9SJack Steiner CBE_CAUSE_RA_RESPONSE_NON_FATAL | \
296270952a9SJack Steiner CBE_CAUSE_HA_RESPONSE_NON_FATAL | \
297270952a9SJack Steiner CBE_CAUSE_RA_RESPONSE_DATA_ERROR | \
298270952a9SJack Steiner CBE_CAUSE_HA_RESPONSE_DATA_ERROR \
299270952a9SJack Steiner )
3004c921d4dSJack Steiner
3014c921d4dSJack Steiner /* Message queue head structure */
3024c921d4dSJack Steiner union gru_mesqhead {
3034c921d4dSJack Steiner unsigned long val;
3044c921d4dSJack Steiner struct {
3054c921d4dSJack Steiner unsigned int head;
3064c921d4dSJack Steiner unsigned int limit;
3074c921d4dSJack Steiner };
3084c921d4dSJack Steiner };
3094c921d4dSJack Steiner
3104c921d4dSJack Steiner
3114c921d4dSJack Steiner /* Generate the low word of a GRU instruction */
31257ebb034SJack Steiner static inline unsigned long
__opdword(unsigned char opcode,unsigned char exopc,unsigned char xtype,unsigned char iaa0,unsigned char iaa1,unsigned long idef2,unsigned char ima)31357ebb034SJack Steiner __opdword(unsigned char opcode, unsigned char exopc, unsigned char xtype,
3144c921d4dSJack Steiner unsigned char iaa0, unsigned char iaa1,
31557ebb034SJack Steiner unsigned long idef2, unsigned char ima)
3164c921d4dSJack Steiner {
3174c921d4dSJack Steiner return (1 << GRU_CB_ICMD_SHFT) |
31857ebb034SJack Steiner ((unsigned long)CBS_ACTIVE << GRU_ISTATUS_SHFT) |
31957ebb034SJack Steiner (idef2<< GRU_IDEF2_SHFT) |
3204c921d4dSJack Steiner (iaa0 << GRU_CB_IAA0_SHFT) |
3214c921d4dSJack Steiner (iaa1 << GRU_CB_IAA1_SHFT) |
3224c921d4dSJack Steiner (ima << GRU_CB_IMA_SHFT) |
3234c921d4dSJack Steiner (xtype << GRU_CB_XTYPE_SHFT) |
3244c921d4dSJack Steiner (opcode << GRU_CB_OPC_SHFT) |
3254c921d4dSJack Steiner (exopc << GRU_CB_EXOPC_SHFT);
3264c921d4dSJack Steiner }
3274c921d4dSJack Steiner
3284c921d4dSJack Steiner /*
3294c921d4dSJack Steiner * Architecture specific intrinsics
3304c921d4dSJack Steiner */
gru_flush_cache(void * p)3314c921d4dSJack Steiner static inline void gru_flush_cache(void *p)
3324c921d4dSJack Steiner {
3334c921d4dSJack Steiner __flush_cache(p);
3344c921d4dSJack Steiner }
3354c921d4dSJack Steiner
3364c921d4dSJack Steiner /*
33757ebb034SJack Steiner * Store the lower 64 bits of the command including the "start" bit. Then
3384c921d4dSJack Steiner * start the instruction executing.
3394c921d4dSJack Steiner */
gru_start_instruction(struct gru_instruction * ins,unsigned long op64)34057ebb034SJack Steiner static inline void gru_start_instruction(struct gru_instruction *ins, unsigned long op64)
3414c921d4dSJack Steiner {
34257ebb034SJack Steiner gru_ordered_store_ulong(ins, op64);
34367bf04a5SJack Steiner mb();
344923f7f69SJack Steiner gru_flush_cache(ins);
3454c921d4dSJack Steiner }
3464c921d4dSJack Steiner
3474c921d4dSJack Steiner
3484c921d4dSJack Steiner /* Convert "hints" to IMA */
3494c921d4dSJack Steiner #define CB_IMA(h) ((h) | IMA_UNMAPPED)
3504c921d4dSJack Steiner
3514c921d4dSJack Steiner /* Convert data segment cache line index into TRI0 / TRI1 value */
3524c921d4dSJack Steiner #define GRU_DINDEX(i) ((i) * GRU_CACHE_LINE_BYTES)
3534c921d4dSJack Steiner
3544c921d4dSJack Steiner /* Inline functions for GRU instructions.
3554c921d4dSJack Steiner * Note:
3564c921d4dSJack Steiner * - nelem and stride are in elements
3574c921d4dSJack Steiner * - tri0/tri1 is in bytes for the beginning of the data segment.
3584c921d4dSJack Steiner */
gru_vload_phys(void * cb,unsigned long gpa,unsigned int tri0,int iaa,unsigned long hints)359289750d1SRobin Holt static inline void gru_vload_phys(void *cb, unsigned long gpa,
360289750d1SRobin Holt unsigned int tri0, int iaa, unsigned long hints)
361289750d1SRobin Holt {
362289750d1SRobin Holt struct gru_instruction *ins = (struct gru_instruction *)cb;
363289750d1SRobin Holt
364289750d1SRobin Holt ins->baddr0 = (long)gpa | ((unsigned long)iaa << 62);
365289750d1SRobin Holt ins->nelem = 1;
366289750d1SRobin Holt ins->op1_stride = 1;
36757ebb034SJack Steiner gru_start_instruction(ins, __opdword(OP_VLOAD, 0, XTYPE_DW, iaa, 0,
36857ebb034SJack Steiner (unsigned long)tri0, CB_IMA(hints)));
369289750d1SRobin Holt }
370289750d1SRobin Holt
gru_vstore_phys(void * cb,unsigned long gpa,unsigned int tri0,int iaa,unsigned long hints)37176148df1SJack Steiner static inline void gru_vstore_phys(void *cb, unsigned long gpa,
37276148df1SJack Steiner unsigned int tri0, int iaa, unsigned long hints)
37376148df1SJack Steiner {
37476148df1SJack Steiner struct gru_instruction *ins = (struct gru_instruction *)cb;
37576148df1SJack Steiner
37676148df1SJack Steiner ins->baddr0 = (long)gpa | ((unsigned long)iaa << 62);
37776148df1SJack Steiner ins->nelem = 1;
37876148df1SJack Steiner ins->op1_stride = 1;
37976148df1SJack Steiner gru_start_instruction(ins, __opdword(OP_VSTORE, 0, XTYPE_DW, iaa, 0,
38076148df1SJack Steiner (unsigned long)tri0, CB_IMA(hints)));
38176148df1SJack Steiner }
38276148df1SJack Steiner
gru_vload(void * cb,unsigned long mem_addr,unsigned int tri0,unsigned char xtype,unsigned long nelem,unsigned long stride,unsigned long hints)3834c921d4dSJack Steiner static inline void gru_vload(void *cb, unsigned long mem_addr,
3844c921d4dSJack Steiner unsigned int tri0, unsigned char xtype, unsigned long nelem,
3854c921d4dSJack Steiner unsigned long stride, unsigned long hints)
3864c921d4dSJack Steiner {
3874c921d4dSJack Steiner struct gru_instruction *ins = (struct gru_instruction *)cb;
3884c921d4dSJack Steiner
3894c921d4dSJack Steiner ins->baddr0 = (long)mem_addr;
3904c921d4dSJack Steiner ins->nelem = nelem;
3914c921d4dSJack Steiner ins->op1_stride = stride;
39257ebb034SJack Steiner gru_start_instruction(ins, __opdword(OP_VLOAD, 0, xtype, IAA_RAM, 0,
39357ebb034SJack Steiner (unsigned long)tri0, CB_IMA(hints)));
3944c921d4dSJack Steiner }
3954c921d4dSJack Steiner
gru_vstore(void * cb,unsigned long mem_addr,unsigned int tri0,unsigned char xtype,unsigned long nelem,unsigned long stride,unsigned long hints)3964c921d4dSJack Steiner static inline void gru_vstore(void *cb, unsigned long mem_addr,
3974c921d4dSJack Steiner unsigned int tri0, unsigned char xtype, unsigned long nelem,
3984c921d4dSJack Steiner unsigned long stride, unsigned long hints)
3994c921d4dSJack Steiner {
4004c921d4dSJack Steiner struct gru_instruction *ins = (void *)cb;
4014c921d4dSJack Steiner
4024c921d4dSJack Steiner ins->baddr0 = (long)mem_addr;
4034c921d4dSJack Steiner ins->nelem = nelem;
4044c921d4dSJack Steiner ins->op1_stride = stride;
40557ebb034SJack Steiner gru_start_instruction(ins, __opdword(OP_VSTORE, 0, xtype, IAA_RAM, 0,
40657ebb034SJack Steiner tri0, CB_IMA(hints)));
4074c921d4dSJack Steiner }
4084c921d4dSJack Steiner
gru_ivload(void * cb,unsigned long mem_addr,unsigned int tri0,unsigned int tri1,unsigned char xtype,unsigned long nelem,unsigned long hints)4094c921d4dSJack Steiner static inline void gru_ivload(void *cb, unsigned long mem_addr,
4104c921d4dSJack Steiner unsigned int tri0, unsigned int tri1, unsigned char xtype,
4114c921d4dSJack Steiner unsigned long nelem, unsigned long hints)
4124c921d4dSJack Steiner {
4134c921d4dSJack Steiner struct gru_instruction *ins = (void *)cb;
4144c921d4dSJack Steiner
4154c921d4dSJack Steiner ins->baddr0 = (long)mem_addr;
4164c921d4dSJack Steiner ins->nelem = nelem;
4174c921d4dSJack Steiner ins->tri1_bufsize = tri1;
41857ebb034SJack Steiner gru_start_instruction(ins, __opdword(OP_IVLOAD, 0, xtype, IAA_RAM, 0,
41957ebb034SJack Steiner tri0, CB_IMA(hints)));
4204c921d4dSJack Steiner }
4214c921d4dSJack Steiner
gru_ivstore(void * cb,unsigned long mem_addr,unsigned int tri0,unsigned int tri1,unsigned char xtype,unsigned long nelem,unsigned long hints)4224c921d4dSJack Steiner static inline void gru_ivstore(void *cb, unsigned long mem_addr,
4234c921d4dSJack Steiner unsigned int tri0, unsigned int tri1,
4244c921d4dSJack Steiner unsigned char xtype, unsigned long nelem, unsigned long hints)
4254c921d4dSJack Steiner {
4264c921d4dSJack Steiner struct gru_instruction *ins = (void *)cb;
4274c921d4dSJack Steiner
4284c921d4dSJack Steiner ins->baddr0 = (long)mem_addr;
4294c921d4dSJack Steiner ins->nelem = nelem;
4304c921d4dSJack Steiner ins->tri1_bufsize = tri1;
43157ebb034SJack Steiner gru_start_instruction(ins, __opdword(OP_IVSTORE, 0, xtype, IAA_RAM, 0,
43257ebb034SJack Steiner tri0, CB_IMA(hints)));
4334c921d4dSJack Steiner }
4344c921d4dSJack Steiner
gru_vset(void * cb,unsigned long mem_addr,unsigned long value,unsigned char xtype,unsigned long nelem,unsigned long stride,unsigned long hints)4354c921d4dSJack Steiner static inline void gru_vset(void *cb, unsigned long mem_addr,
4364c921d4dSJack Steiner unsigned long value, unsigned char xtype, unsigned long nelem,
4374c921d4dSJack Steiner unsigned long stride, unsigned long hints)
4384c921d4dSJack Steiner {
4394c921d4dSJack Steiner struct gru_instruction *ins = (void *)cb;
4404c921d4dSJack Steiner
4414c921d4dSJack Steiner ins->baddr0 = (long)mem_addr;
4424c921d4dSJack Steiner ins->op2_value_baddr1 = value;
4434c921d4dSJack Steiner ins->nelem = nelem;
4444c921d4dSJack Steiner ins->op1_stride = stride;
44557ebb034SJack Steiner gru_start_instruction(ins, __opdword(OP_VSET, 0, xtype, IAA_RAM, 0,
44657ebb034SJack Steiner 0, CB_IMA(hints)));
4474c921d4dSJack Steiner }
4484c921d4dSJack Steiner
gru_ivset(void * cb,unsigned long mem_addr,unsigned int tri1,unsigned long value,unsigned char xtype,unsigned long nelem,unsigned long hints)4494c921d4dSJack Steiner static inline void gru_ivset(void *cb, unsigned long mem_addr,
4504c921d4dSJack Steiner unsigned int tri1, unsigned long value, unsigned char xtype,
4514c921d4dSJack Steiner unsigned long nelem, unsigned long hints)
4524c921d4dSJack Steiner {
4534c921d4dSJack Steiner struct gru_instruction *ins = (void *)cb;
4544c921d4dSJack Steiner
4554c921d4dSJack Steiner ins->baddr0 = (long)mem_addr;
4564c921d4dSJack Steiner ins->op2_value_baddr1 = value;
4574c921d4dSJack Steiner ins->nelem = nelem;
4584c921d4dSJack Steiner ins->tri1_bufsize = tri1;
45957ebb034SJack Steiner gru_start_instruction(ins, __opdword(OP_IVSET, 0, xtype, IAA_RAM, 0,
46057ebb034SJack Steiner 0, CB_IMA(hints)));
4614c921d4dSJack Steiner }
4624c921d4dSJack Steiner
gru_vflush(void * cb,unsigned long mem_addr,unsigned long nelem,unsigned char xtype,unsigned long stride,unsigned long hints)4634c921d4dSJack Steiner static inline void gru_vflush(void *cb, unsigned long mem_addr,
4644c921d4dSJack Steiner unsigned long nelem, unsigned char xtype, unsigned long stride,
4654c921d4dSJack Steiner unsigned long hints)
4664c921d4dSJack Steiner {
4674c921d4dSJack Steiner struct gru_instruction *ins = (void *)cb;
4684c921d4dSJack Steiner
4694c921d4dSJack Steiner ins->baddr0 = (long)mem_addr;
4704c921d4dSJack Steiner ins->op1_stride = stride;
4714c921d4dSJack Steiner ins->nelem = nelem;
47257ebb034SJack Steiner gru_start_instruction(ins, __opdword(OP_VFLUSH, 0, xtype, IAA_RAM, 0,
47357ebb034SJack Steiner 0, CB_IMA(hints)));
4744c921d4dSJack Steiner }
4754c921d4dSJack Steiner
gru_nop(void * cb,int hints)4764c921d4dSJack Steiner static inline void gru_nop(void *cb, int hints)
4774c921d4dSJack Steiner {
4784c921d4dSJack Steiner struct gru_instruction *ins = (void *)cb;
4794c921d4dSJack Steiner
48057ebb034SJack Steiner gru_start_instruction(ins, __opdword(OP_NOP, 0, 0, 0, 0, 0, CB_IMA(hints)));
4814c921d4dSJack Steiner }
4824c921d4dSJack Steiner
4834c921d4dSJack Steiner
gru_bcopy(void * cb,const unsigned long src,unsigned long dest,unsigned int tri0,unsigned int xtype,unsigned long nelem,unsigned int bufsize,unsigned long hints)4844c921d4dSJack Steiner static inline void gru_bcopy(void *cb, const unsigned long src,
4854c921d4dSJack Steiner unsigned long dest,
4864c921d4dSJack Steiner unsigned int tri0, unsigned int xtype, unsigned long nelem,
4874c921d4dSJack Steiner unsigned int bufsize, unsigned long hints)
4884c921d4dSJack Steiner {
4894c921d4dSJack Steiner struct gru_instruction *ins = (void *)cb;
4904c921d4dSJack Steiner
4914c921d4dSJack Steiner ins->baddr0 = (long)src;
4924c921d4dSJack Steiner ins->op2_value_baddr1 = (long)dest;
4934c921d4dSJack Steiner ins->nelem = nelem;
4944c921d4dSJack Steiner ins->tri1_bufsize = bufsize;
49557ebb034SJack Steiner gru_start_instruction(ins, __opdword(OP_BCOPY, 0, xtype, IAA_RAM,
49657ebb034SJack Steiner IAA_RAM, tri0, CB_IMA(hints)));
4974c921d4dSJack Steiner }
4984c921d4dSJack Steiner
gru_bstore(void * cb,const unsigned long src,unsigned long dest,unsigned int tri0,unsigned int xtype,unsigned long nelem,unsigned long hints)4994c921d4dSJack Steiner static inline void gru_bstore(void *cb, const unsigned long src,
5004c921d4dSJack Steiner unsigned long dest, unsigned int tri0, unsigned int xtype,
5014c921d4dSJack Steiner unsigned long nelem, unsigned long hints)
5024c921d4dSJack Steiner {
5034c921d4dSJack Steiner struct gru_instruction *ins = (void *)cb;
5044c921d4dSJack Steiner
5054c921d4dSJack Steiner ins->baddr0 = (long)src;
5064c921d4dSJack Steiner ins->op2_value_baddr1 = (long)dest;
5074c921d4dSJack Steiner ins->nelem = nelem;
50857ebb034SJack Steiner gru_start_instruction(ins, __opdword(OP_BSTORE, 0, xtype, 0, IAA_RAM,
50957ebb034SJack Steiner tri0, CB_IMA(hints)));
5104c921d4dSJack Steiner }
5114c921d4dSJack Steiner
gru_gamir(void * cb,int exopc,unsigned long src,unsigned int xtype,unsigned long hints)5124c921d4dSJack Steiner static inline void gru_gamir(void *cb, int exopc, unsigned long src,
5134c921d4dSJack Steiner unsigned int xtype, unsigned long hints)
5144c921d4dSJack Steiner {
5154c921d4dSJack Steiner struct gru_instruction *ins = (void *)cb;
5164c921d4dSJack Steiner
5174c921d4dSJack Steiner ins->baddr0 = (long)src;
51857ebb034SJack Steiner gru_start_instruction(ins, __opdword(OP_GAMIR, exopc, xtype, IAA_RAM, 0,
51957ebb034SJack Steiner 0, CB_IMA(hints)));
5204c921d4dSJack Steiner }
5214c921d4dSJack Steiner
gru_gamirr(void * cb,int exopc,unsigned long src,unsigned int xtype,unsigned long hints)5224c921d4dSJack Steiner static inline void gru_gamirr(void *cb, int exopc, unsigned long src,
5234c921d4dSJack Steiner unsigned int xtype, unsigned long hints)
5244c921d4dSJack Steiner {
5254c921d4dSJack Steiner struct gru_instruction *ins = (void *)cb;
5264c921d4dSJack Steiner
5274c921d4dSJack Steiner ins->baddr0 = (long)src;
52857ebb034SJack Steiner gru_start_instruction(ins, __opdword(OP_GAMIRR, exopc, xtype, IAA_RAM, 0,
52957ebb034SJack Steiner 0, CB_IMA(hints)));
5304c921d4dSJack Steiner }
5314c921d4dSJack Steiner
gru_gamer(void * cb,int exopc,unsigned long src,unsigned int xtype,unsigned long operand1,unsigned long operand2,unsigned long hints)5324c921d4dSJack Steiner static inline void gru_gamer(void *cb, int exopc, unsigned long src,
5334c921d4dSJack Steiner unsigned int xtype,
5344c921d4dSJack Steiner unsigned long operand1, unsigned long operand2,
5354c921d4dSJack Steiner unsigned long hints)
5364c921d4dSJack Steiner {
5374c921d4dSJack Steiner struct gru_instruction *ins = (void *)cb;
5384c921d4dSJack Steiner
5394c921d4dSJack Steiner ins->baddr0 = (long)src;
5404c921d4dSJack Steiner ins->op1_stride = operand1;
5414c921d4dSJack Steiner ins->op2_value_baddr1 = operand2;
54257ebb034SJack Steiner gru_start_instruction(ins, __opdword(OP_GAMER, exopc, xtype, IAA_RAM, 0,
54357ebb034SJack Steiner 0, CB_IMA(hints)));
5444c921d4dSJack Steiner }
5454c921d4dSJack Steiner
gru_gamerr(void * cb,int exopc,unsigned long src,unsigned int xtype,unsigned long operand1,unsigned long operand2,unsigned long hints)5464c921d4dSJack Steiner static inline void gru_gamerr(void *cb, int exopc, unsigned long src,
5474c921d4dSJack Steiner unsigned int xtype, unsigned long operand1,
5484c921d4dSJack Steiner unsigned long operand2, unsigned long hints)
5494c921d4dSJack Steiner {
5504c921d4dSJack Steiner struct gru_instruction *ins = (void *)cb;
5514c921d4dSJack Steiner
5524c921d4dSJack Steiner ins->baddr0 = (long)src;
5534c921d4dSJack Steiner ins->op1_stride = operand1;
5544c921d4dSJack Steiner ins->op2_value_baddr1 = operand2;
55557ebb034SJack Steiner gru_start_instruction(ins, __opdword(OP_GAMERR, exopc, xtype, IAA_RAM, 0,
55657ebb034SJack Steiner 0, CB_IMA(hints)));
5574c921d4dSJack Steiner }
5584c921d4dSJack Steiner
gru_gamxr(void * cb,unsigned long src,unsigned int tri0,unsigned long hints)5594c921d4dSJack Steiner static inline void gru_gamxr(void *cb, unsigned long src,
5604c921d4dSJack Steiner unsigned int tri0, unsigned long hints)
5614c921d4dSJack Steiner {
5624c921d4dSJack Steiner struct gru_instruction *ins = (void *)cb;
5634c921d4dSJack Steiner
5644c921d4dSJack Steiner ins->baddr0 = (long)src;
5654c921d4dSJack Steiner ins->nelem = 4;
56657ebb034SJack Steiner gru_start_instruction(ins, __opdword(OP_GAMXR, EOP_XR_CSWAP, XTYPE_DW,
56757ebb034SJack Steiner IAA_RAM, 0, 0, CB_IMA(hints)));
5684c921d4dSJack Steiner }
5694c921d4dSJack Steiner
gru_mesq(void * cb,unsigned long queue,unsigned long tri0,unsigned long nelem,unsigned long hints)5704c921d4dSJack Steiner static inline void gru_mesq(void *cb, unsigned long queue,
5714c921d4dSJack Steiner unsigned long tri0, unsigned long nelem,
5724c921d4dSJack Steiner unsigned long hints)
5734c921d4dSJack Steiner {
5744c921d4dSJack Steiner struct gru_instruction *ins = (void *)cb;
5754c921d4dSJack Steiner
5764c921d4dSJack Steiner ins->baddr0 = (long)queue;
5774c921d4dSJack Steiner ins->nelem = nelem;
57857ebb034SJack Steiner gru_start_instruction(ins, __opdword(OP_MESQ, 0, XTYPE_CL, IAA_RAM, 0,
57957ebb034SJack Steiner tri0, CB_IMA(hints)));
5804c921d4dSJack Steiner }
5814c921d4dSJack Steiner
gru_get_amo_value(void * cb)5824c921d4dSJack Steiner static inline unsigned long gru_get_amo_value(void *cb)
5834c921d4dSJack Steiner {
5844c921d4dSJack Steiner struct gru_instruction *ins = (void *)cb;
5854c921d4dSJack Steiner
5864c921d4dSJack Steiner return ins->avalue;
5874c921d4dSJack Steiner }
5884c921d4dSJack Steiner
gru_get_amo_value_head(void * cb)5894c921d4dSJack Steiner static inline int gru_get_amo_value_head(void *cb)
5904c921d4dSJack Steiner {
5914c921d4dSJack Steiner struct gru_instruction *ins = (void *)cb;
5924c921d4dSJack Steiner
5934c921d4dSJack Steiner return ins->avalue & 0xffffffff;
5944c921d4dSJack Steiner }
5954c921d4dSJack Steiner
gru_get_amo_value_limit(void * cb)5964c921d4dSJack Steiner static inline int gru_get_amo_value_limit(void *cb)
5974c921d4dSJack Steiner {
5984c921d4dSJack Steiner struct gru_instruction *ins = (void *)cb;
5994c921d4dSJack Steiner
6004c921d4dSJack Steiner return ins->avalue >> 32;
6014c921d4dSJack Steiner }
6024c921d4dSJack Steiner
gru_mesq_head(int head,int limit)6034c921d4dSJack Steiner static inline union gru_mesqhead gru_mesq_head(int head, int limit)
6044c921d4dSJack Steiner {
6054c921d4dSJack Steiner union gru_mesqhead mqh;
6064c921d4dSJack Steiner
6074c921d4dSJack Steiner mqh.head = head;
6084c921d4dSJack Steiner mqh.limit = limit;
6094c921d4dSJack Steiner return mqh;
6104c921d4dSJack Steiner }
6114c921d4dSJack Steiner
6124c921d4dSJack Steiner /*
6134c921d4dSJack Steiner * Get struct control_block_extended_exc_detail for CB.
6144c921d4dSJack Steiner */
6154c921d4dSJack Steiner extern int gru_get_cb_exception_detail(void *cb,
6164c921d4dSJack Steiner struct control_block_extended_exc_detail *excdet);
6174c921d4dSJack Steiner
6184c921d4dSJack Steiner #define GRU_EXC_STR_SIZE 256
6194c921d4dSJack Steiner
6204c921d4dSJack Steiner
6214c921d4dSJack Steiner /*
6224c921d4dSJack Steiner * Control block definition for checking status
6234c921d4dSJack Steiner */
6244c921d4dSJack Steiner struct gru_control_block_status {
6254c921d4dSJack Steiner unsigned int icmd :1;
626fe5bb6b0SJack Steiner unsigned int ima :3;
627fe5bb6b0SJack Steiner unsigned int reserved0 :4;
628fe5bb6b0SJack Steiner unsigned int unused1 :24;
6294c921d4dSJack Steiner unsigned int unused2 :24;
6304c921d4dSJack Steiner unsigned int istatus :2;
6314c921d4dSJack Steiner unsigned int isubstatus :4;
632fe5bb6b0SJack Steiner unsigned int unused3 :2;
6334c921d4dSJack Steiner };
6344c921d4dSJack Steiner
6354c921d4dSJack Steiner /* Get CB status */
gru_get_cb_status(void * cb)6364c921d4dSJack Steiner static inline int gru_get_cb_status(void *cb)
6374c921d4dSJack Steiner {
6384c921d4dSJack Steiner struct gru_control_block_status *cbs = (void *)cb;
6394c921d4dSJack Steiner
6404c921d4dSJack Steiner return cbs->istatus;
6414c921d4dSJack Steiner }
6424c921d4dSJack Steiner
6434c921d4dSJack Steiner /* Get CB message queue substatus */
gru_get_cb_message_queue_substatus(void * cb)6444c921d4dSJack Steiner static inline int gru_get_cb_message_queue_substatus(void *cb)
6454c921d4dSJack Steiner {
6464c921d4dSJack Steiner struct gru_control_block_status *cbs = (void *)cb;
6474c921d4dSJack Steiner
6484c921d4dSJack Steiner return cbs->isubstatus & CBSS_MSG_QUEUE_MASK;
6494c921d4dSJack Steiner }
6504c921d4dSJack Steiner
6514c921d4dSJack Steiner /* Get CB substatus */
gru_get_cb_substatus(void * cb)6524c921d4dSJack Steiner static inline int gru_get_cb_substatus(void *cb)
6534c921d4dSJack Steiner {
6544c921d4dSJack Steiner struct gru_control_block_status *cbs = (void *)cb;
6554c921d4dSJack Steiner
6564c921d4dSJack Steiner return cbs->isubstatus;
6574c921d4dSJack Steiner }
6584c921d4dSJack Steiner
6599f250114SJack Steiner /*
6609f250114SJack Steiner * User interface to check an instruction status. UPM and exceptions
6619f250114SJack Steiner * are handled automatically. However, this function does NOT wait
6629f250114SJack Steiner * for an active instruction to complete.
6639f250114SJack Steiner *
6644c921d4dSJack Steiner */
gru_check_status(void * cb)6654c921d4dSJack Steiner static inline int gru_check_status(void *cb)
6664c921d4dSJack Steiner {
6674c921d4dSJack Steiner struct gru_control_block_status *cbs = (void *)cb;
668923f7f69SJack Steiner int ret;
6694c921d4dSJack Steiner
670923f7f69SJack Steiner ret = cbs->istatus;
6719f250114SJack Steiner if (ret != CBS_ACTIVE)
6724c921d4dSJack Steiner ret = gru_check_status_proc(cb);
6734c921d4dSJack Steiner return ret;
6744c921d4dSJack Steiner }
6754c921d4dSJack Steiner
6769f250114SJack Steiner /*
6779f250114SJack Steiner * User interface (via inline function) to wait for an instruction
6789f250114SJack Steiner * to complete. Completion status (IDLE or EXCEPTION is returned
6799f250114SJack Steiner * to the user. Exception due to hardware errors are automatically
6809f250114SJack Steiner * retried before returning an exception.
6819f250114SJack Steiner *
6824c921d4dSJack Steiner */
gru_wait(void * cb)6834c921d4dSJack Steiner static inline int gru_wait(void *cb)
6844c921d4dSJack Steiner {
6859f250114SJack Steiner return gru_wait_proc(cb);
6864c921d4dSJack Steiner }
6874c921d4dSJack Steiner
6889f250114SJack Steiner /*
6899f250114SJack Steiner * Wait for CB to complete. Aborts program if error. (Note: error does NOT
6904c921d4dSJack Steiner * mean TLB mis - only fatal errors such as memory parity error or user
6914c921d4dSJack Steiner * bugs will cause termination.
6924c921d4dSJack Steiner */
gru_wait_abort(void * cb)6934c921d4dSJack Steiner static inline void gru_wait_abort(void *cb)
6944c921d4dSJack Steiner {
6954c921d4dSJack Steiner gru_wait_abort_proc(cb);
6964c921d4dSJack Steiner }
6974c921d4dSJack Steiner
69857ebb034SJack Steiner /*
69957ebb034SJack Steiner * Get a pointer to the start of a gseg
70057ebb034SJack Steiner * p - Any valid pointer within the gseg
70157ebb034SJack Steiner */
gru_get_gseg_pointer(void * p)70257ebb034SJack Steiner static inline void *gru_get_gseg_pointer (void *p)
70357ebb034SJack Steiner {
70457ebb034SJack Steiner return (void *)((unsigned long)p & ~(GRU_GSEG_PAGESIZE - 1));
70557ebb034SJack Steiner }
7064c921d4dSJack Steiner
7074c921d4dSJack Steiner /*
7084c921d4dSJack Steiner * Get a pointer to a control block
7094c921d4dSJack Steiner * gseg - GSeg address returned from gru_get_thread_gru_segment()
7104c921d4dSJack Steiner * index - index of desired CB
7114c921d4dSJack Steiner */
gru_get_cb_pointer(void * gseg,int index)7124c921d4dSJack Steiner static inline void *gru_get_cb_pointer(void *gseg,
7134c921d4dSJack Steiner int index)
7144c921d4dSJack Steiner {
7154c921d4dSJack Steiner return gseg + GRU_CB_BASE + index * GRU_HANDLE_STRIDE;
7164c921d4dSJack Steiner }
7174c921d4dSJack Steiner
7184c921d4dSJack Steiner /*
7194c921d4dSJack Steiner * Get a pointer to a cacheline in the data segment portion of a GSeg
7204c921d4dSJack Steiner * gseg - GSeg address returned from gru_get_thread_gru_segment()
7214c921d4dSJack Steiner * index - index of desired cache line
7224c921d4dSJack Steiner */
gru_get_data_pointer(void * gseg,int index)7234c921d4dSJack Steiner static inline void *gru_get_data_pointer(void *gseg, int index)
7244c921d4dSJack Steiner {
7254c921d4dSJack Steiner return gseg + GRU_DS_BASE + index * GRU_CACHE_LINE_BYTES;
7264c921d4dSJack Steiner }
7274c921d4dSJack Steiner
7284c921d4dSJack Steiner /*
7294c921d4dSJack Steiner * Convert a vaddr into the tri index within the GSEG
7304c921d4dSJack Steiner * vaddr - virtual address of within gseg
7314c921d4dSJack Steiner */
gru_get_tri(void * vaddr)7324c921d4dSJack Steiner static inline int gru_get_tri(void *vaddr)
7334c921d4dSJack Steiner {
7344c921d4dSJack Steiner return ((unsigned long)vaddr & (GRU_GSEG_PAGESIZE - 1)) - GRU_DS_BASE;
7354c921d4dSJack Steiner }
7364c921d4dSJack Steiner #endif /* __GRU_INSTRUCTIONS_H__ */
737