VirtualBox

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

最後變更 在這個檔案從61632是 61632,由 vboxsync 提交於 9 年 前

GIM: Correct header order to match what is use *everywhere* else in the VMM and what is absolutely necessary for some of the tricks we use (like the CPUM and DBGF read-only data!).

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 22.1 KB
 
1/* $Id: GIM.cpp 61632 2016-06-09 18:06:26Z 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.alldomusa.eu.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 /*
98 * Initialize members.
99 */
100 pVM->gim.s.hSemiReadOnlyMmio2Handler = NIL_PGMPHYSHANDLERTYPE;
101
102 /*
103 * Register the saved state data unit.
104 */
105 int rc = SSMR3RegisterInternal(pVM, "GIM", 0 /* uInstance */, GIM_SAVED_STATE_VERSION, sizeof(GIM),
106 NULL /* pfnLivePrep */, NULL /* pfnLiveExec */, NULL /* pfnLiveVote*/,
107 NULL /* pfnSavePrep */, gimR3Save, NULL /* pfnSaveDone */,
108 NULL /* pfnLoadPrep */, gimR3Load, NULL /* pfnLoadDone */);
109 if (RT_FAILURE(rc))
110 return rc;
111
112 /*
113 * Read configuration.
114 */
115 PCFGMNODE pCfgNode = CFGMR3GetChild(CFGMR3GetRoot(pVM), "GIM/");
116
117 /*
118 * Validate the GIM settings.
119 */
120 rc = CFGMR3ValidateConfig(pCfgNode, "/GIM/", /* pszNode */
121 "Provider" /* pszValidValues */
122 "|Version",
123 "HyperV", /* pszValidNodes */
124 "GIM", /* pszWho */
125 0); /* uInstance */
126 if (RT_FAILURE(rc))
127 return rc;
128
129 /** @cfgm{/GIM/Provider, string}
130 * The name of the GIM provider. The default is "none". */
131 char szProvider[64];
132 rc = CFGMR3QueryStringDef(pCfgNode, "Provider", szProvider, sizeof(szProvider), "None");
133 AssertLogRelRCReturn(rc, rc);
134
135 /** @cfgm{/GIM/Version, uint32_t}
136 * The interface version. The default is 0, which means "provide the most
137 * up-to-date implementation". */
138 uint32_t uVersion;
139 rc = CFGMR3QueryU32Def(pCfgNode, "Version", &uVersion, 0 /* default */);
140 AssertLogRelRCReturn(rc, rc);
141
142 /*
143 * Setup the GIM provider for this VM.
144 */
145 LogRel(("GIM: Using provider '%s' (Implementation version: %u)\n", szProvider, uVersion));
146 if (!RTStrCmp(szProvider, "None"))
147 pVM->gim.s.enmProviderId = GIMPROVIDERID_NONE;
148 else
149 {
150 pVM->gim.s.u32Version = uVersion;
151 /** @todo r=bird: Because u32Version is saved, it should be translated to the
152 * 'most up-to-date implementation' version number when 0. Otherwise,
153 * we'll have abiguities when loading the state of older VMs. */
154 if (!RTStrCmp(szProvider, "Minimal"))
155 {
156 pVM->gim.s.enmProviderId = GIMPROVIDERID_MINIMAL;
157 rc = gimR3MinimalInit(pVM);
158 }
159 else if (!RTStrCmp(szProvider, "HyperV"))
160 {
161 pVM->gim.s.enmProviderId = GIMPROVIDERID_HYPERV;
162 rc = gimR3HvInit(pVM, pCfgNode);
163 }
164 else if (!RTStrCmp(szProvider, "KVM"))
165 {
166 pVM->gim.s.enmProviderId = GIMPROVIDERID_KVM;
167 rc = gimR3KvmInit(pVM);
168 }
169 else
170 rc = VMR3SetError(pVM->pUVM, VERR_GIM_INVALID_PROVIDER, RT_SRC_POS, "Provider '%s' unknown.", szProvider);
171 }
172
173 /*
174 * Statistics.
175 */
176 STAM_REL_REG_USED(pVM, &pVM->gim.s.StatDbgXmit, STAMTYPE_COUNTER, "/GIM/Debug/Transmit", STAMUNIT_OCCURENCES, "Debug packets sent.");
177 STAM_REL_REG_USED(pVM, &pVM->gim.s.StatDbgXmitBytes, STAMTYPE_COUNTER, "/GIM/Debug/TransmitBytes", STAMUNIT_OCCURENCES, "Debug bytes sent.");
178 STAM_REL_REG_USED(pVM, &pVM->gim.s.StatDbgRecv, STAMTYPE_COUNTER, "/GIM/Debug/Receive", STAMUNIT_OCCURENCES, "Debug packets received.");
179 STAM_REL_REG_USED(pVM, &pVM->gim.s.StatDbgRecvBytes, STAMTYPE_COUNTER, "/GIM/Debug/ReceiveBytes", STAMUNIT_OCCURENCES, "Debug bytes received.");
180
181 STAM_REL_REG_USED(pVM, &pVM->gim.s.StatHypercalls, STAMTYPE_COUNTER, "/GIM/Hypercalls", STAMUNIT_OCCURENCES, "Number of hypercalls initiated.");
182 return rc;
183}
184
185
186/**
187 * Initializes the remaining bits of the GIM provider.
188 *
189 * This is called after initializing HM and most other VMM components.
190 *
191 * @returns VBox status code.
192 * @param pVM The cross context VM structure.
193 * @thread EMT(0)
194 */
195VMMR3_INT_DECL(int) GIMR3InitCompleted(PVM pVM)
196{
197 switch (pVM->gim.s.enmProviderId)
198 {
199 case GIMPROVIDERID_MINIMAL:
200 return gimR3MinimalInitCompleted(pVM);
201
202 case GIMPROVIDERID_HYPERV:
203 return gimR3HvInitCompleted(pVM);
204
205 case GIMPROVIDERID_KVM:
206 return gimR3KvmInitCompleted(pVM);
207
208 default:
209 break;
210 }
211
212 if (!TMR3CpuTickIsFixedRateMonotonic(pVM, true /* fWithParavirtEnabled */))
213 LogRel(("GIM: Warning!!! Host TSC is unstable. The guest may behave unpredictably with a paravirtualized clock.\n"));
214
215 return VINF_SUCCESS;
216}
217
218
219/**
220 * @callback_method_impl{FNSSMINTSAVEEXEC}
221 */
222static DECLCALLBACK(int) gimR3Save(PVM pVM, PSSMHANDLE pSSM)
223{
224 AssertReturn(pVM, VERR_INVALID_PARAMETER);
225 AssertReturn(pSSM, VERR_SSM_INVALID_STATE);
226
227 /** @todo Save per-CPU data. */
228 int rc = VINF_SUCCESS;
229#if 0
230 SSMR3PutU32(pSSM, pVM->cCpus);
231 for (VMCPUID i = 0; i < pVM->cCpus; i++)
232 {
233 rc = SSMR3PutXYZ(pSSM, pVM->aCpus[i].gim.s.XYZ);
234 }
235#endif
236
237 /*
238 * Save per-VM data.
239 */
240 SSMR3PutU32(pSSM, pVM->gim.s.enmProviderId);
241 SSMR3PutU32(pSSM, pVM->gim.s.u32Version);
242
243 /*
244 * Save provider-specific data.
245 */
246 switch (pVM->gim.s.enmProviderId)
247 {
248 case GIMPROVIDERID_HYPERV:
249 rc = gimR3HvSave(pVM, pSSM);
250 AssertRCReturn(rc, rc);
251 break;
252
253 case GIMPROVIDERID_KVM:
254 rc = gimR3KvmSave(pVM, pSSM);
255 AssertRCReturn(rc, rc);
256 break;
257
258 default:
259 break;
260 }
261
262 return rc;
263}
264
265
266/**
267 * @callback_method_impl{FNSSMINTLOADEXEC}
268 */
269static DECLCALLBACK(int) gimR3Load(PVM pVM, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
270{
271 if (uPass != SSM_PASS_FINAL)
272 return VINF_SUCCESS;
273 if (uVersion != GIM_SAVED_STATE_VERSION)
274 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
275
276 /** @todo Load per-CPU data. */
277 int rc;
278#if 0
279 for (VMCPUID i = 0; i < pVM->cCpus; i++)
280 {
281 rc = SSMR3PutXYZ(pSSM, pVM->aCpus[i].gim.s.XYZ);
282 }
283#endif
284
285 /*
286 * Load per-VM data.
287 */
288 uint32_t uProviderId;
289 uint32_t uProviderVersion;
290
291 rc = SSMR3GetU32(pSSM, &uProviderId); AssertRCReturn(rc, rc);
292 rc = SSMR3GetU32(pSSM, &uProviderVersion); AssertRCReturn(rc, rc);
293
294 if ((GIMPROVIDERID)uProviderId != pVM->gim.s.enmProviderId)
295 return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Saved GIM provider %u differs from the configured one (%u)."),
296 uProviderId, pVM->gim.s.enmProviderId);
297#if 0 /** @todo r=bird: Figure out what you mean to do here with the version. */
298 if (uProviderVersion != pVM->gim.s.u32Version)
299 return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Saved GIM provider version %u differs from the configured one (%u)."),
300 uProviderVersion, pVM->gim.s.u32Version);
301#else
302 pVM->gim.s.u32Version = uProviderVersion;
303#endif
304
305 /*
306 * Load provider-specific data.
307 */
308 switch (pVM->gim.s.enmProviderId)
309 {
310 case GIMPROVIDERID_HYPERV:
311 rc = gimR3HvLoad(pVM, pSSM, uVersion);
312 AssertRCReturn(rc, rc);
313 break;
314
315 case GIMPROVIDERID_KVM:
316 rc = gimR3KvmLoad(pVM, pSSM, uVersion);
317 AssertRCReturn(rc, rc);
318 break;
319
320 default:
321 break;
322 }
323
324 return VINF_SUCCESS;
325}
326
327
328/**
329 * Terminates the GIM.
330 *
331 * Termination means cleaning up and freeing all resources,
332 * the VM itself is, at this point, powered off or suspended.
333 *
334 * @returns VBox status code.
335 * @param pVM The cross context VM structure.
336 */
337VMMR3_INT_DECL(int) GIMR3Term(PVM pVM)
338{
339 switch (pVM->gim.s.enmProviderId)
340 {
341 case GIMPROVIDERID_HYPERV:
342 return gimR3HvTerm(pVM);
343
344 case GIMPROVIDERID_KVM:
345 return gimR3KvmTerm(pVM);
346
347 default:
348 break;
349 }
350 return VINF_SUCCESS;
351}
352
353
354/**
355 * The VM is being reset.
356 *
357 * For the GIM component this means unmapping and unregistering MMIO2 regions
358 * and other provider-specific resets.
359 *
360 * @returns VBox status code.
361 * @param pVM The cross context VM structure.
362 */
363VMMR3_INT_DECL(void) GIMR3Reset(PVM pVM)
364{
365 switch (pVM->gim.s.enmProviderId)
366 {
367 case GIMPROVIDERID_HYPERV:
368 return gimR3HvReset(pVM);
369
370 case GIMPROVIDERID_KVM:
371 return gimR3KvmReset(pVM);
372
373 default:
374 break;
375 }
376}
377
378
379/**
380 * Registers the GIM device with VMM.
381 *
382 * @param pVM The cross context VM structure.
383 * @param pDevIns Pointer to the GIM device instance.
384 * @param pDbg Pointer to the GIM device debug structure, can be
385 * NULL.
386 */
387VMMR3DECL(void) GIMR3GimDeviceRegister(PVM pVM, PPDMDEVINS pDevIns, PGIMDEBUG pDbg)
388{
389 pVM->gim.s.pDevInsR3 = pDevIns;
390 pVM->gim.s.pDbgR3 = pDbg;
391}
392
393
394/**
395 * Gets debug setup specified by the provider.
396 *
397 * @returns VBox status code.
398 * @param pVM The cross context VM structure.
399 * @param pDbgSetup Where to store the debug setup details.
400 */
401VMMR3DECL(int) GIMR3GetDebugSetup(PVM pVM, PGIMDEBUGSETUP pDbgSetup)
402{
403 AssertReturn(pVM, VERR_INVALID_PARAMETER);
404 AssertReturn(pDbgSetup, VERR_INVALID_PARAMETER);
405
406 switch (pVM->gim.s.enmProviderId)
407 {
408 case GIMPROVIDERID_HYPERV:
409 return gimR3HvGetDebugSetup(pVM, pDbgSetup);
410 default:
411 break;
412 }
413 return VERR_GIM_NO_DEBUG_CONNECTION;
414}
415
416
417/**
418 * Read data from a host debug session.
419 *
420 * @returns VBox status code.
421 *
422 * @param pVM The cross context VM structure.
423 * @param pvRead The read buffer.
424 * @param pcbRead The size of the read buffer as well as where to store
425 * the number of bytes read.
426 * @param pfnReadComplete Callback when the buffer has been read and
427 * before signaling reading of the next buffer.
428 * Optional, can be NULL.
429 * @thread EMT.
430 */
431VMMR3_INT_DECL(int) GIMR3DebugRead(PVM pVM, void *pvRead, size_t *pcbRead, PFNGIMDEBUGBUFREADCOMPLETED pfnReadComplete)
432{
433 PGIMDEBUG pDbg = pVM->gim.s.pDbgR3;
434 if (pDbg)
435 {
436 if (ASMAtomicReadBool(&pDbg->fDbgRecvBufRead) == true)
437 {
438 STAM_REL_COUNTER_INC(&pVM->gim.s.StatDbgRecv);
439 STAM_REL_COUNTER_ADD(&pVM->gim.s.StatDbgRecvBytes, pDbg->cbDbgRecvBufRead);
440
441 memcpy(pvRead, pDbg->pvDbgRecvBuf, pDbg->cbDbgRecvBufRead);
442 *pcbRead = pDbg->cbDbgRecvBufRead;
443 if (pfnReadComplete)
444 pfnReadComplete(pVM);
445 RTSemEventMultiSignal(pDbg->hDbgRecvThreadSem);
446 ASMAtomicWriteBool(&pDbg->fDbgRecvBufRead, false);
447 return VINF_SUCCESS;
448 }
449 else
450 *pcbRead = 0;
451 return VERR_NO_DATA;
452 }
453 return VERR_GIM_NO_DEBUG_CONNECTION;
454}
455
456
457/**
458 * Write data to a host debug session.
459 *
460 * @returns VBox status code.
461 *
462 * @param pVM The cross context VM structure.
463 * @param pvWrite The write buffer.
464 * @param pcbWrite The size of the write buffer as well as where to store
465 * the number of bytes written.
466 * @thread EMT.
467 */
468VMMR3_INT_DECL(int) GIMR3DebugWrite(PVM pVM, void *pvWrite, size_t *pcbWrite)
469{
470 PGIMDEBUG pDbg = pVM->gim.s.pDbgR3;
471 if (pDbg)
472 {
473 PPDMISTREAM pDbgStream = pDbg->pDbgDrvStream;
474 if (pDbgStream)
475 {
476 size_t cbWrite = *pcbWrite;
477 int rc = pDbgStream->pfnWrite(pDbgStream, pvWrite, pcbWrite);
478 if ( RT_SUCCESS(rc)
479 && *pcbWrite == cbWrite)
480 {
481 STAM_REL_COUNTER_INC(&pVM->gim.s.StatDbgXmit);
482 STAM_REL_COUNTER_ADD(&pVM->gim.s.StatDbgXmitBytes, *pcbWrite);
483 }
484 return rc;
485 }
486 }
487 return VERR_GIM_NO_DEBUG_CONNECTION;
488}
489
490
491/**
492 * Returns the array of MMIO2 regions that are expected to be registered and
493 * later mapped into the guest-physical address space for the GIM provider
494 * configured for the VM.
495 *
496 * @returns Pointer to an array of GIM MMIO2 regions, may return NULL.
497 * @param pVM The cross context VM structure.
498 * @param pcRegions Where to store the number of items in the array.
499 *
500 * @remarks The caller does not own and therefore must -NOT- try to free the
501 * returned pointer.
502 */
503VMMR3DECL(PGIMMMIO2REGION) GIMR3GetMmio2Regions(PVM pVM, uint32_t *pcRegions)
504{
505 Assert(pVM);
506 Assert(pcRegions);
507
508 *pcRegions = 0;
509 switch (pVM->gim.s.enmProviderId)
510 {
511 case GIMPROVIDERID_HYPERV:
512 return gimR3HvGetMmio2Regions(pVM, pcRegions);
513
514 default:
515 break;
516 }
517
518 return NULL;
519}
520
521
522/**
523 * Unmaps a registered MMIO2 region in the guest address space and removes any
524 * access handlers for it.
525 *
526 * @returns VBox status code.
527 * @param pVM The cross context VM structure.
528 * @param pRegion Pointer to the GIM MMIO2 region.
529 */
530VMMR3_INT_DECL(int) GIMR3Mmio2Unmap(PVM pVM, PGIMMMIO2REGION pRegion)
531{
532 AssertPtr(pVM);
533 AssertPtr(pRegion);
534
535 PPDMDEVINS pDevIns = pVM->gim.s.pDevInsR3;
536 AssertPtr(pDevIns);
537 if (pRegion->fMapped)
538 {
539 int rc = PGMHandlerPhysicalDeregister(pVM, pRegion->GCPhysPage);
540 AssertRC(rc);
541
542 rc = PDMDevHlpMMIO2Unmap(pDevIns, pRegion->iRegion, pRegion->GCPhysPage);
543 if (RT_SUCCESS(rc))
544 {
545 pRegion->fMapped = false;
546 pRegion->GCPhysPage = NIL_RTGCPHYS;
547 }
548 }
549 return VINF_SUCCESS;
550}
551
552
553/**
554 * @callback_method_impl{FNPGMPHYSHANDLER,
555 * Write access handler for mapped MMIO2 pages. Currently ignores writes.}
556 *
557 * @todo In the future we might want to let the GIM provider decide what the
558 * handler should do (like throwing \#GP faults).
559 */
560static DECLCALLBACK(VBOXSTRICTRC)
561gimR3Mmio2WriteHandler(PVM pVM, PVMCPU pVCpu, RTGCPHYS GCPhys, void *pvPhys, void *pvBuf, size_t cbBuf,
562 PGMACCESSTYPE enmAccessType, PGMACCESSORIGIN enmOrigin, void *pvUser)
563{
564 /*
565 * Ignore writes to the mapped MMIO2 page.
566 */
567 Assert(enmAccessType == PGMACCESSTYPE_WRITE);
568 return VINF_SUCCESS; /** @todo Hyper-V says we should \#GP(0) fault for writes to the Hypercall and TSC page. */
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#if 0
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
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette