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