3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/mm/cont.c
6 * PURPOSE: Manages non-cached memory
7 * PROGRAMMER: David Welch (welch@cwcom.net)
12 /* INCLUDES *****************************************************************/
14 #include <ddk/ntddk.h>
15 #include <internal/mm.h>
16 #include <internal/ps.h>
19 #include <internal/debug.h>
21 /* FUNCTIONS *****************************************************************/
24 /**********************************************************************
26 * MmAllocateNonCachedMemory@4
29 * Allocates a virtual address range of noncached and cache
34 * Size of region to allocate.
37 * The base address of the range on success;
41 * Description taken from include/ddk/mmfuncs.h.
42 * Code taken from ntoskrnl/mm/special.c.
48 MmAllocateNonCachedMemory(IN ULONG NumberOfBytes)
56 MmLockAddressSpace(MmGetKernelAddressSpace());
58 Status = MmCreateMemoryArea (NULL,
59 MmGetKernelAddressSpace(),
66 MmUnlockAddressSpace(MmGetKernelAddressSpace());
68 if (!NT_SUCCESS(Status))
72 Attributes = PAGE_READWRITE | PAGE_SYSTEM | PAGE_NOCACHE |
74 for (i = 0; i <= (NumberOfBytes / PAGE_SIZE); i++)
76 PHYSICAL_ADDRESS NPage;
78 Status = MmRequestPageMemoryConsumer(MC_NPPOOL, TRUE, &NPage);
79 MmCreateVirtualMapping (NULL,
80 Result + (i * PAGE_SIZE),
85 return ((PVOID)Result);
89 MmFreeNonCachedPage(PVOID Context, MEMORY_AREA* MemoryArea, PVOID Address,
90 PHYSICAL_ADDRESS PhysAddr, SWAPENTRY SwapEntry,
93 assert(SwapEntry == 0);
94 if (PhysAddr.QuadPart != 0)
96 MmReleasePageMemoryConsumer(MC_NPPOOL, PhysAddr);
100 /**********************************************************************
102 * MmFreeNonCachedMemory@8
105 * Releases a range of noncached memory allocated with
106 * MmAllocateNonCachedMemory.
110 * Virtual address to be freed;
113 * Size of the region to be freed.
119 * Description taken from include/ddk/mmfuncs.h.
120 * Code taken from ntoskrnl/mm/special.c.
125 VOID STDCALL MmFreeNonCachedMemory (IN PVOID BaseAddress,
126 IN ULONG NumberOfBytes)
128 MmFreeMemoryArea (MmGetKernelAddressSpace(),