VirtualBox

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

Last change on this file since 8170 was 8155, checked in by vboxsync, 16 years ago

The Big Sun Rebranding Header Change

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 23.9 KB
Line 
1/* $Id: MMInternal.h 8155 2008-04-18 15:16:47Z 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__)
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__)
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__)
156# define MMHYPER_HEAP_STRICT 1
157# if 0 || defined(__DOXYGEN__)
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 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 VM. */
248 R3PTRTYPE(PVM) pVMHC;
249 /** The HC Ring-3 address of the heap. */
250 R3R0PTRTYPE(uint8_t *) pbHeapHC;
251 /** The GC address of the heap. */
252 GCPTRTYPE(uint8_t *) pbHeapGC;
253 /** The GC address of the VM. */
254 GCPTRTYPE(PVM) pVMGC;
255 /** The amount of free memory in the heap. */
256 uint32_t cbFree;
257 /** Offset of the first free chunk in the heap.
258 * The offset is relative to the start of the heap. */
259 uint32_t offFreeHead;
260 /** Offset of the last free chunk in the heap.
261 * The offset is relative to the start of the heap. */
262 uint32_t offFreeTail;
263 /** Offset of the first page aligned block in the heap.
264 * The offset is equal to cbHeap initially. */
265 uint32_t offPageAligned;
266 /** Tree of hypervisor heap statistics. */
267 AVLOGCPHYSTREE HyperHeapStatTree;
268#ifdef MMHYPER_HEAP_FREE_DELAY
269 /** Where to insert the next free. */
270 uint32_t iDelayedFree;
271 /** Array of delayed frees. Circular. Offsets relative to this structure. */
272 struct
273 {
274 /** The free caller address. */
275 RTUINTPTR uCaller;
276 /** The offset of the freed chunk. */
277 uint32_t offChunk;
278 } aDelayedFrees[MMHYPER_HEAP_FREE_DELAY];
279#else
280 /** Padding the structure to a 64-bit aligned size. */
281 uint32_t u32Padding0;
282#endif
283} MMHYPERHEAP;
284/** Pointer to the hypervisor heap. */
285typedef MMHYPERHEAP *PMMHYPERHEAP;
286
287/** Magic value for MMHYPERHEAP. (C. S. Lewis) */
288#define MMHYPERHEAP_MAGIC 0x18981129
289
290
291/**
292 * Hypervisor heap minimum alignment (16 bytes).
293 */
294#define MMHYPER_HEAP_ALIGN_MIN 16
295
296/**
297 * The aligned size of the the MMHYPERHEAP structure.
298 */
299#define MMYPERHEAP_HDR_SIZE RT_ALIGN_Z(sizeof(MMHYPERHEAP), MMHYPER_HEAP_ALIGN_MIN * 4)
300
301/** @name Hypervisor heap chunk flags.
302 * The flags are put in the first bits of the MMHYPERCHUNK::offPrev member.
303 * These bits aren't used anyway because of the chunk minimal alignment (16 bytes).
304 * @{ */
305/** The chunk is free. (The code ASSUMES this is 0!) */
306#define MMHYPERCHUNK_FLAGS_FREE 0x0
307/** The chunk is in use. */
308#define MMHYPERCHUNK_FLAGS_USED 0x1
309/** The type mask. */
310#define MMHYPERCHUNK_FLAGS_TYPE_MASK 0x1
311/** The flag mask */
312#define MMHYPERCHUNK_FLAGS_MASK 0x1
313
314/** Checks if the chunk is free. */
315#define MMHYPERCHUNK_ISFREE(pChunk) ( (((pChunk)->offPrev) & MMHYPERCHUNK_FLAGS_TYPE_MASK) == MMHYPERCHUNK_FLAGS_FREE )
316/** Checks if the chunk is used. */
317#define MMHYPERCHUNK_ISUSED(pChunk) ( (((pChunk)->offPrev) & MMHYPERCHUNK_FLAGS_TYPE_MASK) == MMHYPERCHUNK_FLAGS_USED )
318/** Toggles FREE/USED flag of a chunk. */
319#define MMHYPERCHUNK_SET_TYPE(pChunk, type) do { (pChunk)->offPrev = ((pChunk)->offPrev & ~MMHYPERCHUNK_FLAGS_TYPE_MASK) | ((type) & MMHYPERCHUNK_FLAGS_TYPE_MASK); } while (0)
320
321/** Gets the prev offset without the flags. */
322#define MMHYPERCHUNK_GET_OFFPREV(pChunk) ((int32_t)((pChunk)->offPrev & ~MMHYPERCHUNK_FLAGS_MASK))
323/** Sets the prev offset without changing the flags. */
324#define MMHYPERCHUNK_SET_OFFPREV(pChunk, off) do { (pChunk)->offPrev = (off) | ((pChunk)->offPrev & MMHYPERCHUNK_FLAGS_MASK); } while (0)
325#if 0
326/** Clears one or more flags. */
327#define MMHYPERCHUNK_FLAGS_OP_CLEAR(pChunk, fFlags) do { ((pChunk)->offPrev) &= ~((fFlags) & MMHYPERCHUNK_FLAGS_MASK); } while (0)
328/** Sets one or more flags. */
329#define MMHYPERCHUNK_FLAGS_OP_SET(pChunk, fFlags) do { ((pChunk)->offPrev) |= ((fFlags) & MMHYPERCHUNK_FLAGS_MASK); } while (0)
330/** Checks if one is set. */
331#define MMHYPERCHUNK_FLAGS_OP_ISSET(pChunk, fFlag) (!!(((pChunk)->offPrev) & ((fFlag) & MMHYPERCHUNK_FLAGS_MASK)))
332#endif
333/** @} */
334
335/** @} */
336
337
338/** @name Page Pool Internals
339 * @{
340 */
341
342/**
343 * Page sub pool
344 *
345 * About the allocation of this structrue. To keep the number of heap blocks,
346 * the number of heap calls, and fragmentation low we allocate all the data
347 * related to a MMPAGESUBPOOL node in one chunk. That means that after the
348 * bitmap (which is of variable size) comes the SUPPAGE records and then
349 * follows the lookup tree nodes.
350 */
351typedef struct MMPAGESUBPOOL
352{
353 /** Pointer to next sub pool. */
354 struct MMPAGESUBPOOL *pNext;
355 /** Pointer to next sub pool in the free chain.
356 * This is NULL if we're not in the free chain or at the end of it. */
357 struct MMPAGESUBPOOL *pNextFree;
358 /** Pointer to array of lock ranges.
359 * This is allocated together with the MMPAGESUBPOOL and thus needs no freeing.
360 * It follows immediately after the bitmap.
361 * The reserved field is a pointer to this structure.
362 */
363 PSUPPAGE paPhysPages;
364 /** Pointer to the first page. */
365 void *pvPages;
366 /** Size of the subpool. */
367 unsigned cPages;
368 /** Number of free pages. */
369 unsigned cPagesFree;
370 /** The allocation bitmap.
371 * This may extend beyond the end of the defined array size.
372 */
373 unsigned auBitmap[1];
374 /* ... SUPPAGE aRanges[1]; */
375} MMPAGESUBPOOL;
376/** Pointer to page sub pool. */
377typedef MMPAGESUBPOOL *PMMPAGESUBPOOL;
378
379/**
380 * Page pool.
381 */
382typedef struct MMPAGEPOOL
383{
384 /** List of subpools. */
385 PMMPAGESUBPOOL pHead;
386 /** Head of subpools with free pages. */
387 PMMPAGESUBPOOL pHeadFree;
388 /** AVLPV tree for looking up HC virtual addresses.
389 * The tree contains MMLOOKUPVIRTPP records.
390 */
391 PAVLPVNODECORE pLookupVirt;
392 /** Tree for looking up HC physical addresses.
393 * The tree contains MMLOOKUPPHYSHC records.
394 */
395 AVLHCPHYSTREE pLookupPhys;
396 /** Pointer to the VM this pool belongs. */
397 PVM pVM;
398 /** Flag indicating the allocation method.
399 * Set: SUPLowAlloc().
400 * Clear: SUPPageAlloc() + SUPPageLock(). */
401 bool fLow;
402 /** Number of subpools. */
403 uint32_t cSubPools;
404 /** Number of pages in pool. */
405 uint32_t cPages;
406#ifdef VBOX_WITH_STATISTICS
407 /** Number of free pages in pool. */
408 uint32_t cFreePages;
409 /** Number of alloc calls. */
410 STAMCOUNTER cAllocCalls;
411 /** Number of free calls. */
412 STAMCOUNTER cFreeCalls;
413 /** Number of to phys conversions. */
414 STAMCOUNTER cToPhysCalls;
415 /** Number of to virtual conversions. */
416 STAMCOUNTER cToVirtCalls;
417 /** Number of real errors. */
418 STAMCOUNTER cErrors;
419#endif
420} MMPAGEPOOL;
421/** Pointer to page pool. */
422typedef MMPAGEPOOL *PMMPAGEPOOL;
423
424/**
425 * Lookup record for HC virtual memory in the page pool.
426 */
427typedef struct MMPPLOOKUPHCPTR
428{
429 /** The key is virtual address. */
430 AVLPVNODECORE Core;
431 /** Pointer to subpool if lookup record for a pool. */
432 struct MMPAGESUBPOOL *pSubPool;
433} MMPPLOOKUPHCPTR;
434/** Pointer to virtual memory lookup record. */
435typedef MMPPLOOKUPHCPTR *PMMPPLOOKUPHCPTR;
436
437/**
438 * Lookup record for HC physical memory.
439 */
440typedef struct MMPPLOOKUPHCPHYS
441{
442 /** The key is physical address. */
443 AVLHCPHYSNODECORE Core;
444 /** Pointer to SUPPAGE record for this physical address. */
445 PSUPPAGE pPhysPage;
446} MMPPLOOKUPHCPHYS;
447/** Pointer to physical memory lookup record. */
448typedef MMPPLOOKUPHCPHYS *PMMPPLOOKUPHCPHYS;
449
450/** @} */
451
452
453
454/**
455 * Type of memory that's locked.
456 */
457typedef enum MMLOCKEDTYPE
458{
459 /** Hypervisor: Ring-3 memory locked by MM. */
460 MM_LOCKED_TYPE_HYPER,
461 /** Hypervisor: Ring-3 memory locked by MM that shouldn't be freed up. */
462 MM_LOCKED_TYPE_HYPER_NOFREE,
463 /** Hypervisor: Pre-locked ring-3 pages. */
464 MM_LOCKED_TYPE_HYPER_PAGES,
465 /** Guest: Physical VM memory (RAM & MMIO2). */
466 MM_LOCKED_TYPE_PHYS
467} MMLOCKEDTYPE;
468/** Pointer to memory type. */
469typedef MMLOCKEDTYPE *PMMLOCKEDTYPE;
470
471
472/**
473 * Converts a SUPPAGE pointer to a MMLOCKEDMEM pointer.
474 * @returns Pointer to the MMLOCKEDMEM record the range is associated with.
475 * @param pSupPage Pointer to SUPPAGE structure managed by MM.
476 */
477#define MM_SUPRANGE_TO_MMLOCKEDMEM(pSupPage) ((PMMLOCKEDMEM)pSupPage->uReserved)
478
479
480/**
481 * Locked memory record.
482 */
483typedef struct MMLOCKEDMEM
484{
485 /** Address (host mapping). */
486 void *pv;
487 /** Size. */
488 size_t cb;
489 /** Next record. */
490 struct MMLOCKEDMEM *pNext;
491 /** Record type. */
492 MMLOCKEDTYPE eType;
493 /** Type specific data. */
494 union
495 {
496 /** Data for MM_LOCKED_TYPE_HYPER, MM_LOCKED_TYPE_HYPER_NOFREE and MM_LOCKED_TYPE_HYPER_PAGES. */
497 struct
498 {
499 unsigned uNothing;
500 } hyper;
501
502 /** Data for MM_LOCKED_TYPE_PHYS. */
503 struct
504 {
505 /** The GC physical address.
506 * (Assuming that this is a linear range of GC physical pages.)
507 */
508 RTGCPHYS GCPhys;
509 } phys;
510 } u;
511
512 /** Physical Page Array. (Variable length.)
513 * The uReserved field contains pointer to the MMLOCKMEM record.
514 * Use the macro MM_SUPPAGE_TO_MMLOCKEDMEM() to convert.
515 *
516 * For MM_LOCKED_TYPE_PHYS the low 12 bits of the pvPhys member
517 * are bits (MM_RAM_FLAGS_*) and not part of the physical address.
518 */
519 SUPPAGE aPhysPages[1];
520} MMLOCKEDMEM;
521/** Pointer to locked memory. */
522typedef MMLOCKEDMEM *PMMLOCKEDMEM;
523
524
525/**
526 * A registered Rom range.
527 *
528 * This is used to track ROM registrations both for debug reasons
529 * and for resetting shadow ROM at reset.
530 *
531 * This is allocated of the MMR3Heap and thus only accessibel from ring-3.
532 */
533typedef struct MMROMRANGE
534{
535 /** Pointer to the next */
536 struct MMROMRANGE *pNext;
537 /** Address of the range. */
538 RTGCPHYS GCPhys;
539 /** Size of the range. */
540 uint32_t cbRange;
541 /** Shadow ROM? */
542 bool fShadow;
543 /** Is the shadow ROM currently wriable? */
544 bool fWritable;
545 /** The address of the virgin ROM image for shadow ROM. */
546 const void *pvBinary;
547 /** The address of the guest RAM that's shadowing the ROM. (lazy bird) */
548 void *pvCopy;
549 /** The ROM description. */
550 const char *pszDesc;
551} MMROMRANGE;
552/** Pointer to a ROM range. */
553typedef MMROMRANGE *PMMROMRANGE;
554
555
556/**
557 * Hypervisor memory mapping type.
558 */
559typedef enum MMLOOKUPHYPERTYPE
560{
561 /** Invalid record. This is used for record which are incomplete. */
562 MMLOOKUPHYPERTYPE_INVALID = 0,
563 /** Mapping of locked memory. */
564 MMLOOKUPHYPERTYPE_LOCKED,
565 /** Mapping of contiguous HC physical memory. */
566 MMLOOKUPHYPERTYPE_HCPHYS,
567 /** Mapping of contiguous GC physical memory. */
568 MMLOOKUPHYPERTYPE_GCPHYS,
569 /** Mapping of MMIO2 memory. */
570 MMLOOKUPHYPERTYPE_MMIO2,
571 /** Dynamic mapping area (MMR3HyperReserve).
572 * A conversion will require to check what's in the page table for the pages. */
573 MMLOOKUPHYPERTYPE_DYNAMIC
574} MMLOOKUPHYPERTYPE;
575
576/**
577 * Lookup record for the hypervisor memory area.
578 */
579typedef struct MMLOOKUPHYPER
580{
581 /** Byte offset from the start of this record to the next.
582 * If the value is NIL_OFFSET the chain is terminated. */
583 int32_t offNext;
584 /** Offset into the hypvervisor memory area. */
585 uint32_t off;
586 /** Size of this part. */
587 uint32_t cb;
588 /** Locking type. */
589 MMLOOKUPHYPERTYPE enmType;
590 /** Type specific data */
591 union
592 {
593 /** Locked memory. */
594 struct
595 {
596 /** Host context pointer. */
597 R3PTRTYPE(void *) pvHC;
598 /** Host context ring-0 pointer. */
599 RTR0PTR pvR0;
600 /** Pointer to the locked mem record. */
601 R3PTRTYPE(PMMLOCKEDMEM) pLockedMem;
602 } Locked;
603
604 /** Contiguous physical memory. */
605 struct
606 {
607 /** Host context pointer. */
608 R3PTRTYPE(void *) pvHC;
609 /** HC physical address corresponding to pvHC. */
610 RTHCPHYS HCPhys;
611 } HCPhys;
612 /** Contiguous guest physical memory. */
613 struct
614 {
615 /** HC physical address corresponding to pvHC. */
616 RTGCPHYS GCPhys;
617 } GCPhys;
618 /** MMIO2 memory. */
619 struct
620 {
621 /** The device instance owning the MMIO2 region. */
622 PPDMDEVINS pDevIns;
623 /** The region number. */
624 uint32_t iRegion;
625 /** The offset into the MMIO2 region. */
626 RTGCPHYS off;
627 } MMIO2;
628 } u;
629 /** Description. */
630 R3PTRTYPE(const char *) pszDesc;
631} MMLOOKUPHYPER;
632/** Pointer to a hypervisor memory lookup record. */
633typedef MMLOOKUPHYPER *PMMLOOKUPHYPER;
634
635
636/**
637 * Converts a MM pointer into a VM pointer.
638 * @returns Pointer to the VM structure the MM is part of.
639 * @param pMM Pointer to MM instance data.
640 */
641#define MM2VM(pMM) ( (PVM)((char*)pMM - pMM->offVM) )
642
643
644/**
645 * MM Data (part of VM)
646 */
647typedef struct MM
648{
649 /** Offset to the VM structure.
650 * See MM2VM(). */
651 RTINT offVM;
652
653 /** Set if MMR3InitPaging has been called. */
654 bool fDoneMMR3InitPaging;
655 /** Set if PGM has been initialized and we can safely call PGMR3Map(). */
656 bool fPGMInitialized;
657#if GC_ARCH_BITS == 64 || HC_ARCH_BITS == 64
658 uint32_t u32Padding1; /**< alignment padding. */
659#endif
660
661 /** Lookup list for the Hypervisor Memory Area.
662 * The offset is relative to the start of the heap.
663 * Use pHyperHeapHC or pHyperHeapGC to calculate the address.
664 */
665 RTUINT offLookupHyper;
666
667 /** The offset of the next static mapping in the Hypervisor Memory Area. */
668 RTUINT offHyperNextStatic;
669 /** The size of the HMA.
670 * Starts at 12MB and will be fixed late in the init process. */
671 RTUINT cbHyperArea;
672
673 /** Guest address of the Hypervisor Memory Area. */
674 RTGCPTR pvHyperAreaGC;
675
676 /** The hypervisor heap (GC Ptr). */
677 GCPTRTYPE(PMMHYPERHEAP) pHyperHeapGC;
678 /** The hypervisor heap (HC Ptr). */
679 R3R0PTRTYPE(PMMHYPERHEAP) pHyperHeapHC;
680
681 /** List of memory locks. (HC only) */
682 R3PTRTYPE(PMMLOCKEDMEM) pLockedMem;
683
684 /** Page pool. (HC only) */
685 R3R0PTRTYPE(PMMPAGEPOOL) pPagePool;
686 /** Page pool pages in low memory. (HC only) */
687 R3R0PTRTYPE(PMMPAGEPOOL) pPagePoolLow;
688
689 /** Pointer to the dummy page.
690 * The dummy page is a paranoia thingy used for instance for pure MMIO RAM ranges
691 * to make sure any bugs will not harm whatever the system stores in the first
692 * physical page. */
693 R3PTRTYPE(void *) pvDummyPage;
694 /** Physical address of the dummy page. */
695 RTHCPHYS HCPhysDummyPage;
696
697 /** Size of the base RAM in bytes. (The CFGM RamSize value.) */
698 uint64_t cbRamBase;
699 /** The number of base RAM pages that PGM has reserved (GMM).
700 * @remarks Shadow ROMs will be counted twice (RAM+ROM), so it won't be 1:1 with
701 * what the guest sees. */
702 uint64_t cBasePages;
703 /** The number of shadow pages PGM has reserved (GMM). */
704 uint32_t cShadowPages;
705 /** The number of fixed pages we've reserved (GMM). */
706 uint32_t cFixedPages;
707
708 /** The head of the ROM ranges. */
709 R3PTRTYPE(PMMROMRANGE) pRomHead;
710} MM;
711/** Pointer to MM Data (part of VM). */
712typedef MM *PMM;
713
714
715/**
716 * MM data kept in the UVM.
717 */
718typedef struct MMUSERPERVM
719{
720 /** Pointer to the MM R3 Heap. */
721 R3PTRTYPE(PMMHEAP) pHeap;
722} MMUSERPERVM;
723/** Pointer to the MM data kept in the UVM. */
724typedef MMUSERPERVM *PMMUSERPERVM;
725
726
727__BEGIN_DECLS
728
729
730int mmR3UpdateReservation(PVM pVM);
731
732int mmR3PagePoolInit(PVM pVM);
733void mmR3PagePoolTerm(PVM pVM);
734
735int mmR3HeapCreateU(PUVM pUVM, PMMHEAP *ppHeap);
736void mmR3HeapDestroy(PMMHEAP pHeap);
737
738int mmR3HyperInit(PVM pVM);
739int mmR3HyperInitPaging(PVM pVM);
740
741int mmR3LockMem(PVM pVM, void *pv, size_t cb, MMLOCKEDTYPE eType, PMMLOCKEDMEM *ppLockedMem, bool fSilentFailure);
742int mmR3MapLocked(PVM pVM, PMMLOCKEDMEM pLockedMem, RTGCPTR Addr, unsigned iPage, size_t cPages, unsigned fFlags);
743
744const char *mmR3GetTagName(MMTAG enmTag);
745
746void mmR3PhysRomReset(PVM pVM);
747
748/**
749 * Converts a pool address to a physical address.
750 * The specified allocation type must match with the address.
751 *
752 * @returns Physical address.
753 * @returns NIL_RTHCPHYS if not found or eType is not matching.
754 * @param pPool Pointer to the page pool.
755 * @param pv The address to convert.
756 * @thread The Emulation Thread.
757 */
758MMDECL(RTHCPHYS) mmPagePoolPtr2Phys(PMMPAGEPOOL pPool, void *pv);
759
760/**
761 * Converts a pool physical address to a linear address.
762 * The specified allocation type must match with the address.
763 *
764 * @returns Physical address.
765 * @returns NULL if not found or eType is not matching.
766 * @param pPool Pointer to the page pool.
767 * @param HCPhys The address to convert.
768 * @thread The Emulation Thread.
769 */
770MMDECL(void *) mmPagePoolPhys2Ptr(PMMPAGEPOOL pPool, RTHCPHYS HCPhys);
771
772__END_DECLS
773
774/** @} */
775
776#endif
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