blob: 4fb00898bfd56d3899e82d38177762d4292fdae0 [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>
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
Harshdeep Dhatte8046962017-11-10 15:45:24 -0700178/* Number of times to see if INT_0_STATUS changed or not */
179#define STATUS_RETRY_MAX 3
180
Shrenuj Bansala419c792016-10-20 14:05:11 -0700181/* One cannot wait forever for the core to idle, so set an upper limit to the
182 * amount of time to wait for the core to go idle
183 */
Shrenuj Bansala419c792016-10-20 14:05:11 -0700184#define ADRENO_IDLE_TIMEOUT (20 * 1000)
185
186#define ADRENO_UCHE_GMEM_BASE 0x100000
187
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -0700188#define ADRENO_FW_PFP 0
189#define ADRENO_FW_SQE 0
190#define ADRENO_FW_PM4 1
191
Shrenuj Bansala419c792016-10-20 14:05:11 -0700192enum adreno_gpurev {
193 ADRENO_REV_UNKNOWN = 0,
194 ADRENO_REV_A304 = 304,
195 ADRENO_REV_A305 = 305,
196 ADRENO_REV_A305C = 306,
197 ADRENO_REV_A306 = 307,
198 ADRENO_REV_A306A = 308,
199 ADRENO_REV_A310 = 310,
200 ADRENO_REV_A320 = 320,
201 ADRENO_REV_A330 = 330,
202 ADRENO_REV_A305B = 335,
203 ADRENO_REV_A405 = 405,
204 ADRENO_REV_A418 = 418,
205 ADRENO_REV_A420 = 420,
206 ADRENO_REV_A430 = 430,
207 ADRENO_REV_A505 = 505,
208 ADRENO_REV_A506 = 506,
Rajesh Kemisettiaed6ec72017-02-06 09:37:00 +0530209 ADRENO_REV_A508 = 508,
Shrenuj Bansala419c792016-10-20 14:05:11 -0700210 ADRENO_REV_A510 = 510,
211 ADRENO_REV_A512 = 512,
212 ADRENO_REV_A530 = 530,
213 ADRENO_REV_A540 = 540,
Rajesh Kemisetti8d5cc6e2017-06-06 16:44:17 +0530214 ADRENO_REV_A615 = 615,
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -0700215 ADRENO_REV_A630 = 630,
Shrenuj Bansala419c792016-10-20 14:05:11 -0700216};
217
218#define ADRENO_START_WARM 0
219#define ADRENO_START_COLD 1
220
221#define ADRENO_SOFT_FAULT BIT(0)
222#define ADRENO_HARD_FAULT BIT(1)
223#define ADRENO_TIMEOUT_FAULT BIT(2)
224#define ADRENO_IOMMU_PAGE_FAULT BIT(3)
225#define ADRENO_PREEMPT_FAULT BIT(4)
Shrenuj Bansald0fe7462017-05-08 16:11:19 -0700226#define ADRENO_GMU_FAULT BIT(5)
Hareesh Gundu28b9efd2017-08-24 23:11:09 +0530227#define ADRENO_CTX_DETATCH_TIMEOUT_FAULT BIT(6)
Shrenuj Bansala419c792016-10-20 14:05:11 -0700228
229#define ADRENO_SPTP_PC_CTRL 0
230#define ADRENO_PPD_CTRL 1
231#define ADRENO_LM_CTRL 2
232#define ADRENO_HWCG_CTRL 3
233#define ADRENO_THROTTLING_CTRL 4
234
Rajesh Kemisettid1ca9542017-10-18 15:35:41 +0530235/* VBIF, GBIF halt request and ack mask */
236#define GBIF_HALT_REQUEST 0x1E0
237#define VBIF_RESET_ACK_MASK 0x00f0
238#define VBIF_RESET_ACK_TIMEOUT 100
Shrenuj Bansala419c792016-10-20 14:05:11 -0700239
240/* number of throttle counters for DCVS adjustment */
241#define ADRENO_GPMU_THROTTLE_COUNTERS 4
242/* base for throttle counters */
243#define ADRENO_GPMU_THROTTLE_COUNTERS_BASE_REG 43
244
245struct adreno_gpudev;
246
247/* Time to allow preemption to complete (in ms) */
248#define ADRENO_PREEMPT_TIMEOUT 10000
249
250#define ADRENO_INT_BIT(a, _bit) (((a)->gpucore->gpudev->int_bits) ? \
251 (adreno_get_int(a, _bit) < 0 ? 0 : \
252 BIT(adreno_get_int(a, _bit))) : 0)
253
254/**
255 * enum adreno_preempt_states
256 * ADRENO_PREEMPT_NONE: No preemption is scheduled
257 * ADRENO_PREEMPT_START: The S/W has started
258 * ADRENO_PREEMPT_TRIGGERED: A preeempt has been triggered in the HW
259 * ADRENO_PREEMPT_FAULTED: The preempt timer has fired
260 * ADRENO_PREEMPT_PENDING: The H/W has signaled preemption complete
261 * ADRENO_PREEMPT_COMPLETE: Preemption could not be finished in the IRQ handler,
262 * worker has been scheduled
263 */
264enum adreno_preempt_states {
265 ADRENO_PREEMPT_NONE = 0,
266 ADRENO_PREEMPT_START,
267 ADRENO_PREEMPT_TRIGGERED,
268 ADRENO_PREEMPT_FAULTED,
269 ADRENO_PREEMPT_PENDING,
270 ADRENO_PREEMPT_COMPLETE,
271};
272
273/**
274 * struct adreno_preemption
275 * @state: The current state of preemption
276 * @counters: Memory descriptor for the memory where the GPU writes the
277 * preemption counters on switch
278 * @timer: A timer to make sure preemption doesn't stall
279 * @work: A work struct for the preemption worker (for 5XX)
280 * @token_submit: Indicates if a preempt token has been submitted in
281 * current ringbuffer (for 4XX)
Harshdeep Dhatta8ec51c2017-09-21 17:24:08 -0600282 * preempt_level: The level of preemption (for 6XX)
283 * skipsaverestore: To skip saverestore during L1 preemption (for 6XX)
284 * usesgmem: enable GMEM save/restore across preemption (for 6XX)
Harshdeep Dhatt4ab35b12017-11-16 08:34:39 -0700285 * count: Track the number of preemptions triggered
Shrenuj Bansala419c792016-10-20 14:05:11 -0700286 */
287struct adreno_preemption {
288 atomic_t state;
289 struct kgsl_memdesc counters;
290 struct timer_list timer;
291 struct work_struct work;
292 bool token_submit;
Harshdeep Dhatta8ec51c2017-09-21 17:24:08 -0600293 unsigned int preempt_level;
294 bool skipsaverestore;
295 bool usesgmem;
Harshdeep Dhatt4ab35b12017-11-16 08:34:39 -0700296 unsigned int count;
Shrenuj Bansala419c792016-10-20 14:05:11 -0700297};
298
299
300struct adreno_busy_data {
301 unsigned int gpu_busy;
Deepak Kumar84b9e032017-11-08 13:08:50 +0530302 unsigned int bif_ram_cycles;
303 unsigned int bif_ram_cycles_read_ch1;
304 unsigned int bif_ram_cycles_write_ch0;
305 unsigned int bif_ram_cycles_write_ch1;
306 unsigned int bif_starved_ram;
307 unsigned int bif_starved_ram_ch1;
Shrenuj Bansala419c792016-10-20 14:05:11 -0700308 unsigned int throttle_cycles[ADRENO_GPMU_THROTTLE_COUNTERS];
309};
310
311/**
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -0700312 * struct adreno_firmware - Struct holding fw details
313 * @fwvirt: Buffer which holds the ucode
314 * @size: Size of ucode buffer
315 * @version: Version of ucode
316 * @memdesc: Memory descriptor which holds ucode buffer info
317 */
318struct adreno_firmware {
319 unsigned int *fwvirt;
320 size_t size;
321 unsigned int version;
322 struct kgsl_memdesc memdesc;
323};
324
325/**
Shrenuj Bansala419c792016-10-20 14:05:11 -0700326 * struct adreno_gpu_core - A specific GPU core definition
327 * @gpurev: Unique GPU revision identifier
328 * @core: Match for the core version of the GPU
329 * @major: Match for the major version of the GPU
330 * @minor: Match for the minor version of the GPU
331 * @patchid: Match for the patch revision of the GPU
332 * @features: Common adreno features supported by this core
333 * @pm4fw_name: Filename for th PM4 firmware
334 * @pfpfw_name: Filename for the PFP firmware
335 * @zap_name: Filename for the Zap Shader ucode
336 * @gpudev: Pointer to the GPU family specific functions for this core
337 * @gmem_size: Amount of binning memory (GMEM/OCMEM) to reserve for the core
338 * @pm4_jt_idx: Index of the jump table in the PM4 microcode
339 * @pm4_jt_addr: Address offset to load the jump table for the PM4 microcode
340 * @pfp_jt_idx: Index of the jump table in the PFP microcode
341 * @pfp_jt_addr: Address offset to load the jump table for the PFP microcode
342 * @pm4_bstrp_size: Size of the bootstrap loader for PM4 microcode
343 * @pfp_bstrp_size: Size of the bootstrap loader for PFP microcde
344 * @pfp_bstrp_ver: Version of the PFP microcode that supports bootstraping
345 * @shader_offset: Offset of shader from gpu reg base
346 * @shader_size: Shader size
347 * @num_protected_regs: number of protected registers
348 * @gpmufw_name: Filename for the GPMU firmware
349 * @gpmu_major: Match for the GPMU & firmware, major revision
350 * @gpmu_minor: Match for the GPMU & firmware, minor revision
351 * @gpmu_features: Supported features for any given GPMU version
352 * @busy_mask: mask to check if GPU is busy in RBBM_STATUS
353 * @lm_major: Limits Management register sequence, major revision
354 * @lm_minor: LM register sequence, minor revision
355 * @regfw_name: Filename for the register sequence firmware
356 * @gpmu_tsens: ID for the temporature sensor used by the GPMU
357 * @max_power: Max possible power draw of a core, units elephant tail hairs
358 */
359struct adreno_gpu_core {
360 enum adreno_gpurev gpurev;
361 unsigned int core, major, minor, patchid;
362 unsigned long features;
363 const char *pm4fw_name;
364 const char *pfpfw_name;
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -0700365 const char *sqefw_name;
Shrenuj Bansala419c792016-10-20 14:05:11 -0700366 const char *zap_name;
367 struct adreno_gpudev *gpudev;
368 size_t gmem_size;
369 unsigned int pm4_jt_idx;
370 unsigned int pm4_jt_addr;
371 unsigned int pfp_jt_idx;
372 unsigned int pfp_jt_addr;
373 unsigned int pm4_bstrp_size;
374 unsigned int pfp_bstrp_size;
375 unsigned int pfp_bstrp_ver;
376 unsigned long shader_offset;
377 unsigned int shader_size;
378 unsigned int num_protected_regs;
379 const char *gpmufw_name;
380 unsigned int gpmu_major;
381 unsigned int gpmu_minor;
382 unsigned int gpmu_features;
383 unsigned int busy_mask;
384 unsigned int lm_major, lm_minor;
385 const char *regfw_name;
386 unsigned int gpmu_tsens;
387 unsigned int max_power;
388};
389
Lokesh Batraa8300e02017-05-25 11:17:40 -0700390
391enum gpu_coresight_sources {
392 GPU_CORESIGHT_GX = 0,
393 GPU_CORESIGHT_CX = 1,
394 GPU_CORESIGHT_MAX,
395};
396
Shrenuj Bansala419c792016-10-20 14:05:11 -0700397/**
398 * struct adreno_device - The mothership structure for all adreno related info
399 * @dev: Reference to struct kgsl_device
400 * @priv: Holds the private flags specific to the adreno_device
401 * @chipid: Chip ID specific to the GPU
402 * @gmem_base: Base physical address of GMEM
403 * @gmem_size: GMEM size
404 * @gpucore: Pointer to the adreno_gpu_core structure
405 * @pfp_fw: Buffer which holds the pfp ucode
406 * @pfp_fw_size: Size of pfp ucode buffer
407 * @pfp_fw_version: Version of pfp ucode
408 * @pfp: Memory descriptor which holds pfp ucode buffer info
409 * @pm4_fw: Buffer which holds the pm4 ucode
410 * @pm4_fw_size: Size of pm4 ucode buffer
411 * @pm4_fw_version: Version of pm4 ucode
412 * @pm4: Memory descriptor which holds pm4 ucode buffer info
413 * @gpmu_cmds_size: Length of gpmu cmd stream
414 * @gpmu_cmds: gpmu cmd stream
415 * @ringbuffers: Array of pointers to adreno_ringbuffers
416 * @num_ringbuffers: Number of ringbuffers for the GPU
417 * @cur_rb: Pointer to the current ringbuffer
418 * @next_rb: Ringbuffer we are switching to during preemption
419 * @prev_rb: Ringbuffer we are switching from during preemption
420 * @fast_hang_detect: Software fault detection availability
421 * @ft_policy: Defines the fault tolerance policy
422 * @long_ib_detect: Long IB detection availability
423 * @ft_pf_policy: Defines the fault policy for page faults
424 * @ocmem_hdl: Handle to the ocmem allocated buffer
425 * @profile: Container for adreno profiler information
426 * @dispatcher: Container for adreno GPU dispatcher
427 * @pwron_fixup: Command buffer to run a post-power collapse shader workaround
428 * @pwron_fixup_dwords: Number of dwords in the command buffer
429 * @input_work: Work struct for turning on the GPU after a touch event
430 * @busy_data: Struct holding GPU VBIF busy stats
Deepak Kumar84b9e032017-11-08 13:08:50 +0530431 * @ram_cycles_lo: Number of DDR clock cycles for the monitor session (Only
432 * DDR channel 0 read cycles in case of GBIF)
433 * @ram_cycles_lo_ch1_read: Number of DDR channel 1 Read clock cycles for
434 * the monitor session
435 * @ram_cycles_lo_ch0_write: Number of DDR channel 0 Write clock cycles for
436 * the monitor session
437 * @ram_cycles_lo_ch1_write: Number of DDR channel 0 Write clock cycles for
438 * the monitor session
Deepak Kumarc52781f2017-11-06 16:10:17 +0530439 * @starved_ram_lo: Number of cycles VBIF/GBIF is stalled by DDR (Only channel 0
440 * stall cycles in case of GBIF)
441 * @starved_ram_lo_ch1: Number of cycles GBIF is stalled by DDR channel 1
442 * @perfctr_pwr_lo: GPU busy cycles
Shrenuj Bansala419c792016-10-20 14:05:11 -0700443 * @halt: Atomic variable to check whether the GPU is currently halted
Deepak Kumar273c5712017-01-03 21:49:03 +0530444 * @pending_irq_refcnt: Atomic variable to keep track of running IRQ handlers
Shrenuj Bansala419c792016-10-20 14:05:11 -0700445 * @ctx_d_debugfs: Context debugfs node
446 * @pwrctrl_flag: Flag to hold adreno specific power attributes
447 * @profile_buffer: Memdesc holding the drawobj profiling buffer
448 * @profile_index: Index to store the start/stop ticks in the profiling
449 * buffer
Harshdeep Dhattd0f38f62017-06-01 12:45:26 -0600450 * @pwrup_reglist: Memdesc holding the power up register list
451 * which is used by CP during preemption and IFPC
Shrenuj Bansala419c792016-10-20 14:05:11 -0700452 * @sp_local_gpuaddr: Base GPU virtual address for SP local memory
453 * @sp_pvt_gpuaddr: Base GPU virtual address for SP private memory
454 * @lm_fw: The LM firmware handle
455 * @lm_sequence: Pointer to the start of the register write sequence for LM
456 * @lm_size: The dword size of the LM sequence
457 * @lm_limit: limiting value for LM
458 * @lm_threshold_count: register value for counter for lm threshold breakin
459 * @lm_threshold_cross: number of current peaks exceeding threshold
460 * @speed_bin: Indicate which power level set to use
461 * @csdev: Pointer to a coresight device (if applicable)
462 * @gpmu_throttle_counters - counteers for number of throttled clocks
463 * @irq_storm_work: Worker to handle possible interrupt storms
464 * @active_list: List to track active contexts
465 * @active_list_lock: Lock to protect active_list
Sushmita Susheelendra7f66cf72016-09-12 11:04:43 -0600466 * @gpu_llc_slice: GPU system cache slice descriptor
Sushmita Susheelendrab1976682016-11-07 14:21:11 -0700467 * @gpu_llc_slice_enable: To enable the GPU system cache slice or not
Sushmita Susheelendra906564d2017-01-10 15:53:55 -0700468 * @gpuhtw_llc_slice: GPU pagetables system cache slice descriptor
Sushmita Susheelendrad3756c02017-01-11 15:05:40 -0700469 * @gpuhtw_llc_slice_enable: To enable the GPUHTW system cache slice or not
Harshdeep Dhatta9e0d762017-05-10 14:16:42 -0600470 * @zap_loaded: Used to track if zap was successfully loaded or not
Shrenuj Bansala419c792016-10-20 14:05:11 -0700471 */
472struct adreno_device {
473 struct kgsl_device dev; /* Must be first field in this struct */
474 unsigned long priv;
475 unsigned int chipid;
476 unsigned long gmem_base;
477 unsigned long gmem_size;
Lynus Vaz9ed8cf92017-09-21 21:55:34 +0530478 unsigned long cx_dbgc_base;
479 unsigned int cx_dbgc_len;
480 void __iomem *cx_dbgc_virt;
Shrenuj Bansala419c792016-10-20 14:05:11 -0700481 const struct adreno_gpu_core *gpucore;
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -0700482 struct adreno_firmware fw[2];
Shrenuj Bansala419c792016-10-20 14:05:11 -0700483 size_t gpmu_cmds_size;
484 unsigned int *gpmu_cmds;
485 struct adreno_ringbuffer ringbuffers[KGSL_PRIORITY_MAX_RB_LEVELS];
486 int num_ringbuffers;
487 struct adreno_ringbuffer *cur_rb;
488 struct adreno_ringbuffer *next_rb;
489 struct adreno_ringbuffer *prev_rb;
490 unsigned int fast_hang_detect;
491 unsigned long ft_policy;
492 unsigned int long_ib_detect;
493 unsigned long ft_pf_policy;
494 struct ocmem_buf *ocmem_hdl;
495 struct adreno_profile profile;
496 struct adreno_dispatcher dispatcher;
497 struct kgsl_memdesc pwron_fixup;
498 unsigned int pwron_fixup_dwords;
499 struct work_struct input_work;
500 struct adreno_busy_data busy_data;
501 unsigned int ram_cycles_lo;
Deepak Kumar84b9e032017-11-08 13:08:50 +0530502 unsigned int ram_cycles_lo_ch1_read;
503 unsigned int ram_cycles_lo_ch0_write;
504 unsigned int ram_cycles_lo_ch1_write;
Shrenuj Bansala419c792016-10-20 14:05:11 -0700505 unsigned int starved_ram_lo;
Deepak Kumarc52781f2017-11-06 16:10:17 +0530506 unsigned int starved_ram_lo_ch1;
Shrenuj Bansala419c792016-10-20 14:05:11 -0700507 unsigned int perfctr_pwr_lo;
508 atomic_t halt;
Deepak Kumar273c5712017-01-03 21:49:03 +0530509 atomic_t pending_irq_refcnt;
Shrenuj Bansala419c792016-10-20 14:05:11 -0700510 struct dentry *ctx_d_debugfs;
511 unsigned long pwrctrl_flag;
512
513 struct kgsl_memdesc profile_buffer;
514 unsigned int profile_index;
Harshdeep Dhattd0f38f62017-06-01 12:45:26 -0600515 struct kgsl_memdesc pwrup_reglist;
Shrenuj Bansala419c792016-10-20 14:05:11 -0700516 uint64_t sp_local_gpuaddr;
517 uint64_t sp_pvt_gpuaddr;
518 const struct firmware *lm_fw;
519 uint32_t *lm_sequence;
520 uint32_t lm_size;
521 struct adreno_preemption preempt;
522 struct work_struct gpmu_work;
523 uint32_t lm_leakage;
524 uint32_t lm_limit;
525 uint32_t lm_threshold_count;
526 uint32_t lm_threshold_cross;
527
528 unsigned int speed_bin;
529 unsigned int quirks;
530
Lokesh Batraa8300e02017-05-25 11:17:40 -0700531 struct coresight_device *csdev[GPU_CORESIGHT_MAX];
Shrenuj Bansala419c792016-10-20 14:05:11 -0700532 uint32_t gpmu_throttle_counters[ADRENO_GPMU_THROTTLE_COUNTERS];
533 struct work_struct irq_storm_work;
534
535 struct list_head active_list;
536 spinlock_t active_list_lock;
Sushmita Susheelendra7f66cf72016-09-12 11:04:43 -0600537
538 void *gpu_llc_slice;
Sushmita Susheelendrab1976682016-11-07 14:21:11 -0700539 bool gpu_llc_slice_enable;
Sushmita Susheelendra906564d2017-01-10 15:53:55 -0700540 void *gpuhtw_llc_slice;
Sushmita Susheelendrad3756c02017-01-11 15:05:40 -0700541 bool gpuhtw_llc_slice_enable;
Harshdeep Dhatta9e0d762017-05-10 14:16:42 -0600542 unsigned int zap_loaded;
Shrenuj Bansala419c792016-10-20 14:05:11 -0700543};
544
545/**
546 * enum adreno_device_flags - Private flags for the adreno_device
547 * @ADRENO_DEVICE_PWRON - Set during init after a power collapse
548 * @ADRENO_DEVICE_PWRON_FIXUP - Set if the target requires the shader fixup
549 * after power collapse
550 * @ADRENO_DEVICE_CORESIGHT - Set if the coresight (trace bus) registers should
551 * be restored after power collapse
552 * @ADRENO_DEVICE_HANG_INTR - Set if the hang interrupt should be enabled for
553 * this target
554 * @ADRENO_DEVICE_STARTED - Set if the device start sequence is in progress
555 * @ADRENO_DEVICE_FAULT - Set if the device is currently in fault (and shouldn't
556 * send any more commands to the ringbuffer)
557 * @ADRENO_DEVICE_DRAWOBJ_PROFILE - Set if the device supports drawobj
558 * profiling via the ALWAYSON counter
559 * @ADRENO_DEVICE_PREEMPTION - Turn on/off preemption
560 * @ADRENO_DEVICE_SOFT_FAULT_DETECT - Set if soft fault detect is enabled
561 * @ADRENO_DEVICE_GPMU_INITIALIZED - Set if GPMU firmware initialization succeed
562 * @ADRENO_DEVICE_ISDB_ENABLED - Set if the Integrated Shader DeBugger is
563 * attached and enabled
564 * @ADRENO_DEVICE_CACHE_FLUSH_TS_SUSPENDED - Set if a CACHE_FLUSH_TS irq storm
565 * is in progress
Kyle Piefere923b7a2017-03-28 17:31:48 -0700566 * @ADRENO_DEVICE_HARD_RESET - Set if soft reset fails and hard reset is needed
Shrenuj Bansala419c792016-10-20 14:05:11 -0700567 */
568enum adreno_device_flags {
569 ADRENO_DEVICE_PWRON = 0,
570 ADRENO_DEVICE_PWRON_FIXUP = 1,
571 ADRENO_DEVICE_INITIALIZED = 2,
572 ADRENO_DEVICE_CORESIGHT = 3,
573 ADRENO_DEVICE_HANG_INTR = 4,
574 ADRENO_DEVICE_STARTED = 5,
575 ADRENO_DEVICE_FAULT = 6,
576 ADRENO_DEVICE_DRAWOBJ_PROFILE = 7,
577 ADRENO_DEVICE_GPU_REGULATOR_ENABLED = 8,
578 ADRENO_DEVICE_PREEMPTION = 9,
579 ADRENO_DEVICE_SOFT_FAULT_DETECT = 10,
580 ADRENO_DEVICE_GPMU_INITIALIZED = 11,
581 ADRENO_DEVICE_ISDB_ENABLED = 12,
582 ADRENO_DEVICE_CACHE_FLUSH_TS_SUSPENDED = 13,
Kyle Piefere923b7a2017-03-28 17:31:48 -0700583 ADRENO_DEVICE_HARD_RESET = 14,
Lokesh Batraa8300e02017-05-25 11:17:40 -0700584 ADRENO_DEVICE_CORESIGHT_CX = 16,
Shrenuj Bansala419c792016-10-20 14:05:11 -0700585};
586
587/**
588 * struct adreno_drawobj_profile_entry - a single drawobj entry in the
589 * kernel profiling buffer
590 * @started: Number of GPU ticks at start of the drawobj
591 * @retired: Number of GPU ticks at the end of the drawobj
592 */
593struct adreno_drawobj_profile_entry {
594 uint64_t started;
595 uint64_t retired;
596};
597
598#define ADRENO_DRAWOBJ_PROFILE_COUNT \
599 (PAGE_SIZE / sizeof(struct adreno_drawobj_profile_entry))
600
601#define ADRENO_DRAWOBJ_PROFILE_OFFSET(_index, _member) \
602 ((_index) * sizeof(struct adreno_drawobj_profile_entry) \
603 + offsetof(struct adreno_drawobj_profile_entry, _member))
604
605
606/**
607 * adreno_regs: List of registers that are used in kgsl driver for all
608 * 3D devices. Each device type has different offset value for the same
609 * register, so an array of register offsets are declared for every device
610 * and are indexed by the enumeration values defined in this enum
611 */
612enum adreno_regs {
613 ADRENO_REG_CP_ME_RAM_WADDR,
614 ADRENO_REG_CP_ME_RAM_DATA,
615 ADRENO_REG_CP_PFP_UCODE_DATA,
616 ADRENO_REG_CP_PFP_UCODE_ADDR,
617 ADRENO_REG_CP_WFI_PEND_CTR,
618 ADRENO_REG_CP_RB_BASE,
619 ADRENO_REG_CP_RB_BASE_HI,
620 ADRENO_REG_CP_RB_RPTR_ADDR_LO,
621 ADRENO_REG_CP_RB_RPTR_ADDR_HI,
622 ADRENO_REG_CP_RB_RPTR,
623 ADRENO_REG_CP_RB_WPTR,
624 ADRENO_REG_CP_CNTL,
625 ADRENO_REG_CP_ME_CNTL,
626 ADRENO_REG_CP_RB_CNTL,
627 ADRENO_REG_CP_IB1_BASE,
628 ADRENO_REG_CP_IB1_BASE_HI,
629 ADRENO_REG_CP_IB1_BUFSZ,
630 ADRENO_REG_CP_IB2_BASE,
631 ADRENO_REG_CP_IB2_BASE_HI,
632 ADRENO_REG_CP_IB2_BUFSZ,
633 ADRENO_REG_CP_TIMESTAMP,
634 ADRENO_REG_CP_SCRATCH_REG6,
635 ADRENO_REG_CP_SCRATCH_REG7,
636 ADRENO_REG_CP_ME_RAM_RADDR,
637 ADRENO_REG_CP_ROQ_ADDR,
638 ADRENO_REG_CP_ROQ_DATA,
639 ADRENO_REG_CP_MERCIU_ADDR,
640 ADRENO_REG_CP_MERCIU_DATA,
641 ADRENO_REG_CP_MERCIU_DATA2,
642 ADRENO_REG_CP_MEQ_ADDR,
643 ADRENO_REG_CP_MEQ_DATA,
644 ADRENO_REG_CP_HW_FAULT,
645 ADRENO_REG_CP_PROTECT_STATUS,
646 ADRENO_REG_CP_PREEMPT,
647 ADRENO_REG_CP_PREEMPT_DEBUG,
648 ADRENO_REG_CP_PREEMPT_DISABLE,
649 ADRENO_REG_CP_PROTECT_REG_0,
650 ADRENO_REG_CP_CONTEXT_SWITCH_SMMU_INFO_LO,
651 ADRENO_REG_CP_CONTEXT_SWITCH_SMMU_INFO_HI,
Harshdeep Dhatt59a69572017-11-01 14:46:13 -0600652 ADRENO_REG_CP_CONTEXT_SWITCH_PRIV_NON_SECURE_RESTORE_ADDR_LO,
653 ADRENO_REG_CP_CONTEXT_SWITCH_PRIV_NON_SECURE_RESTORE_ADDR_HI,
654 ADRENO_REG_CP_CONTEXT_SWITCH_PRIV_SECURE_RESTORE_ADDR_LO,
655 ADRENO_REG_CP_CONTEXT_SWITCH_PRIV_SECURE_RESTORE_ADDR_HI,
656 ADRENO_REG_CP_CONTEXT_SWITCH_NON_PRIV_RESTORE_ADDR_LO,
657 ADRENO_REG_CP_CONTEXT_SWITCH_NON_PRIV_RESTORE_ADDR_HI,
Harshdeep Dhatt003f6cf2017-12-14 11:00:22 -0700658 ADRENO_REG_CP_PREEMPT_LEVEL_STATUS,
Shrenuj Bansala419c792016-10-20 14:05:11 -0700659 ADRENO_REG_RBBM_STATUS,
660 ADRENO_REG_RBBM_STATUS3,
661 ADRENO_REG_RBBM_PERFCTR_CTL,
662 ADRENO_REG_RBBM_PERFCTR_LOAD_CMD0,
663 ADRENO_REG_RBBM_PERFCTR_LOAD_CMD1,
664 ADRENO_REG_RBBM_PERFCTR_LOAD_CMD2,
665 ADRENO_REG_RBBM_PERFCTR_LOAD_CMD3,
666 ADRENO_REG_RBBM_PERFCTR_PWR_1_LO,
667 ADRENO_REG_RBBM_INT_0_MASK,
668 ADRENO_REG_RBBM_INT_0_STATUS,
669 ADRENO_REG_RBBM_PM_OVERRIDE2,
670 ADRENO_REG_RBBM_INT_CLEAR_CMD,
671 ADRENO_REG_RBBM_SW_RESET_CMD,
672 ADRENO_REG_RBBM_BLOCK_SW_RESET_CMD,
673 ADRENO_REG_RBBM_BLOCK_SW_RESET_CMD2,
674 ADRENO_REG_RBBM_CLOCK_CTL,
675 ADRENO_REG_VPC_DEBUG_RAM_SEL,
676 ADRENO_REG_VPC_DEBUG_RAM_READ,
677 ADRENO_REG_PA_SC_AA_CONFIG,
678 ADRENO_REG_SQ_GPR_MANAGEMENT,
679 ADRENO_REG_SQ_INST_STORE_MANAGEMENT,
680 ADRENO_REG_TP0_CHICKEN,
681 ADRENO_REG_RBBM_RBBM_CTL,
682 ADRENO_REG_UCHE_INVALIDATE0,
683 ADRENO_REG_UCHE_INVALIDATE1,
Abhilash Kumarf1af1042017-07-14 13:13:44 +0530684 ADRENO_REG_RBBM_PERFCTR_RBBM_0_LO,
685 ADRENO_REG_RBBM_PERFCTR_RBBM_0_HI,
Shrenuj Bansala419c792016-10-20 14:05:11 -0700686 ADRENO_REG_RBBM_PERFCTR_LOAD_VALUE_LO,
687 ADRENO_REG_RBBM_PERFCTR_LOAD_VALUE_HI,
688 ADRENO_REG_RBBM_SECVID_TRUST_CONTROL,
689 ADRENO_REG_RBBM_ALWAYSON_COUNTER_LO,
690 ADRENO_REG_RBBM_ALWAYSON_COUNTER_HI,
691 ADRENO_REG_RBBM_SECVID_TRUST_CONFIG,
692 ADRENO_REG_RBBM_SECVID_TSB_CONTROL,
693 ADRENO_REG_RBBM_SECVID_TSB_TRUSTED_BASE,
694 ADRENO_REG_RBBM_SECVID_TSB_TRUSTED_BASE_HI,
695 ADRENO_REG_RBBM_SECVID_TSB_TRUSTED_SIZE,
Rajesh Kemisettid1ca9542017-10-18 15:35:41 +0530696 ADRENO_REG_RBBM_GPR0_CNTL,
697 ADRENO_REG_RBBM_VBIF_GX_RESET_STATUS,
Shrenuj Bansala419c792016-10-20 14:05:11 -0700698 ADRENO_REG_VBIF_XIN_HALT_CTRL0,
699 ADRENO_REG_VBIF_XIN_HALT_CTRL1,
700 ADRENO_REG_VBIF_VERSION,
Rajesh Kemisetti77b82ed2017-09-24 20:42:41 +0530701 ADRENO_REG_GBIF_HALT,
702 ADRENO_REG_GBIF_HALT_ACK,
Kyle Pieferda0fa542017-08-04 13:39:40 -0700703 ADRENO_REG_GMU_AO_AHB_FENCE_CTRL,
Kyle Pieferb1027b02017-02-10 13:58:58 -0800704 ADRENO_REG_GMU_AO_INTERRUPT_EN,
Kyle Piefere7b06b42017-04-06 13:53:01 -0700705 ADRENO_REG_GMU_AO_HOST_INTERRUPT_CLR,
706 ADRENO_REG_GMU_AO_HOST_INTERRUPT_STATUS,
707 ADRENO_REG_GMU_AO_HOST_INTERRUPT_MASK,
Kyle Pieferb1027b02017-02-10 13:58:58 -0800708 ADRENO_REG_GMU_PWR_COL_KEEPALIVE,
709 ADRENO_REG_GMU_AHB_FENCE_STATUS,
710 ADRENO_REG_GMU_RPMH_POWER_STATE,
711 ADRENO_REG_GMU_HFI_CTRL_STATUS,
712 ADRENO_REG_GMU_HFI_VERSION_INFO,
713 ADRENO_REG_GMU_HFI_SFR_ADDR,
714 ADRENO_REG_GMU_GMU2HOST_INTR_CLR,
715 ADRENO_REG_GMU_GMU2HOST_INTR_INFO,
Kyle Piefere7b06b42017-04-06 13:53:01 -0700716 ADRENO_REG_GMU_GMU2HOST_INTR_MASK,
Kyle Pieferb1027b02017-02-10 13:58:58 -0800717 ADRENO_REG_GMU_HOST2GMU_INTR_SET,
718 ADRENO_REG_GMU_HOST2GMU_INTR_CLR,
719 ADRENO_REG_GMU_HOST2GMU_INTR_RAW_INFO,
George Shen6927d8f2017-07-19 11:38:10 -0700720 ADRENO_REG_GMU_NMI_CONTROL_STATUS,
721 ADRENO_REG_GMU_CM3_CFG,
Lynus Vaz76ecd062017-06-01 20:00:53 +0530722 ADRENO_REG_GPMU_POWER_COUNTER_ENABLE,
Shrenuj Bansala419c792016-10-20 14:05:11 -0700723 ADRENO_REG_REGISTER_MAX,
724};
725
726enum adreno_int_bits {
727 ADRENO_INT_RBBM_AHB_ERROR,
728 ADRENO_INT_BITS_MAX,
729};
730
731/**
732 * adreno_reg_offsets: Holds array of register offsets
733 * @offsets: Offset array of size defined by enum adreno_regs
734 * @offset_0: This is the index of the register in offset array whose value
735 * is 0. 0 is a valid register offset and during initialization of the
736 * offset array we need to know if an offset value is correctly defined to 0
737 */
738struct adreno_reg_offsets {
739 unsigned int *const offsets;
740 enum adreno_regs offset_0;
741};
742
743#define ADRENO_REG_UNUSED 0xFFFFFFFF
744#define ADRENO_REG_SKIP 0xFFFFFFFE
745#define ADRENO_REG_DEFINE(_offset, _reg) [_offset] = _reg
746#define ADRENO_INT_DEFINE(_offset, _val) ADRENO_REG_DEFINE(_offset, _val)
747
748/*
749 * struct adreno_vbif_data - Describes vbif register value pair
750 * @reg: Offset to vbif register
751 * @val: The value that should be programmed in the register at reg
752 */
753struct adreno_vbif_data {
754 unsigned int reg;
755 unsigned int val;
756};
757
758/*
759 * struct adreno_vbif_platform - Holds an array of vbif reg value pairs
760 * for a particular core
761 * @devfunc: Pointer to platform/core identification function
762 * @vbif: Array of reg value pairs for vbif registers
763 */
764struct adreno_vbif_platform {
765 int (*devfunc)(struct adreno_device *);
766 const struct adreno_vbif_data *vbif;
767};
768
769/*
770 * struct adreno_vbif_snapshot_registers - Holds an array of vbif registers
771 * listed for snapshot dump for a particular core
772 * @version: vbif version
773 * @mask: vbif revision mask
774 * @registers: vbif registers listed for snapshot dump
775 * @count: count of vbif registers listed for snapshot
776 */
777struct adreno_vbif_snapshot_registers {
778 const unsigned int version;
779 const unsigned int mask;
780 const unsigned int *registers;
781 const int count;
782};
783
784/**
785 * struct adreno_coresight_register - Definition for a coresight (tracebus)
786 * debug register
787 * @offset: Offset of the debug register in the KGSL mmio region
788 * @initial: Default value to write when coresight is enabled
789 * @value: Current shadow value of the register (to be reprogrammed after power
790 * collapse)
791 */
792struct adreno_coresight_register {
793 unsigned int offset;
794 unsigned int initial;
795 unsigned int value;
796};
797
798struct adreno_coresight_attr {
799 struct device_attribute attr;
800 struct adreno_coresight_register *reg;
801};
802
803ssize_t adreno_coresight_show_register(struct device *device,
804 struct device_attribute *attr, char *buf);
805
806ssize_t adreno_coresight_store_register(struct device *dev,
807 struct device_attribute *attr, const char *buf, size_t size);
808
809#define ADRENO_CORESIGHT_ATTR(_attrname, _reg) \
810 struct adreno_coresight_attr coresight_attr_##_attrname = { \
811 __ATTR(_attrname, 0644, \
812 adreno_coresight_show_register, \
813 adreno_coresight_store_register), \
814 (_reg), }
815
816/**
817 * struct adreno_coresight - GPU specific coresight definition
818 * @registers - Array of GPU specific registers to configure trace bus output
819 * @count - Number of registers in the array
820 * @groups - Pointer to an attribute list of control files
821 * @atid - The unique ATID value of the coresight device
822 */
823struct adreno_coresight {
824 struct adreno_coresight_register *registers;
825 unsigned int count;
826 const struct attribute_group **groups;
827 unsigned int atid;
828};
829
830
831struct adreno_irq_funcs {
832 void (*func)(struct adreno_device *, int);
833};
834#define ADRENO_IRQ_CALLBACK(_c) { .func = _c }
835
836struct adreno_irq {
837 unsigned int mask;
838 struct adreno_irq_funcs *funcs;
839};
840
841/*
842 * struct adreno_debugbus_block - Holds info about debug buses of a chip
843 * @block_id: Bus identifier
844 * @dwords: Number of dwords of data that this block holds
845 */
846struct adreno_debugbus_block {
847 unsigned int block_id;
848 unsigned int dwords;
849};
850
851/*
852 * struct adreno_snapshot_section_sizes - Structure holding the size of
853 * different sections dumped during device snapshot
854 * @cp_pfp: CP PFP data section size
855 * @cp_me: CP ME data section size
856 * @vpc_mem: VPC memory section size
857 * @cp_meq: CP MEQ size
858 * @shader_mem: Size of shader memory of 1 shader section
859 * @cp_merciu: CP MERCIU size
860 * @roq: ROQ size
861 */
862struct adreno_snapshot_sizes {
863 int cp_pfp;
864 int cp_me;
865 int vpc_mem;
866 int cp_meq;
867 int shader_mem;
868 int cp_merciu;
869 int roq;
870};
871
872/*
873 * struct adreno_snapshot_data - Holds data used in snapshot
874 * @sect_sizes: Has sections sizes
875 */
876struct adreno_snapshot_data {
877 struct adreno_snapshot_sizes *sect_sizes;
878};
879
Kyle Pieferedc6c8a2017-11-10 14:51:58 -0800880enum adreno_cp_marker_type {
881 IFPC_DISABLE,
882 IFPC_ENABLE,
883 IB1LIST_START,
884 IB1LIST_END,
885};
886
Shrenuj Bansala419c792016-10-20 14:05:11 -0700887struct adreno_gpudev {
888 /*
889 * These registers are in a different location on different devices,
890 * so define them in the structure and use them as variables.
891 */
892 const struct adreno_reg_offsets *reg_offsets;
893 unsigned int *const int_bits;
894 const struct adreno_ft_perf_counters *ft_perf_counters;
895 unsigned int ft_perf_counters_count;
896
897 struct adreno_perfcounters *perfcounters;
898 const struct adreno_invalid_countables *invalid_countables;
899 struct adreno_snapshot_data *snapshot_data;
900
Lokesh Batraa8300e02017-05-25 11:17:40 -0700901 struct adreno_coresight *coresight[GPU_CORESIGHT_MAX];
Shrenuj Bansala419c792016-10-20 14:05:11 -0700902
903 struct adreno_irq *irq;
904 int num_prio_levels;
905 unsigned int vbif_xin_halt_ctrl0_mask;
906 /* GPU specific function hooks */
907 void (*irq_trace)(struct adreno_device *, unsigned int status);
908 void (*snapshot)(struct adreno_device *, struct kgsl_snapshot *);
Carter Cooperb88b7082017-09-14 09:03:26 -0600909 void (*snapshot_gmu)(struct adreno_device *, struct kgsl_snapshot *);
Shrenuj Bansala419c792016-10-20 14:05:11 -0700910 void (*platform_setup)(struct adreno_device *);
911 void (*init)(struct adreno_device *);
912 void (*remove)(struct adreno_device *);
913 int (*rb_start)(struct adreno_device *, unsigned int start_type);
914 int (*microcode_read)(struct adreno_device *);
915 void (*perfcounter_init)(struct adreno_device *);
916 void (*perfcounter_close)(struct adreno_device *);
917 void (*start)(struct adreno_device *);
918 bool (*is_sptp_idle)(struct adreno_device *);
919 int (*regulator_enable)(struct adreno_device *);
920 void (*regulator_disable)(struct adreno_device *);
921 void (*pwrlevel_change_settings)(struct adreno_device *,
922 unsigned int prelevel, unsigned int postlevel,
923 bool post);
924 uint64_t (*read_throttling_counters)(struct adreno_device *);
925 void (*count_throttles)(struct adreno_device *, uint64_t adj);
926 int (*enable_pwr_counters)(struct adreno_device *,
927 unsigned int counter);
928 unsigned int (*preemption_pre_ibsubmit)(
929 struct adreno_device *adreno_dev,
930 struct adreno_ringbuffer *rb,
931 unsigned int *cmds,
932 struct kgsl_context *context);
933 int (*preemption_yield_enable)(unsigned int *);
Kyle Pieferedc6c8a2017-11-10 14:51:58 -0800934 unsigned int (*set_marker)(unsigned int *cmds,
935 enum adreno_cp_marker_type type);
Shrenuj Bansala419c792016-10-20 14:05:11 -0700936 unsigned int (*preemption_post_ibsubmit)(
937 struct adreno_device *adreno_dev,
938 unsigned int *cmds);
939 int (*preemption_init)(struct adreno_device *);
940 void (*preemption_schedule)(struct adreno_device *);
Harshdeep Dhatt2e42f122017-05-31 17:27:19 -0600941 int (*preemption_context_init)(struct kgsl_context *);
942 void (*preemption_context_destroy)(struct kgsl_context *);
Shrenuj Bansala419c792016-10-20 14:05:11 -0700943 void (*enable_64bit)(struct adreno_device *);
944 void (*clk_set_options)(struct adreno_device *,
Deepak Kumara309e0e2017-03-17 17:27:42 +0530945 const char *, struct clk *, bool on);
Sushmita Susheelendra7f66cf72016-09-12 11:04:43 -0600946 void (*llc_configure_gpu_scid)(struct adreno_device *adreno_dev);
Sushmita Susheelendra906564d2017-01-10 15:53:55 -0700947 void (*llc_configure_gpuhtw_scid)(struct adreno_device *adreno_dev);
Sushmita Susheelendra7f66cf72016-09-12 11:04:43 -0600948 void (*llc_enable_overrides)(struct adreno_device *adreno_dev);
Kyle Pieferb1027b02017-02-10 13:58:58 -0800949 void (*pre_reset)(struct adreno_device *);
950 int (*oob_set)(struct adreno_device *adreno_dev, unsigned int set_mask,
951 unsigned int check_mask,
952 unsigned int clear_mask);
953 void (*oob_clear)(struct adreno_device *adreno_dev,
954 unsigned int clear_mask);
Carter Cooperdf7ba702017-03-20 11:28:04 -0600955 void (*gpu_keepalive)(struct adreno_device *adreno_dev,
956 bool state);
Kyle Pieferb1027b02017-02-10 13:58:58 -0800957 int (*rpmh_gpu_pwrctrl)(struct adreno_device *, unsigned int ops,
958 unsigned int arg1, unsigned int arg2);
Oleg Perelet62d5cec2017-03-27 16:14:52 -0700959 bool (*hw_isidle)(struct adreno_device *);
Kyle Piefer4033f562017-08-16 10:00:48 -0700960 int (*wait_for_lowest_idle)(struct adreno_device *);
Oleg Perelet62d5cec2017-03-27 16:14:52 -0700961 int (*wait_for_gmu_idle)(struct adreno_device *);
Lynus Vaz1fde74d2017-03-20 18:02:47 +0530962 const char *(*iommu_fault_block)(struct adreno_device *adreno_dev,
963 unsigned int fsynr1);
Shrenuj Bansald0fe7462017-05-08 16:11:19 -0700964 int (*reset)(struct kgsl_device *, int fault);
Shrenuj Bansal49d0e9f2017-05-08 16:10:24 -0700965 int (*soft_reset)(struct adreno_device *);
Shrenuj Bansald197bf62017-04-07 11:00:09 -0700966 bool (*gx_is_on)(struct adreno_device *);
967 bool (*sptprac_is_on)(struct adreno_device *);
Harshdeep Dhatt6ba7a942017-08-21 17:53:52 -0600968 unsigned int (*ccu_invalidate)(struct adreno_device *adreno_dev,
969 unsigned int *cmds);
Tarun Karra1382e512017-10-30 19:41:25 -0700970 int (*perfcounter_update)(struct adreno_device *adreno_dev,
971 struct adreno_perfcount_register *reg,
972 bool update_reg);
Shrenuj Bansala419c792016-10-20 14:05:11 -0700973};
974
975/**
976 * enum kgsl_ft_policy_bits - KGSL fault tolerance policy bits
977 * @KGSL_FT_OFF: Disable fault detection (not used)
978 * @KGSL_FT_REPLAY: Replay the faulting command
979 * @KGSL_FT_SKIPIB: Skip the faulting indirect buffer
980 * @KGSL_FT_SKIPFRAME: Skip the frame containing the faulting IB
981 * @KGSL_FT_DISABLE: Tells the dispatcher to disable FT for the command obj
982 * @KGSL_FT_TEMP_DISABLE: Disables FT for all commands
983 * @KGSL_FT_THROTTLE: Disable the context if it faults too often
984 * @KGSL_FT_SKIPCMD: Skip the command containing the faulting IB
985 */
986enum kgsl_ft_policy_bits {
987 KGSL_FT_OFF = 0,
988 KGSL_FT_REPLAY = 1,
989 KGSL_FT_SKIPIB = 2,
990 KGSL_FT_SKIPFRAME = 3,
991 KGSL_FT_DISABLE = 4,
992 KGSL_FT_TEMP_DISABLE = 5,
993 KGSL_FT_THROTTLE = 6,
994 KGSL_FT_SKIPCMD = 7,
995 /* KGSL_FT_MAX_BITS is used to calculate the mask */
996 KGSL_FT_MAX_BITS,
997 /* Internal bits - set during GFT */
998 /* Skip the PM dump on replayed command obj's */
999 KGSL_FT_SKIP_PMDUMP = 31,
1000};
1001
1002#define KGSL_FT_POLICY_MASK GENMASK(KGSL_FT_MAX_BITS - 1, 0)
1003
1004#define KGSL_FT_DEFAULT_POLICY \
1005 (BIT(KGSL_FT_REPLAY) | \
1006 BIT(KGSL_FT_SKIPCMD) | \
1007 BIT(KGSL_FT_THROTTLE))
1008
1009#define ADRENO_FT_TYPES \
1010 { BIT(KGSL_FT_OFF), "off" }, \
1011 { BIT(KGSL_FT_REPLAY), "replay" }, \
1012 { BIT(KGSL_FT_SKIPIB), "skipib" }, \
1013 { BIT(KGSL_FT_SKIPFRAME), "skipframe" }, \
1014 { BIT(KGSL_FT_DISABLE), "disable" }, \
1015 { BIT(KGSL_FT_TEMP_DISABLE), "temp" }, \
1016 { BIT(KGSL_FT_THROTTLE), "throttle"}, \
1017 { BIT(KGSL_FT_SKIPCMD), "skipcmd" }
1018
1019/**
1020 * enum kgsl_ft_pagefault_policy_bits - KGSL pagefault policy bits
1021 * @KGSL_FT_PAGEFAULT_INT_ENABLE: No longer used, but retained for compatibility
1022 * @KGSL_FT_PAGEFAULT_GPUHALT_ENABLE: enable GPU halt on pagefaults
1023 * @KGSL_FT_PAGEFAULT_LOG_ONE_PER_PAGE: log one pagefault per page
1024 * @KGSL_FT_PAGEFAULT_LOG_ONE_PER_INT: log one pagefault per interrupt
1025 */
1026enum {
1027 KGSL_FT_PAGEFAULT_INT_ENABLE = 0,
1028 KGSL_FT_PAGEFAULT_GPUHALT_ENABLE = 1,
1029 KGSL_FT_PAGEFAULT_LOG_ONE_PER_PAGE = 2,
1030 KGSL_FT_PAGEFAULT_LOG_ONE_PER_INT = 3,
1031 /* KGSL_FT_PAGEFAULT_MAX_BITS is used to calculate the mask */
1032 KGSL_FT_PAGEFAULT_MAX_BITS,
1033};
1034
1035#define KGSL_FT_PAGEFAULT_MASK GENMASK(KGSL_FT_PAGEFAULT_MAX_BITS - 1, 0)
1036
1037#define KGSL_FT_PAGEFAULT_DEFAULT_POLICY 0
1038
1039#define FOR_EACH_RINGBUFFER(_dev, _rb, _i) \
1040 for ((_i) = 0, (_rb) = &((_dev)->ringbuffers[0]); \
1041 (_i) < (_dev)->num_ringbuffers; \
1042 (_i)++, (_rb)++)
1043
1044struct adreno_ft_perf_counters {
1045 unsigned int counter;
1046 unsigned int countable;
1047};
1048
1049extern unsigned int *adreno_ft_regs;
1050extern unsigned int adreno_ft_regs_num;
1051extern unsigned int *adreno_ft_regs_val;
1052
1053extern struct adreno_gpudev adreno_a3xx_gpudev;
1054extern struct adreno_gpudev adreno_a4xx_gpudev;
1055extern struct adreno_gpudev adreno_a5xx_gpudev;
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -07001056extern struct adreno_gpudev adreno_a6xx_gpudev;
Shrenuj Bansala419c792016-10-20 14:05:11 -07001057
1058extern int adreno_wake_nice;
1059extern unsigned int adreno_wake_timeout;
1060
Shrenuj Bansald0fe7462017-05-08 16:11:19 -07001061int adreno_start(struct kgsl_device *device, int priority);
1062int adreno_soft_reset(struct kgsl_device *device);
Shrenuj Bansala419c792016-10-20 14:05:11 -07001063long adreno_ioctl(struct kgsl_device_private *dev_priv,
1064 unsigned int cmd, unsigned long arg);
1065
1066long adreno_ioctl_helper(struct kgsl_device_private *dev_priv,
1067 unsigned int cmd, unsigned long arg,
1068 const struct kgsl_ioctl *cmds, int len);
1069
Carter Cooper1d8f5472017-03-15 15:01:09 -06001070int a5xx_critical_packet_submit(struct adreno_device *adreno_dev,
1071 struct adreno_ringbuffer *rb);
1072int adreno_set_unsecured_mode(struct adreno_device *adreno_dev,
1073 struct adreno_ringbuffer *rb);
Carter Cooper8567af02017-03-15 14:22:03 -06001074void adreno_spin_idle_debug(struct adreno_device *adreno_dev, const char *str);
Shrenuj Bansala419c792016-10-20 14:05:11 -07001075int adreno_spin_idle(struct adreno_device *device, unsigned int timeout);
1076int adreno_idle(struct kgsl_device *device);
1077bool adreno_isidle(struct kgsl_device *device);
1078
1079int adreno_set_constraint(struct kgsl_device *device,
1080 struct kgsl_context *context,
1081 struct kgsl_device_constraint *constraint);
1082
1083void adreno_shadermem_regread(struct kgsl_device *device,
1084 unsigned int offsetwords,
1085 unsigned int *value);
1086
1087void adreno_snapshot(struct kgsl_device *device,
1088 struct kgsl_snapshot *snapshot,
1089 struct kgsl_context *context);
1090
Carter Cooperb88b7082017-09-14 09:03:26 -06001091void adreno_snapshot_gmu(struct kgsl_device *device,
1092 struct kgsl_snapshot *snapshot);
1093
Shrenuj Bansala419c792016-10-20 14:05:11 -07001094int adreno_reset(struct kgsl_device *device, int fault);
1095
1096void adreno_fault_skipcmd_detached(struct adreno_device *adreno_dev,
1097 struct adreno_context *drawctxt,
1098 struct kgsl_drawobj *drawobj);
1099
1100int adreno_coresight_init(struct adreno_device *adreno_dev);
1101
1102void adreno_coresight_start(struct adreno_device *adreno_dev);
1103void adreno_coresight_stop(struct adreno_device *adreno_dev);
1104
1105void adreno_coresight_remove(struct adreno_device *adreno_dev);
1106
1107bool adreno_hw_isidle(struct adreno_device *adreno_dev);
1108
1109void adreno_fault_detect_start(struct adreno_device *adreno_dev);
1110void adreno_fault_detect_stop(struct adreno_device *adreno_dev);
1111
1112void adreno_hang_int_callback(struct adreno_device *adreno_dev, int bit);
1113void adreno_cp_callback(struct adreno_device *adreno_dev, int bit);
1114
1115int adreno_sysfs_init(struct adreno_device *adreno_dev);
1116void adreno_sysfs_close(struct adreno_device *adreno_dev);
1117
1118void adreno_irqctrl(struct adreno_device *adreno_dev, int state);
1119
1120long adreno_ioctl_perfcounter_get(struct kgsl_device_private *dev_priv,
1121 unsigned int cmd, void *data);
1122
1123long adreno_ioctl_perfcounter_put(struct kgsl_device_private *dev_priv,
1124 unsigned int cmd, void *data);
1125
1126int adreno_efuse_map(struct adreno_device *adreno_dev);
1127int adreno_efuse_read_u32(struct adreno_device *adreno_dev, unsigned int offset,
1128 unsigned int *val);
1129void adreno_efuse_unmap(struct adreno_device *adreno_dev);
1130
Lynus Vaz9ed8cf92017-09-21 21:55:34 +05301131bool adreno_is_cx_dbgc_register(struct kgsl_device *device,
1132 unsigned int offset);
1133void adreno_cx_dbgc_regread(struct kgsl_device *adreno_device,
1134 unsigned int offsetwords, unsigned int *value);
1135void adreno_cx_dbgc_regwrite(struct kgsl_device *device,
1136 unsigned int offsetwords, unsigned int value);
1137
Shrenuj Bansala419c792016-10-20 14:05:11 -07001138#define ADRENO_TARGET(_name, _id) \
1139static inline int adreno_is_##_name(struct adreno_device *adreno_dev) \
1140{ \
1141 return (ADRENO_GPUREV(adreno_dev) == (_id)); \
1142}
1143
1144static inline int adreno_is_a3xx(struct adreno_device *adreno_dev)
1145{
1146 return ((ADRENO_GPUREV(adreno_dev) >= 300) &&
1147 (ADRENO_GPUREV(adreno_dev) < 400));
1148}
1149
1150ADRENO_TARGET(a304, ADRENO_REV_A304)
1151ADRENO_TARGET(a305, ADRENO_REV_A305)
1152ADRENO_TARGET(a305b, ADRENO_REV_A305B)
1153ADRENO_TARGET(a305c, ADRENO_REV_A305C)
1154ADRENO_TARGET(a306, ADRENO_REV_A306)
1155ADRENO_TARGET(a306a, ADRENO_REV_A306A)
1156ADRENO_TARGET(a310, ADRENO_REV_A310)
1157ADRENO_TARGET(a320, ADRENO_REV_A320)
1158ADRENO_TARGET(a330, ADRENO_REV_A330)
1159
1160static inline int adreno_is_a330v2(struct adreno_device *adreno_dev)
1161{
1162 return ((ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A330) &&
1163 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) > 0));
1164}
1165
1166static inline int adreno_is_a330v21(struct adreno_device *adreno_dev)
1167{
1168 return ((ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A330) &&
1169 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) > 0xF));
1170}
1171
1172static inline int adreno_is_a4xx(struct adreno_device *adreno_dev)
1173{
1174 return ADRENO_GPUREV(adreno_dev) >= 400 &&
1175 ADRENO_GPUREV(adreno_dev) < 500;
1176}
1177
1178ADRENO_TARGET(a405, ADRENO_REV_A405);
1179
1180static inline int adreno_is_a405v2(struct adreno_device *adreno_dev)
1181{
1182 return (ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A405) &&
1183 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) == 0x10);
1184}
1185
1186ADRENO_TARGET(a418, ADRENO_REV_A418)
1187ADRENO_TARGET(a420, ADRENO_REV_A420)
1188ADRENO_TARGET(a430, ADRENO_REV_A430)
1189
1190static inline int adreno_is_a430v2(struct adreno_device *adreno_dev)
1191{
1192 return ((ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A430) &&
1193 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) == 1));
1194}
1195
1196static inline int adreno_is_a5xx(struct adreno_device *adreno_dev)
1197{
1198 return ADRENO_GPUREV(adreno_dev) >= 500 &&
1199 ADRENO_GPUREV(adreno_dev) < 600;
1200}
1201
1202ADRENO_TARGET(a505, ADRENO_REV_A505)
1203ADRENO_TARGET(a506, ADRENO_REV_A506)
Rajesh Kemisettiaed6ec72017-02-06 09:37:00 +05301204ADRENO_TARGET(a508, ADRENO_REV_A508)
Shrenuj Bansala419c792016-10-20 14:05:11 -07001205ADRENO_TARGET(a510, ADRENO_REV_A510)
1206ADRENO_TARGET(a512, ADRENO_REV_A512)
1207ADRENO_TARGET(a530, ADRENO_REV_A530)
1208ADRENO_TARGET(a540, ADRENO_REV_A540)
1209
1210static inline int adreno_is_a530v1(struct adreno_device *adreno_dev)
1211{
1212 return (ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A530) &&
1213 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) == 0);
1214}
1215
1216static inline int adreno_is_a530v2(struct adreno_device *adreno_dev)
1217{
1218 return (ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A530) &&
1219 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) == 1);
1220}
1221
1222static inline int adreno_is_a530v3(struct adreno_device *adreno_dev)
1223{
1224 return (ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A530) &&
1225 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) == 2);
1226}
1227
1228static inline int adreno_is_a505_or_a506(struct adreno_device *adreno_dev)
1229{
1230 return ADRENO_GPUREV(adreno_dev) >= 505 &&
1231 ADRENO_GPUREV(adreno_dev) <= 506;
1232}
1233
1234static inline int adreno_is_a540v1(struct adreno_device *adreno_dev)
1235{
1236 return (ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A540) &&
1237 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) == 0);
1238}
1239
1240static inline int adreno_is_a540v2(struct adreno_device *adreno_dev)
1241{
1242 return (ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A540) &&
1243 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) == 1);
1244}
1245
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -07001246static inline int adreno_is_a6xx(struct adreno_device *adreno_dev)
1247{
1248 return ADRENO_GPUREV(adreno_dev) >= 600 &&
1249 ADRENO_GPUREV(adreno_dev) < 700;
1250}
1251
Rajesh Kemisetti8d5cc6e2017-06-06 16:44:17 +05301252ADRENO_TARGET(a615, ADRENO_REV_A615)
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -07001253ADRENO_TARGET(a630, ADRENO_REV_A630)
1254
Shrenuj Bansal397e5892017-03-13 13:38:47 -07001255static inline int adreno_is_a630v1(struct adreno_device *adreno_dev)
1256{
1257 return (ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A630) &&
1258 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) == 0);
1259}
1260
Kyle Piefer240295972017-08-10 11:38:00 -07001261static inline int adreno_is_a630v2(struct adreno_device *adreno_dev)
1262{
1263 return (ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A630) &&
1264 (ADRENO_CHIPID_PATCH(adreno_dev->chipid) == 1);
1265}
1266
Shrenuj Bansala419c792016-10-20 14:05:11 -07001267/*
1268 * adreno_checkreg_off() - Checks the validity of a register enum
1269 * @adreno_dev: Pointer to adreno device
1270 * @offset_name: The register enum that is checked
1271 */
1272static inline bool adreno_checkreg_off(struct adreno_device *adreno_dev,
1273 enum adreno_regs offset_name)
1274{
1275 struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
1276
1277 if (offset_name >= ADRENO_REG_REGISTER_MAX ||
1278 gpudev->reg_offsets->offsets[offset_name] == ADRENO_REG_UNUSED)
1279 return false;
1280
1281 /*
1282 * GPU register programming is kept common as much as possible
1283 * across the cores, Use ADRENO_REG_SKIP when certain register
1284 * programming needs to be skipped for certain GPU cores.
1285 * Example: Certain registers on a5xx like IB1_BASE are 64 bit.
1286 * Common programming programs 64bit register but upper 32 bits
1287 * are skipped in a4xx and a3xx using ADRENO_REG_SKIP.
1288 */
1289 if (gpudev->reg_offsets->offsets[offset_name] == ADRENO_REG_SKIP)
1290 return false;
1291
1292 return true;
1293}
1294
1295/*
1296 * adreno_readreg() - Read a register by getting its offset from the
1297 * offset array defined in gpudev node
1298 * @adreno_dev: Pointer to the the adreno device
1299 * @offset_name: The register enum that is to be read
1300 * @val: Register value read is placed here
1301 */
1302static inline void adreno_readreg(struct adreno_device *adreno_dev,
1303 enum adreno_regs offset_name, unsigned int *val)
1304{
1305 struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
1306
1307 if (adreno_checkreg_off(adreno_dev, offset_name))
1308 kgsl_regread(KGSL_DEVICE(adreno_dev),
1309 gpudev->reg_offsets->offsets[offset_name], val);
1310 else
1311 *val = 0;
1312}
1313
1314/*
1315 * adreno_writereg() - Write a register by getting its offset from the
1316 * offset array defined in gpudev node
1317 * @adreno_dev: Pointer to the the adreno device
1318 * @offset_name: The register enum that is to be written
1319 * @val: Value to write
1320 */
1321static inline void adreno_writereg(struct adreno_device *adreno_dev,
1322 enum adreno_regs offset_name, unsigned int val)
1323{
1324 struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
1325
1326 if (adreno_checkreg_off(adreno_dev, offset_name))
1327 kgsl_regwrite(KGSL_DEVICE(adreno_dev),
1328 gpudev->reg_offsets->offsets[offset_name], val);
1329}
1330
1331/*
1332 * adreno_getreg() - Returns the offset value of a register from the
1333 * register offset array in the gpudev node
1334 * @adreno_dev: Pointer to the the adreno device
1335 * @offset_name: The register enum whore offset is returned
1336 */
1337static inline unsigned int adreno_getreg(struct adreno_device *adreno_dev,
1338 enum adreno_regs offset_name)
1339{
1340 struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
1341
1342 if (!adreno_checkreg_off(adreno_dev, offset_name))
1343 return ADRENO_REG_REGISTER_MAX;
1344 return gpudev->reg_offsets->offsets[offset_name];
1345}
1346
1347/*
Kyle Pieferb1027b02017-02-10 13:58:58 -08001348 * adreno_read_gmureg() - Read a GMU register by getting its offset from the
1349 * offset array defined in gpudev node
1350 * @adreno_dev: Pointer to the the adreno device
1351 * @offset_name: The register enum that is to be read
1352 * @val: Register value read is placed here
1353 */
1354static inline void adreno_read_gmureg(struct adreno_device *adreno_dev,
1355 enum adreno_regs offset_name, unsigned int *val)
1356{
1357 struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
1358
1359 if (adreno_checkreg_off(adreno_dev, offset_name))
1360 kgsl_gmu_regread(KGSL_DEVICE(adreno_dev),
1361 gpudev->reg_offsets->offsets[offset_name], val);
1362 else
Carter Cooper83454bf2017-03-20 11:26:04 -06001363 *val = 0;
Kyle Pieferb1027b02017-02-10 13:58:58 -08001364}
1365
1366/*
1367 * adreno_write_gmureg() - Write a GMU register by getting its offset from the
1368 * offset array defined in gpudev node
1369 * @adreno_dev: Pointer to the the adreno device
1370 * @offset_name: The register enum that is to be written
1371 * @val: Value to write
1372 */
1373static inline void adreno_write_gmureg(struct adreno_device *adreno_dev,
1374 enum adreno_regs offset_name, unsigned int val)
1375{
1376 struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
1377
1378 if (adreno_checkreg_off(adreno_dev, offset_name))
1379 kgsl_gmu_regwrite(KGSL_DEVICE(adreno_dev),
1380 gpudev->reg_offsets->offsets[offset_name], val);
1381}
1382
1383/*
Shrenuj Bansala419c792016-10-20 14:05:11 -07001384 * adreno_get_int() - Returns the offset value of an interrupt bit from
1385 * the interrupt bit array in the gpudev node
1386 * @adreno_dev: Pointer to the the adreno device
1387 * @bit_name: The interrupt bit enum whose bit is returned
1388 */
1389static inline unsigned int adreno_get_int(struct adreno_device *adreno_dev,
1390 enum adreno_int_bits bit_name)
1391{
1392 struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
1393
1394 if (bit_name >= ADRENO_INT_BITS_MAX)
1395 return -ERANGE;
1396
1397 return gpudev->int_bits[bit_name];
1398}
1399
1400/**
1401 * adreno_gpu_fault() - Return the current state of the GPU
1402 * @adreno_dev: A pointer to the adreno_device to query
1403 *
1404 * Return 0 if there is no fault or positive with the last type of fault that
1405 * occurred
1406 */
1407static inline unsigned int adreno_gpu_fault(struct adreno_device *adreno_dev)
1408{
1409 /* make sure we're reading the latest value */
1410 smp_rmb();
1411 return atomic_read(&adreno_dev->dispatcher.fault);
1412}
1413
1414/**
1415 * adreno_set_gpu_fault() - Set the current fault status of the GPU
1416 * @adreno_dev: A pointer to the adreno_device to set
1417 * @state: fault state to set
1418 *
1419 */
1420static inline void adreno_set_gpu_fault(struct adreno_device *adreno_dev,
1421 int state)
1422{
1423 /* only set the fault bit w/o overwriting other bits */
1424 atomic_add(state, &adreno_dev->dispatcher.fault);
1425
1426 /* make sure other CPUs see the update */
1427 smp_wmb();
1428}
1429
Lynus Vaz43695aa2017-09-01 21:55:23 +05301430static inline bool adreno_gmu_gpu_fault(struct adreno_device *adreno_dev)
1431{
1432 return adreno_gpu_fault(adreno_dev) & ADRENO_GMU_FAULT;
1433}
Shrenuj Bansala419c792016-10-20 14:05:11 -07001434
1435/**
1436 * adreno_clear_gpu_fault() - Clear the GPU fault register
1437 * @adreno_dev: A pointer to an adreno_device structure
1438 *
1439 * Clear the GPU fault status for the adreno device
1440 */
1441
1442static inline void adreno_clear_gpu_fault(struct adreno_device *adreno_dev)
1443{
1444 atomic_set(&adreno_dev->dispatcher.fault, 0);
1445
1446 /* make sure other CPUs see the update */
1447 smp_wmb();
1448}
1449
1450/**
1451 * adreno_gpu_halt() - Return the GPU halt refcount
1452 * @adreno_dev: A pointer to the adreno_device
1453 */
1454static inline int adreno_gpu_halt(struct adreno_device *adreno_dev)
1455{
1456 /* make sure we're reading the latest value */
1457 smp_rmb();
1458 return atomic_read(&adreno_dev->halt);
1459}
1460
1461
1462/**
1463 * adreno_clear_gpu_halt() - Clear the GPU halt refcount
1464 * @adreno_dev: A pointer to the adreno_device
1465 */
1466static inline void adreno_clear_gpu_halt(struct adreno_device *adreno_dev)
1467{
1468 atomic_set(&adreno_dev->halt, 0);
1469
1470 /* make sure other CPUs see the update */
1471 smp_wmb();
1472}
1473
1474/**
1475 * adreno_get_gpu_halt() - Increment GPU halt refcount
1476 * @adreno_dev: A pointer to the adreno_device
1477 */
1478static inline void adreno_get_gpu_halt(struct adreno_device *adreno_dev)
1479{
1480 atomic_inc(&adreno_dev->halt);
1481}
1482
1483/**
1484 * adreno_put_gpu_halt() - Decrement GPU halt refcount
1485 * @adreno_dev: A pointer to the adreno_device
1486 */
1487static inline void adreno_put_gpu_halt(struct adreno_device *adreno_dev)
1488{
1489 /* Make sure the refcount is good */
1490 int ret = atomic_dec_if_positive(&adreno_dev->halt);
1491
1492 WARN(ret < 0, "GPU halt refcount unbalanced\n");
1493}
1494
1495
1496/*
1497 * adreno_vbif_start() - Program VBIF registers, called in device start
1498 * @adreno_dev: Pointer to device whose vbif data is to be programmed
1499 * @vbif_platforms: list register value pair of vbif for a family
1500 * of adreno cores
1501 * @num_platforms: Number of platforms contained in vbif_platforms
1502 */
1503static inline void adreno_vbif_start(struct adreno_device *adreno_dev,
1504 const struct adreno_vbif_platform *vbif_platforms,
1505 int num_platforms)
1506{
1507 int i;
1508 const struct adreno_vbif_data *vbif = NULL;
1509
1510 for (i = 0; i < num_platforms; i++) {
1511 if (vbif_platforms[i].devfunc(adreno_dev)) {
1512 vbif = vbif_platforms[i].vbif;
1513 break;
1514 }
1515 }
1516
1517 while ((vbif != NULL) && (vbif->reg != 0)) {
1518 kgsl_regwrite(KGSL_DEVICE(adreno_dev), vbif->reg, vbif->val);
1519 vbif++;
1520 }
1521}
1522
1523/**
1524 * adreno_set_protected_registers() - Protect the specified range of registers
1525 * from being accessed by the GPU
1526 * @adreno_dev: pointer to the Adreno device
1527 * @index: Pointer to the index of the protect mode register to write to
1528 * @reg: Starting dword register to write
1529 * @mask_len: Size of the mask to protect (# of registers = 2 ** mask_len)
1530 *
1531 * Add the range of registers to the list of protected mode registers that will
1532 * cause an exception if the GPU accesses them. There are 16 available
1533 * protected mode registers. Index is used to specify which register to write
1534 * to - the intent is to call this function multiple times with the same index
1535 * pointer for each range and the registers will be magically programmed in
1536 * incremental fashion
1537 */
1538static inline void adreno_set_protected_registers(
1539 struct adreno_device *adreno_dev, unsigned int *index,
1540 unsigned int reg, int mask_len)
1541{
1542 unsigned int val;
1543 unsigned int base =
1544 adreno_getreg(adreno_dev, ADRENO_REG_CP_PROTECT_REG_0);
1545 unsigned int offset = *index;
1546 unsigned int max_slots = adreno_dev->gpucore->num_protected_regs ?
1547 adreno_dev->gpucore->num_protected_regs : 16;
1548
1549 /* Do we have a free slot? */
1550 if (WARN(*index >= max_slots, "Protected register slots full: %d/%d\n",
1551 *index, max_slots))
1552 return;
1553
1554 /*
1555 * On A4XX targets with more than 16 protected mode registers
1556 * the upper registers are not contiguous with the lower 16
1557 * registers so we have to adjust the base and offset accordingly
1558 */
1559
1560 if (adreno_is_a4xx(adreno_dev) && *index >= 0x10) {
1561 base = A4XX_CP_PROTECT_REG_10;
1562 offset = *index - 0x10;
1563 }
1564
1565 val = 0x60000000 | ((mask_len & 0x1F) << 24) | ((reg << 2) & 0xFFFFF);
1566
1567 kgsl_regwrite(KGSL_DEVICE(adreno_dev), base + offset, val);
1568 *index = *index + 1;
1569}
1570
1571#ifdef CONFIG_DEBUG_FS
1572void adreno_debugfs_init(struct adreno_device *adreno_dev);
1573void adreno_context_debugfs_init(struct adreno_device *adreno_dev,
1574 struct adreno_context *ctx);
1575#else
1576static inline void adreno_debugfs_init(struct adreno_device *adreno_dev) { }
1577static inline void adreno_context_debugfs_init(struct adreno_device *device,
1578 struct adreno_context *context)
1579 { }
1580#endif
1581
1582/**
1583 * adreno_compare_pm4_version() - Compare the PM4 microcode version
1584 * @adreno_dev: Pointer to the adreno_device struct
1585 * @version: Version number to compare again
1586 *
1587 * Compare the current version against the specified version and return -1 if
1588 * the current code is older, 0 if equal or 1 if newer.
1589 */
1590static inline int adreno_compare_pm4_version(struct adreno_device *adreno_dev,
1591 unsigned int version)
1592{
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -07001593 if (adreno_dev->fw[ADRENO_FW_PM4].version == version)
Shrenuj Bansala419c792016-10-20 14:05:11 -07001594 return 0;
1595
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -07001596 return (adreno_dev->fw[ADRENO_FW_PM4].version > version) ? 1 : -1;
Shrenuj Bansala419c792016-10-20 14:05:11 -07001597}
1598
1599/**
1600 * adreno_compare_pfp_version() - Compare the PFP microcode version
1601 * @adreno_dev: Pointer to the adreno_device struct
1602 * @version: Version number to compare against
1603 *
1604 * Compare the current version against the specified version and return -1 if
1605 * the current code is older, 0 if equal or 1 if newer.
1606 */
1607static inline int adreno_compare_pfp_version(struct adreno_device *adreno_dev,
1608 unsigned int version)
1609{
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -07001610 if (adreno_dev->fw[ADRENO_FW_PFP].version == version)
Shrenuj Bansala419c792016-10-20 14:05:11 -07001611 return 0;
1612
Shrenuj Bansalacf1ef42016-06-01 11:11:27 -07001613 return (adreno_dev->fw[ADRENO_FW_PFP].version > version) ? 1 : -1;
Shrenuj Bansala419c792016-10-20 14:05:11 -07001614}
1615
1616/*
1617 * adreno_bootstrap_ucode() - Checks if Ucode bootstrapping is supported
1618 * @adreno_dev: Pointer to the the adreno device
1619 */
1620static inline int adreno_bootstrap_ucode(struct adreno_device *adreno_dev)
1621{
1622 return (ADRENO_FEATURE(adreno_dev, ADRENO_USE_BOOTSTRAP) &&
1623 adreno_compare_pfp_version(adreno_dev,
1624 adreno_dev->gpucore->pfp_bstrp_ver) >= 0) ? 1 : 0;
1625}
1626
1627/**
1628 * adreno_in_preempt_state() - Check if preemption state is equal to given state
1629 * @adreno_dev: Device whose preemption state is checked
1630 * @state: State to compare against
1631 */
1632static inline bool adreno_in_preempt_state(struct adreno_device *adreno_dev,
1633 enum adreno_preempt_states state)
1634{
1635 return atomic_read(&adreno_dev->preempt.state) == state;
1636}
1637/**
1638 * adreno_set_preempt_state() - Set the specified preemption state
1639 * @adreno_dev: Device to change preemption state
1640 * @state: State to set
1641 */
1642static inline void adreno_set_preempt_state(struct adreno_device *adreno_dev,
1643 enum adreno_preempt_states state)
1644{
1645 /*
1646 * atomic_set doesn't use barriers, so we need to do it ourselves. One
1647 * before...
1648 */
1649 smp_wmb();
1650 atomic_set(&adreno_dev->preempt.state, state);
1651
1652 /* ... and one after */
1653 smp_wmb();
1654}
1655
Harshdeep Dhatt38e57d72017-08-30 13:24:07 -06001656static inline bool adreno_is_preemption_enabled(
1657 struct adreno_device *adreno_dev)
1658{
Harshdeep Dhatt7ee8a862017-11-20 17:51:54 -07001659 return test_bit(ADRENO_DEVICE_PREEMPTION, &adreno_dev->priv);
Harshdeep Dhatt38e57d72017-08-30 13:24:07 -06001660}
Shrenuj Bansala419c792016-10-20 14:05:11 -07001661/**
1662 * adreno_ctx_get_rb() - Return the ringbuffer that a context should
1663 * use based on priority
1664 * @adreno_dev: The adreno device that context is using
1665 * @drawctxt: The context pointer
1666 */
1667static inline struct adreno_ringbuffer *adreno_ctx_get_rb(
1668 struct adreno_device *adreno_dev,
1669 struct adreno_context *drawctxt)
1670{
1671 struct kgsl_context *context;
1672 int level;
1673
1674 if (!drawctxt)
1675 return NULL;
1676
1677 context = &(drawctxt->base);
1678
1679 /*
1680 * If preemption is disabled then everybody needs to go on the same
1681 * ringbuffer
1682 */
1683
Harshdeep Dhatt7ee8a862017-11-20 17:51:54 -07001684 if (!adreno_is_preemption_enabled(adreno_dev))
Shrenuj Bansala419c792016-10-20 14:05:11 -07001685 return &(adreno_dev->ringbuffers[0]);
1686
1687 /*
1688 * Math to convert the priority field in context structure to an RB ID.
1689 * Divide up the context priority based on number of ringbuffer levels.
1690 */
1691 level = context->priority / adreno_dev->num_ringbuffers;
1692 if (level < adreno_dev->num_ringbuffers)
1693 return &(adreno_dev->ringbuffers[level]);
1694 else
1695 return &(adreno_dev->ringbuffers[
1696 adreno_dev->num_ringbuffers - 1]);
1697}
1698
1699/*
1700 * adreno_compare_prio_level() - Compares 2 priority levels based on enum values
1701 * @p1: First priority level
1702 * @p2: Second priority level
1703 *
1704 * Returns greater than 0 if p1 is higher priority, 0 if levels are equal else
1705 * less than 0
1706 */
1707static inline int adreno_compare_prio_level(int p1, int p2)
1708{
1709 return p2 - p1;
1710}
1711
1712void adreno_readreg64(struct adreno_device *adreno_dev,
1713 enum adreno_regs lo, enum adreno_regs hi, uint64_t *val);
1714
1715void adreno_writereg64(struct adreno_device *adreno_dev,
1716 enum adreno_regs lo, enum adreno_regs hi, uint64_t val);
1717
1718unsigned int adreno_get_rptr(struct adreno_ringbuffer *rb);
1719
1720static inline bool adreno_rb_empty(struct adreno_ringbuffer *rb)
1721{
1722 return (adreno_get_rptr(rb) == rb->wptr);
1723}
1724
1725static inline bool adreno_soft_fault_detect(struct adreno_device *adreno_dev)
1726{
1727 return adreno_dev->fast_hang_detect &&
1728 !test_bit(ADRENO_DEVICE_ISDB_ENABLED, &adreno_dev->priv);
1729}
1730
1731static inline bool adreno_long_ib_detect(struct adreno_device *adreno_dev)
1732{
1733 return adreno_dev->long_ib_detect &&
1734 !test_bit(ADRENO_DEVICE_ISDB_ENABLED, &adreno_dev->priv);
1735}
1736
1737/*
1738 * adreno_support_64bit() - Check the feature flag only if it is in
1739 * 64bit kernel otherwise return false
1740 * adreno_dev: The adreno device
1741 */
1742#if BITS_PER_LONG == 64
1743static inline bool adreno_support_64bit(struct adreno_device *adreno_dev)
1744{
1745 return ADRENO_FEATURE(adreno_dev, ADRENO_64BIT);
1746}
1747#else
1748static inline bool adreno_support_64bit(struct adreno_device *adreno_dev)
1749{
1750 return false;
1751}
1752#endif /*BITS_PER_LONG*/
1753
1754static inline void adreno_ringbuffer_set_global(
1755 struct adreno_device *adreno_dev, int name)
1756{
1757 struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
1758
1759 kgsl_sharedmem_writel(device,
1760 &adreno_dev->ringbuffers[0].pagetable_desc,
1761 PT_INFO_OFFSET(current_global_ptname), name);
1762}
1763
1764static inline void adreno_ringbuffer_set_pagetable(struct adreno_ringbuffer *rb,
1765 struct kgsl_pagetable *pt)
1766{
1767 struct adreno_device *adreno_dev = ADRENO_RB_DEVICE(rb);
1768 struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
1769 unsigned long flags;
1770
1771 spin_lock_irqsave(&rb->preempt_lock, flags);
1772
1773 kgsl_sharedmem_writel(device, &rb->pagetable_desc,
1774 PT_INFO_OFFSET(current_rb_ptname), pt->name);
1775
1776 kgsl_sharedmem_writeq(device, &rb->pagetable_desc,
1777 PT_INFO_OFFSET(ttbr0), kgsl_mmu_pagetable_get_ttbr0(pt));
1778
1779 kgsl_sharedmem_writel(device, &rb->pagetable_desc,
1780 PT_INFO_OFFSET(contextidr),
1781 kgsl_mmu_pagetable_get_contextidr(pt));
1782
1783 spin_unlock_irqrestore(&rb->preempt_lock, flags);
1784}
1785
Abhilash Kumarf1af1042017-07-14 13:13:44 +05301786static inline bool is_power_counter_overflow(struct adreno_device *adreno_dev,
1787 unsigned int reg, unsigned int prev_val, unsigned int *perfctr_pwr_hi)
1788{
1789 unsigned int val;
1790 bool ret = false;
1791
1792 /*
1793 * If prev_val is zero, it is first read after perf counter reset.
1794 * So set perfctr_pwr_hi register to zero.
1795 */
1796 if (prev_val == 0) {
1797 *perfctr_pwr_hi = 0;
1798 return ret;
1799 }
1800 adreno_readreg(adreno_dev, ADRENO_REG_RBBM_PERFCTR_RBBM_0_HI, &val);
1801 if (val != *perfctr_pwr_hi) {
1802 *perfctr_pwr_hi = val;
1803 ret = true;
1804 }
1805 return ret;
1806}
1807
Shrenuj Bansala419c792016-10-20 14:05:11 -07001808static inline unsigned int counter_delta(struct kgsl_device *device,
1809 unsigned int reg, unsigned int *counter)
1810{
Abhilash Kumarf1af1042017-07-14 13:13:44 +05301811 struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
Shrenuj Bansala419c792016-10-20 14:05:11 -07001812 unsigned int val;
1813 unsigned int ret = 0;
Abhilash Kumarf1af1042017-07-14 13:13:44 +05301814 bool overflow = true;
1815 static unsigned int perfctr_pwr_hi;
Shrenuj Bansala419c792016-10-20 14:05:11 -07001816
1817 /* Read the value */
1818 kgsl_regread(device, reg, &val);
1819
Abhilash Kumarf1af1042017-07-14 13:13:44 +05301820 if (adreno_is_a5xx(adreno_dev) && reg == adreno_getreg
1821 (adreno_dev, ADRENO_REG_RBBM_PERFCTR_RBBM_0_LO))
1822 overflow = is_power_counter_overflow(adreno_dev, reg,
1823 *counter, &perfctr_pwr_hi);
1824
Shrenuj Bansala419c792016-10-20 14:05:11 -07001825 /* Return 0 for the first read */
1826 if (*counter != 0) {
Abhilash Kumarf1af1042017-07-14 13:13:44 +05301827 if (val >= *counter) {
Shrenuj Bansala419c792016-10-20 14:05:11 -07001828 ret = val - *counter;
Abhilash Kumarf1af1042017-07-14 13:13:44 +05301829 } else if (overflow == true) {
1830 ret = (0xFFFFFFFF - *counter) + val;
1831 } else {
1832 /*
1833 * Since KGSL got abnormal value from the counter,
1834 * We will drop the value from being accumulated.
1835 */
1836 pr_warn_once("KGSL: Abnormal value :0x%x (0x%x) from perf counter : 0x%x\n",
1837 val, *counter, reg);
1838 return 0;
1839 }
Shrenuj Bansala419c792016-10-20 14:05:11 -07001840 }
1841
1842 *counter = val;
1843 return ret;
1844}
Carter Cooper05f2a6b2017-03-20 11:43:11 -06001845
1846static inline int adreno_perfcntr_active_oob_get(
1847 struct adreno_device *adreno_dev)
1848{
1849 struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
1850 int ret;
1851
1852 ret = kgsl_active_count_get(KGSL_DEVICE(adreno_dev));
1853 if (ret)
1854 return ret;
1855
1856 if (gpudev->oob_set) {
1857 ret = gpudev->oob_set(adreno_dev, OOB_PERFCNTR_SET_MASK,
1858 OOB_PERFCNTR_CHECK_MASK,
1859 OOB_PERFCNTR_CLEAR_MASK);
1860 if (ret)
1861 kgsl_active_count_put(KGSL_DEVICE(adreno_dev));
1862 }
1863
1864 return ret;
1865}
1866
1867static inline void adreno_perfcntr_active_oob_put(
1868 struct adreno_device *adreno_dev)
1869{
1870 struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
1871
1872 if (gpudev->oob_clear)
1873 gpudev->oob_clear(adreno_dev, OOB_PERFCNTR_CLEAR_MASK);
1874
1875 kgsl_active_count_put(KGSL_DEVICE(adreno_dev));
1876}
1877
Rajesh Kemisetti77b82ed2017-09-24 20:42:41 +05301878static inline bool adreno_has_gbif(struct adreno_device *adreno_dev)
1879{
1880 if (adreno_is_a615(adreno_dev))
1881 return true;
1882 else
1883 return false;
1884}
1885
1886/**
1887 * adreno_wait_for_vbif_halt_ack() - wait for VBIF acknowledgment
1888 * for given HALT request.
1889 * @ack_reg: register offset to wait for acknowledge
1890 */
1891static inline int adreno_wait_for_vbif_halt_ack(struct kgsl_device *device,
Rajesh Kemisettid1ca9542017-10-18 15:35:41 +05301892 int ack_reg, unsigned int mask)
Rajesh Kemisetti77b82ed2017-09-24 20:42:41 +05301893{
1894 struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
Rajesh Kemisetti77b82ed2017-09-24 20:42:41 +05301895 unsigned long wait_for_vbif;
Rajesh Kemisetti77b82ed2017-09-24 20:42:41 +05301896 unsigned int val;
1897 int ret = 0;
1898
1899 /* wait for the transactions to clear */
Rajesh Kemisettid1ca9542017-10-18 15:35:41 +05301900 wait_for_vbif = jiffies + msecs_to_jiffies(VBIF_RESET_ACK_TIMEOUT);
Rajesh Kemisetti77b82ed2017-09-24 20:42:41 +05301901 while (1) {
1902 adreno_readreg(adreno_dev, ack_reg,
1903 &val);
1904 if ((val & mask) == mask)
1905 break;
1906 if (time_after(jiffies, wait_for_vbif)) {
1907 KGSL_DRV_ERR(device,
1908 "Wait limit reached for VBIF XIN Halt\n");
1909 ret = -ETIMEDOUT;
1910 break;
1911 }
1912 }
1913
1914 return ret;
1915}
1916
Kyle Piefere923b7a2017-03-28 17:31:48 -07001917/**
1918 * adreno_vbif_clear_pending_transactions() - Clear transactions in VBIF pipe
1919 * @device: Pointer to the device whose VBIF pipe is to be cleared
1920 */
1921static inline int adreno_vbif_clear_pending_transactions(
1922 struct kgsl_device *device)
1923{
1924 struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
1925 struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
1926 unsigned int mask = gpudev->vbif_xin_halt_ctrl0_mask;
Kyle Piefere923b7a2017-03-28 17:31:48 -07001927 int ret = 0;
1928
Rajesh Kemisetti77b82ed2017-09-24 20:42:41 +05301929 if (adreno_has_gbif(adreno_dev)) {
Rajesh Kemisettid1ca9542017-10-18 15:35:41 +05301930 /*
1931 * Halt GBIF GX first and then CX part.
1932 * Need to release CX Halt explicitly in case of SW_RESET.
1933 * GX Halt release will be taken care by SW_RESET internally.
1934 */
Deepak Kumar7e39bf62017-12-28 16:29:27 +05301935 if (gpudev->gx_is_on(adreno_dev)) {
1936 adreno_writereg(adreno_dev, ADRENO_REG_RBBM_GPR0_CNTL,
1937 GBIF_HALT_REQUEST);
1938 ret = adreno_wait_for_vbif_halt_ack(device,
1939 ADRENO_REG_RBBM_VBIF_GX_RESET_STATUS,
1940 VBIF_RESET_ACK_MASK);
1941 if (ret)
1942 return ret;
1943 }
Rajesh Kemisettid1ca9542017-10-18 15:35:41 +05301944
Rajesh Kemisetti77b82ed2017-09-24 20:42:41 +05301945 adreno_writereg(adreno_dev, ADRENO_REG_GBIF_HALT, mask);
1946 ret = adreno_wait_for_vbif_halt_ack(device,
Rajesh Kemisettid1ca9542017-10-18 15:35:41 +05301947 ADRENO_REG_GBIF_HALT_ACK, mask);
Rajesh Kemisetti77b82ed2017-09-24 20:42:41 +05301948 } else {
1949 adreno_writereg(adreno_dev, ADRENO_REG_VBIF_XIN_HALT_CTRL0,
1950 mask);
1951 ret = adreno_wait_for_vbif_halt_ack(device,
Rajesh Kemisettid1ca9542017-10-18 15:35:41 +05301952 ADRENO_REG_VBIF_XIN_HALT_CTRL1, mask);
Rajesh Kemisetti77b82ed2017-09-24 20:42:41 +05301953 adreno_writereg(adreno_dev, ADRENO_REG_VBIF_XIN_HALT_CTRL0, 0);
Kyle Piefere923b7a2017-03-28 17:31:48 -07001954 }
Kyle Piefere923b7a2017-03-28 17:31:48 -07001955 return ret;
1956}
1957
Harshdeep Dhatt56107782017-12-05 09:54:47 -07001958int adreno_gmu_fenced_write(struct adreno_device *adreno_dev,
Harshdeep Dhatt8f78d5f2017-11-01 14:24:36 -06001959 enum adreno_regs offset, unsigned int val,
1960 unsigned int fence_mask);
Shrenuj Bansala419c792016-10-20 14:05:11 -07001961#endif /*__ADRENO_H */