| .. | .. |
|---|
| 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 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 6 | | - * under the terms of the GNU General Public License version 2 as published by |
|---|
| 7 | | - * the Free Software Foundation. |
|---|
| 8 | | - * |
|---|
| 9 | | - * This program is distributed in the hope that it will be useful, but WITHOUT |
|---|
| 10 | | - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|---|
| 11 | | - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
|---|
| 12 | | - * more details. |
|---|
| 13 | | - * |
|---|
| 14 | | - * You should have received a copy of the GNU General Public License along with |
|---|
| 15 | | - * this program. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 16 | 5 | */ |
|---|
| 17 | 6 | |
|---|
| 18 | 7 | #ifndef __MSM_GPU_H__ |
|---|
| 19 | 8 | #define __MSM_GPU_H__ |
|---|
| 20 | 9 | |
|---|
| 10 | +#include <linux/adreno-smmu-priv.h> |
|---|
| 21 | 11 | #include <linux/clk.h> |
|---|
| 12 | +#include <linux/interconnect.h> |
|---|
| 13 | +#include <linux/pm_opp.h> |
|---|
| 22 | 14 | #include <linux/regulator/consumer.h> |
|---|
| 23 | 15 | |
|---|
| 24 | 16 | #include "msm_drv.h" |
|---|
| 25 | 17 | #include "msm_fence.h" |
|---|
| 26 | 18 | #include "msm_ringbuffer.h" |
|---|
| 19 | +#include "msm_gem.h" |
|---|
| 27 | 20 | |
|---|
| 28 | 21 | struct msm_gem_submit; |
|---|
| 29 | 22 | struct msm_gpu_perfcntr; |
|---|
| .. | .. |
|---|
| 31 | 24 | |
|---|
| 32 | 25 | struct msm_gpu_config { |
|---|
| 33 | 26 | const char *ioname; |
|---|
| 34 | | - const char *irqname; |
|---|
| 35 | | - uint64_t va_start; |
|---|
| 36 | | - uint64_t va_end; |
|---|
| 37 | 27 | unsigned int nr_rings; |
|---|
| 38 | 28 | }; |
|---|
| 39 | 29 | |
|---|
| .. | .. |
|---|
| 56 | 46 | int (*hw_init)(struct msm_gpu *gpu); |
|---|
| 57 | 47 | int (*pm_suspend)(struct msm_gpu *gpu); |
|---|
| 58 | 48 | int (*pm_resume)(struct msm_gpu *gpu); |
|---|
| 59 | | - void (*submit)(struct msm_gpu *gpu, struct msm_gem_submit *submit, |
|---|
| 60 | | - struct msm_file_private *ctx); |
|---|
| 49 | + void (*submit)(struct msm_gpu *gpu, struct msm_gem_submit *submit); |
|---|
| 61 | 50 | void (*flush)(struct msm_gpu *gpu, struct msm_ringbuffer *ring); |
|---|
| 62 | 51 | irqreturn_t (*irq)(struct msm_gpu *irq); |
|---|
| 63 | 52 | struct msm_ringbuffer *(*active_ring)(struct msm_gpu *gpu); |
|---|
| .. | .. |
|---|
| 68 | 57 | void (*show)(struct msm_gpu *gpu, struct msm_gpu_state *state, |
|---|
| 69 | 58 | struct drm_printer *p); |
|---|
| 70 | 59 | /* for generation specific debugfs: */ |
|---|
| 71 | | - int (*debugfs_init)(struct msm_gpu *gpu, struct drm_minor *minor); |
|---|
| 60 | + void (*debugfs_init)(struct msm_gpu *gpu, struct drm_minor *minor); |
|---|
| 72 | 61 | #endif |
|---|
| 73 | | - int (*gpu_busy)(struct msm_gpu *gpu, uint64_t *value); |
|---|
| 62 | + unsigned long (*gpu_busy)(struct msm_gpu *gpu); |
|---|
| 74 | 63 | struct msm_gpu_state *(*gpu_state_get)(struct msm_gpu *gpu); |
|---|
| 75 | 64 | int (*gpu_state_put)(struct msm_gpu_state *state); |
|---|
| 65 | + unsigned long (*gpu_get_freq)(struct msm_gpu *gpu); |
|---|
| 66 | + void (*gpu_set_freq)(struct msm_gpu *gpu, struct dev_pm_opp *opp); |
|---|
| 67 | + struct msm_gem_address_space *(*create_address_space) |
|---|
| 68 | + (struct msm_gpu *gpu, struct platform_device *pdev); |
|---|
| 69 | + struct msm_gem_address_space *(*create_private_address_space) |
|---|
| 70 | + (struct msm_gpu *gpu); |
|---|
| 71 | + uint32_t (*get_rptr)(struct msm_gpu *gpu, struct msm_ringbuffer *ring); |
|---|
| 76 | 72 | }; |
|---|
| 77 | 73 | |
|---|
| 78 | 74 | struct msm_gpu { |
|---|
| .. | .. |
|---|
| 80 | 76 | struct drm_device *dev; |
|---|
| 81 | 77 | struct platform_device *pdev; |
|---|
| 82 | 78 | const struct msm_gpu_funcs *funcs; |
|---|
| 79 | + |
|---|
| 80 | + struct adreno_smmu_priv adreno_smmu; |
|---|
| 83 | 81 | |
|---|
| 84 | 82 | /* performance counters (hw & sw): */ |
|---|
| 85 | 83 | spinlock_t perf_lock; |
|---|
| .. | .. |
|---|
| 102 | 100 | /* does gpu need hw_init? */ |
|---|
| 103 | 101 | bool needs_hw_init; |
|---|
| 104 | 102 | |
|---|
| 103 | + /* number of GPU hangs (for all contexts) */ |
|---|
| 104 | + int global_faults; |
|---|
| 105 | + |
|---|
| 105 | 106 | /* worker for handling active-list retiring: */ |
|---|
| 106 | 107 | struct work_struct retire_work; |
|---|
| 107 | 108 | |
|---|
| .. | .. |
|---|
| 116 | 117 | int nr_clocks; |
|---|
| 117 | 118 | struct clk *ebi1_clk, *core_clk, *rbbmtimer_clk; |
|---|
| 118 | 119 | uint32_t fast_rate; |
|---|
| 120 | + |
|---|
| 121 | + /* The gfx-mem interconnect path that's used by all GPU types. */ |
|---|
| 122 | + struct icc_path *icc_path; |
|---|
| 123 | + |
|---|
| 124 | + /* |
|---|
| 125 | + * Second interconnect path for some A3xx and all A4xx GPUs to the |
|---|
| 126 | + * On Chip MEMory (OCMEM). |
|---|
| 127 | + */ |
|---|
| 128 | + struct icc_path *ocmem_icc_path; |
|---|
| 119 | 129 | |
|---|
| 120 | 130 | /* Hang and Inactivity Detection: |
|---|
| 121 | 131 | */ |
|---|
| .. | .. |
|---|
| 135 | 145 | } devfreq; |
|---|
| 136 | 146 | |
|---|
| 137 | 147 | struct msm_gpu_state *crashstate; |
|---|
| 148 | + /* True if the hardware supports expanded apriv (a650 and newer) */ |
|---|
| 149 | + bool hw_apriv; |
|---|
| 138 | 150 | }; |
|---|
| 151 | + |
|---|
| 152 | +static inline struct msm_gpu *dev_to_gpu(struct device *dev) |
|---|
| 153 | +{ |
|---|
| 154 | + struct adreno_smmu_priv *adreno_smmu = dev_get_drvdata(dev); |
|---|
| 155 | + return container_of(adreno_smmu, struct msm_gpu, adreno_smmu); |
|---|
| 156 | +} |
|---|
| 139 | 157 | |
|---|
| 140 | 158 | /* It turns out that all targets use the same ringbuffer size */ |
|---|
| 141 | 159 | #define MSM_GPU_RINGBUFFER_SZ SZ_32K |
|---|
| .. | .. |
|---|
| 177 | 195 | u32 flags; |
|---|
| 178 | 196 | u32 prio; |
|---|
| 179 | 197 | int faults; |
|---|
| 198 | + struct msm_file_private *ctx; |
|---|
| 180 | 199 | struct list_head node; |
|---|
| 181 | 200 | struct kref ref; |
|---|
| 182 | 201 | }; |
|---|
| .. | .. |
|---|
| 185 | 204 | u64 iova; |
|---|
| 186 | 205 | size_t size; |
|---|
| 187 | 206 | void *data; |
|---|
| 207 | + bool encoded; |
|---|
| 188 | 208 | }; |
|---|
| 189 | 209 | |
|---|
| 190 | 210 | struct msm_gpu_state { |
|---|
| .. | .. |
|---|
| 199 | 219 | u32 wptr; |
|---|
| 200 | 220 | void *data; |
|---|
| 201 | 221 | int data_size; |
|---|
| 222 | + bool encoded; |
|---|
| 202 | 223 | } ring[MSM_GPU_MAX_RINGS]; |
|---|
| 203 | 224 | |
|---|
| 204 | 225 | int nr_registers; |
|---|
| .. | .. |
|---|
| 264 | 285 | |
|---|
| 265 | 286 | int msm_gpu_pm_suspend(struct msm_gpu *gpu); |
|---|
| 266 | 287 | int msm_gpu_pm_resume(struct msm_gpu *gpu); |
|---|
| 288 | +void msm_gpu_resume_devfreq(struct msm_gpu *gpu); |
|---|
| 267 | 289 | |
|---|
| 268 | 290 | int msm_gpu_hw_init(struct msm_gpu *gpu); |
|---|
| 269 | 291 | |
|---|
| .. | .. |
|---|
| 273 | 295 | uint32_t *totaltime, uint32_t ncntrs, uint32_t *cntrs); |
|---|
| 274 | 296 | |
|---|
| 275 | 297 | void msm_gpu_retire(struct msm_gpu *gpu); |
|---|
| 276 | | -void msm_gpu_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit, |
|---|
| 277 | | - struct msm_file_private *ctx); |
|---|
| 298 | +void msm_gpu_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit); |
|---|
| 278 | 299 | |
|---|
| 279 | 300 | int msm_gpu_init(struct drm_device *drm, struct platform_device *pdev, |
|---|
| 280 | 301 | struct msm_gpu *gpu, const struct msm_gpu_funcs *funcs, |
|---|
| 281 | 302 | const char *name, struct msm_gpu_config *config); |
|---|
| 303 | + |
|---|
| 304 | +struct msm_gem_address_space * |
|---|
| 305 | +msm_gpu_create_private_address_space(struct msm_gpu *gpu, struct task_struct *task); |
|---|
| 282 | 306 | |
|---|
| 283 | 307 | void msm_gpu_cleanup(struct msm_gpu *gpu); |
|---|
| 284 | 308 | |
|---|
| .. | .. |
|---|
| 320 | 344 | mutex_unlock(&gpu->dev->struct_mutex); |
|---|
| 321 | 345 | } |
|---|
| 322 | 346 | |
|---|
| 347 | +/* |
|---|
| 348 | + * Simple macro to semi-cleanly add the MAP_PRIV flag for targets that can |
|---|
| 349 | + * support expanded privileges |
|---|
| 350 | + */ |
|---|
| 351 | +#define check_apriv(gpu, flags) \ |
|---|
| 352 | + (((gpu)->hw_apriv ? MSM_BO_MAP_PRIV : 0) | (flags)) |
|---|
| 353 | + |
|---|
| 354 | + |
|---|
| 323 | 355 | #endif /* __MSM_GPU_H__ */ |
|---|