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