VirtualBox

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

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

GIM: Please refrain from using 'c' as 'const', 'c' always means 'count of' and make variables like 'pcRegion' very very confusing. The compiler will tell you if you try access a const variable, don't worry. Fixed unused variable warnings/

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