begin rework of vmmap.c to use rbtree to track stuff, also added the
kernel_space manager code and a bunch of other bits and bobs
This commit is contained in:
@@ -45,7 +45,8 @@
|
||||
#define VMADDR_LIBRARY_FENCE 0xB0000000 /* base address for kernel "shared library" code */
|
||||
#define VMADDR_KERNEL_FENCE 0xC0000000 /* base address for the internal kernel code */
|
||||
#define VMADDR_IO_BASE 0xE0000000 /* base address for memory-mapped IO */
|
||||
#define PAGE_COUNT_IO 1024 /* 4 megabytes mapped for IO */
|
||||
#define PAGE_COUNT_IO 4096 /* 16 megabytes mapped for IO */
|
||||
#define VMADDR_KERNEL_NOMANS 0xFFFF0000 /* start of kernel "no man's land" */
|
||||
|
||||
#endif /* __COMROGUE_INTERNALS__ */
|
||||
|
||||
|
||||
@@ -43,11 +43,18 @@
|
||||
|
||||
CDECL_BEGIN
|
||||
|
||||
/* Kernel address space functions */
|
||||
extern KERNADDR _MmAllocKernelAddr(UINT32 cpgNeeded);
|
||||
extern void _MmFreeKernelAddr(KERNADDR kaBase, UINT32 cpgToFree);
|
||||
|
||||
/* Page mapping functions */
|
||||
extern PHYSADDR MmGetPhysAddr(PTTB pTTB, KERNADDR vma);
|
||||
extern HRESULT MmDemapPages(PTTB pTTB, KERNADDR vmaBase, UINT32 cpg);
|
||||
extern HRESULT MmMapPages(PTTB pTTB, PHYSADDR paBase, KERNADDR vmaBase, UINT32 cpg, UINT32 uiTableFlags,
|
||||
UINT32 uiPageFlags);
|
||||
extern HRESULT MmDemapPages(PTTB pTTB, PTTBAUX pTTBAux, KERNADDR vmaBase, UINT32 cpg);
|
||||
extern HRESULT MmMapPages(PTTB pTTB, PTTBAUX pTTBAux, PHYSADDR paBase, KERNADDR vmaBase, UINT32 cpg,
|
||||
UINT32 uiTableFlags, UINT32 uiPageFlags, UINT32 uiAuxFlags);
|
||||
extern HRESULT MmMapKernelPages(PTTB pTTB, PTTBAUX pTTBAux, PHYSADDR paBase, UINT32 cpg, UINT32 uiTableFlags,
|
||||
UINT32 uiPageFlags, UINT32 uiAuxFlags, PKERNADDR pvmaLocation);
|
||||
extern HRESULT MmDemapKernelPages(PTTB pTTB, PTTBAUX pTTBAux, KERNADDR vmaBase, UINT32 cpg);
|
||||
|
||||
/* Initialization functions only */
|
||||
extern void _MmInit(PSTARTUP_INFO pstartup);
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
#define SYS_TTB1_ENTRIES 4096 /* SYS_TTB1_SIZE/4, number of entries in TTB1 */
|
||||
#define SYS_TTB_BITS 12 /* log2(SYS_TTB1_SIZE/4), number of bits in a TTB address */
|
||||
#define SYS_SEC_SIZE 1048576 /* standard section size */
|
||||
#define SYS_SEC_BITS 20 /* number of bits in a section address */
|
||||
#define SYS_SEC_PAGES 256 /* SYS_SEC_SIZE/SYS_PAGE_SIZE, number of pages equivalent to a section */
|
||||
#define SYS_PGTBL_SIZE 1024 /* page tables must be located on this boundary and are this size */
|
||||
#define SYS_PGTBL_BITS 8 /* log2(SYS_PGTBL_SIZE/4), number of bits in a page table address */
|
||||
@@ -100,6 +101,9 @@
|
||||
#define TTBQUERY_SEC 0x00000002 /* indicates a section */
|
||||
#define TTBQUERY_PXNSEC 0x00000003 /* indicates a section with PXN (or reserved) */
|
||||
|
||||
/* TTB auxiliary descriptor bits */
|
||||
#define TTBAUX_SACRED 0x00000001 /* sacred entry, do not deallocate */
|
||||
|
||||
/* Small page table entry bits */
|
||||
#define PGTBLSM_XN 0x00000001 /* Execute-Never */
|
||||
#define PGTBLSM_ALWAYS 0x00000002 /* this bit must always be set for a page table entry */
|
||||
@@ -125,15 +129,29 @@
|
||||
#define PGQUERY_SM 0x00000002 /* small page (4K) */
|
||||
#define PGQUERY_SM_XN 0x00000003 /* small page with Execute-Never set */
|
||||
|
||||
/* Page auxiliary descriptor bits */
|
||||
#define PGAUX_SACRED 0x00000001 /* sacred entry, do not deallocate */
|
||||
|
||||
/* Combinations of flags we use regularly. */
|
||||
#define TTBFLAGS_LIB_CODE TTBPGTBL_ALWAYS
|
||||
#define PGTBLFLAGS_LIB_CODE (PGTBLSM_ALWAYS | PGTBLSM_B | PGTBLSM_C | PGTBLSM_AP10)
|
||||
#define PGAUXFLAGS_LIB_CODE PGAUX_SACRED
|
||||
#define TTBFLAGS_KERNEL_CODE TTBPGTBL_ALWAYS
|
||||
#define PGTBLFLAGS_KERNEL_CODE (PGTBLSM_ALWAYS | PGTBLSM_B | PGTBLSM_C | PGTBLSM_AP01)
|
||||
#define PGAUXFLAGS_KERNEL_CODE PGAUX_SACRED
|
||||
#define TTBFLAGS_KERNEL_DATA TTBPGTBL_ALWAYS
|
||||
#define PGTBLFLAGS_KERNEL_DATA (PGTBLSM_XN | PGTBLSM_ALWAYS | PGTBLSM_B | PGTBLSM_C | PGTBLSM_AP01)
|
||||
#define PGAUXFLAGS_KERNEL_DATA PGAUX_SACRED
|
||||
#define TTBFLAGS_INIT_CODE TTBFLAGS_KERNEL_CODE
|
||||
#define PGTBLFLAGS_INIT_CODE PGTBLFLAGS_KERNEL_CODE
|
||||
#define PGAUXFLAGS_INIT_CODE 0
|
||||
#define TTBFLAGS_INIT_DATA TTBFLAGS_KERNEL_DATA
|
||||
#define PGTBLFLAGS_INIT_DATA PGTBLFLAGS_KERNEL_DATA
|
||||
#define PGAUXFLAGS_INIT_DATA 0
|
||||
#define TTBFLAGS_MMIO TTBPGTBL_ALWAYS
|
||||
#define PGTBLFLAGS_MMIO (PGTBLSM_ALWAYS | PGTBLSM_AP01)
|
||||
#define PGAUXFLAGS_MMIO PGAUX_SACRED
|
||||
#define TTBAUXFLAGS_PAGETABLE 0
|
||||
|
||||
#ifndef __ASM__
|
||||
|
||||
@@ -186,6 +204,18 @@ typedef union tagTTB {
|
||||
TTBSEC sec; /* 1Mb section data */
|
||||
} TTB, *PTTB;
|
||||
|
||||
/* TTB auxiliary descriptor */
|
||||
typedef struct tagTTBAUXENTRY {
|
||||
unsigned sacred : 1; /* sacred TTB - should never be deallocated */
|
||||
unsigned reserved : 31; /* reserved for future allocation */
|
||||
} TTBAUXENTRY, *PTTBAUXENTRY;
|
||||
|
||||
/* TTB auxiliary table entry */
|
||||
typedef union tagTTBAUX {
|
||||
UINT32 data; /* raw data for entry */
|
||||
TTBAUXENTRY aux; /* aux entry itself */
|
||||
} TTBAUX, *PTTBAUX;
|
||||
|
||||
/* page table descriptor for a fault entry */
|
||||
typedef struct tagPGTBLFAULT {
|
||||
unsigned always0 : 2; /* bits are always 0 for a fault entry */
|
||||
@@ -213,10 +243,16 @@ typedef union tagPGTBL {
|
||||
PGTBLSM pg; /* small page descriptor */
|
||||
} PGTBL, *PPGTBL;
|
||||
|
||||
/* page auxiliary descriptor */
|
||||
typedef struct tagPGAUXENTRY {
|
||||
unsigned sacred : 1; /* sacred page - should never be deallocated */
|
||||
unsigned reserved : 31; /* reserved for future allocation */
|
||||
} PGAUXENTRY, *PPGAUXENTRY;
|
||||
|
||||
/* page table auxiliary entry */
|
||||
typedef union tagPGAUX {
|
||||
UINT32 data; /* raw data for entry */
|
||||
/* TODO */
|
||||
PGAUXENTRY aux; /* the auxiliary entry itself */
|
||||
} PGAUX, *PPGAUX;
|
||||
|
||||
/* complete structure of a page table, hardware + auxiliary */
|
||||
|
||||
@@ -66,14 +66,14 @@ typedef struct tagRBTREENODE {
|
||||
#define rbtNodeRight(ptn) ((PRBTREENODE)((ptn)->ptnRightColor & ~1))
|
||||
#define rbtNodeColor(ptn) ((ptn)->ptnRightColor & 1)
|
||||
#define rbtIsRed(ptn) ((ptn) ? rbtNodeColor(ptn) : FALSE)
|
||||
#define rbtSetNodeRight(ptn, ptnRight) \
|
||||
do { (ptn)->ptnRightColor = (((UINT_PTR)(ptnRight)) & ~1) | ((ptn)->ptnRightColor & 1); } while (0)
|
||||
#define rbtSetNodeRight(ptn, ptnR) \
|
||||
do { (ptn)->ptnRightColor = (((UINT_PTR)(ptnR)) & ~1) | ((ptn)->ptnRightColor & 1); } while (0)
|
||||
#define rbtSetNodeColor(ptn, clr) \
|
||||
do { (ptn)->ptnRightColor = ((ptn)->ptnRightColor & ~1) | ((clr) ? 1 : 0); } while (0)
|
||||
#define rbtToggleColor(ptn) do { if (ptn) (ptn)->ptnRightColor ^= 1; } while (0)
|
||||
#define rbtInitNode(ptn, ptnLeft, ptnRight, clr, key) \
|
||||
do { (ptn)->ptnLeft = (ptnLeft); (ptn)->ptnRightColor = (((UINT_PTR)(ptnRight)) & ~1) | ((clr) ? 1 : 0); \
|
||||
(ptn)->treekey = (key); } while (0)
|
||||
#define rbtInitNode(ptn, ptnL, ptnR, clr, key) \
|
||||
do { (ptn)->ptnLeft = (ptnL); (ptn)->ptnRightColor = (((UINT_PTR)(ptnR)) & ~1) | ((clr) ? 1 : 0); \
|
||||
(ptn)->treekey = (TREEKEY)(key); } while (0)
|
||||
#define rbtNewNode(ptn, key) rbtInitNode(ptn, NULL, NULL, RED, key)
|
||||
|
||||
/* The head-of-tree structure. */
|
||||
@@ -86,14 +86,20 @@ typedef struct tagRBTREE {
|
||||
#define rbtInitTree(ptree, pfnCompare) \
|
||||
do { (ptree)->pfnTreeCompare = (pfnCompare); (ptree)->ptnRoot = NULL; } while (0)
|
||||
|
||||
/* Type of function used by RbtWalk. */
|
||||
typedef BOOL (*PFNRBTWALK)(PRBTREE, PRBTREENODE, PVOID);
|
||||
|
||||
/* Function prototypes. */
|
||||
CDECL_BEGIN
|
||||
|
||||
extern INT32 RbtStdCompareByValue(TREEKEY k1, TREEKEY k2);
|
||||
extern void RbtInsert(PRBTREE ptree, PRBTREENODE ptnNew);
|
||||
extern PRBTREENODE RbtFind(PRBTREE ptree, TREEKEY key);
|
||||
extern PRBTREENODE RbtFindPredecessor(PRBTREE ptree, TREEKEY key);
|
||||
extern PRBTREENODE RbtFindSuccessor(PRBTREE ptree, TREEKEY key);
|
||||
extern PRBTREENODE RbtFindMin(PRBTREE ptree);
|
||||
extern void RbtDelete(PRBTREE ptree, TREEKEY key);
|
||||
extern BOOL RbtWalk(PRBTREE ptree, PFNRBTWALK pfnWalk, PVOID pData);
|
||||
|
||||
CDECL_END
|
||||
|
||||
|
||||
@@ -177,6 +177,8 @@ typedef struct tagSTARTUP_INFO {
|
||||
UINT32 cpgSystemTotal; /* total number of memory pages in the system */
|
||||
UINT32 cpgSystemAvail; /* available memory pages in the system after GPU takes its bite */
|
||||
UINT32 cpgTTBGap; /* number of pages in the "gap" between the end of kernel and TTB */
|
||||
PHYSADDR paTTBAux; /* physical address of the auxiliary TTB data */
|
||||
KERNADDR kaTTBAux; /* kernel address of the auxiliary TTB data */
|
||||
PHYSADDR paMPDB; /* physical address of the Master Page Database */
|
||||
KERNADDR kaMPDB; /* kernel address of the Master Page Database */
|
||||
UINT32 cpgMPDB; /* number of pages we allocated for Master Page Database */
|
||||
|
||||
Reference in New Issue
Block a user