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