VirtualBox

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

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

VMM: bugref:10759 Refactor GIC for use with different backends. [build fix]

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.8 KB
Line 
1/* $Id: GICInternal.h 107315 2024-12-13 09:08:26Z vboxsync $ */
2/** @file
3 * GIC - Generic Interrupt Controller Architecture (GICv3).
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# endif
56#endif
57
58#define VMCPU_TO_GICCPU(a_pVCpu) (&(a_pVCpu)->gic.s)
59#define VM_TO_GIC(a_pVM) (&(a_pVM)->gic.s)
60#define VM_TO_GICDEV(a_pVM) CTX_SUFF(VM_TO_GIC(a_pVM)->pGicDev)
61#ifdef IN_RING3
62# define VMCPU_TO_DEVINS(a_pVCpu) ((a_pVCpu)->pVMR3->gic.s.pDevInsR3)
63#elif defined(IN_RING0)
64# error "Not implemented!"
65#endif
66
67/** Maximum number of SPI interrupts. */
68#define GIC_SPI_MAX 32
69
70/**
71 * GIC PDM instance data (per-VM).
72 */
73typedef struct GICDEV
74{
75 /** The distributor MMIO handle. */
76 IOMMMIOHANDLE hMmioDist;
77 /** The redistributor MMIO handle. */
78 IOMMMIOHANDLE hMmioReDist;
79
80 /** @name SPI distributor register state.
81 * @{ */
82 /** Interrupt Group 0 Register. */
83 volatile uint32_t u32RegIGrp0;
84 /** Interrupt Configuration Register 0. */
85 volatile uint32_t u32RegICfg0;
86 /** Interrupt Configuration Register 1. */
87 volatile uint32_t u32RegICfg1;
88 /** Interrupt enabled bitmap. */
89 volatile uint32_t bmIntEnabled;
90 /** Current interrupt pending state. */
91 volatile uint32_t bmIntPending;
92 /** The current interrupt active state. */
93 volatile uint32_t bmIntActive;
94 /** The interrupt priority for each of the SGI/PPIs */
95 volatile uint8_t abIntPriority[GIC_SPI_MAX];
96 /** The interrupt routing information. */
97 volatile uint32_t au32IntRouting[GIC_SPI_MAX];
98
99 /** Flag whether group 0 interrupts are currently enabled. */
100 volatile bool fIrqGrp0Enabled;
101 /** Flag whether group 1 interrupts are currently enabled. */
102 volatile bool fIrqGrp1Enabled;
103 /** @} */
104
105} GICDEV;
106/** Pointer to a GIC device. */
107typedef GICDEV *PGICDEV;
108/** Pointer to a const GIC device. */
109typedef GICDEV const *PCGICDEV;
110
111
112/**
113 * GIC VM Instance data.
114 */
115typedef struct GIC
116{
117 /** The ring-3 device instance. */
118 PPDMDEVINSR3 pDevInsR3;
119} GIC;
120/** Pointer to GIC VM instance data. */
121typedef GIC *PGIC;
122/** Pointer to const GIC VM instance data. */
123typedef GIC const *PCGIC;
124AssertCompileSizeAlignment(GIC, 8);
125
126/**
127 * GIC VMCPU Instance data.
128 */
129typedef struct GICCPU
130{
131 /** @name The per vCPU redistributor data is kept here.
132 * @{ */
133
134 /** @name Physical LPI register state.
135 * @{ */
136 /** @} */
137
138 /** @name SGI and PPI redistributor register state.
139 * @{ */
140 /** Interrupt Group 0 Register. */
141 volatile uint32_t u32RegIGrp0;
142 /** Interrupt Configuration Register 0. */
143 volatile uint32_t u32RegICfg0;
144 /** Interrupt Configuration Register 1. */
145 volatile uint32_t u32RegICfg1;
146 /** Interrupt enabled bitmap. */
147 volatile uint32_t bmIntEnabled;
148 /** Current interrupt pending state. */
149 volatile uint32_t bmIntPending;
150 /** The current interrupt active state. */
151 volatile uint32_t bmIntActive;
152 /** The interrupt priority for each of the SGI/PPIs */
153 volatile uint8_t abIntPriority[GIC_INTID_RANGE_PPI_LAST + 1];
154 /** @} */
155
156 /** @name ICC system register state.
157 * @{ */
158 /** Flag whether group 0 interrupts are currently enabled. */
159 volatile bool fIrqGrp0Enabled;
160 /** Flag whether group 1 interrupts are currently enabled. */
161 volatile bool fIrqGrp1Enabled;
162 /** The current interrupt priority, only interrupts with a higher priority get signalled. */
163 volatile uint8_t bInterruptPriority;
164 /** The interrupt controller Binary Point Register for Group 0 interrupts. */
165 uint8_t bBinaryPointGrp0;
166 /** The interrupt controller Binary Point Register for Group 1 interrupts. */
167 uint8_t bBinaryPointGrp1;
168 /** The running poriorities caused by preemption. */
169 volatile uint8_t abRunningPriorities[256];
170 /** The index to the current running priority. */
171 volatile uint8_t idxRunningPriority;
172 /** @} */
173
174 /** @name Log Max counters
175 * @{ */
176 uint32_t cLogMaxAccessError;
177 uint32_t cLogMaxSetApicBaseAddr;
178 uint32_t cLogMaxGetApicBaseAddr;
179 uint32_t uAlignment4;
180 /** @} */
181
182 /** @name APIC statistics.
183 * @{ */
184#ifdef VBOX_WITH_STATISTICS
185 /** Number of MMIO reads in R3. */
186 STAMCOUNTER StatMmioReadR3;
187 /** Number of MMIO writes in R3. */
188 STAMCOUNTER StatMmioWriteR3;
189 /** Number of MSR reads in R3. */
190 STAMCOUNTER StatSysRegReadR3;
191 /** Number of MSR writes in R3. */
192 STAMCOUNTER StatSysRegWriteR3;
193
194# if 0 /* No R0 for now. */
195 /** Number of MMIO reads in RZ. */
196 STAMCOUNTER StatMmioReadRZ;
197 /** Number of MMIO writes in RZ. */
198 STAMCOUNTER StatMmioWriteRZ;
199 /** Number of MSR reads in RZ. */
200 STAMCOUNTER StatSysRegReadRZ;
201 /** Number of MSR writes in RZ. */
202 STAMCOUNTER StatSysRegWriteRZ;
203# endif
204#endif
205 /** @} */
206} GICCPU;
207/** Pointer to GIC VMCPU instance data. */
208typedef GICCPU *PGICCPU;
209/** Pointer to a const GIC VMCPU instance data. */
210typedef GICCPU const *PCGICCPU;
211
212DECL_HIDDEN_CALLBACK(VBOXSTRICTRC) gicDistMmioRead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void *pv, unsigned cb);
213DECL_HIDDEN_CALLBACK(VBOXSTRICTRC) gicDistMmioWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void const *pv, unsigned cb);
214
215DECL_HIDDEN_CALLBACK(VBOXSTRICTRC) gicReDistMmioRead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void *pv, unsigned cb);
216DECL_HIDDEN_CALLBACK(VBOXSTRICTRC) gicReDistMmioWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void const *pv, unsigned cb);
217
218DECLHIDDEN(void) gicResetCpu(PVMCPUCC pVCpu);
219
220DECLCALLBACK(int) gicR3Construct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg);
221DECLCALLBACK(int) gicR3Destruct(PPDMDEVINS pDevIns);
222DECLCALLBACK(void) gicR3Relocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta);
223DECLCALLBACK(void) gicR3Reset(PPDMDEVINS pDevIns);
224
225/** @} */
226
227#endif /* !VMM_INCLUDED_SRC_include_GICInternal_h */
228
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