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