VirtualBox

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

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

build hacking.

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