VirtualBox

source: vbox/trunk/src/VBox/VMM/MMInternal.h@ 12986

Last change on this file since 12986 was 12968, checked in by vboxsync, 16 years ago

#1865: MM done for now (needs revisiting later).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 25.1 KB
Line 
1/* $Id: MMInternal.h 12968 2008-10-03 00:16:13Z vboxsync $ */
2/** @file
3 * MM - Internal header file.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22#ifndef ___MMInternal_h
23#define ___MMInternal_h
24
25#include <VBox/cdefs.h>
26#include <VBox/types.h>
27#include <VBox/sup.h>
28#include <VBox/stam.h>
29#include <iprt/avl.h>
30#include <iprt/critsect.h>
31
32
33#if !defined(IN_MM_R3) && !defined(IN_MM_R0) && !defined(IN_MM_GC)
34# error "Not in MM! This is an internal header!"
35#endif
36
37
38/** @defgroup grp_mm_int Internals
39 * @internal
40 * @ingroup grp_mm
41 * @{
42 */
43
44/** @name VM Ring-3 Heap Internals
45 * @{
46 */
47
48/** @def MMR3HEAP_WITH_STATISTICS
49 * Enable MMR3Heap statistics.
50 */
51#if !defined(MMR3HEAP_WITH_STATISTICS) && defined(VBOX_WITH_STATISTICS)
52# define MMR3HEAP_WITH_STATISTICS
53#endif
54
55/** @def MMR3HEAP_SIZE_ALIGNMENT
56 * The allocation size alignment of the MMR3Heap.
57 */
58#define MMR3HEAP_SIZE_ALIGNMENT 16
59
60/**
61 * Heap statistics record.
62 * There is one global and one per allocation tag.
63 */
64typedef struct MMHEAPSTAT
65{
66 /** Core avl node, key is the tag. */
67 AVLULNODECORE Core;
68 /** Pointer to the heap the memory belongs to. */
69 struct MMHEAP *pHeap;
70#ifdef MMR3HEAP_WITH_STATISTICS
71 /** Number of allocation. */
72 uint64_t cAllocations;
73 /** Number of reallocations. */
74 uint64_t cReallocations;
75 /** Number of frees. */
76 uint64_t cFrees;
77 /** Failures. */
78 uint64_t cFailures;
79 /** Number of bytes allocated (sum). */
80 uint64_t cbAllocated;
81 /** Number of bytes freed. */
82 uint64_t cbFreed;
83 /** Number of bytes currently allocated. */
84 size_t cbCurAllocated;
85#endif
86} MMHEAPSTAT;
87/** Pointer to heap statistics record. */
88typedef MMHEAPSTAT *PMMHEAPSTAT;
89
90
91
92/**
93 * Additional heap block header for relating allocations to the VM.
94 */
95typedef struct MMHEAPHDR
96{
97 /** Pointer to the next record. */
98 struct MMHEAPHDR *pNext;
99 /** Pointer to the previous record. */
100 struct MMHEAPHDR *pPrev;
101 /** Pointer to the heap statistics record.
102 * (Where the a PVM can be found.) */
103 PMMHEAPSTAT pStat;
104 /** Size of the allocation (including this header). */
105 size_t cbSize;
106} MMHEAPHDR;
107/** Pointer to MM heap header. */
108typedef MMHEAPHDR *PMMHEAPHDR;
109
110
111/** MM Heap structure. */
112typedef struct MMHEAP
113{
114 /** Lock protecting the heap. */
115 RTCRITSECT Lock;
116 /** Heap block list head. */
117 PMMHEAPHDR pHead;
118 /** Heap block list tail. */
119 PMMHEAPHDR pTail;
120 /** Heap per tag statistics tree. */
121 PAVLULNODECORE pStatTree;
122 /** The VM handle. */
123 PUVM pUVM;
124 /** Heap global statistics. */
125 MMHEAPSTAT Stat;
126} MMHEAP;
127/** Pointer to MM Heap structure. */
128typedef MMHEAP *PMMHEAP;
129
130/** @} */
131
132
133
134/** @name Hypervisor Heap Internals
135 * @{
136 */
137
138/** @def MMHYPER_HEAP_FREE_DELAY
139 * If defined, it indicates the number of frees that should be delayed.
140 */
141#if defined(DOXYGEN_RUNNING)
142# define MMHYPER_HEAP_FREE_DELAY 64
143#endif
144
145/** @def MMHYPER_HEAP_FREE_POISON
146 * If defined, it indicates that freed memory should be poisoned
147 * with the value it has.
148 */
149#if defined(VBOX_STRICT) || defined(DOXYGEN_RUNNING)
150# define MMHYPER_HEAP_FREE_POISON 0xcb
151#endif
152
153/** @def MMHYPER_HEAP_STRICT
154 * Enables a bunch of assertions in the heap code. */
155#if defined(VBOX_STRICT) || defined(DOXYGEN_RUNNING)
156# define MMHYPER_HEAP_STRICT 1
157# if 0 || defined(DOXYGEN_RUNNING)
158/** @def MMHYPER_HEAP_STRICT_FENCE
159 * Enables tail fence. */
160# define MMHYPER_HEAP_STRICT_FENCE
161/** @def MMHYPER_HEAP_STRICT_FENCE_SIZE
162 * The fence size in bytes. */
163# define MMHYPER_HEAP_STRICT_FENCE_SIZE 256
164/** @def MMHYPER_HEAP_STRICT_FENCE_U32
165 * The fence filler. */
166# define MMHYPER_HEAP_STRICT_FENCE_U32 UINT32_C(0xdeadbeef)
167# endif
168#endif
169
170/**
171 * Hypervisor heap statistics record.
172 * There is one global and one per allocation tag.
173 */
174typedef struct MMHYPERSTAT
175{
176 /** Core avl node, key is the tag.
177 * @todo The type is wrong! Get your lazy a$$ over and create that offsetted uint32_t version we need here! */
178 AVLOGCPHYSNODECORE Core;
179 /** Aligning the 64-bit fields on a 64-bit line. */
180 uint32_t u32Padding0;
181 /** Indicator for whether these statistics are registered with STAM or not. */
182 bool fRegistered;
183 /** Number of allocation. */
184 uint64_t cAllocations;
185 /** Number of frees. */
186 uint64_t cFrees;
187 /** Failures. */
188 uint64_t cFailures;
189 /** Number of bytes allocated (sum). */
190 uint64_t cbAllocated;
191 /** Number of bytes freed (sum). */
192 uint64_t cbFreed;
193 /** Number of bytes currently allocated. */
194 uint32_t cbCurAllocated;
195 /** Max number of bytes allocated. */
196 uint32_t cbMaxAllocated;
197} MMHYPERSTAT;
198/** Pointer to hypervisor heap statistics record. */
199typedef MMHYPERSTAT *PMMHYPERSTAT;
200
201/**
202 * Hypervisor heap chunk.
203 */
204typedef struct MMHYPERCHUNK
205{
206 /** Previous block in the list of all blocks.
207 * This is relative to the start of the heap. */
208 uint32_t offNext;
209 /** Offset to the previous block relative to this one. */
210 int32_t offPrev;
211 /** The statistics record this allocation belongs to (self relative). */
212 int32_t offStat;
213 /** Offset to the heap block (self relative). */
214 int32_t offHeap;
215} MMHYPERCHUNK;
216/** Pointer to a hypervisor heap chunk. */
217typedef MMHYPERCHUNK *PMMHYPERCHUNK;
218
219
220/**
221 * Hypervisor heap chunk.
222 */
223typedef struct MMHYPERCHUNKFREE
224{
225 /** Main list. */
226 MMHYPERCHUNK core;
227 /** Offset of the next chunk in the list of free nodes. */
228 uint32_t offNext;
229 /** Offset of the previous chunk in the list of free nodes. */
230 int32_t offPrev;
231 /** Size of the block. */
232 uint32_t cb;
233} MMHYPERCHUNKFREE;
234/** Pointer to a free hypervisor heap chunk. */
235typedef MMHYPERCHUNKFREE *PMMHYPERCHUNKFREE;
236
237
238/**
239 * The hypervisor heap.
240 */
241typedef struct MMHYPERHEAP
242{
243 /** The typical magic (MMHYPERHEAP_MAGIC). */
244 uint32_t u32Magic;
245 /** The heap size. (This structure is not included!) */
246 uint32_t cbHeap;
247 /** The HC ring-3 address of the heap. */
248 R3PTRTYPE(uint8_t *) pbHeapR3;
249 /** The HC ring-3 address of the shared VM strcture. */
250 PVMR3 pVMR3;
251 /** The HC ring-0 address of the heap. */
252 R0PTRTYPE(uint8_t *) pbHeapR0;
253 /** The HC ring-0 address of the shared VM strcture. */
254 PVMR0 pVMR0;
255 /** The RC address of the heap. */
256 RCPTRTYPE(uint8_t *) pbHeapRC;
257 /** The RC address of the shared VM strcture. */
258 PVMRC pVMRC;
259 /** The amount of free memory in the heap. */
260 uint32_t cbFree;
261 /** Offset of the first free chunk in the heap.
262 * The offset is relative to the start of the heap. */
263 uint32_t offFreeHead;
264 /** Offset of the last free chunk in the heap.
265 * The offset is relative to the start of the heap. */
266 uint32_t offFreeTail;
267 /** Offset of the first page aligned block in the heap.
268 * The offset is equal to cbHeap initially. */
269 uint32_t offPageAligned;
270 /** Tree of hypervisor heap statistics. */
271 AVLOGCPHYSTREE HyperHeapStatTree;
272#ifdef MMHYPER_HEAP_FREE_DELAY
273 /** Where to insert the next free. */
274 uint32_t iDelayedFree;
275 /** Array of delayed frees. Circular. Offsets relative to this structure. */
276 struct
277 {
278 /** The free caller address. */
279 RTUINTPTR uCaller;
280 /** The offset of the freed chunk. */
281 uint32_t offChunk;
282 } aDelayedFrees[MMHYPER_HEAP_FREE_DELAY];
283#else
284 /** Padding the structure to a 64-bit aligned size. */
285 uint32_t u32Padding0;
286#endif
287} MMHYPERHEAP;
288/** Pointer to the hypervisor heap. */
289typedef MMHYPERHEAP *PMMHYPERHEAP;
290
291/** Magic value for MMHYPERHEAP. (C. S. Lewis) */
292#define MMHYPERHEAP_MAGIC UINT32_C(0x18981129)
293
294
295/**
296 * Hypervisor heap minimum alignment (16 bytes).
297 */
298#define MMHYPER_HEAP_ALIGN_MIN 16
299
300/**
301 * The aligned size of the the MMHYPERHEAP structure.
302 */
303#define MMYPERHEAP_HDR_SIZE RT_ALIGN_Z(sizeof(MMHYPERHEAP), MMHYPER_HEAP_ALIGN_MIN * 4)
304
305/** @name Hypervisor heap chunk flags.
306 * The flags are put in the first bits of the MMHYPERCHUNK::offPrev member.
307 * These bits aren't used anyway because of the chunk minimal alignment (16 bytes).
308 * @{ */
309/** The chunk is free. (The code ASSUMES this is 0!) */
310#define MMHYPERCHUNK_FLAGS_FREE 0x0
311/** The chunk is in use. */
312#define MMHYPERCHUNK_FLAGS_USED 0x1
313/** The type mask. */
314#define MMHYPERCHUNK_FLAGS_TYPE_MASK 0x1
315/** The flag mask */
316#define MMHYPERCHUNK_FLAGS_MASK 0x1
317
318/** Checks if the chunk is free. */
319#define MMHYPERCHUNK_ISFREE(pChunk) ( (((pChunk)->offPrev) & MMHYPERCHUNK_FLAGS_TYPE_MASK) == MMHYPERCHUNK_FLAGS_FREE )
320/** Checks if the chunk is used. */
321#define MMHYPERCHUNK_ISUSED(pChunk) ( (((pChunk)->offPrev) & MMHYPERCHUNK_FLAGS_TYPE_MASK) == MMHYPERCHUNK_FLAGS_USED )
322/** Toggles FREE/USED flag of a chunk. */
323#define MMHYPERCHUNK_SET_TYPE(pChunk, type) do { (pChunk)->offPrev = ((pChunk)->offPrev & ~MMHYPERCHUNK_FLAGS_TYPE_MASK) | ((type) & MMHYPERCHUNK_FLAGS_TYPE_MASK); } while (0)
324
325/** Gets the prev offset without the flags. */
326#define MMHYPERCHUNK_GET_OFFPREV(pChunk) ((int32_t)((pChunk)->offPrev & ~MMHYPERCHUNK_FLAGS_MASK))
327/** Sets the prev offset without changing the flags. */
328#define MMHYPERCHUNK_SET_OFFPREV(pChunk, off) do { (pChunk)->offPrev = (off) | ((pChunk)->offPrev & MMHYPERCHUNK_FLAGS_MASK); } while (0)
329#if 0
330/** Clears one or more flags. */
331#define MMHYPERCHUNK_FLAGS_OP_CLEAR(pChunk, fFlags) do { ((pChunk)->offPrev) &= ~((fFlags) & MMHYPERCHUNK_FLAGS_MASK); } while (0)
332/** Sets one or more flags. */
333#define MMHYPERCHUNK_FLAGS_OP_SET(pChunk, fFlags) do { ((pChunk)->offPrev) |= ((fFlags) & MMHYPERCHUNK_FLAGS_MASK); } while (0)
334/** Checks if one is set. */
335#define MMHYPERCHUNK_FLAGS_OP_ISSET(pChunk, fFlag) (!!(((pChunk)->offPrev) & ((fFlag) & MMHYPERCHUNK_FLAGS_MASK)))
336#endif
337/** @} */
338
339/** @} */
340
341
342/** @name Page Pool Internals
343 * @{
344 */
345
346/**
347 * Page sub pool
348 *
349 * About the allocation of this structure. To keep the number of heap blocks,
350 * the number of heap calls, and fragmentation low we allocate all the data
351 * related to a MMPAGESUBPOOL node in one chunk. That means that after the
352 * bitmap (which is of variable size) comes the SUPPAGE records and then
353 * follows the lookup tree nodes. (The heap in question is the hyper heap.)
354 */
355typedef struct MMPAGESUBPOOL
356{
357 /** Pointer to next sub pool. */
358 R3R0PTRTYPE(struct MMPAGESUBPOOL *) pNext;
359 /** Pointer to next sub pool in the free chain.
360 * This is NULL if we're not in the free chain or at the end of it. */
361 R3R0PTRTYPE(struct MMPAGESUBPOOL *) pNextFree;
362 /** Pointer to array of lock ranges.
363 * This is allocated together with the MMPAGESUBPOOL and thus needs no freeing.
364 * It follows immediately after the bitmap.
365 * The reserved field is a pointer to this structure.
366 */
367 R3R0PTRTYPE(PSUPPAGE) paPhysPages;
368 /** Pointer to the first page. */
369 R3R0PTRTYPE(void *) pvPages;
370 /** Size of the subpool. */
371 unsigned cPages;
372 /** Number of free pages. */
373 unsigned cPagesFree;
374 /** The allocation bitmap.
375 * This may extend beyond the end of the defined array size.
376 */
377 unsigned auBitmap[1];
378 /* ... SUPPAGE aRanges[1]; */
379} MMPAGESUBPOOL;
380/** Pointer to page sub pool. */
381typedef MMPAGESUBPOOL *PMMPAGESUBPOOL;
382
383/**
384 * Page pool.
385 */
386typedef struct MMPAGEPOOL
387{
388 /** List of subpools. */
389 R3R0PTRTYPE(PMMPAGESUBPOOL) pHead;
390 /** Head of subpools with free pages. */
391 R3R0PTRTYPE(PMMPAGESUBPOOL) pHeadFree;
392 /** AVLPV tree for looking up HC virtual addresses.
393 * The tree contains MMLOOKUPVIRTPP records.
394 */
395 R3R0PTRTYPE(PAVLPVNODECORE) pLookupVirt;
396 /** Tree for looking up HC physical addresses.
397 * The tree contains MMLOOKUPPHYSHC records.
398 */
399 R3R0PTRTYPE(AVLHCPHYSTREE) pLookupPhys;
400 /** Pointer to the VM this pool belongs. */
401 R3R0PTRTYPE(PVM) pVM;
402 /** Flag indicating the allocation method.
403 * Set: SUPLowAlloc().
404 * Clear: SUPPageAlloc() + SUPPageLock(). */
405 bool fLow;
406 /** Number of subpools. */
407 uint32_t cSubPools;
408 /** Number of pages in pool. */
409 uint32_t cPages;
410#ifdef VBOX_WITH_STATISTICS
411 /** Number of free pages in pool. */
412 uint32_t cFreePages;
413 /** Number of alloc calls. */
414 STAMCOUNTER cAllocCalls;
415 /** Number of free calls. */
416 STAMCOUNTER cFreeCalls;
417 /** Number of to phys conversions. */
418 STAMCOUNTER cToPhysCalls;
419 /** Number of to virtual conversions. */
420 STAMCOUNTER cToVirtCalls;
421 /** Number of real errors. */
422 STAMCOUNTER cErrors;
423#endif
424} MMPAGEPOOL;
425/** Pointer to page pool. */
426typedef MMPAGEPOOL *PMMPAGEPOOL;
427
428/**
429 * Lookup record for HC virtual memory in the page pool.
430 */
431typedef struct MMPPLOOKUPHCPTR
432{
433 /** The key is virtual address. */
434 AVLPVNODECORE Core;
435 /** Pointer to subpool if lookup record for a pool. */
436 struct MMPAGESUBPOOL *pSubPool;
437} MMPPLOOKUPHCPTR;
438/** Pointer to virtual memory lookup record. */
439typedef MMPPLOOKUPHCPTR *PMMPPLOOKUPHCPTR;
440
441/**
442 * Lookup record for HC physical memory.
443 */
444typedef struct MMPPLOOKUPHCPHYS
445{
446 /** The key is physical address. */
447 AVLHCPHYSNODECORE Core;
448 /** Pointer to SUPPAGE record for this physical address. */
449 PSUPPAGE pPhysPage;
450} MMPPLOOKUPHCPHYS;
451/** Pointer to physical memory lookup record. */
452typedef MMPPLOOKUPHCPHYS *PMMPPLOOKUPHCPHYS;
453
454/** @} */
455
456
457
458/**
459 * Type of memory that's locked.
460 */
461typedef enum MMLOCKEDTYPE
462{
463 /** Hypervisor: Ring-3 memory locked by MM. */
464 MM_LOCKED_TYPE_HYPER,
465 /** Hypervisor: Ring-3 memory locked by MM that shouldn't be freed up. */
466 MM_LOCKED_TYPE_HYPER_NOFREE,
467 /** Hypervisor: Pre-locked ring-3 pages. */
468 MM_LOCKED_TYPE_HYPER_PAGES,
469 /** Guest: Physical VM memory (RAM & MMIO2). */
470 MM_LOCKED_TYPE_PHYS
471} MMLOCKEDTYPE;
472/** Pointer to memory type. */
473typedef MMLOCKEDTYPE *PMMLOCKEDTYPE;
474
475
476/**
477 * Converts a SUPPAGE pointer to a MMLOCKEDMEM pointer.
478 * @returns Pointer to the MMLOCKEDMEM record the range is associated with.
479 * @param pSupPage Pointer to SUPPAGE structure managed by MM.
480 */
481#define MM_SUPRANGE_TO_MMLOCKEDMEM(pSupPage) ((PMMLOCKEDMEM)pSupPage->uReserved)
482
483
484/**
485 * Locked memory record.
486 */
487typedef struct MMLOCKEDMEM
488{
489 /** Address (host mapping). */
490 void *pv;
491 /** Size. */
492 size_t cb;
493 /** Next record. */
494 struct MMLOCKEDMEM *pNext;
495 /** Record type. */
496 MMLOCKEDTYPE eType;
497 /** Type specific data. */
498 union
499 {
500 /** Data for MM_LOCKED_TYPE_HYPER, MM_LOCKED_TYPE_HYPER_NOFREE and MM_LOCKED_TYPE_HYPER_PAGES. */
501 struct
502 {
503 unsigned uNothing;
504 } hyper;
505
506 /** Data for MM_LOCKED_TYPE_PHYS. */
507 struct
508 {
509 /** The GC physical address.
510 * (Assuming that this is a linear range of GC physical pages.)
511 */
512 RTGCPHYS GCPhys;
513 } phys;
514 } u;
515
516 /** Physical Page Array. (Variable length.)
517 * The uReserved field contains pointer to the MMLOCKMEM record.
518 * Use the macro MM_SUPPAGE_TO_MMLOCKEDMEM() to convert.
519 *
520 * For MM_LOCKED_TYPE_PHYS the low 12 bits of the pvPhys member
521 * are bits (MM_RAM_FLAGS_*) and not part of the physical address.
522 */
523 SUPPAGE aPhysPages[1];
524} MMLOCKEDMEM;
525/** Pointer to locked memory. */
526typedef MMLOCKEDMEM *PMMLOCKEDMEM;
527
528
529/**
530 * A registered Rom range.
531 *
532 * This is used to track ROM registrations both for debug reasons
533 * and for resetting shadow ROM at reset.
534 *
535 * This is allocated of the MMR3Heap and thus only accessibel from ring-3.
536 */
537typedef struct MMROMRANGE
538{
539 /** Pointer to the next */
540 struct MMROMRANGE *pNext;
541 /** Address of the range. */
542 RTGCPHYS GCPhys;
543 /** Size of the range. */
544 uint32_t cbRange;
545 /** Shadow ROM? */
546 bool fShadow;
547 /** Is the shadow ROM currently wriable? */
548 bool fWritable;
549 /** The address of the virgin ROM image for shadow ROM. */
550 const void *pvBinary;
551 /** The address of the guest RAM that's shadowing the ROM. (lazy bird) */
552 void *pvCopy;
553 /** The ROM description. */
554 const char *pszDesc;
555} MMROMRANGE;
556/** Pointer to a ROM range. */
557typedef MMROMRANGE *PMMROMRANGE;
558
559
560/**
561 * Hypervisor memory mapping type.
562 */
563typedef enum MMLOOKUPHYPERTYPE
564{
565 /** Invalid record. This is used for record which are incomplete. */
566 MMLOOKUPHYPERTYPE_INVALID = 0,
567 /** Mapping of locked memory. */
568 MMLOOKUPHYPERTYPE_LOCKED,
569 /** Mapping of contiguous HC physical memory. */
570 MMLOOKUPHYPERTYPE_HCPHYS,
571 /** Mapping of contiguous GC physical memory. */
572 MMLOOKUPHYPERTYPE_GCPHYS,
573 /** Mapping of MMIO2 memory. */
574 MMLOOKUPHYPERTYPE_MMIO2,
575 /** Dynamic mapping area (MMR3HyperReserve).
576 * A conversion will require to check what's in the page table for the pages. */
577 MMLOOKUPHYPERTYPE_DYNAMIC
578} MMLOOKUPHYPERTYPE;
579
580/**
581 * Lookup record for the hypervisor memory area.
582 */
583typedef struct MMLOOKUPHYPER
584{
585 /** Byte offset from the start of this record to the next.
586 * If the value is NIL_OFFSET the chain is terminated. */
587 int32_t offNext;
588 /** Offset into the hypvervisor memory area. */
589 uint32_t off;
590 /** Size of this part. */
591 uint32_t cb;
592 /** Locking type. */
593 MMLOOKUPHYPERTYPE enmType;
594 /** Type specific data */
595 union
596 {
597 /** Locked memory. */
598 struct
599 {
600 /** Host context pointer. */
601 R3PTRTYPE(void *) pvR3;
602 /** Host context ring-0 pointer. */
603 /** @todo #1865: Check if this actually works (doubt it) */
604 RTR0PTR pvR0;
605 /** Pointer to the locked mem record. */
606 R3PTRTYPE(PMMLOCKEDMEM) pLockedMem;
607 } Locked;
608
609 /** Contiguous physical memory. */
610 struct
611 {
612 /** Host context pointer. */
613 R3PTRTYPE(void *) pvR3;
614 /** @todo #1865: Add a pvR0 here! */
615 /** HC physical address corresponding to pvR3. */
616 RTHCPHYS HCPhys;
617 } HCPhys;
618
619 /** Contiguous guest physical memory. */
620 struct
621 {
622 /** The memory address (Guest Context). */
623 RTGCPHYS GCPhys;
624 } GCPhys;
625
626 /** MMIO2 memory. */
627 struct
628 {
629 /** The device instance owning the MMIO2 region. */
630 PPDMDEVINSR3 pDevIns;
631 /** The region number. */
632 uint32_t iRegion;
633 /** The offset into the MMIO2 region. */
634 RTGCPHYS off;
635 } MMIO2;
636 } u;
637 /** Description. */
638 R3PTRTYPE(const char *) pszDesc;
639} MMLOOKUPHYPER;
640/** Pointer to a hypervisor memory lookup record. */
641typedef MMLOOKUPHYPER *PMMLOOKUPHYPER;
642
643
644/**
645 * Converts a MM pointer into a VM pointer.
646 * @returns Pointer to the VM structure the MM is part of.
647 * @param pMM Pointer to MM instance data.
648 */
649#define MM2VM(pMM) ( (PVM)((uint8_t *)pMM - pMM->offVM) )
650
651
652/**
653 * MM Data (part of VM)
654 */
655typedef struct MM
656{
657 /** Offset to the VM structure.
658 * See MM2VM(). */
659 RTINT offVM;
660
661 /** Set if MMR3InitPaging has been called. */
662 bool fDoneMMR3InitPaging;
663 /** Set if PGM has been initialized and we can safely call PGMR3Map(). */
664 bool fPGMInitialized;
665#if GC_ARCH_BITS == 64 || HC_ARCH_BITS == 64
666 uint32_t u32Padding1; /**< alignment padding. */
667#endif
668
669 /** Lookup list for the Hypervisor Memory Area.
670 * The offset is relative to the start of the heap.
671 * Use pHyperHeapR3, pHyperHeapR0 or pHypeRHeapRC to calculate the address.
672 */
673 RTUINT offLookupHyper;
674
675 /** The offset of the next static mapping in the Hypervisor Memory Area. */
676 RTUINT offHyperNextStatic;
677 /** The size of the HMA.
678 * Starts at 12MB and will be fixed late in the init process. */
679 RTUINT cbHyperArea;
680
681 /** Guest address of the Hypervisor Memory Area.
682 * @remarks It's still a bit open whether this should be change to RTRCPTR or
683 * remain a RTGCPTR. */
684 RTGCPTR pvHyperAreaGC;
685
686 /** The hypervisor heap (GC Ptr). */
687 RCPTRTYPE(PMMHYPERHEAP) pHyperHeapRC;
688#if HC_ARCH_BITS == 64 && GC_ARCH_BITS == 64
689 uint32_t u32Padding2;
690#endif
691
692 /** The hypervisor heap (R0 Ptr). */
693 R0PTRTYPE(PMMHYPERHEAP) pHyperHeapR0;
694 /** Page pool - R0 Ptr. */
695 R0PTRTYPE(PMMPAGEPOOL) pPagePoolR0;
696 /** Page pool pages in low memory R0 Ptr. */
697 R0PTRTYPE(PMMPAGEPOOL) pPagePoolLowR0;
698
699 /** The hypervisor heap (R3 Ptr). */
700 R3PTRTYPE(PMMHYPERHEAP) pHyperHeapR3;
701 /** Page pool - R3 Ptr. */
702 R3PTRTYPE(PMMPAGEPOOL) pPagePoolR3;
703 /** Page pool pages in low memory R3 Ptr. */
704 R3PTRTYPE(PMMPAGEPOOL) pPagePoolLowR3;
705 /** List of memory locks. (HC only) */
706 R3PTRTYPE(PMMLOCKEDMEM) pLockedMem;
707
708 /** Pointer to the dummy page.
709 * The dummy page is a paranoia thingy used for instance for pure MMIO RAM ranges
710 * to make sure any bugs will not harm whatever the system stores in the first
711 * physical page. */
712 R3PTRTYPE(void *) pvDummyPage;
713 /** Physical address of the dummy page. */
714 RTHCPHYS HCPhysDummyPage;
715
716 /** Size of the base RAM in bytes. (The CFGM RamSize value.) */
717 uint64_t cbRamBase;
718 /** The number of base RAM pages that PGM has reserved (GMM).
719 * @remarks Shadow ROMs will be counted twice (RAM+ROM), so it won't be 1:1 with
720 * what the guest sees. */
721 uint64_t cBasePages;
722 /** The number of shadow pages PGM has reserved (GMM). */
723 uint32_t cShadowPages;
724 /** The number of fixed pages we've reserved (GMM). */
725 uint32_t cFixedPages;
726
727 /** The head of the ROM ranges. */
728 R3PTRTYPE(PMMROMRANGE) pRomHead;
729} MM;
730/** Pointer to MM Data (part of VM). */
731typedef MM *PMM;
732
733
734/**
735 * MM data kept in the UVM.
736 */
737typedef struct MMUSERPERVM
738{
739 /** Pointer to the MM R3 Heap. */
740 R3PTRTYPE(PMMHEAP) pHeap;
741} MMUSERPERVM;
742/** Pointer to the MM data kept in the UVM. */
743typedef MMUSERPERVM *PMMUSERPERVM;
744
745
746__BEGIN_DECLS
747
748
749int mmR3UpdateReservation(PVM pVM);
750
751int mmR3PagePoolInit(PVM pVM);
752void mmR3PagePoolTerm(PVM pVM);
753
754int mmR3HeapCreateU(PUVM pUVM, PMMHEAP *ppHeap);
755void mmR3HeapDestroy(PMMHEAP pHeap);
756
757int mmR3HyperInit(PVM pVM);
758int mmR3HyperInitPaging(PVM pVM);
759
760int mmR3LockMem(PVM pVM, void *pv, size_t cb, MMLOCKEDTYPE eType, PMMLOCKEDMEM *ppLockedMem, bool fSilentFailure);
761int mmR3MapLocked(PVM pVM, PMMLOCKEDMEM pLockedMem, RTGCPTR Addr, unsigned iPage, size_t cPages, unsigned fFlags);
762
763const char *mmR3GetTagName(MMTAG enmTag);
764
765void mmR3PhysRomReset(PVM pVM);
766
767/**
768 * Converts a pool address to a physical address.
769 * The specified allocation type must match with the address.
770 *
771 * @returns Physical address.
772 * @returns NIL_RTHCPHYS if not found or eType is not matching.
773 * @param pPool Pointer to the page pool.
774 * @param pv The address to convert.
775 * @thread The Emulation Thread.
776 */
777MMDECL(RTHCPHYS) mmPagePoolPtr2Phys(PMMPAGEPOOL pPool, void *pv);
778
779/**
780 * Converts a pool physical address to a linear address.
781 * The specified allocation type must match with the address.
782 *
783 * @returns Physical address.
784 * @returns NULL if not found or eType is not matching.
785 * @param pPool Pointer to the page pool.
786 * @param HCPhys The address to convert.
787 * @thread The Emulation Thread.
788 */
789MMDECL(void *) mmPagePoolPhys2Ptr(PMMPAGEPOOL pPool, RTHCPHYS HCPhys);
790
791__END_DECLS
792
793/** @} */
794
795#endif
796
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