blob: cd36e47c4285e0b69b0b35b8343ce01f79f8fa15 [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);
855 bool (*hw_isidle)(struct adreno_device *);
856 int (*rpmh_gpu_pwrctrl)(struct adreno_device *, unsigned int ops,
857 unsigned int arg1, unsigned int arg2);
858 bool (*gmu_isidle)(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 Cooper8567af02017-03-15 14:22:03 -0600954void adreno_spin_idle_debug(struct adreno_device *adreno_dev, const char *str);
Shrenuj Bansala419c792016-10-20 14:05:11 -0700955int adreno_spin_idle(struct adreno_device *device, unsigned int timeout);
956int adreno_idle(struct kgsl_device *device);
957bool adreno_isidle(struct kgsl_device *device);
958
959int adreno_set_constraint(struct kgsl_device *device,
960 struct kgsl_context *context,
961 struct kgsl_device_constraint *constraint);
962
963void adreno_shadermem_regread(struct kgsl_device *device,
964 unsigned int offsetwords,
965 unsigned int *value);
966
967void adreno_snapshot(struct kgsl_device *device,
968 struct kgsl_snapshot *snapshot,
969 struct kgsl_context *context);
970
971int adreno_reset(struct kgsl_device *device, int fault);
972
973void adreno_fault_skipcmd_detached(struct adreno_device *adreno_dev,
974 struct adreno_context *drawctxt,
975 struct kgsl_drawobj *drawobj);
976
977int adreno_coresight_init(struct adreno_device *adreno_dev);
978
979void adreno_coresight_start(struct adreno_device *adreno_dev);
980void adreno_coresight_stop(struct adreno_device *adreno_dev);
981
982void adreno_coresight_remove(struct adreno_device *adreno_dev);
983
984bool adreno_hw_isidle(struct adreno_device *adreno_dev);
985
986void adreno_fault_detect_start(struct adreno_device *adreno_dev);
987void adreno_fault_detect_stop(struct adreno_device *adreno_dev);
988
989void adreno_hang_int_callback(struct adreno_device *adreno_dev, int bit);
990void adreno_cp_callback(struct adreno_device *adreno_dev, int bit);
991
992int adreno_sysfs_init(struct adreno_device *adreno_dev);
993void adreno_sysfs_close(struct adreno_device *adreno_dev);
994
995void adreno_irqctrl(struct adreno_device *adreno_dev, int state);
996
997long adreno_ioctl_perfcounter_get(struct kgsl_device_private *dev_priv,
998 unsigned int cmd, void *data);
999
1000long adreno_ioctl_perfcounter_put(struct kgsl_device_private *dev_priv,
1001 unsigned int cmd, void *data);
1002
1003int adreno_efuse_map(struct adreno_device *adreno_dev);
1004int adreno_efuse_read_u32(struct adreno_device *adreno_dev, unsigned int offset,
1005 unsigned int *val);
1006void adreno_efuse_unmap(struct adreno_device *adreno_dev);
1007
1008#define ADRENO_TARGET(_name, _id) \
1009static inline int adreno_is_##_name(struct adreno_device *adreno_dev) \
1010{ \
1011 return (ADRENO_GPUREV(adreno_dev) == (_id)); \
1012}
1013
1014static inline int adreno_is_a3xx(struct adreno_device *adreno_dev)
1015{
1016 return ((ADRENO_GPUREV(adreno_dev) >= 300) &&
1017 (ADRENO_GPUREV(adreno_dev) < 400));
1018}
1019
1020ADRENO_TARGET(a304, ADRENO_REV_A304)
1021ADRENO_TARGET(a305, ADRENO_REV_A305)
1022ADRENO_TARGET(a305b, ADRENO_REV_A305B)
1023ADRENO_TARGET(a305c, ADRENO_REV_A305C)
1024ADRENO_TARGET(a306, ADRENO_REV_A306)
1025ADRENO_TARGET(a306a, ADRENO_REV_A306A)
1026ADRENO_TARGET(a310, ADRENO_REV_A310)
1027ADRENO_TARGET(a320, ADRENO_REV_A320)
1028ADRENO_TARGET(a330, ADRENO_REV_A330)
1029
1030static inline int adreno_is_a330v2(struct adreno_device *adreno_dev)
1031{
1032 return ((ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A330) &&
1033 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) > 0));
1034}
1035
1036static inline int adreno_is_a330v21(struct adreno_device *adreno_dev)
1037{
1038 return ((ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A330) &&
1039 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) > 0xF));
1040}
1041
1042static inline int adreno_is_a4xx(struct adreno_device *adreno_dev)
1043{
1044 return ADRENO_GPUREV(adreno_dev) >= 400 &&
1045 ADRENO_GPUREV(adreno_dev) < 500;
1046}
1047
1048ADRENO_TARGET(a405, ADRENO_REV_A405);
1049
1050static inline int adreno_is_a405v2(struct adreno_device *adreno_dev)
1051{
1052 return (ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A405) &&
1053 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) == 0x10);
1054}
1055
1056ADRENO_TARGET(a418, ADRENO_REV_A418)
1057ADRENO_TARGET(a420, ADRENO_REV_A420)
1058ADRENO_TARGET(a430, ADRENO_REV_A430)
1059
1060static inline int adreno_is_a430v2(struct adreno_device *adreno_dev)
1061{
1062 return ((ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A430) &&
1063 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) == 1));
1064}
1065
1066static inline int adreno_is_a5xx(struct adreno_device *adreno_dev)
1067{
1068 return ADRENO_GPUREV(adreno_dev) >= 500 &&
1069 ADRENO_GPUREV(adreno_dev) < 600;
1070}
1071
1072ADRENO_TARGET(a505, ADRENO_REV_A505)
1073ADRENO_TARGET(a506, ADRENO_REV_A506)
Rajesh Kemisettiaed6ec72017-02-06 09:37:00 +05301074ADRENO_TARGET(a508, ADRENO_REV_A508)
Shrenuj Bansala419c792016-10-20 14:05:11 -07001075ADRENO_TARGET(a510, ADRENO_REV_A510)
1076ADRENO_TARGET(a512, ADRENO_REV_A512)
1077ADRENO_TARGET(a530, ADRENO_REV_A530)
1078ADRENO_TARGET(a540, ADRENO_REV_A540)
1079
1080static inline int adreno_is_a530v1(struct adreno_device *adreno_dev)
1081{
1082 return (ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A530) &&
1083 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) == 0);
1084}
1085
1086static inline int adreno_is_a530v2(struct adreno_device *adreno_dev)
1087{
1088 return (ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A530) &&
1089 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) == 1);
1090}
1091
1092static inline int adreno_is_a530v3(struct adreno_device *adreno_dev)
1093{
1094 return (ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A530) &&
1095 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) == 2);
1096}
1097
1098static inline int adreno_is_a505_or_a506(struct adreno_device *adreno_dev)
1099{
1100 return ADRENO_GPUREV(adreno_dev) >= 505 &&
1101 ADRENO_GPUREV(adreno_dev) <= 506;
1102}
1103
1104static inline int adreno_is_a540v1(struct adreno_device *adreno_dev)
1105{
1106 return (ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A540) &&
1107 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) == 0);
1108}
1109
1110static inline int adreno_is_a540v2(struct adreno_device *adreno_dev)
1111{
1112 return (ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A540) &&
1113 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) == 1);
1114}
1115
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -07001116static inline int adreno_is_a6xx(struct adreno_device *adreno_dev)
1117{
1118 return ADRENO_GPUREV(adreno_dev) >= 600 &&
1119 ADRENO_GPUREV(adreno_dev) < 700;
1120}
1121
1122ADRENO_TARGET(a630, ADRENO_REV_A630)
1123
Shrenuj Bansal397e5892017-03-13 13:38:47 -07001124static inline int adreno_is_a630v1(struct adreno_device *adreno_dev)
1125{
1126 return (ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A630) &&
1127 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) == 0);
1128}
1129
Shrenuj Bansala419c792016-10-20 14:05:11 -07001130/*
1131 * adreno_checkreg_off() - Checks the validity of a register enum
1132 * @adreno_dev: Pointer to adreno device
1133 * @offset_name: The register enum that is checked
1134 */
1135static inline bool adreno_checkreg_off(struct adreno_device *adreno_dev,
1136 enum adreno_regs offset_name)
1137{
1138 struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
1139
1140 if (offset_name >= ADRENO_REG_REGISTER_MAX ||
1141 gpudev->reg_offsets->offsets[offset_name] == ADRENO_REG_UNUSED)
1142 return false;
1143
1144 /*
1145 * GPU register programming is kept common as much as possible
1146 * across the cores, Use ADRENO_REG_SKIP when certain register
1147 * programming needs to be skipped for certain GPU cores.
1148 * Example: Certain registers on a5xx like IB1_BASE are 64 bit.
1149 * Common programming programs 64bit register but upper 32 bits
1150 * are skipped in a4xx and a3xx using ADRENO_REG_SKIP.
1151 */
1152 if (gpudev->reg_offsets->offsets[offset_name] == ADRENO_REG_SKIP)
1153 return false;
1154
1155 return true;
1156}
1157
1158/*
1159 * adreno_readreg() - Read a register by getting its offset from the
1160 * offset array defined in gpudev node
1161 * @adreno_dev: Pointer to the the adreno device
1162 * @offset_name: The register enum that is to be read
1163 * @val: Register value read is placed here
1164 */
1165static inline void adreno_readreg(struct adreno_device *adreno_dev,
1166 enum adreno_regs offset_name, unsigned int *val)
1167{
1168 struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
1169
1170 if (adreno_checkreg_off(adreno_dev, offset_name))
1171 kgsl_regread(KGSL_DEVICE(adreno_dev),
1172 gpudev->reg_offsets->offsets[offset_name], val);
1173 else
1174 *val = 0;
1175}
1176
1177/*
1178 * adreno_writereg() - Write a register by getting its offset from the
1179 * offset array defined in gpudev node
1180 * @adreno_dev: Pointer to the the adreno device
1181 * @offset_name: The register enum that is to be written
1182 * @val: Value to write
1183 */
1184static inline void adreno_writereg(struct adreno_device *adreno_dev,
1185 enum adreno_regs offset_name, unsigned int val)
1186{
1187 struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
1188
1189 if (adreno_checkreg_off(adreno_dev, offset_name))
1190 kgsl_regwrite(KGSL_DEVICE(adreno_dev),
1191 gpudev->reg_offsets->offsets[offset_name], val);
1192}
1193
1194/*
1195 * adreno_getreg() - Returns the offset value of a register from the
1196 * register offset array in the gpudev node
1197 * @adreno_dev: Pointer to the the adreno device
1198 * @offset_name: The register enum whore offset is returned
1199 */
1200static inline unsigned int adreno_getreg(struct adreno_device *adreno_dev,
1201 enum adreno_regs offset_name)
1202{
1203 struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
1204
1205 if (!adreno_checkreg_off(adreno_dev, offset_name))
1206 return ADRENO_REG_REGISTER_MAX;
1207 return gpudev->reg_offsets->offsets[offset_name];
1208}
1209
1210/*
Kyle Pieferb1027b02017-02-10 13:58:58 -08001211 * adreno_read_gmureg() - Read a GMU register by getting its offset from the
1212 * offset array defined in gpudev node
1213 * @adreno_dev: Pointer to the the adreno device
1214 * @offset_name: The register enum that is to be read
1215 * @val: Register value read is placed here
1216 */
1217static inline void adreno_read_gmureg(struct adreno_device *adreno_dev,
1218 enum adreno_regs offset_name, unsigned int *val)
1219{
1220 struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
1221
1222 if (adreno_checkreg_off(adreno_dev, offset_name))
1223 kgsl_gmu_regread(KGSL_DEVICE(adreno_dev),
1224 gpudev->reg_offsets->offsets[offset_name], val);
1225 else
1226 *val = 0xDEADBEEF;
1227}
1228
1229/*
1230 * adreno_write_gmureg() - Write a GMU register by getting its offset from the
1231 * offset array defined in gpudev node
1232 * @adreno_dev: Pointer to the the adreno device
1233 * @offset_name: The register enum that is to be written
1234 * @val: Value to write
1235 */
1236static inline void adreno_write_gmureg(struct adreno_device *adreno_dev,
1237 enum adreno_regs offset_name, unsigned int val)
1238{
1239 struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
1240
1241 if (adreno_checkreg_off(adreno_dev, offset_name))
1242 kgsl_gmu_regwrite(KGSL_DEVICE(adreno_dev),
1243 gpudev->reg_offsets->offsets[offset_name], val);
1244}
1245
1246/*
Shrenuj Bansala419c792016-10-20 14:05:11 -07001247 * adreno_get_int() - Returns the offset value of an interrupt bit from
1248 * the interrupt bit array in the gpudev node
1249 * @adreno_dev: Pointer to the the adreno device
1250 * @bit_name: The interrupt bit enum whose bit is returned
1251 */
1252static inline unsigned int adreno_get_int(struct adreno_device *adreno_dev,
1253 enum adreno_int_bits bit_name)
1254{
1255 struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
1256
1257 if (bit_name >= ADRENO_INT_BITS_MAX)
1258 return -ERANGE;
1259
1260 return gpudev->int_bits[bit_name];
1261}
1262
1263/**
1264 * adreno_gpu_fault() - Return the current state of the GPU
1265 * @adreno_dev: A pointer to the adreno_device to query
1266 *
1267 * Return 0 if there is no fault or positive with the last type of fault that
1268 * occurred
1269 */
1270static inline unsigned int adreno_gpu_fault(struct adreno_device *adreno_dev)
1271{
1272 /* make sure we're reading the latest value */
1273 smp_rmb();
1274 return atomic_read(&adreno_dev->dispatcher.fault);
1275}
1276
1277/**
1278 * adreno_set_gpu_fault() - Set the current fault status of the GPU
1279 * @adreno_dev: A pointer to the adreno_device to set
1280 * @state: fault state to set
1281 *
1282 */
1283static inline void adreno_set_gpu_fault(struct adreno_device *adreno_dev,
1284 int state)
1285{
1286 /* only set the fault bit w/o overwriting other bits */
1287 atomic_add(state, &adreno_dev->dispatcher.fault);
1288
1289 /* make sure other CPUs see the update */
1290 smp_wmb();
1291}
1292
1293
1294/**
1295 * adreno_clear_gpu_fault() - Clear the GPU fault register
1296 * @adreno_dev: A pointer to an adreno_device structure
1297 *
1298 * Clear the GPU fault status for the adreno device
1299 */
1300
1301static inline void adreno_clear_gpu_fault(struct adreno_device *adreno_dev)
1302{
1303 atomic_set(&adreno_dev->dispatcher.fault, 0);
1304
1305 /* make sure other CPUs see the update */
1306 smp_wmb();
1307}
1308
1309/**
1310 * adreno_gpu_halt() - Return the GPU halt refcount
1311 * @adreno_dev: A pointer to the adreno_device
1312 */
1313static inline int adreno_gpu_halt(struct adreno_device *adreno_dev)
1314{
1315 /* make sure we're reading the latest value */
1316 smp_rmb();
1317 return atomic_read(&adreno_dev->halt);
1318}
1319
1320
1321/**
1322 * adreno_clear_gpu_halt() - Clear the GPU halt refcount
1323 * @adreno_dev: A pointer to the adreno_device
1324 */
1325static inline void adreno_clear_gpu_halt(struct adreno_device *adreno_dev)
1326{
1327 atomic_set(&adreno_dev->halt, 0);
1328
1329 /* make sure other CPUs see the update */
1330 smp_wmb();
1331}
1332
1333/**
1334 * adreno_get_gpu_halt() - Increment GPU halt refcount
1335 * @adreno_dev: A pointer to the adreno_device
1336 */
1337static inline void adreno_get_gpu_halt(struct adreno_device *adreno_dev)
1338{
1339 atomic_inc(&adreno_dev->halt);
1340}
1341
1342/**
1343 * adreno_put_gpu_halt() - Decrement GPU halt refcount
1344 * @adreno_dev: A pointer to the adreno_device
1345 */
1346static inline void adreno_put_gpu_halt(struct adreno_device *adreno_dev)
1347{
1348 /* Make sure the refcount is good */
1349 int ret = atomic_dec_if_positive(&adreno_dev->halt);
1350
1351 WARN(ret < 0, "GPU halt refcount unbalanced\n");
1352}
1353
1354
1355/*
1356 * adreno_vbif_start() - Program VBIF registers, called in device start
1357 * @adreno_dev: Pointer to device whose vbif data is to be programmed
1358 * @vbif_platforms: list register value pair of vbif for a family
1359 * of adreno cores
1360 * @num_platforms: Number of platforms contained in vbif_platforms
1361 */
1362static inline void adreno_vbif_start(struct adreno_device *adreno_dev,
1363 const struct adreno_vbif_platform *vbif_platforms,
1364 int num_platforms)
1365{
1366 int i;
1367 const struct adreno_vbif_data *vbif = NULL;
1368
1369 for (i = 0; i < num_platforms; i++) {
1370 if (vbif_platforms[i].devfunc(adreno_dev)) {
1371 vbif = vbif_platforms[i].vbif;
1372 break;
1373 }
1374 }
1375
1376 while ((vbif != NULL) && (vbif->reg != 0)) {
1377 kgsl_regwrite(KGSL_DEVICE(adreno_dev), vbif->reg, vbif->val);
1378 vbif++;
1379 }
1380}
1381
1382/**
1383 * adreno_set_protected_registers() - Protect the specified range of registers
1384 * from being accessed by the GPU
1385 * @adreno_dev: pointer to the Adreno device
1386 * @index: Pointer to the index of the protect mode register to write to
1387 * @reg: Starting dword register to write
1388 * @mask_len: Size of the mask to protect (# of registers = 2 ** mask_len)
1389 *
1390 * Add the range of registers to the list of protected mode registers that will
1391 * cause an exception if the GPU accesses them. There are 16 available
1392 * protected mode registers. Index is used to specify which register to write
1393 * to - the intent is to call this function multiple times with the same index
1394 * pointer for each range and the registers will be magically programmed in
1395 * incremental fashion
1396 */
1397static inline void adreno_set_protected_registers(
1398 struct adreno_device *adreno_dev, unsigned int *index,
1399 unsigned int reg, int mask_len)
1400{
1401 unsigned int val;
1402 unsigned int base =
1403 adreno_getreg(adreno_dev, ADRENO_REG_CP_PROTECT_REG_0);
1404 unsigned int offset = *index;
1405 unsigned int max_slots = adreno_dev->gpucore->num_protected_regs ?
1406 adreno_dev->gpucore->num_protected_regs : 16;
1407
1408 /* Do we have a free slot? */
1409 if (WARN(*index >= max_slots, "Protected register slots full: %d/%d\n",
1410 *index, max_slots))
1411 return;
1412
1413 /*
1414 * On A4XX targets with more than 16 protected mode registers
1415 * the upper registers are not contiguous with the lower 16
1416 * registers so we have to adjust the base and offset accordingly
1417 */
1418
1419 if (adreno_is_a4xx(adreno_dev) && *index >= 0x10) {
1420 base = A4XX_CP_PROTECT_REG_10;
1421 offset = *index - 0x10;
1422 }
1423
1424 val = 0x60000000 | ((mask_len & 0x1F) << 24) | ((reg << 2) & 0xFFFFF);
1425
1426 kgsl_regwrite(KGSL_DEVICE(adreno_dev), base + offset, val);
1427 *index = *index + 1;
1428}
1429
1430#ifdef CONFIG_DEBUG_FS
1431void adreno_debugfs_init(struct adreno_device *adreno_dev);
1432void adreno_context_debugfs_init(struct adreno_device *adreno_dev,
1433 struct adreno_context *ctx);
1434#else
1435static inline void adreno_debugfs_init(struct adreno_device *adreno_dev) { }
1436static inline void adreno_context_debugfs_init(struct adreno_device *device,
1437 struct adreno_context *context)
1438 { }
1439#endif
1440
1441/**
1442 * adreno_compare_pm4_version() - Compare the PM4 microcode version
1443 * @adreno_dev: Pointer to the adreno_device struct
1444 * @version: Version number to compare again
1445 *
1446 * Compare the current version against the specified version and return -1 if
1447 * the current code is older, 0 if equal or 1 if newer.
1448 */
1449static inline int adreno_compare_pm4_version(struct adreno_device *adreno_dev,
1450 unsigned int version)
1451{
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -07001452 if (adreno_dev->fw[ADRENO_FW_PM4].version == version)
Shrenuj Bansala419c792016-10-20 14:05:11 -07001453 return 0;
1454
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -07001455 return (adreno_dev->fw[ADRENO_FW_PM4].version > version) ? 1 : -1;
Shrenuj Bansala419c792016-10-20 14:05:11 -07001456}
1457
1458/**
1459 * adreno_compare_pfp_version() - Compare the PFP microcode version
1460 * @adreno_dev: Pointer to the adreno_device struct
1461 * @version: Version number to compare against
1462 *
1463 * Compare the current version against the specified version and return -1 if
1464 * the current code is older, 0 if equal or 1 if newer.
1465 */
1466static inline int adreno_compare_pfp_version(struct adreno_device *adreno_dev,
1467 unsigned int version)
1468{
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -07001469 if (adreno_dev->fw[ADRENO_FW_PFP].version == version)
Shrenuj Bansala419c792016-10-20 14:05:11 -07001470 return 0;
1471
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -07001472 return (adreno_dev->fw[ADRENO_FW_PFP].version > version) ? 1 : -1;
Shrenuj Bansala419c792016-10-20 14:05:11 -07001473}
1474
1475/*
1476 * adreno_bootstrap_ucode() - Checks if Ucode bootstrapping is supported
1477 * @adreno_dev: Pointer to the the adreno device
1478 */
1479static inline int adreno_bootstrap_ucode(struct adreno_device *adreno_dev)
1480{
1481 return (ADRENO_FEATURE(adreno_dev, ADRENO_USE_BOOTSTRAP) &&
1482 adreno_compare_pfp_version(adreno_dev,
1483 adreno_dev->gpucore->pfp_bstrp_ver) >= 0) ? 1 : 0;
1484}
1485
1486/**
1487 * adreno_in_preempt_state() - Check if preemption state is equal to given state
1488 * @adreno_dev: Device whose preemption state is checked
1489 * @state: State to compare against
1490 */
1491static inline bool adreno_in_preempt_state(struct adreno_device *adreno_dev,
1492 enum adreno_preempt_states state)
1493{
1494 return atomic_read(&adreno_dev->preempt.state) == state;
1495}
1496/**
1497 * adreno_set_preempt_state() - Set the specified preemption state
1498 * @adreno_dev: Device to change preemption state
1499 * @state: State to set
1500 */
1501static inline void adreno_set_preempt_state(struct adreno_device *adreno_dev,
1502 enum adreno_preempt_states state)
1503{
1504 /*
1505 * atomic_set doesn't use barriers, so we need to do it ourselves. One
1506 * before...
1507 */
1508 smp_wmb();
1509 atomic_set(&adreno_dev->preempt.state, state);
1510
1511 /* ... and one after */
1512 smp_wmb();
1513}
1514
1515static inline bool adreno_is_preemption_enabled(
1516 struct adreno_device *adreno_dev)
1517{
1518 return test_bit(ADRENO_DEVICE_PREEMPTION, &adreno_dev->priv);
1519}
1520/**
1521 * adreno_ctx_get_rb() - Return the ringbuffer that a context should
1522 * use based on priority
1523 * @adreno_dev: The adreno device that context is using
1524 * @drawctxt: The context pointer
1525 */
1526static inline struct adreno_ringbuffer *adreno_ctx_get_rb(
1527 struct adreno_device *adreno_dev,
1528 struct adreno_context *drawctxt)
1529{
1530 struct kgsl_context *context;
1531 int level;
1532
1533 if (!drawctxt)
1534 return NULL;
1535
1536 context = &(drawctxt->base);
1537
1538 /*
1539 * If preemption is disabled then everybody needs to go on the same
1540 * ringbuffer
1541 */
1542
1543 if (!adreno_is_preemption_enabled(adreno_dev))
1544 return &(adreno_dev->ringbuffers[0]);
1545
1546 /*
1547 * Math to convert the priority field in context structure to an RB ID.
1548 * Divide up the context priority based on number of ringbuffer levels.
1549 */
1550 level = context->priority / adreno_dev->num_ringbuffers;
1551 if (level < adreno_dev->num_ringbuffers)
1552 return &(adreno_dev->ringbuffers[level]);
1553 else
1554 return &(adreno_dev->ringbuffers[
1555 adreno_dev->num_ringbuffers - 1]);
1556}
1557
1558/*
1559 * adreno_compare_prio_level() - Compares 2 priority levels based on enum values
1560 * @p1: First priority level
1561 * @p2: Second priority level
1562 *
1563 * Returns greater than 0 if p1 is higher priority, 0 if levels are equal else
1564 * less than 0
1565 */
1566static inline int adreno_compare_prio_level(int p1, int p2)
1567{
1568 return p2 - p1;
1569}
1570
1571void adreno_readreg64(struct adreno_device *adreno_dev,
1572 enum adreno_regs lo, enum adreno_regs hi, uint64_t *val);
1573
1574void adreno_writereg64(struct adreno_device *adreno_dev,
1575 enum adreno_regs lo, enum adreno_regs hi, uint64_t val);
1576
1577unsigned int adreno_get_rptr(struct adreno_ringbuffer *rb);
1578
1579static inline bool adreno_rb_empty(struct adreno_ringbuffer *rb)
1580{
1581 return (adreno_get_rptr(rb) == rb->wptr);
1582}
1583
1584static inline bool adreno_soft_fault_detect(struct adreno_device *adreno_dev)
1585{
1586 return adreno_dev->fast_hang_detect &&
1587 !test_bit(ADRENO_DEVICE_ISDB_ENABLED, &adreno_dev->priv);
1588}
1589
1590static inline bool adreno_long_ib_detect(struct adreno_device *adreno_dev)
1591{
1592 return adreno_dev->long_ib_detect &&
1593 !test_bit(ADRENO_DEVICE_ISDB_ENABLED, &adreno_dev->priv);
1594}
1595
1596/*
1597 * adreno_support_64bit() - Check the feature flag only if it is in
1598 * 64bit kernel otherwise return false
1599 * adreno_dev: The adreno device
1600 */
1601#if BITS_PER_LONG == 64
1602static inline bool adreno_support_64bit(struct adreno_device *adreno_dev)
1603{
1604 return ADRENO_FEATURE(adreno_dev, ADRENO_64BIT);
1605}
1606#else
1607static inline bool adreno_support_64bit(struct adreno_device *adreno_dev)
1608{
1609 return false;
1610}
1611#endif /*BITS_PER_LONG*/
1612
1613static inline void adreno_ringbuffer_set_global(
1614 struct adreno_device *adreno_dev, int name)
1615{
1616 struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
1617
1618 kgsl_sharedmem_writel(device,
1619 &adreno_dev->ringbuffers[0].pagetable_desc,
1620 PT_INFO_OFFSET(current_global_ptname), name);
1621}
1622
1623static inline void adreno_ringbuffer_set_pagetable(struct adreno_ringbuffer *rb,
1624 struct kgsl_pagetable *pt)
1625{
1626 struct adreno_device *adreno_dev = ADRENO_RB_DEVICE(rb);
1627 struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
1628 unsigned long flags;
1629
1630 spin_lock_irqsave(&rb->preempt_lock, flags);
1631
1632 kgsl_sharedmem_writel(device, &rb->pagetable_desc,
1633 PT_INFO_OFFSET(current_rb_ptname), pt->name);
1634
1635 kgsl_sharedmem_writeq(device, &rb->pagetable_desc,
1636 PT_INFO_OFFSET(ttbr0), kgsl_mmu_pagetable_get_ttbr0(pt));
1637
1638 kgsl_sharedmem_writel(device, &rb->pagetable_desc,
1639 PT_INFO_OFFSET(contextidr),
1640 kgsl_mmu_pagetable_get_contextidr(pt));
1641
1642 spin_unlock_irqrestore(&rb->preempt_lock, flags);
1643}
1644
1645static inline unsigned int counter_delta(struct kgsl_device *device,
1646 unsigned int reg, unsigned int *counter)
1647{
1648 unsigned int val;
1649 unsigned int ret = 0;
1650
1651 /* Read the value */
1652 kgsl_regread(device, reg, &val);
1653
1654 /* Return 0 for the first read */
1655 if (*counter != 0) {
1656 if (val < *counter)
1657 ret = (0xFFFFFFFF - *counter) + val;
1658 else
1659 ret = val - *counter;
1660 }
1661
1662 *counter = val;
1663 return ret;
1664}
1665#endif /*__ADRENO_H */