3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/mm/cont.c
6 * PURPOSE: Manages continuous memory
8 * PROGRAMMERS: David Welch (welch@cwcom.net)
11 /* INCLUDES *****************************************************************/
15 #include <internal/debug.h>
17 /* FUNCTIONS *****************************************************************/
20 MmFreeContinuousPage(PVOID Context
, MEMORY_AREA
* MemoryArea
, PVOID Address
,
21 PFN_TYPE Page
, SWAPENTRY SwapEntry
,
24 ASSERT(SwapEntry
== 0);
27 MmReleasePageMemoryConsumer(MC_NPPOOL
, Page
);
35 MmAllocateContiguousAlignedMemory(IN ULONG NumberOfBytes
,
36 IN PHYSICAL_ADDRESS LowestAcceptableAddress OPTIONAL
,
37 IN PHYSICAL_ADDRESS HighestAcceptableAddress
,
38 IN PHYSICAL_ADDRESS BoundaryAddressMultiple OPTIONAL
,
39 IN MEMORY_CACHING_TYPE CacheType OPTIONAL
,
44 PVOID BaseAddress
= NULL
;
49 Attributes
= PAGE_EXECUTE_READWRITE
| PAGE_SYSTEM
;
50 if (CacheType
== MmNonCached
|| CacheType
== MmWriteCombined
)
52 Attributes
|= PAGE_NOCACHE
;
54 if (CacheType
== MmWriteCombined
)
56 Attributes
|= PAGE_WRITECOMBINE
;
59 MmLockAddressSpace(MmGetKernelAddressSpace());
60 Status
= MmCreateMemoryArea(NULL
,
61 MmGetKernelAddressSpace(),
62 MEMORY_AREA_CONTINUOUS_MEMORY
,
69 BoundaryAddressMultiple
);
70 MmUnlockAddressSpace(MmGetKernelAddressSpace());
72 if (!NT_SUCCESS(Status
))
76 DPRINT( "Base = %x\n", BaseAddress
);
77 PBase
= MmGetContinuousPages(NumberOfBytes
,
78 LowestAcceptableAddress
,
79 HighestAcceptableAddress
,
83 MmLockAddressSpace(MmGetKernelAddressSpace());
84 MmFreeMemoryArea(MmGetKernelAddressSpace(),
88 MmUnlockAddressSpace(MmGetKernelAddressSpace());
91 for (i
= 0; i
< (PAGE_ROUND_UP(NumberOfBytes
) / PAGE_SIZE
); i
++, PBase
++)
93 MmCreateVirtualMapping(NULL
,
94 (char*)BaseAddress
+ (i
* 4096),
102 /**********************************************************************
104 * MmAllocateContiguousMemory@12
107 * Allocates a range of physically contiguous cache aligned
108 * memory from the non-paged pool.
112 * Size of the memory block to allocate;
114 * HighestAcceptableAddress
115 * Highest address valid for the caller.
118 * The virtual address of the memory block on success;
122 * Description taken from include/ddk/mmfuncs.h.
123 * Code taken from ntoskrnl/mm/special.c.
130 MmAllocateContiguousMemory (IN ULONG NumberOfBytes
,
131 IN PHYSICAL_ADDRESS HighestAcceptableAddress
)
133 PHYSICAL_ADDRESS LowestAcceptableAddress
;
134 PHYSICAL_ADDRESS BoundaryAddressMultiple
;
136 LowestAcceptableAddress
.QuadPart
= 0;
137 BoundaryAddressMultiple
.QuadPart
= 0;
139 return(MmAllocateContiguousAlignedMemory(NumberOfBytes
,
140 LowestAcceptableAddress
,
141 HighestAcceptableAddress
,
142 BoundaryAddressMultiple
,
148 /**********************************************************************
150 * MmFreeContiguousMemory@4
153 * Releases a range of physically contiguous memory allocated
154 * with MmAllocateContiguousMemory.
158 * Virtual address of the memory to be freed.
164 * Description taken from include/ddk/mmfuncs.h.
165 * Code taken from ntoskrnl/mm/special.c.
172 MmFreeContiguousMemory(IN PVOID BaseAddress
)
174 MmLockAddressSpace(MmGetKernelAddressSpace());
175 MmFreeMemoryAreaByPtr(MmGetKernelAddressSpace(),
177 MmFreeContinuousPage
,
179 MmUnlockAddressSpace(MmGetKernelAddressSpace());
182 /**********************************************************************
184 * MmAllocateContiguousMemorySpecifyCache@32
187 * Allocates a range of physically contiguous memory
188 * with a cache parameter.
192 * Size of the memory block to allocate;
194 * LowestAcceptableAddress
195 * Lowest address valid for the caller.
197 * HighestAcceptableAddress
198 * Highest address valid for the caller.
200 * BoundaryAddressMultiple
201 * Address multiple not to be crossed by allocated buffer (optional).
204 * Type of caching to use.
207 * The virtual address of the memory block on success;
215 MmAllocateContiguousMemorySpecifyCache (IN ULONG NumberOfBytes
,
216 IN PHYSICAL_ADDRESS LowestAcceptableAddress
,
217 IN PHYSICAL_ADDRESS HighestAcceptableAddress
,
218 IN PHYSICAL_ADDRESS BoundaryAddressMultiple OPTIONAL
,
219 IN MEMORY_CACHING_TYPE CacheType
)
221 return(MmAllocateContiguousAlignedMemory(NumberOfBytes
,
222 LowestAcceptableAddress
,
223 HighestAcceptableAddress
,
224 BoundaryAddressMultiple
,
229 /**********************************************************************
231 * MmFreeContiguousMemorySpecifyCache@12
234 * Releases a range of physically contiguous memory allocated
235 * with MmAllocateContiguousMemorySpecifyCache.
239 * Virtual address of the memory to be freed.
242 * Size of the memory block to free.
245 * Type of caching used.
255 MmFreeContiguousMemorySpecifyCache(IN PVOID BaseAddress
,
256 IN ULONG NumberOfBytes
,
257 IN MEMORY_CACHING_TYPE CacheType
)
259 MmLockAddressSpace(MmGetKernelAddressSpace());
260 MmFreeMemoryAreaByPtr(MmGetKernelAddressSpace(),
262 MmFreeContinuousPage
,
264 MmUnlockAddressSpace(MmGetKernelAddressSpace());