VirtualBox

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

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette