21
21
#include "vpu_boot_api.h"
22
22
23
23
#define CMD_BUF_IDX 0
24
- #define JOB_ID_JOB_MASK GENMASK(7, 0)
25
- #define JOB_ID_CONTEXT_MASK GENMASK(31, 8)
26
24
#define JOB_MAX_BUFFER_COUNT 65535
27
25
28
26
static void ivpu_cmdq_ring_db (struct ivpu_device * vdev , struct ivpu_cmdq * cmdq )
@@ -77,9 +75,28 @@ static void ivpu_preemption_buffers_free(struct ivpu_device *vdev,
77
75
ivpu_bo_free (cmdq -> secondary_preempt_buf );
78
76
}
79
77
78
+ static int ivpu_id_alloc (struct xarray * xa , u32 * id , void * entry , struct xa_limit * limit ,
79
+ const struct xa_limit default_limit )
80
+ {
81
+ int ret ;
82
+
83
+ ret = __xa_alloc (xa , id , entry , * limit , GFP_KERNEL );
84
+ if (ret ) {
85
+ limit -> min = default_limit .min ;
86
+ ret = __xa_alloc (xa , id , entry , * limit , GFP_KERNEL );
87
+ if (ret )
88
+ return ret ;
89
+ }
90
+
91
+ limit -> min = * id + 1 ;
92
+ if (limit -> min > limit -> max )
93
+ limit -> min = default_limit .min ;
94
+
95
+ return ret ;
96
+ }
97
+
80
98
static struct ivpu_cmdq * ivpu_cmdq_alloc (struct ivpu_file_priv * file_priv )
81
99
{
82
- struct xa_limit db_xa_limit = {.max = IVPU_MAX_DB , .min = IVPU_MIN_DB };
83
100
struct ivpu_device * vdev = file_priv -> vdev ;
84
101
struct ivpu_cmdq * cmdq ;
85
102
int ret ;
@@ -88,7 +105,10 @@ static struct ivpu_cmdq *ivpu_cmdq_alloc(struct ivpu_file_priv *file_priv)
88
105
if (!cmdq )
89
106
return NULL ;
90
107
91
- ret = xa_alloc (& vdev -> db_xa , & cmdq -> db_id , NULL , db_xa_limit , GFP_KERNEL );
108
+ xa_lock (& vdev -> db_xa ); /* lock here to protect db_limit */
109
+ ret = ivpu_id_alloc (& vdev -> db_xa , & cmdq -> db_id , NULL , & vdev -> db_limit ,
110
+ vdev -> default_db_limit );
111
+ xa_unlock (& vdev -> db_xa );
92
112
if (ret ) {
93
113
ivpu_err (vdev , "Failed to allocate doorbell id: %d\n" , ret );
94
114
goto err_free_cmdq ;
@@ -519,7 +539,6 @@ static int ivpu_job_submit(struct ivpu_job *job, u8 priority)
519
539
{
520
540
struct ivpu_file_priv * file_priv = job -> file_priv ;
521
541
struct ivpu_device * vdev = job -> vdev ;
522
- struct xa_limit job_id_range ;
523
542
struct ivpu_cmdq * cmdq ;
524
543
bool is_first_job ;
525
544
int ret ;
@@ -530,20 +549,18 @@ static int ivpu_job_submit(struct ivpu_job *job, u8 priority)
530
549
531
550
mutex_lock (& file_priv -> lock );
532
551
533
- cmdq = ivpu_cmdq_acquire (job -> file_priv , job -> engine_idx , priority );
552
+ cmdq = ivpu_cmdq_acquire (file_priv , job -> engine_idx , priority );
534
553
if (!cmdq ) {
535
554
ivpu_warn_ratelimited (vdev , "Failed to get job queue, ctx %d engine %d prio %d\n" ,
536
555
file_priv -> ctx .id , job -> engine_idx , priority );
537
556
ret = - EINVAL ;
538
557
goto err_unlock_file_priv ;
539
558
}
540
559
541
- job_id_range .min = FIELD_PREP (JOB_ID_CONTEXT_MASK , (file_priv -> ctx .id - 1 ));
542
- job_id_range .max = job_id_range .min | JOB_ID_JOB_MASK ;
543
-
544
560
xa_lock (& vdev -> submitted_jobs_xa );
545
561
is_first_job = xa_empty (& vdev -> submitted_jobs_xa );
546
- ret = __xa_alloc (& vdev -> submitted_jobs_xa , & job -> job_id , job , job_id_range , GFP_KERNEL );
562
+ ret = ivpu_id_alloc (& vdev -> submitted_jobs_xa , & job -> job_id , job , & file_priv -> job_limit ,
563
+ file_priv -> default_job_limit );
547
564
if (ret ) {
548
565
ivpu_dbg (vdev , JOB , "Too many active jobs in ctx %d\n" ,
549
566
file_priv -> ctx .id );
0 commit comments