hw/riscv: Don't insert DDT cache in Bare mode
In Bare mode the IOMMU does not perform DDT look-ups, therefore caching DDT entries is unnecessary. Signed-off-by: Jay Chang <jay.chang@sifive.com> Reviewed-by: Frank Chang <frank.chang@sifive.com> Reviewed-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com> Reviewed-by: Nutty Liu <nutty.liu@hotmail.com> Message-ID: <20260518072239.16293-2-jay.chang@sifive.com> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
Jay Chang committed
May 18, 2026 at 15:22 UTC
f081225c62cbd6facdcd7c74bfd795fe99eda6c2
1 file changed
+15
-8
hw/riscv/riscv-iommu.c
+15
-8
@@ -1358,16 +1358,23 @@ static RISCVIOMMUContext *riscv_iommu_ctx(RISCVIOMMUState *s,
1358
1359
int fault = riscv_iommu_ctx_fetch(s, ctx);
1360
if (!fault) {
1361
- if (g_hash_table_size(ctx_cache) >= LIMIT_CACHE_CTX) {
1361
+ if (mode != RISCV_IOMMU_DDTP_MODE_BARE) {
1362
+ if (g_hash_table_size(ctx_cache) >= LIMIT_CACHE_CTX) {
1363
+ g_hash_table_unref(ctx_cache);
1364
+ ctx_cache = g_hash_table_new_full(riscv_iommu_ctx_hash,
1365
+ riscv_iommu_ctx_equal,
1366
+ g_free, NULL);
1367
+ g_hash_table_ref(ctx_cache);
1368
+ g_hash_table_unref(qatomic_xchg(&s->ctx_cache, ctx_cache));
1369
+ }
1370
+
1371
+ g_hash_table_add(ctx_cache, ctx);
1372
+ *ref = ctx_cache;
1373
+ } else {
1374
g_hash_table_unref(ctx_cache);
1363
- ctx_cache = g_hash_table_new_full(riscv_iommu_ctx_hash,
1364
- riscv_iommu_ctx_equal,
1365
- g_free, NULL);
1366
- g_hash_table_ref(ctx_cache);
1367
- g_hash_table_unref(qatomic_xchg(&s->ctx_cache, ctx_cache));
1375
+ /* Remember ctx so it can be freed */
1376
+ *ref = ctx;
1377
}
1369
- g_hash_table_add(ctx_cache, ctx);
1370
- *ref = ctx_cache;
1378
return ctx;
1379
}
1380