diff --git a/sys/x86/iommu/amd_drv.c b/sys/x86/iommu/amd_drv.c --- a/sys/x86/iommu/amd_drv.c +++ b/sys/x86/iommu/amd_drv.c @@ -217,6 +217,17 @@ sc->devtbl_obj = NULL; } +static const int amdiommu_devtab_base_seg_regs[] = { + [0] = AMDIOMMU_DEVTAB_BASE, + [1] = AMDIOMMU_DEVTAB_S1_BASE, + [2] = AMDIOMMU_DEVTAB_S2_BASE, + [3] = AMDIOMMU_DEVTAB_S3_BASE, + [4] = AMDIOMMU_DEVTAB_S4_BASE, + [5] = AMDIOMMU_DEVTAB_S5_BASE, + [6] = AMDIOMMU_DEVTAB_S6_BASE, + [7] = AMDIOMMU_DEVTAB_S7_BASE, +}; + static int amdiommu_create_dev_tbl(struct amdiommu_unit *sc) { @@ -227,6 +238,7 @@ segnum_log = (sc->efr & AMDIOMMU_EFR_DEVTBLSEG_MASK) >> AMDIOMMU_EFR_DEVTBLSEG_SHIFT; segnum = 1 << segnum_log; + MPASS(segnum <= nitems(amdiommu_devtab_base_seg_regs)); devtbl_sz = amdiommu_devtbl_sz(sc); seg_sz = devtbl_sz / segnum; @@ -276,9 +288,7 @@ pmap_zero_page(m); pmap_qenter(seg_vaddr, &m, 1); } - reg = i == 0 ? AMDIOMMU_DEVTAB_BASE : AMDIOMMU_DEVTAB_S1_BASE + - ((i - 1) << 3); - amdiommu_write8(sc, reg, rval); + amdiommu_write8(sc, amdiommu_devtab_base_seg_regs[i], rval); } return (0);