drm/etnaviv: replace MMU flush marker with flush sequence
[linux-2.6-microblaze.git] / drivers / gpu / drm / etnaviv / etnaviv_gpu.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2015-2018 Etnaviv Project
4  */
5
6 #ifndef __ETNAVIV_GPU_H__
7 #define __ETNAVIV_GPU_H__
8
9 #include "etnaviv_cmdbuf.h"
10 #include "etnaviv_gem.h"
11 #include "etnaviv_drv.h"
12
13 struct etnaviv_gem_submit;
14 struct etnaviv_vram_mapping;
15
16 struct etnaviv_chip_identity {
17         /* Chip model. */
18         u32 model;
19
20         /* Revision value.*/
21         u32 revision;
22
23         /* Supported feature fields. */
24         u32 features;
25
26         /* Supported minor feature fields. */
27         u32 minor_features0;
28         u32 minor_features1;
29         u32 minor_features2;
30         u32 minor_features3;
31         u32 minor_features4;
32         u32 minor_features5;
33         u32 minor_features6;
34         u32 minor_features7;
35         u32 minor_features8;
36         u32 minor_features9;
37         u32 minor_features10;
38         u32 minor_features11;
39
40         /* Number of streams supported. */
41         u32 stream_count;
42
43         /* Total number of temporary registers per thread. */
44         u32 register_max;
45
46         /* Maximum number of threads. */
47         u32 thread_count;
48
49         /* Number of shader cores. */
50         u32 shader_core_count;
51
52         /* Size of the vertex cache. */
53         u32 vertex_cache_size;
54
55         /* Number of entries in the vertex output buffer. */
56         u32 vertex_output_buffer_size;
57
58         /* Number of pixel pipes. */
59         u32 pixel_pipes;
60
61         /* Number of instructions. */
62         u32 instruction_count;
63
64         /* Number of constants. */
65         u32 num_constants;
66
67         /* Buffer size */
68         u32 buffer_size;
69
70         /* Number of varyings */
71         u8 varyings_count;
72 };
73
74 enum etnaviv_sec_mode {
75         ETNA_SEC_NONE = 0,
76         ETNA_SEC_KERNEL,
77         ETNA_SEC_TZ
78 };
79
80 struct etnaviv_event {
81         struct dma_fence *fence;
82         struct etnaviv_gem_submit *submit;
83
84         void (*sync_point)(struct etnaviv_gpu *gpu, struct etnaviv_event *event);
85 };
86
87 struct etnaviv_cmdbuf_suballoc;
88 struct regulator;
89 struct clk;
90
91 #define ETNA_NR_EVENTS 30
92
93 struct etnaviv_gpu {
94         struct drm_device *drm;
95         struct thermal_cooling_device *cooling;
96         struct device *dev;
97         struct mutex lock;
98         struct etnaviv_chip_identity identity;
99         enum etnaviv_sec_mode sec_mode;
100         struct workqueue_struct *wq;
101         struct drm_gpu_scheduler sched;
102         bool initialized;
103
104         /* 'ring'-buffer: */
105         struct etnaviv_vram_mapping cmdbuf_mapping;
106         struct etnaviv_cmdbuf buffer;
107         int exec_state;
108
109         /* bus base address of memory  */
110         u32 memory_base;
111
112         /* event management: */
113         DECLARE_BITMAP(event_bitmap, ETNA_NR_EVENTS);
114         struct etnaviv_event event[ETNA_NR_EVENTS];
115         struct completion event_free;
116         spinlock_t event_spinlock;
117
118         u32 idle_mask;
119
120         /* Fencing support */
121         struct mutex fence_lock;
122         struct idr fence_idr;
123         u32 next_fence;
124         u32 completed_fence;
125         wait_queue_head_t fence_event;
126         u64 fence_context;
127         spinlock_t fence_spinlock;
128
129         /* worker for handling 'sync' points: */
130         struct work_struct sync_point_work;
131         int sync_point_event;
132
133         /* hang detection */
134         u32 hangcheck_dma_addr;
135
136         void __iomem *mmio;
137         int irq;
138
139         struct etnaviv_iommu *mmu;
140         unsigned int flush_seq;
141
142         /* Power Control: */
143         struct clk *clk_bus;
144         struct clk *clk_reg;
145         struct clk *clk_core;
146         struct clk *clk_shader;
147
148         unsigned int freq_scale;
149         unsigned long base_rate_core;
150         unsigned long base_rate_shader;
151 };
152
153 static inline void gpu_write(struct etnaviv_gpu *gpu, u32 reg, u32 data)
154 {
155         writel(data, gpu->mmio + reg);
156 }
157
158 static inline u32 gpu_read(struct etnaviv_gpu *gpu, u32 reg)
159 {
160         return readl(gpu->mmio + reg);
161 }
162
163 int etnaviv_gpu_get_param(struct etnaviv_gpu *gpu, u32 param, u64 *value);
164
165 int etnaviv_gpu_init(struct etnaviv_gpu *gpu);
166 bool etnaviv_fill_identity_from_hwdb(struct etnaviv_gpu *gpu);
167
168 #ifdef CONFIG_DEBUG_FS
169 int etnaviv_gpu_debugfs(struct etnaviv_gpu *gpu, struct seq_file *m);
170 #endif
171
172 void etnaviv_gpu_recover_hang(struct etnaviv_gpu *gpu);
173 void etnaviv_gpu_retire(struct etnaviv_gpu *gpu);
174 int etnaviv_gpu_wait_fence_interruptible(struct etnaviv_gpu *gpu,
175         u32 fence, struct timespec *timeout);
176 int etnaviv_gpu_wait_obj_inactive(struct etnaviv_gpu *gpu,
177         struct etnaviv_gem_object *etnaviv_obj, struct timespec *timeout);
178 struct dma_fence *etnaviv_gpu_submit(struct etnaviv_gem_submit *submit);
179 int etnaviv_gpu_pm_get_sync(struct etnaviv_gpu *gpu);
180 void etnaviv_gpu_pm_put(struct etnaviv_gpu *gpu);
181 int etnaviv_gpu_wait_idle(struct etnaviv_gpu *gpu, unsigned int timeout_ms);
182 void etnaviv_gpu_start_fe(struct etnaviv_gpu *gpu, u32 address, u16 prefetch);
183
184 extern struct platform_driver etnaviv_gpu_driver;
185
186 #endif /* __ETNAVIV_GPU_H__ */