18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * SN Platform GRU Driver
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci *              GRU HANDLE DEFINITION
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci *  Copyright (c) 2008 Silicon Graphics, Inc.  All Rights Reserved.
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#ifndef __GRUHANDLES_H__
118c2ecf20Sopenharmony_ci#define __GRUHANDLES_H__
128c2ecf20Sopenharmony_ci#include "gru_instructions.h"
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci/*
158c2ecf20Sopenharmony_ci * Manifest constants for GRU Memory Map
168c2ecf20Sopenharmony_ci */
178c2ecf20Sopenharmony_ci#define GRU_GSEG0_BASE		0
188c2ecf20Sopenharmony_ci#define GRU_MCS_BASE		(64 * 1024 * 1024)
198c2ecf20Sopenharmony_ci#define GRU_SIZE		(128UL * 1024 * 1024)
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci/* Handle & resource counts */
228c2ecf20Sopenharmony_ci#define GRU_NUM_CB		128
238c2ecf20Sopenharmony_ci#define GRU_NUM_DSR_BYTES	(32 * 1024)
248c2ecf20Sopenharmony_ci#define GRU_NUM_TFM		16
258c2ecf20Sopenharmony_ci#define GRU_NUM_TGH		24
268c2ecf20Sopenharmony_ci#define GRU_NUM_CBE		128
278c2ecf20Sopenharmony_ci#define GRU_NUM_TFH		128
288c2ecf20Sopenharmony_ci#define GRU_NUM_CCH		16
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci/* Maximum resource counts that can be reserved by user programs */
318c2ecf20Sopenharmony_ci#define GRU_NUM_USER_CBR	GRU_NUM_CBE
328c2ecf20Sopenharmony_ci#define GRU_NUM_USER_DSR_BYTES	GRU_NUM_DSR_BYTES
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci/* Bytes per handle & handle stride. Code assumes all cb, tfh, cbe handles
358c2ecf20Sopenharmony_ci * are the same */
368c2ecf20Sopenharmony_ci#define GRU_HANDLE_BYTES	64
378c2ecf20Sopenharmony_ci#define GRU_HANDLE_STRIDE	256
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci/* Base addresses of handles */
408c2ecf20Sopenharmony_ci#define GRU_TFM_BASE		(GRU_MCS_BASE + 0x00000)
418c2ecf20Sopenharmony_ci#define GRU_TGH_BASE		(GRU_MCS_BASE + 0x08000)
428c2ecf20Sopenharmony_ci#define GRU_CBE_BASE		(GRU_MCS_BASE + 0x10000)
438c2ecf20Sopenharmony_ci#define GRU_TFH_BASE		(GRU_MCS_BASE + 0x18000)
448c2ecf20Sopenharmony_ci#define GRU_CCH_BASE		(GRU_MCS_BASE + 0x20000)
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci/* User gseg constants */
478c2ecf20Sopenharmony_ci#define GRU_GSEG_STRIDE		(4 * 1024 * 1024)
488c2ecf20Sopenharmony_ci#define GSEG_BASE(a)		((a) & ~(GRU_GSEG_PAGESIZE - 1))
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci/* Data segment constants */
518c2ecf20Sopenharmony_ci#define GRU_DSR_AU_BYTES	1024
528c2ecf20Sopenharmony_ci#define GRU_DSR_CL		(GRU_NUM_DSR_BYTES / GRU_CACHE_LINE_BYTES)
538c2ecf20Sopenharmony_ci#define GRU_DSR_AU_CL		(GRU_DSR_AU_BYTES / GRU_CACHE_LINE_BYTES)
548c2ecf20Sopenharmony_ci#define GRU_DSR_AU		(GRU_NUM_DSR_BYTES / GRU_DSR_AU_BYTES)
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci/* Control block constants */
578c2ecf20Sopenharmony_ci#define GRU_CBR_AU_SIZE		2
588c2ecf20Sopenharmony_ci#define GRU_CBR_AU		(GRU_NUM_CBE / GRU_CBR_AU_SIZE)
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci/* Convert resource counts to the number of AU */
618c2ecf20Sopenharmony_ci#define GRU_DS_BYTES_TO_AU(n)	DIV_ROUND_UP(n, GRU_DSR_AU_BYTES)
628c2ecf20Sopenharmony_ci#define GRU_CB_COUNT_TO_AU(n)	DIV_ROUND_UP(n, GRU_CBR_AU_SIZE)
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci/* UV limits */
658c2ecf20Sopenharmony_ci#define GRU_CHIPLETS_PER_HUB	2
668c2ecf20Sopenharmony_ci#define GRU_HUBS_PER_BLADE	1
678c2ecf20Sopenharmony_ci#define GRU_CHIPLETS_PER_BLADE	(GRU_HUBS_PER_BLADE * GRU_CHIPLETS_PER_HUB)
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci/* User GRU Gseg offsets */
708c2ecf20Sopenharmony_ci#define GRU_CB_BASE		0
718c2ecf20Sopenharmony_ci#define GRU_CB_LIMIT		(GRU_CB_BASE + GRU_HANDLE_STRIDE * GRU_NUM_CBE)
728c2ecf20Sopenharmony_ci#define GRU_DS_BASE		0x20000
738c2ecf20Sopenharmony_ci#define GRU_DS_LIMIT		(GRU_DS_BASE + GRU_NUM_DSR_BYTES)
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci/* Convert a GRU physical address to the chiplet offset */
768c2ecf20Sopenharmony_ci#define GSEGPOFF(h) 		((h) & (GRU_SIZE - 1))
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci/* Convert an arbitrary handle address to the beginning of the GRU segment */
798c2ecf20Sopenharmony_ci#define GRUBASE(h)		((void *)((unsigned long)(h) & ~(GRU_SIZE - 1)))
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci/* Test a valid handle address to determine the type */
828c2ecf20Sopenharmony_ci#define TYPE_IS(hn, h)		((h) >= GRU_##hn##_BASE && (h) <	\
838c2ecf20Sopenharmony_ci		GRU_##hn##_BASE + GRU_NUM_##hn * GRU_HANDLE_STRIDE &&   \
848c2ecf20Sopenharmony_ci		(((h) & (GRU_HANDLE_STRIDE - 1)) == 0))
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci/* General addressing macros. */
888c2ecf20Sopenharmony_cistatic inline void *get_gseg_base_address(void *base, int ctxnum)
898c2ecf20Sopenharmony_ci{
908c2ecf20Sopenharmony_ci	return (void *)(base + GRU_GSEG0_BASE + GRU_GSEG_STRIDE * ctxnum);
918c2ecf20Sopenharmony_ci}
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_cistatic inline void *get_gseg_base_address_cb(void *base, int ctxnum, int line)
948c2ecf20Sopenharmony_ci{
958c2ecf20Sopenharmony_ci	return (void *)(get_gseg_base_address(base, ctxnum) +
968c2ecf20Sopenharmony_ci			GRU_CB_BASE + GRU_HANDLE_STRIDE * line);
978c2ecf20Sopenharmony_ci}
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_cistatic inline void *get_gseg_base_address_ds(void *base, int ctxnum, int line)
1008c2ecf20Sopenharmony_ci{
1018c2ecf20Sopenharmony_ci	return (void *)(get_gseg_base_address(base, ctxnum) + GRU_DS_BASE +
1028c2ecf20Sopenharmony_ci			GRU_CACHE_LINE_BYTES * line);
1038c2ecf20Sopenharmony_ci}
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_cistatic inline struct gru_tlb_fault_map *get_tfm(void *base, int ctxnum)
1068c2ecf20Sopenharmony_ci{
1078c2ecf20Sopenharmony_ci	return (struct gru_tlb_fault_map *)(base + GRU_TFM_BASE +
1088c2ecf20Sopenharmony_ci					ctxnum * GRU_HANDLE_STRIDE);
1098c2ecf20Sopenharmony_ci}
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_cistatic inline struct gru_tlb_global_handle *get_tgh(void *base, int ctxnum)
1128c2ecf20Sopenharmony_ci{
1138c2ecf20Sopenharmony_ci	return (struct gru_tlb_global_handle *)(base + GRU_TGH_BASE +
1148c2ecf20Sopenharmony_ci					ctxnum * GRU_HANDLE_STRIDE);
1158c2ecf20Sopenharmony_ci}
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_cistatic inline struct gru_control_block_extended *get_cbe(void *base, int ctxnum)
1188c2ecf20Sopenharmony_ci{
1198c2ecf20Sopenharmony_ci	return (struct gru_control_block_extended *)(base + GRU_CBE_BASE +
1208c2ecf20Sopenharmony_ci					ctxnum * GRU_HANDLE_STRIDE);
1218c2ecf20Sopenharmony_ci}
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_cistatic inline struct gru_tlb_fault_handle *get_tfh(void *base, int ctxnum)
1248c2ecf20Sopenharmony_ci{
1258c2ecf20Sopenharmony_ci	return (struct gru_tlb_fault_handle *)(base + GRU_TFH_BASE +
1268c2ecf20Sopenharmony_ci					ctxnum * GRU_HANDLE_STRIDE);
1278c2ecf20Sopenharmony_ci}
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_cistatic inline struct gru_context_configuration_handle *get_cch(void *base,
1308c2ecf20Sopenharmony_ci					int ctxnum)
1318c2ecf20Sopenharmony_ci{
1328c2ecf20Sopenharmony_ci	return (struct gru_context_configuration_handle *)(base +
1338c2ecf20Sopenharmony_ci				GRU_CCH_BASE + ctxnum * GRU_HANDLE_STRIDE);
1348c2ecf20Sopenharmony_ci}
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_cistatic inline unsigned long get_cb_number(void *cb)
1378c2ecf20Sopenharmony_ci{
1388c2ecf20Sopenharmony_ci	return (((unsigned long)cb - GRU_CB_BASE) % GRU_GSEG_PAGESIZE) /
1398c2ecf20Sopenharmony_ci					GRU_HANDLE_STRIDE;
1408c2ecf20Sopenharmony_ci}
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci/* byte offset to a specific GRU chiplet. (p=pnode, c=chiplet (0 or 1)*/
1438c2ecf20Sopenharmony_cistatic inline unsigned long gru_chiplet_paddr(unsigned long paddr, int pnode,
1448c2ecf20Sopenharmony_ci							int chiplet)
1458c2ecf20Sopenharmony_ci{
1468c2ecf20Sopenharmony_ci	return paddr + GRU_SIZE * (2 * pnode  + chiplet);
1478c2ecf20Sopenharmony_ci}
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_cistatic inline void *gru_chiplet_vaddr(void *vaddr, int pnode, int chiplet)
1508c2ecf20Sopenharmony_ci{
1518c2ecf20Sopenharmony_ci	return vaddr + GRU_SIZE * (2 * pnode  + chiplet);
1528c2ecf20Sopenharmony_ci}
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_cistatic inline struct gru_control_block_extended *gru_tfh_to_cbe(
1558c2ecf20Sopenharmony_ci					struct gru_tlb_fault_handle *tfh)
1568c2ecf20Sopenharmony_ci{
1578c2ecf20Sopenharmony_ci	unsigned long cbe;
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_ci	cbe = (unsigned long)tfh - GRU_TFH_BASE + GRU_CBE_BASE;
1608c2ecf20Sopenharmony_ci	return (struct gru_control_block_extended*)cbe;
1618c2ecf20Sopenharmony_ci}
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci/*
1678c2ecf20Sopenharmony_ci * Global TLB Fault Map
1688c2ecf20Sopenharmony_ci * 	Bitmap of outstanding TLB misses needing interrupt/polling service.
1698c2ecf20Sopenharmony_ci *
1708c2ecf20Sopenharmony_ci */
1718c2ecf20Sopenharmony_cistruct gru_tlb_fault_map {
1728c2ecf20Sopenharmony_ci	unsigned long fault_bits[BITS_TO_LONGS(GRU_NUM_CBE)];
1738c2ecf20Sopenharmony_ci	unsigned long fill0[2];
1748c2ecf20Sopenharmony_ci	unsigned long done_bits[BITS_TO_LONGS(GRU_NUM_CBE)];
1758c2ecf20Sopenharmony_ci	unsigned long fill1[2];
1768c2ecf20Sopenharmony_ci};
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci/*
1798c2ecf20Sopenharmony_ci * TGH - TLB Global Handle
1808c2ecf20Sopenharmony_ci * 	Used for TLB flushing.
1818c2ecf20Sopenharmony_ci *
1828c2ecf20Sopenharmony_ci */
1838c2ecf20Sopenharmony_cistruct gru_tlb_global_handle {
1848c2ecf20Sopenharmony_ci	unsigned int cmd:1;		/* DW 0 */
1858c2ecf20Sopenharmony_ci	unsigned int delresp:1;
1868c2ecf20Sopenharmony_ci	unsigned int opc:1;
1878c2ecf20Sopenharmony_ci	unsigned int fill1:5;
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ci	unsigned int fill2:8;
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_ci	unsigned int status:2;
1928c2ecf20Sopenharmony_ci	unsigned long fill3:2;
1938c2ecf20Sopenharmony_ci	unsigned int state:3;
1948c2ecf20Sopenharmony_ci	unsigned long fill4:1;
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_ci	unsigned int cause:3;
1978c2ecf20Sopenharmony_ci	unsigned long fill5:37;
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci	unsigned long vaddr:64;		/* DW 1 */
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ci	unsigned int asid:24;		/* DW 2 */
2028c2ecf20Sopenharmony_ci	unsigned int fill6:8;
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_ci	unsigned int pagesize:5;
2058c2ecf20Sopenharmony_ci	unsigned int fill7:11;
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_ci	unsigned int global:1;
2088c2ecf20Sopenharmony_ci	unsigned int fill8:15;
2098c2ecf20Sopenharmony_ci
2108c2ecf20Sopenharmony_ci	unsigned long vaddrmask:39;	/* DW 3 */
2118c2ecf20Sopenharmony_ci	unsigned int fill9:9;
2128c2ecf20Sopenharmony_ci	unsigned int n:10;
2138c2ecf20Sopenharmony_ci	unsigned int fill10:6;
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_ci	unsigned int ctxbitmap:16;	/* DW4 */
2168c2ecf20Sopenharmony_ci	unsigned long fill11[3];
2178c2ecf20Sopenharmony_ci};
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_cienum gru_tgh_cmd {
2208c2ecf20Sopenharmony_ci	TGHCMD_START
2218c2ecf20Sopenharmony_ci};
2228c2ecf20Sopenharmony_ci
2238c2ecf20Sopenharmony_cienum gru_tgh_opc {
2248c2ecf20Sopenharmony_ci	TGHOP_TLBNOP,
2258c2ecf20Sopenharmony_ci	TGHOP_TLBINV
2268c2ecf20Sopenharmony_ci};
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_cienum gru_tgh_status {
2298c2ecf20Sopenharmony_ci	TGHSTATUS_IDLE,
2308c2ecf20Sopenharmony_ci	TGHSTATUS_EXCEPTION,
2318c2ecf20Sopenharmony_ci	TGHSTATUS_ACTIVE
2328c2ecf20Sopenharmony_ci};
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_cienum gru_tgh_state {
2358c2ecf20Sopenharmony_ci	TGHSTATE_IDLE,
2368c2ecf20Sopenharmony_ci	TGHSTATE_PE_INVAL,
2378c2ecf20Sopenharmony_ci	TGHSTATE_INTERRUPT_INVAL,
2388c2ecf20Sopenharmony_ci	TGHSTATE_WAITDONE,
2398c2ecf20Sopenharmony_ci	TGHSTATE_RESTART_CTX,
2408c2ecf20Sopenharmony_ci};
2418c2ecf20Sopenharmony_ci
2428c2ecf20Sopenharmony_cienum gru_tgh_cause {
2438c2ecf20Sopenharmony_ci	TGHCAUSE_RR_ECC,
2448c2ecf20Sopenharmony_ci	TGHCAUSE_TLB_ECC,
2458c2ecf20Sopenharmony_ci	TGHCAUSE_LRU_ECC,
2468c2ecf20Sopenharmony_ci	TGHCAUSE_PS_ECC,
2478c2ecf20Sopenharmony_ci	TGHCAUSE_MUL_ERR,
2488c2ecf20Sopenharmony_ci	TGHCAUSE_DATA_ERR,
2498c2ecf20Sopenharmony_ci	TGHCAUSE_SW_FORCE
2508c2ecf20Sopenharmony_ci};
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_ci
2538c2ecf20Sopenharmony_ci/*
2548c2ecf20Sopenharmony_ci * TFH - TLB Global Handle
2558c2ecf20Sopenharmony_ci * 	Used for TLB dropins into the GRU TLB.
2568c2ecf20Sopenharmony_ci *
2578c2ecf20Sopenharmony_ci */
2588c2ecf20Sopenharmony_cistruct gru_tlb_fault_handle {
2598c2ecf20Sopenharmony_ci	unsigned int cmd:1;		/* DW 0 - low 32*/
2608c2ecf20Sopenharmony_ci	unsigned int delresp:1;
2618c2ecf20Sopenharmony_ci	unsigned int fill0:2;
2628c2ecf20Sopenharmony_ci	unsigned int opc:3;
2638c2ecf20Sopenharmony_ci	unsigned int fill1:9;
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_ci	unsigned int status:2;
2668c2ecf20Sopenharmony_ci	unsigned int fill2:2;
2678c2ecf20Sopenharmony_ci	unsigned int state:3;
2688c2ecf20Sopenharmony_ci	unsigned int fill3:1;
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_ci	unsigned int cause:6;
2718c2ecf20Sopenharmony_ci	unsigned int cb_int:1;
2728c2ecf20Sopenharmony_ci	unsigned int fill4:1;
2738c2ecf20Sopenharmony_ci
2748c2ecf20Sopenharmony_ci	unsigned int indexway:12;	/* DW 0 - high 32 */
2758c2ecf20Sopenharmony_ci	unsigned int fill5:4;
2768c2ecf20Sopenharmony_ci
2778c2ecf20Sopenharmony_ci	unsigned int ctxnum:4;
2788c2ecf20Sopenharmony_ci	unsigned int fill6:12;
2798c2ecf20Sopenharmony_ci
2808c2ecf20Sopenharmony_ci	unsigned long missvaddr:64;	/* DW 1 */
2818c2ecf20Sopenharmony_ci
2828c2ecf20Sopenharmony_ci	unsigned int missasid:24;	/* DW 2 */
2838c2ecf20Sopenharmony_ci	unsigned int fill7:8;
2848c2ecf20Sopenharmony_ci	unsigned int fillasid:24;
2858c2ecf20Sopenharmony_ci	unsigned int dirty:1;
2868c2ecf20Sopenharmony_ci	unsigned int gaa:2;
2878c2ecf20Sopenharmony_ci	unsigned long fill8:5;
2888c2ecf20Sopenharmony_ci
2898c2ecf20Sopenharmony_ci	unsigned long pfn:41;		/* DW 3 */
2908c2ecf20Sopenharmony_ci	unsigned int fill9:7;
2918c2ecf20Sopenharmony_ci	unsigned int pagesize:5;
2928c2ecf20Sopenharmony_ci	unsigned int fill10:11;
2938c2ecf20Sopenharmony_ci
2948c2ecf20Sopenharmony_ci	unsigned long fillvaddr:64;	/* DW 4 */
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_ci	unsigned long fill11[3];
2978c2ecf20Sopenharmony_ci};
2988c2ecf20Sopenharmony_ci
2998c2ecf20Sopenharmony_cienum gru_tfh_opc {
3008c2ecf20Sopenharmony_ci	TFHOP_NOOP,
3018c2ecf20Sopenharmony_ci	TFHOP_RESTART,
3028c2ecf20Sopenharmony_ci	TFHOP_WRITE_ONLY,
3038c2ecf20Sopenharmony_ci	TFHOP_WRITE_RESTART,
3048c2ecf20Sopenharmony_ci	TFHOP_EXCEPTION,
3058c2ecf20Sopenharmony_ci	TFHOP_USER_POLLING_MODE = 7,
3068c2ecf20Sopenharmony_ci};
3078c2ecf20Sopenharmony_ci
3088c2ecf20Sopenharmony_cienum tfh_status {
3098c2ecf20Sopenharmony_ci	TFHSTATUS_IDLE,
3108c2ecf20Sopenharmony_ci	TFHSTATUS_EXCEPTION,
3118c2ecf20Sopenharmony_ci	TFHSTATUS_ACTIVE,
3128c2ecf20Sopenharmony_ci};
3138c2ecf20Sopenharmony_ci
3148c2ecf20Sopenharmony_cienum tfh_state {
3158c2ecf20Sopenharmony_ci	TFHSTATE_INACTIVE,
3168c2ecf20Sopenharmony_ci	TFHSTATE_IDLE,
3178c2ecf20Sopenharmony_ci	TFHSTATE_MISS_UPM,
3188c2ecf20Sopenharmony_ci	TFHSTATE_MISS_FMM,
3198c2ecf20Sopenharmony_ci	TFHSTATE_HW_ERR,
3208c2ecf20Sopenharmony_ci	TFHSTATE_WRITE_TLB,
3218c2ecf20Sopenharmony_ci	TFHSTATE_RESTART_CBR,
3228c2ecf20Sopenharmony_ci};
3238c2ecf20Sopenharmony_ci
3248c2ecf20Sopenharmony_ci/* TFH cause bits */
3258c2ecf20Sopenharmony_cienum tfh_cause {
3268c2ecf20Sopenharmony_ci	TFHCAUSE_NONE,
3278c2ecf20Sopenharmony_ci	TFHCAUSE_TLB_MISS,
3288c2ecf20Sopenharmony_ci	TFHCAUSE_TLB_MOD,
3298c2ecf20Sopenharmony_ci	TFHCAUSE_HW_ERROR_RR,
3308c2ecf20Sopenharmony_ci	TFHCAUSE_HW_ERROR_MAIN_ARRAY,
3318c2ecf20Sopenharmony_ci	TFHCAUSE_HW_ERROR_VALID,
3328c2ecf20Sopenharmony_ci	TFHCAUSE_HW_ERROR_PAGESIZE,
3338c2ecf20Sopenharmony_ci	TFHCAUSE_INSTRUCTION_EXCEPTION,
3348c2ecf20Sopenharmony_ci	TFHCAUSE_UNCORRECTIBLE_ERROR,
3358c2ecf20Sopenharmony_ci};
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_ci/* GAA values */
3388c2ecf20Sopenharmony_ci#define GAA_RAM				0x0
3398c2ecf20Sopenharmony_ci#define GAA_NCRAM			0x2
3408c2ecf20Sopenharmony_ci#define GAA_MMIO			0x1
3418c2ecf20Sopenharmony_ci#define GAA_REGISTER			0x3
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_ci/* GRU paddr shift for pfn. (NOTE: shift is NOT by actual pagesize) */
3448c2ecf20Sopenharmony_ci#define GRU_PADDR_SHIFT			12
3458c2ecf20Sopenharmony_ci
3468c2ecf20Sopenharmony_ci/*
3478c2ecf20Sopenharmony_ci * Context Configuration handle
3488c2ecf20Sopenharmony_ci * 	Used to allocate resources to a GSEG context.
3498c2ecf20Sopenharmony_ci *
3508c2ecf20Sopenharmony_ci */
3518c2ecf20Sopenharmony_cistruct gru_context_configuration_handle {
3528c2ecf20Sopenharmony_ci	unsigned int cmd:1;			/* DW0 */
3538c2ecf20Sopenharmony_ci	unsigned int delresp:1;
3548c2ecf20Sopenharmony_ci	unsigned int opc:3;
3558c2ecf20Sopenharmony_ci	unsigned int unmap_enable:1;
3568c2ecf20Sopenharmony_ci	unsigned int req_slice_set_enable:1;
3578c2ecf20Sopenharmony_ci	unsigned int req_slice:2;
3588c2ecf20Sopenharmony_ci	unsigned int cb_int_enable:1;
3598c2ecf20Sopenharmony_ci	unsigned int tlb_int_enable:1;
3608c2ecf20Sopenharmony_ci	unsigned int tfm_fault_bit_enable:1;
3618c2ecf20Sopenharmony_ci	unsigned int tlb_int_select:4;
3628c2ecf20Sopenharmony_ci
3638c2ecf20Sopenharmony_ci	unsigned int status:2;
3648c2ecf20Sopenharmony_ci	unsigned int state:2;
3658c2ecf20Sopenharmony_ci	unsigned int reserved2:4;
3668c2ecf20Sopenharmony_ci
3678c2ecf20Sopenharmony_ci	unsigned int cause:4;
3688c2ecf20Sopenharmony_ci	unsigned int tfm_done_bit_enable:1;
3698c2ecf20Sopenharmony_ci	unsigned int unused:3;
3708c2ecf20Sopenharmony_ci
3718c2ecf20Sopenharmony_ci	unsigned int dsr_allocation_map;
3728c2ecf20Sopenharmony_ci
3738c2ecf20Sopenharmony_ci	unsigned long cbr_allocation_map;	/* DW1 */
3748c2ecf20Sopenharmony_ci
3758c2ecf20Sopenharmony_ci	unsigned int asid[8];			/* DW 2 - 5 */
3768c2ecf20Sopenharmony_ci	unsigned short sizeavail[8];		/* DW 6 - 7 */
3778c2ecf20Sopenharmony_ci} __attribute__ ((packed));
3788c2ecf20Sopenharmony_ci
3798c2ecf20Sopenharmony_cienum gru_cch_opc {
3808c2ecf20Sopenharmony_ci	CCHOP_START = 1,
3818c2ecf20Sopenharmony_ci	CCHOP_ALLOCATE,
3828c2ecf20Sopenharmony_ci	CCHOP_INTERRUPT,
3838c2ecf20Sopenharmony_ci	CCHOP_DEALLOCATE,
3848c2ecf20Sopenharmony_ci	CCHOP_INTERRUPT_SYNC,
3858c2ecf20Sopenharmony_ci};
3868c2ecf20Sopenharmony_ci
3878c2ecf20Sopenharmony_cienum gru_cch_status {
3888c2ecf20Sopenharmony_ci	CCHSTATUS_IDLE,
3898c2ecf20Sopenharmony_ci	CCHSTATUS_EXCEPTION,
3908c2ecf20Sopenharmony_ci	CCHSTATUS_ACTIVE,
3918c2ecf20Sopenharmony_ci};
3928c2ecf20Sopenharmony_ci
3938c2ecf20Sopenharmony_cienum gru_cch_state {
3948c2ecf20Sopenharmony_ci	CCHSTATE_INACTIVE,
3958c2ecf20Sopenharmony_ci	CCHSTATE_MAPPED,
3968c2ecf20Sopenharmony_ci	CCHSTATE_ACTIVE,
3978c2ecf20Sopenharmony_ci	CCHSTATE_INTERRUPTED,
3988c2ecf20Sopenharmony_ci};
3998c2ecf20Sopenharmony_ci
4008c2ecf20Sopenharmony_ci/* CCH Exception cause */
4018c2ecf20Sopenharmony_cienum gru_cch_cause {
4028c2ecf20Sopenharmony_ci	CCHCAUSE_REGION_REGISTER_WRITE_ERROR = 1,
4038c2ecf20Sopenharmony_ci	CCHCAUSE_ILLEGAL_OPCODE = 2,
4048c2ecf20Sopenharmony_ci	CCHCAUSE_INVALID_START_REQUEST = 3,
4058c2ecf20Sopenharmony_ci	CCHCAUSE_INVALID_ALLOCATION_REQUEST = 4,
4068c2ecf20Sopenharmony_ci	CCHCAUSE_INVALID_DEALLOCATION_REQUEST = 5,
4078c2ecf20Sopenharmony_ci	CCHCAUSE_INVALID_INTERRUPT_REQUEST = 6,
4088c2ecf20Sopenharmony_ci	CCHCAUSE_CCH_BUSY = 7,
4098c2ecf20Sopenharmony_ci	CCHCAUSE_NO_CBRS_TO_ALLOCATE = 8,
4108c2ecf20Sopenharmony_ci	CCHCAUSE_BAD_TFM_CONFIG = 9,
4118c2ecf20Sopenharmony_ci	CCHCAUSE_CBR_RESOURCES_OVERSUBSCRIPED = 10,
4128c2ecf20Sopenharmony_ci	CCHCAUSE_DSR_RESOURCES_OVERSUBSCRIPED = 11,
4138c2ecf20Sopenharmony_ci	CCHCAUSE_CBR_DEALLOCATION_ERROR = 12,
4148c2ecf20Sopenharmony_ci};
4158c2ecf20Sopenharmony_ci/*
4168c2ecf20Sopenharmony_ci * CBE - Control Block Extended
4178c2ecf20Sopenharmony_ci * 	Maintains internal GRU state for active CBs.
4188c2ecf20Sopenharmony_ci *
4198c2ecf20Sopenharmony_ci */
4208c2ecf20Sopenharmony_cistruct gru_control_block_extended {
4218c2ecf20Sopenharmony_ci	unsigned int reserved0:1;	/* DW 0  - low */
4228c2ecf20Sopenharmony_ci	unsigned int imacpy:3;
4238c2ecf20Sopenharmony_ci	unsigned int reserved1:4;
4248c2ecf20Sopenharmony_ci	unsigned int xtypecpy:3;
4258c2ecf20Sopenharmony_ci	unsigned int iaa0cpy:2;
4268c2ecf20Sopenharmony_ci	unsigned int iaa1cpy:2;
4278c2ecf20Sopenharmony_ci	unsigned int reserved2:1;
4288c2ecf20Sopenharmony_ci	unsigned int opccpy:8;
4298c2ecf20Sopenharmony_ci	unsigned int exopccpy:8;
4308c2ecf20Sopenharmony_ci
4318c2ecf20Sopenharmony_ci	unsigned int idef2cpy:22;	/* DW 0  - high */
4328c2ecf20Sopenharmony_ci	unsigned int reserved3:10;
4338c2ecf20Sopenharmony_ci
4348c2ecf20Sopenharmony_ci	unsigned int idef4cpy:22;	/* DW 1 */
4358c2ecf20Sopenharmony_ci	unsigned int reserved4:10;
4368c2ecf20Sopenharmony_ci	unsigned int idef4upd:22;
4378c2ecf20Sopenharmony_ci	unsigned int reserved5:10;
4388c2ecf20Sopenharmony_ci
4398c2ecf20Sopenharmony_ci	unsigned long idef1upd:64;	/* DW 2 */
4408c2ecf20Sopenharmony_ci
4418c2ecf20Sopenharmony_ci	unsigned long idef5cpy:64;	/* DW 3 */
4428c2ecf20Sopenharmony_ci
4438c2ecf20Sopenharmony_ci	unsigned long idef6cpy:64;	/* DW 4 */
4448c2ecf20Sopenharmony_ci
4458c2ecf20Sopenharmony_ci	unsigned long idef3upd:64;	/* DW 5 */
4468c2ecf20Sopenharmony_ci
4478c2ecf20Sopenharmony_ci	unsigned long idef5upd:64;	/* DW 6 */
4488c2ecf20Sopenharmony_ci
4498c2ecf20Sopenharmony_ci	unsigned int idef2upd:22;	/* DW 7 */
4508c2ecf20Sopenharmony_ci	unsigned int reserved6:10;
4518c2ecf20Sopenharmony_ci
4528c2ecf20Sopenharmony_ci	unsigned int ecause:20;
4538c2ecf20Sopenharmony_ci	unsigned int cbrstate:4;
4548c2ecf20Sopenharmony_ci	unsigned int cbrexecstatus:8;
4558c2ecf20Sopenharmony_ci};
4568c2ecf20Sopenharmony_ci
4578c2ecf20Sopenharmony_ci/* CBE fields for active BCOPY instructions */
4588c2ecf20Sopenharmony_ci#define cbe_baddr0	idef1upd
4598c2ecf20Sopenharmony_ci#define cbe_baddr1	idef3upd
4608c2ecf20Sopenharmony_ci#define cbe_src_cl	idef6cpy
4618c2ecf20Sopenharmony_ci#define cbe_nelemcur	idef5upd
4628c2ecf20Sopenharmony_ci
4638c2ecf20Sopenharmony_cienum gru_cbr_state {
4648c2ecf20Sopenharmony_ci	CBRSTATE_INACTIVE,
4658c2ecf20Sopenharmony_ci	CBRSTATE_IDLE,
4668c2ecf20Sopenharmony_ci	CBRSTATE_PE_CHECK,
4678c2ecf20Sopenharmony_ci	CBRSTATE_QUEUED,
4688c2ecf20Sopenharmony_ci	CBRSTATE_WAIT_RESPONSE,
4698c2ecf20Sopenharmony_ci	CBRSTATE_INTERRUPTED,
4708c2ecf20Sopenharmony_ci	CBRSTATE_INTERRUPTED_MISS_FMM,
4718c2ecf20Sopenharmony_ci	CBRSTATE_BUSY_INTERRUPT_MISS_FMM,
4728c2ecf20Sopenharmony_ci	CBRSTATE_INTERRUPTED_MISS_UPM,
4738c2ecf20Sopenharmony_ci	CBRSTATE_BUSY_INTERRUPTED_MISS_UPM,
4748c2ecf20Sopenharmony_ci	CBRSTATE_REQUEST_ISSUE,
4758c2ecf20Sopenharmony_ci	CBRSTATE_BUSY_INTERRUPT,
4768c2ecf20Sopenharmony_ci};
4778c2ecf20Sopenharmony_ci
4788c2ecf20Sopenharmony_ci/* CBE cbrexecstatus bits  - defined in gru_instructions.h*/
4798c2ecf20Sopenharmony_ci/* CBE ecause bits  - defined in gru_instructions.h */
4808c2ecf20Sopenharmony_ci
4818c2ecf20Sopenharmony_ci/*
4828c2ecf20Sopenharmony_ci * Convert a processor pagesize into the strange encoded pagesize used by the
4838c2ecf20Sopenharmony_ci * GRU. Processor pagesize is encoded as log of bytes per page. (or PAGE_SHIFT)
4848c2ecf20Sopenharmony_ci * 	pagesize	log pagesize	grupagesize
4858c2ecf20Sopenharmony_ci * 	  4k			12	0
4868c2ecf20Sopenharmony_ci * 	 16k 			14	1
4878c2ecf20Sopenharmony_ci * 	 64k			16	2
4888c2ecf20Sopenharmony_ci * 	256k			18	3
4898c2ecf20Sopenharmony_ci * 	  1m			20	4
4908c2ecf20Sopenharmony_ci * 	  2m			21	5
4918c2ecf20Sopenharmony_ci * 	  4m			22	6
4928c2ecf20Sopenharmony_ci * 	 16m			24	7
4938c2ecf20Sopenharmony_ci * 	 64m			26	8
4948c2ecf20Sopenharmony_ci * 	...
4958c2ecf20Sopenharmony_ci */
4968c2ecf20Sopenharmony_ci#define GRU_PAGESIZE(sh)	((((sh) > 20 ? (sh) + 2 : (sh)) >> 1) - 6)
4978c2ecf20Sopenharmony_ci#define GRU_SIZEAVAIL(sh)	(1UL << GRU_PAGESIZE(sh))
4988c2ecf20Sopenharmony_ci
4998c2ecf20Sopenharmony_ci/* minimum TLB purge count to ensure a full purge */
5008c2ecf20Sopenharmony_ci#define GRUMAXINVAL		1024UL
5018c2ecf20Sopenharmony_ci
5028c2ecf20Sopenharmony_ciint cch_allocate(struct gru_context_configuration_handle *cch);
5038c2ecf20Sopenharmony_ciint cch_start(struct gru_context_configuration_handle *cch);
5048c2ecf20Sopenharmony_ciint cch_interrupt(struct gru_context_configuration_handle *cch);
5058c2ecf20Sopenharmony_ciint cch_deallocate(struct gru_context_configuration_handle *cch);
5068c2ecf20Sopenharmony_ciint cch_interrupt_sync(struct gru_context_configuration_handle *cch);
5078c2ecf20Sopenharmony_ciint tgh_invalidate(struct gru_tlb_global_handle *tgh, unsigned long vaddr,
5088c2ecf20Sopenharmony_ci	unsigned long vaddrmask, int asid, int pagesize, int global, int n,
5098c2ecf20Sopenharmony_ci	unsigned short ctxbitmap);
5108c2ecf20Sopenharmony_ciint tfh_write_only(struct gru_tlb_fault_handle *tfh, unsigned long paddr,
5118c2ecf20Sopenharmony_ci	int gaa, unsigned long vaddr, int asid, int dirty, int pagesize);
5128c2ecf20Sopenharmony_civoid tfh_write_restart(struct gru_tlb_fault_handle *tfh, unsigned long paddr,
5138c2ecf20Sopenharmony_ci	int gaa, unsigned long vaddr, int asid, int dirty, int pagesize);
5148c2ecf20Sopenharmony_civoid tfh_user_polling_mode(struct gru_tlb_fault_handle *tfh);
5158c2ecf20Sopenharmony_civoid tfh_exception(struct gru_tlb_fault_handle *tfh);
5168c2ecf20Sopenharmony_ci
5178c2ecf20Sopenharmony_ci#endif /* __GRUHANDLES_H__ */
518