Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * SN Platform GRU Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *            GRU DRIVER TABLES, MACROS, externs, etc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *  Copyright (c) 2008 Silicon Graphics, Inc.  All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #ifndef __GRUTABLES_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #define __GRUTABLES_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * GRU Chiplet:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *   The GRU is a user addressible memory accelerator. It provides
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *   several forms of load, store, memset, bcopy instructions. In addition, it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *   contains special instructions for AMOs, sending messages to message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *   queues, etc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  *   The GRU is an integral part of the node controller. It connects
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  *   directly to the cpu socket. In its current implementation, there are 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  *   GRU chiplets in the node controller on each blade (~node).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  *   The entire GRU memory space is fully coherent and cacheable by the cpus.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  *   Each GRU chiplet has a physical memory map that looks like the following:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  *   	+-----------------+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  *   	|/////////////////|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  *   	|/////////////////|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  *   	|/////////////////|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  *   	|/////////////////|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  *   	|/////////////////|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  *   	|/////////////////|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  *   	|/////////////////|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  *   	|/////////////////|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  *   	+-----------------+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  *   	|  system control |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  *   	+-----------------+        _______ +-------------+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  *   	|/////////////////|       /        |             |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  *   	|/////////////////|      /         |             |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  *   	|/////////////////|     /          | instructions|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  *   	|/////////////////|    /           |             |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  *   	|/////////////////|   /            |             |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  *   	|/////////////////|  /             |-------------|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  *   	|/////////////////| /              |             |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  *   	+-----------------+                |             |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  *   	|   context 15    |                |  data       |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  *   	+-----------------+                |             |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  *   	|    ......       | \              |             |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  *   	+-----------------+  \____________ +-------------+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  *   	|   context 1     |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  *   	+-----------------+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  *   	|   context 0     |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  *   	+-----------------+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  *   Each of the "contexts" is a chunk of memory that can be mmaped into user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  *   space. The context consists of 2 parts:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  *  	- an instruction space that can be directly accessed by the user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  *  	  to issue GRU instructions and to check instruction status.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  *  	- a data area that acts as normal RAM.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  *   User instructions contain virtual addresses of data to be accessed by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  *   GRU. The GRU contains a TLB that is used to convert these user virtual
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  *   addresses to physical addresses.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  *   The "system control" area of the GRU chiplet is used by the kernel driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  *   to manage user contexts and to perform functions such as TLB dropin and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  *   purging.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73)  *   One context may be reserved for the kernel and used for cross-partition
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)  *   communication. The GRU will also be used to asynchronously zero out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)  *   large blocks of memory (not currently implemented).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)  * Tables:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  * 	VDATA-VMA Data		- Holds a few parameters. Head of linked list of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  * 				  GTS tables for threads using the GSEG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82)  * 	GTS - Gru Thread State  - contains info for managing a GSEG context. A
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83)  * 				  GTS is allocated for each thread accessing a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84)  * 				  GSEG.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85)  *     	GTD - GRU Thread Data   - contains shadow copy of GRU data when GSEG is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86)  *     				  not loaded into a GRU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87)  *	GMS - GRU Memory Struct - Used to manage TLB shootdowns. Tracks GRUs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88)  *				  where a GSEG has been loaded. Similar to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89)  *				  an mm_struct but for GRU.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91)  *	GS  - GRU State 	- Used to manage the state of a GRU chiplet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92)  *	BS  - Blade State	- Used to manage state of all GRU chiplets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)  *				  on a blade
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96)  *  Normal task tables for task using GRU.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)  *  		- 2 threads in process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98)  *  		- 2 GSEGs open in process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99)  *  		- GSEG1 is being used by both threads
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  *  		- GSEG2 is used only by thread 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)  *       task -->|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)  *       task ---+---> mm ->------ (notifier) -------+-> gms
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)  *                     |                             |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)  *                     |--> vma -> vdata ---> gts--->|		GSEG1 (thread1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)  *                     |                  |          |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)  *                     |                  +-> gts--->|		GSEG1 (thread2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)  *                     |                             |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)  *                     |--> vma -> vdata ---> gts--->|		GSEG2 (thread2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)  *                     .
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)  *                     .
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)  *  GSEGs are marked DONTCOPY on fork
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)  * At open
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)  * 	file.private_data -> NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)  * At mmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)  * 	vma -> vdata
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)  * After gseg reference
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)  * 	vma -> vdata ->gts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)  * After fork
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)  *   parent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)  * 	vma -> vdata -> gts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)  *   child
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)  * 	(vma is not copied)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) #include <linux/rmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) #include <linux/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) #include <linux/mmu_notifier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) #include <linux/mm_types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) #include "gru.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) #include "grulib.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) #include "gruhandles.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) extern struct gru_stats_s gru_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) extern struct gru_blade_state *gru_base[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) extern unsigned long gru_start_paddr, gru_end_paddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) extern void *gru_start_vaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) extern unsigned int gru_max_gids;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) #define GRU_MAX_BLADES		MAX_NUMNODES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) #define GRU_MAX_GRUS		(GRU_MAX_BLADES * GRU_CHIPLETS_PER_BLADE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) #define GRU_DRIVER_ID_STR	"SGI GRU Device Driver"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) #define GRU_DRIVER_VERSION_STR	"0.85"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)  * GRU statistics.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) struct gru_stats_s {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	atomic_long_t vdata_alloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	atomic_long_t vdata_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	atomic_long_t gts_alloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	atomic_long_t gts_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	atomic_long_t gms_alloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	atomic_long_t gms_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	atomic_long_t gts_double_allocate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	atomic_long_t assign_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	atomic_long_t assign_context_failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	atomic_long_t free_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	atomic_long_t load_user_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	atomic_long_t load_kernel_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	atomic_long_t lock_kernel_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	atomic_long_t unlock_kernel_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	atomic_long_t steal_user_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	atomic_long_t steal_kernel_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	atomic_long_t steal_context_failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	atomic_long_t nopfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	atomic_long_t asid_new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	atomic_long_t asid_next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	atomic_long_t asid_wrap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	atomic_long_t asid_reuse;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	atomic_long_t intr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	atomic_long_t intr_cbr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	atomic_long_t intr_tfh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	atomic_long_t intr_spurious;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	atomic_long_t intr_mm_lock_failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	atomic_long_t call_os;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	atomic_long_t call_os_wait_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	atomic_long_t user_flush_tlb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	atomic_long_t user_unload_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	atomic_long_t user_exception;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	atomic_long_t set_context_option;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	atomic_long_t check_context_retarget_intr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	atomic_long_t check_context_unload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	atomic_long_t tlb_dropin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	atomic_long_t tlb_preload_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	atomic_long_t tlb_dropin_fail_no_asid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	atomic_long_t tlb_dropin_fail_upm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	atomic_long_t tlb_dropin_fail_invalid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	atomic_long_t tlb_dropin_fail_range_active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	atomic_long_t tlb_dropin_fail_idle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	atomic_long_t tlb_dropin_fail_fmm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	atomic_long_t tlb_dropin_fail_no_exception;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	atomic_long_t tfh_stale_on_fault;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	atomic_long_t mmu_invalidate_range;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	atomic_long_t mmu_invalidate_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	atomic_long_t flush_tlb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	atomic_long_t flush_tlb_gru;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	atomic_long_t flush_tlb_gru_tgh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	atomic_long_t flush_tlb_gru_zero_asid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	atomic_long_t copy_gpa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	atomic_long_t read_gpa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	atomic_long_t mesq_receive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	atomic_long_t mesq_receive_none;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	atomic_long_t mesq_send;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	atomic_long_t mesq_send_failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	atomic_long_t mesq_noop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	atomic_long_t mesq_send_unexpected_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	atomic_long_t mesq_send_lb_overflow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	atomic_long_t mesq_send_qlimit_reached;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	atomic_long_t mesq_send_amo_nacked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	atomic_long_t mesq_send_put_nacked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	atomic_long_t mesq_page_overflow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	atomic_long_t mesq_qf_locked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	atomic_long_t mesq_qf_noop_not_full;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	atomic_long_t mesq_qf_switch_head_failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	atomic_long_t mesq_qf_unexpected_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	atomic_long_t mesq_noop_unexpected_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	atomic_long_t mesq_noop_lb_overflow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	atomic_long_t mesq_noop_qlimit_reached;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	atomic_long_t mesq_noop_amo_nacked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	atomic_long_t mesq_noop_put_nacked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	atomic_long_t mesq_noop_page_overflow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	cchop_deallocate, tfhop_write_only, tfhop_write_restart,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	tghop_invalidate, mcsop_last};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) struct mcs_op_statistic {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	atomic_long_t	count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	atomic_long_t	total;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	unsigned long	max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) #define OPT_DPRINT		1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) #define OPT_STATS		2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) #define IRQ_GRU			110	/* Starting IRQ number for interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) /* Delay in jiffies between attempts to assign a GRU context */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) #define GRU_ASSIGN_DELAY	((HZ * 20) / 1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)  * If a process has it's context stolen, min delay in jiffies before trying to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)  * steal a context from another process.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) #define GRU_STEAL_DELAY		((HZ * 200) / 1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) #define STAT(id)	do {						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 				if (gru_options & OPT_STATS)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 					atomic_long_inc(&gru_stats.id);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 			} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) #ifdef CONFIG_SGI_GRU_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) #define gru_dbg(dev, fmt, x...)						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	do {								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		if (gru_options & OPT_DPRINT)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 			printk(KERN_DEBUG "GRU:%d %s: " fmt, smp_processor_id(), __func__, x);\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) #define gru_dbg(x...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) /*-----------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)  * ASID management
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) #define MAX_ASID	0xfffff0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) #define MIN_ASID	8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) #define ASID_INC	8	/* number of regions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) /* Generate a GRU asid value from a GRU base asid & a virtual address. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) #define VADDR_HI_BIT		64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) #define GRUREGION(addr)		((addr) >> (VADDR_HI_BIT - 3) & 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) #define GRUASID(asid, addr)	((asid) + GRUREGION(addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) /*------------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)  *  File & VMS Tables
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) struct gru_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)  * This structure is pointed to from the mmstruct via the notifier pointer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)  * There is one of these per address space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) struct gru_mm_tracker {				/* pack to reduce size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	unsigned int		mt_asid_gen:24;	/* ASID wrap count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	unsigned int		mt_asid:24;	/* current base ASID for gru */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	unsigned short		mt_ctxbitmap:16;/* bitmap of contexts using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 						   asid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) } __attribute__ ((packed));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) struct gru_mm_struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	struct mmu_notifier	ms_notifier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	spinlock_t		ms_asid_lock;	/* protects ASID assignment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	atomic_t		ms_range_active;/* num range_invals active */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	wait_queue_head_t	ms_wait_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	DECLARE_BITMAP(ms_asidmap, GRU_MAX_GRUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	struct gru_mm_tracker	ms_asids[GRU_MAX_GRUS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)  * One of these structures is allocated when a GSEG is mmaped. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)  * structure is pointed to by the vma->vm_private_data field in the vma struct.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) struct gru_vma_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	spinlock_t		vd_lock;	/* Serialize access to vma */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	struct list_head	vd_head;	/* head of linked list of gts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	long			vd_user_options;/* misc user option flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	int			vd_cbr_au_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	int			vd_dsr_au_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	unsigned char		vd_tlb_preload_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)  * One of these is allocated for each thread accessing a mmaped GRU. A linked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)  * list of these structure is hung off the struct gru_vma_data in the mm_struct.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) struct gru_thread_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	struct list_head	ts_next;	/* list - head at vma-private */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	struct mutex		ts_ctxlock;	/* load/unload CTX lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	struct mm_struct	*ts_mm;		/* mm currently mapped to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 						   context */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	struct vm_area_struct	*ts_vma;	/* vma of GRU context */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	struct gru_state	*ts_gru;	/* GRU where the context is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 						   loaded */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	struct gru_mm_struct	*ts_gms;	/* asid & ioproc struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	unsigned char		ts_tlb_preload_count; /* TLB preload pages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	unsigned long		ts_cbr_map;	/* map of allocated CBRs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	unsigned long		ts_dsr_map;	/* map of allocated DATA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 						   resources */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	unsigned long		ts_steal_jiffies;/* jiffies when context last
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 						    stolen */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	long			ts_user_options;/* misc user option flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	pid_t			ts_tgid_owner;	/* task that is using the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 						   context - for migration */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	short			ts_user_blade_id;/* user selected blade */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	char			ts_user_chiplet_id;/* user selected chiplet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	unsigned short		ts_sizeavail;	/* Pagesizes in use */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	int			ts_tsid;	/* thread that owns the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 						   structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	int			ts_tlb_int_select;/* target cpu if interrupts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 						     enabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	int			ts_ctxnum;	/* context number where the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 						   context is loaded */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	atomic_t		ts_refcnt;	/* reference count GTS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	unsigned char		ts_dsr_au_count;/* Number of DSR resources
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 						   required for contest */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	unsigned char		ts_cbr_au_count;/* Number of CBR resources
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 						   required for contest */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	char			ts_cch_req_slice;/* CCH packet slice */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	char			ts_blade;	/* If >= 0, migrate context if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 						   ref from different blade */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	char			ts_force_cch_reload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	char			ts_cbr_idx[GRU_CBR_AU];/* CBR numbers of each
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 							  allocated CB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	int			ts_data_valid;	/* Indicates if ts_gdata has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 						   valid data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	struct gru_gseg_statistics ustats;	/* User statistics */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	unsigned long		ts_gdata[];	/* save area for GRU data (CB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 						   DS, CBE) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)  * Threaded programs actually allocate an array of GSEGs when a context is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)  * created. Each thread uses a separate GSEG. TSID is the index into the GSEG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)  * array.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) #define TSID(a, v)		(((a) - (v)->vm_start) / GRU_GSEG_PAGESIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) #define UGRUADDR(gts)		((gts)->ts_vma->vm_start +		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 					(gts)->ts_tsid * GRU_GSEG_PAGESIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) #define NULLCTX			(-1)	/* if context not loaded into GRU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) /*-----------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)  *  GRU State Tables
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)  * One of these exists for each GRU chiplet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) struct gru_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	struct gru_blade_state	*gs_blade;		/* GRU state for entire
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 							   blade */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	unsigned long		gs_gru_base_paddr;	/* Physical address of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 							   gru segments (64) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	void			*gs_gru_base_vaddr;	/* Virtual address of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 							   gru segments (64) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	unsigned short		gs_gid;			/* unique GRU number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	unsigned short		gs_blade_id;		/* blade of GRU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	unsigned char		gs_chiplet_id;		/* blade chiplet of GRU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	unsigned char		gs_tgh_local_shift;	/* used to pick TGH for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 							   local flush */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	unsigned char		gs_tgh_first_remote;	/* starting TGH# for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 							   remote flush */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	spinlock_t		gs_asid_lock;		/* lock used for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 							   assigning asids */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	spinlock_t		gs_lock;		/* lock used for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 							   assigning contexts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	/* -- the following are protected by the gs_asid_lock spinlock ---- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	unsigned int		gs_asid;		/* Next availe ASID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	unsigned int		gs_asid_limit;		/* Limit of available
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 							   ASIDs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	unsigned int		gs_asid_gen;		/* asid generation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 							   Inc on wrap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	/* --- the following fields are protected by the gs_lock spinlock --- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	unsigned long		gs_context_map;		/* bitmap to manage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 							   contexts in use */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	unsigned long		gs_cbr_map;		/* bitmap to manage CB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 							   resources */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	unsigned long		gs_dsr_map;		/* bitmap used to manage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 							   DATA resources */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	unsigned int		gs_reserved_cbrs;	/* Number of kernel-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 							   reserved cbrs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	unsigned int		gs_reserved_dsr_bytes;	/* Bytes of kernel-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 							   reserved dsrs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	unsigned short		gs_active_contexts;	/* number of contexts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 							   in use */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	struct gru_thread_state	*gs_gts[GRU_NUM_CCH];	/* GTS currently using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 							   the context */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	int			gs_irq[GRU_NUM_TFM];	/* Interrupt irqs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)  * This structure contains the GRU state for all the GRUs on a blade.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) struct gru_blade_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	void			*kernel_cb;		/* First kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 							   reserved cb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	void			*kernel_dsr;		/* First kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 							   reserved DSR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	struct rw_semaphore	bs_kgts_sema;		/* lock for kgts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	struct gru_thread_state *bs_kgts;		/* GTS for kernel use */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	/* ---- the following are used for managing kernel async GRU CBRs --- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	int			bs_async_dsr_bytes;	/* DSRs for async */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	int			bs_async_cbrs;		/* CBRs AU for async */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	struct completion	*bs_async_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	/* ---- the following are protected by the bs_lock spinlock ---- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	spinlock_t		bs_lock;		/* lock used for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 							   stealing contexts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	int			bs_lru_ctxnum;		/* STEAL - last context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 							   stolen */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	struct gru_state	*bs_lru_gru;		/* STEAL - last gru
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 							   stolen */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	struct gru_state	bs_grus[GRU_CHIPLETS_PER_BLADE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) /*-----------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)  * Address Primitives
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) #define get_tfm_for_cpu(g, c)						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	((struct gru_tlb_fault_map *)get_tfm((g)->gs_gru_base_vaddr, (c)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) #define get_tfh_by_index(g, i)						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	((struct gru_tlb_fault_handle *)get_tfh((g)->gs_gru_base_vaddr, (i)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) #define get_tgh_by_index(g, i)						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	((struct gru_tlb_global_handle *)get_tgh((g)->gs_gru_base_vaddr, (i)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) #define get_cbe_by_index(g, i)						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	((struct gru_control_block_extended *)get_cbe((g)->gs_gru_base_vaddr,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 			(i)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) /*-----------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)  * Useful Macros
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) /* Given a blade# & chiplet#, get a pointer to the GRU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) #define get_gru(b, c)		(&gru_base[b]->bs_grus[c])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) /* Number of bytes to save/restore when unloading/loading GRU contexts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) #define DSR_BYTES(dsr)		((dsr) * GRU_DSR_AU_BYTES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) #define CBR_BYTES(cbr)		((cbr) * GRU_HANDLE_BYTES * GRU_CBR_AU_SIZE * 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) /* Convert a user CB number to the actual CBRNUM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) #define thread_cbr_number(gts, n) ((gts)->ts_cbr_idx[(n) / GRU_CBR_AU_SIZE] \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 				  * GRU_CBR_AU_SIZE + (n) % GRU_CBR_AU_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) /* Convert a gid to a pointer to the GRU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) #define GID_TO_GRU(gid)							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	(gru_base[(gid) / GRU_CHIPLETS_PER_BLADE] ?			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 		(&gru_base[(gid) / GRU_CHIPLETS_PER_BLADE]->		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 			bs_grus[(gid) % GRU_CHIPLETS_PER_BLADE]) :	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	 NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) /* Scan all active GRUs in a GRU bitmap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) #define for_each_gru_in_bitmap(gid, map)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	for_each_set_bit((gid), (map), GRU_MAX_GRUS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) /* Scan all active GRUs on a specific blade */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) #define for_each_gru_on_blade(gru, nid, i)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	for ((gru) = gru_base[nid]->bs_grus, (i) = 0;			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 			(i) < GRU_CHIPLETS_PER_BLADE;			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 			(i)++, (gru)++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) /* Scan all GRUs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) #define foreach_gid(gid)						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	for ((gid) = 0; (gid) < gru_max_gids; (gid)++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) /* Scan all active GTSs on a gru. Note: must hold ss_lock to use this macro. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) #define for_each_gts_on_gru(gts, gru, ctxnum)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	for ((ctxnum) = 0; (ctxnum) < GRU_NUM_CCH; (ctxnum)++)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 		if (((gts) = (gru)->gs_gts[ctxnum]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) /* Scan each CBR whose bit is set in a TFM (or copy of) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) #define for_each_cbr_in_tfm(i, map)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	for_each_set_bit((i), (map), GRU_NUM_CBE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) /* Scan each CBR in a CBR bitmap. Note: multiple CBRs in an allocation unit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) #define for_each_cbr_in_allocation_map(i, map, k)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	for_each_set_bit((k), (map), GRU_CBR_AU)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 		for ((i) = (k)*GRU_CBR_AU_SIZE;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 				(i) < ((k) + 1) * GRU_CBR_AU_SIZE; (i)++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) /* Scan each DSR in a DSR bitmap. Note: multiple DSRs in an allocation unit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) #define for_each_dsr_in_allocation_map(i, map, k)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	for_each_set_bit((k), (const unsigned long *)(map), GRU_DSR_AU)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 		for ((i) = (k) * GRU_DSR_AU_CL;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 				(i) < ((k) + 1) * GRU_DSR_AU_CL; (i)++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) #define gseg_physical_address(gru, ctxnum)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 		((gru)->gs_gru_base_paddr + ctxnum * GRU_GSEG_STRIDE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) #define gseg_virtual_address(gru, ctxnum)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 		((gru)->gs_gru_base_vaddr + ctxnum * GRU_GSEG_STRIDE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) /*-----------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)  * Lock / Unlock GRU handles
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)  * 	Use the "delresp" bit in the handle as a "lock" bit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) /* Lock hierarchy checking enabled only in emulator */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) /* 0 = lock failed, 1 = locked */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) static inline int __trylock_handle(void *h)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 	return !test_and_set_bit(1, h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) static inline void __lock_handle(void *h)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 	while (test_and_set_bit(1, h))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 		cpu_relax();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) static inline void __unlock_handle(void *h)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	clear_bit(1, h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) static inline int trylock_cch_handle(struct gru_context_configuration_handle *cch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 	return __trylock_handle(cch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) static inline void lock_cch_handle(struct gru_context_configuration_handle *cch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	__lock_handle(cch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) static inline void unlock_cch_handle(struct gru_context_configuration_handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 				     *cch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 	__unlock_handle(cch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) static inline void lock_tgh_handle(struct gru_tlb_global_handle *tgh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 	__lock_handle(tgh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) static inline void unlock_tgh_handle(struct gru_tlb_global_handle *tgh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 	__unlock_handle(tgh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) static inline int is_kernel_context(struct gru_thread_state *gts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 	return !gts->ts_mm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599)  * The following are for Nehelem-EX. A more general scheme is needed for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600)  * future processors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) #define UV_MAX_INT_CORES		8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) #define uv_cpu_socket_number(p)		((cpu_physical_id(p) >> 5) & 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) #define uv_cpu_ht_number(p)		(cpu_physical_id(p) & 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) #define uv_cpu_core_number(p)		(((cpu_physical_id(p) >> 2) & 4) |	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 					((cpu_physical_id(p) >> 1) & 3))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) /*-----------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608)  * Function prototypes & externs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) struct gru_unload_context_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) extern const struct vm_operations_struct gru_vm_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) extern struct device *grudev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) extern struct gru_vma_data *gru_alloc_vma_data(struct vm_area_struct *vma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 				int tsid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) extern struct gru_thread_state *gru_find_thread_state(struct vm_area_struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 				*vma, int tsid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) extern struct gru_thread_state *gru_alloc_thread_state(struct vm_area_struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 				*vma, int tsid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) extern struct gru_state *gru_assign_gru_context(struct gru_thread_state *gts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) extern void gru_load_context(struct gru_thread_state *gts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) extern void gru_steal_context(struct gru_thread_state *gts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) extern void gru_unload_context(struct gru_thread_state *gts, int savestate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) extern int gru_update_cch(struct gru_thread_state *gts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) extern void gts_drop(struct gru_thread_state *gts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) extern void gru_tgh_flush_init(struct gru_state *gru);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) extern int gru_kservices_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) extern void gru_kservices_exit(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) extern irqreturn_t gru0_intr(int irq, void *dev_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) extern irqreturn_t gru1_intr(int irq, void *dev_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) extern irqreturn_t gru_intr_mblade(int irq, void *dev_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) extern int gru_dump_chiplet_request(unsigned long arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) extern long gru_get_gseg_statistics(unsigned long arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) extern int gru_handle_user_call_os(unsigned long address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) extern int gru_user_flush_tlb(unsigned long arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) extern int gru_user_unload_context(unsigned long arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) extern int gru_get_exception_detail(unsigned long arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) extern int gru_set_context_option(unsigned long address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) extern void gru_check_context_placement(struct gru_thread_state *gts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) extern int gru_cpu_fault_map_id(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) extern struct vm_area_struct *gru_find_vma(unsigned long vaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) extern void gru_flush_all_tlb(struct gru_state *gru);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) extern int gru_proc_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) extern void gru_proc_exit(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) extern struct gru_thread_state *gru_alloc_gts(struct vm_area_struct *vma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 		int cbr_au_count, int dsr_au_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 		unsigned char tlb_preload_count, int options, int tsid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) extern unsigned long gru_reserve_cb_resources(struct gru_state *gru,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 		int cbr_au_count, char *cbmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) extern unsigned long gru_reserve_ds_resources(struct gru_state *gru,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 		int dsr_au_count, char *dsmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) extern vm_fault_t gru_fault(struct vm_fault *vmf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) extern struct gru_mm_struct *gru_register_mmu_notifier(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) extern void gru_drop_mmu_notifier(struct gru_mm_struct *gms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) extern int gru_ktest(unsigned long arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) extern void gru_flush_tlb_range(struct gru_mm_struct *gms, unsigned long start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 					unsigned long len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) extern unsigned long gru_options;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) #endif /* __GRUTABLES_H__ */