VirtualBox

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

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