VirtualBox

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

Last change on this file since 83665 was 83665, 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: 159.3 KB
Line 
1/* $Id: DevIommuAmd.cpp 83665 2020-04-10 09:33:38Z 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
1134/**
1135 * IOMMU Exclusion Range Limit Register (MMIO).
1136 * In accordance with the AMD spec.
1137 */
1138typedef union
1139{
1140 struct
1141 {
1142 RT_GCC_EXTENSION uint64_t u12Rsvd0 : 12; /**< Bits 11:0 - Reserved. */
1143 RT_GCC_EXTENSION uint64_t u40ExclLimit : 40; /**< Bits 51:12 - Exclusion Range Limit. */
1144 RT_GCC_EXTENSION uint64_t u12Rsvd1 : 12; /**< Bits 63:52 - Reserved. */
1145 } n;
1146 /** The 64-bit unsigned integer view. */
1147 uint64_t u64;
1148} IOMMU_EXCL_RANGE_LIMIT_T;
1149AssertCompileSize(IOMMU_EXCL_RANGE_LIMIT_T, 8);
1150
1151/**
1152 * IOMMU Extended Feature Register (MMIO).
1153 * In accordance with the AMD spec.
1154 */
1155typedef union
1156{
1157 struct
1158 {
1159 uint32_t u1PrefetchSup : 1; /**< Bit 0 - PreFSup: Prefetch Support. */
1160 uint32_t u1PprSup : 1; /**< Bit 1 - PPRSup: Peripheral Page Request Support. */
1161 uint32_t u1X2ApicSup : 1; /**< Bit 2 - XTSup: x2Apic Support. */
1162 uint32_t u1NoExecuteSup : 1; /**< Bit 3 - NXSup: No-Execute and Privilege Level Support. */
1163 uint32_t u1GstTranslateSup : 1; /**< Bit 4 - GTSup: Guest Translations Support. */
1164 uint32_t u1Rsvd0 : 1; /**< Bit 5 - Reserved. */
1165 uint32_t u1InvAllSup : 1; /**< Bit 6 - IASup: Invalidate-All Support. */
1166 uint32_t u1GstVirtApicSup : 1; /**< Bit 7 - GASup: Guest Virtual-APIC Support. */
1167 uint32_t u1HwErrorSup : 1; /**< Bit 8 - HESup: Hardware Error registers Support. */
1168 uint32_t u1PerfCounterSup : 1; /**< Bit 8 - PCSup: Performance Counter Support. */
1169 uint32_t u2HostAddrTranslateSize : 2; /**< Bits 11:10 - HATS: Host Address Translation Size. */
1170 uint32_t u2GstAddrTranslateSize : 2; /**< Bits 13:12 - GATS: Guest Address Translation Size. */
1171 uint32_t u2GstCr3RootTblLevel : 2; /**< Bits 15:14 - GLXSup: Guest CR3 Root Table Level (Max) Size Support. */
1172 uint32_t u2SmiFilterSup : 2; /**< Bits 17:16 - SmiFSup: SMI Filter Register Support. */
1173 uint32_t u3SmiFilterCount : 3; /**< Bits 20:18 - SmiFRC: SMI Filter Register Count. */
1174 uint32_t u3GstVirtApicModeSup : 3; /**< Bits 23:21 - GAMSup: Guest Virtual-APIC Modes Supported. */
1175 uint32_t u2DualPprLogSup : 2; /**< Bits 25:24 - DualPprLogSup: Dual Peripheral Page Request Log Support. */
1176 uint32_t u2Rsvd0 : 2; /**< Bits 27:26 - Reserved. */
1177 uint32_t u2DualEvtLogSup : 2; /**< Bits 29:28 - DualEventLogSup: Dual Event Log Support. */
1178 uint32_t u2Rsvd1 : 2; /**< Bits 31:30 - Reserved. */
1179 uint32_t u5MaxPasidSup : 5; /**< Bits 36:32 - PASMax: Maximum PASID Supported. */
1180 uint32_t u1UserSupervisorSup : 1; /**< Bit 37 - USSup: User/Supervisor Page Protection Support. */
1181 uint32_t u2DevTabSegSup : 2; /**< Bits 39:38 - DevTlbSegSup: Segmented Device Table Support. */
1182 uint32_t u1PprLogOverflowWarn : 1; /**< Bit 40 - PprOvrflwEarlySup: PPR Log Overflow Early Warning Support. */
1183 uint32_t u1PprAutoRespSup : 1; /**< Bit 41 - PprAutoRspSup: PPR Automatic Response Support. */
1184 uint32_t u2MarcSup : 2; /**< Bit 43:42 - MarcSup: Memory Access Routing and Control Support. */
1185 uint32_t u1BlockStopMarkSup : 1; /**< Bit 44 - BlkStopMarkSup: Block StopMark messages Support. */
1186 uint32_t u1PerfOptSup : 1; /**< Bit 45 - PerfOptSup: IOMMU Performance Optimization Support. */
1187 uint32_t u1MsiCapMmioSup : 1; /**< Bit 46 - MsiCapMmioSup: MSI Capability Register MMIO Access Support. */
1188 uint32_t u1Rsvd1 : 1; /**< Bit 47 - Reserved. */
1189 uint32_t u1GstIoSup : 1; /**< Bit 48 - GIoSup: Guest I/O Protection Support. */
1190 uint32_t u1HostAccessSup : 1; /**< Bit 49 - HASup: Host Access Support. */
1191 uint32_t u1EnhancedPprSup : 1; /**< Bit 50 - EPHSup: Enhanced Peripheral Page Request Handling Support. */
1192 uint32_t u1AttrForwardSup : 1; /**< Bit 51 - AttrFWSup: Attribute Forward Support. */
1193 uint32_t u1HostDirtySup : 1; /**< Bit 52 - HDSup: Host Dirty Support. */
1194 uint32_t u1Rsvd2 : 1; /**< Bit 53 - Reserved. */
1195 uint32_t u1InvIoTlbTypeSup : 1; /**< Bit 54 - InvIotlbTypeSup: Invalidate IOTLB Type Support. */
1196 uint32_t u6Rsvd0 : 6; /**< Bit 60:55 - Reserved. */
1197 uint32_t u1GstUpdateDisSup : 1; /**< Bit 61 - GAUpdateDisSup: Disable hardware update on GPT Support. */
1198 uint32_t u1ForcePhysDstSup : 1; /**< Bit 62 - ForcePhyDestSup: Force Phys. Dst. Mode for Remapped Intr. */
1199 uint32_t u1Rsvd3 : 1; /**< Bit 63 - Reserved. */
1200 } n;
1201 /** The 64-bit unsigned integer view. */
1202 uint64_t u64;
1203} IOMMU_EXT_FEAT_T;
1204AssertCompileSize(IOMMU_EXT_FEAT_T, 8);
1205
1206/**
1207 * Peripheral Page Request Log Base Address Register (MMIO).
1208 * In accordance with the AMD spec.
1209 */
1210typedef union
1211{
1212 struct
1213 {
1214 RT_GCC_EXTENSION uint64_t u12Rsvd0 : 12; /**< Bit 11:0 - Reserved. */
1215 RT_GCC_EXTENSION uint64_t u40PprLogBase : 40; /**< Bits 51:12 - PPRLogBase: Peripheral Page Request Log Base Address. */
1216 RT_GCC_EXTENSION uint64_t u4Rsvd0 : 4; /**< Bits 55:52 - Reserved. */
1217 RT_GCC_EXTENSION uint64_t u4PprLogLen : 4; /**< Bits 59:56 - PPRLogLen: Peripheral Page Request Log Length. */
1218 RT_GCC_EXTENSION uint64_t u4Rsvd1 : 4; /**< Bits 63:60 - Reserved. */
1219 } n;
1220 /** The 64-bit unsigned integer view. */
1221 uint64_t u64;
1222} PPR_LOG_BAR_T;
1223AssertCompileSize(PPR_LOG_BAR_T, 8);
1224
1225/**
1226 * IOMMU Hardware Event Upper Register (MMIO).
1227 * In accordance with the AMD spec.
1228 */
1229typedef union
1230{
1231 struct
1232 {
1233 RT_GCC_EXTENSION uint64_t u60FirstOperand : 60; /**< Bits 59:0 - First event code dependent operand. */
1234 RT_GCC_EXTENSION uint64_t u4EvtCode : 4; /**< Bits 63:60 - Event Code. */
1235 } n;
1236 /** The 64-bit unsigned integer view. */
1237 uint64_t u64;
1238} IOMMU_HW_EVT_HI_T;
1239AssertCompileSize(IOMMU_HW_EVT_HI_T, 8);
1240
1241/**
1242 * IOMMU Hardware Event Lower Register (MMIO).
1243 * In accordance with the AMD spec.
1244 */
1245typedef uint64_t IOMMU_HW_EVT_LO_T;
1246
1247/**
1248 * IOMMU Hardware Event Status (MMIO).
1249 * In accordance with the AMD spec.
1250 */
1251typedef union
1252{
1253 struct
1254 {
1255 uint32_t u1Valid : 1; /**< Bit 0 - HEV: Hardware Event Valid. */
1256 uint32_t u1Overflow : 1; /**< Bit 1 - HEO: Hardware Event Overflow. */
1257 uint32_t u30Rsvd0 : 30; /**< Bits 31:2 - Reserved. */
1258 uint32_t u32Rsvd0; /**< Bits 63:32 - Reserved. */
1259 } n;
1260 /** The 64-bit unsigned integer view. */
1261 uint64_t u64;
1262} IOMMU_HW_EVT_STATUS_T;
1263AssertCompileSize(IOMMU_HW_EVT_STATUS_T, 8);
1264
1265/**
1266 * Guest Virtual-APIC Log Base Address Register (MMIO).
1267 * In accordance with the AMD spec.
1268 */
1269typedef union
1270{
1271 struct
1272 {
1273 RT_GCC_EXTENSION uint64_t u12Rsvd0 : 12; /**< Bit 11:0 - Reserved. */
1274 RT_GCC_EXTENSION uint64_t u40GALogBase : 40; /**< Bits 51:12 - GALogBase: Guest Virtual-APIC Log Base Address. */
1275 RT_GCC_EXTENSION uint64_t u4Rsvd0 : 4; /**< Bits 55:52 - Reserved. */
1276 RT_GCC_EXTENSION uint64_t u4GALogLen : 4; /**< Bits 59:56 - GALogLen: Guest Virtual-APIC Log Length. */
1277 RT_GCC_EXTENSION uint64_t u4Rsvd1 : 4; /**< Bits 63:60 - Reserved. */
1278 } n;
1279 /** The 64-bit unsigned integer view. */
1280 uint64_t u64;
1281} GALOG_BAR_T;
1282AssertCompileSize(GALOG_BAR_T, 8);
1283
1284/**
1285 * Guest Virtual-APIC Log Tail Address Register (MMIO).
1286 * In accordance with the AMD spec.
1287 */
1288typedef union
1289{
1290 struct
1291 {
1292 RT_GCC_EXTENSION uint64_t u3Rsvd0 : 3; /**< Bits 2:0 - Reserved. */
1293 RT_GCC_EXTENSION uint64_t u40GALogTailAddr : 48; /**< Bits 51:3 - GATAddr: Guest Virtual-APIC Tail Log Address. */
1294 RT_GCC_EXTENSION uint64_t u11Rsvd1 : 11; /**< Bits 63:52 - Reserved. */
1295 } n;
1296 /** The 64-bit unsigned integer view. */
1297 uint64_t u64;
1298} GALOG_TAIL_ADDR_T;
1299AssertCompileSize(GALOG_TAIL_ADDR_T, 8);
1300
1301/**
1302 * PPR Log B Base Address Register (MMIO).
1303 * In accordance with the AMD spec.
1304 * Currently identical to PPR_LOG_BAR_T.
1305 */
1306typedef PPR_LOG_BAR_T PPR_LOG_B_BAR_T;
1307
1308/**
1309 * Event Log B Base Address Register (MMIO).
1310 * In accordance with the AMD spec.
1311 * Currently identical to EVT_LOG_BAR_T.
1312 */
1313typedef EVT_LOG_BAR_T EVT_LOG_B_BAR_T;
1314
1315/**
1316 * Device Table Segment Register (MMIO).
1317 * In accordance with the AMD spec.
1318 */
1319typedef union
1320{
1321 struct
1322 {
1323 RT_GCC_EXTENSION uint64_t u8Size : 8; /**< Bits 7:0 - Size: Size of the Device Table segment. */
1324 RT_GCC_EXTENSION uint64_t u4Rsvd0 : 4; /**< Bits 11:8 - Reserved. */
1325 RT_GCC_EXTENSION uint64_t u40DevTabBase : 40; /**< Bits 51:12 - DevTabBase: Device Table Segment Base Address. */
1326 RT_GCC_EXTENSION uint64_t u12Rsvd0 : 12; /**< Bits 63:52 - Reserved. */
1327 } n;
1328 /** The 64-bit unsigned integer view. */
1329 uint64_t u64;
1330} DEV_TAB_SEG_BAR_T;
1331AssertCompileSize(DEV_TAB_SEG_BAR_T, 8);
1332
1333/**
1334 * Device-specific Feature Extension (DSFX) Register (MMIO).
1335 * In accordance with the AMD spec.
1336 */
1337typedef union
1338{
1339 struct
1340 {
1341 uint32_t u24DevSpecFeat : 24; /**< Bits 23:0 - DevSpecificFeatSupp: Implementation specific features. */
1342 uint32_t u4RevMinor : 4; /**< Bits 27:24 - RevMinor: Minor revision identifier. */
1343 uint32_t u4RevMajor : 4; /**< Bits 31:28 - RevMajor: Major revision identifier. */
1344 uint32_t u32Rsvd0; /**< Bits 63:32 - Reserved.*/
1345 } n;
1346 /** The 64-bit unsigned integer view. */
1347 uint64_t u64;
1348} DEV_SPECIFIC_FEAT_T;
1349AssertCompileSize(DEV_SPECIFIC_FEAT_T, 8);
1350
1351/**
1352 * Device-specific Control Extension (DSCX) Register (MMIO).
1353 * In accordance with the AMD spec.
1354 */
1355typedef union
1356{
1357 struct
1358 {
1359 uint32_t u24DevSpecCtrl : 24; /**< Bits 23:0 - DevSpecificFeatCntrl: Implementation specific control. */
1360 uint32_t u4RevMinor : 4; /**< Bits 27:24 - RevMinor: Minor revision identifier. */
1361 uint32_t u4RevMajor : 4; /**< Bits 31:28 - RevMajor: Major revision identifier. */
1362 uint32_t u32Rsvd0; /**< Bits 63:32 - Reserved.*/
1363 } n;
1364 /** The 64-bit unsigned integer view. */
1365 uint64_t u64;
1366} DEV_SPECIFIC_CTRL_T;
1367AssertCompileSize(DEV_SPECIFIC_CTRL_T, 8);
1368
1369/**
1370 * Device-specific Status Extension (DSSX) Register (MMIO).
1371 * In accordance with the AMD spec.
1372 */
1373typedef union
1374{
1375 struct
1376 {
1377 uint32_t u24DevSpecStatus : 24; /**< Bits 23:0 - DevSpecificFeatStatus: Implementation specific status. */
1378 uint32_t u4RevMinor : 4; /**< Bits 27:24 - RevMinor: Minor revision identifier. */
1379 uint32_t u4RevMajor : 4; /**< Bits 31:28 - RevMajor: Major revision identifier. */
1380 uint32_t u32Rsvd0; /**< Bits 63:32 - Reserved.*/
1381 } n;
1382 /** The 64-bit unsigned integer view. */
1383 uint64_t u64;
1384} DEV_SPECIFIC_STATUS_T;
1385AssertCompileSize(DEV_SPECIFIC_STATUS_T, 8);
1386
1387/**
1388 * MSI Information Register 0 and 1 (PCI) / MSI Vector Register 0 and 1 (MMIO).
1389 * In accordance with the AMD spec.
1390 */
1391typedef union
1392{
1393 struct
1394 {
1395 uint32_t u5MsiNumEvtLog : 5; /**< Bits 4:0 - MsiNum: Event Log MSI message number. */
1396 uint32_t u3GstVirtAddrSize: 3; /**< Bits 7:5 - GVAsize: Guest Virtual Address Size. */
1397 uint32_t u7PhysAddrSize : 7; /**< Bits 14:8 - PAsize: Physical Address Size. */
1398 uint32_t u7VirtAddrSize : 7; /**< Bits 21:15 - VAsize: Virtual Address Size. */
1399 uint32_t u1HtAtsResv: 1; /**< Bit 22 - HtAtsResv: HyperTransport ATS Response Address range Reserved. */
1400 uint32_t u4Rsvd0 : 4; /**< Bits 26:23 - Reserved. */
1401 uint32_t u5MsiNumPpr : 5; /**< Bits 31:27 - MsiNumPPR: Peripheral Page Request MSI message number. */
1402 uint32_t u5MsiNumGa : 5; /**< Bits 36:32 - MsiNumGa: MSI message number for guest virtual-APIC log. */
1403 uint32_t u27Rsvd0: 27; /**< Bits 63:37 - Reserved. */
1404 } n;
1405 /** The 32-bit unsigned integer view. */
1406 uint32_t au32[2];
1407 /** The 64-bit unsigned integer view. */
1408 uint64_t u64;
1409} MSI_MISC_INFO_T;
1410AssertCompileSize(MSI_MISC_INFO_T, 8);
1411/** MSI Vector Register 0 and 1 (MMIO). */
1412typedef MSI_MISC_INFO_T MSI_VECTOR_T;
1413
1414/**
1415 * MSI Capability Header Register (PCI + MMIO).
1416 * In accordance with the AMD spec.
1417 */
1418typedef union
1419{
1420 struct
1421 {
1422 uint32_t u8MsiCapId : 8; /**< Bits 7:0 - MsiCapId: Capability ID. */
1423 uint32_t u8MsiCapPtr : 8; /**< Bits 15:8 - MsiCapPtr: Pointer (PCI config offset) to the next capability. */
1424 uint32_t u1MsiEnable : 1; /**< Bit 16 - MsiEn: Message Signal Interrupt Enable. */
1425 uint32_t u3MsiMultiMessCap : 3; /**< Bits 19:17 - MsiMultMessCap: MSI Multi-Message Capability. */
1426 uint32_t u3MsiMultiMessEn : 3; /**< Bits 22:20 - MsiMultMessEn: MSI Multi-Message Enable. */
1427 uint32_t u1Msi64BitEn : 1; /**< Bit 23 - Msi64BitEn: MSI 64-bit Enable. */
1428 uint32_t u8Rsvd0 : 8; /**< Bits 31:24 - Reserved. */
1429 } n;
1430 /** The 32-bit unsigned integer view. */
1431 uint32_t u32;
1432} MSI_CAP_HDR_T;
1433AssertCompileSize(MSI_CAP_HDR_T, 4);
1434
1435/**
1436 * MSI Address Register (PCI + MMIO).
1437 * In accordance with the AMD spec.
1438 */
1439typedef union
1440{
1441 struct
1442 {
1443 RT_GCC_EXTENSION uint64_t u2Rsvd : 2; /**< Bits 1:0 - Reserved. */
1444 RT_GCC_EXTENSION uint64_t u62MsiAddr : 62; /**< Bits 31:2 - MsiAddr: MSI Address. */
1445 } n;
1446 /** The 32-bit unsigned integer view. */
1447 uint32_t au32[2];
1448 /** The 64-bit unsigned integer view. */
1449 uint64_t u64;
1450} MSI_ADDR_T;
1451AssertCompileSize(MSI_ADDR_T, 8);
1452
1453/**
1454 * MSI Data Register (PCI + MMIO).
1455 * In accordance with the AMD spec.
1456 */
1457typedef union
1458{
1459 struct
1460 {
1461 uint16_t u16MsiData; /**< Bits 15:0 - MsiData: MSI Data. */
1462 uint16_t u16Rsvd0; /**< Bits 31:16 - Reserved. */
1463 } n;
1464 /** The 32-bit unsigned integer view. */
1465 uint32_t u32;
1466} MSI_DATA_T;
1467AssertCompileSize(MSI_DATA_T, 4);
1468
1469/**
1470 * MSI Mapping Capability Header Register (PCI + MMIO).
1471 * In accordance with the AMD spec.
1472 */
1473typedef union
1474{
1475 struct
1476 {
1477 uint32_t u8MsiMapCapId : 8; /**< Bits 7:0 - MsiMapCapId: MSI Map capability ID. */
1478 uint32_t u8Rsvd0 : 8; /**< Bits 15:8 - Reserved. */
1479 uint32_t u1MsiMapEn : 1; /**< Bit 16 - MsiMapEn: MSI Map enable. */
1480 uint32_t u1MsiMapFixed : 1; /**< Bit 17 - MsiMapFixd: MSI Map fixed. */
1481 uint32_t u9Rsvd0 : 9; /**< Bits 26:18 - Reserved. */
1482 uint32_t u5MapCapType : 5; /**< Bits 31:27 - MsiMapCapType: MSI Mapping capability type. */
1483 } n;
1484 /** The 32-bit unsigned integer view. */
1485 uint32_t u32;
1486} MSI_MAP_CAP_HDR_T;
1487AssertCompileSize(MSI_MAP_CAP_HDR_T, 4);
1488
1489/**
1490 * Performance Optimization Control Register (MMIO).
1491 * In accordance with the AMD spec.
1492 */
1493typedef union
1494{
1495 struct
1496 {
1497 uint32_t u13Rsvd0 : 13; /**< Bits 12:0 - Reserved. */
1498 uint32_t u1PerfOptEn : 1; /**< Bit 13 - PerfOptEn: Performance Optimization Enable. */
1499 uint32_t u17Rsvd0 : 18; /**< Bits 31:14 - Reserved. */
1500 } n;
1501 /** The 32-bit unsigned integer view. */
1502 uint32_t u32;
1503} IOMMU_PERF_OPT_CTRL_T;
1504AssertCompileSize(IOMMU_PERF_OPT_CTRL_T, 4);
1505
1506/**
1507 * XT (x2APIC) IOMMU General Interrupt Control Register (MMIO).
1508 * In accordance with the AMD spec.
1509 */
1510typedef union
1511{
1512 struct
1513 {
1514 uint32_t u2Rsvd0 : 2; /**< Bits 1:0 - Reserved.*/
1515 uint32_t u1X2ApicIntrDstMode : 1; /**< Bit 2 - Destination Mode for general interrupt.*/
1516 uint32_t u4Rsvd0 : 4; /**< Bits 7:3 - Reserved.*/
1517 uint32_t u24X2ApicIntrDstLo : 24; /**< Bits 31:8 - Destination for general interrupt (Lo).*/
1518 uint32_t u8X2ApicIntrVector : 8; /**< Bits 39:32 - Vector for general interrupt.*/
1519 uint32_t u1X2ApicIntrDeliveryMode : 1; /**< Bit 40 - Delivery Mode for general interrupt.*/
1520 uint32_t u15Rsvd0 : 15; /**< Bits 55:41 - Reserved.*/
1521 uint32_t u7X2ApicIntrDstHi : 7; /**< Bits 63:56 - Destination for general interrupt (Hi) .*/
1522 } n;
1523 /** The 64-bit unsigned integer view. */
1524 uint64_t u64;
1525} IOMMU_XT_GEN_INTR_CTRL_T;
1526AssertCompileSize(IOMMU_XT_GEN_INTR_CTRL_T, 8);
1527
1528/**
1529 * XT (x2APIC) IOMMU General Interrupt Control Register (MMIO).
1530 * In accordance with the AMD spec.
1531 */
1532typedef union
1533{
1534 struct
1535 {
1536 uint32_t u2Rsvd0 : 2; /**< Bits 1:0 - Reserved.*/
1537 uint32_t u1X2ApicIntrDstMode : 1; /**< Bit 2 - Destination Mode for the interrupt.*/
1538 uint32_t u4Rsvd0 : 4; /**< Bits 7:3 - Reserved.*/
1539 uint32_t u24X2ApicIntrDstLo : 24; /**< Bits 31:8 - Destination for the interrupt (Lo).*/
1540 uint32_t u8X2ApicIntrVector : 8; /**< Bits 39:32 - Vector for the interrupt.*/
1541 uint32_t u1X2ApicIntrDeliveryMode : 1; /**< Bit 40 - Delivery Mode for the interrupt.*/
1542 uint32_t u15Rsvd0 : 15; /**< Bits 55:41 - Reserved.*/
1543 uint32_t u7X2ApicIntrDstHi : 7; /**< Bits 63:56 - Destination for the interrupt (Hi) .*/
1544 } n;
1545 /** The 64-bit unsigned integer view. */
1546 uint64_t u64;
1547} IOMMU_XT_INTR_CTRL_T;
1548AssertCompileSize(IOMMU_XT_INTR_CTRL_T, 8);
1549
1550/**
1551 * XT (x2APIC) IOMMU PPR Interrupt Control Register (MMIO).
1552 * In accordance with the AMD spec.
1553 * Currently identical to IOMMU_XT_INTR_CTRL_T.
1554 */
1555typedef IOMMU_XT_INTR_CTRL_T IOMMU_XT_PPR_INTR_CTRL_T;
1556
1557/**
1558 * XT (x2APIC) IOMMU GA (Guest Address) Log 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_GALOG_INTR_CTRL_T;
1563
1564/**
1565 * Memory Access and Routing Control (MARC) Aperture Base Register (MMIO).
1566 * In accordance with the AMD spec.
1567 */
1568typedef union
1569{
1570 struct
1571 {
1572 RT_GCC_EXTENSION uint64_t u12Rsvd0 : 12; /**< Bits 11:0 - Reserved. */
1573 RT_GCC_EXTENSION uint64_t u40MarcBaseAddr : 40; /**< Bits 51:12 - MarcBaseAddr: MARC Aperture Base Address. */
1574 RT_GCC_EXTENSION uint64_t u12Rsvd1 : 12; /**< Bits 63:52 - Reserved. */
1575 } n;
1576 /** The 64-bit unsigned integer view. */
1577 uint64_t u64;
1578} MARC_APER_BAR_T;
1579AssertCompileSize(MARC_APER_BAR_T, 8);
1580
1581/**
1582 * Memory Access and Routing Control (MARC) Relocation Register (MMIO).
1583 * In accordance with the AMD spec.
1584 */
1585typedef union
1586{
1587 struct
1588 {
1589 RT_GCC_EXTENSION uint64_t u1RelocEn : 1; /**< Bit 0 - RelocEn: Relocation Enabled. */
1590 RT_GCC_EXTENSION uint64_t u1ReadOnly : 1; /**< Bit 1 - ReadOnly: Whether only read-only acceses allowed. */
1591 RT_GCC_EXTENSION uint64_t u10Rsvd0 : 10; /**< Bits 11:2 - Reserved. */
1592 RT_GCC_EXTENSION uint64_t u40MarcRelocAddr : 40; /**< Bits 51:12 - MarcRelocAddr: MARC Aperture Relocation Address. */
1593 RT_GCC_EXTENSION uint64_t u12Rsvd1 : 12; /**< Bits 63:52 - Reserved. */
1594 } n;
1595 /** The 64-bit unsigned integer view. */
1596 uint64_t u64;
1597} MARC_APER_RELOC_T;
1598AssertCompileSize(MARC_APER_RELOC_T, 8);
1599
1600/**
1601 * Memory Access and Routing Control (MARC) Length Register (MMIO).
1602 * In accordance with the AMD spec.
1603 */
1604typedef union
1605{
1606 struct
1607 {
1608 RT_GCC_EXTENSION uint64_t u12Rsvd0 : 12; /**< Bits 11:0 - Reserved. */
1609 RT_GCC_EXTENSION uint64_t u40MarcLength : 40; /**< Bits 51:12 - MarcLength: MARC Aperture Length. */
1610 RT_GCC_EXTENSION uint64_t u12Rsvd1 : 12; /**< Bits 63:52 - Reserved. */
1611 } n;
1612 /** The 64-bit unsigned integer view. */
1613 uint64_t u64;
1614} MARC_APER_LEN_T;
1615
1616/**
1617 * Memory Access and Routing Control (MARC) Aperture Register.
1618 * This combines other registers to match the MMIO layout for convenient access.
1619 */
1620typedef struct
1621{
1622 MARC_APER_BAR_T Base;
1623 MARC_APER_RELOC_T Reloc;
1624 MARC_APER_LEN_T Length;
1625} MARC_APER_T;
1626AssertCompileSize(MARC_APER_T, 24);
1627
1628/**
1629 * IOMMU Reserved Register (MMIO).
1630 * In accordance with the AMD spec.
1631 * This register is reserved for hardware use (although RW?).
1632 */
1633typedef uint64_t IOMMU_RSVD_REG_T;
1634
1635/**
1636 * Command Buffer Head Pointer Register (MMIO).
1637 * In accordance with the AMD spec.
1638 */
1639typedef union
1640{
1641 struct
1642 {
1643 uint32_t u4Rsvd0 : 4; /**< Bits 3:0 - Reserved. */
1644 uint32_t u15Ptr : 15; /**< Bits 18:4 - Buffer pointer. */
1645 uint32_t u13Rsvd0 : 13; /**< Bits 31:19 - Reserved. */
1646 uint32_t u32Rsvd0; /**< Bits 63:32 - Reserved. */
1647 } n;
1648 /** The 32-bit unsigned integer view. */
1649 uint32_t au32[2];
1650 /** The 64-bit unsigned integer view. */
1651 uint64_t u64;
1652} CMD_BUF_HEAD_PTR_T;
1653AssertCompileSize(CMD_BUF_HEAD_PTR_T, 8);
1654
1655/**
1656 * Command Buffer Tail Pointer Register (MMIO).
1657 * In accordance with the AMD spec.
1658 * Currently identical to CMD_BUF_HEAD_PTR_T.
1659 */
1660typedef CMD_BUF_HEAD_PTR_T CMD_BUF_TAIL_PTR_T;
1661
1662/**
1663 * Event Log Head Pointer Register (MMIO).
1664 * In accordance with the AMD spec.
1665 * Currently identical to CMD_BUF_HEAD_PTR_T.
1666 */
1667typedef CMD_BUF_HEAD_PTR_T EVT_LOG_HEAD_PTR_T;
1668
1669/**
1670 * Event Log Tail Pointer Register (MMIO).
1671 * In accordance with the AMD spec.
1672 * Currently identical to CMD_BUF_HEAD_PTR_T.
1673 */
1674typedef CMD_BUF_HEAD_PTR_T EVT_LOG_TAIL_PTR_T;
1675
1676/**
1677 * IOMMU Status Register (MMIO).
1678 * In accordance with the AMD spec.
1679 */
1680typedef union
1681{
1682 struct
1683 {
1684 uint32_t u1EvtOverflow : 1; /**< Bit 0 - EventOverflow: Event log overflow. */
1685 uint32_t u1EvtLogIntr : 1; /**< Bit 1 - EventLogInt: Event log interrupt. */
1686 uint32_t u1CompWaitIntr : 1; /**< Bit 2 - ComWaitInt: Completion wait interrupt . */
1687 uint32_t u1EvtLogRunning : 1; /**< Bit 3 - EventLogRun: Event logging is running. */
1688 uint32_t u1CmdBufRunning : 1; /**< Bit 4 - CmdBufRun: Command buffer is running. */
1689 uint32_t u1PprOverflow : 1; /**< Bit 5 - PprOverflow: Peripheral Page Request Log (PPR) overflow. */
1690 uint32_t u1PprIntr : 1; /**< Bit 6 - PprInt: PPR interrupt. */
1691 uint32_t u1PprLogRunning : 1; /**< Bit 7 - PprLogRun: PPR logging is running. */
1692 uint32_t u1GstLogRunning : 1; /**< Bit 8 - GALogRun: Guest virtual-APIC logging is running. */
1693 uint32_t u1GstLogOverflow : 1; /**< Bit 9 - GALOverflow: Guest virtual-APIC log overflow. */
1694 uint32_t u1GstLogIntr : 1; /**< Bit 10 - GAInt: Guest virtual-APIC log interrupt. */
1695 uint32_t u1PprOverflowB : 1; /**< Bit 11 - PprOverflowB: PPR log B overflow. */
1696 uint32_t u1PprLogActive : 1; /**< Bit 12 - PprLogActive: PPR log A is active. */
1697 uint32_t u2Rsvd0 : 2; /**< Bits 14:13 - Reserved. */
1698 uint32_t u1EvtOverflowB : 1; /**< Bit 15 - EvtOverflowB: Event log B overflow. */
1699 uint32_t u1EvtLogActive : 1; /**< Bit 16 - EvtLogActive: Event log A active. */
1700 uint32_t u1PprOverflowEarlyB : 1; /**< Bit 17 - PprOverflowEarlyB: PPR log B overflow early warning. */
1701 uint32_t u1PprOverflowEarly : 1; /**< Bit 18 - PprOverflowEarly: PPR log overflow early warning. */
1702 uint32_t u13Rsvd0 : 13; /**< Bits 31:19 - Reserved. */
1703 uint32_t u32Rsvd0; /**< Bits 63:32 - Reserved . */
1704 } n;
1705 /** The 32-bit unsigned integer view. */
1706 uint32_t au32[2];
1707 /** The 64-bit unsigned integer view. */
1708 uint64_t u64;
1709} IOMMU_STATUS_T;
1710AssertCompileSize(IOMMU_STATUS_T, 8);
1711
1712/**
1713 * PPR Log Head Pointer Register (MMIO).
1714 * In accordance with the AMD spec.
1715 * Currently identical to CMD_BUF_HEAD_PTR_T.
1716 */
1717typedef CMD_BUF_HEAD_PTR_T PPR_LOG_HEAD_PTR_T;
1718
1719/**
1720 * PPR Log Tail Pointer Register (MMIO).
1721 * In accordance with the AMD spec.
1722 * Currently identical to CMD_BUF_HEAD_PTR_T.
1723 */
1724typedef CMD_BUF_HEAD_PTR_T PPR_LOG_TAIL_PTR_T;
1725
1726/**
1727 * Guest Virtual-APIC Log Head Pointer Register (MMIO).
1728 * In accordance with the AMD spec.
1729 */
1730typedef union
1731{
1732 struct
1733 {
1734 uint32_t u2Rsvd0 : 2; /**< Bits 2:0 - Reserved. */
1735 uint32_t u12GALogPtr : 12; /**< Bits 15:3 - Guest Virtual-APIC Log Head or Tail Pointer. */
1736 uint32_t u16Rsvd0 : 16; /**< Bits 31:16 - Reserved. */
1737 uint32_t u32Rsvd0; /**< Bits 63:32 - Reserved. */
1738 } n;
1739 /** The 32-bit unsigned integer view. */
1740 uint32_t au32[2];
1741 /** The 64-bit unsigned integer view. */
1742 uint64_t u64;
1743} GALOG_HEAD_PTR_T;
1744AssertCompileSize(GALOG_HEAD_PTR_T, 8);
1745
1746/**
1747 * Guest Virtual-APIC Log Tail Pointer Register (MMIO).
1748 * In accordance with the AMD spec.
1749 * Currently identical to GALOG_HEAD_PTR_T.
1750 */
1751typedef GALOG_HEAD_PTR_T GALOG_TAIL_PTR_T;
1752
1753/**
1754 * PPR Log B Head Pointer Register (MMIO).
1755 * In accordance with the AMD spec.
1756 * Currently identical to CMD_BUF_HEAD_PTR_T.
1757 */
1758typedef CMD_BUF_HEAD_PTR_T PPR_LOG_B_HEAD_PTR_T;
1759
1760/**
1761 * PPR Log B Tail Pointer Register (MMIO).
1762 * In accordance with the AMD spec.
1763 * Currently identical to CMD_BUF_HEAD_PTR_T.
1764 */
1765typedef CMD_BUF_HEAD_PTR_T PPR_LOG_B_TAIL_PTR_T;
1766
1767/**
1768 * Event Log B Head Pointer Register (MMIO).
1769 * In accordance with the AMD spec.
1770 * Currently identical to CMD_BUF_HEAD_PTR_T.
1771 */
1772typedef CMD_BUF_HEAD_PTR_T EVT_LOG_B_HEAD_PTR_T;
1773
1774/**
1775 * Event Log B Tail Pointer Register (MMIO).
1776 * In accordance with the AMD spec.
1777 * Currently identical to CMD_BUF_HEAD_PTR_T.
1778 */
1779typedef CMD_BUF_HEAD_PTR_T EVT_LOG_B_TAIL_PTR_T;
1780
1781/**
1782 * PPR Log Auto Response Register (MMIO).
1783 * In accordance with the AMD spec.
1784 */
1785typedef union
1786{
1787 struct
1788 {
1789 uint32_t u4AutoRespCode : 4; /**< Bits 3:0 - PprAutoRespCode: PPR log Auto Response Code. */
1790 uint32_t u1AutoRespMaskGen : 1; /**< Bit 4 - PprAutoRespMaskGn: PPR log Auto Response Mask Gen. */
1791 uint32_t u27Rsvd0 : 27; /**< Bits 31:5 - Reserved. */
1792 uint32_t u32Rsvd0; /**< Bits 63:32 - Reserved.*/
1793 } n;
1794 /** The 32-bit unsigned integer view. */
1795 uint32_t au32[2];
1796 /** The 64-bit unsigned integer view. */
1797 uint64_t u64;
1798} PPR_LOG_AUTO_RESP_T;
1799AssertCompileSize(PPR_LOG_AUTO_RESP_T, 8);
1800
1801/**
1802 * PPR Log Overflow Early Indicator Register (MMIO).
1803 * In accordance with the AMD spec.
1804 */
1805typedef union
1806{
1807 struct
1808 {
1809 uint32_t u15Threshold : 15; /**< Bits 14:0 - PprOvrflwEarlyThreshold: Overflow early indicator threshold. */
1810 uint32_t u15Rsvd0 : 15; /**< Bits 29:15 - Reserved. */
1811 uint32_t u1IntrEn : 1; /**< Bit 30 - PprOvrflwEarlyIntEn: Overflow early indicator interrupt enable. */
1812 uint32_t u1Enable : 1; /**< Bit 31 - PprOvrflwEarlyEn: Overflow early indicator enable. */
1813 uint32_t u32Rsvd0; /**< Bits 63:32 - Reserved. */
1814 } n;
1815 /** The 32-bit unsigned integer view. */
1816 uint32_t au32[2];
1817 /** The 64-bit unsigned integer view. */
1818 uint64_t u64;
1819} PPR_LOG_OVERFLOW_EARLY_T;
1820AssertCompileSize(PPR_LOG_OVERFLOW_EARLY_T, 8);
1821
1822/**
1823 * PPR Log B Overflow Early Indicator Register (MMIO).
1824 * In accordance with the AMD spec.
1825 * Currently identical to PPR_LOG_OVERFLOW_EARLY_T.
1826 */
1827typedef PPR_LOG_OVERFLOW_EARLY_T PPR_LOG_B_OVERFLOW_EARLY_T;
1828
1829
1830/**
1831 * The shared IOMMU device state.
1832 */
1833typedef struct IOMMU
1834{
1835 /** Whether this IOMMU is at the top of the PCI tree hierarchy or not. */
1836 bool fRootComplex;
1837 /** Alignment padding. */
1838 bool afPadding[3];
1839 /** The MMIO handle. */
1840 IOMMMIOHANDLE hMmio;
1841
1842 /** @name MMIO: Control and status registers.
1843 * @{ */
1844 DEV_TAB_BAR_T DevTabBaseAddr; /**< Device table base address register. */
1845 CMD_BUF_BAR_T CmdBufBaseAddr; /**< Command buffer base address register. */
1846 EVT_LOG_BAR_T EvtLogBaseAddr; /**< Event log base address register. */
1847 IOMMU_CTRL_T Ctrl; /**< IOMMU control register. */
1848 IOMMU_EXCL_RANGE_BAR_T ExclRangeBaseAddr; /**< IOMMU exclusion range base register. */
1849 IOMMU_EXCL_RANGE_LIMIT_T ExclRangeLimit; /**< IOMMU exclusion range limit. */
1850 IOMMU_EXT_FEAT_T ExtFeat; /**< IOMMU extended feature register. */
1851 /** @} */
1852
1853 /** @name MMIO: PPR Log registers.
1854 * @{ */
1855 PPR_LOG_BAR_T PprLogBaseAddr; /**< PPR Log base address register. */
1856 IOMMU_HW_EVT_HI_T HwEvtHi; /**< IOMMU hardware event register (Hi). */
1857 IOMMU_HW_EVT_LO_T HwEvtLo; /**< IOMMU hardware event register (Lo). */
1858 IOMMU_HW_EVT_STATUS_T HwEvtStatus; /**< IOMMU hardware event status. */
1859 /** @} */
1860
1861 /** @todo IOMMU: SMI filter. */
1862
1863 /** @name MMIO: Guest Virtual-APIC Log registers.
1864 * @{ */
1865 GALOG_BAR_T GALogBaseAddr; /**< Guest Virtual-APIC Log base address register. */
1866 GALOG_TAIL_ADDR_T GALogTailAddr; /**< Guest Virtual-APIC Log Tail address register. */
1867 /** @} */
1868
1869 /** @name MMIO: Alternate PPR and Event Log registers.
1870 * @{ */
1871 PPR_LOG_B_BAR_T PprLogBBaseAddr; /**< PPR Log B base address register. */
1872 EVT_LOG_B_BAR_T EvtLogBBaseAddr; /**< Event Log B base address register. */
1873 /** @} */
1874
1875 /** @name MMIO: Device table segment registers.
1876 * @{ */
1877 DEV_TAB_SEG_BAR_T DevTabSeg[7]; /**< Device Table Segment base address register. */
1878 /** @} */
1879
1880 /** @name MMIO: Device-specific feature registers.
1881 * @{ */
1882 DEV_SPECIFIC_FEAT_T DevSpecificFeat; /**< Device-specific feature extension register (DSFX). */
1883 DEV_SPECIFIC_CTRL_T DevSpecificCtrl; /**< Device-specific control extension register (DSCX). */
1884 DEV_SPECIFIC_STATUS_T DevSpecificStatus; /**< Device-specific status extension register (DSSX). */
1885 /** @} */
1886
1887 /** @name MMIO: MSI Capability Block registers.
1888 * @{ */
1889 MSI_MISC_INFO_T MsiMiscInfo; /**< MSI Misc. info registers / MSI Vector registers. */
1890 MSI_CAP_HDR_T MsiCapHdr; /**< MSI Capability header register. */
1891 MSI_ADDR_T MsiAddr; /**< MSI Address register.*/
1892 MSI_DATA_T MsiData; /**< MSI Data register. */
1893 MSI_MAP_CAP_HDR_T MsiMapCapHdr; /**< MSI Mapping capability header register. */
1894 /** @} */
1895
1896 /** @name MMIO: Performance Optimization Control registers.
1897 * @{ */
1898 IOMMU_PERF_OPT_CTRL_T PerfOptCtrl; /**< IOMMU Performance optimization control register. */
1899 /** @} */
1900
1901 /** @name MMIO: x2APIC Control registers.
1902 * @{ */
1903 IOMMU_XT_GEN_INTR_CTRL_T XtGenIntrCtrl; /**< IOMMU X2APIC General interrupt control register. */
1904 IOMMU_XT_PPR_INTR_CTRL_T XtPprIntrCtrl; /**< IOMMU X2APIC PPR interrupt control register. */
1905 IOMMU_XT_GALOG_INTR_CTRL_T XtGALogIntrCtrl; /**< IOMMU X2APIC Guest Log interrupt control register. */
1906 /** @} */
1907
1908 /** @name MMIO: MARC registers.
1909 * @{ */
1910 MARC_APER_T aMarcApers[4]; /**< MARC Aperture Registers. */
1911 /** @} */
1912
1913 /** @name MMIO: Reserved register.
1914 * @{ */
1915 IOMMU_RSVD_REG_T RsvdReg; /**< IOMMU Reserved Register. */
1916 /** @} */
1917
1918 /** @name MMIO: Command and Event Log pointer registers.
1919 * @{ */
1920 CMD_BUF_HEAD_PTR_T CmdBufHeadPtr; /**< Command buffer head pointer register. */
1921 CMD_BUF_TAIL_PTR_T CmdBufTailPtr; /**< Command buffer tail pointer register. */
1922 EVT_LOG_HEAD_PTR_T EvtLogHeadPtr; /**< Event log head pointer register. */
1923 EVT_LOG_TAIL_PTR_T EvtLogTailPtr; /**< Event log tail pointer register. */
1924 /** @} */
1925
1926 /** @name MMIO: Command and Event Status register.
1927 * @{ */
1928 IOMMU_STATUS_T Status; /**< IOMMU status register. */
1929 /** @} */
1930
1931 /** @name MMIO: PPR Log Head and Tail pointer registers.
1932 * @{ */
1933 PPR_LOG_HEAD_PTR_T PprLogHeadPtr; /**< IOMMU PPR log head pointer register. */
1934 PPR_LOG_TAIL_PTR_T PprLogTailPtr; /**< IOMMU PPR log tail pointer register. */
1935 /** @} */
1936
1937 /** @name MMIO: Guest Virtual-APIC Log Head and Tail pointer registers.
1938 * @{ */
1939 GALOG_HEAD_PTR_T GALogHeadPtr; /**< Guest Virtual-APIC log head pointer register. */
1940 GALOG_TAIL_PTR_T GALogTailPtr; /**< Guest Virtual-APIC log tail pointer register. */
1941 /** @} */
1942
1943 /** @name MMIO: PPR Log B Head and Tail pointer registers.
1944 * @{ */
1945 PPR_LOG_B_HEAD_PTR_T PprLogBHeadPtr; /**< PPR log B head pointer register. */
1946 PPR_LOG_B_TAIL_PTR_T PprLogBTailPtr; /**< PPR log B tail pointer register. */
1947 /** @} */
1948
1949 /** @name MMIO: Event Log B Head and Tail pointer registers.
1950 * @{ */
1951 EVT_LOG_B_HEAD_PTR_T EvtLogBHeadPtr; /**< Event log B head pointer register. */
1952 EVT_LOG_B_TAIL_PTR_T EvtLogBTailPtr; /**< Event log B tail pointer register. */
1953 /** @} */
1954
1955 /** @name MMIO: PPR Log Overflow protection registers.
1956 * @{ */
1957 PPR_LOG_AUTO_RESP_T PprLogAutoResp; /**< PPR Log Auto Response register. */
1958 PPR_LOG_OVERFLOW_EARLY_T PprLogOverflowEarly; /**< PPR Log Overflow Early Indicator register. */
1959 PPR_LOG_B_OVERFLOW_EARLY_T PprLogBOverflowEarly; /**< PPR Log B Overflow Early Indicator register. */
1960 /** @} */
1961
1962 /** @todo IOMMU: IOMMU Event counter registers. */
1963
1964 /** @todo IOMMU: Stat counters. */
1965} IOMMU;
1966/** Pointer to the IOMMU device state. */
1967typedef struct IOMMU *PIOMMU;
1968/** Pointer to the const IOMMU device state. */
1969typedef const struct IOMMU *PCIOMMU;
1970
1971/**
1972 * The ring-3 IOMMU device state.
1973 */
1974typedef struct IOMMUR3
1975{
1976 /** The IOMMU helpers. */
1977 PCPDMIOMMUHLPR3 pIommuHlp;
1978} IOMMUR3;
1979/** Pointer to the ring-3 IOMMU device state. */
1980typedef IOMMUR3 *PIOMMUR3;
1981
1982/**
1983 * The ring-0 IOMMU device state.
1984 */
1985typedef struct IOMMUR0
1986{
1987 /** The IOMMU helpers. */
1988 PCPDMIOMMUHLPR0 pIommuHlp;
1989} IOMMUR0;
1990/** Pointer to the ring-0 IOMMU device state. */
1991typedef IOMMUR0 *PIOMMUR0;
1992
1993/**
1994 * The raw-mode IOMMU device state.
1995 */
1996typedef struct IOMMURC
1997{
1998 /** The IOMMU helpers. */
1999 PCPDMIOMMUHLPRC pIommuHlp;
2000} IOMMURC;
2001/** Pointer to the raw-mode IOMMU device state. */
2002typedef IOMMURC *PIOMMURC;
2003
2004/** The IOMMU device state for the current context. */
2005typedef CTX_SUFF(IOMMU) IOMMUCC;
2006/** Pointer to the IOMMU device state for the current context. */
2007typedef CTX_SUFF(PIOMMU) PIOMMUCC;
2008
2009/**
2010 * IOMMU register access routines.
2011 */
2012typedef struct
2013{
2014 const char *pszName;
2015 VBOXSTRICTRC (*pfnRead )(PPDMDEVINS pDevIns, PIOMMU pThis, uint32_t iReg, uint64_t *pu64Value);
2016 VBOXSTRICTRC (*pfnWrite)(PPDMDEVINS pDevIns, PIOMMU pThis, uint32_t iReg, uint64_t u64Value);
2017 bool f64BitReg;
2018} IOMMUREGACC;
2019
2020
2021#ifndef VBOX_DEVICE_STRUCT_TESTCASE
2022
2023/**
2024 * Returns the number of entries and buffer size for a power-of-2 encoded length.
2025 *
2026 * @param uEncodedLen The length to decode.
2027 * @param pcEntries Where to store the number of entries. Optional, can be
2028 * NULL.
2029 * @param pcbBuffer Where to store the size of the buffer. Optional, can be
2030 * NULL.
2031 *
2032 * @remarks Both @a pcEntries and @a pcbBuffer cannot both be NULL.
2033 */
2034static void iommuAmdDecodeBufferLength(uint8_t uEncodedLen, uint32_t *pcEntries, uint32_t *pcbBuffer)
2035{
2036 uint32_t cEntries;
2037 uint32_t cbBuffer;
2038 if (uEncodedLen > 7)
2039 {
2040 cEntries = 2 << (uEncodedLen - 1);
2041 cbBuffer = *pcEntries << 4;
2042 }
2043 else
2044 cEntries = cbBuffer = 0;
2045
2046 Assert(pcEntries || pcbBuffer);
2047 if (pcEntries)
2048 *pcEntries = cEntries;
2049 if (pcbBuffer)
2050 *pcbBuffer = cbBuffer;
2051}
2052
2053
2054/**
2055 * Writes the Device Table Base Address Register.
2056 */
2057static VBOXSTRICTRC iommuAmdDevTabBar_w(PPDMDEVINS pDevIns, PIOMMU pThis, uint32_t iReg, uint64_t u64Value)
2058{
2059 RT_NOREF(pDevIns, pThis, iReg);
2060 pThis->DevTabBaseAddr.u64 = u64Value & IOMMU_DEV_TAB_BAR_VALID_MASK;
2061 return VINF_SUCCESS;
2062}
2063
2064
2065/**
2066 * Writes the Command Buffer Base Address Register.
2067 */
2068static VBOXSTRICTRC iommuAmdCmdBufBar_w(PPDMDEVINS pDevIns, PIOMMU pThis, uint32_t iReg, uint64_t u64Value)
2069{
2070 RT_NOREF(pDevIns, pThis, iReg);
2071 pThis->CmdBufBaseAddr.u64 = u64Value & IOMMU_CMD_BUF_BAR_VALID_MASK;
2072
2073#ifdef VBOX_STRICT
2074 uint32_t cEntries;
2075 uint8_t const uLen = pThis->CmdBufBaseAddr.n.u4CmdLen;
2076 iommuAmdDecodeBufferLength(uLen, &cEntries, NULL /* pcbBuffer */);
2077 if (!cEntries)
2078 Log((IOMMU_LOG_PFX ": iommuAmdCmdBufBar_w: Invalid length %#x\n", uLen));
2079#endif
2080 return VINF_SUCCESS;
2081}
2082
2083/**
2084 * Writes the Event Log Base Address Register.
2085 */
2086static VBOXSTRICTRC iommuAmdEvtLogBar_w(PPDMDEVINS pDevIns, PIOMMU pThis, uint32_t iReg, uint64_t u64Value)
2087{
2088 RT_NOREF(pDevIns, pThis, iReg);
2089 pThis->EvtLogBaseAddr.u64 = u64Value & IOMMU_EVT_LOG_BAR_VALID_MASK;
2090
2091#ifdef VBOX_STRICT
2092 uint32_t cEntries;
2093 uint8_t const uLen = pThis->EvtLogBaseAddr.n.u4EvtLen;
2094 iommuAmdDecodeBufferLength(uLen, &cEntries, NULL /* pcbBuffer */);
2095 if (!cEntries)
2096 Log((IOMMU_LOG_PFX ": iommuAmdEvtLogBar_w: Invalid length %#x\n", uLen));
2097#endif
2098 return VINF_SUCCESS;
2099}
2100
2101
2102#if 0
2103/**
2104 * Table 0: Registers-access table.
2105 */
2106static const IOMMUREGACC g_aTable0Regs[] =
2107{
2108
2109};
2110
2111/**
2112 * Table 1: Registers-access table.
2113 */
2114static const IOMMUREGACC g_aTable1Regs[] =
2115{
2116};
2117#endif
2118
2119/**
2120 * Writes an IOMMU register (32-bit and 64-bit).
2121 *
2122 * @returns Strict VBox status code.
2123 * @param pDevIns The device instance.
2124 * @param off Offset in bytes.
2125 * @param cb The size of the write access.
2126 * @param uValue The value being written.
2127 */
2128static VBOXSTRICTRC iommuAmdWriteRegister(PPDMDEVINS pDevIns, uint32_t off, uint8_t cb, uint64_t uValue)
2129{
2130 Assert(off < IOMMU_MMIO_REGION_SIZE);
2131 Assert(cb == 4 || cb == 8);
2132 Assert(!(off & (cb - 1)));
2133
2134 PIOMMU pThis = PDMDEVINS_2_DATA(pDevIns, PIOMMU);
2135 Assert(pThis);
2136
2137 VBOXSTRICTRC rcStrict;
2138 switch (off)
2139 {
2140 case IOMMU_MMIO_OFF_DEV_TAB_BAR: return iommuAmdDevTabBar_w(pDevIns, pThis, off, uValue);
2141 case IOMMU_MMIO_OFF_CMD_BUF_BAR: return iommuAmdCmdBufBar_w(pDevIns, pThis, off, uValue);
2142 case IOMMU_MMIO_OFF_EVT_LOG_BAR: return iommuAmdEvtLogBar_w(pDevIns, pThis, off, uValue);
2143 case IOMMU_MMIO_OFF_CTRL:
2144 case IOMMU_MMIO_OFF_EXCL_BAR:
2145 case IOMMU_MMIO_OFF_EXCL_RANGE_LIMIT:
2146 case IOMMU_MMIO_OFF_EXT_FEAT:
2147
2148 case IOMMU_MMIO_OFF_PPR_LOG_BAR:
2149 case IOMMU_MMIO_OFF_HW_EVT_HI:
2150 case IOMMU_MMIO_OFF_HW_EVT_LO:
2151 case IOMMU_MMIO_OFF_HW_EVT_STATUS:
2152
2153 case IOMMU_MMIO_OFF_GALOG_BAR:
2154 case IOMMU_MMIO_OFF_GALOG_TAIL_ADDR:
2155
2156 case IOMMU_MMIO_OFF_PPR_LOG_B_BAR:
2157 case IOMMU_MMIO_OFF_PPR_EVT_B_BAR:
2158
2159 case IOMMU_MMIO_OFF_DEV_TAB_SEG_FIRST:
2160 case IOMMU_MMIO_OFF_DEV_TAB_SEG_LAST:
2161 {
2162 uint8_t const idxDevTabSeg = (off - IOMMU_MMIO_OFF_DEV_TAB_SEG_FIRST) >> 3;
2163 Assert(idxDevTabSeg < RT_ELEMENTS(pThis->DevTabSeg));
2164 break;
2165 }
2166
2167 case IOMMU_MMIO_OFF_DEV_SPECIFIC_FEAT:
2168 case IOMMU_MMIO_OFF_DEV_SPECIFIC_CTRL:
2169 case IOMMU_MMIO_OFF_DEV_SPECIFIC_STATUS:
2170
2171 case IOMMU_MMIO_OFF_MSI_VECTOR_0:
2172 case IOMMU_MMIO_OFF_MSI_VECTOR_1:
2173 case IOMMU_MMIO_OFF_MSI_CAP_HDR:
2174 case IOMMU_MMIO_OFF_MSI_ADDR_LO:
2175 case IOMMU_MMIO_OFF_MSI_ADDR_HI:
2176 case IOMMU_MMIO_OFF_MSI_DATA:
2177 case IOMMU_MMIO_OFF_MSI_MAPPING_CAP_HDR:
2178
2179 case IOMMU_MMIO_OFF_PERF_OPT_CTRL:
2180
2181 case IOMMU_MMIO_OFF_XT_GEN_INTR_CTRL:
2182 case IOMMU_MMIO_OFF_XT_PPR_INTR_CTRL:
2183 case IOMMU_MMIO_OFF_XT_GALOG_INT_CTRL:
2184
2185 case IOMMU_MMIO_OFF_MARC_APER_BAR_0:
2186 case IOMMU_MMIO_OFF_MARC_APER_RELOC_0:
2187 case IOMMU_MMIO_OFF_MARC_APER_LEN_0:
2188 case IOMMU_MMIO_OFF_MARC_APER_BAR_1:
2189 case IOMMU_MMIO_OFF_MARC_APER_RELOC_1:
2190 case IOMMU_MMIO_OFF_MARC_APER_LEN_1:
2191 case IOMMU_MMIO_OFF_MARC_APER_BAR_2:
2192 case IOMMU_MMIO_OFF_MARC_APER_RELOC_2:
2193 case IOMMU_MMIO_OFF_MARC_APER_LEN_2:
2194 case IOMMU_MMIO_OFF_MARC_APER_BAR_3:
2195 case IOMMU_MMIO_OFF_MARC_APER_RELOC_3:
2196 case IOMMU_MMIO_OFF_MARC_APER_LEN_3:
2197
2198 case IOMMU_MMIO_OFF_RSVD_REG:
2199
2200 case IOMMU_MMIO_CMD_BUF_HEAD_PTR:
2201 case IOMMU_MMIO_CMD_BUF_TAIL_PTR:
2202 case IOMMU_MMIO_EVT_LOG_HEAD_PTR:
2203 case IOMMU_MMIO_EVT_LOG_TAIL_PTR:
2204
2205 case IOMMU_MMIO_OFF_STATUS:
2206
2207 case IOMMU_MMIO_OFF_PPR_LOG_HEAD_PTR:
2208 case IOMMU_MMIO_OFF_PPR_LOG_TAIL_PTR:
2209
2210 case IOMMU_MMIO_OFF_GALOG_HEAD_PTR:
2211 case IOMMU_MMIO_OFF_GALOG_TAIL_PTR:
2212
2213 case IOMMU_MMIO_OFF_PPR_LOG_B_HEAD_PTR:
2214 case IOMMU_MMIO_OFF_PPR_LOG_B_TAIL_PTR:
2215
2216 case IOMMU_MMIO_OFF_EVT_LOG_B_HEAD_PTR:
2217 case IOMMU_MMIO_OFF_EVT_LOG_B_TAIL_PTR:
2218
2219 case IOMMU_MMIO_OFF_PPR_LOG_AUTO_RESP:
2220 case IOMMU_MMIO_OFF_PPR_LOG_OVERFLOW_EARLY:
2221 case IOMMU_MMIO_OFF_PPR_LOG_B_OVERFLOW_EARLY:
2222
2223 /* Not implemented. */
2224 case IOMMU_MMIO_OFF_SMI_FLT_FIRST:
2225 case IOMMU_MMIO_OFF_SMI_FLT_LAST:
2226 {
2227 Log((IOMMU_LOG_PFX ": iommuAmdWriteRegister: Writing unsupported register: SMI filter %u -> Ignored\n",
2228 (off - IOMMU_MMIO_OFF_SMI_FLT_FIRST) >> 3));
2229 rcStrict = VINF_SUCCESS;
2230 break;
2231 }
2232
2233 /* Unknown. */
2234 default:
2235 {
2236 Log((IOMMU_LOG_PFX ": iommuAmdWriteRegister: Trying to write unknown register at %u (%#x) with %#RX64\n", off, off,
2237 uValue));
2238 rcStrict = VINF_SUCCESS;
2239 break;
2240 }
2241 }
2242
2243 return rcStrict;
2244}
2245
2246
2247/**
2248 * Reads an IOMMU register (64-bit).
2249 *
2250 * All reads are 64-bit but reads to 32-bit registers that are aligned on an 8-byte
2251 * boundary include the lower half of the subsequent register.
2252 *
2253 * This is because most registers are 64-bit and aligned on 8-byte boundaries but
2254 * some are really 32-bit registers aligned on an 8-byte boundary. We cannot assume
2255 * guests will only perform 32-bit reads on those 32-bit registers that are aligned
2256 * on 8-byte boundaries.
2257 *
2258 * @returns Strict VBox status code.
2259 * @param pThis The IOMMU device state.
2260 * @param off Offset in bytes.
2261 * @param puResult Where to store the value being read.
2262 */
2263static VBOXSTRICTRC iommuAmdReadRegister(PCIOMMU pThis, uint32_t off, uint64_t *puResult)
2264{
2265 Assert(off < IOMMU_MMIO_REGION_SIZE);
2266 Assert(!(off & 7) || !(off & 3));
2267
2268 /** @todo IOMMU: fine-grained locking? */
2269 uint64_t uReg;
2270 switch (off)
2271 {
2272 case IOMMU_MMIO_OFF_DEV_TAB_BAR: uReg = pThis->DevTabBaseAddr.u64; break;
2273 case IOMMU_MMIO_OFF_CMD_BUF_BAR: uReg = pThis->CmdBufBaseAddr.u64; break;
2274 case IOMMU_MMIO_OFF_EVT_LOG_BAR: uReg = pThis->EvtLogBaseAddr.u64; break;
2275 case IOMMU_MMIO_OFF_CTRL: uReg = pThis->Ctrl.u64; break;
2276 case IOMMU_MMIO_OFF_EXCL_BAR: uReg = pThis->ExclRangeBaseAddr.u64; break;
2277 case IOMMU_MMIO_OFF_EXCL_RANGE_LIMIT: uReg = pThis->ExclRangeLimit.u64; break;
2278 case IOMMU_MMIO_OFF_EXT_FEAT: uReg = pThis->ExtFeat.u64; break;
2279
2280 case IOMMU_MMIO_OFF_PPR_LOG_BAR: uReg = pThis->PprLogBaseAddr.u64; break;
2281 case IOMMU_MMIO_OFF_HW_EVT_HI: uReg = pThis->HwEvtHi.u64; break;
2282 case IOMMU_MMIO_OFF_HW_EVT_LO: uReg = pThis->HwEvtLo; break;
2283 case IOMMU_MMIO_OFF_HW_EVT_STATUS: uReg = pThis->HwEvtStatus.u64; break;
2284
2285 case IOMMU_MMIO_OFF_GALOG_BAR: uReg = pThis->GALogBaseAddr.u64; break;
2286 case IOMMU_MMIO_OFF_GALOG_TAIL_ADDR: uReg = pThis->GALogTailAddr.u64; break;
2287
2288 case IOMMU_MMIO_OFF_PPR_LOG_B_BAR: uReg = pThis->PprLogBBaseAddr.u64; break;
2289 case IOMMU_MMIO_OFF_PPR_EVT_B_BAR: uReg = pThis->EvtLogBBaseAddr.u64; break;
2290
2291 case IOMMU_MMIO_OFF_DEV_TAB_SEG_FIRST:
2292 case IOMMU_MMIO_OFF_DEV_TAB_SEG_LAST:
2293 {
2294 uint8_t const idxDevTabSeg = (off - IOMMU_MMIO_OFF_DEV_TAB_SEG_FIRST) >> 3;
2295 Assert(idxDevTabSeg < RT_ELEMENTS(pThis->DevTabSeg));
2296 uReg = pThis->DevTabSeg[idxDevTabSeg].u64;
2297 break;
2298 }
2299
2300 case IOMMU_MMIO_OFF_DEV_SPECIFIC_FEAT: uReg = pThis->DevSpecificFeat.u64; break;
2301 case IOMMU_MMIO_OFF_DEV_SPECIFIC_CTRL: uReg = pThis->DevSpecificCtrl.u64; break;
2302 case IOMMU_MMIO_OFF_DEV_SPECIFIC_STATUS: uReg = pThis->DevSpecificStatus.u64; break;
2303
2304 case IOMMU_MMIO_OFF_MSI_VECTOR_0: uReg = pThis->MsiMiscInfo.u64; break;
2305 case IOMMU_MMIO_OFF_MSI_VECTOR_1: uReg = pThis->MsiMiscInfo.au32[1]; break;
2306 case IOMMU_MMIO_OFF_MSI_CAP_HDR: uReg = RT_MAKE_U64(pThis->MsiCapHdr.u32, pThis->MsiAddr.au32[0]); break;
2307 case IOMMU_MMIO_OFF_MSI_ADDR_LO: uReg = pThis->MsiAddr.au32[0]; break;
2308 case IOMMU_MMIO_OFF_MSI_ADDR_HI: uReg = RT_MAKE_U64(pThis->MsiAddr.au32[1], pThis->MsiData.u32); break;
2309 case IOMMU_MMIO_OFF_MSI_DATA: uReg = pThis->MsiData.u32; break;
2310 case IOMMU_MMIO_OFF_MSI_MAPPING_CAP_HDR: uReg = RT_MAKE_U64(pThis->MsiMapCapHdr.u32, pThis->PerfOptCtrl.u32); break;
2311
2312 case IOMMU_MMIO_OFF_PERF_OPT_CTRL: uReg = pThis->PerfOptCtrl.u32; break;
2313
2314 case IOMMU_MMIO_OFF_XT_GEN_INTR_CTRL: uReg = pThis->XtGenIntrCtrl.u64; break;
2315 case IOMMU_MMIO_OFF_XT_PPR_INTR_CTRL: uReg = pThis->XtPprIntrCtrl.u64; break;
2316 case IOMMU_MMIO_OFF_XT_GALOG_INT_CTRL: uReg = pThis->XtGALogIntrCtrl.u64; break;
2317
2318 case IOMMU_MMIO_OFF_MARC_APER_BAR_0: uReg = pThis->aMarcApers[0].Base.u64; break;
2319 case IOMMU_MMIO_OFF_MARC_APER_RELOC_0: uReg = pThis->aMarcApers[0].Reloc.u64; break;
2320 case IOMMU_MMIO_OFF_MARC_APER_LEN_0: uReg = pThis->aMarcApers[0].Length.u64; break;
2321 case IOMMU_MMIO_OFF_MARC_APER_BAR_1: uReg = pThis->aMarcApers[1].Base.u64; break;
2322 case IOMMU_MMIO_OFF_MARC_APER_RELOC_1: uReg = pThis->aMarcApers[1].Reloc.u64; break;
2323 case IOMMU_MMIO_OFF_MARC_APER_LEN_1: uReg = pThis->aMarcApers[1].Length.u64; break;
2324 case IOMMU_MMIO_OFF_MARC_APER_BAR_2: uReg = pThis->aMarcApers[2].Base.u64; break;
2325 case IOMMU_MMIO_OFF_MARC_APER_RELOC_2: uReg = pThis->aMarcApers[2].Reloc.u64; break;
2326 case IOMMU_MMIO_OFF_MARC_APER_LEN_2: uReg = pThis->aMarcApers[2].Length.u64; break;
2327 case IOMMU_MMIO_OFF_MARC_APER_BAR_3: uReg = pThis->aMarcApers[3].Base.u64; break;
2328 case IOMMU_MMIO_OFF_MARC_APER_RELOC_3: uReg = pThis->aMarcApers[3].Reloc.u64; break;
2329 case IOMMU_MMIO_OFF_MARC_APER_LEN_3: uReg = pThis->aMarcApers[3].Length.u64; break;
2330
2331 case IOMMU_MMIO_OFF_RSVD_REG: uReg = pThis->RsvdReg; break;
2332
2333 case IOMMU_MMIO_CMD_BUF_HEAD_PTR: uReg = pThis->CmdBufHeadPtr.u64; break;
2334 case IOMMU_MMIO_CMD_BUF_TAIL_PTR: uReg = pThis->CmdBufTailPtr.u64; break;
2335 case IOMMU_MMIO_EVT_LOG_HEAD_PTR: uReg = pThis->EvtLogHeadPtr.u64; break;
2336 case IOMMU_MMIO_EVT_LOG_TAIL_PTR: uReg = pThis->EvtLogTailPtr.u64; break;
2337
2338 case IOMMU_MMIO_OFF_STATUS: uReg = pThis->Status.u64; break;
2339
2340 case IOMMU_MMIO_OFF_PPR_LOG_HEAD_PTR: uReg = pThis->PprLogHeadPtr.u64; break;
2341 case IOMMU_MMIO_OFF_PPR_LOG_TAIL_PTR: uReg = pThis->PprLogTailPtr.u64; break;
2342
2343 case IOMMU_MMIO_OFF_GALOG_HEAD_PTR: uReg = pThis->GALogHeadPtr.u64; break;
2344 case IOMMU_MMIO_OFF_GALOG_TAIL_PTR: uReg = pThis->GALogTailPtr.u64; break;
2345
2346 case IOMMU_MMIO_OFF_PPR_LOG_B_HEAD_PTR: uReg = pThis->PprLogBHeadPtr.u64; break;
2347 case IOMMU_MMIO_OFF_PPR_LOG_B_TAIL_PTR: uReg = pThis->PprLogBTailPtr.u64; break;
2348
2349 case IOMMU_MMIO_OFF_EVT_LOG_B_HEAD_PTR: uReg = pThis->EvtLogBHeadPtr.u64; break;
2350 case IOMMU_MMIO_OFF_EVT_LOG_B_TAIL_PTR: uReg = pThis->EvtLogBTailPtr.u64; break;
2351
2352 case IOMMU_MMIO_OFF_PPR_LOG_AUTO_RESP: uReg = pThis->PprLogAutoResp.u64; break;
2353 case IOMMU_MMIO_OFF_PPR_LOG_OVERFLOW_EARLY: uReg = pThis->PprLogOverflowEarly.u64; break;
2354 case IOMMU_MMIO_OFF_PPR_LOG_B_OVERFLOW_EARLY: uReg = pThis->PprLogBOverflowEarly.u64; break;
2355
2356 /* Not implemented. */
2357 case IOMMU_MMIO_OFF_SMI_FLT_FIRST:
2358 case IOMMU_MMIO_OFF_SMI_FLT_LAST:
2359 {
2360 Log((IOMMU_LOG_PFX ": iommuAmdReadRegister: Reading unsupported register: SMI filter %u\n",
2361 (off - IOMMU_MMIO_OFF_SMI_FLT_FIRST) >> 3));
2362 uReg = 0;
2363 break;
2364 }
2365
2366 /* Unknown. */
2367 default:
2368 {
2369 Log((IOMMU_LOG_PFX ": iommuAmdReadRegister: Trying to read unknown register at %u (%#x)\n", off, off));
2370 uReg = 0;
2371 return VINF_IOM_MMIO_UNUSED_00;
2372 }
2373 }
2374
2375 *puResult = uReg;
2376 return VINF_SUCCESS;
2377}
2378
2379/**
2380 * @callback_method_impl{FNIOMMMIONEWWRITE}
2381 */
2382static DECLCALLBACK(VBOXSTRICTRC) iommuAmdMmioWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void const *pv, unsigned cb)
2383{
2384 NOREF(pvUser);
2385 Assert(cb == 4 || cb == 8);
2386 Assert(!(off & (cb - 1)));
2387
2388 uint64_t const uValue = cb == 8 ? *(uint64_t const *)pv : *(uint32_t const *)pv;
2389 return iommuAmdWriteRegister(pDevIns, off, cb, uValue);
2390}
2391
2392
2393/**
2394 * @callback_method_impl{FNIOMMMIONEWREAD}
2395 */
2396static DECLCALLBACK(VBOXSTRICTRC) iommuAmdMmioRead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void *pv, unsigned cb)
2397{
2398 NOREF(pvUser);
2399 Assert(cb == 4 || cb == 8);
2400 Assert(!(off & (cb - 1)));
2401
2402 uint64_t uResult;
2403 PIOMMU pThis = PDMDEVINS_2_DATA(pDevIns, PIOMMU);
2404 VBOXSTRICTRC rcStrict = iommuAmdReadRegister(pThis, off, &uResult);
2405 if (cb == 8)
2406 *(uint64_t *)pv = uResult;
2407 else
2408 *(uint32_t *)pv = (uint32_t)uResult;
2409
2410 return rcStrict;
2411}
2412
2413
2414# ifdef IN_RING3
2415
2416/**
2417 * Resets read-write portions of the IOMMU state.
2418 *
2419 * State data not initialized here is expected to be initialized in the construct
2420 * callback and remain read-only through the lifetime of the VM.
2421 *
2422 * @param pDevIns The device instance.
2423 */
2424static void iommuAmdR3Init(PPDMDEVINS pDevIns)
2425{
2426 PIOMMU pThis = PDMDEVINS_2_DATA(pDevIns, PIOMMU);
2427 Assert(pThis);
2428
2429 PPDMPCIDEV pPciDev = pDevIns->apPciDevs[0];
2430 PDMPCIDEV_ASSERT_VALID(pDevIns, pPciDev);
2431
2432 pThis->DevTabBaseAddr.u64 = 0;
2433 pThis->CmdBufBaseAddr.u64 = 0;
2434 pThis->EvtLogBaseAddr.u64 = 0;
2435 pThis->Ctrl.u64 = 0;
2436 pThis->ExclRangeBaseAddr.u64 = 0;
2437 pThis->ExclRangeLimit.u64 = 0;
2438 pThis->ExtFeat.n.u1PrefetchSup = 0;
2439 pThis->ExtFeat.n.u1PprSup = 0;
2440 pThis->ExtFeat.n.u1X2ApicSup = 0;
2441 pThis->ExtFeat.n.u1NoExecuteSup = 0;
2442 pThis->ExtFeat.n.u1GstTranslateSup = 0;
2443 pThis->ExtFeat.n.u1InvAllSup = 0;
2444 pThis->ExtFeat.n.u1GstVirtApicSup = 0;
2445 pThis->ExtFeat.n.u1HwErrorSup = 0;
2446 pThis->ExtFeat.n.u1PerfCounterSup = 0;
2447 pThis->ExtFeat.n.u2HostAddrTranslateSize = 0; /* Requires GstTranslateSup. */
2448 pThis->ExtFeat.n.u2GstAddrTranslateSize = 0; /* Requires GstTranslateSup. */
2449 pThis->ExtFeat.n.u2GstCr3RootTblLevel = 0; /* Requires GstTranslateSup. */
2450 pThis->ExtFeat.n.u2SmiFilterSup = 0;
2451 pThis->ExtFeat.n.u3SmiFilterCount = 0;
2452 pThis->ExtFeat.n.u3GstVirtApicModeSup = 0; /* Requires GstVirtApicSup */
2453 pThis->ExtFeat.n.u2DualPprLogSup = 0;
2454 pThis->ExtFeat.n.u2DualEvtLogSup = 0;
2455 pThis->ExtFeat.n.u5MaxPasidSup = 0; /* Requires GstTranslateSup. */
2456 pThis->ExtFeat.n.u1UserSupervisorSup = 0;
2457 pThis->ExtFeat.n.u2DevTabSegSup = 0;
2458 pThis->ExtFeat.n.u1PprLogOverflowWarn = 0;
2459 pThis->ExtFeat.n.u1PprAutoRespSup = 0;
2460 pThis->ExtFeat.n.u2MarcSup = 0;
2461 pThis->ExtFeat.n.u1BlockStopMarkSup = 0;
2462 pThis->ExtFeat.n.u1PerfOptSup = 0;
2463 pThis->ExtFeat.n.u1MsiCapMmioSup = 1;
2464 pThis->ExtFeat.n.u1GstIoSup = 0;
2465 pThis->ExtFeat.n.u1HostAccessSup = 0;
2466 pThis->ExtFeat.n.u1EnhancedPprSup = 0;
2467 pThis->ExtFeat.n.u1AttrForwardSup = 0;
2468 pThis->ExtFeat.n.u1HostDirtySup = 0;
2469 pThis->ExtFeat.n.u1InvIoTlbTypeSup = 0;
2470 pThis->ExtFeat.n.u1GstUpdateDisSup = 0;
2471 pThis->ExtFeat.n.u1ForcePhysDstSup = 0;
2472 pThis->PprLogBaseAddr.u64 = 0;
2473 pThis->HwEvtHi.u64 = 0;
2474 pThis->HwEvtLo = 0;
2475 pThis->HwEvtStatus.u64 = 0;
2476 pThis->GALogBaseAddr.n.u40GALogBase = 0;
2477 pThis->GALogBaseAddr.n.u4GALogLen = 8;
2478 pThis->GALogTailAddr.u64 = 0;
2479 pThis->PprLogBBaseAddr.n.u40PprLogBase = 0;
2480 pThis->PprLogBBaseAddr.n.u4PprLogLen = 8;
2481 pThis->EvtLogBBaseAddr.n.u40EvtBase = 0;
2482 pThis->EvtLogBBaseAddr.n.u4EvtLen = 8;
2483 memset(&pThis->DevTabSeg[0], 0, sizeof(pThis->DevTabSeg));
2484 pThis->DevSpecificFeat.u64 = 0;
2485 pThis->DevSpecificCtrl.u64 = 0;
2486 pThis->DevSpecificStatus.u64 = 0;
2487 pThis->MsiMiscInfo.u64 = 0;
2488 pThis->MsiCapHdr.u32 = PDMPciDevGetDWord(pPciDev, IOMMU_PCI_OFF_MSI_CAP_HDR);
2489 pThis->MsiAddr.u64 = 0;
2490 pThis->MsiData.u32 = 0;
2491 pThis->MsiMapCapHdr.u32 = 0;
2492 pThis->PerfOptCtrl.u32 = 0;
2493 pThis->XtGenIntrCtrl.u64 = 0;
2494 pThis->XtPprIntrCtrl.u64 = 0;
2495 pThis->XtGALogIntrCtrl.u64 = 0;
2496 memset(&pThis->aMarcApers[0], 0, sizeof(pThis->aMarcApers));
2497 pThis->RsvdReg = 0;
2498 pThis->CmdBufHeadPtr.u64 = 0;
2499 pThis->CmdBufTailPtr.u64 = 0;
2500 pThis->EvtLogHeadPtr.u64 = 0;
2501 pThis->EvtLogTailPtr.u64 = 0;
2502 pThis->Status.u64 = 0;
2503 pThis->PprLogHeadPtr.u64 = 0;
2504 pThis->PprLogTailPtr.u64 = 0;
2505 pThis->GALogHeadPtr.u64 = 0;
2506 pThis->GALogTailPtr.u64 = 0;
2507 pThis->PprLogBHeadPtr.u64 = 0;
2508 pThis->PprLogBTailPtr.u64 = 0;
2509 pThis->EvtLogBHeadPtr.u64 = 0;
2510 pThis->EvtLogBTailPtr.u64 = 0;
2511 pThis->PprLogAutoResp.u64 = 0;
2512 pThis->PprLogOverflowEarly.u64 = 0;
2513 pThis->PprLogBOverflowEarly.u64 = 0;
2514
2515 PDMPciDevSetDWord(pPciDev, IOMMU_PCI_OFF_BASE_ADDR_REG_LO, 0);
2516 PDMPciDevSetDWord(pPciDev, IOMMU_PCI_OFF_BASE_ADDR_REG_HI, 0);
2517 PDMPciDevSetDWord(pPciDev, IOMMU_PCI_OFF_RANGE_REG, 0);
2518}
2519
2520
2521/**
2522 * @callback_method_impl{FNPCICONFIGREAD}
2523 */
2524static DECLCALLBACK(VBOXSTRICTRC) iommuAmdR3PciConfigRead(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t uAddress,
2525 unsigned cb, uint32_t *pu32Value)
2526{
2527 /** @todo IOMMU: PCI config read stat counter. */
2528 VBOXSTRICTRC rcStrict = PDMDevHlpPCIConfigRead(pDevIns, pPciDev, uAddress, cb, pu32Value);
2529 Log3((IOMMU_LOG_PFX ": PCI config read: At %#x (%u) -> %#x %Rrc\n", uAddress, cb, *pu32Value, VBOXSTRICTRC_VAL(rcStrict)));
2530 return rcStrict;
2531}
2532
2533
2534/**
2535 * @callback_method_impl{FNPCICONFIGWRITE}
2536 */
2537static DECLCALLBACK(VBOXSTRICTRC) iommuAmdR3PciConfigWrite(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t uAddress,
2538 unsigned cb, uint32_t u32Value)
2539{
2540 /** @todo IOMMU: PCI config write. */
2541 VBOXSTRICTRC rcStrict = PDMDevHlpPCIConfigWrite(pDevIns, pPciDev, uAddress, cb, u32Value);
2542 Log3((IOMMU_LOG_PFX ": PCI config write: %#x -> To %#x (%u) %Rrc\n", u32Value, uAddress, cb, VBOXSTRICTRC_VAL(rcStrict)));
2543 return rcStrict;
2544}
2545
2546
2547/**
2548 * @callback_method_impl{FNDBGFHANDLERDEV}
2549 */
2550static DECLCALLBACK(void) iommuAmdR3DbgInfo(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, const char *pszArgs)
2551{
2552 PCIOMMU pThis = PDMDEVINS_2_DATA(pDevIns, PIOMMU);
2553 Assert(pThis);
2554
2555 LogFlow((IOMMU_LOG_PFX ": iommuAmdR3DbgInfo: pThis=%p pszArgs=%s\n", pThis, pszArgs));
2556 bool const fVerbose = !strncmp(pszArgs, RT_STR_TUPLE("verbose")) ? true : false;
2557
2558 pHlp->pfnPrintf(pHlp, "AMD-IOMMU:\n");
2559 /* Device Table Base Address. */
2560 {
2561 DEV_TAB_BAR_T const DevTabBar = pThis->DevTabBaseAddr;
2562 pHlp->pfnPrintf(pHlp, " Device Table BAR = %#RX64\n", DevTabBar.u64);
2563 if (fVerbose)
2564 {
2565 pHlp->pfnPrintf(pHlp, " Size = %u (%u bytes)\n", DevTabBar.n.u9Size,
2566 (DevTabBar.n.u9Size + 1) * _4K);
2567 pHlp->pfnPrintf(pHlp, " Base address = %#RX64\n", DevTabBar.n.u40DevTabBase);
2568 }
2569 }
2570 /* Command Buffer Base Address Register. */
2571 {
2572 CMD_BUF_BAR_T const CmdBufBar = pThis->CmdBufBaseAddr;
2573 uint32_t cEntries;
2574 uint32_t cbBuffer;
2575 uint8_t const uEncodedLen = CmdBufBar.n.u4CmdLen;
2576 iommuAmdDecodeBufferLength(uEncodedLen, &cEntries, &cbBuffer);
2577 pHlp->pfnPrintf(pHlp, " Command buffer BAR = %#RX64\n", CmdBufBar.u64);
2578 if (fVerbose)
2579 {
2580 pHlp->pfnPrintf(pHlp, " Base address = %#RX64\n", CmdBufBar.n.u40CmdBase);
2581 pHlp->pfnPrintf(pHlp, " Length = %u (%u entries, %u bytes)\n", uEncodedLen,
2582 cEntries, cbBuffer);
2583 }
2584 }
2585 /* Event Log Base Address Register. */
2586 {
2587 EVT_LOG_BAR_T const EvtLogBar = pThis->EvtLogBaseAddr;
2588 uint32_t cEntries;
2589 uint32_t cbBuffer;
2590 uint8_t const uEncodedLen = EvtLogBar.n.u4EvtLen;
2591 iommuAmdDecodeBufferLength(uEncodedLen, &cEntries, &cbBuffer);
2592 pHlp->pfnPrintf(pHlp, " Event log BAR = %#RX64\n", EvtLogBar.u64);
2593 if (fVerbose)
2594 {
2595 pHlp->pfnPrintf(pHlp, " Base address = %#RX64\n", EvtLogBar.n.u40EvtBase);
2596 pHlp->pfnPrintf(pHlp, " Length = %u (%u entries, %u bytes)\n", uEncodedLen,
2597 cEntries, cbBuffer);
2598 }
2599 }
2600 /* IOMMU Control Register. */
2601 {
2602 IOMMU_CTRL_T const Ctrl = pThis->Ctrl;
2603 pHlp->pfnPrintf(pHlp, " Control = %#RX64\n", Ctrl.u64);
2604 if (fVerbose)
2605 {
2606 pHlp->pfnPrintf(pHlp, " IOMMU enable = %RTbool\n", Ctrl.n.u1IommuEn);
2607 pHlp->pfnPrintf(pHlp, " HT Tunnel translation enable = %RTbool\n", Ctrl.n.u1HtTunEn);
2608 pHlp->pfnPrintf(pHlp, " Event log enable = %RTbool\n", Ctrl.n.u1EvtLogEn);
2609 pHlp->pfnPrintf(pHlp, " Event log interrupt enable = %RTbool\n", Ctrl.n.u1EvtIntrEn);
2610 pHlp->pfnPrintf(pHlp, " Completion wait interrupt enable = %RTbool\n", Ctrl.n.u1EvtIntrEn);
2611 pHlp->pfnPrintf(pHlp, " Invalidation timeout = %u\n", Ctrl.n.u3InvTimeOut);
2612 pHlp->pfnPrintf(pHlp, " Pass posted write = %RTbool\n", Ctrl.n.u1PassPW);
2613 pHlp->pfnPrintf(pHlp, " Respose Pass posted write = %RTbool\n", Ctrl.n.u1ResPassPW);
2614 pHlp->pfnPrintf(pHlp, " Coherent = %RTbool\n", Ctrl.n.u1Coherent);
2615 pHlp->pfnPrintf(pHlp, " Isochronous = %RTbool\n", Ctrl.n.u1Isoc);
2616 pHlp->pfnPrintf(pHlp, " Command buffer enable = %RTbool\n", Ctrl.n.u1CmdBufEn);
2617 pHlp->pfnPrintf(pHlp, " PPR log enable = %RTbool\n", Ctrl.n.u1PprLogEn);
2618 pHlp->pfnPrintf(pHlp, " PPR interrupt enable = %RTbool\n", Ctrl.n.u1PprIntrEn);
2619 pHlp->pfnPrintf(pHlp, " PPR enable = %RTbool\n", Ctrl.n.u1PprEn);
2620 pHlp->pfnPrintf(pHlp, " Guest translation eanble = %RTbool\n", Ctrl.n.u1GstTranslateEn);
2621 pHlp->pfnPrintf(pHlp, " Guest virtual-APIC enable = %RTbool\n", Ctrl.n.u1GstVirtApicEn);
2622 pHlp->pfnPrintf(pHlp, " CRW = %#x\n", Ctrl.n.u4Crw);
2623 pHlp->pfnPrintf(pHlp, " SMI filter enable = %RTbool\n", Ctrl.n.u1SmiFilterEn);
2624 pHlp->pfnPrintf(pHlp, " Self-writeback disable = %RTbool\n", Ctrl.n.u1SelfWriteBackDis);
2625 pHlp->pfnPrintf(pHlp, " SMI filter log enable = %RTbool\n", Ctrl.n.u1SmiFilterLogEn);
2626 pHlp->pfnPrintf(pHlp, " Guest virtual-APIC mode enable = %#x\n", Ctrl.n.u3GstVirtApicModeEn);
2627 pHlp->pfnPrintf(pHlp, " Guest virtual-APIC GA log enable = %RTbool\n", Ctrl.n.u1GstLogEn);
2628 pHlp->pfnPrintf(pHlp, " Guest virtual-APIC interrupt enable = %RTbool\n", Ctrl.n.u1GstIntrEn);
2629 pHlp->pfnPrintf(pHlp, " Dual PPR log enable = %#x\n", Ctrl.n.u2DualPprLogEn);
2630 pHlp->pfnPrintf(pHlp, " Dual event log enable = %#x\n", Ctrl.n.u2DualEvtLogEn);
2631 pHlp->pfnPrintf(pHlp, " Device table segmentation enable = %#x\n", Ctrl.n.u3DevTabSegEn);
2632 pHlp->pfnPrintf(pHlp, " Privilege abort enable = %#x\n", Ctrl.n.u2PrivAbortEn);
2633 pHlp->pfnPrintf(pHlp, " PPR auto response enable = %RTbool\n", Ctrl.n.u1PprAutoRespEn);
2634 pHlp->pfnPrintf(pHlp, " MARC enable = %RTbool\n", Ctrl.n.u1MarcEn);
2635 pHlp->pfnPrintf(pHlp, " Block StopMark enable = %RTbool\n", Ctrl.n.u1BlockStopMarkEn);
2636 pHlp->pfnPrintf(pHlp, " PPR auto response always-on enable = %RTbool\n", Ctrl.n.u1PprAutoRespAlwaysOnEn);
2637 pHlp->pfnPrintf(pHlp, " Domain IDPNE = %RTbool\n", Ctrl.n.u1DomainIDPNE);
2638 pHlp->pfnPrintf(pHlp, " Enhanced PPR handling = %RTbool\n", Ctrl.n.u1EnhancedPpr);
2639 pHlp->pfnPrintf(pHlp, " Host page table access/dirty bit update = %#x\n", Ctrl.n.u2HstAccDirtyBitUpdate);
2640 pHlp->pfnPrintf(pHlp, " Guest page table dirty bit disable = %RTbool\n", Ctrl.n.u1GstDirtyUpdateDis);
2641 pHlp->pfnPrintf(pHlp, " x2APIC enable = %RTbool\n", Ctrl.n.u1X2ApicEn);
2642 pHlp->pfnPrintf(pHlp, " x2APIC interrupt enable = %RTbool\n", Ctrl.n.u1X2ApicIntrGenEn);
2643 pHlp->pfnPrintf(pHlp, " Guest page table access bit update = %RTbool\n", Ctrl.n.u1GstAccessUpdateDis);
2644 }
2645 }
2646 /* Exclusion Base Address Register. */
2647 {
2648 IOMMU_EXCL_RANGE_BAR_T const ExclRangeBar = pThis->ExclRangeBaseAddr;
2649 pHlp->pfnPrintf(pHlp, " Exclusion BAR = %#RX64\n", ExclRangeBar.u64);
2650 if (fVerbose)
2651 {
2652 pHlp->pfnPrintf(pHlp, " Exclusion enable = %RTbool\n", ExclRangeBar.n.u1ExclEnable);
2653 pHlp->pfnPrintf(pHlp, " Allow all devices = %RTbool\n", ExclRangeBar.n.u1AllowAll);
2654 pHlp->pfnPrintf(pHlp, " Base address = %#RX64\n", ExclRangeBar.n.u40ExclRangeBase);
2655 }
2656 }
2657 /* Exclusion Range Limit Register. */
2658 {
2659 IOMMU_EXCL_RANGE_LIMIT_T const ExclRangeLimit = pThis->ExclRangeLimit;
2660 pHlp->pfnPrintf(pHlp, " Exclusion Range Limit = %#RX64\n", ExclRangeLimit.u64);
2661 if (fVerbose)
2662 pHlp->pfnPrintf(pHlp, " Range limit = %#RX64\n", ExclRangeLimit.n.u40ExclLimit);
2663 }
2664 /* Extended Feature Register. */
2665 {
2666 IOMMU_EXT_FEAT_T ExtFeat = pThis->ExtFeat;
2667 pHlp->pfnPrintf(pHlp, " Extended Feature Register = %#RX64\n", ExtFeat.u64);
2668 pHlp->pfnPrintf(pHlp, " Prefetch support = %RTbool\n", ExtFeat.n.u1PrefetchSup);
2669 if (fVerbose)
2670 {
2671 pHlp->pfnPrintf(pHlp, " PPR support = %RTbool\n", ExtFeat.n.u1PprSup);
2672 pHlp->pfnPrintf(pHlp, " x2APIC support = %RTbool\n", ExtFeat.n.u1X2ApicSup);
2673 pHlp->pfnPrintf(pHlp, " NX and privilege level support = %RTbool\n", ExtFeat.n.u1NoExecuteSup);
2674 pHlp->pfnPrintf(pHlp, " Guest translation support = %RTbool\n", ExtFeat.n.u1GstTranslateSup);
2675 pHlp->pfnPrintf(pHlp, " Invalidate-All command support = %RTbool\n", ExtFeat.n.u1InvAllSup);
2676 pHlp->pfnPrintf(pHlp, " Guest virtual-APIC support = %RTbool\n", ExtFeat.n.u1GstVirtApicSup);
2677 pHlp->pfnPrintf(pHlp, " Hardware error register support = %RTbool\n", ExtFeat.n.u1HwErrorSup);
2678 pHlp->pfnPrintf(pHlp, " Performance counters support = %RTbool\n", ExtFeat.n.u1PerfCounterSup);
2679 pHlp->pfnPrintf(pHlp, " Host address translation size = %#x\n", ExtFeat.n.u2HostAddrTranslateSize);
2680 pHlp->pfnPrintf(pHlp, " Guest address translation size = %#x\n", ExtFeat.n.u2GstAddrTranslateSize);
2681 pHlp->pfnPrintf(pHlp, " Guest CR3 root table level support = %#x\n", ExtFeat.n.u2GstCr3RootTblLevel);
2682 pHlp->pfnPrintf(pHlp, " SMI filter register support = %#x\n", ExtFeat.n.u2SmiFilterSup);
2683 pHlp->pfnPrintf(pHlp, " SMI filter register count = %#x\n", ExtFeat.n.u3SmiFilterCount);
2684 pHlp->pfnPrintf(pHlp, " Guest virtual-APIC modes support = %#x\n", ExtFeat.n.u3GstVirtApicModeSup);
2685 pHlp->pfnPrintf(pHlp, " Dual PPR log support = %#x\n", ExtFeat.n.u2DualPprLogSup);
2686 pHlp->pfnPrintf(pHlp, " Dual event log support = %#x\n", ExtFeat.n.u2DualEvtLogSup);
2687 pHlp->pfnPrintf(pHlp, " Maximum PASID = %#x\n", ExtFeat.n.u5MaxPasidSup);
2688 pHlp->pfnPrintf(pHlp, " User/supervisor page protection support = %RTbool\n", ExtFeat.n.u1UserSupervisorSup);
2689 pHlp->pfnPrintf(pHlp, " Device table segments supported = %u\n", (ExtFeat.n.u2DevTabSegSup << 1));
2690 pHlp->pfnPrintf(pHlp, " PPR log overflow early warning support = %RTbool\n", ExtFeat.n.u1PprLogOverflowWarn);
2691 pHlp->pfnPrintf(pHlp, " PPR auto response support = %RTbool\n", ExtFeat.n.u1PprAutoRespSup);
2692 pHlp->pfnPrintf(pHlp, " MARC support = %#x\n", ExtFeat.n.u2MarcSup);
2693 pHlp->pfnPrintf(pHlp, " Block StopMark message support = %RTbool\n", ExtFeat.n.u1BlockStopMarkSup);
2694 pHlp->pfnPrintf(pHlp, " Performance optimization support = %RTbool\n", ExtFeat.n.u1PerfOptSup);
2695 pHlp->pfnPrintf(pHlp, " MSI capability MMIO access support = %RTbool\n", ExtFeat.n.u1MsiCapMmioSup);
2696 pHlp->pfnPrintf(pHlp, " Guest I/O protection support = %RTbool\n", ExtFeat.n.u1GstIoSup);
2697 pHlp->pfnPrintf(pHlp, " Host access support = %RTbool\n", ExtFeat.n.u1HostAccessSup);
2698 pHlp->pfnPrintf(pHlp, " Enhanced PPR handling support = %RTbool\n", ExtFeat.n.u1EnhancedPprSup);
2699 pHlp->pfnPrintf(pHlp, " Attribute forward supported = %RTbool\n", ExtFeat.n.u1AttrForwardSup);
2700 pHlp->pfnPrintf(pHlp, " Host dirty support = %RTbool\n", ExtFeat.n.u1HostDirtySup);
2701 pHlp->pfnPrintf(pHlp, " Invalidate IOTLB type support = %RTbool\n", ExtFeat.n.u1InvIoTlbTypeSup);
2702 pHlp->pfnPrintf(pHlp, " Guest page table access bit hw disable = %RTbool\n", ExtFeat.n.u1GstUpdateDisSup);
2703 pHlp->pfnPrintf(pHlp, " Force physical dest for remapped intr. = %RTbool\n", ExtFeat.n.u1ForcePhysDstSup);
2704 }
2705 }
2706 /* PPR Log Base Address Register. */
2707 {
2708 PPR_LOG_BAR_T PprLogBar = pThis->PprLogBaseAddr;
2709 uint32_t cEntries;
2710 uint32_t cbBuffer;
2711 uint8_t const uEncodedLen = PprLogBar.n.u4PprLogLen;
2712 iommuAmdDecodeBufferLength(uEncodedLen, &cEntries, &cbBuffer);
2713 pHlp->pfnPrintf(pHlp, " PPR Log BAR = %#RX64\n", PprLogBar.u64);
2714 if (fVerbose)
2715 {
2716 pHlp->pfnPrintf(pHlp, " Base address = %#RX64\n", PprLogBar.n.u40PprLogBase);
2717 pHlp->pfnPrintf(pHlp, " Length = %u (%u entries, %u bytes)\n", uEncodedLen,
2718 cEntries, cbBuffer);
2719 }
2720 }
2721 /* Hardware Event (Hi) Register. */
2722 {
2723 IOMMU_HW_EVT_HI_T HwEvtHi = pThis->HwEvtHi;
2724 pHlp->pfnPrintf(pHlp, " Hardware Event (Hi) = %#RX64\n", HwEvtHi.u64);
2725 if (fVerbose)
2726 {
2727 pHlp->pfnPrintf(pHlp, " First operand = %#RX64\n", HwEvtHi.n.u60FirstOperand);
2728 pHlp->pfnPrintf(pHlp, " Event code = %#RX8\n", HwEvtHi.n.u4EvtCode);
2729 }
2730 }
2731 /* Hardware Event (Lo) Register. */
2732 pHlp->pfnPrintf(pHlp, " Hardware Event (Lo) = %#RX64\n", pThis->HwEvtLo);
2733 /* Hardware Event Status. */
2734 {
2735 IOMMU_HW_EVT_STATUS_T HwEvtStatus = pThis->HwEvtStatus;
2736 pHlp->pfnPrintf(pHlp, " Hardware Event Status = %#RX64\n", HwEvtStatus.u64);
2737 if (fVerbose)
2738 {
2739 pHlp->pfnPrintf(pHlp, " Valid = %RTbool\n", HwEvtStatus.n.u1Valid);
2740 pHlp->pfnPrintf(pHlp, " Overflow = %RTbool\n", HwEvtStatus.n.u1Overflow);
2741 }
2742 }
2743 /* Guest Virtual-APIC Log Base Address Register. */
2744 {
2745 GALOG_BAR_T const GALogBar = pThis->GALogBaseAddr;
2746 uint32_t cEntries;
2747 uint32_t cbBuffer;
2748 uint8_t const uEncodedLen = GALogBar.n.u4GALogLen;
2749 iommuAmdDecodeBufferLength(uEncodedLen, &cEntries, &cbBuffer);
2750 pHlp->pfnPrintf(pHlp, " Guest Log BAR = %#RX64\n", GALogBar.u64);
2751 if (fVerbose)
2752 {
2753 pHlp->pfnPrintf(pHlp, " Base address = %RTbool\n", GALogBar.n.u40GALogBase);
2754 pHlp->pfnPrintf(pHlp, " Length = %u (%u entries, %u bytes)\n", uEncodedLen,
2755 cEntries, cbBuffer);
2756 }
2757 }
2758 /* Guest Virtual-APIC Log Tail Address Register. */
2759 {
2760 GALOG_TAIL_ADDR_T GALogTail = pThis->GALogTailAddr;
2761 pHlp->pfnPrintf(pHlp, " Guest Log Tail Address = %#RX64\n", GALogTail.u64);
2762 if (fVerbose)
2763 pHlp->pfnPrintf(pHlp, " Tail address = %#RX64\n", GALogTail.n.u40GALogTailAddr);
2764 }
2765 /* PPR Log B Base Address Register. */
2766 {
2767 PPR_LOG_B_BAR_T PprLogBBar = pThis->PprLogBBaseAddr;
2768 uint32_t cEntries;
2769 uint32_t cbBuffer;
2770 uint8_t const uEncodedLen = PprLogBBar.n.u4PprLogLen;
2771 iommuAmdDecodeBufferLength(uEncodedLen, &cEntries, &cbBuffer);
2772 pHlp->pfnPrintf(pHlp, " PPR Log B BAR = %#RX64\n", PprLogBBar.u64);
2773 if (fVerbose)
2774 {
2775 pHlp->pfnPrintf(pHlp, " Base address = %#RX64\n", PprLogBBar.n.u40PprLogBase);
2776 pHlp->pfnPrintf(pHlp, " Length = %u (%u entries, %u bytes)\n", uEncodedLen,
2777 cEntries, cbBuffer);
2778 }
2779 }
2780 /* Event Log B Base Address Register. */
2781 {
2782 EVT_LOG_B_BAR_T EvtLogBBar = pThis->EvtLogBBaseAddr;
2783 uint32_t cEntries;
2784 uint32_t cbBuffer;
2785 uint8_t const uEncodedLen = EvtLogBBar.n.u4EvtLen;
2786 iommuAmdDecodeBufferLength(uEncodedLen, &cEntries, &cbBuffer);
2787 pHlp->pfnPrintf(pHlp, " Event Log B BAR = %#RX64\n", EvtLogBBar.u64);
2788 if (fVerbose)
2789 {
2790 pHlp->pfnPrintf(pHlp, " Base address = %#RX64\n", EvtLogBBar.n.u40EvtBase);
2791 pHlp->pfnPrintf(pHlp, " Length = %u (%u entries, %u bytes)\n", uEncodedLen,
2792 cEntries, cbBuffer);
2793 }
2794 }
2795 /* Device Table Segment Registers. */
2796 for (unsigned i = 0; i < RT_ELEMENTS(pThis->DevTabSeg); i++)
2797 {
2798 DEV_TAB_SEG_BAR_T const DevTabSeg = pThis->DevTabSeg[i];
2799 pHlp->pfnPrintf(pHlp, " Device Table Segment BAR [%u] = %#RX64\n", DevTabSeg.u64);
2800 if (fVerbose)
2801 {
2802 pHlp->pfnPrintf(pHlp, " Base address = %#RX64\n", DevTabSeg.n.u40DevTabBase);
2803 pHlp->pfnPrintf(pHlp, " Size = %#x (%u bytes)\n", DevTabSeg.n.u8Size,
2804 (DevTabSeg.n.u8Size + 1) << X86_PAGE_4K_SHIFT);
2805 }
2806 }
2807 /* Device-Specific Feature Extension Register. */
2808 {
2809 DEV_SPECIFIC_FEAT_T const DevSpecificFeat = pThis->DevSpecificFeat;
2810 pHlp->pfnPrintf(pHlp, " Device-specific Feature = %#RX64\n", DevSpecificFeat.u64);
2811 if (fVerbose)
2812 {
2813 pHlp->pfnPrintf(pHlp, " Feature = %#RX32\n", DevSpecificFeat.n.u24DevSpecFeat);
2814 pHlp->pfnPrintf(pHlp, " Minor revision ID = %#x\n", DevSpecificFeat.n.u4RevMinor);
2815 pHlp->pfnPrintf(pHlp, " Major revision ID = %#x\n", DevSpecificFeat.n.u4RevMajor);
2816 }
2817 }
2818 /* Device-Specific Control Extension Register. */
2819 {
2820 DEV_SPECIFIC_CTRL_T const DevSpecificCtrl = pThis->DevSpecificCtrl;
2821 pHlp->pfnPrintf(pHlp, " Device-specific Control = %#RX64\n", DevSpecificCtrl.u64);
2822 if (fVerbose)
2823 {
2824 pHlp->pfnPrintf(pHlp, " Control = %#RX32\n", DevSpecificCtrl.n.u24DevSpecCtrl);
2825 pHlp->pfnPrintf(pHlp, " Minor revision ID = %#x\n", DevSpecificCtrl.n.u4RevMinor);
2826 pHlp->pfnPrintf(pHlp, " Major revision ID = %#x\n", DevSpecificCtrl.n.u4RevMajor);
2827 }
2828 }
2829 /* Device-Specific Status Extension Register. */
2830 {
2831 DEV_SPECIFIC_STATUS_T const DevSpecificStatus = pThis->DevSpecificStatus;
2832 pHlp->pfnPrintf(pHlp, " Device-specific Control = %#RX64\n", DevSpecificStatus.u64);
2833 if (fVerbose)
2834 {
2835 pHlp->pfnPrintf(pHlp, " Status = %#RX32\n", DevSpecificStatus.n.u24DevSpecStatus);
2836 pHlp->pfnPrintf(pHlp, " Minor revision ID = %#x\n", DevSpecificStatus.n.u4RevMinor);
2837 pHlp->pfnPrintf(pHlp, " Major revision ID = %#x\n", DevSpecificStatus.n.u4RevMajor);
2838 }
2839 }
2840 /* MSI Miscellaneous Information Register (Lo and Hi). */
2841 {
2842 MSI_MISC_INFO_T const MsiMiscInfo = pThis->MsiMiscInfo;
2843 pHlp->pfnPrintf(pHlp, " MSI Misc. Info. Register = %#RX64\n", MsiMiscInfo.u64);
2844 if (fVerbose)
2845 {
2846 pHlp->pfnPrintf(pHlp, " Event Log MSI number = %#x\n", MsiMiscInfo.n.u5MsiNumEvtLog);
2847 pHlp->pfnPrintf(pHlp, " Guest Virtual-Address Size = %#x\n", MsiMiscInfo.n.u3GstVirtAddrSize);
2848 pHlp->pfnPrintf(pHlp, " Physical Address Size = %#x\n", MsiMiscInfo.n.u7PhysAddrSize);
2849 pHlp->pfnPrintf(pHlp, " Virtual-Address Size = %#x\n", MsiMiscInfo.n.u7VirtAddrSize);
2850 pHlp->pfnPrintf(pHlp, " HT Transport ATS Range Reserved = %RTbool\n", MsiMiscInfo.n.u1HtAtsResv);
2851 pHlp->pfnPrintf(pHlp, " PPR MSI number = %#x\n", MsiMiscInfo.n.u5MsiNumPpr);
2852 pHlp->pfnPrintf(pHlp, " GA Log MSI number = %#x\n", MsiMiscInfo.n.u5MsiNumGa);
2853 }
2854 }
2855 /* MSI Capability Header. */
2856 {
2857 MSI_CAP_HDR_T const MsiCapHdr = pThis->MsiCapHdr;
2858 pHlp->pfnPrintf(pHlp, " MSI Capability Header = %#RX32\n", MsiCapHdr.u32);
2859 if (fVerbose)
2860 {
2861 pHlp->pfnPrintf(pHlp, " Capability ID = %#x\n", MsiCapHdr.n.u8MsiCapId);
2862 pHlp->pfnPrintf(pHlp, " Capability Ptr (PCI config offset) = %#x\n", MsiCapHdr.n.u8MsiCapPtr);
2863 pHlp->pfnPrintf(pHlp, " Enable = %RTbool\n", MsiCapHdr.n.u1MsiEnable);
2864 pHlp->pfnPrintf(pHlp, " Multi-message capability = %#x\n", MsiCapHdr.n.u3MsiMultiMessCap);
2865 pHlp->pfnPrintf(pHlp, " Multi-message enable = %#x\n", MsiCapHdr.n.u3MsiMultiMessEn);
2866 }
2867 }
2868 /* MSI Address Register (Lo and Hi). */
2869 {
2870 MSI_ADDR_T const MsiAddr = pThis->MsiAddr;
2871 pHlp->pfnPrintf(pHlp, " MSI Address = %#RX64\n", MsiAddr.u64);
2872 if (fVerbose)
2873 pHlp->pfnPrintf(pHlp, " Address = %#RX64\n", MsiAddr.n.u62MsiAddr);
2874 }
2875 /* MSI Data. */
2876 {
2877 MSI_DATA_T const MsiData = pThis->MsiData;
2878 pHlp->pfnPrintf(pHlp, " MSI Data = %#RX32\n", MsiData.u32);
2879 if (fVerbose)
2880 pHlp->pfnPrintf(pHlp, " Data = %#x\n", MsiData.n.u16MsiData);
2881 }
2882 /* MSI Mapping Capability Header. */
2883 {
2884 MSI_MAP_CAP_HDR_T const MsiMapCapHdr = pThis->MsiMapCapHdr;
2885 pHlp->pfnPrintf(pHlp, " MSI Mapping Capability Header = %#RX32\n", MsiMapCapHdr.u32);
2886 if (fVerbose)
2887 {
2888 pHlp->pfnPrintf(pHlp, " Capability ID = %#x\n", MsiMapCapHdr.n.u8MsiMapCapId);
2889 pHlp->pfnPrintf(pHlp, " Map enable = %RTbool\n", MsiMapCapHdr.n.u1MsiMapEn);
2890 pHlp->pfnPrintf(pHlp, " Map fixed = %RTbool\n", MsiMapCapHdr.n.u1MsiMapFixed);
2891 pHlp->pfnPrintf(pHlp, " Map capability type = %#x\n", MsiMapCapHdr.n.u5MapCapType);
2892 }
2893 }
2894 /* Performance Optimization Control Register. */
2895 {
2896 IOMMU_PERF_OPT_CTRL_T const PerfOptCtrl = pThis->PerfOptCtrl;
2897 pHlp->pfnPrintf(pHlp, " Performance Optimization Control = %#RX32\n", PerfOptCtrl.u32);
2898 if (fVerbose)
2899 pHlp->pfnPrintf(pHlp, " Enable = %RTbool\n", PerfOptCtrl.n.u1PerfOptEn);
2900 }
2901 /* XT (x2APIC) General Interrupt Control Register. */
2902 {
2903 IOMMU_XT_GEN_INTR_CTRL_T const XtGenIntrCtrl = pThis->XtGenIntrCtrl;
2904 pHlp->pfnPrintf(pHlp, " XT General Interrupt Control = %#RX64\n", XtGenIntrCtrl.u64);
2905 if (fVerbose)
2906 {
2907 pHlp->pfnPrintf(pHlp, " Interrupt destination mode = %s\n",
2908 !XtGenIntrCtrl.n.u1X2ApicIntrDstMode ? "physical" : "logical");
2909 pHlp->pfnPrintf(pHlp, " Interrupt destination = %#RX64\n",
2910 RT_MAKE_U64(XtGenIntrCtrl.n.u24X2ApicIntrDstLo, XtGenIntrCtrl.n.u7X2ApicIntrDstHi));
2911 pHlp->pfnPrintf(pHlp, " Interrupt vector = %#x\n", XtGenIntrCtrl.n.u8X2ApicIntrVector);
2912 pHlp->pfnPrintf(pHlp, " Interrupt delivery mode = %#x\n",
2913 !XtGenIntrCtrl.n.u8X2ApicIntrVector ? "fixed" : "arbitrated");
2914 }
2915 }
2916 /* XT (x2APIC) PPR Interrupt Control Register. */
2917 {
2918 IOMMU_XT_PPR_INTR_CTRL_T const XtPprIntrCtrl = pThis->XtPprIntrCtrl;
2919 pHlp->pfnPrintf(pHlp, " XT PPR Interrupt Control = %#RX64\n", XtPprIntrCtrl.u64);
2920 if (fVerbose)
2921 {
2922 pHlp->pfnPrintf(pHlp, " Interrupt destination mode = %s\n",
2923 !XtPprIntrCtrl.n.u1X2ApicIntrDstMode ? "physical" : "logical");
2924 pHlp->pfnPrintf(pHlp, " Interrupt destination = %#RX64\n",
2925 RT_MAKE_U64(XtPprIntrCtrl.n.u24X2ApicIntrDstLo, XtPprIntrCtrl.n.u7X2ApicIntrDstHi));
2926 pHlp->pfnPrintf(pHlp, " Interrupt vector = %#x\n", XtPprIntrCtrl.n.u8X2ApicIntrVector);
2927 pHlp->pfnPrintf(pHlp, " Interrupt delivery mode = %#x\n",
2928 !XtPprIntrCtrl.n.u8X2ApicIntrVector ? "fixed" : "arbitrated");
2929 }
2930 }
2931 /* XT (X2APIC) GA Log Interrupt Control Register. */
2932 {
2933 IOMMU_XT_GALOG_INTR_CTRL_T const XtGALogIntrCtrl = pThis->XtGALogIntrCtrl;
2934 pHlp->pfnPrintf(pHlp, " XT PPR Interrupt Control = %#RX64\n", XtGALogIntrCtrl.u64);
2935 if (fVerbose)
2936 {
2937 pHlp->pfnPrintf(pHlp, " Interrupt destination mode = %s\n",
2938 !XtGALogIntrCtrl.n.u1X2ApicIntrDstMode ? "physical" : "logical");
2939 pHlp->pfnPrintf(pHlp, " Interrupt destination = %#RX64\n",
2940 RT_MAKE_U64(XtGALogIntrCtrl.n.u24X2ApicIntrDstLo, XtGALogIntrCtrl.n.u7X2ApicIntrDstHi));
2941 pHlp->pfnPrintf(pHlp, " Interrupt vector = %#x\n", XtGALogIntrCtrl.n.u8X2ApicIntrVector);
2942 pHlp->pfnPrintf(pHlp, " Interrupt delivery mode = %#x\n",
2943 !XtGALogIntrCtrl.n.u8X2ApicIntrVector ? "fixed" : "arbitrated");
2944 }
2945 }
2946 /* MARC Registers. */
2947 {
2948 for (unsigned i = 0; i < RT_ELEMENTS(pThis->aMarcApers); i++)
2949 {
2950 pHlp->pfnPrintf(pHlp, " MARC Aperature %u:\n", i);
2951 MARC_APER_BAR_T const MarcAperBar = pThis->aMarcApers[i].Base;
2952 pHlp->pfnPrintf(pHlp, " Base = %#RX64 (addr: %#RX64)\n", MarcAperBar.u64, MarcAperBar.n.u40MarcBaseAddr);
2953
2954 MARC_APER_RELOC_T const MarcAperReloc = pThis->aMarcApers[i].Reloc;
2955 pHlp->pfnPrintf(pHlp, " Reloc = %#RX64 (addr: %#RX64, read-only: %RTbool, enable: %RTbool)\n",
2956 MarcAperReloc.u64, MarcAperReloc.n.u40MarcRelocAddr, MarcAperReloc.n.u1ReadOnly,
2957 MarcAperReloc.n.u1RelocEn);
2958
2959 MARC_APER_LEN_T const MarcAperLen = pThis->aMarcApers[i].Length;
2960 pHlp->pfnPrintf(pHlp, " Length = %u pages\n", MarcAperLen.n.u40MarcLength);
2961 }
2962 }
2963 /* Reserved Register. */
2964 pHlp->pfnPrintf(pHlp, " Reserved Register = %#RX64\n", pThis->RsvdReg);
2965 /* Command Buffer Head Pointer Register. */
2966 {
2967 CMD_BUF_HEAD_PTR_T const CmdBufHeadPtr = pThis->CmdBufHeadPtr;
2968 pHlp->pfnPrintf(pHlp, " Command Buffer Head Pointer = %#RX64\n", CmdBufHeadPtr.u64);
2969 pHlp->pfnPrintf(pHlp, " Pointer = %#x\n", CmdBufHeadPtr.n.u15Ptr);
2970 }
2971 /* Command Buffer Tail Pointer Register. */
2972 {
2973 CMD_BUF_HEAD_PTR_T const CmdBufTailPtr = pThis->CmdBufTailPtr;
2974 pHlp->pfnPrintf(pHlp, " Command Buffer Tail Pointer = %#RX64\n", CmdBufTailPtr.u64);
2975 pHlp->pfnPrintf(pHlp, " Pointer = %#x\n", CmdBufTailPtr.n.u15Ptr);
2976 }
2977 /* Event Log Head Pointer Register. */
2978 {
2979 EVT_LOG_HEAD_PTR_T const EvtLogHeadPtr = pThis->EvtLogHeadPtr;
2980 pHlp->pfnPrintf(pHlp, " Event Log Head Pointer = %#RX64\n", EvtLogHeadPtr.u64);
2981 pHlp->pfnPrintf(pHlp, " Pointer = %#x\n", EvtLogHeadPtr.n.u15Ptr);
2982 }
2983 /* Event Log Tail Pointer Register. */
2984 {
2985 EVT_LOG_TAIL_PTR_T const EvtLogTailPtr = pThis->EvtLogTailPtr;
2986 pHlp->pfnPrintf(pHlp, " Event Log Head Pointer = %#RX64\n", EvtLogTailPtr.u64);
2987 pHlp->pfnPrintf(pHlp, " Pointer = %#x\n", EvtLogTailPtr.n.u15Ptr);
2988 }
2989 /* Status Register. */
2990 {
2991 IOMMU_STATUS_T const Status = pThis->Status;
2992 pHlp->pfnPrintf(pHlp, " Status Register = %#RX64\n", Status.u64);
2993 if (fVerbose)
2994 {
2995 pHlp->pfnPrintf(pHlp, " Event log overflow = %RTbool\n", Status.n.u1EvtOverflow);
2996 pHlp->pfnPrintf(pHlp, " Event log interrupt = %RTbool\n", Status.n.u1EvtLogIntr);
2997 pHlp->pfnPrintf(pHlp, " Completion wait interrupt = %RTbool\n", Status.n.u1CompWaitIntr);
2998 pHlp->pfnPrintf(pHlp, " Event log running = %RTbool\n", Status.n.u1EvtLogRunning);
2999 pHlp->pfnPrintf(pHlp, " Command buffer running = %RTbool\n", Status.n.u1CmdBufRunning);
3000 pHlp->pfnPrintf(pHlp, " PPR overflow = %RTbool\n", Status.n.u1PprOverflow);
3001 pHlp->pfnPrintf(pHlp, " PPR interrupt = %RTbool\n", Status.n.u1PprIntr);
3002 pHlp->pfnPrintf(pHlp, " PPR log running = %RTbool\n", Status.n.u1PprLogRunning);
3003 pHlp->pfnPrintf(pHlp, " Guest log running = %RTbool\n", Status.n.u1GstLogRunning);
3004 pHlp->pfnPrintf(pHlp, " Guest log interrupt = %RTbool\n", Status.n.u1GstLogIntr);
3005 pHlp->pfnPrintf(pHlp, " PPR log B overflow = %RTbool\n", Status.n.u1PprOverflowB);
3006 pHlp->pfnPrintf(pHlp, " PPR log active = %RTbool\n", Status.n.u1PprLogActive);
3007 pHlp->pfnPrintf(pHlp, " Event log B overflow = %RTbool\n", Status.n.u1EvtOverflowB);
3008 pHlp->pfnPrintf(pHlp, " Event log active = %RTbool\n", Status.n.u1EvtLogActive);
3009 pHlp->pfnPrintf(pHlp, " PPR log B overflow early warning = %RTbool\n", Status.n.u1PprOverflowEarlyB);
3010 pHlp->pfnPrintf(pHlp, " PPR log overflow early warning = %RTbool\n", Status.n.u1PprOverflowEarly);
3011 }
3012 }
3013 /* PPR Log Head Pointer. */
3014 {
3015 PPR_LOG_HEAD_PTR_T const PprLogHeadPtr = pThis->PprLogHeadPtr;
3016 pHlp->pfnPrintf(pHlp, " PPR Log Head Pointer = %#RX64\n", PprLogHeadPtr.u64);
3017 pHlp->pfnPrintf(pHlp, " Pointer = %#x\n", PprLogHeadPtr.n.u15Ptr);
3018 }
3019 /* PPR Log Tail Pointer. */
3020 {
3021 PPR_LOG_TAIL_PTR_T const PprLogTailPtr = pThis->PprLogTailPtr;
3022 pHlp->pfnPrintf(pHlp, " PPR Log Tail Pointer = %#RX64\n", PprLogTailPtr.u64);
3023 pHlp->pfnPrintf(pHlp, " Pointer = %#x\n", PprLogTailPtr.n.u15Ptr);
3024 }
3025 /* Guest Virtual-APIC Log Head Pointer. */
3026 {
3027 GALOG_HEAD_PTR_T const GALogHeadPtr = pThis->GALogHeadPtr;
3028 pHlp->pfnPrintf(pHlp, " Guest Virtual-APIC Log Head Pointer = %#RX64\n", GALogHeadPtr.u64);
3029 pHlp->pfnPrintf(pHlp, " Pointer = %#x\n", GALogHeadPtr.n.u12GALogPtr);
3030 }
3031 /* Guest Virtual-APIC Log Tail Pointer. */
3032 {
3033 GALOG_HEAD_PTR_T const GALogTailPtr = pThis->GALogTailPtr;
3034 pHlp->pfnPrintf(pHlp, " Guest Virtual-APIC Log Tail Pointer = %#RX64\n", GALogTailPtr.u64);
3035 pHlp->pfnPrintf(pHlp, " Pointer = %#x\n", GALogTailPtr.n.u12GALogPtr);
3036 }
3037 /* PPR Log B Head Pointer. */
3038 {
3039 PPR_LOG_B_HEAD_PTR_T const PprLogBHeadPtr = pThis->PprLogBHeadPtr;
3040 pHlp->pfnPrintf(pHlp, " PPR Log B Head Pointer = %#RX64\n", PprLogBHeadPtr.u64);
3041 pHlp->pfnPrintf(pHlp, " Pointer = %#x\n", PprLogBHeadPtr.n.u15Ptr);
3042 }
3043 /* PPR Log B Tail Pointer. */
3044 {
3045 PPR_LOG_B_TAIL_PTR_T const PprLogBTailPtr = pThis->PprLogBTailPtr;
3046 pHlp->pfnPrintf(pHlp, " PPR Log B Tail Pointer = %#RX64\n", PprLogBTailPtr.u64);
3047 pHlp->pfnPrintf(pHlp, " Pointer = %#x\n", PprLogBTailPtr.n.u15Ptr);
3048 }
3049 /* Event Log B Head Pointer. */
3050 {
3051 EVT_LOG_B_HEAD_PTR_T const EvtLogBHeadPtr = pThis->EvtLogBHeadPtr;
3052 pHlp->pfnPrintf(pHlp, " Event Log B Head Pointer = %#RX64\n", EvtLogBHeadPtr.u64);
3053 pHlp->pfnPrintf(pHlp, " Pointer = %#x\n", EvtLogBHeadPtr.n.u15Ptr);
3054 }
3055 /* Event Log B Tail Pointer. */
3056 {
3057 EVT_LOG_B_TAIL_PTR_T const EvtLogBTailPtr = pThis->EvtLogBTailPtr;
3058 pHlp->pfnPrintf(pHlp, " Event Log B Tail Pointer = %#RX64\n", EvtLogBTailPtr.u64);
3059 pHlp->pfnPrintf(pHlp, " Pointer = %#x\n", EvtLogBTailPtr.n.u15Ptr);
3060 }
3061 /* PPR Log Auto Response Register. */
3062 {
3063 PPR_LOG_AUTO_RESP_T const PprLogAutoResp = pThis->PprLogAutoResp;
3064 pHlp->pfnPrintf(pHlp, " PPR Log Auto Response Register = %#RX64\n", PprLogAutoResp.u64);
3065 if (fVerbose)
3066 {
3067 pHlp->pfnPrintf(pHlp, " Code = %#x\n", PprLogAutoResp.n.u4AutoRespCode);
3068 pHlp->pfnPrintf(pHlp, " Mask Gen. = %RTbool\n", PprLogAutoResp.n.u1AutoRespMaskGen);
3069 }
3070 }
3071 /* PPR Log Overflow Early Warning Indicator Register. */
3072 {
3073 PPR_LOG_OVERFLOW_EARLY_T const PprLogOverflowEarly = pThis->PprLogOverflowEarly;
3074 pHlp->pfnPrintf(pHlp, " PPR Log overflow early warning = %#RX64\n", PprLogOverflowEarly.u64);
3075 if (fVerbose)
3076 {
3077 pHlp->pfnPrintf(pHlp, " Threshold = %#x\n", PprLogOverflowEarly.n.u15Threshold);
3078 pHlp->pfnPrintf(pHlp, " Interrupt enable = %RTbool\n", PprLogOverflowEarly.n.u1IntrEn);
3079 pHlp->pfnPrintf(pHlp, " Enable = %RTbool\n", PprLogOverflowEarly.n.u1Enable);
3080 }
3081 }
3082 /* PPR Log Overflow Early Warning Indicator Register. */
3083 {
3084 PPR_LOG_OVERFLOW_EARLY_T const PprLogBOverflowEarly = pThis->PprLogBOverflowEarly;
3085 pHlp->pfnPrintf(pHlp, " PPR Log B overflow early warning = %#RX64\n", PprLogBOverflowEarly.u64);
3086 if (fVerbose)
3087 {
3088 pHlp->pfnPrintf(pHlp, " Threshold = %#x\n", PprLogBOverflowEarly.n.u15Threshold);
3089 pHlp->pfnPrintf(pHlp, " Interrupt enable = %RTbool\n", PprLogBOverflowEarly.n.u1IntrEn);
3090 pHlp->pfnPrintf(pHlp, " Enable = %RTbool\n", PprLogBOverflowEarly.n.u1Enable);
3091 }
3092 }
3093}
3094
3095
3096/**
3097 * @callback_method_impl{FNSSMDEVSAVEEXEC}
3098 */
3099static DECLCALLBACK(int) iommuAmdR3SaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
3100{
3101 /** @todo IOMMU: Save state. */
3102 RT_NOREF2(pDevIns, pSSM);
3103 return VERR_NOT_IMPLEMENTED;
3104}
3105
3106
3107/**
3108 * @callback_method_impl{FNSSMDEVLOADEXEC}
3109 */
3110static DECLCALLBACK(int) iommuAmdR3LoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
3111{
3112 /** @todo IOMMU: Load state. */
3113 RT_NOREF4(pDevIns, pSSM, uVersion, uPass);
3114 return VERR_NOT_IMPLEMENTED;
3115}
3116
3117
3118/**
3119 * @interface_method_impl{PDMDEVREG,pfnReset}
3120 */
3121static DECLCALLBACK(void) iommuAmdR3Reset(PPDMDEVINS pDevIns)
3122{
3123 iommuAmdR3Init(pDevIns);
3124}
3125
3126
3127/**
3128 * @interface_method_impl{PDMDEVREG,pfnDestruct}
3129 */
3130static DECLCALLBACK(int) iommuAmdR3Destruct(PPDMDEVINS pDevIns)
3131{
3132 NOREF(pDevIns);
3133 return VINF_SUCCESS;
3134}
3135
3136
3137/**
3138 * @interface_method_impl{PDMDEVREG,pfnConstruct}
3139 */
3140static DECLCALLBACK(int) iommuAmdR3Construct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
3141{
3142 NOREF(iInstance);
3143
3144 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
3145 PIOMMU pThis = PDMDEVINS_2_DATA(pDevIns, PIOMMU);
3146 PIOMMUCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PIOMMUCC);
3147 PCPDMDEVHLPR3 pHlp = pDevIns->pHlpR3;
3148 int rc;
3149 LogFlowFunc(("\n"));
3150
3151 NOREF(pThisCC); /** @todo IOMMU: populate CC data. */
3152
3153 /*
3154 * Validate and read the configuration.
3155 */
3156 PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns, "Device|Function", "");
3157
3158 uint8_t uPciDevice;
3159 rc = pHlp->pfnCFGMQueryU8Def(pCfg, "Device", &uPciDevice, 0);
3160 if (RT_FAILURE(rc))
3161 return PDMDEV_SET_ERROR(pDevIns, rc, N_("IOMMU: Failed to query \"Device\""));
3162
3163 uint8_t uPciFunction;
3164 rc = pHlp->pfnCFGMQueryU8Def(pCfg, "Function", &uPciFunction, 2);
3165 if (RT_FAILURE(rc))
3166 return PDMDEV_SET_ERROR(pDevIns, rc, N_("IOMMU: Failed to query \"Function\""));
3167
3168 /*
3169 * Initialize read-only PCI configuration space.
3170 */
3171 PPDMPCIDEV pPciDev = pDevIns->apPciDevs[0];
3172 PDMPCIDEV_ASSERT_VALID(pDevIns, pPciDev);
3173
3174 /* Header. */
3175 PDMPciDevSetVendorId(pPciDev, IOMMU_PCI_VENDOR_ID); /* AMD */
3176 PDMPciDevSetDeviceId(pPciDev, IOMMU_PCI_DEVICE_ID); /* VirtualBox IOMMU device */
3177 PDMPciDevSetCommand(pPciDev, 0); /* Command */
3178 PDMPciDevSetStatus(pPciDev, 0x5); /* Status - CapList supported */
3179 PDMPciDevSetRevisionId(pPciDev, IOMMU_PCI_REVISION_ID); /* VirtualBox specific device implementation revision */
3180 PDMPciDevSetClassBase(pPciDev, 0x08); /* System Base Peripheral */
3181 PDMPciDevSetClassSub(pPciDev, 0x06); /* IOMMU */
3182 PDMPciDevSetClassProg(pPciDev, 0x00); /* IOMMU Programming interface */
3183 PDMPciDevSetHeaderType(pPciDev, 0x00); /* Single function, type 0. */
3184 PDMPciDevSetSubSystemId(pPciDev, IOMMU_PCI_DEVICE_ID); /* AMD */
3185 PDMPciDevSetSubSystemVendorId(pPciDev, IOMMU_PCI_VENDOR_ID); /* VirtualBox IOMMU device */
3186 PDMPciDevSetCapabilityList(pPciDev, IOMMU_PCI_OFF_CAP_HDR); /* Offset into capability registers. */
3187 PDMPciDevSetInterruptPin(pPciDev, 0x01); /* INTA#. */
3188 PDMPciDevSetInterruptLine(pPciDev, 0x00); /* For software compatibility; no effect on hardware. */
3189 /* Capability Header. */
3190 PDMPciDevSetDWord(pPciDev, IOMMU_PCI_OFF_CAP_HDR,
3191 RT_BF_MAKE(IOMMU_BF_CAPHDR_CAP_ID, 0xf) /* RO - Secure Device capability block */
3192 | RT_BF_MAKE(IOMMU_BF_CAPHDR_CAP_PTR, IOMMU_PCI_OFF_MSI_CAP_HDR) /* RO - Offset to next capability block */
3193 | RT_BF_MAKE(IOMMU_BF_CAPHDR_CAP_TYPE, 0x3) /* RO - IOMMU capability block */
3194 | RT_BF_MAKE(IOMMU_BF_CAPHDR_CAP_REV, 0x1) /* RO - IOMMU interface revision */
3195 | RT_BF_MAKE(IOMMU_BF_CAPHDR_IOTLB_SUP, 0x0) /* RO - Remote IOTLB support */
3196 | RT_BF_MAKE(IOMMU_BF_CAPHDR_HT_TUNNEL, 0x0) /* RO - HyperTransport Tunnel support */
3197 | RT_BF_MAKE(IOMMU_BF_CAPHDR_NP_CACHE, 0x0) /* RO - Cache NP page table entries */
3198 | RT_BF_MAKE(IOMMU_BF_CAPHDR_EFR_SUP, 0x1) /* RO - Extended Feature Register support */
3199 | RT_BF_MAKE(IOMMU_BF_CAPHDR_CAP_EXT, 0x1)); /* RO - Misc. Information Register support */
3200 /* Base Address Low Register. */
3201 PDMPciDevSetDWord(pPciDev, IOMMU_PCI_OFF_BASE_ADDR_REG_LO, 0x0); /* RW - Base address (Lo) and enable bit. */
3202 /* Base Address High Register. */
3203 PDMPciDevSetDWord(pPciDev, IOMMU_PCI_OFF_BASE_ADDR_REG_HI, 0x0); /* RW - Base address (Hi) */
3204 /* IOMMU Range Register. */
3205 PDMPciDevSetDWord(pPciDev, IOMMU_PCI_OFF_RANGE_REG, 0x0); /* RW - Range register. */
3206 /* Misc. Information Register 0. */
3207 PDMPciDevSetDWord(pPciDev, IOMMU_PCI_OFF_MISCINFO_REG_0,
3208 RT_BF_MAKE(IOMMU_BF_MISCINFO_0_MSI_NUM, 0x0) /* RO - MSI number */
3209 | RT_BF_MAKE(IOMMU_BF_MISCINFO_0_GVA_SIZE, 0x2) /* RO - Guest Virt. Addr size (2=48 bits) */
3210 | RT_BF_MAKE(IOMMU_BF_MISCINFO_0_PA_SIZE, 0x30) /* RO - Physical Addr size (48 bits) */
3211 | RT_BF_MAKE(IOMMU_BF_MISCINFO_0_VA_SIZE, 0x40) /* RO - Virt. Addr size (64 bits) */
3212 | RT_BF_MAKE(IOMMU_BF_MISCINFO_0_HT_ATS_RESV, 0x0) /* RW - HT ATS reserved */
3213 | RT_BF_MAKE(IOMMU_BF_MISCINFO_0_MSI_NUM_PPR, 0x0)); /* RW - PPR interrupt number */
3214 /* Misc. Information Register 1. */
3215 PDMPciDevSetDWord(pPciDev, IOMMU_PCI_OFF_MISCINFO_REG_0, 0);
3216 /* MSI Capability Header register. */
3217#if 0
3218 PDMPciDevSetDWord(pPciDev, IOMMU_PCI_OFF_MSI_CAP_HDR,
3219 RT_BF_MAKE(IOMMU_BF_MSI_CAPHDR_CAP_ID, 0x5) /* RO - Capability ID. */
3220 | RT_BF_MAKE(IOMMU_BF_MSI_CAPHDR_CAP_PTR, offMsiMapCapHdr) /* RO - Offset to next capability block */
3221 | RT_BF_MAKE(IOMMU_BF_MSI_CAPHDR_EN, 0x0) /* RW - MSI capability enable */
3222 | RT_BF_MAKE(IOMMU_BF_MSI_CAPHDR_MULTMESS_CAP, 0x0) /* RO - MSI multi-message capability */
3223 | RT_BF_MAKE(IOMMU_BF_MSI_CAPHDR_MULTMESS_EN, 0x0) /* RW - MSI multi-message enable */
3224 | RT_BF_MAKE(IOMMU_BF_MSI_CAPHDR_64BIT_EN, 0x1)); /* RO - MSI 64-bit enable */
3225#else
3226 PDMMSIREG MsiReg;
3227 RT_ZERO(MsiReg);
3228 MsiReg.cMsiVectors = 1;
3229 MsiReg.iMsiCapOffset = IOMMU_PCI_OFF_MSI_CAP_HDR;
3230 MsiReg.iMsiNextOffset = 0; /* IOMMU_PCI_OFF_MSI_MAP_CAP_HDR */
3231 rc = PDMDevHlpPCIRegisterMsi(pDevIns, &MsiReg);
3232 AssertRCReturn(rc, rc);
3233 /* This is later copied to its MMIO shadow register (MsiCapHdr), see iommuAmdR3Init. */
3234#endif
3235
3236 /* These read-write PCI config registers are initialized in iommuAmdR3Init. */
3237#if 0
3238 /* MSI Address Lo. */
3239 PDMPciDevSetDWord(pPciDev, IOMMU_PCI_OFF_MSI_ADDR_LO, 0); /* RW - MSI message address (Lo). */
3240 /* MSI Address Hi. */
3241 PDMPciDevSetDWord(pPciDev, IOMMU_PCI_OFF_MSI_ADDR_HI, 0); /* RW - MSI message address (Hi). */
3242 /* MSI Data. */
3243 PDMPciDevSetDWord(pPciDev, IOMMU_PCI_OFF_MSI_DATA, 0); /* RW - MSI data. */
3244#endif
3245
3246#if 0
3247 /** @todo IOMMU: I don't know if we need to support this, enable later if
3248 * required. */
3249 /* MSI Mapping Capability Header register. */
3250 PDMPciDevSetDWord(pPciDev, IOMMU_PCI_OFF_MSI_MAP_CAP_HDR,
3251 RT_BF_MAKE(IOMMU_BF_MSI_MAP_CAPHDR_CAP_ID, 0x8) /* RO - Capability ID */
3252 | RT_BF_MAKE(IOMMU_BF_MSI_MAP_CAPHDR_CAP_PTR, 0x0) /* RO - Offset to next capability (NULL) */
3253 | RT_BF_MAKE(IOMMU_BF_MSI_MAP_CAPHDR_EN, 0x1) /* RO - MSI mapping capability enable */
3254 | RT_BF_MAKE(IOMMU_BF_MSI_MAP_CAPHDR_FIXED, 0x1) /* RO - MSI mapping range is fixed */
3255 | RT_BF_MAKE(IOMMU_BF_MSI_MAP_CAPHDR_CAP_TYPE, 0x15)); /* RO - MSI mapping capability */
3256 /* When implementing don't forget to copy this to its MMIO shadow register (MsiMapCapHdr) in iommuAmdR3Init. */
3257#endif
3258
3259 /*
3260 * Initialize parts of the IOMMU state as it would during reset.
3261 * Must be called -after- initializing PCI config. space registers.
3262 */
3263 iommuAmdR3Init(pDevIns);
3264
3265 /*
3266 * Register the PCI function with PDM.
3267 */
3268 rc = PDMDevHlpPCIRegisterEx(pDevIns, pPciDev, 0 /* fFlags */, uPciDevice, uPciFunction, "amd-iommu");
3269 AssertLogRelRCReturn(rc, rc);
3270
3271 /*
3272 * Intercept PCI config. space accesses.
3273 */
3274 rc = PDMDevHlpPCIInterceptConfigAccesses(pDevIns, pPciDev, iommuAmdR3PciConfigRead, iommuAmdR3PciConfigWrite);
3275 AssertRCReturn(rc, rc);
3276
3277 /*
3278 * Register the MMIO region.
3279 */
3280 rc = PDMDevHlpMmioCreate(pDevIns, IOMMU_MMIO_REGION_SIZE, pPciDev, 0 /* iPciRegion */, iommuAmdMmioWrite, iommuAmdMmioRead,
3281 NULL /* pvUser */, IOMMMIO_FLAGS_READ_DWORD_QWORD | IOMMMIO_FLAGS_WRITE_DWORD_QWORD_ZEROED,
3282 "AMD-IOMMU", &pThis->hMmio);
3283 AssertRCReturn(rc, rc);
3284
3285 /*
3286 * Register saved state.
3287 */
3288 rc = PDMDevHlpSSMRegisterEx(pDevIns, IOMMU_SAVED_STATE_VERSION, sizeof(IOMMU), NULL,
3289 NULL, NULL, NULL,
3290 NULL, iommuAmdR3SaveExec, NULL,
3291 NULL, iommuAmdR3LoadExec, NULL);
3292 AssertRCReturn(rc, rc);
3293
3294 /*
3295 * Register debugger info item.
3296 */
3297 rc = PDMDevHlpDBGFInfoRegister(pDevIns, "iommu", "Display IOMMU state.", iommuAmdR3DbgInfo);
3298 AssertRCReturn(rc, rc);
3299
3300 return VINF_SUCCESS;
3301}
3302
3303# else /* !IN_RING3 */
3304
3305/**
3306 * @callback_method_impl{PDMDEVREGR0,pfnConstruct}
3307 */
3308static DECLCALLBACK(int) iommuAmdRZConstruct(PPDMDEVINS pDevIns)
3309{
3310 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
3311 return VINF_SUCCESS;
3312}
3313
3314# endif /* !IN_RING3 */
3315
3316/**
3317 * The device registration structure.
3318 */
3319const PDMDEVREG g_DeviceIommuAmd =
3320{
3321 /* .u32Version = */ PDM_DEVREG_VERSION,
3322 /* .uReserved0 = */ 0,
3323 /* .szName = */ "iommu-amd",
3324 /* .fFlags = */ PDM_DEVREG_FLAGS_DEFAULT_BITS | PDM_DEVREG_FLAGS_RZ | PDM_DEVREG_FLAGS_NEW_STYLE,
3325 /* .fClass = */ PDM_DEVREG_CLASS_BUS_ISA, /* Instantiate after PDM_DEVREG_CLASS_BUS_PCI */
3326 /* .cMaxInstances = */ ~0U,
3327 /* .uSharedVersion = */ 42,
3328 /* .cbInstanceShared = */ sizeof(IOMMU),
3329 /* .cbInstanceCC = */ sizeof(IOMMUCC),
3330 /* .cbInstanceRC = */ sizeof(IOMMURC),
3331 /* .cMaxPciDevices = */ 1,
3332 /* .cMaxMsixVectors = */ 0,
3333 /* .pszDescription = */ "IOMMU (AMD)",
3334#if defined(IN_RING3)
3335 /* .pszRCMod = */ "VBoxDDRC.rc",
3336 /* .pszR0Mod = */ "VBoxDDR0.r0",
3337 /* .pfnConstruct = */ iommuAmdR3Construct,
3338 /* .pfnDestruct = */ iommuAmdR3Destruct,
3339 /* .pfnRelocate = */ NULL,
3340 /* .pfnMemSetup = */ NULL,
3341 /* .pfnPowerOn = */ NULL,
3342 /* .pfnReset = */ iommuAmdR3Reset,
3343 /* .pfnSuspend = */ NULL,
3344 /* .pfnResume = */ NULL,
3345 /* .pfnAttach = */ NULL,
3346 /* .pfnDetach = */ NULL,
3347 /* .pfnQueryInterface = */ NULL,
3348 /* .pfnInitComplete = */ NULL,
3349 /* .pfnPowerOff = */ NULL,
3350 /* .pfnSoftReset = */ NULL,
3351 /* .pfnReserved0 = */ NULL,
3352 /* .pfnReserved1 = */ NULL,
3353 /* .pfnReserved2 = */ NULL,
3354 /* .pfnReserved3 = */ NULL,
3355 /* .pfnReserved4 = */ NULL,
3356 /* .pfnReserved5 = */ NULL,
3357 /* .pfnReserved6 = */ NULL,
3358 /* .pfnReserved7 = */ NULL,
3359#elif defined(IN_RING0)
3360 /* .pfnEarlyConstruct = */ NULL,
3361 /* .pfnConstruct = */ iommuAmdRZConstruct,
3362 /* .pfnDestruct = */ NULL,
3363 /* .pfnFinalDestruct = */ NULL,
3364 /* .pfnRequest = */ NULL,
3365 /* .pfnReserved0 = */ NULL,
3366 /* .pfnReserved1 = */ NULL,
3367 /* .pfnReserved2 = */ NULL,
3368 /* .pfnReserved3 = */ NULL,
3369 /* .pfnReserved4 = */ NULL,
3370 /* .pfnReserved5 = */ NULL,
3371 /* .pfnReserved6 = */ NULL,
3372 /* .pfnReserved7 = */ NULL,
3373#elif defined(IN_RC)
3374 /* .pfnConstruct = */ iommuAmdRZConstruct,
3375 /* .pfnReserved0 = */ NULL,
3376 /* .pfnReserved1 = */ NULL,
3377 /* .pfnReserved2 = */ NULL,
3378 /* .pfnReserved3 = */ NULL,
3379 /* .pfnReserved4 = */ NULL,
3380 /* .pfnReserved5 = */ NULL,
3381 /* .pfnReserved6 = */ NULL,
3382 /* .pfnReserved7 = */ NULL,
3383#else
3384# error "Not in IN_RING3, IN_RING0 or IN_RC!"
3385#endif
3386 /* .u32VersionEnd = */ PDM_DEVREG_VERSION
3387};
3388
3389#endif /* !VBOX_DEVICE_STRUCT_TESTCASE */
3390
Note: See TracBrowser for help on using the repository browser.

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