2 * Copyright (C) 2013 Red Hat
3 * Author: Rob Clark <robdclark@gmail.com>
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.
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
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/>.
21 #include <linux/clk.h>
22 #include <linux/regulator/consumer.h>
25 #include "msm_fence.h"
26 #include "msm_ringbuffer.h"
28 struct msm_gem_submit;
29 struct msm_gpu_perfcntr;
31 struct msm_gpu_config {
39 /* So far, with hardware that I've seen to date, we can have:
40 * + zero, one, or two z180 2d cores
41 * + a3xx or a2xx 3d core, which share a common CP (the firmware
42 * for the CP seems to implement some different PM4 packet types
43 * but the basics of cmdstream submission are the same)
45 * Which means that the eventual complete "class" hierarchy, once
46 * support for all past and present hw is in place, becomes:
53 struct msm_gpu_funcs {
54 int (*get_param)(struct msm_gpu *gpu, uint32_t param, uint64_t *value);
55 int (*hw_init)(struct msm_gpu *gpu);
56 int (*pm_suspend)(struct msm_gpu *gpu);
57 int (*pm_resume)(struct msm_gpu *gpu);
58 void (*submit)(struct msm_gpu *gpu, struct msm_gem_submit *submit,
59 struct msm_file_private *ctx);
60 void (*flush)(struct msm_gpu *gpu);
61 irqreturn_t (*irq)(struct msm_gpu *irq);
62 uint32_t (*last_fence)(struct msm_gpu *gpu);
63 void (*recover)(struct msm_gpu *gpu);
64 void (*destroy)(struct msm_gpu *gpu);
65 #ifdef CONFIG_DEBUG_FS
66 /* show GPU status in debugfs: */
67 void (*show)(struct msm_gpu *gpu, struct seq_file *m);
73 struct drm_device *dev;
74 struct platform_device *pdev;
75 const struct msm_gpu_funcs *funcs;
77 /* performance counters (hw & sw): */
84 uint32_t totaltime, activetime; /* sw counters */
85 uint32_t last_cntrs[5]; /* hw counters */
86 const struct msm_gpu_perfcntr *perfcntrs;
87 uint32_t num_perfcntrs;
90 struct msm_ringbuffer *rb;
93 /* list of GEM active objects: */
94 struct list_head active_list;
97 struct msm_fence_context *fctx;
99 /* does gpu need hw_init? */
102 /* worker for handling active-list retiring: */
103 struct work_struct retire_work;
108 struct msm_gem_address_space *aspace;
111 struct regulator *gpu_reg, *gpu_cx;
112 struct clk **grp_clks;
114 struct clk *ebi1_clk, *core_clk, *rbbmtimer_clk;
115 uint32_t fast_rate, bus_freq;
117 #ifdef DOWNSTREAM_CONFIG_MSM_BUS_SCALING
118 struct msm_bus_scale_pdata *bus_scale_table;
122 /* Hang and Inactivity Detection:
124 #define DRM_MSM_INACTIVE_PERIOD 66 /* in ms (roughly four frames) */
126 #define DRM_MSM_HANGCHECK_PERIOD 500 /* in ms */
127 #define DRM_MSM_HANGCHECK_JIFFIES msecs_to_jiffies(DRM_MSM_HANGCHECK_PERIOD)
128 struct timer_list hangcheck_timer;
129 uint32_t hangcheck_fence;
130 struct work_struct recover_work;
132 struct list_head submit_list;
135 static inline bool msm_gpu_active(struct msm_gpu *gpu)
137 return gpu->fctx->last_fence > gpu->funcs->last_fence(gpu);
141 * The select_reg and select_val are just there for the benefit of the child
142 * class that actually enables the perf counter.. but msm_gpu base class
143 * will handle sampling/displaying the counters.
146 struct msm_gpu_perfcntr {
153 static inline void gpu_write(struct msm_gpu *gpu, u32 reg, u32 data)
155 msm_writel(data, gpu->mmio + (reg << 2));
158 static inline u32 gpu_read(struct msm_gpu *gpu, u32 reg)
160 return msm_readl(gpu->mmio + (reg << 2));
163 static inline void gpu_rmw(struct msm_gpu *gpu, u32 reg, u32 mask, u32 or)
165 uint32_t val = gpu_read(gpu, reg);
168 gpu_write(gpu, reg, val | or);
171 static inline u64 gpu_read64(struct msm_gpu *gpu, u32 lo, u32 hi)
176 * Why not a readq here? Two reasons: 1) many of the LO registers are
177 * not quad word aligned and 2) the GPU hardware designers have a bit
178 * of a history of putting registers where they fit, especially in
179 * spins. The longer a GPU family goes the higher the chance that
180 * we'll get burned. We could do a series of validity checks if we
181 * wanted to, but really is a readq() that much better? Nah.
185 * For some lo/hi registers (like perfcounters), the hi value is latched
186 * when the lo is read, so make sure to read the lo first to trigger
189 val = (u64) msm_readl(gpu->mmio + (lo << 2));
190 val |= ((u64) msm_readl(gpu->mmio + (hi << 2)) << 32);
195 static inline void gpu_write64(struct msm_gpu *gpu, u32 lo, u32 hi, u64 val)
197 /* Why not a writeq here? Read the screed above */
198 msm_writel(lower_32_bits(val), gpu->mmio + (lo << 2));
199 msm_writel(upper_32_bits(val), gpu->mmio + (hi << 2));
202 int msm_gpu_pm_suspend(struct msm_gpu *gpu);
203 int msm_gpu_pm_resume(struct msm_gpu *gpu);
205 int msm_gpu_hw_init(struct msm_gpu *gpu);
207 void msm_gpu_perfcntr_start(struct msm_gpu *gpu);
208 void msm_gpu_perfcntr_stop(struct msm_gpu *gpu);
209 int msm_gpu_perfcntr_sample(struct msm_gpu *gpu, uint32_t *activetime,
210 uint32_t *totaltime, uint32_t ncntrs, uint32_t *cntrs);
212 void msm_gpu_retire(struct msm_gpu *gpu);
213 void msm_gpu_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit,
214 struct msm_file_private *ctx);
216 int msm_gpu_init(struct drm_device *drm, struct platform_device *pdev,
217 struct msm_gpu *gpu, const struct msm_gpu_funcs *funcs,
218 const char *name, struct msm_gpu_config *config);
220 void msm_gpu_cleanup(struct msm_gpu *gpu);
222 struct msm_gpu *adreno_load_gpu(struct drm_device *dev);
223 void __init adreno_register(void);
224 void __exit adreno_unregister(void);
226 #endif /* __MSM_GPU_H__ */