VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMR3/GIM.cpp@ 62354

Last change on this file since 62354 was 62354, checked in by vboxsync, 8 years ago

VMM/GIM/HyperV: SynIC: APIC-assist page bits.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 22.2 KB
Line 
1/* $Id: GIM.cpp 62354 2016-07-20 12:19:28Z vboxsync $ */
2/** @file
3 * GIM - Guest Interface Manager.
4 */
5
6/*
7 * Copyright (C) 2014-2015 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/** @page pg_gim GIM - The Guest Interface Manager
19 *
20 * The Guest Interface Manager abstracts an interface provider through which
21 * guests may interact with the hypervisor.
22 *
23 * @see grp_gim
24 *
25 *
26 * @section sec_gim_provider Providers
27 *
28 * A GIM provider implements a particular hypervisor interface such as Microsoft
29 * Hyper-V, Linux KVM and so on. It hooks into various components in the VMM to
30 * ease the guest in running under a recognized, virtualized environment.
31 *
32 * The GIM provider configured for the VM needs to be recognized by the guest OS
33 * in order to make use of features supported by the interface. Since it
34 * requires co-operation from the guest OS, a GIM provider may also referred to
35 * as a paravirtualization interface.
36 *
37 * One of the goals of having a paravirtualized interface is for enabling guests
38 * to be more accurate and efficient when operating in a virtualized
39 * environment. For instance, a guest OS which interfaces to VirtualBox through
40 * a GIM provider may rely on the provider for supplying the correct TSC
41 * frequency of the host processor. The guest can then avoid caliberating the
42 * TSC itself, resulting in higher accuracy and better performance.
43 *
44 * At most, only one GIM provider can be active for a running VM and cannot be
45 * changed during the lifetime of the VM.
46 */
47
48
49/*********************************************************************************************************************************
50* Header Files *
51*********************************************************************************************************************************/
52#define LOG_GROUP LOG_GROUP_GIM
53#include <VBox/vmm/gim.h>
54#include <VBox/vmm/hm.h>
55#include <VBox/vmm/ssm.h>
56#include <VBox/vmm/pdmdev.h>
57#include "GIMInternal.h"
58#include <VBox/vmm/vm.h>
59
60#include <VBox/log.h>
61
62#include <iprt/err.h>
63#include <iprt/semaphore.h>
64#include <iprt/string.h>
65
66/* Include all GIM providers. */
67#include "GIMMinimalInternal.h"
68#include "GIMHvInternal.h"
69#include "GIMKvmInternal.h"
70
71
72/*********************************************************************************************************************************
73* Internal Functions *
74*********************************************************************************************************************************/
75static FNSSMINTSAVEEXEC gimR3Save;
76static FNSSMINTLOADEXEC gimR3Load;
77static FNPGMPHYSHANDLER gimR3Mmio2WriteHandler;
78
79
80/**
81 * Initializes the GIM.
82 *
83 * @returns VBox status code.
84 * @param pVM The cross context VM structure.
85 */
86VMMR3_INT_DECL(int) GIMR3Init(PVM pVM)
87{
88 LogFlow(("GIMR3Init\n"));
89
90 /*
91 * Assert alignment and sizes.
92 */
93 AssertCompile(sizeof(pVM->gim.s) <= sizeof(pVM->gim.padding));
94 AssertCompile(sizeof(pVM->aCpus[0].gim.s) <= sizeof(pVM->aCpus[0].gim.padding));
95
96 /*
97 * Initialize members.
98 */
99 pVM->gim.s.hSemiReadOnlyMmio2Handler = NIL_PGMPHYSHANDLERTYPE;
100
101 /*
102 * Register the saved state data unit.
103 */
104 int rc = SSMR3RegisterInternal(pVM, "GIM", 0 /* uInstance */, GIM_SAVED_STATE_VERSION, sizeof(GIM),
105 NULL /* pfnLivePrep */, NULL /* pfnLiveExec */, NULL /* pfnLiveVote*/,
106 NULL /* pfnSavePrep */, gimR3Save, NULL /* pfnSaveDone */,
107 NULL /* pfnLoadPrep */, gimR3Load, NULL /* pfnLoadDone */);
108 if (RT_FAILURE(rc))
109 return rc;
110
111 /*
112 * Read configuration.
113 */
114 PCFGMNODE pCfgNode = CFGMR3GetChild(CFGMR3GetRoot(pVM), "GIM/");
115
116 /*
117 * Validate the GIM settings.
118 */
119 rc = CFGMR3ValidateConfig(pCfgNode, "/GIM/", /* pszNode */
120 "Provider" /* pszValidValues */
121 "|Version",
122 "HyperV", /* pszValidNodes */
123 "GIM", /* pszWho */
124 0); /* uInstance */
125 if (RT_FAILURE(rc))
126 return rc;
127
128 /** @cfgm{/GIM/Provider, string}
129 * The name of the GIM provider. The default is "none". */
130 char szProvider[64];
131 rc = CFGMR3QueryStringDef(pCfgNode, "Provider", szProvider, sizeof(szProvider), "None");
132 AssertLogRelRCReturn(rc, rc);
133
134 /** @cfgm{/GIM/Version, uint32_t}
135 * The interface version. The default is 0, which means "provide the most
136 * up-to-date implementation". */
137 uint32_t uVersion;
138 rc = CFGMR3QueryU32Def(pCfgNode, "Version", &uVersion, 0 /* default */);
139 AssertLogRelRCReturn(rc, rc);
140
141 /*
142 * Setup the GIM provider for this VM.
143 */
144 LogRel(("GIM: Using provider '%s' (Implementation version: %u)\n", szProvider, uVersion));
145 if (!RTStrCmp(szProvider, "None"))
146 pVM->gim.s.enmProviderId = GIMPROVIDERID_NONE;
147 else
148 {
149 pVM->gim.s.u32Version = uVersion;
150 /** @todo r=bird: Because u32Version is saved, it should be translated to the
151 * 'most up-to-date implementation' version number when 0. Otherwise,
152 * we'll have abiguities when loading the state of older VMs. */
153 if (!RTStrCmp(szProvider, "Minimal"))
154 {
155 pVM->gim.s.enmProviderId = GIMPROVIDERID_MINIMAL;
156 rc = gimR3MinimalInit(pVM);
157 }
158 else if (!RTStrCmp(szProvider, "HyperV"))
159 {
160 pVM->gim.s.enmProviderId = GIMPROVIDERID_HYPERV;
161 rc = gimR3HvInit(pVM, pCfgNode);
162 }
163 else if (!RTStrCmp(szProvider, "KVM"))
164 {
165 pVM->gim.s.enmProviderId = GIMPROVIDERID_KVM;
166 rc = gimR3KvmInit(pVM);
167 }
168 else
169 rc = VMR3SetError(pVM->pUVM, VERR_GIM_INVALID_PROVIDER, RT_SRC_POS, "Provider '%s' unknown.", szProvider);
170 }
171
172 /*
173 * Statistics.
174 */
175 STAM_REL_REG_USED(pVM, &pVM->gim.s.StatDbgXmit, STAMTYPE_COUNTER, "/GIM/Debug/Transmit", STAMUNIT_OCCURENCES, "Debug packets sent.");
176 STAM_REL_REG_USED(pVM, &pVM->gim.s.StatDbgXmitBytes, STAMTYPE_COUNTER, "/GIM/Debug/TransmitBytes", STAMUNIT_OCCURENCES, "Debug bytes sent.");
177 STAM_REL_REG_USED(pVM, &pVM->gim.s.StatDbgRecv, STAMTYPE_COUNTER, "/GIM/Debug/Receive", STAMUNIT_OCCURENCES, "Debug packets received.");
178 STAM_REL_REG_USED(pVM, &pVM->gim.s.StatDbgRecvBytes, STAMTYPE_COUNTER, "/GIM/Debug/ReceiveBytes", STAMUNIT_OCCURENCES, "Debug bytes received.");
179
180 STAM_REL_REG_USED(pVM, &pVM->gim.s.StatHypercalls, STAMTYPE_COUNTER, "/GIM/Hypercalls", STAMUNIT_OCCURENCES, "Number of hypercalls initiated.");
181 return rc;
182}
183
184
185/**
186 * Initializes the remaining bits of the GIM provider.
187 *
188 * This is called after initializing HM and most other VMM components.
189 *
190 * @returns VBox status code.
191 * @param pVM The cross context VM structure.
192 * @thread EMT(0)
193 */
194VMMR3_INT_DECL(int) GIMR3InitCompleted(PVM pVM)
195{
196 switch (pVM->gim.s.enmProviderId)
197 {
198 case GIMPROVIDERID_MINIMAL:
199 return gimR3MinimalInitCompleted(pVM);
200
201 case GIMPROVIDERID_HYPERV:
202 return gimR3HvInitCompleted(pVM);
203
204 case GIMPROVIDERID_KVM:
205 return gimR3KvmInitCompleted(pVM);
206
207 default:
208 break;
209 }
210
211 if (!TMR3CpuTickIsFixedRateMonotonic(pVM, true /* fWithParavirtEnabled */))
212 LogRel(("GIM: Warning!!! Host TSC is unstable. The guest may behave unpredictably with a paravirtualized clock.\n"));
213
214 return VINF_SUCCESS;
215}
216
217
218/**
219 * @callback_method_impl{FNSSMINTSAVEEXEC}
220 */
221static DECLCALLBACK(int) gimR3Save(PVM pVM, PSSMHANDLE pSSM)
222{
223 AssertReturn(pVM, VERR_INVALID_PARAMETER);
224 AssertReturn(pSSM, VERR_SSM_INVALID_STATE);
225
226 /** @todo Save per-CPU data. */
227 int rc = VINF_SUCCESS;
228#if 0
229 SSMR3PutU32(pSSM, pVM->cCpus);
230 for (VMCPUID i = 0; i < pVM->cCpus; i++)
231 {
232 rc = SSMR3PutXYZ(pSSM, pVM->aCpus[i].gim.s.XYZ);
233 }
234#endif
235
236 /*
237 * Save per-VM data.
238 */
239 SSMR3PutU32(pSSM, pVM->gim.s.enmProviderId);
240 SSMR3PutU32(pSSM, pVM->gim.s.u32Version);
241
242 /*
243 * Save provider-specific data.
244 */
245 switch (pVM->gim.s.enmProviderId)
246 {
247 case GIMPROVIDERID_HYPERV:
248 rc = gimR3HvSave(pVM, pSSM);
249 AssertRCReturn(rc, rc);
250 break;
251
252 case GIMPROVIDERID_KVM:
253 rc = gimR3KvmSave(pVM, pSSM);
254 AssertRCReturn(rc, rc);
255 break;
256
257 default:
258 break;
259 }
260
261 return rc;
262}
263
264
265/**
266 * @callback_method_impl{FNSSMINTLOADEXEC}
267 */
268static DECLCALLBACK(int) gimR3Load(PVM pVM, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
269{
270 if (uPass != SSM_PASS_FINAL)
271 return VINF_SUCCESS;
272 if (uVersion != GIM_SAVED_STATE_VERSION)
273 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
274
275 /** @todo Load per-CPU data. */
276 int rc;
277#if 0
278 for (VMCPUID i = 0; i < pVM->cCpus; i++)
279 {
280 rc = SSMR3PutXYZ(pSSM, pVM->aCpus[i].gim.s.XYZ);
281 }
282#endif
283
284 /*
285 * Load per-VM data.
286 */
287 uint32_t uProviderId;
288 uint32_t uProviderVersion;
289
290 rc = SSMR3GetU32(pSSM, &uProviderId); AssertRCReturn(rc, rc);
291 rc = SSMR3GetU32(pSSM, &uProviderVersion); AssertRCReturn(rc, rc);
292
293 if ((GIMPROVIDERID)uProviderId != pVM->gim.s.enmProviderId)
294 return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Saved GIM provider %u differs from the configured one (%u)."),
295 uProviderId, pVM->gim.s.enmProviderId);
296#if 0 /** @todo r=bird: Figure out what you mean to do here with the version. */
297 if (uProviderVersion != pVM->gim.s.u32Version)
298 return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Saved GIM provider version %u differs from the configured one (%u)."),
299 uProviderVersion, pVM->gim.s.u32Version);
300#else
301 pVM->gim.s.u32Version = uProviderVersion;
302#endif
303
304 /*
305 * Load provider-specific data.
306 */
307 switch (pVM->gim.s.enmProviderId)
308 {
309 case GIMPROVIDERID_HYPERV:
310 rc = gimR3HvLoad(pVM, pSSM, uVersion);
311 AssertRCReturn(rc, rc);
312 break;
313
314 case GIMPROVIDERID_KVM:
315 rc = gimR3KvmLoad(pVM, pSSM, uVersion);
316 AssertRCReturn(rc, rc);
317 break;
318
319 default:
320 break;
321 }
322
323 return VINF_SUCCESS;
324}
325
326
327/**
328 * Terminates the GIM.
329 *
330 * Termination means cleaning up and freeing all resources,
331 * the VM itself is, at this point, powered off or suspended.
332 *
333 * @returns VBox status code.
334 * @param pVM The cross context VM structure.
335 */
336VMMR3_INT_DECL(int) GIMR3Term(PVM pVM)
337{
338 switch (pVM->gim.s.enmProviderId)
339 {
340 case GIMPROVIDERID_HYPERV:
341 return gimR3HvTerm(pVM);
342
343 case GIMPROVIDERID_KVM:
344 return gimR3KvmTerm(pVM);
345
346 default:
347 break;
348 }
349 return VINF_SUCCESS;
350}
351
352
353/**
354 * The VM is being reset.
355 *
356 * For the GIM component this means unmapping and unregistering MMIO2 regions
357 * and other provider-specific resets.
358 *
359 * @returns VBox status code.
360 * @param pVM The cross context VM structure.
361 */
362VMMR3_INT_DECL(void) GIMR3Reset(PVM pVM)
363{
364 switch (pVM->gim.s.enmProviderId)
365 {
366 case GIMPROVIDERID_HYPERV:
367 return gimR3HvReset(pVM);
368
369 case GIMPROVIDERID_KVM:
370 return gimR3KvmReset(pVM);
371
372 default:
373 break;
374 }
375}
376
377
378/**
379 * Registers the GIM device with VMM.
380 *
381 * @param pVM The cross context VM structure.
382 * @param pDevIns Pointer to the GIM device instance.
383 * @param pDbg Pointer to the GIM device debug structure, can be
384 * NULL.
385 */
386VMMR3DECL(void) GIMR3GimDeviceRegister(PVM pVM, PPDMDEVINS pDevIns, PGIMDEBUG pDbg)
387{
388 pVM->gim.s.pDevInsR3 = pDevIns;
389 pVM->gim.s.pDbgR3 = pDbg;
390}
391
392
393/**
394 * Gets debug setup specified by the provider.
395 *
396 * @returns VBox status code.
397 * @param pVM The cross context VM structure.
398 * @param pDbgSetup Where to store the debug setup details.
399 */
400VMMR3DECL(int) GIMR3GetDebugSetup(PVM pVM, PGIMDEBUGSETUP pDbgSetup)
401{
402 AssertReturn(pVM, VERR_INVALID_PARAMETER);
403 AssertReturn(pDbgSetup, VERR_INVALID_PARAMETER);
404
405 switch (pVM->gim.s.enmProviderId)
406 {
407 case GIMPROVIDERID_HYPERV:
408 return gimR3HvGetDebugSetup(pVM, pDbgSetup);
409 default:
410 break;
411 }
412 return VERR_GIM_NO_DEBUG_CONNECTION;
413}
414
415
416/**
417 * Read data from a host debug session.
418 *
419 * @returns VBox status code.
420 *
421 * @param pVM The cross context VM structure.
422 * @param pvRead The read buffer.
423 * @param pcbRead The size of the read buffer as well as where to store
424 * the number of bytes read.
425 * @param pfnReadComplete Callback when the buffer has been read and
426 * before signaling reading of the next buffer.
427 * Optional, can be NULL.
428 * @thread EMT.
429 */
430VMMR3_INT_DECL(int) gimR3DebugRead(PVM pVM, void *pvRead, size_t *pcbRead, PFNGIMDEBUGBUFREADCOMPLETED pfnReadComplete)
431{
432 PGIMDEBUG pDbg = pVM->gim.s.pDbgR3;
433 if (pDbg)
434 {
435 if (ASMAtomicReadBool(&pDbg->fDbgRecvBufRead) == true)
436 {
437 STAM_REL_COUNTER_INC(&pVM->gim.s.StatDbgRecv);
438 STAM_REL_COUNTER_ADD(&pVM->gim.s.StatDbgRecvBytes, pDbg->cbDbgRecvBufRead);
439
440 memcpy(pvRead, pDbg->pvDbgRecvBuf, pDbg->cbDbgRecvBufRead);
441 *pcbRead = pDbg->cbDbgRecvBufRead;
442 if (pfnReadComplete)
443 pfnReadComplete(pVM);
444 RTSemEventMultiSignal(pDbg->hDbgRecvThreadSem);
445 ASMAtomicWriteBool(&pDbg->fDbgRecvBufRead, false);
446 return VINF_SUCCESS;
447 }
448 else
449 *pcbRead = 0;
450 return VERR_NO_DATA;
451 }
452 return VERR_GIM_NO_DEBUG_CONNECTION;
453}
454
455
456/**
457 * Write data to a host debug session.
458 *
459 * @returns VBox status code.
460 *
461 * @param pVM The cross context VM structure.
462 * @param pvWrite The write buffer.
463 * @param pcbWrite The size of the write buffer as well as where to store
464 * the number of bytes written.
465 * @thread EMT.
466 */
467VMMR3_INT_DECL(int) gimR3DebugWrite(PVM pVM, void *pvWrite, size_t *pcbWrite)
468{
469 PGIMDEBUG pDbg = pVM->gim.s.pDbgR3;
470 if (pDbg)
471 {
472 PPDMISTREAM pDbgStream = pDbg->pDbgDrvStream;
473 if (pDbgStream)
474 {
475 size_t cbWrite = *pcbWrite;
476 int rc = pDbgStream->pfnWrite(pDbgStream, pvWrite, pcbWrite);
477 if ( RT_SUCCESS(rc)
478 && *pcbWrite == cbWrite)
479 {
480 STAM_REL_COUNTER_INC(&pVM->gim.s.StatDbgXmit);
481 STAM_REL_COUNTER_ADD(&pVM->gim.s.StatDbgXmitBytes, *pcbWrite);
482 }
483 return rc;
484 }
485 }
486 return VERR_GIM_NO_DEBUG_CONNECTION;
487}
488
489
490/**
491 * Returns the array of MMIO2 regions that are expected to be registered and
492 * later mapped into the guest-physical address space for the GIM provider
493 * configured for the VM.
494 *
495 * @returns Pointer to an array of GIM MMIO2 regions, may return NULL.
496 * @param pVM The cross context VM structure.
497 * @param pcRegions Where to store the number of items in the array.
498 *
499 * @remarks The caller does not own and therefore must -NOT- try to free the
500 * returned pointer.
501 */
502VMMR3DECL(PGIMMMIO2REGION) GIMR3GetMmio2Regions(PVM pVM, uint32_t *pcRegions)
503{
504 Assert(pVM);
505 Assert(pcRegions);
506
507 *pcRegions = 0;
508 switch (pVM->gim.s.enmProviderId)
509 {
510 case GIMPROVIDERID_HYPERV:
511 return gimR3HvGetMmio2Regions(pVM, pcRegions);
512
513 default:
514 break;
515 }
516
517 return NULL;
518}
519
520
521/**
522 * @callback_method_impl{FNPGMPHYSHANDLER,
523 * Write access handler for mapped MMIO2 pages. Currently ignores writes.}
524 *
525 * @todo In the future we might want to let the GIM provider decide what the
526 * handler should do (like throwing \#GP faults).
527 */
528static DECLCALLBACK(VBOXSTRICTRC) gimR3Mmio2WriteHandler(PVM pVM, PVMCPU pVCpu, RTGCPHYS GCPhys, void *pvPhys, void *pvBuf,
529 size_t cbBuf, PGMACCESSTYPE enmAccessType, PGMACCESSORIGIN enmOrigin,
530 void *pvUser)
531{
532 /*
533 * Ignore writes to the mapped MMIO2 page.
534 */
535 Assert(enmAccessType == PGMACCESSTYPE_WRITE);
536 return VINF_SUCCESS; /** @todo Hyper-V says we should \#GP(0) fault for writes to the Hypercall and TSC page. */
537}
538
539
540#if 0
541/**
542 * Unmaps a registered MMIO2 region in the guest address space and removes any
543 * access handlers for it.
544 *
545 * @returns VBox status code.
546 * @param pVM The cross context VM structure.
547 * @param pRegion Pointer to the GIM MMIO2 region.
548 */
549VMMR3_INT_DECL(int) gimR3Mmio2Unmap(PVM pVM, PGIMMMIO2REGION pRegion)
550{
551 AssertPtr(pVM);
552 AssertPtr(pRegion);
553
554 PPDMDEVINS pDevIns = pVM->gim.s.pDevInsR3;
555 AssertPtr(pDevIns);
556 if (pRegion->fMapped)
557 {
558 int rc = PGMHandlerPhysicalDeregister(pVM, pRegion->GCPhysPage);
559 AssertRC(rc);
560
561 rc = PDMDevHlpMMIO2Unmap(pDevIns, pRegion->iRegion, pRegion->GCPhysPage);
562 if (RT_SUCCESS(rc))
563 {
564 pRegion->fMapped = false;
565 pRegion->GCPhysPage = NIL_RTGCPHYS;
566 }
567 }
568 return VINF_SUCCESS;
569}
570
571
572/**
573 * Maps a registered MMIO2 region in the guest address space.
574 *
575 * The region will be made read-only and writes from the guest will be ignored.
576 *
577 * @returns VBox status code.
578 * @param pVM The cross context VM structure.
579 * @param pRegion Pointer to the GIM MMIO2 region.
580 * @param GCPhysRegion Where in the guest address space to map the region.
581 */
582VMMR3_INT_DECL(int) GIMR3Mmio2Map(PVM pVM, PGIMMMIO2REGION pRegion, RTGCPHYS GCPhysRegion)
583{
584 PPDMDEVINS pDevIns = pVM->gim.s.pDevInsR3;
585 AssertPtr(pDevIns);
586
587 /* The guest-physical address must be page-aligned. */
588 if (GCPhysRegion & PAGE_OFFSET_MASK)
589 {
590 LogFunc(("%s: %#RGp not paging aligned\n", pRegion->szDescription, GCPhysRegion));
591 return VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS;
592 }
593
594 /* Allow only normal pages to be overlaid using our MMIO2 pages (disallow MMIO, ROM, reserved pages). */
595 /** @todo Hyper-V doesn't seem to be very strict about this, may be relax
596 * later if some guest really requires it. */
597 if (!PGMPhysIsGCPhysNormal(pVM, GCPhysRegion))
598 {
599 LogFunc(("%s: %#RGp is not normal memory\n", pRegion->szDescription, GCPhysRegion));
600 return VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS;
601 }
602
603 if (!pRegion->fRegistered)
604 {
605 LogFunc(("%s: Region has not been registered.\n", pRegion->szDescription));
606 return VERR_GIM_IPE_1;
607 }
608
609 /*
610 * Map the MMIO2 region over the specified guest-physical address.
611 */
612 int rc = PDMDevHlpMMIO2Map(pDevIns, pRegion->iRegion, GCPhysRegion);
613 if (RT_SUCCESS(rc))
614 {
615 /*
616 * Install access-handlers for the mapped page to prevent (ignore) writes to it
617 * from the guest.
618 */
619 if (pVM->gim.s.hSemiReadOnlyMmio2Handler == NIL_PGMPHYSHANDLERTYPE)
620 rc = PGMR3HandlerPhysicalTypeRegister(pVM, PGMPHYSHANDLERKIND_WRITE,
621 gimR3Mmio2WriteHandler,
622 NULL /* pszModR0 */, NULL /* pszHandlerR0 */, NULL /* pszPfHandlerR0 */,
623 NULL /* pszModRC */, NULL /* pszHandlerRC */, NULL /* pszPfHandlerRC */,
624 "GIM read-only MMIO2 handler",
625 &pVM->gim.s.hSemiReadOnlyMmio2Handler);
626 if (RT_SUCCESS(rc))
627 {
628 rc = PGMHandlerPhysicalRegister(pVM, GCPhysRegion, GCPhysRegion + (pRegion->cbRegion - 1),
629 pVM->gim.s.hSemiReadOnlyMmio2Handler,
630 NULL /* pvUserR3 */, NIL_RTR0PTR /* pvUserR0 */, NIL_RTRCPTR /* pvUserRC */,
631 pRegion->szDescription);
632 if (RT_SUCCESS(rc))
633 {
634 pRegion->fMapped = true;
635 pRegion->GCPhysPage = GCPhysRegion;
636 return rc;
637 }
638 }
639
640 PDMDevHlpMMIO2Unmap(pDevIns, pRegion->iRegion, GCPhysRegion);
641 }
642
643 return rc;
644}
645
646
647/**
648 * Registers the physical handler for the registered and mapped MMIO2 region.
649 *
650 * @returns VBox status code.
651 * @param pVM The cross context VM structure.
652 * @param pRegion Pointer to the GIM MMIO2 region.
653 */
654VMMR3_INT_DECL(int) gimR3Mmio2HandlerPhysicalRegister(PVM pVM, PGIMMMIO2REGION pRegion)
655{
656 AssertPtr(pRegion);
657 AssertReturn(pRegion->fRegistered, VERR_GIM_IPE_2);
658 AssertReturn(pRegion->fMapped, VERR_GIM_IPE_3);
659
660 return PGMR3HandlerPhysicalRegister(pVM,
661 PGMPHYSHANDLERKIND_WRITE,
662 pRegion->GCPhysPage, pRegion->GCPhysPage + (pRegion->cbRegion - 1),
663 gimR3Mmio2WriteHandler, NULL /* pvUserR3 */,
664 NULL /* pszModR0 */, NULL /* pszHandlerR0 */, NIL_RTR0PTR /* pvUserR0 */,
665 NULL /* pszModRC */, NULL /* pszHandlerRC */, NIL_RTRCPTR /* pvUserRC */,
666 pRegion->szDescription);
667}
668
669
670/**
671 * Deregisters the physical handler for the MMIO2 region.
672 *
673 * @returns VBox status code.
674 * @param pVM The cross context VM structure.
675 * @param pRegion Pointer to the GIM MMIO2 region.
676 */
677VMMR3_INT_DECL(int) gimR3Mmio2HandlerPhysicalDeregister(PVM pVM, PGIMMMIO2REGION pRegion)
678{
679 return PGMHandlerPhysicalDeregister(pVM, pRegion->GCPhysPage);
680}
681#endif
682
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