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.
49 MmAllocateNonCachedMemory(IN ULONG NumberOfBytes)
57 MmLockAddressSpace(MmGetKernelAddressSpace());
59 Status = MmCreateMemoryArea (NULL,
60 MmGetKernelAddressSpace(),
68 MmUnlockAddressSpace(MmGetKernelAddressSpace());
70 if (!NT_SUCCESS(Status))
74 Attributes = PAGE_READWRITE | PAGE_SYSTEM | PAGE_NOCACHE |
76 for (i = 0; i < (PAGE_ROUND_UP(NumberOfBytes) / PAGE_SIZE); i++)
78 PHYSICAL_ADDRESS NPage;
80 Status = MmRequestPageMemoryConsumer(MC_NPPOOL, TRUE, &NPage);
81 MmCreateVirtualMapping (NULL,
82 Result + (i * PAGE_SIZE),
87 return ((PVOID)Result);
91 MmFreeNonCachedPage(PVOID Context, MEMORY_AREA* MemoryArea, PVOID Address,
92 PHYSICAL_ADDRESS PhysAddr, SWAPENTRY SwapEntry,
95 assert(SwapEntry == 0);
96 if (PhysAddr.QuadPart != 0)
98 MmReleasePageMemoryConsumer(MC_NPPOOL, PhysAddr);
102 /**********************************************************************
104 * MmFreeNonCachedMemory@8
107 * Releases a range of noncached memory allocated with
108 * MmAllocateNonCachedMemory.
112 * Virtual address to be freed;
115 * Size of the region to be freed.
121 * Description taken from include/ddk/mmfuncs.h.
122 * Code taken from ntoskrnl/mm/special.c.
128 VOID STDCALL MmFreeNonCachedMemory (IN PVOID BaseAddress,
129 IN ULONG NumberOfBytes)
131 MmLockAddressSpace(MmGetKernelAddressSpace());
132 MmFreeMemoryArea (MmGetKernelAddressSpace(),
137 MmUnlockAddressSpace(MmGetKernelAddressSpace());