gru_instructions.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. /*
  2. * Copyright (c) 2008 Silicon Graphics, Inc. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU Lesser General Public License as published by
  6. * the Free Software Foundation; either version 2.1 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. #ifndef __GRU_INSTRUCTIONS_H__
  19. #define __GRU_INSTRUCTIONS_H__
  20. extern int gru_check_status_proc(void *cb);
  21. extern int gru_wait_proc(void *cb);
  22. extern void gru_wait_abort_proc(void *cb);
  23. /*
  24. * Architecture dependent functions
  25. */
  26. #if defined(CONFIG_IA64)
  27. #include <linux/compiler.h>
  28. #include <asm/intrinsics.h>
  29. #define __flush_cache(p) ia64_fc((unsigned long)p)
  30. /* Use volatile on IA64 to ensure ordering via st4.rel */
  31. #define gru_ordered_store_ulong(p, v) \
  32. do { \
  33. barrier(); \
  34. *((volatile unsigned long *)(p)) = v; /* force st.rel */ \
  35. } while (0)
  36. #elif defined(CONFIG_X86_64)
  37. #include <asm/cacheflush.h>
  38. #define __flush_cache(p) clflush(p)
  39. #define gru_ordered_store_ulong(p, v) \
  40. do { \
  41. barrier(); \
  42. *(unsigned long *)p = v; \
  43. } while (0)
  44. #else
  45. #error "Unsupported architecture"
  46. #endif
  47. /*
  48. * Control block status and exception codes
  49. */
  50. #define CBS_IDLE 0
  51. #define CBS_EXCEPTION 1
  52. #define CBS_ACTIVE 2
  53. #define CBS_CALL_OS 3
  54. /* CB substatus bitmasks */
  55. #define CBSS_MSG_QUEUE_MASK 7
  56. #define CBSS_IMPLICIT_ABORT_ACTIVE_MASK 8
  57. /* CB substatus message queue values (low 3 bits of substatus) */
  58. #define CBSS_NO_ERROR 0
  59. #define CBSS_LB_OVERFLOWED 1
  60. #define CBSS_QLIMIT_REACHED 2
  61. #define CBSS_PAGE_OVERFLOW 3
  62. #define CBSS_AMO_NACKED 4
  63. #define CBSS_PUT_NACKED 5
  64. /*
  65. * Structure used to fetch exception detail for CBs that terminate with
  66. * CBS_EXCEPTION
  67. */
  68. struct control_block_extended_exc_detail {
  69. unsigned long cb;
  70. int opc;
  71. int ecause;
  72. int exopc;
  73. long exceptdet0;
  74. int exceptdet1;
  75. int cbrstate;
  76. int cbrexecstatus;
  77. };
  78. /*
  79. * Instruction formats
  80. */
  81. /*
  82. * Generic instruction format.
  83. * This definition has precise bit field definitions.
  84. */
  85. struct gru_instruction_bits {
  86. /* DW 0 - low */
  87. unsigned int icmd: 1;
  88. unsigned char ima: 3; /* CB_DelRep, unmapped mode */
  89. unsigned char reserved0: 4;
  90. unsigned int xtype: 3;
  91. unsigned int iaa0: 2;
  92. unsigned int iaa1: 2;
  93. unsigned char reserved1: 1;
  94. unsigned char opc: 8; /* opcode */
  95. unsigned char exopc: 8; /* extended opcode */
  96. /* DW 0 - high */
  97. unsigned int idef2: 22; /* TRi0 */
  98. unsigned char reserved2: 2;
  99. unsigned char istatus: 2;
  100. unsigned char isubstatus:4;
  101. unsigned char reserved3: 1;
  102. unsigned char tlb_fault_color: 1;
  103. /* DW 1 */
  104. unsigned long idef4; /* 42 bits: TRi1, BufSize */
  105. /* DW 2-6 */
  106. unsigned long idef1; /* BAddr0 */
  107. unsigned long idef5; /* Nelem */
  108. unsigned long idef6; /* Stride, Operand1 */
  109. unsigned long idef3; /* BAddr1, Value, Operand2 */
  110. unsigned long reserved4;
  111. /* DW 7 */
  112. unsigned long avalue; /* AValue */
  113. };
  114. /*
  115. * Generic instruction with friendlier names. This format is used
  116. * for inline instructions.
  117. */
  118. struct gru_instruction {
  119. /* DW 0 */
  120. union {
  121. unsigned long op64; /* icmd,xtype,iaa0,ima,opc,tri0 */
  122. struct {
  123. unsigned int op32;
  124. unsigned int tri0;
  125. };
  126. };
  127. unsigned long tri1_bufsize; /* DW 1 */
  128. unsigned long baddr0; /* DW 2 */
  129. unsigned long nelem; /* DW 3 */
  130. unsigned long op1_stride; /* DW 4 */
  131. unsigned long op2_value_baddr1; /* DW 5 */
  132. unsigned long reserved0; /* DW 6 */
  133. unsigned long avalue; /* DW 7 */
  134. };
  135. /* Some shifts and masks for the low 64 bits of a GRU command */
  136. #define GRU_CB_ICMD_SHFT 0
  137. #define GRU_CB_ICMD_MASK 0x1
  138. #define GRU_CB_XTYPE_SHFT 8
  139. #define GRU_CB_XTYPE_MASK 0x7
  140. #define GRU_CB_IAA0_SHFT 11
  141. #define GRU_CB_IAA0_MASK 0x3
  142. #define GRU_CB_IAA1_SHFT 13
  143. #define GRU_CB_IAA1_MASK 0x3
  144. #define GRU_CB_IMA_SHFT 1
  145. #define GRU_CB_IMA_MASK 0x3
  146. #define GRU_CB_OPC_SHFT 16
  147. #define GRU_CB_OPC_MASK 0xff
  148. #define GRU_CB_EXOPC_SHFT 24
  149. #define GRU_CB_EXOPC_MASK 0xff
  150. #define GRU_IDEF2_SHFT 32
  151. #define GRU_IDEF2_MASK 0x3ffff
  152. #define GRU_ISTATUS_SHFT 56
  153. #define GRU_ISTATUS_MASK 0x3
  154. /* GRU instruction opcodes (opc field) */
  155. #define OP_NOP 0x00
  156. #define OP_BCOPY 0x01
  157. #define OP_VLOAD 0x02
  158. #define OP_IVLOAD 0x03
  159. #define OP_VSTORE 0x04
  160. #define OP_IVSTORE 0x05
  161. #define OP_VSET 0x06
  162. #define OP_IVSET 0x07
  163. #define OP_MESQ 0x08
  164. #define OP_GAMXR 0x09
  165. #define OP_GAMIR 0x0a
  166. #define OP_GAMIRR 0x0b
  167. #define OP_GAMER 0x0c
  168. #define OP_GAMERR 0x0d
  169. #define OP_BSTORE 0x0e
  170. #define OP_VFLUSH 0x0f
  171. /* Extended opcodes values (exopc field) */
  172. /* GAMIR - AMOs with implicit operands */
  173. #define EOP_IR_FETCH 0x01 /* Plain fetch of memory */
  174. #define EOP_IR_CLR 0x02 /* Fetch and clear */
  175. #define EOP_IR_INC 0x05 /* Fetch and increment */
  176. #define EOP_IR_DEC 0x07 /* Fetch and decrement */
  177. #define EOP_IR_QCHK1 0x0d /* Queue check, 64 byte msg */
  178. #define EOP_IR_QCHK2 0x0e /* Queue check, 128 byte msg */
  179. /* GAMIRR - Registered AMOs with implicit operands */
  180. #define EOP_IRR_FETCH 0x01 /* Registered fetch of memory */
  181. #define EOP_IRR_CLR 0x02 /* Registered fetch and clear */
  182. #define EOP_IRR_INC 0x05 /* Registered fetch and increment */
  183. #define EOP_IRR_DEC 0x07 /* Registered fetch and decrement */
  184. #define EOP_IRR_DECZ 0x0f /* Registered fetch and decrement, update on zero*/
  185. /* GAMER - AMOs with explicit operands */
  186. #define EOP_ER_SWAP 0x00 /* Exchange argument and memory */
  187. #define EOP_ER_OR 0x01 /* Logical OR with memory */
  188. #define EOP_ER_AND 0x02 /* Logical AND with memory */
  189. #define EOP_ER_XOR 0x03 /* Logical XOR with memory */
  190. #define EOP_ER_ADD 0x04 /* Add value to memory */
  191. #define EOP_ER_CSWAP 0x08 /* Compare with operand2, write operand1 if match*/
  192. #define EOP_ER_CADD 0x0c /* Queue check, operand1*64 byte msg */
  193. /* GAMERR - Registered AMOs with explicit operands */
  194. #define EOP_ERR_SWAP 0x00 /* Exchange argument and memory */
  195. #define EOP_ERR_OR 0x01 /* Logical OR with memory */
  196. #define EOP_ERR_AND 0x02 /* Logical AND with memory */
  197. #define EOP_ERR_XOR 0x03 /* Logical XOR with memory */
  198. #define EOP_ERR_ADD 0x04 /* Add value to memory */
  199. #define EOP_ERR_CSWAP 0x08 /* Compare with operand2, write operand1 if match*/
  200. #define EOP_ERR_EPOLL 0x09 /* Poll for equality */
  201. #define EOP_ERR_NPOLL 0x0a /* Poll for inequality */
  202. /* GAMXR - SGI Arithmetic unit */
  203. #define EOP_XR_CSWAP 0x0b /* Masked compare exchange */
  204. /* Transfer types (xtype field) */
  205. #define XTYPE_B 0x0 /* byte */
  206. #define XTYPE_S 0x1 /* short (2-byte) */
  207. #define XTYPE_W 0x2 /* word (4-byte) */
  208. #define XTYPE_DW 0x3 /* doubleword (8-byte) */
  209. #define XTYPE_CL 0x6 /* cacheline (64-byte) */
  210. /* Instruction access attributes (iaa0, iaa1 fields) */
  211. #define IAA_RAM 0x0 /* normal cached RAM access */
  212. #define IAA_NCRAM 0x2 /* noncoherent RAM access */
  213. #define IAA_MMIO 0x1 /* noncoherent memory-mapped I/O space */
  214. #define IAA_REGISTER 0x3 /* memory-mapped registers, etc. */
  215. /* Instruction mode attributes (ima field) */
  216. #define IMA_MAPPED 0x0 /* Virtual mode */
  217. #define IMA_CB_DELAY 0x1 /* hold read responses until status changes */
  218. #define IMA_UNMAPPED 0x2 /* bypass the TLBs (OS only) */
  219. #define IMA_INTERRUPT 0x4 /* Interrupt when instruction completes */
  220. /* CBE ecause bits */
  221. #define CBE_CAUSE_RI (1 << 0)
  222. #define CBE_CAUSE_INVALID_INSTRUCTION (1 << 1)
  223. #define CBE_CAUSE_UNMAPPED_MODE_FORBIDDEN (1 << 2)
  224. #define CBE_CAUSE_PE_CHECK_DATA_ERROR (1 << 3)
  225. #define CBE_CAUSE_IAA_GAA_MISMATCH (1 << 4)
  226. #define CBE_CAUSE_DATA_SEGMENT_LIMIT_EXCEPTION (1 << 5)
  227. #define CBE_CAUSE_OS_FATAL_TLB_FAULT (1 << 6)
  228. #define CBE_CAUSE_EXECUTION_HW_ERROR (1 << 7)
  229. #define CBE_CAUSE_TLBHW_ERROR (1 << 8)
  230. #define CBE_CAUSE_RA_REQUEST_TIMEOUT (1 << 9)
  231. #define CBE_CAUSE_HA_REQUEST_TIMEOUT (1 << 10)
  232. #define CBE_CAUSE_RA_RESPONSE_FATAL (1 << 11)
  233. #define CBE_CAUSE_RA_RESPONSE_NON_FATAL (1 << 12)
  234. #define CBE_CAUSE_HA_RESPONSE_FATAL (1 << 13)
  235. #define CBE_CAUSE_HA_RESPONSE_NON_FATAL (1 << 14)
  236. #define CBE_CAUSE_ADDRESS_SPACE_DECODE_ERROR (1 << 15)
  237. #define CBE_CAUSE_PROTOCOL_STATE_DATA_ERROR (1 << 16)
  238. #define CBE_CAUSE_RA_RESPONSE_DATA_ERROR (1 << 17)
  239. #define CBE_CAUSE_HA_RESPONSE_DATA_ERROR (1 << 18)
  240. #define CBE_CAUSE_FORCED_ERROR (1 << 19)
  241. /* CBE cbrexecstatus bits */
  242. #define CBR_EXS_ABORT_OCC_BIT 0
  243. #define CBR_EXS_INT_OCC_BIT 1
  244. #define CBR_EXS_PENDING_BIT 2
  245. #define CBR_EXS_QUEUED_BIT 3
  246. #define CBR_EXS_TLB_INVAL_BIT 4
  247. #define CBR_EXS_EXCEPTION_BIT 5
  248. #define CBR_EXS_CB_INT_PENDING_BIT 6
  249. #define CBR_EXS_ABORT_OCC (1 << CBR_EXS_ABORT_OCC_BIT)
  250. #define CBR_EXS_INT_OCC (1 << CBR_EXS_INT_OCC_BIT)
  251. #define CBR_EXS_PENDING (1 << CBR_EXS_PENDING_BIT)
  252. #define CBR_EXS_QUEUED (1 << CBR_EXS_QUEUED_BIT)
  253. #define CBR_EXS_TLB_INVAL (1 << CBR_EXS_TLB_INVAL_BIT)
  254. #define CBR_EXS_EXCEPTION (1 << CBR_EXS_EXCEPTION_BIT)
  255. #define CBR_EXS_CB_INT_PENDING (1 << CBR_EXS_CB_INT_PENDING_BIT)
  256. /*
  257. * Exceptions are retried for the following cases. If any OTHER bits are set
  258. * in ecause, the exception is not retryable.
  259. */
  260. #define EXCEPTION_RETRY_BITS (CBE_CAUSE_EXECUTION_HW_ERROR | \
  261. CBE_CAUSE_TLBHW_ERROR | \
  262. CBE_CAUSE_RA_REQUEST_TIMEOUT | \
  263. CBE_CAUSE_RA_RESPONSE_NON_FATAL | \
  264. CBE_CAUSE_HA_RESPONSE_NON_FATAL | \
  265. CBE_CAUSE_RA_RESPONSE_DATA_ERROR | \
  266. CBE_CAUSE_HA_RESPONSE_DATA_ERROR \
  267. )
  268. /* Message queue head structure */
  269. union gru_mesqhead {
  270. unsigned long val;
  271. struct {
  272. unsigned int head;
  273. unsigned int limit;
  274. };
  275. };
  276. /* Generate the low word of a GRU instruction */
  277. static inline unsigned long
  278. __opdword(unsigned char opcode, unsigned char exopc, unsigned char xtype,
  279. unsigned char iaa0, unsigned char iaa1,
  280. unsigned long idef2, unsigned char ima)
  281. {
  282. return (1 << GRU_CB_ICMD_SHFT) |
  283. ((unsigned long)CBS_ACTIVE << GRU_ISTATUS_SHFT) |
  284. (idef2<< GRU_IDEF2_SHFT) |
  285. (iaa0 << GRU_CB_IAA0_SHFT) |
  286. (iaa1 << GRU_CB_IAA1_SHFT) |
  287. (ima << GRU_CB_IMA_SHFT) |
  288. (xtype << GRU_CB_XTYPE_SHFT) |
  289. (opcode << GRU_CB_OPC_SHFT) |
  290. (exopc << GRU_CB_EXOPC_SHFT);
  291. }
  292. /*
  293. * Architecture specific intrinsics
  294. */
  295. static inline void gru_flush_cache(void *p)
  296. {
  297. __flush_cache(p);
  298. }
  299. /*
  300. * Store the lower 64 bits of the command including the "start" bit. Then
  301. * start the instruction executing.
  302. */
  303. static inline void gru_start_instruction(struct gru_instruction *ins, unsigned long op64)
  304. {
  305. gru_ordered_store_ulong(ins, op64);
  306. mb();
  307. gru_flush_cache(ins);
  308. }
  309. /* Convert "hints" to IMA */
  310. #define CB_IMA(h) ((h) | IMA_UNMAPPED)
  311. /* Convert data segment cache line index into TRI0 / TRI1 value */
  312. #define GRU_DINDEX(i) ((i) * GRU_CACHE_LINE_BYTES)
  313. /* Inline functions for GRU instructions.
  314. * Note:
  315. * - nelem and stride are in elements
  316. * - tri0/tri1 is in bytes for the beginning of the data segment.
  317. */
  318. static inline void gru_vload_phys(void *cb, unsigned long gpa,
  319. unsigned int tri0, int iaa, unsigned long hints)
  320. {
  321. struct gru_instruction *ins = (struct gru_instruction *)cb;
  322. ins->baddr0 = (long)gpa | ((unsigned long)iaa << 62);
  323. ins->nelem = 1;
  324. ins->op1_stride = 1;
  325. gru_start_instruction(ins, __opdword(OP_VLOAD, 0, XTYPE_DW, iaa, 0,
  326. (unsigned long)tri0, CB_IMA(hints)));
  327. }
  328. static inline void gru_vstore_phys(void *cb, unsigned long gpa,
  329. unsigned int tri0, int iaa, unsigned long hints)
  330. {
  331. struct gru_instruction *ins = (struct gru_instruction *)cb;
  332. ins->baddr0 = (long)gpa | ((unsigned long)iaa << 62);
  333. ins->nelem = 1;
  334. ins->op1_stride = 1;
  335. gru_start_instruction(ins, __opdword(OP_VSTORE, 0, XTYPE_DW, iaa, 0,
  336. (unsigned long)tri0, CB_IMA(hints)));
  337. }
  338. static inline void gru_vload(void *cb, unsigned long mem_addr,
  339. unsigned int tri0, unsigned char xtype, unsigned long nelem,
  340. unsigned long stride, unsigned long hints)
  341. {
  342. struct gru_instruction *ins = (struct gru_instruction *)cb;
  343. ins->baddr0 = (long)mem_addr;
  344. ins->nelem = nelem;
  345. ins->op1_stride = stride;
  346. gru_start_instruction(ins, __opdword(OP_VLOAD, 0, xtype, IAA_RAM, 0,
  347. (unsigned long)tri0, CB_IMA(hints)));
  348. }
  349. static inline void gru_vstore(void *cb, unsigned long mem_addr,
  350. unsigned int tri0, unsigned char xtype, unsigned long nelem,
  351. unsigned long stride, unsigned long hints)
  352. {
  353. struct gru_instruction *ins = (void *)cb;
  354. ins->baddr0 = (long)mem_addr;
  355. ins->nelem = nelem;
  356. ins->op1_stride = stride;
  357. gru_start_instruction(ins, __opdword(OP_VSTORE, 0, xtype, IAA_RAM, 0,
  358. tri0, CB_IMA(hints)));
  359. }
  360. static inline void gru_ivload(void *cb, unsigned long mem_addr,
  361. unsigned int tri0, unsigned int tri1, unsigned char xtype,
  362. unsigned long nelem, unsigned long hints)
  363. {
  364. struct gru_instruction *ins = (void *)cb;
  365. ins->baddr0 = (long)mem_addr;
  366. ins->nelem = nelem;
  367. ins->tri1_bufsize = tri1;
  368. gru_start_instruction(ins, __opdword(OP_IVLOAD, 0, xtype, IAA_RAM, 0,
  369. tri0, CB_IMA(hints)));
  370. }
  371. static inline void gru_ivstore(void *cb, unsigned long mem_addr,
  372. unsigned int tri0, unsigned int tri1,
  373. unsigned char xtype, unsigned long nelem, unsigned long hints)
  374. {
  375. struct gru_instruction *ins = (void *)cb;
  376. ins->baddr0 = (long)mem_addr;
  377. ins->nelem = nelem;
  378. ins->tri1_bufsize = tri1;
  379. gru_start_instruction(ins, __opdword(OP_IVSTORE, 0, xtype, IAA_RAM, 0,
  380. tri0, CB_IMA(hints)));
  381. }
  382. static inline void gru_vset(void *cb, unsigned long mem_addr,
  383. unsigned long value, unsigned char xtype, unsigned long nelem,
  384. unsigned long stride, unsigned long hints)
  385. {
  386. struct gru_instruction *ins = (void *)cb;
  387. ins->baddr0 = (long)mem_addr;
  388. ins->op2_value_baddr1 = value;
  389. ins->nelem = nelem;
  390. ins->op1_stride = stride;
  391. gru_start_instruction(ins, __opdword(OP_VSET, 0, xtype, IAA_RAM, 0,
  392. 0, CB_IMA(hints)));
  393. }
  394. static inline void gru_ivset(void *cb, unsigned long mem_addr,
  395. unsigned int tri1, unsigned long value, unsigned char xtype,
  396. unsigned long nelem, unsigned long hints)
  397. {
  398. struct gru_instruction *ins = (void *)cb;
  399. ins->baddr0 = (long)mem_addr;
  400. ins->op2_value_baddr1 = value;
  401. ins->nelem = nelem;
  402. ins->tri1_bufsize = tri1;
  403. gru_start_instruction(ins, __opdword(OP_IVSET, 0, xtype, IAA_RAM, 0,
  404. 0, CB_IMA(hints)));
  405. }
  406. static inline void gru_vflush(void *cb, unsigned long mem_addr,
  407. unsigned long nelem, unsigned char xtype, unsigned long stride,
  408. unsigned long hints)
  409. {
  410. struct gru_instruction *ins = (void *)cb;
  411. ins->baddr0 = (long)mem_addr;
  412. ins->op1_stride = stride;
  413. ins->nelem = nelem;
  414. gru_start_instruction(ins, __opdword(OP_VFLUSH, 0, xtype, IAA_RAM, 0,
  415. 0, CB_IMA(hints)));
  416. }
  417. static inline void gru_nop(void *cb, int hints)
  418. {
  419. struct gru_instruction *ins = (void *)cb;
  420. gru_start_instruction(ins, __opdword(OP_NOP, 0, 0, 0, 0, 0, CB_IMA(hints)));
  421. }
  422. static inline void gru_bcopy(void *cb, const unsigned long src,
  423. unsigned long dest,
  424. unsigned int tri0, unsigned int xtype, unsigned long nelem,
  425. unsigned int bufsize, unsigned long hints)
  426. {
  427. struct gru_instruction *ins = (void *)cb;
  428. ins->baddr0 = (long)src;
  429. ins->op2_value_baddr1 = (long)dest;
  430. ins->nelem = nelem;
  431. ins->tri1_bufsize = bufsize;
  432. gru_start_instruction(ins, __opdword(OP_BCOPY, 0, xtype, IAA_RAM,
  433. IAA_RAM, tri0, CB_IMA(hints)));
  434. }
  435. static inline void gru_bstore(void *cb, const unsigned long src,
  436. unsigned long dest, unsigned int tri0, unsigned int xtype,
  437. unsigned long nelem, unsigned long hints)
  438. {
  439. struct gru_instruction *ins = (void *)cb;
  440. ins->baddr0 = (long)src;
  441. ins->op2_value_baddr1 = (long)dest;
  442. ins->nelem = nelem;
  443. gru_start_instruction(ins, __opdword(OP_BSTORE, 0, xtype, 0, IAA_RAM,
  444. tri0, CB_IMA(hints)));
  445. }
  446. static inline void gru_gamir(void *cb, int exopc, unsigned long src,
  447. unsigned int xtype, unsigned long hints)
  448. {
  449. struct gru_instruction *ins = (void *)cb;
  450. ins->baddr0 = (long)src;
  451. gru_start_instruction(ins, __opdword(OP_GAMIR, exopc, xtype, IAA_RAM, 0,
  452. 0, CB_IMA(hints)));
  453. }
  454. static inline void gru_gamirr(void *cb, int exopc, unsigned long src,
  455. unsigned int xtype, unsigned long hints)
  456. {
  457. struct gru_instruction *ins = (void *)cb;
  458. ins->baddr0 = (long)src;
  459. gru_start_instruction(ins, __opdword(OP_GAMIRR, exopc, xtype, IAA_RAM, 0,
  460. 0, CB_IMA(hints)));
  461. }
  462. static inline void gru_gamer(void *cb, int exopc, unsigned long src,
  463. unsigned int xtype,
  464. unsigned long operand1, unsigned long operand2,
  465. unsigned long hints)
  466. {
  467. struct gru_instruction *ins = (void *)cb;
  468. ins->baddr0 = (long)src;
  469. ins->op1_stride = operand1;
  470. ins->op2_value_baddr1 = operand2;
  471. gru_start_instruction(ins, __opdword(OP_GAMER, exopc, xtype, IAA_RAM, 0,
  472. 0, CB_IMA(hints)));
  473. }
  474. static inline void gru_gamerr(void *cb, int exopc, unsigned long src,
  475. unsigned int xtype, unsigned long operand1,
  476. unsigned long operand2, unsigned long hints)
  477. {
  478. struct gru_instruction *ins = (void *)cb;
  479. ins->baddr0 = (long)src;
  480. ins->op1_stride = operand1;
  481. ins->op2_value_baddr1 = operand2;
  482. gru_start_instruction(ins, __opdword(OP_GAMERR, exopc, xtype, IAA_RAM, 0,
  483. 0, CB_IMA(hints)));
  484. }
  485. static inline void gru_gamxr(void *cb, unsigned long src,
  486. unsigned int tri0, unsigned long hints)
  487. {
  488. struct gru_instruction *ins = (void *)cb;
  489. ins->baddr0 = (long)src;
  490. ins->nelem = 4;
  491. gru_start_instruction(ins, __opdword(OP_GAMXR, EOP_XR_CSWAP, XTYPE_DW,
  492. IAA_RAM, 0, 0, CB_IMA(hints)));
  493. }
  494. static inline void gru_mesq(void *cb, unsigned long queue,
  495. unsigned long tri0, unsigned long nelem,
  496. unsigned long hints)
  497. {
  498. struct gru_instruction *ins = (void *)cb;
  499. ins->baddr0 = (long)queue;
  500. ins->nelem = nelem;
  501. gru_start_instruction(ins, __opdword(OP_MESQ, 0, XTYPE_CL, IAA_RAM, 0,
  502. tri0, CB_IMA(hints)));
  503. }
  504. static inline unsigned long gru_get_amo_value(void *cb)
  505. {
  506. struct gru_instruction *ins = (void *)cb;
  507. return ins->avalue;
  508. }
  509. static inline int gru_get_amo_value_head(void *cb)
  510. {
  511. struct gru_instruction *ins = (void *)cb;
  512. return ins->avalue & 0xffffffff;
  513. }
  514. static inline int gru_get_amo_value_limit(void *cb)
  515. {
  516. struct gru_instruction *ins = (void *)cb;
  517. return ins->avalue >> 32;
  518. }
  519. static inline union gru_mesqhead gru_mesq_head(int head, int limit)
  520. {
  521. union gru_mesqhead mqh;
  522. mqh.head = head;
  523. mqh.limit = limit;
  524. return mqh;
  525. }
  526. /*
  527. * Get struct control_block_extended_exc_detail for CB.
  528. */
  529. extern int gru_get_cb_exception_detail(void *cb,
  530. struct control_block_extended_exc_detail *excdet);
  531. #define GRU_EXC_STR_SIZE 256
  532. /*
  533. * Control block definition for checking status
  534. */
  535. struct gru_control_block_status {
  536. unsigned int icmd :1;
  537. unsigned int ima :3;
  538. unsigned int reserved0 :4;
  539. unsigned int unused1 :24;
  540. unsigned int unused2 :24;
  541. unsigned int istatus :2;
  542. unsigned int isubstatus :4;
  543. unsigned int unused3 :2;
  544. };
  545. /* Get CB status */
  546. static inline int gru_get_cb_status(void *cb)
  547. {
  548. struct gru_control_block_status *cbs = (void *)cb;
  549. return cbs->istatus;
  550. }
  551. /* Get CB message queue substatus */
  552. static inline int gru_get_cb_message_queue_substatus(void *cb)
  553. {
  554. struct gru_control_block_status *cbs = (void *)cb;
  555. return cbs->isubstatus & CBSS_MSG_QUEUE_MASK;
  556. }
  557. /* Get CB substatus */
  558. static inline int gru_get_cb_substatus(void *cb)
  559. {
  560. struct gru_control_block_status *cbs = (void *)cb;
  561. return cbs->isubstatus;
  562. }
  563. /*
  564. * User interface to check an instruction status. UPM and exceptions
  565. * are handled automatically. However, this function does NOT wait
  566. * for an active instruction to complete.
  567. *
  568. */
  569. static inline int gru_check_status(void *cb)
  570. {
  571. struct gru_control_block_status *cbs = (void *)cb;
  572. int ret;
  573. ret = cbs->istatus;
  574. if (ret != CBS_ACTIVE)
  575. ret = gru_check_status_proc(cb);
  576. return ret;
  577. }
  578. /*
  579. * User interface (via inline function) to wait for an instruction
  580. * to complete. Completion status (IDLE or EXCEPTION is returned
  581. * to the user. Exception due to hardware errors are automatically
  582. * retried before returning an exception.
  583. *
  584. */
  585. static inline int gru_wait(void *cb)
  586. {
  587. return gru_wait_proc(cb);
  588. }
  589. /*
  590. * Wait for CB to complete. Aborts program if error. (Note: error does NOT
  591. * mean TLB mis - only fatal errors such as memory parity error or user
  592. * bugs will cause termination.
  593. */
  594. static inline void gru_wait_abort(void *cb)
  595. {
  596. gru_wait_abort_proc(cb);
  597. }
  598. /*
  599. * Get a pointer to the start of a gseg
  600. * p - Any valid pointer within the gseg
  601. */
  602. static inline void *gru_get_gseg_pointer (void *p)
  603. {
  604. return (void *)((unsigned long)p & ~(GRU_GSEG_PAGESIZE - 1));
  605. }
  606. /*
  607. * Get a pointer to a control block
  608. * gseg - GSeg address returned from gru_get_thread_gru_segment()
  609. * index - index of desired CB
  610. */
  611. static inline void *gru_get_cb_pointer(void *gseg,
  612. int index)
  613. {
  614. return gseg + GRU_CB_BASE + index * GRU_HANDLE_STRIDE;
  615. }
  616. /*
  617. * Get a pointer to a cacheline in the data segment portion of a GSeg
  618. * gseg - GSeg address returned from gru_get_thread_gru_segment()
  619. * index - index of desired cache line
  620. */
  621. static inline void *gru_get_data_pointer(void *gseg, int index)
  622. {
  623. return gseg + GRU_DS_BASE + index * GRU_CACHE_LINE_BYTES;
  624. }
  625. /*
  626. * Convert a vaddr into the tri index within the GSEG
  627. * vaddr - virtual address of within gseg
  628. */
  629. static inline int gru_get_tri(void *vaddr)
  630. {
  631. return ((unsigned long)vaddr & (GRU_GSEG_PAGESIZE - 1)) - GRU_DS_BASE;
  632. }
  633. #endif /* __GRU_INSTRUCTIONS_H__ */