1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun *
3*4882a593Smuzhiyun * (C) COPYRIGHT 2011-2017 ARM Limited. All rights reserved.
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * This program is free software and is provided to you under the terms of the
6*4882a593Smuzhiyun * GNU General Public License version 2 as published by the Free Software
7*4882a593Smuzhiyun * Foundation, and any use by you of this program is subject to the terms
8*4882a593Smuzhiyun * of such GNU licence.
9*4882a593Smuzhiyun *
10*4882a593Smuzhiyun * A copy of the licence is included with the program, and can also be obtained
11*4882a593Smuzhiyun * from Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
12*4882a593Smuzhiyun * Boston, MA 02110-1301, USA.
13*4882a593Smuzhiyun *
14*4882a593Smuzhiyun */
15*4882a593Smuzhiyun
16*4882a593Smuzhiyun
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun /**
21*4882a593Smuzhiyun * @file mali_kbase_defs.h
22*4882a593Smuzhiyun *
23*4882a593Smuzhiyun * Defintions (types, defines, etcs) common to Kbase. They are placed here to
24*4882a593Smuzhiyun * allow the hierarchy of header files to work.
25*4882a593Smuzhiyun */
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun #ifndef _KBASE_DEFS_H_
28*4882a593Smuzhiyun #define _KBASE_DEFS_H_
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun #include <mali_kbase_config.h>
31*4882a593Smuzhiyun #include <mali_base_hwconfig_features.h>
32*4882a593Smuzhiyun #include <mali_base_hwconfig_issues.h>
33*4882a593Smuzhiyun #include <mali_kbase_mem_lowlevel.h>
34*4882a593Smuzhiyun #include <mali_kbase_mmu_hw.h>
35*4882a593Smuzhiyun #include <mali_kbase_mmu_mode.h>
36*4882a593Smuzhiyun #include <mali_kbase_instr_defs.h>
37*4882a593Smuzhiyun #include <mali_kbase_pm.h>
38*4882a593Smuzhiyun #include <protected_mode_switcher.h>
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun #include <linux/atomic.h>
41*4882a593Smuzhiyun #include <linux/mempool.h>
42*4882a593Smuzhiyun #include <linux/slab.h>
43*4882a593Smuzhiyun #include <linux/file.h>
44*4882a593Smuzhiyun
45*4882a593Smuzhiyun #ifdef CONFIG_MALI_FPGA_BUS_LOGGER
46*4882a593Smuzhiyun #include <linux/bus_logger.h>
47*4882a593Smuzhiyun #endif
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun #ifdef CONFIG_KDS
51*4882a593Smuzhiyun #include <linux/kds.h>
52*4882a593Smuzhiyun #endif /* CONFIG_KDS */
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun #if defined(CONFIG_SYNC)
55*4882a593Smuzhiyun #include <sync.h>
56*4882a593Smuzhiyun #else
57*4882a593Smuzhiyun #include "mali_kbase_fence_defs.h"
58*4882a593Smuzhiyun #endif
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun #ifdef CONFIG_DEBUG_FS
61*4882a593Smuzhiyun #include <linux/debugfs.h>
62*4882a593Smuzhiyun #endif /* CONFIG_DEBUG_FS */
63*4882a593Smuzhiyun
64*4882a593Smuzhiyun #ifdef CONFIG_MALI_DEVFREQ
65*4882a593Smuzhiyun #include <linux/devfreq.h>
66*4882a593Smuzhiyun #endif /* CONFIG_MALI_DEVFREQ */
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun #include <linux/clk.h>
69*4882a593Smuzhiyun #include <linux/regulator/consumer.h>
70*4882a593Smuzhiyun #include <soc/rockchip/rockchip_opp_select.h>
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun #if defined(CONFIG_PM)
73*4882a593Smuzhiyun #define KBASE_PM_RUNTIME 1
74*4882a593Smuzhiyun #endif
75*4882a593Smuzhiyun
76*4882a593Smuzhiyun /** Enable SW tracing when set */
77*4882a593Smuzhiyun #ifdef CONFIG_MALI_MIDGARD_ENABLE_TRACE
78*4882a593Smuzhiyun #define KBASE_TRACE_ENABLE 1
79*4882a593Smuzhiyun #endif
80*4882a593Smuzhiyun
81*4882a593Smuzhiyun #ifndef KBASE_TRACE_ENABLE
82*4882a593Smuzhiyun #ifdef CONFIG_MALI_DEBUG
83*4882a593Smuzhiyun #define KBASE_TRACE_ENABLE 1
84*4882a593Smuzhiyun #else
85*4882a593Smuzhiyun #define KBASE_TRACE_ENABLE 0
86*4882a593Smuzhiyun #endif /* CONFIG_MALI_DEBUG */
87*4882a593Smuzhiyun #endif /* KBASE_TRACE_ENABLE */
88*4882a593Smuzhiyun
89*4882a593Smuzhiyun /** Dump Job slot trace on error (only active if KBASE_TRACE_ENABLE != 0) */
90*4882a593Smuzhiyun #define KBASE_TRACE_DUMP_ON_JOB_SLOT_ERROR 1
91*4882a593Smuzhiyun
92*4882a593Smuzhiyun /**
93*4882a593Smuzhiyun * Number of milliseconds before resetting the GPU when a job cannot be "zapped" from the hardware.
94*4882a593Smuzhiyun * Note that the time is actually ZAP_TIMEOUT+SOFT_STOP_RESET_TIMEOUT between the context zap starting and the GPU
95*4882a593Smuzhiyun * actually being reset to give other contexts time for their jobs to be soft-stopped and removed from the hardware
96*4882a593Smuzhiyun * before resetting.
97*4882a593Smuzhiyun */
98*4882a593Smuzhiyun #define ZAP_TIMEOUT 1000
99*4882a593Smuzhiyun
100*4882a593Smuzhiyun /** Number of milliseconds before we time out on a GPU soft/hard reset */
101*4882a593Smuzhiyun #define RESET_TIMEOUT 500
102*4882a593Smuzhiyun
103*4882a593Smuzhiyun /**
104*4882a593Smuzhiyun * Prevent soft-stops from occuring in scheduling situations
105*4882a593Smuzhiyun *
106*4882a593Smuzhiyun * This is not due to HW issues, but when scheduling is desired to be more predictable.
107*4882a593Smuzhiyun *
108*4882a593Smuzhiyun * Therefore, soft stop may still be disabled due to HW issues.
109*4882a593Smuzhiyun *
110*4882a593Smuzhiyun * @note Soft stop will still be used for non-scheduling purposes e.g. when terminating a context.
111*4882a593Smuzhiyun *
112*4882a593Smuzhiyun * @note if not in use, define this value to 0 instead of \#undef'ing it
113*4882a593Smuzhiyun */
114*4882a593Smuzhiyun #define KBASE_DISABLE_SCHEDULING_SOFT_STOPS 0
115*4882a593Smuzhiyun
116*4882a593Smuzhiyun /**
117*4882a593Smuzhiyun * Prevent hard-stops from occuring in scheduling situations
118*4882a593Smuzhiyun *
119*4882a593Smuzhiyun * This is not due to HW issues, but when scheduling is desired to be more predictable.
120*4882a593Smuzhiyun *
121*4882a593Smuzhiyun * @note Hard stop will still be used for non-scheduling purposes e.g. when terminating a context.
122*4882a593Smuzhiyun *
123*4882a593Smuzhiyun * @note if not in use, define this value to 0 instead of \#undef'ing it
124*4882a593Smuzhiyun */
125*4882a593Smuzhiyun #define KBASE_DISABLE_SCHEDULING_HARD_STOPS 0
126*4882a593Smuzhiyun
127*4882a593Smuzhiyun /**
128*4882a593Smuzhiyun * The maximum number of Job Slots to support in the Hardware.
129*4882a593Smuzhiyun *
130*4882a593Smuzhiyun * You can optimize this down if your target devices will only ever support a
131*4882a593Smuzhiyun * small number of job slots.
132*4882a593Smuzhiyun */
133*4882a593Smuzhiyun #define BASE_JM_MAX_NR_SLOTS 3
134*4882a593Smuzhiyun
135*4882a593Smuzhiyun /**
136*4882a593Smuzhiyun * The maximum number of Address Spaces to support in the Hardware.
137*4882a593Smuzhiyun *
138*4882a593Smuzhiyun * You can optimize this down if your target devices will only ever support a
139*4882a593Smuzhiyun * small number of Address Spaces
140*4882a593Smuzhiyun */
141*4882a593Smuzhiyun #define BASE_MAX_NR_AS 16
142*4882a593Smuzhiyun
143*4882a593Smuzhiyun /* mmu */
144*4882a593Smuzhiyun #define MIDGARD_MMU_VA_BITS 48
145*4882a593Smuzhiyun
146*4882a593Smuzhiyun #if MIDGARD_MMU_VA_BITS > 39
147*4882a593Smuzhiyun #define MIDGARD_MMU_TOPLEVEL 0
148*4882a593Smuzhiyun #else
149*4882a593Smuzhiyun #define MIDGARD_MMU_TOPLEVEL 1
150*4882a593Smuzhiyun #endif
151*4882a593Smuzhiyun
152*4882a593Smuzhiyun #define MIDGARD_MMU_BOTTOMLEVEL 3
153*4882a593Smuzhiyun
154*4882a593Smuzhiyun #define GROWABLE_FLAGS_REQUIRED (KBASE_REG_PF_GROW | KBASE_REG_GPU_WR)
155*4882a593Smuzhiyun
156*4882a593Smuzhiyun /** setting in kbase_context::as_nr that indicates it's invalid */
157*4882a593Smuzhiyun #define KBASEP_AS_NR_INVALID (-1)
158*4882a593Smuzhiyun
159*4882a593Smuzhiyun #define KBASE_LOCK_REGION_MAX_SIZE (63)
160*4882a593Smuzhiyun #define KBASE_LOCK_REGION_MIN_SIZE (11)
161*4882a593Smuzhiyun
162*4882a593Smuzhiyun #define KBASE_TRACE_SIZE_LOG2 8 /* 256 entries */
163*4882a593Smuzhiyun #define KBASE_TRACE_SIZE (1 << KBASE_TRACE_SIZE_LOG2)
164*4882a593Smuzhiyun #define KBASE_TRACE_MASK ((1 << KBASE_TRACE_SIZE_LOG2)-1)
165*4882a593Smuzhiyun
166*4882a593Smuzhiyun #include "mali_kbase_js_defs.h"
167*4882a593Smuzhiyun #include "mali_kbase_hwaccess_defs.h"
168*4882a593Smuzhiyun
169*4882a593Smuzhiyun #define KBASEP_FORCE_REPLAY_DISABLED 0
170*4882a593Smuzhiyun
171*4882a593Smuzhiyun /* Maximum force replay limit when randomization is enabled */
172*4882a593Smuzhiyun #define KBASEP_FORCE_REPLAY_RANDOM_LIMIT 16
173*4882a593Smuzhiyun
174*4882a593Smuzhiyun /** Atom has been previously soft-stoppped */
175*4882a593Smuzhiyun #define KBASE_KATOM_FLAG_BEEN_SOFT_STOPPPED (1<<1)
176*4882a593Smuzhiyun /** Atom has been previously retried to execute */
177*4882a593Smuzhiyun #define KBASE_KATOM_FLAGS_RERUN (1<<2)
178*4882a593Smuzhiyun #define KBASE_KATOM_FLAGS_JOBCHAIN (1<<3)
179*4882a593Smuzhiyun /** Atom has been previously hard-stopped. */
180*4882a593Smuzhiyun #define KBASE_KATOM_FLAG_BEEN_HARD_STOPPED (1<<4)
181*4882a593Smuzhiyun /** Atom has caused us to enter disjoint state */
182*4882a593Smuzhiyun #define KBASE_KATOM_FLAG_IN_DISJOINT (1<<5)
183*4882a593Smuzhiyun /* Atom blocked on cross-slot dependency */
184*4882a593Smuzhiyun #define KBASE_KATOM_FLAG_X_DEP_BLOCKED (1<<7)
185*4882a593Smuzhiyun /* Atom has fail dependency on cross-slot dependency */
186*4882a593Smuzhiyun #define KBASE_KATOM_FLAG_FAIL_BLOCKER (1<<8)
187*4882a593Smuzhiyun /* Atom is currently in the list of atoms blocked on cross-slot dependencies */
188*4882a593Smuzhiyun #define KBASE_KATOM_FLAG_JSCTX_IN_X_DEP_LIST (1<<9)
189*4882a593Smuzhiyun /* Atom is currently holding a context reference */
190*4882a593Smuzhiyun #define KBASE_KATOM_FLAG_HOLDING_CTX_REF (1<<10)
191*4882a593Smuzhiyun /* Atom requires GPU to be in protected mode */
192*4882a593Smuzhiyun #define KBASE_KATOM_FLAG_PROTECTED (1<<11)
193*4882a593Smuzhiyun /* Atom has been stored in runnable_tree */
194*4882a593Smuzhiyun #define KBASE_KATOM_FLAG_JSCTX_IN_TREE (1<<12)
195*4882a593Smuzhiyun
196*4882a593Smuzhiyun /* SW related flags about types of JS_COMMAND action
197*4882a593Smuzhiyun * NOTE: These must be masked off by JS_COMMAND_MASK */
198*4882a593Smuzhiyun
199*4882a593Smuzhiyun /** This command causes a disjoint event */
200*4882a593Smuzhiyun #define JS_COMMAND_SW_CAUSES_DISJOINT 0x100
201*4882a593Smuzhiyun
202*4882a593Smuzhiyun /** Bitmask of all SW related flags */
203*4882a593Smuzhiyun #define JS_COMMAND_SW_BITS (JS_COMMAND_SW_CAUSES_DISJOINT)
204*4882a593Smuzhiyun
205*4882a593Smuzhiyun #if (JS_COMMAND_SW_BITS & JS_COMMAND_MASK)
206*4882a593Smuzhiyun #error JS_COMMAND_SW_BITS not masked off by JS_COMMAND_MASK. Must update JS_COMMAND_SW_<..> bitmasks
207*4882a593Smuzhiyun #endif
208*4882a593Smuzhiyun
209*4882a593Smuzhiyun /** Soft-stop command that causes a Disjoint event. This of course isn't
210*4882a593Smuzhiyun * entirely masked off by JS_COMMAND_MASK */
211*4882a593Smuzhiyun #define JS_COMMAND_SOFT_STOP_WITH_SW_DISJOINT \
212*4882a593Smuzhiyun (JS_COMMAND_SW_CAUSES_DISJOINT | JS_COMMAND_SOFT_STOP)
213*4882a593Smuzhiyun
214*4882a593Smuzhiyun #define KBASEP_ATOM_ID_INVALID BASE_JD_ATOM_COUNT
215*4882a593Smuzhiyun
216*4882a593Smuzhiyun /* Serialize atoms within a slot (ie only one atom per job slot) */
217*4882a593Smuzhiyun #define KBASE_SERIALIZE_INTRA_SLOT (1 << 0)
218*4882a593Smuzhiyun /* Serialize atoms between slots (ie only one job slot running at any time) */
219*4882a593Smuzhiyun #define KBASE_SERIALIZE_INTER_SLOT (1 << 1)
220*4882a593Smuzhiyun /* Reset the GPU after each atom completion */
221*4882a593Smuzhiyun #define KBASE_SERIALIZE_RESET (1 << 2)
222*4882a593Smuzhiyun
223*4882a593Smuzhiyun #ifdef CONFIG_DEBUG_FS
224*4882a593Smuzhiyun struct base_job_fault_event {
225*4882a593Smuzhiyun
226*4882a593Smuzhiyun u32 event_code;
227*4882a593Smuzhiyun struct kbase_jd_atom *katom;
228*4882a593Smuzhiyun struct work_struct job_fault_work;
229*4882a593Smuzhiyun struct list_head head;
230*4882a593Smuzhiyun int reg_offset;
231*4882a593Smuzhiyun };
232*4882a593Smuzhiyun
233*4882a593Smuzhiyun #endif
234*4882a593Smuzhiyun
235*4882a593Smuzhiyun struct kbase_jd_atom_dependency {
236*4882a593Smuzhiyun struct kbase_jd_atom *atom;
237*4882a593Smuzhiyun u8 dep_type;
238*4882a593Smuzhiyun };
239*4882a593Smuzhiyun
240*4882a593Smuzhiyun /**
241*4882a593Smuzhiyun * struct kbase_io_access - holds information about 1 register access
242*4882a593Smuzhiyun *
243*4882a593Smuzhiyun * @addr: first bit indicates r/w (r=0, w=1)
244*4882a593Smuzhiyun * @value: value written or read
245*4882a593Smuzhiyun */
246*4882a593Smuzhiyun struct kbase_io_access {
247*4882a593Smuzhiyun uintptr_t addr;
248*4882a593Smuzhiyun u32 value;
249*4882a593Smuzhiyun };
250*4882a593Smuzhiyun
251*4882a593Smuzhiyun /**
252*4882a593Smuzhiyun * struct kbase_io_history - keeps track of all recent register accesses
253*4882a593Smuzhiyun *
254*4882a593Smuzhiyun * @enabled: true if register accesses are recorded, false otherwise
255*4882a593Smuzhiyun * @lock: spinlock protecting kbase_io_access array
256*4882a593Smuzhiyun * @count: number of registers read/written
257*4882a593Smuzhiyun * @size: number of elements in kbase_io_access array
258*4882a593Smuzhiyun * @buf: array of kbase_io_access
259*4882a593Smuzhiyun */
260*4882a593Smuzhiyun struct kbase_io_history {
261*4882a593Smuzhiyun #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0))
262*4882a593Smuzhiyun bool enabled;
263*4882a593Smuzhiyun #else
264*4882a593Smuzhiyun u32 enabled;
265*4882a593Smuzhiyun #endif
266*4882a593Smuzhiyun
267*4882a593Smuzhiyun spinlock_t lock;
268*4882a593Smuzhiyun size_t count;
269*4882a593Smuzhiyun u16 size;
270*4882a593Smuzhiyun struct kbase_io_access *buf;
271*4882a593Smuzhiyun };
272*4882a593Smuzhiyun
273*4882a593Smuzhiyun /**
274*4882a593Smuzhiyun * @brief The function retrieves a read-only reference to the atom field from
275*4882a593Smuzhiyun * the kbase_jd_atom_dependency structure
276*4882a593Smuzhiyun *
277*4882a593Smuzhiyun * @param[in] dep kbase jd atom dependency.
278*4882a593Smuzhiyun *
279*4882a593Smuzhiyun * @return readonly reference to dependent ATOM.
280*4882a593Smuzhiyun */
kbase_jd_katom_dep_atom(const struct kbase_jd_atom_dependency * dep)281*4882a593Smuzhiyun static inline const struct kbase_jd_atom * kbase_jd_katom_dep_atom(const struct kbase_jd_atom_dependency *dep)
282*4882a593Smuzhiyun {
283*4882a593Smuzhiyun LOCAL_ASSERT(dep != NULL);
284*4882a593Smuzhiyun
285*4882a593Smuzhiyun return (const struct kbase_jd_atom *)(dep->atom);
286*4882a593Smuzhiyun }
287*4882a593Smuzhiyun
288*4882a593Smuzhiyun /**
289*4882a593Smuzhiyun * @brief The function retrieves a read-only reference to the dependency type field from
290*4882a593Smuzhiyun * the kbase_jd_atom_dependency structure
291*4882a593Smuzhiyun *
292*4882a593Smuzhiyun * @param[in] dep kbase jd atom dependency.
293*4882a593Smuzhiyun *
294*4882a593Smuzhiyun * @return A dependency type value.
295*4882a593Smuzhiyun */
kbase_jd_katom_dep_type(const struct kbase_jd_atom_dependency * dep)296*4882a593Smuzhiyun static inline u8 kbase_jd_katom_dep_type(const struct kbase_jd_atom_dependency *dep)
297*4882a593Smuzhiyun {
298*4882a593Smuzhiyun LOCAL_ASSERT(dep != NULL);
299*4882a593Smuzhiyun
300*4882a593Smuzhiyun return dep->dep_type;
301*4882a593Smuzhiyun }
302*4882a593Smuzhiyun
303*4882a593Smuzhiyun /**
304*4882a593Smuzhiyun * @brief Setter macro for dep_atom array entry in kbase_jd_atom
305*4882a593Smuzhiyun *
306*4882a593Smuzhiyun * @param[in] dep The kbase jd atom dependency.
307*4882a593Smuzhiyun * @param[in] a The ATOM to be set as a dependency.
308*4882a593Smuzhiyun * @param type The ATOM dependency type to be set.
309*4882a593Smuzhiyun *
310*4882a593Smuzhiyun */
kbase_jd_katom_dep_set(const struct kbase_jd_atom_dependency * const_dep,struct kbase_jd_atom * a,u8 type)311*4882a593Smuzhiyun static inline void kbase_jd_katom_dep_set(const struct kbase_jd_atom_dependency *const_dep,
312*4882a593Smuzhiyun struct kbase_jd_atom *a, u8 type)
313*4882a593Smuzhiyun {
314*4882a593Smuzhiyun struct kbase_jd_atom_dependency *dep;
315*4882a593Smuzhiyun
316*4882a593Smuzhiyun LOCAL_ASSERT(const_dep != NULL);
317*4882a593Smuzhiyun
318*4882a593Smuzhiyun dep = (struct kbase_jd_atom_dependency *)const_dep;
319*4882a593Smuzhiyun
320*4882a593Smuzhiyun dep->atom = a;
321*4882a593Smuzhiyun dep->dep_type = type;
322*4882a593Smuzhiyun }
323*4882a593Smuzhiyun
324*4882a593Smuzhiyun /**
325*4882a593Smuzhiyun * @brief Setter macro for dep_atom array entry in kbase_jd_atom
326*4882a593Smuzhiyun *
327*4882a593Smuzhiyun * @param[in] dep The kbase jd atom dependency to be cleared.
328*4882a593Smuzhiyun *
329*4882a593Smuzhiyun */
kbase_jd_katom_dep_clear(const struct kbase_jd_atom_dependency * const_dep)330*4882a593Smuzhiyun static inline void kbase_jd_katom_dep_clear(const struct kbase_jd_atom_dependency *const_dep)
331*4882a593Smuzhiyun {
332*4882a593Smuzhiyun struct kbase_jd_atom_dependency *dep;
333*4882a593Smuzhiyun
334*4882a593Smuzhiyun LOCAL_ASSERT(const_dep != NULL);
335*4882a593Smuzhiyun
336*4882a593Smuzhiyun dep = (struct kbase_jd_atom_dependency *)const_dep;
337*4882a593Smuzhiyun
338*4882a593Smuzhiyun dep->atom = NULL;
339*4882a593Smuzhiyun dep->dep_type = BASE_JD_DEP_TYPE_INVALID;
340*4882a593Smuzhiyun }
341*4882a593Smuzhiyun
342*4882a593Smuzhiyun enum kbase_atom_gpu_rb_state {
343*4882a593Smuzhiyun /* Atom is not currently present in slot ringbuffer */
344*4882a593Smuzhiyun KBASE_ATOM_GPU_RB_NOT_IN_SLOT_RB,
345*4882a593Smuzhiyun /* Atom is in slot ringbuffer but is blocked on a previous atom */
346*4882a593Smuzhiyun KBASE_ATOM_GPU_RB_WAITING_BLOCKED,
347*4882a593Smuzhiyun /* Atom is in slot ringbuffer but is waiting for a previous protected
348*4882a593Smuzhiyun * mode transition to complete */
349*4882a593Smuzhiyun KBASE_ATOM_GPU_RB_WAITING_PROTECTED_MODE_PREV,
350*4882a593Smuzhiyun /* Atom is in slot ringbuffer but is waiting for proected mode
351*4882a593Smuzhiyun * transition */
352*4882a593Smuzhiyun KBASE_ATOM_GPU_RB_WAITING_PROTECTED_MODE_TRANSITION,
353*4882a593Smuzhiyun /* Atom is in slot ringbuffer but is waiting for cores to become
354*4882a593Smuzhiyun * available */
355*4882a593Smuzhiyun KBASE_ATOM_GPU_RB_WAITING_FOR_CORE_AVAILABLE,
356*4882a593Smuzhiyun /* Atom is in slot ringbuffer but is blocked on affinity */
357*4882a593Smuzhiyun KBASE_ATOM_GPU_RB_WAITING_AFFINITY,
358*4882a593Smuzhiyun /* Atom is in slot ringbuffer and ready to run */
359*4882a593Smuzhiyun KBASE_ATOM_GPU_RB_READY,
360*4882a593Smuzhiyun /* Atom is in slot ringbuffer and has been submitted to the GPU */
361*4882a593Smuzhiyun KBASE_ATOM_GPU_RB_SUBMITTED,
362*4882a593Smuzhiyun /* Atom must be returned to JS as soon as it reaches the head of the
363*4882a593Smuzhiyun * ringbuffer due to a previous failure */
364*4882a593Smuzhiyun KBASE_ATOM_GPU_RB_RETURN_TO_JS = -1
365*4882a593Smuzhiyun };
366*4882a593Smuzhiyun
367*4882a593Smuzhiyun enum kbase_atom_enter_protected_state {
368*4882a593Smuzhiyun /*
369*4882a593Smuzhiyun * Starting state:
370*4882a593Smuzhiyun * Check if a transition into protected mode is required.
371*4882a593Smuzhiyun *
372*4882a593Smuzhiyun * NOTE: The integer value of this must
373*4882a593Smuzhiyun * match KBASE_ATOM_EXIT_PROTECTED_CHECK.
374*4882a593Smuzhiyun */
375*4882a593Smuzhiyun KBASE_ATOM_ENTER_PROTECTED_CHECK = 0,
376*4882a593Smuzhiyun /* Wait for vinstr to suspend. */
377*4882a593Smuzhiyun KBASE_ATOM_ENTER_PROTECTED_VINSTR,
378*4882a593Smuzhiyun /* Wait for the L2 to become idle in preparation for
379*4882a593Smuzhiyun * the coherency change. */
380*4882a593Smuzhiyun KBASE_ATOM_ENTER_PROTECTED_IDLE_L2,
381*4882a593Smuzhiyun /* End state;
382*4882a593Smuzhiyun * Prepare coherency change. */
383*4882a593Smuzhiyun KBASE_ATOM_ENTER_PROTECTED_FINISHED,
384*4882a593Smuzhiyun };
385*4882a593Smuzhiyun
386*4882a593Smuzhiyun enum kbase_atom_exit_protected_state {
387*4882a593Smuzhiyun /*
388*4882a593Smuzhiyun * Starting state:
389*4882a593Smuzhiyun * Check if a transition out of protected mode is required.
390*4882a593Smuzhiyun *
391*4882a593Smuzhiyun * NOTE: The integer value of this must
392*4882a593Smuzhiyun * match KBASE_ATOM_ENTER_PROTECTED_CHECK.
393*4882a593Smuzhiyun */
394*4882a593Smuzhiyun KBASE_ATOM_EXIT_PROTECTED_CHECK = 0,
395*4882a593Smuzhiyun /* Wait for the L2 to become idle in preparation
396*4882a593Smuzhiyun * for the reset. */
397*4882a593Smuzhiyun KBASE_ATOM_EXIT_PROTECTED_IDLE_L2,
398*4882a593Smuzhiyun /* Issue the protected reset. */
399*4882a593Smuzhiyun KBASE_ATOM_EXIT_PROTECTED_RESET,
400*4882a593Smuzhiyun /* End state;
401*4882a593Smuzhiyun * Wait for the reset to complete. */
402*4882a593Smuzhiyun KBASE_ATOM_EXIT_PROTECTED_RESET_WAIT,
403*4882a593Smuzhiyun };
404*4882a593Smuzhiyun
405*4882a593Smuzhiyun struct kbase_ext_res {
406*4882a593Smuzhiyun u64 gpu_address;
407*4882a593Smuzhiyun struct kbase_mem_phy_alloc *alloc;
408*4882a593Smuzhiyun };
409*4882a593Smuzhiyun
410*4882a593Smuzhiyun struct kbase_jd_atom {
411*4882a593Smuzhiyun struct work_struct work;
412*4882a593Smuzhiyun ktime_t start_timestamp;
413*4882a593Smuzhiyun
414*4882a593Smuzhiyun struct base_jd_udata udata;
415*4882a593Smuzhiyun struct kbase_context *kctx;
416*4882a593Smuzhiyun
417*4882a593Smuzhiyun struct list_head dep_head[2];
418*4882a593Smuzhiyun struct list_head dep_item[2];
419*4882a593Smuzhiyun const struct kbase_jd_atom_dependency dep[2];
420*4882a593Smuzhiyun /* List head used during job dispatch job_done processing - as
421*4882a593Smuzhiyun * dependencies may not be entirely resolved at this point, we need to
422*4882a593Smuzhiyun * use a separate list head. */
423*4882a593Smuzhiyun struct list_head jd_item;
424*4882a593Smuzhiyun /* true if atom's jd_item is currently on a list. Prevents atom being
425*4882a593Smuzhiyun * processed twice. */
426*4882a593Smuzhiyun bool in_jd_list;
427*4882a593Smuzhiyun
428*4882a593Smuzhiyun u16 nr_extres;
429*4882a593Smuzhiyun struct kbase_ext_res *extres;
430*4882a593Smuzhiyun
431*4882a593Smuzhiyun u32 device_nr;
432*4882a593Smuzhiyun u64 affinity;
433*4882a593Smuzhiyun u64 jc;
434*4882a593Smuzhiyun enum kbase_atom_coreref_state coreref_state;
435*4882a593Smuzhiyun #ifdef CONFIG_KDS
436*4882a593Smuzhiyun struct list_head node;
437*4882a593Smuzhiyun struct kds_resource_set *kds_rset;
438*4882a593Smuzhiyun bool kds_dep_satisfied;
439*4882a593Smuzhiyun #endif /* CONFIG_KDS */
440*4882a593Smuzhiyun #if defined(CONFIG_SYNC)
441*4882a593Smuzhiyun /* Stores either an input or output fence, depending on soft-job type */
442*4882a593Smuzhiyun struct sync_fence *fence;
443*4882a593Smuzhiyun struct sync_fence_waiter sync_waiter;
444*4882a593Smuzhiyun #endif /* CONFIG_SYNC */
445*4882a593Smuzhiyun #if defined(CONFIG_MALI_DMA_FENCE) || defined(CONFIG_SYNC_FILE)
446*4882a593Smuzhiyun struct {
447*4882a593Smuzhiyun /* Use the functions/API defined in mali_kbase_fence.h to
448*4882a593Smuzhiyun * when working with this sub struct */
449*4882a593Smuzhiyun #if defined(CONFIG_SYNC_FILE)
450*4882a593Smuzhiyun /* Input fence */
451*4882a593Smuzhiyun #if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0))
452*4882a593Smuzhiyun struct fence *fence_in;
453*4882a593Smuzhiyun #else
454*4882a593Smuzhiyun struct dma_fence *fence_in;
455*4882a593Smuzhiyun #endif
456*4882a593Smuzhiyun #endif
457*4882a593Smuzhiyun /* This points to the dma-buf output fence for this atom. If
458*4882a593Smuzhiyun * this is NULL then there is no fence for this atom and the
459*4882a593Smuzhiyun * following fields related to dma_fence may have invalid data.
460*4882a593Smuzhiyun *
461*4882a593Smuzhiyun * The context and seqno fields contain the details for this
462*4882a593Smuzhiyun * fence.
463*4882a593Smuzhiyun *
464*4882a593Smuzhiyun * This fence is signaled when the katom is completed,
465*4882a593Smuzhiyun * regardless of the event_code of the katom (signal also on
466*4882a593Smuzhiyun * failure).
467*4882a593Smuzhiyun */
468*4882a593Smuzhiyun #if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0))
469*4882a593Smuzhiyun struct fence *fence;
470*4882a593Smuzhiyun #else
471*4882a593Smuzhiyun struct dma_fence *fence;
472*4882a593Smuzhiyun #endif
473*4882a593Smuzhiyun /* The dma-buf fence context number for this atom. A unique
474*4882a593Smuzhiyun * context number is allocated to each katom in the context on
475*4882a593Smuzhiyun * context creation.
476*4882a593Smuzhiyun */
477*4882a593Smuzhiyun unsigned int context;
478*4882a593Smuzhiyun /* The dma-buf fence sequence number for this atom. This is
479*4882a593Smuzhiyun * increased every time this katom uses dma-buf fence.
480*4882a593Smuzhiyun */
481*4882a593Smuzhiyun atomic_t seqno;
482*4882a593Smuzhiyun /* This contains a list of all callbacks set up to wait on
483*4882a593Smuzhiyun * other fences. This atom must be held back from JS until all
484*4882a593Smuzhiyun * these callbacks have been called and dep_count have reached
485*4882a593Smuzhiyun * 0. The initial value of dep_count must be equal to the
486*4882a593Smuzhiyun * number of callbacks on this list.
487*4882a593Smuzhiyun *
488*4882a593Smuzhiyun * This list is protected by jctx.lock. Callbacks are added to
489*4882a593Smuzhiyun * this list when the atom is built and the wait are set up.
490*4882a593Smuzhiyun * All the callbacks then stay on the list until all callbacks
491*4882a593Smuzhiyun * have been called and the atom is queued, or cancelled, and
492*4882a593Smuzhiyun * then all callbacks are taken off the list and freed.
493*4882a593Smuzhiyun */
494*4882a593Smuzhiyun struct list_head callbacks;
495*4882a593Smuzhiyun /* Atomic counter of number of outstandind dma-buf fence
496*4882a593Smuzhiyun * dependencies for this atom. When dep_count reaches 0 the
497*4882a593Smuzhiyun * atom may be queued.
498*4882a593Smuzhiyun *
499*4882a593Smuzhiyun * The special value "-1" may only be set after the count
500*4882a593Smuzhiyun * reaches 0, while holding jctx.lock. This indicates that the
501*4882a593Smuzhiyun * atom has been handled, either queued in JS or cancelled.
502*4882a593Smuzhiyun *
503*4882a593Smuzhiyun * If anyone but the dma-fence worker sets this to -1 they must
504*4882a593Smuzhiyun * ensure that any potentially queued worker must have
505*4882a593Smuzhiyun * completed before allowing the atom to be marked as unused.
506*4882a593Smuzhiyun * This can be done by flushing the fence work queue:
507*4882a593Smuzhiyun * kctx->dma_fence.wq.
508*4882a593Smuzhiyun */
509*4882a593Smuzhiyun atomic_t dep_count;
510*4882a593Smuzhiyun } dma_fence;
511*4882a593Smuzhiyun #endif /* CONFIG_MALI_DMA_FENCE || CONFIG_SYNC_FILE*/
512*4882a593Smuzhiyun
513*4882a593Smuzhiyun /* Note: refer to kbasep_js_atom_retained_state, which will take a copy of some of the following members */
514*4882a593Smuzhiyun enum base_jd_event_code event_code;
515*4882a593Smuzhiyun base_jd_core_req core_req; /**< core requirements */
516*4882a593Smuzhiyun /** Job Slot to retry submitting to if submission from IRQ handler failed
517*4882a593Smuzhiyun *
518*4882a593Smuzhiyun * NOTE: see if this can be unified into the another member e.g. the event */
519*4882a593Smuzhiyun int retry_submit_on_slot;
520*4882a593Smuzhiyun
521*4882a593Smuzhiyun u32 ticks;
522*4882a593Smuzhiyun /* JS atom priority with respect to other atoms on its kctx. */
523*4882a593Smuzhiyun int sched_priority;
524*4882a593Smuzhiyun
525*4882a593Smuzhiyun int poking; /* BASE_HW_ISSUE_8316 */
526*4882a593Smuzhiyun
527*4882a593Smuzhiyun wait_queue_head_t completed;
528*4882a593Smuzhiyun enum kbase_jd_atom_state status;
529*4882a593Smuzhiyun #ifdef CONFIG_GPU_TRACEPOINTS
530*4882a593Smuzhiyun int work_id;
531*4882a593Smuzhiyun #endif
532*4882a593Smuzhiyun /* Assigned after atom is completed. Used to check whether PRLAM-10676 workaround should be applied */
533*4882a593Smuzhiyun int slot_nr;
534*4882a593Smuzhiyun
535*4882a593Smuzhiyun u32 atom_flags;
536*4882a593Smuzhiyun
537*4882a593Smuzhiyun /* Number of times this atom has been retried. Used by replay soft job.
538*4882a593Smuzhiyun */
539*4882a593Smuzhiyun int retry_count;
540*4882a593Smuzhiyun
541*4882a593Smuzhiyun enum kbase_atom_gpu_rb_state gpu_rb_state;
542*4882a593Smuzhiyun
543*4882a593Smuzhiyun u64 need_cache_flush_cores_retained;
544*4882a593Smuzhiyun
545*4882a593Smuzhiyun atomic_t blocked;
546*4882a593Smuzhiyun
547*4882a593Smuzhiyun /* Pointer to atom that this atom has same-slot dependency on */
548*4882a593Smuzhiyun struct kbase_jd_atom *pre_dep;
549*4882a593Smuzhiyun /* Pointer to atom that has same-slot dependency on this atom */
550*4882a593Smuzhiyun struct kbase_jd_atom *post_dep;
551*4882a593Smuzhiyun
552*4882a593Smuzhiyun /* Pointer to atom that this atom has cross-slot dependency on */
553*4882a593Smuzhiyun struct kbase_jd_atom *x_pre_dep;
554*4882a593Smuzhiyun /* Pointer to atom that has cross-slot dependency on this atom */
555*4882a593Smuzhiyun struct kbase_jd_atom *x_post_dep;
556*4882a593Smuzhiyun
557*4882a593Smuzhiyun /* The GPU's flush count recorded at the time of submission, used for
558*4882a593Smuzhiyun * the cache flush optimisation */
559*4882a593Smuzhiyun u32 flush_id;
560*4882a593Smuzhiyun
561*4882a593Smuzhiyun struct kbase_jd_atom_backend backend;
562*4882a593Smuzhiyun #ifdef CONFIG_DEBUG_FS
563*4882a593Smuzhiyun struct base_job_fault_event fault_event;
564*4882a593Smuzhiyun #endif
565*4882a593Smuzhiyun
566*4882a593Smuzhiyun /* List head used for three different purposes:
567*4882a593Smuzhiyun * 1. Overflow list for JS ring buffers. If an atom is ready to run,
568*4882a593Smuzhiyun * but there is no room in the JS ring buffer, then the atom is put
569*4882a593Smuzhiyun * on the ring buffer's overflow list using this list node.
570*4882a593Smuzhiyun * 2. List of waiting soft jobs.
571*4882a593Smuzhiyun */
572*4882a593Smuzhiyun struct list_head queue;
573*4882a593Smuzhiyun
574*4882a593Smuzhiyun /* Used to keep track of all JIT free/alloc jobs in submission order
575*4882a593Smuzhiyun */
576*4882a593Smuzhiyun struct list_head jit_node;
577*4882a593Smuzhiyun bool jit_blocked;
578*4882a593Smuzhiyun
579*4882a593Smuzhiyun /* If non-zero, this indicates that the atom will fail with the set
580*4882a593Smuzhiyun * event_code when the atom is processed. */
581*4882a593Smuzhiyun enum base_jd_event_code will_fail_event_code;
582*4882a593Smuzhiyun
583*4882a593Smuzhiyun /* Atoms will only ever be transitioning into, or out of
584*4882a593Smuzhiyun * protected mode so we do not need two separate fields.
585*4882a593Smuzhiyun */
586*4882a593Smuzhiyun union {
587*4882a593Smuzhiyun enum kbase_atom_enter_protected_state enter;
588*4882a593Smuzhiyun enum kbase_atom_exit_protected_state exit;
589*4882a593Smuzhiyun } protected_state;
590*4882a593Smuzhiyun
591*4882a593Smuzhiyun struct rb_node runnable_tree_node;
592*4882a593Smuzhiyun
593*4882a593Smuzhiyun /* 'Age' of atom relative to other atoms in the context. */
594*4882a593Smuzhiyun u32 age;
595*4882a593Smuzhiyun };
596*4882a593Smuzhiyun
kbase_jd_katom_is_protected(const struct kbase_jd_atom * katom)597*4882a593Smuzhiyun static inline bool kbase_jd_katom_is_protected(const struct kbase_jd_atom *katom)
598*4882a593Smuzhiyun {
599*4882a593Smuzhiyun return (bool)(katom->atom_flags & KBASE_KATOM_FLAG_PROTECTED);
600*4882a593Smuzhiyun }
601*4882a593Smuzhiyun
602*4882a593Smuzhiyun /*
603*4882a593Smuzhiyun * Theory of operations:
604*4882a593Smuzhiyun *
605*4882a593Smuzhiyun * Atom objects are statically allocated within the context structure.
606*4882a593Smuzhiyun *
607*4882a593Smuzhiyun * Each atom is the head of two lists, one for the "left" set of dependencies, one for the "right" set.
608*4882a593Smuzhiyun */
609*4882a593Smuzhiyun
610*4882a593Smuzhiyun #define KBASE_JD_DEP_QUEUE_SIZE 256
611*4882a593Smuzhiyun
612*4882a593Smuzhiyun struct kbase_jd_context {
613*4882a593Smuzhiyun struct mutex lock;
614*4882a593Smuzhiyun struct kbasep_js_kctx_info sched_info;
615*4882a593Smuzhiyun struct kbase_jd_atom atoms[BASE_JD_ATOM_COUNT];
616*4882a593Smuzhiyun
617*4882a593Smuzhiyun /** Tracks all job-dispatch jobs. This includes those not tracked by
618*4882a593Smuzhiyun * the scheduler: 'not ready to run' and 'dependency-only' jobs. */
619*4882a593Smuzhiyun u32 job_nr;
620*4882a593Smuzhiyun
621*4882a593Smuzhiyun /** Waitq that reflects whether there are no jobs (including SW-only
622*4882a593Smuzhiyun * dependency jobs). This is set when no jobs are present on the ctx,
623*4882a593Smuzhiyun * and clear when there are jobs.
624*4882a593Smuzhiyun *
625*4882a593Smuzhiyun * @note: Job Dispatcher knows about more jobs than the Job Scheduler:
626*4882a593Smuzhiyun * the Job Scheduler is unaware of jobs that are blocked on dependencies,
627*4882a593Smuzhiyun * and SW-only dependency jobs.
628*4882a593Smuzhiyun *
629*4882a593Smuzhiyun * This waitq can be waited upon to find out when the context jobs are all
630*4882a593Smuzhiyun * done/cancelled (including those that might've been blocked on
631*4882a593Smuzhiyun * dependencies) - and so, whether it can be terminated. However, it should
632*4882a593Smuzhiyun * only be terminated once it is not present in the run-pool (see
633*4882a593Smuzhiyun * kbasep_js_kctx_info::ctx::is_scheduled).
634*4882a593Smuzhiyun *
635*4882a593Smuzhiyun * Since the waitq is only set under kbase_jd_context::lock,
636*4882a593Smuzhiyun * the waiter should also briefly obtain and drop kbase_jd_context::lock to
637*4882a593Smuzhiyun * guarentee that the setter has completed its work on the kbase_context
638*4882a593Smuzhiyun *
639*4882a593Smuzhiyun * This must be updated atomically with:
640*4882a593Smuzhiyun * - kbase_jd_context::job_nr */
641*4882a593Smuzhiyun wait_queue_head_t zero_jobs_wait;
642*4882a593Smuzhiyun
643*4882a593Smuzhiyun /** Job Done workqueue. */
644*4882a593Smuzhiyun struct workqueue_struct *job_done_wq;
645*4882a593Smuzhiyun
646*4882a593Smuzhiyun spinlock_t tb_lock;
647*4882a593Smuzhiyun u32 *tb;
648*4882a593Smuzhiyun size_t tb_wrap_offset;
649*4882a593Smuzhiyun
650*4882a593Smuzhiyun #ifdef CONFIG_KDS
651*4882a593Smuzhiyun struct kds_callback kds_cb;
652*4882a593Smuzhiyun #endif /* CONFIG_KDS */
653*4882a593Smuzhiyun #ifdef CONFIG_GPU_TRACEPOINTS
654*4882a593Smuzhiyun atomic_t work_id;
655*4882a593Smuzhiyun #endif
656*4882a593Smuzhiyun };
657*4882a593Smuzhiyun
658*4882a593Smuzhiyun struct kbase_device_info {
659*4882a593Smuzhiyun u32 features;
660*4882a593Smuzhiyun };
661*4882a593Smuzhiyun
662*4882a593Smuzhiyun /** Poking state for BASE_HW_ISSUE_8316 */
663*4882a593Smuzhiyun enum {
664*4882a593Smuzhiyun KBASE_AS_POKE_STATE_IN_FLIGHT = 1<<0,
665*4882a593Smuzhiyun KBASE_AS_POKE_STATE_KILLING_POKE = 1<<1
666*4882a593Smuzhiyun };
667*4882a593Smuzhiyun
668*4882a593Smuzhiyun /** Poking state for BASE_HW_ISSUE_8316 */
669*4882a593Smuzhiyun typedef u32 kbase_as_poke_state;
670*4882a593Smuzhiyun
671*4882a593Smuzhiyun struct kbase_mmu_setup {
672*4882a593Smuzhiyun u64 transtab;
673*4882a593Smuzhiyun u64 memattr;
674*4882a593Smuzhiyun u64 transcfg;
675*4882a593Smuzhiyun };
676*4882a593Smuzhiyun
677*4882a593Smuzhiyun /**
678*4882a593Smuzhiyun * Important: Our code makes assumptions that a struct kbase_as structure is always at
679*4882a593Smuzhiyun * kbase_device->as[number]. This is used to recover the containing
680*4882a593Smuzhiyun * struct kbase_device from a struct kbase_as structure.
681*4882a593Smuzhiyun *
682*4882a593Smuzhiyun * Therefore, struct kbase_as structures must not be allocated anywhere else.
683*4882a593Smuzhiyun */
684*4882a593Smuzhiyun struct kbase_as {
685*4882a593Smuzhiyun int number;
686*4882a593Smuzhiyun
687*4882a593Smuzhiyun struct workqueue_struct *pf_wq;
688*4882a593Smuzhiyun struct work_struct work_pagefault;
689*4882a593Smuzhiyun struct work_struct work_busfault;
690*4882a593Smuzhiyun enum kbase_mmu_fault_type fault_type;
691*4882a593Smuzhiyun bool protected_mode;
692*4882a593Smuzhiyun u32 fault_status;
693*4882a593Smuzhiyun u64 fault_addr;
694*4882a593Smuzhiyun u64 fault_extra_addr;
695*4882a593Smuzhiyun
696*4882a593Smuzhiyun struct kbase_mmu_setup current_setup;
697*4882a593Smuzhiyun
698*4882a593Smuzhiyun /* BASE_HW_ISSUE_8316 */
699*4882a593Smuzhiyun struct workqueue_struct *poke_wq;
700*4882a593Smuzhiyun struct work_struct poke_work;
701*4882a593Smuzhiyun /** Protected by hwaccess_lock */
702*4882a593Smuzhiyun int poke_refcount;
703*4882a593Smuzhiyun /** Protected by hwaccess_lock */
704*4882a593Smuzhiyun kbase_as_poke_state poke_state;
705*4882a593Smuzhiyun struct hrtimer poke_timer;
706*4882a593Smuzhiyun };
707*4882a593Smuzhiyun
kbase_as_has_bus_fault(struct kbase_as * as)708*4882a593Smuzhiyun static inline int kbase_as_has_bus_fault(struct kbase_as *as)
709*4882a593Smuzhiyun {
710*4882a593Smuzhiyun return as->fault_type == KBASE_MMU_FAULT_TYPE_BUS;
711*4882a593Smuzhiyun }
712*4882a593Smuzhiyun
kbase_as_has_page_fault(struct kbase_as * as)713*4882a593Smuzhiyun static inline int kbase_as_has_page_fault(struct kbase_as *as)
714*4882a593Smuzhiyun {
715*4882a593Smuzhiyun return as->fault_type == KBASE_MMU_FAULT_TYPE_PAGE;
716*4882a593Smuzhiyun }
717*4882a593Smuzhiyun
718*4882a593Smuzhiyun struct kbasep_mem_device {
719*4882a593Smuzhiyun atomic_t used_pages; /* Tracks usage of OS shared memory. Updated
720*4882a593Smuzhiyun when OS memory is allocated/freed. */
721*4882a593Smuzhiyun
722*4882a593Smuzhiyun };
723*4882a593Smuzhiyun
724*4882a593Smuzhiyun #define KBASE_TRACE_CODE(X) KBASE_TRACE_CODE_ ## X
725*4882a593Smuzhiyun
726*4882a593Smuzhiyun enum kbase_trace_code {
727*4882a593Smuzhiyun /* IMPORTANT: USE OF SPECIAL #INCLUDE OF NON-STANDARD HEADER FILE
728*4882a593Smuzhiyun * THIS MUST BE USED AT THE START OF THE ENUM */
729*4882a593Smuzhiyun #define KBASE_TRACE_CODE_MAKE_CODE(X) KBASE_TRACE_CODE(X)
730*4882a593Smuzhiyun #include "mali_kbase_trace_defs.h"
731*4882a593Smuzhiyun #undef KBASE_TRACE_CODE_MAKE_CODE
732*4882a593Smuzhiyun /* Comma on its own, to extend the list */
733*4882a593Smuzhiyun ,
734*4882a593Smuzhiyun /* Must be the last in the enum */
735*4882a593Smuzhiyun KBASE_TRACE_CODE_COUNT
736*4882a593Smuzhiyun };
737*4882a593Smuzhiyun
738*4882a593Smuzhiyun #define KBASE_TRACE_FLAG_REFCOUNT (((u8)1) << 0)
739*4882a593Smuzhiyun #define KBASE_TRACE_FLAG_JOBSLOT (((u8)1) << 1)
740*4882a593Smuzhiyun
741*4882a593Smuzhiyun struct kbase_trace {
742*4882a593Smuzhiyun struct timespec64 timestamp;
743*4882a593Smuzhiyun u32 thread_id;
744*4882a593Smuzhiyun u32 cpu;
745*4882a593Smuzhiyun void *ctx;
746*4882a593Smuzhiyun bool katom;
747*4882a593Smuzhiyun int atom_number;
748*4882a593Smuzhiyun u64 atom_udata[2];
749*4882a593Smuzhiyun u64 gpu_addr;
750*4882a593Smuzhiyun unsigned long info_val;
751*4882a593Smuzhiyun u8 code;
752*4882a593Smuzhiyun u8 jobslot;
753*4882a593Smuzhiyun u8 refcount;
754*4882a593Smuzhiyun u8 flags;
755*4882a593Smuzhiyun };
756*4882a593Smuzhiyun
757*4882a593Smuzhiyun /** Event IDs for the power management framework.
758*4882a593Smuzhiyun *
759*4882a593Smuzhiyun * Any of these events might be missed, so they should not be relied upon to
760*4882a593Smuzhiyun * find the precise state of the GPU at a particular time in the
761*4882a593Smuzhiyun * trace. Overall, we should get a high percentage of these events for
762*4882a593Smuzhiyun * statisical purposes, and so a few missing should not be a problem */
763*4882a593Smuzhiyun enum kbase_timeline_pm_event {
764*4882a593Smuzhiyun /* helper for tests */
765*4882a593Smuzhiyun KBASEP_TIMELINE_PM_EVENT_FIRST,
766*4882a593Smuzhiyun
767*4882a593Smuzhiyun /** Event reserved for backwards compatibility with 'init' events */
768*4882a593Smuzhiyun KBASE_TIMELINE_PM_EVENT_RESERVED_0 = KBASEP_TIMELINE_PM_EVENT_FIRST,
769*4882a593Smuzhiyun
770*4882a593Smuzhiyun /** The power state of the device has changed.
771*4882a593Smuzhiyun *
772*4882a593Smuzhiyun * Specifically, the device has reached a desired or available state.
773*4882a593Smuzhiyun */
774*4882a593Smuzhiyun KBASE_TIMELINE_PM_EVENT_GPU_STATE_CHANGED,
775*4882a593Smuzhiyun
776*4882a593Smuzhiyun /** The GPU is becoming active.
777*4882a593Smuzhiyun *
778*4882a593Smuzhiyun * This event is sent when the first context is about to use the GPU.
779*4882a593Smuzhiyun */
780*4882a593Smuzhiyun KBASE_TIMELINE_PM_EVENT_GPU_ACTIVE,
781*4882a593Smuzhiyun
782*4882a593Smuzhiyun /** The GPU is becoming idle.
783*4882a593Smuzhiyun *
784*4882a593Smuzhiyun * This event is sent when the last context has finished using the GPU.
785*4882a593Smuzhiyun */
786*4882a593Smuzhiyun KBASE_TIMELINE_PM_EVENT_GPU_IDLE,
787*4882a593Smuzhiyun
788*4882a593Smuzhiyun /** Event reserved for backwards compatibility with 'policy_change'
789*4882a593Smuzhiyun * events */
790*4882a593Smuzhiyun KBASE_TIMELINE_PM_EVENT_RESERVED_4,
791*4882a593Smuzhiyun
792*4882a593Smuzhiyun /** Event reserved for backwards compatibility with 'system_suspend'
793*4882a593Smuzhiyun * events */
794*4882a593Smuzhiyun KBASE_TIMELINE_PM_EVENT_RESERVED_5,
795*4882a593Smuzhiyun
796*4882a593Smuzhiyun /** Event reserved for backwards compatibility with 'system_resume'
797*4882a593Smuzhiyun * events */
798*4882a593Smuzhiyun KBASE_TIMELINE_PM_EVENT_RESERVED_6,
799*4882a593Smuzhiyun
800*4882a593Smuzhiyun /** The job scheduler is requesting to power up/down cores.
801*4882a593Smuzhiyun *
802*4882a593Smuzhiyun * This event is sent when:
803*4882a593Smuzhiyun * - powered down cores are needed to complete a job
804*4882a593Smuzhiyun * - powered up cores are not needed anymore
805*4882a593Smuzhiyun */
806*4882a593Smuzhiyun KBASE_TIMELINE_PM_EVENT_CHANGE_GPU_STATE,
807*4882a593Smuzhiyun
808*4882a593Smuzhiyun KBASEP_TIMELINE_PM_EVENT_LAST = KBASE_TIMELINE_PM_EVENT_CHANGE_GPU_STATE,
809*4882a593Smuzhiyun };
810*4882a593Smuzhiyun
811*4882a593Smuzhiyun #ifdef CONFIG_MALI_TRACE_TIMELINE
812*4882a593Smuzhiyun struct kbase_trace_kctx_timeline {
813*4882a593Smuzhiyun atomic_t jd_atoms_in_flight;
814*4882a593Smuzhiyun u32 owner_tgid;
815*4882a593Smuzhiyun };
816*4882a593Smuzhiyun
817*4882a593Smuzhiyun struct kbase_trace_kbdev_timeline {
818*4882a593Smuzhiyun /* Note: strictly speaking, not needed, because it's in sync with
819*4882a593Smuzhiyun * kbase_device::jm_slots[]::submitted_nr
820*4882a593Smuzhiyun *
821*4882a593Smuzhiyun * But it's kept as an example of how to add global timeline tracking
822*4882a593Smuzhiyun * information
823*4882a593Smuzhiyun *
824*4882a593Smuzhiyun * The caller must hold hwaccess_lock when accessing this */
825*4882a593Smuzhiyun u8 slot_atoms_submitted[BASE_JM_MAX_NR_SLOTS];
826*4882a593Smuzhiyun
827*4882a593Smuzhiyun /* Last UID for each PM event */
828*4882a593Smuzhiyun atomic_t pm_event_uid[KBASEP_TIMELINE_PM_EVENT_LAST+1];
829*4882a593Smuzhiyun /* Counter for generating PM event UIDs */
830*4882a593Smuzhiyun atomic_t pm_event_uid_counter;
831*4882a593Smuzhiyun /*
832*4882a593Smuzhiyun * L2 transition state - true indicates that the transition is ongoing
833*4882a593Smuzhiyun * Expected to be protected by hwaccess_lock */
834*4882a593Smuzhiyun bool l2_transitioning;
835*4882a593Smuzhiyun };
836*4882a593Smuzhiyun #endif /* CONFIG_MALI_TRACE_TIMELINE */
837*4882a593Smuzhiyun
838*4882a593Smuzhiyun
839*4882a593Smuzhiyun struct kbasep_kctx_list_element {
840*4882a593Smuzhiyun struct list_head link;
841*4882a593Smuzhiyun struct kbase_context *kctx;
842*4882a593Smuzhiyun };
843*4882a593Smuzhiyun
844*4882a593Smuzhiyun /**
845*4882a593Smuzhiyun * Data stored per device for power management.
846*4882a593Smuzhiyun *
847*4882a593Smuzhiyun * This structure contains data for the power management framework. There is one
848*4882a593Smuzhiyun * instance of this structure per device in the system.
849*4882a593Smuzhiyun */
850*4882a593Smuzhiyun struct kbase_pm_device_data {
851*4882a593Smuzhiyun /**
852*4882a593Smuzhiyun * The lock protecting Power Management structures accessed outside of
853*4882a593Smuzhiyun * IRQ.
854*4882a593Smuzhiyun *
855*4882a593Smuzhiyun * This lock must also be held whenever the GPU is being powered on or
856*4882a593Smuzhiyun * off.
857*4882a593Smuzhiyun */
858*4882a593Smuzhiyun struct mutex lock;
859*4882a593Smuzhiyun
860*4882a593Smuzhiyun /** The reference count of active contexts on this device. */
861*4882a593Smuzhiyun int active_count;
862*4882a593Smuzhiyun /** Flag indicating suspending/suspended */
863*4882a593Smuzhiyun bool suspending;
864*4882a593Smuzhiyun /* Wait queue set when active_count == 0 */
865*4882a593Smuzhiyun wait_queue_head_t zero_active_count_wait;
866*4882a593Smuzhiyun
867*4882a593Smuzhiyun /**
868*4882a593Smuzhiyun * Bit masks identifying the available shader cores that are specified
869*4882a593Smuzhiyun * via sysfs. One mask per job slot.
870*4882a593Smuzhiyun */
871*4882a593Smuzhiyun u64 debug_core_mask[BASE_JM_MAX_NR_SLOTS];
872*4882a593Smuzhiyun u64 debug_core_mask_all;
873*4882a593Smuzhiyun
874*4882a593Smuzhiyun /**
875*4882a593Smuzhiyun * Callback for initializing the runtime power management.
876*4882a593Smuzhiyun *
877*4882a593Smuzhiyun * @param kbdev The kbase device
878*4882a593Smuzhiyun *
879*4882a593Smuzhiyun * @return 0 on success, else error code
880*4882a593Smuzhiyun */
881*4882a593Smuzhiyun int (*callback_power_runtime_init)(struct kbase_device *kbdev);
882*4882a593Smuzhiyun
883*4882a593Smuzhiyun /**
884*4882a593Smuzhiyun * Callback for terminating the runtime power management.
885*4882a593Smuzhiyun *
886*4882a593Smuzhiyun * @param kbdev The kbase device
887*4882a593Smuzhiyun */
888*4882a593Smuzhiyun void (*callback_power_runtime_term)(struct kbase_device *kbdev);
889*4882a593Smuzhiyun
890*4882a593Smuzhiyun /* Time in milliseconds between each dvfs sample */
891*4882a593Smuzhiyun u32 dvfs_period;
892*4882a593Smuzhiyun
893*4882a593Smuzhiyun /* Period of GPU poweroff timer */
894*4882a593Smuzhiyun ktime_t gpu_poweroff_time;
895*4882a593Smuzhiyun
896*4882a593Smuzhiyun /* Number of ticks of GPU poweroff timer before shader is powered off */
897*4882a593Smuzhiyun int poweroff_shader_ticks;
898*4882a593Smuzhiyun
899*4882a593Smuzhiyun /* Number of ticks of GPU poweroff timer before GPU is powered off */
900*4882a593Smuzhiyun int poweroff_gpu_ticks;
901*4882a593Smuzhiyun
902*4882a593Smuzhiyun struct kbase_pm_backend_data backend;
903*4882a593Smuzhiyun };
904*4882a593Smuzhiyun
905*4882a593Smuzhiyun /**
906*4882a593Smuzhiyun * struct kbase_mem_pool - Page based memory pool for kctx/kbdev
907*4882a593Smuzhiyun * @kbdev: Kbase device where memory is used
908*4882a593Smuzhiyun * @cur_size: Number of free pages currently in the pool (may exceed @max_size
909*4882a593Smuzhiyun * in some corner cases)
910*4882a593Smuzhiyun * @max_size: Maximum number of free pages in the pool
911*4882a593Smuzhiyun * @pool_lock: Lock protecting the pool - must be held when modifying @cur_size
912*4882a593Smuzhiyun * and @page_list
913*4882a593Smuzhiyun * @page_list: List of free pages in the pool
914*4882a593Smuzhiyun * @reclaim: Shrinker for kernel reclaim of free pages
915*4882a593Smuzhiyun * @next_pool: Pointer to next pool where pages can be allocated when this pool
916*4882a593Smuzhiyun * is empty. Pages will spill over to the next pool when this pool
917*4882a593Smuzhiyun * is full. Can be NULL if there is no next pool.
918*4882a593Smuzhiyun */
919*4882a593Smuzhiyun struct kbase_mem_pool {
920*4882a593Smuzhiyun struct kbase_device *kbdev;
921*4882a593Smuzhiyun size_t cur_size;
922*4882a593Smuzhiyun size_t max_size;
923*4882a593Smuzhiyun spinlock_t pool_lock;
924*4882a593Smuzhiyun struct list_head page_list;
925*4882a593Smuzhiyun struct shrinker reclaim;
926*4882a593Smuzhiyun
927*4882a593Smuzhiyun struct kbase_mem_pool *next_pool;
928*4882a593Smuzhiyun };
929*4882a593Smuzhiyun
930*4882a593Smuzhiyun /**
931*4882a593Smuzhiyun * struct kbase_devfreq_opp - Lookup table for converting between nominal OPP
932*4882a593Smuzhiyun * frequency, and real frequency and core mask
933*4882a593Smuzhiyun * @opp_freq: Nominal OPP frequency
934*4882a593Smuzhiyun * @real_freq: Real GPU frequency
935*4882a593Smuzhiyun * @core_mask: Shader core mask
936*4882a593Smuzhiyun */
937*4882a593Smuzhiyun struct kbase_devfreq_opp {
938*4882a593Smuzhiyun u64 opp_freq;
939*4882a593Smuzhiyun u64 real_freq;
940*4882a593Smuzhiyun u64 core_mask;
941*4882a593Smuzhiyun };
942*4882a593Smuzhiyun
943*4882a593Smuzhiyun #define DEVNAME_SIZE 16
944*4882a593Smuzhiyun
945*4882a593Smuzhiyun struct kbase_device {
946*4882a593Smuzhiyun s8 slot_submit_count_irq[BASE_JM_MAX_NR_SLOTS];
947*4882a593Smuzhiyun
948*4882a593Smuzhiyun u32 hw_quirks_sc;
949*4882a593Smuzhiyun u32 hw_quirks_tiler;
950*4882a593Smuzhiyun u32 hw_quirks_mmu;
951*4882a593Smuzhiyun u32 hw_quirks_jm;
952*4882a593Smuzhiyun
953*4882a593Smuzhiyun struct list_head entry;
954*4882a593Smuzhiyun struct device *dev;
955*4882a593Smuzhiyun unsigned int kbase_group_error;
956*4882a593Smuzhiyun struct miscdevice mdev;
957*4882a593Smuzhiyun u64 reg_start;
958*4882a593Smuzhiyun size_t reg_size;
959*4882a593Smuzhiyun void __iomem *reg;
960*4882a593Smuzhiyun
961*4882a593Smuzhiyun struct {
962*4882a593Smuzhiyun int irq;
963*4882a593Smuzhiyun int flags;
964*4882a593Smuzhiyun } irqs[3];
965*4882a593Smuzhiyun
966*4882a593Smuzhiyun struct clk *clock;
967*4882a593Smuzhiyun #ifdef CONFIG_REGULATOR
968*4882a593Smuzhiyun struct regulator *regulator;
969*4882a593Smuzhiyun #endif
970*4882a593Smuzhiyun char devname[DEVNAME_SIZE];
971*4882a593Smuzhiyun
972*4882a593Smuzhiyun #ifdef CONFIG_MALI_NO_MALI
973*4882a593Smuzhiyun void *model;
974*4882a593Smuzhiyun struct kmem_cache *irq_slab;
975*4882a593Smuzhiyun struct workqueue_struct *irq_workq;
976*4882a593Smuzhiyun atomic_t serving_job_irq;
977*4882a593Smuzhiyun atomic_t serving_gpu_irq;
978*4882a593Smuzhiyun atomic_t serving_mmu_irq;
979*4882a593Smuzhiyun spinlock_t reg_op_lock;
980*4882a593Smuzhiyun #endif /* CONFIG_MALI_NO_MALI */
981*4882a593Smuzhiyun
982*4882a593Smuzhiyun struct kbase_pm_device_data pm;
983*4882a593Smuzhiyun struct kbasep_js_device_data js_data;
984*4882a593Smuzhiyun struct kbase_mem_pool mem_pool;
985*4882a593Smuzhiyun struct kbasep_mem_device memdev;
986*4882a593Smuzhiyun struct kbase_mmu_mode const *mmu_mode;
987*4882a593Smuzhiyun
988*4882a593Smuzhiyun struct kbase_as as[BASE_MAX_NR_AS];
989*4882a593Smuzhiyun /* The below variables (as_free and as_to_kctx) are managed by the
990*4882a593Smuzhiyun * Context Scheduler. The kbasep_js_device_data::runpool_irq::lock must
991*4882a593Smuzhiyun * be held whilst accessing these.
992*4882a593Smuzhiyun */
993*4882a593Smuzhiyun u16 as_free; /* Bitpattern of free Address Spaces */
994*4882a593Smuzhiyun /* Mapping from active Address Spaces to kbase_context */
995*4882a593Smuzhiyun struct kbase_context *as_to_kctx[BASE_MAX_NR_AS];
996*4882a593Smuzhiyun
997*4882a593Smuzhiyun
998*4882a593Smuzhiyun spinlock_t mmu_mask_change;
999*4882a593Smuzhiyun
1000*4882a593Smuzhiyun struct kbase_gpu_props gpu_props;
1001*4882a593Smuzhiyun
1002*4882a593Smuzhiyun /** List of SW workarounds for HW issues */
1003*4882a593Smuzhiyun unsigned long hw_issues_mask[(BASE_HW_ISSUE_END + BITS_PER_LONG - 1) / BITS_PER_LONG];
1004*4882a593Smuzhiyun /** List of features available */
1005*4882a593Smuzhiyun unsigned long hw_features_mask[(BASE_HW_FEATURE_END + BITS_PER_LONG - 1) / BITS_PER_LONG];
1006*4882a593Smuzhiyun
1007*4882a593Smuzhiyun /* Bitmaps of cores that are currently in use (running jobs).
1008*4882a593Smuzhiyun * These should be kept up to date by the job scheduler.
1009*4882a593Smuzhiyun *
1010*4882a593Smuzhiyun * pm.power_change_lock should be held when accessing these members.
1011*4882a593Smuzhiyun *
1012*4882a593Smuzhiyun * kbase_pm_check_transitions_nolock() should be called when bits are
1013*4882a593Smuzhiyun * cleared to update the power management system and allow transitions to
1014*4882a593Smuzhiyun * occur. */
1015*4882a593Smuzhiyun u64 shader_inuse_bitmap;
1016*4882a593Smuzhiyun
1017*4882a593Smuzhiyun /* Refcount for cores in use */
1018*4882a593Smuzhiyun u32 shader_inuse_cnt[64];
1019*4882a593Smuzhiyun
1020*4882a593Smuzhiyun /* Bitmaps of cores the JS needs for jobs ready to run */
1021*4882a593Smuzhiyun u64 shader_needed_bitmap;
1022*4882a593Smuzhiyun
1023*4882a593Smuzhiyun /* Refcount for cores needed */
1024*4882a593Smuzhiyun u32 shader_needed_cnt[64];
1025*4882a593Smuzhiyun
1026*4882a593Smuzhiyun u32 tiler_inuse_cnt;
1027*4882a593Smuzhiyun
1028*4882a593Smuzhiyun u32 tiler_needed_cnt;
1029*4882a593Smuzhiyun
1030*4882a593Smuzhiyun /* struct for keeping track of the disjoint information
1031*4882a593Smuzhiyun *
1032*4882a593Smuzhiyun * The state is > 0 if the GPU is in a disjoint state. Otherwise 0
1033*4882a593Smuzhiyun * The count is the number of disjoint events that have occurred on the GPU
1034*4882a593Smuzhiyun */
1035*4882a593Smuzhiyun struct {
1036*4882a593Smuzhiyun atomic_t count;
1037*4882a593Smuzhiyun atomic_t state;
1038*4882a593Smuzhiyun } disjoint_event;
1039*4882a593Smuzhiyun
1040*4882a593Smuzhiyun /* Refcount for tracking users of the l2 cache, e.g. when using hardware counter instrumentation. */
1041*4882a593Smuzhiyun u32 l2_users_count;
1042*4882a593Smuzhiyun
1043*4882a593Smuzhiyun /* Bitmaps of cores that are currently available (powered up and the power policy is happy for jobs to be
1044*4882a593Smuzhiyun * submitted to these cores. These are updated by the power management code. The job scheduler should avoid
1045*4882a593Smuzhiyun * submitting new jobs to any cores that are not marked as available.
1046*4882a593Smuzhiyun *
1047*4882a593Smuzhiyun * pm.power_change_lock should be held when accessing these members.
1048*4882a593Smuzhiyun */
1049*4882a593Smuzhiyun u64 shader_available_bitmap;
1050*4882a593Smuzhiyun u64 tiler_available_bitmap;
1051*4882a593Smuzhiyun u64 l2_available_bitmap;
1052*4882a593Smuzhiyun u64 stack_available_bitmap;
1053*4882a593Smuzhiyun
1054*4882a593Smuzhiyun u64 shader_ready_bitmap;
1055*4882a593Smuzhiyun u64 shader_transitioning_bitmap;
1056*4882a593Smuzhiyun
1057*4882a593Smuzhiyun s8 nr_hw_address_spaces; /**< Number of address spaces in the GPU (constant after driver initialisation) */
1058*4882a593Smuzhiyun s8 nr_user_address_spaces; /**< Number of address spaces available to user contexts */
1059*4882a593Smuzhiyun
1060*4882a593Smuzhiyun /* Structure used for instrumentation and HW counters dumping */
1061*4882a593Smuzhiyun struct kbase_hwcnt {
1062*4882a593Smuzhiyun /* The lock should be used when accessing any of the following members */
1063*4882a593Smuzhiyun spinlock_t lock;
1064*4882a593Smuzhiyun
1065*4882a593Smuzhiyun struct kbase_context *kctx;
1066*4882a593Smuzhiyun u64 addr;
1067*4882a593Smuzhiyun
1068*4882a593Smuzhiyun struct kbase_instr_backend backend;
1069*4882a593Smuzhiyun } hwcnt;
1070*4882a593Smuzhiyun
1071*4882a593Smuzhiyun struct kbase_vinstr_context *vinstr_ctx;
1072*4882a593Smuzhiyun
1073*4882a593Smuzhiyun #if KBASE_TRACE_ENABLE
1074*4882a593Smuzhiyun spinlock_t trace_lock;
1075*4882a593Smuzhiyun u16 trace_first_out;
1076*4882a593Smuzhiyun u16 trace_next_in;
1077*4882a593Smuzhiyun struct kbase_trace *trace_rbuf;
1078*4882a593Smuzhiyun #endif
1079*4882a593Smuzhiyun
1080*4882a593Smuzhiyun u32 reset_timeout_ms;
1081*4882a593Smuzhiyun
1082*4882a593Smuzhiyun struct mutex cacheclean_lock;
1083*4882a593Smuzhiyun
1084*4882a593Smuzhiyun /* Platform specific private data to be accessed by mali_kbase_config_xxx.c only */
1085*4882a593Smuzhiyun void *platform_context;
1086*4882a593Smuzhiyun
1087*4882a593Smuzhiyun /* List of kbase_contexts created */
1088*4882a593Smuzhiyun struct list_head kctx_list;
1089*4882a593Smuzhiyun struct mutex kctx_list_lock;
1090*4882a593Smuzhiyun
1091*4882a593Smuzhiyun struct rockchip_opp_info opp_info;
1092*4882a593Smuzhiyun #ifdef CONFIG_MALI_DEVFREQ
1093*4882a593Smuzhiyun struct devfreq_dev_profile devfreq_profile;
1094*4882a593Smuzhiyun struct devfreq *devfreq;
1095*4882a593Smuzhiyun unsigned long current_freq;
1096*4882a593Smuzhiyun unsigned long current_nominal_freq;
1097*4882a593Smuzhiyun unsigned long current_voltage;
1098*4882a593Smuzhiyun u64 current_core_mask;
1099*4882a593Smuzhiyun struct kbase_devfreq_opp *opp_table;
1100*4882a593Smuzhiyun int num_opps;
1101*4882a593Smuzhiyun struct monitor_dev_info *mdev_info;
1102*4882a593Smuzhiyun #ifdef CONFIG_DEVFREQ_THERMAL
1103*4882a593Smuzhiyun #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 4, 0)
1104*4882a593Smuzhiyun struct devfreq_cooling_device *devfreq_cooling;
1105*4882a593Smuzhiyun #else
1106*4882a593Smuzhiyun struct thermal_cooling_device *devfreq_cooling;
1107*4882a593Smuzhiyun #endif
1108*4882a593Smuzhiyun /* Current IPA model - true for configured model, false for fallback */
1109*4882a593Smuzhiyun atomic_t ipa_use_configured_model;
1110*4882a593Smuzhiyun struct {
1111*4882a593Smuzhiyun /* Access to this struct must be with ipa.lock held */
1112*4882a593Smuzhiyun struct mutex lock;
1113*4882a593Smuzhiyun struct kbase_ipa_model *configured_model;
1114*4882a593Smuzhiyun struct kbase_ipa_model *fallback_model;
1115*4882a593Smuzhiyun } ipa;
1116*4882a593Smuzhiyun #endif /* CONFIG_DEVFREQ_THERMAL */
1117*4882a593Smuzhiyun #endif /* CONFIG_MALI_DEVFREQ */
1118*4882a593Smuzhiyun
1119*4882a593Smuzhiyun
1120*4882a593Smuzhiyun #ifdef CONFIG_MALI_TRACE_TIMELINE
1121*4882a593Smuzhiyun struct kbase_trace_kbdev_timeline timeline;
1122*4882a593Smuzhiyun #endif
1123*4882a593Smuzhiyun
1124*4882a593Smuzhiyun /*
1125*4882a593Smuzhiyun * Control for enabling job dump on failure, set when control debugfs
1126*4882a593Smuzhiyun * is opened.
1127*4882a593Smuzhiyun */
1128*4882a593Smuzhiyun bool job_fault_debug;
1129*4882a593Smuzhiyun
1130*4882a593Smuzhiyun #ifdef CONFIG_DEBUG_FS
1131*4882a593Smuzhiyun /* directory for debugfs entries */
1132*4882a593Smuzhiyun struct dentry *mali_debugfs_directory;
1133*4882a593Smuzhiyun /* Root directory for per context entry */
1134*4882a593Smuzhiyun struct dentry *debugfs_ctx_directory;
1135*4882a593Smuzhiyun
1136*4882a593Smuzhiyun #ifdef CONFIG_MALI_DEBUG
1137*4882a593Smuzhiyun /* bit for each as, set if there is new data to report */
1138*4882a593Smuzhiyun u64 debugfs_as_read_bitmap;
1139*4882a593Smuzhiyun #endif /* CONFIG_MALI_DEBUG */
1140*4882a593Smuzhiyun
1141*4882a593Smuzhiyun /* failed job dump, used for separate debug process */
1142*4882a593Smuzhiyun wait_queue_head_t job_fault_wq;
1143*4882a593Smuzhiyun wait_queue_head_t job_fault_resume_wq;
1144*4882a593Smuzhiyun struct workqueue_struct *job_fault_resume_workq;
1145*4882a593Smuzhiyun struct list_head job_fault_event_list;
1146*4882a593Smuzhiyun spinlock_t job_fault_event_lock;
1147*4882a593Smuzhiyun struct kbase_context *kctx_fault;
1148*4882a593Smuzhiyun
1149*4882a593Smuzhiyun #if !MALI_CUSTOMER_RELEASE
1150*4882a593Smuzhiyun /* Per-device data for register dumping interface */
1151*4882a593Smuzhiyun struct {
1152*4882a593Smuzhiyun u16 reg_offset; /* Offset of a GPU_CONTROL register to be
1153*4882a593Smuzhiyun dumped upon request */
1154*4882a593Smuzhiyun } regs_dump_debugfs_data;
1155*4882a593Smuzhiyun #endif /* !MALI_CUSTOMER_RELEASE */
1156*4882a593Smuzhiyun #endif /* CONFIG_DEBUG_FS */
1157*4882a593Smuzhiyun
1158*4882a593Smuzhiyun /* fbdump profiling controls set by gator */
1159*4882a593Smuzhiyun u32 kbase_profiling_controls[FBDUMP_CONTROL_MAX];
1160*4882a593Smuzhiyun
1161*4882a593Smuzhiyun
1162*4882a593Smuzhiyun #if MALI_CUSTOMER_RELEASE == 0
1163*4882a593Smuzhiyun /* Number of jobs that are run before a job is forced to fail and
1164*4882a593Smuzhiyun * replay. May be KBASEP_FORCE_REPLAY_DISABLED, to disable forced
1165*4882a593Smuzhiyun * failures. */
1166*4882a593Smuzhiyun int force_replay_limit;
1167*4882a593Smuzhiyun /* Count of jobs between forced failures. Incremented on each job. A
1168*4882a593Smuzhiyun * job is forced to fail once this is greater than or equal to
1169*4882a593Smuzhiyun * force_replay_limit. */
1170*4882a593Smuzhiyun int force_replay_count;
1171*4882a593Smuzhiyun /* Core requirement for jobs to be failed and replayed. May be zero. */
1172*4882a593Smuzhiyun base_jd_core_req force_replay_core_req;
1173*4882a593Smuzhiyun /* true if force_replay_limit should be randomized. The random
1174*4882a593Smuzhiyun * value will be in the range of 1 - KBASEP_FORCE_REPLAY_RANDOM_LIMIT.
1175*4882a593Smuzhiyun */
1176*4882a593Smuzhiyun bool force_replay_random;
1177*4882a593Smuzhiyun #endif
1178*4882a593Smuzhiyun
1179*4882a593Smuzhiyun /* Total number of created contexts */
1180*4882a593Smuzhiyun atomic_t ctx_num;
1181*4882a593Smuzhiyun
1182*4882a593Smuzhiyun #ifdef CONFIG_DEBUG_FS
1183*4882a593Smuzhiyun /* Holds the most recent register accesses */
1184*4882a593Smuzhiyun struct kbase_io_history io_history;
1185*4882a593Smuzhiyun #endif /* CONFIG_DEBUG_FS */
1186*4882a593Smuzhiyun
1187*4882a593Smuzhiyun struct kbase_hwaccess_data hwaccess;
1188*4882a593Smuzhiyun
1189*4882a593Smuzhiyun /* Count of page/bus faults waiting for workqueues to process */
1190*4882a593Smuzhiyun atomic_t faults_pending;
1191*4882a593Smuzhiyun
1192*4882a593Smuzhiyun /* true if GPU is powered off or power off operation is in progress */
1193*4882a593Smuzhiyun bool poweroff_pending;
1194*4882a593Smuzhiyun
1195*4882a593Smuzhiyun
1196*4882a593Smuzhiyun /* defaults for new context created for this device */
1197*4882a593Smuzhiyun #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0))
1198*4882a593Smuzhiyun bool infinite_cache_active_default;
1199*4882a593Smuzhiyun #else
1200*4882a593Smuzhiyun u32 infinite_cache_active_default;
1201*4882a593Smuzhiyun #endif
1202*4882a593Smuzhiyun size_t mem_pool_max_size_default;
1203*4882a593Smuzhiyun
1204*4882a593Smuzhiyun /* current gpu coherency mode */
1205*4882a593Smuzhiyun u32 current_gpu_coherency_mode;
1206*4882a593Smuzhiyun /* system coherency mode */
1207*4882a593Smuzhiyun u32 system_coherency;
1208*4882a593Smuzhiyun /* Flag to track when cci snoops have been enabled on the interface */
1209*4882a593Smuzhiyun bool cci_snoop_enabled;
1210*4882a593Smuzhiyun
1211*4882a593Smuzhiyun /* SMC function IDs to call into Trusted firmware to enable/disable
1212*4882a593Smuzhiyun * cache snooping. Value of 0 indicates that they are not used
1213*4882a593Smuzhiyun */
1214*4882a593Smuzhiyun u32 snoop_enable_smc;
1215*4882a593Smuzhiyun u32 snoop_disable_smc;
1216*4882a593Smuzhiyun
1217*4882a593Smuzhiyun /* Protected mode operations */
1218*4882a593Smuzhiyun struct protected_mode_ops *protected_ops;
1219*4882a593Smuzhiyun
1220*4882a593Smuzhiyun /* Protected device attached to this kbase device */
1221*4882a593Smuzhiyun struct protected_mode_device *protected_dev;
1222*4882a593Smuzhiyun
1223*4882a593Smuzhiyun /*
1224*4882a593Smuzhiyun * true when GPU is put into protected mode
1225*4882a593Smuzhiyun */
1226*4882a593Smuzhiyun bool protected_mode;
1227*4882a593Smuzhiyun
1228*4882a593Smuzhiyun /*
1229*4882a593Smuzhiyun * true when GPU is transitioning into or out of protected mode
1230*4882a593Smuzhiyun */
1231*4882a593Smuzhiyun bool protected_mode_transition;
1232*4882a593Smuzhiyun
1233*4882a593Smuzhiyun /*
1234*4882a593Smuzhiyun * true if protected mode is supported
1235*4882a593Smuzhiyun */
1236*4882a593Smuzhiyun bool protected_mode_support;
1237*4882a593Smuzhiyun
1238*4882a593Smuzhiyun
1239*4882a593Smuzhiyun #ifdef CONFIG_MALI_DEBUG
1240*4882a593Smuzhiyun wait_queue_head_t driver_inactive_wait;
1241*4882a593Smuzhiyun bool driver_inactive;
1242*4882a593Smuzhiyun #endif /* CONFIG_MALI_DEBUG */
1243*4882a593Smuzhiyun
1244*4882a593Smuzhiyun #ifdef CONFIG_MALI_FPGA_BUS_LOGGER
1245*4882a593Smuzhiyun /*
1246*4882a593Smuzhiyun * Bus logger integration.
1247*4882a593Smuzhiyun */
1248*4882a593Smuzhiyun struct bus_logger_client *buslogger;
1249*4882a593Smuzhiyun #endif
1250*4882a593Smuzhiyun /* Boolean indicating if an IRQ flush during reset is in progress. */
1251*4882a593Smuzhiyun bool irq_reset_flush;
1252*4882a593Smuzhiyun
1253*4882a593Smuzhiyun /* list of inited sub systems. Used during terminate/error recovery */
1254*4882a593Smuzhiyun u32 inited_subsys;
1255*4882a593Smuzhiyun
1256*4882a593Smuzhiyun spinlock_t hwaccess_lock;
1257*4882a593Smuzhiyun
1258*4882a593Smuzhiyun /* Protects access to MMU operations */
1259*4882a593Smuzhiyun struct mutex mmu_hw_mutex;
1260*4882a593Smuzhiyun
1261*4882a593Smuzhiyun /* Current serialization mode. See KBASE_SERIALIZE_* for details */
1262*4882a593Smuzhiyun u8 serialize_jobs;
1263*4882a593Smuzhiyun };
1264*4882a593Smuzhiyun
1265*4882a593Smuzhiyun /**
1266*4882a593Smuzhiyun * struct jsctx_queue - JS context atom queue
1267*4882a593Smuzhiyun * @runnable_tree: Root of RB-tree containing currently runnable atoms on this
1268*4882a593Smuzhiyun * job slot.
1269*4882a593Smuzhiyun * @x_dep_head: Head item of the linked list of atoms blocked on cross-slot
1270*4882a593Smuzhiyun * dependencies. Atoms on this list will be moved to the
1271*4882a593Smuzhiyun * runnable_tree when the blocking atom completes.
1272*4882a593Smuzhiyun *
1273*4882a593Smuzhiyun * hwaccess_lock must be held when accessing this structure.
1274*4882a593Smuzhiyun */
1275*4882a593Smuzhiyun struct jsctx_queue {
1276*4882a593Smuzhiyun struct rb_root runnable_tree;
1277*4882a593Smuzhiyun struct list_head x_dep_head;
1278*4882a593Smuzhiyun };
1279*4882a593Smuzhiyun
1280*4882a593Smuzhiyun
1281*4882a593Smuzhiyun #define KBASE_API_VERSION(major, minor) ((((major) & 0xFFF) << 20) | \
1282*4882a593Smuzhiyun (((minor) & 0xFFF) << 8) | \
1283*4882a593Smuzhiyun ((0 & 0xFF) << 0))
1284*4882a593Smuzhiyun
1285*4882a593Smuzhiyun /**
1286*4882a593Smuzhiyun * enum kbase_context_flags - Flags for kbase contexts
1287*4882a593Smuzhiyun *
1288*4882a593Smuzhiyun * @KCTX_COMPAT: Set when the context process is a compat process, 32-bit
1289*4882a593Smuzhiyun * process on a 64-bit kernel.
1290*4882a593Smuzhiyun *
1291*4882a593Smuzhiyun * @KCTX_RUNNABLE_REF: Set when context is counted in
1292*4882a593Smuzhiyun * kbdev->js_data.nr_contexts_runnable. Must hold queue_mutex when accessing.
1293*4882a593Smuzhiyun *
1294*4882a593Smuzhiyun * @KCTX_ACTIVE: Set when the context is active.
1295*4882a593Smuzhiyun *
1296*4882a593Smuzhiyun * @KCTX_PULLED: Set when last kick() caused atoms to be pulled from this
1297*4882a593Smuzhiyun * context.
1298*4882a593Smuzhiyun *
1299*4882a593Smuzhiyun * @KCTX_MEM_PROFILE_INITIALIZED: Set when the context's memory profile has been
1300*4882a593Smuzhiyun * initialized.
1301*4882a593Smuzhiyun *
1302*4882a593Smuzhiyun * @KCTX_INFINITE_CACHE: Set when infinite cache is to be enabled for new
1303*4882a593Smuzhiyun * allocations. Existing allocations will not change.
1304*4882a593Smuzhiyun *
1305*4882a593Smuzhiyun * @KCTX_SUBMIT_DISABLED: Set to prevent context from submitting any jobs.
1306*4882a593Smuzhiyun *
1307*4882a593Smuzhiyun * @KCTX_PRIVILEGED:Set if the context uses an address space and should be kept
1308*4882a593Smuzhiyun * scheduled in.
1309*4882a593Smuzhiyun *
1310*4882a593Smuzhiyun * @KCTX_SCHEDULED: Set when the context is scheduled on the Run Pool.
1311*4882a593Smuzhiyun * This is only ever updated whilst the jsctx_mutex is held.
1312*4882a593Smuzhiyun *
1313*4882a593Smuzhiyun * @KCTX_DYING: Set when the context process is in the process of being evicted.
1314*4882a593Smuzhiyun *
1315*4882a593Smuzhiyun * @KCTX_NO_IMPLICIT_SYNC: Set when explicit Android fences are in use on this
1316*4882a593Smuzhiyun * context, to disable use of implicit dma-buf fences. This is used to avoid
1317*4882a593Smuzhiyun * potential synchronization deadlocks.
1318*4882a593Smuzhiyun *
1319*4882a593Smuzhiyun * All members need to be separate bits. This enum is intended for use in a
1320*4882a593Smuzhiyun * bitmask where multiple values get OR-ed together.
1321*4882a593Smuzhiyun */
1322*4882a593Smuzhiyun enum kbase_context_flags {
1323*4882a593Smuzhiyun KCTX_COMPAT = 1U << 0,
1324*4882a593Smuzhiyun KCTX_RUNNABLE_REF = 1U << 1,
1325*4882a593Smuzhiyun KCTX_ACTIVE = 1U << 2,
1326*4882a593Smuzhiyun KCTX_PULLED = 1U << 3,
1327*4882a593Smuzhiyun KCTX_MEM_PROFILE_INITIALIZED = 1U << 4,
1328*4882a593Smuzhiyun KCTX_INFINITE_CACHE = 1U << 5,
1329*4882a593Smuzhiyun KCTX_SUBMIT_DISABLED = 1U << 6,
1330*4882a593Smuzhiyun KCTX_PRIVILEGED = 1U << 7,
1331*4882a593Smuzhiyun KCTX_SCHEDULED = 1U << 8,
1332*4882a593Smuzhiyun KCTX_DYING = 1U << 9,
1333*4882a593Smuzhiyun KCTX_NO_IMPLICIT_SYNC = 1U << 10,
1334*4882a593Smuzhiyun };
1335*4882a593Smuzhiyun
1336*4882a593Smuzhiyun struct kbase_context {
1337*4882a593Smuzhiyun struct file *filp;
1338*4882a593Smuzhiyun struct kbase_device *kbdev;
1339*4882a593Smuzhiyun int id; /* System wide unique id */
1340*4882a593Smuzhiyun unsigned long api_version;
1341*4882a593Smuzhiyun phys_addr_t pgd;
1342*4882a593Smuzhiyun struct list_head event_list;
1343*4882a593Smuzhiyun struct list_head event_coalesce_list;
1344*4882a593Smuzhiyun struct mutex event_mutex;
1345*4882a593Smuzhiyun atomic_t event_closed;
1346*4882a593Smuzhiyun struct workqueue_struct *event_workq;
1347*4882a593Smuzhiyun atomic_t event_count;
1348*4882a593Smuzhiyun int event_coalesce_count;
1349*4882a593Smuzhiyun
1350*4882a593Smuzhiyun atomic_t flags;
1351*4882a593Smuzhiyun
1352*4882a593Smuzhiyun atomic_t setup_complete;
1353*4882a593Smuzhiyun atomic_t setup_in_progress;
1354*4882a593Smuzhiyun
1355*4882a593Smuzhiyun u64 *mmu_teardown_pages;
1356*4882a593Smuzhiyun
1357*4882a593Smuzhiyun struct page *aliasing_sink_page;
1358*4882a593Smuzhiyun
1359*4882a593Smuzhiyun struct mutex mmu_lock;
1360*4882a593Smuzhiyun struct mutex reg_lock; /* To be converted to a rwlock? */
1361*4882a593Smuzhiyun struct rb_root reg_rbtree_same; /* RB tree of GPU (live) regions,
1362*4882a593Smuzhiyun * SAME_VA zone */
1363*4882a593Smuzhiyun struct rb_root reg_rbtree_exec; /* RB tree of GPU (live) regions,
1364*4882a593Smuzhiyun * EXEC zone */
1365*4882a593Smuzhiyun struct rb_root reg_rbtree_custom; /* RB tree of GPU (live) regions,
1366*4882a593Smuzhiyun * CUSTOM_VA zone */
1367*4882a593Smuzhiyun
1368*4882a593Smuzhiyun unsigned long cookies;
1369*4882a593Smuzhiyun struct kbase_va_region *pending_regions[BITS_PER_LONG];
1370*4882a593Smuzhiyun
1371*4882a593Smuzhiyun wait_queue_head_t event_queue;
1372*4882a593Smuzhiyun pid_t tgid;
1373*4882a593Smuzhiyun pid_t pid;
1374*4882a593Smuzhiyun
1375*4882a593Smuzhiyun struct kbase_jd_context jctx;
1376*4882a593Smuzhiyun atomic_t used_pages;
1377*4882a593Smuzhiyun atomic_t nonmapped_pages;
1378*4882a593Smuzhiyun
1379*4882a593Smuzhiyun struct kbase_mem_pool mem_pool;
1380*4882a593Smuzhiyun
1381*4882a593Smuzhiyun struct shrinker reclaim;
1382*4882a593Smuzhiyun struct list_head evict_list;
1383*4882a593Smuzhiyun
1384*4882a593Smuzhiyun struct list_head waiting_soft_jobs;
1385*4882a593Smuzhiyun spinlock_t waiting_soft_jobs_lock;
1386*4882a593Smuzhiyun #ifdef CONFIG_KDS
1387*4882a593Smuzhiyun struct list_head waiting_kds_resource;
1388*4882a593Smuzhiyun #endif
1389*4882a593Smuzhiyun #ifdef CONFIG_MALI_DMA_FENCE
1390*4882a593Smuzhiyun struct {
1391*4882a593Smuzhiyun struct list_head waiting_resource;
1392*4882a593Smuzhiyun struct workqueue_struct *wq;
1393*4882a593Smuzhiyun } dma_fence;
1394*4882a593Smuzhiyun #endif /* CONFIG_MALI_DMA_FENCE */
1395*4882a593Smuzhiyun /** This is effectively part of the Run Pool, because it only has a valid
1396*4882a593Smuzhiyun * setting (!=KBASEP_AS_NR_INVALID) whilst the context is scheduled in
1397*4882a593Smuzhiyun *
1398*4882a593Smuzhiyun * The hwaccess_lock must be held whilst accessing this.
1399*4882a593Smuzhiyun *
1400*4882a593Smuzhiyun * If the context relating to this as_nr is required, you must use
1401*4882a593Smuzhiyun * kbasep_js_runpool_retain_ctx() to ensure that the context doesn't disappear
1402*4882a593Smuzhiyun * whilst you're using it. Alternatively, just hold the hwaccess_lock
1403*4882a593Smuzhiyun * to ensure the context doesn't disappear (but this has restrictions on what other locks
1404*4882a593Smuzhiyun * you can take whilst doing this) */
1405*4882a593Smuzhiyun int as_nr;
1406*4882a593Smuzhiyun
1407*4882a593Smuzhiyun /* Keeps track of the number of users of this context. A user can be a
1408*4882a593Smuzhiyun * job that is available for execution, instrumentation needing to 'pin'
1409*4882a593Smuzhiyun * a context for counter collection, etc. If the refcount reaches 0 then
1410*4882a593Smuzhiyun * this context is considered inactive and the previously programmed
1411*4882a593Smuzhiyun * AS might be cleared at any point.
1412*4882a593Smuzhiyun */
1413*4882a593Smuzhiyun atomic_t refcount;
1414*4882a593Smuzhiyun
1415*4882a593Smuzhiyun /* NOTE:
1416*4882a593Smuzhiyun *
1417*4882a593Smuzhiyun * Flags are in jctx.sched_info.ctx.flags
1418*4882a593Smuzhiyun * Mutable flags *must* be accessed under jctx.sched_info.ctx.jsctx_mutex
1419*4882a593Smuzhiyun *
1420*4882a593Smuzhiyun * All other flags must be added there */
1421*4882a593Smuzhiyun spinlock_t mm_update_lock;
1422*4882a593Smuzhiyun struct mm_struct *process_mm;
1423*4882a593Smuzhiyun /* End of the SAME_VA zone */
1424*4882a593Smuzhiyun u64 same_va_end;
1425*4882a593Smuzhiyun
1426*4882a593Smuzhiyun #ifdef CONFIG_MALI_TRACE_TIMELINE
1427*4882a593Smuzhiyun struct kbase_trace_kctx_timeline timeline;
1428*4882a593Smuzhiyun #endif
1429*4882a593Smuzhiyun #ifdef CONFIG_DEBUG_FS
1430*4882a593Smuzhiyun /* Content of mem_profile file */
1431*4882a593Smuzhiyun char *mem_profile_data;
1432*4882a593Smuzhiyun /* Size of @c mem_profile_data */
1433*4882a593Smuzhiyun size_t mem_profile_size;
1434*4882a593Smuzhiyun /* Mutex guarding memory profile state */
1435*4882a593Smuzhiyun struct mutex mem_profile_lock;
1436*4882a593Smuzhiyun /* Memory profile directory under debugfs */
1437*4882a593Smuzhiyun struct dentry *kctx_dentry;
1438*4882a593Smuzhiyun
1439*4882a593Smuzhiyun /* for job fault debug */
1440*4882a593Smuzhiyun unsigned int *reg_dump;
1441*4882a593Smuzhiyun atomic_t job_fault_count;
1442*4882a593Smuzhiyun /* This list will keep the following atoms during the dump
1443*4882a593Smuzhiyun * in the same context
1444*4882a593Smuzhiyun */
1445*4882a593Smuzhiyun struct list_head job_fault_resume_event_list;
1446*4882a593Smuzhiyun
1447*4882a593Smuzhiyun #endif /* CONFIG_DEBUG_FS */
1448*4882a593Smuzhiyun
1449*4882a593Smuzhiyun struct jsctx_queue jsctx_queue
1450*4882a593Smuzhiyun [KBASE_JS_ATOM_SCHED_PRIO_COUNT][BASE_JM_MAX_NR_SLOTS];
1451*4882a593Smuzhiyun
1452*4882a593Smuzhiyun /* Number of atoms currently pulled from this context */
1453*4882a593Smuzhiyun atomic_t atoms_pulled;
1454*4882a593Smuzhiyun /* Number of atoms currently pulled from this context, per slot */
1455*4882a593Smuzhiyun atomic_t atoms_pulled_slot[BASE_JM_MAX_NR_SLOTS];
1456*4882a593Smuzhiyun /* Number of atoms currently pulled from this context, per slot and
1457*4882a593Smuzhiyun * priority. Hold hwaccess_lock when accessing */
1458*4882a593Smuzhiyun int atoms_pulled_slot_pri[BASE_JM_MAX_NR_SLOTS][
1459*4882a593Smuzhiyun KBASE_JS_ATOM_SCHED_PRIO_COUNT];
1460*4882a593Smuzhiyun
1461*4882a593Smuzhiyun /* true if slot is blocked on the given priority. This will be set on a
1462*4882a593Smuzhiyun * soft-stop */
1463*4882a593Smuzhiyun bool blocked_js[BASE_JM_MAX_NR_SLOTS][KBASE_JS_ATOM_SCHED_PRIO_COUNT];
1464*4882a593Smuzhiyun
1465*4882a593Smuzhiyun /* Bitmask of slots that can be pulled from */
1466*4882a593Smuzhiyun u32 slots_pullable;
1467*4882a593Smuzhiyun
1468*4882a593Smuzhiyun /* Backend specific data */
1469*4882a593Smuzhiyun struct kbase_context_backend backend;
1470*4882a593Smuzhiyun
1471*4882a593Smuzhiyun /* Work structure used for deferred ASID assignment */
1472*4882a593Smuzhiyun struct work_struct work;
1473*4882a593Smuzhiyun
1474*4882a593Smuzhiyun /* Only one userspace vinstr client per kbase context */
1475*4882a593Smuzhiyun struct kbase_vinstr_client *vinstr_cli;
1476*4882a593Smuzhiyun struct mutex vinstr_cli_lock;
1477*4882a593Smuzhiyun
1478*4882a593Smuzhiyun /* List of completed jobs waiting for events to be posted */
1479*4882a593Smuzhiyun struct list_head completed_jobs;
1480*4882a593Smuzhiyun /* Number of work items currently pending on job_done_wq */
1481*4882a593Smuzhiyun atomic_t work_count;
1482*4882a593Smuzhiyun
1483*4882a593Smuzhiyun /* Waiting soft-jobs will fail when this timer expires */
1484*4882a593Smuzhiyun struct timer_list soft_job_timeout;
1485*4882a593Smuzhiyun
1486*4882a593Smuzhiyun /* JIT allocation management */
1487*4882a593Smuzhiyun struct kbase_va_region *jit_alloc[256];
1488*4882a593Smuzhiyun struct list_head jit_active_head;
1489*4882a593Smuzhiyun struct list_head jit_pool_head;
1490*4882a593Smuzhiyun struct list_head jit_destroy_head;
1491*4882a593Smuzhiyun struct mutex jit_evict_lock;
1492*4882a593Smuzhiyun struct work_struct jit_work;
1493*4882a593Smuzhiyun
1494*4882a593Smuzhiyun /* A list of the JIT soft-jobs in submission order
1495*4882a593Smuzhiyun * (protected by kbase_jd_context.lock)
1496*4882a593Smuzhiyun */
1497*4882a593Smuzhiyun struct list_head jit_atoms_head;
1498*4882a593Smuzhiyun /* A list of pending JIT alloc soft-jobs (using the 'queue' list_head)
1499*4882a593Smuzhiyun * (protected by kbase_jd_context.lock)
1500*4882a593Smuzhiyun */
1501*4882a593Smuzhiyun struct list_head jit_pending_alloc;
1502*4882a593Smuzhiyun
1503*4882a593Smuzhiyun /* External sticky resource management */
1504*4882a593Smuzhiyun struct list_head ext_res_meta_head;
1505*4882a593Smuzhiyun
1506*4882a593Smuzhiyun /* Used to record that a drain was requested from atomic context */
1507*4882a593Smuzhiyun atomic_t drain_pending;
1508*4882a593Smuzhiyun
1509*4882a593Smuzhiyun /* Current age count, used to determine age for newly submitted atoms */
1510*4882a593Smuzhiyun u32 age_count;
1511*4882a593Smuzhiyun };
1512*4882a593Smuzhiyun
1513*4882a593Smuzhiyun /**
1514*4882a593Smuzhiyun * struct kbase_ctx_ext_res_meta - Structure which binds an external resource
1515*4882a593Smuzhiyun * to a @kbase_context.
1516*4882a593Smuzhiyun * @ext_res_node: List head for adding the metadata to a
1517*4882a593Smuzhiyun * @kbase_context.
1518*4882a593Smuzhiyun * @alloc: The physical memory allocation structure
1519*4882a593Smuzhiyun * which is mapped.
1520*4882a593Smuzhiyun * @gpu_addr: The GPU virtual address the resource is
1521*4882a593Smuzhiyun * mapped to.
1522*4882a593Smuzhiyun *
1523*4882a593Smuzhiyun * External resources can be mapped into multiple contexts as well as the same
1524*4882a593Smuzhiyun * context multiple times.
1525*4882a593Smuzhiyun * As kbase_va_region itself isn't refcounted we can't attach our extra
1526*4882a593Smuzhiyun * information to it as it could be removed under our feet leaving external
1527*4882a593Smuzhiyun * resources pinned.
1528*4882a593Smuzhiyun * This metadata structure binds a single external resource to a single
1529*4882a593Smuzhiyun * context, ensuring that per context mapping is tracked separately so it can
1530*4882a593Smuzhiyun * be overridden when needed and abuses by the application (freeing the resource
1531*4882a593Smuzhiyun * multiple times) don't effect the refcount of the physical allocation.
1532*4882a593Smuzhiyun */
1533*4882a593Smuzhiyun struct kbase_ctx_ext_res_meta {
1534*4882a593Smuzhiyun struct list_head ext_res_node;
1535*4882a593Smuzhiyun struct kbase_mem_phy_alloc *alloc;
1536*4882a593Smuzhiyun u64 gpu_addr;
1537*4882a593Smuzhiyun };
1538*4882a593Smuzhiyun
1539*4882a593Smuzhiyun enum kbase_reg_access_type {
1540*4882a593Smuzhiyun REG_READ,
1541*4882a593Smuzhiyun REG_WRITE
1542*4882a593Smuzhiyun };
1543*4882a593Smuzhiyun
1544*4882a593Smuzhiyun enum kbase_share_attr_bits {
1545*4882a593Smuzhiyun /* (1ULL << 8) bit is reserved */
1546*4882a593Smuzhiyun SHARE_BOTH_BITS = (2ULL << 8), /* inner and outer shareable coherency */
1547*4882a593Smuzhiyun SHARE_INNER_BITS = (3ULL << 8) /* inner shareable coherency */
1548*4882a593Smuzhiyun };
1549*4882a593Smuzhiyun
1550*4882a593Smuzhiyun /**
1551*4882a593Smuzhiyun * kbase_device_is_cpu_coherent - Returns if the device is CPU coherent.
1552*4882a593Smuzhiyun * @kbdev: kbase device
1553*4882a593Smuzhiyun *
1554*4882a593Smuzhiyun * Return: true if the device access are coherent, false if not.
1555*4882a593Smuzhiyun */
kbase_device_is_cpu_coherent(struct kbase_device * kbdev)1556*4882a593Smuzhiyun static inline bool kbase_device_is_cpu_coherent(struct kbase_device *kbdev)
1557*4882a593Smuzhiyun {
1558*4882a593Smuzhiyun if ((kbdev->system_coherency == COHERENCY_ACE_LITE) ||
1559*4882a593Smuzhiyun (kbdev->system_coherency == COHERENCY_ACE))
1560*4882a593Smuzhiyun return true;
1561*4882a593Smuzhiyun
1562*4882a593Smuzhiyun return false;
1563*4882a593Smuzhiyun }
1564*4882a593Smuzhiyun
1565*4882a593Smuzhiyun /* Conversion helpers for setting up high resolution timers */
1566*4882a593Smuzhiyun #define HR_TIMER_DELAY_MSEC(x) (ns_to_ktime(((u64)(x))*1000000U))
1567*4882a593Smuzhiyun #define HR_TIMER_DELAY_NSEC(x) (ns_to_ktime(x))
1568*4882a593Smuzhiyun
1569*4882a593Smuzhiyun /* Maximum number of loops polling the GPU for a cache flush before we assume it must have completed */
1570*4882a593Smuzhiyun #define KBASE_CLEAN_CACHE_MAX_LOOPS 100000
1571*4882a593Smuzhiyun /* Maximum number of loops polling the GPU for an AS command to complete before we assume the GPU has hung */
1572*4882a593Smuzhiyun #define KBASE_AS_INACTIVE_MAX_LOOPS 100000
1573*4882a593Smuzhiyun
1574*4882a593Smuzhiyun /* Maximum number of times a job can be replayed */
1575*4882a593Smuzhiyun #define BASEP_JD_REPLAY_LIMIT 15
1576*4882a593Smuzhiyun
1577*4882a593Smuzhiyun /* JobDescriptorHeader - taken from the architecture specifications, the layout
1578*4882a593Smuzhiyun * is currently identical for all GPU archs. */
1579*4882a593Smuzhiyun struct job_descriptor_header {
1580*4882a593Smuzhiyun u32 exception_status;
1581*4882a593Smuzhiyun u32 first_incomplete_task;
1582*4882a593Smuzhiyun u64 fault_pointer;
1583*4882a593Smuzhiyun u8 job_descriptor_size : 1;
1584*4882a593Smuzhiyun u8 job_type : 7;
1585*4882a593Smuzhiyun u8 job_barrier : 1;
1586*4882a593Smuzhiyun u8 _reserved_01 : 1;
1587*4882a593Smuzhiyun u8 _reserved_1 : 1;
1588*4882a593Smuzhiyun u8 _reserved_02 : 1;
1589*4882a593Smuzhiyun u8 _reserved_03 : 1;
1590*4882a593Smuzhiyun u8 _reserved_2 : 1;
1591*4882a593Smuzhiyun u8 _reserved_04 : 1;
1592*4882a593Smuzhiyun u8 _reserved_05 : 1;
1593*4882a593Smuzhiyun u16 job_index;
1594*4882a593Smuzhiyun u16 job_dependency_index_1;
1595*4882a593Smuzhiyun u16 job_dependency_index_2;
1596*4882a593Smuzhiyun union {
1597*4882a593Smuzhiyun u64 _64;
1598*4882a593Smuzhiyun u32 _32;
1599*4882a593Smuzhiyun } next_job;
1600*4882a593Smuzhiyun };
1601*4882a593Smuzhiyun
1602*4882a593Smuzhiyun #endif /* _KBASE_DEFS_H_ */
1603