pvr_drv.h 5.1 KB

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