VirtualBox

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

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

AMD IOMMU: bugref:9654 Bits.

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