2 * Copyright (C) 2015 Etnaviv Project
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 as published by
6 * the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License along with
14 * this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef __ETNAVIV_GPU_H__
18 #define __ETNAVIV_GPU_H__
20 #include <linux/clk.h>
21 #include <linux/regulator/consumer.h>
23 #include "etnaviv_cmdbuf.h"
24 #include "etnaviv_drv.h"
26 struct etnaviv_gem_submit
;
27 struct etnaviv_vram_mapping
;
29 struct etnaviv_chip_identity
{
36 /* Supported feature fields. */
39 /* Supported minor feature fields. */
42 /* Supported minor feature 1 fields. */
45 /* Supported minor feature 2 fields. */
48 /* Supported minor feature 3 fields. */
51 /* Supported minor feature 4 fields. */
54 /* Supported minor feature 5 fields. */
57 /* Number of streams supported. */
60 /* Total number of temporary registers per thread. */
63 /* Maximum number of threads. */
66 /* Number of shader cores. */
67 u32 shader_core_count
;
69 /* Size of the vertex cache. */
70 u32 vertex_cache_size
;
72 /* Number of entries in the vertex output buffer. */
73 u32 vertex_output_buffer_size
;
75 /* Number of pixel pipes. */
78 /* Number of instructions. */
79 u32 instruction_count
;
81 /* Number of constants. */
87 /* Number of varyings */
91 struct etnaviv_event
{
92 struct dma_fence
*fence
;
93 struct etnaviv_gem_submit
*submit
;
95 void (*sync_point
)(struct etnaviv_gpu
*gpu
, struct etnaviv_event
*event
);
98 struct etnaviv_cmdbuf_suballoc
;
99 struct etnaviv_cmdbuf
;
101 #define ETNA_NR_EVENTS 30
104 struct drm_device
*drm
;
105 struct thermal_cooling_device
*cooling
;
108 struct etnaviv_chip_identity identity
;
109 struct etnaviv_file_private
*lastctx
;
110 struct workqueue_struct
*wq
;
113 struct etnaviv_cmdbuf buffer
;
116 /* bus base address of memory */
119 /* event management: */
120 DECLARE_BITMAP(event_bitmap
, ETNA_NR_EVENTS
);
121 struct etnaviv_event event
[ETNA_NR_EVENTS
];
122 struct completion event_free
;
123 spinlock_t event_spinlock
;
125 /* list of currently in-flight command buffers */
126 struct list_head active_submit_list
;
130 /* Fencing support */
135 wait_queue_head_t fence_event
;
137 spinlock_t fence_spinlock
;
139 /* worker for handling active-list retiring: */
140 struct work_struct retire_work
;
142 /* worker for handling 'sync' points: */
143 struct work_struct sync_point_work
;
144 int sync_point_event
;
149 struct etnaviv_iommu
*mmu
;
150 struct etnaviv_cmdbuf_suballoc
*cmdbuf_suballoc
;
154 struct clk
*clk_core
;
155 struct clk
*clk_shader
;
158 #define DRM_ETNAVIV_HANGCHECK_PERIOD 500 /* in ms */
159 #define DRM_ETNAVIV_HANGCHECK_JIFFIES msecs_to_jiffies(DRM_ETNAVIV_HANGCHECK_PERIOD)
160 struct timer_list hangcheck_timer
;
162 u32 hangcheck_dma_addr
;
163 struct work_struct recover_work
;
164 unsigned int freq_scale
;
165 unsigned long base_rate_core
;
166 unsigned long base_rate_shader
;
169 static inline void gpu_write(struct etnaviv_gpu
*gpu
, u32 reg
, u32 data
)
171 etnaviv_writel(data
, gpu
->mmio
+ reg
);
174 static inline u32
gpu_read(struct etnaviv_gpu
*gpu
, u32 reg
)
176 return etnaviv_readl(gpu
->mmio
+ reg
);
179 static inline bool fence_completed(struct etnaviv_gpu
*gpu
, u32 fence
)
181 return fence_after_eq(gpu
->completed_fence
, fence
);
184 static inline bool fence_retired(struct etnaviv_gpu
*gpu
, u32 fence
)
186 return fence_after_eq(gpu
->retired_fence
, fence
);
189 int etnaviv_gpu_get_param(struct etnaviv_gpu
*gpu
, u32 param
, u64
*value
);
191 int etnaviv_gpu_init(struct etnaviv_gpu
*gpu
);
193 #ifdef CONFIG_DEBUG_FS
194 int etnaviv_gpu_debugfs(struct etnaviv_gpu
*gpu
, struct seq_file
*m
);
197 int etnaviv_gpu_fence_sync_obj(struct etnaviv_gem_object
*etnaviv_obj
,
198 unsigned int context
, bool exclusive
, bool implicit
);
200 void etnaviv_gpu_retire(struct etnaviv_gpu
*gpu
);
201 int etnaviv_gpu_wait_fence_interruptible(struct etnaviv_gpu
*gpu
,
202 u32 fence
, struct timespec
*timeout
);
203 int etnaviv_gpu_wait_obj_inactive(struct etnaviv_gpu
*gpu
,
204 struct etnaviv_gem_object
*etnaviv_obj
, struct timespec
*timeout
);
205 int etnaviv_gpu_submit(struct etnaviv_gpu
*gpu
,
206 struct etnaviv_gem_submit
*submit
);
207 int etnaviv_gpu_pm_get_sync(struct etnaviv_gpu
*gpu
);
208 void etnaviv_gpu_pm_put(struct etnaviv_gpu
*gpu
);
209 int etnaviv_gpu_wait_idle(struct etnaviv_gpu
*gpu
, unsigned int timeout_ms
);
210 void etnaviv_gpu_start_fe(struct etnaviv_gpu
*gpu
, u32 address
, u16 prefetch
);
212 extern struct platform_driver etnaviv_gpu_driver
;
214 #endif /* __ETNAVIV_GPU_H__ */