VirtualBox

source: vbox/trunk/src/VBox/Devices/Bus/DevIommuAmd.cpp@ 83711

Last change on this file since 83711 was 83711, checked in by vboxsync, 5 years ago

AMD IOMMU: bugref:9654 Bits.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 170.5 KB
Line 
1/* $Id: DevIommuAmd.cpp 83711 2020-04-16 05:12:58Z vboxsync $ */
2/** @file
3 * IOMMU - Input/Output Memory Management Unit - AMD implementation.
4 */
5
6/*
7 * Copyright (C) 2020 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
22#define LOG_GROUP LOG_GROUP_DEV_IOMMU
23#include <VBox/vmm/pdmdev.h>
24#include <VBox/AssertGuest.h>
25
26#include "VBoxDD.h"
27#include <iprt/x86.h>
28
29
30/*********************************************************************************************************************************
31* Defined Constants And Macros *
32*********************************************************************************************************************************/
33/**
34 * @name PCI configuration register offsets.
35 * In accordance with the AMD spec.
36 * @{
37 */
38#define IOMMU_PCI_OFF_CAP_HDR 0x40
39#define IOMMU_PCI_OFF_BASE_ADDR_REG_LO 0x44
40#define IOMMU_PCI_OFF_BASE_ADDR_REG_HI 0x48
41#define IOMMU_PCI_OFF_RANGE_REG 0x4c
42#define IOMMU_PCI_OFF_MISCINFO_REG_0 0x50
43#define IOMMU_PCI_OFF_MISCINFO_REG_1 0x54
44#define IOMMU_PCI_OFF_MSI_CAP_HDR 0x64
45#define IOMMU_PCI_OFF_MSI_ADDR_LO 0x68
46#define IOMMU_PCI_OFF_MSI_ADDR_HI 0x6c
47#define IOMMU_PCI_OFF_MSI_DATA 0x70
48#define IOMMU_PCI_OFF_MSI_MAP_CAP_HDR 0x74
49/** @} */
50
51/**
52 * @name MMIO register offsets.
53 * In accordance with the AMD spec.
54 * @{
55 */
56#define IOMMU_MMIO_OFF_DEV_TAB_BAR 0x00
57#define IOMMU_MMIO_OFF_CMD_BUF_BAR 0x08
58#define IOMMU_MMIO_OFF_EVT_LOG_BAR 0x10
59#define IOMMU_MMIO_OFF_CTRL 0x18
60#define IOMMU_MMIO_OFF_EXCL_BAR 0x20
61#define IOMMU_MMIO_OFF_EXCL_RANGE_LIMIT 0x28
62#define IOMMU_MMIO_OFF_EXT_FEAT 0x30
63
64#define IOMMU_MMIO_OFF_PPR_LOG_BAR 0x38
65#define IOMMU_MMIO_OFF_HW_EVT_HI 0x40
66#define IOMMU_MMIO_OFF_HW_EVT_LO 0x48
67#define IOMMU_MMIO_OFF_HW_EVT_STATUS 0x50
68
69#define IOMMU_MMIO_OFF_SMI_FLT_FIRST 0x60
70#define IOMMU_MMIO_OFF_SMI_FLT_LAST 0xd8
71
72#define IOMMU_MMIO_OFF_GALOG_BAR 0xe0
73#define IOMMU_MMIO_OFF_GALOG_TAIL_ADDR 0xe8
74
75#define IOMMU_MMIO_OFF_PPR_LOG_B_BAR 0xf0
76#define IOMMU_MMIO_OFF_PPR_EVT_B_BAR 0xf8
77
78#define IOMMU_MMIO_OFF_DEV_TAB_SEG_FIRST 0x100
79#define IOMMU_MMIO_OFF_DEV_TAB_SEG_LAST 0x130
80
81#define IOMMU_MMIO_OFF_DEV_SPECIFIC_FEAT 0x138
82#define IOMMU_MMIO_OFF_DEV_SPECIFIC_CTRL 0x140
83#define IOMMU_MMIO_OFF_DEV_SPECIFIC_STATUS 0x148
84
85#define IOMMU_MMIO_OFF_MSI_VECTOR_0 0x150
86#define IOMMU_MMIO_OFF_MSI_VECTOR_1 0x154
87#define IOMMU_MMIO_OFF_MSI_CAP_HDR 0x158
88#define IOMMU_MMIO_OFF_MSI_ADDR_LO 0x15c
89#define IOMMU_MMIO_OFF_MSI_ADDR_HI 0x160
90#define IOMMU_MMIO_OFF_MSI_DATA 0x164
91#define IOMMU_MMIO_OFF_MSI_MAPPING_CAP_HDR 0x168
92
93#define IOMMU_MMIO_OFF_PERF_OPT_CTRL 0x16c
94
95#define IOMMU_MMIO_OFF_XT_GEN_INTR_CTRL 0x170
96#define IOMMU_MMIO_OFF_XT_PPR_INTR_CTRL 0x178
97#define IOMMU_MMIO_OFF_XT_GALOG_INT_CTRL 0x180
98
99#define IOMMU_MMIO_OFF_MARC_APER_BAR_0 0x200
100#define IOMMU_MMIO_OFF_MARC_APER_RELOC_0 0x208
101#define IOMMU_MMIO_OFF_MARC_APER_LEN_0 0x210
102#define IOMMU_MMIO_OFF_MARC_APER_BAR_1 0x218
103#define IOMMU_MMIO_OFF_MARC_APER_RELOC_1 0x220
104#define IOMMU_MMIO_OFF_MARC_APER_LEN_1 0x228
105#define IOMMU_MMIO_OFF_MARC_APER_BAR_2 0x230
106#define IOMMU_MMIO_OFF_MARC_APER_RELOC_2 0x238
107#define IOMMU_MMIO_OFF_MARC_APER_LEN_2 0x240
108#define IOMMU_MMIO_OFF_MARC_APER_BAR_3 0x248
109#define IOMMU_MMIO_OFF_MARC_APER_RELOC_3 0x250
110#define IOMMU_MMIO_OFF_MARC_APER_LEN_3 0x258
111
112#define IOMMU_MMIO_OFF_RSVD_REG 0x1ff8
113
114#define IOMMU_MMIO_CMD_BUF_HEAD_PTR 0x2000
115#define IOMMU_MMIO_CMD_BUF_TAIL_PTR 0x2008
116#define IOMMU_MMIO_EVT_LOG_HEAD_PTR 0x2010
117#define IOMMU_MMIO_EVT_LOG_TAIL_PTR 0x2018
118
119#define IOMMU_MMIO_OFF_STATUS 0x2020
120
121#define IOMMU_MMIO_OFF_PPR_LOG_HEAD_PTR 0x2030
122#define IOMMU_MMIO_OFF_PPR_LOG_TAIL_PTR 0x2038
123
124#define IOMMU_MMIO_OFF_GALOG_HEAD_PTR 0x2040
125#define IOMMU_MMIO_OFF_GALOG_TAIL_PTR 0x2048
126
127#define IOMMU_MMIO_OFF_PPR_LOG_B_HEAD_PTR 0x2050
128#define IOMMU_MMIO_OFF_PPR_LOG_B_TAIL_PTR 0x2058
129
130#define IOMMU_MMIO_OFF_EVT_LOG_B_HEAD_PTR 0x2070
131#define IOMMU_MMIO_OFF_EVT_LOG_B_TAIL_PTR 0x2078
132
133#define IOMMU_MMIO_OFF_PPR_LOG_AUTO_RESP 0x2080
134#define IOMMU_MMIO_OFF_PPR_LOG_OVERFLOW_EARLY 0x2088
135#define IOMMU_MMIO_OFF_PPR_LOG_B_OVERFLOW_EARLY 0x2090
136/** @} */
137
138/**
139 * @name MMIO register-access table offsets.
140 * Each table [first..last] (both inclusive) represents the range of registers
141 * covered by a distinct register-access table. This is done due to arbitrary large
142 * gaps in the MMIO register offsets themselves.
143 * @{
144 */
145#define IOMMU_MMIO_OFF_TABLE_0_FIRST 0x00
146#define IOMMU_MMIO_OFF_TABLE_0_LAST 0x258
147
148#define IOMMU_MMIO_OFF_TABLE_1_FIRST 0x1ff8
149#define IOMMU_MMIO_OFF_TABLE_1_LAST 0x2090
150/** @} */
151
152/**
153 * @name Commands.
154 * In accordance with the AMD spec.
155 * @{
156 */
157#define IOMMU_CMD_COMPLETION_WAIT 0x01
158#define IOMMU_CMD_INV_DEV_TAB_ENTRY 0x02
159#define IOMMU_CMD_INV_IOMMU_PAGES 0x03
160#define IOMMU_CMD_INV_IOTLB_PAGES 0x04
161#define IOMMU_CMD_INV_INTR_TABLE 0x05
162#define IOMMU_CMD_PREFETCH_IOMMU_PAGES 0x06
163#define IOMMU_CMD_COMPLETE_PPR_REQ 0x07
164#define IOMMU_CMD_INV_IOMMU_ALL 0x08
165/** @} */
166
167/**
168 * @name Event codes.
169 * In accordance with the AMD spec.
170 * @{
171 */
172#define IOMMU_EVT_ILLEGAL_DEV_TAB_ENTRY 0x01
173#define IOMMU_EVT_IO_PAGE_FAULT 0x02
174#define IOMMU_EVT_DEV_TAB_HARDWARE_ERROR 0x03
175#define IOMMU_EVT_PAGE_TAB_HARDWARE_ERROR 0x04
176#define IOMMU_EVT_ILLEGAL_COMMAND_ERROR 0x05
177#define IOMMU_EVT_COMMAND_HARDWARE_ERROR 0x06
178#define IOMMU_EVT_IOTLB_INV_TIMEOUT 0x07
179#define IOMMU_EVT_INVALID_DEVICE_REQUEST 0x08
180#define IOMMU_EVT_INVALID_PPR_REQUEST 0x09
181#define IOMMU_EVT_EVENT_COUNTER_ZERO 0x10
182#define IOMMU_EVT_GUEST_EVENT_FAULT 0x11
183/** @} */
184
185/**
186 * @name IOMMU Capability Header.
187 * In accordance with the AMD spec.
188 * @{
189 */
190/** CapId: Capability ID. */
191#define IOMMU_BF_CAPHDR_CAP_ID_SHIFT 0
192#define IOMMU_BF_CAPHDR_CAP_ID_MASK UINT32_C(0x000000ff)
193/** CapPtr: Capability Pointer. */
194#define IOMMU_BF_CAPHDR_CAP_PTR_SHIFT 8
195#define IOMMU_BF_CAPHDR_CAP_PTR_MASK UINT32_C(0x0000ff00)
196/** CapType: Capability Type. */
197#define IOMMU_BF_CAPHDR_CAP_TYPE_SHIFT 16
198#define IOMMU_BF_CAPHDR_CAP_TYPE_MASK UINT32_C(0x00070000)
199/** CapRev: Capability Revision. */
200#define IOMMU_BF_CAPHDR_CAP_REV_SHIFT 19
201#define IOMMU_BF_CAPHDR_CAP_REV_MASK UINT32_C(0x00f80000)
202/** IoTlbSup: IO TLB Support. */
203#define IOMMU_BF_CAPHDR_IOTLB_SUP_SHIFT 24
204#define IOMMU_BF_CAPHDR_IOTLB_SUP_MASK UINT32_C(0x01000000)
205/** HtTunnel: HyperTransport Tunnel translation support. */
206#define IOMMU_BF_CAPHDR_HT_TUNNEL_SHIFT 25
207#define IOMMU_BF_CAPHDR_HT_TUNNEL_MASK UINT32_C(0x02000000)
208/** NpCache: Not Present table entries Cached. */
209#define IOMMU_BF_CAPHDR_NP_CACHE_SHIFT 26
210#define IOMMU_BF_CAPHDR_NP_CACHE_MASK UINT32_C(0x04000000)
211/** EFRSup: Extended Feature Register (EFR) Supported. */
212#define IOMMU_BF_CAPHDR_EFR_SUP_SHIFT 27
213#define IOMMU_BF_CAPHDR_EFR_SUP_MASK UINT32_C(0x08000000)
214/** CapExt: Miscellaneous Information Register Supported . */
215#define IOMMU_BF_CAPHDR_CAP_EXT_SHIFT 28
216#define IOMMU_BF_CAPHDR_CAP_EXT_MASK UINT32_C(0x10000000)
217/** Bits 31:29 reserved. */
218#define IOMMU_BF_CAPHDR_RSVD_29_31_SHIFT 29
219#define IOMMU_BF_CAPHDR_RSVD_29_31_MASK UINT32_C(0xe0000000)
220RT_BF_ASSERT_COMPILE_CHECKS(IOMMU_BF_CAPHDR_, UINT32_C(0), UINT32_MAX,
221 (CAP_ID, CAP_PTR, CAP_TYPE, CAP_REV, IOTLB_SUP, HT_TUNNEL, NP_CACHE, EFR_SUP, CAP_EXT, RSVD_29_31));
222/** @} */
223
224/**
225 * @name IOMMU Base Address Low Register.
226 * In accordance with the AMD spec.
227 * @{
228 */
229/** Enable: Enables access to the address specified in the Base Address Register. */
230#define IOMMU_BF_BASEADDR_LO_ENABLE_SHIFT 0
231#define IOMMU_BF_BASEADDR_LO_ENABLE_MASK UINT32_C(0x00000001)
232/** Bits 13:1 reserved. */
233#define IOMMU_BF_BASEADDR_LO_RSVD_1_13_SHIFT 1
234#define IOMMU_BF_BASEADDR_LO_RSVD_1_13_MASK UINT32_C(0x00003ffe)
235/** Base Address[31:14]: Low Base address of IOMMU MMIO control registers. */
236#define IOMMU_BF_BASEADDR_LO_ADDR_SHIFT 14
237#define IOMMU_BF_BASEADDR_LO_ADDR_MASK UINT32_C(0xffffc000)
238RT_BF_ASSERT_COMPILE_CHECKS(IOMMU_BF_BASEADDR_LO_, UINT32_C(0), UINT32_MAX,
239 (ENABLE, RSVD_1_13, ADDR));
240/** @} */
241
242/**
243 * @name IOMMU Range Register.
244 * In accordance with the AMD spec.
245 * @{
246 */
247/** UnitID: HyperTransport Unit ID. */
248#define IOMMU_BF_RANGE_UNIT_ID_SHIFT 0
249#define IOMMU_BF_RANGE_UNIT_ID_MASK UINT32_C(0x0000001f)
250/** Bits 6:5 reserved. */
251#define IOMMU_BF_RANGE_RSVD_5_6_SHIFT 5
252#define IOMMU_BF_RANGE_RSVD_5_6_MASK UINT32_C(0x00000060)
253/** RngValid: Range valid. */
254#define IOMMU_BF_RANGE_VALID_SHIFT 7
255#define IOMMU_BF_RANGE_VALID_MASK UINT32_C(0x00000080)
256/** BusNumber: Device range bus number. */
257#define IOMMU_BF_RANGE_BUS_NUMBER_SHIFT 8
258#define IOMMU_BF_RANGE_BUS_NUMBER_MASK UINT32_C(0x0000ff00)
259/** First Device. */
260#define IOMMU_BF_RANGE_FIRST_DEVICE_SHIFT 16
261#define IOMMU_BF_RANGE_FIRST_DEVICE_MASK UINT32_C(0x00ff0000)
262/** Last Device. */
263#define IOMMU_BF_RANGE_LAST_DEVICE_SHIFT 24
264#define IOMMU_BF_RANGE_LAST_DEVICE_MASK UINT32_C(0xff000000)
265RT_BF_ASSERT_COMPILE_CHECKS(IOMMU_BF_RANGE_, UINT32_C(0), UINT32_MAX,
266 (UNIT_ID, RSVD_5_6, VALID, BUS_NUMBER, FIRST_DEVICE, LAST_DEVICE));
267/** @} */
268
269/**
270 * @name IOMMU Miscellaneous Information Register 0.
271 * In accordance with the AMD spec.
272 * @{
273 */
274/** MsiNum: MSI message number. */
275#define IOMMU_BF_MISCINFO_0_MSI_NUM_SHIFT 0
276#define IOMMU_BF_MISCINFO_0_MSI_NUM_MASK UINT32_C(0x0000001f)
277/** GvaSize: Guest Virtual Address Size. */
278#define IOMMU_BF_MISCINFO_0_GVA_SIZE_SHIFT 5
279#define IOMMU_BF_MISCINFO_0_GVA_SIZE_MASK UINT32_C(0x000000e0)
280/** PaSize: Physical Address Size. */
281#define IOMMU_BF_MISCINFO_0_PA_SIZE_SHIFT 8
282#define IOMMU_BF_MISCINFO_0_PA_SIZE_MASK UINT32_C(0x00007f00)
283/** VaSize: Virtual Address Size. */
284#define IOMMU_BF_MISCINFO_0_VA_SIZE_SHIFT 15
285#define IOMMU_BF_MISCINFO_0_VA_SIZE_MASK UINT32_C(0x003f8000)
286/** HtAtsResv: HyperTransport ATS Response Address range Reserved. */
287#define IOMMU_BF_MISCINFO_0_HT_ATS_RESV_SHIFT 22
288#define IOMMU_BF_MISCINFO_0_HT_ATS_RESV_MASK UINT32_C(0x00400000)
289/** Bits 26:23 reserved. */
290#define IOMMU_BF_MISCINFO_0_RSVD_23_26_SHIFT 23
291#define IOMMU_BF_MISCINFO_0_RSVD_23_26_MASK UINT32_C(0x07800000)
292/** MsiNumPPR: Peripheral Page Request MSI message number. */
293#define IOMMU_BF_MISCINFO_0_MSI_NUM_PPR_SHIFT 27
294#define IOMMU_BF_MISCINFO_0_MSI_NUM_PPR_MASK UINT32_C(0xf8000000)
295RT_BF_ASSERT_COMPILE_CHECKS(IOMMU_BF_MISCINFO_0_, UINT32_C(0), UINT32_MAX,
296 (MSI_NUM, GVA_SIZE, PA_SIZE, VA_SIZE, HT_ATS_RESV, RSVD_23_26, MSI_NUM_PPR));
297/** @} */
298
299/**
300 * @name IOMMU Miscellaneous Information Register 1.
301 * In accordance with the AMD spec.
302 * @{
303 */
304/** MsiNumGA: MSI message number for guest virtual-APIC log. */
305#define IOMMU_BF_MISCINFO_1_MSI_NUM_GA_SHIFT 0
306#define IOMMU_BF_MISCINFO_1_MSI_NUM_GA_MASK UINT32_C(0x0000001f)
307/** Bits 31:5 reserved. */
308#define IOMMU_BF_MISCINFO_1_RSVD_5_31_SHIFT 5
309#define IOMMU_BF_MISCINFO_1_RSVD_5_31_MASK UINT32_C(0xffffffe0)
310RT_BF_ASSERT_COMPILE_CHECKS(IOMMU_BF_MISCINFO_1_, UINT32_C(0), UINT32_MAX,
311 (MSI_NUM_GA, RSVD_5_31));
312/** @} */
313
314/**
315 * @name MSI Capability Header Register.
316 * In accordance with the AMD spec.
317 * @{
318 */
319/** MsiCapId: Capability ID. */
320#define IOMMU_BF_MSI_CAPHDR_CAP_ID_SHIFT 0
321#define IOMMU_BF_MSI_CAPHDR_CAP_ID_MASK UINT32_C(0x000000ff)
322/** MsiCapPtr: Pointer (PCI config offset) to the next capability. */
323#define IOMMU_BF_MSI_CAPHDR_CAP_PTR_SHIFT 8
324#define IOMMU_BF_MSI_CAPHDR_CAP_PTR_MASK UINT32_C(0x0000ff00)
325/** MsiEn: Message Signal Interrupt enable. */
326#define IOMMU_BF_MSI_CAPHDR_EN_SHIFT 16
327#define IOMMU_BF_MSI_CAPHDR_EN_MASK UINT32_C(0x00010000)
328/** MsiMultMessCap: MSI Multi-Message Capability. */
329#define IOMMU_BF_MSI_CAPHDR_MULTMESS_CAP_SHIFT 17
330#define IOMMU_BF_MSI_CAPHDR_MULTMESS_CAP_MASK UINT32_C(0x000e0000)
331/** MsiMultMessEn: MSI Mult-Message Enable. */
332#define IOMMU_BF_MSI_CAPHDR_MULTMESS_EN_SHIFT 20
333#define IOMMU_BF_MSI_CAPHDR_MULTMESS_EN_MASK UINT32_C(0x00700000)
334/** Msi64BitEn: MSI 64-bit Enabled. */
335#define IOMMU_BF_MSI_CAPHDR_64BIT_EN_SHIFT 23
336#define IOMMU_BF_MSI_CAPHDR_64BIT_EN_MASK UINT32_C(0x00800000)
337/** Bits 31:24 reserved. */
338#define IOMMU_BF_MSI_CAPHDR_RSVD_24_31_SHIFT 24
339#define IOMMU_BF_MSI_CAPHDR_RSVD_24_31_MASK UINT32_C(0xff000000)
340RT_BF_ASSERT_COMPILE_CHECKS(IOMMU_BF_MSI_CAPHDR_, UINT32_C(0), UINT32_MAX,
341 (CAP_ID, CAP_PTR, EN, MULTMESS_CAP, MULTMESS_EN, 64BIT_EN, RSVD_24_31));
342/** @} */
343
344/**
345 * @name MSI Mapping Capability Header Register.
346 * In accordance with the AMD spec.
347 * @{
348 */
349/** MsiMapCapId: Capability ID. */
350#define IOMMU_BF_MSI_MAP_CAPHDR_CAP_ID_SHIFT 0
351#define IOMMU_BF_MSI_MAP_CAPHDR_CAP_ID_MASK UINT32_C(0x000000ff)
352/** MsiMapCapPtr: Pointer (PCI config offset) to the next capability. */
353#define IOMMU_BF_MSI_MAP_CAPHDR_CAP_PTR_SHIFT 8
354#define IOMMU_BF_MSI_MAP_CAPHDR_CAP_PTR_MASK UINT32_C(0x0000ff00)
355/** MsiMapEn: MSI mapping capability enable. */
356#define IOMMU_BF_MSI_MAP_CAPHDR_EN_SHIFT 16
357#define IOMMU_BF_MSI_MAP_CAPHDR_EN_MASK UINT32_C(0x00010000)
358/** MsiMapFixd: MSI interrupt mapping range is not programmable. */
359#define IOMMU_BF_MSI_MAP_CAPHDR_FIXED_SHIFT 17
360#define IOMMU_BF_MSI_MAP_CAPHDR_FIXED_MASK UINT32_C(0x00020000)
361/** Bits 18:28 reserved. */
362#define IOMMU_BF_MSI_MAP_CAPHDR_RSVD_18_28_SHIFT 18
363#define IOMMU_BF_MSI_MAP_CAPHDR_RSVD_18_28_MASK UINT32_C(0x07fc0000)
364/** MsiMapCapType: MSI mapping capability. */
365#define IOMMU_BF_MSI_MAP_CAPHDR_CAP_TYPE_SHIFT 27
366#define IOMMU_BF_MSI_MAP_CAPHDR_CAP_TYPE_MASK UINT32_C(0xf8000000)
367RT_BF_ASSERT_COMPILE_CHECKS(IOMMU_BF_MSI_MAP_CAPHDR_, UINT32_C(0), UINT32_MAX,
368 (CAP_ID, CAP_PTR, EN, FIXED, RSVD_18_28, CAP_TYPE));
369/** @} */
370
371/** @name Miscellaneous IOMMU defines.
372 * @{ */
373#define IOMMU_LOG_PFX "AMD_IOMMU" /**< Log prefix string. */
374#define IOMMU_SAVED_STATE_VERSION 1 /**< The current saved state version. */
375#define IOMMU_PCI_VENDOR_ID 0x1022 /**< AMD's vendor ID. */
376#define IOMMU_PCI_DEVICE_ID 0xc0de /**< VirtualBox IOMMU device ID. */
377#define IOMMU_PCI_REVISION_ID 0x01 /**< VirtualBox IOMMU device revision ID. */
378#define IOMMU_MMIO_REGION_SIZE _16K /**< Size of the MMIO region in bytes. */
379/** @} */
380
381/**
382 * Acquires the IOMMU lock or returns.
383 */
384#define IOMMU_LOCK_RET(a_pDevIns, a_pThis, a_rcBusy) \
385 do { \
386 int rcLock = PDMDevHlpCritSectEnter((a_pDevIns), &(a_pThis)->CritSect, (a_rcBusy)); \
387 if (RT_LIKELY(rcLock == VINF_SUCCESS)) \
388 { /* likely */ } \
389 else \
390 return rcLock; \
391 } while (0)
392
393/**
394 * Releases the IOMMU lock.
395 */
396#define IOMMU_UNLOCK(a_pDevIns, a_pThis) \
397 do { PDMDevHlpCritSectLeave((a_pDevIns), &(a_pThis)->CritSect); } while (0)
398
399
400/*********************************************************************************************************************************
401* Structures and Typedefs *
402*********************************************************************************************************************************/
403/**
404 * The Device ID.
405 * In accordance with the AMD spec.
406 */
407typedef union
408{
409 struct
410 {
411 uint16_t uFunction : 3; /**< Bits 2:0 - Function. */
412 uint16_t uDevice : 5; /**< Bits 7:3 - Device. */
413 uint16_t uBus : 8; /**< Bits 15:8 - Bus. */
414 } n;
415 /** The unsigned integer view. */
416 uint16_t u;
417} DEVICE_ID_T;
418AssertCompileSize(DEVICE_ID_T, 2);
419
420/**
421 * Device Table Entry (DTE).
422 * In accordance with the AMD spec.
423 */
424typedef union
425{
426 struct
427 {
428 uint32_t u1Valid : 1; /**< Bit 0 - V: Valid. */
429 uint32_t u1TranslationValid : 1; /**< Bit 1 - TV: Translation information Valid. */
430 uint32_t u5Rsvd0 : 5; /**< Bits 6:2 - Reserved. */
431 uint32_t u2Had : 2; /**< Bits 8:7 - HAD: Host Access Dirty. */
432 uint32_t u3Mode : 3; /**< Bits 11:9 - Mode: Paging mode. */
433 uint32_t u20PageTableRootPtrLo : 20; /**< Bits 31:12 - Page Table Root Pointer (Lo). */
434 uint32_t u20PageTableRootPtrHi : 20; /**< Bits 51:32 - Page Table Root Pointer (Hi). */
435 uint32_t u1Ppr : 1; /**< Bit 52 - PPR: Peripheral Page Request. */
436 uint32_t u1GstPprRespPasid : 1; /**< Bit 53 - GRPR: Guest PPR Response with PASID. */
437 uint32_t u1GstIoValid : 1; /**< Bit 54 - GIoV: Guest I/O Protection Valid. */
438 uint32_t u1GstTranslateValid : 1; /**< Bit 55 - GV: Guest translation Valid. */
439 uint32_t u2GstCr3RootTblTranslated : 2; /**< Bits 57:56 - GLX: Guest Levels Translated. */
440 uint32_t u3GstCr3TableRootPtrLo : 2; /**< Bits 60:58 - GCR3 TRP: Guest CR3 Table Root Pointer (Lo). */
441 uint32_t u1IoRead : 1; /**< Bit 61 - IR: I/O Read permission. */
442 uint32_t u1IoWrite : 1; /**< Bit 62 - IW: I/O Write permission. */
443 uint32_t u1Rsvd0 : 1; /**< Bit 63 - Reserved. */
444 uint32_t u16DomainId : 1; /**< Bits 79:64 - Domain ID. */
445 uint32_t u16GstCr3TableRootPtrMed : 16; /**< Bits 95:80 - GCR3 TRP: Guest CR3 Table Root Pointer (Mid). */
446 uint32_t u1IoTlbEnable : 1; /**< Bit 96 - IOTLB Enable. */
447 uint32_t u1SuppressPfEvents : 1; /**< Bit 97 - SE: Supress Page-fault events. */
448 uint32_t u1SuppressAllPfEvents : 1; /**< Bit 98 - SA: Supress All Page-fault events. */
449 uint32_t u2IoCtl : 1; /**< Bits 100:99 - IoCtl: Port I/O Control. */
450 uint32_t u1Cache : 1; /**< Bit 101 - Cache: IOTLB Cache Hint. */
451 uint32_t u1SnoopDisable : 1; /**< Bit 102 - SD: Snoop Disable. */
452 uint32_t u1AllowExclusion : 1; /**< Bit 103 - EX: Allow Exclusion. */
453 uint32_t u2SysMgt : 2; /**< Bits 105:104 - SysMgt: System Management message enable. */
454 uint32_t u1Rsvd1 : 1; /**< Bit 106 - Reserved. */
455 uint32_t u21GstCr3TableRootPtrHi : 21; /**< Bits 127:107 - GCR3 TRP: Guest CR3 Table Root Pointer (Hi). */
456 uint32_t u1IntrMapValid : 1; /**< Bit 128 - IV: Interrupt map Valid. */
457 uint32_t u4IntrTableLength : 4; /**< Bits 132:129 - IntTabLen: Interrupt Table Length. */
458 uint32_t u1IgnoreUnmappedIntrs : 1; /**< Bits 133 - IG: Ignore unmapped interrupts. */
459 uint32_t u26IntrTableRootPtr : 26; /**< Bits 159:134 - Interrupt Root Table Pointer (Lo). */
460 uint32_t u20IntrTableRootPtr : 20; /**< Bits 179:160 - Interrupt Root Table Pointer (Hi). */
461 uint32_t u4Rsvd0 : 4; /**< Bits 183:180 - Reserved. */
462 uint32_t u1InitPassthru : 1; /**< Bits 184 - INIT Pass-through. */
463 uint32_t u1ExtIntPassthru : 1; /**< Bits 185 - External Interrupt Pass-through. */
464 uint32_t u1NmiPassthru : 1; /**< Bits 186 - NMI Pass-through. */
465 uint32_t u1Rsvd2 : 1; /**< Bits 187 - Reserved. */
466 uint32_t u2IntrCtrl : 2; /**< Bits 189:188 - IntCtl: Interrupt Control. */
467 uint32_t u1Lint0Passthru : 1; /**< Bit 190 - Lint0Pass: LINT0 (Legacy PIC NMI) Pass-thru. */
468 uint32_t u1Lint1Passthru : 1; /**< Bit 191 - Lint1Pass: LINT1 (Legacy PIC NMI) Pass-thru. */
469 uint32_t u32Rsvd0; /**< Bits 223:192 - Reserved. */
470 uint32_t u22Rsvd0 : 22; /**< Bits 245:224 - Reserved. */
471 uint32_t u1AttrOverride : 1; /**< Bit 246 - AttrV: Attribute Override. */
472 uint32_t u1Mode0FC: 1; /**< Bit 247 - Mode0FC. */
473 uint32_t u8SnoopAttr: 1; /**< Bits 255:248 - Snoop Attribute. */
474 } n;
475 /** The 32-bit unsigned integer view. */
476 uint32_t au32[8];
477} DEV_TAB_ENTRY_T;
478AssertCompileSize(DEV_TAB_ENTRY_T, 32);
479
480/**
481 * I/O Page Table Entry.
482 * In accordance with the AMD spec.
483 */
484typedef union
485{
486 struct
487 {
488 RT_GCC_EXTENSION uint64_t u1Present : 1; /**< Bit 0 - PR: Present. */
489 RT_GCC_EXTENSION uint64_t u4Ign0 : 4; /**< Bits 4:1 - Ignored. */
490 RT_GCC_EXTENSION uint64_t u1Accessed : 1; /**< Bit 5 - A: Accessed. */
491 RT_GCC_EXTENSION uint64_t u1Dirty : 1; /**< Bit 6 - D: Dirty. */
492 RT_GCC_EXTENSION uint64_t u2Ign0 : 2; /**< Bits 8:7 - Ignored. */
493 RT_GCC_EXTENSION uint64_t u3NextLevel : 3; /**< Bits 11:9 - Next Level: Next page translation level. */
494 RT_GCC_EXTENSION uint64_t u40PageAddr : 40; /**< Bits 51:12 - Page address. */
495 RT_GCC_EXTENSION uint64_t u7Rsvd0 : 7; /**< Bits 58:52 - Reserved. */
496 RT_GCC_EXTENSION uint64_t u1UntranslatedAccess : 1; /**< Bit 59 - U: Untranslated Access Only. */
497 RT_GCC_EXTENSION uint64_t u1ForceCoherent : 1; /**< Bit 60 - FC: Force Coherent. */
498 RT_GCC_EXTENSION uint64_t u1IoRead : 1; /**< Bit 61 - IR: I/O Read permission. */
499 RT_GCC_EXTENSION uint64_t u1IoWrite : 1; /**< Bit 62 - IW: I/O Wead permission. */
500 RT_GCC_EXTENSION uint64_t u1Ign0 : 1; /**< Bit 63 - Ignored. */
501 } n;
502 /** The 64-bit unsigned integer view. */
503 uint64_t u;
504} IOPTE_T;
505AssertCompileSize(IOPTE_T, 8);
506
507/**
508 * I/O Page Directory Entry.
509 * In accordance with the AMD spec.
510 */
511typedef union
512{
513 struct
514 {
515 RT_GCC_EXTENSION uint64_t u1Present : 1; /**< Bit 0 - PR: Present. */
516 RT_GCC_EXTENSION uint64_t u4Ign0 : 4; /**< Bits 4:1 - Ignored. */
517 RT_GCC_EXTENSION uint64_t u1Accessed : 1; /**< Bit 5 - A: Accessed. */
518 RT_GCC_EXTENSION uint64_t u3Ign0 : 3; /**< Bits 8:6 - Ignored. */
519 RT_GCC_EXTENSION uint64_t u3NextLevel : 3; /**< Bits 11:9 - Next Level: Next page translation level. */
520 RT_GCC_EXTENSION uint64_t u40PageAddr : 40; /**< Bits 51:12 - Page address (Next Table Address). */
521 RT_GCC_EXTENSION uint64_t u9Rsvd0 : 9; /**< Bits 60:52 - Reserved. */
522 RT_GCC_EXTENSION uint64_t u1IoRead : 1; /**< Bit 61 - IR: I/O Read permission. */
523 RT_GCC_EXTENSION uint64_t u1IoWrite : 1; /**< Bit 62 - IW: I/O Wead permission. */
524 RT_GCC_EXTENSION uint64_t u1Ign0 : 1; /**< Bit 63 - Ignored. */
525 } n;
526 /** The 64-bit unsigned integer view. */
527 uint64_t u;
528} IOPDE_T;
529AssertCompileSize(IOPDE_T, 8);
530
531/**
532 * Interrupt Remapping Table Entry.
533 * In accordance with the AMD spec.
534 */
535typedef union
536{
537 struct
538 {
539 uint32_t u1RemapEnable : 1; /**< Bit 0 - RemapEn: Remap Enable. */
540 uint32_t u1SuppressPf : 1; /**< Bit 1 - SupIOPF: Supress I/O Page Fault. */
541 uint32_t u3IntrType : 1; /**< Bits 4:2 - IntType: Interrupt Type. */
542 uint32_t u1ReqEoi : 1; /**< Bit 5 - RqEoi: Request EOI. */
543 uint32_t u1DstMode : 1; /**< Bit 6 - DM: Destination Mode. */
544 uint32_t u1GuestMode : 1; /**< Bit 7 - GuestMode. */
545 uint32_t u8Dst : 8; /**< Bits 15:8 - Destination. */
546 uint32_t u8Vector : 8; /**< Bits 23:16 - Vector. */
547 uint32_t u8Rsvd0 : 8; /**< Bits 31:24 - Reserved. */
548 } n;
549 /** The 32-bit unsigned integer view. */
550 uint32_t u;
551} IRTE_T;
552AssertCompileSize(IRTE_T, 4);
553
554/**
555 * Command: Generic Command Buffer Entry.
556 * In accordance with the AMD spec.
557 */
558typedef union
559{
560 struct
561 {
562 uint32_t u32Operand1Lo; /**< Bits 31:0 - Operand 1 (Lo). */
563 uint32_t u32Operand1Hi : 28; /**< Bits 59:32 - Operand 1 (Hi). */
564 uint32_t u4Opcode : 4; /**< Bits 63:60 - Op Code. */
565 uint64_t u64Operand2; /**< Bits 127:64 - Operand 2. */
566 } n;
567 /** The 64-bit unsigned integer view. */
568 uint64_t au64[2];
569} CMD_GENERIC_T;
570AssertCompileSize(CMD_GENERIC_T, 16);
571
572/**
573 * Command: COMPLETION_WAIT.
574 * In accordance with the AMD spec.
575 */
576typedef union
577{
578 struct
579 {
580 uint32_t u1Store : 1; /**< Bit 0 - S: Completion Store. */
581 uint32_t u1Interrupt : 1; /**< Bit 1 - I: Completion Interrupt. */
582 uint32_t u1Flush : 1; /**< Bit 2 - F: Flush Queue. */
583 uint32_t u29StoreAddrLo : 29; /**< Bits 31:3 - Store Address (Lo). */
584 uint32_t u20StoreAddrHi : 20; /**< Bits 51:32 - Store Address (Hi). */
585 uint32_t u8Rsvd0 : 8; /**< Bits 59:52 - Reserved. */
586 uint32_t u4OpCode : 4; /**< Bits 63:60 - OpCode (Command). */
587 uint64_t u64StoreData; /**< Bits 127:64 - Store Data. */
588 } n;
589 /** The 64-bit unsigned integer view. */
590 uint32_t au64[2];
591} CMD_COMPLETION_WAIT_T;
592AssertCompileSize(CMD_COMPLETION_WAIT_T, 16);
593
594/**
595 * Command: INVALIDATE_DEVTAB_ENTRY.
596 * In accordance with the AMD spec.
597 */
598typedef union
599{
600 struct
601 {
602 uint16_t u16DeviceId; /**< Bits 15:0 - DeviceID. */
603 uint16_t u16Rsvd0; /**< Bits 31:16 - Reserved. */
604 uint32_t u28Rsvd0 : 28; /**< Bits 59:32 - Reserved. */
605 uint32_t u4OpCode : 4; /**< Bits 63:60 - Op Code (Command). */
606 uint64_t u64Rsvd0; /**< Bits 127:64 - Reserved. */
607 } n;
608 /** The 64-bit unsigned integer view. */
609 uint64_t au64[2];
610} CMD_INV_DEV_TAB_ENTRY_T;
611AssertCompileSize(CMD_INV_DEV_TAB_ENTRY_T, 16);
612
613/**
614 * Command: INVALIDATE_IOMMU_PAGES.
615 * In accordance with the AMD spec.
616 */
617typedef union
618{
619 struct
620 {
621 uint32_t u20Pasid : 20; /**< Bits 19:0 - PASID: Process Address-Space ID. */
622 uint32_t u12Rsvd0 : 12; /**< Bits 31:20 - Reserved. */
623 uint32_t u16DomainId : 16; /**< Bits 47:32 - Domain ID. */
624 uint32_t u12Rsvd1 : 12; /**< Bits 59:48 - Reserved. */
625 uint32_t u4OpCode : 4; /**< Bits 63:60 - Op Code (Command). */
626 uint32_t u1Size : 1; /**< Bit 64 - S: Size. */
627 uint32_t u1PageDirEntries : 1; /**< Bit 65 - PDE: Page Directory Entries. */
628 uint32_t u1GuestOrNested : 1; /**< Bit 66 - GN: Guest (GPA) or Nested (GVA). */
629 uint32_t u9Rsvd0 : 9; /**< Bits 75:67 - Reserved. */
630 uint32_t u20AddrLo : 20; /**< Bits 95:76 - Address (Lo). */
631 uint32_t u32AddrHi; /**< Bits 127:96 - Address (Hi). */
632 } n;
633 /** The 64-bit unsigned integer view. */
634 uint64_t au64[2];
635} CMD_INV_IOMMU_PAGES_T;
636AssertCompileSize(CMD_INV_IOMMU_PAGES_T, 16);
637
638/**
639 * Command: INVALIDATE_IOTLB_PAGES.
640 * In accordance with the AMD spec.
641 */
642typedef union
643{
644 struct
645 {
646 uint16_t u16DeviceId; /**< Bits 15:0 - Device ID. */
647 uint8_t u8PasidLo; /**< Bits 23:16 - PASID: Process Address-Space ID (Lo). */
648 uint8_t u8MaxPend; /**< Bits 31:24 - Maxpend: Maximum simultaneous in-flight transactions. */
649 uint32_t u16QueueId : 16; /**< Bits 47:32 - Queue ID. */
650 uint32_t u12PasidHi : 12; /**< Bits 59:48 - PASID: Process Address-Space ID (Hi). */
651 uint32_t u4OpCode : 4; /**< Bits 63:60 - Op Code (Command). */
652 uint32_t u1Size : 1; /**< Bit 64 - S: Size. */
653 uint32_t u1Rsvd0: 1; /**< Bit 65 - Reserved. */
654 uint32_t u1GuestOrNested : 1; /**< Bit 66 - GN: Guest (GPA) or Nested (GVA). */
655 uint32_t u1Rsvd1 : 1; /**< Bit 67 - Reserved. */
656 uint32_t u2Type : 2; /**< Bit 69:68 - Type. */
657 uint32_t u6Rsvd0 : 6; /**< Bits 75:70 - Reserved. */
658 uint32_t u20AddrLo : 20; /**< Bits 95:76 - Address (Lo). */
659 uint32_t u32AddrHi; /**< Bits 127:96 - Address (Hi). */
660 } n;
661 /** The 64-bit unsigned integer view. */
662 uint64_t au64[2];
663} CMD_INV_IOTLB_PAGES_T;
664AssertCompileSize(CMD_INV_IOTLB_PAGES_T, 16);
665
666/**
667 * Command: INVALIDATE_INTR_TABLE.
668 * In accordance with the AMD spec.
669 */
670typedef union
671{
672 struct
673 {
674 uint16_t u16DeviceId; /**< Bits 15:0 - Device ID. */
675 uint16_t u16Rsvd0; /**< Bits 31:16 - Reserved. */
676 uint32_t u32Rsvd0 : 28; /**< Bits 59:32 - Reserved. */
677 uint32_t u4OpCode : 4; /**< Bits 63:60 - Op Code (Command). */
678 uint64_t u64Rsvd0; /**< Bits 127:64 - Reserved. */
679 } u;
680 /** The 64-bit unsigned integer view. */
681 uint64_t au64[2];
682} CMD_INV_INTR_TABLE_T;
683AssertCompileSize(CMD_INV_INTR_TABLE_T, 16);
684
685/**
686 * Command: COMPLETE_PPR_REQ.
687 * In accordance with the AMD spec.
688 */
689typedef union
690{
691 struct
692 {
693 uint16_t u16DeviceId; /**< Bits 15:0 - Device ID. */
694 uint16_t u16Rsvd0; /**< Bits 31:16 - Reserved. */
695 uint32_t u20Pasid : 20; /**< Bits 51:32 - PASID: Process Address-Space ID. */
696 uint32_t u8Rsvd0 : 8; /**< Bits 59:52 - Reserved. */
697 uint32_t u4OpCode : 4; /**< Bits 63:60 - Op Code (Command). */
698 uint32_t u2Rsvd0 : 2; /**< Bits 65:64 - Reserved. */
699 uint32_t u1GuestOrNested : 1; /**< Bit 66 - GN: Guest (GPA) or Nested (GVA). */
700 uint32_t u29Rsvd0 : 29; /**< Bits 95:67 - Reserved. */
701 uint32_t u16CompletionTag : 16; /**< Bits 111:96 - Completion Tag. */
702 uint32_t u16Rsvd1 : 16; /**< Bits 127:112 - Reserved. */
703 } n;
704 /** The 64-bit unsigned integer view. */
705 uint64_t au64[2];
706} CMD_COMPLETE_PPR_REQ_T;
707AssertCompileSize(CMD_COMPLETE_PPR_REQ_T, 16);
708
709/**
710 * Command: INV_IOMMU_ALL.
711 * In accordance with the AMD spec.
712 */
713typedef union
714{
715 struct
716 {
717 uint32_t u32Rsvd0; /**< Bits 31:0 - Reserved. */
718 uint32_t u28Rsvd0 : 28; /**< Bits 59:32 - Reserved. */
719 uint32_t u4OpCode : 4; /**< Bits 63:60 - Op Code (Command). */
720 uint64_t u64Rsvd0; /**< Bits 127:64 - Reserved. */
721 } n;
722 /** The 64-bit unsigned integer view. */
723 uint64_t au64[2];
724} CMD_IOMMU_ALL_T;
725AssertCompileSize(CMD_IOMMU_ALL_T, 16);
726
727/**
728 * Event Log Entry: Generic.
729 * In accordance with the AMD spec.
730 */
731typedef union
732{
733 struct
734 {
735 uint32_t u32Operand1Lo; /**< Bits 31:0 - Operand 1 (Lo). */
736 uint32_t u32Operand1Hi : 28; /**< Bits 59:32 - Operand 1 (Hi). */
737 uint32_t u4EventCode : 4; /**< Bits 63:60 - Event code. */
738 uint32_t u32Operand2Lo; /**< Bits 95:64 - Operand 2 (Lo). */
739 uint32_t u32Operand2Hi; /**< Bits 127:96 - Operand 2 (Hi). */
740 } n;
741 /** The 32-bit unsigned integer view. */
742 uint32_t au32[4];
743} EVT_GENERIC_T;
744AssertCompileSize(EVT_GENERIC_T, 16);
745
746/**
747 * Event Log Entry: ILLEGAL_DEV_TAB_ENTRY.
748 * In accordance with the AMD spec.
749 */
750typedef union
751{
752 struct
753 {
754 uint16_t u16DeviceId; /**< Bits 15:0 - Device ID. */
755 uint16_t u4PasidHi : 4; /**< Bits 19:16 - PASID: Process Address-Space ID (Hi). */
756 uint16_t u12Rsvd0 : 12; /**< Bits 31:20 - Reserved. */
757 uint16_t u16PasidLo; /**< Bits 47:32 - PASID: Process Address-Space ID (Lo). */
758 uint16_t u1GuestOrNested : 1; /**< Bit 48 - GN: Guest (GPA) or Nested (GVA). */
759 uint16_t u2Rsvd0 : 2; /**< Bits 50:49 - Reserved. */
760 uint16_t u1Interrupt : 1; /**< Bit 51 - I: Interrupt. */
761 uint16_t u1Rsvd0 : 1; /**< Bit 52 - Reserved. */
762 uint16_t u1ReadWrite : 1; /**< Bit 53 - RW: Read/Write. */
763 uint16_t u1Rsvd1 : 1; /**< Bit 54 - Reserved. */
764 uint16_t u1RsvdZero : 1; /**< Bit 55 - RZ: Reserved bit not Zero or invalid level encoding. */
765 uint16_t u1Translation : 1; /**< Bit 56 - TN: Translation. */
766 uint16_t u3Rsvd0 : 3; /**< Bits 59:57 - Reserved. */
767 uint16_t u4EventCode : 4; /**< Bits 63:60 - Event code. */
768 uint32_t u2Rsvd1 : 2; /**< Bits 65:64 - Reserved. */
769 uint32_t u30AddrLo : 2; /**< Bits 95:66 - Address: Device Virtual Address (Lo). */
770 uint32_t u30AddrHi; /**< Bits 127:96 - Address: Device Virtual Address (Hi). */
771 } n;
772 /** The 32-bit unsigned integer view. */
773 uint32_t au32[4];
774} EVT_ILLEGAL_DEV_TAB_ENTRY_T;
775AssertCompileSize(EVT_ILLEGAL_DEV_TAB_ENTRY_T, 16);
776
777/**
778 * Event Log Entry: IO_PAGE_FAULT_EVENT.
779 * In accordance with the AMD spec.
780 */
781typedef union
782{
783 struct
784 {
785 uint16_t u16DeviceId; /**< Bits 15:0 - Device ID. */
786 uint16_t u4PasidHi : 4; /**< Bits 19:16 - PASID: Process Address-Space ID (Hi). */
787 uint16_t u16DomainOrPasidLo; /**< Bits 47:32 - D/P: Domain ID or Process Address-Space ID (Lo). */
788 uint16_t u1GuestOrNested : 1; /**< Bit 48 - GN: Guest (GPA) or Nested (GVA). */
789 uint16_t u1NoExecute : 1; /**< Bit 49 - NX: No Execute. */
790 uint16_t u1User : 1; /**< Bit 50 - US: User/Supervisor. */
791 uint16_t u1Interrupt : 1; /**< Bit 51 - I: Interrupt. */
792 uint16_t u1Present : 1; /**< Bit 52 - PR: Present. */
793 uint16_t u1ReadWrite : 1; /**< Bit 53 - RW: Read/Write. */
794 uint16_t u1Perm : 1; /**< Bit 54 - PE: Permission Indicator. */
795 uint16_t u1RsvdZero : 1; /**< Bit 55 - RZ: Reserved bit not Zero or invalid level encoding. */
796 uint16_t u1Translation : 1; /**< Bit 56 - TN: Translation. */
797 uint16_t u3Rsvd0 : 3; /**< Bit 59:57 - Reserved. */
798 uint16_t u4EventCode : 4; /**< Bits 63:60 - Event code. */
799 uint64_t u64Addr; /**< Bits 127:64 - Address: Device Virtual Address. */
800 } n;
801 /** The 32-bit unsigned integer view. */
802 uint32_t au32[4];
803} EVT_IO_PAGE_FAULT_T;
804AssertCompileSize(EVT_IO_PAGE_FAULT_T, 16);
805
806/**
807 * Event Log Entry: DEV_TAB_HARDWARE_ERROR.
808 * In accordance with the AMD spec.
809 */
810typedef union
811{
812 struct
813 {
814 uint16_t u16DeviceId; /**< Bits 15:0 - Device ID. */
815 uint16_t u16Rsvd0; /**< Bits 31:16 - Reserved. */
816 uint32_t u19Rsvd0 : 19; /**< Bits 50:32 - Reserved. */
817 uint32_t u1Intr : 1; /**< Bit 51 - I: Interrupt. */
818 uint32_t u1Rsvd0 : 1; /**< Bit 52 - Reserved. */
819 uint32_t u1ReadWrite : 1; /**< Bit 53 - RW: Read/Write. */
820 uint32_t u2Rsvd0 : 2; /**< Bits 55:54 - Reserved. */
821 uint32_t u1Translation : 1; /**< Bit 56 - TR: Translation. */
822 uint32_t u2Type : 2; /**< Bits 58:57 - Type: The type of hardware error. */
823 uint32_t u1Rsvd1 : 1; /**< Bit 59 - Reserved. */
824 uint32_t u4EventCode : 4; /**< Bits 63:60 - Event code. */
825 uint32_t u4Rsvd0 : 4; /**< Bits 67:64 - Reserved. */
826 uint32_t u28AddrLo : 28; /**< Bits 95:68 - Address: System Physical Address (Lo). */
827 uint32_t u32AddrHi; /**< Bits 127:96 - Address: System Physical Address (Hi). */
828 } n;
829 /** The 32-bit unsigned integer view. */
830 uint32_t au32[4];
831} EVT_DEV_TAB_HARDWARE_ERROR;
832AssertCompileSize(EVT_DEV_TAB_HARDWARE_ERROR, 16);
833
834/**
835 * Event Log Entry: EVT_PAGE_TAB_HARDWARE_ERROR.
836 * In accordance with the AMD spec.
837 */
838typedef union
839{
840 struct
841 {
842 uint16_t u16DeviceId; /**< Bits 15:0 - Device ID. */
843 uint16_t u16Rsvd0; /**< Bits 31:16 - Reserved. */
844 uint32_t u16DomainOrPasidLo : 16; /**< Bits 47:32 - D/P: Domain ID or Process Address-Space ID (Lo). */
845 uint32_t u1GuestOrNested : 1; /**< Bit 48 - GN: Guest (GPA) or Nested (GVA). */
846 uint32_t u2Rsvd0 : 2; /**< Bits 50:49 - Reserved. */
847 uint32_t u1Interrupt : 1; /**< Bit 51 - I: Interrupt. */
848 uint32_t u1Rsvd0 : 1; /**< Bit 52 - Reserved. */
849 uint32_t u1ReadWrite : 1; /**< Bit 53 - RW: Read/Write. */
850 uint32_t u2Rsvd1 : 2; /**< Bit 55:54 - Reserved. */
851 uint32_t u1Translation : 1; /**< Bit 56 - TR: Translation. */
852 uint32_t u2Type : 2; /**< Bits 58:57 - Type: The type of hardware error. */
853 uint32_t u1Rsvd1 : 1; /**< Bit 59 - Reserved. */
854 uint32_t u4EventCode : 4; /**< Bit 63:60 - Event code. */
855 /** @todo r=ramshankar: Figure 55: PAGE_TAB_HARDWARE_ERROR says Addr[31:3] but
856 * table 58 mentions Addr[31:4]. Looks like a typo in the figure. Use
857 * table as it makes more sense and matches address size in
858 * EVT_DEV_TAB_HARDWARE_ERROR. See AMD AMD IOMMU spec (3.05-PUB, Jan
859 * 2020). */
860 uint32_t u4Rsvd0 : 4; /**< Bits 67:64 - Reserved. */
861 uint32_t u28AddrLo : 28; /**< Bits 95:68 - Address: SPA of page table entry (Lo). */
862 uint32_t u32AddrHi; /**< Bits 127:96 - Address: SPA of page table entry (Hi). */
863 } n;
864 /** The 32-bit unsigned integer view. */
865 uint32_t au32[4];
866} EVT_PAGE_TAB_HARDWARE_ERROR;
867AssertCompileSize(EVT_PAGE_TAB_HARDWARE_ERROR, 16);
868
869/**
870 * Event Log Entry: ILLEGAL_COMMAND_ERROR.
871 * In accordance with the AMD spec.
872 */
873typedef union
874{
875 struct
876 {
877 uint32_t u32Rsvd0; /**< Bits 31:0 - Reserved. */
878 uint32_t u28Rsvd0 : 28; /**< Bits 47:32 - Reserved. */
879 uint32_t u4EventCode : 4; /**< Bits 63:60 - Event code. */
880 uint32_t u4Rsvd0 : 4; /**< Bits 67:64 - Reserved. */
881 uint32_t u28AddrLo : 28; /**< Bits 95:68 - Address: SPA of the invalid command (Lo). */
882 uint32_t u32AddrHi; /**< Bits 127:96 - Address: SPA of the invalid command (Hi). */
883 } n;
884 /** The 32-bit unsigned integer view. */
885 uint32_t au32[4];
886} EVT_ILLEGAL_COMMAND_ENTRY;
887AssertCompileSize(EVT_ILLEGAL_COMMAND_ENTRY, 16);
888
889/**
890 * Event Log Entry: COMMAND_HARDWARE_ERROR.
891 * In accordance with the AMD spec.
892 */
893typedef union
894{
895 struct
896 {
897 uint32_t u32Rsvd0; /**< Bits 31:0 - Reserved. */
898 uint32_t u4Rsvd0 : 4; /**< Bits 35:32 - Reserved. */
899 uint32_t u28AddrLo : 28; /**< Bits 63:36 - Address: SPA of the attempted access (Lo). */
900 uint32_t u32AddrHi; /**< Bits 95:64 - Address: SPA of the attempted access (Hi). */
901 } n;
902 /** The 32-bit unsigned integer view. */
903 uint32_t au32[3];
904} EVT_COMMAND_HARDWARE_ERROR;
905AssertCompileSize(EVT_COMMAND_HARDWARE_ERROR, 12);
906
907/**
908 * Event Log Entry: IOTLB_INV_TIMEOUT.
909 * In accordance with the AMD spec.
910 */
911typedef union
912{
913 struct
914 {
915 uint16_t u16DeviceId; /**< Bits 15:0 - Device ID. */
916 uint16_t u16Rsvd0; /**< Bits 31:16 - Reserved.*/
917 uint32_t u28Rsvd0 : 28; /**< Bits 59:32 - Reserved. */
918 uint32_t u4EventCode : 4; /**< Bits 63:60 - Event code. */
919 uint32_t u4Rsvd0 : 4; /**< Bits 67:64 - Reserved. */
920 uint32_t u28AddrLo : 28; /**< Bits 95:68 - Address: SPA of the invalidation command that timedout (Lo). */
921 uint32_t u32AddrHi; /**< Bits 127:96 - Address: SPA of the invalidation command that timedout (Hi). */
922 } n;
923 /** The 32-bit unsigned integer view. */
924 uint32_t au32[4];
925} EVT_IOTLB_INV_TIMEOUT;
926AssertCompileSize(EVT_IOTLB_INV_TIMEOUT, 16);
927
928/**
929 * Event Log Entry: INVALID_DEVICE_REQUEST.
930 * In accordance with the AMD spec.
931 */
932typedef union
933{
934 struct
935 {
936 uint32_t u16DeviceId : 16; /***< Bits 15:0 - Device ID. */
937 uint32_t u4PasidHi : 4; /***< Bits 19:16 - PASID: Process Address-Space ID (Hi). */
938 uint32_t u12Rsvd0 : 12; /***< Bits 31:20 - Reserved. */
939 uint32_t u16PasidLo : 16; /***< Bits 47:32 - PASID: Process Address-Space ID (Lo). */
940 uint32_t u1GuestOrNested : 1; /***< Bit 48 - GN: Guest (GPA) or Nested (GVA). */
941 uint32_t u1User : 1; /***< Bit 49 - US: User/Supervisor. */
942 uint32_t u6Rsvd0 : 6; /***< Bits 55:50 - Reserved. */
943 uint32_t u1Translation: 1; /***< Bit 56 - TR: Translation. */
944 uint32_t u3Type: 3; /***< Bits 59:57 - Type: The type of hardware error. */
945 uint32_t u4EventCode : 4; /***< Bits 63:60 - Event code. */
946 uint64_t u64Addr; /***< Bits 127:64 - Address: Translation or access address. */
947 } n;
948 /** The 32-bit unsigned integer view. */
949 uint32_t au32[4];
950} EVT_INVALID_DEVICE_REQUEST;
951AssertCompileSize(EVT_INVALID_DEVICE_REQUEST, 16);
952
953/**
954 * Event Log Entry: EVENT_COUNTER_ZERO.
955 * In accordance with the AMD spec.
956 */
957typedef union
958{
959 struct
960 {
961 uint32_t u32Rsvd0; /**< Bits 31:0 - Reserved. */
962 uint32_t u28Rsvd0 : 28; /**< Bits 59:32 - Reserved. */
963 uint32_t u4EventCode : 4; /**< Bits 63:60 - Event code. */
964 uint32_t u20CounterNoteHi : 20; /**< Bits 83:64 - CounterNote: Counter value for the event counter register (Hi). */
965 uint32_t u12Rsvd0 : 12; /**< Bits 95:84 - Reserved. */
966 uint32_t u32CounterNoteLo; /**< Bits 127:96 - CounterNote: Counter value for the event cuonter register (Lo). */
967 } n;
968 /** The 32-bit unsigned integer view. */
969 uint32_t au32[4];
970} EVT_EVENT_COUNTER_ZERO;
971AssertCompileSize(EVT_EVENT_COUNTER_ZERO, 16);
972
973/* Not needed as we can initialize from bitfields and set/get using PCI config PDM helpers. */
974#if 0
975/**
976 * IOMMU Capability Header (PCI).
977 * In accordance with the AMD spec.
978 */
979typedef union
980{
981 struct
982 {
983 uint32_t u8CapId : 8; /**< Bits 7:0 - CapId: Capability ID. */
984 uint32_t u8CapPtr : 8; /**< Bits 15:8 - CapPtr: Pointer (PCI config offset) to the next capability. */
985 uint32_t u3CapType : 3; /**< Bits 18:16 - CapType: Capability Type. */
986 uint32_t u5CapRev : 5; /**< Bits 23:19 - CapRev: Capability revision. */
987 uint32_t u1IoTlbSup : 1; /**< Bit 24 - IotlbSup: IOTLB Support. */
988 uint32_t u1HtTunnel : 1; /**< Bit 25 - HtTunnel: HyperTransport Tunnel translation support. */
989 uint32_t u1NpCache : 1; /**< Bit 26 - NpCache: Not Present table entries are cached. */
990 uint32_t u1EfrSup : 1; /**< Bit 27 - EFRSup: Extended Feature Register Support. */
991 uint32_t u1CapExt : 1; /**< Bit 28 - CapExt: Misc. Information Register 1 Support. */
992 uint32_t u4Rsvd0 : 4; /**< Bits 31:29 - Reserved. */
993 } n;
994 /** The 32-bit unsigned integer view. */
995 uint32_t u32;
996} IOMMU_CAP_HDR_T;
997AssertCompileSize(IOMMU_CAP_HDR_T, 4);
998#endif
999
1000/**
1001 * Device Table Base Address Register (MMIO).
1002 * In accordance with the AMD spec.
1003 */
1004typedef union
1005{
1006 struct
1007 {
1008 RT_GCC_EXTENSION uint64_t u9Size : 9; /**< Bits 8:0 - Size: Size of the device table. */
1009 RT_GCC_EXTENSION uint64_t u3Rsvd0 : 3; /**< Bits 11:9 - Reserved. */
1010 RT_GCC_EXTENSION uint64_t u40DevTabBase : 40; /**< Bits 51:12 - DevTabBase: Device table base address. */
1011 RT_GCC_EXTENSION uint64_t u12Rsvd0 : 12; /**< Bits 63:52 - Reserved. */
1012 } n;
1013 /** The 64-bit unsigned integer view. */
1014 uint64_t u64;
1015} DEV_TAB_BAR_T;
1016AssertCompileSize(DEV_TAB_BAR_T, 8);
1017#define IOMMU_DEV_TAB_BAR_VALID_MASK UINT64_C(0x000ffffffffff3ff)
1018
1019/**
1020 * Command Buffer Base Address Register (MMIO).
1021 * In accordance with the AMD spec.
1022 */
1023typedef union
1024{
1025 struct
1026 {
1027 RT_GCC_EXTENSION uint64_t u12Rsvd0 : 12; /**< Bits 11:0 - Reserved. */
1028 RT_GCC_EXTENSION uint64_t u40CmdBase : 40; /**< Bits 51:12 - ComBase: Command buffer base address. */
1029 RT_GCC_EXTENSION uint64_t u4Rsvd0 : 4; /**< Bits 55:52 - Reserved. */
1030 RT_GCC_EXTENSION uint64_t u4CmdLen : 4; /**< Bits 59:56 - ComLen: Command buffer length. */
1031 RT_GCC_EXTENSION uint64_t u4Rsvd1 : 4; /**< Bits 63:60 - Reserved. */
1032 } n;
1033 /** The 64-bit unsigned integer view. */
1034 uint64_t u64;
1035} CMD_BUF_BAR_T;
1036AssertCompileSize(CMD_BUF_BAR_T, 8);
1037#define IOMMU_CMD_BUF_BAR_VALID_MASK UINT64_C(0x0f0ffffffffff000)
1038
1039/**
1040 * Event Log Base Address Register (MMIO).
1041 * In accordance with the AMD spec.
1042 */
1043typedef union
1044{
1045 struct
1046 {
1047 RT_GCC_EXTENSION uint64_t u12Rsvd0 : 12; /**< Bits 11:0 - Reserved. */
1048 RT_GCC_EXTENSION uint64_t u40EvtBase : 40; /**< Bits 51:12 - EventBase: Event log base address. */
1049 RT_GCC_EXTENSION uint64_t u4Rsvd0 : 4; /**< Bits 55:52 - Reserved. */
1050 RT_GCC_EXTENSION uint64_t u4EvtLen : 4; /**< Bits 59:56 - EventLen: Event log length. */
1051 RT_GCC_EXTENSION uint64_t u4Rsvd1 : 4; /**< Bits 63:60 - Reserved. */
1052 } n;
1053 /** The 64-bit unsigned integer view. */
1054 uint64_t u64;
1055} EVT_LOG_BAR_T;
1056AssertCompileSize(EVT_LOG_BAR_T, 8);
1057#define IOMMU_EVT_LOG_BAR_VALID_MASK UINT64_C(0x0f0ffffffffff000)
1058
1059/**
1060 * IOMMU Control Register (MMIO).
1061 * In accordance with the AMD spec.
1062 */
1063typedef union
1064{
1065 struct
1066 {
1067 uint32_t u1IommuEn : 1; /**< Bit 0 - IommuEn: IOMMU Enable. */
1068 uint32_t u1HtTunEn : 1; /**< Bit 1 - HtTunEn: HyperTransport Tunnel Enable. */
1069 uint32_t u1EvtLogEn : 1; /**< Bit 2 - EventLogEn: Event Log Enable. */
1070 uint32_t u1EvtIntrEn : 1; /**< Bit 3 - EventIntEn: Event Log Interrupt Enable. */
1071 uint32_t u1CompWaitIntrEn : 1; /**< Bit 4 - ComWaitIntEn: Completion Wait Interrupt Enable. */
1072 uint32_t u3InvTimeOut : 3; /**< Bits 7:5 - InvTimeOut: Invalidation Timeout. */
1073 uint32_t u1PassPW : 1; /**< Bit 8 - PassPW: Pass Posted Write. */
1074 uint32_t u1ResPassPW : 1; /**< Bit 9 - ResPassPW: Response Pass Posted Write. */
1075 uint32_t u1Coherent : 1; /**< Bit 10 - Coherent: HT read request packet Coherent bit. */
1076 uint32_t u1Isoc : 1; /**< Bit 11 - Isoc: HT read request packet Isochronous bit. */
1077 uint32_t u1CmdBufEn : 1; /**< Bit 12 - CmdBufEn: Command Buffer Enable. */
1078 uint32_t u1PprLogEn : 1; /**< Bit 13 - PprLogEn: Peripheral Page Request (PPR) Log Enable. */
1079 uint32_t u1PprIntrEn : 1; /**< Bit 14 - PprIntrEn: Peripheral Page Request Interrupt Enable. */
1080 uint32_t u1PprEn : 1; /**< Bit 15 - PprEn: Peripheral Page Request processing Enable. */
1081 uint32_t u1GstTranslateEn : 1; /**< Bit 16 - GTEn: Guest Translate Enable. */
1082 uint32_t u1GstVirtApicEn : 1; /**< Bit 17 - GAEn: Guest Virtual-APIC Enable. */
1083 uint32_t u4Crw : 1; /**< Bits 21:18 - CRW: Intended for future use (not documented). */
1084 uint32_t u1SmiFilterEn : 1; /**< Bit 22 - SmiFEn: SMI Filter Enable. */
1085 uint32_t u1SelfWriteBackDis : 1; /**< Bit 23 - SlfWBDis: Self Write-Back Disable. */
1086 uint32_t u1SmiFilterLogEn : 1; /**< Bit 24 - SmiFLogEn: SMI Filter Log Enable. */
1087 uint32_t u3GstVirtApicModeEn : 3; /**< Bits 27:25 - GAMEn: Guest Virtual-APIC Mode Enable. */
1088 uint32_t u1GstLogEn : 1; /**< Bit 28 - GALogEn: Guest Virtual-APIC GA Log Enable. */
1089 uint32_t u1GstIntrEn : 1; /**< Bit 29 - GAIntEn: Guest Virtual-APIC Interrupt Enable. */
1090 uint32_t u2DualPprLogEn : 2; /**< Bits 31:30 - DualPprLogEn: Dual Peripheral Page Request Log Enable. */
1091 uint32_t u2DualEvtLogEn : 2; /**< Bits 33:32 - DualEventLogEn: Dual Event Log Enable. */
1092 uint32_t u3DevTabSegEn : 3; /**< Bits 36:34 - DevTblSegEn: Device Table Segment Enable. */
1093 uint32_t u2PrivAbortEn : 2; /**< Bits 38:37 - PrivAbrtEn: Privilege Abort Enable. */
1094 uint32_t u1PprAutoRespEn : 1; /**< Bit 39 - PprAutoRspEn: Peripheral Page Request Auto Response Enable. */
1095 uint32_t u1MarcEn : 1; /**< Bit 40 - MarcEn: Memory Address Routing and Control Enable. */
1096 uint32_t u1BlockStopMarkEn : 1; /**< Bit 41 - BlkStopMarkEn: Block StopMark messages Enable. */
1097 uint32_t u1PprAutoRespAlwaysOnEn : 1; /**< Bit 42 - PprAutoRspAon:: PPR Auto Response - Always On Enable. */
1098 uint32_t u1DomainIDPNE : 1; /**< Bit 43 - DomainIDPE: Reserved (not documented). */
1099 uint32_t u1Rsvd0 : 1; /**< Bit 44 - Reserved. */
1100 uint32_t u1EnhancedPpr : 1; /**< Bit 45 - EPHEn: Enhanced Peripheral Page Request Handling Enable. */
1101 uint32_t u2HstAccDirtyBitUpdate : 2; /**< Bits 47:46 - HADUpdate: Access and Dirty Bit updated in host page table. */
1102 uint32_t u1GstDirtyUpdateDis : 1; /**< Bit 48 - GDUpdateDis: Disable hardare update of Dirty bit in GPT. */
1103 uint32_t u1Rsvd1 : 1; /**< Bit 49 - Reserved. */
1104 uint32_t u1X2ApicEn : 1; /**< Bit 50 - XTEn: Enable X2APIC. */
1105 uint32_t u1X2ApicIntrGenEn : 1; /**< Bit 51 - IntCapXTEn: Enable IOMMU X2APIC Interrupt generation. */
1106 uint32_t u2Rsvd0 : 2; /**< Bits 53:52 - Reserved. */
1107 uint32_t u1GstAccessUpdateDis : 1; /**< Bit 54 - GAUpdateDis: Disable hardare update of Access bit in GPT. */
1108 uint32_t u8Rsvd0 : 8; /**< Bits 63:55 - Reserved. */
1109 } n;
1110 /** The 64-bit unsigned integer view. */
1111 uint64_t u64;
1112} IOMMU_CTRL_T;
1113AssertCompileSize(IOMMU_CTRL_T, 8);
1114
1115/**
1116 * IOMMU Exclusion Base Register (MMIO).
1117 * In accordance with the AMD spec.
1118 */
1119typedef union
1120{
1121 struct
1122 {
1123 RT_GCC_EXTENSION uint64_t u1ExclEnable : 1; /**< Bit 0 - ExEn: Exclusion Range Enable. */
1124 RT_GCC_EXTENSION uint64_t u1AllowAll : 1; /**< Bit 1 - Allow: Allow All Devices. */
1125 RT_GCC_EXTENSION uint64_t u10Rsvd0 : 10; /**< Bits 11:2 - Reserved. */
1126 RT_GCC_EXTENSION uint64_t u40ExclRangeBase : 40; /**< Bits 51:12 - Exclusion Range Base Address. */
1127 RT_GCC_EXTENSION uint64_t u12Rsvd0 : 12; /**< Bits 63:52 - Reserved. */
1128 } n;
1129 /** The 64-bit unsigned integer view. */
1130 uint64_t u64;
1131} IOMMU_EXCL_RANGE_BAR_T;
1132AssertCompileSize(IOMMU_EXCL_RANGE_BAR_T, 8);
1133#define IOMMU_EXCL_RANGE_BAR_VALID_MASK UINT64_C(0x000ffffffffff003)
1134
1135/**
1136 * IOMMU Exclusion Range Limit Register (MMIO).
1137 * In accordance with the AMD spec.
1138 */
1139typedef union
1140{
1141 struct
1142 {
1143 RT_GCC_EXTENSION uint64_t u12Rsvd0 : 12; /**< Bits 11:0 - Reserved. */
1144 RT_GCC_EXTENSION uint64_t u40ExclLimit : 40; /**< Bits 51:12 - Exclusion Range Limit. */
1145 RT_GCC_EXTENSION uint64_t u12Rsvd1 : 12; /**< Bits 63:52 - Reserved. */
1146 } n;
1147 /** The 64-bit unsigned integer view. */
1148 uint64_t u64;
1149} IOMMU_EXCL_RANGE_LIMIT_T;
1150AssertCompileSize(IOMMU_EXCL_RANGE_LIMIT_T, 8);
1151#define IOMMU_EXCL_RANGE_LIMIT_VALID_MASK UINT64_C(0x000ffffffffff000)
1152
1153
1154/**
1155 * IOMMU Extended Feature Register (MMIO).
1156 * In accordance with the AMD spec.
1157 */
1158typedef union
1159{
1160 struct
1161 {
1162 uint32_t u1PrefetchSup : 1; /**< Bit 0 - PreFSup: Prefetch Support. */
1163 uint32_t u1PprSup : 1; /**< Bit 1 - PPRSup: Peripheral Page Request Support. */
1164 uint32_t u1X2ApicSup : 1; /**< Bit 2 - XTSup: x2Apic Support. */
1165 uint32_t u1NoExecuteSup : 1; /**< Bit 3 - NXSup: No-Execute and Privilege Level Support. */
1166 uint32_t u1GstTranslateSup : 1; /**< Bit 4 - GTSup: Guest Translations Support. */
1167 uint32_t u1Rsvd0 : 1; /**< Bit 5 - Reserved. */
1168 uint32_t u1InvAllSup : 1; /**< Bit 6 - IASup: Invalidate-All Support. */
1169 uint32_t u1GstVirtApicSup : 1; /**< Bit 7 - GASup: Guest Virtual-APIC Support. */
1170 uint32_t u1HwErrorSup : 1; /**< Bit 8 - HESup: Hardware Error registers Support. */
1171 uint32_t u1PerfCounterSup : 1; /**< Bit 8 - PCSup: Performance Counter Support. */
1172 uint32_t u2HostAddrTranslateSize : 2; /**< Bits 11:10 - HATS: Host Address Translation Size. */
1173 uint32_t u2GstAddrTranslateSize : 2; /**< Bits 13:12 - GATS: Guest Address Translation Size. */
1174 uint32_t u2GstCr3RootTblLevel : 2; /**< Bits 15:14 - GLXSup: Guest CR3 Root Table Level (Max) Size Support. */
1175 uint32_t u2SmiFilterSup : 2; /**< Bits 17:16 - SmiFSup: SMI Filter Register Support. */
1176 uint32_t u3SmiFilterCount : 3; /**< Bits 20:18 - SmiFRC: SMI Filter Register Count. */
1177 uint32_t u3GstVirtApicModeSup : 3; /**< Bits 23:21 - GAMSup: Guest Virtual-APIC Modes Supported. */
1178 uint32_t u2DualPprLogSup : 2; /**< Bits 25:24 - DualPprLogSup: Dual Peripheral Page Request Log Support. */
1179 uint32_t u2Rsvd0 : 2; /**< Bits 27:26 - Reserved. */
1180 uint32_t u2DualEvtLogSup : 2; /**< Bits 29:28 - DualEventLogSup: Dual Event Log Support. */
1181 uint32_t u2Rsvd1 : 2; /**< Bits 31:30 - Reserved. */
1182 uint32_t u5MaxPasidSup : 5; /**< Bits 36:32 - PASMax: Maximum PASID Supported. */
1183 uint32_t u1UserSupervisorSup : 1; /**< Bit 37 - USSup: User/Supervisor Page Protection Support. */
1184 uint32_t u2DevTabSegSup : 2; /**< Bits 39:38 - DevTlbSegSup: Segmented Device Table Support. */
1185 uint32_t u1PprLogOverflowWarn : 1; /**< Bit 40 - PprOvrflwEarlySup: PPR Log Overflow Early Warning Support. */
1186 uint32_t u1PprAutoRespSup : 1; /**< Bit 41 - PprAutoRspSup: PPR Automatic Response Support. */
1187 uint32_t u2MarcSup : 2; /**< Bit 43:42 - MarcSup: Memory Access Routing and Control Support. */
1188 uint32_t u1BlockStopMarkSup : 1; /**< Bit 44 - BlkStopMarkSup: Block StopMark messages Support. */
1189 uint32_t u1PerfOptSup : 1; /**< Bit 45 - PerfOptSup: IOMMU Performance Optimization Support. */
1190 uint32_t u1MsiCapMmioSup : 1; /**< Bit 46 - MsiCapMmioSup: MSI Capability Register MMIO Access Support. */
1191 uint32_t u1Rsvd1 : 1; /**< Bit 47 - Reserved. */
1192 uint32_t u1GstIoSup : 1; /**< Bit 48 - GIoSup: Guest I/O Protection Support. */
1193 uint32_t u1HostAccessSup : 1; /**< Bit 49 - HASup: Host Access Support. */
1194 uint32_t u1EnhancedPprSup : 1; /**< Bit 50 - EPHSup: Enhanced Peripheral Page Request Handling Support. */
1195 uint32_t u1AttrForwardSup : 1; /**< Bit 51 - AttrFWSup: Attribute Forward Support. */
1196 uint32_t u1HostDirtySup : 1; /**< Bit 52 - HDSup: Host Dirty Support. */
1197 uint32_t u1Rsvd2 : 1; /**< Bit 53 - Reserved. */
1198 uint32_t u1InvIoTlbTypeSup : 1; /**< Bit 54 - InvIotlbTypeSup: Invalidate IOTLB Type Support. */
1199 uint32_t u6Rsvd0 : 6; /**< Bit 60:55 - Reserved. */
1200 uint32_t u1GstUpdateDisSup : 1; /**< Bit 61 - GAUpdateDisSup: Disable hardware update on GPT Support. */
1201 uint32_t u1ForcePhysDstSup : 1; /**< Bit 62 - ForcePhyDestSup: Force Phys. Dst. Mode for Remapped Intr. */
1202 uint32_t u1Rsvd3 : 1; /**< Bit 63 - Reserved. */
1203 } n;
1204 /** The 64-bit unsigned integer view. */
1205 uint64_t u64;
1206} IOMMU_EXT_FEAT_T;
1207AssertCompileSize(IOMMU_EXT_FEAT_T, 8);
1208
1209/**
1210 * Peripheral Page Request Log Base Address Register (MMIO).
1211 * In accordance with the AMD spec.
1212 */
1213typedef union
1214{
1215 struct
1216 {
1217 RT_GCC_EXTENSION uint64_t u12Rsvd0 : 12; /**< Bit 11:0 - Reserved. */
1218 RT_GCC_EXTENSION uint64_t u40PprLogBase : 40; /**< Bits 51:12 - PPRLogBase: Peripheral Page Request Log Base Address. */
1219 RT_GCC_EXTENSION uint64_t u4Rsvd0 : 4; /**< Bits 55:52 - Reserved. */
1220 RT_GCC_EXTENSION uint64_t u4PprLogLen : 4; /**< Bits 59:56 - PPRLogLen: Peripheral Page Request Log Length. */
1221 RT_GCC_EXTENSION uint64_t u4Rsvd1 : 4; /**< Bits 63:60 - Reserved. */
1222 } n;
1223 /** The 64-bit unsigned integer view. */
1224 uint64_t u64;
1225} PPR_LOG_BAR_T;
1226AssertCompileSize(PPR_LOG_BAR_T, 8);
1227#define IOMMU_PPR_LOG_BAR_VALID_MASK UINT64_C(0x0f0ffffffffff000)
1228
1229/**
1230 * IOMMU Hardware Event Upper Register (MMIO).
1231 * In accordance with the AMD spec.
1232 */
1233typedef union
1234{
1235 struct
1236 {
1237 RT_GCC_EXTENSION uint64_t u60FirstOperand : 60; /**< Bits 59:0 - First event code dependent operand. */
1238 RT_GCC_EXTENSION uint64_t u4EvtCode : 4; /**< Bits 63:60 - Event Code. */
1239 } n;
1240 /** The 64-bit unsigned integer view. */
1241 uint64_t u64;
1242} IOMMU_HW_EVT_HI_T;
1243AssertCompileSize(IOMMU_HW_EVT_HI_T, 8);
1244
1245/**
1246 * IOMMU Hardware Event Lower Register (MMIO).
1247 * In accordance with the AMD spec.
1248 */
1249typedef uint64_t IOMMU_HW_EVT_LO_T;
1250
1251/**
1252 * IOMMU Hardware Event Status (MMIO).
1253 * In accordance with the AMD spec.
1254 */
1255typedef union
1256{
1257 struct
1258 {
1259 uint32_t u1Valid : 1; /**< Bit 0 - HEV: Hardware Event Valid. */
1260 uint32_t u1Overflow : 1; /**< Bit 1 - HEO: Hardware Event Overflow. */
1261 uint32_t u30Rsvd0 : 30; /**< Bits 31:2 - Reserved. */
1262 uint32_t u32Rsvd0; /**< Bits 63:32 - Reserved. */
1263 } n;
1264 /** The 64-bit unsigned integer view. */
1265 uint64_t u64;
1266} IOMMU_HW_EVT_STATUS_T;
1267AssertCompileSize(IOMMU_HW_EVT_STATUS_T, 8);
1268#define IOMMU_HW_EVT_STATUS_VALID_MASK UINT64_C(0x0000000000000003)
1269
1270/**
1271 * Guest Virtual-APIC Log Base Address Register (MMIO).
1272 * In accordance with the AMD spec.
1273 */
1274typedef union
1275{
1276 struct
1277 {
1278 RT_GCC_EXTENSION uint64_t u12Rsvd0 : 12; /**< Bit 11:0 - Reserved. */
1279 RT_GCC_EXTENSION uint64_t u40GALogBase : 40; /**< Bits 51:12 - GALogBase: Guest Virtual-APIC Log Base Address. */
1280 RT_GCC_EXTENSION uint64_t u4Rsvd0 : 4; /**< Bits 55:52 - Reserved. */
1281 RT_GCC_EXTENSION uint64_t u4GALogLen : 4; /**< Bits 59:56 - GALogLen: Guest Virtual-APIC Log Length. */
1282 RT_GCC_EXTENSION uint64_t u4Rsvd1 : 4; /**< Bits 63:60 - Reserved. */
1283 } n;
1284 /** The 64-bit unsigned integer view. */
1285 uint64_t u64;
1286} GALOG_BAR_T;
1287AssertCompileSize(GALOG_BAR_T, 8);
1288
1289/**
1290 * Guest Virtual-APIC Log Tail Address Register (MMIO).
1291 * In accordance with the AMD spec.
1292 */
1293typedef union
1294{
1295 struct
1296 {
1297 RT_GCC_EXTENSION uint64_t u3Rsvd0 : 3; /**< Bits 2:0 - Reserved. */
1298 RT_GCC_EXTENSION uint64_t u40GALogTailAddr : 48; /**< Bits 51:3 - GATAddr: Guest Virtual-APIC Tail Log Address. */
1299 RT_GCC_EXTENSION uint64_t u11Rsvd1 : 11; /**< Bits 63:52 - Reserved. */
1300 } n;
1301 /** The 64-bit unsigned integer view. */
1302 uint64_t u64;
1303} GALOG_TAIL_ADDR_T;
1304AssertCompileSize(GALOG_TAIL_ADDR_T, 8);
1305
1306/**
1307 * PPR Log B Base Address Register (MMIO).
1308 * In accordance with the AMD spec.
1309 * Currently identical to PPR_LOG_BAR_T.
1310 */
1311typedef PPR_LOG_BAR_T PPR_LOG_B_BAR_T;
1312
1313/**
1314 * Event Log B Base Address Register (MMIO).
1315 * In accordance with the AMD spec.
1316 * Currently identical to EVT_LOG_BAR_T.
1317 */
1318typedef EVT_LOG_BAR_T EVT_LOG_B_BAR_T;
1319
1320/**
1321 * Device Table Segment Register (MMIO).
1322 * In accordance with the AMD spec.
1323 */
1324typedef union
1325{
1326 struct
1327 {
1328 RT_GCC_EXTENSION uint64_t u8Size : 8; /**< Bits 7:0 - Size: Size of the Device Table segment. */
1329 RT_GCC_EXTENSION uint64_t u4Rsvd0 : 4; /**< Bits 11:8 - Reserved. */
1330 RT_GCC_EXTENSION uint64_t u40DevTabBase : 40; /**< Bits 51:12 - DevTabBase: Device Table Segment Base Address. */
1331 RT_GCC_EXTENSION uint64_t u12Rsvd0 : 12; /**< Bits 63:52 - Reserved. */
1332 } n;
1333 /** The 64-bit unsigned integer view. */
1334 uint64_t u64;
1335} DEV_TAB_SEG_BAR_T;
1336AssertCompileSize(DEV_TAB_SEG_BAR_T, 8);
1337
1338/**
1339 * Device-specific Feature Extension (DSFX) Register (MMIO).
1340 * In accordance with the AMD spec.
1341 */
1342typedef union
1343{
1344 struct
1345 {
1346 uint32_t u24DevSpecFeat : 24; /**< Bits 23:0 - DevSpecificFeatSupp: Implementation specific features. */
1347 uint32_t u4RevMinor : 4; /**< Bits 27:24 - RevMinor: Minor revision identifier. */
1348 uint32_t u4RevMajor : 4; /**< Bits 31:28 - RevMajor: Major revision identifier. */
1349 uint32_t u32Rsvd0; /**< Bits 63:32 - Reserved.*/
1350 } n;
1351 /** The 64-bit unsigned integer view. */
1352 uint64_t u64;
1353} DEV_SPECIFIC_FEAT_T;
1354AssertCompileSize(DEV_SPECIFIC_FEAT_T, 8);
1355
1356/**
1357 * Device-specific Control Extension (DSCX) Register (MMIO).
1358 * In accordance with the AMD spec.
1359 */
1360typedef union
1361{
1362 struct
1363 {
1364 uint32_t u24DevSpecCtrl : 24; /**< Bits 23:0 - DevSpecificFeatCntrl: Implementation specific control. */
1365 uint32_t u4RevMinor : 4; /**< Bits 27:24 - RevMinor: Minor revision identifier. */
1366 uint32_t u4RevMajor : 4; /**< Bits 31:28 - RevMajor: Major revision identifier. */
1367 uint32_t u32Rsvd0; /**< Bits 63:32 - Reserved.*/
1368 } n;
1369 /** The 64-bit unsigned integer view. */
1370 uint64_t u64;
1371} DEV_SPECIFIC_CTRL_T;
1372AssertCompileSize(DEV_SPECIFIC_CTRL_T, 8);
1373
1374/**
1375 * Device-specific Status Extension (DSSX) Register (MMIO).
1376 * In accordance with the AMD spec.
1377 */
1378typedef union
1379{
1380 struct
1381 {
1382 uint32_t u24DevSpecStatus : 24; /**< Bits 23:0 - DevSpecificFeatStatus: Implementation specific status. */
1383 uint32_t u4RevMinor : 4; /**< Bits 27:24 - RevMinor: Minor revision identifier. */
1384 uint32_t u4RevMajor : 4; /**< Bits 31:28 - RevMajor: Major revision identifier. */
1385 uint32_t u32Rsvd0; /**< Bits 63:32 - Reserved.*/
1386 } n;
1387 /** The 64-bit unsigned integer view. */
1388 uint64_t u64;
1389} DEV_SPECIFIC_STATUS_T;
1390AssertCompileSize(DEV_SPECIFIC_STATUS_T, 8);
1391
1392/**
1393 * MSI Information Register 0 and 1 (PCI) / MSI Vector Register 0 and 1 (MMIO).
1394 * In accordance with the AMD spec.
1395 */
1396typedef union
1397{
1398 struct
1399 {
1400 uint32_t u5MsiNumEvtLog : 5; /**< Bits 4:0 - MsiNum: Event Log MSI message number. */
1401 uint32_t u3GstVirtAddrSize: 3; /**< Bits 7:5 - GVAsize: Guest Virtual Address Size. */
1402 uint32_t u7PhysAddrSize : 7; /**< Bits 14:8 - PAsize: Physical Address Size. */
1403 uint32_t u7VirtAddrSize : 7; /**< Bits 21:15 - VAsize: Virtual Address Size. */
1404 uint32_t u1HtAtsResv: 1; /**< Bit 22 - HtAtsResv: HyperTransport ATS Response Address range Reserved. */
1405 uint32_t u4Rsvd0 : 4; /**< Bits 26:23 - Reserved. */
1406 uint32_t u5MsiNumPpr : 5; /**< Bits 31:27 - MsiNumPPR: Peripheral Page Request MSI message number. */
1407 uint32_t u5MsiNumGa : 5; /**< Bits 36:32 - MsiNumGa: MSI message number for guest virtual-APIC log. */
1408 uint32_t u27Rsvd0: 27; /**< Bits 63:37 - Reserved. */
1409 } n;
1410 /** The 32-bit unsigned integer view. */
1411 uint32_t au32[2];
1412 /** The 64-bit unsigned integer view. */
1413 uint64_t u64;
1414} MSI_MISC_INFO_T;
1415AssertCompileSize(MSI_MISC_INFO_T, 8);
1416/** MSI Vector Register 0 and 1 (MMIO). */
1417typedef MSI_MISC_INFO_T MSI_VECTOR_T;
1418
1419/**
1420 * MSI Capability Header Register (PCI + MMIO).
1421 * In accordance with the AMD spec.
1422 */
1423typedef union
1424{
1425 struct
1426 {
1427 uint32_t u8MsiCapId : 8; /**< Bits 7:0 - MsiCapId: Capability ID. */
1428 uint32_t u8MsiCapPtr : 8; /**< Bits 15:8 - MsiCapPtr: Pointer (PCI config offset) to the next capability. */
1429 uint32_t u1MsiEnable : 1; /**< Bit 16 - MsiEn: Message Signal Interrupt Enable. */
1430 uint32_t u3MsiMultiMessCap : 3; /**< Bits 19:17 - MsiMultMessCap: MSI Multi-Message Capability. */
1431 uint32_t u3MsiMultiMessEn : 3; /**< Bits 22:20 - MsiMultMessEn: MSI Multi-Message Enable. */
1432 uint32_t u1Msi64BitEn : 1; /**< Bit 23 - Msi64BitEn: MSI 64-bit Enable. */
1433 uint32_t u8Rsvd0 : 8; /**< Bits 31:24 - Reserved. */
1434 } n;
1435 /** The 32-bit unsigned integer view. */
1436 uint32_t u32;
1437} MSI_CAP_HDR_T;
1438AssertCompileSize(MSI_CAP_HDR_T, 4);
1439
1440/**
1441 * MSI Address Register (PCI + MMIO).
1442 * In accordance with the AMD spec.
1443 */
1444typedef union
1445{
1446 struct
1447 {
1448 RT_GCC_EXTENSION uint64_t u2Rsvd : 2; /**< Bits 1:0 - Reserved. */
1449 RT_GCC_EXTENSION uint64_t u62MsiAddr : 62; /**< Bits 31:2 - MsiAddr: MSI Address. */
1450 } n;
1451 /** The 32-bit unsigned integer view. */
1452 uint32_t au32[2];
1453 /** The 64-bit unsigned integer view. */
1454 uint64_t u64;
1455} MSI_ADDR_T;
1456AssertCompileSize(MSI_ADDR_T, 8);
1457#define IOMMU_MSI_ADDR_VALID_MASK UINT64_C(0xfffffffffffffffc)
1458
1459/**
1460 * MSI Data Register (PCI + MMIO).
1461 * In accordance with the AMD spec.
1462 */
1463typedef union
1464{
1465 struct
1466 {
1467 uint16_t u16MsiData; /**< Bits 15:0 - MsiData: MSI Data. */
1468 uint16_t u16Rsvd0; /**< Bits 31:16 - Reserved. */
1469 } n;
1470 /** The 32-bit unsigned integer view. */
1471 uint32_t u32;
1472} MSI_DATA_T;
1473AssertCompileSize(MSI_DATA_T, 4);
1474#define IOMMU_MSI_DATA_VALID_MASK UINT64_C(0x000000000000ffff)
1475
1476/**
1477 * MSI Mapping Capability Header Register (PCI + MMIO).
1478 * In accordance with the AMD spec.
1479 */
1480typedef union
1481{
1482 struct
1483 {
1484 uint32_t u8MsiMapCapId : 8; /**< Bits 7:0 - MsiMapCapId: MSI Map capability ID. */
1485 uint32_t u8Rsvd0 : 8; /**< Bits 15:8 - Reserved. */
1486 uint32_t u1MsiMapEn : 1; /**< Bit 16 - MsiMapEn: MSI Map enable. */
1487 uint32_t u1MsiMapFixed : 1; /**< Bit 17 - MsiMapFixd: MSI Map fixed. */
1488 uint32_t u9Rsvd0 : 9; /**< Bits 26:18 - Reserved. */
1489 uint32_t u5MapCapType : 5; /**< Bits 31:27 - MsiMapCapType: MSI Mapping capability type. */
1490 } n;
1491 /** The 32-bit unsigned integer view. */
1492 uint32_t u32;
1493} MSI_MAP_CAP_HDR_T;
1494AssertCompileSize(MSI_MAP_CAP_HDR_T, 4);
1495
1496/**
1497 * Performance Optimization Control Register (MMIO).
1498 * In accordance with the AMD spec.
1499 */
1500typedef union
1501{
1502 struct
1503 {
1504 uint32_t u13Rsvd0 : 13; /**< Bits 12:0 - Reserved. */
1505 uint32_t u1PerfOptEn : 1; /**< Bit 13 - PerfOptEn: Performance Optimization Enable. */
1506 uint32_t u17Rsvd0 : 18; /**< Bits 31:14 - Reserved. */
1507 } n;
1508 /** The 32-bit unsigned integer view. */
1509 uint32_t u32;
1510} IOMMU_PERF_OPT_CTRL_T;
1511AssertCompileSize(IOMMU_PERF_OPT_CTRL_T, 4);
1512
1513/**
1514 * XT (x2APIC) IOMMU General Interrupt Control Register (MMIO).
1515 * In accordance with the AMD spec.
1516 */
1517typedef union
1518{
1519 struct
1520 {
1521 uint32_t u2Rsvd0 : 2; /**< Bits 1:0 - Reserved.*/
1522 uint32_t u1X2ApicIntrDstMode : 1; /**< Bit 2 - Destination Mode for general interrupt.*/
1523 uint32_t u4Rsvd0 : 4; /**< Bits 7:3 - Reserved.*/
1524 uint32_t u24X2ApicIntrDstLo : 24; /**< Bits 31:8 - Destination for general interrupt (Lo).*/
1525 uint32_t u8X2ApicIntrVector : 8; /**< Bits 39:32 - Vector for general interrupt.*/
1526 uint32_t u1X2ApicIntrDeliveryMode : 1; /**< Bit 40 - Delivery Mode for general interrupt.*/
1527 uint32_t u15Rsvd0 : 15; /**< Bits 55:41 - Reserved.*/
1528 uint32_t u7X2ApicIntrDstHi : 7; /**< Bits 63:56 - Destination for general interrupt (Hi) .*/
1529 } n;
1530 /** The 64-bit unsigned integer view. */
1531 uint64_t u64;
1532} IOMMU_XT_GEN_INTR_CTRL_T;
1533AssertCompileSize(IOMMU_XT_GEN_INTR_CTRL_T, 8);
1534
1535/**
1536 * XT (x2APIC) IOMMU General Interrupt Control Register (MMIO).
1537 * In accordance with the AMD spec.
1538 */
1539typedef union
1540{
1541 struct
1542 {
1543 uint32_t u2Rsvd0 : 2; /**< Bits 1:0 - Reserved.*/
1544 uint32_t u1X2ApicIntrDstMode : 1; /**< Bit 2 - Destination Mode for the interrupt.*/
1545 uint32_t u4Rsvd0 : 4; /**< Bits 7:3 - Reserved.*/
1546 uint32_t u24X2ApicIntrDstLo : 24; /**< Bits 31:8 - Destination for the interrupt (Lo).*/
1547 uint32_t u8X2ApicIntrVector : 8; /**< Bits 39:32 - Vector for the interrupt.*/
1548 uint32_t u1X2ApicIntrDeliveryMode : 1; /**< Bit 40 - Delivery Mode for the interrupt.*/
1549 uint32_t u15Rsvd0 : 15; /**< Bits 55:41 - Reserved.*/
1550 uint32_t u7X2ApicIntrDstHi : 7; /**< Bits 63:56 - Destination for the interrupt (Hi) .*/
1551 } n;
1552 /** The 64-bit unsigned integer view. */
1553 uint64_t u64;
1554} IOMMU_XT_INTR_CTRL_T;
1555AssertCompileSize(IOMMU_XT_INTR_CTRL_T, 8);
1556
1557/**
1558 * XT (x2APIC) IOMMU PPR Interrupt Control Register (MMIO).
1559 * In accordance with the AMD spec.
1560 * Currently identical to IOMMU_XT_INTR_CTRL_T.
1561 */
1562typedef IOMMU_XT_INTR_CTRL_T IOMMU_XT_PPR_INTR_CTRL_T;
1563
1564/**
1565 * XT (x2APIC) IOMMU GA (Guest Address) Log Control Register (MMIO).
1566 * In accordance with the AMD spec.
1567 * Currently identical to IOMMU_XT_INTR_CTRL_T.
1568 */
1569typedef IOMMU_XT_INTR_CTRL_T IOMMU_XT_GALOG_INTR_CTRL_T;
1570
1571/**
1572 * Memory Access and Routing Control (MARC) Aperture Base Register (MMIO).
1573 * In accordance with the AMD spec.
1574 */
1575typedef union
1576{
1577 struct
1578 {
1579 RT_GCC_EXTENSION uint64_t u12Rsvd0 : 12; /**< Bits 11:0 - Reserved. */
1580 RT_GCC_EXTENSION uint64_t u40MarcBaseAddr : 40; /**< Bits 51:12 - MarcBaseAddr: MARC Aperture Base Address. */
1581 RT_GCC_EXTENSION uint64_t u12Rsvd1 : 12; /**< Bits 63:52 - Reserved. */
1582 } n;
1583 /** The 64-bit unsigned integer view. */
1584 uint64_t u64;
1585} MARC_APER_BAR_T;
1586AssertCompileSize(MARC_APER_BAR_T, 8);
1587
1588/**
1589 * Memory Access and Routing Control (MARC) Relocation Register (MMIO).
1590 * In accordance with the AMD spec.
1591 */
1592typedef union
1593{
1594 struct
1595 {
1596 RT_GCC_EXTENSION uint64_t u1RelocEn : 1; /**< Bit 0 - RelocEn: Relocation Enabled. */
1597 RT_GCC_EXTENSION uint64_t u1ReadOnly : 1; /**< Bit 1 - ReadOnly: Whether only read-only acceses allowed. */
1598 RT_GCC_EXTENSION uint64_t u10Rsvd0 : 10; /**< Bits 11:2 - Reserved. */
1599 RT_GCC_EXTENSION uint64_t u40MarcRelocAddr : 40; /**< Bits 51:12 - MarcRelocAddr: MARC Aperture Relocation Address. */
1600 RT_GCC_EXTENSION uint64_t u12Rsvd1 : 12; /**< Bits 63:52 - Reserved. */
1601 } n;
1602 /** The 64-bit unsigned integer view. */
1603 uint64_t u64;
1604} MARC_APER_RELOC_T;
1605AssertCompileSize(MARC_APER_RELOC_T, 8);
1606
1607/**
1608 * Memory Access and Routing Control (MARC) Length Register (MMIO).
1609 * In accordance with the AMD spec.
1610 */
1611typedef union
1612{
1613 struct
1614 {
1615 RT_GCC_EXTENSION uint64_t u12Rsvd0 : 12; /**< Bits 11:0 - Reserved. */
1616 RT_GCC_EXTENSION uint64_t u40MarcLength : 40; /**< Bits 51:12 - MarcLength: MARC Aperture Length. */
1617 RT_GCC_EXTENSION uint64_t u12Rsvd1 : 12; /**< Bits 63:52 - Reserved. */
1618 } n;
1619 /** The 64-bit unsigned integer view. */
1620 uint64_t u64;
1621} MARC_APER_LEN_T;
1622
1623/**
1624 * Memory Access and Routing Control (MARC) Aperture Register.
1625 * This combines other registers to match the MMIO layout for convenient access.
1626 */
1627typedef struct
1628{
1629 MARC_APER_BAR_T Base;
1630 MARC_APER_RELOC_T Reloc;
1631 MARC_APER_LEN_T Length;
1632} MARC_APER_T;
1633AssertCompileSize(MARC_APER_T, 24);
1634
1635/**
1636 * IOMMU Reserved Register (MMIO).
1637 * In accordance with the AMD spec.
1638 * This register is reserved for hardware use (although RW?).
1639 */
1640typedef uint64_t IOMMU_RSVD_REG_T;
1641
1642/**
1643 * Command Buffer Head Pointer Register (MMIO).
1644 * In accordance with the AMD spec.
1645 */
1646typedef union
1647{
1648 struct
1649 {
1650 uint32_t u4Rsvd0 : 4; /**< Bits 3:0 - Reserved. */
1651 uint32_t u15Ptr : 15; /**< Bits 18:4 - Buffer pointer. */
1652 uint32_t u13Rsvd0 : 13; /**< Bits 31:19 - Reserved. */
1653 uint32_t u32Rsvd0; /**< Bits 63:32 - Reserved. */
1654 } n;
1655 /** The 32-bit unsigned integer view. */
1656 uint32_t au32[2];
1657 /** The 64-bit unsigned integer view. */
1658 uint64_t u64;
1659} CMD_BUF_HEAD_PTR_T;
1660AssertCompileSize(CMD_BUF_HEAD_PTR_T, 8);
1661#define IOMMU_CMD_BUF_HEAD_PTR_VALID_MASK UINT64_C(0x000000000007fff0)
1662
1663/**
1664 * Command Buffer Tail Pointer Register (MMIO).
1665 * In accordance with the AMD spec.
1666 * Currently identical to CMD_BUF_HEAD_PTR_T.
1667 */
1668typedef CMD_BUF_HEAD_PTR_T CMD_BUF_TAIL_PTR_T;
1669#define IOMMU_CMD_BUF_TAIL_PTR_VALID_MASK UINT64_C(0x000000000007fff0)
1670
1671
1672/**
1673 * Event Log Head Pointer Register (MMIO).
1674 * In accordance with the AMD spec.
1675 * Currently identical to CMD_BUF_HEAD_PTR_T.
1676 */
1677typedef CMD_BUF_HEAD_PTR_T EVT_LOG_HEAD_PTR_T;
1678
1679/**
1680 * Event Log Tail Pointer Register (MMIO).
1681 * In accordance with the AMD spec.
1682 * Currently identical to CMD_BUF_HEAD_PTR_T.
1683 */
1684typedef CMD_BUF_HEAD_PTR_T EVT_LOG_TAIL_PTR_T;
1685
1686/**
1687 * IOMMU Status Register (MMIO).
1688 * In accordance with the AMD spec.
1689 */
1690typedef union
1691{
1692 struct
1693 {
1694 uint32_t u1EvtOverflow : 1; /**< Bit 0 - EventOverflow: Event log overflow. */
1695 uint32_t u1EvtLogIntr : 1; /**< Bit 1 - EventLogInt: Event log interrupt. */
1696 uint32_t u1CompWaitIntr : 1; /**< Bit 2 - ComWaitInt: Completion wait interrupt . */
1697 uint32_t u1EvtLogRunning : 1; /**< Bit 3 - EventLogRun: Event logging is running. */
1698 uint32_t u1CmdBufRunning : 1; /**< Bit 4 - CmdBufRun: Command buffer is running. */
1699 uint32_t u1PprOverflow : 1; /**< Bit 5 - PprOverflow: Peripheral Page Request Log (PPR) overflow. */
1700 uint32_t u1PprIntr : 1; /**< Bit 6 - PprInt: PPR interrupt. */
1701 uint32_t u1PprLogRunning : 1; /**< Bit 7 - PprLogRun: PPR logging is running. */
1702 uint32_t u1GstLogRunning : 1; /**< Bit 8 - GALogRun: Guest virtual-APIC logging is running. */
1703 uint32_t u1GstLogOverflow : 1; /**< Bit 9 - GALOverflow: Guest virtual-APIC log overflow. */
1704 uint32_t u1GstLogIntr : 1; /**< Bit 10 - GAInt: Guest virtual-APIC log interrupt. */
1705 uint32_t u1PprOverflowB : 1; /**< Bit 11 - PprOverflowB: PPR log B overflow. */
1706 uint32_t u1PprLogActive : 1; /**< Bit 12 - PprLogActive: PPR log A is active. */
1707 uint32_t u2Rsvd0 : 2; /**< Bits 14:13 - Reserved. */
1708 uint32_t u1EvtOverflowB : 1; /**< Bit 15 - EvtOverflowB: Event log B overflow. */
1709 uint32_t u1EvtLogActive : 1; /**< Bit 16 - EvtLogActive: Event log A active. */
1710 uint32_t u1PprOverflowEarlyB : 1; /**< Bit 17 - PprOverflowEarlyB: PPR log B overflow early warning. */
1711 uint32_t u1PprOverflowEarly : 1; /**< Bit 18 - PprOverflowEarly: PPR log overflow early warning. */
1712 uint32_t u13Rsvd0 : 13; /**< Bits 31:19 - Reserved. */
1713 uint32_t u32Rsvd0; /**< Bits 63:32 - Reserved . */
1714 } n;
1715 /** The 32-bit unsigned integer view. */
1716 uint32_t au32[2];
1717 /** The 64-bit unsigned integer view. */
1718 uint64_t u64;
1719} IOMMU_STATUS_T;
1720AssertCompileSize(IOMMU_STATUS_T, 8);
1721
1722/**
1723 * PPR Log Head Pointer Register (MMIO).
1724 * In accordance with the AMD spec.
1725 * Currently identical to CMD_BUF_HEAD_PTR_T.
1726 */
1727typedef CMD_BUF_HEAD_PTR_T PPR_LOG_HEAD_PTR_T;
1728
1729/**
1730 * PPR Log Tail Pointer Register (MMIO).
1731 * In accordance with the AMD spec.
1732 * Currently identical to CMD_BUF_HEAD_PTR_T.
1733 */
1734typedef CMD_BUF_HEAD_PTR_T PPR_LOG_TAIL_PTR_T;
1735
1736/**
1737 * Guest Virtual-APIC Log Head Pointer Register (MMIO).
1738 * In accordance with the AMD spec.
1739 */
1740typedef union
1741{
1742 struct
1743 {
1744 uint32_t u2Rsvd0 : 2; /**< Bits 2:0 - Reserved. */
1745 uint32_t u12GALogPtr : 12; /**< Bits 15:3 - Guest Virtual-APIC Log Head or Tail Pointer. */
1746 uint32_t u16Rsvd0 : 16; /**< Bits 31:16 - Reserved. */
1747 uint32_t u32Rsvd0; /**< Bits 63:32 - Reserved. */
1748 } n;
1749 /** The 32-bit unsigned integer view. */
1750 uint32_t au32[2];
1751 /** The 64-bit unsigned integer view. */
1752 uint64_t u64;
1753} GALOG_HEAD_PTR_T;
1754AssertCompileSize(GALOG_HEAD_PTR_T, 8);
1755
1756/**
1757 * Guest Virtual-APIC Log Tail Pointer Register (MMIO).
1758 * In accordance with the AMD spec.
1759 * Currently identical to GALOG_HEAD_PTR_T.
1760 */
1761typedef GALOG_HEAD_PTR_T GALOG_TAIL_PTR_T;
1762
1763/**
1764 * PPR Log B Head Pointer Register (MMIO).
1765 * In accordance with the AMD spec.
1766 * Currently identical to CMD_BUF_HEAD_PTR_T.
1767 */
1768typedef CMD_BUF_HEAD_PTR_T PPR_LOG_B_HEAD_PTR_T;
1769
1770/**
1771 * PPR Log B Tail Pointer Register (MMIO).
1772 * In accordance with the AMD spec.
1773 * Currently identical to CMD_BUF_HEAD_PTR_T.
1774 */
1775typedef CMD_BUF_HEAD_PTR_T PPR_LOG_B_TAIL_PTR_T;
1776
1777/**
1778 * Event Log B Head Pointer Register (MMIO).
1779 * In accordance with the AMD spec.
1780 * Currently identical to CMD_BUF_HEAD_PTR_T.
1781 */
1782typedef CMD_BUF_HEAD_PTR_T EVT_LOG_B_HEAD_PTR_T;
1783
1784/**
1785 * Event Log B Tail Pointer Register (MMIO).
1786 * In accordance with the AMD spec.
1787 * Currently identical to CMD_BUF_HEAD_PTR_T.
1788 */
1789typedef CMD_BUF_HEAD_PTR_T EVT_LOG_B_TAIL_PTR_T;
1790
1791/**
1792 * PPR Log Auto Response Register (MMIO).
1793 * In accordance with the AMD spec.
1794 */
1795typedef union
1796{
1797 struct
1798 {
1799 uint32_t u4AutoRespCode : 4; /**< Bits 3:0 - PprAutoRespCode: PPR log Auto Response Code. */
1800 uint32_t u1AutoRespMaskGen : 1; /**< Bit 4 - PprAutoRespMaskGn: PPR log Auto Response Mask Gen. */
1801 uint32_t u27Rsvd0 : 27; /**< Bits 31:5 - Reserved. */
1802 uint32_t u32Rsvd0; /**< Bits 63:32 - Reserved.*/
1803 } n;
1804 /** The 32-bit unsigned integer view. */
1805 uint32_t au32[2];
1806 /** The 64-bit unsigned integer view. */
1807 uint64_t u64;
1808} PPR_LOG_AUTO_RESP_T;
1809AssertCompileSize(PPR_LOG_AUTO_RESP_T, 8);
1810
1811/**
1812 * PPR Log Overflow Early Indicator Register (MMIO).
1813 * In accordance with the AMD spec.
1814 */
1815typedef union
1816{
1817 struct
1818 {
1819 uint32_t u15Threshold : 15; /**< Bits 14:0 - PprOvrflwEarlyThreshold: Overflow early indicator threshold. */
1820 uint32_t u15Rsvd0 : 15; /**< Bits 29:15 - Reserved. */
1821 uint32_t u1IntrEn : 1; /**< Bit 30 - PprOvrflwEarlyIntEn: Overflow early indicator interrupt enable. */
1822 uint32_t u1Enable : 1; /**< Bit 31 - PprOvrflwEarlyEn: Overflow early indicator enable. */
1823 uint32_t u32Rsvd0; /**< Bits 63:32 - Reserved. */
1824 } n;
1825 /** The 32-bit unsigned integer view. */
1826 uint32_t au32[2];
1827 /** The 64-bit unsigned integer view. */
1828 uint64_t u64;
1829} PPR_LOG_OVERFLOW_EARLY_T;
1830AssertCompileSize(PPR_LOG_OVERFLOW_EARLY_T, 8);
1831
1832/**
1833 * PPR Log B Overflow Early Indicator Register (MMIO).
1834 * In accordance with the AMD spec.
1835 * Currently identical to PPR_LOG_OVERFLOW_EARLY_T.
1836 */
1837typedef PPR_LOG_OVERFLOW_EARLY_T PPR_LOG_B_OVERFLOW_EARLY_T;
1838
1839
1840/**
1841 * The shared IOMMU device state.
1842 */
1843typedef struct IOMMU
1844{
1845 /** The event semaphore the command thread waits on. */
1846 SUPSEMEVENT hEvtCmdThread;
1847 /** The MMIO handle. */
1848 IOMMMIOHANDLE hMmio;
1849 /** Whether this IOMMU is at the top of the PCI tree hierarchy or not. */
1850 bool fRootComplex;
1851 /** Alignment padding. */
1852 bool afPadding[7];
1853
1854 /** @name MMIO: Control and status registers.
1855 * @{ */
1856 DEV_TAB_BAR_T DevTabBaseAddr; /**< Device table base address register. */
1857 CMD_BUF_BAR_T CmdBufBaseAddr; /**< Command buffer base address register. */
1858 EVT_LOG_BAR_T EvtLogBaseAddr; /**< Event log base address register. */
1859 IOMMU_CTRL_T Ctrl; /**< IOMMU control register. */
1860 IOMMU_EXCL_RANGE_BAR_T ExclRangeBaseAddr; /**< IOMMU exclusion range base register. */
1861 IOMMU_EXCL_RANGE_LIMIT_T ExclRangeLimit; /**< IOMMU exclusion range limit. */
1862 IOMMU_EXT_FEAT_T ExtFeat; /**< IOMMU extended feature register. */
1863 /** @} */
1864
1865 /** @name MMIO: PPR Log registers.
1866 * @{ */
1867 PPR_LOG_BAR_T PprLogBaseAddr; /**< PPR Log base address register. */
1868 IOMMU_HW_EVT_HI_T HwEvtHi; /**< IOMMU hardware event register (Hi). */
1869 IOMMU_HW_EVT_LO_T HwEvtLo; /**< IOMMU hardware event register (Lo). */
1870 IOMMU_HW_EVT_STATUS_T HwEvtStatus; /**< IOMMU hardware event status. */
1871 /** @} */
1872
1873 /** @todo IOMMU: SMI filter. */
1874
1875 /** @name MMIO: Guest Virtual-APIC Log registers.
1876 * @{ */
1877 GALOG_BAR_T GALogBaseAddr; /**< Guest Virtual-APIC Log base address register. */
1878 GALOG_TAIL_ADDR_T GALogTailAddr; /**< Guest Virtual-APIC Log Tail address register. */
1879 /** @} */
1880
1881 /** @name MMIO: Alternate PPR and Event Log registers.
1882 * @{ */
1883 PPR_LOG_B_BAR_T PprLogBBaseAddr; /**< PPR Log B base address register. */
1884 EVT_LOG_B_BAR_T EvtLogBBaseAddr; /**< Event Log B base address register. */
1885 /** @} */
1886
1887 /** @name MMIO: Device table segment registers.
1888 * @{ */
1889 DEV_TAB_SEG_BAR_T DevTabSeg[7]; /**< Device Table Segment base address register. */
1890 /** @} */
1891
1892 /** @name MMIO: Device-specific feature registers.
1893 * @{ */
1894 DEV_SPECIFIC_FEAT_T DevSpecificFeat; /**< Device-specific feature extension register (DSFX). */
1895 DEV_SPECIFIC_CTRL_T DevSpecificCtrl; /**< Device-specific control extension register (DSCX). */
1896 DEV_SPECIFIC_STATUS_T DevSpecificStatus; /**< Device-specific status extension register (DSSX). */
1897 /** @} */
1898
1899 /** @name MMIO: MSI Capability Block registers.
1900 * @{ */
1901 MSI_MISC_INFO_T MsiMiscInfo; /**< MSI Misc. info registers / MSI Vector registers. */
1902 MSI_CAP_HDR_T MsiCapHdr; /**< MSI Capability header register. */
1903 MSI_ADDR_T MsiAddr; /**< MSI Address register.*/
1904 MSI_DATA_T MsiData; /**< MSI Data register. */
1905 MSI_MAP_CAP_HDR_T MsiMapCapHdr; /**< MSI Mapping capability header register. */
1906 /** @} */
1907
1908 /** @name MMIO: Performance Optimization Control registers.
1909 * @{ */
1910 IOMMU_PERF_OPT_CTRL_T PerfOptCtrl; /**< IOMMU Performance optimization control register. */
1911 /** @} */
1912
1913 /** @name MMIO: x2APIC Control registers.
1914 * @{ */
1915 IOMMU_XT_GEN_INTR_CTRL_T XtGenIntrCtrl; /**< IOMMU X2APIC General interrupt control register. */
1916 IOMMU_XT_PPR_INTR_CTRL_T XtPprIntrCtrl; /**< IOMMU X2APIC PPR interrupt control register. */
1917 IOMMU_XT_GALOG_INTR_CTRL_T XtGALogIntrCtrl; /**< IOMMU X2APIC Guest Log interrupt control register. */
1918 /** @} */
1919
1920 /** @name MMIO: MARC registers.
1921 * @{ */
1922 MARC_APER_T aMarcApers[4]; /**< MARC Aperture Registers. */
1923 /** @} */
1924
1925 /** @name MMIO: Reserved register.
1926 * @{ */
1927 IOMMU_RSVD_REG_T RsvdReg; /**< IOMMU Reserved Register. */
1928 /** @} */
1929
1930 /** @name MMIO: Command and Event Log pointer registers.
1931 * @{ */
1932 CMD_BUF_HEAD_PTR_T CmdBufHeadPtr; /**< Command buffer head pointer register. */
1933 CMD_BUF_TAIL_PTR_T CmdBufTailPtr; /**< Command buffer tail pointer register. */
1934 EVT_LOG_HEAD_PTR_T EvtLogHeadPtr; /**< Event log head pointer register. */
1935 EVT_LOG_TAIL_PTR_T EvtLogTailPtr; /**< Event log tail pointer register. */
1936 /** @} */
1937
1938 /** @name MMIO: Command and Event Status register.
1939 * @{ */
1940 IOMMU_STATUS_T Status; /**< IOMMU status register. */
1941 /** @} */
1942
1943 /** @name MMIO: PPR Log Head and Tail pointer registers.
1944 * @{ */
1945 PPR_LOG_HEAD_PTR_T PprLogHeadPtr; /**< IOMMU PPR log head pointer register. */
1946 PPR_LOG_TAIL_PTR_T PprLogTailPtr; /**< IOMMU PPR log tail pointer register. */
1947 /** @} */
1948
1949 /** @name MMIO: Guest Virtual-APIC Log Head and Tail pointer registers.
1950 * @{ */
1951 GALOG_HEAD_PTR_T GALogHeadPtr; /**< Guest Virtual-APIC log head pointer register. */
1952 GALOG_TAIL_PTR_T GALogTailPtr; /**< Guest Virtual-APIC log tail pointer register. */
1953 /** @} */
1954
1955 /** @name MMIO: PPR Log B Head and Tail pointer registers.
1956 * @{ */
1957 PPR_LOG_B_HEAD_PTR_T PprLogBHeadPtr; /**< PPR log B head pointer register. */
1958 PPR_LOG_B_TAIL_PTR_T PprLogBTailPtr; /**< PPR log B tail pointer register. */
1959 /** @} */
1960
1961 /** @name MMIO: Event Log B Head and Tail pointer registers.
1962 * @{ */
1963 EVT_LOG_B_HEAD_PTR_T EvtLogBHeadPtr; /**< Event log B head pointer register. */
1964 EVT_LOG_B_TAIL_PTR_T EvtLogBTailPtr; /**< Event log B tail pointer register. */
1965 /** @} */
1966
1967 /** @name MMIO: PPR Log Overflow protection registers.
1968 * @{ */
1969 PPR_LOG_AUTO_RESP_T PprLogAutoResp; /**< PPR Log Auto Response register. */
1970 PPR_LOG_OVERFLOW_EARLY_T PprLogOverflowEarly; /**< PPR Log Overflow Early Indicator register. */
1971 PPR_LOG_B_OVERFLOW_EARLY_T PprLogBOverflowEarly; /**< PPR Log B Overflow Early Indicator register. */
1972 /** @} */
1973
1974 /** @todo IOMMU: IOMMU Event counter registers. */
1975
1976 /** @todo IOMMU: Stat counters. */
1977} IOMMU;
1978/** Pointer to the IOMMU device state. */
1979typedef struct IOMMU *PIOMMU;
1980/** Pointer to the const IOMMU device state. */
1981typedef const struct IOMMU *PCIOMMU;
1982
1983/**
1984 * The ring-3 IOMMU device state.
1985 */
1986typedef struct IOMMUR3
1987{
1988 /** Device instance. */
1989 PPDMDEVINSR3 pDevInsR3;
1990 /** The IOMMU helpers. */
1991 PCPDMIOMMUHLPR3 pIommuHlp;
1992 /** The command thread handle. */
1993 R3PTRTYPE(PPDMTHREAD) pCmdThread;
1994} IOMMUR3;
1995/** Pointer to the ring-3 IOMMU device state. */
1996typedef IOMMUR3 *PIOMMUR3;
1997
1998/**
1999 * The ring-0 IOMMU device state.
2000 */
2001typedef struct IOMMUR0
2002{
2003 /** Device instance. */
2004 PPDMDEVINSR0 pDevInsR0;
2005 /** The IOMMU helpers. */
2006 PCPDMIOMMUHLPR0 pIommuHlp;
2007} IOMMUR0;
2008/** Pointer to the ring-0 IOMMU device state. */
2009typedef IOMMUR0 *PIOMMUR0;
2010
2011/**
2012 * The raw-mode IOMMU device state.
2013 */
2014typedef struct IOMMURC
2015{
2016 /** Device instance. */
2017 PPDMDEVINSR0 pDevInsRC;
2018 /** The IOMMU helpers. */
2019 PCPDMIOMMUHLPRC pIommuHlp;
2020} IOMMURC;
2021/** Pointer to the raw-mode IOMMU device state. */
2022typedef IOMMURC *PIOMMURC;
2023
2024/** The IOMMU device state for the current context. */
2025typedef CTX_SUFF(IOMMU) IOMMUCC;
2026/** Pointer to the IOMMU device state for the current context. */
2027typedef CTX_SUFF(PIOMMU) PIOMMUCC;
2028
2029/**
2030 * IOMMU register access routines.
2031 */
2032typedef struct
2033{
2034 const char *pszName;
2035 VBOXSTRICTRC (*pfnRead )(PPDMDEVINS pDevIns, PIOMMU pThis, uint32_t iReg, uint64_t *pu64Value);
2036 VBOXSTRICTRC (*pfnWrite)(PPDMDEVINS pDevIns, PIOMMU pThis, uint32_t iReg, uint64_t u64Value);
2037 bool f64BitReg;
2038} IOMMUREGACC;
2039
2040
2041#ifndef VBOX_DEVICE_STRUCT_TESTCASE
2042
2043/**
2044 * Returns the number of entries and buffer size for a power-of-2 encoded length.
2045 *
2046 * @param uEncodedLen The length to decode.
2047 * @param pcEntries Where to store the number of entries. Optional, can be
2048 * NULL.
2049 * @param pcbBuffer Where to store the size of the buffer. Optional, can be
2050 * NULL.
2051 *
2052 * @remarks Both @a pcEntries and @a pcbBuffer cannot both be NULL.
2053 */
2054static void iommuAmdDecodeBufferLength(uint8_t uEncodedLen, uint32_t *pcEntries, uint32_t *pcbBuffer)
2055{
2056 uint32_t cEntries;
2057 uint32_t cbBuffer;
2058 if (uEncodedLen > 7)
2059 {
2060 cEntries = 2 << (uEncodedLen - 1);
2061 cbBuffer = *pcEntries << 4;
2062 }
2063 else
2064 cEntries = cbBuffer = 0;
2065
2066 Assert(pcEntries || pcbBuffer);
2067 if (pcEntries)
2068 *pcEntries = cEntries;
2069 if (pcbBuffer)
2070 *pcbBuffer = cbBuffer;
2071}
2072
2073
2074/**
2075 * Logs if the buffer length is invalid.
2076 *
2077 * @param uEncodedLen The length to decode.
2078 * @param pszFunc Name of the calling function for logging purposes.
2079 */
2080DECLINLINE(void) iommuAmdCheckBufferLength(uint8_t uEncodedLen, const char *pszFunc)
2081{
2082#ifdef VBOX_STRICT
2083 uint32_t cEntries;
2084 iommuAmdDecodeBufferLength(uEncodedLen, &cEntries, NULL /* pcbBuffer */);
2085 if (!cEntries)
2086 Log((IOMMU_LOG_PFX ": %s: Invalid length %#x\n", pszFunc, uEncodedLen));
2087#else
2088 RT_NOREF(uEncodedLen, pszFunc);
2089#endif
2090}
2091
2092
2093/**
2094 * Writes to a read-only register.
2095 */
2096static VBOXSTRICTRC iommuAmdIgnore_w(PPDMDEVINS pDevIns, PIOMMU pThis, uint32_t iReg, uint64_t u64Value)
2097{
2098 RT_NOREF(pDevIns, pThis, iReg, u64Value);
2099 Log((IOMMU_LOG_PFX ": iommuAmdIgnore_w: Write to read-only register (%#x) with value %#RX64 ignored\n", iReg, u64Value));
2100 return VINF_SUCCESS;
2101}
2102
2103
2104/**
2105 * Writes the Device Table Base Address Register.
2106 */
2107static VBOXSTRICTRC iommuAmdDevTabBar_w(PPDMDEVINS pDevIns, PIOMMU pThis, uint32_t iReg, uint64_t u64Value)
2108{
2109 RT_NOREF(pDevIns, iReg);
2110 pThis->DevTabBaseAddr.u64 = u64Value & IOMMU_DEV_TAB_BAR_VALID_MASK;
2111 return VINF_SUCCESS;
2112}
2113
2114
2115/**
2116 * Writes the Command Buffer Base Address Register.
2117 */
2118static VBOXSTRICTRC iommuAmdCmdBufBar_w(PPDMDEVINS pDevIns, PIOMMU pThis, uint32_t iReg, uint64_t u64Value)
2119{
2120 RT_NOREF(pDevIns, iReg);
2121 pThis->CmdBufBaseAddr.u64 = u64Value & IOMMU_CMD_BUF_BAR_VALID_MASK;
2122 iommuAmdCheckBufferLength(pThis->CmdBufBaseAddr.n.u4CmdLen, __PRETTY_FUNCTION__);
2123 return VINF_SUCCESS;
2124}
2125
2126
2127/**
2128 * Writes the Event Log Base Address Register.
2129 */
2130static VBOXSTRICTRC iommuAmdEvtLogBar_w(PPDMDEVINS pDevIns, PIOMMU pThis, uint32_t iReg, uint64_t u64Value)
2131{
2132 RT_NOREF(pDevIns, iReg);
2133 pThis->EvtLogBaseAddr.u64 = u64Value & IOMMU_EVT_LOG_BAR_VALID_MASK;
2134 iommuAmdCheckBufferLength(pThis->EvtLogBaseAddr.n.u4EvtLen, __PRETTY_FUNCTION__);
2135 return VINF_SUCCESS;
2136}
2137
2138
2139/**
2140 * Writes to the Excluse Range Base Address Register.
2141 */
2142static VBOXSTRICTRC iommuAmdExclRangeBar_w(PPDMDEVINS pDevIns, PIOMMU pThis, uint32_t iReg, uint64_t u64Value)
2143{
2144 RT_NOREF(pDevIns, iReg);
2145 pThis->ExclRangeBaseAddr.u64 = u64Value & IOMMU_EXCL_RANGE_BAR_VALID_MASK;
2146 return VINF_SUCCESS;
2147}
2148
2149
2150/**
2151 * Writes to the Excluse Range Limit Register.
2152 */
2153static VBOXSTRICTRC iommuAmdExclRangeLimit_w(PPDMDEVINS pDevIns, PIOMMU pThis, uint32_t iReg, uint64_t u64Value)
2154{
2155 RT_NOREF(pDevIns, iReg);
2156 pThis->ExclRangeLimit.u64 = u64Value & IOMMU_EXCL_RANGE_LIMIT_VALID_MASK;
2157 return VINF_SUCCESS;
2158}
2159
2160
2161/**
2162 * Writes the PPR Log Base Address Register.
2163 */
2164static VBOXSTRICTRC iommuAmdPprLogBar_w(PPDMDEVINS pDevIns, PIOMMU pThis, uint32_t iReg, uint64_t u64Value)
2165{
2166 RT_NOREF(pDevIns, iReg);
2167 pThis->PprLogBaseAddr.u64 = u64Value & IOMMU_PPR_LOG_BAR_VALID_MASK;
2168 iommuAmdCheckBufferLength(pThis->PprLogBaseAddr.n.u4PprLogLen, __PRETTY_FUNCTION__);
2169 return VINF_SUCCESS;
2170}
2171
2172
2173/**
2174 * Writes the Hardware Event Register (Hi).
2175 */
2176static VBOXSTRICTRC iommuAmdHwEvtHi_w(PPDMDEVINS pDevIns, PIOMMU pThis, uint32_t iReg, uint64_t u64Value)
2177{
2178 /** @todo IOMMU: Why the heck is this marked read/write by the AMD IOMMU spec? */
2179 RT_NOREF(pDevIns, iReg);
2180 Log((IOMMU_LOG_PFX ": Writing %#RX64 to hardware event (Hi) register!\n", u64Value));
2181 pThis->HwEvtHi.u64 = u64Value;
2182 return VINF_SUCCESS;
2183}
2184
2185
2186/**
2187 * Writes the Hardware Event Register (Lo).
2188 */
2189static VBOXSTRICTRC iommuAmdHwEvtLo_w(PPDMDEVINS pDevIns, PIOMMU pThis, uint32_t iReg, uint64_t u64Value)
2190{
2191 /** @todo IOMMU: Why the heck is this marked read/write by the AMD IOMMU spec? */
2192 RT_NOREF(pDevIns, iReg);
2193 Log((IOMMU_LOG_PFX ": Writing %#RX64 to hardware event (Lo) register!\n", u64Value));
2194 pThis->HwEvtLo = u64Value;
2195 return VINF_SUCCESS;
2196}
2197
2198
2199/**
2200 * Writes the Hardware Event Status Register.
2201 */
2202static VBOXSTRICTRC iommuAmdHwEvtStatus_w(PPDMDEVINS pDevIns, PIOMMU pThis, uint32_t iReg, uint64_t u64Value)
2203{
2204 RT_NOREF(pDevIns, iReg);
2205
2206 /* Ignore all unrecognized bits. */
2207 u64Value &= IOMMU_HW_EVT_STATUS_VALID_MASK;
2208
2209 /*
2210 * The two bits (HEO and HEV) are RW1C (Read/Write 1-to-Clear; writing 0 has no effect).
2211 * If the current status bits or the bits being written are both 0, we've nothing to do.
2212 * The Overflow bit (bit 1) is only valid when the Valid bit (bit 0) is 1.
2213 */
2214 uint64_t HwStatus = pThis->HwEvtStatus.u64;
2215 if (!(HwStatus & RT_BIT(0)))
2216 return VINF_SUCCESS;
2217 if (u64Value & HwStatus & RT_BIT_64(0))
2218 HwStatus &= ~RT_BIT_64(0);
2219 if (u64Value & HwStatus & RT_BIT_64(1))
2220 HwStatus &= ~RT_BIT_64(1);
2221 pThis->HwEvtStatus.u64 = HwStatus;
2222 return VINF_SUCCESS;
2223}
2224
2225
2226/**
2227 * Writes the MSI Address (Lo) Register (32-bit).
2228 */
2229static VBOXSTRICTRC iommuAmdMsiAddrLo_w(PPDMDEVINS pDevIns, PIOMMU pThis, uint32_t iReg, uint64_t u64Value)
2230{
2231 RT_NOREF(pDevIns, iReg);
2232 Assert(!RT_HI_U32(u64Value));
2233 pThis->MsiAddr.au32[0] = u64Value & IOMMU_MSI_ADDR_VALID_MASK;
2234 return VINF_SUCCESS;
2235}
2236
2237
2238/**
2239 * Writes the MSI Address (Hi) Register (32-bit).
2240 */
2241static VBOXSTRICTRC iommuAmdMsiAddrHi_w(PPDMDEVINS pDevIns, PIOMMU pThis, uint32_t iReg, uint64_t u64Value)
2242{
2243 RT_NOREF(pDevIns, iReg);
2244 Assert(!RT_HI_U32(u64Value));
2245 pThis->MsiAddr.au32[1] = u64Value;
2246 return VINF_SUCCESS;
2247}
2248
2249
2250/**
2251 * Writes the MSI Data Register (32-bit).
2252 */
2253static VBOXSTRICTRC iommuAmdMsiData_w(PPDMDEVINS pDevIns, PIOMMU pThis, uint32_t iReg, uint64_t u64Value)
2254{
2255 RT_NOREF(pDevIns, iReg);
2256 pThis->MsiData.u32 = u64Value & IOMMU_MSI_DATA_VALID_MASK;
2257 return VINF_SUCCESS;
2258}
2259
2260
2261/**
2262 * Writes the Command Buffer Head Pointer Register (32-bit).
2263 */
2264static VBOXSTRICTRC iommuAmdCmdBufHeadPtr_w(PPDMDEVINS pDevIns, PIOMMU pThis, uint32_t iReg, uint64_t u64Value)
2265{
2266 RT_NOREF(pDevIns, iReg);
2267
2268 /*
2269 * IOMMU behavior is undefined when software writes this register when the command buffer is running.
2270 * In our emulation, we ignore the write entirely.
2271 * See AMD IOMMU spec. 3.3.13 "Command and Event Log Pointer Registers".
2272 */
2273 IOMMU_STATUS_T const Status = pThis->Status;
2274 if (Status.n.u1CmdBufRunning)
2275 {
2276 Log((IOMMU_LOG_PFX ": Setting CmdBufHeadPtr (%#RX64) when command buffer is running -> Ignored\n", u64Value));
2277 return VINF_SUCCESS;
2278 }
2279
2280 /*
2281 * IOMMU behavior is undefined when software writes a value value outside the buffer length.
2282 * In our emtulation, we ignore the write entirely.
2283 */
2284 uint32_t const offBuf = u64Value & IOMMU_CMD_BUF_HEAD_PTR_VALID_MASK;
2285 CMD_BUF_BAR_T const CmdBufBar = pThis->CmdBufBaseAddr;
2286 uint32_t cbBuf;
2287 iommuAmdDecodeBufferLength(CmdBufBar.n.u4CmdLen, NULL, &cbBuf);
2288 if (offBuf >= cbBuf)
2289 {
2290 Log((IOMMU_LOG_PFX ": Setting CmdBufHeadPtr (%#RX32) to a value that exceeds buffer length -> Ignored\n", offBuf, cbBuf));
2291 return VINF_SUCCESS;
2292 }
2293
2294 pThis->CmdBufHeadPtr.u64 = offBuf;
2295 LogFlow((IOMMU_LOG_PFX ": Set CmdBufHeadPtr to %#RX32\n", offBuf));
2296 return VINF_SUCCESS;
2297}
2298
2299
2300/**
2301 * Writes the Command Buffer Tail Pointer Register (32-bit).
2302 */
2303static VBOXSTRICTRC iommuAmdCmdBufTailPtr_w(PPDMDEVINS pDevIns, PIOMMU pThis, uint32_t iReg, uint64_t u64Value)
2304{
2305 RT_NOREF(pDevIns, iReg);
2306
2307 /*
2308 * IOMMU behavior is undefined when software advances this register equal or beyond its head pointer.
2309 * In our emulation, we ignore the write entirely.
2310 * See AMD IOMMU spec. 3.3.13 "Command and Event Log Pointer Registers".
2311 */
2312 uint32_t const offBufTail = u64Value & IOMMU_CMD_BUF_HEAD_PTR_VALID_MASK;
2313 NOREF(offBufTail);
2314 NOREF(pThis);
2315 return VINF_SUCCESS;
2316}
2317
2318
2319/**
2320 * Writes the Event Log Head Pointer Register (32-bit).
2321 */
2322static VBOXSTRICTRC iommuAmdEvtLogHeadPtr_w(PPDMDEVINS pDevIns, PIOMMU pThis, uint32_t iReg, uint64_t u64Value)
2323{
2324 RT_NOREF(pDevIns, iReg);
2325 NOREF(pThis);
2326 NOREF(u64Value);
2327 return VINF_SUCCESS;
2328}
2329
2330
2331/**
2332 * Writes the Event Log Tail Pointer Register (32-bit).
2333 */
2334static VBOXSTRICTRC iommuAmdEvtLogTailPtr_w(PPDMDEVINS pDevIns, PIOMMU pThis, uint32_t iReg, uint64_t u64Value)
2335{
2336 RT_NOREF(pDevIns, iReg);
2337 NOREF(pThis);
2338 NOREF(u64Value);
2339 return VINF_SUCCESS;
2340}
2341
2342
2343/**
2344 * The IOMMU command thread.
2345 *
2346 * @returns VBox status code.
2347 * @param pDevIns The device instance.
2348 * @param pThread The command thread.
2349 */
2350static DECLCALLBACK(int) iommuAmdR3CmdThread(PPDMDEVINS pDevIns, PPDMTHREAD pThread)
2351{
2352 RT_NOREF(pDevIns, pThread);
2353}
2354
2355
2356/**
2357 * Unblocks the command thread so it can respond to a state change.
2358 *
2359 * @returns VBox status code.
2360 * @param pDevIns The device instance.
2361 * @param pThread The command thread.
2362 */
2363static DECLCALLBACK(int) iommuAmdR3CmdThreadWakeUp(PPDMDEVINS pDevIns, PPDMTHREAD pThread)
2364{
2365 NOREF(pThread);
2366 PIOMMU pThis = PDMDEVINS_2_DATA(pDevIns, PIOMMU);
2367 return PDMDevHlpSUPSemEventSignal(pDevIns, pThis->hEvtCmdThread);
2368}
2369
2370
2371#if 0
2372/**
2373 * Table 0: Registers-access table.
2374 */
2375static const IOMMUREGACC g_aTable0Regs[] =
2376{
2377
2378};
2379
2380/**
2381 * Table 1: Registers-access table.
2382 */
2383static const IOMMUREGACC g_aTable1Regs[] =
2384{
2385};
2386#endif
2387
2388/**
2389 * Writes an IOMMU register (32-bit and 64-bit).
2390 *
2391 * @returns Strict VBox status code.
2392 * @param pDevIns The device instance.
2393 * @param off MMIO byte offset to the register.
2394 * @param cb The size of the write access.
2395 * @param uValue The value being written.
2396 */
2397static VBOXSTRICTRC iommuAmdWriteRegister(PPDMDEVINS pDevIns, uint32_t off, uint8_t cb, uint64_t uValue)
2398{
2399 Assert(off < IOMMU_MMIO_REGION_SIZE);
2400 Assert(cb == 4 || cb == 8);
2401 Assert(!(off & (cb - 1)));
2402
2403 PIOMMU pThis = PDMDEVINS_2_DATA(pDevIns, PIOMMU);
2404 Assert(pThis);
2405
2406 switch (off)
2407 {
2408 case IOMMU_MMIO_OFF_DEV_TAB_BAR: return iommuAmdDevTabBar_w(pDevIns, pThis, off, uValue);
2409 case IOMMU_MMIO_OFF_CMD_BUF_BAR: return iommuAmdCmdBufBar_w(pDevIns, pThis, off, uValue);
2410 case IOMMU_MMIO_OFF_EVT_LOG_BAR: return iommuAmdEvtLogBar_w(pDevIns, pThis, off, uValue);
2411 case IOMMU_MMIO_OFF_CTRL: /** @todo IOMMU: Control register. */
2412 case IOMMU_MMIO_OFF_EXCL_BAR: return iommuAmdExclRangeBar_w(pDevIns, pThis, off, uValue);
2413 case IOMMU_MMIO_OFF_EXCL_RANGE_LIMIT: return iommuAmdExclRangeLimit_w(pDevIns, pThis, off, uValue);
2414 case IOMMU_MMIO_OFF_EXT_FEAT: return iommuAmdIgnore_w(pDevIns, pThis, off, uValue);
2415
2416 case IOMMU_MMIO_OFF_PPR_LOG_BAR: return iommuAmdPprLogBar_w(pDevIns, pThis, off, uValue);
2417 case IOMMU_MMIO_OFF_HW_EVT_HI: return iommuAmdHwEvtHi_w(pDevIns, pThis, off, uValue);
2418 case IOMMU_MMIO_OFF_HW_EVT_LO: return iommuAmdHwEvtLo_w(pDevIns, pThis, off, uValue);
2419 case IOMMU_MMIO_OFF_HW_EVT_STATUS: return iommuAmdHwEvtStatus_w(pDevIns, pThis, off, uValue);
2420
2421 case IOMMU_MMIO_OFF_GALOG_BAR:
2422 case IOMMU_MMIO_OFF_GALOG_TAIL_ADDR: return iommuAmdIgnore_w(pDevIns, pThis, off, uValue);
2423
2424 case IOMMU_MMIO_OFF_PPR_LOG_B_BAR:
2425 case IOMMU_MMIO_OFF_PPR_EVT_B_BAR: return iommuAmdIgnore_w(pDevIns, pThis, off, uValue);
2426
2427 case IOMMU_MMIO_OFF_DEV_TAB_SEG_FIRST:
2428 case IOMMU_MMIO_OFF_DEV_TAB_SEG_LAST:
2429 {
2430 uint8_t const idxDevTabSeg = (off - IOMMU_MMIO_OFF_DEV_TAB_SEG_FIRST) >> 3;
2431 Assert(idxDevTabSeg < RT_ELEMENTS(pThis->DevTabSeg));
2432 return iommuAmdIgnore_w(pDevIns, pThis, off, uValue);
2433 }
2434
2435 case IOMMU_MMIO_OFF_DEV_SPECIFIC_FEAT:
2436 case IOMMU_MMIO_OFF_DEV_SPECIFIC_CTRL:
2437 case IOMMU_MMIO_OFF_DEV_SPECIFIC_STATUS: return iommuAmdIgnore_w(pDevIns, pThis, off, uValue);
2438
2439 case IOMMU_MMIO_OFF_MSI_VECTOR_0:
2440 case IOMMU_MMIO_OFF_MSI_VECTOR_1: return iommuAmdIgnore_w(pDevIns, pThis, off, uValue);
2441 case IOMMU_MMIO_OFF_MSI_CAP_HDR:
2442 {
2443 VBOXSTRICTRC rcStrict = iommuAmdIgnore_w(pDevIns, pThis, off, (uint32_t)uValue);
2444 if (cb == 4 || RT_FAILURE(rcStrict))
2445 return rcStrict;
2446 uValue >>= 32;
2447 RT_FALL_THRU();
2448 }
2449 case IOMMU_MMIO_OFF_MSI_ADDR_LO: return iommuAmdMsiAddrLo_w(pDevIns, pThis, off, uValue);
2450 case IOMMU_MMIO_OFF_MSI_ADDR_HI:
2451 {
2452 VBOXSTRICTRC rcStrict = iommuAmdMsiAddrHi_w(pDevIns, pThis, off, (uint32_t)uValue);
2453 if (cb == 4 || RT_FAILURE(rcStrict))
2454 return rcStrict;
2455 uValue >>= 32;
2456 RT_FALL_THRU();
2457 }
2458 case IOMMU_MMIO_OFF_MSI_DATA: return iommuAmdMsiData_w(pDevIns, pThis, off, uValue);
2459 case IOMMU_MMIO_OFF_MSI_MAPPING_CAP_HDR: return iommuAmdIgnore_w(pDevIns, pThis, off, uValue);
2460
2461 case IOMMU_MMIO_OFF_PERF_OPT_CTRL: return iommuAmdIgnore_w(pDevIns, pThis, off, uValue);
2462
2463 case IOMMU_MMIO_OFF_XT_GEN_INTR_CTRL:
2464 case IOMMU_MMIO_OFF_XT_PPR_INTR_CTRL:
2465 case IOMMU_MMIO_OFF_XT_GALOG_INT_CTRL: return iommuAmdIgnore_w(pDevIns, pThis, off, uValue);
2466
2467 case IOMMU_MMIO_OFF_MARC_APER_BAR_0:
2468 case IOMMU_MMIO_OFF_MARC_APER_RELOC_0:
2469 case IOMMU_MMIO_OFF_MARC_APER_LEN_0:
2470 case IOMMU_MMIO_OFF_MARC_APER_BAR_1:
2471 case IOMMU_MMIO_OFF_MARC_APER_RELOC_1:
2472 case IOMMU_MMIO_OFF_MARC_APER_LEN_1:
2473 case IOMMU_MMIO_OFF_MARC_APER_BAR_2:
2474 case IOMMU_MMIO_OFF_MARC_APER_RELOC_2:
2475 case IOMMU_MMIO_OFF_MARC_APER_LEN_2:
2476 case IOMMU_MMIO_OFF_MARC_APER_BAR_3:
2477 case IOMMU_MMIO_OFF_MARC_APER_RELOC_3:
2478 case IOMMU_MMIO_OFF_MARC_APER_LEN_3: return iommuAmdIgnore_w(pDevIns, pThis, off, uValue);
2479
2480 case IOMMU_MMIO_OFF_RSVD_REG: return iommuAmdIgnore_w(pDevIns, pThis, off, uValue);
2481
2482 case IOMMU_MMIO_CMD_BUF_HEAD_PTR: return iommuAmdCmdBufHeadPtr_w(pDevIns, pThis, off, uValue);
2483 case IOMMU_MMIO_CMD_BUF_TAIL_PTR: return iommuAmdCmdBufTailPtr_w(pDevIns, pThis, off, uValue);
2484 case IOMMU_MMIO_EVT_LOG_HEAD_PTR: return iommuAmdEvtLogHeadPtr_w(pDevIns, pThis, off, uValue);
2485 case IOMMU_MMIO_EVT_LOG_TAIL_PTR: return iommuAmdEvtLogTailPtr_w(pDevIns, pThis, off, uValue);
2486
2487 case IOMMU_MMIO_OFF_STATUS:
2488
2489 case IOMMU_MMIO_OFF_PPR_LOG_HEAD_PTR:
2490 case IOMMU_MMIO_OFF_PPR_LOG_TAIL_PTR:
2491
2492 case IOMMU_MMIO_OFF_GALOG_HEAD_PTR:
2493 case IOMMU_MMIO_OFF_GALOG_TAIL_PTR:
2494
2495 case IOMMU_MMIO_OFF_PPR_LOG_B_HEAD_PTR:
2496 case IOMMU_MMIO_OFF_PPR_LOG_B_TAIL_PTR:
2497
2498 case IOMMU_MMIO_OFF_EVT_LOG_B_HEAD_PTR:
2499 case IOMMU_MMIO_OFF_EVT_LOG_B_TAIL_PTR: return iommuAmdIgnore_w(pDevIns, pThis, off, uValue);
2500
2501 case IOMMU_MMIO_OFF_PPR_LOG_AUTO_RESP:
2502 case IOMMU_MMIO_OFF_PPR_LOG_OVERFLOW_EARLY:
2503 case IOMMU_MMIO_OFF_PPR_LOG_B_OVERFLOW_EARLY:
2504
2505 /* Not implemented. */
2506 case IOMMU_MMIO_OFF_SMI_FLT_FIRST:
2507 case IOMMU_MMIO_OFF_SMI_FLT_LAST:
2508 {
2509 Log((IOMMU_LOG_PFX ": iommuAmdWriteRegister: Writing unsupported register: SMI filter %u -> Ignored\n",
2510 (off - IOMMU_MMIO_OFF_SMI_FLT_FIRST) >> 3));
2511 return VINF_SUCCESS;
2512 }
2513
2514 /* Unknown. */
2515 default:
2516 {
2517 Log((IOMMU_LOG_PFX ": iommuAmdWriteRegister: Trying to write unknown register at %u (%#x) with %#RX64\n", off, off,
2518 uValue));
2519 return VINF_SUCCESS;
2520 }
2521 }
2522}
2523
2524
2525/**
2526 * Reads an IOMMU register (64-bit).
2527 *
2528 * All reads are 64-bit but reads to 32-bit registers that are aligned on an 8-byte
2529 * boundary include the lower half of the subsequent register.
2530 *
2531 * This is because most registers are 64-bit and aligned on 8-byte boundaries but
2532 * some are really 32-bit registers aligned on an 8-byte boundary. We cannot assume
2533 * guests will only perform 32-bit reads on those 32-bit registers that are aligned
2534 * on 8-byte boundaries.
2535 *
2536 * @returns Strict VBox status code.
2537 * @param pDevIns The device instance.
2538 * @param off Offset in bytes.
2539 * @param puResult Where to store the value being read.
2540 */
2541static VBOXSTRICTRC iommuAmdReadRegister(PPDMDEVINS pDevIns, uint32_t off, uint64_t *puResult)
2542{
2543 Assert(off < IOMMU_MMIO_REGION_SIZE);
2544 Assert(!(off & 7) || !(off & 3));
2545
2546 PIOMMU pThis = PDMDEVINS_2_DATA(pDevIns, PIOMMU);
2547 Assert(pThis);
2548
2549 /** @todo IOMMU: fine-grained locking? */
2550 uint64_t uReg;
2551 switch (off)
2552 {
2553 case IOMMU_MMIO_OFF_DEV_TAB_BAR: uReg = pThis->DevTabBaseAddr.u64; break;
2554 case IOMMU_MMIO_OFF_CMD_BUF_BAR: uReg = pThis->CmdBufBaseAddr.u64; break;
2555 case IOMMU_MMIO_OFF_EVT_LOG_BAR: uReg = pThis->EvtLogBaseAddr.u64; break;
2556 case IOMMU_MMIO_OFF_CTRL: uReg = pThis->Ctrl.u64; break;
2557 case IOMMU_MMIO_OFF_EXCL_BAR: uReg = pThis->ExclRangeBaseAddr.u64; break;
2558 case IOMMU_MMIO_OFF_EXCL_RANGE_LIMIT: uReg = pThis->ExclRangeLimit.u64; break;
2559 case IOMMU_MMIO_OFF_EXT_FEAT: uReg = pThis->ExtFeat.u64; break;
2560
2561 case IOMMU_MMIO_OFF_PPR_LOG_BAR: uReg = pThis->PprLogBaseAddr.u64; break;
2562 case IOMMU_MMIO_OFF_HW_EVT_HI: uReg = pThis->HwEvtHi.u64; break;
2563 case IOMMU_MMIO_OFF_HW_EVT_LO: uReg = pThis->HwEvtLo; break;
2564 case IOMMU_MMIO_OFF_HW_EVT_STATUS: uReg = pThis->HwEvtStatus.u64; break;
2565
2566 case IOMMU_MMIO_OFF_GALOG_BAR: uReg = pThis->GALogBaseAddr.u64; break;
2567 case IOMMU_MMIO_OFF_GALOG_TAIL_ADDR: uReg = pThis->GALogTailAddr.u64; break;
2568
2569 case IOMMU_MMIO_OFF_PPR_LOG_B_BAR: uReg = pThis->PprLogBBaseAddr.u64; break;
2570 case IOMMU_MMIO_OFF_PPR_EVT_B_BAR: uReg = pThis->EvtLogBBaseAddr.u64; break;
2571
2572 case IOMMU_MMIO_OFF_DEV_TAB_SEG_FIRST:
2573 case IOMMU_MMIO_OFF_DEV_TAB_SEG_LAST:
2574 {
2575 uint8_t const idxDevTabSeg = (off - IOMMU_MMIO_OFF_DEV_TAB_SEG_FIRST) >> 3;
2576 Assert(idxDevTabSeg < RT_ELEMENTS(pThis->DevTabSeg));
2577 uReg = pThis->DevTabSeg[idxDevTabSeg].u64;
2578 break;
2579 }
2580
2581 case IOMMU_MMIO_OFF_DEV_SPECIFIC_FEAT: uReg = pThis->DevSpecificFeat.u64; break;
2582 case IOMMU_MMIO_OFF_DEV_SPECIFIC_CTRL: uReg = pThis->DevSpecificCtrl.u64; break;
2583 case IOMMU_MMIO_OFF_DEV_SPECIFIC_STATUS: uReg = pThis->DevSpecificStatus.u64; break;
2584
2585 case IOMMU_MMIO_OFF_MSI_VECTOR_0: uReg = pThis->MsiMiscInfo.u64; break;
2586 case IOMMU_MMIO_OFF_MSI_VECTOR_1: uReg = pThis->MsiMiscInfo.au32[1]; break;
2587 case IOMMU_MMIO_OFF_MSI_CAP_HDR: uReg = RT_MAKE_U64(pThis->MsiCapHdr.u32, pThis->MsiAddr.au32[0]); break;
2588 case IOMMU_MMIO_OFF_MSI_ADDR_LO: uReg = pThis->MsiAddr.au32[0]; break;
2589 case IOMMU_MMIO_OFF_MSI_ADDR_HI: uReg = RT_MAKE_U64(pThis->MsiAddr.au32[1], pThis->MsiData.u32); break;
2590 case IOMMU_MMIO_OFF_MSI_DATA: uReg = pThis->MsiData.u32; break;
2591 case IOMMU_MMIO_OFF_MSI_MAPPING_CAP_HDR: uReg = RT_MAKE_U64(pThis->MsiMapCapHdr.u32, pThis->PerfOptCtrl.u32); break;
2592
2593 case IOMMU_MMIO_OFF_PERF_OPT_CTRL: uReg = pThis->PerfOptCtrl.u32; break;
2594
2595 case IOMMU_MMIO_OFF_XT_GEN_INTR_CTRL: uReg = pThis->XtGenIntrCtrl.u64; break;
2596 case IOMMU_MMIO_OFF_XT_PPR_INTR_CTRL: uReg = pThis->XtPprIntrCtrl.u64; break;
2597 case IOMMU_MMIO_OFF_XT_GALOG_INT_CTRL: uReg = pThis->XtGALogIntrCtrl.u64; break;
2598
2599 case IOMMU_MMIO_OFF_MARC_APER_BAR_0: uReg = pThis->aMarcApers[0].Base.u64; break;
2600 case IOMMU_MMIO_OFF_MARC_APER_RELOC_0: uReg = pThis->aMarcApers[0].Reloc.u64; break;
2601 case IOMMU_MMIO_OFF_MARC_APER_LEN_0: uReg = pThis->aMarcApers[0].Length.u64; break;
2602 case IOMMU_MMIO_OFF_MARC_APER_BAR_1: uReg = pThis->aMarcApers[1].Base.u64; break;
2603 case IOMMU_MMIO_OFF_MARC_APER_RELOC_1: uReg = pThis->aMarcApers[1].Reloc.u64; break;
2604 case IOMMU_MMIO_OFF_MARC_APER_LEN_1: uReg = pThis->aMarcApers[1].Length.u64; break;
2605 case IOMMU_MMIO_OFF_MARC_APER_BAR_2: uReg = pThis->aMarcApers[2].Base.u64; break;
2606 case IOMMU_MMIO_OFF_MARC_APER_RELOC_2: uReg = pThis->aMarcApers[2].Reloc.u64; break;
2607 case IOMMU_MMIO_OFF_MARC_APER_LEN_2: uReg = pThis->aMarcApers[2].Length.u64; break;
2608 case IOMMU_MMIO_OFF_MARC_APER_BAR_3: uReg = pThis->aMarcApers[3].Base.u64; break;
2609 case IOMMU_MMIO_OFF_MARC_APER_RELOC_3: uReg = pThis->aMarcApers[3].Reloc.u64; break;
2610 case IOMMU_MMIO_OFF_MARC_APER_LEN_3: uReg = pThis->aMarcApers[3].Length.u64; break;
2611
2612 case IOMMU_MMIO_OFF_RSVD_REG: uReg = pThis->RsvdReg; break;
2613
2614 case IOMMU_MMIO_CMD_BUF_HEAD_PTR: uReg = pThis->CmdBufHeadPtr.u64; break;
2615 case IOMMU_MMIO_CMD_BUF_TAIL_PTR: uReg = pThis->CmdBufTailPtr.u64; break;
2616 case IOMMU_MMIO_EVT_LOG_HEAD_PTR: uReg = pThis->EvtLogHeadPtr.u64; break;
2617 case IOMMU_MMIO_EVT_LOG_TAIL_PTR: uReg = pThis->EvtLogTailPtr.u64; break;
2618
2619 case IOMMU_MMIO_OFF_STATUS: uReg = pThis->Status.u64; break;
2620
2621 case IOMMU_MMIO_OFF_PPR_LOG_HEAD_PTR: uReg = pThis->PprLogHeadPtr.u64; break;
2622 case IOMMU_MMIO_OFF_PPR_LOG_TAIL_PTR: uReg = pThis->PprLogTailPtr.u64; break;
2623
2624 case IOMMU_MMIO_OFF_GALOG_HEAD_PTR: uReg = pThis->GALogHeadPtr.u64; break;
2625 case IOMMU_MMIO_OFF_GALOG_TAIL_PTR: uReg = pThis->GALogTailPtr.u64; break;
2626
2627 case IOMMU_MMIO_OFF_PPR_LOG_B_HEAD_PTR: uReg = pThis->PprLogBHeadPtr.u64; break;
2628 case IOMMU_MMIO_OFF_PPR_LOG_B_TAIL_PTR: uReg = pThis->PprLogBTailPtr.u64; break;
2629
2630 case IOMMU_MMIO_OFF_EVT_LOG_B_HEAD_PTR: uReg = pThis->EvtLogBHeadPtr.u64; break;
2631 case IOMMU_MMIO_OFF_EVT_LOG_B_TAIL_PTR: uReg = pThis->EvtLogBTailPtr.u64; break;
2632
2633 case IOMMU_MMIO_OFF_PPR_LOG_AUTO_RESP: uReg = pThis->PprLogAutoResp.u64; break;
2634 case IOMMU_MMIO_OFF_PPR_LOG_OVERFLOW_EARLY: uReg = pThis->PprLogOverflowEarly.u64; break;
2635 case IOMMU_MMIO_OFF_PPR_LOG_B_OVERFLOW_EARLY: uReg = pThis->PprLogBOverflowEarly.u64; break;
2636
2637 /* Not implemented. */
2638 case IOMMU_MMIO_OFF_SMI_FLT_FIRST:
2639 case IOMMU_MMIO_OFF_SMI_FLT_LAST:
2640 {
2641 Log((IOMMU_LOG_PFX ": iommuAmdReadRegister: Reading unsupported register: SMI filter %u\n",
2642 (off - IOMMU_MMIO_OFF_SMI_FLT_FIRST) >> 3));
2643 uReg = 0;
2644 break;
2645 }
2646
2647 /* Unknown. */
2648 default:
2649 {
2650 Log((IOMMU_LOG_PFX ": iommuAmdReadRegister: Trying to read unknown register at %u (%#x)\n", off, off));
2651 uReg = 0;
2652 return VINF_IOM_MMIO_UNUSED_00;
2653 }
2654 }
2655
2656 *puResult = uReg;
2657 return VINF_SUCCESS;
2658}
2659
2660/**
2661 * @callback_method_impl{FNIOMMMIONEWWRITE}
2662 */
2663static DECLCALLBACK(VBOXSTRICTRC) iommuAmdMmioWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void const *pv, unsigned cb)
2664{
2665 NOREF(pvUser);
2666 Assert(cb == 4 || cb == 8);
2667 Assert(!(off & (cb - 1)));
2668
2669 uint64_t const uValue = cb == 8 ? *(uint64_t const *)pv : *(uint32_t const *)pv;
2670 return iommuAmdWriteRegister(pDevIns, off, cb, uValue);
2671}
2672
2673
2674/**
2675 * @callback_method_impl{FNIOMMMIONEWREAD}
2676 */
2677static DECLCALLBACK(VBOXSTRICTRC) iommuAmdMmioRead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void *pv, unsigned cb)
2678{
2679 NOREF(pvUser);
2680 Assert(cb == 4 || cb == 8);
2681 Assert(!(off & (cb - 1)));
2682
2683 uint64_t uResult;
2684 VBOXSTRICTRC rcStrict = iommuAmdReadRegister(pDevIns, off, &uResult);
2685 if (cb == 8)
2686 *(uint64_t *)pv = uResult;
2687 else
2688 *(uint32_t *)pv = (uint32_t)uResult;
2689
2690 return rcStrict;
2691}
2692
2693
2694# ifdef IN_RING3
2695/**
2696 * @callback_method_impl{FNPCICONFIGREAD}
2697 */
2698static DECLCALLBACK(VBOXSTRICTRC) iommuAmdR3PciConfigRead(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t uAddress,
2699 unsigned cb, uint32_t *pu32Value)
2700{
2701 /** @todo IOMMU: PCI config read stat counter. */
2702 VBOXSTRICTRC rcStrict = PDMDevHlpPCIConfigRead(pDevIns, pPciDev, uAddress, cb, pu32Value);
2703 Log3((IOMMU_LOG_PFX ": PCI config read: At %#x (%u) -> %#x %Rrc\n", uAddress, cb, *pu32Value, VBOXSTRICTRC_VAL(rcStrict)));
2704 return rcStrict;
2705}
2706
2707
2708/**
2709 * @callback_method_impl{FNPCICONFIGWRITE}
2710 */
2711static DECLCALLBACK(VBOXSTRICTRC) iommuAmdR3PciConfigWrite(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t uAddress,
2712 unsigned cb, uint32_t u32Value)
2713{
2714 /** @todo IOMMU: PCI config write. */
2715 VBOXSTRICTRC rcStrict = PDMDevHlpPCIConfigWrite(pDevIns, pPciDev, uAddress, cb, u32Value);
2716 Log3((IOMMU_LOG_PFX ": PCI config write: %#x -> To %#x (%u) %Rrc\n", u32Value, uAddress, cb, VBOXSTRICTRC_VAL(rcStrict)));
2717 return rcStrict;
2718}
2719
2720
2721/**
2722 * @callback_method_impl{FNDBGFHANDLERDEV}
2723 */
2724static DECLCALLBACK(void) iommuAmdR3DbgInfo(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, const char *pszArgs)
2725{
2726 PCIOMMU pThis = PDMDEVINS_2_DATA(pDevIns, PIOMMU);
2727 Assert(pThis);
2728
2729 LogFlow((IOMMU_LOG_PFX ": iommuAmdR3DbgInfo: pThis=%p pszArgs=%s\n", pThis, pszArgs));
2730 bool const fVerbose = !strncmp(pszArgs, RT_STR_TUPLE("verbose")) ? true : false;
2731
2732 pHlp->pfnPrintf(pHlp, "AMD-IOMMU:\n");
2733 /* Device Table Base Address. */
2734 {
2735 DEV_TAB_BAR_T const DevTabBar = pThis->DevTabBaseAddr;
2736 pHlp->pfnPrintf(pHlp, " Device Table BAR = %#RX64\n", DevTabBar.u64);
2737 if (fVerbose)
2738 {
2739 pHlp->pfnPrintf(pHlp, " Size = %u (%u bytes)\n", DevTabBar.n.u9Size,
2740 (DevTabBar.n.u9Size + 1) * _4K);
2741 pHlp->pfnPrintf(pHlp, " Base address = %#RX64\n", DevTabBar.n.u40DevTabBase);
2742 }
2743 }
2744 /* Command Buffer Base Address Register. */
2745 {
2746 CMD_BUF_BAR_T const CmdBufBar = pThis->CmdBufBaseAddr;
2747 uint32_t cEntries;
2748 uint32_t cbBuffer;
2749 uint8_t const uEncodedLen = CmdBufBar.n.u4CmdLen;
2750 iommuAmdDecodeBufferLength(uEncodedLen, &cEntries, &cbBuffer);
2751 pHlp->pfnPrintf(pHlp, " Command buffer BAR = %#RX64\n", CmdBufBar.u64);
2752 if (fVerbose)
2753 {
2754 pHlp->pfnPrintf(pHlp, " Base address = %#RX64\n", CmdBufBar.n.u40CmdBase);
2755 pHlp->pfnPrintf(pHlp, " Length = %u (%u entries, %u bytes)\n", uEncodedLen,
2756 cEntries, cbBuffer);
2757 }
2758 }
2759 /* Event Log Base Address Register. */
2760 {
2761 EVT_LOG_BAR_T const EvtLogBar = pThis->EvtLogBaseAddr;
2762 uint32_t cEntries;
2763 uint32_t cbBuffer;
2764 uint8_t const uEncodedLen = EvtLogBar.n.u4EvtLen;
2765 iommuAmdDecodeBufferLength(uEncodedLen, &cEntries, &cbBuffer);
2766 pHlp->pfnPrintf(pHlp, " Event log BAR = %#RX64\n", EvtLogBar.u64);
2767 if (fVerbose)
2768 {
2769 pHlp->pfnPrintf(pHlp, " Base address = %#RX64\n", EvtLogBar.n.u40EvtBase);
2770 pHlp->pfnPrintf(pHlp, " Length = %u (%u entries, %u bytes)\n", uEncodedLen,
2771 cEntries, cbBuffer);
2772 }
2773 }
2774 /* IOMMU Control Register. */
2775 {
2776 IOMMU_CTRL_T const Ctrl = pThis->Ctrl;
2777 pHlp->pfnPrintf(pHlp, " Control = %#RX64\n", Ctrl.u64);
2778 if (fVerbose)
2779 {
2780 pHlp->pfnPrintf(pHlp, " IOMMU enable = %RTbool\n", Ctrl.n.u1IommuEn);
2781 pHlp->pfnPrintf(pHlp, " HT Tunnel translation enable = %RTbool\n", Ctrl.n.u1HtTunEn);
2782 pHlp->pfnPrintf(pHlp, " Event log enable = %RTbool\n", Ctrl.n.u1EvtLogEn);
2783 pHlp->pfnPrintf(pHlp, " Event log interrupt enable = %RTbool\n", Ctrl.n.u1EvtIntrEn);
2784 pHlp->pfnPrintf(pHlp, " Completion wait interrupt enable = %RTbool\n", Ctrl.n.u1EvtIntrEn);
2785 pHlp->pfnPrintf(pHlp, " Invalidation timeout = %u\n", Ctrl.n.u3InvTimeOut);
2786 pHlp->pfnPrintf(pHlp, " Pass posted write = %RTbool\n", Ctrl.n.u1PassPW);
2787 pHlp->pfnPrintf(pHlp, " Respose Pass posted write = %RTbool\n", Ctrl.n.u1ResPassPW);
2788 pHlp->pfnPrintf(pHlp, " Coherent = %RTbool\n", Ctrl.n.u1Coherent);
2789 pHlp->pfnPrintf(pHlp, " Isochronous = %RTbool\n", Ctrl.n.u1Isoc);
2790 pHlp->pfnPrintf(pHlp, " Command buffer enable = %RTbool\n", Ctrl.n.u1CmdBufEn);
2791 pHlp->pfnPrintf(pHlp, " PPR log enable = %RTbool\n", Ctrl.n.u1PprLogEn);
2792 pHlp->pfnPrintf(pHlp, " PPR interrupt enable = %RTbool\n", Ctrl.n.u1PprIntrEn);
2793 pHlp->pfnPrintf(pHlp, " PPR enable = %RTbool\n", Ctrl.n.u1PprEn);
2794 pHlp->pfnPrintf(pHlp, " Guest translation eanble = %RTbool\n", Ctrl.n.u1GstTranslateEn);
2795 pHlp->pfnPrintf(pHlp, " Guest virtual-APIC enable = %RTbool\n", Ctrl.n.u1GstVirtApicEn);
2796 pHlp->pfnPrintf(pHlp, " CRW = %#x\n", Ctrl.n.u4Crw);
2797 pHlp->pfnPrintf(pHlp, " SMI filter enable = %RTbool\n", Ctrl.n.u1SmiFilterEn);
2798 pHlp->pfnPrintf(pHlp, " Self-writeback disable = %RTbool\n", Ctrl.n.u1SelfWriteBackDis);
2799 pHlp->pfnPrintf(pHlp, " SMI filter log enable = %RTbool\n", Ctrl.n.u1SmiFilterLogEn);
2800 pHlp->pfnPrintf(pHlp, " Guest virtual-APIC mode enable = %#x\n", Ctrl.n.u3GstVirtApicModeEn);
2801 pHlp->pfnPrintf(pHlp, " Guest virtual-APIC GA log enable = %RTbool\n", Ctrl.n.u1GstLogEn);
2802 pHlp->pfnPrintf(pHlp, " Guest virtual-APIC interrupt enable = %RTbool\n", Ctrl.n.u1GstIntrEn);
2803 pHlp->pfnPrintf(pHlp, " Dual PPR log enable = %#x\n", Ctrl.n.u2DualPprLogEn);
2804 pHlp->pfnPrintf(pHlp, " Dual event log enable = %#x\n", Ctrl.n.u2DualEvtLogEn);
2805 pHlp->pfnPrintf(pHlp, " Device table segmentation enable = %#x\n", Ctrl.n.u3DevTabSegEn);
2806 pHlp->pfnPrintf(pHlp, " Privilege abort enable = %#x\n", Ctrl.n.u2PrivAbortEn);
2807 pHlp->pfnPrintf(pHlp, " PPR auto response enable = %RTbool\n", Ctrl.n.u1PprAutoRespEn);
2808 pHlp->pfnPrintf(pHlp, " MARC enable = %RTbool\n", Ctrl.n.u1MarcEn);
2809 pHlp->pfnPrintf(pHlp, " Block StopMark enable = %RTbool\n", Ctrl.n.u1BlockStopMarkEn);
2810 pHlp->pfnPrintf(pHlp, " PPR auto response always-on enable = %RTbool\n", Ctrl.n.u1PprAutoRespAlwaysOnEn);
2811 pHlp->pfnPrintf(pHlp, " Domain IDPNE = %RTbool\n", Ctrl.n.u1DomainIDPNE);
2812 pHlp->pfnPrintf(pHlp, " Enhanced PPR handling = %RTbool\n", Ctrl.n.u1EnhancedPpr);
2813 pHlp->pfnPrintf(pHlp, " Host page table access/dirty bit update = %#x\n", Ctrl.n.u2HstAccDirtyBitUpdate);
2814 pHlp->pfnPrintf(pHlp, " Guest page table dirty bit disable = %RTbool\n", Ctrl.n.u1GstDirtyUpdateDis);
2815 pHlp->pfnPrintf(pHlp, " x2APIC enable = %RTbool\n", Ctrl.n.u1X2ApicEn);
2816 pHlp->pfnPrintf(pHlp, " x2APIC interrupt enable = %RTbool\n", Ctrl.n.u1X2ApicIntrGenEn);
2817 pHlp->pfnPrintf(pHlp, " Guest page table access bit update = %RTbool\n", Ctrl.n.u1GstAccessUpdateDis);
2818 }
2819 }
2820 /* Exclusion Base Address Register. */
2821 {
2822 IOMMU_EXCL_RANGE_BAR_T const ExclRangeBar = pThis->ExclRangeBaseAddr;
2823 pHlp->pfnPrintf(pHlp, " Exclusion BAR = %#RX64\n", ExclRangeBar.u64);
2824 if (fVerbose)
2825 {
2826 pHlp->pfnPrintf(pHlp, " Exclusion enable = %RTbool\n", ExclRangeBar.n.u1ExclEnable);
2827 pHlp->pfnPrintf(pHlp, " Allow all devices = %RTbool\n", ExclRangeBar.n.u1AllowAll);
2828 pHlp->pfnPrintf(pHlp, " Base address = %#RX64\n", ExclRangeBar.n.u40ExclRangeBase);
2829 }
2830 }
2831 /* Exclusion Range Limit Register. */
2832 {
2833 IOMMU_EXCL_RANGE_LIMIT_T const ExclRangeLimit = pThis->ExclRangeLimit;
2834 pHlp->pfnPrintf(pHlp, " Exclusion Range Limit = %#RX64\n", ExclRangeLimit.u64);
2835 if (fVerbose)
2836 pHlp->pfnPrintf(pHlp, " Range limit = %#RX64\n", ExclRangeLimit.n.u40ExclLimit);
2837 }
2838 /* Extended Feature Register. */
2839 {
2840 IOMMU_EXT_FEAT_T ExtFeat = pThis->ExtFeat;
2841 pHlp->pfnPrintf(pHlp, " Extended Feature Register = %#RX64\n", ExtFeat.u64);
2842 pHlp->pfnPrintf(pHlp, " Prefetch support = %RTbool\n", ExtFeat.n.u1PrefetchSup);
2843 if (fVerbose)
2844 {
2845 pHlp->pfnPrintf(pHlp, " PPR support = %RTbool\n", ExtFeat.n.u1PprSup);
2846 pHlp->pfnPrintf(pHlp, " x2APIC support = %RTbool\n", ExtFeat.n.u1X2ApicSup);
2847 pHlp->pfnPrintf(pHlp, " NX and privilege level support = %RTbool\n", ExtFeat.n.u1NoExecuteSup);
2848 pHlp->pfnPrintf(pHlp, " Guest translation support = %RTbool\n", ExtFeat.n.u1GstTranslateSup);
2849 pHlp->pfnPrintf(pHlp, " Invalidate-All command support = %RTbool\n", ExtFeat.n.u1InvAllSup);
2850 pHlp->pfnPrintf(pHlp, " Guest virtual-APIC support = %RTbool\n", ExtFeat.n.u1GstVirtApicSup);
2851 pHlp->pfnPrintf(pHlp, " Hardware error register support = %RTbool\n", ExtFeat.n.u1HwErrorSup);
2852 pHlp->pfnPrintf(pHlp, " Performance counters support = %RTbool\n", ExtFeat.n.u1PerfCounterSup);
2853 pHlp->pfnPrintf(pHlp, " Host address translation size = %#x\n", ExtFeat.n.u2HostAddrTranslateSize);
2854 pHlp->pfnPrintf(pHlp, " Guest address translation size = %#x\n", ExtFeat.n.u2GstAddrTranslateSize);
2855 pHlp->pfnPrintf(pHlp, " Guest CR3 root table level support = %#x\n", ExtFeat.n.u2GstCr3RootTblLevel);
2856 pHlp->pfnPrintf(pHlp, " SMI filter register support = %#x\n", ExtFeat.n.u2SmiFilterSup);
2857 pHlp->pfnPrintf(pHlp, " SMI filter register count = %#x\n", ExtFeat.n.u3SmiFilterCount);
2858 pHlp->pfnPrintf(pHlp, " Guest virtual-APIC modes support = %#x\n", ExtFeat.n.u3GstVirtApicModeSup);
2859 pHlp->pfnPrintf(pHlp, " Dual PPR log support = %#x\n", ExtFeat.n.u2DualPprLogSup);
2860 pHlp->pfnPrintf(pHlp, " Dual event log support = %#x\n", ExtFeat.n.u2DualEvtLogSup);
2861 pHlp->pfnPrintf(pHlp, " Maximum PASID = %#x\n", ExtFeat.n.u5MaxPasidSup);
2862 pHlp->pfnPrintf(pHlp, " User/supervisor page protection support = %RTbool\n", ExtFeat.n.u1UserSupervisorSup);
2863 pHlp->pfnPrintf(pHlp, " Device table segments supported = %u\n", (ExtFeat.n.u2DevTabSegSup << 1));
2864 pHlp->pfnPrintf(pHlp, " PPR log overflow early warning support = %RTbool\n", ExtFeat.n.u1PprLogOverflowWarn);
2865 pHlp->pfnPrintf(pHlp, " PPR auto response support = %RTbool\n", ExtFeat.n.u1PprAutoRespSup);
2866 pHlp->pfnPrintf(pHlp, " MARC support = %#x\n", ExtFeat.n.u2MarcSup);
2867 pHlp->pfnPrintf(pHlp, " Block StopMark message support = %RTbool\n", ExtFeat.n.u1BlockStopMarkSup);
2868 pHlp->pfnPrintf(pHlp, " Performance optimization support = %RTbool\n", ExtFeat.n.u1PerfOptSup);
2869 pHlp->pfnPrintf(pHlp, " MSI capability MMIO access support = %RTbool\n", ExtFeat.n.u1MsiCapMmioSup);
2870 pHlp->pfnPrintf(pHlp, " Guest I/O protection support = %RTbool\n", ExtFeat.n.u1GstIoSup);
2871 pHlp->pfnPrintf(pHlp, " Host access support = %RTbool\n", ExtFeat.n.u1HostAccessSup);
2872 pHlp->pfnPrintf(pHlp, " Enhanced PPR handling support = %RTbool\n", ExtFeat.n.u1EnhancedPprSup);
2873 pHlp->pfnPrintf(pHlp, " Attribute forward supported = %RTbool\n", ExtFeat.n.u1AttrForwardSup);
2874 pHlp->pfnPrintf(pHlp, " Host dirty support = %RTbool\n", ExtFeat.n.u1HostDirtySup);
2875 pHlp->pfnPrintf(pHlp, " Invalidate IOTLB type support = %RTbool\n", ExtFeat.n.u1InvIoTlbTypeSup);
2876 pHlp->pfnPrintf(pHlp, " Guest page table access bit hw disable = %RTbool\n", ExtFeat.n.u1GstUpdateDisSup);
2877 pHlp->pfnPrintf(pHlp, " Force physical dest for remapped intr. = %RTbool\n", ExtFeat.n.u1ForcePhysDstSup);
2878 }
2879 }
2880 /* PPR Log Base Address Register. */
2881 {
2882 PPR_LOG_BAR_T PprLogBar = pThis->PprLogBaseAddr;
2883 uint32_t cEntries;
2884 uint32_t cbBuffer;
2885 uint8_t const uEncodedLen = PprLogBar.n.u4PprLogLen;
2886 iommuAmdDecodeBufferLength(uEncodedLen, &cEntries, &cbBuffer);
2887 pHlp->pfnPrintf(pHlp, " PPR Log BAR = %#RX64\n", PprLogBar.u64);
2888 if (fVerbose)
2889 {
2890 pHlp->pfnPrintf(pHlp, " Base address = %#RX64\n", PprLogBar.n.u40PprLogBase);
2891 pHlp->pfnPrintf(pHlp, " Length = %u (%u entries, %u bytes)\n", uEncodedLen,
2892 cEntries, cbBuffer);
2893 }
2894 }
2895 /* Hardware Event (Hi) Register. */
2896 {
2897 IOMMU_HW_EVT_HI_T HwEvtHi = pThis->HwEvtHi;
2898 pHlp->pfnPrintf(pHlp, " Hardware Event (Hi) = %#RX64\n", HwEvtHi.u64);
2899 if (fVerbose)
2900 {
2901 pHlp->pfnPrintf(pHlp, " First operand = %#RX64\n", HwEvtHi.n.u60FirstOperand);
2902 pHlp->pfnPrintf(pHlp, " Event code = %#RX8\n", HwEvtHi.n.u4EvtCode);
2903 }
2904 }
2905 /* Hardware Event (Lo) Register. */
2906 pHlp->pfnPrintf(pHlp, " Hardware Event (Lo) = %#RX64\n", pThis->HwEvtLo);
2907 /* Hardware Event Status. */
2908 {
2909 IOMMU_HW_EVT_STATUS_T HwEvtStatus = pThis->HwEvtStatus;
2910 pHlp->pfnPrintf(pHlp, " Hardware Event Status = %#RX64\n", HwEvtStatus.u64);
2911 if (fVerbose)
2912 {
2913 pHlp->pfnPrintf(pHlp, " Valid = %RTbool\n", HwEvtStatus.n.u1Valid);
2914 pHlp->pfnPrintf(pHlp, " Overflow = %RTbool\n", HwEvtStatus.n.u1Overflow);
2915 }
2916 }
2917 /* Guest Virtual-APIC Log Base Address Register. */
2918 {
2919 GALOG_BAR_T const GALogBar = pThis->GALogBaseAddr;
2920 uint32_t cEntries;
2921 uint32_t cbBuffer;
2922 uint8_t const uEncodedLen = GALogBar.n.u4GALogLen;
2923 iommuAmdDecodeBufferLength(uEncodedLen, &cEntries, &cbBuffer);
2924 pHlp->pfnPrintf(pHlp, " Guest Log BAR = %#RX64\n", GALogBar.u64);
2925 if (fVerbose)
2926 {
2927 pHlp->pfnPrintf(pHlp, " Base address = %RTbool\n", GALogBar.n.u40GALogBase);
2928 pHlp->pfnPrintf(pHlp, " Length = %u (%u entries, %u bytes)\n", uEncodedLen,
2929 cEntries, cbBuffer);
2930 }
2931 }
2932 /* Guest Virtual-APIC Log Tail Address Register. */
2933 {
2934 GALOG_TAIL_ADDR_T GALogTail = pThis->GALogTailAddr;
2935 pHlp->pfnPrintf(pHlp, " Guest Log Tail Address = %#RX64\n", GALogTail.u64);
2936 if (fVerbose)
2937 pHlp->pfnPrintf(pHlp, " Tail address = %#RX64\n", GALogTail.n.u40GALogTailAddr);
2938 }
2939 /* PPR Log B Base Address Register. */
2940 {
2941 PPR_LOG_B_BAR_T PprLogBBar = pThis->PprLogBBaseAddr;
2942 uint32_t cEntries;
2943 uint32_t cbBuffer;
2944 uint8_t const uEncodedLen = PprLogBBar.n.u4PprLogLen;
2945 iommuAmdDecodeBufferLength(uEncodedLen, &cEntries, &cbBuffer);
2946 pHlp->pfnPrintf(pHlp, " PPR Log B BAR = %#RX64\n", PprLogBBar.u64);
2947 if (fVerbose)
2948 {
2949 pHlp->pfnPrintf(pHlp, " Base address = %#RX64\n", PprLogBBar.n.u40PprLogBase);
2950 pHlp->pfnPrintf(pHlp, " Length = %u (%u entries, %u bytes)\n", uEncodedLen,
2951 cEntries, cbBuffer);
2952 }
2953 }
2954 /* Event Log B Base Address Register. */
2955 {
2956 EVT_LOG_B_BAR_T EvtLogBBar = pThis->EvtLogBBaseAddr;
2957 uint32_t cEntries;
2958 uint32_t cbBuffer;
2959 uint8_t const uEncodedLen = EvtLogBBar.n.u4EvtLen;
2960 iommuAmdDecodeBufferLength(uEncodedLen, &cEntries, &cbBuffer);
2961 pHlp->pfnPrintf(pHlp, " Event Log B BAR = %#RX64\n", EvtLogBBar.u64);
2962 if (fVerbose)
2963 {
2964 pHlp->pfnPrintf(pHlp, " Base address = %#RX64\n", EvtLogBBar.n.u40EvtBase);
2965 pHlp->pfnPrintf(pHlp, " Length = %u (%u entries, %u bytes)\n", uEncodedLen,
2966 cEntries, cbBuffer);
2967 }
2968 }
2969 /* Device Table Segment Registers. */
2970 for (unsigned i = 0; i < RT_ELEMENTS(pThis->DevTabSeg); i++)
2971 {
2972 DEV_TAB_SEG_BAR_T const DevTabSeg = pThis->DevTabSeg[i];
2973 pHlp->pfnPrintf(pHlp, " Device Table Segment BAR [%u] = %#RX64\n", DevTabSeg.u64);
2974 if (fVerbose)
2975 {
2976 pHlp->pfnPrintf(pHlp, " Base address = %#RX64\n", DevTabSeg.n.u40DevTabBase);
2977 pHlp->pfnPrintf(pHlp, " Size = %#x (%u bytes)\n", DevTabSeg.n.u8Size,
2978 (DevTabSeg.n.u8Size + 1) << X86_PAGE_4K_SHIFT);
2979 }
2980 }
2981 /* Device-Specific Feature Extension Register. */
2982 {
2983 DEV_SPECIFIC_FEAT_T const DevSpecificFeat = pThis->DevSpecificFeat;
2984 pHlp->pfnPrintf(pHlp, " Device-specific Feature = %#RX64\n", DevSpecificFeat.u64);
2985 if (fVerbose)
2986 {
2987 pHlp->pfnPrintf(pHlp, " Feature = %#RX32\n", DevSpecificFeat.n.u24DevSpecFeat);
2988 pHlp->pfnPrintf(pHlp, " Minor revision ID = %#x\n", DevSpecificFeat.n.u4RevMinor);
2989 pHlp->pfnPrintf(pHlp, " Major revision ID = %#x\n", DevSpecificFeat.n.u4RevMajor);
2990 }
2991 }
2992 /* Device-Specific Control Extension Register. */
2993 {
2994 DEV_SPECIFIC_CTRL_T const DevSpecificCtrl = pThis->DevSpecificCtrl;
2995 pHlp->pfnPrintf(pHlp, " Device-specific Control = %#RX64\n", DevSpecificCtrl.u64);
2996 if (fVerbose)
2997 {
2998 pHlp->pfnPrintf(pHlp, " Control = %#RX32\n", DevSpecificCtrl.n.u24DevSpecCtrl);
2999 pHlp->pfnPrintf(pHlp, " Minor revision ID = %#x\n", DevSpecificCtrl.n.u4RevMinor);
3000 pHlp->pfnPrintf(pHlp, " Major revision ID = %#x\n", DevSpecificCtrl.n.u4RevMajor);
3001 }
3002 }
3003 /* Device-Specific Status Extension Register. */
3004 {
3005 DEV_SPECIFIC_STATUS_T const DevSpecificStatus = pThis->DevSpecificStatus;
3006 pHlp->pfnPrintf(pHlp, " Device-specific Control = %#RX64\n", DevSpecificStatus.u64);
3007 if (fVerbose)
3008 {
3009 pHlp->pfnPrintf(pHlp, " Status = %#RX32\n", DevSpecificStatus.n.u24DevSpecStatus);
3010 pHlp->pfnPrintf(pHlp, " Minor revision ID = %#x\n", DevSpecificStatus.n.u4RevMinor);
3011 pHlp->pfnPrintf(pHlp, " Major revision ID = %#x\n", DevSpecificStatus.n.u4RevMajor);
3012 }
3013 }
3014 /* MSI Miscellaneous Information Register (Lo and Hi). */
3015 {
3016 MSI_MISC_INFO_T const MsiMiscInfo = pThis->MsiMiscInfo;
3017 pHlp->pfnPrintf(pHlp, " MSI Misc. Info. Register = %#RX64\n", MsiMiscInfo.u64);
3018 if (fVerbose)
3019 {
3020 pHlp->pfnPrintf(pHlp, " Event Log MSI number = %#x\n", MsiMiscInfo.n.u5MsiNumEvtLog);
3021 pHlp->pfnPrintf(pHlp, " Guest Virtual-Address Size = %#x\n", MsiMiscInfo.n.u3GstVirtAddrSize);
3022 pHlp->pfnPrintf(pHlp, " Physical Address Size = %#x\n", MsiMiscInfo.n.u7PhysAddrSize);
3023 pHlp->pfnPrintf(pHlp, " Virtual-Address Size = %#x\n", MsiMiscInfo.n.u7VirtAddrSize);
3024 pHlp->pfnPrintf(pHlp, " HT Transport ATS Range Reserved = %RTbool\n", MsiMiscInfo.n.u1HtAtsResv);
3025 pHlp->pfnPrintf(pHlp, " PPR MSI number = %#x\n", MsiMiscInfo.n.u5MsiNumPpr);
3026 pHlp->pfnPrintf(pHlp, " GA Log MSI number = %#x\n", MsiMiscInfo.n.u5MsiNumGa);
3027 }
3028 }
3029 /* MSI Capability Header. */
3030 {
3031 MSI_CAP_HDR_T const MsiCapHdr = pThis->MsiCapHdr;
3032 pHlp->pfnPrintf(pHlp, " MSI Capability Header = %#RX32\n", MsiCapHdr.u32);
3033 if (fVerbose)
3034 {
3035 pHlp->pfnPrintf(pHlp, " Capability ID = %#x\n", MsiCapHdr.n.u8MsiCapId);
3036 pHlp->pfnPrintf(pHlp, " Capability Ptr (PCI config offset) = %#x\n", MsiCapHdr.n.u8MsiCapPtr);
3037 pHlp->pfnPrintf(pHlp, " Enable = %RTbool\n", MsiCapHdr.n.u1MsiEnable);
3038 pHlp->pfnPrintf(pHlp, " Multi-message capability = %#x\n", MsiCapHdr.n.u3MsiMultiMessCap);
3039 pHlp->pfnPrintf(pHlp, " Multi-message enable = %#x\n", MsiCapHdr.n.u3MsiMultiMessEn);
3040 }
3041 }
3042 /* MSI Address Register (Lo and Hi). */
3043 {
3044 MSI_ADDR_T const MsiAddr = pThis->MsiAddr;
3045 pHlp->pfnPrintf(pHlp, " MSI Address = %#RX64\n", MsiAddr.u64);
3046 if (fVerbose)
3047 pHlp->pfnPrintf(pHlp, " Address = %#RX64\n", MsiAddr.n.u62MsiAddr);
3048 }
3049 /* MSI Data. */
3050 {
3051 MSI_DATA_T const MsiData = pThis->MsiData;
3052 pHlp->pfnPrintf(pHlp, " MSI Data = %#RX32\n", MsiData.u32);
3053 if (fVerbose)
3054 pHlp->pfnPrintf(pHlp, " Data = %#x\n", MsiData.n.u16MsiData);
3055 }
3056 /* MSI Mapping Capability Header. */
3057 {
3058 MSI_MAP_CAP_HDR_T const MsiMapCapHdr = pThis->MsiMapCapHdr;
3059 pHlp->pfnPrintf(pHlp, " MSI Mapping Capability Header = %#RX32\n", MsiMapCapHdr.u32);
3060 if (fVerbose)
3061 {
3062 pHlp->pfnPrintf(pHlp, " Capability ID = %#x\n", MsiMapCapHdr.n.u8MsiMapCapId);
3063 pHlp->pfnPrintf(pHlp, " Map enable = %RTbool\n", MsiMapCapHdr.n.u1MsiMapEn);
3064 pHlp->pfnPrintf(pHlp, " Map fixed = %RTbool\n", MsiMapCapHdr.n.u1MsiMapFixed);
3065 pHlp->pfnPrintf(pHlp, " Map capability type = %#x\n", MsiMapCapHdr.n.u5MapCapType);
3066 }
3067 }
3068 /* Performance Optimization Control Register. */
3069 {
3070 IOMMU_PERF_OPT_CTRL_T const PerfOptCtrl = pThis->PerfOptCtrl;
3071 pHlp->pfnPrintf(pHlp, " Performance Optimization Control = %#RX32\n", PerfOptCtrl.u32);
3072 if (fVerbose)
3073 pHlp->pfnPrintf(pHlp, " Enable = %RTbool\n", PerfOptCtrl.n.u1PerfOptEn);
3074 }
3075 /* XT (x2APIC) General Interrupt Control Register. */
3076 {
3077 IOMMU_XT_GEN_INTR_CTRL_T const XtGenIntrCtrl = pThis->XtGenIntrCtrl;
3078 pHlp->pfnPrintf(pHlp, " XT General Interrupt Control = %#RX64\n", XtGenIntrCtrl.u64);
3079 if (fVerbose)
3080 {
3081 pHlp->pfnPrintf(pHlp, " Interrupt destination mode = %s\n",
3082 !XtGenIntrCtrl.n.u1X2ApicIntrDstMode ? "physical" : "logical");
3083 pHlp->pfnPrintf(pHlp, " Interrupt destination = %#RX64\n",
3084 RT_MAKE_U64(XtGenIntrCtrl.n.u24X2ApicIntrDstLo, XtGenIntrCtrl.n.u7X2ApicIntrDstHi));
3085 pHlp->pfnPrintf(pHlp, " Interrupt vector = %#x\n", XtGenIntrCtrl.n.u8X2ApicIntrVector);
3086 pHlp->pfnPrintf(pHlp, " Interrupt delivery mode = %#x\n",
3087 !XtGenIntrCtrl.n.u8X2ApicIntrVector ? "fixed" : "arbitrated");
3088 }
3089 }
3090 /* XT (x2APIC) PPR Interrupt Control Register. */
3091 {
3092 IOMMU_XT_PPR_INTR_CTRL_T const XtPprIntrCtrl = pThis->XtPprIntrCtrl;
3093 pHlp->pfnPrintf(pHlp, " XT PPR Interrupt Control = %#RX64\n", XtPprIntrCtrl.u64);
3094 if (fVerbose)
3095 {
3096 pHlp->pfnPrintf(pHlp, " Interrupt destination mode = %s\n",
3097 !XtPprIntrCtrl.n.u1X2ApicIntrDstMode ? "physical" : "logical");
3098 pHlp->pfnPrintf(pHlp, " Interrupt destination = %#RX64\n",
3099 RT_MAKE_U64(XtPprIntrCtrl.n.u24X2ApicIntrDstLo, XtPprIntrCtrl.n.u7X2ApicIntrDstHi));
3100 pHlp->pfnPrintf(pHlp, " Interrupt vector = %#x\n", XtPprIntrCtrl.n.u8X2ApicIntrVector);
3101 pHlp->pfnPrintf(pHlp, " Interrupt delivery mode = %#x\n",
3102 !XtPprIntrCtrl.n.u8X2ApicIntrVector ? "fixed" : "arbitrated");
3103 }
3104 }
3105 /* XT (X2APIC) GA Log Interrupt Control Register. */
3106 {
3107 IOMMU_XT_GALOG_INTR_CTRL_T const XtGALogIntrCtrl = pThis->XtGALogIntrCtrl;
3108 pHlp->pfnPrintf(pHlp, " XT PPR Interrupt Control = %#RX64\n", XtGALogIntrCtrl.u64);
3109 if (fVerbose)
3110 {
3111 pHlp->pfnPrintf(pHlp, " Interrupt destination mode = %s\n",
3112 !XtGALogIntrCtrl.n.u1X2ApicIntrDstMode ? "physical" : "logical");
3113 pHlp->pfnPrintf(pHlp, " Interrupt destination = %#RX64\n",
3114 RT_MAKE_U64(XtGALogIntrCtrl.n.u24X2ApicIntrDstLo, XtGALogIntrCtrl.n.u7X2ApicIntrDstHi));
3115 pHlp->pfnPrintf(pHlp, " Interrupt vector = %#x\n", XtGALogIntrCtrl.n.u8X2ApicIntrVector);
3116 pHlp->pfnPrintf(pHlp, " Interrupt delivery mode = %#x\n",
3117 !XtGALogIntrCtrl.n.u8X2ApicIntrVector ? "fixed" : "arbitrated");
3118 }
3119 }
3120 /* MARC Registers. */
3121 {
3122 for (unsigned i = 0; i < RT_ELEMENTS(pThis->aMarcApers); i++)
3123 {
3124 pHlp->pfnPrintf(pHlp, " MARC Aperature %u:\n", i);
3125 MARC_APER_BAR_T const MarcAperBar = pThis->aMarcApers[i].Base;
3126 pHlp->pfnPrintf(pHlp, " Base = %#RX64 (addr: %#RX64)\n", MarcAperBar.u64, MarcAperBar.n.u40MarcBaseAddr);
3127
3128 MARC_APER_RELOC_T const MarcAperReloc = pThis->aMarcApers[i].Reloc;
3129 pHlp->pfnPrintf(pHlp, " Reloc = %#RX64 (addr: %#RX64, read-only: %RTbool, enable: %RTbool)\n",
3130 MarcAperReloc.u64, MarcAperReloc.n.u40MarcRelocAddr, MarcAperReloc.n.u1ReadOnly,
3131 MarcAperReloc.n.u1RelocEn);
3132
3133 MARC_APER_LEN_T const MarcAperLen = pThis->aMarcApers[i].Length;
3134 pHlp->pfnPrintf(pHlp, " Length = %u pages\n", MarcAperLen.n.u40MarcLength);
3135 }
3136 }
3137 /* Reserved Register. */
3138 pHlp->pfnPrintf(pHlp, " Reserved Register = %#RX64\n", pThis->RsvdReg);
3139 /* Command Buffer Head Pointer Register. */
3140 {
3141 CMD_BUF_HEAD_PTR_T const CmdBufHeadPtr = pThis->CmdBufHeadPtr;
3142 pHlp->pfnPrintf(pHlp, " Command Buffer Head Pointer = %#RX64\n", CmdBufHeadPtr.u64);
3143 pHlp->pfnPrintf(pHlp, " Pointer = %#x\n", CmdBufHeadPtr.n.u15Ptr);
3144 }
3145 /* Command Buffer Tail Pointer Register. */
3146 {
3147 CMD_BUF_HEAD_PTR_T const CmdBufTailPtr = pThis->CmdBufTailPtr;
3148 pHlp->pfnPrintf(pHlp, " Command Buffer Tail Pointer = %#RX64\n", CmdBufTailPtr.u64);
3149 pHlp->pfnPrintf(pHlp, " Pointer = %#x\n", CmdBufTailPtr.n.u15Ptr);
3150 }
3151 /* Event Log Head Pointer Register. */
3152 {
3153 EVT_LOG_HEAD_PTR_T const EvtLogHeadPtr = pThis->EvtLogHeadPtr;
3154 pHlp->pfnPrintf(pHlp, " Event Log Head Pointer = %#RX64\n", EvtLogHeadPtr.u64);
3155 pHlp->pfnPrintf(pHlp, " Pointer = %#x\n", EvtLogHeadPtr.n.u15Ptr);
3156 }
3157 /* Event Log Tail Pointer Register. */
3158 {
3159 EVT_LOG_TAIL_PTR_T const EvtLogTailPtr = pThis->EvtLogTailPtr;
3160 pHlp->pfnPrintf(pHlp, " Event Log Head Pointer = %#RX64\n", EvtLogTailPtr.u64);
3161 pHlp->pfnPrintf(pHlp, " Pointer = %#x\n", EvtLogTailPtr.n.u15Ptr);
3162 }
3163 /* Status Register. */
3164 {
3165 IOMMU_STATUS_T const Status = pThis->Status;
3166 pHlp->pfnPrintf(pHlp, " Status Register = %#RX64\n", Status.u64);
3167 if (fVerbose)
3168 {
3169 pHlp->pfnPrintf(pHlp, " Event log overflow = %RTbool\n", Status.n.u1EvtOverflow);
3170 pHlp->pfnPrintf(pHlp, " Event log interrupt = %RTbool\n", Status.n.u1EvtLogIntr);
3171 pHlp->pfnPrintf(pHlp, " Completion wait interrupt = %RTbool\n", Status.n.u1CompWaitIntr);
3172 pHlp->pfnPrintf(pHlp, " Event log running = %RTbool\n", Status.n.u1EvtLogRunning);
3173 pHlp->pfnPrintf(pHlp, " Command buffer running = %RTbool\n", Status.n.u1CmdBufRunning);
3174 pHlp->pfnPrintf(pHlp, " PPR overflow = %RTbool\n", Status.n.u1PprOverflow);
3175 pHlp->pfnPrintf(pHlp, " PPR interrupt = %RTbool\n", Status.n.u1PprIntr);
3176 pHlp->pfnPrintf(pHlp, " PPR log running = %RTbool\n", Status.n.u1PprLogRunning);
3177 pHlp->pfnPrintf(pHlp, " Guest log running = %RTbool\n", Status.n.u1GstLogRunning);
3178 pHlp->pfnPrintf(pHlp, " Guest log interrupt = %RTbool\n", Status.n.u1GstLogIntr);
3179 pHlp->pfnPrintf(pHlp, " PPR log B overflow = %RTbool\n", Status.n.u1PprOverflowB);
3180 pHlp->pfnPrintf(pHlp, " PPR log active = %RTbool\n", Status.n.u1PprLogActive);
3181 pHlp->pfnPrintf(pHlp, " Event log B overflow = %RTbool\n", Status.n.u1EvtOverflowB);
3182 pHlp->pfnPrintf(pHlp, " Event log active = %RTbool\n", Status.n.u1EvtLogActive);
3183 pHlp->pfnPrintf(pHlp, " PPR log B overflow early warning = %RTbool\n", Status.n.u1PprOverflowEarlyB);
3184 pHlp->pfnPrintf(pHlp, " PPR log overflow early warning = %RTbool\n", Status.n.u1PprOverflowEarly);
3185 }
3186 }
3187 /* PPR Log Head Pointer. */
3188 {
3189 PPR_LOG_HEAD_PTR_T const PprLogHeadPtr = pThis->PprLogHeadPtr;
3190 pHlp->pfnPrintf(pHlp, " PPR Log Head Pointer = %#RX64\n", PprLogHeadPtr.u64);
3191 pHlp->pfnPrintf(pHlp, " Pointer = %#x\n", PprLogHeadPtr.n.u15Ptr);
3192 }
3193 /* PPR Log Tail Pointer. */
3194 {
3195 PPR_LOG_TAIL_PTR_T const PprLogTailPtr = pThis->PprLogTailPtr;
3196 pHlp->pfnPrintf(pHlp, " PPR Log Tail Pointer = %#RX64\n", PprLogTailPtr.u64);
3197 pHlp->pfnPrintf(pHlp, " Pointer = %#x\n", PprLogTailPtr.n.u15Ptr);
3198 }
3199 /* Guest Virtual-APIC Log Head Pointer. */
3200 {
3201 GALOG_HEAD_PTR_T const GALogHeadPtr = pThis->GALogHeadPtr;
3202 pHlp->pfnPrintf(pHlp, " Guest Virtual-APIC Log Head Pointer = %#RX64\n", GALogHeadPtr.u64);
3203 pHlp->pfnPrintf(pHlp, " Pointer = %#x\n", GALogHeadPtr.n.u12GALogPtr);
3204 }
3205 /* Guest Virtual-APIC Log Tail Pointer. */
3206 {
3207 GALOG_HEAD_PTR_T const GALogTailPtr = pThis->GALogTailPtr;
3208 pHlp->pfnPrintf(pHlp, " Guest Virtual-APIC Log Tail Pointer = %#RX64\n", GALogTailPtr.u64);
3209 pHlp->pfnPrintf(pHlp, " Pointer = %#x\n", GALogTailPtr.n.u12GALogPtr);
3210 }
3211 /* PPR Log B Head Pointer. */
3212 {
3213 PPR_LOG_B_HEAD_PTR_T const PprLogBHeadPtr = pThis->PprLogBHeadPtr;
3214 pHlp->pfnPrintf(pHlp, " PPR Log B Head Pointer = %#RX64\n", PprLogBHeadPtr.u64);
3215 pHlp->pfnPrintf(pHlp, " Pointer = %#x\n", PprLogBHeadPtr.n.u15Ptr);
3216 }
3217 /* PPR Log B Tail Pointer. */
3218 {
3219 PPR_LOG_B_TAIL_PTR_T const PprLogBTailPtr = pThis->PprLogBTailPtr;
3220 pHlp->pfnPrintf(pHlp, " PPR Log B Tail Pointer = %#RX64\n", PprLogBTailPtr.u64);
3221 pHlp->pfnPrintf(pHlp, " Pointer = %#x\n", PprLogBTailPtr.n.u15Ptr);
3222 }
3223 /* Event Log B Head Pointer. */
3224 {
3225 EVT_LOG_B_HEAD_PTR_T const EvtLogBHeadPtr = pThis->EvtLogBHeadPtr;
3226 pHlp->pfnPrintf(pHlp, " Event Log B Head Pointer = %#RX64\n", EvtLogBHeadPtr.u64);
3227 pHlp->pfnPrintf(pHlp, " Pointer = %#x\n", EvtLogBHeadPtr.n.u15Ptr);
3228 }
3229 /* Event Log B Tail Pointer. */
3230 {
3231 EVT_LOG_B_TAIL_PTR_T const EvtLogBTailPtr = pThis->EvtLogBTailPtr;
3232 pHlp->pfnPrintf(pHlp, " Event Log B Tail Pointer = %#RX64\n", EvtLogBTailPtr.u64);
3233 pHlp->pfnPrintf(pHlp, " Pointer = %#x\n", EvtLogBTailPtr.n.u15Ptr);
3234 }
3235 /* PPR Log Auto Response Register. */
3236 {
3237 PPR_LOG_AUTO_RESP_T const PprLogAutoResp = pThis->PprLogAutoResp;
3238 pHlp->pfnPrintf(pHlp, " PPR Log Auto Response Register = %#RX64\n", PprLogAutoResp.u64);
3239 if (fVerbose)
3240 {
3241 pHlp->pfnPrintf(pHlp, " Code = %#x\n", PprLogAutoResp.n.u4AutoRespCode);
3242 pHlp->pfnPrintf(pHlp, " Mask Gen. = %RTbool\n", PprLogAutoResp.n.u1AutoRespMaskGen);
3243 }
3244 }
3245 /* PPR Log Overflow Early Warning Indicator Register. */
3246 {
3247 PPR_LOG_OVERFLOW_EARLY_T const PprLogOverflowEarly = pThis->PprLogOverflowEarly;
3248 pHlp->pfnPrintf(pHlp, " PPR Log overflow early warning = %#RX64\n", PprLogOverflowEarly.u64);
3249 if (fVerbose)
3250 {
3251 pHlp->pfnPrintf(pHlp, " Threshold = %#x\n", PprLogOverflowEarly.n.u15Threshold);
3252 pHlp->pfnPrintf(pHlp, " Interrupt enable = %RTbool\n", PprLogOverflowEarly.n.u1IntrEn);
3253 pHlp->pfnPrintf(pHlp, " Enable = %RTbool\n", PprLogOverflowEarly.n.u1Enable);
3254 }
3255 }
3256 /* PPR Log Overflow Early Warning Indicator Register. */
3257 {
3258 PPR_LOG_OVERFLOW_EARLY_T const PprLogBOverflowEarly = pThis->PprLogBOverflowEarly;
3259 pHlp->pfnPrintf(pHlp, " PPR Log B overflow early warning = %#RX64\n", PprLogBOverflowEarly.u64);
3260 if (fVerbose)
3261 {
3262 pHlp->pfnPrintf(pHlp, " Threshold = %#x\n", PprLogBOverflowEarly.n.u15Threshold);
3263 pHlp->pfnPrintf(pHlp, " Interrupt enable = %RTbool\n", PprLogBOverflowEarly.n.u1IntrEn);
3264 pHlp->pfnPrintf(pHlp, " Enable = %RTbool\n", PprLogBOverflowEarly.n.u1Enable);
3265 }
3266 }
3267}
3268
3269
3270/**
3271 * @callback_method_impl{FNSSMDEVSAVEEXEC}
3272 */
3273static DECLCALLBACK(int) iommuAmdR3SaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
3274{
3275 /** @todo IOMMU: Save state. */
3276 RT_NOREF2(pDevIns, pSSM);
3277 return VERR_NOT_IMPLEMENTED;
3278}
3279
3280
3281/**
3282 * @callback_method_impl{FNSSMDEVLOADEXEC}
3283 */
3284static DECLCALLBACK(int) iommuAmdR3LoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
3285{
3286 /** @todo IOMMU: Load state. */
3287 RT_NOREF4(pDevIns, pSSM, uVersion, uPass);
3288 return VERR_NOT_IMPLEMENTED;
3289}
3290
3291
3292/**
3293 * @interface_method_impl{PDMDEVREG,pfnReset}
3294 */
3295static DECLCALLBACK(void) iommuAmdR3Reset(PPDMDEVINS pDevIns)
3296{
3297 /*
3298 * Resets read-write portion of the IOMMU state.
3299 *
3300 * State data not initialized here is expected to be initialized during
3301 * device construction and remain read-only through the lifetime of the VM.
3302 */
3303 PIOMMU pThis = PDMDEVINS_2_DATA(pDevIns, PIOMMU);
3304 Assert(pThis);
3305
3306 PPDMPCIDEV pPciDev = pDevIns->apPciDevs[0];
3307 PDMPCIDEV_ASSERT_VALID(pDevIns, pPciDev);
3308
3309 pThis->DevTabBaseAddr.u64 = 0;
3310 pThis->CmdBufBaseAddr.u64 = 0;
3311 pThis->EvtLogBaseAddr.u64 = 0;
3312 pThis->Ctrl.u64 = 0;
3313 pThis->ExclRangeBaseAddr.u64 = 0;
3314 pThis->ExclRangeLimit.u64 = 0;
3315 pThis->ExtFeat.n.u1PrefetchSup = 0;
3316 pThis->ExtFeat.n.u1PprSup = 0;
3317 pThis->ExtFeat.n.u1X2ApicSup = 0;
3318 pThis->ExtFeat.n.u1NoExecuteSup = 0;
3319 pThis->ExtFeat.n.u1GstTranslateSup = 0;
3320 pThis->ExtFeat.n.u1InvAllSup = 0;
3321 pThis->ExtFeat.n.u1GstVirtApicSup = 0;
3322 pThis->ExtFeat.n.u1HwErrorSup = 0;
3323 pThis->ExtFeat.n.u1PerfCounterSup = 0;
3324 pThis->ExtFeat.n.u2HostAddrTranslateSize = 0; /* Requires GstTranslateSup. */
3325 pThis->ExtFeat.n.u2GstAddrTranslateSize = 0; /* Requires GstTranslateSup. */
3326 pThis->ExtFeat.n.u2GstCr3RootTblLevel = 0; /* Requires GstTranslateSup. */
3327 pThis->ExtFeat.n.u2SmiFilterSup = 0;
3328 pThis->ExtFeat.n.u3SmiFilterCount = 0;
3329 pThis->ExtFeat.n.u3GstVirtApicModeSup = 0; /* Requires GstVirtApicSup */
3330 pThis->ExtFeat.n.u2DualPprLogSup = 0;
3331 pThis->ExtFeat.n.u2DualEvtLogSup = 0;
3332 pThis->ExtFeat.n.u5MaxPasidSup = 0; /* Requires GstTranslateSup. */
3333 pThis->ExtFeat.n.u1UserSupervisorSup = 0;
3334 pThis->ExtFeat.n.u2DevTabSegSup = 0;
3335 pThis->ExtFeat.n.u1PprLogOverflowWarn = 0;
3336 pThis->ExtFeat.n.u1PprAutoRespSup = 0;
3337 pThis->ExtFeat.n.u2MarcSup = 0;
3338 pThis->ExtFeat.n.u1BlockStopMarkSup = 0;
3339 pThis->ExtFeat.n.u1PerfOptSup = 0;
3340 pThis->ExtFeat.n.u1MsiCapMmioSup = 1;
3341 pThis->ExtFeat.n.u1GstIoSup = 0;
3342 pThis->ExtFeat.n.u1HostAccessSup = 0;
3343 pThis->ExtFeat.n.u1EnhancedPprSup = 0;
3344 pThis->ExtFeat.n.u1AttrForwardSup = 0;
3345 pThis->ExtFeat.n.u1HostDirtySup = 0;
3346 pThis->ExtFeat.n.u1InvIoTlbTypeSup = 0;
3347 pThis->ExtFeat.n.u1GstUpdateDisSup = 0;
3348 pThis->ExtFeat.n.u1ForcePhysDstSup = 0;
3349 pThis->PprLogBaseAddr.u64 = 0;
3350 pThis->HwEvtHi.u64 = 0;
3351 pThis->HwEvtLo = 0;
3352 pThis->HwEvtStatus.u64 = 0;
3353 pThis->GALogBaseAddr.n.u40GALogBase = 0;
3354 pThis->GALogBaseAddr.n.u4GALogLen = 8;
3355 pThis->GALogTailAddr.u64 = 0;
3356 pThis->PprLogBBaseAddr.n.u40PprLogBase = 0;
3357 pThis->PprLogBBaseAddr.n.u4PprLogLen = 8;
3358 pThis->EvtLogBBaseAddr.n.u40EvtBase = 0;
3359 pThis->EvtLogBBaseAddr.n.u4EvtLen = 8;
3360 memset(&pThis->DevTabSeg[0], 0, sizeof(pThis->DevTabSeg));
3361 pThis->DevSpecificFeat.u64 = 0;
3362 pThis->DevSpecificCtrl.u64 = 0;
3363 pThis->DevSpecificStatus.u64 = 0;
3364 pThis->MsiMiscInfo.u64 = 0;
3365 pThis->MsiCapHdr.u32 = PDMPciDevGetDWord(pPciDev, IOMMU_PCI_OFF_MSI_CAP_HDR);
3366 pThis->MsiAddr.u64 = 0;
3367 pThis->MsiData.u32 = 0;
3368 pThis->MsiMapCapHdr.u32 = 0;
3369 pThis->PerfOptCtrl.u32 = 0;
3370 pThis->XtGenIntrCtrl.u64 = 0;
3371 pThis->XtPprIntrCtrl.u64 = 0;
3372 pThis->XtGALogIntrCtrl.u64 = 0;
3373 memset(&pThis->aMarcApers[0], 0, sizeof(pThis->aMarcApers));
3374 pThis->RsvdReg = 0;
3375 pThis->CmdBufHeadPtr.u64 = 0;
3376 pThis->CmdBufTailPtr.u64 = 0;
3377 pThis->EvtLogHeadPtr.u64 = 0;
3378 pThis->EvtLogTailPtr.u64 = 0;
3379 pThis->Status.u64 = 0;
3380 pThis->PprLogHeadPtr.u64 = 0;
3381 pThis->PprLogTailPtr.u64 = 0;
3382 pThis->GALogHeadPtr.u64 = 0;
3383 pThis->GALogTailPtr.u64 = 0;
3384 pThis->PprLogBHeadPtr.u64 = 0;
3385 pThis->PprLogBTailPtr.u64 = 0;
3386 pThis->EvtLogBHeadPtr.u64 = 0;
3387 pThis->EvtLogBTailPtr.u64 = 0;
3388 pThis->PprLogAutoResp.u64 = 0;
3389 pThis->PprLogOverflowEarly.u64 = 0;
3390 pThis->PprLogBOverflowEarly.u64 = 0;
3391
3392 PDMPciDevSetDWord(pPciDev, IOMMU_PCI_OFF_BASE_ADDR_REG_LO, 0);
3393 PDMPciDevSetDWord(pPciDev, IOMMU_PCI_OFF_BASE_ADDR_REG_HI, 0);
3394 PDMPciDevSetDWord(pPciDev, IOMMU_PCI_OFF_RANGE_REG, 0);
3395}
3396
3397
3398/**
3399 * @interface_method_impl{PDMDEVREG,pfnDestruct}
3400 */
3401static DECLCALLBACK(int) iommuAmdR3Destruct(PPDMDEVINS pDevIns)
3402{
3403 PDMDEV_CHECK_VERSIONS_RETURN_QUIET(pDevIns);
3404 PIOMMU pThis = PDMDEVINS_2_DATA(pDevIns, PIOMMU);
3405 LogFlowFunc(("\n"));
3406
3407 /* Close the command thread semaphore. */
3408 if (pThis->hEvtCmdThread != NIL_SUPSEMEVENT)
3409 {
3410 PDMDevHlpSUPSemEventClose(pDevIns, pThis->hEvtCmdThread);
3411 pThis->hEvtCmdThread = NIL_SUPSEMEVENT;
3412 }
3413 return VINF_SUCCESS;
3414}
3415
3416
3417/**
3418 * @interface_method_impl{PDMDEVREG,pfnConstruct}
3419 */
3420static DECLCALLBACK(int) iommuAmdR3Construct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
3421{
3422 NOREF(iInstance);
3423
3424 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
3425 PIOMMU pThis = PDMDEVINS_2_DATA(pDevIns, PIOMMU);
3426 PIOMMUCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PIOMMUCC);
3427 PCPDMDEVHLPR3 pHlp = pDevIns->pHlpR3;
3428 int rc;
3429 LogFlowFunc(("\n"));
3430
3431 pThisCC->pDevInsR3 = pDevIns;
3432
3433 /*
3434 * Validate and read the configuration.
3435 */
3436 PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns, "Device|Function", "");
3437
3438 uint8_t uPciDevice;
3439 rc = pHlp->pfnCFGMQueryU8Def(pCfg, "Device", &uPciDevice, 0);
3440 if (RT_FAILURE(rc))
3441 return PDMDEV_SET_ERROR(pDevIns, rc, N_("IOMMU: Failed to query \"Device\""));
3442
3443 uint8_t uPciFunction;
3444 rc = pHlp->pfnCFGMQueryU8Def(pCfg, "Function", &uPciFunction, 2);
3445 if (RT_FAILURE(rc))
3446 return PDMDEV_SET_ERROR(pDevIns, rc, N_("IOMMU: Failed to query \"Function\""));
3447
3448 /*
3449 * Initialize read-only PCI configuration space.
3450 */
3451 PPDMPCIDEV pPciDev = pDevIns->apPciDevs[0];
3452 PDMPCIDEV_ASSERT_VALID(pDevIns, pPciDev);
3453
3454 /* Header. */
3455 PDMPciDevSetVendorId(pPciDev, IOMMU_PCI_VENDOR_ID); /* AMD */
3456 PDMPciDevSetDeviceId(pPciDev, IOMMU_PCI_DEVICE_ID); /* VirtualBox IOMMU device */
3457 PDMPciDevSetCommand(pPciDev, 0); /* Command */
3458 PDMPciDevSetStatus(pPciDev, 0x5); /* Status - CapList supported */
3459 PDMPciDevSetRevisionId(pPciDev, IOMMU_PCI_REVISION_ID); /* VirtualBox specific device implementation revision */
3460 PDMPciDevSetClassBase(pPciDev, 0x08); /* System Base Peripheral */
3461 PDMPciDevSetClassSub(pPciDev, 0x06); /* IOMMU */
3462 PDMPciDevSetClassProg(pPciDev, 0x00); /* IOMMU Programming interface */
3463 PDMPciDevSetHeaderType(pPciDev, 0x00); /* Single function, type 0. */
3464 PDMPciDevSetSubSystemId(pPciDev, IOMMU_PCI_DEVICE_ID); /* AMD */
3465 PDMPciDevSetSubSystemVendorId(pPciDev, IOMMU_PCI_VENDOR_ID); /* VirtualBox IOMMU device */
3466 PDMPciDevSetCapabilityList(pPciDev, IOMMU_PCI_OFF_CAP_HDR); /* Offset into capability registers. */
3467 PDMPciDevSetInterruptPin(pPciDev, 0x01); /* INTA#. */
3468 PDMPciDevSetInterruptLine(pPciDev, 0x00); /* For software compatibility; no effect on hardware. */
3469 /* Capability Header. */
3470 PDMPciDevSetDWord(pPciDev, IOMMU_PCI_OFF_CAP_HDR,
3471 RT_BF_MAKE(IOMMU_BF_CAPHDR_CAP_ID, 0xf) /* RO - Secure Device capability block */
3472 | RT_BF_MAKE(IOMMU_BF_CAPHDR_CAP_PTR, IOMMU_PCI_OFF_MSI_CAP_HDR) /* RO - Offset to next capability block */
3473 | RT_BF_MAKE(IOMMU_BF_CAPHDR_CAP_TYPE, 0x3) /* RO - IOMMU capability block */
3474 | RT_BF_MAKE(IOMMU_BF_CAPHDR_CAP_REV, 0x1) /* RO - IOMMU interface revision */
3475 | RT_BF_MAKE(IOMMU_BF_CAPHDR_IOTLB_SUP, 0x0) /* RO - Remote IOTLB support */
3476 | RT_BF_MAKE(IOMMU_BF_CAPHDR_HT_TUNNEL, 0x0) /* RO - HyperTransport Tunnel support */
3477 | RT_BF_MAKE(IOMMU_BF_CAPHDR_NP_CACHE, 0x0) /* RO - Cache NP page table entries */
3478 | RT_BF_MAKE(IOMMU_BF_CAPHDR_EFR_SUP, 0x1) /* RO - Extended Feature Register support */
3479 | RT_BF_MAKE(IOMMU_BF_CAPHDR_CAP_EXT, 0x1)); /* RO - Misc. Information Register support */
3480 /* Base Address Low Register. */
3481 PDMPciDevSetDWord(pPciDev, IOMMU_PCI_OFF_BASE_ADDR_REG_LO, 0x0); /* RW - Base address (Lo) and enable bit. */
3482 /* Base Address High Register. */
3483 PDMPciDevSetDWord(pPciDev, IOMMU_PCI_OFF_BASE_ADDR_REG_HI, 0x0); /* RW - Base address (Hi) */
3484 /* IOMMU Range Register. */
3485 PDMPciDevSetDWord(pPciDev, IOMMU_PCI_OFF_RANGE_REG, 0x0); /* RW - Range register. */
3486 /* Misc. Information Register 0. */
3487 PDMPciDevSetDWord(pPciDev, IOMMU_PCI_OFF_MISCINFO_REG_0,
3488 RT_BF_MAKE(IOMMU_BF_MISCINFO_0_MSI_NUM, 0x0) /* RO - MSI number */
3489 | RT_BF_MAKE(IOMMU_BF_MISCINFO_0_GVA_SIZE, 0x2) /* RO - Guest Virt. Addr size (2=48 bits) */
3490 | RT_BF_MAKE(IOMMU_BF_MISCINFO_0_PA_SIZE, 0x30) /* RO - Physical Addr size (48 bits) */
3491 | RT_BF_MAKE(IOMMU_BF_MISCINFO_0_VA_SIZE, 0x40) /* RO - Virt. Addr size (64 bits) */
3492 | RT_BF_MAKE(IOMMU_BF_MISCINFO_0_HT_ATS_RESV, 0x0) /* RW - HT ATS reserved */
3493 | RT_BF_MAKE(IOMMU_BF_MISCINFO_0_MSI_NUM_PPR, 0x0)); /* RW - PPR interrupt number */
3494 /* Misc. Information Register 1. */
3495 PDMPciDevSetDWord(pPciDev, IOMMU_PCI_OFF_MISCINFO_REG_0, 0);
3496 /* MSI Capability Header register. */
3497#if 0
3498 PDMPciDevSetDWord(pPciDev, IOMMU_PCI_OFF_MSI_CAP_HDR,
3499 RT_BF_MAKE(IOMMU_BF_MSI_CAPHDR_CAP_ID, 0x5) /* RO - Capability ID. */
3500 | RT_BF_MAKE(IOMMU_BF_MSI_CAPHDR_CAP_PTR, offMsiMapCapHdr) /* RO - Offset to next capability block */
3501 | RT_BF_MAKE(IOMMU_BF_MSI_CAPHDR_EN, 0x0) /* RW - MSI capability enable */
3502 | RT_BF_MAKE(IOMMU_BF_MSI_CAPHDR_MULTMESS_CAP, 0x0) /* RO - MSI multi-message capability */
3503 | RT_BF_MAKE(IOMMU_BF_MSI_CAPHDR_MULTMESS_EN, 0x0) /* RW - MSI multi-message enable */
3504 | RT_BF_MAKE(IOMMU_BF_MSI_CAPHDR_64BIT_EN, 0x1)); /* RO - MSI 64-bit enable */
3505#else
3506 PDMMSIREG MsiReg;
3507 RT_ZERO(MsiReg);
3508 MsiReg.cMsiVectors = 1;
3509 MsiReg.iMsiCapOffset = IOMMU_PCI_OFF_MSI_CAP_HDR;
3510 MsiReg.iMsiNextOffset = 0; /* IOMMU_PCI_OFF_MSI_MAP_CAP_HDR */
3511 rc = PDMDevHlpPCIRegisterMsi(pDevIns, &MsiReg);
3512 AssertRCReturn(rc, rc);
3513 /* This is later copied to its MMIO shadow register (MsiCapHdr), see iommuAmdR3Init. */
3514#endif
3515
3516 /* These read-write PCI config registers are initialized in iommuAmdR3Init. */
3517#if 0
3518 /* MSI Address Lo. */
3519 PDMPciDevSetDWord(pPciDev, IOMMU_PCI_OFF_MSI_ADDR_LO, 0); /* RW - MSI message address (Lo). */
3520 /* MSI Address Hi. */
3521 PDMPciDevSetDWord(pPciDev, IOMMU_PCI_OFF_MSI_ADDR_HI, 0); /* RW - MSI message address (Hi). */
3522 /* MSI Data. */
3523 PDMPciDevSetDWord(pPciDev, IOMMU_PCI_OFF_MSI_DATA, 0); /* RW - MSI data. */
3524#endif
3525
3526#if 0
3527 /** @todo IOMMU: I don't know if we need to support this, enable later if
3528 * required. */
3529 /* MSI Mapping Capability Header register. */
3530 PDMPciDevSetDWord(pPciDev, IOMMU_PCI_OFF_MSI_MAP_CAP_HDR,
3531 RT_BF_MAKE(IOMMU_BF_MSI_MAP_CAPHDR_CAP_ID, 0x8) /* RO - Capability ID */
3532 | RT_BF_MAKE(IOMMU_BF_MSI_MAP_CAPHDR_CAP_PTR, 0x0) /* RO - Offset to next capability (NULL) */
3533 | RT_BF_MAKE(IOMMU_BF_MSI_MAP_CAPHDR_EN, 0x1) /* RO - MSI mapping capability enable */
3534 | RT_BF_MAKE(IOMMU_BF_MSI_MAP_CAPHDR_FIXED, 0x1) /* RO - MSI mapping range is fixed */
3535 | RT_BF_MAKE(IOMMU_BF_MSI_MAP_CAPHDR_CAP_TYPE, 0x15)); /* RO - MSI mapping capability */
3536 /* When implementing don't forget to copy this to its MMIO shadow register (MsiMapCapHdr) in iommuAmdR3Init. */
3537#endif
3538
3539 /*
3540 * Register the PCI function with PDM.
3541 */
3542 rc = PDMDevHlpPCIRegisterEx(pDevIns, pPciDev, 0 /* fFlags */, uPciDevice, uPciFunction, "amd-iommu");
3543 AssertLogRelRCReturn(rc, rc);
3544
3545 /*
3546 * Intercept PCI config. space accesses.
3547 */
3548 rc = PDMDevHlpPCIInterceptConfigAccesses(pDevIns, pPciDev, iommuAmdR3PciConfigRead, iommuAmdR3PciConfigWrite);
3549 AssertLogRelRCReturn(rc, rc);
3550
3551 /*
3552 * Register the MMIO region.
3553 */
3554 rc = PDMDevHlpMmioCreate(pDevIns, IOMMU_MMIO_REGION_SIZE, pPciDev, 0 /* iPciRegion */, iommuAmdMmioWrite, iommuAmdMmioRead,
3555 NULL /* pvUser */, IOMMMIO_FLAGS_READ_DWORD_QWORD | IOMMMIO_FLAGS_WRITE_DWORD_QWORD_ZEROED,
3556 "AMD-IOMMU", &pThis->hMmio);
3557 AssertLogRelRCReturn(rc, rc);
3558
3559 /*
3560 * Register saved state.
3561 */
3562 rc = PDMDevHlpSSMRegisterEx(pDevIns, IOMMU_SAVED_STATE_VERSION, sizeof(IOMMU), NULL,
3563 NULL, NULL, NULL,
3564 NULL, iommuAmdR3SaveExec, NULL,
3565 NULL, iommuAmdR3LoadExec, NULL);
3566 AssertLogRelRCReturn(rc, rc);
3567
3568 /*
3569 * Register debugger info item.
3570 */
3571 rc = PDMDevHlpDBGFInfoRegister(pDevIns, "iommu", "Display IOMMU state.", iommuAmdR3DbgInfo);
3572 AssertLogRelRCReturn(rc, rc);
3573
3574 /*
3575 * Create the command thread and its event semaphore.
3576 */
3577 rc = PDMDevHlpThreadCreate(pDevIns, &pThisCC->pCmdThread, pThis, iommuAmdR3CmdThread, iommuAmdR3CmdThreadWakeUp,
3578 0 /* cbStack */, RTTHREADTYPE_IO, "AMD-IOMMU");
3579 AssertLogRelRCReturn(rc, rc);
3580
3581 rc = PDMDevHlpSUPSemEventCreate(pDevIns, &pThis->hEvtCmdThread);
3582 AssertLogRelRCReturn(rc, rc);
3583
3584 /*
3585 * Initialize parts of the IOMMU state as it would during reset.
3586 * Must be called -after- initializing PCI config. space registers.
3587 */
3588 iommuAmdR3Reset(pDevIns);
3589
3590 return VINF_SUCCESS;
3591}
3592
3593# else /* !IN_RING3 */
3594
3595/**
3596 * @callback_method_impl{PDMDEVREGR0,pfnConstruct}
3597 */
3598static DECLCALLBACK(int) iommuAmdRZConstruct(PPDMDEVINS pDevIns)
3599{
3600 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
3601 PIOMMU pThis = PDMDEVINS_2_DATA(pDevIns, PIOMMU);
3602 PIOMMUCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PIOMMUCC);
3603
3604 pThisCC->CTX_SUFF(pDevIns) = pDevIns;
3605
3606 int rc = PDMDevHlpMmioSetUpContext(pDevIns, pThis->hMmio, iommuAmdMmioWrite, iommuAmdMmioRead, NULL /* pvUser */);
3607 AssertRCReturn(rc, rc);
3608
3609 return VINF_SUCCESS;
3610}
3611
3612# endif /* !IN_RING3 */
3613
3614/**
3615 * The device registration structure.
3616 */
3617const PDMDEVREG g_DeviceIommuAmd =
3618{
3619 /* .u32Version = */ PDM_DEVREG_VERSION,
3620 /* .uReserved0 = */ 0,
3621 /* .szName = */ "iommu-amd",
3622 /* .fFlags = */ PDM_DEVREG_FLAGS_DEFAULT_BITS | PDM_DEVREG_FLAGS_RZ | PDM_DEVREG_FLAGS_NEW_STYLE,
3623 /* .fClass = */ PDM_DEVREG_CLASS_BUS_ISA, /* Instantiate after PDM_DEVREG_CLASS_BUS_PCI */
3624 /* .cMaxInstances = */ ~0U,
3625 /* .uSharedVersion = */ 42,
3626 /* .cbInstanceShared = */ sizeof(IOMMU),
3627 /* .cbInstanceCC = */ sizeof(IOMMUCC),
3628 /* .cbInstanceRC = */ sizeof(IOMMURC),
3629 /* .cMaxPciDevices = */ 1,
3630 /* .cMaxMsixVectors = */ 0,
3631 /* .pszDescription = */ "IOMMU (AMD)",
3632#if defined(IN_RING3)
3633 /* .pszRCMod = */ "VBoxDDRC.rc",
3634 /* .pszR0Mod = */ "VBoxDDR0.r0",
3635 /* .pfnConstruct = */ iommuAmdR3Construct,
3636 /* .pfnDestruct = */ iommuAmdR3Destruct,
3637 /* .pfnRelocate = */ NULL,
3638 /* .pfnMemSetup = */ NULL,
3639 /* .pfnPowerOn = */ NULL,
3640 /* .pfnReset = */ iommuAmdR3Reset,
3641 /* .pfnSuspend = */ NULL,
3642 /* .pfnResume = */ NULL,
3643 /* .pfnAttach = */ NULL,
3644 /* .pfnDetach = */ NULL,
3645 /* .pfnQueryInterface = */ NULL,
3646 /* .pfnInitComplete = */ NULL,
3647 /* .pfnPowerOff = */ NULL,
3648 /* .pfnSoftReset = */ NULL,
3649 /* .pfnReserved0 = */ NULL,
3650 /* .pfnReserved1 = */ NULL,
3651 /* .pfnReserved2 = */ NULL,
3652 /* .pfnReserved3 = */ NULL,
3653 /* .pfnReserved4 = */ NULL,
3654 /* .pfnReserved5 = */ NULL,
3655 /* .pfnReserved6 = */ NULL,
3656 /* .pfnReserved7 = */ NULL,
3657#elif defined(IN_RING0)
3658 /* .pfnEarlyConstruct = */ NULL,
3659 /* .pfnConstruct = */ iommuAmdRZConstruct,
3660 /* .pfnDestruct = */ NULL,
3661 /* .pfnFinalDestruct = */ NULL,
3662 /* .pfnRequest = */ NULL,
3663 /* .pfnReserved0 = */ NULL,
3664 /* .pfnReserved1 = */ NULL,
3665 /* .pfnReserved2 = */ NULL,
3666 /* .pfnReserved3 = */ NULL,
3667 /* .pfnReserved4 = */ NULL,
3668 /* .pfnReserved5 = */ NULL,
3669 /* .pfnReserved6 = */ NULL,
3670 /* .pfnReserved7 = */ NULL,
3671#elif defined(IN_RC)
3672 /* .pfnConstruct = */ iommuAmdRZConstruct,
3673 /* .pfnReserved0 = */ NULL,
3674 /* .pfnReserved1 = */ NULL,
3675 /* .pfnReserved2 = */ NULL,
3676 /* .pfnReserved3 = */ NULL,
3677 /* .pfnReserved4 = */ NULL,
3678 /* .pfnReserved5 = */ NULL,
3679 /* .pfnReserved6 = */ NULL,
3680 /* .pfnReserved7 = */ NULL,
3681#else
3682# error "Not in IN_RING3, IN_RING0 or IN_RC!"
3683#endif
3684 /* .u32VersionEnd = */ PDM_DEVREG_VERSION
3685};
3686
3687#endif /* !VBOX_DEVICE_STRUCT_TESTCASE */
3688
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette