msm_gpu.h 6.19 KB
Newer Older
Rob Clark's avatar
Rob Clark committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*
 * Copyright (C) 2013 Red Hat
 * Author: Rob Clark <robdclark@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 as published by
 * the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef __MSM_GPU_H__
#define __MSM_GPU_H__

#include <linux/clk.h>
#include <linux/regulator/consumer.h>

#include "msm_drv.h"
25
#include "msm_fence.h"
Rob Clark's avatar
Rob Clark committed
26 27 28
#include "msm_ringbuffer.h"

struct msm_gem_submit;
29
struct msm_gpu_perfcntr;
Rob Clark's avatar
Rob Clark committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

/* So far, with hardware that I've seen to date, we can have:
 *  + zero, one, or two z180 2d cores
 *  + a3xx or a2xx 3d core, which share a common CP (the firmware
 *    for the CP seems to implement some different PM4 packet types
 *    but the basics of cmdstream submission are the same)
 *
 * Which means that the eventual complete "class" hierarchy, once
 * support for all past and present hw is in place, becomes:
 *  + msm_gpu
 *    + adreno_gpu
 *      + a3xx_gpu
 *      + a2xx_gpu
 *    + z180_gpu
 */
struct msm_gpu_funcs {
	int (*get_param)(struct msm_gpu *gpu, uint32_t param, uint64_t *value);
	int (*hw_init)(struct msm_gpu *gpu);
	int (*pm_suspend)(struct msm_gpu *gpu);
	int (*pm_resume)(struct msm_gpu *gpu);
50
	void (*submit)(struct msm_gpu *gpu, struct msm_gem_submit *submit,
Rob Clark's avatar
Rob Clark committed
51 52
			struct msm_file_private *ctx);
	void (*flush)(struct msm_gpu *gpu);
53
	bool (*idle)(struct msm_gpu *gpu);
Rob Clark's avatar
Rob Clark committed
54 55
	irqreturn_t (*irq)(struct msm_gpu *irq);
	uint32_t (*last_fence)(struct msm_gpu *gpu);
56
	void (*recover)(struct msm_gpu *gpu);
Rob Clark's avatar
Rob Clark committed
57 58 59 60 61 62 63 64 65 66
	void (*destroy)(struct msm_gpu *gpu);
#ifdef CONFIG_DEBUG_FS
	/* show GPU status in debugfs: */
	void (*show)(struct msm_gpu *gpu, struct seq_file *m);
#endif
};

struct msm_gpu {
	const char *name;
	struct drm_device *dev;
Rob Clark's avatar
Rob Clark committed
67
	struct platform_device *pdev;
Rob Clark's avatar
Rob Clark committed
68 69
	const struct msm_gpu_funcs *funcs;

70 71 72 73 74 75 76 77 78 79 80 81
	/* performance counters (hw & sw): */
	spinlock_t perf_lock;
	bool perfcntr_active;
	struct {
		bool active;
		ktime_t time;
	} last_sample;
	uint32_t totaltime, activetime;    /* sw counters */
	uint32_t last_cntrs[5];            /* hw counters */
	const struct msm_gpu_perfcntr *perfcntrs;
	uint32_t num_perfcntrs;

82
	/* ringbuffer: */
Rob Clark's avatar
Rob Clark committed
83
	struct msm_ringbuffer *rb;
Rob Clark's avatar
Rob Clark committed
84
	uint64_t rb_iova;
Rob Clark's avatar
Rob Clark committed
85 86 87 88

	/* list of GEM active objects: */
	struct list_head active_list;

89 90
	/* fencing: */
	struct msm_fence_context *fctx;
91

Rob Clark's avatar
Rob Clark committed
92 93
	/* does gpu need hw_init? */
	bool needs_hw_init;
94

Rob Clark's avatar
Rob Clark committed
95 96 97 98 99 100
	/* worker for handling active-list retiring: */
	struct work_struct retire_work;

	void __iomem *mmio;
	int irq;

101
	struct msm_gem_address_space *aspace;
Rob Clark's avatar
Rob Clark committed
102 103 104 105
	int id;

	/* Power Control: */
	struct regulator *gpu_reg, *gpu_cx;
106
	struct clk *ebi1_clk, *grp_clks[6];
Rob Clark's avatar
Rob Clark committed
107
	uint32_t fast_rate, slow_rate, bus_freq;
Rob Clark's avatar
Rob Clark committed
108

109
#ifdef DOWNSTREAM_CONFIG_MSM_BUS_SCALING
Rob Clark's avatar
Rob Clark committed
110
	struct msm_bus_scale_pdata *bus_scale_table;
Rob Clark's avatar
Rob Clark committed
111
	uint32_t bsc;
Rob Clark's avatar
Rob Clark committed
112
#endif
113

114 115 116
	/* Hang and Inactivity Detection:
	 */
#define DRM_MSM_INACTIVE_PERIOD   66 /* in ms (roughly four frames) */
Rob Clark's avatar
Rob Clark committed
117

118 119 120 121 122
#define DRM_MSM_HANGCHECK_PERIOD 500 /* in ms */
#define DRM_MSM_HANGCHECK_JIFFIES msecs_to_jiffies(DRM_MSM_HANGCHECK_PERIOD)
	struct timer_list hangcheck_timer;
	uint32_t hangcheck_fence;
	struct work_struct recover_work;
123 124

	struct list_head submit_list;
Rob Clark's avatar
Rob Clark committed
125 126
};

127 128
static inline bool msm_gpu_active(struct msm_gpu *gpu)
{
129
	return gpu->fctx->last_fence > gpu->funcs->last_fence(gpu);
130 131
}

132 133 134 135 136 137 138 139 140 141 142 143 144
/* Perf-Counters:
 * The select_reg and select_val are just there for the benefit of the child
 * class that actually enables the perf counter..  but msm_gpu base class
 * will handle sampling/displaying the counters.
 */

struct msm_gpu_perfcntr {
	uint32_t select_reg;
	uint32_t sample_reg;
	uint32_t select_val;
	const char *name;
};

Rob Clark's avatar
Rob Clark committed
145 146 147 148 149 150 151 152 153 154
static inline void gpu_write(struct msm_gpu *gpu, u32 reg, u32 data)
{
	msm_writel(data, gpu->mmio + (reg << 2));
}

static inline u32 gpu_read(struct msm_gpu *gpu, u32 reg)
{
	return msm_readl(gpu->mmio + (reg << 2));
}

155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
static inline void gpu_rmw(struct msm_gpu *gpu, u32 reg, u32 mask, u32 or)
{
	uint32_t val = gpu_read(gpu, reg);

	val &= ~mask;
	gpu_write(gpu, reg, val | or);
}

static inline u64 gpu_read64(struct msm_gpu *gpu, u32 lo, u32 hi)
{
	u64 val;

	/*
	 * Why not a readq here? Two reasons: 1) many of the LO registers are
	 * not quad word aligned and 2) the GPU hardware designers have a bit
	 * of a history of putting registers where they fit, especially in
	 * spins. The longer a GPU family goes the higher the chance that
	 * we'll get burned.  We could do a series of validity checks if we
	 * wanted to, but really is a readq() that much better? Nah.
	 */

	/*
	 * For some lo/hi registers (like perfcounters), the hi value is latched
	 * when the lo is read, so make sure to read the lo first to trigger
	 * that
	 */
	val = (u64) msm_readl(gpu->mmio + (lo << 2));
	val |= ((u64) msm_readl(gpu->mmio + (hi << 2)) << 32);

	return val;
}

static inline void gpu_write64(struct msm_gpu *gpu, u32 lo, u32 hi, u64 val)
{
	/* Why not a writeq here? Read the screed above */
	msm_writel(lower_32_bits(val), gpu->mmio + (lo << 2));
	msm_writel(upper_32_bits(val), gpu->mmio + (hi << 2));
}

Rob Clark's avatar
Rob Clark committed
194 195 196
int msm_gpu_pm_suspend(struct msm_gpu *gpu);
int msm_gpu_pm_resume(struct msm_gpu *gpu);

Rob Clark's avatar
Rob Clark committed
197 198
int msm_gpu_hw_init(struct msm_gpu *gpu);

199 200 201 202 203
void msm_gpu_perfcntr_start(struct msm_gpu *gpu);
void msm_gpu_perfcntr_stop(struct msm_gpu *gpu);
int msm_gpu_perfcntr_sample(struct msm_gpu *gpu, uint32_t *activetime,
		uint32_t *totaltime, uint32_t ncntrs, uint32_t *cntrs);

Rob Clark's avatar
Rob Clark committed
204
void msm_gpu_retire(struct msm_gpu *gpu);
205
void msm_gpu_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit,
Rob Clark's avatar
Rob Clark committed
206 207 208 209 210 211 212
		struct msm_file_private *ctx);

int msm_gpu_init(struct drm_device *drm, struct platform_device *pdev,
		struct msm_gpu *gpu, const struct msm_gpu_funcs *funcs,
		const char *name, const char *ioname, const char *irqname, int ringsz);
void msm_gpu_cleanup(struct msm_gpu *gpu);

213
struct msm_gpu *adreno_load_gpu(struct drm_device *dev);
214 215
void __init adreno_register(void);
void __exit adreno_unregister(void);
Rob Clark's avatar
Rob Clark committed
216 217

#endif /* __MSM_GPU_H__ */