VirtualBox

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

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