Path: blob/master/drivers/misc/sgi-gru/gru_instructions.h
15111 views
/*1* Copyright (c) 2008 Silicon Graphics, Inc. All Rights Reserved.2*3* This program is free software; you can redistribute it and/or modify4* it under the terms of the GNU Lesser General Public License as published by5* the Free Software Foundation; either version 2.1 of the License, or6* (at your option) any later version.7*8* This program is distributed in the hope that it will be useful,9* but WITHOUT ANY WARRANTY; without even the implied warranty of10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the11* GNU Lesser General Public License for more details.12*13* You should have received a copy of the GNU Lesser General Public License14* along with this program; if not, write to the Free Software15* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA16*/1718#ifndef __GRU_INSTRUCTIONS_H__19#define __GRU_INSTRUCTIONS_H__2021extern int gru_check_status_proc(void *cb);22extern int gru_wait_proc(void *cb);23extern void gru_wait_abort_proc(void *cb);24252627/*28* Architecture dependent functions29*/3031#if defined(CONFIG_IA64)32#include <linux/compiler.h>33#include <asm/intrinsics.h>34#define __flush_cache(p) ia64_fc((unsigned long)p)35/* Use volatile on IA64 to ensure ordering via st4.rel */36#define gru_ordered_store_ulong(p, v) \37do { \38barrier(); \39*((volatile unsigned long *)(p)) = v; /* force st.rel */ \40} while (0)41#elif defined(CONFIG_X86_64)42#define __flush_cache(p) clflush(p)43#define gru_ordered_store_ulong(p, v) \44do { \45barrier(); \46*(unsigned long *)p = v; \47} while (0)48#else49#error "Unsupported architecture"50#endif5152/*53* Control block status and exception codes54*/55#define CBS_IDLE 056#define CBS_EXCEPTION 157#define CBS_ACTIVE 258#define CBS_CALL_OS 35960/* CB substatus bitmasks */61#define CBSS_MSG_QUEUE_MASK 762#define CBSS_IMPLICIT_ABORT_ACTIVE_MASK 86364/* CB substatus message queue values (low 3 bits of substatus) */65#define CBSS_NO_ERROR 066#define CBSS_LB_OVERFLOWED 167#define CBSS_QLIMIT_REACHED 268#define CBSS_PAGE_OVERFLOW 369#define CBSS_AMO_NACKED 470#define CBSS_PUT_NACKED 57172/*73* Structure used to fetch exception detail for CBs that terminate with74* CBS_EXCEPTION75*/76struct control_block_extended_exc_detail {77unsigned long cb;78int opc;79int ecause;80int exopc;81long exceptdet0;82int exceptdet1;83int cbrstate;84int cbrexecstatus;85};8687/*88* Instruction formats89*/9091/*92* Generic instruction format.93* This definition has precise bit field definitions.94*/95struct gru_instruction_bits {96/* DW 0 - low */97unsigned int icmd: 1;98unsigned char ima: 3; /* CB_DelRep, unmapped mode */99unsigned char reserved0: 4;100unsigned int xtype: 3;101unsigned int iaa0: 2;102unsigned int iaa1: 2;103unsigned char reserved1: 1;104unsigned char opc: 8; /* opcode */105unsigned char exopc: 8; /* extended opcode */106/* DW 0 - high */107unsigned int idef2: 22; /* TRi0 */108unsigned char reserved2: 2;109unsigned char istatus: 2;110unsigned char isubstatus:4;111unsigned char reserved3: 1;112unsigned char tlb_fault_color: 1;113/* DW 1 */114unsigned long idef4; /* 42 bits: TRi1, BufSize */115/* DW 2-6 */116unsigned long idef1; /* BAddr0 */117unsigned long idef5; /* Nelem */118unsigned long idef6; /* Stride, Operand1 */119unsigned long idef3; /* BAddr1, Value, Operand2 */120unsigned long reserved4;121/* DW 7 */122unsigned long avalue; /* AValue */123};124125/*126* Generic instruction with friendlier names. This format is used127* for inline instructions.128*/129struct gru_instruction {130/* DW 0 */131union {132unsigned long op64; /* icmd,xtype,iaa0,ima,opc,tri0 */133struct {134unsigned int op32;135unsigned int tri0;136};137};138unsigned long tri1_bufsize; /* DW 1 */139unsigned long baddr0; /* DW 2 */140unsigned long nelem; /* DW 3 */141unsigned long op1_stride; /* DW 4 */142unsigned long op2_value_baddr1; /* DW 5 */143unsigned long reserved0; /* DW 6 */144unsigned long avalue; /* DW 7 */145};146147/* Some shifts and masks for the low 64 bits of a GRU command */148#define GRU_CB_ICMD_SHFT 0149#define GRU_CB_ICMD_MASK 0x1150#define GRU_CB_XTYPE_SHFT 8151#define GRU_CB_XTYPE_MASK 0x7152#define GRU_CB_IAA0_SHFT 11153#define GRU_CB_IAA0_MASK 0x3154#define GRU_CB_IAA1_SHFT 13155#define GRU_CB_IAA1_MASK 0x3156#define GRU_CB_IMA_SHFT 1157#define GRU_CB_IMA_MASK 0x3158#define GRU_CB_OPC_SHFT 16159#define GRU_CB_OPC_MASK 0xff160#define GRU_CB_EXOPC_SHFT 24161#define GRU_CB_EXOPC_MASK 0xff162#define GRU_IDEF2_SHFT 32163#define GRU_IDEF2_MASK 0x3ffff164#define GRU_ISTATUS_SHFT 56165#define GRU_ISTATUS_MASK 0x3166167/* GRU instruction opcodes (opc field) */168#define OP_NOP 0x00169#define OP_BCOPY 0x01170#define OP_VLOAD 0x02171#define OP_IVLOAD 0x03172#define OP_VSTORE 0x04173#define OP_IVSTORE 0x05174#define OP_VSET 0x06175#define OP_IVSET 0x07176#define OP_MESQ 0x08177#define OP_GAMXR 0x09178#define OP_GAMIR 0x0a179#define OP_GAMIRR 0x0b180#define OP_GAMER 0x0c181#define OP_GAMERR 0x0d182#define OP_BSTORE 0x0e183#define OP_VFLUSH 0x0f184185186/* Extended opcodes values (exopc field) */187188/* GAMIR - AMOs with implicit operands */189#define EOP_IR_FETCH 0x01 /* Plain fetch of memory */190#define EOP_IR_CLR 0x02 /* Fetch and clear */191#define EOP_IR_INC 0x05 /* Fetch and increment */192#define EOP_IR_DEC 0x07 /* Fetch and decrement */193#define EOP_IR_QCHK1 0x0d /* Queue check, 64 byte msg */194#define EOP_IR_QCHK2 0x0e /* Queue check, 128 byte msg */195196/* GAMIRR - Registered AMOs with implicit operands */197#define EOP_IRR_FETCH 0x01 /* Registered fetch of memory */198#define EOP_IRR_CLR 0x02 /* Registered fetch and clear */199#define EOP_IRR_INC 0x05 /* Registered fetch and increment */200#define EOP_IRR_DEC 0x07 /* Registered fetch and decrement */201#define EOP_IRR_DECZ 0x0f /* Registered fetch and decrement, update on zero*/202203/* GAMER - AMOs with explicit operands */204#define EOP_ER_SWAP 0x00 /* Exchange argument and memory */205#define EOP_ER_OR 0x01 /* Logical OR with memory */206#define EOP_ER_AND 0x02 /* Logical AND with memory */207#define EOP_ER_XOR 0x03 /* Logical XOR with memory */208#define EOP_ER_ADD 0x04 /* Add value to memory */209#define EOP_ER_CSWAP 0x08 /* Compare with operand2, write operand1 if match*/210#define EOP_ER_CADD 0x0c /* Queue check, operand1*64 byte msg */211212/* GAMERR - Registered AMOs with explicit operands */213#define EOP_ERR_SWAP 0x00 /* Exchange argument and memory */214#define EOP_ERR_OR 0x01 /* Logical OR with memory */215#define EOP_ERR_AND 0x02 /* Logical AND with memory */216#define EOP_ERR_XOR 0x03 /* Logical XOR with memory */217#define EOP_ERR_ADD 0x04 /* Add value to memory */218#define EOP_ERR_CSWAP 0x08 /* Compare with operand2, write operand1 if match*/219#define EOP_ERR_EPOLL 0x09 /* Poll for equality */220#define EOP_ERR_NPOLL 0x0a /* Poll for inequality */221222/* GAMXR - SGI Arithmetic unit */223#define EOP_XR_CSWAP 0x0b /* Masked compare exchange */224225226/* Transfer types (xtype field) */227#define XTYPE_B 0x0 /* byte */228#define XTYPE_S 0x1 /* short (2-byte) */229#define XTYPE_W 0x2 /* word (4-byte) */230#define XTYPE_DW 0x3 /* doubleword (8-byte) */231#define XTYPE_CL 0x6 /* cacheline (64-byte) */232233234/* Instruction access attributes (iaa0, iaa1 fields) */235#define IAA_RAM 0x0 /* normal cached RAM access */236#define IAA_NCRAM 0x2 /* noncoherent RAM access */237#define IAA_MMIO 0x1 /* noncoherent memory-mapped I/O space */238#define IAA_REGISTER 0x3 /* memory-mapped registers, etc. */239240241/* Instruction mode attributes (ima field) */242#define IMA_MAPPED 0x0 /* Virtual mode */243#define IMA_CB_DELAY 0x1 /* hold read responses until status changes */244#define IMA_UNMAPPED 0x2 /* bypass the TLBs (OS only) */245#define IMA_INTERRUPT 0x4 /* Interrupt when instruction completes */246247/* CBE ecause bits */248#define CBE_CAUSE_RI (1 << 0)249#define CBE_CAUSE_INVALID_INSTRUCTION (1 << 1)250#define CBE_CAUSE_UNMAPPED_MODE_FORBIDDEN (1 << 2)251#define CBE_CAUSE_PE_CHECK_DATA_ERROR (1 << 3)252#define CBE_CAUSE_IAA_GAA_MISMATCH (1 << 4)253#define CBE_CAUSE_DATA_SEGMENT_LIMIT_EXCEPTION (1 << 5)254#define CBE_CAUSE_OS_FATAL_TLB_FAULT (1 << 6)255#define CBE_CAUSE_EXECUTION_HW_ERROR (1 << 7)256#define CBE_CAUSE_TLBHW_ERROR (1 << 8)257#define CBE_CAUSE_RA_REQUEST_TIMEOUT (1 << 9)258#define CBE_CAUSE_HA_REQUEST_TIMEOUT (1 << 10)259#define CBE_CAUSE_RA_RESPONSE_FATAL (1 << 11)260#define CBE_CAUSE_RA_RESPONSE_NON_FATAL (1 << 12)261#define CBE_CAUSE_HA_RESPONSE_FATAL (1 << 13)262#define CBE_CAUSE_HA_RESPONSE_NON_FATAL (1 << 14)263#define CBE_CAUSE_ADDRESS_SPACE_DECODE_ERROR (1 << 15)264#define CBE_CAUSE_PROTOCOL_STATE_DATA_ERROR (1 << 16)265#define CBE_CAUSE_RA_RESPONSE_DATA_ERROR (1 << 17)266#define CBE_CAUSE_HA_RESPONSE_DATA_ERROR (1 << 18)267#define CBE_CAUSE_FORCED_ERROR (1 << 19)268269/* CBE cbrexecstatus bits */270#define CBR_EXS_ABORT_OCC_BIT 0271#define CBR_EXS_INT_OCC_BIT 1272#define CBR_EXS_PENDING_BIT 2273#define CBR_EXS_QUEUED_BIT 3274#define CBR_EXS_TLB_INVAL_BIT 4275#define CBR_EXS_EXCEPTION_BIT 5276#define CBR_EXS_CB_INT_PENDING_BIT 6277278#define CBR_EXS_ABORT_OCC (1 << CBR_EXS_ABORT_OCC_BIT)279#define CBR_EXS_INT_OCC (1 << CBR_EXS_INT_OCC_BIT)280#define CBR_EXS_PENDING (1 << CBR_EXS_PENDING_BIT)281#define CBR_EXS_QUEUED (1 << CBR_EXS_QUEUED_BIT)282#define CBR_EXS_TLB_INVAL (1 << CBR_EXS_TLB_INVAL_BIT)283#define CBR_EXS_EXCEPTION (1 << CBR_EXS_EXCEPTION_BIT)284#define CBR_EXS_CB_INT_PENDING (1 << CBR_EXS_CB_INT_PENDING_BIT)285286/*287* Exceptions are retried for the following cases. If any OTHER bits are set288* in ecause, the exception is not retryable.289*/290#define EXCEPTION_RETRY_BITS (CBE_CAUSE_EXECUTION_HW_ERROR | \291CBE_CAUSE_TLBHW_ERROR | \292CBE_CAUSE_RA_REQUEST_TIMEOUT | \293CBE_CAUSE_RA_RESPONSE_NON_FATAL | \294CBE_CAUSE_HA_RESPONSE_NON_FATAL | \295CBE_CAUSE_RA_RESPONSE_DATA_ERROR | \296CBE_CAUSE_HA_RESPONSE_DATA_ERROR \297)298299/* Message queue head structure */300union gru_mesqhead {301unsigned long val;302struct {303unsigned int head;304unsigned int limit;305};306};307308309/* Generate the low word of a GRU instruction */310static inline unsigned long311__opdword(unsigned char opcode, unsigned char exopc, unsigned char xtype,312unsigned char iaa0, unsigned char iaa1,313unsigned long idef2, unsigned char ima)314{315return (1 << GRU_CB_ICMD_SHFT) |316((unsigned long)CBS_ACTIVE << GRU_ISTATUS_SHFT) |317(idef2<< GRU_IDEF2_SHFT) |318(iaa0 << GRU_CB_IAA0_SHFT) |319(iaa1 << GRU_CB_IAA1_SHFT) |320(ima << GRU_CB_IMA_SHFT) |321(xtype << GRU_CB_XTYPE_SHFT) |322(opcode << GRU_CB_OPC_SHFT) |323(exopc << GRU_CB_EXOPC_SHFT);324}325326/*327* Architecture specific intrinsics328*/329static inline void gru_flush_cache(void *p)330{331__flush_cache(p);332}333334/*335* Store the lower 64 bits of the command including the "start" bit. Then336* start the instruction executing.337*/338static inline void gru_start_instruction(struct gru_instruction *ins, unsigned long op64)339{340gru_ordered_store_ulong(ins, op64);341mb();342gru_flush_cache(ins);343}344345346/* Convert "hints" to IMA */347#define CB_IMA(h) ((h) | IMA_UNMAPPED)348349/* Convert data segment cache line index into TRI0 / TRI1 value */350#define GRU_DINDEX(i) ((i) * GRU_CACHE_LINE_BYTES)351352/* Inline functions for GRU instructions.353* Note:354* - nelem and stride are in elements355* - tri0/tri1 is in bytes for the beginning of the data segment.356*/357static inline void gru_vload_phys(void *cb, unsigned long gpa,358unsigned int tri0, int iaa, unsigned long hints)359{360struct gru_instruction *ins = (struct gru_instruction *)cb;361362ins->baddr0 = (long)gpa | ((unsigned long)iaa << 62);363ins->nelem = 1;364ins->op1_stride = 1;365gru_start_instruction(ins, __opdword(OP_VLOAD, 0, XTYPE_DW, iaa, 0,366(unsigned long)tri0, CB_IMA(hints)));367}368369static inline void gru_vstore_phys(void *cb, unsigned long gpa,370unsigned int tri0, int iaa, unsigned long hints)371{372struct gru_instruction *ins = (struct gru_instruction *)cb;373374ins->baddr0 = (long)gpa | ((unsigned long)iaa << 62);375ins->nelem = 1;376ins->op1_stride = 1;377gru_start_instruction(ins, __opdword(OP_VSTORE, 0, XTYPE_DW, iaa, 0,378(unsigned long)tri0, CB_IMA(hints)));379}380381static inline void gru_vload(void *cb, unsigned long mem_addr,382unsigned int tri0, unsigned char xtype, unsigned long nelem,383unsigned long stride, unsigned long hints)384{385struct gru_instruction *ins = (struct gru_instruction *)cb;386387ins->baddr0 = (long)mem_addr;388ins->nelem = nelem;389ins->op1_stride = stride;390gru_start_instruction(ins, __opdword(OP_VLOAD, 0, xtype, IAA_RAM, 0,391(unsigned long)tri0, CB_IMA(hints)));392}393394static inline void gru_vstore(void *cb, unsigned long mem_addr,395unsigned int tri0, unsigned char xtype, unsigned long nelem,396unsigned long stride, unsigned long hints)397{398struct gru_instruction *ins = (void *)cb;399400ins->baddr0 = (long)mem_addr;401ins->nelem = nelem;402ins->op1_stride = stride;403gru_start_instruction(ins, __opdword(OP_VSTORE, 0, xtype, IAA_RAM, 0,404tri0, CB_IMA(hints)));405}406407static inline void gru_ivload(void *cb, unsigned long mem_addr,408unsigned int tri0, unsigned int tri1, unsigned char xtype,409unsigned long nelem, unsigned long hints)410{411struct gru_instruction *ins = (void *)cb;412413ins->baddr0 = (long)mem_addr;414ins->nelem = nelem;415ins->tri1_bufsize = tri1;416gru_start_instruction(ins, __opdword(OP_IVLOAD, 0, xtype, IAA_RAM, 0,417tri0, CB_IMA(hints)));418}419420static inline void gru_ivstore(void *cb, unsigned long mem_addr,421unsigned int tri0, unsigned int tri1,422unsigned char xtype, unsigned long nelem, unsigned long hints)423{424struct gru_instruction *ins = (void *)cb;425426ins->baddr0 = (long)mem_addr;427ins->nelem = nelem;428ins->tri1_bufsize = tri1;429gru_start_instruction(ins, __opdword(OP_IVSTORE, 0, xtype, IAA_RAM, 0,430tri0, CB_IMA(hints)));431}432433static inline void gru_vset(void *cb, unsigned long mem_addr,434unsigned long value, unsigned char xtype, unsigned long nelem,435unsigned long stride, unsigned long hints)436{437struct gru_instruction *ins = (void *)cb;438439ins->baddr0 = (long)mem_addr;440ins->op2_value_baddr1 = value;441ins->nelem = nelem;442ins->op1_stride = stride;443gru_start_instruction(ins, __opdword(OP_VSET, 0, xtype, IAA_RAM, 0,4440, CB_IMA(hints)));445}446447static inline void gru_ivset(void *cb, unsigned long mem_addr,448unsigned int tri1, unsigned long value, unsigned char xtype,449unsigned long nelem, unsigned long hints)450{451struct gru_instruction *ins = (void *)cb;452453ins->baddr0 = (long)mem_addr;454ins->op2_value_baddr1 = value;455ins->nelem = nelem;456ins->tri1_bufsize = tri1;457gru_start_instruction(ins, __opdword(OP_IVSET, 0, xtype, IAA_RAM, 0,4580, CB_IMA(hints)));459}460461static inline void gru_vflush(void *cb, unsigned long mem_addr,462unsigned long nelem, unsigned char xtype, unsigned long stride,463unsigned long hints)464{465struct gru_instruction *ins = (void *)cb;466467ins->baddr0 = (long)mem_addr;468ins->op1_stride = stride;469ins->nelem = nelem;470gru_start_instruction(ins, __opdword(OP_VFLUSH, 0, xtype, IAA_RAM, 0,4710, CB_IMA(hints)));472}473474static inline void gru_nop(void *cb, int hints)475{476struct gru_instruction *ins = (void *)cb;477478gru_start_instruction(ins, __opdword(OP_NOP, 0, 0, 0, 0, 0, CB_IMA(hints)));479}480481482static inline void gru_bcopy(void *cb, const unsigned long src,483unsigned long dest,484unsigned int tri0, unsigned int xtype, unsigned long nelem,485unsigned int bufsize, unsigned long hints)486{487struct gru_instruction *ins = (void *)cb;488489ins->baddr0 = (long)src;490ins->op2_value_baddr1 = (long)dest;491ins->nelem = nelem;492ins->tri1_bufsize = bufsize;493gru_start_instruction(ins, __opdword(OP_BCOPY, 0, xtype, IAA_RAM,494IAA_RAM, tri0, CB_IMA(hints)));495}496497static inline void gru_bstore(void *cb, const unsigned long src,498unsigned long dest, unsigned int tri0, unsigned int xtype,499unsigned long nelem, unsigned long hints)500{501struct gru_instruction *ins = (void *)cb;502503ins->baddr0 = (long)src;504ins->op2_value_baddr1 = (long)dest;505ins->nelem = nelem;506gru_start_instruction(ins, __opdword(OP_BSTORE, 0, xtype, 0, IAA_RAM,507tri0, CB_IMA(hints)));508}509510static inline void gru_gamir(void *cb, int exopc, unsigned long src,511unsigned int xtype, unsigned long hints)512{513struct gru_instruction *ins = (void *)cb;514515ins->baddr0 = (long)src;516gru_start_instruction(ins, __opdword(OP_GAMIR, exopc, xtype, IAA_RAM, 0,5170, CB_IMA(hints)));518}519520static inline void gru_gamirr(void *cb, int exopc, unsigned long src,521unsigned int xtype, unsigned long hints)522{523struct gru_instruction *ins = (void *)cb;524525ins->baddr0 = (long)src;526gru_start_instruction(ins, __opdword(OP_GAMIRR, exopc, xtype, IAA_RAM, 0,5270, CB_IMA(hints)));528}529530static inline void gru_gamer(void *cb, int exopc, unsigned long src,531unsigned int xtype,532unsigned long operand1, unsigned long operand2,533unsigned long hints)534{535struct gru_instruction *ins = (void *)cb;536537ins->baddr0 = (long)src;538ins->op1_stride = operand1;539ins->op2_value_baddr1 = operand2;540gru_start_instruction(ins, __opdword(OP_GAMER, exopc, xtype, IAA_RAM, 0,5410, CB_IMA(hints)));542}543544static inline void gru_gamerr(void *cb, int exopc, unsigned long src,545unsigned int xtype, unsigned long operand1,546unsigned long operand2, unsigned long hints)547{548struct gru_instruction *ins = (void *)cb;549550ins->baddr0 = (long)src;551ins->op1_stride = operand1;552ins->op2_value_baddr1 = operand2;553gru_start_instruction(ins, __opdword(OP_GAMERR, exopc, xtype, IAA_RAM, 0,5540, CB_IMA(hints)));555}556557static inline void gru_gamxr(void *cb, unsigned long src,558unsigned int tri0, unsigned long hints)559{560struct gru_instruction *ins = (void *)cb;561562ins->baddr0 = (long)src;563ins->nelem = 4;564gru_start_instruction(ins, __opdword(OP_GAMXR, EOP_XR_CSWAP, XTYPE_DW,565IAA_RAM, 0, 0, CB_IMA(hints)));566}567568static inline void gru_mesq(void *cb, unsigned long queue,569unsigned long tri0, unsigned long nelem,570unsigned long hints)571{572struct gru_instruction *ins = (void *)cb;573574ins->baddr0 = (long)queue;575ins->nelem = nelem;576gru_start_instruction(ins, __opdword(OP_MESQ, 0, XTYPE_CL, IAA_RAM, 0,577tri0, CB_IMA(hints)));578}579580static inline unsigned long gru_get_amo_value(void *cb)581{582struct gru_instruction *ins = (void *)cb;583584return ins->avalue;585}586587static inline int gru_get_amo_value_head(void *cb)588{589struct gru_instruction *ins = (void *)cb;590591return ins->avalue & 0xffffffff;592}593594static inline int gru_get_amo_value_limit(void *cb)595{596struct gru_instruction *ins = (void *)cb;597598return ins->avalue >> 32;599}600601static inline union gru_mesqhead gru_mesq_head(int head, int limit)602{603union gru_mesqhead mqh;604605mqh.head = head;606mqh.limit = limit;607return mqh;608}609610/*611* Get struct control_block_extended_exc_detail for CB.612*/613extern int gru_get_cb_exception_detail(void *cb,614struct control_block_extended_exc_detail *excdet);615616#define GRU_EXC_STR_SIZE 256617618619/*620* Control block definition for checking status621*/622struct gru_control_block_status {623unsigned int icmd :1;624unsigned int ima :3;625unsigned int reserved0 :4;626unsigned int unused1 :24;627unsigned int unused2 :24;628unsigned int istatus :2;629unsigned int isubstatus :4;630unsigned int unused3 :2;631};632633/* Get CB status */634static inline int gru_get_cb_status(void *cb)635{636struct gru_control_block_status *cbs = (void *)cb;637638return cbs->istatus;639}640641/* Get CB message queue substatus */642static inline int gru_get_cb_message_queue_substatus(void *cb)643{644struct gru_control_block_status *cbs = (void *)cb;645646return cbs->isubstatus & CBSS_MSG_QUEUE_MASK;647}648649/* Get CB substatus */650static inline int gru_get_cb_substatus(void *cb)651{652struct gru_control_block_status *cbs = (void *)cb;653654return cbs->isubstatus;655}656657/*658* User interface to check an instruction status. UPM and exceptions659* are handled automatically. However, this function does NOT wait660* for an active instruction to complete.661*662*/663static inline int gru_check_status(void *cb)664{665struct gru_control_block_status *cbs = (void *)cb;666int ret;667668ret = cbs->istatus;669if (ret != CBS_ACTIVE)670ret = gru_check_status_proc(cb);671return ret;672}673674/*675* User interface (via inline function) to wait for an instruction676* to complete. Completion status (IDLE or EXCEPTION is returned677* to the user. Exception due to hardware errors are automatically678* retried before returning an exception.679*680*/681static inline int gru_wait(void *cb)682{683return gru_wait_proc(cb);684}685686/*687* Wait for CB to complete. Aborts program if error. (Note: error does NOT688* mean TLB mis - only fatal errors such as memory parity error or user689* bugs will cause termination.690*/691static inline void gru_wait_abort(void *cb)692{693gru_wait_abort_proc(cb);694}695696/*697* Get a pointer to the start of a gseg698* p - Any valid pointer within the gseg699*/700static inline void *gru_get_gseg_pointer (void *p)701{702return (void *)((unsigned long)p & ~(GRU_GSEG_PAGESIZE - 1));703}704705/*706* Get a pointer to a control block707* gseg - GSeg address returned from gru_get_thread_gru_segment()708* index - index of desired CB709*/710static inline void *gru_get_cb_pointer(void *gseg,711int index)712{713return gseg + GRU_CB_BASE + index * GRU_HANDLE_STRIDE;714}715716/*717* Get a pointer to a cacheline in the data segment portion of a GSeg718* gseg - GSeg address returned from gru_get_thread_gru_segment()719* index - index of desired cache line720*/721static inline void *gru_get_data_pointer(void *gseg, int index)722{723return gseg + GRU_DS_BASE + index * GRU_CACHE_LINE_BYTES;724}725726/*727* Convert a vaddr into the tri index within the GSEG728* vaddr - virtual address of within gseg729*/730static inline int gru_get_tri(void *vaddr)731{732return ((unsigned long)vaddr & (GRU_GSEG_PAGESIZE - 1)) - GRU_DS_BASE;733}734#endif /* __GRU_INSTRUCTIONS_H__ */735736737