VirtualBox

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

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

AMD IOMMU: bugref:9654 Doxygen burn fix.

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