| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (C) 2013 Red Hat |
|---|
| 3 | 4 | * Author: Rob Clark <robdclark@gmail.com> |
|---|
| 4 | 5 | * |
|---|
| 5 | | - * Copyright (c) 2014,2017 The Linux Foundation. All rights reserved. |
|---|
| 6 | | - * |
|---|
| 7 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 8 | | - * under the terms of the GNU General Public License version 2 as published by |
|---|
| 9 | | - * the Free Software Foundation. |
|---|
| 10 | | - * |
|---|
| 11 | | - * This program is distributed in the hope that it will be useful, but WITHOUT |
|---|
| 12 | | - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|---|
| 13 | | - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
|---|
| 14 | | - * more details. |
|---|
| 15 | | - * |
|---|
| 16 | | - * You should have received a copy of the GNU General Public License along with |
|---|
| 17 | | - * this program. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 6 | + * Copyright (c) 2014,2017, 2019 The Linux Foundation. All rights reserved. |
|---|
| 18 | 7 | */ |
|---|
| 19 | 8 | |
|---|
| 20 | 9 | #ifndef __ADRENO_GPU_H__ |
|---|
| 21 | 10 | #define __ADRENO_GPU_H__ |
|---|
| 22 | 11 | |
|---|
| 23 | 12 | #include <linux/firmware.h> |
|---|
| 13 | +#include <linux/iopoll.h> |
|---|
| 24 | 14 | |
|---|
| 25 | 15 | #include "msm_gpu.h" |
|---|
| 26 | 16 | |
|---|
| 27 | 17 | #include "adreno_common.xml.h" |
|---|
| 28 | 18 | #include "adreno_pm4.xml.h" |
|---|
| 29 | 19 | |
|---|
| 30 | | -#define REG_ADRENO_DEFINE(_offset, _reg) [_offset] = (_reg) + 1 |
|---|
| 31 | | -#define REG_SKIP ~0 |
|---|
| 32 | | -#define REG_ADRENO_SKIP(_offset) [_offset] = REG_SKIP |
|---|
| 33 | | - |
|---|
| 34 | | -/** |
|---|
| 35 | | - * adreno_regs: List of registers that are used in across all |
|---|
| 36 | | - * 3D devices. Each device type has different offset value for the same |
|---|
| 37 | | - * register, so an array of register offsets are declared for every device |
|---|
| 38 | | - * and are indexed by the enumeration values defined in this enum |
|---|
| 39 | | - */ |
|---|
| 40 | | -enum adreno_regs { |
|---|
| 41 | | - REG_ADRENO_CP_RB_BASE, |
|---|
| 42 | | - REG_ADRENO_CP_RB_BASE_HI, |
|---|
| 43 | | - REG_ADRENO_CP_RB_RPTR_ADDR, |
|---|
| 44 | | - REG_ADRENO_CP_RB_RPTR_ADDR_HI, |
|---|
| 45 | | - REG_ADRENO_CP_RB_RPTR, |
|---|
| 46 | | - REG_ADRENO_CP_RB_WPTR, |
|---|
| 47 | | - REG_ADRENO_CP_RB_CNTL, |
|---|
| 48 | | - REG_ADRENO_REGISTER_MAX, |
|---|
| 49 | | -}; |
|---|
| 20 | +extern bool snapshot_debugbus; |
|---|
| 50 | 21 | |
|---|
| 51 | 22 | enum { |
|---|
| 52 | 23 | ADRENO_FW_PM4 = 0, |
|---|
| .. | .. |
|---|
| 57 | 28 | ADRENO_FW_MAX, |
|---|
| 58 | 29 | }; |
|---|
| 59 | 30 | |
|---|
| 60 | | -enum adreno_quirks { |
|---|
| 61 | | - ADRENO_QUIRK_TWO_PASS_USE_WFI = 1, |
|---|
| 62 | | - ADRENO_QUIRK_FAULT_DETECT_MASK = 2, |
|---|
| 63 | | -}; |
|---|
| 31 | +#define ADRENO_QUIRK_TWO_PASS_USE_WFI BIT(0) |
|---|
| 32 | +#define ADRENO_QUIRK_FAULT_DETECT_MASK BIT(1) |
|---|
| 33 | +#define ADRENO_QUIRK_LMLOADKILL_DISABLE BIT(2) |
|---|
| 64 | 34 | |
|---|
| 65 | 35 | struct adreno_rev { |
|---|
| 66 | 36 | uint8_t core; |
|---|
| .. | .. |
|---|
| 77 | 47 | int (*get_timestamp)(struct msm_gpu *gpu, uint64_t *value); |
|---|
| 78 | 48 | }; |
|---|
| 79 | 49 | |
|---|
| 50 | +struct adreno_reglist { |
|---|
| 51 | + u32 offset; |
|---|
| 52 | + u32 value; |
|---|
| 53 | +}; |
|---|
| 54 | + |
|---|
| 55 | +extern const struct adreno_reglist a630_hwcg[], a640_hwcg[], a650_hwcg[]; |
|---|
| 56 | + |
|---|
| 80 | 57 | struct adreno_info { |
|---|
| 81 | 58 | struct adreno_rev rev; |
|---|
| 82 | 59 | uint32_t revn; |
|---|
| 83 | 60 | const char *name; |
|---|
| 84 | 61 | const char *fw[ADRENO_FW_MAX]; |
|---|
| 85 | 62 | uint32_t gmem; |
|---|
| 86 | | - enum adreno_quirks quirks; |
|---|
| 63 | + u64 quirks; |
|---|
| 87 | 64 | struct msm_gpu *(*init)(struct drm_device *dev); |
|---|
| 88 | 65 | const char *zapfw; |
|---|
| 89 | 66 | u32 inactive_period; |
|---|
| 67 | + const struct adreno_reglist *hwcg; |
|---|
| 90 | 68 | }; |
|---|
| 91 | 69 | |
|---|
| 92 | 70 | const struct adreno_info *adreno_info(struct adreno_rev rev); |
|---|
| .. | .. |
|---|
| 135 | 113 | }; |
|---|
| 136 | 114 | #define to_adreno_gpu(x) container_of(x, struct adreno_gpu, base) |
|---|
| 137 | 115 | |
|---|
| 116 | +struct adreno_ocmem { |
|---|
| 117 | + struct ocmem *ocmem; |
|---|
| 118 | + unsigned long base; |
|---|
| 119 | + void *hdl; |
|---|
| 120 | +}; |
|---|
| 121 | + |
|---|
| 138 | 122 | /* platform config data (ie. from DT, or pdata) */ |
|---|
| 139 | 123 | struct adreno_platform_config { |
|---|
| 140 | 124 | struct adreno_rev rev; |
|---|
| .. | .. |
|---|
| 154 | 138 | __ret; \ |
|---|
| 155 | 139 | }) |
|---|
| 156 | 140 | |
|---|
| 157 | | - |
|---|
| 158 | | -static inline bool adreno_is_a3xx(struct adreno_gpu *gpu) |
|---|
| 141 | +static inline bool adreno_is_a2xx(struct adreno_gpu *gpu) |
|---|
| 159 | 142 | { |
|---|
| 160 | | - return (gpu->revn >= 300) && (gpu->revn < 400); |
|---|
| 143 | + return (gpu->revn < 300); |
|---|
| 144 | +} |
|---|
| 145 | + |
|---|
| 146 | +static inline bool adreno_is_a20x(struct adreno_gpu *gpu) |
|---|
| 147 | +{ |
|---|
| 148 | + return (gpu->revn < 210); |
|---|
| 149 | +} |
|---|
| 150 | + |
|---|
| 151 | +static inline bool adreno_is_a225(struct adreno_gpu *gpu) |
|---|
| 152 | +{ |
|---|
| 153 | + return gpu->revn == 225; |
|---|
| 161 | 154 | } |
|---|
| 162 | 155 | |
|---|
| 163 | 156 | static inline bool adreno_is_a305(struct adreno_gpu *gpu) |
|---|
| .. | .. |
|---|
| 186 | 179 | return adreno_is_a330(gpu) && (gpu->rev.patchid > 0); |
|---|
| 187 | 180 | } |
|---|
| 188 | 181 | |
|---|
| 189 | | -static inline bool adreno_is_a4xx(struct adreno_gpu *gpu) |
|---|
| 182 | +static inline int adreno_is_a405(struct adreno_gpu *gpu) |
|---|
| 190 | 183 | { |
|---|
| 191 | | - return (gpu->revn >= 400) && (gpu->revn < 500); |
|---|
| 184 | + return gpu->revn == 405; |
|---|
| 192 | 185 | } |
|---|
| 193 | 186 | |
|---|
| 194 | 187 | static inline int adreno_is_a420(struct adreno_gpu *gpu) |
|---|
| .. | .. |
|---|
| 201 | 194 | return gpu->revn == 430; |
|---|
| 202 | 195 | } |
|---|
| 203 | 196 | |
|---|
| 197 | +static inline int adreno_is_a510(struct adreno_gpu *gpu) |
|---|
| 198 | +{ |
|---|
| 199 | + return gpu->revn == 510; |
|---|
| 200 | +} |
|---|
| 201 | + |
|---|
| 204 | 202 | static inline int adreno_is_a530(struct adreno_gpu *gpu) |
|---|
| 205 | 203 | { |
|---|
| 206 | 204 | return gpu->revn == 530; |
|---|
| 205 | +} |
|---|
| 206 | + |
|---|
| 207 | +static inline int adreno_is_a540(struct adreno_gpu *gpu) |
|---|
| 208 | +{ |
|---|
| 209 | + return gpu->revn == 540; |
|---|
| 210 | +} |
|---|
| 211 | + |
|---|
| 212 | +static inline int adreno_is_a618(struct adreno_gpu *gpu) |
|---|
| 213 | +{ |
|---|
| 214 | + return gpu->revn == 618; |
|---|
| 215 | +} |
|---|
| 216 | + |
|---|
| 217 | +static inline int adreno_is_a630(struct adreno_gpu *gpu) |
|---|
| 218 | +{ |
|---|
| 219 | + return gpu->revn == 630; |
|---|
| 220 | +} |
|---|
| 221 | + |
|---|
| 222 | +static inline int adreno_is_a640(struct adreno_gpu *gpu) |
|---|
| 223 | +{ |
|---|
| 224 | + return gpu->revn == 640; |
|---|
| 225 | +} |
|---|
| 226 | + |
|---|
| 227 | +static inline int adreno_is_a650(struct adreno_gpu *gpu) |
|---|
| 228 | +{ |
|---|
| 229 | + return gpu->revn == 650; |
|---|
| 207 | 230 | } |
|---|
| 208 | 231 | |
|---|
| 209 | 232 | int adreno_get_param(struct msm_gpu *gpu, uint32_t param, uint64_t *value); |
|---|
| .. | .. |
|---|
| 213 | 236 | const struct firmware *fw, u64 *iova); |
|---|
| 214 | 237 | int adreno_hw_init(struct msm_gpu *gpu); |
|---|
| 215 | 238 | void adreno_recover(struct msm_gpu *gpu); |
|---|
| 216 | | -void adreno_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit, |
|---|
| 217 | | - struct msm_file_private *ctx); |
|---|
| 218 | | -void adreno_flush(struct msm_gpu *gpu, struct msm_ringbuffer *ring); |
|---|
| 239 | +void adreno_flush(struct msm_gpu *gpu, struct msm_ringbuffer *ring, u32 reg); |
|---|
| 219 | 240 | bool adreno_idle(struct msm_gpu *gpu, struct msm_ringbuffer *ring); |
|---|
| 220 | 241 | #if defined(CONFIG_DEBUG_FS) || defined(CONFIG_DEV_COREDUMP) |
|---|
| 221 | 242 | void adreno_show(struct msm_gpu *gpu, struct msm_gpu_state *state, |
|---|
| .. | .. |
|---|
| 225 | 246 | void adreno_dump(struct msm_gpu *gpu); |
|---|
| 226 | 247 | void adreno_wait_ring(struct msm_ringbuffer *ring, uint32_t ndwords); |
|---|
| 227 | 248 | struct msm_ringbuffer *adreno_active_ring(struct msm_gpu *gpu); |
|---|
| 249 | + |
|---|
| 250 | +int adreno_gpu_ocmem_init(struct device *dev, struct adreno_gpu *adreno_gpu, |
|---|
| 251 | + struct adreno_ocmem *ocmem); |
|---|
| 252 | +void adreno_gpu_ocmem_cleanup(struct adreno_ocmem *ocmem); |
|---|
| 228 | 253 | |
|---|
| 229 | 254 | int adreno_gpu_init(struct drm_device *drm, struct platform_device *pdev, |
|---|
| 230 | 255 | struct adreno_gpu *gpu, const struct adreno_gpu_funcs *funcs, |
|---|
| .. | .. |
|---|
| 236 | 261 | |
|---|
| 237 | 262 | int adreno_gpu_state_get(struct msm_gpu *gpu, struct msm_gpu_state *state); |
|---|
| 238 | 263 | int adreno_gpu_state_put(struct msm_gpu_state *state); |
|---|
| 264 | + |
|---|
| 265 | +/* |
|---|
| 266 | + * Common helper function to initialize the default address space for arm-smmu |
|---|
| 267 | + * attached targets |
|---|
| 268 | + */ |
|---|
| 269 | +struct msm_gem_address_space * |
|---|
| 270 | +adreno_iommu_create_address_space(struct msm_gpu *gpu, |
|---|
| 271 | + struct platform_device *pdev); |
|---|
| 272 | + |
|---|
| 273 | +/* |
|---|
| 274 | + * For a5xx and a6xx targets load the zap shader that is used to pull the GPU |
|---|
| 275 | + * out of secure mode |
|---|
| 276 | + */ |
|---|
| 277 | +int adreno_zap_shader_load(struct msm_gpu *gpu, u32 pasid); |
|---|
| 239 | 278 | |
|---|
| 240 | 279 | /* ringbuffer helpers (the parts that are adreno specific) */ |
|---|
| 241 | 280 | |
|---|
| .. | .. |
|---|
| 291 | 330 | ((opcode & 0x7F) << 16) | (PM4_PARITY(opcode) << 23)); |
|---|
| 292 | 331 | } |
|---|
| 293 | 332 | |
|---|
| 294 | | -/* |
|---|
| 295 | | - * adreno_reg_check() - Checks the validity of a register enum |
|---|
| 296 | | - * @gpu: Pointer to struct adreno_gpu |
|---|
| 297 | | - * @offset_name: The register enum that is checked |
|---|
| 298 | | - */ |
|---|
| 299 | | -static inline bool adreno_reg_check(struct adreno_gpu *gpu, |
|---|
| 300 | | - enum adreno_regs offset_name) |
|---|
| 301 | | -{ |
|---|
| 302 | | - if (offset_name >= REG_ADRENO_REGISTER_MAX || |
|---|
| 303 | | - !gpu->reg_offsets[offset_name]) { |
|---|
| 304 | | - BUG(); |
|---|
| 305 | | - } |
|---|
| 306 | | - |
|---|
| 307 | | - /* |
|---|
| 308 | | - * REG_SKIP is a special value that tell us that the register in |
|---|
| 309 | | - * question isn't implemented on target but don't trigger a BUG(). This |
|---|
| 310 | | - * is used to cleanly implement adreno_gpu_write64() and |
|---|
| 311 | | - * adreno_gpu_read64() in a generic fashion |
|---|
| 312 | | - */ |
|---|
| 313 | | - if (gpu->reg_offsets[offset_name] == REG_SKIP) |
|---|
| 314 | | - return false; |
|---|
| 315 | | - |
|---|
| 316 | | - return true; |
|---|
| 317 | | -} |
|---|
| 318 | | - |
|---|
| 319 | | -static inline u32 adreno_gpu_read(struct adreno_gpu *gpu, |
|---|
| 320 | | - enum adreno_regs offset_name) |
|---|
| 321 | | -{ |
|---|
| 322 | | - u32 reg = gpu->reg_offsets[offset_name]; |
|---|
| 323 | | - u32 val = 0; |
|---|
| 324 | | - if(adreno_reg_check(gpu,offset_name)) |
|---|
| 325 | | - val = gpu_read(&gpu->base, reg - 1); |
|---|
| 326 | | - return val; |
|---|
| 327 | | -} |
|---|
| 328 | | - |
|---|
| 329 | | -static inline void adreno_gpu_write(struct adreno_gpu *gpu, |
|---|
| 330 | | - enum adreno_regs offset_name, u32 data) |
|---|
| 331 | | -{ |
|---|
| 332 | | - u32 reg = gpu->reg_offsets[offset_name]; |
|---|
| 333 | | - if(adreno_reg_check(gpu, offset_name)) |
|---|
| 334 | | - gpu_write(&gpu->base, reg - 1, data); |
|---|
| 335 | | -} |
|---|
| 336 | | - |
|---|
| 333 | +struct msm_gpu *a2xx_gpu_init(struct drm_device *dev); |
|---|
| 337 | 334 | struct msm_gpu *a3xx_gpu_init(struct drm_device *dev); |
|---|
| 338 | 335 | struct msm_gpu *a4xx_gpu_init(struct drm_device *dev); |
|---|
| 339 | 336 | struct msm_gpu *a5xx_gpu_init(struct drm_device *dev); |
|---|
| 340 | 337 | struct msm_gpu *a6xx_gpu_init(struct drm_device *dev); |
|---|
| 341 | | - |
|---|
| 342 | | -static inline void adreno_gpu_write64(struct adreno_gpu *gpu, |
|---|
| 343 | | - enum adreno_regs lo, enum adreno_regs hi, u64 data) |
|---|
| 344 | | -{ |
|---|
| 345 | | - adreno_gpu_write(gpu, lo, lower_32_bits(data)); |
|---|
| 346 | | - adreno_gpu_write(gpu, hi, upper_32_bits(data)); |
|---|
| 347 | | -} |
|---|
| 348 | 338 | |
|---|
| 349 | 339 | static inline uint32_t get_wptr(struct msm_ringbuffer *ring) |
|---|
| 350 | 340 | { |
|---|
| .. | .. |
|---|
| 375 | 365 | ((1 << 29) \ |
|---|
| 376 | 366 | ((ilog2((_len)) & 0x1F) << 24) | (((_reg) << 2) & 0xFFFFF)) |
|---|
| 377 | 367 | |
|---|
| 368 | + |
|---|
| 369 | +#define gpu_poll_timeout(gpu, addr, val, cond, interval, timeout) \ |
|---|
| 370 | + readl_poll_timeout((gpu)->mmio + ((addr) << 2), val, cond, \ |
|---|
| 371 | + interval, timeout) |
|---|
| 372 | + |
|---|
| 378 | 373 | #endif /* __ADRENO_GPU_H__ */ |
|---|