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