1 | /* $Id: GICR3Nem-darwin.cpp 107308 2024-12-13 08:09:39Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * GIC - Generic Interrupt Controller Architecture (GICv3) - 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.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 |
|
---|
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 | #ifndef VBOX_DEVICE_STRUCT_TESTCASE
|
---|
45 |
|
---|
46 |
|
---|
47 | /*********************************************************************************************************************************
|
---|
48 | * Structures and Typedefs *
|
---|
49 | *********************************************************************************************************************************/
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * GIC Hypervisor.Framework PDM instance data (per-VM).
|
---|
53 | */
|
---|
54 | typedef struct GICHVFDEV
|
---|
55 | {
|
---|
56 | /** Pointer to the PDM device instance. */
|
---|
57 | PPDMDEVINSR3 pDevIns;
|
---|
58 | } GICHVFDEV;
|
---|
59 | /** Pointer to a GIC KVM device. */
|
---|
60 | typedef GICHVFDEV *PGICHVFDEV;
|
---|
61 | /** Pointer to a const GIC KVM device. */
|
---|
62 | typedef GICHVFDEV const *PCGICHVFDEV;
|
---|
63 |
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * @interface_method_impl{PDMDEVREG,pfnConstruct}
|
---|
67 | */
|
---|
68 | DECLCALLBACK(int) gicR3HvfConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
|
---|
69 | {
|
---|
70 | PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
|
---|
71 | PGICHVFDEV pThis = PDMDEVINS_2_DATA(pDevIns, PGICHVFDEV);
|
---|
72 | PVM pVM = PDMDevHlpGetVM(pDevIns);
|
---|
73 | PGIC pGic = VM_TO_GIC(pVM);
|
---|
74 | Assert(iInstance == 0); NOREF(iInstance);
|
---|
75 |
|
---|
76 | RT_NOREF(pCfg);
|
---|
77 |
|
---|
78 | /*
|
---|
79 | * Init the data.
|
---|
80 | */
|
---|
81 | pGic->pDevInsR3 = pDevIns;
|
---|
82 | pThis->pDevIns = pDevIns;
|
---|
83 |
|
---|
84 | /*
|
---|
85 | * Disable automatic PDM locking for this device.
|
---|
86 | */
|
---|
87 | int rc = PDMDevHlpSetDeviceCritSect(pDevIns, PDMDevHlpCritSectGetNop(pDevIns));
|
---|
88 | AssertRCReturn(rc, rc);
|
---|
89 |
|
---|
90 | /*
|
---|
91 | * Register the GIC with PDM.
|
---|
92 | */
|
---|
93 | rc = PDMDevHlpIcRegister(pDevIns);
|
---|
94 | AssertLogRelRCReturn(rc, rc);
|
---|
95 |
|
---|
96 | rc = PDMGicRegisterBackend(pVM, PDMGICBACKENDTYPE_HVF, &g_GicHvfBackend);
|
---|
97 | AssertLogRelRCReturn(rc, rc);
|
---|
98 |
|
---|
99 | return VINF_SUCCESS;
|
---|
100 | }
|
---|
101 |
|
---|
102 |
|
---|
103 | /**
|
---|
104 | * GIC device registration structure.
|
---|
105 | */
|
---|
106 | const PDMDEVREG g_DeviceGICNem =
|
---|
107 | {
|
---|
108 | /* .u32Version = */ PDM_DEVREG_VERSION,
|
---|
109 | /* .uReserved0 = */ 0,
|
---|
110 | /* .szName = */ "gic-nem",
|
---|
111 | /* .fFlags = */ PDM_DEVREG_FLAGS_DEFAULT_BITS | PDM_DEVREG_FLAGS_NEW_STYLE,
|
---|
112 | /* .fClass = */ PDM_DEVREG_CLASS_PIC,
|
---|
113 | /* .cMaxInstances = */ 1,
|
---|
114 | /* .uSharedVersion = */ 42,
|
---|
115 | /* .cbInstanceShared = */ sizeof(GICDEV),
|
---|
116 | /* .cbInstanceCC = */ 0,
|
---|
117 | /* .cbInstanceRC = */ 0,
|
---|
118 | /* .cMaxPciDevices = */ 0,
|
---|
119 | /* .cMaxMsixVectors = */ 0,
|
---|
120 | /* .pszDescription = */ "Generic Interrupt Controller",
|
---|
121 | #if defined(IN_RING3)
|
---|
122 | /* .szRCMod = */ "VMMRC.rc",
|
---|
123 | /* .szR0Mod = */ "VMMR0.r0",
|
---|
124 | /* .pfnConstruct = */ gicR3HvfConstruct,
|
---|
125 | /* .pfnDestruct = */ NULL,
|
---|
126 | /* .pfnRelocate = */ NULL,
|
---|
127 | /* .pfnMemSetup = */ NULL,
|
---|
128 | /* .pfnPowerOn = */ NULL,
|
---|
129 | /* .pfnReset = */ NULL,
|
---|
130 | /* .pfnSuspend = */ NULL,
|
---|
131 | /* .pfnResume = */ NULL,
|
---|
132 | /* .pfnAttach = */ NULL,
|
---|
133 | /* .pfnDetach = */ NULL,
|
---|
134 | /* .pfnQueryInterface = */ NULL,
|
---|
135 | /* .pfnInitComplete = */ NULL,
|
---|
136 | /* .pfnPowerOff = */ NULL,
|
---|
137 | /* .pfnSoftReset = */ NULL,
|
---|
138 | /* .pfnReserved0 = */ NULL,
|
---|
139 | /* .pfnReserved1 = */ NULL,
|
---|
140 | /* .pfnReserved2 = */ NULL,
|
---|
141 | /* .pfnReserved3 = */ NULL,
|
---|
142 | /* .pfnReserved4 = */ NULL,
|
---|
143 | /* .pfnReserved5 = */ NULL,
|
---|
144 | /* .pfnReserved6 = */ NULL,
|
---|
145 | /* .pfnReserved7 = */ NULL,
|
---|
146 | #else
|
---|
147 | # error "Not in IN_RING3!"
|
---|
148 | #endif
|
---|
149 | /* .u32VersionEnd = */ PDM_DEVREG_VERSION
|
---|
150 | };
|
---|
151 |
|
---|
152 |
|
---|
153 | /**
|
---|
154 | * The Hypervisor.Framework GIC backend.
|
---|
155 | */
|
---|
156 | const PDMGICBACKEND g_GicHvfBackend =
|
---|
157 | {
|
---|
158 | /* .pfnReadSysReg = */ NEMR3GicReadSysReg,
|
---|
159 | /* .pfnWriteSysReg = */ NEMR3GicWriteSysReg,
|
---|
160 | /* .pfnSetSpi = */ NEMR3GicSetSpi,
|
---|
161 | /* .pfnSetPpi = */ NEMR3GicSetPpi,
|
---|
162 | };
|
---|
163 |
|
---|
164 | #endif /* !VBOX_DEVICE_STRUCT_TESTCASE */
|
---|
165 |
|
---|