Skip to content

Commit caaa648

Browse files
aljimenezbMichael Tokarev
authored andcommitted
amd_iommu: Fix masks for various IOMMU MMIO Registers
Address various issues with definitions of the MMIO registers e.g. for the Device Table Address Register, the size mask currently encompasses reserved bits [11:9], so change it to only extract the bits [8:0] encoding size. Convert masks to use GENMASK64 for consistency, and make unrelated definitions independent. Cc: [email protected] Fixes: d29a09c ("hw/i386: Introduce AMD IOMMU") Signed-off-by: Alejandro Jimenez <[email protected]> Reviewed-by: Vasant Hegde <[email protected]> Message-Id: <[email protected]> Reviewed-by: Michael S. Tsirkin <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]> (cherry picked from commit 108e10ff69099c3ebe147f505246be7c2ad2a499) Signed-off-by: Michael Tokarev <[email protected]>
1 parent d1ea4a1 commit caaa648

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

hw/i386/amd_iommu.h

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -68,34 +68,34 @@
6868

6969
#define AMDVI_MMIO_SIZE 0x4000
7070

71-
#define AMDVI_MMIO_DEVTAB_SIZE_MASK ((1ULL << 12) - 1)
72-
#define AMDVI_MMIO_DEVTAB_BASE_MASK (((1ULL << 52) - 1) & ~ \
73-
AMDVI_MMIO_DEVTAB_SIZE_MASK)
71+
#define AMDVI_MMIO_DEVTAB_SIZE_MASK GENMASK64(8, 0)
72+
#define AMDVI_MMIO_DEVTAB_BASE_MASK GENMASK64(51, 12)
73+
7474
#define AMDVI_MMIO_DEVTAB_ENTRY_SIZE 32
7575
#define AMDVI_MMIO_DEVTAB_SIZE_UNIT 4096
7676

7777
/* some of this are similar but just for readability */
7878
#define AMDVI_MMIO_CMDBUF_SIZE_BYTE (AMDVI_MMIO_COMMAND_BASE + 7)
7979
#define AMDVI_MMIO_CMDBUF_SIZE_MASK 0x0f
80-
#define AMDVI_MMIO_CMDBUF_BASE_MASK AMDVI_MMIO_DEVTAB_BASE_MASK
81-
#define AMDVI_MMIO_CMDBUF_HEAD_MASK (((1ULL << 19) - 1) & ~0x0f)
82-
#define AMDVI_MMIO_CMDBUF_TAIL_MASK AMDVI_MMIO_EVTLOG_HEAD_MASK
80+
#define AMDVI_MMIO_CMDBUF_BASE_MASK GENMASK64(51, 12)
81+
#define AMDVI_MMIO_CMDBUF_HEAD_MASK GENMASK64(18, 4)
82+
#define AMDVI_MMIO_CMDBUF_TAIL_MASK GENMASK64(18, 4)
8383

8484
#define AMDVI_MMIO_EVTLOG_SIZE_BYTE (AMDVI_MMIO_EVENT_BASE + 7)
85-
#define AMDVI_MMIO_EVTLOG_SIZE_MASK AMDVI_MMIO_CMDBUF_SIZE_MASK
86-
#define AMDVI_MMIO_EVTLOG_BASE_MASK AMDVI_MMIO_CMDBUF_BASE_MASK
87-
#define AMDVI_MMIO_EVTLOG_HEAD_MASK (((1ULL << 19) - 1) & ~0x0f)
88-
#define AMDVI_MMIO_EVTLOG_TAIL_MASK AMDVI_MMIO_EVTLOG_HEAD_MASK
85+
#define AMDVI_MMIO_EVTLOG_SIZE_MASK 0x0f
86+
#define AMDVI_MMIO_EVTLOG_BASE_MASK GENMASK64(51, 12)
87+
#define AMDVI_MMIO_EVTLOG_HEAD_MASK GENMASK64(18, 4)
88+
#define AMDVI_MMIO_EVTLOG_TAIL_MASK GENMASK64(18, 4)
8989

90-
#define AMDVI_MMIO_PPRLOG_SIZE_BYTE (AMDVI_MMIO_EVENT_BASE + 7)
91-
#define AMDVI_MMIO_PPRLOG_HEAD_MASK AMDVI_MMIO_EVTLOG_HEAD_MASK
92-
#define AMDVI_MMIO_PPRLOG_TAIL_MASK AMDVI_MMIO_EVTLOG_HEAD_MASK
93-
#define AMDVI_MMIO_PPRLOG_BASE_MASK AMDVI_MMIO_EVTLOG_BASE_MASK
94-
#define AMDVI_MMIO_PPRLOG_SIZE_MASK AMDVI_MMIO_EVTLOG_SIZE_MASK
90+
#define AMDVI_MMIO_PPRLOG_SIZE_BYTE (AMDVI_MMIO_PPR_BASE + 7)
91+
#define AMDVI_MMIO_PPRLOG_SIZE_MASK 0x0f
92+
#define AMDVI_MMIO_PPRLOG_BASE_MASK GENMASK64(51, 12)
93+
#define AMDVI_MMIO_PPRLOG_HEAD_MASK GENMASK64(18, 4)
94+
#define AMDVI_MMIO_PPRLOG_TAIL_MASK GENMASK64(18, 4)
9595

9696
#define AMDVI_MMIO_EXCL_ENABLED_MASK (1ULL << 0)
9797
#define AMDVI_MMIO_EXCL_ALLOW_MASK (1ULL << 1)
98-
#define AMDVI_MMIO_EXCL_LIMIT_MASK AMDVI_MMIO_DEVTAB_BASE_MASK
98+
#define AMDVI_MMIO_EXCL_LIMIT_MASK GENMASK64(51, 12)
9999
#define AMDVI_MMIO_EXCL_LIMIT_LOW 0xfff
100100

101101
/* mmio control register flags */
@@ -132,14 +132,14 @@
132132
#define AMDVI_DEV_TRANSLATION_VALID (1ULL << 1)
133133
#define AMDVI_DEV_MODE_MASK 0x7
134134
#define AMDVI_DEV_MODE_RSHIFT 9
135-
#define AMDVI_DEV_PT_ROOT_MASK 0xffffffffff000
135+
#define AMDVI_DEV_PT_ROOT_MASK GENMASK64(51, 12)
136136
#define AMDVI_DEV_PT_ROOT_RSHIFT 12
137137
#define AMDVI_DEV_PERM_SHIFT 61
138138
#define AMDVI_DEV_PERM_READ (1ULL << 61)
139139
#define AMDVI_DEV_PERM_WRITE (1ULL << 62)
140140

141141
/* Device table entry bits 64:127 */
142-
#define AMDVI_DEV_DOMID_ID_MASK ((1ULL << 16) - 1)
142+
#define AMDVI_DEV_DOMID_ID_MASK GENMASK64(15, 0)
143143

144144
/* Event codes and flags, as stored in the info field */
145145
#define AMDVI_EVENT_ILLEGAL_DEVTAB_ENTRY (0x1U << 12)
@@ -197,7 +197,7 @@
197197
#define AMDVI_PAGE_SIZE (1ULL << AMDVI_PAGE_SHIFT)
198198

199199
#define AMDVI_PAGE_SHIFT_4K 12
200-
#define AMDVI_PAGE_MASK_4K (~((1ULL << AMDVI_PAGE_SHIFT_4K) - 1))
200+
#define AMDVI_PAGE_MASK_4K GENMASK64(63, 12)
201201

202202
#define AMDVI_MAX_GVA_ADDR (2UL << 5)
203203
#define AMDVI_MAX_PH_ADDR (40UL << 8)

0 commit comments

Comments
 (0)