xref: /linux/drivers/gpu/drm/imagination/pvr_drv.h (revision 0ea5c948cb64bab5bc7a5516774eb8536f05aa0d)
1 /* SPDX-License-Identifier: GPL-2.0-only OR MIT */
2 /* Copyright (c) 2023 Imagination Technologies Ltd. */
3 
4 #ifndef PVR_DRV_H
5 #define PVR_DRV_H
6 
7 #include "linux/compiler_attributes.h"
8 #include <uapi/drm/pvr_drm.h>
9 
10 #define PVR_DRIVER_NAME "powervr"
11 #define PVR_DRIVER_DESC "Imagination PowerVR (Series 6 and later) & IMG Graphics"
12 #define PVR_DRIVER_DATE "20230904"
13 
14 /*
15  * Driver interface version:
16  *  - 1.0: Initial interface
17  */
18 #define PVR_DRIVER_MAJOR 1
19 #define PVR_DRIVER_MINOR 0
20 #define PVR_DRIVER_PATCHLEVEL 0
21 
22 int pvr_get_uobj(u64 usr_ptr, u32 usr_size, u32 min_size, u32 obj_size, void *out);
23 int pvr_set_uobj(u64 usr_ptr, u32 usr_size, u32 min_size, u32 obj_size, const void *in);
24 int pvr_get_uobj_array(const struct drm_pvr_obj_array *in, u32 min_stride, u32 obj_size,
25 		       void **out);
26 int pvr_set_uobj_array(const struct drm_pvr_obj_array *out, u32 min_stride, u32 obj_size,
27 		       const void *in);
28 
29 #define PVR_UOBJ_MIN_SIZE_INTERNAL(_typename, _last_mandatory_field) \
30 	(offsetof(_typename, _last_mandatory_field) + \
31 	 sizeof(((_typename *)NULL)->_last_mandatory_field))
32 
33 /* NOLINTBEGIN(bugprone-macro-parentheses) */
34 #define PVR_UOBJ_DECL(_typename, _last_mandatory_field) \
35 	, _typename : PVR_UOBJ_MIN_SIZE_INTERNAL(_typename, _last_mandatory_field)
36 /* NOLINTEND(bugprone-macro-parentheses) */
37 
38 /**
39  * DOC: PVR user objects.
40  *
41  * Macros used to aid copying structured and array data to and from
42  * userspace. Objects can differ in size, provided the minimum size
43  * allowed is specified (using the last mandatory field in the struct).
44  * All types used with PVR_UOBJ_GET/SET macros must be listed here under
45  * PVR_UOBJ_MIN_SIZE, with the last mandatory struct field specified.
46  */
47 
48 /**
49  * PVR_UOBJ_MIN_SIZE() - Fetch the minimum copy size of a compatible type object.
50  * @_obj_name: The name of the object. Cannot be a typename - this is deduced.
51  *
52  * This cannot fail. Using the macro with an incompatible type will result in a
53  * compiler error.
54  *
55  * To add compatibility for a type, list it within the macro in an orderly
56  * fashion. The second argument is the name of the last mandatory field of the
57  * struct type, which is used to calculate the size. See also PVR_UOBJ_DECL().
58  *
59  * Return: The minimum copy size.
60  */
61 #define PVR_UOBJ_MIN_SIZE(_obj_name) _Generic(_obj_name \
62 	PVR_UOBJ_DECL(struct drm_pvr_job, hwrt) \
63 	PVR_UOBJ_DECL(struct drm_pvr_sync_op, value) \
64 	PVR_UOBJ_DECL(struct drm_pvr_dev_query_gpu_info, num_phantoms) \
65 	PVR_UOBJ_DECL(struct drm_pvr_dev_query_runtime_info, cdm_max_local_mem_size_regs) \
66 	PVR_UOBJ_DECL(struct drm_pvr_dev_query_quirks, _padding_c) \
67 	PVR_UOBJ_DECL(struct drm_pvr_dev_query_enhancements, _padding_c) \
68 	PVR_UOBJ_DECL(struct drm_pvr_heap, page_size_log2) \
69 	PVR_UOBJ_DECL(struct drm_pvr_dev_query_heap_info, heaps) \
70 	PVR_UOBJ_DECL(struct drm_pvr_static_data_area, offset) \
71 	PVR_UOBJ_DECL(struct drm_pvr_dev_query_static_data_areas, static_data_areas) \
72 	)
73 
74 /**
75  * PVR_UOBJ_GET() - Copies from _src_usr_ptr to &_dest_obj.
76  * @_dest_obj: The destination container object in kernel space.
77  * @_usr_size: The size of the source container in user space.
78  * @_src_usr_ptr: __u64 raw pointer to the source container in user space.
79  *
80  * Return: Error code. See pvr_get_uobj().
81  */
82 #define PVR_UOBJ_GET(_dest_obj, _usr_size, _src_usr_ptr) \
83 	pvr_get_uobj(_src_usr_ptr, _usr_size, \
84 		     PVR_UOBJ_MIN_SIZE(_dest_obj), \
85 		     sizeof(_dest_obj), &(_dest_obj))
86 
87 /**
88  * PVR_UOBJ_SET() - Copies from &_src_obj to _dest_usr_ptr.
89  * @_dest_usr_ptr: __u64 raw pointer to the destination container in user space.
90  * @_usr_size: The size of the destination container in user space.
91  * @_src_obj: The source container object in kernel space.
92  *
93  * Return: Error code. See pvr_set_uobj().
94  */
95 #define PVR_UOBJ_SET(_dest_usr_ptr, _usr_size, _src_obj) \
96 	pvr_set_uobj(_dest_usr_ptr, _usr_size, \
97 		     PVR_UOBJ_MIN_SIZE(_src_obj), \
98 		     sizeof(_src_obj), &(_src_obj))
99 
100 /**
101  * PVR_UOBJ_GET_ARRAY() - Copies from @_src_drm_pvr_obj_array.array to
102  * alloced memory and returns a pointer in _dest_array.
103  * @_dest_array: The destination C array object in kernel space.
104  * @_src_drm_pvr_obj_array: The &struct drm_pvr_obj_array containing a __u64 raw
105  * pointer to the source C array in user space and the size of each array
106  * element in user space (the 'stride').
107  *
108  * Return: Error code. See pvr_get_uobj_array().
109  */
110 #define PVR_UOBJ_GET_ARRAY(_dest_array, _src_drm_pvr_obj_array) \
111 	pvr_get_uobj_array(_src_drm_pvr_obj_array, \
112 			   PVR_UOBJ_MIN_SIZE((_dest_array)[0]), \
113 			   sizeof((_dest_array)[0]), (void **)&(_dest_array))
114 
115 /**
116  * PVR_UOBJ_SET_ARRAY() - Copies from _src_array to @_dest_drm_pvr_obj_array.array.
117  * @_dest_drm_pvr_obj_array: The &struct drm_pvr_obj_array containing a __u64 raw
118  * pointer to the destination C array in user space and the size of each array
119  * element in user space (the 'stride').
120  * @_src_array: The source C array object in kernel space.
121  *
122  * Return: Error code. See pvr_set_uobj_array().
123  */
124 #define PVR_UOBJ_SET_ARRAY(_dest_drm_pvr_obj_array, _src_array) \
125 	pvr_set_uobj_array(_dest_drm_pvr_obj_array, \
126 			   PVR_UOBJ_MIN_SIZE((_src_array)[0]), \
127 			   sizeof((_src_array)[0]), _src_array)
128 
129 #endif /* PVR_DRV_H */
130