2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: ntoskrnl/mm/cont.c
5 * PURPOSE: Manages continuous memory
7 * PROGRAMMERS: David Welch (welch@cwcom.net)
10 /* INCLUDES *****************************************************************/
16 /* FUNCTIONS *****************************************************************/
19 MmFreeContinuousPage(PVOID Context
, MEMORY_AREA
* MemoryArea
, PVOID Address
,
20 PFN_TYPE Page
, SWAPENTRY SwapEntry
,
23 ASSERT(SwapEntry
== 0);
26 MmReleasePageMemoryConsumer(MC_NPPOOL
, Page
);
30 /**********************************************************************
32 * MmAllocateContiguousMemorySpecifyCache@32
35 * Allocates a range of physically contiguous memory
36 * with a cache parameter.
40 * Size of the memory block to allocate;
42 * LowestAcceptableAddress
43 * Lowest address valid for the caller.
45 * HighestAcceptableAddress
46 * Highest address valid for the caller.
48 * BoundaryAddressMultiple
49 * Address multiple not to be crossed by allocated buffer (optional).
52 * Type of caching to use.
55 * The virtual address of the memory block on success;
63 MmAllocateContiguousMemorySpecifyCache(IN SIZE_T NumberOfBytes
,
64 IN PHYSICAL_ADDRESS LowestAcceptableAddress OPTIONAL
,
65 IN PHYSICAL_ADDRESS HighestAcceptableAddress
,
66 IN PHYSICAL_ADDRESS BoundaryAddressMultiple OPTIONAL
,
67 IN MEMORY_CACHING_TYPE CacheType OPTIONAL
)
71 PVOID BaseAddress
= NULL
;
76 Protect
= PAGE_EXECUTE_READWRITE
| PAGE_SYSTEM
;
77 if (CacheType
== MmNonCached
|| CacheType
== MmWriteCombined
)
79 Protect
|= PAGE_NOCACHE
;
81 if (CacheType
== MmWriteCombined
)
83 Protect
|= PAGE_WRITECOMBINE
;
86 MmLockAddressSpace(MmGetKernelAddressSpace());
87 Status
= MmCreateMemoryArea(MmGetKernelAddressSpace(),
88 MEMORY_AREA_CONTINUOUS_MEMORY
,
95 RtlConvertLongToLargeInteger(0));
96 MmUnlockAddressSpace(MmGetKernelAddressSpace());
98 if (!NT_SUCCESS(Status
))
102 DPRINT( "Base = %x\n", BaseAddress
);
103 PBase
= MmGetContinuousPages(NumberOfBytes
,
104 LowestAcceptableAddress
,
105 HighestAcceptableAddress
,
106 BoundaryAddressMultiple
);
109 MmLockAddressSpace(MmGetKernelAddressSpace());
110 MmFreeMemoryArea(MmGetKernelAddressSpace(),
114 MmUnlockAddressSpace(MmGetKernelAddressSpace());
117 for (i
= 0; i
< (PAGE_ROUND_UP(NumberOfBytes
) / PAGE_SIZE
); i
++, PBase
++)
119 MmCreateVirtualMapping(NULL
,
120 (char*)BaseAddress
+ (i
* PAGE_SIZE
),
128 /**********************************************************************
130 * MmAllocateContiguousMemory@12
133 * Allocates a range of physically contiguous cache aligned
134 * memory from the non-paged pool.
138 * Size of the memory block to allocate;
140 * HighestAcceptableAddress
141 * Highest address valid for the caller.
144 * The virtual address of the memory block on success;
148 * Description taken from include/ddk/mmfuncs.h.
149 * Code taken from ntoskrnl/mm/special.c.
156 MmAllocateContiguousMemory (IN ULONG NumberOfBytes
,
157 IN PHYSICAL_ADDRESS HighestAcceptableAddress
)
159 return MmAllocateContiguousMemorySpecifyCache(NumberOfBytes
,
160 RtlConvertLongToLargeInteger(0),
161 HighestAcceptableAddress
,
162 RtlConvertLongToLargeInteger(0),
167 /**********************************************************************
169 * MmFreeContiguousMemory@4
172 * Releases a range of physically contiguous memory allocated
173 * with MmAllocateContiguousMemory.
177 * Virtual address of the memory to be freed.
183 * Description taken from include/ddk/mmfuncs.h.
184 * Code taken from ntoskrnl/mm/special.c.
191 MmFreeContiguousMemory(IN PVOID BaseAddress
)
193 MmLockAddressSpace(MmGetKernelAddressSpace());
194 MmFreeMemoryAreaByPtr(MmGetKernelAddressSpace(),
196 MmFreeContinuousPage
,
198 MmUnlockAddressSpace(MmGetKernelAddressSpace());
201 /**********************************************************************
203 * MmFreeContiguousMemorySpecifyCache@12
206 * Releases a range of physically contiguous memory allocated
207 * with MmAllocateContiguousMemorySpecifyCache.
211 * Virtual address of the memory to be freed.
214 * Size of the memory block to free.
217 * Type of caching used.
227 MmFreeContiguousMemorySpecifyCache(IN PVOID BaseAddress
,
228 IN SIZE_T NumberOfBytes
,
229 IN MEMORY_CACHING_TYPE CacheType
)
231 MmLockAddressSpace(MmGetKernelAddressSpace());
232 MmFreeMemoryAreaByPtr(MmGetKernelAddressSpace(),
234 MmFreeContinuousPage
,
236 MmUnlockAddressSpace(MmGetKernelAddressSpace());