1 /*
2 * Copyright © 2014 Broadcom
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #ifndef VC4_SIMULATOR_VALIDATE_H
25 #define VC4_SIMULATOR_VALIDATE_H
26
27 #include <stdbool.h>
28 #include <string.h>
29 #include <stdlib.h>
30 #include <stdint.h>
31 #include <stdio.h>
32 #include <errno.h>
33
34 #include "vc4_context.h"
35 #include "vc4_qpu_defines.h"
36
37 struct vc4_exec_info;
38
39 #define DRM_INFO(...) fprintf(stderr, __VA_ARGS__)
40 #define DRM_ERROR(...) fprintf(stderr, __VA_ARGS__)
41 #define kmalloc(size, arg) malloc(size)
42 #define kcalloc(size, count, arg) calloc(size, count)
43 #define kfree(ptr) free(ptr)
44 #define krealloc(ptr, size, args) realloc(ptr, size)
45 #define roundup(x, y) align(x, y)
46 #define round_up(x, y) align(x, y)
47 #define max(x, y) MAX2(x, y)
48 #define min(x, y) MIN2(x, y)
49 #define BUG_ON(condition) assert(!(condition))
50 #define BIT(bit) (1u << bit)
51
52 /* Unsigned long-based bitmap interface in the linux kernel */
53 #define BITMAP_WORDBITS (sizeof(unsigned long) * 8)
54 #define BITS_TO_LONGS(bits) (roundup(bits, BITMAP_WORDBITS) / \
55 sizeof(unsigned long))
56 static inline bool
test_bit(unsigned int bit,unsigned long * addr)57 test_bit(unsigned int bit, unsigned long *addr)
58 {
59 return addr[bit / BITMAP_WORDBITS] & (1ul << (bit % BITMAP_WORDBITS));
60 }
61
62 static inline bool
set_bit(unsigned int bit,unsigned long * addr)63 set_bit(unsigned int bit, unsigned long *addr)
64 {
65 return addr[bit / BITMAP_WORDBITS] |= (1ul << (bit % BITMAP_WORDBITS));
66 }
67
68
69 static inline int
copy_from_user(void * dst,void * src,size_t size)70 copy_from_user(void *dst, void *src, size_t size)
71 {
72 memcpy(dst, src, size);
73 return 0;
74 }
75
76 typedef uint8_t u8;
77 typedef uint16_t u16;
78 typedef uint32_t u32;
79
80 struct drm_device {
81 struct vc4_screen *screen;
82 };
83
84 struct drm_gem_object {
85 size_t size;
86 struct drm_device *dev;
87 };
88
89 struct drm_gem_cma_object {
90 struct drm_gem_object base;
91 uint32_t paddr;
92 void *vaddr;
93 };
94
95 struct drm_vc4_bo {
96 struct drm_gem_cma_object base;
97 struct vc4_validated_shader_info *validated_shader;
98 struct list_head unref_head;
99 };
100
to_vc4_bo(struct drm_gem_object * obj)101 static inline struct drm_vc4_bo *to_vc4_bo(struct drm_gem_object *obj)
102 {
103 return (struct drm_vc4_bo *)obj;
104 }
105
106 struct drm_gem_cma_object *
107 drm_gem_cma_create(struct drm_device *dev, size_t size);
108
109 int
110 vc4_cl_validate(struct drm_device *dev, struct vc4_exec_info *exec);
111
112 #endif /* VC4_SIMULATOR_VALIDATE_H */
113