ReactOS  0.4.14-dev-358-gbef841c
io.c File Reference
#include "ndissys.h"
Include dependency graph for io.c:

Go to the source code of this file.

Functions

VOID NTAPI HandleDeferredProcessing (IN PKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
 
BOOLEAN NTAPI ServiceRoutine (IN PKINTERRUPT Interrupt, IN PVOID ServiceContext)
 
VOID EXPORT NdisImmediateReadPortUchar (IN NDIS_HANDLE WrapperConfigurationContext, IN ULONG Port, OUT PUCHAR Data)
 
VOID EXPORT NdisImmediateReadPortUlong (IN NDIS_HANDLE WrapperConfigurationContext, IN ULONG Port, OUT PULONG Data)
 
VOID EXPORT NdisImmediateReadPortUshort (IN NDIS_HANDLE WrapperConfigurationContext, IN ULONG Port, OUT PUSHORT Data)
 
VOID EXPORT NdisImmediateWritePortUchar (IN NDIS_HANDLE WrapperConfigurationContext, IN ULONG Port, IN UCHAR Data)
 
VOID EXPORT NdisImmediateWritePortUlong (IN NDIS_HANDLE WrapperConfigurationContext, IN ULONG Port, IN ULONG Data)
 
VOID EXPORT NdisImmediateWritePortUshort (IN NDIS_HANDLE WrapperConfigurationContext, IN ULONG Port, IN USHORT Data)
 
IO_ALLOCATION_ACTION NTAPI NdisSubordinateMapRegisterCallback (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID MapRegisterBase, IN PVOID Context)
 
IO_ALLOCATION_ACTION NTAPI NdisBusMasterMapRegisterCallback (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID MapRegisterBase, IN PVOID Context)
 
NDIS_STATUS EXPORT NdisMAllocateMapRegisters (IN NDIS_HANDLE MiniportAdapterHandle, IN UINT DmaChannel, IN NDIS_DMA_SIZE DmaSize, IN ULONG BaseMapRegistersNeeded, IN ULONG MaximumBufferSize)
 
VOID EXPORT NdisMSetupDmaTransfer (OUT PNDIS_STATUS Status, IN NDIS_HANDLE MiniportDmaHandle, IN PNDIS_BUFFER Buffer, IN ULONG Offset, IN ULONG Length, IN BOOLEAN WriteToDevice)
 
VOID EXPORT NdisSetupDmaTransfer (OUT PNDIS_STATUS Status, IN PNDIS_HANDLE NdisDmaHandle, IN PNDIS_BUFFER Buffer, IN ULONG Offset, IN ULONG Length, IN BOOLEAN WriteToDevice)
 
VOID EXPORT NdisMCompleteDmaTransfer (OUT PNDIS_STATUS Status, IN NDIS_HANDLE MiniportDmaHandle, IN PNDIS_BUFFER Buffer, IN ULONG Offset, IN ULONG Length, IN BOOLEAN WriteToDevice)
 
VOID EXPORT NdisCompleteDmaTransfer (OUT PNDIS_STATUS Status, IN PNDIS_HANDLE NdisDmaHandle, IN PNDIS_BUFFER Buffer, IN ULONG Offset, IN ULONG Length, IN BOOLEAN WriteToDevice)
 
VOID EXPORT NdisMStartBufferPhysicalMapping (IN NDIS_HANDLE MiniportAdapterHandle, IN PNDIS_BUFFER Buffer, IN ULONG PhysicalMapRegister, IN BOOLEAN WriteToDevice, OUT PNDIS_PHYSICAL_ADDRESS_UNIT PhysicalAddressArray, OUT PUINT ArraySize)
 
VOID EXPORT NdisMCompleteBufferPhysicalMapping (IN NDIS_HANDLE MiniportAdapterHandle, IN PNDIS_BUFFER Buffer, IN ULONG PhysicalMapRegister)
 
VOID EXPORT NdisMDeregisterDmaChannel (IN NDIS_HANDLE MiniportDmaHandle)
 
VOID EXPORT NdisMDeregisterInterrupt (IN PNDIS_MINIPORT_INTERRUPT Interrupt)
 
VOID EXPORT NdisMFreeMapRegisters (IN NDIS_HANDLE MiniportAdapterHandle)
 
NDIS_STATUS EXPORT NdisMMapIoSpace (OUT PVOID *VirtualAddress, IN NDIS_HANDLE MiniportAdapterHandle, IN NDIS_PHYSICAL_ADDRESS PhysicalAddress, IN UINT Length)
 
ULONG EXPORT NdisMReadDmaCounter (IN NDIS_HANDLE MiniportDmaHandle)
 
ULONG EXPORT NdisMGetDmaAlignment (IN NDIS_HANDLE MiniportAdapterHandle)
 
NDIS_STATUS EXPORT NdisMRegisterDmaChannel (OUT PNDIS_HANDLE MiniportDmaHandle, IN NDIS_HANDLE MiniportAdapterHandle, IN UINT DmaChannel, IN BOOLEAN Dma32BitAddresses, IN PNDIS_DMA_DESCRIPTION DmaDescription, IN ULONG MaximumLength)
 
VOID EXPORT NdisAllocateDmaChannel (OUT PNDIS_STATUS Status, OUT PNDIS_HANDLE NdisDmaHandle, IN NDIS_HANDLE NdisAdapterHandle, IN PNDIS_DMA_DESCRIPTION DmaDescription, IN ULONG MaximumLength)
 
NDIS_STATUS EXPORT NdisMRegisterInterrupt (OUT PNDIS_MINIPORT_INTERRUPT Interrupt, IN NDIS_HANDLE MiniportAdapterHandle, IN UINT InterruptVector, IN UINT InterruptLevel, IN BOOLEAN RequestIsr, IN BOOLEAN SharedInterrupt, IN NDIS_INTERRUPT_MODE InterruptMode)
 
NDIS_STATUS EXPORT NdisMRegisterIoPortRange (OUT PVOID *PortOffset, IN NDIS_HANDLE MiniportAdapterHandle, IN UINT InitialPort, IN UINT NumberOfPorts)
 
VOID EXPORT NdisMDeregisterIoPortRange (IN NDIS_HANDLE MiniportAdapterHandle, IN UINT InitialPort, IN UINT NumberOfPorts, IN PVOID PortOffset)
 
VOID EXPORT NdisMUnmapIoSpace (IN NDIS_HANDLE MiniportAdapterHandle, IN PVOID VirtualAddress, IN UINT Length)
 
NDIS_STATUS EXPORT NdisMInitializeScatterGatherDma (IN NDIS_HANDLE MiniportAdapterHandle, IN BOOLEAN Dma64BitAddresses, IN ULONG MaximumPhysicalMapping)
 
VOID EXPORT NdisMapIoSpace (OUT PNDIS_STATUS Status, OUT PVOID *VirtualAddress, IN NDIS_HANDLE NdisAdapterHandle, IN NDIS_PHYSICAL_ADDRESS PhysicalAddress, IN UINT Length)
 
VOID EXPORT NdisFreeDmaChannel (IN PNDIS_HANDLE NdisDmaHandle)
 

Function Documentation

◆ HandleDeferredProcessing()

VOID NTAPI HandleDeferredProcessing ( IN PKDPC  Dpc,
IN PVOID  DeferredContext,
IN PVOID  SystemArgument1,
IN PVOID  SystemArgument2 
)

Definition at line 16 of file io.c.

29 {
31 
32  NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
33 
35 
36  /* Call the deferred interrupt service handler for this adapter */
37  (*Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.HandleInterruptHandler)(
39 
40  /* re-enable the interrupt */
41  NDIS_DbgPrint(MAX_TRACE, ("re-enabling the interrupt\n"));
42  if(Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.EnableInterruptHandler)
43  (*Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.EnableInterruptHandler)(
45 
46  NDIS_DbgPrint(MAX_TRACE, ("Leaving.\n"));
47 }
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
NDIS_MINIPORT_CHARACTERISTICS MiniportCharacteristics
Definition: miniport.h:22
#define GET_LOGICAL_ADAPTER(Handle)
Definition: miniport.h:101
NDIS_HANDLE MiniportAdapterContext
Definition: ndis.h:2510
NDIS_MINIPORT_BLOCK NdisMiniportBlock
Definition: miniport.h:89
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
#define MAX_TRACE
Definition: debug.h:16
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
PNDIS_M_DRIVER_BLOCK DriverHandle
Definition: ndis.h:2509
_In_opt_ PVOID DeferredContext
Definition: ketypes.h:675

Referenced by NdisMRegisterInterrupt().

◆ NdisAllocateDmaChannel()

VOID EXPORT NdisAllocateDmaChannel ( OUT PNDIS_STATUS  Status,
OUT PNDIS_HANDLE  NdisDmaHandle,
IN NDIS_HANDLE  NdisAdapterHandle,
IN PNDIS_DMA_DESCRIPTION  DmaDescription,
IN ULONG  MaximumLength 
)

Definition at line 922 of file io.c.

927 {
928  *Status = NdisMRegisterDmaChannel(NdisDmaHandle,
929  NdisAdapterHandle,
930  0,
931  FALSE,
932  DmaDescription,
933  MaximumLength);
934 }
NDIS_STATUS EXPORT NdisMRegisterDmaChannel(OUT PNDIS_HANDLE MiniportDmaHandle, IN NDIS_HANDLE MiniportAdapterHandle, IN UINT DmaChannel, IN BOOLEAN Dma32BitAddresses, IN PNDIS_DMA_DESCRIPTION DmaDescription, IN ULONG MaximumLength)
Definition: io.c:860
Status
Definition: gdiplustypes.h:24
UnicodeString MaximumLength
Definition: rtlfuncs.h:2982

◆ NdisBusMasterMapRegisterCallback()

IO_ALLOCATION_ACTION NTAPI NdisBusMasterMapRegisterCallback ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp,
IN PVOID  MapRegisterBase,
IN PVOID  Context 
)

Definition at line 216 of file io.c.

232 {
233  PLOGICAL_ADAPTER Adapter = Context;
234 
235  NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
236 
237  Adapter->NdisMiniportBlock.MapRegisters[Adapter->NdisMiniportBlock.CurrentMapRegister].MapRegister = MapRegisterBase;
238 
239  NDIS_DbgPrint(MAX_TRACE, ("setting event and leaving.\n"));
240 
241  KeSetEvent(Adapter->NdisMiniportBlock.AllocationEvent, 0, FALSE);
242 
243  /* We're a bus master so we can go ahead and deallocate the object now */
245 }
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
NDIS_MINIPORT_BLOCK NdisMiniportBlock
Definition: miniport.h:89
_Inout_ struct _IRP _In_ PVOID MapRegisterBase
Definition: iotypes.h:189
#define MAX_TRACE
Definition: debug.h:16
PMAP_REGISTER_ENTRY MapRegisters
Definition: ndis.h:2555
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
struct tagContext Context
Definition: acpixf.h:1030
PVOID MapRegister
Definition: haltypes.h:186

Referenced by NdisMAllocateMapRegisters().

◆ NdisCompleteDmaTransfer()

VOID EXPORT NdisCompleteDmaTransfer ( OUT PNDIS_STATUS  Status,
IN PNDIS_HANDLE  NdisDmaHandle,
IN PNDIS_BUFFER  Buffer,
IN ULONG  Offset,
IN ULONG  Length,
IN BOOLEAN  WriteToDevice 
)

Definition at line 559 of file io.c.

565 {
567  NdisDmaHandle,
568  Buffer,
569  Offset,
570  Length,
571  WriteToDevice);
572 }
VOID EXPORT NdisMCompleteDmaTransfer(OUT PNDIS_STATUS Status, IN NDIS_HANDLE MiniportDmaHandle, IN PNDIS_BUFFER Buffer, IN ULONG Offset, IN ULONG Length, IN BOOLEAN WriteToDevice)
Definition: io.c:523
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
Definition: bufpool.h:45
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
Status
Definition: gdiplustypes.h:24

◆ NdisFreeDmaChannel()

VOID EXPORT NdisFreeDmaChannel ( IN PNDIS_HANDLE  NdisDmaHandle)

Definition at line 1245 of file io.c.

1253 {
1254  NdisMDeregisterDmaChannel(NdisDmaHandle);
1255 }
VOID EXPORT NdisMDeregisterDmaChannel(IN NDIS_HANDLE MiniportDmaHandle)
Definition: io.c:681

◆ NdisImmediateReadPortUchar()

VOID EXPORT NdisImmediateReadPortUchar ( IN NDIS_HANDLE  WrapperConfigurationContext,
IN ULONG  Port,
OUT PUCHAR  Data 
)

Definition at line 107 of file io.c.

111 {
112  NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
113  *Data = READ_PORT_UCHAR(UlongToPtr(Port)); // FIXME: What to do with WrapperConfigurationContext?
114 }
CPPORT Port[4]
Definition: headless.c:34
UCHAR NTAPI READ_PORT_UCHAR(PUCHAR Address)
Definition: mach.c:528
#define UlongToPtr(u)
Definition: config.h:106
#define MAX_TRACE
Definition: debug.h:16
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40

◆ NdisImmediateReadPortUlong()

VOID EXPORT NdisImmediateReadPortUlong ( IN NDIS_HANDLE  WrapperConfigurationContext,
IN ULONG  Port,
OUT PULONG  Data 
)

Definition at line 121 of file io.c.

125 {
126  NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
127  *Data = READ_PORT_ULONG(UlongToPtr(Port)); // FIXME: What to do with WrapperConfigurationContext?
128 }
CPPORT Port[4]
Definition: headless.c:34
ULONG NTAPI READ_PORT_ULONG(IN PULONG Port)
Definition: portio.c:70
#define UlongToPtr(u)
Definition: config.h:106
#define MAX_TRACE
Definition: debug.h:16
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40

◆ NdisImmediateReadPortUshort()

VOID EXPORT NdisImmediateReadPortUshort ( IN NDIS_HANDLE  WrapperConfigurationContext,
IN ULONG  Port,
OUT PUSHORT  Data 
)

Definition at line 135 of file io.c.

139 {
140  NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
141  *Data = READ_PORT_USHORT(UlongToPtr(Port)); // FIXME: What to do with WrapperConfigurationContext?
142 }
CPPORT Port[4]
Definition: headless.c:34
#define UlongToPtr(u)
Definition: config.h:106
#define MAX_TRACE
Definition: debug.h:16
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
USHORT NTAPI READ_PORT_USHORT(IN PUSHORT Port)
Definition: portio.c:63

◆ NdisImmediateWritePortUchar()

VOID EXPORT NdisImmediateWritePortUchar ( IN NDIS_HANDLE  WrapperConfigurationContext,
IN ULONG  Port,
IN UCHAR  Data 
)

Definition at line 149 of file io.c.

153 {
154  NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
155  WRITE_PORT_UCHAR(UlongToPtr(Port), Data); // FIXME: What to do with WrapperConfigurationContext?
156 }
CPPORT Port[4]
Definition: headless.c:34
#define UlongToPtr(u)
Definition: config.h:106
#define MAX_TRACE
Definition: debug.h:16
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
void WRITE_PORT_UCHAR(PUCHAR Address, UCHAR Value)
Definition: mach.c:532

◆ NdisImmediateWritePortUlong()

VOID EXPORT NdisImmediateWritePortUlong ( IN NDIS_HANDLE  WrapperConfigurationContext,
IN ULONG  Port,
IN ULONG  Data 
)

Definition at line 163 of file io.c.

167 {
168  NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
169  WRITE_PORT_ULONG(UlongToPtr(Port), Data); // FIXME: What to do with WrapperConfigurationContext?
170 }
CPPORT Port[4]
Definition: headless.c:34
VOID NTAPI WRITE_PORT_ULONG(IN PULONG Port, IN ULONG Value)
Definition: portio.c:123
#define UlongToPtr(u)
Definition: config.h:106
#define MAX_TRACE
Definition: debug.h:16
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40

◆ NdisImmediateWritePortUshort()

VOID EXPORT NdisImmediateWritePortUshort ( IN NDIS_HANDLE  WrapperConfigurationContext,
IN ULONG  Port,
IN USHORT  Data 
)

Definition at line 177 of file io.c.

181 {
182  NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
183  WRITE_PORT_USHORT(UlongToPtr(Port), Data); // FIXME: What to do with WrapperConfigurationContext?
184 }
CPPORT Port[4]
Definition: headless.c:34
VOID NTAPI WRITE_PORT_USHORT(IN PUSHORT Port, IN USHORT Value)
Definition: portio.c:115
#define UlongToPtr(u)
Definition: config.h:106
#define MAX_TRACE
Definition: debug.h:16
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40

◆ NdisMAllocateMapRegisters()

NDIS_STATUS EXPORT NdisMAllocateMapRegisters ( IN NDIS_HANDLE  MiniportAdapterHandle,
IN UINT  DmaChannel,
IN NDIS_DMA_SIZE  DmaSize,
IN ULONG  BaseMapRegistersNeeded,
IN ULONG  MaximumBufferSize 
)

Definition at line 252 of file io.c.

287 {
289  PDMA_ADAPTER AdapterObject = 0;
290  UINT MapRegistersPerBaseRegister = 0;
291  ULONG AvailableMapRegisters;
292  NTSTATUS NtStatus;
293  PLOGICAL_ADAPTER Adapter;
295  KEVENT AllocationEvent;
296  KIRQL OldIrql;
297 
298  NDIS_DbgPrint(MAX_TRACE, ("called: Handle 0x%x, DmaChannel 0x%x, DmaSize 0x%x, BaseMapRegsNeeded: 0x%x, MaxBuffer: 0x%x.\n",
299  MiniportAdapterHandle, DmaChannel, DmaSize, BaseMapRegistersNeeded, MaximumBufferSize));
300 
301  memset(&Description,0,sizeof(Description));
302 
304 
305  ASSERT(Adapter);
306 
307  /* only bus masters may call this routine */
309  NDIS_DbgPrint(MIN_TRACE, ("Not a bus master\n"));
311  }
312 
314 
315  KeInitializeEvent(&AllocationEvent, NotificationEvent, FALSE);
316  Adapter->NdisMiniportBlock.AllocationEvent = &AllocationEvent;
317 
318  /*
319  * map registers correlate to physical pages. ndis documents a
320  * maximum of 64 map registers that it will return.
321  * at 4k pages, a 1514-byte buffer can span not more than 2 pages.
322  *
323  * the number of registers required for a given physical mapping
324  * is (first register + last register + one per page size),
325  * given that physical mapping is > 2.
326  */
327 
328  /* unhandled corner case: {1,2}-byte max buffer size */
329  ASSERT(MaximumBufferSize > 2);
330  MapRegistersPerBaseRegister = ((MaximumBufferSize-2) / (2*PAGE_SIZE)) + 2;
331 
333  Description.Master = TRUE; /* implied by calling this function */
334  Description.ScatterGather = TRUE; /* XXX UNTRUE: All BM DMA are S/G (ms seems to do this) */
335  Description.BusNumber = Adapter->NdisMiniportBlock.BusNumber;
336  Description.InterfaceType = Adapter->NdisMiniportBlock.BusType;
337  Description.DmaChannel = DmaChannel;
338  Description.MaximumLength = MaximumBufferSize;
339 
340  if(DmaSize == NDIS_DMA_64BITS)
341  Description.Dma64BitAddresses = TRUE;
342  else if(DmaSize == NDIS_DMA_32BITS)
343  Description.Dma32BitAddresses = TRUE;
344 
345  AdapterObject = IoGetDmaAdapter(
346  Adapter->NdisMiniportBlock.PhysicalDeviceObject, &Description, &AvailableMapRegisters);
347 
348  if(!AdapterObject)
349  {
350  NDIS_DbgPrint(MIN_TRACE, ("Unable to allocate an adapter object; bailing out\n"));
351  return NDIS_STATUS_RESOURCES;
352  }
353 
354  Adapter->NdisMiniportBlock.SystemAdapterObject = AdapterObject;
355 
356  if(AvailableMapRegisters < MapRegistersPerBaseRegister)
357  {
358  NDIS_DbgPrint(MIN_TRACE, ("Didn't get enough map registers from hal - requested 0x%x, got 0x%x\n",
359  MapRegistersPerBaseRegister, AvailableMapRegisters));
360 
361  AdapterObject->DmaOperations->PutDmaAdapter(AdapterObject);
362  Adapter->NdisMiniportBlock.SystemAdapterObject = NULL;
363  return NDIS_STATUS_RESOURCES;
364  }
365 
366  /* allocate & zero space in the miniport block for the registers */
367  Adapter->NdisMiniportBlock.MapRegisters = ExAllocatePool(NonPagedPool, BaseMapRegistersNeeded * sizeof(MAP_REGISTER_ENTRY));
368  if(!Adapter->NdisMiniportBlock.MapRegisters)
369  {
370  NDIS_DbgPrint(MIN_TRACE, ("insufficient resources.\n"));
371  AdapterObject->DmaOperations->PutDmaAdapter(AdapterObject);
372  Adapter->NdisMiniportBlock.SystemAdapterObject = NULL;
373  return NDIS_STATUS_RESOURCES;
374  }
375 
376  memset(Adapter->NdisMiniportBlock.MapRegisters, 0, BaseMapRegistersNeeded * sizeof(MAP_REGISTER_ENTRY));
377  Adapter->NdisMiniportBlock.BaseMapRegistersNeeded = (USHORT)BaseMapRegistersNeeded;
378 
379  while(BaseMapRegistersNeeded)
380  {
381  NDIS_DbgPrint(MAX_TRACE, ("iterating, basemapregistersneeded = %d\n", BaseMapRegistersNeeded));
382 
383  BaseMapRegistersNeeded--;
384  Adapter->NdisMiniportBlock.CurrentMapRegister = (USHORT)BaseMapRegistersNeeded;
386  {
387  NtStatus = AdapterObject->DmaOperations->AllocateAdapterChannel(
388  AdapterObject, DeviceObject, MapRegistersPerBaseRegister,
390  }
392 
393  if(!NT_SUCCESS(NtStatus))
394  {
395  NDIS_DbgPrint(MIN_TRACE, ("IoAllocateAdapterChannel failed: 0x%x\n", NtStatus));
397  AdapterObject->DmaOperations->PutDmaAdapter(AdapterObject);
398  Adapter->NdisMiniportBlock.CurrentMapRegister = Adapter->NdisMiniportBlock.BaseMapRegistersNeeded = 0;
399  Adapter->NdisMiniportBlock.SystemAdapterObject = NULL;
400  return NDIS_STATUS_RESOURCES;
401  }
402 
403  NDIS_DbgPrint(MAX_TRACE, ("waiting on event\n"));
404 
405  NtStatus = KeWaitForSingleObject(&AllocationEvent, Executive, KernelMode, FALSE, 0);
406 
407  if(!NT_SUCCESS(NtStatus))
408  {
409  NDIS_DbgPrint(MIN_TRACE, ("KeWaitForSingleObject failed: 0x%x\n", NtStatus));
411  AdapterObject->DmaOperations->PutDmaAdapter(AdapterObject);
412  Adapter->NdisMiniportBlock.CurrentMapRegister = Adapter->NdisMiniportBlock.BaseMapRegistersNeeded = 0;
413  Adapter->NdisMiniportBlock.SystemAdapterObject = NULL;
414  return NDIS_STATUS_RESOURCES;
415  }
416 
417  NDIS_DbgPrint(MAX_TRACE, ("resetting event\n"));
418 
419  KeClearEvent(&AllocationEvent);
420  }
421 
422  NDIS_DbgPrint(MAX_TRACE, ("returning success\n"));
423  return NDIS_STATUS_SUCCESS;
424 }
PDEVICE_OBJECT PhysicalDeviceObject
Definition: ndis.h:2553
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define TRUE
Definition: types.h:120
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
PDMA_ADAPTER NTAPI IoGetDmaAdapter(IN PDEVICE_OBJECT PhysicalDeviceObject, IN PDEVICE_DESCRIPTION DeviceDescription, IN OUT PULONG NumberOfMapRegisters)
Definition: pnpdma.c:23
LONG NTSTATUS
Definition: precomp.h:26
_In_ NDIS_HANDLE MiniportAdapterHandle
Definition: ndis.h:4668
static const WCHAR Description[]
Definition: oid.c:1266
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
struct _DMA_OPERATIONS * DmaOperations
Definition: iotypes.h:2187
#define DEVICE_DESCRIPTION_VERSION
Definition: iotypes.h:2020
#define NDIS_STATUS_NOT_SUPPORTED
Definition: ndis.h:479
Definition: haltypes.h:185
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define NDIS_DMA_64BITS
Definition: ndis.h:882
#define NDIS_DMA_32BITS
Definition: ndis.h:881
smooth NULL
Definition: ftsmooth.c:416
#define NDIS_ATTRIBUTE_BUS_MASTER
Definition: ndis.h:586
NDIS_MINIPORT_BLOCK NdisMiniportBlock
Definition: miniport.h:89
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
struct _LOGICAL_ADAPTER * PLOGICAL_ADAPTER
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define MAX_TRACE
Definition: debug.h:16
unsigned short USHORT
Definition: pedump.c:61
PMAP_REGISTER_ENTRY MapRegisters
Definition: ndis.h:2555
PDEVICE_OBJECT DeviceObject
Definition: ndis.h:2552
unsigned int UINT
Definition: ndis.h:50
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
#define NDIS_STATUS_RESOURCES
Definition: ndis.h:466
unsigned int ULONG
Definition: retypes.h:1
#define MIN_TRACE
Definition: debug.h:14
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
#define memset(x, y, z)
Definition: compat.h:39
NDIS_INTERFACE_TYPE BusType
Definition: ndis.h:2550
IO_ALLOCATION_ACTION NTAPI NdisBusMasterMapRegisterCallback(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID MapRegisterBase, IN PVOID Context)
Definition: io.c:216
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by MiniportInitialize().

◆ NdisMapIoSpace()

VOID EXPORT NdisMapIoSpace ( OUT PNDIS_STATUS  Status,
OUT PVOID VirtualAddress,
IN NDIS_HANDLE  NdisAdapterHandle,
IN NDIS_PHYSICAL_ADDRESS  PhysicalAddress,
IN UINT  Length 
)

Definition at line 1220 of file io.c.

1232 {
1234  NdisAdapterHandle,
1236  Length);
1237 }
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS PhysicalAddress
Definition: iotypes.h:1061
_In_ ULONG _In_ BOOLEAN _Must_inspect_result_ PVOID * VirtualAddress
Definition: ndis.h:3791
Status
Definition: gdiplustypes.h:24
NDIS_STATUS EXPORT NdisMMapIoSpace(OUT PVOID *VirtualAddress, IN NDIS_HANDLE MiniportAdapterHandle, IN NDIS_PHYSICAL_ADDRESS PhysicalAddress, IN UINT Length)
Definition: io.c:774

◆ NdisMCompleteBufferPhysicalMapping()

VOID EXPORT NdisMCompleteBufferPhysicalMapping ( IN NDIS_HANDLE  MiniportAdapterHandle,
IN PNDIS_BUFFER  Buffer,
IN ULONG  PhysicalMapRegister 
)

Definition at line 644 of file io.c.

657 {
658  PLOGICAL_ADAPTER Adapter;
659  VOID *CurrentVa;
660  ULONG Length;
661 
664 
666  CurrentVa = MmGetMdlVirtualAddress(Buffer);
668 
669  Adapter->NdisMiniportBlock.SystemAdapterObject->DmaOperations->FlushAdapterBuffers(
670  Adapter->NdisMiniportBlock.SystemAdapterObject, Buffer,
671  Adapter->NdisMiniportBlock.MapRegisters[PhysicalMapRegister].MapRegister,
672  CurrentVa, Length,
673  Adapter->NdisMiniportBlock.MapRegisters[PhysicalMapRegister].WriteToDevice);
674 }
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define MmGetMdlVirtualAddress(_Mdl)
_In_ NDIS_HANDLE MiniportAdapterHandle
Definition: ndis.h:4668
BOOLEAN WriteToDevice
Definition: haltypes.h:187
Definition: bufpool.h:45
NDIS_MINIPORT_BLOCK NdisMiniportBlock
Definition: miniport.h:89
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
struct _LOGICAL_ADAPTER * PLOGICAL_ADAPTER
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
PMAP_REGISTER_ENTRY MapRegisters
Definition: ndis.h:2555
#define MmGetMdlByteCount(_Mdl)
unsigned int ULONG
Definition: retypes.h:1
PVOID MapRegister
Definition: haltypes.h:186

◆ NdisMCompleteDmaTransfer()

VOID EXPORT NdisMCompleteDmaTransfer ( OUT PNDIS_STATUS  Status,
IN NDIS_HANDLE  MiniportDmaHandle,
IN PNDIS_BUFFER  Buffer,
IN ULONG  Offset,
IN ULONG  Length,
IN BOOLEAN  WriteToDevice 
)

Definition at line 523 of file io.c.

529 {
530  PNDIS_DMA_BLOCK DmaBlock = MiniportDmaHandle;
531  PDMA_ADAPTER AdapterObject = (PDMA_ADAPTER)DmaBlock->SystemAdapterObject;
532 
533  NDIS_DbgPrint(MAX_TRACE, ("called: Handle 0x%x, Buffer 0x%x, Offset 0x%x, Length 0x%x, WriteToDevice 0x%x\n",
534  MiniportDmaHandle, Buffer, Offset, Length, WriteToDevice));
535 
536  if (!AdapterObject->DmaOperations->FlushAdapterBuffers(AdapterObject,
537  Buffer,
538  DmaBlock->MapRegisterBase,
540  Length,
541  WriteToDevice))
542  {
543  NDIS_DbgPrint(MIN_TRACE, ("FlushAdapterBuffers failed\n"));
545  return;
546  }
547 
548  AdapterObject->DmaOperations->FreeAdapterChannel(AdapterObject);
549 
550  NDIS_DbgPrint(MAX_TRACE, ("returning success\n"));
552 }
#define MmGetMdlVirtualAddress(_Mdl)
unsigned char * PUCHAR
Definition: retypes.h:3
PVOID MapRegisterBase
Definition: ndis.h:871
PADAPTER_OBJECT SystemAdapterObject
Definition: ndis.h:873
struct _DMA_ADAPTER * PDMA_ADAPTER
struct _DMA_OPERATIONS * DmaOperations
Definition: iotypes.h:2187
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
Definition: bufpool.h:45
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
Status
Definition: gdiplustypes.h:24
#define MAX_TRACE
Definition: debug.h:16
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
#define MIN_TRACE
Definition: debug.h:14
#define NDIS_STATUS_FAILURE
Definition: ndis.h:465

Referenced by NdisCompleteDmaTransfer().

◆ NdisMDeregisterDmaChannel()

VOID EXPORT NdisMDeregisterDmaChannel ( IN NDIS_HANDLE  MiniportDmaHandle)

Definition at line 681 of file io.c.

683 {
684  PNDIS_DMA_BLOCK DmaBlock = MiniportDmaHandle;
685  PDMA_ADAPTER AdapterObject = (PDMA_ADAPTER)DmaBlock->SystemAdapterObject;
686 
687  if (AdapterObject == ((PLOGICAL_ADAPTER)DmaBlock->Miniport)->NdisMiniportBlock.SystemAdapterObject)
688  ((PLOGICAL_ADAPTER)DmaBlock->Miniport)->NdisMiniportBlock.SystemAdapterObject = NULL;
689 
690  AdapterObject->DmaOperations->PutDmaAdapter(AdapterObject);
691 
692  ExFreePool(DmaBlock);
693 }
PADAPTER_OBJECT SystemAdapterObject
Definition: ndis.h:873
struct _DMA_ADAPTER * PDMA_ADAPTER
struct _DMA_OPERATIONS * DmaOperations
Definition: iotypes.h:2187
smooth NULL
Definition: ftsmooth.c:416
if(!(yy_init))
Definition: macro.lex.yy.c:714
PVOID Miniport
Definition: ndis.h:874
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by NdisFreeDmaChannel().

◆ NdisMDeregisterInterrupt()

VOID EXPORT NdisMDeregisterInterrupt ( IN PNDIS_MINIPORT_INTERRUPT  Interrupt)

Definition at line 700 of file io.c.

707 {
708  NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
709  IoDisconnectInterrupt(Interrupt->InterruptObject);
710  Interrupt->Miniport->RegisteredInterrupts--;
711 
712  if (Interrupt->Miniport->Interrupt == Interrupt)
713  Interrupt->Miniport->Interrupt = NULL;
714 }
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI IoDisconnectInterrupt(PKINTERRUPT InterruptObject)
Definition: irq.c:140
#define MAX_TRACE
Definition: debug.h:16
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40

Referenced by MiniportHalt(), MiniportInitialize(), and NICUnregisterInterrupts().

◆ NdisMDeregisterIoPortRange()

VOID EXPORT NdisMDeregisterIoPortRange ( IN NDIS_HANDLE  MiniportAdapterHandle,
IN UINT  InitialPort,
IN UINT  NumberOfPorts,
IN PVOID  PortOffset 
)

Definition at line 1093 of file io.c.

1105 {
1109  ULONG AddressSpace = 1;
1110 
1111  NDIS_DbgPrint(MAX_TRACE, ("Called - InitialPort 0x%x, NumberOfPorts 0x%x, Port Offset 0x%x\n", InitialPort, NumberOfPorts, PortOffset));
1112 
1113  /* Translate the initial port again to find the address space of the translated address */
1115  PortAddress, &AddressSpace, &TranslatedAddress))
1116  {
1117  NDIS_DbgPrint(MIN_TRACE, ("Unable to translate address\n"));
1118  return;
1119  }
1120 
1121  /* Make sure we got the same translation as last time */
1123 
1124  /* Check if we're in memory space */
1125  if (!AddressSpace)
1126  {
1127  NDIS_DbgPrint(MAX_TRACE, ("Calling MmUnmapIoSpace\n"));
1128 
1129  /* Unmap the memory */
1131  }
1132 }
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
_In_ NDIS_HANDLE MiniportAdapterHandle
Definition: ndis.h:4668
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG _Out_ PPHYSICAL_ADDRESS TranslatedAddress
Definition: iofuncs.h:2268
uint32_t ULONG_PTR
Definition: typedefs.h:63
_In_ UINT InitialPort
Definition: ndis.h:5443
_In_ UINT _In_ UINT NumberOfPorts
Definition: ndis.h:5443
NTSYSAPI ULONGLONG WINAPI RtlConvertUlongToLargeInteger(ULONG)
Definition: largeint.c:47
NDIS_MINIPORT_BLOCK NdisMiniportBlock
Definition: miniport.h:89
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
struct _LOGICAL_ADAPTER * PLOGICAL_ADAPTER
BOOLEAN NTAPI HalTranslateBusAddress(IN INTERFACE_TYPE InterfaceType, IN ULONG BusNumber, IN PHYSICAL_ADDRESS BusAddress, IN OUT PULONG AddressSpace, OUT PPHYSICAL_ADDRESS TranslatedAddress)
Definition: bus.c:140
#define MAX_TRACE
Definition: debug.h:16
_In_ UINT _In_ UINT _In_ PVOID PortOffset
Definition: ndis.h:5443
VOID NTAPI MmUnmapIoSpace(IN PVOID BaseAddress, IN SIZE_T NumberOfBytes)
Definition: iosup.c:193
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
unsigned int ULONG
Definition: retypes.h:1
#define MIN_TRACE
Definition: debug.h:14
NDIS_INTERFACE_TYPE BusType
Definition: ndis.h:2550
LONGLONG QuadPart
Definition: typedefs.h:112

Referenced by MiniportHalt(), MiniportInitialize(), and NICReleaseIoResources().

◆ NdisMFreeMapRegisters()

VOID EXPORT NdisMFreeMapRegisters ( IN NDIS_HANDLE  MiniportAdapterHandle)

Definition at line 721 of file io.c.

729 {
730  KIRQL OldIrql;
732  PDMA_ADAPTER AdapterObject;
733  UINT MapRegistersPerBaseRegister;
734  UINT i;
735 
736  NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
737 
738  ASSERT(Adapter);
739 
740  /* only bus masters may call this routine */
742  Adapter->NdisMiniportBlock.SystemAdapterObject == NULL) {
743  NDIS_DbgPrint(MIN_TRACE, ("Not bus master or bad adapter object\n"));
744  return;
745  }
746 
747  MapRegistersPerBaseRegister = ((Adapter->NdisMiniportBlock.MaximumPhysicalMapping - 2) / PAGE_SIZE) + 2;
748 
749  AdapterObject = Adapter->NdisMiniportBlock.SystemAdapterObject;
750 
752  {
753  for(i = 0; i < Adapter->NdisMiniportBlock.BaseMapRegistersNeeded; i++)
754  {
755  AdapterObject->DmaOperations->FreeMapRegisters(
756  Adapter->NdisMiniportBlock.SystemAdapterObject,
758  MapRegistersPerBaseRegister);
759  }
760  }
762 
763  AdapterObject->DmaOperations->PutDmaAdapter(AdapterObject);
764  Adapter->NdisMiniportBlock.SystemAdapterObject = NULL;
765 
767 }
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
_In_ NDIS_HANDLE MiniportAdapterHandle
Definition: ndis.h:4668
struct _DMA_OPERATIONS * DmaOperations
Definition: iotypes.h:2187
UCHAR KIRQL
Definition: env_spec_w32.h:591
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
smooth NULL
Definition: ftsmooth.c:416
#define NDIS_ATTRIBUTE_BUS_MASTER
Definition: ndis.h:586
NDIS_MINIPORT_BLOCK NdisMiniportBlock
Definition: miniport.h:89
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
struct _LOGICAL_ADAPTER * PLOGICAL_ADAPTER
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
#define MAX_TRACE
Definition: debug.h:16
PMAP_REGISTER_ENTRY MapRegisters
Definition: ndis.h:2555
unsigned int UINT
Definition: ndis.h:50
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
#define MIN_TRACE
Definition: debug.h:14
PVOID MapRegister
Definition: haltypes.h:186
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by MiniportHalt(), and MiniportInitialize().

◆ NdisMGetDmaAlignment()

ULONG EXPORT NdisMGetDmaAlignment ( IN NDIS_HANDLE  MiniportAdapterHandle)

Definition at line 843 of file io.c.

845 {
846  /* NOTE: Unlike NdisMReadDmaCounter() above, this is a handle to the NDIS miniport block */
848  PDMA_ADAPTER AdapterObject = (PDMA_ADAPTER)Adapter->NdisMiniportBlock.SystemAdapterObject;
849 
850  NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
851 
852  return AdapterObject->DmaOperations->GetDmaAlignment(AdapterObject);
853 }
_In_ NDIS_HANDLE MiniportAdapterHandle
Definition: ndis.h:4668
struct _DMA_ADAPTER * PDMA_ADAPTER
struct _DMA_OPERATIONS * DmaOperations
Definition: iotypes.h:2187
NDIS_MINIPORT_BLOCK NdisMiniportBlock
Definition: miniport.h:89
#define MAX_TRACE
Definition: debug.h:16
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40

◆ NdisMInitializeScatterGatherDma()

NDIS_STATUS EXPORT NdisMInitializeScatterGatherDma ( IN NDIS_HANDLE  MiniportAdapterHandle,
IN BOOLEAN  Dma64BitAddresses,
IN ULONG  MaximumPhysicalMapping 
)

Definition at line 1169 of file io.c.

1179 {
1181  ULONG MapRegisters;
1182  DEVICE_DESCRIPTION DeviceDesc;
1183 
1184  NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
1185 
1187  NDIS_DbgPrint(MIN_TRACE, ("Not a bus master\n"));
1189  }
1190 
1191  RtlZeroMemory(&DeviceDesc, sizeof(DEVICE_DESCRIPTION));
1192 
1193  DeviceDesc.Version = DEVICE_DESCRIPTION_VERSION;
1194  DeviceDesc.Master = TRUE;
1195  DeviceDesc.ScatterGather = TRUE;
1196  DeviceDesc.Dma32BitAddresses = TRUE; // All callers support 32-bit addresses
1197  DeviceDesc.Dma64BitAddresses = Dma64BitAddresses;
1198  DeviceDesc.BusNumber = Adapter->NdisMiniportBlock.BusNumber;
1199  DeviceDesc.InterfaceType = Adapter->NdisMiniportBlock.BusType;
1201 
1202  Adapter->NdisMiniportBlock.SystemAdapterObject =
1203  IoGetDmaAdapter(Adapter->NdisMiniportBlock.PhysicalDeviceObject, &DeviceDesc, &MapRegisters);
1204 
1205  if (!Adapter->NdisMiniportBlock.SystemAdapterObject)
1206  return NDIS_STATUS_RESOURCES;
1207 
1208  /* FIXME: Right now we just use this as a place holder */
1209  Adapter->NdisMiniportBlock.ScatterGatherListSize = 1;
1210 
1211  return NDIS_STATUS_SUCCESS;
1212 }
PDEVICE_OBJECT PhysicalDeviceObject
Definition: ndis.h:2553
#define TRUE
Definition: types.h:120
PDMA_ADAPTER NTAPI IoGetDmaAdapter(IN PDEVICE_OBJECT PhysicalDeviceObject, IN PDEVICE_DESCRIPTION DeviceDescription, IN OUT PULONG NumberOfMapRegisters)
Definition: pnpdma.c:23
_In_ NDIS_HANDLE MiniportAdapterHandle
Definition: ndis.h:4668
#define DEVICE_DESCRIPTION_VERSION
Definition: iotypes.h:2020
#define NDIS_STATUS_NOT_SUPPORTED
Definition: ndis.h:479
_In_ BOOLEAN Dma64BitAddresses
Definition: ndis.h:4652
BOOLEAN Dma32BitAddresses
Definition: iotypes.h:2030
BOOLEAN Dma64BitAddresses
Definition: iotypes.h:2033
#define NDIS_ATTRIBUTE_BUS_MASTER
Definition: ndis.h:586
NDIS_MINIPORT_BLOCK NdisMiniportBlock
Definition: miniport.h:89
BOOLEAN ScatterGather
Definition: iotypes.h:2027
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
struct _LOGICAL_ADAPTER * PLOGICAL_ADAPTER
#define MAX_TRACE
Definition: debug.h:16
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
INTERFACE_TYPE InterfaceType
Definition: iotypes.h:2036
#define NDIS_STATUS_RESOURCES
Definition: ndis.h:466
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define MIN_TRACE
Definition: debug.h:14
NDIS_INTERFACE_TYPE BusType
Definition: ndis.h:2550
_In_ BOOLEAN _In_ ULONG MaximumPhysicalMapping
Definition: ndis.h:4652

Referenced by MiniportInitialize().

◆ NdisMMapIoSpace()

NDIS_STATUS EXPORT NdisMMapIoSpace ( OUT PVOID VirtualAddress,
IN NDIS_HANDLE  MiniportAdapterHandle,
IN NDIS_PHYSICAL_ADDRESS  PhysicalAddress,
IN UINT  Length 
)

Definition at line 774 of file io.c.

794 {
796  ULONG AddressSpace = 0; /* Memory Space */
798 
799  PAGED_CODE();
801 
802  NDIS_DbgPrint(MAX_TRACE, ("Called\n"));
803 
806  {
807  NDIS_DbgPrint(MIN_TRACE, ("Unable to translate address\n"));
808  return NDIS_STATUS_RESOURCES;
809  }
810 
812 
813  if(!*VirtualAddress) {
814  NDIS_DbgPrint(MIN_TRACE, ("MmMapIoSpace failed\n"));
815  return NDIS_STATUS_RESOURCES;
816  }
817 
818  return NDIS_STATUS_SUCCESS;
819 }
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
_In_ NDIS_HANDLE MiniportAdapterHandle
Definition: ndis.h:4668
PVOID NTAPI MmMapIoSpace(IN PHYSICAL_ADDRESS PhysicalAddress, IN SIZE_T NumberOfBytes, IN MEMORY_CACHING_TYPE CacheType)
Definition: iosup.c:47
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG _Out_ PPHYSICAL_ADDRESS TranslatedAddress
Definition: iofuncs.h:2268
#define PAGED_CODE()
Definition: video.h:57
NDIS_MINIPORT_BLOCK NdisMiniportBlock
Definition: miniport.h:89
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS PhysicalAddress
Definition: iotypes.h:1061
_In_ ULONG _In_ BOOLEAN _Must_inspect_result_ PVOID * VirtualAddress
Definition: ndis.h:3791
BOOLEAN NTAPI HalTranslateBusAddress(IN INTERFACE_TYPE InterfaceType, IN ULONG BusNumber, IN PHYSICAL_ADDRESS BusAddress, IN OUT PULONG AddressSpace, OUT PPHYSICAL_ADDRESS TranslatedAddress)
Definition: bus.c:140
#define MAX_TRACE
Definition: debug.h:16
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
#define NDIS_STATUS_RESOURCES
Definition: ndis.h:466
unsigned int ULONG
Definition: retypes.h:1
#define MIN_TRACE
Definition: debug.h:14
NDIS_INTERFACE_TYPE BusType
Definition: ndis.h:2550

Referenced by NdisMapIoSpace(), and NICAllocateIoResources().

◆ NdisMReadDmaCounter()

ULONG EXPORT NdisMReadDmaCounter ( IN NDIS_HANDLE  MiniportDmaHandle)

Definition at line 826 of file io.c.

828 {
829  /* NOTE: Unlike NdisMGetDmaAlignment() below, this is a handle to the DMA block */
830  PNDIS_DMA_BLOCK DmaBlock = MiniportDmaHandle;
831  PDMA_ADAPTER AdapterObject = (PDMA_ADAPTER)DmaBlock->SystemAdapterObject;
832 
833  NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
834 
835  return AdapterObject->DmaOperations->ReadDmaCounter(AdapterObject);
836 }
PADAPTER_OBJECT SystemAdapterObject
Definition: ndis.h:873
struct _DMA_ADAPTER * PDMA_ADAPTER
struct _DMA_OPERATIONS * DmaOperations
Definition: iotypes.h:2187
#define MAX_TRACE
Definition: debug.h:16
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40

◆ NdisMRegisterDmaChannel()

NDIS_STATUS EXPORT NdisMRegisterDmaChannel ( OUT PNDIS_HANDLE  MiniportDmaHandle,
IN NDIS_HANDLE  MiniportAdapterHandle,
IN UINT  DmaChannel,
IN BOOLEAN  Dma32BitAddresses,
IN PNDIS_DMA_DESCRIPTION  DmaDescription,
IN ULONG  MaximumLength 
)

Definition at line 860 of file io.c.

867 {
869  DEVICE_DESCRIPTION DeviceDesc;
870  ULONG MapRegisters;
871  PNDIS_DMA_BLOCK DmaBlock;
872 
873  NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
874 
875  RtlZeroMemory(&DeviceDesc, sizeof(DEVICE_DESCRIPTION));
876 
877  DeviceDesc.Version = DEVICE_DESCRIPTION_VERSION;
878  DeviceDesc.Master = (Adapter->NdisMiniportBlock.Flags & NDIS_ATTRIBUTE_BUS_MASTER);
879  DeviceDesc.ScatterGather = FALSE;
880  DeviceDesc.DemandMode = DmaDescription->DemandMode;
881  DeviceDesc.AutoInitialize = DmaDescription->AutoInitialize;
882  DeviceDesc.Dma32BitAddresses = Dma32BitAddresses;
883  DeviceDesc.Dma64BitAddresses = FALSE;
884  DeviceDesc.BusNumber = Adapter->NdisMiniportBlock.BusNumber;
885  DeviceDesc.DmaChannel = DmaDescription->DmaChannel;
886  DeviceDesc.InterfaceType = Adapter->NdisMiniportBlock.BusType;
887  DeviceDesc.DmaWidth = DmaDescription->DmaWidth;
888  DeviceDesc.DmaSpeed = DmaDescription->DmaSpeed;
889  DeviceDesc.MaximumLength = MaximumLength;
890 
891 
892  DmaBlock = ExAllocatePool(NonPagedPool, sizeof(NDIS_DMA_BLOCK));
893  if (!DmaBlock) {
894  NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources\n"));
895  return NDIS_STATUS_RESOURCES;
896  }
897 
898  DmaBlock->SystemAdapterObject = (PVOID)IoGetDmaAdapter(Adapter->NdisMiniportBlock.PhysicalDeviceObject, &DeviceDesc, &MapRegisters);
899 
900  if (!DmaBlock->SystemAdapterObject) {
901  NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources\n"));
902  ExFreePool(DmaBlock);
903  return NDIS_STATUS_RESOURCES;
904  }
905 
906  Adapter->NdisMiniportBlock.SystemAdapterObject = (PDMA_ADAPTER)DmaBlock->SystemAdapterObject;
907 
909 
910  DmaBlock->Miniport = Adapter;
911 
912  *MiniportDmaHandle = DmaBlock;
913 
914  return NDIS_STATUS_SUCCESS;
915 }
PDEVICE_OBJECT PhysicalDeviceObject
Definition: ndis.h:2553
PDMA_ADAPTER NTAPI IoGetDmaAdapter(IN PDEVICE_OBJECT PhysicalDeviceObject, IN PDEVICE_DESCRIPTION DeviceDescription, IN OUT PULONG NumberOfMapRegisters)
Definition: pnpdma.c:23
DMA_SPEED DmaSpeed
Definition: iotypes.h:2038
_In_ NDIS_HANDLE MiniportAdapterHandle
Definition: ndis.h:4668
PADAPTER_OBJECT SystemAdapterObject
Definition: ndis.h:873
struct _DMA_ADAPTER * PDMA_ADAPTER
#define DEVICE_DESCRIPTION_VERSION
Definition: iotypes.h:2020
void * PVOID
Definition: retypes.h:9
BOOLEAN Dma32BitAddresses
Definition: iotypes.h:2030
BOOLEAN Dma64BitAddresses
Definition: iotypes.h:2033
#define NDIS_ATTRIBUTE_BUS_MASTER
Definition: ndis.h:586
NDIS_MINIPORT_BLOCK NdisMiniportBlock
Definition: miniport.h:89
BOOLEAN DemandMode
Definition: iotypes.h:2028
BOOLEAN ScatterGather
Definition: iotypes.h:2027
PVOID Miniport
Definition: ndis.h:874
KEVENT AllocationEvent
Definition: ndis.h:872
DMA_WIDTH DmaWidth
Definition: iotypes.h:2037
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
struct _LOGICAL_ADAPTER * PLOGICAL_ADAPTER
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
UnicodeString MaximumLength
Definition: rtlfuncs.h:2982
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define MAX_TRACE
Definition: debug.h:16
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
INTERFACE_TYPE InterfaceType
Definition: iotypes.h:2036
#define NDIS_STATUS_RESOURCES
Definition: ndis.h:466
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define MIN_TRACE
Definition: debug.h:14
NDIS_INTERFACE_TYPE BusType
Definition: ndis.h:2550
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
BOOLEAN AutoInitialize
Definition: iotypes.h:2029

Referenced by NdisAllocateDmaChannel().

◆ NdisMRegisterInterrupt()

NDIS_STATUS EXPORT NdisMRegisterInterrupt ( OUT PNDIS_MINIPORT_INTERRUPT  Interrupt,
IN NDIS_HANDLE  MiniportAdapterHandle,
IN UINT  InterruptVector,
IN UINT  InterruptLevel,
IN BOOLEAN  RequestIsr,
IN BOOLEAN  SharedInterrupt,
IN NDIS_INTERRUPT_MODE  InterruptMode 
)

Definition at line 941 of file io.c.

962 {
964  ULONG MappedIRQ;
965  KIRQL DIrql;
968 
969  NDIS_DbgPrint(MAX_TRACE, ("Called. InterruptVector (0x%X) InterruptLevel (0x%X) "
970  "SharedInterrupt (%d) InterruptMode (0x%X)\n",
971  InterruptVector, InterruptLevel, SharedInterrupt, InterruptMode));
972 
973  RtlZeroMemory(Interrupt, sizeof(NDIS_MINIPORT_INTERRUPT));
974 
975  KeInitializeSpinLock(&Interrupt->DpcCountLock);
976 
977  KeInitializeDpc(&Interrupt->InterruptDpc, HandleDeferredProcessing, Adapter);
978 
979  KeInitializeEvent(&Interrupt->DpcsCompletedEvent, NotificationEvent, FALSE);
980 
981  Interrupt->SharedInterrupt = SharedInterrupt;
982  Interrupt->IsrRequested = RequestIsr;
983  Interrupt->Miniport = &Adapter->NdisMiniportBlock;
984 
986  InterruptLevel, InterruptVector, &DIrql,
987  &Affinity);
988 
989  NDIS_DbgPrint(MAX_TRACE, ("Connecting to interrupt vector (0x%X) Affinity (0x%X).\n", MappedIRQ, Affinity));
990 
991  Status = IoConnectInterrupt(&Interrupt->InterruptObject, ServiceRoutine, Interrupt, &Interrupt->DpcCountLock, MappedIRQ,
992  DIrql, DIrql, InterruptMode, SharedInterrupt, Affinity, FALSE);
993 
994  NDIS_DbgPrint(MAX_TRACE, ("Leaving. Status (0x%X).\n", Status));
995 
996  if (NT_SUCCESS(Status)) {
997  Adapter->NdisMiniportBlock.Interrupt = Interrupt;
998  Adapter->NdisMiniportBlock.RegisteredInterrupts++;
999  return NDIS_STATUS_SUCCESS;
1000  }
1001 
1003  {
1004  /* FIXME: Log error */
1005  NDIS_DbgPrint(MIN_TRACE, ("Resource conflict!\n"));
1007  }
1008 
1009  NDIS_DbgPrint(MIN_TRACE, ("Function failed. Status (0x%X).\n", Status));
1010  return NDIS_STATUS_FAILURE;
1011 }
_In_ PKSERVICE_ROUTINE _In_opt_ PVOID _In_opt_ PKSPIN_LOCK _In_ ULONG _In_ KIRQL _In_ KIRQL _In_ KINTERRUPT_MODE InterruptMode
Definition: iofuncs.h:798
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
NTHALAPI ULONG NTAPI HalGetInterruptVector(INTERFACE_TYPE, ULONG, ULONG, ULONG, PKIRQL, PKAFFINITY)
LONG NTSTATUS
Definition: precomp.h:26
_In_ NDIS_HANDLE MiniportAdapterHandle
Definition: ndis.h:4668
VOID NTAPI HandleDeferredProcessing(IN PKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: io.c:16
UCHAR KIRQL
Definition: env_spec_w32.h:591
NTSTATUS NTAPI IoConnectInterrupt(OUT PKINTERRUPT *InterruptObject, IN PKSERVICE_ROUTINE ServiceRoutine, IN PVOID ServiceContext, IN PKSPIN_LOCK SpinLock, IN ULONG Vector, IN KIRQL Irql, IN KIRQL SynchronizeIrql, IN KINTERRUPT_MODE InterruptMode, IN BOOLEAN ShareVector, IN KAFFINITY ProcessorEnableMask, IN BOOLEAN FloatingSave)
Definition: irq.c:22
PNDIS_MINIPORT_INTERRUPT Interrupt
Definition: ndis.h:2522
BOOLEAN NTAPI ServiceRoutine(IN PKINTERRUPT Interrupt, IN PVOID ServiceContext)
Definition: io.c:49
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:251
NDIS_MINIPORT_BLOCK NdisMiniportBlock
Definition: miniport.h:89
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_ ULONG _In_ ULONG _In_ ULONG _Out_ PKIRQL _Out_ PKAFFINITY Affinity
Definition: halfuncs.h:170
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
struct _LOGICAL_ADAPTER * PLOGICAL_ADAPTER
#define NDIS_STATUS_RESOURCE_CONFLICT
Definition: ndis.h:495
Status
Definition: gdiplustypes.h:24
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define MAX_TRACE
Definition: debug.h:16
ULONG_PTR KAFFINITY
Definition: compat.h:75
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define MIN_TRACE
Definition: debug.h:14
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:711
NDIS_INTERFACE_TYPE BusType
Definition: ndis.h:2550
#define NDIS_STATUS_FAILURE
Definition: ndis.h:465

Referenced by MiniportInitialize(), and NICRegisterInterrupts().

◆ NdisMRegisterIoPortRange()

NDIS_STATUS EXPORT NdisMRegisterIoPortRange ( OUT PVOID PortOffset,
IN NDIS_HANDLE  MiniportAdapterHandle,
IN UINT  InitialPort,
IN UINT  NumberOfPorts 
)

Definition at line 1018 of file io.c.

1033 {
1034  PHYSICAL_ADDRESS PortAddress, TranslatedAddress;
1036  ULONG AddressSpace = 1; /* FIXME The HAL handles this wrong atm */
1037 
1038  *PortOffset = 0;
1039 
1040  NDIS_DbgPrint(MAX_TRACE, ("Called - InitialPort 0x%x, NumberOfPorts 0x%x\n", InitialPort, NumberOfPorts));
1041 
1042  memset(&PortAddress, 0, sizeof(PortAddress));
1043 
1044  /*
1045  * FIXME: NDIS 5+ completely ignores the InitialPort parameter, but
1046  * we don't have a way to get the I/O base address yet (see
1047  * NDIS_MINIPORT_BLOCK->AllocatedResources and
1048  * NDIS_MINIPORT_BLOCK->AllocatedResourcesTranslated).
1049  */
1050  if(InitialPort)
1052  else
1053  ASSERT(FALSE);
1054 
1055  NDIS_DbgPrint(MAX_TRACE, ("Translating address 0x%x 0x%x\n", PortAddress.u.HighPart, PortAddress.u.LowPart));
1056 
1058  PortAddress, &AddressSpace, &TranslatedAddress))
1059  {
1060  NDIS_DbgPrint(MIN_TRACE, ("Unable to translate address\n"));
1061  return NDIS_STATUS_RESOURCES;
1062  }
1063 
1064  NDIS_DbgPrint(MAX_TRACE, ("Hal returned AddressSpace=0x%x TranslatedAddress=0x%x 0x%x\n",
1065  AddressSpace, TranslatedAddress.u.HighPart, TranslatedAddress.u.LowPart));
1066 
1067  if(AddressSpace)
1068  {
1069  ASSERT(TranslatedAddress.u.HighPart == 0);
1071  NDIS_DbgPrint(MAX_TRACE, ("Returning 0x%x\n", *PortOffset));
1072  return NDIS_STATUS_SUCCESS;
1073  }
1074 
1075  NDIS_DbgPrint(MAX_TRACE, ("calling MmMapIoSpace\n"));
1076 
1078  NDIS_DbgPrint(MAX_TRACE, ("Returning 0x%x for port range\n", *PortOffset));
1079 
1080  if(!*PortOffset) {
1081  NDIS_DbgPrint(MIN_TRACE, ("MmMapIoSpace failed\n"));
1082  return NDIS_STATUS_RESOURCES;
1083  }
1084 
1085  return NDIS_STATUS_SUCCESS;
1086 }
struct _LARGE_INTEGER::@2220 u
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
_In_ NDIS_HANDLE MiniportAdapterHandle
Definition: ndis.h:4668
PVOID NTAPI MmMapIoSpace(IN PHYSICAL_ADDRESS PhysicalAddress, IN SIZE_T NumberOfBytes, IN MEMORY_CACHING_TYPE CacheType)
Definition: iosup.c:47
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG _Out_ PPHYSICAL_ADDRESS TranslatedAddress
Definition: iofuncs.h:2268
uint32_t ULONG_PTR
Definition: typedefs.h:63
_In_ UINT InitialPort
Definition: ndis.h:5443
void * PVOID
Definition: retypes.h:9
_In_ UINT _In_ UINT NumberOfPorts
Definition: ndis.h:5443
NTSYSAPI ULONGLONG WINAPI RtlConvertUlongToLargeInteger(ULONG)
Definition: largeint.c:47
NDIS_MINIPORT_BLOCK NdisMiniportBlock
Definition: miniport.h:89
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
struct _LOGICAL_ADAPTER * PLOGICAL_ADAPTER
BOOLEAN NTAPI HalTranslateBusAddress(IN INTERFACE_TYPE InterfaceType, IN ULONG BusNumber, IN PHYSICAL_ADDRESS BusAddress, IN OUT PULONG AddressSpace, OUT PPHYSICAL_ADDRESS TranslatedAddress)
Definition: bus.c:140
#define MAX_TRACE
Definition: debug.h:16
_In_ UINT _In_ UINT _In_ PVOID PortOffset
Definition: ndis.h:5443
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
#define NDIS_STATUS_RESOURCES
Definition: ndis.h:466
unsigned int ULONG
Definition: retypes.h:1
#define MIN_TRACE
Definition: debug.h:14
#define memset(x, y, z)
Definition: compat.h:39
NDIS_INTERFACE_TYPE BusType
Definition: ndis.h:2550
LONGLONG QuadPart
Definition: typedefs.h:112

Referenced by MiniportInitialize(), and NICAllocateIoResources().

◆ NdisMSetupDmaTransfer()

VOID EXPORT NdisMSetupDmaTransfer ( OUT PNDIS_STATUS  Status,
IN NDIS_HANDLE  MiniportDmaHandle,
IN PNDIS_BUFFER  Buffer,
IN ULONG  Offset,
IN ULONG  Length,
IN BOOLEAN  WriteToDevice 
)

Definition at line 432 of file io.c.

438 {
439  PNDIS_DMA_BLOCK DmaBlock = MiniportDmaHandle;
440  NTSTATUS NtStatus;
441  PLOGICAL_ADAPTER Adapter;
442  KIRQL OldIrql;
443  PDMA_ADAPTER AdapterObject;
444  ULONG MapRegistersNeeded;
445 
446  NDIS_DbgPrint(MAX_TRACE, ("called: Handle 0x%x, Buffer 0x%x, Offset 0x%x, Length 0x%x, WriteToDevice 0x%x\n",
447  MiniportDmaHandle, Buffer, Offset, Length, WriteToDevice));
448 
449  Adapter = (PLOGICAL_ADAPTER)DmaBlock->Miniport;
450  AdapterObject = (PDMA_ADAPTER)DmaBlock->SystemAdapterObject;
451 
452  MapRegistersNeeded = (Length + (PAGE_SIZE - 1)) / PAGE_SIZE;
453 
454  KeFlushIoBuffers(Buffer, !WriteToDevice, TRUE);
455 
457  {
458  NtStatus = AdapterObject->DmaOperations->AllocateAdapterChannel(AdapterObject,
460  MapRegistersNeeded,
462  }
464 
465  if(!NT_SUCCESS(NtStatus))
466  {
467  NDIS_DbgPrint(MIN_TRACE, ("AllocateAdapterChannel failed: 0x%x\n", NtStatus));
468  AdapterObject->DmaOperations->FreeAdapterChannel(AdapterObject);
470  return;
471  }
472 
473  NtStatus = KeWaitForSingleObject(&DmaBlock->AllocationEvent, Executive, KernelMode, FALSE, 0);
474 
475  if(!NT_SUCCESS(NtStatus))
476  {
477  NDIS_DbgPrint(MIN_TRACE, ("KeWaitForSingleObject failed: 0x%x\n", NtStatus));
478  AdapterObject->DmaOperations->FreeAdapterChannel(AdapterObject);
480  return;
481  }
482 
483  /* We must throw away the return value of MapTransfer for a system DMA device */
484  AdapterObject->DmaOperations->MapTransfer(AdapterObject, Buffer,
485  DmaBlock->MapRegisterBase,
486  (PUCHAR)MmGetMdlVirtualAddress(Buffer) + Offset, &Length, WriteToDevice);
487 
488  NDIS_DbgPrint(MAX_TRACE, ("returning success\n"));
490 }
PDEVICE_OBJECT PhysicalDeviceObject
Definition: ndis.h:2553
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define TRUE
Definition: types.h:120
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
#define MmGetMdlVirtualAddress(_Mdl)
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
PVOID MapRegisterBase
Definition: ndis.h:871
PADAPTER_OBJECT SystemAdapterObject
Definition: ndis.h:873
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
struct _DMA_OPERATIONS * DmaOperations
Definition: iotypes.h:2187
UCHAR KIRQL
Definition: env_spec_w32.h:591
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
Definition: bufpool.h:45
NDIS_MINIPORT_BLOCK NdisMiniportBlock
Definition: miniport.h:89
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PVOID Miniport
Definition: ndis.h:874
KEVENT AllocationEvent
Definition: ndis.h:872
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
struct _LOGICAL_ADAPTER * PLOGICAL_ADAPTER
#define PAGE_SIZE
Definition: env_spec_w32.h:49
IO_ALLOCATION_ACTION NTAPI NdisSubordinateMapRegisterCallback(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID MapRegisterBase, IN PVOID Context)
Definition: io.c:186
Status
Definition: gdiplustypes.h:24
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
#define KeFlushIoBuffers(_Mdl, _ReadOperation, _DmaOperation)
Definition: ke.h:161
#define MAX_TRACE
Definition: debug.h:16
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
#define NDIS_STATUS_RESOURCES
Definition: ndis.h:466
unsigned int ULONG
Definition: retypes.h:1
#define MIN_TRACE
Definition: debug.h:14

Referenced by NdisSetupDmaTransfer().

◆ NdisMStartBufferPhysicalMapping()

VOID EXPORT NdisMStartBufferPhysicalMapping ( IN NDIS_HANDLE  MiniportAdapterHandle,
IN PNDIS_BUFFER  Buffer,
IN ULONG  PhysicalMapRegister,
IN BOOLEAN  WriteToDevice,
OUT PNDIS_PHYSICAL_ADDRESS_UNIT  PhysicalAddressArray,
OUT PUINT  ArraySize 
)

Definition at line 579 of file io.c.

602 {
603  PLOGICAL_ADAPTER Adapter;
604  PVOID CurrentVa;
606  PHYSICAL_ADDRESS ReturnedAddress;
607  UINT LoopCount = 0;
608 
610  ASSERT(MiniportAdapterHandle && Buffer && PhysicalAddressArray && ArraySize);
611 
613  CurrentVa = MmGetMdlVirtualAddress(Buffer);
615 
616  while(TotalLength)
617  {
619 
620  ReturnedAddress = Adapter->NdisMiniportBlock.SystemAdapterObject->DmaOperations->MapTransfer(
621  Adapter->NdisMiniportBlock.SystemAdapterObject, Buffer,
622  Adapter->NdisMiniportBlock.MapRegisters[PhysicalMapRegister].MapRegister,
623  CurrentVa, &Length, WriteToDevice);
624 
625  Adapter->NdisMiniportBlock.MapRegisters[PhysicalMapRegister].WriteToDevice = WriteToDevice;
626 
627  PhysicalAddressArray[LoopCount].PhysicalAddress = ReturnedAddress;
628  PhysicalAddressArray[LoopCount].Length = Length;
629 
630  TotalLength -= Length;
631  CurrentVa = (PVOID)((ULONG_PTR)CurrentVa + Length);
632 
633  LoopCount++;
634  }
635 
636  *ArraySize = LoopCount;
637 }
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define MmGetMdlVirtualAddress(_Mdl)
_In_ NDIS_HANDLE MiniportAdapterHandle
Definition: ndis.h:4668
_In_ ULONG TotalLength
Definition: usbdlib.h:145
BOOLEAN WriteToDevice
Definition: haltypes.h:187
uint32_t ULONG_PTR
Definition: typedefs.h:63
Definition: bufpool.h:45
void * PVOID
Definition: retypes.h:9
NDIS_MINIPORT_BLOCK NdisMiniportBlock
Definition: miniport.h:89
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
struct _LOGICAL_ADAPTER * PLOGICAL_ADAPTER
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
PMAP_REGISTER_ENTRY MapRegisters
Definition: ndis.h:2555
#define MmGetMdlByteCount(_Mdl)
unsigned int UINT
Definition: ndis.h:50
unsigned int ULONG
Definition: retypes.h:1
PVOID MapRegister
Definition: haltypes.h:186

◆ NdisMUnmapIoSpace()

VOID EXPORT NdisMUnmapIoSpace ( IN NDIS_HANDLE  MiniportAdapterHandle,
IN PVOID  VirtualAddress,
IN UINT  Length 
)

Definition at line 1139 of file io.c.

1156 {
1157  PAGED_CODE();
1158 
1160 
1162 }
_In_ NDIS_HANDLE MiniportAdapterHandle
Definition: ndis.h:4668
#define PAGED_CODE()
Definition: video.h:57
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_In_ ULONG _In_ BOOLEAN _Must_inspect_result_ PVOID * VirtualAddress
Definition: ndis.h:3791
VOID NTAPI MmUnmapIoSpace(IN PVOID BaseAddress, IN SIZE_T NumberOfBytes)
Definition: iosup.c:193

Referenced by NICReleaseIoResources().

◆ NdisSetupDmaTransfer()

VOID EXPORT NdisSetupDmaTransfer ( OUT PNDIS_STATUS  Status,
IN PNDIS_HANDLE  NdisDmaHandle,
IN PNDIS_BUFFER  Buffer,
IN ULONG  Offset,
IN ULONG  Length,
IN BOOLEAN  WriteToDevice 
)

Definition at line 497 of file io.c.

509 {
511  NdisDmaHandle,
512  Buffer,
513  Offset,
514  Length,
515  WriteToDevice);
516 }
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
VOID EXPORT NdisMSetupDmaTransfer(OUT PNDIS_STATUS Status, IN NDIS_HANDLE MiniportDmaHandle, IN PNDIS_BUFFER Buffer, IN ULONG Offset, IN ULONG Length, IN BOOLEAN WriteToDevice)
Definition: io.c:432
Definition: bufpool.h:45
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
Status
Definition: gdiplustypes.h:24

◆ NdisSubordinateMapRegisterCallback()

IO_ALLOCATION_ACTION NTAPI NdisSubordinateMapRegisterCallback ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp,
IN PVOID  MapRegisterBase,
IN PVOID  Context 
)

Definition at line 186 of file io.c.

201 {
202  PNDIS_DMA_BLOCK DmaBlock = Context;
203 
204  NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
205 
206  DmaBlock->MapRegisterBase = MapRegisterBase;
207 
208  NDIS_DbgPrint(MAX_TRACE, ("setting event and leaving.\n"));
209 
210  KeSetEvent(&DmaBlock->AllocationEvent, 0, FALSE);
211 
212  /* We have to hold the object open to keep our lock on the system DMA controller */
213  return KeepObject;
214 }
PVOID MapRegisterBase
Definition: ndis.h:871
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
KEVENT AllocationEvent
Definition: ndis.h:872
_Inout_ struct _IRP _In_ PVOID MapRegisterBase
Definition: iotypes.h:189
#define MAX_TRACE
Definition: debug.h:16
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
struct tagContext Context
Definition: acpixf.h:1030

Referenced by NdisMSetupDmaTransfer().

◆ ServiceRoutine()

BOOLEAN NTAPI ServiceRoutine ( IN PKINTERRUPT  Interrupt,
IN PVOID  ServiceContext 
)

Definition at line 49 of file io.c.

60 {
61  BOOLEAN InterruptRecognized = FALSE;
62  BOOLEAN QueueMiniportHandleInterrupt = FALSE;
64  PNDIS_MINIPORT_BLOCK NdisMiniportBlock = NdisInterrupt->Miniport;
66 
67  NDIS_DbgPrint(MAX_TRACE, ("Called. Interrupt (0x%X)\n", NdisInterrupt));
68 
69  /* Certain behavior differs if MiniportInitialize is executing when the interrupt is generated */
70  Initializing = (NdisMiniportBlock->PnPDeviceState != NdisPnPDeviceStarted);
71  NDIS_DbgPrint(MAX_TRACE, ("MiniportInitialize executing: %s\n", (Initializing ? "yes" : "no")));
72 
73  /* MiniportISR is always called for interrupts during MiniportInitialize */
74  if ((Initializing) || (NdisInterrupt->IsrRequested) || (NdisInterrupt->SharedInterrupt)) {
75  NDIS_DbgPrint(MAX_TRACE, ("Calling MiniportISR\n"));
76  (*NdisMiniportBlock->DriverHandle->MiniportCharacteristics.ISRHandler)(
77  &InterruptRecognized,
78  &QueueMiniportHandleInterrupt,
79  NdisMiniportBlock->MiniportAdapterContext);
80 
81  } else if (NdisMiniportBlock->DriverHandle->MiniportCharacteristics.DisableInterruptHandler) {
82  NDIS_DbgPrint(MAX_TRACE, ("Calling MiniportDisableInterrupt\n"));
83  (*NdisMiniportBlock->DriverHandle->MiniportCharacteristics.DisableInterruptHandler)(
84  NdisMiniportBlock->MiniportAdapterContext);
85  QueueMiniportHandleInterrupt = TRUE;
86  InterruptRecognized = TRUE;
87  }
88 
89  /* TODO: Figure out if we should call this or not if Initializing is true. It appears
90  * that calling it fixes some NICs, but documentation is contradictory on it. */
91  if (QueueMiniportHandleInterrupt)
92  {
93  NDIS_DbgPrint(MAX_TRACE, ("Queuing DPC.\n"));
94  KeInsertQueueDpc(&NdisInterrupt->InterruptDpc, NULL, NULL);
95  }
96 
97  NDIS_DbgPrint(MAX_TRACE, ("Leaving.\n"));
98 
99  return InterruptRecognized;
100 }
#define TRUE
Definition: types.h:120
NDIS_MINIPORT_CHARACTERISTICS MiniportCharacteristics
Definition: miniport.h:22
BOOLEAN NTAPI KeInsertQueueDpc(IN PKDPC Dpc, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: dpc.c:724
NDIS_HANDLE MiniportAdapterContext
Definition: ndis.h:2510
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
BOOLEAN SharedInterrupt
Definition: ndis.h:2243
_In_ PKSERVICE_ROUTINE _In_opt_ PVOID ServiceContext
Definition: iofuncs.h:798
#define MAX_TRACE
Definition: debug.h:16
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
PNDIS_MINIPORT_BLOCK Miniport
Definition: ndis.h:2239
PNDIS_M_DRIVER_BLOCK DriverHandle
Definition: ndis.h:2509

Referenced by NdisMRegisterInterrupt().