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