drm/msm/adreno: move decision about what gpu to to load
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / drm / msm / adreno / adreno_gpu.h
1 /*
2  * Copyright (C) 2013 Red Hat
3  * 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  */
17
18 #ifndef __ADRENO_GPU_H__
19 #define __ADRENO_GPU_H__
20
21 #include <linux/firmware.h>
22
23 #include "msm_gpu.h"
24
25 #include "adreno_common.xml.h"
26 #include "adreno_pm4.xml.h"
27
28 struct adreno_rev {
29         uint8_t  core;
30         uint8_t  major;
31         uint8_t  minor;
32         uint8_t  patchid;
33 };
34
35 #define ADRENO_REV(core, major, minor, patchid) \
36         ((struct adreno_rev){ core, major, minor, patchid })
37
38 struct adreno_gpu_funcs {
39         struct msm_gpu_funcs base;
40 };
41
42 struct adreno_info {
43         struct adreno_rev rev;
44         uint32_t revn;
45         const char *name;
46         const char *pm4fw, *pfpfw;
47         uint32_t gmem;
48         struct msm_gpu *(*init)(struct drm_device *dev);
49 };
50
51 const struct adreno_info *adreno_info(struct adreno_rev rev);
52
53 struct adreno_rbmemptrs {
54         volatile uint32_t rptr;
55         volatile uint32_t wptr;
56         volatile uint32_t fence;
57 };
58
59 struct adreno_gpu {
60         struct msm_gpu base;
61         struct adreno_rev rev;
62         const struct adreno_info *info;
63         uint32_t gmem;  /* actual gmem size */
64         uint32_t revn;  /* numeric revision name */
65         const struct adreno_gpu_funcs *funcs;
66
67         /* firmware: */
68         const struct firmware *pm4, *pfp;
69
70         /* ringbuffer rptr/wptr: */
71         // TODO should this be in msm_ringbuffer?  I think it would be
72         // different for z180..
73         struct adreno_rbmemptrs *memptrs;
74         struct drm_gem_object *memptrs_bo;
75         uint32_t memptrs_iova;
76 };
77 #define to_adreno_gpu(x) container_of(x, struct adreno_gpu, base)
78
79 /* platform config data (ie. from DT, or pdata) */
80 struct adreno_platform_config {
81         struct adreno_rev rev;
82         uint32_t fast_rate, slow_rate, bus_freq;
83 #ifdef CONFIG_MSM_BUS_SCALING
84         struct msm_bus_scale_pdata *bus_scale_table;
85 #endif
86 };
87
88 #define ADRENO_IDLE_TIMEOUT msecs_to_jiffies(1000)
89
90 #define spin_until(X) ({                                   \
91         int __ret = -ETIMEDOUT;                            \
92         unsigned long __t = jiffies + ADRENO_IDLE_TIMEOUT; \
93         do {                                               \
94                 if (X) {                                   \
95                         __ret = 0;                         \
96                         break;                             \
97                 }                                          \
98         } while (time_before(jiffies, __t));               \
99         __ret;                                             \
100 })
101
102
103 static inline bool adreno_is_a3xx(struct adreno_gpu *gpu)
104 {
105         return (gpu->revn >= 300) && (gpu->revn < 400);
106 }
107
108 static inline bool adreno_is_a305(struct adreno_gpu *gpu)
109 {
110         return gpu->revn == 305;
111 }
112
113 static inline bool adreno_is_a320(struct adreno_gpu *gpu)
114 {
115         return gpu->revn == 320;
116 }
117
118 static inline bool adreno_is_a330(struct adreno_gpu *gpu)
119 {
120         return gpu->revn == 330;
121 }
122
123 static inline bool adreno_is_a330v2(struct adreno_gpu *gpu)
124 {
125         return adreno_is_a330(gpu) && (gpu->rev.patchid > 0);
126 }
127
128 int adreno_get_param(struct msm_gpu *gpu, uint32_t param, uint64_t *value);
129 int adreno_hw_init(struct msm_gpu *gpu);
130 uint32_t adreno_last_fence(struct msm_gpu *gpu);
131 void adreno_recover(struct msm_gpu *gpu);
132 int adreno_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit,
133                 struct msm_file_private *ctx);
134 void adreno_flush(struct msm_gpu *gpu);
135 void adreno_idle(struct msm_gpu *gpu);
136 #ifdef CONFIG_DEBUG_FS
137 void adreno_show(struct msm_gpu *gpu, struct seq_file *m);
138 #endif
139 void adreno_dump(struct msm_gpu *gpu);
140 void adreno_wait_ring(struct msm_gpu *gpu, uint32_t ndwords);
141
142 int adreno_gpu_init(struct drm_device *drm, struct platform_device *pdev,
143                 struct adreno_gpu *gpu, const struct adreno_gpu_funcs *funcs,
144                 struct adreno_rev rev);
145 void adreno_gpu_cleanup(struct adreno_gpu *gpu);
146
147
148 /* ringbuffer helpers (the parts that are adreno specific) */
149
150 static inline void
151 OUT_PKT0(struct msm_ringbuffer *ring, uint16_t regindx, uint16_t cnt)
152 {
153         adreno_wait_ring(ring->gpu, cnt+1);
154         OUT_RING(ring, CP_TYPE0_PKT | ((cnt-1) << 16) | (regindx & 0x7FFF));
155 }
156
157 /* no-op packet: */
158 static inline void
159 OUT_PKT2(struct msm_ringbuffer *ring)
160 {
161         adreno_wait_ring(ring->gpu, 1);
162         OUT_RING(ring, CP_TYPE2_PKT);
163 }
164
165 static inline void
166 OUT_PKT3(struct msm_ringbuffer *ring, uint8_t opcode, uint16_t cnt)
167 {
168         adreno_wait_ring(ring->gpu, cnt+1);
169         OUT_RING(ring, CP_TYPE3_PKT | ((cnt-1) << 16) | ((opcode & 0xFF) << 8));
170 }
171
172
173 #endif /* __ADRENO_GPU_H__ */