qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Clément Mathieu--Drif" <clement.mathieu--drif@eviden.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Zhenzhong Duan" <zhenzhong.duan@intel.com>
Subject: [PULL 02/28] hw/i386/intel_iommu: Extract device IOTLB invalidation logic
Date: Tue, 23 Jul 2024 22:38:29 +0200	[thread overview]
Message-ID: <20240723203855.65033-3-philmd@linaro.org> (raw)
In-Reply-To: <20240723203855.65033-1-philmd@linaro.org>

From: Clément Mathieu--Drif <clement.mathieu--drif@eviden.com>

This piece of code can be shared by both IOTLB invalidation and
PASID-based IOTLB invalidation

No functional changes intended.

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Clément Mathieu--Drif <clement.mathieu--drif@eviden.com>
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
Message-ID: <20240718081636.879544-12-zhenzhong.duan@intel.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/i386/intel_iommu.c | 57 +++++++++++++++++++++++++------------------
 1 file changed, 33 insertions(+), 24 deletions(-)

diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index 37c21a0aec6..536994c3107 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -2666,13 +2666,43 @@ static bool vtd_process_inv_iec_desc(IntelIOMMUState *s,
     return true;
 }
 
+static void do_invalidate_device_tlb(VTDAddressSpace *vtd_dev_as,
+                                     bool size, hwaddr addr)
+{
+    /*
+     * According to ATS spec table 2.4:
+     * S = 0, bits 15:12 = xxxx     range size: 4K
+     * S = 1, bits 15:12 = xxx0     range size: 8K
+     * S = 1, bits 15:12 = xx01     range size: 16K
+     * S = 1, bits 15:12 = x011     range size: 32K
+     * S = 1, bits 15:12 = 0111     range size: 64K
+     * ...
+     */
+
+    IOMMUTLBEvent event;
+    uint64_t sz;
+
+    if (size) {
+        sz = (VTD_PAGE_SIZE * 2) << cto64(addr >> VTD_PAGE_SHIFT);
+        addr &= ~(sz - 1);
+    } else {
+        sz = VTD_PAGE_SIZE;
+    }
+
+    event.type = IOMMU_NOTIFIER_DEVIOTLB_UNMAP;
+    event.entry.target_as = &vtd_dev_as->as;
+    event.entry.addr_mask = sz - 1;
+    event.entry.iova = addr;
+    event.entry.perm = IOMMU_NONE;
+    event.entry.translated_addr = 0;
+    memory_region_notify_iommu(&vtd_dev_as->iommu, 0, event);
+}
+
 static bool vtd_process_device_iotlb_desc(IntelIOMMUState *s,
                                           VTDInvDesc *inv_desc)
 {
     VTDAddressSpace *vtd_dev_as;
-    IOMMUTLBEvent event;
     hwaddr addr;
-    uint64_t sz;
     uint16_t sid;
     bool size;
 
@@ -2697,28 +2727,7 @@ static bool vtd_process_device_iotlb_desc(IntelIOMMUState *s,
         goto done;
     }
 
-    /* According to ATS spec table 2.4:
-     * S = 0, bits 15:12 = xxxx     range size: 4K
-     * S = 1, bits 15:12 = xxx0     range size: 8K
-     * S = 1, bits 15:12 = xx01     range size: 16K
-     * S = 1, bits 15:12 = x011     range size: 32K
-     * S = 1, bits 15:12 = 0111     range size: 64K
-     * ...
-     */
-    if (size) {
-        sz = (VTD_PAGE_SIZE * 2) << cto64(addr >> VTD_PAGE_SHIFT);
-        addr &= ~(sz - 1);
-    } else {
-        sz = VTD_PAGE_SIZE;
-    }
-
-    event.type = IOMMU_NOTIFIER_DEVIOTLB_UNMAP;
-    event.entry.target_as = &vtd_dev_as->as;
-    event.entry.addr_mask = sz - 1;
-    event.entry.iova = addr;
-    event.entry.perm = IOMMU_NONE;
-    event.entry.translated_addr = 0;
-    memory_region_notify_iommu(&vtd_dev_as->iommu, 0, event);
+    do_invalidate_device_tlb(vtd_dev_as, size, addr);
 
 done:
     return true;
-- 
2.41.0



  parent reply	other threads:[~2024-07-23 20:39 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-23 20:38 [PULL 00/28] Misc HW+ patches for 2024-07-23 Philippe Mathieu-Daudé
2024-07-23 20:38 ` [PULL 01/28] accel: Restrict probe_access*() functions to TCG Philippe Mathieu-Daudé
2024-07-23 20:38 ` Philippe Mathieu-Daudé [this message]
2024-07-23 20:38 ` [PULL 03/28] hw/intc/loongson_ipi: Access memory in little endian Philippe Mathieu-Daudé
2024-07-23 20:38 ` [PULL 04/28] hw/intc/loongson_ipi: Fix resource leak Philippe Mathieu-Daudé
2024-07-23 20:38 ` [PULL 05/28] hw/intc/loongson_ipi: Declare QOM types using DEFINE_TYPES() macro Philippe Mathieu-Daudé
2024-07-23 20:38 ` [PULL 06/28] docs: Correct Loongarch -> LoongArch Philippe Mathieu-Daudé
2024-07-23 20:38 ` [PULL 07/28] docs/interop/firmware.json: add new enum FirmwareFormat Philippe Mathieu-Daudé
2024-07-23 20:38 ` [PULL 08/28] docs/interop/firmware.json: add new enum FirmwareArchitecture Philippe Mathieu-Daudé
2024-07-23 20:38 ` [PULL 09/28] docs/interop/firmware.json: convert "Example" section Philippe Mathieu-Daudé
2024-07-23 20:38 ` [PULL 10/28] hw/i2c/mpc_i2c: Fix mmio region size Philippe Mathieu-Daudé
2024-07-23 20:38 ` [PULL 11/28] hw/mips/loongson3_virt: remove useless type cast Philippe Mathieu-Daudé
2024-07-23 20:38 ` [PULL 12/28] util/range: Make ranges_overlap() return bool Philippe Mathieu-Daudé
2024-07-23 20:38 ` [PULL 13/28] cxl/mailbox: make range overlap check more readable Philippe Mathieu-Daudé
2024-07-23 20:38 ` [PULL 14/28] sparc/ldst_helper: " Philippe Mathieu-Daudé
2024-07-23 20:38 ` [PULL 15/28] system/memory_mapping: " Philippe Mathieu-Daudé
2024-07-23 20:38 ` [PULL 16/28] crypto/block-luks: " Philippe Mathieu-Daudé
2024-07-23 20:38 ` [PULL 17/28] dump: " Philippe Mathieu-Daudé
2024-07-23 20:38 ` [PULL 18/28] hw/nubus/virtio-mmio: Fix missing ERRP_GUARD() in realize handler Philippe Mathieu-Daudé
2024-07-23 20:38 ` [PULL 19/28] hw/char/goldfish: Use DMA memory API Philippe Mathieu-Daudé
2024-07-23 20:38 ` [PULL 20/28] chardev/char-fe: Document returned value on error Philippe Mathieu-Daudé
2024-07-23 20:38 ` [PULL 21/28] util/fifo8: Fix style Philippe Mathieu-Daudé
2024-07-23 20:38 ` [PULL 22/28] util/fifo8: Use fifo8_reset() in fifo8_create() Philippe Mathieu-Daudé
2024-07-23 20:38 ` [PULL 23/28] util/fifo8: Rename fifo8_peek_buf() -> fifo8_peek_bufptr() Philippe Mathieu-Daudé
2024-07-23 20:38 ` [PULL 24/28] util/fifo8: Rename fifo8_pop_buf() -> fifo8_pop_bufptr() Philippe Mathieu-Daudé
2024-07-23 20:38 ` [PULL 25/28] util/fifo8: Expose fifo8_pop_buf() Philippe Mathieu-Daudé
2024-07-23 20:38 ` [PULL 26/28] util/fifo8: Introduce fifo8_drop() Philippe Mathieu-Daudé
2024-07-23 20:38 ` [PULL 27/28] MAINTAINERS: Cover guest-agent in QAPI schema Philippe Mathieu-Daudé
2024-07-23 20:38 ` [PULL 28/28] MAINTAINERS: Add myself as a reviewer of machine core Philippe Mathieu-Daudé
2024-07-24  8:14 ` [PULL 00/28] Misc HW+ patches for 2024-07-23 Richard Henderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240723203855.65033-3-philmd@linaro.org \
    --to=philmd@linaro.org \
    --cc=clement.mathieu--drif@eviden.com \
    --cc=qemu-devel@nongnu.org \
    --cc=zhenzhong.duan@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).