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