1
1
// SPDX-License-Identifier: GPL-2.0-only
2
2
/*
3
- * Copyright (C) 2020-2024 Intel Corporation
3
+ * Copyright (C) 2020-2025 Intel Corporation
4
4
*/
5
5
6
6
#include <drm/drm_file.h>
@@ -100,15 +100,51 @@ static struct ivpu_cmdq *ivpu_cmdq_alloc(struct ivpu_file_priv *file_priv)
100
100
return NULL ;
101
101
}
102
102
103
+ /**
104
+ * ivpu_cmdq_get_entry_count - Calculate the number of entries in the command queue.
105
+ * @cmdq: Pointer to the command queue structure.
106
+ *
107
+ * Returns the number of entries that can fit in the command queue memory.
108
+ */
109
+ static inline u32 ivpu_cmdq_get_entry_count (struct ivpu_cmdq * cmdq )
110
+ {
111
+ size_t size = ivpu_bo_size (cmdq -> mem ) - sizeof (struct vpu_job_queue_header );
112
+
113
+ return size / sizeof (struct vpu_job_queue_entry );
114
+ }
115
+
116
+ /**
117
+ * ivpu_cmdq_get_flags - Get command queue flags based on input flags and test mode.
118
+ * @vdev: Pointer to the ivpu device structure.
119
+ * @flags: Input flags to determine the command queue flags.
120
+ *
121
+ * Returns the calculated command queue flags, considering both the input flags
122
+ * and the current test mode settings.
123
+ */
124
+ static u32 ivpu_cmdq_get_flags (struct ivpu_device * vdev , u32 flags )
125
+ {
126
+ u32 cmdq_flags = 0 ;
127
+
128
+ if ((flags & DRM_IVPU_CMDQ_FLAG_TURBO ) && (ivpu_hw_ip_gen (vdev ) >= IVPU_HW_IP_40XX ))
129
+ cmdq_flags |= VPU_JOB_QUEUE_FLAGS_TURBO_MODE ;
130
+
131
+ /* Test mode can override the TURBO flag coming from the application */
132
+ if (ivpu_test_mode & IVPU_TEST_MODE_TURBO_ENABLE )
133
+ cmdq_flags |= VPU_JOB_QUEUE_FLAGS_TURBO_MODE ;
134
+ if (ivpu_test_mode & IVPU_TEST_MODE_TURBO_DISABLE )
135
+ cmdq_flags &= ~VPU_JOB_QUEUE_FLAGS_TURBO_MODE ;
136
+
137
+ return cmdq_flags ;
138
+ }
139
+
103
140
static void ivpu_cmdq_free (struct ivpu_file_priv * file_priv , struct ivpu_cmdq * cmdq )
104
141
{
105
142
ivpu_preemption_buffers_free (file_priv -> vdev , file_priv , cmdq );
106
143
ivpu_bo_free (cmdq -> mem );
107
144
kfree (cmdq );
108
145
}
109
146
110
- static struct ivpu_cmdq * ivpu_cmdq_create (struct ivpu_file_priv * file_priv , u8 priority ,
111
- bool is_legacy )
147
+ static struct ivpu_cmdq * ivpu_cmdq_create (struct ivpu_file_priv * file_priv , u8 priority , u32 flags )
112
148
{
113
149
struct ivpu_device * vdev = file_priv -> vdev ;
114
150
struct ivpu_cmdq * cmdq = NULL ;
@@ -121,18 +157,22 @@ static struct ivpu_cmdq *ivpu_cmdq_create(struct ivpu_file_priv *file_priv, u8 p
121
157
ivpu_err (vdev , "Failed to allocate command queue\n" );
122
158
return NULL ;
123
159
}
124
-
125
- cmdq -> priority = priority ;
126
- cmdq -> is_legacy = is_legacy ;
127
-
128
160
ret = xa_alloc_cyclic (& file_priv -> cmdq_xa , & cmdq -> id , cmdq , file_priv -> cmdq_limit ,
129
161
& file_priv -> cmdq_id_next , GFP_KERNEL );
130
162
if (ret < 0 ) {
131
163
ivpu_err (vdev , "Failed to allocate command queue ID: %d\n" , ret );
132
164
goto err_free_cmdq ;
133
165
}
134
166
135
- ivpu_dbg (vdev , JOB , "Command queue %d created, ctx %d\n" , cmdq -> id , file_priv -> ctx .id );
167
+ cmdq -> entry_count = ivpu_cmdq_get_entry_count (cmdq );
168
+ cmdq -> priority = priority ;
169
+
170
+ cmdq -> jobq = (struct vpu_job_queue * )ivpu_bo_vaddr (cmdq -> mem );
171
+ cmdq -> jobq -> header .engine_idx = VPU_ENGINE_COMPUTE ;
172
+ cmdq -> jobq -> header .flags = ivpu_cmdq_get_flags (vdev , flags );
173
+
174
+ ivpu_dbg (vdev , JOB , "Command queue %d created, ctx %d, flags 0x%08x\n" ,
175
+ cmdq -> id , file_priv -> ctx .id , cmdq -> jobq -> header .flags );
136
176
return cmdq ;
137
177
138
178
err_free_cmdq :
@@ -188,27 +228,14 @@ static int ivpu_register_db(struct ivpu_file_priv *file_priv, struct ivpu_cmdq *
188
228
return ret ;
189
229
}
190
230
191
- static void ivpu_cmdq_jobq_init (struct ivpu_device * vdev , struct vpu_job_queue * jobq )
231
+ static void ivpu_cmdq_jobq_reset (struct ivpu_device * vdev , struct vpu_job_queue * jobq )
192
232
{
193
- jobq -> header .engine_idx = VPU_ENGINE_COMPUTE ;
194
233
jobq -> header .head = 0 ;
195
234
jobq -> header .tail = 0 ;
196
235
197
- if (ivpu_test_mode & IVPU_TEST_MODE_TURBO ) {
198
- ivpu_dbg (vdev , JOB , "Turbo mode enabled" );
199
- jobq -> header .flags = VPU_JOB_QUEUE_FLAGS_TURBO_MODE ;
200
- }
201
-
202
236
wmb (); /* Flush WC buffer for jobq->header */
203
237
}
204
238
205
- static inline u32 ivpu_cmdq_get_entry_count (struct ivpu_cmdq * cmdq )
206
- {
207
- size_t size = ivpu_bo_size (cmdq -> mem ) - sizeof (struct vpu_job_queue_header );
208
-
209
- return size / sizeof (struct vpu_job_queue_entry );
210
- }
211
-
212
239
static int ivpu_cmdq_register (struct ivpu_file_priv * file_priv , struct ivpu_cmdq * cmdq )
213
240
{
214
241
struct ivpu_device * vdev = file_priv -> vdev ;
@@ -219,10 +246,7 @@ static int ivpu_cmdq_register(struct ivpu_file_priv *file_priv, struct ivpu_cmdq
219
246
if (cmdq -> db_id )
220
247
return 0 ;
221
248
222
- cmdq -> entry_count = ivpu_cmdq_get_entry_count (cmdq );
223
- cmdq -> jobq = (struct vpu_job_queue * )ivpu_bo_vaddr (cmdq -> mem );
224
-
225
- ivpu_cmdq_jobq_init (vdev , cmdq -> jobq );
249
+ ivpu_cmdq_jobq_reset (vdev , cmdq -> jobq );
226
250
227
251
if (vdev -> fw -> sched_mode == VPU_SCHEDULING_MODE_HW ) {
228
252
ret = ivpu_hws_cmdq_init (file_priv , cmdq , VPU_ENGINE_COMPUTE , cmdq -> priority );
@@ -291,9 +315,10 @@ static struct ivpu_cmdq *ivpu_cmdq_acquire_legacy(struct ivpu_file_priv *file_pr
291
315
break ;
292
316
293
317
if (!cmdq ) {
294
- cmdq = ivpu_cmdq_create (file_priv , priority , true );
318
+ cmdq = ivpu_cmdq_create (file_priv , priority , 0 );
295
319
if (!cmdq )
296
320
return NULL ;
321
+ cmdq -> is_legacy = true;
297
322
}
298
323
299
324
return cmdq ;
@@ -891,7 +916,7 @@ int ivpu_cmdq_create_ioctl(struct drm_device *dev, void *data, struct drm_file *
891
916
892
917
mutex_lock (& file_priv -> lock );
893
918
894
- cmdq = ivpu_cmdq_create (file_priv , ivpu_job_to_jsm_priority (args -> priority ), false );
919
+ cmdq = ivpu_cmdq_create (file_priv , ivpu_job_to_jsm_priority (args -> priority ), args -> flags );
895
920
if (cmdq )
896
921
args -> cmdq_id = cmdq -> id ;
897
922
0 commit comments