VirtualBox

source: vbox/trunk/src/VBox/VMM/include/GICInternal.h@ 108823

Last change on this file since 108823 was 108823, checked in by vboxsync, 2 weeks ago

VMM/GIC: bugref:10877 Minor architecture revision is being configured by Main now, handle it in GIC.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.5 KB
Line 
1/* $Id: GICInternal.h 108823 2025-04-02 06:04:51Z 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. */
49extern const PDMGICBACKEND g_GicBackend;
50# ifdef RT_OS_DARWIN
51/** The Hypervisor.Framework GIC backend. */
52extern const PDMGICBACKEND g_GicHvfBackend;
53# elif defined(RT_OS_WINDOWS)
54/** The Hyper-V GIC backend. */
55extern const PDMGICBACKEND g_GicHvBackend;
56# elif defined(RT_OS_LINUX)
57/** The KVM GIC backend. */
58extern 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 */
75typedef 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 fAlignment0;
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 afPadding[3];
137 /** @} */
138
139 /** @name GITS device data and LPIs.
140 * @{ */
141 /** ITS device state. */
142 GITSDEV Gits;
143 /** LPI configuration table (priority + enabled bit). */
144 uint8_t abLpiConfig[2048];
145 /** LPI pending bitmap. */
146 uint32_t bmLpiPending[64];
147 /** @} */
148
149 /** @name MMIO data.
150 * @{ */
151 /** The distributor MMIO handle. */
152 IOMMMIOHANDLE hMmioDist;
153 /** The redistributor MMIO handle. */
154 IOMMMIOHANDLE hMmioReDist;
155 /** The interrupt translation service MMIO handle. */
156 IOMMMIOHANDLE hMmioGits;
157 /** @} */
158} GICDEV;
159/** Pointer to a GIC device. */
160typedef GICDEV *PGICDEV;
161/** Pointer to a const GIC device. */
162typedef GICDEV const *PCGICDEV;
163AssertCompileMemberSizeAlignment(GICDEV, Gits, 8);
164
165/**
166 * GIC VM Instance data.
167 */
168typedef struct GIC
169{
170 /** The ring-3 device instance. */
171 PPDMDEVINSR3 pDevInsR3;
172} GIC;
173/** Pointer to GIC VM instance data. */
174typedef GIC *PGIC;
175/** Pointer to const GIC VM instance data. */
176typedef GIC const *PCGIC;
177AssertCompileSizeAlignment(GIC, 8);
178
179/**
180 * GIC VMCPU Instance data.
181 */
182typedef struct GICCPU
183{
184 /** @name Redistributor register state.
185 * @{ */
186 /** Interrupt group bitmap. */
187 uint32_t bmIntrGroup[3];
188 /** Interrupt config bitmap (edge-triggered vs level-sensitive). */
189 uint32_t bmIntrConfig[6];
190 /** Interrupt enabled bitmap. */
191 uint32_t bmIntrEnabled[3];
192 /** Interrupt pending bitmap. */
193 uint32_t bmIntrPending[3];
194 /** Interrupt active bitmap. */
195 uint32_t bmIntrActive[3];
196 /** Interrupt priorities. */
197 uint8_t abIntrPriority[96];
198 /** @} */
199
200 /** @name ICC system register state.
201 * @{ */
202 /** The control register (ICC_CTLR_EL1). */
203 uint64_t uIccCtlr;
204 /** The interrupt priority mask of the CPU interface (ICC_PMR_EL1). */
205 uint8_t bIntrPriorityMask;
206 /** The index to the current running priority. */
207 uint8_t idxRunningPriority;
208 /** The running priorities caused by preemption. */
209 uint8_t abRunningPriorities[256];
210 /** The active priorities group 0 bitmap. */
211 uint32_t bmActivePriorityGroup0[4];
212 /** The active priorities group 0 bitmap. */
213 uint32_t bmActivePriorityGroup1[4];
214 /** The binary point register for group 0 interrupts. */
215 uint8_t bBinaryPtGroup0;
216 /** The binary point register for group 1 interrupts. */
217 uint8_t bBinaryPtGroup1;
218 /** Flag whether group 0 interrupts are enabled. */
219 bool fIntrGroup0Enabled;
220 /** Flag whether group 1 interrupts are enabled. */
221 bool fIntrGroup1Enabled;
222 /** @} */
223
224 /** @name Statistics.
225 * @{ */
226#ifdef VBOX_WITH_STATISTICS
227 /** Number of MMIO reads in R3. */
228 STAMCOUNTER StatMmioReadR3;
229 /** Number of MMIO writes in R3. */
230 STAMCOUNTER StatMmioWriteR3;
231 /** Number of MSR reads in R3. */
232 STAMCOUNTER StatSysRegReadR3;
233 /** Number of MSR writes in R3. */
234 STAMCOUNTER StatSysRegWriteR3;
235 /** Number of set SPI callbacks. */
236 STAMCOUNTER StatSetSpiR3;
237 /** Number of set PPI callbacks. */
238 STAMCOUNTER StatSetPpiR3;
239 /** Number of SGIs generated. */
240 STAMCOUNTER StatSetSgiR3;
241
242 /** Profiling of interrupt acknowledge (IAR). */
243 STAMPROFILE StatProfIntrAckR3;
244 /** Profiling of set SPI callback. */
245 STAMPROFILE StatProfSetSpiR3;
246 /** Profiling of set PPI callback. */
247 STAMPROFILE StatProfSetPpiR3;
248 /** Profiling of set SGI function. */
249 STAMPROFILE StatProfSetSgiR3;
250#endif
251 /** @} */
252} GICCPU;
253/** Pointer to GIC VMCPU instance data. */
254typedef GICCPU *PGICCPU;
255/** Pointer to a const GIC VMCPU instance data. */
256typedef GICCPU const *PCGICCPU;
257
258DECL_HIDDEN_CALLBACK(VBOXSTRICTRC) gicDistMmioRead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void *pv, unsigned cb);
259DECL_HIDDEN_CALLBACK(VBOXSTRICTRC) gicDistMmioWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void const *pv, unsigned cb);
260DECL_HIDDEN_CALLBACK(VBOXSTRICTRC) gicReDistMmioRead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void *pv, unsigned cb);
261DECL_HIDDEN_CALLBACK(VBOXSTRICTRC) gicReDistMmioWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void const *pv, unsigned cb);
262DECL_HIDDEN_CALLBACK(VBOXSTRICTRC) gicItsMmioWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void const *pv, unsigned cb);
263DECL_HIDDEN_CALLBACK(VBOXSTRICTRC) gicItsMmioRead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void *pv, unsigned cb);
264
265DECLHIDDEN(void) gicResetCpu(PPDMDEVINS pDevIns, PVMCPUCC pVCpu);
266DECLHIDDEN(void) gicReset(PPDMDEVINS pDevIns);
267DECLHIDDEN(uint16_t) gicReDistGetIntIdFromIndex(uint16_t idxIntr);
268DECLHIDDEN(uint16_t) gicDistGetIntIdFromIndex(uint16_t idxIntr);
269
270DECLCALLBACK(int) gicR3Construct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg);
271DECLCALLBACK(int) gicR3Destruct(PPDMDEVINS pDevIns);
272DECLCALLBACK(void) gicR3Relocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta);
273DECLCALLBACK(void) gicR3Reset(PPDMDEVINS pDevIns);
274
275/** @} */
276
277#endif /* !VMM_INCLUDED_SRC_include_GICInternal_h */
278
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