VirtualBox

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

Last change on this file since 58591 was 58564, checked in by vboxsync, 9 years ago

VMM/GIM: Removed some dead code.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 22.1 KB
Line 
1/* $Id: GIM.cpp 58564 2015-11-04 13:53:54Z 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/log.h>
54#include "GIMInternal.h"
55#include <VBox/vmm/vm.h>
56#include <VBox/vmm/hm.h>
57#include <VBox/vmm/ssm.h>
58#include <VBox/vmm/pdmdev.h>
59
60#include <iprt/err.h>
61#include <iprt/semaphore.h>
62#include <iprt/string.h>
63
64/* Include all GIM providers. */
65#include "GIMMinimalInternal.h"
66#include "GIMHvInternal.h"
67#include "GIMKvmInternal.h"
68
69
70/*********************************************************************************************************************************
71* Internal Functions *
72*********************************************************************************************************************************/
73static FNSSMINTSAVEEXEC gimR3Save;
74static FNSSMINTLOADEXEC gimR3Load;
75static FNPGMPHYSHANDLER gimR3Mmio2WriteHandler;
76
77
78/**
79 * Initializes the GIM.
80 *
81 * @returns VBox status code.
82 * @param pVM The cross context VM structure.
83 */
84VMMR3_INT_DECL(int) GIMR3Init(PVM pVM)
85{
86 LogFlow(("GIMR3Init\n"));
87
88 /*
89 * Assert alignment and sizes.
90 */
91 AssertCompile(sizeof(pVM->gim.s) <= sizeof(pVM->gim.padding));
92 AssertCompile(sizeof(pVM->aCpus[0].gim.s) <= sizeof(pVM->aCpus[0].gim.padding));
93
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, uVersion);
310 AssertRCReturn(rc, rc);
311 break;
312
313 case GIMPROVIDERID_KVM:
314 rc = gimR3KvmLoad(pVM, pSSM, uVersion);
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_COUNTER_INC(&pVM->gim.s.StatDbgRecv);
437 STAM_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_COUNTER_INC(&pVM->gim.s.StatDbgXmit);
480 STAM_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
520/**
521 * Unmaps a registered MMIO2 region in the guest address space and removes any
522 * access handlers for it.
523 *
524 * @returns VBox status code.
525 * @param pVM The cross context VM structure.
526 * @param pRegion Pointer to the GIM MMIO2 region.
527 */
528VMMR3_INT_DECL(int) GIMR3Mmio2Unmap(PVM pVM, PGIMMMIO2REGION pRegion)
529{
530 AssertPtr(pVM);
531 AssertPtr(pRegion);
532
533 PPDMDEVINS pDevIns = pVM->gim.s.pDevInsR3;
534 AssertPtr(pDevIns);
535 if (pRegion->fMapped)
536 {
537 int rc = PGMHandlerPhysicalDeregister(pVM, pRegion->GCPhysPage);
538 AssertRC(rc);
539
540 rc = PDMDevHlpMMIO2Unmap(pDevIns, pRegion->iRegion, pRegion->GCPhysPage);
541 if (RT_SUCCESS(rc))
542 {
543 pRegion->fMapped = false;
544 pRegion->GCPhysPage = NIL_RTGCPHYS;
545 }
546 }
547 return VINF_SUCCESS;
548}
549
550
551/**
552 * @callback_method_impl{FNPGMPHYSHANDLER,
553 * Write access handler for mapped MMIO2 pages. Currently ignores writes.}
554 *
555 * @todo In the future we might want to let the GIM provider decide what the
556 * handler should do (like throwing \#GP faults).
557 */
558static DECLCALLBACK(VBOXSTRICTRC)
559gimR3Mmio2WriteHandler(PVM pVM, PVMCPU pVCpu, RTGCPHYS GCPhys, void *pvPhys, void *pvBuf, size_t cbBuf,
560 PGMACCESSTYPE enmAccessType, PGMACCESSORIGIN enmOrigin, void *pvUser)
561{
562 /*
563 * Ignore writes to the mapped MMIO2 page.
564 */
565 Assert(enmAccessType == PGMACCESSTYPE_WRITE);
566 return VINF_SUCCESS; /** @todo Hyper-V says we should \#GP(0) fault for writes to the Hypercall and TSC page. */
567}
568
569
570/**
571 * Maps a registered MMIO2 region in the guest address space.
572 *
573 * The region will be made read-only and writes from the guest will be ignored.
574 *
575 * @returns VBox status code.
576 * @param pVM The cross context VM structure.
577 * @param pRegion Pointer to the GIM MMIO2 region.
578 * @param GCPhysRegion Where in the guest address space to map the region.
579 */
580VMMR3_INT_DECL(int) GIMR3Mmio2Map(PVM pVM, PGIMMMIO2REGION pRegion, RTGCPHYS GCPhysRegion)
581{
582 PPDMDEVINS pDevIns = pVM->gim.s.pDevInsR3;
583 AssertPtr(pDevIns);
584
585 /* The guest-physical address must be page-aligned. */
586 if (GCPhysRegion & PAGE_OFFSET_MASK)
587 {
588 LogFunc(("%s: %#RGp not paging aligned\n", pRegion->szDescription, GCPhysRegion));
589 return VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS;
590 }
591
592 /* Allow only normal pages to be overlaid using our MMIO2 pages (disallow MMIO, ROM, reserved pages). */
593 /** @todo Hyper-V doesn't seem to be very strict about this, may be relax
594 * later if some guest really requires it. */
595 if (!PGMPhysIsGCPhysNormal(pVM, GCPhysRegion))
596 {
597 LogFunc(("%s: %#RGp is not normal memory\n", pRegion->szDescription, GCPhysRegion));
598 return VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS;
599 }
600
601 if (!pRegion->fRegistered)
602 {
603 LogFunc(("%s: Region has not been registered.\n", pRegion->szDescription));
604 return VERR_GIM_IPE_1;
605 }
606
607 /*
608 * Map the MMIO2 region over the specified guest-physical address.
609 */
610 int rc = PDMDevHlpMMIO2Map(pDevIns, pRegion->iRegion, GCPhysRegion);
611 if (RT_SUCCESS(rc))
612 {
613 /*
614 * Install access-handlers for the mapped page to prevent (ignore) writes to it
615 * from the guest.
616 */
617 if (pVM->gim.s.hSemiReadOnlyMmio2Handler == NIL_PGMPHYSHANDLERTYPE)
618 rc = PGMR3HandlerPhysicalTypeRegister(pVM, PGMPHYSHANDLERKIND_WRITE,
619 gimR3Mmio2WriteHandler,
620 NULL /* pszModR0 */, NULL /* pszHandlerR0 */, NULL /* pszPfHandlerR0 */,
621 NULL /* pszModRC */, NULL /* pszHandlerRC */, NULL /* pszPfHandlerRC */,
622 "GIM read-only MMIO2 handler",
623 &pVM->gim.s.hSemiReadOnlyMmio2Handler);
624 if (RT_SUCCESS(rc))
625 {
626 rc = PGMHandlerPhysicalRegister(pVM, GCPhysRegion, GCPhysRegion + (pRegion->cbRegion - 1),
627 pVM->gim.s.hSemiReadOnlyMmio2Handler,
628 NULL /* pvUserR3 */, NIL_RTR0PTR /* pvUserR0 */, NIL_RTRCPTR /* pvUserRC */,
629 pRegion->szDescription);
630 if (RT_SUCCESS(rc))
631 {
632 pRegion->fMapped = true;
633 pRegion->GCPhysPage = GCPhysRegion;
634 return rc;
635 }
636 }
637
638 PDMDevHlpMMIO2Unmap(pDevIns, pRegion->iRegion, GCPhysRegion);
639 }
640
641 return rc;
642}
643
644#if 0
645/**
646 * Registers the physical handler for the registered and mapped MMIO2 region.
647 *
648 * @returns VBox status code.
649 * @param pVM The cross context VM structure.
650 * @param pRegion Pointer to the GIM MMIO2 region.
651 */
652VMMR3_INT_DECL(int) GIMR3Mmio2HandlerPhysicalRegister(PVM pVM, PGIMMMIO2REGION pRegion)
653{
654 AssertPtr(pRegion);
655 AssertReturn(pRegion->fRegistered, VERR_GIM_IPE_2);
656 AssertReturn(pRegion->fMapped, VERR_GIM_IPE_3);
657
658 return PGMR3HandlerPhysicalRegister(pVM,
659 PGMPHYSHANDLERKIND_WRITE,
660 pRegion->GCPhysPage, pRegion->GCPhysPage + (pRegion->cbRegion - 1),
661 gimR3Mmio2WriteHandler, NULL /* pvUserR3 */,
662 NULL /* pszModR0 */, NULL /* pszHandlerR0 */, NIL_RTR0PTR /* pvUserR0 */,
663 NULL /* pszModRC */, NULL /* pszHandlerRC */, NIL_RTRCPTR /* pvUserRC */,
664 pRegion->szDescription);
665}
666
667
668/**
669 * Deregisters the physical handler for the MMIO2 region.
670 *
671 * @returns VBox status code.
672 * @param pVM The cross context VM structure.
673 * @param pRegion Pointer to the GIM MMIO2 region.
674 */
675VMMR3_INT_DECL(int) GIMR3Mmio2HandlerPhysicalDeregister(PVM pVM, PGIMMMIO2REGION pRegion)
676{
677 return PGMHandlerPhysicalDeregister(pVM, pRegion->GCPhysPage);
678}
679#endif
680
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