pvr_queue.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /* SPDX-License-Identifier: GPL-2.0-only OR MIT */
  2. /* Copyright (c) 2023 Imagination Technologies Ltd. */
  3. #ifndef PVR_QUEUE_H
  4. #define PVR_QUEUE_H
  5. #include <drm/gpu_scheduler.h>
  6. #include <linux/workqueue.h>
  7. #include "pvr_cccb.h"
  8. #include "pvr_device.h"
  9. struct pvr_context;
  10. struct pvr_queue;
  11. /**
  12. * struct pvr_queue_fence_ctx - Queue fence context
  13. *
  14. * Used to implement dma_fence_ops for pvr_job::{done,cccb}_fence.
  15. */
  16. struct pvr_queue_fence_ctx {
  17. /** @id: Fence context ID allocated with dma_fence_context_alloc(). */
  18. u64 id;
  19. /** @seqno: Sequence number incremented each time a fence is created. */
  20. atomic_t seqno;
  21. /** @lock: Lock used to synchronize access to fences allocated by this context. */
  22. spinlock_t lock;
  23. };
  24. /**
  25. * struct pvr_queue_cccb_fence_ctx - CCCB fence context
  26. *
  27. * Context used to manage fences controlling access to the CCCB. No fences are
  28. * issued if there's enough space in the CCCB to push job commands.
  29. */
  30. struct pvr_queue_cccb_fence_ctx {
  31. /** @base: Base queue fence context. */
  32. struct pvr_queue_fence_ctx base;
  33. /**
  34. * @job: Job waiting for CCCB space.
  35. *
  36. * Thanks to the serializationg done at the drm_sched_entity level,
  37. * there's no more than one job waiting for CCCB at a given time.
  38. *
  39. * This field is NULL if no jobs are currently waiting for CCCB space.
  40. *
  41. * Must be accessed with @job_lock held.
  42. */
  43. struct pvr_job *job;
  44. /** @job_lock: Lock protecting access to the job object. */
  45. struct mutex job_lock;
  46. };
  47. /**
  48. * struct pvr_queue_fence - Queue fence object
  49. */
  50. struct pvr_queue_fence {
  51. /** @base: Base dma_fence. */
  52. struct dma_fence base;
  53. /** @queue: Queue that created this fence. */
  54. struct pvr_queue *queue;
  55. /** @release_work: Fence release work structure. */
  56. struct work_struct release_work;
  57. };
  58. /**
  59. * struct pvr_queue - Job queue
  60. *
  61. * Used to queue and track execution of pvr_job objects.
  62. */
  63. struct pvr_queue {
  64. /** @scheduler: Single entity scheduler use to push jobs to this queue. */
  65. struct drm_gpu_scheduler scheduler;
  66. /** @entity: Scheduling entity backing this queue. */
  67. struct drm_sched_entity entity;
  68. /** @type: Type of jobs queued to this queue. */
  69. enum drm_pvr_job_type type;
  70. /** @ctx: Context object this queue is bound to. */
  71. struct pvr_context *ctx;
  72. /** @node: Used to add the queue to the active/idle queue list. */
  73. struct list_head node;
  74. /**
  75. * @in_flight_job_count: Number of jobs submitted to the CCCB that
  76. * have not been processed yet.
  77. */
  78. atomic_t in_flight_job_count;
  79. /**
  80. * @cccb_fence_ctx: CCCB fence context.
  81. *
  82. * Used to control access to the CCCB is full, such that we don't
  83. * end up trying to push commands to the CCCB if there's not enough
  84. * space to receive all commands needed for a job to complete.
  85. */
  86. struct pvr_queue_cccb_fence_ctx cccb_fence_ctx;
  87. /** @job_fence_ctx: Job fence context object. */
  88. struct pvr_queue_fence_ctx job_fence_ctx;
  89. /** @timeline_ufo: Timeline UFO for the context queue. */
  90. struct {
  91. /** @fw_obj: FW object representing the UFO value. */
  92. struct pvr_fw_object *fw_obj;
  93. /** @value: CPU mapping of the UFO value. */
  94. u32 *value;
  95. } timeline_ufo;
  96. /**
  97. * @last_queued_job_scheduled_fence: The scheduled fence of the last
  98. * job queued to this queue.
  99. *
  100. * We use it to insert frag -> geom dependencies when issuing combined
  101. * geom+frag jobs, to guarantee that the fragment job that's part of
  102. * the combined operation comes after all fragment jobs that were queued
  103. * before it.
  104. */
  105. struct dma_fence *last_queued_job_scheduled_fence;
  106. /** @cccb: Client Circular Command Buffer. */
  107. struct pvr_cccb cccb;
  108. /** @reg_state_obj: FW object representing the register state of this queue. */
  109. struct pvr_fw_object *reg_state_obj;
  110. /** @ctx_offset: Offset of the queue context in the FW context object. */
  111. u32 ctx_offset;
  112. /** @callstack_addr: Initial call stack address for register state object. */
  113. u64 callstack_addr;
  114. };
  115. bool pvr_queue_fence_is_ufo_backed(struct dma_fence *f);
  116. int pvr_queue_job_init(struct pvr_job *job);
  117. void pvr_queue_job_cleanup(struct pvr_job *job);
  118. void pvr_queue_job_push(struct pvr_job *job);
  119. struct dma_fence *pvr_queue_job_arm(struct pvr_job *job);
  120. struct pvr_queue *pvr_queue_create(struct pvr_context *ctx,
  121. enum drm_pvr_job_type type,
  122. struct drm_pvr_ioctl_create_context_args *args,
  123. void *fw_ctx_map);
  124. void pvr_queue_kill(struct pvr_queue *queue);
  125. void pvr_queue_destroy(struct pvr_queue *queue);
  126. void pvr_queue_process(struct pvr_queue *queue);
  127. void pvr_queue_device_pre_reset(struct pvr_device *pvr_dev);
  128. void pvr_queue_device_post_reset(struct pvr_device *pvr_dev);
  129. int pvr_queue_device_init(struct pvr_device *pvr_dev);
  130. void pvr_queue_device_fini(struct pvr_device *pvr_dev);
  131. #endif /* PVR_QUEUE_H */