This commit was generated by cvs2svn to compensate for changes in r52,
[reactos.git] / reactos / ntoskrnl / mm / special.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: ntoskrnl/mm/special.c
5 * PURPOSE: Special types of memory region
6 * PROGRAMMER: David Welch (welch@mcmail.com)
7 * UPDATE HISTORY:
8 * Created 22/05/98
9 */
10
11 /* INCLUDES *****************************************************************/
12
13 #include <ddk/ntddk.h>
14 #include <internal/mm.h>
15
16 #define NDEBUG
17 #include <internal/debug.h>
18
19 /* FUNCTIONS *****************************************************************/
20
21 PVOID MmAllocateSection(ULONG Length)
22 {
23 ULONG Result;
24 MEMORY_AREA* marea;
25 NTSTATUS Status;
26 ULONG i;
27 ULONG Attributes;
28
29 DPRINT("MmAllocateSection(Length %x)\n",Length);
30
31 Result = 0;
32 Status = MmCreateMemoryArea(KernelMode,
33 PsGetCurrentProcess(),
34 MEMORY_AREA_SYSTEM,
35 &Result,
36 Length,
37 0,
38 &marea);
39 if (Status!=STATUS_SUCCESS)
40 {
41 return(NULL);
42 }
43 DPRINT("Result %x\n",Result);
44 Attributes = PA_WRITE | PA_READ | PA_EXECUTE | PA_SYSTEM;
45 for (i=0;i<=(Length/PAGESIZE);i++)
46 {
47 set_page(Result+(i*PAGESIZE),Attributes,get_free_page());
48 }
49 return((PVOID)Result);
50 }
51
52 PVOID MmAllocateContiguousMemory(ULONG NumberOfBytes,
53 PHYSICAL_ADDRESS HighestAcceptableAddress)
54 {
55 UNIMPLEMENTED;
56 }
57
58 VOID MmFreeContiguousMemory(PVOID BaseAddress)
59 {
60 UNIMPLEMENTED;
61 }
62
63 PVOID MmMapIoSpace(PHYSICAL_ADDRESS PhysicalAddress,
64 ULONG NumberOfBytes,
65 BOOLEAN CacheEnable)
66 {
67 ULONG Result;
68 MEMORY_AREA* marea;
69 NTSTATUS Status;
70 ULONG i;
71 ULONG Attributes;
72
73 Result=0;
74 Status = MmCreateMemoryArea(KernelMode,
75 PsGetCurrentProcess(),
76 MEMORY_AREA_IO_MAPPING,
77 &Result,
78 NumberOfBytes,
79 0,
80 &marea);
81 if (Status!=STATUS_SUCCESS)
82 {
83 return(NULL);
84 }
85 Attributes = PA_WRITE | PA_READ | PA_EXECUTE | PA_SYSTEM;
86 if (!CacheEnable)
87 {
88 Attributes = Attributes | PA_PWT | PA_PCD;
89 }
90 for (i=0;i<=(NumberOfBytes/PAGESIZE);i++)
91 {
92 set_page(Result+(i*PAGESIZE),Attributes,PhysicalAddress.LowPart);
93 }
94 return((PVOID)Result);
95 }
96
97 VOID MmUnmapIoSpace(PVOID BaseAddress, ULONG NumberOfBytes)
98 {
99 (void)MmFreeMemoryArea(PsGetCurrentProcess(),BaseAddress,NumberOfBytes,
100 FALSE);
101 }
102
103 PVOID MmAllocateNonCachedMemory(ULONG NumberOfBytes)
104 {
105 ULONG Result;
106 MEMORY_AREA* marea;
107 NTSTATUS Status;
108 ULONG i;
109
110 Result=0;
111 Status = MmCreateMemoryArea(KernelMode,
112 PsGetCurrentProcess(),
113 MEMORY_AREA_NO_CACHE,
114 &Result,
115 NumberOfBytes,
116 0,
117 &marea);
118 if (Status!=STATUS_SUCCESS)
119 {
120 return(NULL);
121 }
122 for (i=0;i<=(NumberOfBytes/PAGESIZE);i++)
123 {
124 set_page(Result+(i*PAGESIZE),
125 PA_WRITE | PA_READ | PA_EXECUTE | PA_SYSTEM | PA_PCD | PA_PWT,
126 get_free_page());
127 }
128 return((PVOID)Result);
129 }
130
131 VOID MmFreeNonCachedMemory(PVOID BaseAddress, ULONG NumberOfBytes)
132 {
133 MmFreeMemoryArea(PsGetCurrentProcess(),BaseAddress,NumberOfBytes,TRUE);
134 }