blob: 82b06fe5056225f92d2b2b8cf607b856648805c9 [file] [log] [blame]
Harshdeep Dhattfd2b2792017-12-08 14:28:07 -07001/* Copyright (c) 2008-2018, The Linux Foundation. All rights reserved.
Shrenuj Bansala419c792016-10-20 14:05:11 -07002 *
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>
Carter Cooper05f2a6b2017-03-20 11:43:11 -060026#include "kgsl_gmu.h"
Shrenuj Bansala419c792016-10-20 14:05:11 -070027
28#include "a4xx_reg.h"
29
30#ifdef CONFIG_QCOM_OCMEM
31#include <soc/qcom/ocmem.h>
32#endif
33
34#define DEVICE_3D_NAME "kgsl-3d"
35#define DEVICE_3D0_NAME "kgsl-3d0"
36
37/* ADRENO_DEVICE - Given a kgsl_device return the adreno device struct */
38#define ADRENO_DEVICE(device) \
39 container_of(device, struct adreno_device, dev)
40
41/* KGSL_DEVICE - given an adreno_device, return the KGSL device struct */
42#define KGSL_DEVICE(_dev) (&((_dev)->dev))
43
44/* ADRENO_CONTEXT - Given a context return the adreno context struct */
45#define ADRENO_CONTEXT(context) \
46 container_of(context, struct adreno_context, base)
47
48/* ADRENO_GPU_DEVICE - Given an adreno device return the GPU specific struct */
49#define ADRENO_GPU_DEVICE(_a) ((_a)->gpucore->gpudev)
50
51#define ADRENO_CHIPID_CORE(_id) (((_id) >> 24) & 0xFF)
52#define ADRENO_CHIPID_MAJOR(_id) (((_id) >> 16) & 0xFF)
53#define ADRENO_CHIPID_MINOR(_id) (((_id) >> 8) & 0xFF)
54#define ADRENO_CHIPID_PATCH(_id) ((_id) & 0xFF)
55
56/* ADRENO_GPUREV - Return the GPU ID for the given adreno_device */
57#define ADRENO_GPUREV(_a) ((_a)->gpucore->gpurev)
58
59/*
60 * ADRENO_FEATURE - return true if the specified feature is supported by the GPU
61 * core
62 */
63#define ADRENO_FEATURE(_dev, _bit) \
64 ((_dev)->gpucore->features & (_bit))
65
66/**
67 * ADRENO_QUIRK - return true if the specified quirk is required by the GPU
68 */
69#define ADRENO_QUIRK(_dev, _bit) \
70 ((_dev)->quirks & (_bit))
71
72/*
73 * ADRENO_PREEMPT_STYLE - return preemption style
74 */
75#define ADRENO_PREEMPT_STYLE(flags) \
76 ((flags & KGSL_CONTEXT_PREEMPT_STYLE_MASK) >> \
77 KGSL_CONTEXT_PREEMPT_STYLE_SHIFT)
78
79/*
80 * return the dispatcher drawqueue in which the given drawobj should
81 * be submitted
82 */
83#define ADRENO_DRAWOBJ_DISPATCH_DRAWQUEUE(c) \
84 (&((ADRENO_CONTEXT(c->context))->rb->dispatch_q))
85
86#define ADRENO_DRAWOBJ_RB(c) \
87 ((ADRENO_CONTEXT(c->context))->rb)
88
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -070089#define ADRENO_FW(a, f) (&(a->fw[f]))
90
Shrenuj Bansala419c792016-10-20 14:05:11 -070091/* Adreno core features */
92/* The core uses OCMEM for GMEM/binning memory */
93#define ADRENO_USES_OCMEM BIT(0)
94/* The core supports an accelerated warm start */
95#define ADRENO_WARM_START BIT(1)
96/* The core supports the microcode bootstrap functionality */
97#define ADRENO_USE_BOOTSTRAP BIT(2)
98/* The core supports SP/TP hw controlled power collapse */
99#define ADRENO_SPTP_PC BIT(3)
100/* The core supports Peak Power Detection(PPD)*/
101#define ADRENO_PPD BIT(4)
102/* The GPU supports content protection */
103#define ADRENO_CONTENT_PROTECTION BIT(5)
104/* The GPU supports preemption */
105#define ADRENO_PREEMPTION BIT(6)
106/* The core uses GPMU for power and limit management */
107#define ADRENO_GPMU BIT(7)
108/* The GPMU supports Limits Management */
109#define ADRENO_LM BIT(8)
110/* The core uses 64 bit GPU addresses */
111#define ADRENO_64BIT BIT(9)
112/* The GPU supports retention for cpz registers */
113#define ADRENO_CPZ_RETENTION BIT(10)
Shrenuj Bansalae672812016-02-24 14:17:30 -0800114/* The core has soft fault detection available */
115#define ADRENO_SOFT_FAULT_DETECT BIT(11)
Kyle Pieferb1027b02017-02-10 13:58:58 -0800116/* The GMU supports RPMh for power management*/
117#define ADRENO_RPMH BIT(12)
118/* The GMU supports IFPC power management*/
119#define ADRENO_IFPC BIT(13)
120/* The GMU supports HW based NAP */
121#define ADRENO_HW_NAP BIT(14)
122/* The GMU supports min voltage*/
123#define ADRENO_MIN_VOLT BIT(15)
Shrenuj Bansal4fd6a562017-08-07 15:12:54 -0700124/* The core supports IO-coherent memory */
125#define ADRENO_IOCOHERENT BIT(16)
Shrenuj Bansala419c792016-10-20 14:05:11 -0700126
127/*
128 * Adreno GPU quirks - control bits for various workarounds
129 */
130
Lynus Vaz85c8cee2017-03-07 11:31:02 +0530131/* Set TWOPASSUSEWFI in PC_DBG_ECO_CNTL (5XX/6XX) */
Shrenuj Bansala419c792016-10-20 14:05:11 -0700132#define ADRENO_QUIRK_TWO_PASS_USE_WFI BIT(0)
133/* Lock/unlock mutex to sync with the IOMMU */
134#define ADRENO_QUIRK_IOMMU_SYNC BIT(1)
135/* Submit critical packets at GPU wake up */
136#define ADRENO_QUIRK_CRITICAL_PACKETS BIT(2)
137/* Mask out RB1-3 activity signals from HW hang detection logic */
138#define ADRENO_QUIRK_FAULT_DETECT_MASK BIT(3)
139/* Disable RB sampler datapath clock gating optimization */
140#define ADRENO_QUIRK_DISABLE_RB_DP2CLOCKGATING BIT(4)
141/* Disable local memory(LM) feature to avoid corner case error */
142#define ADRENO_QUIRK_DISABLE_LMLOADKILL BIT(5)
Kyle Pieferb1027b02017-02-10 13:58:58 -0800143/* Allow HFI to use registers to send message to GMU */
144#define ADRENO_QUIRK_HFI_USE_REG BIT(6)
Carter Cooper6682ead2017-09-28 14:52:53 -0600145/* Only set protected SECVID registers once */
146#define ADRENO_QUIRK_SECVID_SET_ONCE BIT(7)
Deepak Kumar9cd40032017-12-27 13:02:10 +0530147/*
148 * Limit number of read and write transactions from
149 * UCHE block to GBIF to avoid possible deadlock
150 * between GBIF, SMMU and MEMNOC.
151 */
152#define ADRENO_QUIRK_LIMIT_UCHE_GBIF_RW BIT(8)
Shrenuj Bansala419c792016-10-20 14:05:11 -0700153
154/* Flags to control command packet settings */
155#define KGSL_CMD_FLAGS_NONE 0
156#define KGSL_CMD_FLAGS_PMODE BIT(0)
157#define KGSL_CMD_FLAGS_INTERNAL_ISSUE BIT(1)
158#define KGSL_CMD_FLAGS_WFI BIT(2)
159#define KGSL_CMD_FLAGS_PROFILE BIT(3)
160#define KGSL_CMD_FLAGS_PWRON_FIXUP BIT(4)
161
162/* Command identifiers */
163#define KGSL_CONTEXT_TO_MEM_IDENTIFIER 0x2EADBEEF
164#define KGSL_CMD_IDENTIFIER 0x2EEDFACE
165#define KGSL_CMD_INTERNAL_IDENTIFIER 0x2EEDD00D
166#define KGSL_START_OF_IB_IDENTIFIER 0x2EADEABE
167#define KGSL_END_OF_IB_IDENTIFIER 0x2ABEDEAD
168#define KGSL_START_OF_PROFILE_IDENTIFIER 0x2DEFADE1
169#define KGSL_END_OF_PROFILE_IDENTIFIER 0x2DEFADE2
170#define KGSL_PWRON_FIXUP_IDENTIFIER 0x2AFAFAFA
171
Shrenuj Bansald0fe7462017-05-08 16:11:19 -0700172/* Number of times to try hard reset */
173#define NUM_TIMES_RESET_RETRY 5
174
Kyle Piefer5e1b78bd2017-10-19 13:22:10 -0700175/* Number of times to poll the AHB fence in ISR */
176#define FENCE_RETRY_MAX 100
177
Shrenuj Bansala419c792016-10-20 14:05:11 -0700178/* One cannot wait forever for the core to idle, so set an upper limit to the
179 * amount of time to wait for the core to go idle
180 */
Shrenuj Bansala419c792016-10-20 14:05:11 -0700181#define ADRENO_IDLE_TIMEOUT (20 * 1000)
182
183#define ADRENO_UCHE_GMEM_BASE 0x100000
184
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -0700185#define ADRENO_FW_PFP 0
186#define ADRENO_FW_SQE 0
187#define ADRENO_FW_PM4 1
188
Shrenuj Bansala419c792016-10-20 14:05:11 -0700189enum adreno_gpurev {
190 ADRENO_REV_UNKNOWN = 0,
191 ADRENO_REV_A304 = 304,
192 ADRENO_REV_A305 = 305,
193 ADRENO_REV_A305C = 306,
194 ADRENO_REV_A306 = 307,
195 ADRENO_REV_A306A = 308,
196 ADRENO_REV_A310 = 310,
197 ADRENO_REV_A320 = 320,
198 ADRENO_REV_A330 = 330,
199 ADRENO_REV_A305B = 335,
200 ADRENO_REV_A405 = 405,
201 ADRENO_REV_A418 = 418,
202 ADRENO_REV_A420 = 420,
203 ADRENO_REV_A430 = 430,
204 ADRENO_REV_A505 = 505,
205 ADRENO_REV_A506 = 506,
Rajesh Kemisettiaed6ec72017-02-06 09:37:00 +0530206 ADRENO_REV_A508 = 508,
Shrenuj Bansala419c792016-10-20 14:05:11 -0700207 ADRENO_REV_A510 = 510,
208 ADRENO_REV_A512 = 512,
209 ADRENO_REV_A530 = 530,
210 ADRENO_REV_A540 = 540,
Rajesh Kemisetti8d5cc6e2017-06-06 16:44:17 +0530211 ADRENO_REV_A615 = 615,
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -0700212 ADRENO_REV_A630 = 630,
Shrenuj Bansala419c792016-10-20 14:05:11 -0700213};
214
215#define ADRENO_START_WARM 0
216#define ADRENO_START_COLD 1
217
218#define ADRENO_SOFT_FAULT BIT(0)
219#define ADRENO_HARD_FAULT BIT(1)
220#define ADRENO_TIMEOUT_FAULT BIT(2)
221#define ADRENO_IOMMU_PAGE_FAULT BIT(3)
222#define ADRENO_PREEMPT_FAULT BIT(4)
Shrenuj Bansald0fe7462017-05-08 16:11:19 -0700223#define ADRENO_GMU_FAULT BIT(5)
Hareesh Gundu28b9efd2017-08-24 23:11:09 +0530224#define ADRENO_CTX_DETATCH_TIMEOUT_FAULT BIT(6)
Shrenuj Bansala419c792016-10-20 14:05:11 -0700225
226#define ADRENO_SPTP_PC_CTRL 0
227#define ADRENO_PPD_CTRL 1
228#define ADRENO_LM_CTRL 2
229#define ADRENO_HWCG_CTRL 3
230#define ADRENO_THROTTLING_CTRL 4
231
Rajesh Kemisettid1ca9542017-10-18 15:35:41 +0530232/* VBIF, GBIF halt request and ack mask */
233#define GBIF_HALT_REQUEST 0x1E0
234#define VBIF_RESET_ACK_MASK 0x00f0
235#define VBIF_RESET_ACK_TIMEOUT 100
Shrenuj Bansala419c792016-10-20 14:05:11 -0700236
237/* number of throttle counters for DCVS adjustment */
238#define ADRENO_GPMU_THROTTLE_COUNTERS 4
239/* base for throttle counters */
240#define ADRENO_GPMU_THROTTLE_COUNTERS_BASE_REG 43
241
242struct adreno_gpudev;
243
244/* Time to allow preemption to complete (in ms) */
245#define ADRENO_PREEMPT_TIMEOUT 10000
246
247#define ADRENO_INT_BIT(a, _bit) (((a)->gpucore->gpudev->int_bits) ? \
248 (adreno_get_int(a, _bit) < 0 ? 0 : \
249 BIT(adreno_get_int(a, _bit))) : 0)
250
251/**
252 * enum adreno_preempt_states
253 * ADRENO_PREEMPT_NONE: No preemption is scheduled
254 * ADRENO_PREEMPT_START: The S/W has started
255 * ADRENO_PREEMPT_TRIGGERED: A preeempt has been triggered in the HW
256 * ADRENO_PREEMPT_FAULTED: The preempt timer has fired
257 * ADRENO_PREEMPT_PENDING: The H/W has signaled preemption complete
258 * ADRENO_PREEMPT_COMPLETE: Preemption could not be finished in the IRQ handler,
259 * worker has been scheduled
260 */
261enum adreno_preempt_states {
262 ADRENO_PREEMPT_NONE = 0,
263 ADRENO_PREEMPT_START,
264 ADRENO_PREEMPT_TRIGGERED,
265 ADRENO_PREEMPT_FAULTED,
266 ADRENO_PREEMPT_PENDING,
267 ADRENO_PREEMPT_COMPLETE,
268};
269
270/**
271 * struct adreno_preemption
272 * @state: The current state of preemption
273 * @counters: Memory descriptor for the memory where the GPU writes the
274 * preemption counters on switch
275 * @timer: A timer to make sure preemption doesn't stall
276 * @work: A work struct for the preemption worker (for 5XX)
277 * @token_submit: Indicates if a preempt token has been submitted in
278 * current ringbuffer (for 4XX)
Harshdeep Dhatta8ec51c2017-09-21 17:24:08 -0600279 * preempt_level: The level of preemption (for 6XX)
280 * skipsaverestore: To skip saverestore during L1 preemption (for 6XX)
281 * usesgmem: enable GMEM save/restore across preemption (for 6XX)
Harshdeep Dhatt4ab35b12017-11-16 08:34:39 -0700282 * count: Track the number of preemptions triggered
Shrenuj Bansala419c792016-10-20 14:05:11 -0700283 */
284struct adreno_preemption {
285 atomic_t state;
286 struct kgsl_memdesc counters;
287 struct timer_list timer;
288 struct work_struct work;
289 bool token_submit;
Harshdeep Dhatta8ec51c2017-09-21 17:24:08 -0600290 unsigned int preempt_level;
291 bool skipsaverestore;
292 bool usesgmem;
Harshdeep Dhatt4ab35b12017-11-16 08:34:39 -0700293 unsigned int count;
Shrenuj Bansala419c792016-10-20 14:05:11 -0700294};
295
296
297struct adreno_busy_data {
298 unsigned int gpu_busy;
Deepak Kumar84b9e032017-11-08 13:08:50 +0530299 unsigned int bif_ram_cycles;
300 unsigned int bif_ram_cycles_read_ch1;
301 unsigned int bif_ram_cycles_write_ch0;
302 unsigned int bif_ram_cycles_write_ch1;
303 unsigned int bif_starved_ram;
304 unsigned int bif_starved_ram_ch1;
Shrenuj Bansala419c792016-10-20 14:05:11 -0700305 unsigned int throttle_cycles[ADRENO_GPMU_THROTTLE_COUNTERS];
306};
307
308/**
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -0700309 * struct adreno_firmware - Struct holding fw details
310 * @fwvirt: Buffer which holds the ucode
311 * @size: Size of ucode buffer
312 * @version: Version of ucode
313 * @memdesc: Memory descriptor which holds ucode buffer info
314 */
315struct adreno_firmware {
316 unsigned int *fwvirt;
317 size_t size;
318 unsigned int version;
319 struct kgsl_memdesc memdesc;
320};
321
322/**
Shrenuj Bansala419c792016-10-20 14:05:11 -0700323 * struct adreno_gpu_core - A specific GPU core definition
324 * @gpurev: Unique GPU revision identifier
325 * @core: Match for the core version of the GPU
326 * @major: Match for the major version of the GPU
327 * @minor: Match for the minor version of the GPU
328 * @patchid: Match for the patch revision of the GPU
329 * @features: Common adreno features supported by this core
330 * @pm4fw_name: Filename for th PM4 firmware
331 * @pfpfw_name: Filename for the PFP firmware
332 * @zap_name: Filename for the Zap Shader ucode
333 * @gpudev: Pointer to the GPU family specific functions for this core
334 * @gmem_size: Amount of binning memory (GMEM/OCMEM) to reserve for the core
335 * @pm4_jt_idx: Index of the jump table in the PM4 microcode
336 * @pm4_jt_addr: Address offset to load the jump table for the PM4 microcode
337 * @pfp_jt_idx: Index of the jump table in the PFP microcode
338 * @pfp_jt_addr: Address offset to load the jump table for the PFP microcode
339 * @pm4_bstrp_size: Size of the bootstrap loader for PM4 microcode
340 * @pfp_bstrp_size: Size of the bootstrap loader for PFP microcde
341 * @pfp_bstrp_ver: Version of the PFP microcode that supports bootstraping
342 * @shader_offset: Offset of shader from gpu reg base
343 * @shader_size: Shader size
344 * @num_protected_regs: number of protected registers
345 * @gpmufw_name: Filename for the GPMU firmware
346 * @gpmu_major: Match for the GPMU & firmware, major revision
347 * @gpmu_minor: Match for the GPMU & firmware, minor revision
348 * @gpmu_features: Supported features for any given GPMU version
349 * @busy_mask: mask to check if GPU is busy in RBBM_STATUS
350 * @lm_major: Limits Management register sequence, major revision
351 * @lm_minor: LM register sequence, minor revision
352 * @regfw_name: Filename for the register sequence firmware
353 * @gpmu_tsens: ID for the temporature sensor used by the GPMU
354 * @max_power: Max possible power draw of a core, units elephant tail hairs
355 */
356struct adreno_gpu_core {
357 enum adreno_gpurev gpurev;
358 unsigned int core, major, minor, patchid;
359 unsigned long features;
360 const char *pm4fw_name;
361 const char *pfpfw_name;
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -0700362 const char *sqefw_name;
Shrenuj Bansala419c792016-10-20 14:05:11 -0700363 const char *zap_name;
364 struct adreno_gpudev *gpudev;
365 size_t gmem_size;
366 unsigned int pm4_jt_idx;
367 unsigned int pm4_jt_addr;
368 unsigned int pfp_jt_idx;
369 unsigned int pfp_jt_addr;
370 unsigned int pm4_bstrp_size;
371 unsigned int pfp_bstrp_size;
372 unsigned int pfp_bstrp_ver;
373 unsigned long shader_offset;
374 unsigned int shader_size;
375 unsigned int num_protected_regs;
376 const char *gpmufw_name;
377 unsigned int gpmu_major;
378 unsigned int gpmu_minor;
379 unsigned int gpmu_features;
380 unsigned int busy_mask;
381 unsigned int lm_major, lm_minor;
382 const char *regfw_name;
383 unsigned int gpmu_tsens;
384 unsigned int max_power;
385};
386
Lokesh Batraa8300e02017-05-25 11:17:40 -0700387
388enum gpu_coresight_sources {
389 GPU_CORESIGHT_GX = 0,
390 GPU_CORESIGHT_CX = 1,
391 GPU_CORESIGHT_MAX,
392};
393
Shrenuj Bansala419c792016-10-20 14:05:11 -0700394/**
395 * struct adreno_device - The mothership structure for all adreno related info
396 * @dev: Reference to struct kgsl_device
397 * @priv: Holds the private flags specific to the adreno_device
398 * @chipid: Chip ID specific to the GPU
399 * @gmem_base: Base physical address of GMEM
400 * @gmem_size: GMEM size
401 * @gpucore: Pointer to the adreno_gpu_core structure
402 * @pfp_fw: Buffer which holds the pfp ucode
403 * @pfp_fw_size: Size of pfp ucode buffer
404 * @pfp_fw_version: Version of pfp ucode
405 * @pfp: Memory descriptor which holds pfp ucode buffer info
406 * @pm4_fw: Buffer which holds the pm4 ucode
407 * @pm4_fw_size: Size of pm4 ucode buffer
408 * @pm4_fw_version: Version of pm4 ucode
409 * @pm4: Memory descriptor which holds pm4 ucode buffer info
410 * @gpmu_cmds_size: Length of gpmu cmd stream
411 * @gpmu_cmds: gpmu cmd stream
412 * @ringbuffers: Array of pointers to adreno_ringbuffers
413 * @num_ringbuffers: Number of ringbuffers for the GPU
414 * @cur_rb: Pointer to the current ringbuffer
415 * @next_rb: Ringbuffer we are switching to during preemption
416 * @prev_rb: Ringbuffer we are switching from during preemption
417 * @fast_hang_detect: Software fault detection availability
418 * @ft_policy: Defines the fault tolerance policy
419 * @long_ib_detect: Long IB detection availability
420 * @ft_pf_policy: Defines the fault policy for page faults
421 * @ocmem_hdl: Handle to the ocmem allocated buffer
422 * @profile: Container for adreno profiler information
423 * @dispatcher: Container for adreno GPU dispatcher
424 * @pwron_fixup: Command buffer to run a post-power collapse shader workaround
425 * @pwron_fixup_dwords: Number of dwords in the command buffer
426 * @input_work: Work struct for turning on the GPU after a touch event
427 * @busy_data: Struct holding GPU VBIF busy stats
Deepak Kumar84b9e032017-11-08 13:08:50 +0530428 * @ram_cycles_lo: Number of DDR clock cycles for the monitor session (Only
429 * DDR channel 0 read cycles in case of GBIF)
430 * @ram_cycles_lo_ch1_read: Number of DDR channel 1 Read clock cycles for
431 * the monitor session
432 * @ram_cycles_lo_ch0_write: Number of DDR channel 0 Write clock cycles for
433 * the monitor session
434 * @ram_cycles_lo_ch1_write: Number of DDR channel 0 Write clock cycles for
435 * the monitor session
Deepak Kumarc52781f2017-11-06 16:10:17 +0530436 * @starved_ram_lo: Number of cycles VBIF/GBIF is stalled by DDR (Only channel 0
437 * stall cycles in case of GBIF)
438 * @starved_ram_lo_ch1: Number of cycles GBIF is stalled by DDR channel 1
439 * @perfctr_pwr_lo: GPU busy cycles
Shrenuj Bansala419c792016-10-20 14:05:11 -0700440 * @halt: Atomic variable to check whether the GPU is currently halted
Deepak Kumar273c5712017-01-03 21:49:03 +0530441 * @pending_irq_refcnt: Atomic variable to keep track of running IRQ handlers
Shrenuj Bansala419c792016-10-20 14:05:11 -0700442 * @ctx_d_debugfs: Context debugfs node
443 * @pwrctrl_flag: Flag to hold adreno specific power attributes
444 * @profile_buffer: Memdesc holding the drawobj profiling buffer
445 * @profile_index: Index to store the start/stop ticks in the profiling
446 * buffer
Harshdeep Dhattd0f38f62017-06-01 12:45:26 -0600447 * @pwrup_reglist: Memdesc holding the power up register list
448 * which is used by CP during preemption and IFPC
Shrenuj Bansala419c792016-10-20 14:05:11 -0700449 * @sp_local_gpuaddr: Base GPU virtual address for SP local memory
450 * @sp_pvt_gpuaddr: Base GPU virtual address for SP private memory
451 * @lm_fw: The LM firmware handle
452 * @lm_sequence: Pointer to the start of the register write sequence for LM
453 * @lm_size: The dword size of the LM sequence
454 * @lm_limit: limiting value for LM
455 * @lm_threshold_count: register value for counter for lm threshold breakin
456 * @lm_threshold_cross: number of current peaks exceeding threshold
457 * @speed_bin: Indicate which power level set to use
458 * @csdev: Pointer to a coresight device (if applicable)
459 * @gpmu_throttle_counters - counteers for number of throttled clocks
460 * @irq_storm_work: Worker to handle possible interrupt storms
461 * @active_list: List to track active contexts
462 * @active_list_lock: Lock to protect active_list
Sushmita Susheelendra7f66cf72016-09-12 11:04:43 -0600463 * @gpu_llc_slice: GPU system cache slice descriptor
Sushmita Susheelendrab1976682016-11-07 14:21:11 -0700464 * @gpu_llc_slice_enable: To enable the GPU system cache slice or not
Sushmita Susheelendra906564d2017-01-10 15:53:55 -0700465 * @gpuhtw_llc_slice: GPU pagetables system cache slice descriptor
Sushmita Susheelendrad3756c02017-01-11 15:05:40 -0700466 * @gpuhtw_llc_slice_enable: To enable the GPUHTW system cache slice or not
Harshdeep Dhatta9e0d762017-05-10 14:16:42 -0600467 * @zap_loaded: Used to track if zap was successfully loaded or not
Shrenuj Bansala419c792016-10-20 14:05:11 -0700468 */
469struct adreno_device {
470 struct kgsl_device dev; /* Must be first field in this struct */
471 unsigned long priv;
472 unsigned int chipid;
473 unsigned long gmem_base;
474 unsigned long gmem_size;
Lynus Vaz9ed8cf92017-09-21 21:55:34 +0530475 unsigned long cx_dbgc_base;
476 unsigned int cx_dbgc_len;
477 void __iomem *cx_dbgc_virt;
Shrenuj Bansala419c792016-10-20 14:05:11 -0700478 const struct adreno_gpu_core *gpucore;
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -0700479 struct adreno_firmware fw[2];
Shrenuj Bansala419c792016-10-20 14:05:11 -0700480 size_t gpmu_cmds_size;
481 unsigned int *gpmu_cmds;
482 struct adreno_ringbuffer ringbuffers[KGSL_PRIORITY_MAX_RB_LEVELS];
483 int num_ringbuffers;
484 struct adreno_ringbuffer *cur_rb;
485 struct adreno_ringbuffer *next_rb;
486 struct adreno_ringbuffer *prev_rb;
487 unsigned int fast_hang_detect;
488 unsigned long ft_policy;
489 unsigned int long_ib_detect;
490 unsigned long ft_pf_policy;
491 struct ocmem_buf *ocmem_hdl;
492 struct adreno_profile profile;
493 struct adreno_dispatcher dispatcher;
494 struct kgsl_memdesc pwron_fixup;
495 unsigned int pwron_fixup_dwords;
496 struct work_struct input_work;
497 struct adreno_busy_data busy_data;
498 unsigned int ram_cycles_lo;
Deepak Kumar84b9e032017-11-08 13:08:50 +0530499 unsigned int ram_cycles_lo_ch1_read;
500 unsigned int ram_cycles_lo_ch0_write;
501 unsigned int ram_cycles_lo_ch1_write;
Shrenuj Bansala419c792016-10-20 14:05:11 -0700502 unsigned int starved_ram_lo;
Deepak Kumarc52781f2017-11-06 16:10:17 +0530503 unsigned int starved_ram_lo_ch1;
Shrenuj Bansala419c792016-10-20 14:05:11 -0700504 unsigned int perfctr_pwr_lo;
505 atomic_t halt;
Deepak Kumar273c5712017-01-03 21:49:03 +0530506 atomic_t pending_irq_refcnt;
Shrenuj Bansala419c792016-10-20 14:05:11 -0700507 struct dentry *ctx_d_debugfs;
508 unsigned long pwrctrl_flag;
509
510 struct kgsl_memdesc profile_buffer;
511 unsigned int profile_index;
Harshdeep Dhattd0f38f62017-06-01 12:45:26 -0600512 struct kgsl_memdesc pwrup_reglist;
Shrenuj Bansala419c792016-10-20 14:05:11 -0700513 uint64_t sp_local_gpuaddr;
514 uint64_t sp_pvt_gpuaddr;
515 const struct firmware *lm_fw;
516 uint32_t *lm_sequence;
517 uint32_t lm_size;
518 struct adreno_preemption preempt;
519 struct work_struct gpmu_work;
520 uint32_t lm_leakage;
521 uint32_t lm_limit;
522 uint32_t lm_threshold_count;
523 uint32_t lm_threshold_cross;
524
525 unsigned int speed_bin;
526 unsigned int quirks;
527
Lokesh Batraa8300e02017-05-25 11:17:40 -0700528 struct coresight_device *csdev[GPU_CORESIGHT_MAX];
Shrenuj Bansala419c792016-10-20 14:05:11 -0700529 uint32_t gpmu_throttle_counters[ADRENO_GPMU_THROTTLE_COUNTERS];
530 struct work_struct irq_storm_work;
531
532 struct list_head active_list;
533 spinlock_t active_list_lock;
Sushmita Susheelendra7f66cf72016-09-12 11:04:43 -0600534
535 void *gpu_llc_slice;
Sushmita Susheelendrab1976682016-11-07 14:21:11 -0700536 bool gpu_llc_slice_enable;
Sushmita Susheelendra906564d2017-01-10 15:53:55 -0700537 void *gpuhtw_llc_slice;
Sushmita Susheelendrad3756c02017-01-11 15:05:40 -0700538 bool gpuhtw_llc_slice_enable;
Harshdeep Dhatta9e0d762017-05-10 14:16:42 -0600539 unsigned int zap_loaded;
Shrenuj Bansala419c792016-10-20 14:05:11 -0700540};
541
542/**
543 * enum adreno_device_flags - Private flags for the adreno_device
544 * @ADRENO_DEVICE_PWRON - Set during init after a power collapse
545 * @ADRENO_DEVICE_PWRON_FIXUP - Set if the target requires the shader fixup
546 * after power collapse
547 * @ADRENO_DEVICE_CORESIGHT - Set if the coresight (trace bus) registers should
548 * be restored after power collapse
549 * @ADRENO_DEVICE_HANG_INTR - Set if the hang interrupt should be enabled for
550 * this target
551 * @ADRENO_DEVICE_STARTED - Set if the device start sequence is in progress
552 * @ADRENO_DEVICE_FAULT - Set if the device is currently in fault (and shouldn't
553 * send any more commands to the ringbuffer)
554 * @ADRENO_DEVICE_DRAWOBJ_PROFILE - Set if the device supports drawobj
555 * profiling via the ALWAYSON counter
556 * @ADRENO_DEVICE_PREEMPTION - Turn on/off preemption
557 * @ADRENO_DEVICE_SOFT_FAULT_DETECT - Set if soft fault detect is enabled
558 * @ADRENO_DEVICE_GPMU_INITIALIZED - Set if GPMU firmware initialization succeed
559 * @ADRENO_DEVICE_ISDB_ENABLED - Set if the Integrated Shader DeBugger is
560 * attached and enabled
561 * @ADRENO_DEVICE_CACHE_FLUSH_TS_SUSPENDED - Set if a CACHE_FLUSH_TS irq storm
562 * is in progress
Kyle Piefere923b7a2017-03-28 17:31:48 -0700563 * @ADRENO_DEVICE_HARD_RESET - Set if soft reset fails and hard reset is needed
Shrenuj Bansala419c792016-10-20 14:05:11 -0700564 */
565enum adreno_device_flags {
566 ADRENO_DEVICE_PWRON = 0,
567 ADRENO_DEVICE_PWRON_FIXUP = 1,
568 ADRENO_DEVICE_INITIALIZED = 2,
569 ADRENO_DEVICE_CORESIGHT = 3,
570 ADRENO_DEVICE_HANG_INTR = 4,
571 ADRENO_DEVICE_STARTED = 5,
572 ADRENO_DEVICE_FAULT = 6,
573 ADRENO_DEVICE_DRAWOBJ_PROFILE = 7,
574 ADRENO_DEVICE_GPU_REGULATOR_ENABLED = 8,
575 ADRENO_DEVICE_PREEMPTION = 9,
576 ADRENO_DEVICE_SOFT_FAULT_DETECT = 10,
577 ADRENO_DEVICE_GPMU_INITIALIZED = 11,
578 ADRENO_DEVICE_ISDB_ENABLED = 12,
579 ADRENO_DEVICE_CACHE_FLUSH_TS_SUSPENDED = 13,
Kyle Piefere923b7a2017-03-28 17:31:48 -0700580 ADRENO_DEVICE_HARD_RESET = 14,
Lokesh Batraa8300e02017-05-25 11:17:40 -0700581 ADRENO_DEVICE_CORESIGHT_CX = 16,
Shrenuj Bansala419c792016-10-20 14:05:11 -0700582};
583
584/**
585 * struct adreno_drawobj_profile_entry - a single drawobj entry in the
586 * kernel profiling buffer
587 * @started: Number of GPU ticks at start of the drawobj
588 * @retired: Number of GPU ticks at the end of the drawobj
589 */
590struct adreno_drawobj_profile_entry {
591 uint64_t started;
592 uint64_t retired;
593};
594
595#define ADRENO_DRAWOBJ_PROFILE_COUNT \
596 (PAGE_SIZE / sizeof(struct adreno_drawobj_profile_entry))
597
598#define ADRENO_DRAWOBJ_PROFILE_OFFSET(_index, _member) \
599 ((_index) * sizeof(struct adreno_drawobj_profile_entry) \
600 + offsetof(struct adreno_drawobj_profile_entry, _member))
601
602
603/**
604 * adreno_regs: List of registers that are used in kgsl driver for all
605 * 3D devices. Each device type has different offset value for the same
606 * register, so an array of register offsets are declared for every device
607 * and are indexed by the enumeration values defined in this enum
608 */
609enum adreno_regs {
610 ADRENO_REG_CP_ME_RAM_WADDR,
611 ADRENO_REG_CP_ME_RAM_DATA,
612 ADRENO_REG_CP_PFP_UCODE_DATA,
613 ADRENO_REG_CP_PFP_UCODE_ADDR,
614 ADRENO_REG_CP_WFI_PEND_CTR,
615 ADRENO_REG_CP_RB_BASE,
616 ADRENO_REG_CP_RB_BASE_HI,
617 ADRENO_REG_CP_RB_RPTR_ADDR_LO,
618 ADRENO_REG_CP_RB_RPTR_ADDR_HI,
619 ADRENO_REG_CP_RB_RPTR,
620 ADRENO_REG_CP_RB_WPTR,
621 ADRENO_REG_CP_CNTL,
622 ADRENO_REG_CP_ME_CNTL,
623 ADRENO_REG_CP_RB_CNTL,
624 ADRENO_REG_CP_IB1_BASE,
625 ADRENO_REG_CP_IB1_BASE_HI,
626 ADRENO_REG_CP_IB1_BUFSZ,
627 ADRENO_REG_CP_IB2_BASE,
628 ADRENO_REG_CP_IB2_BASE_HI,
629 ADRENO_REG_CP_IB2_BUFSZ,
630 ADRENO_REG_CP_TIMESTAMP,
631 ADRENO_REG_CP_SCRATCH_REG6,
632 ADRENO_REG_CP_SCRATCH_REG7,
633 ADRENO_REG_CP_ME_RAM_RADDR,
634 ADRENO_REG_CP_ROQ_ADDR,
635 ADRENO_REG_CP_ROQ_DATA,
636 ADRENO_REG_CP_MERCIU_ADDR,
637 ADRENO_REG_CP_MERCIU_DATA,
638 ADRENO_REG_CP_MERCIU_DATA2,
639 ADRENO_REG_CP_MEQ_ADDR,
640 ADRENO_REG_CP_MEQ_DATA,
641 ADRENO_REG_CP_HW_FAULT,
642 ADRENO_REG_CP_PROTECT_STATUS,
643 ADRENO_REG_CP_PREEMPT,
644 ADRENO_REG_CP_PREEMPT_DEBUG,
645 ADRENO_REG_CP_PREEMPT_DISABLE,
646 ADRENO_REG_CP_PROTECT_REG_0,
647 ADRENO_REG_CP_CONTEXT_SWITCH_SMMU_INFO_LO,
648 ADRENO_REG_CP_CONTEXT_SWITCH_SMMU_INFO_HI,
Harshdeep Dhatt59a69572017-11-01 14:46:13 -0600649 ADRENO_REG_CP_CONTEXT_SWITCH_PRIV_NON_SECURE_RESTORE_ADDR_LO,
650 ADRENO_REG_CP_CONTEXT_SWITCH_PRIV_NON_SECURE_RESTORE_ADDR_HI,
651 ADRENO_REG_CP_CONTEXT_SWITCH_PRIV_SECURE_RESTORE_ADDR_LO,
652 ADRENO_REG_CP_CONTEXT_SWITCH_PRIV_SECURE_RESTORE_ADDR_HI,
653 ADRENO_REG_CP_CONTEXT_SWITCH_NON_PRIV_RESTORE_ADDR_LO,
654 ADRENO_REG_CP_CONTEXT_SWITCH_NON_PRIV_RESTORE_ADDR_HI,
Harshdeep Dhatt003f6cf2017-12-14 11:00:22 -0700655 ADRENO_REG_CP_PREEMPT_LEVEL_STATUS,
Shrenuj Bansala419c792016-10-20 14:05:11 -0700656 ADRENO_REG_RBBM_STATUS,
657 ADRENO_REG_RBBM_STATUS3,
658 ADRENO_REG_RBBM_PERFCTR_CTL,
659 ADRENO_REG_RBBM_PERFCTR_LOAD_CMD0,
660 ADRENO_REG_RBBM_PERFCTR_LOAD_CMD1,
661 ADRENO_REG_RBBM_PERFCTR_LOAD_CMD2,
662 ADRENO_REG_RBBM_PERFCTR_LOAD_CMD3,
663 ADRENO_REG_RBBM_PERFCTR_PWR_1_LO,
664 ADRENO_REG_RBBM_INT_0_MASK,
665 ADRENO_REG_RBBM_INT_0_STATUS,
666 ADRENO_REG_RBBM_PM_OVERRIDE2,
667 ADRENO_REG_RBBM_INT_CLEAR_CMD,
668 ADRENO_REG_RBBM_SW_RESET_CMD,
669 ADRENO_REG_RBBM_BLOCK_SW_RESET_CMD,
670 ADRENO_REG_RBBM_BLOCK_SW_RESET_CMD2,
671 ADRENO_REG_RBBM_CLOCK_CTL,
672 ADRENO_REG_VPC_DEBUG_RAM_SEL,
673 ADRENO_REG_VPC_DEBUG_RAM_READ,
674 ADRENO_REG_PA_SC_AA_CONFIG,
675 ADRENO_REG_SQ_GPR_MANAGEMENT,
676 ADRENO_REG_SQ_INST_STORE_MANAGEMENT,
677 ADRENO_REG_TP0_CHICKEN,
678 ADRENO_REG_RBBM_RBBM_CTL,
679 ADRENO_REG_UCHE_INVALIDATE0,
680 ADRENO_REG_UCHE_INVALIDATE1,
Abhilash Kumarf1af1042017-07-14 13:13:44 +0530681 ADRENO_REG_RBBM_PERFCTR_RBBM_0_LO,
682 ADRENO_REG_RBBM_PERFCTR_RBBM_0_HI,
Shrenuj Bansala419c792016-10-20 14:05:11 -0700683 ADRENO_REG_RBBM_PERFCTR_LOAD_VALUE_LO,
684 ADRENO_REG_RBBM_PERFCTR_LOAD_VALUE_HI,
685 ADRENO_REG_RBBM_SECVID_TRUST_CONTROL,
686 ADRENO_REG_RBBM_ALWAYSON_COUNTER_LO,
687 ADRENO_REG_RBBM_ALWAYSON_COUNTER_HI,
688 ADRENO_REG_RBBM_SECVID_TRUST_CONFIG,
689 ADRENO_REG_RBBM_SECVID_TSB_CONTROL,
690 ADRENO_REG_RBBM_SECVID_TSB_TRUSTED_BASE,
691 ADRENO_REG_RBBM_SECVID_TSB_TRUSTED_BASE_HI,
692 ADRENO_REG_RBBM_SECVID_TSB_TRUSTED_SIZE,
Rajesh Kemisettid1ca9542017-10-18 15:35:41 +0530693 ADRENO_REG_RBBM_GPR0_CNTL,
694 ADRENO_REG_RBBM_VBIF_GX_RESET_STATUS,
Shrenuj Bansala419c792016-10-20 14:05:11 -0700695 ADRENO_REG_VBIF_XIN_HALT_CTRL0,
696 ADRENO_REG_VBIF_XIN_HALT_CTRL1,
697 ADRENO_REG_VBIF_VERSION,
Rajesh Kemisetti77b82ed2017-09-24 20:42:41 +0530698 ADRENO_REG_GBIF_HALT,
699 ADRENO_REG_GBIF_HALT_ACK,
Kyle Pieferda0fa542017-08-04 13:39:40 -0700700 ADRENO_REG_GMU_AO_AHB_FENCE_CTRL,
Kyle Pieferb1027b02017-02-10 13:58:58 -0800701 ADRENO_REG_GMU_AO_INTERRUPT_EN,
Kyle Piefere7b06b42017-04-06 13:53:01 -0700702 ADRENO_REG_GMU_AO_HOST_INTERRUPT_CLR,
703 ADRENO_REG_GMU_AO_HOST_INTERRUPT_STATUS,
704 ADRENO_REG_GMU_AO_HOST_INTERRUPT_MASK,
Kyle Pieferb1027b02017-02-10 13:58:58 -0800705 ADRENO_REG_GMU_PWR_COL_KEEPALIVE,
706 ADRENO_REG_GMU_AHB_FENCE_STATUS,
707 ADRENO_REG_GMU_RPMH_POWER_STATE,
708 ADRENO_REG_GMU_HFI_CTRL_STATUS,
709 ADRENO_REG_GMU_HFI_VERSION_INFO,
710 ADRENO_REG_GMU_HFI_SFR_ADDR,
711 ADRENO_REG_GMU_GMU2HOST_INTR_CLR,
712 ADRENO_REG_GMU_GMU2HOST_INTR_INFO,
Kyle Piefere7b06b42017-04-06 13:53:01 -0700713 ADRENO_REG_GMU_GMU2HOST_INTR_MASK,
Kyle Pieferb1027b02017-02-10 13:58:58 -0800714 ADRENO_REG_GMU_HOST2GMU_INTR_SET,
715 ADRENO_REG_GMU_HOST2GMU_INTR_CLR,
716 ADRENO_REG_GMU_HOST2GMU_INTR_RAW_INFO,
George Shen6927d8f2017-07-19 11:38:10 -0700717 ADRENO_REG_GMU_NMI_CONTROL_STATUS,
718 ADRENO_REG_GMU_CM3_CFG,
Lynus Vaz76ecd062017-06-01 20:00:53 +0530719 ADRENO_REG_GPMU_POWER_COUNTER_ENABLE,
Shrenuj Bansala419c792016-10-20 14:05:11 -0700720 ADRENO_REG_REGISTER_MAX,
721};
722
723enum adreno_int_bits {
724 ADRENO_INT_RBBM_AHB_ERROR,
725 ADRENO_INT_BITS_MAX,
726};
727
728/**
729 * adreno_reg_offsets: Holds array of register offsets
730 * @offsets: Offset array of size defined by enum adreno_regs
731 * @offset_0: This is the index of the register in offset array whose value
732 * is 0. 0 is a valid register offset and during initialization of the
733 * offset array we need to know if an offset value is correctly defined to 0
734 */
735struct adreno_reg_offsets {
736 unsigned int *const offsets;
737 enum adreno_regs offset_0;
738};
739
740#define ADRENO_REG_UNUSED 0xFFFFFFFF
741#define ADRENO_REG_SKIP 0xFFFFFFFE
742#define ADRENO_REG_DEFINE(_offset, _reg) [_offset] = _reg
743#define ADRENO_INT_DEFINE(_offset, _val) ADRENO_REG_DEFINE(_offset, _val)
744
745/*
746 * struct adreno_vbif_data - Describes vbif register value pair
747 * @reg: Offset to vbif register
748 * @val: The value that should be programmed in the register at reg
749 */
750struct adreno_vbif_data {
751 unsigned int reg;
752 unsigned int val;
753};
754
755/*
756 * struct adreno_vbif_platform - Holds an array of vbif reg value pairs
757 * for a particular core
758 * @devfunc: Pointer to platform/core identification function
759 * @vbif: Array of reg value pairs for vbif registers
760 */
761struct adreno_vbif_platform {
762 int (*devfunc)(struct adreno_device *);
763 const struct adreno_vbif_data *vbif;
764};
765
766/*
767 * struct adreno_vbif_snapshot_registers - Holds an array of vbif registers
768 * listed for snapshot dump for a particular core
769 * @version: vbif version
770 * @mask: vbif revision mask
771 * @registers: vbif registers listed for snapshot dump
772 * @count: count of vbif registers listed for snapshot
773 */
774struct adreno_vbif_snapshot_registers {
775 const unsigned int version;
776 const unsigned int mask;
777 const unsigned int *registers;
778 const int count;
779};
780
781/**
782 * struct adreno_coresight_register - Definition for a coresight (tracebus)
783 * debug register
784 * @offset: Offset of the debug register in the KGSL mmio region
785 * @initial: Default value to write when coresight is enabled
786 * @value: Current shadow value of the register (to be reprogrammed after power
787 * collapse)
788 */
789struct adreno_coresight_register {
790 unsigned int offset;
791 unsigned int initial;
792 unsigned int value;
793};
794
795struct adreno_coresight_attr {
796 struct device_attribute attr;
797 struct adreno_coresight_register *reg;
798};
799
800ssize_t adreno_coresight_show_register(struct device *device,
801 struct device_attribute *attr, char *buf);
802
803ssize_t adreno_coresight_store_register(struct device *dev,
804 struct device_attribute *attr, const char *buf, size_t size);
805
806#define ADRENO_CORESIGHT_ATTR(_attrname, _reg) \
807 struct adreno_coresight_attr coresight_attr_##_attrname = { \
808 __ATTR(_attrname, 0644, \
809 adreno_coresight_show_register, \
810 adreno_coresight_store_register), \
811 (_reg), }
812
813/**
814 * struct adreno_coresight - GPU specific coresight definition
815 * @registers - Array of GPU specific registers to configure trace bus output
816 * @count - Number of registers in the array
817 * @groups - Pointer to an attribute list of control files
818 * @atid - The unique ATID value of the coresight device
819 */
820struct adreno_coresight {
821 struct adreno_coresight_register *registers;
822 unsigned int count;
823 const struct attribute_group **groups;
824 unsigned int atid;
825};
826
827
828struct adreno_irq_funcs {
829 void (*func)(struct adreno_device *, int);
830};
831#define ADRENO_IRQ_CALLBACK(_c) { .func = _c }
832
833struct adreno_irq {
834 unsigned int mask;
835 struct adreno_irq_funcs *funcs;
836};
837
838/*
839 * struct adreno_debugbus_block - Holds info about debug buses of a chip
840 * @block_id: Bus identifier
841 * @dwords: Number of dwords of data that this block holds
842 */
843struct adreno_debugbus_block {
844 unsigned int block_id;
845 unsigned int dwords;
846};
847
848/*
849 * struct adreno_snapshot_section_sizes - Structure holding the size of
850 * different sections dumped during device snapshot
851 * @cp_pfp: CP PFP data section size
852 * @cp_me: CP ME data section size
853 * @vpc_mem: VPC memory section size
854 * @cp_meq: CP MEQ size
855 * @shader_mem: Size of shader memory of 1 shader section
856 * @cp_merciu: CP MERCIU size
857 * @roq: ROQ size
858 */
859struct adreno_snapshot_sizes {
860 int cp_pfp;
861 int cp_me;
862 int vpc_mem;
863 int cp_meq;
864 int shader_mem;
865 int cp_merciu;
866 int roq;
867};
868
869/*
870 * struct adreno_snapshot_data - Holds data used in snapshot
871 * @sect_sizes: Has sections sizes
872 */
873struct adreno_snapshot_data {
874 struct adreno_snapshot_sizes *sect_sizes;
875};
876
Kyle Pieferedc6c8a2017-11-10 14:51:58 -0800877enum adreno_cp_marker_type {
878 IFPC_DISABLE,
879 IFPC_ENABLE,
880 IB1LIST_START,
881 IB1LIST_END,
882};
883
Shrenuj Bansala419c792016-10-20 14:05:11 -0700884struct adreno_gpudev {
885 /*
886 * These registers are in a different location on different devices,
887 * so define them in the structure and use them as variables.
888 */
889 const struct adreno_reg_offsets *reg_offsets;
890 unsigned int *const int_bits;
891 const struct adreno_ft_perf_counters *ft_perf_counters;
892 unsigned int ft_perf_counters_count;
893
894 struct adreno_perfcounters *perfcounters;
895 const struct adreno_invalid_countables *invalid_countables;
896 struct adreno_snapshot_data *snapshot_data;
897
Lokesh Batraa8300e02017-05-25 11:17:40 -0700898 struct adreno_coresight *coresight[GPU_CORESIGHT_MAX];
Shrenuj Bansala419c792016-10-20 14:05:11 -0700899
900 struct adreno_irq *irq;
901 int num_prio_levels;
902 unsigned int vbif_xin_halt_ctrl0_mask;
903 /* GPU specific function hooks */
904 void (*irq_trace)(struct adreno_device *, unsigned int status);
905 void (*snapshot)(struct adreno_device *, struct kgsl_snapshot *);
Carter Cooperb88b7082017-09-14 09:03:26 -0600906 void (*snapshot_gmu)(struct adreno_device *, struct kgsl_snapshot *);
Shrenuj Bansala419c792016-10-20 14:05:11 -0700907 void (*platform_setup)(struct adreno_device *);
908 void (*init)(struct adreno_device *);
909 void (*remove)(struct adreno_device *);
910 int (*rb_start)(struct adreno_device *, unsigned int start_type);
911 int (*microcode_read)(struct adreno_device *);
912 void (*perfcounter_init)(struct adreno_device *);
913 void (*perfcounter_close)(struct adreno_device *);
914 void (*start)(struct adreno_device *);
915 bool (*is_sptp_idle)(struct adreno_device *);
916 int (*regulator_enable)(struct adreno_device *);
917 void (*regulator_disable)(struct adreno_device *);
918 void (*pwrlevel_change_settings)(struct adreno_device *,
919 unsigned int prelevel, unsigned int postlevel,
920 bool post);
921 uint64_t (*read_throttling_counters)(struct adreno_device *);
922 void (*count_throttles)(struct adreno_device *, uint64_t adj);
923 int (*enable_pwr_counters)(struct adreno_device *,
924 unsigned int counter);
925 unsigned int (*preemption_pre_ibsubmit)(
926 struct adreno_device *adreno_dev,
927 struct adreno_ringbuffer *rb,
928 unsigned int *cmds,
929 struct kgsl_context *context);
930 int (*preemption_yield_enable)(unsigned int *);
Kyle Pieferedc6c8a2017-11-10 14:51:58 -0800931 unsigned int (*set_marker)(unsigned int *cmds,
932 enum adreno_cp_marker_type type);
Shrenuj Bansala419c792016-10-20 14:05:11 -0700933 unsigned int (*preemption_post_ibsubmit)(
934 struct adreno_device *adreno_dev,
935 unsigned int *cmds);
936 int (*preemption_init)(struct adreno_device *);
937 void (*preemption_schedule)(struct adreno_device *);
Harshdeep Dhatt2e42f122017-05-31 17:27:19 -0600938 int (*preemption_context_init)(struct kgsl_context *);
939 void (*preemption_context_destroy)(struct kgsl_context *);
Shrenuj Bansala419c792016-10-20 14:05:11 -0700940 void (*enable_64bit)(struct adreno_device *);
941 void (*clk_set_options)(struct adreno_device *,
Deepak Kumara309e0e2017-03-17 17:27:42 +0530942 const char *, struct clk *, bool on);
Sushmita Susheelendra7f66cf72016-09-12 11:04:43 -0600943 void (*llc_configure_gpu_scid)(struct adreno_device *adreno_dev);
Sushmita Susheelendra906564d2017-01-10 15:53:55 -0700944 void (*llc_configure_gpuhtw_scid)(struct adreno_device *adreno_dev);
Sushmita Susheelendra7f66cf72016-09-12 11:04:43 -0600945 void (*llc_enable_overrides)(struct adreno_device *adreno_dev);
Kyle Pieferb1027b02017-02-10 13:58:58 -0800946 void (*pre_reset)(struct adreno_device *);
947 int (*oob_set)(struct adreno_device *adreno_dev, unsigned int set_mask,
948 unsigned int check_mask,
949 unsigned int clear_mask);
950 void (*oob_clear)(struct adreno_device *adreno_dev,
951 unsigned int clear_mask);
Carter Cooperdf7ba702017-03-20 11:28:04 -0600952 void (*gpu_keepalive)(struct adreno_device *adreno_dev,
953 bool state);
Kyle Pieferb1027b02017-02-10 13:58:58 -0800954 int (*rpmh_gpu_pwrctrl)(struct adreno_device *, unsigned int ops,
955 unsigned int arg1, unsigned int arg2);
Oleg Perelet62d5cec2017-03-27 16:14:52 -0700956 bool (*hw_isidle)(struct adreno_device *);
Kyle Piefer4033f562017-08-16 10:00:48 -0700957 int (*wait_for_lowest_idle)(struct adreno_device *);
Oleg Perelet62d5cec2017-03-27 16:14:52 -0700958 int (*wait_for_gmu_idle)(struct adreno_device *);
Lynus Vaz1fde74d2017-03-20 18:02:47 +0530959 const char *(*iommu_fault_block)(struct adreno_device *adreno_dev,
960 unsigned int fsynr1);
Shrenuj Bansald0fe7462017-05-08 16:11:19 -0700961 int (*reset)(struct kgsl_device *, int fault);
Shrenuj Bansal49d0e9f2017-05-08 16:10:24 -0700962 int (*soft_reset)(struct adreno_device *);
Shrenuj Bansald197bf62017-04-07 11:00:09 -0700963 bool (*gx_is_on)(struct adreno_device *);
964 bool (*sptprac_is_on)(struct adreno_device *);
Harshdeep Dhatt6ba7a942017-08-21 17:53:52 -0600965 unsigned int (*ccu_invalidate)(struct adreno_device *adreno_dev,
966 unsigned int *cmds);
Tarun Karra1382e512017-10-30 19:41:25 -0700967 int (*perfcounter_update)(struct adreno_device *adreno_dev,
968 struct adreno_perfcount_register *reg,
969 bool update_reg);
Shrenuj Bansala419c792016-10-20 14:05:11 -0700970};
971
972/**
973 * enum kgsl_ft_policy_bits - KGSL fault tolerance policy bits
974 * @KGSL_FT_OFF: Disable fault detection (not used)
975 * @KGSL_FT_REPLAY: Replay the faulting command
976 * @KGSL_FT_SKIPIB: Skip the faulting indirect buffer
977 * @KGSL_FT_SKIPFRAME: Skip the frame containing the faulting IB
978 * @KGSL_FT_DISABLE: Tells the dispatcher to disable FT for the command obj
979 * @KGSL_FT_TEMP_DISABLE: Disables FT for all commands
980 * @KGSL_FT_THROTTLE: Disable the context if it faults too often
981 * @KGSL_FT_SKIPCMD: Skip the command containing the faulting IB
982 */
983enum kgsl_ft_policy_bits {
984 KGSL_FT_OFF = 0,
985 KGSL_FT_REPLAY = 1,
986 KGSL_FT_SKIPIB = 2,
987 KGSL_FT_SKIPFRAME = 3,
988 KGSL_FT_DISABLE = 4,
989 KGSL_FT_TEMP_DISABLE = 5,
990 KGSL_FT_THROTTLE = 6,
991 KGSL_FT_SKIPCMD = 7,
992 /* KGSL_FT_MAX_BITS is used to calculate the mask */
993 KGSL_FT_MAX_BITS,
994 /* Internal bits - set during GFT */
995 /* Skip the PM dump on replayed command obj's */
996 KGSL_FT_SKIP_PMDUMP = 31,
997};
998
999#define KGSL_FT_POLICY_MASK GENMASK(KGSL_FT_MAX_BITS - 1, 0)
1000
1001#define KGSL_FT_DEFAULT_POLICY \
1002 (BIT(KGSL_FT_REPLAY) | \
1003 BIT(KGSL_FT_SKIPCMD) | \
1004 BIT(KGSL_FT_THROTTLE))
1005
1006#define ADRENO_FT_TYPES \
1007 { BIT(KGSL_FT_OFF), "off" }, \
1008 { BIT(KGSL_FT_REPLAY), "replay" }, \
1009 { BIT(KGSL_FT_SKIPIB), "skipib" }, \
1010 { BIT(KGSL_FT_SKIPFRAME), "skipframe" }, \
1011 { BIT(KGSL_FT_DISABLE), "disable" }, \
1012 { BIT(KGSL_FT_TEMP_DISABLE), "temp" }, \
1013 { BIT(KGSL_FT_THROTTLE), "throttle"}, \
1014 { BIT(KGSL_FT_SKIPCMD), "skipcmd" }
1015
1016/**
1017 * enum kgsl_ft_pagefault_policy_bits - KGSL pagefault policy bits
1018 * @KGSL_FT_PAGEFAULT_INT_ENABLE: No longer used, but retained for compatibility
1019 * @KGSL_FT_PAGEFAULT_GPUHALT_ENABLE: enable GPU halt on pagefaults
1020 * @KGSL_FT_PAGEFAULT_LOG_ONE_PER_PAGE: log one pagefault per page
1021 * @KGSL_FT_PAGEFAULT_LOG_ONE_PER_INT: log one pagefault per interrupt
1022 */
1023enum {
1024 KGSL_FT_PAGEFAULT_INT_ENABLE = 0,
1025 KGSL_FT_PAGEFAULT_GPUHALT_ENABLE = 1,
1026 KGSL_FT_PAGEFAULT_LOG_ONE_PER_PAGE = 2,
1027 KGSL_FT_PAGEFAULT_LOG_ONE_PER_INT = 3,
1028 /* KGSL_FT_PAGEFAULT_MAX_BITS is used to calculate the mask */
1029 KGSL_FT_PAGEFAULT_MAX_BITS,
1030};
1031
1032#define KGSL_FT_PAGEFAULT_MASK GENMASK(KGSL_FT_PAGEFAULT_MAX_BITS - 1, 0)
1033
1034#define KGSL_FT_PAGEFAULT_DEFAULT_POLICY 0
1035
1036#define FOR_EACH_RINGBUFFER(_dev, _rb, _i) \
1037 for ((_i) = 0, (_rb) = &((_dev)->ringbuffers[0]); \
1038 (_i) < (_dev)->num_ringbuffers; \
1039 (_i)++, (_rb)++)
1040
1041struct adreno_ft_perf_counters {
1042 unsigned int counter;
1043 unsigned int countable;
1044};
1045
1046extern unsigned int *adreno_ft_regs;
1047extern unsigned int adreno_ft_regs_num;
1048extern unsigned int *adreno_ft_regs_val;
1049
1050extern struct adreno_gpudev adreno_a3xx_gpudev;
1051extern struct adreno_gpudev adreno_a4xx_gpudev;
1052extern struct adreno_gpudev adreno_a5xx_gpudev;
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -07001053extern struct adreno_gpudev adreno_a6xx_gpudev;
Shrenuj Bansala419c792016-10-20 14:05:11 -07001054
1055extern int adreno_wake_nice;
1056extern unsigned int adreno_wake_timeout;
1057
Shrenuj Bansald0fe7462017-05-08 16:11:19 -07001058int adreno_start(struct kgsl_device *device, int priority);
1059int adreno_soft_reset(struct kgsl_device *device);
Shrenuj Bansala419c792016-10-20 14:05:11 -07001060long adreno_ioctl(struct kgsl_device_private *dev_priv,
1061 unsigned int cmd, unsigned long arg);
1062
1063long adreno_ioctl_helper(struct kgsl_device_private *dev_priv,
1064 unsigned int cmd, unsigned long arg,
1065 const struct kgsl_ioctl *cmds, int len);
1066
Carter Cooper1d8f5472017-03-15 15:01:09 -06001067int a5xx_critical_packet_submit(struct adreno_device *adreno_dev,
1068 struct adreno_ringbuffer *rb);
1069int adreno_set_unsecured_mode(struct adreno_device *adreno_dev,
1070 struct adreno_ringbuffer *rb);
Carter Cooper8567af02017-03-15 14:22:03 -06001071void adreno_spin_idle_debug(struct adreno_device *adreno_dev, const char *str);
Shrenuj Bansala419c792016-10-20 14:05:11 -07001072int adreno_spin_idle(struct adreno_device *device, unsigned int timeout);
1073int adreno_idle(struct kgsl_device *device);
1074bool adreno_isidle(struct kgsl_device *device);
1075
1076int adreno_set_constraint(struct kgsl_device *device,
1077 struct kgsl_context *context,
1078 struct kgsl_device_constraint *constraint);
1079
1080void adreno_shadermem_regread(struct kgsl_device *device,
1081 unsigned int offsetwords,
1082 unsigned int *value);
1083
1084void adreno_snapshot(struct kgsl_device *device,
1085 struct kgsl_snapshot *snapshot,
1086 struct kgsl_context *context);
1087
Carter Cooperb88b7082017-09-14 09:03:26 -06001088void adreno_snapshot_gmu(struct kgsl_device *device,
1089 struct kgsl_snapshot *snapshot);
1090
Shrenuj Bansala419c792016-10-20 14:05:11 -07001091int adreno_reset(struct kgsl_device *device, int fault);
1092
1093void adreno_fault_skipcmd_detached(struct adreno_device *adreno_dev,
1094 struct adreno_context *drawctxt,
1095 struct kgsl_drawobj *drawobj);
1096
1097int adreno_coresight_init(struct adreno_device *adreno_dev);
1098
1099void adreno_coresight_start(struct adreno_device *adreno_dev);
1100void adreno_coresight_stop(struct adreno_device *adreno_dev);
1101
1102void adreno_coresight_remove(struct adreno_device *adreno_dev);
1103
1104bool adreno_hw_isidle(struct adreno_device *adreno_dev);
1105
1106void adreno_fault_detect_start(struct adreno_device *adreno_dev);
1107void adreno_fault_detect_stop(struct adreno_device *adreno_dev);
1108
1109void adreno_hang_int_callback(struct adreno_device *adreno_dev, int bit);
1110void adreno_cp_callback(struct adreno_device *adreno_dev, int bit);
1111
1112int adreno_sysfs_init(struct adreno_device *adreno_dev);
1113void adreno_sysfs_close(struct adreno_device *adreno_dev);
1114
1115void adreno_irqctrl(struct adreno_device *adreno_dev, int state);
1116
1117long adreno_ioctl_perfcounter_get(struct kgsl_device_private *dev_priv,
1118 unsigned int cmd, void *data);
1119
1120long adreno_ioctl_perfcounter_put(struct kgsl_device_private *dev_priv,
1121 unsigned int cmd, void *data);
1122
1123int adreno_efuse_map(struct adreno_device *adreno_dev);
1124int adreno_efuse_read_u32(struct adreno_device *adreno_dev, unsigned int offset,
1125 unsigned int *val);
1126void adreno_efuse_unmap(struct adreno_device *adreno_dev);
1127
Lynus Vaz9ed8cf92017-09-21 21:55:34 +05301128bool adreno_is_cx_dbgc_register(struct kgsl_device *device,
1129 unsigned int offset);
1130void adreno_cx_dbgc_regread(struct kgsl_device *adreno_device,
1131 unsigned int offsetwords, unsigned int *value);
1132void adreno_cx_dbgc_regwrite(struct kgsl_device *device,
1133 unsigned int offsetwords, unsigned int value);
1134
Shrenuj Bansala419c792016-10-20 14:05:11 -07001135#define ADRENO_TARGET(_name, _id) \
1136static inline int adreno_is_##_name(struct adreno_device *adreno_dev) \
1137{ \
1138 return (ADRENO_GPUREV(adreno_dev) == (_id)); \
1139}
1140
1141static inline int adreno_is_a3xx(struct adreno_device *adreno_dev)
1142{
1143 return ((ADRENO_GPUREV(adreno_dev) >= 300) &&
1144 (ADRENO_GPUREV(adreno_dev) < 400));
1145}
1146
1147ADRENO_TARGET(a304, ADRENO_REV_A304)
1148ADRENO_TARGET(a305, ADRENO_REV_A305)
1149ADRENO_TARGET(a305b, ADRENO_REV_A305B)
1150ADRENO_TARGET(a305c, ADRENO_REV_A305C)
1151ADRENO_TARGET(a306, ADRENO_REV_A306)
1152ADRENO_TARGET(a306a, ADRENO_REV_A306A)
1153ADRENO_TARGET(a310, ADRENO_REV_A310)
1154ADRENO_TARGET(a320, ADRENO_REV_A320)
1155ADRENO_TARGET(a330, ADRENO_REV_A330)
1156
1157static inline int adreno_is_a330v2(struct adreno_device *adreno_dev)
1158{
1159 return ((ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A330) &&
1160 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) > 0));
1161}
1162
1163static inline int adreno_is_a330v21(struct adreno_device *adreno_dev)
1164{
1165 return ((ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A330) &&
1166 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) > 0xF));
1167}
1168
1169static inline int adreno_is_a4xx(struct adreno_device *adreno_dev)
1170{
1171 return ADRENO_GPUREV(adreno_dev) >= 400 &&
1172 ADRENO_GPUREV(adreno_dev) < 500;
1173}
1174
1175ADRENO_TARGET(a405, ADRENO_REV_A405);
1176
1177static inline int adreno_is_a405v2(struct adreno_device *adreno_dev)
1178{
1179 return (ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A405) &&
1180 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) == 0x10);
1181}
1182
1183ADRENO_TARGET(a418, ADRENO_REV_A418)
1184ADRENO_TARGET(a420, ADRENO_REV_A420)
1185ADRENO_TARGET(a430, ADRENO_REV_A430)
1186
1187static inline int adreno_is_a430v2(struct adreno_device *adreno_dev)
1188{
1189 return ((ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A430) &&
1190 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) == 1));
1191}
1192
1193static inline int adreno_is_a5xx(struct adreno_device *adreno_dev)
1194{
1195 return ADRENO_GPUREV(adreno_dev) >= 500 &&
1196 ADRENO_GPUREV(adreno_dev) < 600;
1197}
1198
1199ADRENO_TARGET(a505, ADRENO_REV_A505)
1200ADRENO_TARGET(a506, ADRENO_REV_A506)
Rajesh Kemisettiaed6ec72017-02-06 09:37:00 +05301201ADRENO_TARGET(a508, ADRENO_REV_A508)
Shrenuj Bansala419c792016-10-20 14:05:11 -07001202ADRENO_TARGET(a510, ADRENO_REV_A510)
1203ADRENO_TARGET(a512, ADRENO_REV_A512)
1204ADRENO_TARGET(a530, ADRENO_REV_A530)
1205ADRENO_TARGET(a540, ADRENO_REV_A540)
1206
1207static inline int adreno_is_a530v1(struct adreno_device *adreno_dev)
1208{
1209 return (ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A530) &&
1210 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) == 0);
1211}
1212
1213static inline int adreno_is_a530v2(struct adreno_device *adreno_dev)
1214{
1215 return (ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A530) &&
1216 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) == 1);
1217}
1218
1219static inline int adreno_is_a530v3(struct adreno_device *adreno_dev)
1220{
1221 return (ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A530) &&
1222 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) == 2);
1223}
1224
1225static inline int adreno_is_a505_or_a506(struct adreno_device *adreno_dev)
1226{
1227 return ADRENO_GPUREV(adreno_dev) >= 505 &&
1228 ADRENO_GPUREV(adreno_dev) <= 506;
1229}
1230
1231static inline int adreno_is_a540v1(struct adreno_device *adreno_dev)
1232{
1233 return (ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A540) &&
1234 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) == 0);
1235}
1236
1237static inline int adreno_is_a540v2(struct adreno_device *adreno_dev)
1238{
1239 return (ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A540) &&
1240 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) == 1);
1241}
1242
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -07001243static inline int adreno_is_a6xx(struct adreno_device *adreno_dev)
1244{
1245 return ADRENO_GPUREV(adreno_dev) >= 600 &&
1246 ADRENO_GPUREV(adreno_dev) < 700;
1247}
1248
Rajesh Kemisetti8d5cc6e2017-06-06 16:44:17 +05301249ADRENO_TARGET(a615, ADRENO_REV_A615)
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -07001250ADRENO_TARGET(a630, ADRENO_REV_A630)
1251
Shrenuj Bansal397e5892017-03-13 13:38:47 -07001252static inline int adreno_is_a630v1(struct adreno_device *adreno_dev)
1253{
1254 return (ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A630) &&
1255 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) == 0);
1256}
1257
Kyle Piefer240295972017-08-10 11:38:00 -07001258static inline int adreno_is_a630v2(struct adreno_device *adreno_dev)
1259{
1260 return (ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A630) &&
1261 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) == 1);
1262}
1263
Shrenuj Bansala419c792016-10-20 14:05:11 -07001264/*
1265 * adreno_checkreg_off() - Checks the validity of a register enum
1266 * @adreno_dev: Pointer to adreno device
1267 * @offset_name: The register enum that is checked
1268 */
1269static inline bool adreno_checkreg_off(struct adreno_device *adreno_dev,
1270 enum adreno_regs offset_name)
1271{
1272 struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
1273
1274 if (offset_name >= ADRENO_REG_REGISTER_MAX ||
1275 gpudev->reg_offsets->offsets[offset_name] == ADRENO_REG_UNUSED)
1276 return false;
1277
1278 /*
1279 * GPU register programming is kept common as much as possible
1280 * across the cores, Use ADRENO_REG_SKIP when certain register
1281 * programming needs to be skipped for certain GPU cores.
1282 * Example: Certain registers on a5xx like IB1_BASE are 64 bit.
1283 * Common programming programs 64bit register but upper 32 bits
1284 * are skipped in a4xx and a3xx using ADRENO_REG_SKIP.
1285 */
1286 if (gpudev->reg_offsets->offsets[offset_name] == ADRENO_REG_SKIP)
1287 return false;
1288
1289 return true;
1290}
1291
1292/*
1293 * adreno_readreg() - Read a register by getting its offset from the
1294 * offset array defined in gpudev node
1295 * @adreno_dev: Pointer to the the adreno device
1296 * @offset_name: The register enum that is to be read
1297 * @val: Register value read is placed here
1298 */
1299static inline void adreno_readreg(struct adreno_device *adreno_dev,
1300 enum adreno_regs offset_name, unsigned int *val)
1301{
1302 struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
1303
1304 if (adreno_checkreg_off(adreno_dev, offset_name))
1305 kgsl_regread(KGSL_DEVICE(adreno_dev),
1306 gpudev->reg_offsets->offsets[offset_name], val);
1307 else
1308 *val = 0;
1309}
1310
1311/*
1312 * adreno_writereg() - Write a register by getting its offset from the
1313 * offset array defined in gpudev node
1314 * @adreno_dev: Pointer to the the adreno device
1315 * @offset_name: The register enum that is to be written
1316 * @val: Value to write
1317 */
1318static inline void adreno_writereg(struct adreno_device *adreno_dev,
1319 enum adreno_regs offset_name, unsigned int val)
1320{
1321 struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
1322
1323 if (adreno_checkreg_off(adreno_dev, offset_name))
1324 kgsl_regwrite(KGSL_DEVICE(adreno_dev),
1325 gpudev->reg_offsets->offsets[offset_name], val);
1326}
1327
1328/*
1329 * adreno_getreg() - Returns the offset value of a register from the
1330 * register offset array in the gpudev node
1331 * @adreno_dev: Pointer to the the adreno device
1332 * @offset_name: The register enum whore offset is returned
1333 */
1334static inline unsigned int adreno_getreg(struct adreno_device *adreno_dev,
1335 enum adreno_regs offset_name)
1336{
1337 struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
1338
1339 if (!adreno_checkreg_off(adreno_dev, offset_name))
1340 return ADRENO_REG_REGISTER_MAX;
1341 return gpudev->reg_offsets->offsets[offset_name];
1342}
1343
1344/*
Kyle Pieferb1027b02017-02-10 13:58:58 -08001345 * adreno_read_gmureg() - Read a GMU register by getting its offset from the
1346 * offset array defined in gpudev node
1347 * @adreno_dev: Pointer to the the adreno device
1348 * @offset_name: The register enum that is to be read
1349 * @val: Register value read is placed here
1350 */
1351static inline void adreno_read_gmureg(struct adreno_device *adreno_dev,
1352 enum adreno_regs offset_name, unsigned int *val)
1353{
1354 struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
1355
1356 if (adreno_checkreg_off(adreno_dev, offset_name))
1357 kgsl_gmu_regread(KGSL_DEVICE(adreno_dev),
1358 gpudev->reg_offsets->offsets[offset_name], val);
1359 else
Carter Cooper83454bf2017-03-20 11:26:04 -06001360 *val = 0;
Kyle Pieferb1027b02017-02-10 13:58:58 -08001361}
1362
1363/*
1364 * adreno_write_gmureg() - Write a GMU register by getting its offset from the
1365 * offset array defined in gpudev node
1366 * @adreno_dev: Pointer to the the adreno device
1367 * @offset_name: The register enum that is to be written
1368 * @val: Value to write
1369 */
1370static inline void adreno_write_gmureg(struct adreno_device *adreno_dev,
1371 enum adreno_regs offset_name, unsigned int val)
1372{
1373 struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
1374
1375 if (adreno_checkreg_off(adreno_dev, offset_name))
1376 kgsl_gmu_regwrite(KGSL_DEVICE(adreno_dev),
1377 gpudev->reg_offsets->offsets[offset_name], val);
1378}
1379
1380/*
Shrenuj Bansala419c792016-10-20 14:05:11 -07001381 * adreno_get_int() - Returns the offset value of an interrupt bit from
1382 * the interrupt bit array in the gpudev node
1383 * @adreno_dev: Pointer to the the adreno device
1384 * @bit_name: The interrupt bit enum whose bit is returned
1385 */
1386static inline unsigned int adreno_get_int(struct adreno_device *adreno_dev,
1387 enum adreno_int_bits bit_name)
1388{
1389 struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
1390
1391 if (bit_name >= ADRENO_INT_BITS_MAX)
1392 return -ERANGE;
1393
1394 return gpudev->int_bits[bit_name];
1395}
1396
1397/**
1398 * adreno_gpu_fault() - Return the current state of the GPU
1399 * @adreno_dev: A pointer to the adreno_device to query
1400 *
1401 * Return 0 if there is no fault or positive with the last type of fault that
1402 * occurred
1403 */
1404static inline unsigned int adreno_gpu_fault(struct adreno_device *adreno_dev)
1405{
1406 /* make sure we're reading the latest value */
1407 smp_rmb();
1408 return atomic_read(&adreno_dev->dispatcher.fault);
1409}
1410
1411/**
1412 * adreno_set_gpu_fault() - Set the current fault status of the GPU
1413 * @adreno_dev: A pointer to the adreno_device to set
1414 * @state: fault state to set
1415 *
1416 */
1417static inline void adreno_set_gpu_fault(struct adreno_device *adreno_dev,
1418 int state)
1419{
1420 /* only set the fault bit w/o overwriting other bits */
1421 atomic_add(state, &adreno_dev->dispatcher.fault);
1422
1423 /* make sure other CPUs see the update */
1424 smp_wmb();
1425}
1426
Lynus Vaz43695aa2017-09-01 21:55:23 +05301427static inline bool adreno_gmu_gpu_fault(struct adreno_device *adreno_dev)
1428{
1429 return adreno_gpu_fault(adreno_dev) & ADRENO_GMU_FAULT;
1430}
Shrenuj Bansala419c792016-10-20 14:05:11 -07001431
1432/**
1433 * adreno_clear_gpu_fault() - Clear the GPU fault register
1434 * @adreno_dev: A pointer to an adreno_device structure
1435 *
1436 * Clear the GPU fault status for the adreno device
1437 */
1438
1439static inline void adreno_clear_gpu_fault(struct adreno_device *adreno_dev)
1440{
1441 atomic_set(&adreno_dev->dispatcher.fault, 0);
1442
1443 /* make sure other CPUs see the update */
1444 smp_wmb();
1445}
1446
1447/**
1448 * adreno_gpu_halt() - Return the GPU halt refcount
1449 * @adreno_dev: A pointer to the adreno_device
1450 */
1451static inline int adreno_gpu_halt(struct adreno_device *adreno_dev)
1452{
1453 /* make sure we're reading the latest value */
1454 smp_rmb();
1455 return atomic_read(&adreno_dev->halt);
1456}
1457
1458
1459/**
1460 * adreno_clear_gpu_halt() - Clear the GPU halt refcount
1461 * @adreno_dev: A pointer to the adreno_device
1462 */
1463static inline void adreno_clear_gpu_halt(struct adreno_device *adreno_dev)
1464{
1465 atomic_set(&adreno_dev->halt, 0);
1466
1467 /* make sure other CPUs see the update */
1468 smp_wmb();
1469}
1470
1471/**
1472 * adreno_get_gpu_halt() - Increment GPU halt refcount
1473 * @adreno_dev: A pointer to the adreno_device
1474 */
1475static inline void adreno_get_gpu_halt(struct adreno_device *adreno_dev)
1476{
1477 atomic_inc(&adreno_dev->halt);
1478}
1479
1480/**
1481 * adreno_put_gpu_halt() - Decrement GPU halt refcount
1482 * @adreno_dev: A pointer to the adreno_device
1483 */
1484static inline void adreno_put_gpu_halt(struct adreno_device *adreno_dev)
1485{
1486 /* Make sure the refcount is good */
1487 int ret = atomic_dec_if_positive(&adreno_dev->halt);
1488
1489 WARN(ret < 0, "GPU halt refcount unbalanced\n");
1490}
1491
1492
1493/*
1494 * adreno_vbif_start() - Program VBIF registers, called in device start
1495 * @adreno_dev: Pointer to device whose vbif data is to be programmed
1496 * @vbif_platforms: list register value pair of vbif for a family
1497 * of adreno cores
1498 * @num_platforms: Number of platforms contained in vbif_platforms
1499 */
1500static inline void adreno_vbif_start(struct adreno_device *adreno_dev,
1501 const struct adreno_vbif_platform *vbif_platforms,
1502 int num_platforms)
1503{
1504 int i;
1505 const struct adreno_vbif_data *vbif = NULL;
1506
1507 for (i = 0; i < num_platforms; i++) {
1508 if (vbif_platforms[i].devfunc(adreno_dev)) {
1509 vbif = vbif_platforms[i].vbif;
1510 break;
1511 }
1512 }
1513
1514 while ((vbif != NULL) && (vbif->reg != 0)) {
1515 kgsl_regwrite(KGSL_DEVICE(adreno_dev), vbif->reg, vbif->val);
1516 vbif++;
1517 }
1518}
1519
1520/**
1521 * adreno_set_protected_registers() - Protect the specified range of registers
1522 * from being accessed by the GPU
1523 * @adreno_dev: pointer to the Adreno device
1524 * @index: Pointer to the index of the protect mode register to write to
1525 * @reg: Starting dword register to write
1526 * @mask_len: Size of the mask to protect (# of registers = 2 ** mask_len)
1527 *
1528 * Add the range of registers to the list of protected mode registers that will
1529 * cause an exception if the GPU accesses them. There are 16 available
1530 * protected mode registers. Index is used to specify which register to write
1531 * to - the intent is to call this function multiple times with the same index
1532 * pointer for each range and the registers will be magically programmed in
1533 * incremental fashion
1534 */
1535static inline void adreno_set_protected_registers(
1536 struct adreno_device *adreno_dev, unsigned int *index,
1537 unsigned int reg, int mask_len)
1538{
1539 unsigned int val;
1540 unsigned int base =
1541 adreno_getreg(adreno_dev, ADRENO_REG_CP_PROTECT_REG_0);
1542 unsigned int offset = *index;
1543 unsigned int max_slots = adreno_dev->gpucore->num_protected_regs ?
1544 adreno_dev->gpucore->num_protected_regs : 16;
1545
1546 /* Do we have a free slot? */
1547 if (WARN(*index >= max_slots, "Protected register slots full: %d/%d\n",
1548 *index, max_slots))
1549 return;
1550
1551 /*
1552 * On A4XX targets with more than 16 protected mode registers
1553 * the upper registers are not contiguous with the lower 16
1554 * registers so we have to adjust the base and offset accordingly
1555 */
1556
1557 if (adreno_is_a4xx(adreno_dev) && *index >= 0x10) {
1558 base = A4XX_CP_PROTECT_REG_10;
1559 offset = *index - 0x10;
1560 }
1561
1562 val = 0x60000000 | ((mask_len & 0x1F) << 24) | ((reg << 2) & 0xFFFFF);
1563
1564 kgsl_regwrite(KGSL_DEVICE(adreno_dev), base + offset, val);
1565 *index = *index + 1;
1566}
1567
1568#ifdef CONFIG_DEBUG_FS
1569void adreno_debugfs_init(struct adreno_device *adreno_dev);
1570void adreno_context_debugfs_init(struct adreno_device *adreno_dev,
1571 struct adreno_context *ctx);
1572#else
1573static inline void adreno_debugfs_init(struct adreno_device *adreno_dev) { }
1574static inline void adreno_context_debugfs_init(struct adreno_device *device,
1575 struct adreno_context *context)
1576 { }
1577#endif
1578
1579/**
1580 * adreno_compare_pm4_version() - Compare the PM4 microcode version
1581 * @adreno_dev: Pointer to the adreno_device struct
1582 * @version: Version number to compare again
1583 *
1584 * Compare the current version against the specified version and return -1 if
1585 * the current code is older, 0 if equal or 1 if newer.
1586 */
1587static inline int adreno_compare_pm4_version(struct adreno_device *adreno_dev,
1588 unsigned int version)
1589{
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -07001590 if (adreno_dev->fw[ADRENO_FW_PM4].version == version)
Shrenuj Bansala419c792016-10-20 14:05:11 -07001591 return 0;
1592
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -07001593 return (adreno_dev->fw[ADRENO_FW_PM4].version > version) ? 1 : -1;
Shrenuj Bansala419c792016-10-20 14:05:11 -07001594}
1595
1596/**
1597 * adreno_compare_pfp_version() - Compare the PFP microcode version
1598 * @adreno_dev: Pointer to the adreno_device struct
1599 * @version: Version number to compare against
1600 *
1601 * Compare the current version against the specified version and return -1 if
1602 * the current code is older, 0 if equal or 1 if newer.
1603 */
1604static inline int adreno_compare_pfp_version(struct adreno_device *adreno_dev,
1605 unsigned int version)
1606{
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -07001607 if (adreno_dev->fw[ADRENO_FW_PFP].version == version)
Shrenuj Bansala419c792016-10-20 14:05:11 -07001608 return 0;
1609
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -07001610 return (adreno_dev->fw[ADRENO_FW_PFP].version > version) ? 1 : -1;
Shrenuj Bansala419c792016-10-20 14:05:11 -07001611}
1612
1613/*
1614 * adreno_bootstrap_ucode() - Checks if Ucode bootstrapping is supported
1615 * @adreno_dev: Pointer to the the adreno device
1616 */
1617static inline int adreno_bootstrap_ucode(struct adreno_device *adreno_dev)
1618{
1619 return (ADRENO_FEATURE(adreno_dev, ADRENO_USE_BOOTSTRAP) &&
1620 adreno_compare_pfp_version(adreno_dev,
1621 adreno_dev->gpucore->pfp_bstrp_ver) >= 0) ? 1 : 0;
1622}
1623
1624/**
1625 * adreno_in_preempt_state() - Check if preemption state is equal to given state
1626 * @adreno_dev: Device whose preemption state is checked
1627 * @state: State to compare against
1628 */
1629static inline bool adreno_in_preempt_state(struct adreno_device *adreno_dev,
1630 enum adreno_preempt_states state)
1631{
1632 return atomic_read(&adreno_dev->preempt.state) == state;
1633}
1634/**
1635 * adreno_set_preempt_state() - Set the specified preemption state
1636 * @adreno_dev: Device to change preemption state
1637 * @state: State to set
1638 */
1639static inline void adreno_set_preempt_state(struct adreno_device *adreno_dev,
1640 enum adreno_preempt_states state)
1641{
1642 /*
1643 * atomic_set doesn't use barriers, so we need to do it ourselves. One
1644 * before...
1645 */
1646 smp_wmb();
1647 atomic_set(&adreno_dev->preempt.state, state);
1648
1649 /* ... and one after */
1650 smp_wmb();
1651}
1652
Harshdeep Dhatt38e57d72017-08-30 13:24:07 -06001653static inline bool adreno_is_preemption_enabled(
1654 struct adreno_device *adreno_dev)
1655{
Harshdeep Dhatt7ee8a862017-11-20 17:51:54 -07001656 return test_bit(ADRENO_DEVICE_PREEMPTION, &adreno_dev->priv);
Harshdeep Dhatt38e57d72017-08-30 13:24:07 -06001657}
Shrenuj Bansala419c792016-10-20 14:05:11 -07001658/**
1659 * adreno_ctx_get_rb() - Return the ringbuffer that a context should
1660 * use based on priority
1661 * @adreno_dev: The adreno device that context is using
1662 * @drawctxt: The context pointer
1663 */
1664static inline struct adreno_ringbuffer *adreno_ctx_get_rb(
1665 struct adreno_device *adreno_dev,
1666 struct adreno_context *drawctxt)
1667{
1668 struct kgsl_context *context;
1669 int level;
1670
1671 if (!drawctxt)
1672 return NULL;
1673
1674 context = &(drawctxt->base);
1675
1676 /*
1677 * If preemption is disabled then everybody needs to go on the same
1678 * ringbuffer
1679 */
1680
Harshdeep Dhatt7ee8a862017-11-20 17:51:54 -07001681 if (!adreno_is_preemption_enabled(adreno_dev))
Shrenuj Bansala419c792016-10-20 14:05:11 -07001682 return &(adreno_dev->ringbuffers[0]);
1683
1684 /*
1685 * Math to convert the priority field in context structure to an RB ID.
1686 * Divide up the context priority based on number of ringbuffer levels.
1687 */
1688 level = context->priority / adreno_dev->num_ringbuffers;
1689 if (level < adreno_dev->num_ringbuffers)
1690 return &(adreno_dev->ringbuffers[level]);
1691 else
1692 return &(adreno_dev->ringbuffers[
1693 adreno_dev->num_ringbuffers - 1]);
1694}
1695
1696/*
1697 * adreno_compare_prio_level() - Compares 2 priority levels based on enum values
1698 * @p1: First priority level
1699 * @p2: Second priority level
1700 *
1701 * Returns greater than 0 if p1 is higher priority, 0 if levels are equal else
1702 * less than 0
1703 */
1704static inline int adreno_compare_prio_level(int p1, int p2)
1705{
1706 return p2 - p1;
1707}
1708
1709void adreno_readreg64(struct adreno_device *adreno_dev,
1710 enum adreno_regs lo, enum adreno_regs hi, uint64_t *val);
1711
1712void adreno_writereg64(struct adreno_device *adreno_dev,
1713 enum adreno_regs lo, enum adreno_regs hi, uint64_t val);
1714
1715unsigned int adreno_get_rptr(struct adreno_ringbuffer *rb);
1716
1717static inline bool adreno_rb_empty(struct adreno_ringbuffer *rb)
1718{
1719 return (adreno_get_rptr(rb) == rb->wptr);
1720}
1721
1722static inline bool adreno_soft_fault_detect(struct adreno_device *adreno_dev)
1723{
1724 return adreno_dev->fast_hang_detect &&
1725 !test_bit(ADRENO_DEVICE_ISDB_ENABLED, &adreno_dev->priv);
1726}
1727
1728static inline bool adreno_long_ib_detect(struct adreno_device *adreno_dev)
1729{
1730 return adreno_dev->long_ib_detect &&
1731 !test_bit(ADRENO_DEVICE_ISDB_ENABLED, &adreno_dev->priv);
1732}
1733
1734/*
1735 * adreno_support_64bit() - Check the feature flag only if it is in
1736 * 64bit kernel otherwise return false
1737 * adreno_dev: The adreno device
1738 */
1739#if BITS_PER_LONG == 64
1740static inline bool adreno_support_64bit(struct adreno_device *adreno_dev)
1741{
1742 return ADRENO_FEATURE(adreno_dev, ADRENO_64BIT);
1743}
1744#else
1745static inline bool adreno_support_64bit(struct adreno_device *adreno_dev)
1746{
1747 return false;
1748}
1749#endif /*BITS_PER_LONG*/
1750
1751static inline void adreno_ringbuffer_set_global(
1752 struct adreno_device *adreno_dev, int name)
1753{
1754 struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
1755
1756 kgsl_sharedmem_writel(device,
1757 &adreno_dev->ringbuffers[0].pagetable_desc,
1758 PT_INFO_OFFSET(current_global_ptname), name);
1759}
1760
1761static inline void adreno_ringbuffer_set_pagetable(struct adreno_ringbuffer *rb,
1762 struct kgsl_pagetable *pt)
1763{
1764 struct adreno_device *adreno_dev = ADRENO_RB_DEVICE(rb);
1765 struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
1766 unsigned long flags;
1767
1768 spin_lock_irqsave(&rb->preempt_lock, flags);
1769
1770 kgsl_sharedmem_writel(device, &rb->pagetable_desc,
1771 PT_INFO_OFFSET(current_rb_ptname), pt->name);
1772
1773 kgsl_sharedmem_writeq(device, &rb->pagetable_desc,
1774 PT_INFO_OFFSET(ttbr0), kgsl_mmu_pagetable_get_ttbr0(pt));
1775
1776 kgsl_sharedmem_writel(device, &rb->pagetable_desc,
1777 PT_INFO_OFFSET(contextidr),
1778 kgsl_mmu_pagetable_get_contextidr(pt));
1779
1780 spin_unlock_irqrestore(&rb->preempt_lock, flags);
1781}
1782
Abhilash Kumarf1af1042017-07-14 13:13:44 +05301783static inline bool is_power_counter_overflow(struct adreno_device *adreno_dev,
1784 unsigned int reg, unsigned int prev_val, unsigned int *perfctr_pwr_hi)
1785{
1786 unsigned int val;
1787 bool ret = false;
1788
1789 /*
1790 * If prev_val is zero, it is first read after perf counter reset.
1791 * So set perfctr_pwr_hi register to zero.
1792 */
1793 if (prev_val == 0) {
1794 *perfctr_pwr_hi = 0;
1795 return ret;
1796 }
1797 adreno_readreg(adreno_dev, ADRENO_REG_RBBM_PERFCTR_RBBM_0_HI, &val);
1798 if (val != *perfctr_pwr_hi) {
1799 *perfctr_pwr_hi = val;
1800 ret = true;
1801 }
1802 return ret;
1803}
1804
Shrenuj Bansala419c792016-10-20 14:05:11 -07001805static inline unsigned int counter_delta(struct kgsl_device *device,
1806 unsigned int reg, unsigned int *counter)
1807{
Abhilash Kumarf1af1042017-07-14 13:13:44 +05301808 struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
Shrenuj Bansala419c792016-10-20 14:05:11 -07001809 unsigned int val;
1810 unsigned int ret = 0;
Abhilash Kumarf1af1042017-07-14 13:13:44 +05301811 bool overflow = true;
1812 static unsigned int perfctr_pwr_hi;
Shrenuj Bansala419c792016-10-20 14:05:11 -07001813
1814 /* Read the value */
1815 kgsl_regread(device, reg, &val);
1816
Abhilash Kumarf1af1042017-07-14 13:13:44 +05301817 if (adreno_is_a5xx(adreno_dev) && reg == adreno_getreg
1818 (adreno_dev, ADRENO_REG_RBBM_PERFCTR_RBBM_0_LO))
1819 overflow = is_power_counter_overflow(adreno_dev, reg,
1820 *counter, &perfctr_pwr_hi);
1821
Shrenuj Bansala419c792016-10-20 14:05:11 -07001822 /* Return 0 for the first read */
1823 if (*counter != 0) {
Abhilash Kumarf1af1042017-07-14 13:13:44 +05301824 if (val >= *counter) {
Shrenuj Bansala419c792016-10-20 14:05:11 -07001825 ret = val - *counter;
Abhilash Kumarf1af1042017-07-14 13:13:44 +05301826 } else if (overflow == true) {
1827 ret = (0xFFFFFFFF - *counter) + val;
1828 } else {
1829 /*
1830 * Since KGSL got abnormal value from the counter,
1831 * We will drop the value from being accumulated.
1832 */
1833 pr_warn_once("KGSL: Abnormal value :0x%x (0x%x) from perf counter : 0x%x\n",
1834 val, *counter, reg);
1835 return 0;
1836 }
Shrenuj Bansala419c792016-10-20 14:05:11 -07001837 }
1838
1839 *counter = val;
1840 return ret;
1841}
Carter Cooper05f2a6b2017-03-20 11:43:11 -06001842
1843static inline int adreno_perfcntr_active_oob_get(
1844 struct adreno_device *adreno_dev)
1845{
1846 struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
1847 int ret;
1848
1849 ret = kgsl_active_count_get(KGSL_DEVICE(adreno_dev));
1850 if (ret)
1851 return ret;
1852
1853 if (gpudev->oob_set) {
1854 ret = gpudev->oob_set(adreno_dev, OOB_PERFCNTR_SET_MASK,
1855 OOB_PERFCNTR_CHECK_MASK,
1856 OOB_PERFCNTR_CLEAR_MASK);
1857 if (ret)
1858 kgsl_active_count_put(KGSL_DEVICE(adreno_dev));
1859 }
1860
1861 return ret;
1862}
1863
1864static inline void adreno_perfcntr_active_oob_put(
1865 struct adreno_device *adreno_dev)
1866{
1867 struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
1868
1869 if (gpudev->oob_clear)
1870 gpudev->oob_clear(adreno_dev, OOB_PERFCNTR_CLEAR_MASK);
1871
1872 kgsl_active_count_put(KGSL_DEVICE(adreno_dev));
1873}
1874
Rajesh Kemisetti77b82ed2017-09-24 20:42:41 +05301875static inline bool adreno_has_gbif(struct adreno_device *adreno_dev)
1876{
1877 if (adreno_is_a615(adreno_dev))
1878 return true;
1879 else
1880 return false;
1881}
1882
1883/**
1884 * adreno_wait_for_vbif_halt_ack() - wait for VBIF acknowledgment
1885 * for given HALT request.
1886 * @ack_reg: register offset to wait for acknowledge
1887 */
1888static inline int adreno_wait_for_vbif_halt_ack(struct kgsl_device *device,
Rajesh Kemisettid1ca9542017-10-18 15:35:41 +05301889 int ack_reg, unsigned int mask)
Rajesh Kemisetti77b82ed2017-09-24 20:42:41 +05301890{
1891 struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
Rajesh Kemisetti77b82ed2017-09-24 20:42:41 +05301892 unsigned long wait_for_vbif;
Rajesh Kemisetti77b82ed2017-09-24 20:42:41 +05301893 unsigned int val;
1894 int ret = 0;
1895
1896 /* wait for the transactions to clear */
Rajesh Kemisettid1ca9542017-10-18 15:35:41 +05301897 wait_for_vbif = jiffies + msecs_to_jiffies(VBIF_RESET_ACK_TIMEOUT);
Rajesh Kemisetti77b82ed2017-09-24 20:42:41 +05301898 while (1) {
1899 adreno_readreg(adreno_dev, ack_reg,
1900 &val);
1901 if ((val & mask) == mask)
1902 break;
1903 if (time_after(jiffies, wait_for_vbif)) {
1904 KGSL_DRV_ERR(device,
1905 "Wait limit reached for VBIF XIN Halt\n");
1906 ret = -ETIMEDOUT;
1907 break;
1908 }
1909 }
1910
1911 return ret;
1912}
1913
Kyle Piefere923b7a2017-03-28 17:31:48 -07001914/**
1915 * adreno_vbif_clear_pending_transactions() - Clear transactions in VBIF pipe
1916 * @device: Pointer to the device whose VBIF pipe is to be cleared
1917 */
1918static inline int adreno_vbif_clear_pending_transactions(
1919 struct kgsl_device *device)
1920{
1921 struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
1922 struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
1923 unsigned int mask = gpudev->vbif_xin_halt_ctrl0_mask;
Kyle Piefere923b7a2017-03-28 17:31:48 -07001924 int ret = 0;
1925
Rajesh Kemisetti77b82ed2017-09-24 20:42:41 +05301926 if (adreno_has_gbif(adreno_dev)) {
Rajesh Kemisettid1ca9542017-10-18 15:35:41 +05301927 /*
1928 * Halt GBIF GX first and then CX part.
1929 * Need to release CX Halt explicitly in case of SW_RESET.
1930 * GX Halt release will be taken care by SW_RESET internally.
1931 */
Deepak Kumar7e39bf62017-12-28 16:29:27 +05301932 if (gpudev->gx_is_on(adreno_dev)) {
1933 adreno_writereg(adreno_dev, ADRENO_REG_RBBM_GPR0_CNTL,
1934 GBIF_HALT_REQUEST);
1935 ret = adreno_wait_for_vbif_halt_ack(device,
1936 ADRENO_REG_RBBM_VBIF_GX_RESET_STATUS,
1937 VBIF_RESET_ACK_MASK);
1938 if (ret)
1939 return ret;
1940 }
Rajesh Kemisettid1ca9542017-10-18 15:35:41 +05301941
Rajesh Kemisetti77b82ed2017-09-24 20:42:41 +05301942 adreno_writereg(adreno_dev, ADRENO_REG_GBIF_HALT, mask);
1943 ret = adreno_wait_for_vbif_halt_ack(device,
Rajesh Kemisettid1ca9542017-10-18 15:35:41 +05301944 ADRENO_REG_GBIF_HALT_ACK, mask);
Rajesh Kemisetti77b82ed2017-09-24 20:42:41 +05301945 } else {
1946 adreno_writereg(adreno_dev, ADRENO_REG_VBIF_XIN_HALT_CTRL0,
1947 mask);
1948 ret = adreno_wait_for_vbif_halt_ack(device,
Rajesh Kemisettid1ca9542017-10-18 15:35:41 +05301949 ADRENO_REG_VBIF_XIN_HALT_CTRL1, mask);
Rajesh Kemisetti77b82ed2017-09-24 20:42:41 +05301950 adreno_writereg(adreno_dev, ADRENO_REG_VBIF_XIN_HALT_CTRL0, 0);
Kyle Piefere923b7a2017-03-28 17:31:48 -07001951 }
Kyle Piefere923b7a2017-03-28 17:31:48 -07001952 return ret;
1953}
1954
Harshdeep Dhatt56107782017-12-05 09:54:47 -07001955int adreno_gmu_fenced_write(struct adreno_device *adreno_dev,
Harshdeep Dhatt8f78d5f2017-11-01 14:24:36 -06001956 enum adreno_regs offset, unsigned int val,
1957 unsigned int fence_mask);
Shrenuj Bansala419c792016-10-20 14:05:11 -07001958#endif /*__ADRENO_H */