VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMR3/APIC.cpp@ 78877

Last change on this file since 78877 was 78208, checked in by vboxsync, 6 years ago

PDM,APIC,PIC: Don't use AssertRelease on VMCPU_FF_INTERRUPT_PIC, VMCPU_FF_INTERRUPT_APIC and friends during restore. Instead added debug assertions in the relevant functions causing these to be set by misbehaving device state loaders. ticketref:18331 ticketref:18265

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 70.6 KB
Line 
1/* $Id: APIC.cpp 78208 2019-04-18 15:54:40Z vboxsync $ */
2/** @file
3 * APIC - Advanced Programmable Interrupt Controller.
4 */
5
6/*
7 * Copyright (C) 2016-2019 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
22#define LOG_GROUP LOG_GROUP_DEV_APIC
23#include <VBox/log.h>
24#include "APICInternal.h"
25#include <VBox/vmm/cpum.h>
26#include <VBox/vmm/hm.h>
27#include <VBox/vmm/mm.h>
28#include <VBox/vmm/pdmdev.h>
29#include <VBox/vmm/ssm.h>
30#include <VBox/vmm/vm.h>
31
32
33#ifndef VBOX_DEVICE_STRUCT_TESTCASE
34
35
36/*********************************************************************************************************************************
37* Defined Constants And Macros *
38*********************************************************************************************************************************/
39/** The current APIC saved state version. */
40#define APIC_SAVED_STATE_VERSION 5
41/** VirtualBox 5.1 beta2 - pre fActiveLintX. */
42#define APIC_SAVED_STATE_VERSION_VBOX_51_BETA2 4
43/** The saved state version used by VirtualBox 5.0 and
44 * earlier. */
45#define APIC_SAVED_STATE_VERSION_VBOX_50 3
46/** The saved state version used by VirtualBox v3 and earlier.
47 * This does not include the config. */
48#define APIC_SAVED_STATE_VERSION_VBOX_30 2
49/** Some ancient version... */
50#define APIC_SAVED_STATE_VERSION_ANCIENT 1
51
52#ifdef VBOX_WITH_STATISTICS
53# define X2APIC_MSRRANGE(a_uFirst, a_uLast, a_szName) \
54 { (a_uFirst), (a_uLast), kCpumMsrRdFn_Ia32X2ApicN, kCpumMsrWrFn_Ia32X2ApicN, 0, 0, 0, 0, 0, a_szName, { 0 }, { 0 }, { 0 }, { 0 } }
55# define X2APIC_MSRRANGE_INVALID(a_uFirst, a_uLast, a_szName) \
56 { (a_uFirst), (a_uLast), kCpumMsrRdFn_WriteOnly, kCpumMsrWrFn_ReadOnly, 0, 0, 0, 0, UINT64_MAX /*fWrGpMask*/, a_szName, { 0 }, { 0 }, { 0 }, { 0 } }
57#else
58# define X2APIC_MSRRANGE(a_uFirst, a_uLast, a_szName) \
59 { (a_uFirst), (a_uLast), kCpumMsrRdFn_Ia32X2ApicN, kCpumMsrWrFn_Ia32X2ApicN, 0, 0, 0, 0, 0, a_szName }
60# define X2APIC_MSRRANGE_INVALID(a_uFirst, a_uLast, a_szName) \
61 { (a_uFirst), (a_uLast), kCpumMsrRdFn_WriteOnly, kCpumMsrWrFn_ReadOnly, 0, 0, 0, 0, UINT64_MAX /*fWrGpMask*/, a_szName }
62#endif
63
64
65/*********************************************************************************************************************************
66* Global Variables *
67*********************************************************************************************************************************/
68/**
69 * MSR range supported by the x2APIC.
70 * See Intel spec. 10.12.2 "x2APIC Register Availability".
71 */
72static CPUMMSRRANGE const g_MsrRange_x2Apic = X2APIC_MSRRANGE(MSR_IA32_X2APIC_START, MSR_IA32_X2APIC_END, "x2APIC range");
73static CPUMMSRRANGE const g_MsrRange_x2Apic_Invalid = X2APIC_MSRRANGE_INVALID(MSR_IA32_X2APIC_START, MSR_IA32_X2APIC_END, "x2APIC range invalid");
74#undef X2APIC_MSRRANGE
75#undef X2APIC_MSRRANGE_GP
76
77/** Saved state field descriptors for XAPICPAGE. */
78static const SSMFIELD g_aXApicPageFields[] =
79{
80 SSMFIELD_ENTRY( XAPICPAGE, id.u8ApicId),
81 SSMFIELD_ENTRY( XAPICPAGE, version.all.u32Version),
82 SSMFIELD_ENTRY( XAPICPAGE, tpr.u8Tpr),
83 SSMFIELD_ENTRY( XAPICPAGE, apr.u8Apr),
84 SSMFIELD_ENTRY( XAPICPAGE, ppr.u8Ppr),
85 SSMFIELD_ENTRY( XAPICPAGE, ldr.all.u32Ldr),
86 SSMFIELD_ENTRY( XAPICPAGE, dfr.all.u32Dfr),
87 SSMFIELD_ENTRY( XAPICPAGE, svr.all.u32Svr),
88 SSMFIELD_ENTRY( XAPICPAGE, isr.u[0].u32Reg),
89 SSMFIELD_ENTRY( XAPICPAGE, isr.u[1].u32Reg),
90 SSMFIELD_ENTRY( XAPICPAGE, isr.u[2].u32Reg),
91 SSMFIELD_ENTRY( XAPICPAGE, isr.u[3].u32Reg),
92 SSMFIELD_ENTRY( XAPICPAGE, isr.u[4].u32Reg),
93 SSMFIELD_ENTRY( XAPICPAGE, isr.u[5].u32Reg),
94 SSMFIELD_ENTRY( XAPICPAGE, isr.u[6].u32Reg),
95 SSMFIELD_ENTRY( XAPICPAGE, isr.u[7].u32Reg),
96 SSMFIELD_ENTRY( XAPICPAGE, tmr.u[0].u32Reg),
97 SSMFIELD_ENTRY( XAPICPAGE, tmr.u[1].u32Reg),
98 SSMFIELD_ENTRY( XAPICPAGE, tmr.u[2].u32Reg),
99 SSMFIELD_ENTRY( XAPICPAGE, tmr.u[3].u32Reg),
100 SSMFIELD_ENTRY( XAPICPAGE, tmr.u[4].u32Reg),
101 SSMFIELD_ENTRY( XAPICPAGE, tmr.u[5].u32Reg),
102 SSMFIELD_ENTRY( XAPICPAGE, tmr.u[6].u32Reg),
103 SSMFIELD_ENTRY( XAPICPAGE, tmr.u[7].u32Reg),
104 SSMFIELD_ENTRY( XAPICPAGE, irr.u[0].u32Reg),
105 SSMFIELD_ENTRY( XAPICPAGE, irr.u[1].u32Reg),
106 SSMFIELD_ENTRY( XAPICPAGE, irr.u[2].u32Reg),
107 SSMFIELD_ENTRY( XAPICPAGE, irr.u[3].u32Reg),
108 SSMFIELD_ENTRY( XAPICPAGE, irr.u[4].u32Reg),
109 SSMFIELD_ENTRY( XAPICPAGE, irr.u[5].u32Reg),
110 SSMFIELD_ENTRY( XAPICPAGE, irr.u[6].u32Reg),
111 SSMFIELD_ENTRY( XAPICPAGE, irr.u[7].u32Reg),
112 SSMFIELD_ENTRY( XAPICPAGE, esr.all.u32Errors),
113 SSMFIELD_ENTRY( XAPICPAGE, icr_lo.all.u32IcrLo),
114 SSMFIELD_ENTRY( XAPICPAGE, icr_hi.all.u32IcrHi),
115 SSMFIELD_ENTRY( XAPICPAGE, lvt_timer.all.u32LvtTimer),
116 SSMFIELD_ENTRY( XAPICPAGE, lvt_thermal.all.u32LvtThermal),
117 SSMFIELD_ENTRY( XAPICPAGE, lvt_perf.all.u32LvtPerf),
118 SSMFIELD_ENTRY( XAPICPAGE, lvt_lint0.all.u32LvtLint0),
119 SSMFIELD_ENTRY( XAPICPAGE, lvt_lint1.all.u32LvtLint1),
120 SSMFIELD_ENTRY( XAPICPAGE, lvt_error.all.u32LvtError),
121 SSMFIELD_ENTRY( XAPICPAGE, timer_icr.u32InitialCount),
122 SSMFIELD_ENTRY( XAPICPAGE, timer_ccr.u32CurrentCount),
123 SSMFIELD_ENTRY( XAPICPAGE, timer_dcr.all.u32DivideValue),
124 SSMFIELD_ENTRY_TERM()
125};
126
127/** Saved state field descriptors for X2APICPAGE. */
128static const SSMFIELD g_aX2ApicPageFields[] =
129{
130 SSMFIELD_ENTRY(X2APICPAGE, id.u32ApicId),
131 SSMFIELD_ENTRY(X2APICPAGE, version.all.u32Version),
132 SSMFIELD_ENTRY(X2APICPAGE, tpr.u8Tpr),
133 SSMFIELD_ENTRY(X2APICPAGE, ppr.u8Ppr),
134 SSMFIELD_ENTRY(X2APICPAGE, ldr.u32LogicalApicId),
135 SSMFIELD_ENTRY(X2APICPAGE, svr.all.u32Svr),
136 SSMFIELD_ENTRY(X2APICPAGE, isr.u[0].u32Reg),
137 SSMFIELD_ENTRY(X2APICPAGE, isr.u[1].u32Reg),
138 SSMFIELD_ENTRY(X2APICPAGE, isr.u[2].u32Reg),
139 SSMFIELD_ENTRY(X2APICPAGE, isr.u[3].u32Reg),
140 SSMFIELD_ENTRY(X2APICPAGE, isr.u[4].u32Reg),
141 SSMFIELD_ENTRY(X2APICPAGE, isr.u[5].u32Reg),
142 SSMFIELD_ENTRY(X2APICPAGE, isr.u[6].u32Reg),
143 SSMFIELD_ENTRY(X2APICPAGE, isr.u[7].u32Reg),
144 SSMFIELD_ENTRY(X2APICPAGE, tmr.u[0].u32Reg),
145 SSMFIELD_ENTRY(X2APICPAGE, tmr.u[1].u32Reg),
146 SSMFIELD_ENTRY(X2APICPAGE, tmr.u[2].u32Reg),
147 SSMFIELD_ENTRY(X2APICPAGE, tmr.u[3].u32Reg),
148 SSMFIELD_ENTRY(X2APICPAGE, tmr.u[4].u32Reg),
149 SSMFIELD_ENTRY(X2APICPAGE, tmr.u[5].u32Reg),
150 SSMFIELD_ENTRY(X2APICPAGE, tmr.u[6].u32Reg),
151 SSMFIELD_ENTRY(X2APICPAGE, tmr.u[7].u32Reg),
152 SSMFIELD_ENTRY(X2APICPAGE, irr.u[0].u32Reg),
153 SSMFIELD_ENTRY(X2APICPAGE, irr.u[1].u32Reg),
154 SSMFIELD_ENTRY(X2APICPAGE, irr.u[2].u32Reg),
155 SSMFIELD_ENTRY(X2APICPAGE, irr.u[3].u32Reg),
156 SSMFIELD_ENTRY(X2APICPAGE, irr.u[4].u32Reg),
157 SSMFIELD_ENTRY(X2APICPAGE, irr.u[5].u32Reg),
158 SSMFIELD_ENTRY(X2APICPAGE, irr.u[6].u32Reg),
159 SSMFIELD_ENTRY(X2APICPAGE, irr.u[7].u32Reg),
160 SSMFIELD_ENTRY(X2APICPAGE, esr.all.u32Errors),
161 SSMFIELD_ENTRY(X2APICPAGE, icr_lo.all.u32IcrLo),
162 SSMFIELD_ENTRY(X2APICPAGE, icr_hi.u32IcrHi),
163 SSMFIELD_ENTRY(X2APICPAGE, lvt_timer.all.u32LvtTimer),
164 SSMFIELD_ENTRY(X2APICPAGE, lvt_thermal.all.u32LvtThermal),
165 SSMFIELD_ENTRY(X2APICPAGE, lvt_perf.all.u32LvtPerf),
166 SSMFIELD_ENTRY(X2APICPAGE, lvt_lint0.all.u32LvtLint0),
167 SSMFIELD_ENTRY(X2APICPAGE, lvt_lint1.all.u32LvtLint1),
168 SSMFIELD_ENTRY(X2APICPAGE, lvt_error.all.u32LvtError),
169 SSMFIELD_ENTRY(X2APICPAGE, timer_icr.u32InitialCount),
170 SSMFIELD_ENTRY(X2APICPAGE, timer_ccr.u32CurrentCount),
171 SSMFIELD_ENTRY(X2APICPAGE, timer_dcr.all.u32DivideValue),
172 SSMFIELD_ENTRY_TERM()
173};
174
175
176/**
177 * Sets the CPUID feature bits for the APIC mode.
178 *
179 * @param pVM The cross context VM structure.
180 * @param enmMode The APIC mode.
181 */
182static void apicR3SetCpuIdFeatureLevel(PVM pVM, PDMAPICMODE enmMode)
183{
184 switch (enmMode)
185 {
186 case PDMAPICMODE_NONE:
187 CPUMR3ClearGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_X2APIC);
188 CPUMR3ClearGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_APIC);
189 break;
190
191 case PDMAPICMODE_APIC:
192 CPUMR3ClearGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_X2APIC);
193 CPUMR3SetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_APIC);
194 break;
195
196 case PDMAPICMODE_X2APIC:
197 CPUMR3SetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_APIC);
198 CPUMR3SetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_X2APIC);
199 break;
200
201 default:
202 AssertMsgFailed(("Unknown/invalid APIC mode: %d\n", (int)enmMode));
203 }
204}
205
206
207/**
208 * Receives an INIT IPI.
209 *
210 * @param pVCpu The cross context virtual CPU structure.
211 */
212VMMR3_INT_DECL(void) APICR3InitIpi(PVMCPU pVCpu)
213{
214 VMCPU_ASSERT_EMT(pVCpu);
215 LogFlow(("APIC%u: APICR3InitIpi\n", pVCpu->idCpu));
216 apicInitIpi(pVCpu);
217}
218
219
220/**
221 * Sets whether Hyper-V compatibility mode (MSR interface) is enabled or not.
222 *
223 * This mode is a hybrid of xAPIC and x2APIC modes, some caveats:
224 * 1. MSRs are used even ones that are missing (illegal) in x2APIC like DFR.
225 * 2. A single ICR is used by the guest to send IPIs rather than 2 ICR writes.
226 * 3. It is unclear what the behaviour will be when invalid bits are set,
227 * currently we follow x2APIC behaviour of causing a \#GP.
228 *
229 * @param pVM The cross context VM structure.
230 * @param fHyperVCompatMode Whether the compatibility mode is enabled.
231 */
232VMMR3_INT_DECL(void) APICR3HvSetCompatMode(PVM pVM, bool fHyperVCompatMode)
233{
234 Assert(pVM);
235 PAPIC pApic = VM_TO_APIC(pVM);
236 pApic->fHyperVCompatMode = fHyperVCompatMode;
237
238 if (fHyperVCompatMode)
239 LogRel(("APIC: Enabling Hyper-V x2APIC compatibility mode\n"));
240
241 int rc = CPUMR3MsrRangesInsert(pVM, &g_MsrRange_x2Apic);
242 AssertLogRelRC(rc);
243}
244
245
246/**
247 * Helper for dumping an APIC 256-bit sparse register.
248 *
249 * @param pApicReg The APIC 256-bit spare register.
250 * @param pHlp The debug output helper.
251 */
252static void apicR3DbgInfo256BitReg(volatile const XAPIC256BITREG *pApicReg, PCDBGFINFOHLP pHlp)
253{
254 ssize_t const cFragments = RT_ELEMENTS(pApicReg->u);
255 unsigned const cBitsPerFragment = sizeof(pApicReg->u[0].u32Reg) * 8;
256 XAPIC256BITREG ApicReg;
257 RT_ZERO(ApicReg);
258
259 pHlp->pfnPrintf(pHlp, " ");
260 for (ssize_t i = cFragments - 1; i >= 0; i--)
261 {
262 uint32_t const uFragment = pApicReg->u[i].u32Reg;
263 ApicReg.u[i].u32Reg = uFragment;
264 pHlp->pfnPrintf(pHlp, "%08x", uFragment);
265 }
266 pHlp->pfnPrintf(pHlp, "\n");
267
268 uint32_t cPending = 0;
269 pHlp->pfnPrintf(pHlp, " Pending:");
270 for (ssize_t i = cFragments - 1; i >= 0; i--)
271 {
272 uint32_t uFragment = ApicReg.u[i].u32Reg;
273 if (uFragment)
274 {
275 do
276 {
277 unsigned idxSetBit = ASMBitLastSetU32(uFragment);
278 --idxSetBit;
279 ASMBitClear(&uFragment, idxSetBit);
280
281 idxSetBit += (i * cBitsPerFragment);
282 pHlp->pfnPrintf(pHlp, " %#02x", idxSetBit);
283 ++cPending;
284 } while (uFragment);
285 }
286 }
287 if (!cPending)
288 pHlp->pfnPrintf(pHlp, " None");
289 pHlp->pfnPrintf(pHlp, "\n");
290}
291
292
293/**
294 * Helper for dumping an APIC pending-interrupt bitmap.
295 *
296 * @param pApicPib The pending-interrupt bitmap.
297 * @param pHlp The debug output helper.
298 */
299static void apicR3DbgInfoPib(PCAPICPIB pApicPib, PCDBGFINFOHLP pHlp)
300{
301 /* Copy the pending-interrupt bitmap as an APIC 256-bit sparse register. */
302 XAPIC256BITREG ApicReg;
303 RT_ZERO(ApicReg);
304 ssize_t const cFragmentsDst = RT_ELEMENTS(ApicReg.u);
305 ssize_t const cFragmentsSrc = RT_ELEMENTS(pApicPib->au64VectorBitmap);
306 AssertCompile(RT_ELEMENTS(ApicReg.u) == 2 * RT_ELEMENTS(pApicPib->au64VectorBitmap));
307 for (ssize_t idxPib = cFragmentsSrc - 1, idxReg = cFragmentsDst - 1; idxPib >= 0; idxPib--, idxReg -= 2)
308 {
309 uint64_t const uFragment = pApicPib->au64VectorBitmap[idxPib];
310 uint32_t const uFragmentLo = RT_LO_U32(uFragment);
311 uint32_t const uFragmentHi = RT_HI_U32(uFragment);
312 ApicReg.u[idxReg].u32Reg = uFragmentHi;
313 ApicReg.u[idxReg - 1].u32Reg = uFragmentLo;
314 }
315
316 /* Dump it. */
317 apicR3DbgInfo256BitReg(&ApicReg, pHlp);
318}
319
320
321/**
322 * Dumps basic APIC state.
323 *
324 * @param pVM The cross context VM structure.
325 * @param pHlp The info helpers.
326 * @param pszArgs Arguments, ignored.
327 */
328static DECLCALLBACK(void) apicR3Info(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs)
329{
330 NOREF(pszArgs);
331 PVMCPU pVCpu = VMMGetCpu(pVM);
332 if (!pVCpu)
333 pVCpu = &pVM->aCpus[0];
334
335 PCAPICCPU pApicCpu = VMCPU_TO_APICCPU(pVCpu);
336 PCXAPICPAGE pXApicPage = VMCPU_TO_CXAPICPAGE(pVCpu);
337 PCX2APICPAGE pX2ApicPage = VMCPU_TO_CX2APICPAGE(pVCpu);
338
339 uint64_t const uBaseMsr = pApicCpu->uApicBaseMsr;
340 APICMODE const enmMode = apicGetMode(uBaseMsr);
341 bool const fX2ApicMode = XAPIC_IN_X2APIC_MODE(pVCpu);
342
343 pHlp->pfnPrintf(pHlp, "APIC%u:\n", pVCpu->idCpu);
344 pHlp->pfnPrintf(pHlp, " APIC Base MSR = %#RX64 (Addr=%#RX64)\n", uBaseMsr,
345 MSR_IA32_APICBASE_GET_ADDR(uBaseMsr));
346 pHlp->pfnPrintf(pHlp, " Mode = %u (%s)\n", enmMode, apicGetModeName(enmMode));
347 if (fX2ApicMode)
348 {
349 pHlp->pfnPrintf(pHlp, " APIC ID = %u (%#x)\n", pX2ApicPage->id.u32ApicId,
350 pX2ApicPage->id.u32ApicId);
351 }
352 else
353 pHlp->pfnPrintf(pHlp, " APIC ID = %u (%#x)\n", pXApicPage->id.u8ApicId, pXApicPage->id.u8ApicId);
354 pHlp->pfnPrintf(pHlp, " Version = %#x\n", pXApicPage->version.all.u32Version);
355 pHlp->pfnPrintf(pHlp, " APIC Version = %#x\n", pXApicPage->version.u.u8Version);
356 pHlp->pfnPrintf(pHlp, " Max LVT entry index (0..N) = %u\n", pXApicPage->version.u.u8MaxLvtEntry);
357 pHlp->pfnPrintf(pHlp, " EOI Broadcast supression = %RTbool\n", pXApicPage->version.u.fEoiBroadcastSupression);
358 if (!fX2ApicMode)
359 pHlp->pfnPrintf(pHlp, " APR = %u (%#x)\n", pXApicPage->apr.u8Apr, pXApicPage->apr.u8Apr);
360 pHlp->pfnPrintf(pHlp, " TPR = %u (%#x)\n", pXApicPage->tpr.u8Tpr, pXApicPage->tpr.u8Tpr);
361 pHlp->pfnPrintf(pHlp, " Task-priority class = %#x\n", XAPIC_TPR_GET_TP(pXApicPage->tpr.u8Tpr) >> 4);
362 pHlp->pfnPrintf(pHlp, " Task-priority subclass = %#x\n", XAPIC_TPR_GET_TP_SUBCLASS(pXApicPage->tpr.u8Tpr));
363 pHlp->pfnPrintf(pHlp, " PPR = %u (%#x)\n", pXApicPage->ppr.u8Ppr, pXApicPage->ppr.u8Ppr);
364 pHlp->pfnPrintf(pHlp, " Processor-priority class = %#x\n", XAPIC_PPR_GET_PP(pXApicPage->ppr.u8Ppr) >> 4);
365 pHlp->pfnPrintf(pHlp, " Processor-priority subclass = %#x\n", XAPIC_PPR_GET_PP_SUBCLASS(pXApicPage->ppr.u8Ppr));
366 if (!fX2ApicMode)
367 pHlp->pfnPrintf(pHlp, " RRD = %u (%#x)\n", pXApicPage->rrd.u32Rrd, pXApicPage->rrd.u32Rrd);
368 pHlp->pfnPrintf(pHlp, " LDR = %#x\n", pXApicPage->ldr.all.u32Ldr);
369 pHlp->pfnPrintf(pHlp, " Logical APIC ID = %#x\n", fX2ApicMode ? pX2ApicPage->ldr.u32LogicalApicId
370 : pXApicPage->ldr.u.u8LogicalApicId);
371 if (!fX2ApicMode)
372 {
373 pHlp->pfnPrintf(pHlp, " DFR = %#x\n", pXApicPage->dfr.all.u32Dfr);
374 pHlp->pfnPrintf(pHlp, " Model = %#x (%s)\n", pXApicPage->dfr.u.u4Model,
375 apicGetDestFormatName((XAPICDESTFORMAT)pXApicPage->dfr.u.u4Model));
376 }
377 pHlp->pfnPrintf(pHlp, " SVR = %#x\n", pXApicPage->svr.all.u32Svr);
378 pHlp->pfnPrintf(pHlp, " Vector = %u (%#x)\n", pXApicPage->svr.u.u8SpuriousVector,
379 pXApicPage->svr.u.u8SpuriousVector);
380 pHlp->pfnPrintf(pHlp, " Software Enabled = %RTbool\n", RT_BOOL(pXApicPage->svr.u.fApicSoftwareEnable));
381 pHlp->pfnPrintf(pHlp, " Supress EOI broadcast = %RTbool\n", RT_BOOL(pXApicPage->svr.u.fSupressEoiBroadcast));
382 pHlp->pfnPrintf(pHlp, " ISR\n");
383 apicR3DbgInfo256BitReg(&pXApicPage->isr, pHlp);
384 pHlp->pfnPrintf(pHlp, " TMR\n");
385 apicR3DbgInfo256BitReg(&pXApicPage->tmr, pHlp);
386 pHlp->pfnPrintf(pHlp, " IRR\n");
387 apicR3DbgInfo256BitReg(&pXApicPage->irr, pHlp);
388 pHlp->pfnPrintf(pHlp, " PIB\n");
389 apicR3DbgInfoPib((PCAPICPIB)pApicCpu->pvApicPibR3, pHlp);
390 pHlp->pfnPrintf(pHlp, " Level PIB\n");
391 apicR3DbgInfoPib(&pApicCpu->ApicPibLevel, pHlp);
392 pHlp->pfnPrintf(pHlp, " ESR Internal = %#x\n", pApicCpu->uEsrInternal);
393 pHlp->pfnPrintf(pHlp, " ESR = %#x\n", pXApicPage->esr.all.u32Errors);
394 pHlp->pfnPrintf(pHlp, " Redirectable IPI = %RTbool\n", pXApicPage->esr.u.fRedirectableIpi);
395 pHlp->pfnPrintf(pHlp, " Send Illegal Vector = %RTbool\n", pXApicPage->esr.u.fSendIllegalVector);
396 pHlp->pfnPrintf(pHlp, " Recv Illegal Vector = %RTbool\n", pXApicPage->esr.u.fRcvdIllegalVector);
397 pHlp->pfnPrintf(pHlp, " Illegal Register Address = %RTbool\n", pXApicPage->esr.u.fIllegalRegAddr);
398 pHlp->pfnPrintf(pHlp, " ICR Low = %#x\n", pXApicPage->icr_lo.all.u32IcrLo);
399 pHlp->pfnPrintf(pHlp, " Vector = %u (%#x)\n", pXApicPage->icr_lo.u.u8Vector,
400 pXApicPage->icr_lo.u.u8Vector);
401 pHlp->pfnPrintf(pHlp, " Delivery Mode = %#x (%s)\n", pXApicPage->icr_lo.u.u3DeliveryMode,
402 apicGetDeliveryModeName((XAPICDELIVERYMODE)pXApicPage->icr_lo.u.u3DeliveryMode));
403 pHlp->pfnPrintf(pHlp, " Destination Mode = %#x (%s)\n", pXApicPage->icr_lo.u.u1DestMode,
404 apicGetDestModeName((XAPICDESTMODE)pXApicPage->icr_lo.u.u1DestMode));
405 if (!fX2ApicMode)
406 pHlp->pfnPrintf(pHlp, " Delivery Status = %u\n", pXApicPage->icr_lo.u.u1DeliveryStatus);
407 pHlp->pfnPrintf(pHlp, " Level = %u\n", pXApicPage->icr_lo.u.u1Level);
408 pHlp->pfnPrintf(pHlp, " Trigger Mode = %u (%s)\n", pXApicPage->icr_lo.u.u1TriggerMode,
409 apicGetTriggerModeName((XAPICTRIGGERMODE)pXApicPage->icr_lo.u.u1TriggerMode));
410 pHlp->pfnPrintf(pHlp, " Destination shorthand = %#x (%s)\n", pXApicPage->icr_lo.u.u2DestShorthand,
411 apicGetDestShorthandName((XAPICDESTSHORTHAND)pXApicPage->icr_lo.u.u2DestShorthand));
412 pHlp->pfnPrintf(pHlp, " ICR High = %#x\n", pXApicPage->icr_hi.all.u32IcrHi);
413 pHlp->pfnPrintf(pHlp, " Destination field/mask = %#x\n", fX2ApicMode ? pX2ApicPage->icr_hi.u32IcrHi
414 : pXApicPage->icr_hi.u.u8Dest);
415}
416
417
418/**
419 * Helper for dumping the LVT timer.
420 *
421 * @param pVCpu The cross context virtual CPU structure.
422 * @param pHlp The debug output helper.
423 */
424static void apicR3InfoLvtTimer(PVMCPU pVCpu, PCDBGFINFOHLP pHlp)
425{
426 PCXAPICPAGE pXApicPage = VMCPU_TO_CXAPICPAGE(pVCpu);
427 uint32_t const uLvtTimer = pXApicPage->lvt_timer.all.u32LvtTimer;
428 pHlp->pfnPrintf(pHlp, "LVT Timer = %#RX32\n", uLvtTimer);
429 pHlp->pfnPrintf(pHlp, " Vector = %u (%#x)\n", pXApicPage->lvt_timer.u.u8Vector, pXApicPage->lvt_timer.u.u8Vector);
430 pHlp->pfnPrintf(pHlp, " Delivery status = %u\n", pXApicPage->lvt_timer.u.u1DeliveryStatus);
431 pHlp->pfnPrintf(pHlp, " Masked = %RTbool\n", XAPIC_LVT_IS_MASKED(uLvtTimer));
432 pHlp->pfnPrintf(pHlp, " Timer Mode = %#x (%s)\n", pXApicPage->lvt_timer.u.u2TimerMode,
433 apicGetTimerModeName((XAPICTIMERMODE)pXApicPage->lvt_timer.u.u2TimerMode));
434}
435
436
437/**
438 * Dumps APIC Local Vector Table (LVT) information.
439 *
440 * @param pVM The cross context VM structure.
441 * @param pHlp The info helpers.
442 * @param pszArgs Arguments, ignored.
443 */
444static DECLCALLBACK(void) apicR3InfoLvt(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs)
445{
446 NOREF(pszArgs);
447 PVMCPU pVCpu = VMMGetCpu(pVM);
448 if (!pVCpu)
449 pVCpu = &pVM->aCpus[0];
450
451 PCXAPICPAGE pXApicPage = VMCPU_TO_CXAPICPAGE(pVCpu);
452
453 /*
454 * Delivery modes available in the LVT entries. They're different (more reserved stuff) from the
455 * ICR delivery modes and hence we don't use apicGetDeliveryMode but mostly because we want small,
456 * fixed-length strings to fit our formatting needs here.
457 */
458 static const char * const s_apszLvtDeliveryModes[] =
459 {
460 "Fixed ",
461 "Rsvd ",
462 "SMI ",
463 "Rsvd ",
464 "NMI ",
465 "INIT ",
466 "Rsvd ",
467 "ExtINT"
468 };
469 /* Delivery Status. */
470 static const char * const s_apszLvtDeliveryStatus[] =
471 {
472 "Idle",
473 "Pend"
474 };
475 const char *pszNotApplicable = "";
476
477 pHlp->pfnPrintf(pHlp, "VCPU[%u] APIC Local Vector Table (LVT):\n", pVCpu->idCpu);
478 pHlp->pfnPrintf(pHlp, "lvt timermode mask trigger rirr polarity dlvr_st dlvr_mode vector\n");
479 /* Timer. */
480 {
481 /* Timer modes. */
482 static const char * const s_apszLvtTimerModes[] =
483 {
484 "One-shot ",
485 "Periodic ",
486 "TSC-dline"
487 };
488 const uint32_t uLvtTimer = pXApicPage->lvt_timer.all.u32LvtTimer;
489 const XAPICTIMERMODE enmTimerMode = XAPIC_LVT_GET_TIMER_MODE(uLvtTimer);
490 const char *pszTimerMode = s_apszLvtTimerModes[enmTimerMode];
491 const uint8_t uMask = XAPIC_LVT_IS_MASKED(uLvtTimer);
492 const uint8_t uDeliveryStatus = uLvtTimer & XAPIC_LVT_DELIVERY_STATUS;
493 const char *pszDeliveryStatus = s_apszLvtDeliveryStatus[uDeliveryStatus];
494 const uint8_t uVector = XAPIC_LVT_GET_VECTOR(uLvtTimer);
495
496 pHlp->pfnPrintf(pHlp, "%-7s %9s %u %5s %1s %8s %4s %6s %3u (%#x)\n",
497 "Timer",
498 pszTimerMode,
499 uMask,
500 pszNotApplicable, /* TriggerMode */
501 pszNotApplicable, /* Remote IRR */
502 pszNotApplicable, /* Polarity */
503 pszDeliveryStatus,
504 pszNotApplicable, /* Delivery Mode */
505 uVector,
506 uVector);
507 }
508
509#if XAPIC_HARDWARE_VERSION == XAPIC_HARDWARE_VERSION_P4
510 /* Thermal sensor. */
511 {
512 uint32_t const uLvtThermal = pXApicPage->lvt_thermal.all.u32LvtThermal;
513 const uint8_t uMask = XAPIC_LVT_IS_MASKED(uLvtThermal);
514 const uint8_t uDeliveryStatus = uLvtThermal & XAPIC_LVT_DELIVERY_STATUS;
515 const char *pszDeliveryStatus = s_apszLvtDeliveryStatus[uDeliveryStatus];
516 const XAPICDELIVERYMODE enmDeliveryMode = XAPIC_LVT_GET_DELIVERY_MODE(uLvtThermal);
517 const char *pszDeliveryMode = s_apszLvtDeliveryModes[enmDeliveryMode];
518 const uint8_t uVector = XAPIC_LVT_GET_VECTOR(uLvtThermal);
519
520 pHlp->pfnPrintf(pHlp, "%-7s %9s %u %5s %1s %8s %4s %6s %3u (%#x)\n",
521 "Thermal",
522 pszNotApplicable, /* Timer mode */
523 uMask,
524 pszNotApplicable, /* TriggerMode */
525 pszNotApplicable, /* Remote IRR */
526 pszNotApplicable, /* Polarity */
527 pszDeliveryStatus,
528 pszDeliveryMode,
529 uVector,
530 uVector);
531 }
532#endif
533
534 /* Performance Monitor Counters. */
535 {
536 uint32_t const uLvtPerf = pXApicPage->lvt_thermal.all.u32LvtThermal;
537 const uint8_t uMask = XAPIC_LVT_IS_MASKED(uLvtPerf);
538 const uint8_t uDeliveryStatus = uLvtPerf & XAPIC_LVT_DELIVERY_STATUS;
539 const char *pszDeliveryStatus = s_apszLvtDeliveryStatus[uDeliveryStatus];
540 const XAPICDELIVERYMODE enmDeliveryMode = XAPIC_LVT_GET_DELIVERY_MODE(uLvtPerf);
541 const char *pszDeliveryMode = s_apszLvtDeliveryModes[enmDeliveryMode];
542 const uint8_t uVector = XAPIC_LVT_GET_VECTOR(uLvtPerf);
543
544 pHlp->pfnPrintf(pHlp, "%-7s %9s %u %5s %1s %8s %4s %6s %3u (%#x)\n",
545 "Perf",
546 pszNotApplicable, /* Timer mode */
547 uMask,
548 pszNotApplicable, /* TriggerMode */
549 pszNotApplicable, /* Remote IRR */
550 pszNotApplicable, /* Polarity */
551 pszDeliveryStatus,
552 pszDeliveryMode,
553 uVector,
554 uVector);
555 }
556
557 /* LINT0, LINT1. */
558 {
559 /* LINTx name. */
560 static const char * const s_apszLvtLint[] =
561 {
562 "LINT0",
563 "LINT1"
564 };
565 /* Trigger mode. */
566 static const char * const s_apszLvtTriggerModes[] =
567 {
568 "Edge ",
569 "Level"
570 };
571 /* Polarity. */
572 static const char * const s_apszLvtPolarity[] =
573 {
574 "ActiveHi",
575 "ActiveLo"
576 };
577
578 uint32_t aLvtLint[2];
579 aLvtLint[0] = pXApicPage->lvt_lint0.all.u32LvtLint0;
580 aLvtLint[1] = pXApicPage->lvt_lint1.all.u32LvtLint1;
581 for (size_t i = 0; i < RT_ELEMENTS(aLvtLint); i++)
582 {
583 uint32_t const uLvtLint = aLvtLint[i];
584 const char *pszLint = s_apszLvtLint[i];
585 const uint8_t uMask = XAPIC_LVT_IS_MASKED(uLvtLint);
586 const XAPICTRIGGERMODE enmTriggerMode = XAPIC_LVT_GET_TRIGGER_MODE(uLvtLint);
587 const char *pszTriggerMode = s_apszLvtTriggerModes[enmTriggerMode];
588 const uint8_t uRemoteIrr = XAPIC_LVT_GET_REMOTE_IRR(uLvtLint);
589 const uint8_t uPolarity = XAPIC_LVT_GET_POLARITY(uLvtLint);
590 const char *pszPolarity = s_apszLvtPolarity[uPolarity];
591 const uint8_t uDeliveryStatus = uLvtLint & XAPIC_LVT_DELIVERY_STATUS;
592 const char *pszDeliveryStatus = s_apszLvtDeliveryStatus[uDeliveryStatus];
593 const XAPICDELIVERYMODE enmDeliveryMode = XAPIC_LVT_GET_DELIVERY_MODE(uLvtLint);
594 const char *pszDeliveryMode = s_apszLvtDeliveryModes[enmDeliveryMode];
595 const uint8_t uVector = XAPIC_LVT_GET_VECTOR(uLvtLint);
596
597 pHlp->pfnPrintf(pHlp, "%-7s %9s %u %5s %u %8s %4s %6s %3u (%#x)\n",
598 pszLint,
599 pszNotApplicable, /* Timer mode */
600 uMask,
601 pszTriggerMode,
602 uRemoteIrr,
603 pszPolarity,
604 pszDeliveryStatus,
605 pszDeliveryMode,
606 uVector,
607 uVector);
608 }
609 }
610
611 /* Error. */
612 {
613 uint32_t const uLvtError = pXApicPage->lvt_thermal.all.u32LvtThermal;
614 const uint8_t uMask = XAPIC_LVT_IS_MASKED(uLvtError);
615 const uint8_t uDeliveryStatus = uLvtError & XAPIC_LVT_DELIVERY_STATUS;
616 const char *pszDeliveryStatus = s_apszLvtDeliveryStatus[uDeliveryStatus];
617 const XAPICDELIVERYMODE enmDeliveryMode = XAPIC_LVT_GET_DELIVERY_MODE(uLvtError);
618 const char *pszDeliveryMode = s_apszLvtDeliveryModes[enmDeliveryMode];
619 const uint8_t uVector = XAPIC_LVT_GET_VECTOR(uLvtError);
620
621 pHlp->pfnPrintf(pHlp, "%-7s %9s %u %5s %1s %8s %4s %6s %3u (%#x)\n",
622 "Error",
623 pszNotApplicable, /* Timer mode */
624 uMask,
625 pszNotApplicable, /* TriggerMode */
626 pszNotApplicable, /* Remote IRR */
627 pszNotApplicable, /* Polarity */
628 pszDeliveryStatus,
629 pszDeliveryMode,
630 uVector,
631 uVector);
632 }
633}
634
635
636/**
637 * Dumps the APIC timer information.
638 *
639 * @param pVM The cross context VM structure.
640 * @param pHlp The info helpers.
641 * @param pszArgs Arguments, ignored.
642 */
643static DECLCALLBACK(void) apicR3InfoTimer(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs)
644{
645 NOREF(pszArgs);
646 PVMCPU pVCpu = VMMGetCpu(pVM);
647 if (!pVCpu)
648 pVCpu = &pVM->aCpus[0];
649
650 PCXAPICPAGE pXApicPage = VMCPU_TO_CXAPICPAGE(pVCpu);
651 PCAPICCPU pApicCpu = VMCPU_TO_APICCPU(pVCpu);
652
653 pHlp->pfnPrintf(pHlp, "VCPU[%u] Local APIC timer:\n", pVCpu->idCpu);
654 pHlp->pfnPrintf(pHlp, " ICR = %#RX32\n", pXApicPage->timer_icr.u32InitialCount);
655 pHlp->pfnPrintf(pHlp, " CCR = %#RX32\n", pXApicPage->timer_ccr.u32CurrentCount);
656 pHlp->pfnPrintf(pHlp, " DCR = %#RX32\n", pXApicPage->timer_dcr.all.u32DivideValue);
657 pHlp->pfnPrintf(pHlp, " Timer shift = %#x\n", apicGetTimerShift(pXApicPage));
658 pHlp->pfnPrintf(pHlp, " Timer initial TS = %#RU64\n", pApicCpu->u64TimerInitial);
659 apicR3InfoLvtTimer(pVCpu, pHlp);
660}
661
662
663#ifdef APIC_FUZZY_SSM_COMPAT_TEST
664
665/**
666 * Reads a 32-bit register at a specified offset.
667 *
668 * @returns The value at the specified offset.
669 * @param pXApicPage The xAPIC page.
670 * @param offReg The offset of the register being read.
671 *
672 * @remarks Duplicate of apicReadRaw32()!
673 */
674static uint32_t apicR3ReadRawR32(PCXAPICPAGE pXApicPage, uint16_t offReg)
675{
676 Assert(offReg < sizeof(*pXApicPage) - sizeof(uint32_t));
677 uint8_t const *pbXApic = (const uint8_t *)pXApicPage;
678 uint32_t const uValue = *(const uint32_t *)(pbXApic + offReg);
679 return uValue;
680}
681
682
683/**
684 * Helper for dumping per-VCPU APIC state to the release logger.
685 *
686 * This is primarily concerned about the APIC state relevant for saved-states.
687 *
688 * @param pVCpu The cross context virtual CPU structure.
689 * @param pszPrefix A caller supplied prefix before dumping the state.
690 * @param uVersion Data layout version.
691 */
692static void apicR3DumpState(PVMCPU pVCpu, const char *pszPrefix, uint32_t uVersion)
693{
694 PCAPICCPU pApicCpu = VMCPU_TO_APICCPU(pVCpu);
695
696 LogRel(("APIC%u: %s (version %u):\n", pVCpu->idCpu, pszPrefix, uVersion));
697
698 switch (uVersion)
699 {
700 case APIC_SAVED_STATE_VERSION:
701 case APIC_SAVED_STATE_VERSION_VBOX_51_BETA2:
702 {
703 /* The auxiliary state. */
704 LogRel(("APIC%u: uApicBaseMsr = %#RX64\n", pVCpu->idCpu, pApicCpu->uApicBaseMsr));
705 LogRel(("APIC%u: uEsrInternal = %#RX64\n", pVCpu->idCpu, pApicCpu->uEsrInternal));
706
707 /* The timer. */
708 LogRel(("APIC%u: u64TimerInitial = %#RU64\n", pVCpu->idCpu, pApicCpu->u64TimerInitial));
709 LogRel(("APIC%u: uHintedTimerInitialCount = %#RU64\n", pVCpu->idCpu, pApicCpu->uHintedTimerInitialCount));
710 LogRel(("APIC%u: uHintedTimerShift = %#RU64\n", pVCpu->idCpu, pApicCpu->uHintedTimerShift));
711
712 PCXAPICPAGE pXApicPage = VMCPU_TO_CXAPICPAGE(pVCpu);
713 LogRel(("APIC%u: uTimerICR = %#RX32\n", pVCpu->idCpu, pXApicPage->timer_icr.u32InitialCount));
714 LogRel(("APIC%u: uTimerCCR = %#RX32\n", pVCpu->idCpu, pXApicPage->timer_ccr.u32CurrentCount));
715
716 /* The PIBs. */
717 LogRel(("APIC%u: Edge PIB : %.*Rhxs\n", pVCpu->idCpu, sizeof(APICPIB), pApicCpu->pvApicPibR3));
718 LogRel(("APIC%u: Level PIB: %.*Rhxs\n", pVCpu->idCpu, sizeof(APICPIB), &pApicCpu->ApicPibLevel));
719
720 /* The LINT0, LINT1 interrupt line active states. */
721 LogRel(("APIC%u: fActiveLint0 = %RTbool\n", pVCpu->idCpu, pApicCpu->fActiveLint0));
722 LogRel(("APIC%u: fActiveLint1 = %RTbool\n", pVCpu->idCpu, pApicCpu->fActiveLint1));
723
724 /* The APIC page. */
725 LogRel(("APIC%u: APIC page: %.*Rhxs\n", pVCpu->idCpu, sizeof(XAPICPAGE), pApicCpu->pvApicPageR3));
726 break;
727 }
728
729 case APIC_SAVED_STATE_VERSION_VBOX_50:
730 case APIC_SAVED_STATE_VERSION_VBOX_30:
731 case APIC_SAVED_STATE_VERSION_ANCIENT:
732 {
733 PCXAPICPAGE pXApicPage = VMCPU_TO_CXAPICPAGE(pVCpu);
734 LogRel(("APIC%u: uApicBaseMsr = %#RX32\n", pVCpu->idCpu, RT_LO_U32(pApicCpu->uApicBaseMsr)));
735 LogRel(("APIC%u: uId = %#RX32\n", pVCpu->idCpu, pXApicPage->id.u8ApicId));
736 LogRel(("APIC%u: uPhysId = N/A\n", pVCpu->idCpu));
737 LogRel(("APIC%u: uArbId = N/A\n", pVCpu->idCpu));
738 LogRel(("APIC%u: uTpr = %#RX32\n", pVCpu->idCpu, pXApicPage->tpr.u8Tpr));
739 LogRel(("APIC%u: uSvr = %#RX32\n", pVCpu->idCpu, pXApicPage->svr.all.u32Svr));
740 LogRel(("APIC%u: uLdr = %#x\n", pVCpu->idCpu, pXApicPage->ldr.all.u32Ldr));
741 LogRel(("APIC%u: uDfr = %#x\n", pVCpu->idCpu, pXApicPage->dfr.all.u32Dfr));
742
743 for (size_t i = 0; i < 8; i++)
744 {
745 LogRel(("APIC%u: Isr[%u].u32Reg = %#RX32\n", pVCpu->idCpu, i, pXApicPage->isr.u[i].u32Reg));
746 LogRel(("APIC%u: Tmr[%u].u32Reg = %#RX32\n", pVCpu->idCpu, i, pXApicPage->tmr.u[i].u32Reg));
747 LogRel(("APIC%u: Irr[%u].u32Reg = %#RX32\n", pVCpu->idCpu, i, pXApicPage->irr.u[i].u32Reg));
748 }
749
750 for (size_t i = 0; i < XAPIC_MAX_LVT_ENTRIES_P4; i++)
751 {
752 uint16_t const offReg = XAPIC_OFF_LVT_START + (i << 4);
753 LogRel(("APIC%u: Lvt[%u].u32Reg = %#RX32\n", pVCpu->idCpu, i, apicR3ReadRawR32(pXApicPage, offReg)));
754 }
755
756 LogRel(("APIC%u: uEsr = %#RX32\n", pVCpu->idCpu, pXApicPage->esr.all.u32Errors));
757 LogRel(("APIC%u: uIcr_Lo = %#RX32\n", pVCpu->idCpu, pXApicPage->icr_lo.all.u32IcrLo));
758 LogRel(("APIC%u: uIcr_Hi = %#RX32\n", pVCpu->idCpu, pXApicPage->icr_hi.all.u32IcrHi));
759 LogRel(("APIC%u: uTimerDcr = %#RX32\n", pVCpu->idCpu, pXApicPage->timer_dcr.all.u32DivideValue));
760 LogRel(("APIC%u: uCountShift = %#RX32\n", pVCpu->idCpu, apicGetTimerShift(pXApicPage)));
761 LogRel(("APIC%u: uInitialCount = %#RX32\n", pVCpu->idCpu, pXApicPage->timer_icr.u32InitialCount));
762 LogRel(("APIC%u: u64InitialCountLoadTime = %#RX64\n", pVCpu->idCpu, pApicCpu->u64TimerInitial));
763 LogRel(("APIC%u: u64NextTime / TimerCCR = %#RX64\n", pVCpu->idCpu, pXApicPage->timer_ccr.u32CurrentCount));
764 break;
765 }
766
767 default:
768 {
769 LogRel(("APIC: apicR3DumpState: Invalid/unrecognized saved-state version %u (%#x)\n", uVersion, uVersion));
770 break;
771 }
772 }
773}
774
775#endif /* APIC_FUZZY_SSM_COMPAT_TEST */
776
777/**
778 * Worker for saving per-VM APIC data.
779 *
780 * @returns VBox status code.
781 * @param pVM The cross context VM structure.
782 * @param pSSM The SSM handle.
783 */
784static int apicR3SaveVMData(PVM pVM, PSSMHANDLE pSSM)
785{
786 PAPIC pApic = VM_TO_APIC(pVM);
787 SSMR3PutU32(pSSM, pVM->cCpus);
788 SSMR3PutBool(pSSM, pApic->fIoApicPresent);
789 return SSMR3PutU32(pSSM, pApic->enmMaxMode);
790}
791
792
793/**
794 * Worker for loading per-VM APIC data.
795 *
796 * @returns VBox status code.
797 * @param pVM The cross context VM structure.
798 * @param pSSM The SSM handle.
799 */
800static int apicR3LoadVMData(PVM pVM, PSSMHANDLE pSSM)
801{
802 PAPIC pApic = VM_TO_APIC(pVM);
803
804 /* Load and verify number of CPUs. */
805 uint32_t cCpus;
806 int rc = SSMR3GetU32(pSSM, &cCpus);
807 AssertRCReturn(rc, rc);
808 if (cCpus != pVM->cCpus)
809 return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch - cCpus: saved=%u config=%u"), cCpus, pVM->cCpus);
810
811 /* Load and verify I/O APIC presence. */
812 bool fIoApicPresent;
813 rc = SSMR3GetBool(pSSM, &fIoApicPresent);
814 AssertRCReturn(rc, rc);
815 if (fIoApicPresent != pApic->fIoApicPresent)
816 return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch - fIoApicPresent: saved=%RTbool config=%RTbool"),
817 fIoApicPresent, pApic->fIoApicPresent);
818
819 /* Load and verify configured max APIC mode. */
820 uint32_t uSavedMaxApicMode;
821 rc = SSMR3GetU32(pSSM, &uSavedMaxApicMode);
822 AssertRCReturn(rc, rc);
823 if (uSavedMaxApicMode != (uint32_t)pApic->enmMaxMode)
824 return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch - uApicMode: saved=%u config=%u"),
825 uSavedMaxApicMode, pApic->enmMaxMode);
826 return VINF_SUCCESS;
827}
828
829
830/**
831 * Worker for loading per-VCPU APIC data for legacy (old) saved-states.
832 *
833 * @returns VBox status code.
834 * @param pVCpu The cross context virtual CPU structure.
835 * @param pSSM The SSM handle.
836 * @param uVersion Data layout version.
837 */
838static int apicR3LoadLegacyVCpuData(PVMCPU pVCpu, PSSMHANDLE pSSM, uint32_t uVersion)
839{
840 AssertReturn(uVersion <= APIC_SAVED_STATE_VERSION_VBOX_50, VERR_NOT_SUPPORTED);
841
842 PAPICCPU pApicCpu = VMCPU_TO_APICCPU(pVCpu);
843 PXAPICPAGE pXApicPage = VMCPU_TO_XAPICPAGE(pVCpu);
844
845 uint32_t uApicBaseLo;
846 int rc = SSMR3GetU32(pSSM, &uApicBaseLo);
847 AssertRCReturn(rc, rc);
848 pApicCpu->uApicBaseMsr = uApicBaseLo;
849 Log2(("APIC%u: apicR3LoadLegacyVCpuData: uApicBaseMsr=%#RX64\n", pVCpu->idCpu, pApicCpu->uApicBaseMsr));
850
851 switch (uVersion)
852 {
853 case APIC_SAVED_STATE_VERSION_VBOX_50:
854 case APIC_SAVED_STATE_VERSION_VBOX_30:
855 {
856 uint32_t uApicId, uPhysApicId, uArbId;
857 SSMR3GetU32(pSSM, &uApicId); pXApicPage->id.u8ApicId = uApicId;
858 SSMR3GetU32(pSSM, &uPhysApicId); NOREF(uPhysApicId); /* PhysId == pVCpu->idCpu */
859 SSMR3GetU32(pSSM, &uArbId); NOREF(uArbId); /* ArbID is & was unused. */
860 break;
861 }
862
863 case APIC_SAVED_STATE_VERSION_ANCIENT:
864 {
865 uint8_t uPhysApicId;
866 SSMR3GetU8(pSSM, &pXApicPage->id.u8ApicId);
867 SSMR3GetU8(pSSM, &uPhysApicId); NOREF(uPhysApicId); /* PhysId == pVCpu->idCpu */
868 break;
869 }
870
871 default:
872 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
873 }
874
875 uint32_t u32Tpr;
876 SSMR3GetU32(pSSM, &u32Tpr);
877 pXApicPage->tpr.u8Tpr = u32Tpr & XAPIC_TPR_VALID;
878
879 SSMR3GetU32(pSSM, &pXApicPage->svr.all.u32Svr);
880 SSMR3GetU8(pSSM, &pXApicPage->ldr.u.u8LogicalApicId);
881
882 uint8_t uDfr;
883 SSMR3GetU8(pSSM, &uDfr);
884 pXApicPage->dfr.u.u4Model = uDfr >> 4;
885
886 AssertCompile(RT_ELEMENTS(pXApicPage->isr.u) == 8);
887 AssertCompile(RT_ELEMENTS(pXApicPage->tmr.u) == 8);
888 AssertCompile(RT_ELEMENTS(pXApicPage->irr.u) == 8);
889 for (size_t i = 0; i < 8; i++)
890 {
891 SSMR3GetU32(pSSM, &pXApicPage->isr.u[i].u32Reg);
892 SSMR3GetU32(pSSM, &pXApicPage->tmr.u[i].u32Reg);
893 SSMR3GetU32(pSSM, &pXApicPage->irr.u[i].u32Reg);
894 }
895
896 SSMR3GetU32(pSSM, &pXApicPage->lvt_timer.all.u32LvtTimer);
897 SSMR3GetU32(pSSM, &pXApicPage->lvt_thermal.all.u32LvtThermal);
898 SSMR3GetU32(pSSM, &pXApicPage->lvt_perf.all.u32LvtPerf);
899 SSMR3GetU32(pSSM, &pXApicPage->lvt_lint0.all.u32LvtLint0);
900 SSMR3GetU32(pSSM, &pXApicPage->lvt_lint1.all.u32LvtLint1);
901 SSMR3GetU32(pSSM, &pXApicPage->lvt_error.all.u32LvtError);
902
903 SSMR3GetU32(pSSM, &pXApicPage->esr.all.u32Errors);
904 SSMR3GetU32(pSSM, &pXApicPage->icr_lo.all.u32IcrLo);
905 SSMR3GetU32(pSSM, &pXApicPage->icr_hi.all.u32IcrHi);
906
907 uint32_t u32TimerShift;
908 SSMR3GetU32(pSSM, &pXApicPage->timer_dcr.all.u32DivideValue);
909 SSMR3GetU32(pSSM, &u32TimerShift);
910 /*
911 * Old implementation may have left the timer shift uninitialized until
912 * the timer configuration register was written. Unfortunately zero is
913 * also a valid timer shift value, so we're just going to ignore it
914 * completely. The shift count can always be derived from the DCR.
915 * See @bugref{8245#c98}.
916 */
917 uint8_t const uTimerShift = apicGetTimerShift(pXApicPage);
918
919 SSMR3GetU32(pSSM, &pXApicPage->timer_icr.u32InitialCount);
920 SSMR3GetU64(pSSM, &pApicCpu->u64TimerInitial);
921 uint64_t uNextTS;
922 rc = SSMR3GetU64(pSSM, &uNextTS); AssertRCReturn(rc, rc);
923 if (uNextTS >= pApicCpu->u64TimerInitial + ((pXApicPage->timer_icr.u32InitialCount + 1) << uTimerShift))
924 pXApicPage->timer_ccr.u32CurrentCount = pXApicPage->timer_icr.u32InitialCount;
925
926 rc = TMR3TimerLoad(pApicCpu->pTimerR3, pSSM);
927 AssertRCReturn(rc, rc);
928 Assert(pApicCpu->uHintedTimerInitialCount == 0);
929 Assert(pApicCpu->uHintedTimerShift == 0);
930 if (TMTimerIsActive(pApicCpu->pTimerR3))
931 {
932 uint32_t const uInitialCount = pXApicPage->timer_icr.u32InitialCount;
933 apicHintTimerFreq(pApicCpu, uInitialCount, uTimerShift);
934 }
935
936 return rc;
937}
938
939
940/**
941 * @copydoc FNSSMDEVSAVEEXEC
942 */
943static DECLCALLBACK(int) apicR3SaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
944{
945 PVM pVM = PDMDevHlpGetVM(pDevIns);
946 AssertReturn(pVM, VERR_INVALID_VM_HANDLE);
947
948 LogFlow(("APIC: apicR3SaveExec\n"));
949
950 /* Save per-VM data. */
951 int rc = apicR3SaveVMData(pVM, pSSM);
952 AssertRCReturn(rc, rc);
953
954 /* Save per-VCPU data.*/
955 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
956 {
957 PVMCPU pVCpu = &pVM->aCpus[idCpu];
958 PCAPICCPU pApicCpu = VMCPU_TO_APICCPU(pVCpu);
959
960 /* Update interrupts from the pending-interrupts bitmaps to the IRR. */
961 APICUpdatePendingInterrupts(pVCpu);
962
963 /* Save the auxiliary data. */
964 SSMR3PutU64(pSSM, pApicCpu->uApicBaseMsr);
965 SSMR3PutU32(pSSM, pApicCpu->uEsrInternal);
966
967 /* Save the APIC page. */
968 if (XAPIC_IN_X2APIC_MODE(pVCpu))
969 SSMR3PutStruct(pSSM, (const void *)pApicCpu->pvApicPageR3, &g_aX2ApicPageFields[0]);
970 else
971 SSMR3PutStruct(pSSM, (const void *)pApicCpu->pvApicPageR3, &g_aXApicPageFields[0]);
972
973 /* Save the timer. */
974 SSMR3PutU64(pSSM, pApicCpu->u64TimerInitial);
975 TMR3TimerSave(pApicCpu->pTimerR3, pSSM);
976
977 /* Save the LINT0, LINT1 interrupt line states. */
978 SSMR3PutBool(pSSM, pApicCpu->fActiveLint0);
979 SSMR3PutBool(pSSM, pApicCpu->fActiveLint1);
980
981#if defined(APIC_FUZZY_SSM_COMPAT_TEST) || defined(DEBUG_ramshankar)
982 apicR3DumpState(pVCpu, "Saved state", APIC_SAVED_STATE_VERSION);
983#endif
984 }
985
986#ifdef APIC_FUZZY_SSM_COMPAT_TEST
987 /* The state is fuzzy, don't even bother trying to load the guest. */
988 return VERR_INVALID_STATE;
989#else
990 return rc;
991#endif
992}
993
994
995/**
996 * @copydoc FNSSMDEVLOADEXEC
997 */
998static DECLCALLBACK(int) apicR3LoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
999{
1000 PVM pVM = PDMDevHlpGetVM(pDevIns);
1001
1002 AssertReturn(pVM, VERR_INVALID_VM_HANDLE);
1003 AssertReturn(uPass == SSM_PASS_FINAL, VERR_WRONG_ORDER);
1004
1005 LogFlow(("APIC: apicR3LoadExec: uVersion=%u uPass=%#x\n", uVersion, uPass));
1006
1007 /* Weed out invalid versions. */
1008 if ( uVersion != APIC_SAVED_STATE_VERSION
1009 && uVersion != APIC_SAVED_STATE_VERSION_VBOX_51_BETA2
1010 && uVersion != APIC_SAVED_STATE_VERSION_VBOX_50
1011 && uVersion != APIC_SAVED_STATE_VERSION_VBOX_30
1012 && uVersion != APIC_SAVED_STATE_VERSION_ANCIENT)
1013 {
1014 LogRel(("APIC: apicR3LoadExec: Invalid/unrecognized saved-state version %u (%#x)\n", uVersion, uVersion));
1015 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
1016 }
1017
1018 int rc = VINF_SUCCESS;
1019 if (uVersion > APIC_SAVED_STATE_VERSION_VBOX_30)
1020 {
1021 rc = apicR3LoadVMData(pVM, pSSM);
1022 AssertRCReturn(rc, rc);
1023
1024 if (uVersion == APIC_SAVED_STATE_VERSION)
1025 { /* Load any new additional per-VM data. */ }
1026 }
1027
1028 /*
1029 * Restore per CPU state.
1030 *
1031 * Note! PDM will restore the VMCPU_FF_INTERRUPT_APIC flag for us.
1032 * This code doesn't touch it. No devices should make us touch
1033 * it later during the restore either, only during the 'done' phase.
1034 */
1035 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
1036 {
1037 PVMCPU pVCpu = &pVM->aCpus[idCpu];
1038 PAPICCPU pApicCpu = VMCPU_TO_APICCPU(pVCpu);
1039
1040 if (uVersion > APIC_SAVED_STATE_VERSION_VBOX_50)
1041 {
1042 /* Load the auxiliary data. */
1043 SSMR3GetU64(pSSM, (uint64_t *)&pApicCpu->uApicBaseMsr);
1044 SSMR3GetU32(pSSM, &pApicCpu->uEsrInternal);
1045
1046 /* Load the APIC page. */
1047 if (XAPIC_IN_X2APIC_MODE(pVCpu))
1048 SSMR3GetStruct(pSSM, pApicCpu->pvApicPageR3, &g_aX2ApicPageFields[0]);
1049 else
1050 SSMR3GetStruct(pSSM, pApicCpu->pvApicPageR3, &g_aXApicPageFields[0]);
1051
1052 /* Load the timer. */
1053 rc = SSMR3GetU64(pSSM, &pApicCpu->u64TimerInitial); AssertRCReturn(rc, rc);
1054 rc = TMR3TimerLoad(pApicCpu->pTimerR3, pSSM); AssertRCReturn(rc, rc);
1055 Assert(pApicCpu->uHintedTimerShift == 0);
1056 Assert(pApicCpu->uHintedTimerInitialCount == 0);
1057 if (TMTimerIsActive(pApicCpu->pTimerR3))
1058 {
1059 PCXAPICPAGE pXApicPage = VMCPU_TO_CXAPICPAGE(pVCpu);
1060 uint32_t const uInitialCount = pXApicPage->timer_icr.u32InitialCount;
1061 uint8_t const uTimerShift = apicGetTimerShift(pXApicPage);
1062 apicHintTimerFreq(pApicCpu, uInitialCount, uTimerShift);
1063 }
1064
1065 /* Load the LINT0, LINT1 interrupt line states. */
1066 if (uVersion > APIC_SAVED_STATE_VERSION_VBOX_51_BETA2)
1067 {
1068 SSMR3GetBool(pSSM, (bool *)&pApicCpu->fActiveLint0);
1069 SSMR3GetBool(pSSM, (bool *)&pApicCpu->fActiveLint1);
1070 }
1071 }
1072 else
1073 {
1074 rc = apicR3LoadLegacyVCpuData(pVCpu, pSSM, uVersion);
1075 AssertRCReturn(rc, rc);
1076 }
1077
1078 /*
1079 * Check that we're still good wrt restored data, then tell CPUM about the current CPUID[1].EDX[9] visibility.
1080 */
1081 rc = SSMR3HandleGetStatus(pSSM);
1082 AssertRCReturn(rc, rc);
1083 CPUMSetGuestCpuIdPerCpuApicFeature(pVCpu, RT_BOOL(pApicCpu->uApicBaseMsr & MSR_IA32_APICBASE_EN));
1084
1085#if defined(APIC_FUZZY_SSM_COMPAT_TEST) || defined(DEBUG_ramshankar)
1086 apicR3DumpState(pVCpu, "Loaded state", uVersion);
1087#endif
1088 }
1089
1090 return rc;
1091}
1092
1093
1094/**
1095 * The timer callback.
1096 *
1097 * @param pDevIns The device instance.
1098 * @param pTimer The timer handle.
1099 * @param pvUser Opaque pointer to the VMCPU.
1100 *
1101 * @thread Any.
1102 * @remarks Currently this function is invoked on the last EMT, see @c
1103 * idTimerCpu in tmR3TimerCallback(). However, the code does -not-
1104 * rely on this and is designed to work with being invoked on any
1105 * thread.
1106 */
1107static DECLCALLBACK(void) apicR3TimerCallback(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)
1108{
1109 PVMCPU pVCpu = (PVMCPU)pvUser;
1110 Assert(TMTimerIsLockOwner(pTimer));
1111 Assert(pVCpu);
1112 LogFlow(("APIC%u: apicR3TimerCallback\n", pVCpu->idCpu));
1113 RT_NOREF2(pDevIns, pTimer);
1114
1115 PXAPICPAGE pXApicPage = VMCPU_TO_XAPICPAGE(pVCpu);
1116 uint32_t const uLvtTimer = pXApicPage->lvt_timer.all.u32LvtTimer;
1117#ifdef VBOX_WITH_STATISTICS
1118 PAPICCPU pApicCpu = VMCPU_TO_APICCPU(pVCpu);
1119 STAM_COUNTER_INC(&pApicCpu->StatTimerCallback);
1120#endif
1121 if (!XAPIC_LVT_IS_MASKED(uLvtTimer))
1122 {
1123 uint8_t uVector = XAPIC_LVT_GET_VECTOR(uLvtTimer);
1124 Log2(("APIC%u: apicR3TimerCallback: Raising timer interrupt. uVector=%#x\n", pVCpu->idCpu, uVector));
1125 apicPostInterrupt(pVCpu, uVector, XAPICTRIGGERMODE_EDGE, 0 /* uSrcTag */);
1126 }
1127
1128 XAPICTIMERMODE enmTimerMode = XAPIC_LVT_GET_TIMER_MODE(uLvtTimer);
1129 switch (enmTimerMode)
1130 {
1131 case XAPICTIMERMODE_PERIODIC:
1132 {
1133 /* The initial-count register determines if the periodic timer is re-armed. */
1134 uint32_t const uInitialCount = pXApicPage->timer_icr.u32InitialCount;
1135 pXApicPage->timer_ccr.u32CurrentCount = uInitialCount;
1136 if (uInitialCount)
1137 {
1138 Log2(("APIC%u: apicR3TimerCallback: Re-arming timer. uInitialCount=%#RX32\n", pVCpu->idCpu, uInitialCount));
1139 apicStartTimer(pVCpu, uInitialCount);
1140 }
1141 break;
1142 }
1143
1144 case XAPICTIMERMODE_ONESHOT:
1145 {
1146 pXApicPage->timer_ccr.u32CurrentCount = 0;
1147 break;
1148 }
1149
1150 case XAPICTIMERMODE_TSC_DEADLINE:
1151 {
1152 /** @todo implement TSC deadline. */
1153 AssertMsgFailed(("APIC: TSC deadline mode unimplemented\n"));
1154 break;
1155 }
1156 }
1157}
1158
1159
1160/**
1161 * @interface_method_impl{PDMDEVREG,pfnReset}
1162 */
1163static DECLCALLBACK(void) apicR3Reset(PPDMDEVINS pDevIns)
1164{
1165 PVM pVM = PDMDevHlpGetVM(pDevIns);
1166 VM_ASSERT_EMT0(pVM);
1167 VM_ASSERT_IS_NOT_RUNNING(pVM);
1168
1169 LogFlow(("APIC: apicR3Reset\n"));
1170
1171 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
1172 {
1173 PVMCPU pVCpuDest = &pVM->aCpus[idCpu];
1174 PAPICCPU pApicCpu = VMCPU_TO_APICCPU(pVCpuDest);
1175
1176 if (TMTimerIsActive(pApicCpu->pTimerR3))
1177 TMTimerStop(pApicCpu->pTimerR3);
1178
1179 apicResetCpu(pVCpuDest, true /* fResetApicBaseMsr */);
1180
1181 /* Clear the interrupt pending force flag. */
1182 apicClearInterruptFF(pVCpuDest, PDMAPICIRQ_HARDWARE);
1183 }
1184}
1185
1186
1187/**
1188 * @interface_method_impl{PDMDEVREG,pfnRelocate}
1189 */
1190static DECLCALLBACK(void) apicR3Relocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta)
1191{
1192 PVM pVM = PDMDevHlpGetVM(pDevIns);
1193 PAPIC pApic = VM_TO_APIC(pVM);
1194 PAPICDEV pApicDev = PDMINS_2_DATA(pDevIns, PAPICDEV);
1195
1196 LogFlow(("APIC: apicR3Relocate: pVM=%p pDevIns=%p offDelta=%RGi\n", pVM, pDevIns, offDelta));
1197
1198 pApicDev->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
1199
1200 pApic->pApicDevRC = PDMINS_2_DATA_RCPTR(pDevIns);
1201 pApic->pvApicPibRC += offDelta;
1202
1203 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
1204 {
1205 PVMCPU pVCpu = &pVM->aCpus[idCpu];
1206 PAPICCPU pApicCpu = VMCPU_TO_APICCPU(pVCpu);
1207 pApicCpu->pTimerRC = TMTimerRCPtr(pApicCpu->pTimerR3);
1208
1209 pApicCpu->pvApicPageRC += offDelta;
1210 pApicCpu->pvApicPibRC += offDelta;
1211 Log2(("APIC%u: apicR3Relocate: APIC PIB at %RGv\n", pVCpu->idCpu, pApicCpu->pvApicPibRC));
1212 }
1213}
1214
1215
1216/**
1217 * Terminates the APIC state.
1218 *
1219 * @param pVM The cross context VM structure.
1220 */
1221static void apicR3TermState(PVM pVM)
1222{
1223 PAPIC pApic = VM_TO_APIC(pVM);
1224 LogFlow(("APIC: apicR3TermState: pVM=%p\n", pVM));
1225
1226 /* Unmap and free the PIB. */
1227 if (pApic->pvApicPibR3 != NIL_RTR3PTR)
1228 {
1229 size_t const cPages = pApic->cbApicPib >> PAGE_SHIFT;
1230 if (cPages == 1)
1231 SUPR3PageFreeEx(pApic->pvApicPibR3, cPages);
1232 else
1233 SUPR3ContFree(pApic->pvApicPibR3, cPages);
1234 pApic->pvApicPibR3 = NIL_RTR3PTR;
1235 pApic->pvApicPibR0 = NIL_RTR0PTR;
1236 pApic->pvApicPibRC = NIL_RTRCPTR;
1237 }
1238
1239 /* Unmap and free the virtual-APIC pages. */
1240 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
1241 {
1242 PVMCPU pVCpu = &pVM->aCpus[idCpu];
1243 PAPICCPU pApicCpu = VMCPU_TO_APICCPU(pVCpu);
1244
1245 pApicCpu->pvApicPibR3 = NIL_RTR3PTR;
1246 pApicCpu->pvApicPibR0 = NIL_RTR0PTR;
1247 pApicCpu->pvApicPibRC = NIL_RTRCPTR;
1248
1249 if (pApicCpu->pvApicPageR3 != NIL_RTR3PTR)
1250 {
1251 SUPR3PageFreeEx(pApicCpu->pvApicPageR3, 1 /* cPages */);
1252 pApicCpu->pvApicPageR3 = NIL_RTR3PTR;
1253 pApicCpu->pvApicPageR0 = NIL_RTR0PTR;
1254 pApicCpu->pvApicPageRC = NIL_RTRCPTR;
1255 }
1256 }
1257}
1258
1259
1260/**
1261 * Initializes the APIC state.
1262 *
1263 * @returns VBox status code.
1264 * @param pVM The cross context VM structure.
1265 */
1266static int apicR3InitState(PVM pVM)
1267{
1268 PAPIC pApic = VM_TO_APIC(pVM);
1269 LogFlow(("APIC: apicR3InitState: pVM=%p\n", pVM));
1270
1271 /* With hardware virtualization, we don't need to map the APIC in GC. */
1272 bool const fNeedsGCMapping = VM_IS_RAW_MODE_ENABLED(pVM);
1273
1274 /*
1275 * Allocate and map the pending-interrupt bitmap (PIB).
1276 *
1277 * We allocate all the VCPUs' PIBs contiguously in order to save space as
1278 * physically contiguous allocations are rounded to a multiple of page size.
1279 */
1280 Assert(pApic->pvApicPibR3 == NIL_RTR3PTR);
1281 Assert(pApic->pvApicPibR0 == NIL_RTR0PTR);
1282 Assert(pApic->pvApicPibRC == NIL_RTRCPTR);
1283 pApic->cbApicPib = RT_ALIGN_Z(pVM->cCpus * sizeof(APICPIB), PAGE_SIZE);
1284 size_t const cPages = pApic->cbApicPib >> PAGE_SHIFT;
1285 if (cPages == 1)
1286 {
1287 SUPPAGE SupApicPib;
1288 RT_ZERO(SupApicPib);
1289 SupApicPib.Phys = NIL_RTHCPHYS;
1290 int rc = SUPR3PageAllocEx(1 /* cPages */, 0 /* fFlags */, &pApic->pvApicPibR3, &pApic->pvApicPibR0, &SupApicPib);
1291 if (RT_SUCCESS(rc))
1292 {
1293 pApic->HCPhysApicPib = SupApicPib.Phys;
1294 AssertLogRelReturn(pApic->pvApicPibR3, VERR_INTERNAL_ERROR);
1295 }
1296 else
1297 {
1298 LogRel(("APIC: Failed to allocate %u bytes for the pending-interrupt bitmap, rc=%Rrc\n", pApic->cbApicPib, rc));
1299 return rc;
1300 }
1301 }
1302 else
1303 pApic->pvApicPibR3 = SUPR3ContAlloc(cPages, &pApic->pvApicPibR0, &pApic->HCPhysApicPib);
1304
1305 if (pApic->pvApicPibR3)
1306 {
1307 AssertLogRelReturn(pApic->pvApicPibR0 != NIL_RTR0PTR, VERR_INTERNAL_ERROR);
1308 AssertLogRelReturn(pApic->HCPhysApicPib != NIL_RTHCPHYS, VERR_INTERNAL_ERROR);
1309
1310 /* Initialize the PIB. */
1311 RT_BZERO(pApic->pvApicPibR3, pApic->cbApicPib);
1312
1313 /* Map the PIB into GC. */
1314 if (fNeedsGCMapping)
1315 {
1316 pApic->pvApicPibRC = NIL_RTRCPTR;
1317 int rc = MMR3HyperMapHCPhys(pVM, pApic->pvApicPibR3, NIL_RTR0PTR, pApic->HCPhysApicPib, pApic->cbApicPib,
1318 "APIC PIB", (PRTGCPTR)&pApic->pvApicPibRC);
1319 if (RT_FAILURE(rc))
1320 {
1321 LogRel(("APIC: Failed to map %u bytes for the pending-interrupt bitmap into GC, rc=%Rrc\n", pApic->cbApicPib,
1322 rc));
1323 apicR3TermState(pVM);
1324 return rc;
1325 }
1326
1327 AssertLogRelReturn(pApic->pvApicPibRC != NIL_RTRCPTR, VERR_INTERNAL_ERROR);
1328 }
1329
1330 /*
1331 * Allocate the map the virtual-APIC pages.
1332 */
1333 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
1334 {
1335 PVMCPU pVCpu = &pVM->aCpus[idCpu];
1336 PAPICCPU pApicCpu = VMCPU_TO_APICCPU(pVCpu);
1337
1338 SUPPAGE SupApicPage;
1339 RT_ZERO(SupApicPage);
1340 SupApicPage.Phys = NIL_RTHCPHYS;
1341
1342 Assert(pVCpu->idCpu == idCpu);
1343 Assert(pApicCpu->pvApicPageR3 == NIL_RTR3PTR);
1344 Assert(pApicCpu->pvApicPageR0 == NIL_RTR0PTR);
1345 Assert(pApicCpu->pvApicPageRC == NIL_RTRCPTR);
1346 AssertCompile(sizeof(XAPICPAGE) == PAGE_SIZE);
1347 pApicCpu->cbApicPage = sizeof(XAPICPAGE);
1348 int rc = SUPR3PageAllocEx(1 /* cPages */, 0 /* fFlags */, &pApicCpu->pvApicPageR3, &pApicCpu->pvApicPageR0,
1349 &SupApicPage);
1350 if (RT_SUCCESS(rc))
1351 {
1352 AssertLogRelReturn(pApicCpu->pvApicPageR3 != NIL_RTR3PTR, VERR_INTERNAL_ERROR);
1353 AssertLogRelReturn(pApicCpu->HCPhysApicPage != NIL_RTHCPHYS, VERR_INTERNAL_ERROR);
1354 pApicCpu->HCPhysApicPage = SupApicPage.Phys;
1355
1356 /* Map the virtual-APIC page into GC. */
1357 if (fNeedsGCMapping)
1358 {
1359 rc = MMR3HyperMapHCPhys(pVM, pApicCpu->pvApicPageR3, NIL_RTR0PTR, pApicCpu->HCPhysApicPage,
1360 pApicCpu->cbApicPage, "APIC", (PRTGCPTR)&pApicCpu->pvApicPageRC);
1361 if (RT_FAILURE(rc))
1362 {
1363 LogRel(("APIC%u: Failed to map %u bytes for the virtual-APIC page into GC, rc=%Rrc", idCpu,
1364 pApicCpu->cbApicPage, rc));
1365 apicR3TermState(pVM);
1366 return rc;
1367 }
1368
1369 AssertLogRelReturn(pApicCpu->pvApicPageRC != NIL_RTRCPTR, VERR_INTERNAL_ERROR);
1370 }
1371
1372 /* Associate the per-VCPU PIB pointers to the per-VM PIB mapping. */
1373 uint32_t const offApicPib = idCpu * sizeof(APICPIB);
1374 pApicCpu->pvApicPibR0 = (RTR0PTR)((RTR0UINTPTR)pApic->pvApicPibR0 + offApicPib);
1375 pApicCpu->pvApicPibR3 = (RTR3PTR)((RTR3UINTPTR)pApic->pvApicPibR3 + offApicPib);
1376 if (fNeedsGCMapping)
1377 pApicCpu->pvApicPibRC = (RTRCPTR)((RTRCUINTPTR)pApic->pvApicPibRC + offApicPib);
1378
1379 /* Initialize the virtual-APIC state. */
1380 RT_BZERO(pApicCpu->pvApicPageR3, pApicCpu->cbApicPage);
1381 apicResetCpu(pVCpu, true /* fResetApicBaseMsr */);
1382
1383#ifdef DEBUG_ramshankar
1384 Assert(pApicCpu->pvApicPibR3 != NIL_RTR3PTR);
1385 Assert(pApicCpu->pvApicPibR0 != NIL_RTR0PTR);
1386 Assert(!fNeedsGCMapping || pApicCpu->pvApicPibRC != NIL_RTRCPTR);
1387 Assert(pApicCpu->pvApicPageR3 != NIL_RTR3PTR);
1388 Assert(pApicCpu->pvApicPageR0 != NIL_RTR0PTR);
1389 Assert(!fNeedsGCMapping || pApicCpu->pvApicPageRC != NIL_RTRCPTR);
1390 Assert(!fNeedsGCMapping || pApic->pvApicPibRC == pVM->aCpus[0].apic.s.pvApicPibRC);
1391#endif
1392 }
1393 else
1394 {
1395 LogRel(("APIC%u: Failed to allocate %u bytes for the virtual-APIC page, rc=%Rrc\n", idCpu, pApicCpu->cbApicPage, rc));
1396 apicR3TermState(pVM);
1397 return rc;
1398 }
1399 }
1400
1401#ifdef DEBUG_ramshankar
1402 Assert(pApic->pvApicPibR3 != NIL_RTR3PTR);
1403 Assert(pApic->pvApicPibR0 != NIL_RTR0PTR);
1404 Assert(!fNeedsGCMapping || pApic->pvApicPibRC != NIL_RTRCPTR);
1405#endif
1406 return VINF_SUCCESS;
1407 }
1408
1409 LogRel(("APIC: Failed to allocate %u bytes of physically contiguous memory for the pending-interrupt bitmap\n",
1410 pApic->cbApicPib));
1411 return VERR_NO_MEMORY;
1412}
1413
1414
1415/**
1416 * @interface_method_impl{PDMDEVREG,pfnDestruct}
1417 */
1418static DECLCALLBACK(int) apicR3Destruct(PPDMDEVINS pDevIns)
1419{
1420 PVM pVM = PDMDevHlpGetVM(pDevIns);
1421 LogFlow(("APIC: apicR3Destruct: pVM=%p\n", pVM));
1422
1423 apicR3TermState(pVM);
1424 return VINF_SUCCESS;
1425}
1426
1427
1428/**
1429 * @interface_method_impl{PDMDEVREG,pfnInitComplete}
1430 */
1431static DECLCALLBACK(int) apicR3InitComplete(PPDMDEVINS pDevIns)
1432{
1433 PVM pVM = PDMDevHlpGetVM(pDevIns);
1434 PAPIC pApic = VM_TO_APIC(pVM);
1435
1436 /*
1437 * Init APIC settings that rely on HM and CPUM configurations.
1438 */
1439 CPUMCPUIDLEAF CpuLeaf;
1440 int rc = CPUMR3CpuIdGetLeaf(pVM, &CpuLeaf, 1, 0);
1441 AssertRCReturn(rc, rc);
1442
1443 pApic->fSupportsTscDeadline = RT_BOOL(CpuLeaf.uEcx & X86_CPUID_FEATURE_ECX_TSCDEADL);
1444 pApic->fPostedIntrsEnabled = HMR3IsPostedIntrsEnabled(pVM->pUVM);
1445 pApic->fVirtApicRegsEnabled = HMR3IsVirtApicRegsEnabled(pVM->pUVM);
1446
1447 LogRel(("APIC: fPostedIntrsEnabled=%RTbool fVirtApicRegsEnabled=%RTbool fSupportsTscDeadline=%RTbool\n",
1448 pApic->fPostedIntrsEnabled, pApic->fVirtApicRegsEnabled, pApic->fSupportsTscDeadline));
1449
1450 return VINF_SUCCESS;
1451}
1452
1453
1454/**
1455 * @interface_method_impl{PDMDEVREG,pfnConstruct}
1456 */
1457static DECLCALLBACK(int) apicR3Construct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
1458{
1459 /*
1460 * Validate inputs.
1461 */
1462 Assert(iInstance == 0); NOREF(iInstance);
1463 Assert(pDevIns);
1464
1465 PAPICDEV pApicDev = PDMINS_2_DATA(pDevIns, PAPICDEV);
1466 PVM pVM = PDMDevHlpGetVM(pDevIns);
1467 PAPIC pApic = VM_TO_APIC(pVM);
1468
1469 /*
1470 * Init the data.
1471 */
1472 pApicDev->pDevInsR3 = pDevIns;
1473 pApicDev->pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns);
1474 pApicDev->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
1475
1476 pApic->pApicDevR0 = PDMINS_2_DATA_R0PTR(pDevIns);
1477 pApic->pApicDevR3 = (PAPICDEV)PDMINS_2_DATA_R3PTR(pDevIns);
1478 pApic->pApicDevRC = PDMINS_2_DATA_RCPTR(pDevIns);
1479
1480 /*
1481 * Validate APIC settings.
1482 */
1483 if (!CFGMR3AreValuesValid(pCfg, "RZEnabled\0"
1484 "Mode\0"
1485 "IOAPIC\0"
1486 "NumCPUs\0"))
1487 {
1488 return PDMDEV_SET_ERROR(pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES,
1489 N_("APIC configuration error: unknown option specified"));
1490 }
1491
1492 int rc = CFGMR3QueryBoolDef(pCfg, "RZEnabled", &pApic->fRZEnabled, true);
1493 AssertLogRelRCReturn(rc, rc);
1494
1495 rc = CFGMR3QueryBoolDef(pCfg, "IOAPIC", &pApic->fIoApicPresent, true);
1496 AssertLogRelRCReturn(rc, rc);
1497
1498 /* Max APIC feature level. */
1499 uint8_t uMaxMode;
1500 rc = CFGMR3QueryU8Def(pCfg, "Mode", &uMaxMode, PDMAPICMODE_APIC);
1501 AssertLogRelRCReturn(rc, rc);
1502 switch ((PDMAPICMODE)uMaxMode)
1503 {
1504 case PDMAPICMODE_NONE:
1505 LogRel(("APIC: APIC maximum mode configured as 'None', effectively disabled/not-present!\n"));
1506 case PDMAPICMODE_APIC:
1507 case PDMAPICMODE_X2APIC:
1508 break;
1509 default:
1510 return VMR3SetError(pVM->pUVM, VERR_INVALID_PARAMETER, RT_SRC_POS, "APIC mode %d unknown.", uMaxMode);
1511 }
1512 pApic->enmMaxMode = (PDMAPICMODE)uMaxMode;
1513
1514 /*
1515 * Disable automatic PDM locking for this device.
1516 */
1517 rc = PDMDevHlpSetDeviceCritSect(pDevIns, PDMDevHlpCritSectGetNop(pDevIns));
1518 AssertRCReturn(rc, rc);
1519
1520 /*
1521 * Register the APIC with PDM.
1522 */
1523 rc = PDMDevHlpAPICRegister(pDevIns);
1524 AssertLogRelRCReturn(rc, rc);
1525
1526 /*
1527 * Initialize the APIC state.
1528 */
1529 if (pApic->enmMaxMode == PDMAPICMODE_X2APIC)
1530 {
1531 rc = CPUMR3MsrRangesInsert(pVM, &g_MsrRange_x2Apic);
1532 AssertLogRelRCReturn(rc, rc);
1533 }
1534 else
1535 {
1536 /* We currently don't have a function to remove the range, so we register an range which will cause a #GP. */
1537 rc = CPUMR3MsrRangesInsert(pVM, &g_MsrRange_x2Apic_Invalid);
1538 AssertLogRelRCReturn(rc, rc);
1539 }
1540
1541 /* Tell CPUM about the APIC feature level so it can adjust APICBASE MSR GP mask and CPUID bits. */
1542 apicR3SetCpuIdFeatureLevel(pVM, pApic->enmMaxMode);
1543 /* Finally, initialize the state. */
1544 rc = apicR3InitState(pVM);
1545 AssertRCReturn(rc, rc);
1546
1547 /*
1548 * Register the MMIO range.
1549 */
1550 PAPICCPU pApicCpu0 = VMCPU_TO_APICCPU(&pVM->aCpus[0]);
1551 RTGCPHYS GCPhysApicBase = MSR_IA32_APICBASE_GET_ADDR(pApicCpu0->uApicBaseMsr);
1552
1553 rc = PDMDevHlpMMIORegister(pDevIns, GCPhysApicBase, sizeof(XAPICPAGE), NULL /* pvUser */,
1554 IOMMMIO_FLAGS_READ_DWORD | IOMMMIO_FLAGS_WRITE_DWORD_ZEROED,
1555 apicWriteMmio, apicReadMmio, "APIC");
1556 if (RT_FAILURE(rc))
1557 return rc;
1558
1559 if (pApic->fRZEnabled)
1560 {
1561 rc = PDMDevHlpMMIORegisterRC(pDevIns, GCPhysApicBase, sizeof(XAPICPAGE), NIL_RTRCPTR /*pvUser*/,
1562 "apicWriteMmio", "apicReadMmio");
1563 if (RT_FAILURE(rc))
1564 return rc;
1565
1566 rc = PDMDevHlpMMIORegisterR0(pDevIns, GCPhysApicBase, sizeof(XAPICPAGE), NIL_RTR0PTR /*pvUser*/,
1567 "apicWriteMmio", "apicReadMmio");
1568 if (RT_FAILURE(rc))
1569 return rc;
1570 }
1571
1572 /*
1573 * Create the APIC timers.
1574 */
1575 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
1576 {
1577 PVMCPU pVCpu = &pVM->aCpus[idCpu];
1578 PAPICCPU pApicCpu = VMCPU_TO_APICCPU(pVCpu);
1579 RTStrPrintf(&pApicCpu->szTimerDesc[0], sizeof(pApicCpu->szTimerDesc), "APIC Timer %u", pVCpu->idCpu);
1580 rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL_SYNC, apicR3TimerCallback, pVCpu, TMTIMER_FLAGS_NO_CRIT_SECT,
1581 pApicCpu->szTimerDesc, &pApicCpu->pTimerR3);
1582 if (RT_SUCCESS(rc))
1583 {
1584 pApicCpu->pTimerR0 = TMTimerR0Ptr(pApicCpu->pTimerR3);
1585 pApicCpu->pTimerRC = TMTimerRCPtr(pApicCpu->pTimerR3);
1586 }
1587 else
1588 return rc;
1589 }
1590
1591 /*
1592 * Register saved state callbacks.
1593 */
1594 rc = PDMDevHlpSSMRegister3(pDevIns, APIC_SAVED_STATE_VERSION, sizeof(*pApicDev), NULL /*pfnLiveExec*/, apicR3SaveExec,
1595 apicR3LoadExec);
1596 if (RT_FAILURE(rc))
1597 return rc;
1598
1599 /*
1600 * Register debugger info callbacks.
1601 *
1602 * We use separate callbacks rather than arguments so they can also be
1603 * dumped in an automated fashion while collecting crash diagnostics and
1604 * not just used during live debugging via the VM debugger.
1605 */
1606 rc = DBGFR3InfoRegisterInternalEx(pVM, "apic", "Dumps APIC basic information.", apicR3Info, DBGFINFO_FLAGS_ALL_EMTS);
1607 rc |= DBGFR3InfoRegisterInternalEx(pVM, "apiclvt", "Dumps APIC LVT information.", apicR3InfoLvt, DBGFINFO_FLAGS_ALL_EMTS);
1608 rc |= DBGFR3InfoRegisterInternalEx(pVM, "apictimer", "Dumps APIC timer information.", apicR3InfoTimer, DBGFINFO_FLAGS_ALL_EMTS);
1609 AssertRCReturn(rc, rc);
1610
1611#ifdef VBOX_WITH_STATISTICS
1612 /*
1613 * Statistics.
1614 */
1615#define APIC_REG_COUNTER(a_Reg, a_Desc, a_Key) \
1616 do { \
1617 rc = STAMR3RegisterF(pVM, a_Reg, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, a_Desc, a_Key, idCpu); \
1618 AssertRCReturn(rc, rc); \
1619 } while(0)
1620
1621#define APIC_PROF_COUNTER(a_Reg, a_Desc, a_Key) \
1622 do { \
1623 rc = STAMR3RegisterF(pVM, a_Reg, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, a_Desc, a_Key, \
1624 idCpu); \
1625 AssertRCReturn(rc, rc); \
1626 } while(0)
1627
1628 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
1629 {
1630 PVMCPU pVCpu = &pVM->aCpus[idCpu];
1631 PAPICCPU pApicCpu = VMCPU_TO_APICCPU(pVCpu);
1632
1633 APIC_REG_COUNTER(&pApicCpu->StatMmioReadRZ, "Number of APIC MMIO reads in RZ.", "/Devices/APIC/%u/RZ/MmioRead");
1634 APIC_REG_COUNTER(&pApicCpu->StatMmioWriteRZ, "Number of APIC MMIO writes in RZ.", "/Devices/APIC/%u/RZ/MmioWrite");
1635 APIC_REG_COUNTER(&pApicCpu->StatMsrReadRZ, "Number of APIC MSR reads in RZ.", "/Devices/APIC/%u/RZ/MsrRead");
1636 APIC_REG_COUNTER(&pApicCpu->StatMsrWriteRZ, "Number of APIC MSR writes in RZ.", "/Devices/APIC/%u/RZ/MsrWrite");
1637
1638 APIC_REG_COUNTER(&pApicCpu->StatMmioReadR3, "Number of APIC MMIO reads in R3.", "/Devices/APIC/%u/R3/MmioReadR3");
1639 APIC_REG_COUNTER(&pApicCpu->StatMmioWriteR3, "Number of APIC MMIO writes in R3.", "/Devices/APIC/%u/R3/MmioWriteR3");
1640 APIC_REG_COUNTER(&pApicCpu->StatMsrReadR3, "Number of APIC MSR reads in R3.", "/Devices/APIC/%u/R3/MsrReadR3");
1641 APIC_REG_COUNTER(&pApicCpu->StatMsrWriteR3, "Number of APIC MSR writes in R3.", "/Devices/APIC/%u/R3/MsrWriteR3");
1642
1643 APIC_PROF_COUNTER(&pApicCpu->StatUpdatePendingIntrs, "Profiling of APICUpdatePendingInterrupts",
1644 "/PROF/CPU%d/APIC/UpdatePendingInterrupts");
1645 APIC_PROF_COUNTER(&pApicCpu->StatPostIntr, "Profiling of APICPostInterrupt", "/PROF/CPU%d/APIC/PostInterrupt");
1646
1647 APIC_REG_COUNTER(&pApicCpu->StatPostIntrAlreadyPending, "Number of times an interrupt is already pending.",
1648 "/Devices/APIC/%u/PostInterruptAlreadyPending");
1649 APIC_REG_COUNTER(&pApicCpu->StatTimerCallback, "Number of times the timer callback is invoked.",
1650 "/Devices/APIC/%u/TimerCallback");
1651
1652 APIC_REG_COUNTER(&pApicCpu->StatTprWrite, "Number of TPR writes.", "/Devices/APIC/%u/TprWrite");
1653 APIC_REG_COUNTER(&pApicCpu->StatTprRead, "Number of TPR reads.", "/Devices/APIC/%u/TprRead");
1654 APIC_REG_COUNTER(&pApicCpu->StatEoiWrite, "Number of EOI writes.", "/Devices/APIC/%u/EoiWrite");
1655 APIC_REG_COUNTER(&pApicCpu->StatMaskedByTpr, "Number of times TPR masks an interrupt in apicGetInterrupt.",
1656 "/Devices/APIC/%u/MaskedByTpr");
1657 APIC_REG_COUNTER(&pApicCpu->StatMaskedByPpr, "Number of times PPR masks an interrupt in apicGetInterrupt.",
1658 "/Devices/APIC/%u/MaskedByPpr");
1659 APIC_REG_COUNTER(&pApicCpu->StatTimerIcrWrite, "Number of times the timer ICR is written.",
1660 "/Devices/APIC/%u/TimerIcrWrite");
1661 APIC_REG_COUNTER(&pApicCpu->StatIcrLoWrite, "Number of times the ICR Lo (send IPI) is written.",
1662 "/Devices/APIC/%u/IcrLoWrite");
1663 APIC_REG_COUNTER(&pApicCpu->StatIcrHiWrite, "Number of times the ICR Hi is written.",
1664 "/Devices/APIC/%u/IcrHiWrite");
1665 APIC_REG_COUNTER(&pApicCpu->StatIcrFullWrite, "Number of times the ICR full (send IPI, x2APIC) is written.",
1666 "/Devices/APIC/%u/IcrFullWrite");
1667 }
1668# undef APIC_PROF_COUNTER
1669# undef APIC_REG_ACCESS_COUNTER
1670#endif
1671
1672 return VINF_SUCCESS;
1673}
1674
1675
1676/**
1677 * APIC device registration structure.
1678 */
1679static const PDMDEVREG g_DeviceAPIC =
1680{
1681 /* u32Version */
1682 PDM_DEVREG_VERSION,
1683 /* szName */
1684 "apic",
1685 /* szRCMod */
1686 "VMMRC.rc",
1687 /* szR0Mod */
1688 "VMMR0.r0",
1689 /* pszDescription */
1690 "Advanced Programmable Interrupt Controller",
1691 /* fFlags */
1692 PDM_DEVREG_FLAGS_HOST_BITS_DEFAULT | PDM_DEVREG_FLAGS_GUEST_BITS_32_64 | PDM_DEVREG_FLAGS_PAE36
1693 | PDM_DEVREG_FLAGS_RC | PDM_DEVREG_FLAGS_R0,
1694 /* fClass */
1695 PDM_DEVREG_CLASS_PIC,
1696 /* cMaxInstances */
1697 1,
1698 /* cbInstance */
1699 sizeof(APICDEV),
1700 /* pfnConstruct */
1701 apicR3Construct,
1702 /* pfnDestruct */
1703 apicR3Destruct,
1704 /* pfnRelocate */
1705 apicR3Relocate,
1706 /* pfnMemSetup */
1707 NULL,
1708 /* pfnPowerOn */
1709 NULL,
1710 /* pfnReset */
1711 apicR3Reset,
1712 /* pfnSuspend */
1713 NULL,
1714 /* pfnResume */
1715 NULL,
1716 /* pfnAttach */
1717 NULL,
1718 /* pfnDetach */
1719 NULL,
1720 /* pfnQueryInterface. */
1721 NULL,
1722 /* pfnInitComplete */
1723 apicR3InitComplete,
1724 /* pfnPowerOff */
1725 NULL,
1726 /* pfnSoftReset */
1727 NULL,
1728 /* u32VersionEnd */
1729 PDM_DEVREG_VERSION
1730};
1731
1732
1733/**
1734 * Called by PDM to register the APIC device.
1735 */
1736VMMR3_INT_DECL(int) APICR3RegisterDevice(PPDMDEVREGCB pCallbacks)
1737{
1738 return pCallbacks->pfnRegister(pCallbacks, &g_DeviceAPIC);
1739}
1740
1741#endif /* !VBOX_DEVICE_STRUCT_TESTCASE */
1742
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