blob: e23d6a001318d0848a70880f4d70742ce3649726 [file] [log] [blame]
Shrenuj Bansala419c792016-10-20 14:05:11 -07001/* Copyright (c) 2008-2017, The Linux Foundation. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 */
13#ifndef __ADRENO_H
14#define __ADRENO_H
15
16#include "kgsl_device.h"
17#include "kgsl_sharedmem.h"
18#include "adreno_drawctxt.h"
19#include "adreno_ringbuffer.h"
20#include "adreno_profile.h"
21#include "adreno_dispatch.h"
22#include "kgsl_iommu.h"
23#include "adreno_perfcounter.h"
24#include <linux/stat.h>
25#include <linux/delay.h>
26
27#include "a4xx_reg.h"
28
29#ifdef CONFIG_QCOM_OCMEM
30#include <soc/qcom/ocmem.h>
31#endif
32
33#define DEVICE_3D_NAME "kgsl-3d"
34#define DEVICE_3D0_NAME "kgsl-3d0"
35
36/* ADRENO_DEVICE - Given a kgsl_device return the adreno device struct */
37#define ADRENO_DEVICE(device) \
38 container_of(device, struct adreno_device, dev)
39
40/* KGSL_DEVICE - given an adreno_device, return the KGSL device struct */
41#define KGSL_DEVICE(_dev) (&((_dev)->dev))
42
43/* ADRENO_CONTEXT - Given a context return the adreno context struct */
44#define ADRENO_CONTEXT(context) \
45 container_of(context, struct adreno_context, base)
46
47/* ADRENO_GPU_DEVICE - Given an adreno device return the GPU specific struct */
48#define ADRENO_GPU_DEVICE(_a) ((_a)->gpucore->gpudev)
49
50#define ADRENO_CHIPID_CORE(_id) (((_id) >> 24) & 0xFF)
51#define ADRENO_CHIPID_MAJOR(_id) (((_id) >> 16) & 0xFF)
52#define ADRENO_CHIPID_MINOR(_id) (((_id) >> 8) & 0xFF)
53#define ADRENO_CHIPID_PATCH(_id) ((_id) & 0xFF)
54
55/* ADRENO_GPUREV - Return the GPU ID for the given adreno_device */
56#define ADRENO_GPUREV(_a) ((_a)->gpucore->gpurev)
57
58/*
59 * ADRENO_FEATURE - return true if the specified feature is supported by the GPU
60 * core
61 */
62#define ADRENO_FEATURE(_dev, _bit) \
63 ((_dev)->gpucore->features & (_bit))
64
65/**
66 * ADRENO_QUIRK - return true if the specified quirk is required by the GPU
67 */
68#define ADRENO_QUIRK(_dev, _bit) \
69 ((_dev)->quirks & (_bit))
70
71/*
72 * ADRENO_PREEMPT_STYLE - return preemption style
73 */
74#define ADRENO_PREEMPT_STYLE(flags) \
75 ((flags & KGSL_CONTEXT_PREEMPT_STYLE_MASK) >> \
76 KGSL_CONTEXT_PREEMPT_STYLE_SHIFT)
77
78/*
79 * return the dispatcher drawqueue in which the given drawobj should
80 * be submitted
81 */
82#define ADRENO_DRAWOBJ_DISPATCH_DRAWQUEUE(c) \
83 (&((ADRENO_CONTEXT(c->context))->rb->dispatch_q))
84
85#define ADRENO_DRAWOBJ_RB(c) \
86 ((ADRENO_CONTEXT(c->context))->rb)
87
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -070088#define ADRENO_FW(a, f) (&(a->fw[f]))
89
Shrenuj Bansala419c792016-10-20 14:05:11 -070090/* Adreno core features */
91/* The core uses OCMEM for GMEM/binning memory */
92#define ADRENO_USES_OCMEM BIT(0)
93/* The core supports an accelerated warm start */
94#define ADRENO_WARM_START BIT(1)
95/* The core supports the microcode bootstrap functionality */
96#define ADRENO_USE_BOOTSTRAP BIT(2)
97/* The core supports SP/TP hw controlled power collapse */
98#define ADRENO_SPTP_PC BIT(3)
99/* The core supports Peak Power Detection(PPD)*/
100#define ADRENO_PPD BIT(4)
101/* The GPU supports content protection */
102#define ADRENO_CONTENT_PROTECTION BIT(5)
103/* The GPU supports preemption */
104#define ADRENO_PREEMPTION BIT(6)
105/* The core uses GPMU for power and limit management */
106#define ADRENO_GPMU BIT(7)
107/* The GPMU supports Limits Management */
108#define ADRENO_LM BIT(8)
109/* The core uses 64 bit GPU addresses */
110#define ADRENO_64BIT BIT(9)
111/* The GPU supports retention for cpz registers */
112#define ADRENO_CPZ_RETENTION BIT(10)
Shrenuj Bansalae672812016-02-24 14:17:30 -0800113/* The core has soft fault detection available */
114#define ADRENO_SOFT_FAULT_DETECT BIT(11)
Kyle Pieferb1027b02017-02-10 13:58:58 -0800115/* The GMU supports RPMh for power management*/
116#define ADRENO_RPMH BIT(12)
117/* The GMU supports IFPC power management*/
118#define ADRENO_IFPC BIT(13)
119/* The GMU supports HW based NAP */
120#define ADRENO_HW_NAP BIT(14)
121/* The GMU supports min voltage*/
122#define ADRENO_MIN_VOLT BIT(15)
Shrenuj Bansala419c792016-10-20 14:05:11 -0700123
124/*
125 * Adreno GPU quirks - control bits for various workarounds
126 */
127
Lynus Vaz85c8cee2017-03-07 11:31:02 +0530128/* Set TWOPASSUSEWFI in PC_DBG_ECO_CNTL (5XX/6XX) */
Shrenuj Bansala419c792016-10-20 14:05:11 -0700129#define ADRENO_QUIRK_TWO_PASS_USE_WFI BIT(0)
130/* Lock/unlock mutex to sync with the IOMMU */
131#define ADRENO_QUIRK_IOMMU_SYNC BIT(1)
132/* Submit critical packets at GPU wake up */
133#define ADRENO_QUIRK_CRITICAL_PACKETS BIT(2)
134/* Mask out RB1-3 activity signals from HW hang detection logic */
135#define ADRENO_QUIRK_FAULT_DETECT_MASK BIT(3)
136/* Disable RB sampler datapath clock gating optimization */
137#define ADRENO_QUIRK_DISABLE_RB_DP2CLOCKGATING BIT(4)
138/* Disable local memory(LM) feature to avoid corner case error */
139#define ADRENO_QUIRK_DISABLE_LMLOADKILL BIT(5)
Kyle Pieferb1027b02017-02-10 13:58:58 -0800140/* Allow HFI to use registers to send message to GMU */
141#define ADRENO_QUIRK_HFI_USE_REG BIT(6)
Shrenuj Bansala419c792016-10-20 14:05:11 -0700142
143/* Flags to control command packet settings */
144#define KGSL_CMD_FLAGS_NONE 0
145#define KGSL_CMD_FLAGS_PMODE BIT(0)
146#define KGSL_CMD_FLAGS_INTERNAL_ISSUE BIT(1)
147#define KGSL_CMD_FLAGS_WFI BIT(2)
148#define KGSL_CMD_FLAGS_PROFILE BIT(3)
149#define KGSL_CMD_FLAGS_PWRON_FIXUP BIT(4)
150
151/* Command identifiers */
152#define KGSL_CONTEXT_TO_MEM_IDENTIFIER 0x2EADBEEF
153#define KGSL_CMD_IDENTIFIER 0x2EEDFACE
154#define KGSL_CMD_INTERNAL_IDENTIFIER 0x2EEDD00D
155#define KGSL_START_OF_IB_IDENTIFIER 0x2EADEABE
156#define KGSL_END_OF_IB_IDENTIFIER 0x2ABEDEAD
157#define KGSL_START_OF_PROFILE_IDENTIFIER 0x2DEFADE1
158#define KGSL_END_OF_PROFILE_IDENTIFIER 0x2DEFADE2
159#define KGSL_PWRON_FIXUP_IDENTIFIER 0x2AFAFAFA
160
161/* One cannot wait forever for the core to idle, so set an upper limit to the
162 * amount of time to wait for the core to go idle
163 */
164
165#define ADRENO_IDLE_TIMEOUT (20 * 1000)
166
167#define ADRENO_UCHE_GMEM_BASE 0x100000
168
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -0700169#define ADRENO_FW_PFP 0
170#define ADRENO_FW_SQE 0
171#define ADRENO_FW_PM4 1
172
Shrenuj Bansala419c792016-10-20 14:05:11 -0700173enum adreno_gpurev {
174 ADRENO_REV_UNKNOWN = 0,
175 ADRENO_REV_A304 = 304,
176 ADRENO_REV_A305 = 305,
177 ADRENO_REV_A305C = 306,
178 ADRENO_REV_A306 = 307,
179 ADRENO_REV_A306A = 308,
180 ADRENO_REV_A310 = 310,
181 ADRENO_REV_A320 = 320,
182 ADRENO_REV_A330 = 330,
183 ADRENO_REV_A305B = 335,
184 ADRENO_REV_A405 = 405,
185 ADRENO_REV_A418 = 418,
186 ADRENO_REV_A420 = 420,
187 ADRENO_REV_A430 = 430,
188 ADRENO_REV_A505 = 505,
189 ADRENO_REV_A506 = 506,
Rajesh Kemisettiaed6ec72017-02-06 09:37:00 +0530190 ADRENO_REV_A508 = 508,
Shrenuj Bansala419c792016-10-20 14:05:11 -0700191 ADRENO_REV_A510 = 510,
192 ADRENO_REV_A512 = 512,
193 ADRENO_REV_A530 = 530,
194 ADRENO_REV_A540 = 540,
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -0700195 ADRENO_REV_A630 = 630,
Shrenuj Bansala419c792016-10-20 14:05:11 -0700196};
197
198#define ADRENO_START_WARM 0
199#define ADRENO_START_COLD 1
200
201#define ADRENO_SOFT_FAULT BIT(0)
202#define ADRENO_HARD_FAULT BIT(1)
203#define ADRENO_TIMEOUT_FAULT BIT(2)
204#define ADRENO_IOMMU_PAGE_FAULT BIT(3)
205#define ADRENO_PREEMPT_FAULT BIT(4)
206
207#define ADRENO_SPTP_PC_CTRL 0
208#define ADRENO_PPD_CTRL 1
209#define ADRENO_LM_CTRL 2
210#define ADRENO_HWCG_CTRL 3
211#define ADRENO_THROTTLING_CTRL 4
212
213
214/* number of throttle counters for DCVS adjustment */
215#define ADRENO_GPMU_THROTTLE_COUNTERS 4
216/* base for throttle counters */
217#define ADRENO_GPMU_THROTTLE_COUNTERS_BASE_REG 43
218
219struct adreno_gpudev;
220
221/* Time to allow preemption to complete (in ms) */
222#define ADRENO_PREEMPT_TIMEOUT 10000
223
224#define ADRENO_INT_BIT(a, _bit) (((a)->gpucore->gpudev->int_bits) ? \
225 (adreno_get_int(a, _bit) < 0 ? 0 : \
226 BIT(adreno_get_int(a, _bit))) : 0)
227
228/**
229 * enum adreno_preempt_states
230 * ADRENO_PREEMPT_NONE: No preemption is scheduled
231 * ADRENO_PREEMPT_START: The S/W has started
232 * ADRENO_PREEMPT_TRIGGERED: A preeempt has been triggered in the HW
233 * ADRENO_PREEMPT_FAULTED: The preempt timer has fired
234 * ADRENO_PREEMPT_PENDING: The H/W has signaled preemption complete
235 * ADRENO_PREEMPT_COMPLETE: Preemption could not be finished in the IRQ handler,
236 * worker has been scheduled
237 */
238enum adreno_preempt_states {
239 ADRENO_PREEMPT_NONE = 0,
240 ADRENO_PREEMPT_START,
241 ADRENO_PREEMPT_TRIGGERED,
242 ADRENO_PREEMPT_FAULTED,
243 ADRENO_PREEMPT_PENDING,
244 ADRENO_PREEMPT_COMPLETE,
245};
246
247/**
248 * struct adreno_preemption
249 * @state: The current state of preemption
250 * @counters: Memory descriptor for the memory where the GPU writes the
251 * preemption counters on switch
252 * @timer: A timer to make sure preemption doesn't stall
253 * @work: A work struct for the preemption worker (for 5XX)
254 * @token_submit: Indicates if a preempt token has been submitted in
255 * current ringbuffer (for 4XX)
256 */
257struct adreno_preemption {
258 atomic_t state;
259 struct kgsl_memdesc counters;
260 struct timer_list timer;
261 struct work_struct work;
262 bool token_submit;
263};
264
265
266struct adreno_busy_data {
267 unsigned int gpu_busy;
268 unsigned int vbif_ram_cycles;
269 unsigned int vbif_starved_ram;
270 unsigned int throttle_cycles[ADRENO_GPMU_THROTTLE_COUNTERS];
271};
272
273/**
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -0700274 * struct adreno_firmware - Struct holding fw details
275 * @fwvirt: Buffer which holds the ucode
276 * @size: Size of ucode buffer
277 * @version: Version of ucode
278 * @memdesc: Memory descriptor which holds ucode buffer info
279 */
280struct adreno_firmware {
281 unsigned int *fwvirt;
282 size_t size;
283 unsigned int version;
284 struct kgsl_memdesc memdesc;
285};
286
287/**
Shrenuj Bansala419c792016-10-20 14:05:11 -0700288 * struct adreno_gpu_core - A specific GPU core definition
289 * @gpurev: Unique GPU revision identifier
290 * @core: Match for the core version of the GPU
291 * @major: Match for the major version of the GPU
292 * @minor: Match for the minor version of the GPU
293 * @patchid: Match for the patch revision of the GPU
294 * @features: Common adreno features supported by this core
295 * @pm4fw_name: Filename for th PM4 firmware
296 * @pfpfw_name: Filename for the PFP firmware
297 * @zap_name: Filename for the Zap Shader ucode
298 * @gpudev: Pointer to the GPU family specific functions for this core
299 * @gmem_size: Amount of binning memory (GMEM/OCMEM) to reserve for the core
300 * @pm4_jt_idx: Index of the jump table in the PM4 microcode
301 * @pm4_jt_addr: Address offset to load the jump table for the PM4 microcode
302 * @pfp_jt_idx: Index of the jump table in the PFP microcode
303 * @pfp_jt_addr: Address offset to load the jump table for the PFP microcode
304 * @pm4_bstrp_size: Size of the bootstrap loader for PM4 microcode
305 * @pfp_bstrp_size: Size of the bootstrap loader for PFP microcde
306 * @pfp_bstrp_ver: Version of the PFP microcode that supports bootstraping
307 * @shader_offset: Offset of shader from gpu reg base
308 * @shader_size: Shader size
309 * @num_protected_regs: number of protected registers
310 * @gpmufw_name: Filename for the GPMU firmware
311 * @gpmu_major: Match for the GPMU & firmware, major revision
312 * @gpmu_minor: Match for the GPMU & firmware, minor revision
313 * @gpmu_features: Supported features for any given GPMU version
314 * @busy_mask: mask to check if GPU is busy in RBBM_STATUS
315 * @lm_major: Limits Management register sequence, major revision
316 * @lm_minor: LM register sequence, minor revision
317 * @regfw_name: Filename for the register sequence firmware
318 * @gpmu_tsens: ID for the temporature sensor used by the GPMU
319 * @max_power: Max possible power draw of a core, units elephant tail hairs
320 */
321struct adreno_gpu_core {
322 enum adreno_gpurev gpurev;
323 unsigned int core, major, minor, patchid;
324 unsigned long features;
325 const char *pm4fw_name;
326 const char *pfpfw_name;
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -0700327 const char *sqefw_name;
Shrenuj Bansala419c792016-10-20 14:05:11 -0700328 const char *zap_name;
329 struct adreno_gpudev *gpudev;
330 size_t gmem_size;
331 unsigned int pm4_jt_idx;
332 unsigned int pm4_jt_addr;
333 unsigned int pfp_jt_idx;
334 unsigned int pfp_jt_addr;
335 unsigned int pm4_bstrp_size;
336 unsigned int pfp_bstrp_size;
337 unsigned int pfp_bstrp_ver;
338 unsigned long shader_offset;
339 unsigned int shader_size;
340 unsigned int num_protected_regs;
341 const char *gpmufw_name;
342 unsigned int gpmu_major;
343 unsigned int gpmu_minor;
344 unsigned int gpmu_features;
345 unsigned int busy_mask;
346 unsigned int lm_major, lm_minor;
347 const char *regfw_name;
348 unsigned int gpmu_tsens;
349 unsigned int max_power;
350};
351
352/**
353 * struct adreno_device - The mothership structure for all adreno related info
354 * @dev: Reference to struct kgsl_device
355 * @priv: Holds the private flags specific to the adreno_device
356 * @chipid: Chip ID specific to the GPU
357 * @gmem_base: Base physical address of GMEM
358 * @gmem_size: GMEM size
359 * @gpucore: Pointer to the adreno_gpu_core structure
360 * @pfp_fw: Buffer which holds the pfp ucode
361 * @pfp_fw_size: Size of pfp ucode buffer
362 * @pfp_fw_version: Version of pfp ucode
363 * @pfp: Memory descriptor which holds pfp ucode buffer info
364 * @pm4_fw: Buffer which holds the pm4 ucode
365 * @pm4_fw_size: Size of pm4 ucode buffer
366 * @pm4_fw_version: Version of pm4 ucode
367 * @pm4: Memory descriptor which holds pm4 ucode buffer info
368 * @gpmu_cmds_size: Length of gpmu cmd stream
369 * @gpmu_cmds: gpmu cmd stream
370 * @ringbuffers: Array of pointers to adreno_ringbuffers
371 * @num_ringbuffers: Number of ringbuffers for the GPU
372 * @cur_rb: Pointer to the current ringbuffer
373 * @next_rb: Ringbuffer we are switching to during preemption
374 * @prev_rb: Ringbuffer we are switching from during preemption
375 * @fast_hang_detect: Software fault detection availability
376 * @ft_policy: Defines the fault tolerance policy
377 * @long_ib_detect: Long IB detection availability
378 * @ft_pf_policy: Defines the fault policy for page faults
379 * @ocmem_hdl: Handle to the ocmem allocated buffer
380 * @profile: Container for adreno profiler information
381 * @dispatcher: Container for adreno GPU dispatcher
382 * @pwron_fixup: Command buffer to run a post-power collapse shader workaround
383 * @pwron_fixup_dwords: Number of dwords in the command buffer
384 * @input_work: Work struct for turning on the GPU after a touch event
385 * @busy_data: Struct holding GPU VBIF busy stats
386 * @ram_cycles_lo: Number of DDR clock cycles for the monitor session
387 * @perfctr_pwr_lo: Number of cycles VBIF is stalled by DDR
388 * @halt: Atomic variable to check whether the GPU is currently halted
Deepak Kumar273c5712017-01-03 21:49:03 +0530389 * @pending_irq_refcnt: Atomic variable to keep track of running IRQ handlers
Shrenuj Bansala419c792016-10-20 14:05:11 -0700390 * @ctx_d_debugfs: Context debugfs node
391 * @pwrctrl_flag: Flag to hold adreno specific power attributes
392 * @profile_buffer: Memdesc holding the drawobj profiling buffer
393 * @profile_index: Index to store the start/stop ticks in the profiling
394 * buffer
395 * @sp_local_gpuaddr: Base GPU virtual address for SP local memory
396 * @sp_pvt_gpuaddr: Base GPU virtual address for SP private memory
397 * @lm_fw: The LM firmware handle
398 * @lm_sequence: Pointer to the start of the register write sequence for LM
399 * @lm_size: The dword size of the LM sequence
400 * @lm_limit: limiting value for LM
401 * @lm_threshold_count: register value for counter for lm threshold breakin
402 * @lm_threshold_cross: number of current peaks exceeding threshold
403 * @speed_bin: Indicate which power level set to use
404 * @csdev: Pointer to a coresight device (if applicable)
405 * @gpmu_throttle_counters - counteers for number of throttled clocks
406 * @irq_storm_work: Worker to handle possible interrupt storms
407 * @active_list: List to track active contexts
408 * @active_list_lock: Lock to protect active_list
Sushmita Susheelendra7f66cf72016-09-12 11:04:43 -0600409 * @gpu_llc_slice: GPU system cache slice descriptor
Sushmita Susheelendrab1976682016-11-07 14:21:11 -0700410 * @gpu_llc_slice_enable: To enable the GPU system cache slice or not
Sushmita Susheelendra906564d2017-01-10 15:53:55 -0700411 * @gpuhtw_llc_slice: GPU pagetables system cache slice descriptor
Sushmita Susheelendrad3756c02017-01-11 15:05:40 -0700412 * @gpuhtw_llc_slice_enable: To enable the GPUHTW system cache slice or not
Shrenuj Bansala419c792016-10-20 14:05:11 -0700413 */
414struct adreno_device {
415 struct kgsl_device dev; /* Must be first field in this struct */
416 unsigned long priv;
417 unsigned int chipid;
418 unsigned long gmem_base;
419 unsigned long gmem_size;
420 const struct adreno_gpu_core *gpucore;
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -0700421 struct adreno_firmware fw[2];
Shrenuj Bansala419c792016-10-20 14:05:11 -0700422 size_t gpmu_cmds_size;
423 unsigned int *gpmu_cmds;
424 struct adreno_ringbuffer ringbuffers[KGSL_PRIORITY_MAX_RB_LEVELS];
425 int num_ringbuffers;
426 struct adreno_ringbuffer *cur_rb;
427 struct adreno_ringbuffer *next_rb;
428 struct adreno_ringbuffer *prev_rb;
429 unsigned int fast_hang_detect;
430 unsigned long ft_policy;
431 unsigned int long_ib_detect;
432 unsigned long ft_pf_policy;
433 struct ocmem_buf *ocmem_hdl;
434 struct adreno_profile profile;
435 struct adreno_dispatcher dispatcher;
436 struct kgsl_memdesc pwron_fixup;
437 unsigned int pwron_fixup_dwords;
438 struct work_struct input_work;
439 struct adreno_busy_data busy_data;
440 unsigned int ram_cycles_lo;
441 unsigned int starved_ram_lo;
442 unsigned int perfctr_pwr_lo;
443 atomic_t halt;
Deepak Kumar273c5712017-01-03 21:49:03 +0530444 atomic_t pending_irq_refcnt;
Shrenuj Bansala419c792016-10-20 14:05:11 -0700445 struct dentry *ctx_d_debugfs;
446 unsigned long pwrctrl_flag;
447
448 struct kgsl_memdesc profile_buffer;
449 unsigned int profile_index;
450 uint64_t sp_local_gpuaddr;
451 uint64_t sp_pvt_gpuaddr;
452 const struct firmware *lm_fw;
453 uint32_t *lm_sequence;
454 uint32_t lm_size;
455 struct adreno_preemption preempt;
456 struct work_struct gpmu_work;
457 uint32_t lm_leakage;
458 uint32_t lm_limit;
459 uint32_t lm_threshold_count;
460 uint32_t lm_threshold_cross;
461
462 unsigned int speed_bin;
463 unsigned int quirks;
464
465 struct coresight_device *csdev;
466 uint32_t gpmu_throttle_counters[ADRENO_GPMU_THROTTLE_COUNTERS];
467 struct work_struct irq_storm_work;
468
469 struct list_head active_list;
470 spinlock_t active_list_lock;
Sushmita Susheelendra7f66cf72016-09-12 11:04:43 -0600471
472 void *gpu_llc_slice;
Sushmita Susheelendrab1976682016-11-07 14:21:11 -0700473 bool gpu_llc_slice_enable;
Sushmita Susheelendra906564d2017-01-10 15:53:55 -0700474 void *gpuhtw_llc_slice;
Sushmita Susheelendrad3756c02017-01-11 15:05:40 -0700475 bool gpuhtw_llc_slice_enable;
Shrenuj Bansala419c792016-10-20 14:05:11 -0700476};
477
478/**
479 * enum adreno_device_flags - Private flags for the adreno_device
480 * @ADRENO_DEVICE_PWRON - Set during init after a power collapse
481 * @ADRENO_DEVICE_PWRON_FIXUP - Set if the target requires the shader fixup
482 * after power collapse
483 * @ADRENO_DEVICE_CORESIGHT - Set if the coresight (trace bus) registers should
484 * be restored after power collapse
485 * @ADRENO_DEVICE_HANG_INTR - Set if the hang interrupt should be enabled for
486 * this target
487 * @ADRENO_DEVICE_STARTED - Set if the device start sequence is in progress
488 * @ADRENO_DEVICE_FAULT - Set if the device is currently in fault (and shouldn't
489 * send any more commands to the ringbuffer)
490 * @ADRENO_DEVICE_DRAWOBJ_PROFILE - Set if the device supports drawobj
491 * profiling via the ALWAYSON counter
492 * @ADRENO_DEVICE_PREEMPTION - Turn on/off preemption
493 * @ADRENO_DEVICE_SOFT_FAULT_DETECT - Set if soft fault detect is enabled
494 * @ADRENO_DEVICE_GPMU_INITIALIZED - Set if GPMU firmware initialization succeed
495 * @ADRENO_DEVICE_ISDB_ENABLED - Set if the Integrated Shader DeBugger is
496 * attached and enabled
497 * @ADRENO_DEVICE_CACHE_FLUSH_TS_SUSPENDED - Set if a CACHE_FLUSH_TS irq storm
498 * is in progress
499 */
500enum adreno_device_flags {
501 ADRENO_DEVICE_PWRON = 0,
502 ADRENO_DEVICE_PWRON_FIXUP = 1,
503 ADRENO_DEVICE_INITIALIZED = 2,
504 ADRENO_DEVICE_CORESIGHT = 3,
505 ADRENO_DEVICE_HANG_INTR = 4,
506 ADRENO_DEVICE_STARTED = 5,
507 ADRENO_DEVICE_FAULT = 6,
508 ADRENO_DEVICE_DRAWOBJ_PROFILE = 7,
509 ADRENO_DEVICE_GPU_REGULATOR_ENABLED = 8,
510 ADRENO_DEVICE_PREEMPTION = 9,
511 ADRENO_DEVICE_SOFT_FAULT_DETECT = 10,
512 ADRENO_DEVICE_GPMU_INITIALIZED = 11,
513 ADRENO_DEVICE_ISDB_ENABLED = 12,
514 ADRENO_DEVICE_CACHE_FLUSH_TS_SUSPENDED = 13,
515};
516
517/**
518 * struct adreno_drawobj_profile_entry - a single drawobj entry in the
519 * kernel profiling buffer
520 * @started: Number of GPU ticks at start of the drawobj
521 * @retired: Number of GPU ticks at the end of the drawobj
522 */
523struct adreno_drawobj_profile_entry {
524 uint64_t started;
525 uint64_t retired;
526};
527
528#define ADRENO_DRAWOBJ_PROFILE_COUNT \
529 (PAGE_SIZE / sizeof(struct adreno_drawobj_profile_entry))
530
531#define ADRENO_DRAWOBJ_PROFILE_OFFSET(_index, _member) \
532 ((_index) * sizeof(struct adreno_drawobj_profile_entry) \
533 + offsetof(struct adreno_drawobj_profile_entry, _member))
534
535
536/**
537 * adreno_regs: List of registers that are used in kgsl driver for all
538 * 3D devices. Each device type has different offset value for the same
539 * register, so an array of register offsets are declared for every device
540 * and are indexed by the enumeration values defined in this enum
541 */
542enum adreno_regs {
543 ADRENO_REG_CP_ME_RAM_WADDR,
544 ADRENO_REG_CP_ME_RAM_DATA,
545 ADRENO_REG_CP_PFP_UCODE_DATA,
546 ADRENO_REG_CP_PFP_UCODE_ADDR,
547 ADRENO_REG_CP_WFI_PEND_CTR,
548 ADRENO_REG_CP_RB_BASE,
549 ADRENO_REG_CP_RB_BASE_HI,
550 ADRENO_REG_CP_RB_RPTR_ADDR_LO,
551 ADRENO_REG_CP_RB_RPTR_ADDR_HI,
552 ADRENO_REG_CP_RB_RPTR,
553 ADRENO_REG_CP_RB_WPTR,
554 ADRENO_REG_CP_CNTL,
555 ADRENO_REG_CP_ME_CNTL,
556 ADRENO_REG_CP_RB_CNTL,
557 ADRENO_REG_CP_IB1_BASE,
558 ADRENO_REG_CP_IB1_BASE_HI,
559 ADRENO_REG_CP_IB1_BUFSZ,
560 ADRENO_REG_CP_IB2_BASE,
561 ADRENO_REG_CP_IB2_BASE_HI,
562 ADRENO_REG_CP_IB2_BUFSZ,
563 ADRENO_REG_CP_TIMESTAMP,
564 ADRENO_REG_CP_SCRATCH_REG6,
565 ADRENO_REG_CP_SCRATCH_REG7,
566 ADRENO_REG_CP_ME_RAM_RADDR,
567 ADRENO_REG_CP_ROQ_ADDR,
568 ADRENO_REG_CP_ROQ_DATA,
569 ADRENO_REG_CP_MERCIU_ADDR,
570 ADRENO_REG_CP_MERCIU_DATA,
571 ADRENO_REG_CP_MERCIU_DATA2,
572 ADRENO_REG_CP_MEQ_ADDR,
573 ADRENO_REG_CP_MEQ_DATA,
574 ADRENO_REG_CP_HW_FAULT,
575 ADRENO_REG_CP_PROTECT_STATUS,
576 ADRENO_REG_CP_PREEMPT,
577 ADRENO_REG_CP_PREEMPT_DEBUG,
578 ADRENO_REG_CP_PREEMPT_DISABLE,
579 ADRENO_REG_CP_PROTECT_REG_0,
580 ADRENO_REG_CP_CONTEXT_SWITCH_SMMU_INFO_LO,
581 ADRENO_REG_CP_CONTEXT_SWITCH_SMMU_INFO_HI,
582 ADRENO_REG_RBBM_STATUS,
583 ADRENO_REG_RBBM_STATUS3,
584 ADRENO_REG_RBBM_PERFCTR_CTL,
585 ADRENO_REG_RBBM_PERFCTR_LOAD_CMD0,
586 ADRENO_REG_RBBM_PERFCTR_LOAD_CMD1,
587 ADRENO_REG_RBBM_PERFCTR_LOAD_CMD2,
588 ADRENO_REG_RBBM_PERFCTR_LOAD_CMD3,
589 ADRENO_REG_RBBM_PERFCTR_PWR_1_LO,
590 ADRENO_REG_RBBM_INT_0_MASK,
591 ADRENO_REG_RBBM_INT_0_STATUS,
592 ADRENO_REG_RBBM_PM_OVERRIDE2,
593 ADRENO_REG_RBBM_INT_CLEAR_CMD,
594 ADRENO_REG_RBBM_SW_RESET_CMD,
595 ADRENO_REG_RBBM_BLOCK_SW_RESET_CMD,
596 ADRENO_REG_RBBM_BLOCK_SW_RESET_CMD2,
597 ADRENO_REG_RBBM_CLOCK_CTL,
598 ADRENO_REG_VPC_DEBUG_RAM_SEL,
599 ADRENO_REG_VPC_DEBUG_RAM_READ,
600 ADRENO_REG_PA_SC_AA_CONFIG,
601 ADRENO_REG_SQ_GPR_MANAGEMENT,
602 ADRENO_REG_SQ_INST_STORE_MANAGEMENT,
603 ADRENO_REG_TP0_CHICKEN,
604 ADRENO_REG_RBBM_RBBM_CTL,
605 ADRENO_REG_UCHE_INVALIDATE0,
606 ADRENO_REG_UCHE_INVALIDATE1,
607 ADRENO_REG_RBBM_PERFCTR_LOAD_VALUE_LO,
608 ADRENO_REG_RBBM_PERFCTR_LOAD_VALUE_HI,
609 ADRENO_REG_RBBM_SECVID_TRUST_CONTROL,
610 ADRENO_REG_RBBM_ALWAYSON_COUNTER_LO,
611 ADRENO_REG_RBBM_ALWAYSON_COUNTER_HI,
612 ADRENO_REG_RBBM_SECVID_TRUST_CONFIG,
613 ADRENO_REG_RBBM_SECVID_TSB_CONTROL,
614 ADRENO_REG_RBBM_SECVID_TSB_TRUSTED_BASE,
615 ADRENO_REG_RBBM_SECVID_TSB_TRUSTED_BASE_HI,
616 ADRENO_REG_RBBM_SECVID_TSB_TRUSTED_SIZE,
617 ADRENO_REG_VBIF_XIN_HALT_CTRL0,
618 ADRENO_REG_VBIF_XIN_HALT_CTRL1,
619 ADRENO_REG_VBIF_VERSION,
Kyle Pieferb1027b02017-02-10 13:58:58 -0800620 ADRENO_REG_GMU_AO_INTERRUPT_EN,
621 ADRENO_REG_GMU_HOST_INTERRUPT_CLR,
622 ADRENO_REG_GMU_HOST_INTERRUPT_STATUS,
623 ADRENO_REG_GMU_HOST_INTERRUPT_MASK,
624 ADRENO_REG_GMU_PWR_COL_KEEPALIVE,
625 ADRENO_REG_GMU_AHB_FENCE_STATUS,
626 ADRENO_REG_GMU_RPMH_POWER_STATE,
627 ADRENO_REG_GMU_HFI_CTRL_STATUS,
628 ADRENO_REG_GMU_HFI_VERSION_INFO,
629 ADRENO_REG_GMU_HFI_SFR_ADDR,
630 ADRENO_REG_GMU_GMU2HOST_INTR_CLR,
631 ADRENO_REG_GMU_GMU2HOST_INTR_INFO,
632 ADRENO_REG_GMU_HOST2GMU_INTR_SET,
633 ADRENO_REG_GMU_HOST2GMU_INTR_CLR,
634 ADRENO_REG_GMU_HOST2GMU_INTR_RAW_INFO,
Shrenuj Bansala419c792016-10-20 14:05:11 -0700635 ADRENO_REG_REGISTER_MAX,
636};
637
638enum adreno_int_bits {
639 ADRENO_INT_RBBM_AHB_ERROR,
640 ADRENO_INT_BITS_MAX,
641};
642
643/**
644 * adreno_reg_offsets: Holds array of register offsets
645 * @offsets: Offset array of size defined by enum adreno_regs
646 * @offset_0: This is the index of the register in offset array whose value
647 * is 0. 0 is a valid register offset and during initialization of the
648 * offset array we need to know if an offset value is correctly defined to 0
649 */
650struct adreno_reg_offsets {
651 unsigned int *const offsets;
652 enum adreno_regs offset_0;
653};
654
655#define ADRENO_REG_UNUSED 0xFFFFFFFF
656#define ADRENO_REG_SKIP 0xFFFFFFFE
657#define ADRENO_REG_DEFINE(_offset, _reg) [_offset] = _reg
658#define ADRENO_INT_DEFINE(_offset, _val) ADRENO_REG_DEFINE(_offset, _val)
659
660/*
661 * struct adreno_vbif_data - Describes vbif register value pair
662 * @reg: Offset to vbif register
663 * @val: The value that should be programmed in the register at reg
664 */
665struct adreno_vbif_data {
666 unsigned int reg;
667 unsigned int val;
668};
669
670/*
671 * struct adreno_vbif_platform - Holds an array of vbif reg value pairs
672 * for a particular core
673 * @devfunc: Pointer to platform/core identification function
674 * @vbif: Array of reg value pairs for vbif registers
675 */
676struct adreno_vbif_platform {
677 int (*devfunc)(struct adreno_device *);
678 const struct adreno_vbif_data *vbif;
679};
680
681/*
682 * struct adreno_vbif_snapshot_registers - Holds an array of vbif registers
683 * listed for snapshot dump for a particular core
684 * @version: vbif version
685 * @mask: vbif revision mask
686 * @registers: vbif registers listed for snapshot dump
687 * @count: count of vbif registers listed for snapshot
688 */
689struct adreno_vbif_snapshot_registers {
690 const unsigned int version;
691 const unsigned int mask;
692 const unsigned int *registers;
693 const int count;
694};
695
696/**
697 * struct adreno_coresight_register - Definition for a coresight (tracebus)
698 * debug register
699 * @offset: Offset of the debug register in the KGSL mmio region
700 * @initial: Default value to write when coresight is enabled
701 * @value: Current shadow value of the register (to be reprogrammed after power
702 * collapse)
703 */
704struct adreno_coresight_register {
705 unsigned int offset;
706 unsigned int initial;
707 unsigned int value;
708};
709
710struct adreno_coresight_attr {
711 struct device_attribute attr;
712 struct adreno_coresight_register *reg;
713};
714
715ssize_t adreno_coresight_show_register(struct device *device,
716 struct device_attribute *attr, char *buf);
717
718ssize_t adreno_coresight_store_register(struct device *dev,
719 struct device_attribute *attr, const char *buf, size_t size);
720
721#define ADRENO_CORESIGHT_ATTR(_attrname, _reg) \
722 struct adreno_coresight_attr coresight_attr_##_attrname = { \
723 __ATTR(_attrname, 0644, \
724 adreno_coresight_show_register, \
725 adreno_coresight_store_register), \
726 (_reg), }
727
728/**
729 * struct adreno_coresight - GPU specific coresight definition
730 * @registers - Array of GPU specific registers to configure trace bus output
731 * @count - Number of registers in the array
732 * @groups - Pointer to an attribute list of control files
733 * @atid - The unique ATID value of the coresight device
734 */
735struct adreno_coresight {
736 struct adreno_coresight_register *registers;
737 unsigned int count;
738 const struct attribute_group **groups;
739 unsigned int atid;
740};
741
742
743struct adreno_irq_funcs {
744 void (*func)(struct adreno_device *, int);
745};
746#define ADRENO_IRQ_CALLBACK(_c) { .func = _c }
747
748struct adreno_irq {
749 unsigned int mask;
750 struct adreno_irq_funcs *funcs;
751};
752
753/*
754 * struct adreno_debugbus_block - Holds info about debug buses of a chip
755 * @block_id: Bus identifier
756 * @dwords: Number of dwords of data that this block holds
757 */
758struct adreno_debugbus_block {
759 unsigned int block_id;
760 unsigned int dwords;
761};
762
763/*
764 * struct adreno_snapshot_section_sizes - Structure holding the size of
765 * different sections dumped during device snapshot
766 * @cp_pfp: CP PFP data section size
767 * @cp_me: CP ME data section size
768 * @vpc_mem: VPC memory section size
769 * @cp_meq: CP MEQ size
770 * @shader_mem: Size of shader memory of 1 shader section
771 * @cp_merciu: CP MERCIU size
772 * @roq: ROQ size
773 */
774struct adreno_snapshot_sizes {
775 int cp_pfp;
776 int cp_me;
777 int vpc_mem;
778 int cp_meq;
779 int shader_mem;
780 int cp_merciu;
781 int roq;
782};
783
784/*
785 * struct adreno_snapshot_data - Holds data used in snapshot
786 * @sect_sizes: Has sections sizes
787 */
788struct adreno_snapshot_data {
789 struct adreno_snapshot_sizes *sect_sizes;
790};
791
792struct adreno_gpudev {
793 /*
794 * These registers are in a different location on different devices,
795 * so define them in the structure and use them as variables.
796 */
797 const struct adreno_reg_offsets *reg_offsets;
798 unsigned int *const int_bits;
799 const struct adreno_ft_perf_counters *ft_perf_counters;
800 unsigned int ft_perf_counters_count;
801
802 struct adreno_perfcounters *perfcounters;
803 const struct adreno_invalid_countables *invalid_countables;
804 struct adreno_snapshot_data *snapshot_data;
805
806 struct adreno_coresight *coresight;
807
808 struct adreno_irq *irq;
809 int num_prio_levels;
810 unsigned int vbif_xin_halt_ctrl0_mask;
811 /* GPU specific function hooks */
812 void (*irq_trace)(struct adreno_device *, unsigned int status);
813 void (*snapshot)(struct adreno_device *, struct kgsl_snapshot *);
814 void (*platform_setup)(struct adreno_device *);
815 void (*init)(struct adreno_device *);
816 void (*remove)(struct adreno_device *);
817 int (*rb_start)(struct adreno_device *, unsigned int start_type);
818 int (*microcode_read)(struct adreno_device *);
819 void (*perfcounter_init)(struct adreno_device *);
820 void (*perfcounter_close)(struct adreno_device *);
821 void (*start)(struct adreno_device *);
822 bool (*is_sptp_idle)(struct adreno_device *);
823 int (*regulator_enable)(struct adreno_device *);
824 void (*regulator_disable)(struct adreno_device *);
825 void (*pwrlevel_change_settings)(struct adreno_device *,
826 unsigned int prelevel, unsigned int postlevel,
827 bool post);
828 uint64_t (*read_throttling_counters)(struct adreno_device *);
829 void (*count_throttles)(struct adreno_device *, uint64_t adj);
830 int (*enable_pwr_counters)(struct adreno_device *,
831 unsigned int counter);
832 unsigned int (*preemption_pre_ibsubmit)(
833 struct adreno_device *adreno_dev,
834 struct adreno_ringbuffer *rb,
835 unsigned int *cmds,
836 struct kgsl_context *context);
837 int (*preemption_yield_enable)(unsigned int *);
838 unsigned int (*preemption_post_ibsubmit)(
839 struct adreno_device *adreno_dev,
840 unsigned int *cmds);
841 int (*preemption_init)(struct adreno_device *);
842 void (*preemption_schedule)(struct adreno_device *);
843 void (*enable_64bit)(struct adreno_device *);
844 void (*clk_set_options)(struct adreno_device *,
845 const char *, struct clk *);
Sushmita Susheelendra7f66cf72016-09-12 11:04:43 -0600846 void (*llc_configure_gpu_scid)(struct adreno_device *adreno_dev);
Sushmita Susheelendra906564d2017-01-10 15:53:55 -0700847 void (*llc_configure_gpuhtw_scid)(struct adreno_device *adreno_dev);
Sushmita Susheelendra7f66cf72016-09-12 11:04:43 -0600848 void (*llc_enable_overrides)(struct adreno_device *adreno_dev);
Kyle Pieferb1027b02017-02-10 13:58:58 -0800849 void (*pre_reset)(struct adreno_device *);
850 int (*oob_set)(struct adreno_device *adreno_dev, unsigned int set_mask,
851 unsigned int check_mask,
852 unsigned int clear_mask);
853 void (*oob_clear)(struct adreno_device *adreno_dev,
854 unsigned int clear_mask);
Kyle Pieferb1027b02017-02-10 13:58:58 -0800855 int (*rpmh_gpu_pwrctrl)(struct adreno_device *, unsigned int ops,
856 unsigned int arg1, unsigned int arg2);
Oleg Perelet62d5cec2017-03-27 16:14:52 -0700857 bool (*hw_isidle)(struct adreno_device *);
858 int (*wait_for_gmu_idle)(struct adreno_device *);
Shrenuj Bansala419c792016-10-20 14:05:11 -0700859};
860
861/**
862 * enum kgsl_ft_policy_bits - KGSL fault tolerance policy bits
863 * @KGSL_FT_OFF: Disable fault detection (not used)
864 * @KGSL_FT_REPLAY: Replay the faulting command
865 * @KGSL_FT_SKIPIB: Skip the faulting indirect buffer
866 * @KGSL_FT_SKIPFRAME: Skip the frame containing the faulting IB
867 * @KGSL_FT_DISABLE: Tells the dispatcher to disable FT for the command obj
868 * @KGSL_FT_TEMP_DISABLE: Disables FT for all commands
869 * @KGSL_FT_THROTTLE: Disable the context if it faults too often
870 * @KGSL_FT_SKIPCMD: Skip the command containing the faulting IB
871 */
872enum kgsl_ft_policy_bits {
873 KGSL_FT_OFF = 0,
874 KGSL_FT_REPLAY = 1,
875 KGSL_FT_SKIPIB = 2,
876 KGSL_FT_SKIPFRAME = 3,
877 KGSL_FT_DISABLE = 4,
878 KGSL_FT_TEMP_DISABLE = 5,
879 KGSL_FT_THROTTLE = 6,
880 KGSL_FT_SKIPCMD = 7,
881 /* KGSL_FT_MAX_BITS is used to calculate the mask */
882 KGSL_FT_MAX_BITS,
883 /* Internal bits - set during GFT */
884 /* Skip the PM dump on replayed command obj's */
885 KGSL_FT_SKIP_PMDUMP = 31,
886};
887
888#define KGSL_FT_POLICY_MASK GENMASK(KGSL_FT_MAX_BITS - 1, 0)
889
890#define KGSL_FT_DEFAULT_POLICY \
891 (BIT(KGSL_FT_REPLAY) | \
892 BIT(KGSL_FT_SKIPCMD) | \
893 BIT(KGSL_FT_THROTTLE))
894
895#define ADRENO_FT_TYPES \
896 { BIT(KGSL_FT_OFF), "off" }, \
897 { BIT(KGSL_FT_REPLAY), "replay" }, \
898 { BIT(KGSL_FT_SKIPIB), "skipib" }, \
899 { BIT(KGSL_FT_SKIPFRAME), "skipframe" }, \
900 { BIT(KGSL_FT_DISABLE), "disable" }, \
901 { BIT(KGSL_FT_TEMP_DISABLE), "temp" }, \
902 { BIT(KGSL_FT_THROTTLE), "throttle"}, \
903 { BIT(KGSL_FT_SKIPCMD), "skipcmd" }
904
905/**
906 * enum kgsl_ft_pagefault_policy_bits - KGSL pagefault policy bits
907 * @KGSL_FT_PAGEFAULT_INT_ENABLE: No longer used, but retained for compatibility
908 * @KGSL_FT_PAGEFAULT_GPUHALT_ENABLE: enable GPU halt on pagefaults
909 * @KGSL_FT_PAGEFAULT_LOG_ONE_PER_PAGE: log one pagefault per page
910 * @KGSL_FT_PAGEFAULT_LOG_ONE_PER_INT: log one pagefault per interrupt
911 */
912enum {
913 KGSL_FT_PAGEFAULT_INT_ENABLE = 0,
914 KGSL_FT_PAGEFAULT_GPUHALT_ENABLE = 1,
915 KGSL_FT_PAGEFAULT_LOG_ONE_PER_PAGE = 2,
916 KGSL_FT_PAGEFAULT_LOG_ONE_PER_INT = 3,
917 /* KGSL_FT_PAGEFAULT_MAX_BITS is used to calculate the mask */
918 KGSL_FT_PAGEFAULT_MAX_BITS,
919};
920
921#define KGSL_FT_PAGEFAULT_MASK GENMASK(KGSL_FT_PAGEFAULT_MAX_BITS - 1, 0)
922
923#define KGSL_FT_PAGEFAULT_DEFAULT_POLICY 0
924
925#define FOR_EACH_RINGBUFFER(_dev, _rb, _i) \
926 for ((_i) = 0, (_rb) = &((_dev)->ringbuffers[0]); \
927 (_i) < (_dev)->num_ringbuffers; \
928 (_i)++, (_rb)++)
929
930struct adreno_ft_perf_counters {
931 unsigned int counter;
932 unsigned int countable;
933};
934
935extern unsigned int *adreno_ft_regs;
936extern unsigned int adreno_ft_regs_num;
937extern unsigned int *adreno_ft_regs_val;
938
939extern struct adreno_gpudev adreno_a3xx_gpudev;
940extern struct adreno_gpudev adreno_a4xx_gpudev;
941extern struct adreno_gpudev adreno_a5xx_gpudev;
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -0700942extern struct adreno_gpudev adreno_a6xx_gpudev;
Shrenuj Bansala419c792016-10-20 14:05:11 -0700943
944extern int adreno_wake_nice;
945extern unsigned int adreno_wake_timeout;
946
947long adreno_ioctl(struct kgsl_device_private *dev_priv,
948 unsigned int cmd, unsigned long arg);
949
950long adreno_ioctl_helper(struct kgsl_device_private *dev_priv,
951 unsigned int cmd, unsigned long arg,
952 const struct kgsl_ioctl *cmds, int len);
953
Carter Cooper1d8f5472017-03-15 15:01:09 -0600954int a5xx_critical_packet_submit(struct adreno_device *adreno_dev,
955 struct adreno_ringbuffer *rb);
956int adreno_set_unsecured_mode(struct adreno_device *adreno_dev,
957 struct adreno_ringbuffer *rb);
Carter Cooper8567af02017-03-15 14:22:03 -0600958void adreno_spin_idle_debug(struct adreno_device *adreno_dev, const char *str);
Shrenuj Bansala419c792016-10-20 14:05:11 -0700959int adreno_spin_idle(struct adreno_device *device, unsigned int timeout);
960int adreno_idle(struct kgsl_device *device);
961bool adreno_isidle(struct kgsl_device *device);
962
963int adreno_set_constraint(struct kgsl_device *device,
964 struct kgsl_context *context,
965 struct kgsl_device_constraint *constraint);
966
967void adreno_shadermem_regread(struct kgsl_device *device,
968 unsigned int offsetwords,
969 unsigned int *value);
970
971void adreno_snapshot(struct kgsl_device *device,
972 struct kgsl_snapshot *snapshot,
973 struct kgsl_context *context);
974
975int adreno_reset(struct kgsl_device *device, int fault);
976
977void adreno_fault_skipcmd_detached(struct adreno_device *adreno_dev,
978 struct adreno_context *drawctxt,
979 struct kgsl_drawobj *drawobj);
980
981int adreno_coresight_init(struct adreno_device *adreno_dev);
982
983void adreno_coresight_start(struct adreno_device *adreno_dev);
984void adreno_coresight_stop(struct adreno_device *adreno_dev);
985
986void adreno_coresight_remove(struct adreno_device *adreno_dev);
987
988bool adreno_hw_isidle(struct adreno_device *adreno_dev);
989
990void adreno_fault_detect_start(struct adreno_device *adreno_dev);
991void adreno_fault_detect_stop(struct adreno_device *adreno_dev);
992
993void adreno_hang_int_callback(struct adreno_device *adreno_dev, int bit);
994void adreno_cp_callback(struct adreno_device *adreno_dev, int bit);
995
996int adreno_sysfs_init(struct adreno_device *adreno_dev);
997void adreno_sysfs_close(struct adreno_device *adreno_dev);
998
999void adreno_irqctrl(struct adreno_device *adreno_dev, int state);
1000
1001long adreno_ioctl_perfcounter_get(struct kgsl_device_private *dev_priv,
1002 unsigned int cmd, void *data);
1003
1004long adreno_ioctl_perfcounter_put(struct kgsl_device_private *dev_priv,
1005 unsigned int cmd, void *data);
1006
1007int adreno_efuse_map(struct adreno_device *adreno_dev);
1008int adreno_efuse_read_u32(struct adreno_device *adreno_dev, unsigned int offset,
1009 unsigned int *val);
1010void adreno_efuse_unmap(struct adreno_device *adreno_dev);
1011
1012#define ADRENO_TARGET(_name, _id) \
1013static inline int adreno_is_##_name(struct adreno_device *adreno_dev) \
1014{ \
1015 return (ADRENO_GPUREV(adreno_dev) == (_id)); \
1016}
1017
1018static inline int adreno_is_a3xx(struct adreno_device *adreno_dev)
1019{
1020 return ((ADRENO_GPUREV(adreno_dev) >= 300) &&
1021 (ADRENO_GPUREV(adreno_dev) < 400));
1022}
1023
1024ADRENO_TARGET(a304, ADRENO_REV_A304)
1025ADRENO_TARGET(a305, ADRENO_REV_A305)
1026ADRENO_TARGET(a305b, ADRENO_REV_A305B)
1027ADRENO_TARGET(a305c, ADRENO_REV_A305C)
1028ADRENO_TARGET(a306, ADRENO_REV_A306)
1029ADRENO_TARGET(a306a, ADRENO_REV_A306A)
1030ADRENO_TARGET(a310, ADRENO_REV_A310)
1031ADRENO_TARGET(a320, ADRENO_REV_A320)
1032ADRENO_TARGET(a330, ADRENO_REV_A330)
1033
1034static inline int adreno_is_a330v2(struct adreno_device *adreno_dev)
1035{
1036 return ((ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A330) &&
1037 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) > 0));
1038}
1039
1040static inline int adreno_is_a330v21(struct adreno_device *adreno_dev)
1041{
1042 return ((ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A330) &&
1043 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) > 0xF));
1044}
1045
1046static inline int adreno_is_a4xx(struct adreno_device *adreno_dev)
1047{
1048 return ADRENO_GPUREV(adreno_dev) >= 400 &&
1049 ADRENO_GPUREV(adreno_dev) < 500;
1050}
1051
1052ADRENO_TARGET(a405, ADRENO_REV_A405);
1053
1054static inline int adreno_is_a405v2(struct adreno_device *adreno_dev)
1055{
1056 return (ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A405) &&
1057 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) == 0x10);
1058}
1059
1060ADRENO_TARGET(a418, ADRENO_REV_A418)
1061ADRENO_TARGET(a420, ADRENO_REV_A420)
1062ADRENO_TARGET(a430, ADRENO_REV_A430)
1063
1064static inline int adreno_is_a430v2(struct adreno_device *adreno_dev)
1065{
1066 return ((ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A430) &&
1067 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) == 1));
1068}
1069
1070static inline int adreno_is_a5xx(struct adreno_device *adreno_dev)
1071{
1072 return ADRENO_GPUREV(adreno_dev) >= 500 &&
1073 ADRENO_GPUREV(adreno_dev) < 600;
1074}
1075
1076ADRENO_TARGET(a505, ADRENO_REV_A505)
1077ADRENO_TARGET(a506, ADRENO_REV_A506)
Rajesh Kemisettiaed6ec72017-02-06 09:37:00 +05301078ADRENO_TARGET(a508, ADRENO_REV_A508)
Shrenuj Bansala419c792016-10-20 14:05:11 -07001079ADRENO_TARGET(a510, ADRENO_REV_A510)
1080ADRENO_TARGET(a512, ADRENO_REV_A512)
1081ADRENO_TARGET(a530, ADRENO_REV_A530)
1082ADRENO_TARGET(a540, ADRENO_REV_A540)
1083
1084static inline int adreno_is_a530v1(struct adreno_device *adreno_dev)
1085{
1086 return (ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A530) &&
1087 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) == 0);
1088}
1089
1090static inline int adreno_is_a530v2(struct adreno_device *adreno_dev)
1091{
1092 return (ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A530) &&
1093 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) == 1);
1094}
1095
1096static inline int adreno_is_a530v3(struct adreno_device *adreno_dev)
1097{
1098 return (ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A530) &&
1099 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) == 2);
1100}
1101
1102static inline int adreno_is_a505_or_a506(struct adreno_device *adreno_dev)
1103{
1104 return ADRENO_GPUREV(adreno_dev) >= 505 &&
1105 ADRENO_GPUREV(adreno_dev) <= 506;
1106}
1107
1108static inline int adreno_is_a540v1(struct adreno_device *adreno_dev)
1109{
1110 return (ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A540) &&
1111 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) == 0);
1112}
1113
1114static inline int adreno_is_a540v2(struct adreno_device *adreno_dev)
1115{
1116 return (ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A540) &&
1117 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) == 1);
1118}
1119
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -07001120static inline int adreno_is_a6xx(struct adreno_device *adreno_dev)
1121{
1122 return ADRENO_GPUREV(adreno_dev) >= 600 &&
1123 ADRENO_GPUREV(adreno_dev) < 700;
1124}
1125
1126ADRENO_TARGET(a630, ADRENO_REV_A630)
1127
Shrenuj Bansal397e5892017-03-13 13:38:47 -07001128static inline int adreno_is_a630v1(struct adreno_device *adreno_dev)
1129{
1130 return (ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A630) &&
1131 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) == 0);
1132}
1133
Shrenuj Bansala419c792016-10-20 14:05:11 -07001134/*
1135 * adreno_checkreg_off() - Checks the validity of a register enum
1136 * @adreno_dev: Pointer to adreno device
1137 * @offset_name: The register enum that is checked
1138 */
1139static inline bool adreno_checkreg_off(struct adreno_device *adreno_dev,
1140 enum adreno_regs offset_name)
1141{
1142 struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
1143
1144 if (offset_name >= ADRENO_REG_REGISTER_MAX ||
1145 gpudev->reg_offsets->offsets[offset_name] == ADRENO_REG_UNUSED)
1146 return false;
1147
1148 /*
1149 * GPU register programming is kept common as much as possible
1150 * across the cores, Use ADRENO_REG_SKIP when certain register
1151 * programming needs to be skipped for certain GPU cores.
1152 * Example: Certain registers on a5xx like IB1_BASE are 64 bit.
1153 * Common programming programs 64bit register but upper 32 bits
1154 * are skipped in a4xx and a3xx using ADRENO_REG_SKIP.
1155 */
1156 if (gpudev->reg_offsets->offsets[offset_name] == ADRENO_REG_SKIP)
1157 return false;
1158
1159 return true;
1160}
1161
1162/*
1163 * adreno_readreg() - Read a register by getting its offset from the
1164 * offset array defined in gpudev node
1165 * @adreno_dev: Pointer to the the adreno device
1166 * @offset_name: The register enum that is to be read
1167 * @val: Register value read is placed here
1168 */
1169static inline void adreno_readreg(struct adreno_device *adreno_dev,
1170 enum adreno_regs offset_name, unsigned int *val)
1171{
1172 struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
1173
1174 if (adreno_checkreg_off(adreno_dev, offset_name))
1175 kgsl_regread(KGSL_DEVICE(adreno_dev),
1176 gpudev->reg_offsets->offsets[offset_name], val);
1177 else
1178 *val = 0;
1179}
1180
1181/*
1182 * adreno_writereg() - Write a register by getting its offset from the
1183 * offset array defined in gpudev node
1184 * @adreno_dev: Pointer to the the adreno device
1185 * @offset_name: The register enum that is to be written
1186 * @val: Value to write
1187 */
1188static inline void adreno_writereg(struct adreno_device *adreno_dev,
1189 enum adreno_regs offset_name, unsigned int val)
1190{
1191 struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
1192
1193 if (adreno_checkreg_off(adreno_dev, offset_name))
1194 kgsl_regwrite(KGSL_DEVICE(adreno_dev),
1195 gpudev->reg_offsets->offsets[offset_name], val);
1196}
1197
1198/*
1199 * adreno_getreg() - Returns the offset value of a register from the
1200 * register offset array in the gpudev node
1201 * @adreno_dev: Pointer to the the adreno device
1202 * @offset_name: The register enum whore offset is returned
1203 */
1204static inline unsigned int adreno_getreg(struct adreno_device *adreno_dev,
1205 enum adreno_regs offset_name)
1206{
1207 struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
1208
1209 if (!adreno_checkreg_off(adreno_dev, offset_name))
1210 return ADRENO_REG_REGISTER_MAX;
1211 return gpudev->reg_offsets->offsets[offset_name];
1212}
1213
1214/*
Kyle Pieferb1027b02017-02-10 13:58:58 -08001215 * adreno_read_gmureg() - Read a GMU register by getting its offset from the
1216 * offset array defined in gpudev node
1217 * @adreno_dev: Pointer to the the adreno device
1218 * @offset_name: The register enum that is to be read
1219 * @val: Register value read is placed here
1220 */
1221static inline void adreno_read_gmureg(struct adreno_device *adreno_dev,
1222 enum adreno_regs offset_name, unsigned int *val)
1223{
1224 struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
1225
1226 if (adreno_checkreg_off(adreno_dev, offset_name))
1227 kgsl_gmu_regread(KGSL_DEVICE(adreno_dev),
1228 gpudev->reg_offsets->offsets[offset_name], val);
1229 else
1230 *val = 0xDEADBEEF;
1231}
1232
1233/*
1234 * adreno_write_gmureg() - Write a GMU register by getting its offset from the
1235 * offset array defined in gpudev node
1236 * @adreno_dev: Pointer to the the adreno device
1237 * @offset_name: The register enum that is to be written
1238 * @val: Value to write
1239 */
1240static inline void adreno_write_gmureg(struct adreno_device *adreno_dev,
1241 enum adreno_regs offset_name, unsigned int val)
1242{
1243 struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
1244
1245 if (adreno_checkreg_off(adreno_dev, offset_name))
1246 kgsl_gmu_regwrite(KGSL_DEVICE(adreno_dev),
1247 gpudev->reg_offsets->offsets[offset_name], val);
1248}
1249
1250/*
Shrenuj Bansala419c792016-10-20 14:05:11 -07001251 * adreno_get_int() - Returns the offset value of an interrupt bit from
1252 * the interrupt bit array in the gpudev node
1253 * @adreno_dev: Pointer to the the adreno device
1254 * @bit_name: The interrupt bit enum whose bit is returned
1255 */
1256static inline unsigned int adreno_get_int(struct adreno_device *adreno_dev,
1257 enum adreno_int_bits bit_name)
1258{
1259 struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
1260
1261 if (bit_name >= ADRENO_INT_BITS_MAX)
1262 return -ERANGE;
1263
1264 return gpudev->int_bits[bit_name];
1265}
1266
1267/**
1268 * adreno_gpu_fault() - Return the current state of the GPU
1269 * @adreno_dev: A pointer to the adreno_device to query
1270 *
1271 * Return 0 if there is no fault or positive with the last type of fault that
1272 * occurred
1273 */
1274static inline unsigned int adreno_gpu_fault(struct adreno_device *adreno_dev)
1275{
1276 /* make sure we're reading the latest value */
1277 smp_rmb();
1278 return atomic_read(&adreno_dev->dispatcher.fault);
1279}
1280
1281/**
1282 * adreno_set_gpu_fault() - Set the current fault status of the GPU
1283 * @adreno_dev: A pointer to the adreno_device to set
1284 * @state: fault state to set
1285 *
1286 */
1287static inline void adreno_set_gpu_fault(struct adreno_device *adreno_dev,
1288 int state)
1289{
1290 /* only set the fault bit w/o overwriting other bits */
1291 atomic_add(state, &adreno_dev->dispatcher.fault);
1292
1293 /* make sure other CPUs see the update */
1294 smp_wmb();
1295}
1296
1297
1298/**
1299 * adreno_clear_gpu_fault() - Clear the GPU fault register
1300 * @adreno_dev: A pointer to an adreno_device structure
1301 *
1302 * Clear the GPU fault status for the adreno device
1303 */
1304
1305static inline void adreno_clear_gpu_fault(struct adreno_device *adreno_dev)
1306{
1307 atomic_set(&adreno_dev->dispatcher.fault, 0);
1308
1309 /* make sure other CPUs see the update */
1310 smp_wmb();
1311}
1312
1313/**
1314 * adreno_gpu_halt() - Return the GPU halt refcount
1315 * @adreno_dev: A pointer to the adreno_device
1316 */
1317static inline int adreno_gpu_halt(struct adreno_device *adreno_dev)
1318{
1319 /* make sure we're reading the latest value */
1320 smp_rmb();
1321 return atomic_read(&adreno_dev->halt);
1322}
1323
1324
1325/**
1326 * adreno_clear_gpu_halt() - Clear the GPU halt refcount
1327 * @adreno_dev: A pointer to the adreno_device
1328 */
1329static inline void adreno_clear_gpu_halt(struct adreno_device *adreno_dev)
1330{
1331 atomic_set(&adreno_dev->halt, 0);
1332
1333 /* make sure other CPUs see the update */
1334 smp_wmb();
1335}
1336
1337/**
1338 * adreno_get_gpu_halt() - Increment GPU halt refcount
1339 * @adreno_dev: A pointer to the adreno_device
1340 */
1341static inline void adreno_get_gpu_halt(struct adreno_device *adreno_dev)
1342{
1343 atomic_inc(&adreno_dev->halt);
1344}
1345
1346/**
1347 * adreno_put_gpu_halt() - Decrement GPU halt refcount
1348 * @adreno_dev: A pointer to the adreno_device
1349 */
1350static inline void adreno_put_gpu_halt(struct adreno_device *adreno_dev)
1351{
1352 /* Make sure the refcount is good */
1353 int ret = atomic_dec_if_positive(&adreno_dev->halt);
1354
1355 WARN(ret < 0, "GPU halt refcount unbalanced\n");
1356}
1357
1358
1359/*
1360 * adreno_vbif_start() - Program VBIF registers, called in device start
1361 * @adreno_dev: Pointer to device whose vbif data is to be programmed
1362 * @vbif_platforms: list register value pair of vbif for a family
1363 * of adreno cores
1364 * @num_platforms: Number of platforms contained in vbif_platforms
1365 */
1366static inline void adreno_vbif_start(struct adreno_device *adreno_dev,
1367 const struct adreno_vbif_platform *vbif_platforms,
1368 int num_platforms)
1369{
1370 int i;
1371 const struct adreno_vbif_data *vbif = NULL;
1372
1373 for (i = 0; i < num_platforms; i++) {
1374 if (vbif_platforms[i].devfunc(adreno_dev)) {
1375 vbif = vbif_platforms[i].vbif;
1376 break;
1377 }
1378 }
1379
1380 while ((vbif != NULL) && (vbif->reg != 0)) {
1381 kgsl_regwrite(KGSL_DEVICE(adreno_dev), vbif->reg, vbif->val);
1382 vbif++;
1383 }
1384}
1385
1386/**
1387 * adreno_set_protected_registers() - Protect the specified range of registers
1388 * from being accessed by the GPU
1389 * @adreno_dev: pointer to the Adreno device
1390 * @index: Pointer to the index of the protect mode register to write to
1391 * @reg: Starting dword register to write
1392 * @mask_len: Size of the mask to protect (# of registers = 2 ** mask_len)
1393 *
1394 * Add the range of registers to the list of protected mode registers that will
1395 * cause an exception if the GPU accesses them. There are 16 available
1396 * protected mode registers. Index is used to specify which register to write
1397 * to - the intent is to call this function multiple times with the same index
1398 * pointer for each range and the registers will be magically programmed in
1399 * incremental fashion
1400 */
1401static inline void adreno_set_protected_registers(
1402 struct adreno_device *adreno_dev, unsigned int *index,
1403 unsigned int reg, int mask_len)
1404{
1405 unsigned int val;
1406 unsigned int base =
1407 adreno_getreg(adreno_dev, ADRENO_REG_CP_PROTECT_REG_0);
1408 unsigned int offset = *index;
1409 unsigned int max_slots = adreno_dev->gpucore->num_protected_regs ?
1410 adreno_dev->gpucore->num_protected_regs : 16;
1411
1412 /* Do we have a free slot? */
1413 if (WARN(*index >= max_slots, "Protected register slots full: %d/%d\n",
1414 *index, max_slots))
1415 return;
1416
1417 /*
1418 * On A4XX targets with more than 16 protected mode registers
1419 * the upper registers are not contiguous with the lower 16
1420 * registers so we have to adjust the base and offset accordingly
1421 */
1422
1423 if (adreno_is_a4xx(adreno_dev) && *index >= 0x10) {
1424 base = A4XX_CP_PROTECT_REG_10;
1425 offset = *index - 0x10;
1426 }
1427
1428 val = 0x60000000 | ((mask_len & 0x1F) << 24) | ((reg << 2) & 0xFFFFF);
1429
1430 kgsl_regwrite(KGSL_DEVICE(adreno_dev), base + offset, val);
1431 *index = *index + 1;
1432}
1433
1434#ifdef CONFIG_DEBUG_FS
1435void adreno_debugfs_init(struct adreno_device *adreno_dev);
1436void adreno_context_debugfs_init(struct adreno_device *adreno_dev,
1437 struct adreno_context *ctx);
1438#else
1439static inline void adreno_debugfs_init(struct adreno_device *adreno_dev) { }
1440static inline void adreno_context_debugfs_init(struct adreno_device *device,
1441 struct adreno_context *context)
1442 { }
1443#endif
1444
1445/**
1446 * adreno_compare_pm4_version() - Compare the PM4 microcode version
1447 * @adreno_dev: Pointer to the adreno_device struct
1448 * @version: Version number to compare again
1449 *
1450 * Compare the current version against the specified version and return -1 if
1451 * the current code is older, 0 if equal or 1 if newer.
1452 */
1453static inline int adreno_compare_pm4_version(struct adreno_device *adreno_dev,
1454 unsigned int version)
1455{
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -07001456 if (adreno_dev->fw[ADRENO_FW_PM4].version == version)
Shrenuj Bansala419c792016-10-20 14:05:11 -07001457 return 0;
1458
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -07001459 return (adreno_dev->fw[ADRENO_FW_PM4].version > version) ? 1 : -1;
Shrenuj Bansala419c792016-10-20 14:05:11 -07001460}
1461
1462/**
1463 * adreno_compare_pfp_version() - Compare the PFP microcode version
1464 * @adreno_dev: Pointer to the adreno_device struct
1465 * @version: Version number to compare against
1466 *
1467 * Compare the current version against the specified version and return -1 if
1468 * the current code is older, 0 if equal or 1 if newer.
1469 */
1470static inline int adreno_compare_pfp_version(struct adreno_device *adreno_dev,
1471 unsigned int version)
1472{
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -07001473 if (adreno_dev->fw[ADRENO_FW_PFP].version == version)
Shrenuj Bansala419c792016-10-20 14:05:11 -07001474 return 0;
1475
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -07001476 return (adreno_dev->fw[ADRENO_FW_PFP].version > version) ? 1 : -1;
Shrenuj Bansala419c792016-10-20 14:05:11 -07001477}
1478
1479/*
1480 * adreno_bootstrap_ucode() - Checks if Ucode bootstrapping is supported
1481 * @adreno_dev: Pointer to the the adreno device
1482 */
1483static inline int adreno_bootstrap_ucode(struct adreno_device *adreno_dev)
1484{
1485 return (ADRENO_FEATURE(adreno_dev, ADRENO_USE_BOOTSTRAP) &&
1486 adreno_compare_pfp_version(adreno_dev,
1487 adreno_dev->gpucore->pfp_bstrp_ver) >= 0) ? 1 : 0;
1488}
1489
1490/**
1491 * adreno_in_preempt_state() - Check if preemption state is equal to given state
1492 * @adreno_dev: Device whose preemption state is checked
1493 * @state: State to compare against
1494 */
1495static inline bool adreno_in_preempt_state(struct adreno_device *adreno_dev,
1496 enum adreno_preempt_states state)
1497{
1498 return atomic_read(&adreno_dev->preempt.state) == state;
1499}
1500/**
1501 * adreno_set_preempt_state() - Set the specified preemption state
1502 * @adreno_dev: Device to change preemption state
1503 * @state: State to set
1504 */
1505static inline void adreno_set_preempt_state(struct adreno_device *adreno_dev,
1506 enum adreno_preempt_states state)
1507{
1508 /*
1509 * atomic_set doesn't use barriers, so we need to do it ourselves. One
1510 * before...
1511 */
1512 smp_wmb();
1513 atomic_set(&adreno_dev->preempt.state, state);
1514
1515 /* ... and one after */
1516 smp_wmb();
1517}
1518
1519static inline bool adreno_is_preemption_enabled(
1520 struct adreno_device *adreno_dev)
1521{
1522 return test_bit(ADRENO_DEVICE_PREEMPTION, &adreno_dev->priv);
1523}
1524/**
1525 * adreno_ctx_get_rb() - Return the ringbuffer that a context should
1526 * use based on priority
1527 * @adreno_dev: The adreno device that context is using
1528 * @drawctxt: The context pointer
1529 */
1530static inline struct adreno_ringbuffer *adreno_ctx_get_rb(
1531 struct adreno_device *adreno_dev,
1532 struct adreno_context *drawctxt)
1533{
1534 struct kgsl_context *context;
1535 int level;
1536
1537 if (!drawctxt)
1538 return NULL;
1539
1540 context = &(drawctxt->base);
1541
1542 /*
1543 * If preemption is disabled then everybody needs to go on the same
1544 * ringbuffer
1545 */
1546
1547 if (!adreno_is_preemption_enabled(adreno_dev))
1548 return &(adreno_dev->ringbuffers[0]);
1549
1550 /*
1551 * Math to convert the priority field in context structure to an RB ID.
1552 * Divide up the context priority based on number of ringbuffer levels.
1553 */
1554 level = context->priority / adreno_dev->num_ringbuffers;
1555 if (level < adreno_dev->num_ringbuffers)
1556 return &(adreno_dev->ringbuffers[level]);
1557 else
1558 return &(adreno_dev->ringbuffers[
1559 adreno_dev->num_ringbuffers - 1]);
1560}
1561
1562/*
1563 * adreno_compare_prio_level() - Compares 2 priority levels based on enum values
1564 * @p1: First priority level
1565 * @p2: Second priority level
1566 *
1567 * Returns greater than 0 if p1 is higher priority, 0 if levels are equal else
1568 * less than 0
1569 */
1570static inline int adreno_compare_prio_level(int p1, int p2)
1571{
1572 return p2 - p1;
1573}
1574
1575void adreno_readreg64(struct adreno_device *adreno_dev,
1576 enum adreno_regs lo, enum adreno_regs hi, uint64_t *val);
1577
1578void adreno_writereg64(struct adreno_device *adreno_dev,
1579 enum adreno_regs lo, enum adreno_regs hi, uint64_t val);
1580
1581unsigned int adreno_get_rptr(struct adreno_ringbuffer *rb);
1582
1583static inline bool adreno_rb_empty(struct adreno_ringbuffer *rb)
1584{
1585 return (adreno_get_rptr(rb) == rb->wptr);
1586}
1587
1588static inline bool adreno_soft_fault_detect(struct adreno_device *adreno_dev)
1589{
1590 return adreno_dev->fast_hang_detect &&
1591 !test_bit(ADRENO_DEVICE_ISDB_ENABLED, &adreno_dev->priv);
1592}
1593
1594static inline bool adreno_long_ib_detect(struct adreno_device *adreno_dev)
1595{
1596 return adreno_dev->long_ib_detect &&
1597 !test_bit(ADRENO_DEVICE_ISDB_ENABLED, &adreno_dev->priv);
1598}
1599
1600/*
1601 * adreno_support_64bit() - Check the feature flag only if it is in
1602 * 64bit kernel otherwise return false
1603 * adreno_dev: The adreno device
1604 */
1605#if BITS_PER_LONG == 64
1606static inline bool adreno_support_64bit(struct adreno_device *adreno_dev)
1607{
1608 return ADRENO_FEATURE(adreno_dev, ADRENO_64BIT);
1609}
1610#else
1611static inline bool adreno_support_64bit(struct adreno_device *adreno_dev)
1612{
1613 return false;
1614}
1615#endif /*BITS_PER_LONG*/
1616
1617static inline void adreno_ringbuffer_set_global(
1618 struct adreno_device *adreno_dev, int name)
1619{
1620 struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
1621
1622 kgsl_sharedmem_writel(device,
1623 &adreno_dev->ringbuffers[0].pagetable_desc,
1624 PT_INFO_OFFSET(current_global_ptname), name);
1625}
1626
1627static inline void adreno_ringbuffer_set_pagetable(struct adreno_ringbuffer *rb,
1628 struct kgsl_pagetable *pt)
1629{
1630 struct adreno_device *adreno_dev = ADRENO_RB_DEVICE(rb);
1631 struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
1632 unsigned long flags;
1633
1634 spin_lock_irqsave(&rb->preempt_lock, flags);
1635
1636 kgsl_sharedmem_writel(device, &rb->pagetable_desc,
1637 PT_INFO_OFFSET(current_rb_ptname), pt->name);
1638
1639 kgsl_sharedmem_writeq(device, &rb->pagetable_desc,
1640 PT_INFO_OFFSET(ttbr0), kgsl_mmu_pagetable_get_ttbr0(pt));
1641
1642 kgsl_sharedmem_writel(device, &rb->pagetable_desc,
1643 PT_INFO_OFFSET(contextidr),
1644 kgsl_mmu_pagetable_get_contextidr(pt));
1645
1646 spin_unlock_irqrestore(&rb->preempt_lock, flags);
1647}
1648
1649static inline unsigned int counter_delta(struct kgsl_device *device,
1650 unsigned int reg, unsigned int *counter)
1651{
1652 unsigned int val;
1653 unsigned int ret = 0;
1654
1655 /* Read the value */
1656 kgsl_regread(device, reg, &val);
1657
1658 /* Return 0 for the first read */
1659 if (*counter != 0) {
1660 if (val < *counter)
1661 ret = (0xFFFFFFFF - *counter) + val;
1662 else
1663 ret = val - *counter;
1664 }
1665
1666 *counter = val;
1667 return ret;
1668}
1669#endif /*__ADRENO_H */