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