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
);
31 /**********************************************************************
33 * MmAllocateContiguousMemorySpecifyCache@32
36 * Allocates a range of physically contiguous memory
37 * with a cache parameter.
41 * Size of the memory block to allocate;
43 * LowestAcceptableAddress
44 * Lowest address valid for the caller.
46 * HighestAcceptableAddress
47 * Highest address valid for the caller.
49 * BoundaryAddressMultiple
50 * Address multiple not to be crossed by allocated buffer (optional).
53 * Type of caching to use.
56 * The virtual address of the memory block on success;
64 MmAllocateContiguousMemorySpecifyCache(IN SIZE_T NumberOfBytes
,
65 IN PHYSICAL_ADDRESS LowestAcceptableAddress OPTIONAL
,
66 IN PHYSICAL_ADDRESS HighestAcceptableAddress
,
67 IN PHYSICAL_ADDRESS BoundaryAddressMultiple OPTIONAL
,
68 IN MEMORY_CACHING_TYPE CacheType OPTIONAL
)
72 PVOID BaseAddress
= NULL
;
77 Protect
= PAGE_EXECUTE_READWRITE
| PAGE_SYSTEM
;
78 if (CacheType
== MmNonCached
|| CacheType
== MmWriteCombined
)
80 Protect
|= PAGE_NOCACHE
;
82 if (CacheType
== MmWriteCombined
)
84 Protect
|= PAGE_WRITECOMBINE
;
87 MmLockAddressSpace(MmGetKernelAddressSpace());
88 Status
= MmCreateMemoryArea(MmGetKernelAddressSpace(),
89 MEMORY_AREA_CONTINUOUS_MEMORY
,
96 RtlConvertLongToLargeInteger(0));
97 MmUnlockAddressSpace(MmGetKernelAddressSpace());
99 if (!NT_SUCCESS(Status
))
103 DPRINT( "Base = %x\n", BaseAddress
);
104 PBase
= MmGetContinuousPages(NumberOfBytes
,
105 LowestAcceptableAddress
,
106 HighestAcceptableAddress
,
107 BoundaryAddressMultiple
);
110 MmLockAddressSpace(MmGetKernelAddressSpace());
111 MmFreeMemoryArea(MmGetKernelAddressSpace(),
115 MmUnlockAddressSpace(MmGetKernelAddressSpace());
118 for (i
= 0; i
< (PAGE_ROUND_UP(NumberOfBytes
) / PAGE_SIZE
); i
++, PBase
++)
120 MmCreateVirtualMapping(NULL
,
121 (char*)BaseAddress
+ (i
* PAGE_SIZE
),
129 /**********************************************************************
131 * MmAllocateContiguousMemory@12
134 * Allocates a range of physically contiguous cache aligned
135 * memory from the non-paged pool.
139 * Size of the memory block to allocate;
141 * HighestAcceptableAddress
142 * Highest address valid for the caller.
145 * The virtual address of the memory block on success;
149 * Description taken from include/ddk/mmfuncs.h.
150 * Code taken from ntoskrnl/mm/special.c.
157 MmAllocateContiguousMemory (IN ULONG NumberOfBytes
,
158 IN PHYSICAL_ADDRESS HighestAcceptableAddress
)
160 return MmAllocateContiguousMemorySpecifyCache(NumberOfBytes
,
161 RtlConvertLongToLargeInteger(0),
162 HighestAcceptableAddress
,
163 RtlConvertLongToLargeInteger(0),
168 /**********************************************************************
170 * MmFreeContiguousMemory@4
173 * Releases a range of physically contiguous memory allocated
174 * with MmAllocateContiguousMemory.
178 * Virtual address of the memory to be freed.
184 * Description taken from include/ddk/mmfuncs.h.
185 * Code taken from ntoskrnl/mm/special.c.
192 MmFreeContiguousMemory(IN PVOID BaseAddress
)
194 MmLockAddressSpace(MmGetKernelAddressSpace());
195 MmFreeMemoryAreaByPtr(MmGetKernelAddressSpace(),
197 MmFreeContinuousPage
,
199 MmUnlockAddressSpace(MmGetKernelAddressSpace());
202 /**********************************************************************
204 * MmFreeContiguousMemorySpecifyCache@12
207 * Releases a range of physically contiguous memory allocated
208 * with MmAllocateContiguousMemorySpecifyCache.
212 * Virtual address of the memory to be freed.
215 * Size of the memory block to free.
218 * Type of caching used.
228 MmFreeContiguousMemorySpecifyCache(IN PVOID BaseAddress
,
229 IN ULONG NumberOfBytes
,
230 IN MEMORY_CACHING_TYPE CacheType
)
232 MmLockAddressSpace(MmGetKernelAddressSpace());
233 MmFreeMemoryAreaByPtr(MmGetKernelAddressSpace(),
235 MmFreeContinuousPage
,
237 MmUnlockAddressSpace(MmGetKernelAddressSpace());