1 | /* $Id: GICInternal.h 108824 2025-04-02 07:12:26Z 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 | #ifndef VMM_INCLUDED_SRC_include_GICInternal_h
|
---|
29 | #define VMM_INCLUDED_SRC_include_GICInternal_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | #include <VBox/gic.h>
|
---|
35 | #include <VBox/vmm/pdmdev.h>
|
---|
36 | #include <VBox/vmm/pdmgic.h>
|
---|
37 | #include <VBox/vmm/stam.h>
|
---|
38 |
|
---|
39 | #include "GITSInternal.h"
|
---|
40 |
|
---|
41 | /** @defgroup grp_gic_int Internal
|
---|
42 | * @ingroup grp_gic
|
---|
43 | * @internal
|
---|
44 | * @{
|
---|
45 | */
|
---|
46 |
|
---|
47 | #ifdef VBOX_INCLUDED_vmm_pdmgic_h
|
---|
48 | /** The VirtualBox GIC backend. */
|
---|
49 | extern const PDMGICBACKEND g_GicBackend;
|
---|
50 | # ifdef RT_OS_DARWIN
|
---|
51 | /** The Hypervisor.Framework GIC backend. */
|
---|
52 | extern const PDMGICBACKEND g_GicHvfBackend;
|
---|
53 | # elif defined(RT_OS_WINDOWS)
|
---|
54 | /** The Hyper-V GIC backend. */
|
---|
55 | extern const PDMGICBACKEND g_GicHvBackend;
|
---|
56 | # elif defined(RT_OS_LINUX)
|
---|
57 | /** The KVM GIC backend. */
|
---|
58 | extern const PDMGICBACKEND g_GicKvmBackend;
|
---|
59 | # endif
|
---|
60 | #endif
|
---|
61 |
|
---|
62 | #define VMCPU_TO_GICCPU(a_pVCpu) (&(a_pVCpu)->gic.s)
|
---|
63 | #define VM_TO_GIC(a_pVM) (&(a_pVM)->gic.s)
|
---|
64 | #define VM_TO_GICDEV(a_pVM) CTX_SUFF(VM_TO_GIC(a_pVM)->pGicDev)
|
---|
65 | #define GICDEV_TO_GITSDEV(a_GicDev) (&(a_GicDev)->Gits)
|
---|
66 | #ifdef IN_RING3
|
---|
67 | # define VMCPU_TO_DEVINS(a_pVCpu) ((a_pVCpu)->pVMR3->gic.s.pDevInsR3)
|
---|
68 | #elif defined(IN_RING0)
|
---|
69 | # error "Not implemented!"
|
---|
70 | #endif
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * GIC PDM instance data (per-VM).
|
---|
74 | */
|
---|
75 | typedef struct GICDEV
|
---|
76 | {
|
---|
77 | /** @name Distributor register state.
|
---|
78 | * @{
|
---|
79 | */
|
---|
80 | /** Interrupt group bitmap. */
|
---|
81 | uint32_t bmIntrGroup[64];
|
---|
82 | /** Interrupt config bitmap (edge-triggered vs level-sensitive). */
|
---|
83 | uint32_t bmIntrConfig[128];
|
---|
84 | /** Interrupt enabled bitmap. */
|
---|
85 | uint32_t bmIntrEnabled[64];
|
---|
86 | /** Interrupt pending bitmap. */
|
---|
87 | uint32_t bmIntrPending[64];
|
---|
88 | /** Interrupt active bitmap. */
|
---|
89 | uint32_t bmIntrActive[64];
|
---|
90 | /** Interrupt priorities. */
|
---|
91 | uint8_t abIntrPriority[2048];
|
---|
92 | /** Interrupt routing info. */
|
---|
93 | uint32_t au32IntrRouting[2048];
|
---|
94 | /** Interrupt routine mode bitmap. */
|
---|
95 | uint32_t bmIntrRoutingMode[64];
|
---|
96 | /** Flag whether group 0 interrupts are enabled. */
|
---|
97 | bool fIntrGroup0Enabled;
|
---|
98 | /** Flag whether group 1 interrupts are enabled. */
|
---|
99 | bool fIntrGroup1Enabled;
|
---|
100 | /** Flag whether affinity routing is enabled. */
|
---|
101 | bool fAffRoutingEnabled;
|
---|
102 | /** Alignment. */
|
---|
103 | bool fPadding0;
|
---|
104 | /** @} */
|
---|
105 |
|
---|
106 | /** @name Configurables.
|
---|
107 | * @{ */
|
---|
108 | /** The GIC architecture revision (GICD_PIDR2.ArchRev and GICR_PIDR2.ArchRev). */
|
---|
109 | uint8_t uArchRev;
|
---|
110 | /** The GIC architecture minor revision (currently 1 as we only support GICv3.1). */
|
---|
111 | uint8_t uArchRevMinor;
|
---|
112 | /** The maximum SPI supported (GICD_TYPER.ItLinesNumber). */
|
---|
113 | uint8_t uMaxSpi;
|
---|
114 | /** Whether extended SPIs are supported (GICD_ESPI). */
|
---|
115 | bool fExtSpi;
|
---|
116 | /** The maximum extended SPI supported (GICD_TYPER.ESPI_range). */
|
---|
117 | uint8_t uMaxExtSpi;
|
---|
118 | /** Whether extended PPIs are supported. */
|
---|
119 | bool fExtPpi;
|
---|
120 | /** The maximum extended PPI supported (GICR_TYPER.PPInum). */
|
---|
121 | uint8_t uMaxExtPpi;
|
---|
122 | /** Whether range-selector is supported (GICD_TYPER.RSS and ICC_CTLR_EL1.RSS). */
|
---|
123 | bool fRangeSel;
|
---|
124 | /** Whether NMIs are supported (GICD_TYPER.NMI). */
|
---|
125 | bool fNmi;
|
---|
126 | /** Whether message-based interrupts are supported (GICD_TYPER.MBIS). */
|
---|
127 | bool fMbi;
|
---|
128 | /** Whether non-zero affinity 3 levels are supported (GICD_TYPER.A3V) and
|
---|
129 | * (ICC_CTLR.A3V). */
|
---|
130 | bool fAff3Levels;
|
---|
131 | /** Whether LPIs are supported (GICD_TYPER.PLPIS). */
|
---|
132 | bool fLpi;
|
---|
133 | /** The maximum LPI supported (GICD_TYPER.num_LPI). */
|
---|
134 | uint8_t uMaxLpi;
|
---|
135 | /** Padding. */
|
---|
136 | bool afPadding0[3];
|
---|
137 | /** @} */
|
---|
138 |
|
---|
139 | /** @name GITS device data and LPIs.
|
---|
140 | * @{ */
|
---|
141 | /** ITS device state. */
|
---|
142 | GITSDEV Gits;
|
---|
143 | /** LPI config table (priority + enabled bit). */
|
---|
144 | uint8_t abLpiConfig[2048];
|
---|
145 | /** LPI pending bitmap. */
|
---|
146 | uint32_t bmLpiPending[64];
|
---|
147 | /** The LPI config table base address register (GICR_PROPBASER). */
|
---|
148 | RTUINT64U uLpiConfigBaseReg;
|
---|
149 | /** Whether LPIs are enabled (GICR_CTLR.EnableLpis) common to all
|
---|
150 | * redistributors). */
|
---|
151 | bool fEnableLpis;
|
---|
152 | /** Padding. */
|
---|
153 | bool afPadding1[7];
|
---|
154 | /** @} */
|
---|
155 |
|
---|
156 | /** @name MMIO data.
|
---|
157 | * @{ */
|
---|
158 | /** The distributor MMIO handle. */
|
---|
159 | IOMMMIOHANDLE hMmioDist;
|
---|
160 | /** The redistributor MMIO handle. */
|
---|
161 | IOMMMIOHANDLE hMmioReDist;
|
---|
162 | /** The interrupt translation service MMIO handle. */
|
---|
163 | IOMMMIOHANDLE hMmioGits;
|
---|
164 | /** @} */
|
---|
165 | } GICDEV;
|
---|
166 | /** Pointer to a GIC device. */
|
---|
167 | typedef GICDEV *PGICDEV;
|
---|
168 | /** Pointer to a const GIC device. */
|
---|
169 | typedef GICDEV const *PCGICDEV;
|
---|
170 | AssertCompileMemberSizeAlignment(GICDEV, Gits, 8);
|
---|
171 |
|
---|
172 | /**
|
---|
173 | * GIC VM Instance data.
|
---|
174 | */
|
---|
175 | typedef struct GIC
|
---|
176 | {
|
---|
177 | /** The ring-3 device instance. */
|
---|
178 | PPDMDEVINSR3 pDevInsR3;
|
---|
179 | } GIC;
|
---|
180 | /** Pointer to GIC VM instance data. */
|
---|
181 | typedef GIC *PGIC;
|
---|
182 | /** Pointer to const GIC VM instance data. */
|
---|
183 | typedef GIC const *PCGIC;
|
---|
184 | AssertCompileSizeAlignment(GIC, 8);
|
---|
185 |
|
---|
186 | /**
|
---|
187 | * GIC VMCPU Instance data.
|
---|
188 | */
|
---|
189 | typedef struct GICCPU
|
---|
190 | {
|
---|
191 | /** @name Redistributor register state.
|
---|
192 | * @{ */
|
---|
193 | /** Interrupt group bitmap. */
|
---|
194 | uint32_t bmIntrGroup[3];
|
---|
195 | /** Interrupt config bitmap (edge-triggered vs level-sensitive). */
|
---|
196 | uint32_t bmIntrConfig[6];
|
---|
197 | /** Interrupt enabled bitmap. */
|
---|
198 | uint32_t bmIntrEnabled[3];
|
---|
199 | /** Interrupt pending bitmap. */
|
---|
200 | uint32_t bmIntrPending[3];
|
---|
201 | /** Interrupt active bitmap. */
|
---|
202 | uint32_t bmIntrActive[3];
|
---|
203 | /** Interrupt priorities. */
|
---|
204 | uint8_t abIntrPriority[96];
|
---|
205 | /** @} */
|
---|
206 |
|
---|
207 | /** @name ICC system register state.
|
---|
208 | * @{ */
|
---|
209 | /** The control register (ICC_CTLR_EL1). */
|
---|
210 | uint64_t uIccCtlr;
|
---|
211 | /** The interrupt priority mask of the CPU interface (ICC_PMR_EL1). */
|
---|
212 | uint8_t bIntrPriorityMask;
|
---|
213 | /** The index to the current running priority. */
|
---|
214 | uint8_t idxRunningPriority;
|
---|
215 | /** The running priorities caused by preemption. */
|
---|
216 | uint8_t abRunningPriorities[256];
|
---|
217 | /** The active priorities group 0 bitmap. */
|
---|
218 | uint32_t bmActivePriorityGroup0[4];
|
---|
219 | /** The active priorities group 0 bitmap. */
|
---|
220 | uint32_t bmActivePriorityGroup1[4];
|
---|
221 | /** The binary point register for group 0 interrupts. */
|
---|
222 | uint8_t bBinaryPtGroup0;
|
---|
223 | /** The binary point register for group 1 interrupts. */
|
---|
224 | uint8_t bBinaryPtGroup1;
|
---|
225 | /** Flag whether group 0 interrupts are enabled. */
|
---|
226 | bool fIntrGroup0Enabled;
|
---|
227 | /** Flag whether group 1 interrupts are enabled. */
|
---|
228 | bool fIntrGroup1Enabled;
|
---|
229 | /** @} */
|
---|
230 |
|
---|
231 | /** @name Statistics.
|
---|
232 | * @{ */
|
---|
233 | #ifdef VBOX_WITH_STATISTICS
|
---|
234 | /** Number of MMIO reads in R3. */
|
---|
235 | STAMCOUNTER StatMmioReadR3;
|
---|
236 | /** Number of MMIO writes in R3. */
|
---|
237 | STAMCOUNTER StatMmioWriteR3;
|
---|
238 | /** Number of MSR reads in R3. */
|
---|
239 | STAMCOUNTER StatSysRegReadR3;
|
---|
240 | /** Number of MSR writes in R3. */
|
---|
241 | STAMCOUNTER StatSysRegWriteR3;
|
---|
242 | /** Number of set SPI callbacks. */
|
---|
243 | STAMCOUNTER StatSetSpiR3;
|
---|
244 | /** Number of set PPI callbacks. */
|
---|
245 | STAMCOUNTER StatSetPpiR3;
|
---|
246 | /** Number of SGIs generated. */
|
---|
247 | STAMCOUNTER StatSetSgiR3;
|
---|
248 |
|
---|
249 | /** Profiling of interrupt acknowledge (IAR). */
|
---|
250 | STAMPROFILE StatProfIntrAckR3;
|
---|
251 | /** Profiling of set SPI callback. */
|
---|
252 | STAMPROFILE StatProfSetSpiR3;
|
---|
253 | /** Profiling of set PPI callback. */
|
---|
254 | STAMPROFILE StatProfSetPpiR3;
|
---|
255 | /** Profiling of set SGI function. */
|
---|
256 | STAMPROFILE StatProfSetSgiR3;
|
---|
257 | #endif
|
---|
258 | /** @} */
|
---|
259 | } GICCPU;
|
---|
260 | /** Pointer to GIC VMCPU instance data. */
|
---|
261 | typedef GICCPU *PGICCPU;
|
---|
262 | /** Pointer to a const GIC VMCPU instance data. */
|
---|
263 | typedef GICCPU const *PCGICCPU;
|
---|
264 |
|
---|
265 | DECL_HIDDEN_CALLBACK(VBOXSTRICTRC) gicDistMmioRead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void *pv, unsigned cb);
|
---|
266 | DECL_HIDDEN_CALLBACK(VBOXSTRICTRC) gicDistMmioWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void const *pv, unsigned cb);
|
---|
267 | DECL_HIDDEN_CALLBACK(VBOXSTRICTRC) gicReDistMmioRead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void *pv, unsigned cb);
|
---|
268 | DECL_HIDDEN_CALLBACK(VBOXSTRICTRC) gicReDistMmioWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void const *pv, unsigned cb);
|
---|
269 | DECL_HIDDEN_CALLBACK(VBOXSTRICTRC) gicItsMmioWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void const *pv, unsigned cb);
|
---|
270 | DECL_HIDDEN_CALLBACK(VBOXSTRICTRC) gicItsMmioRead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void *pv, unsigned cb);
|
---|
271 |
|
---|
272 | DECLHIDDEN(void) gicResetCpu(PPDMDEVINS pDevIns, PVMCPUCC pVCpu);
|
---|
273 | DECLHIDDEN(void) gicReset(PPDMDEVINS pDevIns);
|
---|
274 | DECLHIDDEN(uint16_t) gicReDistGetIntIdFromIndex(uint16_t idxIntr);
|
---|
275 | DECLHIDDEN(uint16_t) gicDistGetIntIdFromIndex(uint16_t idxIntr);
|
---|
276 |
|
---|
277 | DECLCALLBACK(int) gicR3Construct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg);
|
---|
278 | DECLCALLBACK(int) gicR3Destruct(PPDMDEVINS pDevIns);
|
---|
279 | DECLCALLBACK(void) gicR3Relocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta);
|
---|
280 | DECLCALLBACK(void) gicR3Reset(PPDMDEVINS pDevIns);
|
---|
281 |
|
---|
282 | /** @} */
|
---|
283 |
|
---|
284 | #endif /* !VMM_INCLUDED_SRC_include_GICInternal_h */
|
---|
285 |
|
---|