VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMR3/GICR3.cpp@ 108716

Last change on this file since 108716 was 108716, checked in by vboxsync, 3 weeks ago

VMM/GIC: bugref:10877 ITS bits, trying guest to probe/enable the ITS. [work-in-progress]

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 42.6 KB
Line 
1/* $Id: GICR3.cpp 108716 2025-03-24 12:43:36Z vboxsync $ */
2/** @file
3 * GIC - Generic Interrupt Controller Architecture (GIC).
4 */
5
6/*
7 * Copyright (C) 2023-2024 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28
29/*********************************************************************************************************************************
30* Header Files *
31*********************************************************************************************************************************/
32#define LOG_GROUP LOG_GROUP_DEV_GIC
33#include <VBox/log.h>
34#include "GICInternal.h"
35#include <VBox/vmm/pdmgic.h>
36#include <VBox/vmm/cpum.h>
37#include <VBox/vmm/hm.h>
38#include <VBox/vmm/mm.h>
39#include <VBox/vmm/pdmdev.h>
40#include <VBox/vmm/ssm.h>
41#include <VBox/vmm/vm.h>
42
43#include <iprt/armv8.h>
44
45
46#ifndef VBOX_DEVICE_STRUCT_TESTCASE
47
48
49/*********************************************************************************************************************************
50* Defined Constants And Macros *
51*********************************************************************************************************************************/
52/** GIC saved state version. */
53#define GIC_SAVED_STATE_VERSION 7
54
55# define GIC_SYSREGRANGE(a_uFirst, a_uLast, a_szName) \
56 { (a_uFirst), (a_uLast), kCpumSysRegRdFn_GicIcc, kCpumSysRegWrFn_GicIcc, 0, 0, 0, 0, 0, 0, a_szName, { 0 }, { 0 }, { 0 }, { 0 } }
57
58
59/*********************************************************************************************************************************
60* Global Variables *
61*********************************************************************************************************************************/
62/**
63 * System register ranges for the GIC.
64 */
65static CPUMSYSREGRANGE const g_aSysRegRanges_GIC[] =
66{
67 GIC_SYSREGRANGE(ARMV8_AARCH64_SYSREG_ICC_PMR_EL1, ARMV8_AARCH64_SYSREG_ICC_PMR_EL1, "ICC_PMR_EL1"),
68 GIC_SYSREGRANGE(ARMV8_AARCH64_SYSREG_ICC_IAR0_EL1, ARMV8_AARCH64_SYSREG_ICC_AP0R3_EL1, "ICC_IAR0_EL1 - ICC_AP0R3_EL1"),
69 GIC_SYSREGRANGE(ARMV8_AARCH64_SYSREG_ICC_AP1R0_EL1, ARMV8_AARCH64_SYSREG_ICC_NMIAR1_EL1, "ICC_AP1R0_EL1 - ICC_NMIAR1_EL1"),
70 GIC_SYSREGRANGE(ARMV8_AARCH64_SYSREG_ICC_DIR_EL1, ARMV8_AARCH64_SYSREG_ICC_SGI0R_EL1, "ICC_DIR_EL1 - ICC_SGI0R_EL1"),
71 GIC_SYSREGRANGE(ARMV8_AARCH64_SYSREG_ICC_IAR1_EL1, ARMV8_AARCH64_SYSREG_ICC_IGRPEN1_EL1, "ICC_IAR1_EL1 - ICC_IGRPEN1_EL1"),
72 GIC_SYSREGRANGE(ARMV8_AARCH64_SYSREG_ICC_SRE_EL2, ARMV8_AARCH64_SYSREG_ICC_SRE_EL2, "ICC_SRE_EL2"),
73 GIC_SYSREGRANGE(ARMV8_AARCH64_SYSREG_ICC_SRE_EL3, ARMV8_AARCH64_SYSREG_ICC_SRE_EL3, "ICC_SRE_EL3")
74};
75
76
77/**
78 * Dumps basic GIC state.
79 *
80 * @param pVM The cross context VM structure.
81 * @param pHlp The info helpers.
82 * @param pszArgs Arguments, ignored.
83 */
84static DECLCALLBACK(void) gicR3DbgInfo(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs)
85{
86 RT_NOREF(pszArgs);
87 PCGIC pGic = VM_TO_GIC(pVM);
88 PPDMDEVINS pDevIns = pGic->CTX_SUFF(pDevIns);
89 PCGICDEV pGicDev = PDMDEVINS_2_DATA(pDevIns, PCGICDEV);
90
91 pHlp->pfnPrintf(pHlp, "GIC:\n");
92 pHlp->pfnPrintf(pHlp, " uArchRev = %u\n", pGicDev->uArchRev);
93 pHlp->pfnPrintf(pHlp, " uMaxSpi = %u (upto IntId %u)\n", pGicDev->uMaxSpi, 32 * (pGicDev->uMaxSpi + 1));
94 pHlp->pfnPrintf(pHlp, " fExtSpi = %RTbool\n", pGicDev->fExtSpi);
95 pHlp->pfnPrintf(pHlp, " uMaxExtSpi = %u (upto IntId %u)\n", pGicDev->uMaxExtSpi,
96 GIC_INTID_RANGE_EXT_SPI_START - 1 + 32 * (pGicDev->uMaxExtSpi + 1));
97 pHlp->pfnPrintf(pHlp, " fExtPpi = %RTbool\n", pGicDev->fExtPpi);
98 pHlp->pfnPrintf(pHlp, " uMaxExtPpi = %u (upto IntId %u)\n", pGicDev->uMaxExtPpi,
99 pGicDev->uMaxExtPpi == GIC_REDIST_REG_TYPER_PPI_NUM_MAX_1087 ? 1087 : GIC_INTID_RANGE_EXT_PPI_LAST);
100 pHlp->pfnPrintf(pHlp, " fRangeSelSupport = %RTbool\n", pGicDev->fRangeSel);
101 pHlp->pfnPrintf(pHlp, " fNmi = %RTbool\n", pGicDev->fNmi);
102 pHlp->pfnPrintf(pHlp, " fMbi = %RTbool\n", pGicDev->fMbi);
103 pHlp->pfnPrintf(pHlp, " fAff3Levels = %RTbool\n", pGicDev->fAff3Levels);
104 pHlp->pfnPrintf(pHlp, " fLpi = %RTbool\n", pGicDev->fLpi);
105}
106
107
108/**
109 * Dumps GIC Distributor information.
110 *
111 * @param pVM The cross context VM structure.
112 * @param pHlp The info helpers.
113 * @param pszArgs Arguments, ignored.
114 */
115static DECLCALLBACK(void) gicR3DbgInfoDist(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs)
116{
117 RT_NOREF(pszArgs);
118
119 PGIC pGic = VM_TO_GIC(pVM);
120 PPDMDEVINS pDevIns = pGic->CTX_SUFF(pDevIns);
121 PCGICDEV pGicDev = PDMDEVINS_2_DATA(pDevIns, PCGICDEV);
122
123#define GIC_DBGFINFO_DIST_INTR_BITMAP(a_Name, a_bmIntr) \
124 do \
125 { \
126 pHlp->pfnPrintf(pHlp, " " a_Name " =\n"); \
127 for (uint32_t i = 0; i < RT_ELEMENTS(a_bmIntr); i += 8) \
128 pHlp->pfnPrintf(pHlp, " [%2u..%-2u] %#010x %#010x %#010x %#010x %#010x %#010x %#010x %#010x\n", i, i + 7, \
129 (a_bmIntr)[i], (a_bmIntr)[i+1], (a_bmIntr)[i+2], (a_bmIntr)[i+3], \
130 (a_bmIntr)[i+4], (a_bmIntr)[i+5], (a_bmIntr)[i+6], (a_bmIntr)[i+7]); \
131 } while (0)
132
133 pHlp->pfnPrintf(pHlp, "GIC Distributor:\n");
134 pHlp->pfnPrintf(pHlp, " fIntrGroup0Enabled = %RTbool\n", pGicDev->fIntrGroup0Enabled);
135 pHlp->pfnPrintf(pHlp, " fIntrGroup1Enabled = %RTbool\n", pGicDev->fIntrGroup1Enabled);
136 pHlp->pfnPrintf(pHlp, " fAffRoutingEnabled = %RTbool\n", pGicDev->fAffRoutingEnabled);
137 GIC_DBGFINFO_DIST_INTR_BITMAP("bmIntrGroup", pGicDev->bmIntrGroup);
138 GIC_DBGFINFO_DIST_INTR_BITMAP("bmIntrEnabled", pGicDev->bmIntrEnabled);
139 GIC_DBGFINFO_DIST_INTR_BITMAP("bmIntrPending", pGicDev->bmIntrPending);
140 GIC_DBGFINFO_DIST_INTR_BITMAP("bmIntrActive", pGicDev->bmIntrActive);
141
142 /* Interrupt priorities.*/
143 {
144 uint32_t const cPriorities = RT_ELEMENTS(pGicDev->abIntrPriority);
145 AssertCompile(!(cPriorities % 16));
146 pHlp->pfnPrintf(pHlp, " Interrupt priorities:\n");
147 for (uint32_t i = 0; i < cPriorities; i += 16)
148 pHlp->pfnPrintf(pHlp, " IntId[%4u..%-4u] = %3u %3u %3u %3u %3u %3u %3u %3u"
149 " IntId[%4u..%-4u] = %3u %3u %3u %3u %3u %3u %3u %3u\n",
150 gicDistGetIntIdFromIndex(i), gicDistGetIntIdFromIndex(i + 7),
151 pGicDev->abIntrPriority[i], pGicDev->abIntrPriority[i + 1],
152 pGicDev->abIntrPriority[i + 2], pGicDev->abIntrPriority[i + 3],
153 pGicDev->abIntrPriority[i + 4], pGicDev->abIntrPriority[i + 5],
154 pGicDev->abIntrPriority[i + 6], pGicDev->abIntrPriority[i + 7],
155 gicDistGetIntIdFromIndex(i + 8), gicDistGetIntIdFromIndex(i + 15),
156 pGicDev->abIntrPriority[i + 8], pGicDev->abIntrPriority[i + 9],
157 pGicDev->abIntrPriority[i + 10], pGicDev->abIntrPriority[i + 11],
158 pGicDev->abIntrPriority[i + 12], pGicDev->abIntrPriority[i + 13],
159 pGicDev->abIntrPriority[i + 14], pGicDev->abIntrPriority[i + 15]);
160 }
161
162 /* Interrupt routing.*/
163 {
164 /** @todo Interrupt rounting mode. */
165 uint32_t const cRouting = RT_ELEMENTS(pGicDev->au32IntrRouting);
166 AssertCompile(!(cRouting % 16));
167 pHlp->pfnPrintf(pHlp, " Interrupt routing:\n");
168 for (uint32_t i = 0; i < cRouting; i += 16)
169 pHlp->pfnPrintf(pHlp, " IntId[%4u..%-4u] = %3u %3u %3u %3u %3u %3u %3u %3u"
170 " IntId[%4u..%-4u] = %3u %3u %3u %3u %3u %3u %3u %3u\n",
171 gicDistGetIntIdFromIndex(i), gicDistGetIntIdFromIndex(i + 7),
172 pGicDev->au32IntrRouting[i], pGicDev->au32IntrRouting[i + 1],
173 pGicDev->au32IntrRouting[i + 2], pGicDev->au32IntrRouting[i + 3],
174 pGicDev->au32IntrRouting[i + 4], pGicDev->au32IntrRouting[i + 5],
175 pGicDev->au32IntrRouting[i + 6], pGicDev->au32IntrRouting[i + 7],
176 gicDistGetIntIdFromIndex(i + 8), gicDistGetIntIdFromIndex(i + 15),
177 pGicDev->au32IntrRouting[i + 8], pGicDev->au32IntrRouting[i + 9],
178 pGicDev->au32IntrRouting[i + 10], pGicDev->au32IntrRouting[i + 11],
179 pGicDev->au32IntrRouting[i + 12], pGicDev->au32IntrRouting[i + 13],
180 pGicDev->au32IntrRouting[i + 14], pGicDev->au32IntrRouting[i + 15]);
181 }
182
183#undef GIC_DBGFINFO_DIST_INTR_BITMAP
184}
185
186
187/**
188 * Dumps the GIC Redistributor information.
189 *
190 * @param pVM The cross context VM structure.
191 * @param pHlp The info helpers.
192 * @param pszArgs Arguments, ignored.
193 */
194static DECLCALLBACK(void) gicR3DbgInfoReDist(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs)
195{
196 NOREF(pszArgs);
197 PVMCPU pVCpu = VMMGetCpu(pVM);
198 if (!pVCpu)
199 pVCpu = pVM->apCpusR3[0];
200
201 PCGICCPU pGicCpu = VMCPU_TO_GICCPU(pVCpu);
202
203 pHlp->pfnPrintf(pHlp, "VCPU[%u] Redistributor:\n", pVCpu->idCpu);
204 AssertCompile(RT_ELEMENTS(pGicCpu->bmIntrGroup) >= 3);
205 AssertCompile(RT_ELEMENTS(pGicCpu->bmIntrEnabled) >= 3);
206 AssertCompile(RT_ELEMENTS(pGicCpu->bmIntrPending) >= 3);
207 AssertCompile(RT_ELEMENTS(pGicCpu->bmIntrActive) >= 3);
208 pHlp->pfnPrintf(pHlp, " bmIntrGroup[0..2] = %#010x %#010x %#010x\n", pGicCpu->bmIntrGroup[0], pGicCpu->bmIntrGroup[1], pGicCpu->bmIntrGroup[2]);
209 pHlp->pfnPrintf(pHlp, " bmIntrEnabled[0..2] = %#010x %#010x %#010x\n", pGicCpu->bmIntrEnabled[0], pGicCpu->bmIntrEnabled[1], pGicCpu->bmIntrEnabled[2]);
210 pHlp->pfnPrintf(pHlp, " bmIntrPending[0..2] = %#010x %#010x %#010x\n", pGicCpu->bmIntrPending[0], pGicCpu->bmIntrPending[1], pGicCpu->bmIntrPending[2]);
211 pHlp->pfnPrintf(pHlp, " bmIntrActive[0..2] = %#010x %#010x %#010x\n", pGicCpu->bmIntrActive[0], pGicCpu->bmIntrActive[1], pGicCpu->bmIntrActive[2]);
212
213 /* Interrupt priorities. */
214 {
215 uint32_t const cPriorities = RT_ELEMENTS(pGicCpu->abIntrPriority);
216 AssertCompile(!(cPriorities % 16));
217 pHlp->pfnPrintf(pHlp, " Interrupt priorities:\n");
218 for (uint32_t i = 0; i < cPriorities; i += 16)
219 pHlp->pfnPrintf(pHlp, " IntId[%4u..%-4u] = %3u %3u %3u %3u %3u %3u %3u %3u"
220 " IntId[%4u..%-4u] = %3u %3u %3u %3u %3u %3u %3u %3u\n",
221 gicReDistGetIntIdFromIndex(i), gicReDistGetIntIdFromIndex(i + 7),
222 pGicCpu->abIntrPriority[i], pGicCpu->abIntrPriority[i + 1],
223 pGicCpu->abIntrPriority[i + 2], pGicCpu->abIntrPriority[i + 3],
224 pGicCpu->abIntrPriority[i + 4], pGicCpu->abIntrPriority[i + 5],
225 pGicCpu->abIntrPriority[i + 6], pGicCpu->abIntrPriority[i + 7],
226 gicReDistGetIntIdFromIndex(i + 8), gicReDistGetIntIdFromIndex(i + 15),
227 pGicCpu->abIntrPriority[i + 8], pGicCpu->abIntrPriority[i + 9],
228 pGicCpu->abIntrPriority[i + 10], pGicCpu->abIntrPriority[i + 11],
229 pGicCpu->abIntrPriority[i + 12], pGicCpu->abIntrPriority[i + 13],
230 pGicCpu->abIntrPriority[i + 14], pGicCpu->abIntrPriority[i + 15]);
231 }
232
233 pHlp->pfnPrintf(pHlp, "\nVCPU[%u] ICC system register state:\n", pVCpu->idCpu);
234 pHlp->pfnPrintf(pHlp, " uIccCtlr = %#RX64\n", pGicCpu->uIccCtlr);
235 pHlp->pfnPrintf(pHlp, " fIntrGroup0Enabled = %RTbool\n", pGicCpu->fIntrGroup0Enabled);
236 pHlp->pfnPrintf(pHlp, " fIntrGroup1Enabled = %RTbool\n", pGicCpu->fIntrGroup1Enabled);
237 pHlp->pfnPrintf(pHlp, " bBinaryPtGroup0 = %#x\n", pGicCpu->bBinaryPtGroup0);
238 pHlp->pfnPrintf(pHlp, " bBinaryPtGroup1 = %#x\n", pGicCpu->bBinaryPtGroup1);
239 pHlp->pfnPrintf(pHlp, " idxRunningPriority = %#x\n", pGicCpu->idxRunningPriority);
240 pHlp->pfnPrintf(pHlp, " Running priority = %#x\n", pGicCpu->abRunningPriorities[pGicCpu->idxRunningPriority]);
241
242 /* Running interrupt priorities. */
243 {
244 uint32_t const cPriorities = RT_ELEMENTS(pGicCpu->abRunningPriorities);
245 AssertCompile(!(cPriorities % 16));
246 pHlp->pfnPrintf(pHlp, " Running-interrupt priorities:\n");
247 for (uint32_t i = 0; i < cPriorities; i += 16)
248 pHlp->pfnPrintf(pHlp, " [%3u..%-3u] = %3u %3u %3u %3u %3u %3u %3u %3u"
249 " [%3u..%-3u] = %3u %3u %3u %3u %3u %3u %3u %3u\n",
250 i, i + 7,
251 pGicCpu->abRunningPriorities[i], pGicCpu->abRunningPriorities[i + 1],
252 pGicCpu->abRunningPriorities[i + 2], pGicCpu->abRunningPriorities[i + 3],
253 pGicCpu->abRunningPriorities[i + 4], pGicCpu->abRunningPriorities[i + 5],
254 pGicCpu->abRunningPriorities[i + 6], pGicCpu->abRunningPriorities[i + 7],
255 i + 8, i + 15,
256 pGicCpu->abRunningPriorities[i + 8], pGicCpu->abRunningPriorities[i + 9],
257 pGicCpu->abRunningPriorities[i + 10], pGicCpu->abRunningPriorities[i + 11],
258 pGicCpu->abRunningPriorities[i + 12], pGicCpu->abRunningPriorities[i + 13],
259 pGicCpu->abRunningPriorities[i + 14], pGicCpu->abRunningPriorities[i + 15]);
260 }
261
262 AssertCompile(RT_ELEMENTS(pGicCpu->bmActivePriorityGroup0) >= 4);
263 pHlp->pfnPrintf(pHlp, " Active-interrupt priorities Group 0:\n");
264 pHlp->pfnPrintf(pHlp, " [0..3] = %#010x %#010x %#010x %#010x\n",
265 pGicCpu->bmActivePriorityGroup0[0], pGicCpu->bmActivePriorityGroup0[1],
266 pGicCpu->bmActivePriorityGroup0[2], pGicCpu->bmActivePriorityGroup0[3]);
267 AssertCompile(RT_ELEMENTS(pGicCpu->bmActivePriorityGroup1) >= 4);
268 pHlp->pfnPrintf(pHlp, " Active-interrupt priorities Group 1:\n");
269 pHlp->pfnPrintf(pHlp, " [0..3] = %#010x %#010x %#010x %#010x\n",
270 pGicCpu->bmActivePriorityGroup1[0], pGicCpu->bmActivePriorityGroup1[1],
271 pGicCpu->bmActivePriorityGroup1[2], pGicCpu->bmActivePriorityGroup1[3]);
272}
273
274
275/**
276 * Dumps the GIC ITS information.
277 *
278 * @param pVM The cross context VM structure.
279 * @param pHlp The info helpers.
280 * @param pszArgs Arguments, ignored.
281 */
282static DECLCALLBACK(void) gicR3DbgInfoIts(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs)
283{
284 PGIC pGic = VM_TO_GIC(pVM);
285 PPDMDEVINS pDevIns = pGic->CTX_SUFF(pDevIns);
286 PCGICDEV pGicDev = PDMDEVINS_2_DATA(pDevIns, PCGICDEV);
287 if (pGicDev->hMmioGits != NIL_IOMMMIOHANDLE)
288 {
289 PCGITSDEV pGitsDev = &pGicDev->Gits;
290 gitsR3DbgInfo(pGitsDev, pHlp, pszArgs);
291 }
292 else
293 pHlp->pfnPrintf(pHlp, "GIC ITS is not mapped/configured for the VM\n");
294}
295
296
297/**
298 * @copydoc FNSSMDEVSAVEEXEC
299 */
300static DECLCALLBACK(int) gicR3SaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
301{
302 PCVM pVM = PDMDevHlpGetVM(pDevIns);
303 PCPDMDEVHLPR3 pHlp = pDevIns->pHlpR3;
304 PCGICDEV pGicDev = PDMDEVINS_2_DATA(pDevIns, PCGICDEV);
305 AssertPtrReturn(pVM, VERR_INVALID_VM_HANDLE);
306 LogFlowFunc(("\n"));
307
308 /*
309 * Save per-VM data.
310 */
311 pHlp->pfnSSMPutU32(pSSM, pVM->cCpus);
312 pHlp->pfnSSMPutU8(pSSM, pGicDev->uArchRev);
313 pHlp->pfnSSMPutU8(pSSM, pGicDev->uMaxSpi);
314 pHlp->pfnSSMPutBool(pSSM, pGicDev->fExtSpi);
315 pHlp->pfnSSMPutU8(pSSM, pGicDev->uMaxExtSpi);
316 pHlp->pfnSSMPutBool(pSSM, pGicDev->fExtPpi);
317 pHlp->pfnSSMPutU8(pSSM, pGicDev->uMaxExtPpi);
318 pHlp->pfnSSMPutBool(pSSM, pGicDev->fRangeSel);
319 pHlp->pfnSSMPutBool(pSSM, pGicDev->fNmi);
320 pHlp->pfnSSMPutBool(pSSM, pGicDev->fMbi);
321 pHlp->pfnSSMPutBool(pSSM, pGicDev->fAff3Levels);
322 pHlp->pfnSSMPutBool(pSSM, pGicDev->fLpi);
323
324 /* Distributor state. */
325 pHlp->pfnSSMPutBool(pSSM, pGicDev->fIntrGroup0Enabled);
326 pHlp->pfnSSMPutBool(pSSM, pGicDev->fIntrGroup1Enabled);
327 pHlp->pfnSSMPutBool(pSSM, pGicDev->fAffRoutingEnabled);
328 pHlp->pfnSSMPutMem(pSSM, &pGicDev->bmIntrGroup[0], sizeof(pGicDev->bmIntrGroup));
329 pHlp->pfnSSMPutMem(pSSM, &pGicDev->bmIntrConfig[0], sizeof(pGicDev->bmIntrConfig));
330 pHlp->pfnSSMPutMem(pSSM, &pGicDev->bmIntrEnabled[0], sizeof(pGicDev->bmIntrEnabled));
331 pHlp->pfnSSMPutMem(pSSM, &pGicDev->bmIntrPending[0], sizeof(pGicDev->bmIntrPending));
332 pHlp->pfnSSMPutMem(pSSM, &pGicDev->bmIntrActive[0], sizeof(pGicDev->bmIntrActive));
333 pHlp->pfnSSMPutMem(pSSM, &pGicDev->abIntrPriority[0], sizeof(pGicDev->abIntrPriority));
334 pHlp->pfnSSMPutMem(pSSM, &pGicDev->au32IntrRouting[0], sizeof(pGicDev->au32IntrRouting));
335 pHlp->pfnSSMPutMem(pSSM, &pGicDev->bmIntrRoutingMode[0], sizeof(pGicDev->bmIntrRoutingMode));
336
337 /* We store the size followed by the data because we currently do not support the full LPI range. */
338 pHlp->pfnSSMPutU32(pSSM, sizeof(pGicDev->abLpiConfig));
339 pHlp->pfnSSMPutMem(pSSM, &pGicDev->abLpiConfig[0], sizeof(pGicDev->abLpiConfig));
340 pHlp->pfnSSMPutU32(pSSM, sizeof(pGicDev->bmLpiPending));
341 pHlp->pfnSSMPutMem(pSSM, &pGicDev->bmLpiPending[0], sizeof(pGicDev->bmLpiPending));
342
343 /** @todo GITS data. */
344
345 /*
346 * Save per-VCPU data.
347 */
348 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
349 {
350 PCGICCPU pGicCpu = VMCPU_TO_GICCPU(pVM->apCpusR3[idCpu]);
351 Assert(pGicCpu);
352
353 /* Redistributor state. */
354 pHlp->pfnSSMPutMem(pSSM, &pGicCpu->bmIntrGroup[0], sizeof(pGicCpu->bmIntrGroup));
355 pHlp->pfnSSMPutMem(pSSM, &pGicCpu->bmIntrConfig[0], sizeof(pGicCpu->bmIntrConfig));
356 pHlp->pfnSSMPutMem(pSSM, &pGicCpu->bmIntrEnabled[0], sizeof(pGicCpu->bmIntrEnabled));
357 pHlp->pfnSSMPutMem(pSSM, &pGicCpu->bmIntrPending[0], sizeof(pGicCpu->bmIntrPending));
358 pHlp->pfnSSMPutMem(pSSM, &pGicCpu->bmIntrActive[0], sizeof(pGicCpu->bmIntrActive));
359 pHlp->pfnSSMPutMem(pSSM, &pGicCpu->abIntrPriority[0], sizeof(pGicCpu->abIntrPriority));
360
361 /* ICC system register state. */
362 pHlp->pfnSSMPutU64(pSSM, pGicCpu->uIccCtlr);
363 pHlp->pfnSSMPutU8(pSSM, pGicCpu->bIntrPriorityMask);
364 pHlp->pfnSSMPutU8(pSSM, pGicCpu->idxRunningPriority);
365 pHlp->pfnSSMPutMem(pSSM, &pGicCpu->abRunningPriorities[0], sizeof(pGicCpu->abRunningPriorities));
366 pHlp->pfnSSMPutMem(pSSM, &pGicCpu->bmActivePriorityGroup0[0], sizeof(pGicCpu->bmActivePriorityGroup0));
367 pHlp->pfnSSMPutMem(pSSM, &pGicCpu->bmActivePriorityGroup1[0], sizeof(pGicCpu->bmActivePriorityGroup1));
368 pHlp->pfnSSMPutU8(pSSM, pGicCpu->bBinaryPtGroup0);
369 pHlp->pfnSSMPutU8(pSSM, pGicCpu->bBinaryPtGroup1);
370 pHlp->pfnSSMPutBool(pSSM, pGicCpu->fIntrGroup0Enabled);
371 pHlp->pfnSSMPutBool(pSSM, pGicCpu->fIntrGroup1Enabled);
372 }
373
374 return pHlp->pfnSSMPutU32(pSSM, UINT32_MAX);
375}
376
377
378/**
379 * @copydoc FNSSMDEVLOADEXEC
380 */
381static DECLCALLBACK(int) gicR3LoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
382{
383 PVM pVM = PDMDevHlpGetVM(pDevIns);
384 PCPDMDEVHLPR3 pHlp = pDevIns->pHlpR3;
385
386 AssertPtrReturn(pVM, VERR_INVALID_VM_HANDLE);
387 AssertReturn(uPass == SSM_PASS_FINAL, VERR_WRONG_ORDER);
388 LogFlowFunc(("uVersion=%u uPass=%#x\n", uVersion, uPass));
389
390 /*
391 * Validate supported saved-state versions.
392 */
393 if (uVersion != GIC_SAVED_STATE_VERSION)
394 return pHlp->pfnSSMSetCfgError(pSSM, RT_SRC_POS, N_("Invalid saved-state version %u"), uVersion);
395
396 /*
397 * Load per-VM data.
398 */
399 uint32_t cCpus;
400 pHlp->pfnSSMGetU32(pSSM, &cCpus);
401 if (cCpus != pVM->cCpus)
402 return pHlp->pfnSSMSetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch: cCpus: got=%u expected=%u"), cCpus, pVM->cCpus);
403
404 PGICDEV pGicDev = PDMDEVINS_2_DATA(pDevIns, PGICDEV);
405 pHlp->pfnSSMGetU8(pSSM, &pGicDev->uArchRev);
406 pHlp->pfnSSMGetU8(pSSM, &pGicDev->uMaxSpi);
407 pHlp->pfnSSMGetBool(pSSM, &pGicDev->fExtSpi);
408 pHlp->pfnSSMGetU8(pSSM, &pGicDev->uMaxExtSpi);
409 pHlp->pfnSSMGetBool(pSSM, &pGicDev->fExtPpi);
410 pHlp->pfnSSMGetU8(pSSM, &pGicDev->uMaxExtPpi);
411 pHlp->pfnSSMGetBool(pSSM, &pGicDev->fRangeSel);
412 pHlp->pfnSSMGetBool(pSSM, &pGicDev->fNmi);
413 pHlp->pfnSSMGetBool(pSSM, &pGicDev->fMbi);
414 pHlp->pfnSSMGetBool(pSSM, &pGicDev->fAff3Levels);
415 pHlp->pfnSSMGetBool(pSSM, &pGicDev->fLpi);
416
417 /* Distributor state. */
418 pHlp->pfnSSMGetBool(pSSM, &pGicDev->fIntrGroup0Enabled);
419 pHlp->pfnSSMGetBool(pSSM, &pGicDev->fIntrGroup1Enabled);
420 pHlp->pfnSSMGetBool(pSSM, &pGicDev->fAffRoutingEnabled);
421 pHlp->pfnSSMGetMem(pSSM, &pGicDev->bmIntrGroup[0], sizeof(pGicDev->bmIntrGroup));
422 pHlp->pfnSSMGetMem(pSSM, &pGicDev->bmIntrConfig[0], sizeof(pGicDev->bmIntrConfig));
423 pHlp->pfnSSMGetMem(pSSM, &pGicDev->bmIntrEnabled[0], sizeof(pGicDev->bmIntrEnabled));
424 pHlp->pfnSSMGetMem(pSSM, &pGicDev->bmIntrPending[0], sizeof(pGicDev->bmIntrPending));
425 pHlp->pfnSSMGetMem(pSSM, &pGicDev->bmIntrActive[0], sizeof(pGicDev->bmIntrActive));
426 pHlp->pfnSSMGetMem(pSSM, &pGicDev->abIntrPriority[0], sizeof(pGicDev->abIntrPriority));
427 pHlp->pfnSSMGetMem(pSSM, &pGicDev->au32IntrRouting[0], sizeof(pGicDev->au32IntrRouting));
428 pHlp->pfnSSMGetMem(pSSM, &pGicDev->bmIntrRoutingMode[0], sizeof(pGicDev->bmIntrRoutingMode));
429
430 /* LPI config. */
431 {
432 uint32_t cbData = 0;
433 int const rc = pHlp->pfnSSMGetU32(pSSM, &cbData);
434 AssertRCReturn(rc, rc);
435 if (cbData <= sizeof(pGicDev->abLpiConfig))
436 pHlp->pfnSSMGetMem(pSSM, &pGicDev->abLpiConfig[0], cbData);
437 else
438 return pHlp->pfnSSMSetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch: LPI config table size: got=%u expected=%u"),
439 cbData, sizeof(pGicDev->abLpiConfig));
440 }
441 /* LPI pending. */
442 {
443 uint32_t cbData = 0;
444 int const rc = pHlp->pfnSSMGetU32(pSSM, &cbData);
445 AssertRCReturn(rc, rc);
446 if (cbData <= sizeof(pGicDev->bmLpiPending))
447 pHlp->pfnSSMGetMem(pSSM, &pGicDev->bmLpiPending[0], cbData);
448 else
449 return pHlp->pfnSSMSetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch: LPI pending bitmap size: got=%u expected=%u"),
450 cbData, sizeof(pGicDev->bmLpiPending));
451 }
452
453 /** @todo GITS data. */
454
455 /*
456 * Load per-VCPU data.
457 */
458 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
459 {
460 PGICCPU pGicCpu = VMCPU_TO_GICCPU(pVM->apCpusR3[idCpu]);
461 Assert(pGicCpu);
462
463 /* Redistributor state. */
464 pHlp->pfnSSMGetMem(pSSM, &pGicCpu->bmIntrGroup[0], sizeof(pGicCpu->bmIntrGroup));
465 pHlp->pfnSSMGetMem(pSSM, &pGicCpu->bmIntrConfig[0], sizeof(pGicCpu->bmIntrConfig));
466 pHlp->pfnSSMGetMem(pSSM, &pGicCpu->bmIntrEnabled[0], sizeof(pGicCpu->bmIntrEnabled));
467 pHlp->pfnSSMGetMem(pSSM, &pGicCpu->bmIntrPending[0], sizeof(pGicCpu->bmIntrPending));
468 pHlp->pfnSSMGetMem(pSSM, &pGicCpu->bmIntrActive[0], sizeof(pGicCpu->bmIntrActive));
469 pHlp->pfnSSMGetMem(pSSM, &pGicCpu->abIntrPriority[0], sizeof(pGicCpu->abIntrPriority));
470
471 /* ICC system register state. */
472 pHlp->pfnSSMGetU64(pSSM, &pGicCpu->uIccCtlr);
473 pHlp->pfnSSMGetU8(pSSM, &pGicCpu->bIntrPriorityMask);
474 pHlp->pfnSSMGetU8(pSSM, &pGicCpu->idxRunningPriority);
475 pHlp->pfnSSMGetMem(pSSM, &pGicCpu->abRunningPriorities[0], sizeof(pGicCpu->abRunningPriorities));
476 pHlp->pfnSSMGetMem(pSSM, &pGicCpu->bmActivePriorityGroup0[0], sizeof(pGicCpu->bmActivePriorityGroup0));
477 pHlp->pfnSSMGetMem(pSSM, &pGicCpu->bmActivePriorityGroup1[0], sizeof(pGicCpu->bmActivePriorityGroup1));
478 pHlp->pfnSSMGetU8(pSSM, &pGicCpu->bBinaryPtGroup0);
479 pHlp->pfnSSMGetU8(pSSM, &pGicCpu->bBinaryPtGroup1);
480 pHlp->pfnSSMGetBool(pSSM, &pGicCpu->fIntrGroup0Enabled);
481 pHlp->pfnSSMGetBool(pSSM, &pGicCpu->fIntrGroup1Enabled);
482 }
483
484 /*
485 * Check that we're still good wrt restored data.
486 */
487 int rc = pHlp->pfnSSMHandleGetStatus(pSSM);
488 AssertRCReturn(rc, rc);
489
490 uint32_t uMarker = 0;
491 rc = pHlp->pfnSSMGetU32(pSSM, &uMarker);
492 AssertRCReturn(rc, rc);
493 if (uMarker == UINT32_MAX)
494 { /* likely */ }
495 else
496 return pHlp->pfnSSMSetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch: Marker: got=%u expected=%u"), uMarker, UINT32_MAX);
497
498 /*
499 * Finally, perform sanity checks.
500 */
501 if (pGicDev->uArchRev <= GIC_DIST_REG_PIDR2_ARCH_REV_GICV4)
502 { /* likely */ }
503 else
504 return pHlp->pfnSSMSetCfgError(pSSM, RT_SRC_POS, N_("Invalid uArchRev, got %u expected range [1,31]"), pGicDev->uArchRev,
505 GIC_DIST_REG_PIDR2_ARCH_REV_GICV1, GIC_DIST_REG_PIDR2_ARCH_REV_GICV4);
506 if (pGicDev->uMaxSpi - 1 < 31)
507 { /* likely */ }
508 else
509 return pHlp->pfnSSMSetCfgError(pSSM, RT_SRC_POS, N_("Invalid MaxSpi, got %u expected range [1,31]"), pGicDev->uMaxSpi);
510 if (pGicDev->uMaxExtSpi <= 31)
511 { /* likely */ }
512 else
513 return pHlp->pfnSSMSetCfgError(pSSM, RT_SRC_POS, N_("Invalid MaxExtSpi, got %u expected range [0,31]"), pGicDev->uMaxExtSpi);
514 if ( pGicDev->uMaxExtPpi == GIC_REDIST_REG_TYPER_PPI_NUM_MAX_1087
515 || pGicDev->uMaxExtPpi == GIC_REDIST_REG_TYPER_PPI_NUM_MAX_1119)
516 { /* likely */ }
517 else
518 return pHlp->pfnSSMSetCfgError(pSSM, RT_SRC_POS, N_("Invalid MaxExtPpi, got %u expected range [1,2]"), pGicDev->uMaxExtPpi);
519 bool const fIsGitsEnabled = RT_BOOL(pGicDev->hMmioGits != NIL_IOMMMIOHANDLE);
520 if (fIsGitsEnabled == pGicDev->fLpi)
521 { /* likely */ }
522 else
523 return pHlp->pfnSSMSetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch: LPIs are %s when ITS is %s"),
524 fIsGitsEnabled ? "enabled" : "disabled", pGicDev->fLpi ? "enabled" : "disabled");
525 return rc;
526}
527
528
529/**
530 * @interface_method_impl{PDMDEVREG,pfnReset}
531 */
532DECLCALLBACK(void) gicR3Reset(PPDMDEVINS pDevIns)
533{
534 PVM pVM = PDMDevHlpGetVM(pDevIns);
535 VM_ASSERT_EMT0(pVM);
536 VM_ASSERT_IS_NOT_RUNNING(pVM);
537
538 LogFlow(("GIC: gicR3Reset\n"));
539
540 gicReset(pDevIns);
541 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
542 {
543 PVMCPU pVCpuDest = pVM->apCpusR3[idCpu];
544 gicResetCpu(pDevIns, pVCpuDest);
545 }
546}
547
548
549/**
550 * @interface_method_impl{PDMDEVREG,pfnRelocate}
551 */
552DECLCALLBACK(void) gicR3Relocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta)
553{
554 RT_NOREF(pDevIns, offDelta);
555}
556
557
558/**
559 * @interface_method_impl{PDMDEVREG,pfnDestruct}
560 */
561DECLCALLBACK(int) gicR3Destruct(PPDMDEVINS pDevIns)
562{
563 LogFlowFunc(("pDevIns=%p\n", pDevIns));
564 PDMDEV_CHECK_VERSIONS_RETURN_QUIET(pDevIns);
565
566 return VINF_SUCCESS;
567}
568
569
570/**
571 * @interface_method_impl{PDMDEVREG,pfnConstruct}
572 */
573DECLCALLBACK(int) gicR3Construct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
574{
575 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
576 PGICDEV pGicDev = PDMDEVINS_2_DATA(pDevIns, PGICDEV);
577 PCPDMDEVHLPR3 pHlp = pDevIns->pHlpR3;
578 PVM pVM = PDMDevHlpGetVM(pDevIns);
579 PGIC pGic = VM_TO_GIC(pVM);
580 Assert(iInstance == 0); NOREF(iInstance);
581
582 /*
583 * Init the data.
584 */
585 pGic->pDevInsR3 = pDevIns;
586
587 /*
588 * Validate GIC settings.
589 */
590 PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns, "DistributorMmioBase|RedistributorMmioBase|ItsMmioBase"
591 "|ArchRev"
592 "|MaxSpi"
593 "|ExtSpi"
594 "|MaxExtSpi"
595 "|ExtPpi"
596 "|MaxExtPpi"
597 "|RangeSel"
598 "|Nmi"
599 "|Mbi"
600 "|Aff3Levels", "");
601
602#if 0
603 /*
604 * Disable automatic PDM locking for this device.
605 */
606 int rc = PDMDevHlpSetDeviceCritSect(pDevIns, PDMDevHlpCritSectGetNop(pDevIns));
607 AssertRCReturn(rc, rc);
608#endif
609
610 /** @devcfgm{gic, ArchRev, uint8_t, 3}
611 * Configures the GIC architecture revision (GICD_PIDR2.ArchRev and
612 * GICR_PIDR2.ArchRev).
613 *
614 * Currently we only support GICv3. */
615 int rc = pHlp->pfnCFGMQueryU8Def(pCfg, "ArchRev", &pGicDev->uArchRev, 3);
616 AssertLogRelRCReturn(rc, rc);
617 if (pGicDev->uArchRev == 3)
618 { /* likely */ }
619 else
620 return PDMDevHlpVMSetError(pDevIns, VERR_INVALID_PARAMETER, RT_SRC_POS,
621 N_("Configuration error: \"ArchRev\" value %u is not supported"), pGicDev->uArchRev);
622
623 /** @devcfgm{gic, MaxSpi, uint8_t, 31}
624 * Configures GICD_TYPER.ItLinesNumber.
625 *
626 * For the IntId range [32,1023], configures the maximum SPI supported. Valid values
627 * are [1,31] which equates to interrupt IDs [63,1023]. A value of 0 implies SPIs
628 * are not supported. We don't allow configuring this value as it's expected that
629 * most guests would assume support for SPIs. */
630 AssertCompile(GIC_DIST_REG_TYPER_NUM_ITLINES == 31);
631 /** @todo This currently isn't implemented and the full range is always
632 * supported. */
633 rc = pHlp->pfnCFGMQueryU8Def(pCfg, "MaxSpi", &pGicDev->uMaxSpi, 31 /* Upto and incl. IntId 1023 */);
634 AssertLogRelRCReturn(rc, rc);
635 if (pGicDev->uMaxSpi - 1 < 31)
636 { /* likely */ }
637 else
638 return PDMDevHlpVMSetError(pDevIns, VERR_INVALID_PARAMETER, RT_SRC_POS,
639 N_("Configuration error: \"MaxSpi\" must be in the range [1,%u]"),
640 GIC_DIST_REG_TYPER_NUM_ITLINES);
641
642 /** @devcfgm{gic, ExtSpi, bool, false}
643 * Configures whether extended SPIs supported is enabled (GICD_TYPER.ESPI). */
644 rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "ExtSpi", &pGicDev->fExtSpi, true);
645 AssertLogRelRCReturn(rc, rc);
646
647 /** @devcfgm{gic, MaxExtSpi, uint8_t, 31}
648 * Configures GICD_TYPER.ESPI_range.
649 *
650 * For the extended SPI range [4096,5119], configures the maximum extended SPI
651 * supported. Valid values are [0,31] which equates to extended SPI IntIds
652 * [4127,5119]. This is ignored (set to 0 in the register) when extended SPIs are
653 * disabled. */
654 AssertCompile(GIC_DIST_REG_TYPER_ESPI_RANGE >> GIC_DIST_REG_TYPER_ESPI_RANGE_BIT == 31);
655 /** @todo This currently isn't implemented and the full range is always
656 * supported. */
657 rc = pHlp->pfnCFGMQueryU8Def(pCfg, "MaxExtSpi", &pGicDev->uMaxExtSpi, 31);
658 AssertLogRelRCReturn(rc, rc);
659 if (pGicDev->uMaxExtSpi <= 31)
660 { /* likely */ }
661 else
662 return PDMDevHlpVMSetError(pDevIns, VERR_INVALID_PARAMETER, RT_SRC_POS,
663 N_("Configuration error: \"MaxExtSpi\" must be in the range [0,31]"));
664
665 /** @devcfgm{gic, ExtPpi, bool, true}
666 * Configures whether extended PPIs support is enabled. */
667 rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "ExtPpi", &pGicDev->fExtPpi, true);
668 AssertLogRelRCReturn(rc, rc);
669
670 /** @devcfgm{gic, MaxExtPpi, uint8_t, 2}
671 * Configures GICR_TYPER.PPInum.
672 *
673 * For the extended PPI range [1056,5119], configures the maximum extended PPI
674 * supported. Valid values are [1,2] which equates to extended PPI IntIds
675 * [1087,1119]. This is unused when extended PPIs are disabled. */
676 /** @todo This currently isn't implemented and the full range is always
677 * supported. */
678 rc = pHlp->pfnCFGMQueryU8Def(pCfg, "MaxExtPpi", &pGicDev->uMaxExtPpi, 2);
679 AssertLogRelRCReturn(rc, rc);
680 if ( pGicDev->uMaxExtPpi == GIC_REDIST_REG_TYPER_PPI_NUM_MAX_1087
681 || pGicDev->uMaxExtPpi == GIC_REDIST_REG_TYPER_PPI_NUM_MAX_1119)
682 { /* likely */ }
683 else
684 return PDMDevHlpVMSetError(pDevIns, VERR_INVALID_PARAMETER, RT_SRC_POS,
685 N_("Configuration error: \"MaxExtPpi\" must be in the range [0,2]"));
686
687 /** @devcfgm{gic, RangeSelSupport, bool, true}
688 * Configures whether range-selector support is enabled (GICD_TYPER.RSS and
689 * ICC_CTLR_EL1.RSS). */
690 rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "RangeSel", &pGicDev->fRangeSel, true);
691 AssertLogRelRCReturn(rc, rc);
692
693 /** @devcfgm{gic, Nmi, bool, false}
694 * Configures whether non-maskable interrupts (NMIs) are supported
695 * (GICD_TYPER.NMI). */
696 rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "Nmi", &pGicDev->fNmi, false);
697 AssertLogRelRCReturn(rc, rc);
698
699 /** @devcfgm{gic, Mbi, bool, true}
700 * Configures whether message-based interrupts (MBIs) are supported
701 * (GICD_TYPER.MBIS). */
702 rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "Mbi", &pGicDev->fMbi, true);
703 AssertLogRelRCReturn(rc, rc);
704
705 /** @devcfgm{gic, Aff3Levels, bool, true}
706 * Configures whether non-zero affinity 3 levels (A3V) are supported
707 * (GICD_TYPER.A3V and ICC_CTLR.A3V). */
708 rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "Aff3Levels", &pGicDev->fAff3Levels, true);
709 AssertLogRelRCReturn(rc, rc);
710
711 /** @devcfgm{gic, Lpi, bool, true}
712 * Configures whether physical LPIs are supported (GICD_TYPER.LPIS and
713 * GICR_TYPER.PLPIS). */
714 rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "Lpi", &pGicDev->fLpi, true);
715 AssertLogRelRCReturn(rc, rc);
716
717 /** @devcfgm{gic, MaxLpi, uint8_t, 14}
718 * Configures GICD_TYPER.num_LPIs.
719 *
720 * For the physical LPI range [8192,65535], configures the number of physical LPI
721 * supported. Valid values are [3,14] which equates to LPI IntIds 8192 to
722 * [8207,40959]. A value of 15 or higher would exceed the maximum INTID size of
723 * 16-bits since 8192 + 2^(NumLpi+1) is >= 73727. A value of 2 or lower support
724 * fewer than 15 LPIs which seem pointless and is hence disallowed. This value is
725 * ignored (set to 0 in the register) when LPIs are disabled. */
726 rc = pHlp->pfnCFGMQueryU8Def(pCfg, "MaxLpi", &pGicDev->uMaxLpi, 10);
727 AssertLogRelRCReturn(rc, rc);
728
729 /* We currently support 2048 LPIs until we need to support more. */
730 if (pGicDev->uMaxLpi == 10)
731 { /* likely */ }
732 else
733 return PDMDevHlpVMSetError(pDevIns, VERR_INVALID_PARAMETER, RT_SRC_POS,
734 N_("Configuration error: \"MaxLpi\" must be in the range [3,14]"));
735 AssertRelease(UINT32_C(2) << pGicDev->uMaxLpi <= RT_ELEMENTS(pGicDev->abLpiConfig));
736
737 /*
738 * Register the GIC with PDM.
739 */
740 rc = PDMDevHlpIcRegister(pDevIns);
741 AssertLogRelRCReturn(rc, rc);
742
743 rc = PDMGicRegisterBackend(pVM, PDMGICBACKENDTYPE_VBOX, &g_GicBackend);
744 AssertLogRelRCReturn(rc, rc);
745
746 /*
747 * Insert the GIC system registers.
748 */
749 for (uint32_t i = 0; i < RT_ELEMENTS(g_aSysRegRanges_GIC); i++)
750 {
751 rc = CPUMR3SysRegRangesInsert(pVM, &g_aSysRegRanges_GIC[i]);
752 AssertLogRelRCReturn(rc, rc);
753 }
754
755 /*
756 * Register the MMIO ranges.
757 */
758 /* Distributor. */
759 {
760 RTGCPHYS GCPhysMmioBase = 0;
761 rc = pHlp->pfnCFGMQueryU64(pCfg, "DistributorMmioBase", &GCPhysMmioBase);
762 if (RT_FAILURE(rc))
763 return PDMDEV_SET_ERROR(pDevIns, rc,
764 N_("Configuration error: Failed to get the \"DistributorMmioBase\" value"));
765
766 rc = PDMDevHlpMmioCreateAndMap(pDevIns, GCPhysMmioBase, GIC_DIST_REG_FRAME_SIZE, gicDistMmioWrite, gicDistMmioRead,
767 IOMMMIO_FLAGS_READ_DWORD | IOMMMIO_FLAGS_WRITE_DWORD_ZEROED, "GIC Distributor",
768 &pGicDev->hMmioDist);
769 AssertRCReturn(rc, rc);
770 }
771
772 /* Redistributor. */
773 {
774 RTGCPHYS GCPhysMmioBase = 0;
775 rc = pHlp->pfnCFGMQueryU64(pCfg, "RedistributorMmioBase", &GCPhysMmioBase);
776 if (RT_FAILURE(rc))
777 return PDMDEV_SET_ERROR(pDevIns, rc,
778 N_("Configuration error: Failed to get the \"RedistributorMmioBase\" value"));
779
780 RTGCPHYS const cbRegion = (RTGCPHYS)pVM->cCpus
781 * (GIC_REDIST_REG_FRAME_SIZE + GIC_REDIST_SGI_PPI_REG_FRAME_SIZE); /* Adjacent and per vCPU. */
782 rc = PDMDevHlpMmioCreateAndMap(pDevIns, GCPhysMmioBase, cbRegion, gicReDistMmioWrite, gicReDistMmioRead,
783 IOMMMIO_FLAGS_READ_DWORD | IOMMMIO_FLAGS_WRITE_DWORD_ZEROED, "GIC Redistributor",
784 &pGicDev->hMmioReDist);
785 AssertRCReturn(rc, rc);
786 }
787
788 /* ITS. */
789 {
790 RTGCPHYS GCPhysMmioBase = 0;
791 rc = pHlp->pfnCFGMQueryU64(pCfg, "ItsMmioBase", &GCPhysMmioBase);
792 if (RT_SUCCESS(rc))
793 {
794 RTGCPHYS const cbRegion = 2 * GITS_REG_FRAME_SIZE; /* 2 frames for GICv3. */
795 rc = PDMDevHlpMmioCreateAndMap(pDevIns, GCPhysMmioBase, cbRegion, gicItsMmioWrite, gicItsMmioRead,
796 IOMMMIO_FLAGS_READ_DWORD | IOMMMIO_FLAGS_WRITE_DWORD_ZEROED, "GIC ITS",
797 &pGicDev->hMmioGits);
798 AssertRCReturn(rc, rc);
799
800 /* When the ITS is enabled we must support LPIs. */
801 if (!pGicDev->fLpi)
802 return PDMDevHlpVMSetError(pDevIns, VERR_INVALID_PARAMETER, RT_SRC_POS,
803 N_("Configuration error: \"Lpi\" must be enabled when ITS is enabled\n"));
804 }
805 else
806 pGicDev->hMmioGits = NIL_IOMMMIOHANDLE;
807 }
808
809 /*
810 * Register saved state callbacks.
811 */
812 rc = PDMDevHlpSSMRegister(pDevIns, GIC_SAVED_STATE_VERSION, 0, gicR3SaveExec, gicR3LoadExec);
813 AssertRCReturn(rc, rc);
814
815 /*
816 * Register debugger info callbacks.
817 *
818 * We use separate callbacks rather than arguments so they can also be
819 * dumped in an automated fashion while collecting crash diagnostics and
820 * not just used during live debugging via the VM debugger.
821 */
822 DBGFR3InfoRegisterInternalEx(pVM, "gic", "Dumps GIC basic information.", gicR3DbgInfo, DBGFINFO_FLAGS_ALL_EMTS);
823 DBGFR3InfoRegisterInternalEx(pVM, "gicdist", "Dumps GIC distributor information.", gicR3DbgInfoDist, DBGFINFO_FLAGS_ALL_EMTS);
824 DBGFR3InfoRegisterInternalEx(pVM, "gicredist", "Dumps GIC redistributor information.", gicR3DbgInfoReDist, DBGFINFO_FLAGS_ALL_EMTS);
825 DBGFR3InfoRegisterInternalEx(pVM, "gicits", "Dumps GIC ITS information.", gicR3DbgInfoIts, DBGFINFO_FLAGS_ALL_EMTS);
826
827 /*
828 * Statistics.
829 */
830#ifdef VBOX_WITH_STATISTICS
831# define GIC_REG_COUNTER(a_pvReg, a_pszNameFmt, a_pszDesc) \
832 PDMDevHlpSTAMRegisterF(pDevIns, a_pvReg, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, \
833 a_pszDesc, a_pszNameFmt, idCpu)
834# define GIC_PROF_COUNTER(a_pvReg, a_pszNameFmt, a_pszDesc) \
835 PDMDevHlpSTAMRegisterF(pDevIns, a_pvReg, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, \
836 a_pszDesc, a_pszNameFmt, idCpu)
837
838 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
839 {
840 PVMCPU pVCpu = pVM->apCpusR3[idCpu];
841 PGICCPU pGicCpu = VMCPU_TO_GICCPU(pVCpu);
842
843 GIC_REG_COUNTER(&pGicCpu->StatMmioReadR3, "%u/MmioRead", "Number of MMIO reads in R3.");
844 GIC_REG_COUNTER(&pGicCpu->StatMmioWriteR3, "%u/MmioWrite", "Number of MMIO writes in R3.");
845 GIC_REG_COUNTER(&pGicCpu->StatSysRegReadR3, "%u/SysRegRead", "Number of system register reads in R3.");
846 GIC_REG_COUNTER(&pGicCpu->StatSysRegWriteR3, "%u/SysRegWrite", "Number of system register writes in R3.");
847 GIC_REG_COUNTER(&pGicCpu->StatSetSpiR3, "%u/SetSpi", "Number of set SPI callbacks in R3.");
848 GIC_REG_COUNTER(&pGicCpu->StatSetPpiR3, "%u/SetPpi", "Number of set PPI callbacks in R3.");
849 GIC_REG_COUNTER(&pGicCpu->StatSetSgiR3, "%u/SetSgi", "Number of SGIs generated in R3.");
850
851 GIC_PROF_COUNTER(&pGicCpu->StatProfIntrAckR3, "%u/Prof/IntrAck", "Profiling of interrupt acknowledge (IAR) in R3.");
852 GIC_PROF_COUNTER(&pGicCpu->StatProfSetSpiR3, "%u/Prof/SetSpi", "Profiling of set SPI callback in R3.");
853 GIC_PROF_COUNTER(&pGicCpu->StatProfSetPpiR3, "%u/Prof/SetPpi", "Profiling of set PPI callback in R3.");
854 GIC_PROF_COUNTER(&pGicCpu->StatProfSetSgiR3, "%u/Prof/SetSgi", "Profiling of SGIs generated in R3.");
855 }
856# undef GIC_REG_COUNTER
857# undef GIC_PROF_COUNTER
858#endif
859
860 gicR3Reset(pDevIns);
861
862 /*
863 * Log features/config.
864 */
865 uint8_t const uArchRev = pGicDev->uArchRev;
866 uint8_t const uMaxSpi = pGicDev->uMaxSpi;
867 bool const fExtSpi = pGicDev->fExtSpi;
868 uint8_t const uMaxExtSpi = pGicDev->uMaxExtSpi;
869 bool const fExtPpi = pGicDev->fExtPpi;
870 uint8_t const uMaxExtPpi = pGicDev->uMaxExtPpi;
871 bool const fRangeSel = pGicDev->fRangeSel;
872 bool const fNmi = pGicDev->fNmi;
873 bool const fMbi = pGicDev->fMbi;
874 bool const fAff3Levels = pGicDev->fAff3Levels;
875 bool const fLpi = pGicDev->fLpi;
876 uint16_t const uExtPpiLast = uMaxExtPpi == GIC_REDIST_REG_TYPER_PPI_NUM_MAX_1087 ? 1087 : GIC_INTID_RANGE_EXT_PPI_LAST;
877 LogRel(("GIC: ArchRev=%u RangeSel=%RTbool Nmi=%RTbool Mbi=%RTbool Aff3Levels=%RTbool Lpi=%RTbool\n",
878 uArchRev, fRangeSel, fNmi, fMbi, fAff3Levels, fLpi));
879 LogRel(("GIC: SPIs=true (%u:32..%u) ExtSPIs=%RTbool (%u:4095..%u) ExtPPIs=%RTbool (%u:1056..%u)\n",
880 uMaxSpi, 32 * (uMaxSpi + 1),
881 fExtSpi, uMaxExtSpi, GIC_INTID_RANGE_EXT_SPI_START - 1 + 32 * (uMaxExtSpi + 1),
882 fExtPpi, uMaxExtPpi, uExtPpiLast));
883 return VINF_SUCCESS;
884}
885
886#endif /* !VBOX_DEVICE_STRUCT_TESTCASE */
887
Note: See TracBrowser for help on using the repository browser.

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