1 /* SPDX-License-Identifier: GPL-2.0-only OR MIT */
2 /* Copyright (c) 2023 Imagination Technologies Ltd. */
7 #include <drm/gpu_scheduler.h>
10 #include "pvr_device.h"
16 * struct pvr_queue_fence_ctx - Queue fence context
18 * Used to implement dma_fence_ops for pvr_job::{done,cccb}_fence.
20 struct pvr_queue_fence_ctx {
21 /** @id: Fence context ID allocated with dma_fence_context_alloc(). */
24 /** @seqno: Sequence number incremented each time a fence is created. */
27 /** @lock: Lock used to synchronize access to fences allocated by this context. */
32 * struct pvr_queue_cccb_fence_ctx - CCCB fence context
34 * Context used to manage fences controlling access to the CCCB. No fences are
35 * issued if there's enough space in the CCCB to push job commands.
37 struct pvr_queue_cccb_fence_ctx {
38 /** @base: Base queue fence context. */
39 struct pvr_queue_fence_ctx base;
42 * @job: Job waiting for CCCB space.
44 * Thanks to the serializationg done at the drm_sched_entity level,
45 * there's no more than one job waiting for CCCB at a given time.
47 * This field is NULL if no jobs are currently waiting for CCCB space.
49 * Must be accessed with @job_lock held.
53 /** @job_lock: Lock protecting access to the job object. */
54 struct mutex job_lock;
58 * struct pvr_queue_fence - Queue fence object
60 struct pvr_queue_fence {
61 /** @base: Base dma_fence. */
62 struct dma_fence base;
64 /** @queue: Queue that created this fence. */
65 struct pvr_queue *queue;
69 * struct pvr_queue - Job queue
71 * Used to queue and track execution of pvr_job objects.
74 /** @scheduler: Single entity scheduler use to push jobs to this queue. */
75 struct drm_gpu_scheduler scheduler;
77 /** @entity: Scheduling entity backing this queue. */
78 struct drm_sched_entity entity;
80 /** @type: Type of jobs queued to this queue. */
81 enum drm_pvr_job_type type;
83 /** @ctx: Context object this queue is bound to. */
84 struct pvr_context *ctx;
86 /** @node: Used to add the queue to the active/idle queue list. */
87 struct list_head node;
90 * @in_flight_job_count: Number of jobs submitted to the CCCB that
91 * have not been processed yet.
93 atomic_t in_flight_job_count;
96 * @cccb_fence_ctx: CCCB fence context.
98 * Used to control access to the CCCB is full, such that we don't
99 * end up trying to push commands to the CCCB if there's not enough
100 * space to receive all commands needed for a job to complete.
102 struct pvr_queue_cccb_fence_ctx cccb_fence_ctx;
104 /** @job_fence_ctx: Job fence context object. */
105 struct pvr_queue_fence_ctx job_fence_ctx;
107 /** @timeline_ufo: Timeline UFO for the context queue. */
109 /** @fw_obj: FW object representing the UFO value. */
110 struct pvr_fw_object *fw_obj;
112 /** @value: CPU mapping of the UFO value. */
117 * @last_queued_job_scheduled_fence: The scheduled fence of the last
118 * job queued to this queue.
120 * We use it to insert frag -> geom dependencies when issuing combined
121 * geom+frag jobs, to guarantee that the fragment job that's part of
122 * the combined operation comes after all fragment jobs that were queued
125 struct dma_fence *last_queued_job_scheduled_fence;
127 /** @cccb: Client Circular Command Buffer. */
128 struct pvr_cccb cccb;
130 /** @reg_state_obj: FW object representing the register state of this queue. */
131 struct pvr_fw_object *reg_state_obj;
133 /** @ctx_offset: Offset of the queue context in the FW context object. */
136 /** @callstack_addr: Initial call stack address for register state object. */
140 bool pvr_queue_fence_is_ufo_backed(struct dma_fence *f);
142 int pvr_queue_job_init(struct pvr_job *job);
144 void pvr_queue_job_cleanup(struct pvr_job *job);
146 void pvr_queue_job_push(struct pvr_job *job);
148 struct dma_fence *pvr_queue_job_arm(struct pvr_job *job);
150 struct pvr_queue *pvr_queue_create(struct pvr_context *ctx,
151 enum drm_pvr_job_type type,
152 struct drm_pvr_ioctl_create_context_args *args,
155 void pvr_queue_kill(struct pvr_queue *queue);
157 void pvr_queue_destroy(struct pvr_queue *queue);
159 void pvr_queue_process(struct pvr_queue *queue);
161 void pvr_queue_device_pre_reset(struct pvr_device *pvr_dev);
163 void pvr_queue_device_post_reset(struct pvr_device *pvr_dev);
165 int pvr_queue_device_init(struct pvr_device *pvr_dev);
167 void pvr_queue_device_fini(struct pvr_device *pvr_dev);
169 #endif /* PVR_QUEUE_H */