2 Copyright (C) 2008 Mathias Gottschlag
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in the
6 Software without restriction, including without limitation the rights to use,
7 copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
8 Software, and to permit persons to whom the Software is furnished to do so,
9 subject to the following conditions:
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16 PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
19 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 #ifndef MM_MEMORY_H_INCLUDED
23 #define MM_MEMORY_H_INCLUDED
25 #include "ke/multiboot.h"
26 #include "ke/spinlock.h"
28 #define MM_KERNEL_BASE 0xC0000000
36 #define MM_MEMORY_ADDR_SHARED 1
38 typedef struct MmMemoryArea
43 struct MmMemoryArea
*next
;
46 int mmInitMemoryManager(MultibootInfo
*mbinfo
, uintptr_t kernel_begin
,
47 uintptr_t kernel_end
);
48 int mmInitPhysicalMemory(MultibootInfo
*mbinfo
, uintptr_t kernel_begin
,
49 uintptr_t kernel_end
);
50 int mmInitVirtualMemory(MultibootInfo
*mbinfo
, uintptr_t kernel_begin
,
51 uintptr_t kernel_end
);
53 KeSpinlock
*mmGetMemoryLock(void);
55 int mmCreateAddressSpace(MmAddressSpace
*addrspace
);
56 int mmCloneAddressSpace(MmAddressSpace
*dest
, MmAddressSpace
*src
);
57 int mmDestroyAddressSpace(MmAddressSpace
*addrspace
);
58 int mmClearAddressSpace(MmAddressSpace
*addrspace
);
60 #define MM_MEMORY_ALLOC_DMA 0x1
61 #define MM_MEMORY_ALLOC_PHYS 0x2
63 uintptr_t mmAllocPhysicalMemory(uint32_t flags
, uintptr_t phys_addr
,
65 void mmFreePhysicalMemory(uintptr_t addr
, uint32_t size
);
67 #define MM_MAP_READ 0x1
68 #define MM_MAP_WRITE 0x2
69 #define MM_MAP_EXECUTE 0x4
70 #define MM_MAP_UNCACHEABLE 0x8
71 #define MM_MAP_USER 0x10
73 int mmMapMemory(MmAddressSpace
*addrspace
, uintptr_t phys
, uintptr_t virt
,
75 int mmMapKernelMemory(uintptr_t phys
, uintptr_t virt
,
77 uintptr_t mmGetPhysAddress(MmAddressSpace
*addrspace
, uintptr_t virt
);
78 uintptr_t mmKernelGetPhysAddress(uintptr_t virt
);
80 #define MM_MIN_USER_PAGE 0x00001000
81 #define MM_MAX_USER_PAGE (MM_KERNEL_BASE - 0x1000)
82 #define MM_MIN_KERNEL_PAGE MM_KERNEL_BASE
83 #define MM_MAX_KERNEL_PAGE 0xEFFFF000
85 uintptr_t mmFindFreePages(MmAddressSpace
*addrspace
, uintptr_t max
, uintptr_t min
,
86 int downwards
, uint32_t size
);
87 uintptr_t mmFindFreeKernelPages(uintptr_t max
, uintptr_t min
,
88 int downwards
, uint32_t size
);
89 int mmKernelPageIsFree(uintptr_t addr
);
91 uint32_t mmGetPhysPageCount(void);
93 void keSyncVirtMemory(void);