strip whitespace from end of lines
[reactos.git] / reactos / ntoskrnl / mm / ncache.c
1 /* $Id$
2 *
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
7 *
8 * PROGRAMMERS: David Welch (welch@cwcom.net)
9 */
10
11 /* INCLUDES *****************************************************************/
12
13 #include <ntoskrnl.h>
14 #define NDEBUG
15 #include <internal/debug.h>
16
17 /* FUNCTIONS *****************************************************************/
18
19
20 /**********************************************************************
21 * NAME EXPORTED
22 * MmAllocateNonCachedMemory@4
23 *
24 * DESCRIPTION
25 * Allocates a virtual address range of noncached and cache
26 * aligned memory.
27 *
28 * ARGUMENTS
29 * NumberOfBytes
30 * Size of region to allocate.
31 *
32 * RETURN VALUE
33 * The base address of the range on success;
34 * NULL on failure.
35 *
36 * NOTE
37 * Description taken from include/ddk/mmfuncs.h.
38 * Code taken from ntoskrnl/mm/special.c.
39 *
40 * REVISIONS
41 *
42 * @implemented
43 */
44 PVOID STDCALL
45 MmAllocateNonCachedMemory(IN ULONG NumberOfBytes)
46 {
47 PVOID Result;
48 MEMORY_AREA* marea;
49 NTSTATUS Status;
50 ULONG i;
51 ULONG Attributes;
52 PHYSICAL_ADDRESS BoundaryAddressMultiple;
53
54 BoundaryAddressMultiple.QuadPart = 0;
55 MmLockAddressSpace(MmGetKernelAddressSpace());
56 Result = NULL;
57 Status = MmCreateMemoryArea (NULL,
58 MmGetKernelAddressSpace(),
59 MEMORY_AREA_NO_CACHE,
60 &Result,
61 NumberOfBytes,
62 0,
63 &marea,
64 FALSE,
65 FALSE,
66 BoundaryAddressMultiple);
67 MmUnlockAddressSpace(MmGetKernelAddressSpace());
68
69 if (!NT_SUCCESS(Status))
70 {
71 return (NULL);
72 }
73 Attributes = PAGE_READWRITE | PAGE_SYSTEM | PAGE_NOCACHE |
74 PAGE_WRITETHROUGH;
75 for (i = 0; i < (PAGE_ROUND_UP(NumberOfBytes) / PAGE_SIZE); i++)
76 {
77 PFN_TYPE NPage;
78
79 Status = MmRequestPageMemoryConsumer(MC_NPPOOL, TRUE, &NPage);
80 MmCreateVirtualMapping (NULL,
81 (char*)Result + (i * PAGE_SIZE),
82 Attributes,
83 &NPage,
84 1);
85 }
86 return ((PVOID)Result);
87 }
88
89 VOID STATIC
90 MmFreeNonCachedPage(PVOID Context, MEMORY_AREA* MemoryArea, PVOID Address,
91 PFN_TYPE Page, SWAPENTRY SwapEntry,
92 BOOLEAN Dirty)
93 {
94 ASSERT(SwapEntry == 0);
95 if (Page != 0)
96 {
97 MmReleasePageMemoryConsumer(MC_NPPOOL, Page);
98 }
99 }
100
101 /**********************************************************************
102 * NAME EXPORTED
103 * MmFreeNonCachedMemory@8
104 *
105 * DESCRIPTION
106 * Releases a range of noncached memory allocated with
107 * MmAllocateNonCachedMemory.
108 *
109 * ARGUMENTS
110 * BaseAddress
111 * Virtual address to be freed;
112 *
113 * NumberOfBytes
114 * Size of the region to be freed.
115 *
116 * RETURN VALUE
117 * None.
118 *
119 * NOTE
120 * Description taken from include/ddk/mmfuncs.h.
121 * Code taken from ntoskrnl/mm/special.c.
122 *
123 * REVISIONS
124 *
125 * @implemented
126 */
127 VOID STDCALL MmFreeNonCachedMemory (IN PVOID BaseAddress,
128 IN ULONG NumberOfBytes)
129 {
130 MmLockAddressSpace(MmGetKernelAddressSpace());
131 MmFreeMemoryAreaByPtr(MmGetKernelAddressSpace(),
132 BaseAddress,
133 MmFreeNonCachedPage,
134 NULL);
135 MmUnlockAddressSpace(MmGetKernelAddressSpace());
136 }
137
138 /* EOF */