VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMR3/GICR3Nem-darwin.cpp

最後變更 在這個檔案是 108413,由 vboxsync 提交於 2 週 前

VMM/NEMR3Native-darwin-armv8.cpp,VMM/GICR3Nem-darwin.cpp: Small cleanups after the GIC interface refactor

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 8.3 KB
 
1/* $Id: GICR3Nem-darwin.cpp 108413 2025-02-28 09:12:06Z vboxsync $ */
2/** @file
3 * GIC - Generic Interrupt Controller Architecture (GIC) - Hypervisor.framework in kernel interface.
4 */
5
6/*
7 * Copyright (C) 2024 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.alldomusa.eu.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_APIC
33#include <VBox/log.h>
34#include "GICInternal.h"
35#include "NEMInternal.h" /* Need access to the VM file descriptor and for GIC API currently implemented in NEM. */
36#include <VBox/vmm/pdmgic.h>
37#include <VBox/vmm/cpum.h>
38#include <VBox/vmm/hm.h>
39#include <VBox/vmm/mm.h>
40#include <VBox/vmm/pdmdev.h>
41#include <VBox/vmm/ssm.h>
42#include <VBox/vmm/vm.h>
43
44#include <Hypervisor/Hypervisor.h>
45
46
47#ifndef VBOX_DEVICE_STRUCT_TESTCASE
48
49
50/*********************************************************************************************************************************
51* Structures and Typedefs *
52*********************************************************************************************************************************/
53
54/**
55 * GIC Hypervisor.Framework PDM instance data (per-VM).
56 */
57typedef struct GICHVFDEV
58{
59 /** Pointer to the PDM device instance. */
60 PPDMDEVINSR3 pDevIns;
61} GICHVFDEV;
62/** Pointer to a GIC KVM device. */
63typedef GICHVFDEV *PGICHVFDEV;
64/** Pointer to a const GIC KVM device. */
65typedef GICHVFDEV const *PCGICHVFDEV;
66
67typedef hv_return_t FN_HV_GIC_SET_SPI(uint32_t intid, bool level);
68
69
70/*********************************************************************************************************************************
71* Global Variables *
72*********************************************************************************************************************************/
73
74extern FN_HV_GIC_SET_SPI *g_pfnHvGicSetSpi; /* Since 15.0, exported for GICR3Nem-darwin.cpp */
75
76#ifndef IN_SLICKEDIT
77# define hv_gic_set_spi g_pfnHvGicSetSpi
78#endif
79
80
81/*********************************************************************************************************************************
82* Internal Functions *
83*********************************************************************************************************************************/
84
85/**
86 * Converts a HV return code to a VBox status code.
87 *
88 * @returns VBox status code.
89 * @param hrc The HV return code to convert.
90 */
91DECLINLINE(int) nemR3DarwinHvSts2Rc(hv_return_t hrc)
92{
93 if (hrc == HV_SUCCESS)
94 return VINF_SUCCESS;
95
96 switch (hrc)
97 {
98 case HV_ERROR: return VERR_INVALID_STATE;
99 case HV_BUSY: return VERR_RESOURCE_BUSY;
100 case HV_BAD_ARGUMENT: return VERR_INVALID_PARAMETER;
101 case HV_NO_RESOURCES: return VERR_OUT_OF_RESOURCES;
102 case HV_NO_DEVICE: return VERR_NOT_FOUND;
103 case HV_UNSUPPORTED: return VERR_NOT_SUPPORTED;
104 }
105
106 return VERR_IPE_UNEXPECTED_STATUS;
107}
108
109
110/**
111 * Sets the given SPI inside the in-kernel HvF GIC.
112 *
113 * @returns VBox status code.
114 * @param pVM The VM instance.
115 * @param uIntId The SPI ID to update.
116 * @param fAsserted Flag whether the interrupt is asserted (true) or not (false).
117 */
118static DECLCALLBACK(int) gicR3HvfSetSpi(PVMCC pVM, uint32_t uIntId, bool fAsserted)
119{
120 RT_NOREF(pVM);
121 Assert(hv_gic_set_spi);
122
123 hv_return_t hrc = hv_gic_set_spi(uIntId + GIC_INTID_RANGE_SPI_START, fAsserted);
124 return nemR3DarwinHvSts2Rc(hrc);
125}
126
127
128/**
129 * Sets the given PPI inside the in-kernel HvF GIC.
130 *
131 * @returns VBox status code.
132 * @param pVCpu The vCPU for which the PPI state is to be updated.
133 * @param uIntId The PPI ID to update.
134 * @param fAsserted Flag whether the interrupt is asserted (true) or not (false).
135 */
136static DECLCALLBACK(int) gicR3HvfSetPpi(PVMCPUCC pVCpu, uint32_t uIntId, bool fAsserted)
137{
138 RT_NOREF(pVCpu, uIntId, fAsserted);
139
140 /* Should never be called as the PPIs are handled entirely in Hypervisor.framework/AppleHV. */
141 AssertFailed();
142 return VERR_NEM_IPE_9;
143}
144
145
146/**
147 * @interface_method_impl{PDMDEVREG,pfnConstruct}
148 */
149DECLCALLBACK(int) gicR3HvfConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
150{
151 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
152 PGICHVFDEV pThis = PDMDEVINS_2_DATA(pDevIns, PGICHVFDEV);
153 PVM pVM = PDMDevHlpGetVM(pDevIns);
154 PGIC pGic = VM_TO_GIC(pVM);
155 Assert(iInstance == 0); NOREF(iInstance);
156
157 RT_NOREF(pCfg);
158
159 /*
160 * Init the data.
161 */
162 pGic->pDevInsR3 = pDevIns;
163 pThis->pDevIns = pDevIns;
164
165 /*
166 * Disable automatic PDM locking for this device.
167 */
168 int rc = PDMDevHlpSetDeviceCritSect(pDevIns, PDMDevHlpCritSectGetNop(pDevIns));
169 AssertRCReturn(rc, rc);
170
171 /*
172 * Register the GIC with PDM.
173 */
174 rc = PDMDevHlpIcRegister(pDevIns);
175 AssertLogRelRCReturn(rc, rc);
176
177 rc = PDMGicRegisterBackend(pVM, PDMGICBACKENDTYPE_HVF, &g_GicHvfBackend);
178 AssertLogRelRCReturn(rc, rc);
179
180 return VINF_SUCCESS;
181}
182
183
184/**
185 * GIC device registration structure.
186 */
187const PDMDEVREG g_DeviceGICNem =
188{
189 /* .u32Version = */ PDM_DEVREG_VERSION,
190 /* .uReserved0 = */ 0,
191 /* .szName = */ "gic-nem",
192 /* .fFlags = */ PDM_DEVREG_FLAGS_DEFAULT_BITS | PDM_DEVREG_FLAGS_NEW_STYLE,
193 /* .fClass = */ PDM_DEVREG_CLASS_PIC,
194 /* .cMaxInstances = */ 1,
195 /* .uSharedVersion = */ 42,
196 /* .cbInstanceShared = */ sizeof(GICDEV),
197 /* .cbInstanceCC = */ 0,
198 /* .cbInstanceRC = */ 0,
199 /* .cMaxPciDevices = */ 0,
200 /* .cMaxMsixVectors = */ 0,
201 /* .pszDescription = */ "Generic Interrupt Controller",
202#if defined(IN_RING3)
203 /* .szRCMod = */ "VMMRC.rc",
204 /* .szR0Mod = */ "VMMR0.r0",
205 /* .pfnConstruct = */ gicR3HvfConstruct,
206 /* .pfnDestruct = */ NULL,
207 /* .pfnRelocate = */ NULL,
208 /* .pfnMemSetup = */ NULL,
209 /* .pfnPowerOn = */ NULL,
210 /* .pfnReset = */ NULL,
211 /* .pfnSuspend = */ NULL,
212 /* .pfnResume = */ NULL,
213 /* .pfnAttach = */ NULL,
214 /* .pfnDetach = */ NULL,
215 /* .pfnQueryInterface = */ NULL,
216 /* .pfnInitComplete = */ NULL,
217 /* .pfnPowerOff = */ NULL,
218 /* .pfnSoftReset = */ NULL,
219 /* .pfnReserved0 = */ NULL,
220 /* .pfnReserved1 = */ NULL,
221 /* .pfnReserved2 = */ NULL,
222 /* .pfnReserved3 = */ NULL,
223 /* .pfnReserved4 = */ NULL,
224 /* .pfnReserved5 = */ NULL,
225 /* .pfnReserved6 = */ NULL,
226 /* .pfnReserved7 = */ NULL,
227#else
228# error "Not in IN_RING3!"
229#endif
230 /* .u32VersionEnd = */ PDM_DEVREG_VERSION
231};
232
233
234/**
235 * The Hypervisor.Framework GIC backend.
236 */
237const PDMGICBACKEND g_GicHvfBackend =
238{
239 /* .pfnReadSysReg = */ NULL,
240 /* .pfnWriteSysReg = */ NULL,
241 /* .pfnSetSpi = */ gicR3HvfSetSpi,
242 /* .pfnSetPpi = */ gicR3HvfSetPpi,
243};
244
245#endif /* !VBOX_DEVICE_STRUCT_TESTCASE */
246
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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