hal_gfx_hal.h
Go to the documentation of this file.
1 
2 
3 /** @addtogroup GRAPHICS_SDK Graphics
4  * @{
5  */
6 
7 /** @defgroup HAL_GFX_HAL Hal gfx hal
8  * @brief GPU low layer interfaces, adaptation platform MCU.
9  * @{
10  */
11 #ifndef HAL_GFX_HAL_H__
12 #define HAL_GFX_HAL_H__
13 
14 #include "hal_gfx_sys_defs.h"
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 /**
21  * @defgroup HAL_GFX_HAL_MACRO Defines
22  * @{
23  */
24 #define MUTEX_RB 0 /**< Mutex for ringbuffer */
25 #define MUTEX_MALLOC 1 /**< Mutex for malloc */
26 #define MUTEX_FLUSH 2 /**< Mutex for flush */
27 #define MUTEX_MAX 2 /**< MAX */
28 /** @} */
29 
30 /**
31  * @defgroup HAL_GFX_HAL_STRUCT Structures
32  * @{
33  */
34 /**@brief The base structure of gpu memory. */
35 typedef struct hal_gfx_buffer_t_
36 {
37  int size; /**< Size of buffer */
38  int fd; /**< File Descriptor of buffer */
39  void *base_virt; /**< Virtual address of buffer */
40  uintptr_t base_phys; /**< Physical address of buffer */
42 
43 /**@brief The ringbuffer structure. */
44 typedef struct hal_gfx_ringbuffer_t_
45 {
46  hal_gfx_buffer_t bo; /**< Memory base structure */
47  int offset; /**< Record ringbuffer usage */
48  int last_submission_id; /**< Latest command list id */
50 
51 /** @} */
52 
53 /**
54  * @defgroup HAL_GFX_HAL_FUNCTION Functions
55  * @{
56  */
57 /**
58  *****************************************************************************************
59  * @brief Initialize system. Implementor defined. Called in hal_gfx_init()
60  *
61  * @return 0 if no errors occurred
62  *****************************************************************************************
63  */
64 int32_t hal_gfx_sys_init(void);
65 
66 /**
67  *****************************************************************************************
68  * @brief Wait for interrupt from the GPU
69  *
70  * @return 0 on success
71  *****************************************************************************************
72  */
73 int hal_gfx_wait_irq(void);
74 
75 /**
76  *****************************************************************************************
77  * @brief Wait for a Command List to finish
78  *
79  * @param[in] cl_id: cl_id Command List ID
80  *
81  * @return 0 on success
82  *****************************************************************************************
83  */
84 int hal_gfx_wait_irq_cl(int cl_id);
85 
86 /**
87  *****************************************************************************************
88  * @brief Wait for a Breakpoint
89  *
90  * @param[in] brk_id: Breakpoint ID
91  *
92  * @return 0 on success
93  *****************************************************************************************
94  */
95 int hal_gfx_wait_irq_brk(int brk_id);
96 
97 /**
98  *****************************************************************************************
99  * @brief Read Hardware register
100  *
101  * @param[in] reg: Register to read
102  *
103  * @return Value read from the register
104  *****************************************************************************************
105  */
106 uint32_t hal_gfx_reg_read(uint32_t reg);
107 
108 /**
109  *****************************************************************************************
110  * @brief Write Hardware Register
111  *
112  * @param[in] reg: Register to write
113  * @param[in] value: Value to be written
114  *****************************************************************************************
115  */
116 void hal_gfx_reg_write(uint32_t reg, uint32_t value);
117 
118 /**
119  *****************************************************************************************
120  * @brief Create memory buffer
121  *
122  * @param[in] size: Size of buffer in bytes
123  *
124  * @return hal_gfx_buffer_t struct
125  *****************************************************************************************
126  */
128 
129 /**
130  *****************************************************************************************
131  * @brief Create memory buffer at a specific pool
132  *
133  * @param[in] pool: ID of the desired memory pool
134  * @param[in] size: of buffer in bytes
135  *
136  * @return hal_gfx_buffer_t struct
137  *****************************************************************************************
138  */
140 
141 /**
142  *****************************************************************************************
143  * @brief Maps buffer
144  *
145  * @param[in] bo: Pointer to buffer struct
146  *
147  * @return Virtual pointer of the buffer (same as in bo->base_virt)
148  *****************************************************************************************
149  */
151 
152 /**
153  *****************************************************************************************
154  * @brief Unmaps buffer
155  *
156 * @param[in] bo: Pointer to buffer struct
157  *****************************************************************************************
158  */
160 
161 /**
162  *****************************************************************************************
163  * @brief Destroy/deallocate buffer
164  *
165  * @param[in] bo: Pointer to buffer struct
166  *****************************************************************************************
167  */
169 
170 /**
171  *****************************************************************************************
172  * @brief Get physical (GPU) base address of a given buffer
173  *
174  * @param[in] bo: Pointer to buffer struct
175  *
176  * @return Physical base address of a given buffer
177  *****************************************************************************************
178  */
180 
181 /**
182  *****************************************************************************************
183  * @brief Write-back buffer from cache to main memory
184  *
185  * @param[in] bo: Pointer to buffer struct
186  *****************************************************************************************
187  */
189 
190 /**
191  *****************************************************************************************
192  * @brief Allocate memory for CPU to use (typically, standard malloc() is called)
193  *
194  * @param[in] size: Size in bytes
195  *
196  * @return Pointer to allocated memory (virtual)
197  *****************************************************************************************
198  */
199 void *hal_gfx_host_malloc(size_t size);
200 
201 /**
202  *****************************************************************************************
203  * @brief Free memory previously allocated with hal_gfx_host_malloc()
204  *
205  * @param[in] ptr: Pointer to allocated memory (virtual)
206  *****************************************************************************************
207  */
208 void hal_gfx_host_free(void *ptr );
209 
210 /**
211  *****************************************************************************************
212  * @brief Initialize Ring Buffer. Should be called from inside hal_gfx_sys_init().
213  * This is a private function, the user should never call it.
214  *
215  * @param[in] rb: Pointer to hal_gfx_ring_buffer_t struct
216  * @param[in] reset: Resets the Ring Buffer if non-zero
217  *
218  * @return Negative number on error
219  *****************************************************************************************
220  */
222 
223 /**
224  *****************************************************************************************
225  * @brief Mutex Lock for multiple processes/threads
226  *
227  * @param[in] mutex_id: MUTEX_RB or MUTEX_MALLOC
228  *****************************************************************************************
229  */
230 int hal_gfx_mutex_lock(int mutex_id);
231 
232 /**
233  *****************************************************************************************
234  * @brief Mutex Unlock for multiple processes/threads
235  *
236  * @param[in] mutex_id: MUTEX_RB or MUTEX_MALLOC
237  *****************************************************************************************
238  */
239 int hal_gfx_mutex_unlock(int mutex_id);
240 /** @} */
241 
242 #ifdef __cplusplus
243 }
244 #endif
245 
246 #endif
247 /** @} */
248 /** @} */
249 
hal_gfx_sys_init
int32_t hal_gfx_sys_init(void)
Initialize system. Implementor defined. Called in hal_gfx_init()
hal_gfx_reg_write
void hal_gfx_reg_write(uint32_t reg, uint32_t value)
Write Hardware Register.
hal_gfx_rb_init
int hal_gfx_rb_init(hal_gfx_ringbuffer_t *rb, int reset)
Initialize Ring Buffer. Should be called from inside hal_gfx_sys_init(). This is a private function,...
hal_gfx_wait_irq_brk
int hal_gfx_wait_irq_brk(int brk_id)
Wait for a Breakpoint.
hal_gfx_buffer_t_::size
int size
Definition: hal_gfx_hal.h:37
hal_gfx_ringbuffer_t_
The ringbuffer structure.
Definition: hal_gfx_hal.h:45
hal_gfx_buffer_map
void * hal_gfx_buffer_map(hal_gfx_buffer_t *bo)
Maps buffer.
hal_gfx_ringbuffer_t_::bo
hal_gfx_buffer_t bo
Definition: hal_gfx_hal.h:46
hal_gfx_wait_irq_cl
int hal_gfx_wait_irq_cl(int cl_id)
Wait for a Command List to finish.
hal_gfx_mutex_unlock
int hal_gfx_mutex_unlock(int mutex_id)
Mutex Unlock for multiple processes/threads.
hal_gfx_buffer_create_pool
hal_gfx_buffer_t hal_gfx_buffer_create_pool(int pool, int size)
Create memory buffer at a specific pool.
hal_gfx_buffer_create
hal_gfx_buffer_t hal_gfx_buffer_create(int size)
Create memory buffer.
hal_gfx_sys_defs.h
hal_gfx_buffer_t_
The base structure of gpu memory.
Definition: hal_gfx_hal.h:36
hal_gfx_ringbuffer_t
struct hal_gfx_ringbuffer_t_ hal_gfx_ringbuffer_t
The ringbuffer structure.
hal_gfx_host_malloc
void * hal_gfx_host_malloc(size_t size)
Allocate memory for CPU to use (typically, standard malloc() is called)
hal_gfx_wait_irq
int hal_gfx_wait_irq(void)
Wait for interrupt from the GPU.
hal_gfx_buffer_t_::fd
int fd
Definition: hal_gfx_hal.h:38
hal_gfx_buffer_destroy
void hal_gfx_buffer_destroy(hal_gfx_buffer_t *bo)
Destroy/deallocate buffer.
hal_gfx_ringbuffer_t_::last_submission_id
int last_submission_id
Definition: hal_gfx_hal.h:48
hal_gfx_reg_read
uint32_t hal_gfx_reg_read(uint32_t reg)
Read Hardware register.
hal_gfx_buffer_t_::base_virt
void * base_virt
Definition: hal_gfx_hal.h:39
hal_gfx_mutex_lock
int hal_gfx_mutex_lock(int mutex_id)
Mutex Lock for multiple processes/threads.
hal_gfx_buffer_flush
void hal_gfx_buffer_flush(hal_gfx_buffer_t *bo)
Write-back buffer from cache to main memory.
hal_gfx_buffer_phys
uintptr_t hal_gfx_buffer_phys(hal_gfx_buffer_t *bo)
Get physical (GPU) base address of a given buffer.
hal_gfx_buffer_unmap
void hal_gfx_buffer_unmap(hal_gfx_buffer_t *bo)
Unmaps buffer.
hal_gfx_ringbuffer_t_::offset
int offset
Definition: hal_gfx_hal.h:47
pool
memory pool structure
Definition: tsi_malloc_intern.h:60
hal_gfx_buffer_t
struct hal_gfx_buffer_t_ hal_gfx_buffer_t
The base structure of gpu memory.
hal_gfx_host_free
void hal_gfx_host_free(void *ptr)
Free memory previously allocated with hal_gfx_host_malloc()
hal_gfx_buffer_t_::base_phys
uintptr_t base_phys
Definition: hal_gfx_hal.h:40