ReactOS 0.4.16-dev-2491-g3dc6630
memory.c File Reference
#include "ndissys.h"
Include dependency graph for memory.c:

Go to the source code of this file.

Functions

NDIS_STATUS EXPORT NdisAllocateMemoryWithTag (OUT PVOID *VirtualAddress, IN UINT Length, IN ULONG Tag)
 
NDIS_STATUS EXPORT NdisAllocateMemory (OUT PVOID *VirtualAddress, IN UINT Length, IN UINT MemoryFlags, IN NDIS_PHYSICAL_ADDRESS HighestAcceptableAddress)
 
VOID EXPORT NdisFreeMemory (IN PVOID VirtualAddress, IN UINT Length, IN UINT MemoryFlags)
 
VOID EXPORT NdisMAllocateSharedMemory (IN NDIS_HANDLE MiniportAdapterHandle, IN ULONG Length, IN BOOLEAN Cached, OUT PVOID *VirtualAddress, OUT PNDIS_PHYSICAL_ADDRESS PhysicalAddress)
 
VOID NTAPI NdisMFreeSharedMemoryPassive (PDEVICE_OBJECT DeviceObject, PVOID Context)
 
VOID EXPORT NdisMFreeSharedMemory (IN NDIS_HANDLE MiniportAdapterHandle, IN ULONG Length, IN BOOLEAN Cached, IN PVOID VirtualAddress, IN NDIS_PHYSICAL_ADDRESS PhysicalAddress)
 
VOID NTAPI NdisMAllocateSharedMemoryPassive (PDEVICE_OBJECT DeviceObject, PVOID Context)
 
NDIS_STATUS EXPORT NdisMAllocateSharedMemoryAsync (IN NDIS_HANDLE MiniportAdapterHandle, IN ULONG Length, IN BOOLEAN Cached, IN PVOID Context)
 
VOID EXPORT NdisAllocateSharedMemory (IN NDIS_HANDLE NdisAdapterHandle, IN ULONG Length, IN BOOLEAN Cached, OUT PVOID *VirtualAddress, OUT PNDIS_PHYSICAL_ADDRESS PhysicalAddress)
 
VOID EXPORT NdisFreeSharedMemory (IN NDIS_HANDLE NdisAdapterHandle, IN ULONG Length, IN BOOLEAN Cached, IN PVOID VirtualAddress, IN NDIS_PHYSICAL_ADDRESS PhysicalAddress)
 

Function Documentation

◆ NdisAllocateMemory()

NDIS_STATUS EXPORT NdisAllocateMemory ( OUT PVOID VirtualAddress,
IN UINT  Length,
IN UINT  MemoryFlags,
IN NDIS_PHYSICAL_ADDRESS  HighestAcceptableAddress 
)

Definition at line 57 of file memory.c.

74{
75 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
76
77 if (MemoryFlags & NDIS_MEMORY_CONTIGUOUS)
78 {
79 /* Allocate contiguous memory (possibly noncached) */
82 ZeroAddress,
84 ZeroAddress,
85 (MemoryFlags & NDIS_MEMORY_NONCACHED) ? MmNonCached : MmCached);
86 }
87 else if (MemoryFlags & NDIS_MEMORY_NONCACHED)
88 {
89 /* Allocate noncached noncontiguous memory */
91 }
92 else
93 {
94 /* Allocate plain nonpaged memory */
96 }
97
98 if (!*VirtualAddress) {
99 NDIS_DbgPrint(MIN_TRACE, ("Allocation failed (%lx, %lx)\n", MemoryFlags, Length));
100 return NDIS_STATUS_FAILURE;
101 }
102
103 return NDIS_STATUS_SUCCESS;
104}
#define MIN_TRACE
Definition: debug.h:14
#define MAX_TRACE
Definition: debug.h:16
PVOID NTAPI MmAllocateContiguousMemorySpecifyCache(IN SIZE_T NumberOfBytes, IN PHYSICAL_ADDRESS LowestAcceptableAddress OPTIONAL, IN PHYSICAL_ADDRESS HighestAcceptableAddress, IN PHYSICAL_ADDRESS BoundaryAddressMultiple OPTIONAL, IN MEMORY_CACHING_TYPE CacheType OPTIONAL)
Definition: contmem.c:574
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
#define NonPagedPool
Definition: env_spec_w32.h:307
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
PVOID NTAPI MmAllocateNonCachedMemory(IN SIZE_T NumberOfBytes)
Definition: ncache.c:25
#define NDIS_MEMORY_CONTIGUOUS
Definition: ndis.h:579
#define NDIS_MEMORY_NONCACHED
Definition: ndis.h:580
#define NDIS_STATUS_FAILURE
Definition: ndis.h:465
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
_Out_ PNDIS_HANDLE _Out_ PUINT _In_ PNDIS_STRING _In_ NDIS_PHYSICAL_ADDRESS HighestAcceptableAddress
Definition: ndis.h:3230
#define RTL_CONSTANT_LARGE_INTEGER(quad_part)
Definition: ndissys.h:37
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define LL
Definition: tui.h:166
_Must_inspect_result_ _In_ WDFDMATRANSACTION _In_ PFN_WDF_PROGRAM_DMA _In_ WDF_DMA_DIRECTION _In_ PMDL _In_ PVOID VirtualAddress
@ MmCached
Definition: mmtypes.h:130
@ MmNonCached
Definition: mmtypes.h:129

Referenced by MiniportInitialize(), and MiQueryResources().

◆ NdisAllocateMemoryWithTag()

NDIS_STATUS EXPORT NdisAllocateMemoryWithTag ( OUT PVOID VirtualAddress,
IN UINT  Length,
IN ULONG  Tag 
)

Definition at line 21 of file memory.c.

35{
36 PVOID Block;
37
38 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
39
41 *VirtualAddress = Block;
42
43 if (!Block) {
44 NDIS_DbgPrint(MIN_TRACE, ("Failed to allocate memory (%lx)\n", Length));
46 }
47
49}
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
_Must_inspect_result_ _In_ WDFDEVICE _In_ BOOLEAN _In_opt_ PVOID Tag
Definition: wdfdevice.h:4071

Referenced by AddressRomRead(), AllocateTransmitBlocks(), AllocateTransmitBuffers(), DcAllocateRcb(), DcAllocateReceiveBuffers(), DcAllocateTransmitBlocks(), DcAllocateTransmitBuffers(), DcAllocateTransmitDescriptorsAndBuffers(), DcInitialize(), DcInitializeAdapterResources(), mem_alloc_nonpaged_block(), MiniportInitialize(), NvNetAddWakeUpPattern(), NvNetInitializeAdapterResources(), ParaNdis_AllocateMemory(), and SRomRead().

◆ NdisAllocateSharedMemory()

VOID EXPORT NdisAllocateSharedMemory ( IN NDIS_HANDLE  NdisAdapterHandle,
IN ULONG  Length,
IN BOOLEAN  Cached,
OUT PVOID VirtualAddress,
OUT PNDIS_PHYSICAL_ADDRESS  PhysicalAddress 
)

Definition at line 380 of file memory.c.

386{
387 NdisMAllocateSharedMemory(NdisAdapterHandle,
388 Length,
389 Cached,
392}
VOID EXPORT NdisMAllocateSharedMemory(IN NDIS_HANDLE MiniportAdapterHandle, IN ULONG Length, IN BOOLEAN Cached, OUT PVOID *VirtualAddress, OUT PNDIS_PHYSICAL_ADDRESS PhysicalAddress)
Definition: memory.c:149
_In_ ULONG _In_ BOOLEAN Cached
Definition: ndis.h:3789
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS PhysicalAddress
Definition: iotypes.h:1098

◆ NdisFreeMemory()

VOID EXPORT NdisFreeMemory ( IN PVOID  VirtualAddress,
IN UINT  Length,
IN UINT  MemoryFlags 
)

Definition at line 111 of file memory.c.

122{
123 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
124
125 if (MemoryFlags & NDIS_MEMORY_CONTIGUOUS)
126 {
127 /* Free contiguous memory (possibly noncached) */
129 Length,
130 (MemoryFlags & NDIS_MEMORY_NONCACHED) ? MmNonCached : MmCached);
131 }
132 else if (MemoryFlags & NDIS_MEMORY_NONCACHED)
133 {
134 /* Free noncached noncontiguous memory */
136 }
137 else
138 {
139 /* Free nonpaged pool */
141 }
142}
VOID NTAPI MmFreeContiguousMemorySpecifyCache(IN PVOID BaseAddress, IN SIZE_T NumberOfBytes, IN MEMORY_CACHING_TYPE CacheType)
Definition: contmem.c:666
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
VOID NTAPI MmFreeNonCachedMemory(IN PVOID BaseAddress, IN SIZE_T NumberOfBytes)
Definition: ncache.c:172

Referenced by AddressRomRead(), AllocatePairOfBuffersOnInit(), CreateOffloadInfo5Internal(), DcFreeAdapter(), DcFreeEeprom(), DcFreeRcb(), DcInitializeAdapterResources(), mem_free_nonpaged_block(), MiniportHalt(), MiniportInitialize(), NvNetFreeAdapter(), NvNetInitializeAdapterResources(), NvNetRemoveWakeUpPattern(), OnOidSetNdis5Offload(), OnResetWorkItem(), OnSetPowerWorkItem(), ParaNdis5_CancelSendPackets(), ParaNdis5_Halt(), ParaNdis5_Initialize(), ParaNdis5_Reset(), ParaNdis5_StopSend(), ParaNdis_DoSubmitPacket(), ParaNdis_InitializeContext(), ParaNdis_OidQuery(), ParaNdis_OidQueryCopy(), ParaNdis_OnSetPower(), ParaNdis_ProcessRxPath(), ParaNdis_ProcessTx(), PrepareSendEntry(), ReadNicConfiguration(), SRomRead(), VirtIONetFreeBufferDescriptor(), and VirtIONetRelease().

◆ NdisFreeSharedMemory()

VOID EXPORT NdisFreeSharedMemory ( IN NDIS_HANDLE  NdisAdapterHandle,
IN ULONG  Length,
IN BOOLEAN  Cached,
IN PVOID  VirtualAddress,
IN NDIS_PHYSICAL_ADDRESS  PhysicalAddress 
)

Definition at line 400 of file memory.c.

412{
413 NdisMFreeSharedMemory(NdisAdapterHandle,
414 Length,
415 Cached,
418}
VOID EXPORT NdisMFreeSharedMemory(IN NDIS_HANDLE MiniportAdapterHandle, IN ULONG Length, IN BOOLEAN Cached, IN PVOID VirtualAddress, IN NDIS_PHYSICAL_ADDRESS PhysicalAddress)
Definition: memory.c:216

◆ NdisMAllocateSharedMemory()

VOID EXPORT NdisMAllocateSharedMemory ( IN NDIS_HANDLE  MiniportAdapterHandle,
IN ULONG  Length,
IN BOOLEAN  Cached,
OUT PVOID VirtualAddress,
OUT PNDIS_PHYSICAL_ADDRESS  PhysicalAddress 
)

Definition at line 149 of file memory.c.

166{
168
169 NDIS_DbgPrint(MAX_TRACE,("Called.\n"));
170
172 {
173 KeBugCheckEx(BUGCODE_ID_DRIVER,
175 Length,
176 0,
177 1);
178 }
179
180 *VirtualAddress = Adapter->NdisMiniportBlock.SystemAdapterObject->DmaOperations->AllocateCommonBuffer(
181 Adapter->NdisMiniportBlock.SystemAdapterObject, Length, PhysicalAddress, Cached);
182}
DECLSPEC_NORETURN VOID NTAPI KeBugCheckEx(IN ULONG BugCheckCode, IN ULONG_PTR BugCheckParameter1, IN ULONG_PTR BugCheckParameter2, IN ULONG_PTR BugCheckParameter3, IN ULONG_PTR BugCheckParameter4)
Definition: debug.c:485
struct _LOGICAL_ADAPTER * PLOGICAL_ADAPTER
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
_In_ NDIS_HANDLE MiniportAdapterHandle
Definition: ndis.h:4668
NDIS_MINIPORT_BLOCK NdisMiniportBlock
Definition: miniport.h:89
uint32_t ULONG_PTR
Definition: typedefs.h:65

Referenced by AllocateReceiveBuffers(), AllocateReceiveDescriptors(), AllocateTransmitBuffers(), AllocateTransmitDescriptors(), DcAllocateRcb(), DcAllocateReceiveDescriptors(), DcAllocateTransmitBuffers(), DcAllocateTransmitDescriptorsAndBuffers(), mem_alloc_contiguous_pages(), MiAllocateSharedMemory(), MiniportInitialize(), NdisAllocateSharedMemory(), NICAllocateIoResources(), and ParaNdis_InitialAllocatePhysicalMemory().

◆ NdisMAllocateSharedMemoryAsync()

NDIS_STATUS EXPORT NdisMAllocateSharedMemoryAsync ( IN NDIS_HANDLE  MiniportAdapterHandle,
IN ULONG  Length,
IN BOOLEAN  Cached,
IN PVOID  Context 
)

Definition at line 331 of file memory.c.

336{
339
340 NDIS_DbgPrint(MAX_TRACE,("Called.\n"));
341
343
344 /* Must be NonpagedPool because by definition we're at DISPATCH_LEVEL */
346
347 if(!Memory)
348 {
349 NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources\n"));
350 return NDIS_STATUS_FAILURE;
351 }
352
353 Memory->AdapterObject = Adapter->NdisMiniportBlock.SystemAdapterObject;
354 Memory->Length = Length;
355 Memory->Cached = Cached;
356 Memory->Adapter = &Adapter->NdisMiniportBlock;
357 Memory->Context = Context;
358
360 if (!Memory->WorkItem)
361 {
362 NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources\n"));
364 return NDIS_STATUS_FAILURE;
365 }
366
367 IoQueueWorkItem(Memory->WorkItem,
370 Memory);
371
372 return NDIS_STATUS_PENDING;
373}
VOID NTAPI NdisMAllocateSharedMemoryPassive(PDEVICE_OBJECT DeviceObject, PVOID Context)
Definition: memory.c:296
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
VOID NTAPI IoQueueWorkItem(IN PIO_WORKITEM IoWorkItem, IN PIO_WORKITEM_ROUTINE WorkerRoutine, IN WORK_QUEUE_TYPE QueueType, IN PVOID Context)
Definition: iowork.c:40
PIO_WORKITEM NTAPI IoAllocateWorkItem(IN PDEVICE_OBJECT DeviceObject)
Definition: iowork.c:75
#define ASSERT(a)
Definition: mode.c:44
#define NDIS_STATUS_PENDING
Definition: ndis.h:347
_In_ PVOID Context
Definition: storport.h:2269
PDEVICE_OBJECT DeviceObject
Definition: ndis.h:2552
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ _Strict_type_match_ POOL_TYPE _In_opt_ ULONG _In_ _Out_ WDFMEMORY * Memory
Definition: wdfmemory.h:169
@ DelayedWorkQueue
Definition: extypes.h:190

◆ NdisMAllocateSharedMemoryPassive()

VOID NTAPI NdisMAllocateSharedMemoryPassive ( PDEVICE_OBJECT  DeviceObject,
PVOID  Context 
)

Definition at line 296 of file memory.c.

306{
308
309 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
310
312
313 Memory->VirtualAddress = Memory->AdapterObject->DmaOperations->AllocateCommonBuffer(
314 Memory->AdapterObject, Memory->Length, &Memory->PhysicalAddress, Memory->Cached);
315
316 if (Memory->Adapter->DriverHandle->MiniportCharacteristics.AllocateCompleteHandler)
317 Memory->Adapter->DriverHandle->MiniportCharacteristics.AllocateCompleteHandler(
318 Memory->Adapter->MiniportAdapterContext, Memory->VirtualAddress,
319 &Memory->PhysicalAddress, Memory->Length, Memory->Context);
320
321 IoFreeWorkItem(Memory->WorkItem);
323}
struct _MINIPORT_SHARED_MEMORY * PMINIPORT_SHARED_MEMORY
VOID NTAPI IoFreeWorkItem(IN PIO_WORKITEM IoWorkItem)
Definition: iowork.c:64

Referenced by NdisMAllocateSharedMemoryAsync().

◆ NdisMFreeSharedMemory()

VOID EXPORT NdisMFreeSharedMemory ( IN NDIS_HANDLE  MiniportAdapterHandle,
IN ULONG  Length,
IN BOOLEAN  Cached,
IN PVOID  VirtualAddress,
IN NDIS_PHYSICAL_ADDRESS  PhysicalAddress 
)

Definition at line 216 of file memory.c.

234{
237 PDMA_ADAPTER DmaAdapter = Adapter->NdisMiniportBlock.SystemAdapterObject;
238
239 NDIS_DbgPrint(MAX_TRACE,("Called.\n"));
240
242
243 /* Call FreeCommonBuffer synchronously if we are at PASSIVE_LEVEL */
245 {
246 /* We need this case because we free shared memory asynchronously
247 * and the miniport (and DMA adapter object) could be freed before
248 * our work item executes. Lucky for us, the scenarios where the
249 * freeing needs to be synchronous (failed init, MiniportHalt,
250 * and driver unload) are all at PASSIVE_LEVEL so we can just
251 * call FreeCommonBuffer synchronously and not have to worry
252 * about the miniport falling out from under us */
253
254 NDIS_DbgPrint(MID_TRACE,("Freeing shared memory synchronously\n"));
255
256 DmaAdapter->DmaOperations->FreeCommonBuffer(DmaAdapter,
257 Length,
260 Cached);
261 return;
262 }
263
264 /* Must be NonpagedPool because by definition we're at DISPATCH_LEVEL */
266
267 if(!Memory)
268 {
269 NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources\n"));
270 return;
271 }
272
273 Memory->AdapterObject = Adapter->NdisMiniportBlock.SystemAdapterObject;
274 Memory->Length = Length;
275 Memory->PhysicalAddress = PhysicalAddress;
276 Memory->VirtualAddress = VirtualAddress;
277 Memory->Cached = Cached;
278 Memory->Adapter = &Adapter->NdisMiniportBlock;
279
281 if (!Memory->WorkItem)
282 {
283 NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources\n"));
285 return;
286 }
287
288 IoQueueWorkItem(Memory->WorkItem,
291 Memory);
292}
#define MID_TRACE
Definition: debug.h:15
VOID NTAPI NdisMFreeSharedMemoryPassive(PDEVICE_OBJECT DeviceObject, PVOID Context)
Definition: memory.c:186
struct _DMA_OPERATIONS * DmaOperations
Definition: iotypes.h:2297
@ CriticalWorkQueue
Definition: extypes.h:189

Referenced by DcFreeAdapter(), DcFreeRcb(), MiFreeSharedMemory(), MiniportHalt(), NdisFreeSharedMemory(), NICReleaseIoResources(), NvNetFreeAdapter(), ParaNdis_CleanupContext(), and ParaNdis_FreePhysicalMemory().

◆ NdisMFreeSharedMemoryPassive()

VOID NTAPI NdisMFreeSharedMemoryPassive ( PDEVICE_OBJECT  DeviceObject,
PVOID  Context 
)

Definition at line 186 of file memory.c.

196{
198
199 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
200
202
203 Memory->AdapterObject->DmaOperations->FreeCommonBuffer(
204 Memory->AdapterObject, Memory->Length, Memory->PhysicalAddress,
205 Memory->VirtualAddress, Memory->Cached);
206
207 IoFreeWorkItem(Memory->WorkItem);
209}

Referenced by NdisMFreeSharedMemory().