VirtualBox

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

Last change on this file since 108412 was 108412, checked in by vboxsync, 2 months ago

VMM/KVM: Some linux.arm64 build fixes, bugref:10391

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.6 KB
Line 
1/* $Id: GICInternal.h 108412 2025-02-27 19:10:58Z 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
40/** @defgroup grp_gic_int Internal
41 * @ingroup grp_gic
42 * @internal
43 * @{
44 */
45
46#ifdef VBOX_INCLUDED_vmm_pdmgic_h
47/** The VirtualBox GIC backend. */
48extern const PDMGICBACKEND g_GicBackend;
49# ifdef RT_OS_DARWIN
50/** The Hypervisor.Framework GIC backend. */
51extern const PDMGICBACKEND g_GicHvfBackend;
52# elif defined(RT_OS_WINDOWS)
53/** The Hyper-V GIC backend. */
54extern const PDMGICBACKEND g_GicHvBackend;
55# elif defined(RT_OS_LINUX)
56/** The KVM GIC backend. */
57extern const PDMGICBACKEND g_GicKvmBackend;
58# endif
59#endif
60
61#define VMCPU_TO_GICCPU(a_pVCpu) (&(a_pVCpu)->gic.s)
62#define VM_TO_GIC(a_pVM) (&(a_pVM)->gic.s)
63#define VM_TO_GICDEV(a_pVM) CTX_SUFF(VM_TO_GIC(a_pVM)->pGicDev)
64#ifdef IN_RING3
65# define VMCPU_TO_DEVINS(a_pVCpu) ((a_pVCpu)->pVMR3->gic.s.pDevInsR3)
66#elif defined(IN_RING0)
67# error "Not implemented!"
68#endif
69
70/** Maximum number of SPI interrupts. */
71#define GIC_SPI_MAX 32
72
73/**
74 * GIC PDM instance data (per-VM).
75 */
76typedef struct GICDEV
77{
78 /** The distributor MMIO handle. */
79 IOMMMIOHANDLE hMmioDist;
80 /** The redistributor MMIO handle. */
81 IOMMMIOHANDLE hMmioReDist;
82
83 /** @name SPI distributor register state.
84 * @{ */
85 /** Interrupt Group 0 Register. */
86 volatile uint32_t u32RegIGrp0;
87 /** Interrupt Configuration Register 0. */
88 volatile uint32_t u32RegICfg0;
89 /** Interrupt Configuration Register 1. */
90 volatile uint32_t u32RegICfg1;
91 /** Interrupt enabled bitmap. */
92 volatile uint32_t bmIntEnabled;
93 /** Current interrupt pending state. */
94 volatile uint32_t bmIntPending;
95 /** The current interrupt active state. */
96 volatile uint32_t bmIntActive;
97 /** The interrupt priority for each of the SGI/PPIs */
98 volatile uint8_t abIntPriority[GIC_SPI_MAX];
99 /** The interrupt routing information. */
100 volatile uint32_t au32IntRouting[GIC_SPI_MAX];
101
102 /** Flag whether group 0 interrupts are currently enabled. */
103 volatile bool fIrqGrp0Enabled;
104 /** Flag whether group 1 interrupts are currently enabled. */
105 volatile bool fIrqGrp1Enabled;
106 /** @} */
107
108 /** @name Configurables.
109 * @{ */
110 /** The GIC architecture (GICD_PIDR2.ArchRev and GICR_PIDR2.ArchRev). */
111 uint8_t uArchRev;
112 /** Extended PPIs supported (GICR_TYPER.PpiNum). */
113 uint8_t fPpiNum;
114 /** Whether extended SPIs are supported (GICD_TYPER.ESPI). */
115 bool fExtSpi;
116 /** Whether NMIs are supported (GICD_TYPER.NMI). */
117 bool fNmi;
118 /** The maximum SPI supported (GICD_TYPER.ItsLinesNumber). */
119 uint16_t uMaxSpi;
120 /** Maximum extended SPI supported (GICR_TYPER.ESPI_range). */
121 uint16_t uMaxExtSpi;
122 /** @} */
123} GICDEV;
124/** Pointer to a GIC device. */
125typedef GICDEV *PGICDEV;
126/** Pointer to a const GIC device. */
127typedef GICDEV const *PCGICDEV;
128
129
130/**
131 * GIC VM Instance data.
132 */
133typedef struct GIC
134{
135 /** The ring-3 device instance. */
136 PPDMDEVINSR3 pDevInsR3;
137} GIC;
138/** Pointer to GIC VM instance data. */
139typedef GIC *PGIC;
140/** Pointer to const GIC VM instance data. */
141typedef GIC const *PCGIC;
142AssertCompileSizeAlignment(GIC, 8);
143
144/**
145 * GIC VMCPU Instance data.
146 */
147typedef struct GICCPU
148{
149 /** @name The per vCPU redistributor data is kept here.
150 * @{ */
151 /** @} */
152
153 /** @name Physical LPI register state.
154 * @{ */
155 /** @} */
156
157 /** @name SGI and PPI redistributor register state.
158 * @{ */
159 /** Interrupt Group 0 Register. */
160 volatile uint32_t u32RegIGrp0;
161 /** Interrupt Configuration Register 0. */
162 volatile uint32_t u32RegICfg0;
163 /** Interrupt Configuration Register 1. */
164 volatile uint32_t u32RegICfg1;
165 /** Interrupt enabled bitmap. */
166 volatile uint32_t bmIntEnabled;
167 /** Current interrupt pending state. */
168 volatile uint32_t bmIntPending;
169 /** The current interrupt active state. */
170 volatile uint32_t bmIntActive;
171 /** The interrupt priority for each of the SGI/PPIs */
172 volatile uint8_t abIntPriority[GIC_INTID_RANGE_PPI_LAST + 1];
173 /** @} */
174
175 /** @name ICC system register state.
176 * @{ */
177 /** Flag whether group 0 interrupts are currently enabled. */
178 volatile bool fIrqGrp0Enabled;
179 /** Flag whether group 1 interrupts are currently enabled. */
180 volatile bool fIrqGrp1Enabled;
181 /** The current interrupt priority, only interrupts with a higher priority get signalled. */
182 volatile uint8_t bInterruptPriority;
183 /** The interrupt controller Binary Point Register for Group 0 interrupts. */
184 uint8_t bBinaryPointGrp0;
185 /** The interrupt controller Binary Point Register for Group 1 interrupts. */
186 uint8_t bBinaryPointGrp1;
187 /** The running priorities caused by preemption. */
188 volatile uint8_t abRunningPriorities[256];
189 /** The index to the current running priority. */
190 volatile uint8_t idxRunningPriority;
191 /** @} */
192
193 /** @name Log Max counters
194 * @{ */
195 uint32_t cLogMaxAccessError;
196 uint32_t cLogMaxSetApicBaseAddr;
197 uint32_t cLogMaxGetApicBaseAddr;
198 uint32_t uAlignment4;
199 /** @} */
200
201 /** @name APIC statistics.
202 * @{ */
203#ifdef VBOX_WITH_STATISTICS
204 /** Number of MMIO reads in R3. */
205 STAMCOUNTER StatMmioReadR3;
206 /** Number of MMIO writes in R3. */
207 STAMCOUNTER StatMmioWriteR3;
208 /** Number of MSR reads in R3. */
209 STAMCOUNTER StatSysRegReadR3;
210 /** Number of MSR writes in R3. */
211 STAMCOUNTER StatSysRegWriteR3;
212
213# if 0 /* No R0 for now. */
214 /** Number of MMIO reads in RZ. */
215 STAMCOUNTER StatMmioReadRZ;
216 /** Number of MMIO writes in RZ. */
217 STAMCOUNTER StatMmioWriteRZ;
218 /** Number of MSR reads in RZ. */
219 STAMCOUNTER StatSysRegReadRZ;
220 /** Number of MSR writes in RZ. */
221 STAMCOUNTER StatSysRegWriteRZ;
222# endif
223#endif
224 /** @} */
225} GICCPU;
226/** Pointer to GIC VMCPU instance data. */
227typedef GICCPU *PGICCPU;
228/** Pointer to a const GIC VMCPU instance data. */
229typedef GICCPU const *PCGICCPU;
230
231DECL_HIDDEN_CALLBACK(VBOXSTRICTRC) gicDistMmioRead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void *pv, unsigned cb);
232DECL_HIDDEN_CALLBACK(VBOXSTRICTRC) gicDistMmioWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void const *pv, unsigned cb);
233
234DECL_HIDDEN_CALLBACK(VBOXSTRICTRC) gicReDistMmioRead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void *pv, unsigned cb);
235DECL_HIDDEN_CALLBACK(VBOXSTRICTRC) gicReDistMmioWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void const *pv, unsigned cb);
236
237DECLHIDDEN(void) gicResetCpu(PVMCPUCC pVCpu);
238
239DECLCALLBACK(int) gicR3Construct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg);
240DECLCALLBACK(int) gicR3Destruct(PPDMDEVINS pDevIns);
241DECLCALLBACK(void) gicR3Relocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta);
242DECLCALLBACK(void) gicR3Reset(PPDMDEVINS pDevIns);
243
244/** @} */
245
246#endif /* !VMM_INCLUDED_SRC_include_GICInternal_h */
247
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