1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
|
/****************************************************************************
*
* The MIT License (MIT)
*
* Copyright (c) 2014 - 2020 Vivante Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*****************************************************************************/
#ifndef _vg_lite_kernel_h_
#define _vg_lite_kernel_h_
#include "vg_lite_os.h"
/* Interrupt IDs from GPU. */
#define EVENT_UNEXPECTED_MESH 0x80000000
#define EVENT_CMD_BAD_WRITE 0x40000000
#define EVENT_ERROR_RECOVER 0x20000000
#define EVENT_CMD_SWITCH 0x10000000
#define EVENT_MCU_BAD_WRITE 0x08000000
#define EVENT_END 0
#define MAX_CONTIGUOUS_SIZE 0x02000000
#define VG_LITE_INFINITE 0xFFFFFFFF
#define VG_LITE_MAX_WAIT_TIME 0x130000
#define CMDBUF_COUNT 2
#define VG_LITE_ALIGN(number, alignment) \
(((number) + ((alignment) - 1)) & ~((alignment) - 1))
/* Available function optimization levels */
#if (defined(__ICCARM__))
#define VG_LITE_ATTR_OPTIMIZE_LOW _Pragma("optimize=none")
#define VG_LITE_ATTR_OPTIMIZE_MEDIUM _Pragma("optimize=medium")
#define VG_LITE_ATTR_OPTIMIZE_HIGH _Pragma("optimize=high")
#else /* ARMGCC */
#define VG_LITE_ATTR_OPTIMIZE_LOW __attribute__((optimize(1)))
#define VG_LITE_ATTR_OPTIMIZE_MEDIUM __attribute__((optimize(2)))
#define VG_LITE_ATTR_OPTIMIZE_HIGH __attribute__((optimize(3)))
#endif /* defined(__ICCARM__) */
/* Allow develpers to force a function optimization level */
#define VG_LITE_OPTIMIZE(level) VG_LITE_ATTR_OPTIMIZE_##level
#define VG_LITE_KERNEL_IS_GPU_IDLE() \
((vg_lite_hal_peek(VG_LITE_HW_IDLE) & VG_LITE_HW_IDLE_STATE) == VG_LITE_HW_IDLE_STATE)
/* Hardware chip Ids */
#define GPU_CHIP_ID_GCNanoliteV 0x255
#define GPU_CHIP_ID_GC355 0x355
#ifdef __cplusplus
extern "C" {
#endif
#ifndef VG_LITE_ERROR
#define VG_LITE_ERROR 1
/*!
@abstract Error codes that the vg_lite functions can return.
@discussion
All API functions return a status code. On success, <code>VG_LITE_SUCCESS</code> will be returned when a function is
successful. This value is set to zero, so if any function returns a non-zero value, an error has occured.
*/
typedef enum vg_lite_error
{
VG_LITE_SUCCESS = 0, /*! Success. */
VG_LITE_INVALID_ARGUMENT, /*! An invalid argument was specified. */
VG_LITE_OUT_OF_MEMORY, /*! Out of memory. */
VG_LITE_NO_CONTEXT, /*! No context or an unintialized context specified. */
VG_LITE_TIMEOUT, /*! A timeout has occured during a wait. */
VG_LITE_OUT_OF_RESOURCES, /*! Out of system resources. */
VG_LITE_GENERIC_IO, /*! Cannot communicate with the kernel driver. */
VG_LITE_NOT_SUPPORT, /*! Function call not supported. */
VG_LITE_MULTI_THREAD_FAIL, /*! Multi-thread/tasks fail. */
VG_LITE_ALREADY_EXISTS, /*! Object already exists */
VG_LITE_NOT_ALIGNED, /*! Data alignment error */
}
vg_lite_error_t;
#endif
#if !defined(VG_DRIVER_SINGLE_THREAD)
typedef enum vg_lite_buffer_signal
{
VG_LITE_IDLE = 0, /*! Buffer available. */
VG_LITE_HW_FINISHED, /*! HW has completed command buffer. */
VG_LITE_IN_QUEUE, /*! Buffer has been send to queue. */
}
vg_lite_buffer_signal_t;
#endif /* not defined(VG_DRIVER_SINGLE_THREAD) */
typedef enum vg_lite_kernel_counter
{
/* Dont't touch the counter. */
VG_LITE_NONE,
/* Turn the counter on. */
VG_LITE_ON,
/* Turn the counter off. */
VG_LITE_OFF,
/* Query the counter and reset its values. */
VG_LITE_QUERY,
}
vg_lite_kernel_counter_t;
typedef enum vg_lite_kernel_command
{
/* Initialize the GPU. */
VG_LITE_INITIALIZE,
/* Terminate the GPU. */
VG_LITE_TERMINATE,
/* Allocate memory. */
VG_LITE_ALLOCATE,
/* Free memory. */
VG_LITE_FREE,
/* Submit a command buffer to the GPU. */
VG_LITE_SUBMIT,
/* Wait for the GPU to be completed. */
VG_LITE_WAIT,
/* Reset the GPU. */
VG_LITE_RESET,
/* Debug commands. */
VG_LITE_DEBUG,
/* Map memory. */
VG_LITE_MAP,
/* Unmap memory. */
VG_LITE_UNMAP,
/* Check info. */
VG_LITE_CHECK,
/* Query mem. */
VG_LITE_QUERY_MEM,
#if !defined(VG_DRIVER_SINGLE_THREAD)
/* Mutex lock. */
VG_LITE_LOCK,
/* Mutex unlock. */
VG_LITE_UNLOCK,
/* query context switch. */
VG_LITE_QUERY_CONTEXT_SWITCH,
#endif /* not defined(VG_DRIVER_SINGLE_THREAD) */
}
vg_lite_kernel_command_t;
struct vg_lite_kernel_context {
/* Command buffer. */
void * command_buffer[CMDBUF_COUNT];
void * command_buffer_logical[CMDBUF_COUNT];
uint32_t command_buffer_physical[CMDBUF_COUNT];
#if !defined(VG_DRIVER_SINGLE_THREAD)
vg_lite_os_async_event_t async_event[CMDBUF_COUNT];
#endif /* not defined(VG_DRIVER_SINGLE_THREAD) */
/* Tessellation buffer. */
void * tessellation_buffer;
void * tessellation_buffer_logical;
uint32_t tessellation_buffer_physical;
#if !defined(VG_DRIVER_SINGLE_THREAD)
/* context buffer. */
void * context_buffer[CMDBUF_COUNT];
void * context_buffer_logical[CMDBUF_COUNT];
uint32_t context_buffer_physical[CMDBUF_COUNT];
#endif /* not defined(VG_DRIVER_SINGLE_THREAD) */
};
/* Context structure. */
typedef struct vg_lite_kernel_context vg_lite_kernel_context_t;
typedef struct capabilities
{
uint32_t tiled : 2;
uint32_t l2_cache : 1;
}
capabilities_t;
typedef union vg_lite_capabilities
{
capabilities_t cap;
uint32_t data;
}
vg_lite_capabilities_t;
typedef struct vg_lite_kernel_initialize
{
/* Command buffer size. */
uint32_t command_buffer_size;
#if !defined(VG_DRIVER_SINGLE_THREAD)
/* Context buffer size. */
uint32_t context_buffer_size;
#endif /* not defined(VG_DRIVER_SINGLE_THREAD) */
/* Tessellation buffer width. */
int32_t tessellation_width;
/* Tessellation buffer height. */
int32_t tessellation_height;
/* OUTPUT */
/* Context pointer. */
vg_lite_kernel_context_t * context;
/* Capabilities. */
vg_lite_capabilities_t capabilities;
/* Allocated command buffer. */
void * command_buffer[CMDBUF_COUNT];
/* GPU address for command buffer. */
uint32_t command_buffer_gpu[CMDBUF_COUNT];
#if !defined(VG_DRIVER_SINGLE_THREAD)
/* Allocated context buffer. */
void * context_buffer[CMDBUF_COUNT];
/* GPU address for context buffer. */
uint32_t context_buffer_gpu[CMDBUF_COUNT];
#endif /* not defined(VG_DRIVER_SINGLE_THREAD) */
/* GPU addresses for tesselation buffers. */
uint32_t tessellation_buffer_gpu[3];
/* Logic addresses for tessellation buffers: used by SW Tessellator. */
uint8_t *tessellation_buffer_logic[3];
/* Size of each level of the tesselation buffer. */
uint32_t tessellation_buffer_size[3];
/* Stride of the tessellation buffer. */
uint32_t tessellation_stride;
/* Width and height of tessellation buffer. */
uint32_t tessellation_width_height;
/* Tessellation config: shift. */
uint32_t tessellation_shift;
}
vg_lite_kernel_initialize_t;
typedef struct vg_lite_kernel_terminate
{
/* Context to terminate. */
vg_lite_kernel_context_t * context;
}
vg_lite_kernel_terminate_t;
typedef struct vg_lite_kernel_allocate
{
/* Number of bytes to allocate. */
uint32_t bytes;
/* Flag to indicate whether the allocated memory is contiguous or not. */
int32_t contiguous;
/* OUTPUT */
/* Memory handle. */
void * memory_handle;
/* Allocated memory. */
void * memory;
/* GPU address of allocated memory. */
uint32_t memory_gpu;
}
vg_lite_kernel_allocate_t;
typedef struct vg_lite_kernel_free
{
/* Memory handle to free. */
void * memory_handle;
}
vg_lite_kernel_free_t;
typedef struct vg_lite_kernel_submit
{
/* Context to submit to. */
vg_lite_kernel_context_t * context;
/* Pointer to command buffer. */
void * commands;
/* Number of bytes in command buffer. */
uint32_t command_size;
/* Command Buffer ID. */
uint32_t command_id;
}
vg_lite_kernel_submit_t;
typedef struct vg_lite_kernel_wait
{
/* Context to wait for. */
vg_lite_kernel_context_t * context;
/* Timeout in milliseconds. */
uint32_t timeout_ms;
#if defined(VG_DRIVER_SINGLE_THREAD)
/* The event to wait. */
uint32_t event_mask;
/* The event(s) got after waiting. */
uint32_t event_got;
#else
/* Command Buffer ID. */
uint32_t command_id;
#endif /* VG_DRIVER_SINGLE_THREAD */
}
vg_lite_kernel_wait_t;
typedef struct vg_lite_kernel_reset
{
/* Context to reset. */
vg_lite_kernel_context_t * context;
}
vg_lite_kernel_reset_t;
typedef struct vg_lite_kernel_debug
{
/* Context to debug. */
vg_lite_kernel_context_t * context;
/* Bandwidth counter enabler. */
vg_lite_kernel_counter_t bandwidth_counter;
/* Pixel counter enabler. */
vg_lite_kernel_counter_t pixel_counters;
/* OUTPUT */
/* Bandwidth counters:
* [0] - burst of 8.
* [1] - burst of 16.
* [2] - burst of 32.
* [3] - burst of 64.
*/
uint32_t bandwidth[4];
/* Pixel counters:.
* [0] - Number of tessellated pixels.
* [1] - Number of imaged pixels.
* [2] - Number of rendered pixels.
*/
uint32_t pixels[3];
}
vg_lite_kernel_debug_t;
typedef struct vg_lite_kernel_map
{
/* Number of bytes to map. */
uint32_t bytes;
/* Logical memory address or NULL. */
void * logical;
/* Physical memory address or 0. */
uint32_t physical;
/* OUTPUT */
/* Memory handle for mapped memory. */
void * memory_handle;
/* GPU address of mapped memory. */
uint32_t memory_gpu;
}
vg_lite_kernel_map_t;
typedef struct vg_lite_kernel_unmap
{
/* Memory handle to unmap. */
void * memory_handle;
}
vg_lite_kernel_unmap_t;
typedef struct vg_lite_kernel_info
{
/* Register's address. */
uint32_t addr;
/* Check register info. */
uint32_t reg;
}
vg_lite_kernel_info_t;
typedef struct vg_lite_kernel_mem
{
uint32_t bytes;
}
vg_lite_kernel_mem_t;
#if !defined(VG_DRIVER_SINGLE_THREAD)
typedef struct vg_lite_kernel_context_switch
{
uint8_t isContextSwitched;
uint32_t context;
}
vg_lite_kernel_context_switch_t;
#endif /* not defined(VG_DRIVER_SINGLE_THREAD) */
vg_lite_error_t vg_lite_kernel(vg_lite_kernel_command_t command, void * data);
#ifdef __cplusplus
}
#endif
#endif /* _vg_lite_kernel_h_ */
|