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