VirtualBox

source: vbox/trunk/src/VBox/VMM/PGMPhys.cpp@ 4041

Last change on this file since 4041 was 4013, checked in by vboxsync, 17 years ago

pdm.h = include pdm*.h; pdmapi.h = only the 'core' pdm APIs.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 20.0 KB
Line 
1/* $Id: PGMPhys.cpp 4013 2007-08-03 00:11:38Z vboxsync $ */
2/** @file
3 * PGM - Page Manager and Monitor, Physical Memory Addressing.
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek GmbH
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 as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22
23/*******************************************************************************
24* Header Files *
25*******************************************************************************/
26#define LOG_GROUP LOG_GROUP_PGM
27#include <VBox/pgm.h>
28#include <VBox/cpum.h>
29#include <VBox/iom.h>
30#include <VBox/sup.h>
31#include <VBox/mm.h>
32#include <VBox/stam.h>
33#include <VBox/rem.h>
34#include <VBox/csam.h>
35#include "PGMInternal.h"
36#include <VBox/vm.h>
37#include <VBox/dbg.h>
38#include <VBox/param.h>
39#include <VBox/err.h>
40#include <iprt/assert.h>
41#include <iprt/alloc.h>
42#include <iprt/asm.h>
43#include <VBox/log.h>
44#include <iprt/thread.h>
45#include <iprt/string.h>
46
47
48
49
50/**
51 * Interface MMR3RamRegister(), MMR3RomRegister() and MMIO handler
52 * registration calls.
53 *
54 * It registers the physical memory range with PGM. MM is responsible
55 * for the toplevel things - allocation and locking - while PGM is taking
56 * care of all the details and implements the physical address space virtualization.
57 *
58 * @returns VBox status.
59 * @param pVM The VM handle.
60 * @param pvRam HC virtual address of the RAM range. (page aligned)
61 * @param GCPhys GC physical address of the RAM range. (page aligned)
62 * @param cb Size of the RAM range. (page aligned)
63 * @param fFlags Flags, MM_RAM_*.
64 * @param paPages Pointer an array of physical page descriptors.
65 * @param pszDesc Description string.
66 */
67PGMR3DECL(int) PGMR3PhysRegister(PVM pVM, void *pvRam, RTGCPHYS GCPhys, size_t cb, unsigned fFlags, const SUPPAGE *paPages, const char *pszDesc)
68{
69 /*
70 * Validate input.
71 * (Not so important because callers are only MMR3PhysRegister()
72 * and PGMR3HandlerPhysicalRegisterEx(), but anyway...)
73 */
74 Log(("PGMR3PhysRegister %08X %x bytes flags %x %s\n", GCPhys, cb, fFlags, pszDesc));
75
76 Assert((fFlags & (MM_RAM_FLAGS_RESERVED | MM_RAM_FLAGS_MMIO | MM_RAM_FLAGS_DYNAMIC_ALLOC)) || paPages);
77 /*Assert(!(fFlags & MM_RAM_FLAGS_RESERVED) || !paPages);*/
78 Assert((fFlags == (MM_RAM_FLAGS_RESERVED | MM_RAM_FLAGS_MMIO)) || (fFlags & MM_RAM_FLAGS_DYNAMIC_ALLOC) || pvRam);
79 /*Assert(!(fFlags & MM_RAM_FLAGS_RESERVED) || !pvRam);*/
80 Assert(!(fFlags & ~0xfff));
81 Assert(RT_ALIGN_Z(cb, PAGE_SIZE) == cb && cb);
82 Assert(RT_ALIGN_P(pvRam, PAGE_SIZE) == pvRam);
83 Assert(!(fFlags & ~(MM_RAM_FLAGS_RESERVED | MM_RAM_FLAGS_ROM | MM_RAM_FLAGS_MMIO | MM_RAM_FLAGS_MMIO2 | MM_RAM_FLAGS_DYNAMIC_ALLOC)));
84 Assert(RT_ALIGN_T(GCPhys, PAGE_SIZE, RTGCPHYS) == GCPhys);
85 RTGCPHYS GCPhysLast = GCPhys + (cb - 1);
86 if (GCPhysLast < GCPhys)
87 {
88 AssertMsgFailed(("The range wraps! GCPhys=%VGp cb=%#x\n", GCPhys, cb));
89 return VERR_INVALID_PARAMETER;
90 }
91
92 /*
93 * Find range location and check for conflicts.
94 */
95 PPGMRAMRANGE pPrev = NULL;
96 PPGMRAMRANGE pCur = pVM->pgm.s.pRamRangesHC;
97 while (pCur)
98 {
99 if (GCPhys <= pCur->GCPhysLast && GCPhysLast >= pCur->GCPhys)
100 {
101 AssertMsgFailed(("Conflict! This cannot happen!\n"));
102 return VERR_PGM_RAM_CONFLICT;
103 }
104 if (GCPhysLast < pCur->GCPhys)
105 break;
106
107 /* next */
108 pPrev = pCur;
109 pCur = pCur->pNextHC;
110 }
111
112 /*
113 * Allocate RAM range.
114 * Small ranges are allocated from the heap, big ones have separate mappings.
115 */
116 size_t cbRam = RT_OFFSETOF(PGMRAMRANGE, aHCPhys[cb >> PAGE_SHIFT]);
117 PPGMRAMRANGE pNew;
118 RTGCPTR GCPtrNew;
119 int rc;
120 if (cbRam > PAGE_SIZE / 2)
121 { /* large */
122 cbRam = RT_ALIGN_Z(cbRam, PAGE_SIZE);
123 rc = SUPPageAlloc(cbRam >> PAGE_SHIFT, (void **)&pNew);
124 if (VBOX_SUCCESS(rc))
125 {
126 rc = MMR3HyperMapHCRam(pVM, pNew, cbRam, true, pszDesc, &GCPtrNew);
127 if (VBOX_SUCCESS(rc))
128 {
129 Assert(MMHyperHC2GC(pVM, pNew) == GCPtrNew);
130 rc = MMR3HyperReserve(pVM, PAGE_SIZE, "fence", NULL);
131 }
132 else
133 {
134 AssertMsgFailed(("MMR3HyperMapHCRam(,,%#x,,,) -> %Vrc\n", cbRam, rc));
135 SUPPageFree(pNew, cbRam >> PAGE_SHIFT);
136 }
137 }
138 else
139 AssertMsgFailed(("SUPPageAlloc(%#x,,) -> %Vrc\n", cbRam >> PAGE_SHIFT, rc));
140 }
141 else
142 { /* small */
143 rc = MMHyperAlloc(pVM, cbRam, 16, MM_TAG_PGM, (void **)&pNew);
144 if (VBOX_SUCCESS(rc))
145 GCPtrNew = MMHyperHC2GC(pVM, pNew);
146 else
147 AssertMsgFailed(("MMHyperAlloc(,%#x,,,) -> %Vrc\n", cbRam, cb));
148 }
149 if (VBOX_SUCCESS(rc))
150 {
151 /*
152 * Initialize the range.
153 */
154 pNew->pvHC = pvRam;
155 pNew->GCPhys = GCPhys;
156 pNew->GCPhysLast = GCPhysLast;
157 pNew->cb = cb;
158 pNew->fFlags = fFlags;
159 pNew->pavHCChunkHC = NULL;
160 pNew->pavHCChunkGC = 0;
161
162 unsigned iPage = cb >> PAGE_SHIFT;
163 if (paPages)
164 {
165 while (iPage-- > 0)
166 pNew->aHCPhys[iPage] = (paPages[iPage].Phys & X86_PTE_PAE_PG_MASK) | fFlags;
167 }
168 else if (fFlags & MM_RAM_FLAGS_DYNAMIC_ALLOC)
169 {
170 /* Allocate memory for chunk to HC ptr lookup array. */
171 rc = MMHyperAlloc(pVM, (cb >> PGM_DYNAMIC_CHUNK_SHIFT) * sizeof(void *), 16, MM_TAG_PGM, (void **)&pNew->pavHCChunkHC);
172 AssertMsgReturn(rc == VINF_SUCCESS, ("MMHyperAlloc(,%#x,,,) -> %Vrc\n", cbRam, cb), rc);
173
174 pNew->pavHCChunkGC = MMHyperHC2GC(pVM, pNew->pavHCChunkHC);
175 Assert(pNew->pavHCChunkGC);
176
177 /* Physical memory will be allocated on demand. */
178 while (iPage-- > 0)
179 pNew->aHCPhys[iPage] = fFlags;
180 }
181 else
182 {
183 Assert(fFlags == (MM_RAM_FLAGS_RESERVED | MM_RAM_FLAGS_MMIO));
184 RTHCPHYS HCPhysDummyPage = (MMR3PageDummyHCPhys(pVM) & X86_PTE_PAE_PG_MASK) | fFlags;
185 while (iPage-- > 0)
186 pNew->aHCPhys[iPage] = HCPhysDummyPage;
187 }
188
189 /*
190 * Insert the new RAM range.
191 */
192 pgmLock(pVM);
193 pNew->pNextHC = pCur;
194 pNew->pNextGC = pCur ? MMHyperHC2GC(pVM, pCur) : 0;
195 if (pPrev)
196 {
197 pPrev->pNextHC = pNew;
198 pPrev->pNextGC = GCPtrNew;
199 }
200 else
201 {
202 pVM->pgm.s.pRamRangesHC = pNew;
203 pVM->pgm.s.pRamRangesGC = GCPtrNew;
204 }
205 pgmUnlock(pVM);
206 }
207 return rc;
208}
209
210
211/**
212 * Register a chunk of a the physical memory range with PGM. MM is responsible
213 * for the toplevel things - allocation and locking - while PGM is taking
214 * care of all the details and implements the physical address space virtualization.
215 *
216 *
217 * @returns VBox status.
218 * @param pVM The VM handle.
219 * @param pvRam HC virtual address of the RAM range. (page aligned)
220 * @param GCPhys GC physical address of the RAM range. (page aligned)
221 * @param cb Size of the RAM range. (page aligned)
222 * @param fFlags Flags, MM_RAM_*.
223 * @param paPages Pointer an array of physical page descriptors.
224 * @param pszDesc Description string.
225 */
226PGMR3DECL(int) PGMR3PhysRegisterChunk(PVM pVM, void *pvRam, RTGCPHYS GCPhys, size_t cb, unsigned fFlags, const SUPPAGE *paPages, const char *pszDesc)
227{
228#ifdef PGM_DYNAMIC_RAM_ALLOC
229 NOREF(pszDesc);
230
231 /*
232 * Validate input.
233 * (Not so important because callers are only MMR3PhysRegister()
234 * and PGMR3HandlerPhysicalRegisterEx(), but anyway...)
235 */
236 Log(("PGMR3PhysRegisterChunk %08X %x bytes flags %x %s\n", GCPhys, cb, fFlags, pszDesc));
237
238 Assert(paPages);
239 Assert(pvRam);
240 Assert(!(fFlags & ~0xfff));
241 Assert(RT_ALIGN_Z(cb, PAGE_SIZE) == cb && cb);
242 Assert(RT_ALIGN_P(pvRam, PAGE_SIZE) == pvRam);
243 Assert(!(fFlags & ~(MM_RAM_FLAGS_RESERVED | MM_RAM_FLAGS_ROM | MM_RAM_FLAGS_MMIO | MM_RAM_FLAGS_MMIO2 | MM_RAM_FLAGS_DYNAMIC_ALLOC)));
244 Assert(RT_ALIGN_T(GCPhys, PAGE_SIZE, RTGCPHYS) == GCPhys);
245 Assert(VM_IS_EMT(pVM));
246 Assert(!(GCPhys & PGM_DYNAMIC_CHUNK_OFFSET_MASK));
247 Assert(cb == PGM_DYNAMIC_CHUNK_SIZE);
248
249 RTGCPHYS GCPhysLast = GCPhys + (cb - 1);
250 if (GCPhysLast < GCPhys)
251 {
252 AssertMsgFailed(("The range wraps! GCPhys=%VGp cb=%#x\n", GCPhys, cb));
253 return VERR_INVALID_PARAMETER;
254 }
255
256 /*
257 * Find existing range location.
258 */
259 PPGMRAMRANGE pRam = CTXSUFF(pVM->pgm.s.pRamRanges);
260 while (pRam)
261 {
262 RTGCPHYS off = GCPhys - pRam->GCPhys;
263 if ( off < pRam->cb
264 && (pRam->fFlags & MM_RAM_FLAGS_DYNAMIC_ALLOC))
265 break;
266
267 pRam = CTXSUFF(pRam->pNext);
268 }
269 AssertReturn(pRam, VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS);
270
271 unsigned off = (GCPhys - pRam->GCPhys) >> PAGE_SHIFT;
272 unsigned iPage = cb >> PAGE_SHIFT;
273 if (paPages)
274 {
275 while (iPage-- > 0)
276 pRam->aHCPhys[off + iPage] = (paPages[iPage].Phys & X86_PTE_PAE_PG_MASK) | fFlags;
277 }
278 off >>= (PGM_DYNAMIC_CHUNK_SHIFT - PAGE_SHIFT);
279 pRam->pavHCChunkHC[off] = pvRam;
280
281 /* Notify the recompiler. */
282 REMR3NotifyPhysRamChunkRegister(pVM, GCPhys, PGM_DYNAMIC_CHUNK_SIZE, (RTHCUINTPTR)pvRam, fFlags);
283
284 return VINF_SUCCESS;
285#else /* !PGM_DYNAMIC_RAM_ALLOC */
286 AssertReleaseMsgFailed(("Shouldn't ever get here when PGM_DYNAMIC_RAM_ALLOC isn't defined!\n"));
287 return VERR_INTERNAL_ERROR;
288#endif /* !PGM_DYNAMIC_RAM_ALLOC */
289}
290
291
292/**
293 * Allocate missing physical pages for an existing guest RAM range.
294 *
295 * @returns VBox status.
296 * @param pVM The VM handle.
297 * @param GCPhys GC physical address of the RAM range. (page aligned)
298 */
299PGMR3DECL(int) PGM3PhysGrowRange(PVM pVM, RTGCPHYS GCPhys)
300{
301 /*
302 * Walk range list.
303 */
304 pgmLock(pVM);
305
306 PPGMRAMRANGE pRam = CTXSUFF(pVM->pgm.s.pRamRanges);
307 while (pRam)
308 {
309 RTGCPHYS off = GCPhys - pRam->GCPhys;
310 if ( off < pRam->cb
311 && (pRam->fFlags & MM_RAM_FLAGS_DYNAMIC_ALLOC))
312 {
313 bool fRangeExists = false;
314 unsigned off = (GCPhys - pRam->GCPhys) >> PGM_DYNAMIC_CHUNK_SHIFT;
315
316 /** @note A request made from another thread may end up in EMT after somebody else has already allocated the range. */
317 if (pRam->pavHCChunkHC[off])
318 fRangeExists = true;
319
320 pgmUnlock(pVM);
321 if (fRangeExists)
322 return VINF_SUCCESS;
323 return pgmr3PhysGrowRange(pVM, GCPhys);
324 }
325
326 pRam = CTXSUFF(pRam->pNext);
327 }
328 pgmUnlock(pVM);
329 return VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS;
330}
331
332
333/**
334 * Allocate missing physical pages for an existing guest RAM range.
335 *
336 * @returns VBox status.
337 * @param pVM The VM handle.
338 * @param pRamRange RAM range
339 * @param GCPhys GC physical address of the RAM range. (page aligned)
340 */
341int pgmr3PhysGrowRange(PVM pVM, RTGCPHYS GCPhys)
342{
343 void *pvRam;
344 int rc;
345
346 /* We must execute this function in the EMT thread, otherwise we'll run into problems. */
347 if (!VM_IS_EMT(pVM))
348 {
349 PVMREQ pReq;
350
351 AssertMsg(!PDMCritSectIsOwner(&pVM->pgm.s.CritSect), ("We own the PGM lock -> deadlock danger!!\n"));
352
353 rc = VMR3ReqCall(pVM, &pReq, RT_INDEFINITE_WAIT, (PFNRT)PGM3PhysGrowRange, 2, pVM, GCPhys);
354 if (VBOX_SUCCESS(rc))
355 {
356 rc = pReq->iStatus;
357 VMR3ReqFree(pReq);
358 }
359 return rc;
360 }
361
362 /* Round down to chunk boundary */
363 GCPhys = GCPhys & PGM_DYNAMIC_CHUNK_BASE_MASK;
364
365 STAM_COUNTER_INC(&pVM->pgm.s.StatDynRamGrow);
366 STAM_COUNTER_ADD(&pVM->pgm.s.StatDynRamTotal, PGM_DYNAMIC_CHUNK_SIZE/(1024*1024));
367
368 Log(("pgmr3PhysGrowRange: allocate chunk of size 0x%X at %VGp\n", PGM_DYNAMIC_CHUNK_SIZE, GCPhys));
369
370 unsigned cPages = PGM_DYNAMIC_CHUNK_SIZE >> PAGE_SHIFT;
371 rc = SUPPageAlloc(cPages, &pvRam);
372 if (VBOX_SUCCESS(rc))
373 {
374 VMSTATE enmVMState = VMR3GetState(pVM);
375
376 rc = MMR3PhysRegisterEx(pVM, pvRam, GCPhys, PGM_DYNAMIC_CHUNK_SIZE, 0, MM_PHYS_TYPE_DYNALLOC_CHUNK, "Main Memory");
377 if ( VBOX_SUCCESS(rc)
378 || enmVMState != VMSTATE_RUNNING)
379 {
380 if (VBOX_FAILURE(rc))
381 {
382 AssertMsgFailed(("Out of memory while trying to allocate a guest RAM chunk at %VGp!\n", GCPhys));
383 LogRel(("PGM: Out of memory while trying to allocate a guest RAM chunk at %VGp (VMstate=%s)!\n", GCPhys, VMR3GetStateName(enmVMState)));
384 }
385 return rc;
386 }
387
388 SUPPageFree(pvRam, cPages);
389
390 LogRel(("pgmr3PhysGrowRange: out of memory. pause until the user resumes execution.\n"));
391
392 /* Pause first, then inform Main. */
393 rc = VMR3SuspendNoSave(pVM);
394 AssertRC(rc);
395
396 VMSetRuntimeError(pVM, false, "HostMemoryLow", "Unable to allocate and lock memory. The virtual machine will be paused. Please close applications to free up memory or close the VM.");
397
398 /* Wait for resume event; will only return in that case. If the VM is stopped, the EMT thread will be destroyed. */
399 rc = VMR3WaitForResume(pVM);
400
401 /* Retry */
402 LogRel(("pgmr3PhysGrowRange: VM execution resumed -> retry.\n"));
403 return pgmr3PhysGrowRange(pVM, GCPhys);
404 }
405 return rc;
406}
407
408
409/**
410 * Interface MMIO handler relocation calls.
411 *
412 * It relocates an existing physical memory range with PGM.
413 *
414 * @returns VBox status.
415 * @param pVM The VM handle.
416 * @param GCPhysOld Previous GC physical address of the RAM range. (page aligned)
417 * @param GCPhysNew New GC physical address of the RAM range. (page aligned)
418 * @param cb Size of the RAM range. (page aligned)
419 */
420PGMR3DECL(int) PGMR3PhysRelocate(PVM pVM, RTGCPHYS GCPhysOld, RTGCPHYS GCPhysNew, size_t cb)
421{
422 /*
423 * Validate input.
424 * (Not so important because callers are only MMR3PhysRelocate(),
425 * but anyway...)
426 */
427 Log(("PGMR3PhysRelocate Old %VGp New %VGp (%#x bytes)\n", GCPhysOld, GCPhysNew, cb));
428
429 Assert(RT_ALIGN_Z(cb, PAGE_SIZE) == cb && cb);
430 Assert(RT_ALIGN_T(GCPhysOld, PAGE_SIZE, RTGCPHYS) == GCPhysOld);
431 Assert(RT_ALIGN_T(GCPhysNew, PAGE_SIZE, RTGCPHYS) == GCPhysNew);
432 RTGCPHYS GCPhysLast;
433 GCPhysLast = GCPhysOld + (cb - 1);
434 if (GCPhysLast < GCPhysOld)
435 {
436 AssertMsgFailed(("The old range wraps! GCPhys=%VGp cb=%#x\n", GCPhysOld, cb));
437 return VERR_INVALID_PARAMETER;
438 }
439 GCPhysLast = GCPhysNew + (cb - 1);
440 if (GCPhysLast < GCPhysNew)
441 {
442 AssertMsgFailed(("The new range wraps! GCPhys=%VGp cb=%#x\n", GCPhysNew, cb));
443 return VERR_INVALID_PARAMETER;
444 }
445
446 /*
447 * Find and remove old range location.
448 */
449 pgmLock(pVM);
450 PPGMRAMRANGE pPrev = NULL;
451 PPGMRAMRANGE pCur = pVM->pgm.s.pRamRangesHC;
452 while (pCur)
453 {
454 if (pCur->GCPhys == GCPhysOld && pCur->cb == cb)
455 break;
456
457 /* next */
458 pPrev = pCur;
459 pCur = pCur->pNextHC;
460 }
461 if (pPrev)
462 {
463 pPrev->pNextHC = pCur->pNextHC;
464 pPrev->pNextGC = pCur->pNextGC;
465 }
466 else
467 {
468 pVM->pgm.s.pRamRangesHC = pCur->pNextHC;
469 pVM->pgm.s.pRamRangesGC = pCur->pNextGC;
470 }
471
472 /*
473 * Update the range.
474 */
475 pCur->GCPhys = GCPhysNew;
476 pCur->GCPhysLast= GCPhysLast;
477 PPGMRAMRANGE pNew = pCur;
478
479 /*
480 * Find range location and check for conflicts.
481 */
482 pPrev = NULL;
483 pCur = pVM->pgm.s.pRamRangesHC;
484 while (pCur)
485 {
486 if (GCPhysNew <= pCur->GCPhysLast && GCPhysLast >= pCur->GCPhys)
487 {
488 AssertMsgFailed(("Conflict! This cannot happen!\n"));
489 pgmUnlock(pVM);
490 return VERR_PGM_RAM_CONFLICT;
491 }
492 if (GCPhysLast < pCur->GCPhys)
493 break;
494
495 /* next */
496 pPrev = pCur;
497 pCur = pCur->pNextHC;
498 }
499
500 /*
501 * Reinsert the RAM range.
502 */
503 pNew->pNextHC = pCur;
504 pNew->pNextGC = pCur ? MMHyperHC2GC(pVM, pCur) : 0;
505 if (pPrev)
506 {
507 pPrev->pNextHC = pNew;
508 pPrev->pNextGC = MMHyperHC2GC(pVM, pNew);
509 }
510 else
511 {
512 pVM->pgm.s.pRamRangesHC = pNew;
513 pVM->pgm.s.pRamRangesGC = MMHyperHC2GC(pVM, pNew);
514 }
515
516 pgmUnlock(pVM);
517 return VINF_SUCCESS;
518}
519
520
521/**
522 * Interface MMR3RomRegister() and MMR3PhysReserve calls to update the
523 * flags of existing RAM ranges.
524 *
525 * @returns VBox status.
526 * @param pVM The VM handle.
527 * @param GCPhys GC physical address of the RAM range. (page aligned)
528 * @param cb Size of the RAM range. (page aligned)
529 * @param fFlags The Or flags, MM_RAM_* \#defines.
530 * @param fMask The and mask for the flags.
531 */
532PGMR3DECL(int) PGMR3PhysSetFlags(PVM pVM, RTGCPHYS GCPhys, size_t cb, unsigned fFlags, unsigned fMask)
533{
534 Log(("PGMR3PhysSetFlags %08X %x %x %x\n", GCPhys, cb, fFlags, fMask));
535
536 /*
537 * Validate input.
538 * (Not so important because caller is always MMR3RomRegister() and MMR3PhysReserve(), but anyway...)
539 */
540 Assert(!(fFlags & ~(MM_RAM_FLAGS_RESERVED | MM_RAM_FLAGS_ROM | MM_RAM_FLAGS_MMIO | MM_RAM_FLAGS_MMIO2)));
541 Assert(RT_ALIGN_Z(cb, PAGE_SIZE) == cb && cb);
542 Assert(RT_ALIGN_T(GCPhys, PAGE_SIZE, RTGCPHYS) == GCPhys);
543 RTGCPHYS GCPhysLast = GCPhys + (cb - 1);
544 AssertReturn(GCPhysLast > GCPhys, VERR_INVALID_PARAMETER);
545
546 /*
547 * Lookup the range.
548 */
549 PPGMRAMRANGE pRam = CTXSUFF(pVM->pgm.s.pRamRanges);
550 while (pRam && GCPhys > pRam->GCPhysLast)
551 pRam = CTXSUFF(pRam->pNext);
552 if ( !pRam
553 || GCPhys > pRam->GCPhysLast
554 || GCPhysLast < pRam->GCPhys)
555 {
556 AssertMsgFailed(("No RAM range for %VGp-%VGp\n", GCPhys, GCPhysLast));
557 return VERR_INVALID_PARAMETER;
558 }
559
560 /*
561 * Update the requested flags.
562 */
563 RTHCPHYS fFullMask = ~(RTHCPHYS)(MM_RAM_FLAGS_RESERVED | MM_RAM_FLAGS_ROM | MM_RAM_FLAGS_MMIO | MM_RAM_FLAGS_MMIO2)
564 | fMask;
565 unsigned iPageEnd = (GCPhysLast - pRam->GCPhys + 1) >> PAGE_SHIFT;
566 unsigned iPage = (GCPhys - pRam->GCPhys) >> PAGE_SHIFT;
567 for ( ; iPage < iPageEnd; iPage++)
568 pRam->aHCPhys[iPage] = (pRam->aHCPhys[iPage] & fFullMask) | fFlags;
569
570 return VINF_SUCCESS;
571}
572
573
574/**
575 * Sets the Address Gate 20 state.
576 *
577 * @param pVM VM handle.
578 * @param fEnable True if the gate should be enabled.
579 * False if the gate should be disabled.
580 */
581PGMDECL(void) PGMR3PhysSetA20(PVM pVM, bool fEnable)
582{
583 LogFlow(("PGMR3PhysSetA20 %d (was %d)\n", fEnable, pVM->pgm.s.fA20Enabled));
584 if (pVM->pgm.s.fA20Enabled != (RTUINT)fEnable)
585 {
586 pVM->pgm.s.fA20Enabled = fEnable;
587 pVM->pgm.s.GCPhysA20Mask = ~(RTGCPHYS)(!fEnable << 20);
588 REMR3A20Set(pVM, fEnable);
589 }
590}
591
592
593/*
594 * PGMR3PhysReadByte/Word/Dword
595 * PGMR3PhysWriteByte/Word/Dword
596 */
597
598#define PGMPHYSFN_READNAME PGMR3PhysReadByte
599#define PGMPHYSFN_WRITENAME PGMR3PhysWriteByte
600#define PGMPHYS_DATASIZE 1
601#define PGMPHYS_DATATYPE uint8_t
602#include "PGMPhys.h"
603
604#define PGMPHYSFN_READNAME PGMR3PhysReadWord
605#define PGMPHYSFN_WRITENAME PGMR3PhysWriteWord
606#define PGMPHYS_DATASIZE 2
607#define PGMPHYS_DATATYPE uint16_t
608#include "PGMPhys.h"
609
610#define PGMPHYSFN_READNAME PGMR3PhysReadDword
611#define PGMPHYSFN_WRITENAME PGMR3PhysWriteDword
612#define PGMPHYS_DATASIZE 4
613#define PGMPHYS_DATATYPE uint32_t
614#include "PGMPhys.h"
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