Some generations support only 128 SSIDs, while the KMD configured 256
CD table entries and allowed user contexts up to SSID 130. Align the
limit across all generations.

Limit the CD table to 128 entries and the user SSID range to 2-127, so
root can create 126 contexts and non-root users 64. Also fix the off by
one SSID bounds checks against the CD table size.

Signed-off-by: Karol Wachowski <[email protected]>
---
 drivers/accel/ivpu/ivpu_drv.c | 2 +-
 drivers/accel/ivpu/ivpu_drv.h | 3 ++-
 drivers/accel/ivpu/ivpu_mmu.c | 6 +++---
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/accel/ivpu/ivpu_drv.c b/drivers/accel/ivpu/ivpu_drv.c
index b60430dcf168..045ad6518657 100644
--- a/drivers/accel/ivpu/ivpu_drv.c
+++ b/drivers/accel/ivpu/ivpu_drv.c
@@ -127,7 +127,7 @@ static struct ivpu_user_limits 
*ivpu_user_limits_alloc(struct ivpu_device *vdev,
                limits->max_ctx_count = ivpu_get_context_count(vdev);
                limits->max_db_count = ivpu_get_doorbell_count(vdev);
        } else {
-               limits->max_ctx_count = ivpu_get_context_count(vdev) / 2;
+               limits->max_ctx_count = IVPU_NON_ROOT_USER_MAX_CONTEXTS;
                limits->max_db_count = ivpu_get_doorbell_count(vdev) / 2;
        }
 
diff --git a/drivers/accel/ivpu/ivpu_drv.h b/drivers/accel/ivpu/ivpu_drv.h
index 7ac7a7f82e67..7860993c7617 100644
--- a/drivers/accel/ivpu/ivpu_drv.h
+++ b/drivers/accel/ivpu/ivpu_drv.h
@@ -38,7 +38,8 @@
 /* SSID 1 is used by the VPU to represent reserved context */
 #define IVPU_RESERVED_CONTEXT_MMU_SSID 1
 #define IVPU_USER_CONTEXT_MIN_SSID     2
-#define IVPU_USER_CONTEXT_MAX_SSID     (IVPU_USER_CONTEXT_MIN_SSID + 128)
+#define IVPU_USER_CONTEXT_MAX_SSID     127
+#define IVPU_NON_ROOT_USER_MAX_CONTEXTS 64
 
 #define IVPU_MIN_DB 1
 #define IVPU_MAX_DB 255
diff --git a/drivers/accel/ivpu/ivpu_mmu.c b/drivers/accel/ivpu/ivpu_mmu.c
index 1908375ff128..dc18021261b9 100644
--- a/drivers/accel/ivpu/ivpu_mmu.c
+++ b/drivers/accel/ivpu/ivpu_mmu.c
@@ -65,7 +65,7 @@
 #define IVPU_MMU_IDR5_REF_FPGA         0x00800075
 
 #define IVPU_MMU_CDTAB_ENT_SIZE                64
-#define IVPU_MMU_CDTAB_ENT_COUNT_LOG2  8 /* 256 entries */
+#define IVPU_MMU_CDTAB_ENT_COUNT_LOG2  7 /* 128 entries */
 #define IVPU_MMU_CDTAB_ENT_COUNT       ((u32)1 << 
IVPU_MMU_CDTAB_ENT_COUNT_LOG2)
 
 #define IVPU_MMU_STREAM_ID0            0
@@ -700,7 +700,7 @@ static int ivpu_mmu_cdtab_entry_set(struct ivpu_device 
*vdev, u32 ssid, u64 cd_d
        u64 cd[4];
        int ret = 0;
 
-       if (ssid > IVPU_MMU_CDTAB_ENT_COUNT)
+       if (ssid >= IVPU_MMU_CDTAB_ENT_COUNT)
                return -EINVAL;
 
        entry = cdtab->base + (ssid * IVPU_MMU_CDTAB_ENT_SIZE);
@@ -918,7 +918,7 @@ int ivpu_mmu_disable_ssid_events(struct ivpu_device *vdev, 
u32 ssid)
        u64 *entry;
        u64 val;
 
-       if (ssid > IVPU_MMU_CDTAB_ENT_COUNT)
+       if (ssid >= IVPU_MMU_CDTAB_ENT_COUNT)
                return -EINVAL;
 
        mutex_lock(&mmu->lock);
-- 
2.43.0

Reply via email to