diff options
author | Eric Auger | 2020-07-28 17:08:06 +0200 |
---|---|---|
committer | Peter Maydell | 2020-08-24 11:02:06 +0200 |
commit | 6808bca939b8722d98165319ba42366ca80de907 (patch) | |
tree | 41ef7eaf5f8d99a63d6e4174e412ab548af675ab /hw/arm/smmu-common.c | |
parent | hw/arm/smmu-common: Factorize some code in smmu_ptw_64() (diff) | |
download | qemu-6808bca939b8722d98165319ba42366ca80de907.tar.gz qemu-6808bca939b8722d98165319ba42366ca80de907.tar.xz qemu-6808bca939b8722d98165319ba42366ca80de907.zip |
hw/arm/smmu-common: Add IOTLB helpers
Add two helpers: one to lookup for a given IOTLB entry and
one to insert a new entry. We also move the tracing there.
Signed-off-by: Eric Auger <eric.auger@redhat.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-id: 20200728150815.11446-3-eric.auger@redhat.com
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'hw/arm/smmu-common.c')
-rw-r--r-- | hw/arm/smmu-common.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/hw/arm/smmu-common.c b/hw/arm/smmu-common.c index a3f9e47398..f3aa581f80 100644 --- a/hw/arm/smmu-common.c +++ b/hw/arm/smmu-common.c @@ -32,6 +32,42 @@ /* IOTLB Management */ +IOMMUTLBEntry *smmu_iotlb_lookup(SMMUState *bs, SMMUTransCfg *cfg, + hwaddr iova) +{ + SMMUIOTLBKey key = {.asid = cfg->asid, .iova = iova}; + IOMMUTLBEntry *entry = g_hash_table_lookup(bs->iotlb, &key); + + if (entry) { + cfg->iotlb_hits++; + trace_smmu_iotlb_lookup_hit(cfg->asid, iova, + cfg->iotlb_hits, cfg->iotlb_misses, + 100 * cfg->iotlb_hits / + (cfg->iotlb_hits + cfg->iotlb_misses)); + } else { + cfg->iotlb_misses++; + trace_smmu_iotlb_lookup_miss(cfg->asid, iova, + cfg->iotlb_hits, cfg->iotlb_misses, + 100 * cfg->iotlb_hits / + (cfg->iotlb_hits + cfg->iotlb_misses)); + } + return entry; +} + +void smmu_iotlb_insert(SMMUState *bs, SMMUTransCfg *cfg, IOMMUTLBEntry *entry) +{ + SMMUIOTLBKey *key = g_new0(SMMUIOTLBKey, 1); + + if (g_hash_table_size(bs->iotlb) >= SMMU_IOTLB_MAX_SIZE) { + smmu_iotlb_inv_all(bs); + } + + key->asid = cfg->asid; + key->iova = entry->iova; + trace_smmu_iotlb_insert(cfg->asid, entry->iova); + g_hash_table_insert(bs->iotlb, key, entry); +} + inline void smmu_iotlb_inv_all(SMMUState *s) { trace_smmu_iotlb_inv_all(); |