pvr_hwrt.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /* SPDX-License-Identifier: GPL-2.0-only OR MIT */
  2. /* Copyright (c) 2023 Imagination Technologies Ltd. */
  3. #ifndef PVR_HWRT_H
  4. #define PVR_HWRT_H
  5. #include <linux/compiler_attributes.h>
  6. #include <linux/kref.h>
  7. #include <linux/list.h>
  8. #include <linux/types.h>
  9. #include <linux/xarray.h>
  10. #include <uapi/drm/pvr_drm.h>
  11. #include "pvr_device.h"
  12. #include "pvr_rogue_fwif_shared.h"
  13. /* Forward declaration from pvr_free_list.h. */
  14. struct pvr_free_list;
  15. /* Forward declaration from pvr_gem.h. */
  16. struct pvr_fw_object;
  17. /**
  18. * struct pvr_hwrt_data - structure representing HWRT data
  19. */
  20. struct pvr_hwrt_data {
  21. /** @fw_obj: FW object representing the FW-side structure. */
  22. struct pvr_fw_object *fw_obj;
  23. /** @data: Local copy of FW-side structure. */
  24. struct rogue_fwif_hwrtdata data;
  25. /** @freelist_node: List node connecting this HWRT to the local freelist. */
  26. struct list_head freelist_node;
  27. /**
  28. * @srtc_obj: FW object representing shadow render target cache.
  29. *
  30. * Only valid if @max_rts > 1.
  31. */
  32. struct pvr_fw_object *srtc_obj;
  33. /**
  34. * @raa_obj: FW object representing renders accumulation array.
  35. *
  36. * Only valid if @max_rts > 1.
  37. */
  38. struct pvr_fw_object *raa_obj;
  39. /** @hwrt_dataset: Back pointer to owning HWRT dataset. */
  40. struct pvr_hwrt_dataset *hwrt_dataset;
  41. };
  42. /**
  43. * struct pvr_hwrt_dataset - structure representing a HWRT data set.
  44. */
  45. struct pvr_hwrt_dataset {
  46. /** @ref_count: Reference count of object. */
  47. struct kref ref_count;
  48. /** @pvr_dev: Pointer to device that owns this object. */
  49. struct pvr_device *pvr_dev;
  50. /** @common_fw_obj: FW object representing common FW-side structure. */
  51. struct pvr_fw_object *common_fw_obj;
  52. /** @common: Common HWRT data. */
  53. struct rogue_fwif_hwrtdata_common common;
  54. /** @data: HWRT data structures belonging to this set. */
  55. struct pvr_hwrt_data data[ROGUE_FWIF_NUM_RTDATAS];
  56. /** @free_lists: Free lists used by HWRT data set. */
  57. struct pvr_free_list *free_lists[ROGUE_FWIF_NUM_RTDATA_FREELISTS];
  58. /** @max_rts: Maximum render targets for this HWRT data set. */
  59. u16 max_rts;
  60. };
  61. struct pvr_hwrt_dataset *
  62. pvr_hwrt_dataset_create(struct pvr_file *pvr_file,
  63. struct drm_pvr_ioctl_create_hwrt_dataset_args *args);
  64. void
  65. pvr_destroy_hwrt_datasets_for_file(struct pvr_file *pvr_file);
  66. /**
  67. * pvr_hwrt_dataset_lookup() - Lookup HWRT dataset pointer from handle
  68. * @pvr_file: Pointer to pvr_file structure.
  69. * @handle: Object handle.
  70. *
  71. * Takes reference on dataset object. Call pvr_hwrt_dataset_put() to release.
  72. *
  73. * Returns:
  74. * * The requested object on success, or
  75. * * %NULL on failure (object does not exist in list, or is not a HWRT
  76. * dataset)
  77. */
  78. static __always_inline struct pvr_hwrt_dataset *
  79. pvr_hwrt_dataset_lookup(struct pvr_file *pvr_file, u32 handle)
  80. {
  81. struct pvr_hwrt_dataset *hwrt;
  82. xa_lock(&pvr_file->hwrt_handles);
  83. hwrt = xa_load(&pvr_file->hwrt_handles, handle);
  84. if (hwrt)
  85. kref_get(&hwrt->ref_count);
  86. xa_unlock(&pvr_file->hwrt_handles);
  87. return hwrt;
  88. }
  89. void
  90. pvr_hwrt_dataset_put(struct pvr_hwrt_dataset *hwrt);
  91. /**
  92. * pvr_hwrt_data_lookup() - Lookup HWRT data pointer from handle and index
  93. * @pvr_file: Pointer to pvr_file structure.
  94. * @handle: Object handle.
  95. * @index: Index of RT data within dataset.
  96. *
  97. * Takes reference on dataset object. Call pvr_hwrt_data_put() to release.
  98. *
  99. * Returns:
  100. * * The requested object on success, or
  101. * * %NULL on failure (object does not exist in list, or is not a HWRT
  102. * dataset, or index is out of range)
  103. */
  104. static __always_inline struct pvr_hwrt_data *
  105. pvr_hwrt_data_lookup(struct pvr_file *pvr_file, u32 handle, u32 index)
  106. {
  107. struct pvr_hwrt_dataset *hwrt_dataset = pvr_hwrt_dataset_lookup(pvr_file, handle);
  108. if (hwrt_dataset) {
  109. if (index < ARRAY_SIZE(hwrt_dataset->data))
  110. return &hwrt_dataset->data[index];
  111. pvr_hwrt_dataset_put(hwrt_dataset);
  112. }
  113. return NULL;
  114. }
  115. /**
  116. * pvr_hwrt_data_put() - Release reference on HWRT data
  117. * @hwrt: Pointer to HWRT data to release reference on
  118. */
  119. static __always_inline void
  120. pvr_hwrt_data_put(struct pvr_hwrt_data *hwrt)
  121. {
  122. if (hwrt)
  123. pvr_hwrt_dataset_put(hwrt->hwrt_dataset);
  124. }
  125. static __always_inline struct pvr_hwrt_data *
  126. pvr_hwrt_data_get(struct pvr_hwrt_data *hwrt)
  127. {
  128. if (hwrt)
  129. kref_get(&hwrt->hwrt_dataset->ref_count);
  130. return hwrt;
  131. }
  132. #endif /* PVR_HWRT_H */