From: Kan Liang <kan.li...@linux.intel.com>

commit 4db96bfe9d7772d6ddedd62ce478895999043fd7 upstream.

A new field, which indicates the size of the remapping hardware register
set for this remapping unit, is introduced in the DMA-remapping hardware
unit definition (DRHD) structure with the VT-d Spec 4.0. With this
information, SW doesn't need to 'guess' the size of the register set
anymore.

Update the struct acpi_dmar_hardware_unit to reflect the field. Store the
size of the register set in struct dmar_drhd_unit for each dmar device.

The 'size' information is ResvZ for the old BIOS and platforms. Fall back
to the old guessing method. There is nothing changed.

Signed-off-by: Kan Liang <kan.li...@linux.intel.com>
Link: 
https://lore.kernel.org/r/20230128200428.1459118-2-kan.li...@linux.intel.com
Signed-off-by: Lu Baolu <baolu...@linux.intel.com>
Signed-off-by: Joerg Roedel <jroe...@suse.de>
Signed-off-by: Yongxin Liu <yongxin....@windriver.com>
---
 drivers/iommu/intel/dmar.c | 11 +++++++----
 include/acpi/actbl1.h      |  2 +-
 include/linux/dmar.h       |  1 +
 3 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c
index 4759f79ad7b9..b8dd628125f4 100644
--- a/drivers/iommu/intel/dmar.c
+++ b/drivers/iommu/intel/dmar.c
@@ -428,6 +428,8 @@ static int dmar_parse_one_drhd(struct acpi_dmar_header 
*header, void *arg)
        memcpy(dmaru->hdr, header, header->length);
        dmaru->reg_base_addr = drhd->address;
        dmaru->segment = drhd->segment;
+       /* The size of the register set is 2 ^ N 4 KB pages. */
+       dmaru->reg_size = 1UL << (drhd->size + 12);
        dmaru->include_all = drhd->flags & 0x1; /* BIT0: INCLUDE_ALL */
        dmaru->devices = dmar_alloc_dev_scope((void *)(drhd + 1),
                                              ((void *)drhd) + 
drhd->header.length,
@@ -957,17 +959,18 @@ static void unmap_iommu(struct intel_iommu *iommu)
 /**
  * map_iommu: map the iommu's registers
  * @iommu: the iommu to map
- * @phys_addr: the physical address of the base resgister
+ * @drhd: DMA remapping hardware definition structure
  *
  * Memory map the iommu's registers.  Start w/ a single page, and
  * possibly expand if that turns out to be insufficent.
  */
-static int map_iommu(struct intel_iommu *iommu, u64 phys_addr)
+static int map_iommu(struct intel_iommu *iommu, struct dmar_drhd_unit *drhd)
 {
+       u64 phys_addr = drhd->reg_base_addr;
        int map_size, err=0;
 
        iommu->reg_phys = phys_addr;
-       iommu->reg_size = VTD_PAGE_SIZE;
+       iommu->reg_size = drhd->reg_size;
 
        if (!request_mem_region(iommu->reg_phys, iommu->reg_size, iommu->name)) 
{
                pr_err("Can't reserve memory\n");
@@ -1051,7 +1054,7 @@ static int alloc_iommu(struct dmar_drhd_unit *drhd)
        }
        sprintf(iommu->name, "dmar%d", iommu->seq_id);
 
-       err = map_iommu(iommu, drhd->reg_base_addr);
+       err = map_iommu(iommu, drhd);
        if (err) {
                pr_err("Failed to map %s\n", iommu->name);
                goto error_free_seq_id;
diff --git a/include/acpi/actbl1.h b/include/acpi/actbl1.h
index 15c78678c5d3..c5deb47ecee1 100644
--- a/include/acpi/actbl1.h
+++ b/include/acpi/actbl1.h
@@ -655,7 +655,7 @@ struct acpi_dmar_pci_path {
 struct acpi_dmar_hardware_unit {
        struct acpi_dmar_header header;
        u8 flags;
-       u8 reserved;
+       u8 size;                /* Size of the register set */
        u16 segment;
        u64 address;            /* Register Base Address */
 };
diff --git a/include/linux/dmar.h b/include/linux/dmar.h
index d81a51978d01..725d5e6acec0 100644
--- a/include/linux/dmar.h
+++ b/include/linux/dmar.h
@@ -39,6 +39,7 @@ struct dmar_drhd_unit {
        struct list_head list;          /* list of drhd units   */
        struct  acpi_dmar_header *hdr;  /* ACPI header          */
        u64     reg_base_addr;          /* register base address*/
+       unsigned long reg_size;         /* size of register set */
        struct  dmar_dev_scope *devices;/* target device array  */
        int     devices_cnt;            /* target device count  */
        u16     segment;                /* PCI domain           */
-- 
2.43.2

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#13860): 
https://lists.yoctoproject.org/g/linux-yocto/message/13860
Mute This Topic: https://lists.yoctoproject.org/mt/105704896/21656
Group Owner: linux-yocto+ow...@lists.yoctoproject.org
Unsubscribe: https://lists.yoctoproject.org/g/linux-yocto/unsub 
[arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to