VirtualBox

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

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