VirtualBox

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

Last change on this file since 24323 was 22939, checked in by vboxsync, 15 years ago

MMInternal.h: typo.

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