VirtualBox

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

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

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