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
)
52 PHYSICAL_ADDRESS BoundaryAddressMultiple
;
54 BoundaryAddressMultiple
.QuadPart
= 0;
55 MmLockAddressSpace(MmGetKernelAddressSpace());
57 Status
= MmCreateMemoryArea (NULL
,
58 MmGetKernelAddressSpace(),
66 BoundaryAddressMultiple
);
67 MmUnlockAddressSpace(MmGetKernelAddressSpace());
69 if (!NT_SUCCESS(Status
))
73 Attributes
= PAGE_READWRITE
| PAGE_SYSTEM
| PAGE_NOCACHE
|
75 for (i
= 0; i
< (PAGE_ROUND_UP(NumberOfBytes
) / PAGE_SIZE
); i
++)
79 Status
= MmRequestPageMemoryConsumer(MC_NPPOOL
, TRUE
, &NPage
);
80 MmCreateVirtualMapping (NULL
,
81 (char*)Result
+ (i
* PAGE_SIZE
),
86 return ((PVOID
)Result
);
90 MmFreeNonCachedPage(PVOID Context
, MEMORY_AREA
* MemoryArea
, PVOID Address
,
91 PFN_TYPE Page
, SWAPENTRY SwapEntry
,
94 ASSERT(SwapEntry
== 0);
97 MmReleasePageMemoryConsumer(MC_NPPOOL
, Page
);
101 /**********************************************************************
103 * MmFreeNonCachedMemory@8
106 * Releases a range of noncached memory allocated with
107 * MmAllocateNonCachedMemory.
111 * Virtual address to be freed;
114 * Size of the region to be freed.
120 * Description taken from include/ddk/mmfuncs.h.
121 * Code taken from ntoskrnl/mm/special.c.
127 VOID STDCALL
MmFreeNonCachedMemory (IN PVOID BaseAddress
,
128 IN ULONG NumberOfBytes
)
130 MmLockAddressSpace(MmGetKernelAddressSpace());
131 MmFreeMemoryAreaByPtr(MmGetKernelAddressSpace(),
135 MmUnlockAddressSpace(MmGetKernelAddressSpace());