1a8c21a54SThe etnaviv authors /*
2a8c21a54SThe etnaviv authors  * Copyright (C) 2015 Etnaviv Project
3a8c21a54SThe etnaviv authors  *
4a8c21a54SThe etnaviv authors  * This program is free software; you can redistribute it and/or modify it
5a8c21a54SThe etnaviv authors  * under the terms of the GNU General Public License version 2 as published by
6a8c21a54SThe etnaviv authors  * the Free Software Foundation.
7a8c21a54SThe etnaviv authors  *
8a8c21a54SThe etnaviv authors  * This program is distributed in the hope that it will be useful, but WITHOUT
9a8c21a54SThe etnaviv authors  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10a8c21a54SThe etnaviv authors  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
11a8c21a54SThe etnaviv authors  * more details.
12a8c21a54SThe etnaviv authors  *
13a8c21a54SThe etnaviv authors  * You should have received a copy of the GNU General Public License along with
14a8c21a54SThe etnaviv authors  * this program.  If not, see <http://www.gnu.org/licenses/>.
15a8c21a54SThe etnaviv authors  */
16a8c21a54SThe etnaviv authors 
17a8c21a54SThe etnaviv authors #ifndef __ETNAVIV_GPU_H__
18a8c21a54SThe etnaviv authors #define __ETNAVIV_GPU_H__
19a8c21a54SThe etnaviv authors 
20a8c21a54SThe etnaviv authors #include <linux/clk.h>
21a8c21a54SThe etnaviv authors #include <linux/regulator/consumer.h>
22a8c21a54SThe etnaviv authors 
232f9225dbSLucas Stach #include "etnaviv_cmdbuf.h"
24a8c21a54SThe etnaviv authors #include "etnaviv_drv.h"
25a8c21a54SThe etnaviv authors 
26a8c21a54SThe etnaviv authors struct etnaviv_gem_submit;
27b6325f40SRussell King struct etnaviv_vram_mapping;
28a8c21a54SThe etnaviv authors 
29a8c21a54SThe etnaviv authors struct etnaviv_chip_identity {
30a8c21a54SThe etnaviv authors 	/* Chip model. */
31a8c21a54SThe etnaviv authors 	u32 model;
32a8c21a54SThe etnaviv authors 
33a8c21a54SThe etnaviv authors 	/* Revision value.*/
34a8c21a54SThe etnaviv authors 	u32 revision;
35a8c21a54SThe etnaviv authors 
36a8c21a54SThe etnaviv authors 	/* Supported feature fields. */
37a8c21a54SThe etnaviv authors 	u32 features;
38a8c21a54SThe etnaviv authors 
39a8c21a54SThe etnaviv authors 	/* Supported minor feature fields. */
40a8c21a54SThe etnaviv authors 	u32 minor_features0;
41a8c21a54SThe etnaviv authors 	u32 minor_features1;
42a8c21a54SThe etnaviv authors 	u32 minor_features2;
43a8c21a54SThe etnaviv authors 	u32 minor_features3;
44602eb489SRussell King 	u32 minor_features4;
45602eb489SRussell King 	u32 minor_features5;
460538aaf9SLucas Stach 	u32 minor_features6;
470538aaf9SLucas Stach 	u32 minor_features7;
480538aaf9SLucas Stach 	u32 minor_features8;
490538aaf9SLucas Stach 	u32 minor_features9;
500538aaf9SLucas Stach 	u32 minor_features10;
510538aaf9SLucas Stach 	u32 minor_features11;
52602eb489SRussell King 
53a8c21a54SThe etnaviv authors 	/* Number of streams supported. */
54a8c21a54SThe etnaviv authors 	u32 stream_count;
55a8c21a54SThe etnaviv authors 
56a8c21a54SThe etnaviv authors 	/* Total number of temporary registers per thread. */
57a8c21a54SThe etnaviv authors 	u32 register_max;
58a8c21a54SThe etnaviv authors 
59a8c21a54SThe etnaviv authors 	/* Maximum number of threads. */
60a8c21a54SThe etnaviv authors 	u32 thread_count;
61a8c21a54SThe etnaviv authors 
62a8c21a54SThe etnaviv authors 	/* Number of shader cores. */
63a8c21a54SThe etnaviv authors 	u32 shader_core_count;
64a8c21a54SThe etnaviv authors 
65a8c21a54SThe etnaviv authors 	/* Size of the vertex cache. */
66a8c21a54SThe etnaviv authors 	u32 vertex_cache_size;
67a8c21a54SThe etnaviv authors 
68a8c21a54SThe etnaviv authors 	/* Number of entries in the vertex output buffer. */
69a8c21a54SThe etnaviv authors 	u32 vertex_output_buffer_size;
70a8c21a54SThe etnaviv authors 
71a8c21a54SThe etnaviv authors 	/* Number of pixel pipes. */
72a8c21a54SThe etnaviv authors 	u32 pixel_pipes;
73a8c21a54SThe etnaviv authors 
74a8c21a54SThe etnaviv authors 	/* Number of instructions. */
75a8c21a54SThe etnaviv authors 	u32 instruction_count;
76a8c21a54SThe etnaviv authors 
77a8c21a54SThe etnaviv authors 	/* Number of constants. */
78a8c21a54SThe etnaviv authors 	u32 num_constants;
79a8c21a54SThe etnaviv authors 
80a8c21a54SThe etnaviv authors 	/* Buffer size */
81a8c21a54SThe etnaviv authors 	u32 buffer_size;
82602eb489SRussell King 
83602eb489SRussell King 	/* Number of varyings */
84602eb489SRussell King 	u8 varyings_count;
85a8c21a54SThe etnaviv authors };
86a8c21a54SThe etnaviv authors 
87a8c21a54SThe etnaviv authors struct etnaviv_event {
88f54d1867SChris Wilson 	struct dma_fence *fence;
89ef146c00SLucas Stach 	struct etnaviv_gem_submit *submit;
90357713ceSChristian Gmeiner 
91357713ceSChristian Gmeiner 	void (*sync_point)(struct etnaviv_gpu *gpu, struct etnaviv_event *event);
92a8c21a54SThe etnaviv authors };
93a8c21a54SThe etnaviv authors 
94e66774ddSLucas Stach struct etnaviv_cmdbuf_suballoc;
95a8c21a54SThe etnaviv authors struct etnaviv_cmdbuf;
96a8c21a54SThe etnaviv authors 
97355502e0SChristian Gmeiner #define ETNA_NR_EVENTS 30
98355502e0SChristian Gmeiner 
99a8c21a54SThe etnaviv authors struct etnaviv_gpu {
100a8c21a54SThe etnaviv authors 	struct drm_device *drm;
101bcdfb5e5SRussell King 	struct thermal_cooling_device *cooling;
102a8c21a54SThe etnaviv authors 	struct device *dev;
103a8c21a54SThe etnaviv authors 	struct mutex lock;
104a8c21a54SThe etnaviv authors 	struct etnaviv_chip_identity identity;
105a8c21a54SThe etnaviv authors 	struct etnaviv_file_private *lastctx;
106a7790d78SLucas Stach 	struct workqueue_struct *wq;
107e93b6deeSLucas Stach 	struct drm_gpu_scheduler sched;
108a8c21a54SThe etnaviv authors 
109a8c21a54SThe etnaviv authors 	/* 'ring'-buffer: */
1102f9225dbSLucas Stach 	struct etnaviv_cmdbuf buffer;
111f6086311SRussell King 	int exec_state;
112a8c21a54SThe etnaviv authors 
113a8c21a54SThe etnaviv authors 	/* bus base address of memory  */
114a8c21a54SThe etnaviv authors 	u32 memory_base;
115a8c21a54SThe etnaviv authors 
116a8c21a54SThe etnaviv authors 	/* event management: */
117355502e0SChristian Gmeiner 	DECLARE_BITMAP(event_bitmap, ETNA_NR_EVENTS);
118355502e0SChristian Gmeiner 	struct etnaviv_event event[ETNA_NR_EVENTS];
119a8c21a54SThe etnaviv authors 	struct completion event_free;
120a8c21a54SThe etnaviv authors 	spinlock_t event_spinlock;
121a8c21a54SThe etnaviv authors 
122a8c21a54SThe etnaviv authors 	u32 idle_mask;
123a8c21a54SThe etnaviv authors 
124a8c21a54SThe etnaviv authors 	/* Fencing support */
125e93b6deeSLucas Stach 	struct mutex fence_idr_lock;
1268bc4d885SLucas Stach 	struct idr fence_idr;
127a8c21a54SThe etnaviv authors 	u32 next_fence;
128a8c21a54SThe etnaviv authors 	u32 active_fence;
129a8c21a54SThe etnaviv authors 	u32 completed_fence;
130a8c21a54SThe etnaviv authors 	wait_queue_head_t fence_event;
13176bf0db5SChristian König 	u64 fence_context;
132a8c21a54SThe etnaviv authors 	spinlock_t fence_spinlock;
133a8c21a54SThe etnaviv authors 
134357713ceSChristian Gmeiner 	/* worker for handling 'sync' points: */
135357713ceSChristian Gmeiner 	struct work_struct sync_point_work;
136357713ceSChristian Gmeiner 	int sync_point_event;
137357713ceSChristian Gmeiner 
138a8c21a54SThe etnaviv authors 	void __iomem *mmio;
139a8c21a54SThe etnaviv authors 	int irq;
140a8c21a54SThe etnaviv authors 
141a8c21a54SThe etnaviv authors 	struct etnaviv_iommu *mmu;
142e66774ddSLucas Stach 	struct etnaviv_cmdbuf_suballoc *cmdbuf_suballoc;
143a8c21a54SThe etnaviv authors 
144a8c21a54SThe etnaviv authors 	/* Power Control: */
145a8c21a54SThe etnaviv authors 	struct clk *clk_bus;
14665f037e8SLucas Stach 	struct clk *clk_reg;
147a8c21a54SThe etnaviv authors 	struct clk *clk_core;
148a8c21a54SThe etnaviv authors 	struct clk *clk_shader;
149a8c21a54SThe etnaviv authors 
150bcdfb5e5SRussell King 	unsigned int freq_scale;
151d79fd1ccSLucas Stach 	unsigned long base_rate_core;
152d79fd1ccSLucas Stach 	unsigned long base_rate_shader;
153a8c21a54SThe etnaviv authors };
154a8c21a54SThe etnaviv authors 
155a8c21a54SThe etnaviv authors static inline void gpu_write(struct etnaviv_gpu *gpu, u32 reg, u32 data)
156a8c21a54SThe etnaviv authors {
157a8c21a54SThe etnaviv authors 	etnaviv_writel(data, gpu->mmio + reg);
158a8c21a54SThe etnaviv authors }
159a8c21a54SThe etnaviv authors 
160a8c21a54SThe etnaviv authors static inline u32 gpu_read(struct etnaviv_gpu *gpu, u32 reg)
161a8c21a54SThe etnaviv authors {
162a8c21a54SThe etnaviv authors 	return etnaviv_readl(gpu->mmio + reg);
163a8c21a54SThe etnaviv authors }
164a8c21a54SThe etnaviv authors 
165a8c21a54SThe etnaviv authors static inline bool fence_completed(struct etnaviv_gpu *gpu, u32 fence)
166a8c21a54SThe etnaviv authors {
167a8c21a54SThe etnaviv authors 	return fence_after_eq(gpu->completed_fence, fence);
168a8c21a54SThe etnaviv authors }
169a8c21a54SThe etnaviv authors 
170a8c21a54SThe etnaviv authors int etnaviv_gpu_get_param(struct etnaviv_gpu *gpu, u32 param, u64 *value);
171a8c21a54SThe etnaviv authors 
172a8c21a54SThe etnaviv authors int etnaviv_gpu_init(struct etnaviv_gpu *gpu);
173681c19c8SLucas Stach bool etnaviv_fill_identity_from_hwdb(struct etnaviv_gpu *gpu);
174a8c21a54SThe etnaviv authors 
175a8c21a54SThe etnaviv authors #ifdef CONFIG_DEBUG_FS
176a8c21a54SThe etnaviv authors int etnaviv_gpu_debugfs(struct etnaviv_gpu *gpu, struct seq_file *m);
177a8c21a54SThe etnaviv authors #endif
178a8c21a54SThe etnaviv authors 
1796d7a20c0SLucas Stach void etnaviv_gpu_recover_hang(struct etnaviv_gpu *gpu);
180a8c21a54SThe etnaviv authors void etnaviv_gpu_retire(struct etnaviv_gpu *gpu);
181a8c21a54SThe etnaviv authors int etnaviv_gpu_wait_fence_interruptible(struct etnaviv_gpu *gpu,
182a8c21a54SThe etnaviv authors 	u32 fence, struct timespec *timeout);
183a8c21a54SThe etnaviv authors int etnaviv_gpu_wait_obj_inactive(struct etnaviv_gpu *gpu,
184a8c21a54SThe etnaviv authors 	struct etnaviv_gem_object *etnaviv_obj, struct timespec *timeout);
185e93b6deeSLucas Stach struct dma_fence *etnaviv_gpu_submit(struct etnaviv_gem_submit *submit);
186a8c21a54SThe etnaviv authors int etnaviv_gpu_pm_get_sync(struct etnaviv_gpu *gpu);
187a8c21a54SThe etnaviv authors void etnaviv_gpu_pm_put(struct etnaviv_gpu *gpu);
188b88163e3SLucas Stach int etnaviv_gpu_wait_idle(struct etnaviv_gpu *gpu, unsigned int timeout_ms);
189229855b6SLucas Stach void etnaviv_gpu_start_fe(struct etnaviv_gpu *gpu, u32 address, u16 prefetch);
190a8c21a54SThe etnaviv authors 
191a8c21a54SThe etnaviv authors extern struct platform_driver etnaviv_gpu_driver;
192a8c21a54SThe etnaviv authors 
193a8c21a54SThe etnaviv authors #endif /* __ETNAVIV_GPU_H__ */
194