3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/mm/ncache.c
6 * PURPOSE: Manages non-cached memory
8 * PROGRAMMERS: David Welch (welch@cwcom.net)
11 /* INCLUDES *****************************************************************/
15 #include <internal/debug.h>
17 /* FUNCTIONS *****************************************************************/
20 /**********************************************************************
22 * MmAllocateNonCachedMemory@4
25 * Allocates a virtual address range of noncached and cache
30 * Size of region to allocate.
33 * The base address of the range on success;
37 * Description taken from include/ddk/mmfuncs.h.
38 * Code taken from ntoskrnl/mm/special.c.
45 MmAllocateNonCachedMemory(IN ULONG NumberOfBytes
)
51 ULONG Protect
= PAGE_READWRITE
|PAGE_SYSTEM
|PAGE_NOCACHE
|PAGE_WRITETHROUGH
;
52 PHYSICAL_ADDRESS BoundaryAddressMultiple
;
54 BoundaryAddressMultiple
.QuadPart
= 0;
55 MmLockAddressSpace(MmGetKernelAddressSpace());
57 Status
= MmCreateMemoryArea (MmGetKernelAddressSpace(),
65 BoundaryAddressMultiple
);
66 MmUnlockAddressSpace(MmGetKernelAddressSpace());
68 if (!NT_SUCCESS(Status
))
73 for (i
= 0; i
< (PAGE_ROUND_UP(NumberOfBytes
) / PAGE_SIZE
); i
++)
77 Status
= MmRequestPageMemoryConsumer(MC_NPPOOL
, TRUE
, &NPage
);
78 MmCreateVirtualMapping (NULL
,
79 (char*)Result
+ (i
* PAGE_SIZE
),
84 return ((PVOID
)Result
);
88 MmFreeNonCachedPage(PVOID Context
, MEMORY_AREA
* MemoryArea
, PVOID Address
,
89 PFN_TYPE Page
, SWAPENTRY SwapEntry
,
92 ASSERT(SwapEntry
== 0);
95 MmReleasePageMemoryConsumer(MC_NPPOOL
, Page
);
99 /**********************************************************************
101 * MmFreeNonCachedMemory@8
104 * Releases a range of noncached memory allocated with
105 * MmAllocateNonCachedMemory.
109 * Virtual address to be freed;
112 * Size of the region to be freed.
118 * Description taken from include/ddk/mmfuncs.h.
119 * Code taken from ntoskrnl/mm/special.c.
125 VOID STDCALL
MmFreeNonCachedMemory (IN PVOID BaseAddress
,
126 IN ULONG NumberOfBytes
)
128 MmLockAddressSpace(MmGetKernelAddressSpace());
129 MmFreeMemoryAreaByPtr(MmGetKernelAddressSpace(),
133 MmUnlockAddressSpace(MmGetKernelAddressSpace());