VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMAll/PDMAllGic.cpp@ 107631

Last change on this file since 107631 was 107308, checked in by vboxsync, 5 weeks ago

VMM: bugref:10759 Refactor GIC for use with different backends.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 KB
Line 
1/* $Id: PDMAllGic.cpp 107308 2024-12-13 08:09:39Z vboxsync $ */
2/** @file
3 * PDM - GICv3 (Generic Interrupt Controller) 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_PDM_GIC
33#include "PDMInternal.h"
34#include <VBox/vmm/vm.h>
35#include <VBox/vmm/gvm.h>
36
37
38/**
39 * Gets the PDM GIC backend name.
40 *
41 * @returns The backend name.
42 * @param enmBackendType The PDM GIC backend type.
43 */
44VMM_INT_DECL(const char *) PDMGicGetBackendName(PDMGICBACKENDTYPE enmBackendType)
45{
46 switch (enmBackendType)
47 {
48 case PDMGICBACKENDTYPE_NONE: return "None";
49 case PDMGICBACKENDTYPE_VBOX: return "VirtualBox";
50 case PDMGICBACKENDTYPE_KVM: return "KVM";
51 case PDMGICBACKENDTYPE_HYPERV: return "Hyper-V";
52 case PDMGICBACKENDTYPE_HVF: return "Hypervisor.Framework";
53 default:
54 break;
55 }
56 return "Invalid";
57}
58
59
60/**
61 * Reads a GIC system register.
62 *
63 * @returns Strict VBox status code.
64 * @param pVCpu The cross context virtual CPU structure.
65 * @param u32Reg The system register being read.
66 * @param pu64Value Where to store the read value.
67 */
68VMM_INT_DECL(VBOXSTRICTRC) PDMGicReadSysReg(PVMCPUCC pVCpu, uint32_t u32Reg, uint64_t *pu64Value)
69{
70 AssertReturn(PDMCPU_TO_GICBACKEND(pVCpu)->pfnReadSysReg, VERR_INVALID_POINTER);
71 return PDMCPU_TO_GICBACKEND(pVCpu)->pfnReadSysReg(pVCpu, u32Reg, pu64Value);
72}
73
74
75/**
76 * Writes an GIC system register.
77 *
78 * @returns Strict VBox status code.
79 * @param pVCpu The cross context virtual CPU structure.
80 * @param u32Reg The system register being written (IPRT system register identifier).
81 * @param u64Value The value to write.
82 */
83VMM_INT_DECL(VBOXSTRICTRC) PDMGicWriteSysReg(PVMCPUCC pVCpu, uint32_t u32Reg, uint64_t u64Value)
84{
85 AssertReturn(PDMCPU_TO_GICBACKEND(pVCpu)->pfnWriteSysReg, VERR_INVALID_POINTER);
86 return PDMCPU_TO_GICBACKEND(pVCpu)->pfnWriteSysReg(pVCpu, u32Reg, u64Value);
87}
88
89
90/**
91 * Sets the specified shared peripheral interrupt starting.
92 *
93 * @returns VBox status code.
94 * @param pVM The cross context virtual machine structure.
95 * @param uIntId The SPI ID (minus GIC_INTID_RANGE_SPI_START) to assert/de-assert.
96 * @param fAsserted Flag whether to mark the interrupt as asserted/de-asserted.
97 */
98VMM_INT_DECL(int) PDMGicSetSpi(PVMCC pVM, uint32_t uIntId, bool fAsserted)
99{
100 AssertReturn(PDM_TO_GICBACKEND(pVM)->pfnSetSpi, VERR_INVALID_POINTER);
101 return PDM_TO_GICBACKEND(pVM)->pfnSetSpi(pVM, uIntId, fAsserted);
102}
103
104
105/**
106 * Sets the specified private peripheral interrupt starting.
107 *
108 * @returns VBox status code.
109 * @param pVCpu The cross context virtual CPU structure.
110 * @param uIntId The PPI ID (minus GIC_INTID_RANGE_PPI_START) to assert/de-assert.
111 * @param fAsserted Flag whether to mark the interrupt as asserted/de-asserted.
112 */
113VMM_INT_DECL(int) PDMGicSetPpi(PVMCPUCC pVCpu, uint32_t uIntId, bool fAsserted)
114{
115 AssertReturn(PDMCPU_TO_GICBACKEND(pVCpu)->pfnSetPpi, VERR_INVALID_POINTER);
116 return PDMCPU_TO_GICBACKEND(pVCpu)->pfnSetPpi(pVCpu, uIntId, fAsserted);
117}
118
119
120/**
121 * Registers a PDM GIC backend.
122 *
123 * @returns VBox status code.
124 * @param pVM The cross context VM structure.
125 * @param enmBackendType The PDM GIC backend type.
126 * @param pBackend The PDM GIC backend.
127 */
128VMM_INT_DECL(int) PDMGicRegisterBackend(PVMCC pVM, PDMGICBACKENDTYPE enmBackendType, PCPDMGICBACKEND pBackend)
129{
130 /*
131 * Validate.
132 */
133 AssertPtrReturn(pVM, VERR_INVALID_PARAMETER);
134 AssertPtrReturn(pBackend, VERR_INVALID_PARAMETER);
135 AssertReturn( enmBackendType > PDMGICBACKENDTYPE_NONE
136 && enmBackendType < PDMGICBACKENDTYPE_END, VERR_INVALID_PARAMETER);
137
138 AssertPtrReturn(pBackend->pfnSetSpi, VERR_INVALID_POINTER);
139 AssertPtrReturn(pBackend->pfnSetPpi, VERR_INVALID_POINTER);
140
141 /*
142 * Register the backend.
143 */
144 pVM->pdm.s.Ic.u.armv8.enmKind = enmBackendType;
145#ifdef IN_RING3
146 pVM->pdm.s.Ic.u.armv8.GicBackend = *pBackend;
147#else
148# error "No GIC ring-0 support in this host target"
149#endif
150
151#ifdef IN_RING3
152 LogRel(("PDM: %s GIC backend registered\n", PDMGicGetBackendName(enmBackendType)));
153#endif
154 return VINF_SUCCESS;
155}
156
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