9ee7f062fdfde1f8c4bbba660b59add58b1c224b
[reactos.git] / reactos / drivers / net / ndis / ndis / memory.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS NDIS library
4 * FILE: ndis/memory.c
5 * PURPOSE: Memory management routines
6 * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
7 * REVISIONS:
8 * CSH 01/08-2000 Created
9 */
10 #include <ndissys.h>
11
12
13 /*
14 * @implemented
15 */
16 NDIS_STATUS
17 EXPORT
18 NdisAllocateMemoryWithTag(
19 OUT PVOID *VirtualAddress,
20 IN UINT Length,
21 IN ULONG Tag)
22 /*
23 * FUNCTION: Allocates a block of memory, with a 32-bit tag
24 * ARGUMENTS:
25 * VirtualAddress = a pointer to the returned memory block
26 * Length = the number of requested bytes
27 * Tag = 32-bit pool tag
28 * NOTES:
29 * NDIS 5.0
30 */
31 {
32 PVOID Block;
33
34 /* Plain nonpaged memory with tag */
35 Block = ExAllocatePoolWithTag(NonPagedPool, Length, Tag);
36 *VirtualAddress = Block;
37 if (!Block)
38 return NDIS_STATUS_FAILURE;
39
40 return NDIS_STATUS_SUCCESS;
41 }
42
43
44 /*
45 * @unimplemented
46 */
47 VOID
48 EXPORT
49 NdisCreateLookaheadBufferFromSharedMemory(
50 IN PVOID pSharedMemory,
51 IN UINT LookaheadLength,
52 OUT PVOID *pLookaheadBuffer)
53 {
54 UNIMPLEMENTED
55 }
56
57
58 /*
59 * @unimplemented
60 */
61 VOID
62 EXPORT
63 NdisDestroyLookaheadBufferFromSharedMemory(
64 IN PVOID pLookaheadBuffer)
65 {
66 UNIMPLEMENTED
67 }
68
69
70 /*
71 * @unimplemented
72 */
73 VOID
74 EXPORT
75 NdisMoveFromMappedMemory(
76 OUT PVOID Destination,
77 IN PVOID Source,
78 IN ULONG Length)
79 {
80 UNIMPLEMENTED
81 }
82
83
84 /*
85 * @unimplemented
86 */
87 VOID
88 EXPORT
89 NdisMoveMappedMemory(
90 OUT PVOID Destination,
91 IN PVOID Source,
92 IN ULONG Length)
93 {
94 RtlCopyMemory(Destination,Source,Length);
95 }
96
97
98 /*
99 * @unimplemented
100 */
101 VOID
102 EXPORT
103 NdisMoveToMappedMemory(
104 OUT PVOID Destination,
105 IN PVOID Source,
106 IN ULONG Length)
107 {
108 UNIMPLEMENTED
109 }
110
111
112 /*
113 * @unimplemented
114 */
115 VOID
116 EXPORT
117 NdisMUpdateSharedMemory(
118 IN NDIS_HANDLE MiniportAdapterHandle,
119 IN ULONG Length,
120 IN PVOID VirtualAddress,
121 IN NDIS_PHYSICAL_ADDRESS PhysicalAddress)
122 {
123 UNIMPLEMENTED
124 }
125
126
127 /*
128 * @unimplemented
129 */
130 NDIS_STATUS
131 EXPORT
132 NdisAllocateMemory(
133 OUT PVOID *VirtualAddress,
134 IN UINT Length,
135 IN UINT MemoryFlags,
136 IN NDIS_PHYSICAL_ADDRESS HighestAcceptableAddress)
137 /*
138 * FUNCTION: Allocates a block of memory
139 * ARGUMENTS:
140 * VirtualAddress = Address of buffer to place virtual
141 * address of the allocated memory
142 * Length = Size of the memory block to allocate
143 * MemoryFlags = Flags to specify special restrictions
144 * HighestAcceptableAddress = Specifies -1
145 */
146 {
147 if (MemoryFlags & NDIS_MEMORY_NONCACHED)
148 {
149 *VirtualAddress = MmAllocateNonCachedMemory(Length);
150 if(!*VirtualAddress)
151 return NDIS_STATUS_FAILURE;
152
153 return NDIS_STATUS_SUCCESS;
154 }
155
156 if (MemoryFlags & NDIS_MEMORY_CONTIGUOUS)
157 {
158 *VirtualAddress = MmAllocateContiguousMemory(Length, HighestAcceptableAddress);
159 if(!*VirtualAddress)
160 return NDIS_STATUS_FAILURE;
161
162 return NDIS_STATUS_SUCCESS;
163 }
164
165 /* Plain nonpaged memory */
166 *VirtualAddress = ExAllocatePool(NonPagedPool, Length);
167 if (!*VirtualAddress)
168 return NDIS_STATUS_FAILURE;
169
170 return NDIS_STATUS_SUCCESS;
171 }
172
173
174 /*
175 * @unimplemented
176 */
177 VOID
178 EXPORT
179 NdisFreeMemory(
180 IN PVOID VirtualAddress,
181 IN UINT Length,
182 IN UINT MemoryFlags)
183 /*
184 * FUNCTION: Frees a memory block allocated with NdisAllocateMemory
185 * ARGUMENTS:
186 * VirtualAddress = Pointer to the base virtual address of the allocated memory
187 * Length = Size of the allocated memory block as passed to NdisAllocateMemory
188 * MemoryFlags = Memory flags passed to NdisAllocateMemory
189 */
190 {
191 if (MemoryFlags & NDIS_MEMORY_NONCACHED)
192 {
193 MmFreeNonCachedMemory(VirtualAddress, Length);
194 return;
195 }
196
197 if (MemoryFlags & NDIS_MEMORY_CONTIGUOUS)
198 {
199 MmFreeContiguousMemory(VirtualAddress);
200 return;
201 }
202
203 ExFreePool(VirtualAddress);
204 }
205
206
207 /*
208 * @unimplemented
209 */
210 VOID
211 EXPORT
212 NdisImmediateReadSharedMemory(
213 IN NDIS_HANDLE WrapperConfigurationContext,
214 IN ULONG SharedMemoryAddress,
215 OUT PUCHAR Buffer,
216 IN ULONG Length)
217 {
218 UNIMPLEMENTED
219 }
220
221
222 /*
223 * @unimplemented
224 */
225 VOID
226 EXPORT
227 NdisImmediateWriteSharedMemory(
228 IN NDIS_HANDLE WrapperConfigurationContext,
229 IN ULONG SharedMemoryAddress,
230 IN PUCHAR Buffer,
231 IN ULONG Length)
232 {
233 UNIMPLEMENTED
234 }
235
236
237 /*
238 * @unimplemented
239 */
240 VOID
241 EXPORT
242 NdisMAllocateSharedMemory(
243 IN NDIS_HANDLE MiniportAdapterHandle,
244 IN ULONG Length,
245 IN BOOLEAN Cached,
246 OUT PVOID *VirtualAddress,
247 OUT PNDIS_PHYSICAL_ADDRESS PhysicalAddress)
248 {
249 UNIMPLEMENTED
250 }
251
252
253 /*
254 * @unimplemented
255 */
256 NDIS_STATUS
257 EXPORT
258 NdisMAllocateSharedMemoryAsync(
259 IN NDIS_HANDLE MiniportAdapterHandle,
260 IN ULONG Length,
261 IN BOOLEAN Cached,
262 IN PVOID Context)
263 {
264 UNIMPLEMENTED
265
266 return NDIS_STATUS_FAILURE;
267 }
268
269
270 /*
271 * @unimplemented
272 */
273 VOID
274 EXPORT
275 NdisMFreeSharedMemory(
276 IN NDIS_HANDLE MiniportAdapterHandle,
277 IN ULONG Length,
278 IN BOOLEAN Cached,
279 IN PVOID VirtualAddress,
280 IN NDIS_PHYSICAL_ADDRESS PhysicalAddress)
281 {
282 UNIMPLEMENTED
283 }
284
285 /* EOF */