ReactOS  0.4.15-dev-3165-gdf6fff7
usbport.c File Reference
#include "usbport.h"
#include <debug.h>
#include "usbdebug.h"
Include dependency graph for usbport.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define NDEBUG_USBPORT_CORE
 
#define NDEBUG_USBPORT_INTERRUPT
 
#define NDEBUG_USBPORT_TIMER
 

Functions

PDEVICE_OBJECT NTAPI USBPORT_FindUSB2Controller (IN PDEVICE_OBJECT FdoDevice)
 
VOID NTAPI USBPORT_AddUSB1Fdo (IN PDEVICE_OBJECT FdoDevice)
 
VOID NTAPI USBPORT_AddUSB2Fdo (IN PDEVICE_OBJECT FdoDevice)
 
VOID NTAPI USBPORT_RemoveUSBxFdo (IN PDEVICE_OBJECT FdoDevice)
 
BOOLEAN NTAPI USBPORT_IsCompanionFdoExtension (IN PDEVICE_OBJECT USB2FdoDevice, IN PUSBPORT_DEVICE_EXTENSION USB1FdoExtension)
 
PDEVICE_RELATIONS NTAPI USBPORT_FindCompanionControllers (IN PDEVICE_OBJECT USB2FdoDevice, IN BOOLEAN IsObRefer, IN BOOLEAN IsFDOsReturned)
 
MPSTATUS NTAPI USBPORT_NtStatusToMpStatus (NTSTATUS NtStatus)
 
NTSTATUS NTAPI USBPORT_SetRegistryKeyValue (IN PDEVICE_OBJECT DeviceObject, IN BOOL UseDriverKey, IN ULONG Type, IN PCWSTR ValueNameString, IN PVOID Data, IN ULONG DataSize)
 
NTSTATUS NTAPI USBPORT_GetRegistryKeyValueFullInfo (IN PDEVICE_OBJECT FdoDevice, IN PDEVICE_OBJECT PdoDevice, IN BOOL UseDriverKey, IN PCWSTR SourceString, IN ULONG LengthStr, IN PVOID Buffer, IN ULONG BufferLength)
 
MPSTATUS NTAPI USBPORT_GetMiniportRegistryKeyValue (IN PVOID MiniPortExtension, IN BOOL UseDriverKey, IN PCWSTR SourceString, IN SIZE_T LengthStr, IN PVOID Buffer, IN SIZE_T BufferLength)
 
NTSTATUS NTAPI USBPORT_GetSetConfigSpaceData (IN PDEVICE_OBJECT FdoDevice, IN BOOLEAN IsReadData, IN PVOID Buffer, IN ULONG Offset, IN ULONG Length)
 
MPSTATUS NTAPI USBPORT_ReadWriteConfigSpace (IN PVOID MiniPortExtension, IN BOOLEAN IsReadData, IN PVOID Buffer, IN ULONG Offset, IN ULONG Length)
 
NTSTATUS NTAPI USBPORT_USBDStatusToNtStatus (IN PURB Urb, IN USBD_STATUS USBDStatus)
 
NTSTATUS NTAPI USBPORT_Wait (IN PVOID MiniPortExtension, IN ULONG Milliseconds)
 
VOID NTAPI USBPORT_MiniportInterrupts (IN PDEVICE_OBJECT FdoDevice, IN BOOLEAN IsEnable)
 
VOID NTAPI USBPORT_SoftInterruptDpc (IN PRKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
 
VOID NTAPI USBPORT_SoftInterrupt (IN PDEVICE_OBJECT FdoDevice)
 
VOID NTAPI USBPORT_InvalidateControllerHandler (IN PDEVICE_OBJECT FdoDevice, IN ULONG Type)
 
ULONG NTAPI USBPORT_InvalidateController (IN PVOID MiniPortExtension, IN ULONG Type)
 
ULONG NTAPI USBPORT_NotifyDoubleBuffer (IN PVOID MiniPortExtension, IN PVOID MiniPortTransfer, IN PVOID Buffer, IN SIZE_T Length)
 
VOID NTAPI USBPORT_WorkerRequestDpc (IN PRKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
 
VOID NTAPI USBPORT_DoneTransfer (IN PUSBPORT_TRANSFER Transfer)
 
VOID NTAPI USBPORT_FlushDoneTransfers (IN PDEVICE_OBJECT FdoDevice)
 
VOID NTAPI USBPORT_TransferFlushDpc (IN PRKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
 
BOOLEAN NTAPI USBPORT_QueueDoneTransfer (IN PUSBPORT_TRANSFER Transfer, IN USBD_STATUS USBDStatus)
 
VOID NTAPI USBPORT_DpcHandler (IN PDEVICE_OBJECT FdoDevice)
 
VOID NTAPI USBPORT_IsrDpcHandler (IN PDEVICE_OBJECT FdoDevice, IN BOOLEAN IsDpcHandler)
 
VOID NTAPI USBPORT_IsrDpc (IN PRKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
 
BOOLEAN NTAPI USBPORT_InterruptService (IN PKINTERRUPT Interrupt, IN PVOID ServiceContext)
 
VOID NTAPI USBPORT_SignalWorkerThread (IN PDEVICE_OBJECT FdoDevice)
 
VOID NTAPI USBPORT_WorkerThreadHandler (IN PDEVICE_OBJECT FdoDevice)
 
VOID NTAPI USBPORT_DoRootHubCallback (IN PDEVICE_OBJECT FdoDevice)
 
VOID NTAPI USBPORT_SynchronizeRootHubCallback (IN PDEVICE_OBJECT FdoDevice, IN PDEVICE_OBJECT Usb2FdoDevice)
 
VOID NTAPI USBPORT_WorkerThread (IN PVOID StartContext)
 
NTSTATUS NTAPI USBPORT_CreateWorkerThread (IN PDEVICE_OBJECT FdoDevice)
 
VOID NTAPI USBPORT_StopWorkerThread (IN PDEVICE_OBJECT FdoDevice)
 
VOID NTAPI USBPORT_SynchronizeControllersStart (IN PDEVICE_OBJECT FdoDevice)
 
VOID NTAPI USBPORT_TimerDpc (IN PRKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
 
BOOLEAN NTAPI USBPORT_StartTimer (IN PDEVICE_OBJECT FdoDevice, IN ULONG Time)
 
PUSBPORT_COMMON_BUFFER_HEADER NTAPI USBPORT_AllocateCommonBuffer (IN PDEVICE_OBJECT FdoDevice, IN SIZE_T BufferLength)
 
VOID NTAPI USBPORT_FreeCommonBuffer (IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_COMMON_BUFFER_HEADER HeaderBuffer)
 
PUSBPORT_MINIPORT_INTERFACE NTAPI USBPORT_FindMiniPort (IN PDRIVER_OBJECT DriverObject)
 
NTSTATUS NTAPI USBPORT_AddDevice (IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject)
 
VOID NTAPI USBPORT_Unload (IN PDRIVER_OBJECT DriverObject)
 
VOID NTAPI USBPORT_MiniportCompleteTransfer (IN PVOID MiniPortExtension, IN PVOID MiniPortEndpoint, IN PVOID TransferParameters, IN USBD_STATUS USBDStatus, IN ULONG TransferLength)
 
VOID NTAPI USBPORT_AsyncTimerDpc (IN PRKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
 
ULONG NTAPI USBPORT_RequestAsyncCallback (IN PVOID MiniPortExtension, IN ULONG TimerValue, IN PVOID Buffer, IN SIZE_T Length, IN ASYNC_TIMER_CALLBACK *Callback)
 
PVOID NTAPI USBPORT_GetMappedVirtualAddress (IN ULONG PhysicalAddress, IN PVOID MiniPortExtension, IN PVOID MiniPortEndpoint)
 
ULONG NTAPI USBPORT_InvalidateEndpoint (IN PVOID MiniPortExtension, IN PVOID MiniPortEndpoint)
 
VOID NTAPI USBPORT_CompleteTransfer (IN PURB Urb, IN USBD_STATUS TransferStatus)
 
IO_ALLOCATION_ACTION NTAPI USBPORT_MapTransfer (IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp, IN PVOID MapRegisterBase, IN PVOID Context)
 
VOID NTAPI USBPORT_FlushMapTransfers (IN PDEVICE_OBJECT FdoDevice)
 
USBD_STATUS NTAPI USBPORT_AllocateTransfer (IN PDEVICE_OBJECT FdoDevice, IN PURB Urb, IN PUSBPORT_DEVICE_HANDLE DeviceHandle, IN PIRP Irp, IN PRKEVENT Event)
 
NTSTATUS NTAPI USBPORT_Dispatch (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
ULONG NTAPI USBPORT_GetHciMn (VOID)
 
NTSTATUS NTAPI USBPORT_RegisterUSBPortDriver (IN PDRIVER_OBJECT DriverObject, IN ULONG Version, IN PUSBPORT_REGISTRATION_PACKET RegPacket)
 
NTSTATUS NTAPI DriverEntry (IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
 

Variables

LIST_ENTRY USBPORT_MiniPortDrivers = {NULL, NULL}
 
LIST_ENTRY USBPORT_USB1FdoList = {NULL, NULL}
 
LIST_ENTRY USBPORT_USB2FdoList = {NULL, NULL}
 
KSPIN_LOCK USBPORT_SpinLock
 
BOOLEAN USBPORT_Initialized = FALSE
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 10 of file usbport.c.

◆ NDEBUG_USBPORT_CORE

#define NDEBUG_USBPORT_CORE

Definition at line 13 of file usbport.c.

◆ NDEBUG_USBPORT_INTERRUPT

#define NDEBUG_USBPORT_INTERRUPT

Definition at line 14 of file usbport.c.

◆ NDEBUG_USBPORT_TIMER

#define NDEBUG_USBPORT_TIMER

Definition at line 15 of file usbport.c.

Function Documentation

◆ DriverEntry()

NTSTATUS NTAPI DriverEntry ( IN PDRIVER_OBJECT  DriverObject,
IN PUNICODE_STRING  RegistryPath 
)

Definition at line 2898 of file usbport.c.

2900 {
2901  return STATUS_SUCCESS;
2902 }
#define STATUS_SUCCESS
Definition: shellext.h:65

◆ USBPORT_AddDevice()

NTSTATUS NTAPI USBPORT_AddDevice ( IN PDRIVER_OBJECT  DriverObject,
IN PDEVICE_OBJECT  PhysicalDeviceObject 
)

Definition at line 1833 of file usbport.c.

1835 {
1836  NTSTATUS Status;
1837  PUSBPORT_MINIPORT_INTERFACE MiniPortInterface;
1838  ULONG DeviceNumber = 0;
1839  WCHAR CharDeviceName[64];
1843  PUSBPORT_COMMON_DEVICE_EXTENSION FdoCommonExtension;
1844  PDEVICE_OBJECT LowerDevice;
1845  ULONG Length;
1846 
1847  DPRINT("USBPORT_AddDevice: DriverObject - %p, PhysicalDeviceObject - %p\n",
1848  DriverObject,
1850 
1851  MiniPortInterface = USBPORT_FindMiniPort(DriverObject);
1852 
1853  if (!MiniPortInterface)
1854  {
1855  DPRINT("USBPORT_AddDevice: USBPORT_FindMiniPort not found MiniPortInterface\n");
1856  return STATUS_UNSUCCESSFUL;
1857  }
1858 
1859  while (TRUE)
1860  {
1861  /* Construct device name */
1862  RtlStringCbPrintfW(CharDeviceName,
1863  sizeof(CharDeviceName),
1864  L"\\Device\\USBFDO-%d",
1865  DeviceNumber);
1866 
1867  RtlInitUnicodeString(&DeviceName, CharDeviceName);
1868 
1869  ASSERT(MiniPortInterface->Packet.MiniPortExtensionSize <=
1871  Length = (ULONG)(sizeof(USBPORT_DEVICE_EXTENSION) +
1872  MiniPortInterface->Packet.MiniPortExtensionSize +
1873  sizeof(USB2_HC_EXTENSION));
1874 
1875  /* Create device */
1877  Length,
1878  &DeviceName,
1880  0,
1881  FALSE,
1882  &DeviceObject);
1883 
1884  /* Check for success */
1885  if (NT_SUCCESS(Status)) break;
1886 
1887  /* Is there a device object with that same name */
1888  if ((Status == STATUS_OBJECT_NAME_EXISTS) ||
1890  {
1891  /* Try the next name */
1892  DeviceNumber++;
1893  continue;
1894  }
1895 
1896  /* Bail out on other errors */
1897  if (!NT_SUCCESS(Status))
1898  {
1899  DPRINT1("USBPORT_AddDevice: failed to create %wZ, Status %x\n",
1900  &DeviceName,
1901  Status);
1902 
1903  return Status;
1904  }
1905  }
1906 
1907  DPRINT("USBPORT_AddDevice: created device %p <%wZ>, Status %x\n",
1908  DeviceObject,
1909  &DeviceName,
1910  Status);
1911 
1912  FdoExtension = DeviceObject->DeviceExtension;
1913  FdoCommonExtension = &FdoExtension->CommonExtension;
1914 
1916 
1917  FdoCommonExtension->SelfDevice = DeviceObject;
1918  FdoCommonExtension->LowerPdoDevice = PhysicalDeviceObject;
1919  FdoCommonExtension->IsPDO = FALSE;
1920 
1923 
1924  FdoCommonExtension->LowerDevice = LowerDevice;
1925 
1926  FdoCommonExtension->DevicePowerState = PowerDeviceD3;
1927 
1928  FdoExtension->MiniPortExt = (PVOID)((ULONG_PTR)FdoExtension +
1929  sizeof(USBPORT_DEVICE_EXTENSION));
1930 
1931  if (MiniPortInterface->Packet.MiniPortFlags & USB_MINIPORT_FLAGS_USB2)
1932  {
1933  FdoExtension->Usb2Extension =
1934  (PUSB2_HC_EXTENSION)((ULONG_PTR)FdoExtension->MiniPortExt +
1935  MiniPortInterface->Packet.MiniPortExtensionSize);
1936 
1937  DPRINT("USBPORT_AddDevice: Usb2Extension - %p\n",
1938  FdoExtension->Usb2Extension);
1939 
1940  USB2_InitController(FdoExtension->Usb2Extension);
1941  }
1942  else
1943  {
1944  FdoExtension->Usb2Extension = NULL;
1945  }
1946 
1947  FdoExtension->MiniPortInterface = MiniPortInterface;
1948  FdoExtension->FdoNameNumber = DeviceNumber;
1949 
1950  KeInitializeSemaphore(&FdoExtension->DeviceSemaphore, 1, 1);
1951  KeInitializeSemaphore(&FdoExtension->ControllerSemaphore, 1, 1);
1952 
1953  InitializeListHead(&FdoExtension->EndpointList);
1954  InitializeListHead(&FdoExtension->DoneTransferList);
1955  InitializeListHead(&FdoExtension->WorkerList);
1956  InitializeListHead(&FdoExtension->EpStateChangeList);
1957  InitializeListHead(&FdoExtension->MapTransferList);
1958  InitializeListHead(&FdoExtension->DeviceHandleList);
1959  InitializeListHead(&FdoExtension->IdleIrpList);
1960  InitializeListHead(&FdoExtension->BadRequestList);
1961  InitializeListHead(&FdoExtension->EndpointClosedList);
1962 
1964 
1965  return Status;
1966 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
#define STATUS_OBJECT_NAME_COLLISION
Definition: udferr_usr.h:150
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define TRUE
Definition: types.h:120
PDEVICE_OBJECT LowerPdoDevice
Definition: usbport.h:282
#define STATUS_OBJECT_NAME_EXISTS
Definition: ntstatus.h:114
LONG NTSTATUS
Definition: precomp.h:26
USBPORT_REGISTRATION_PACKET Packet
Definition: usbmport.h:644
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1155
struct _USB2_HC_EXTENSION USB2_HC_EXTENSION
PUSBPORT_MINIPORT_INTERFACE NTAPI USBPORT_FindMiniPort(IN PDRIVER_OBJECT DriverObject)
Definition: usbport.c:1793
uint32_t ULONG_PTR
Definition: typedefs.h:65
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3272
#define FILE_DEVICE_CONTROLLER
Definition: winioctl.h:110
#define FALSE
Definition: types.h:117
#define USB_MINIPORT_FLAGS_USB2
Definition: usbmport.h:534
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:966
struct _USBPORT_DEVICE_EXTENSION USBPORT_DEVICE_EXTENSION
void * PVOID
Definition: retypes.h:9
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
Status
Definition: gdiplustypes.h:24
VOID NTAPI KeInitializeSemaphore(IN PKSEMAPHORE Semaphore, IN LONG Count, IN LONG Limit)
Definition: semphobj.c:22
#define ASSERT(a)
Definition: mode.c:44
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTRSAFEVAPI RtlStringCbPrintfW(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _In_ _Printf_format_string_ NTSTRSAFE_PCWSTR pszFormat,...)
Definition: ntstrsafe.h:1173
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
struct _USB2_HC_EXTENSION * PUSB2_HC_EXTENSION
Definition: usbport.h:157
static const WCHAR L[]
Definition: oid.c:1250
#define MAXULONG
Definition: typedefs.h:251
DEVICE_POWER_STATE DevicePowerState
Definition: usbport.h:287
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
VOID NTAPI USB2_InitController(IN PUSB2_HC_EXTENSION HcExtension)
Definition: usb2.c:2217
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
_In_ PCHAR _In_ ULONG DeviceNumber
Definition: classpnp.h:1229
#define DPRINT
Definition: sndvol32.h:71

Referenced by USBPORT_RegisterUSBPortDriver().

◆ USBPORT_AddUSB1Fdo()

VOID NTAPI USBPORT_AddUSB1Fdo ( IN PDEVICE_OBJECT  FdoDevice)

Definition at line 66 of file usbport.c.

67 {
69 
70  DPRINT("USBPORT_AddUSB1Fdo: FdoDevice - %p\n", FdoDevice);
71 
72  FdoExtension = FdoDevice->DeviceExtension;
74 
76  &FdoExtension->ControllerLink,
78 }
LIST_ENTRY USBPORT_USB1FdoList
Definition: usbport.c:19
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
#define USBPORT_FLAG_REGISTERED_FDO
Definition: usbport.h:79
KSPIN_LOCK USBPORT_SpinLock
Definition: usbport.c:22
#define DPRINT
Definition: sndvol32.h:71

Referenced by USBPORT_FdoPnP().

◆ USBPORT_AddUSB2Fdo()

VOID NTAPI USBPORT_AddUSB2Fdo ( IN PDEVICE_OBJECT  FdoDevice)

Definition at line 82 of file usbport.c.

83 {
85 
86  DPRINT("USBPORT_AddUSB2Fdo: FdoDevice - %p\n", FdoDevice);
87 
88  FdoExtension = FdoDevice->DeviceExtension;
90 
92  &FdoExtension->ControllerLink,
94 }
LIST_ENTRY USBPORT_USB2FdoList
Definition: usbport.c:20
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
#define USBPORT_FLAG_REGISTERED_FDO
Definition: usbport.h:79
KSPIN_LOCK USBPORT_SpinLock
Definition: usbport.c:22
#define DPRINT
Definition: sndvol32.h:71

Referenced by USBPORT_FdoPnP().

◆ USBPORT_AllocateCommonBuffer()

PUSBPORT_COMMON_BUFFER_HEADER NTAPI USBPORT_AllocateCommonBuffer ( IN PDEVICE_OBJECT  FdoDevice,
IN SIZE_T  BufferLength 
)

Definition at line 1708 of file usbport.c.

1710 {
1711  PUSBPORT_COMMON_BUFFER_HEADER HeaderBuffer = NULL;
1713  PDMA_ADAPTER DmaAdapter;
1714  PDMA_OPERATIONS DmaOperations;
1715  SIZE_T HeaderSize;
1716  ULONG Length = 0;
1717  ULONG LengthPadded;
1718  PHYSICAL_ADDRESS LogicalAddress;
1719  ULONG_PTR BaseVA;
1720  ULONG_PTR StartBufferVA;
1721  ULONG StartBufferPA;
1722 
1723  DPRINT("USBPORT_AllocateCommonBuffer: FdoDevice - %p, BufferLength - %p\n",
1724  FdoDevice,
1725  BufferLength);
1726 
1727  if (BufferLength == 0)
1728  goto Exit;
1729 
1730  FdoExtension = FdoDevice->DeviceExtension;
1731 
1732  DmaAdapter = FdoExtension->DmaAdapter;
1733  DmaOperations = DmaAdapter->DmaOperations;
1734 
1735  HeaderSize = sizeof(USBPORT_COMMON_BUFFER_HEADER);
1736  Length = ROUND_TO_PAGES(BufferLength + HeaderSize);
1737  LengthPadded = Length - (BufferLength + HeaderSize);
1738 
1739  BaseVA = (ULONG_PTR)DmaOperations->AllocateCommonBuffer(DmaAdapter,
1740  Length,
1741  &LogicalAddress,
1742  TRUE);
1743 
1744  if (!BaseVA)
1745  goto Exit;
1746 
1747  StartBufferVA = BaseVA & ~(PAGE_SIZE - 1);
1748  StartBufferPA = LogicalAddress.LowPart & ~(PAGE_SIZE - 1);
1749 
1750  HeaderBuffer = (PUSBPORT_COMMON_BUFFER_HEADER)(StartBufferVA +
1751  BufferLength +
1752  LengthPadded);
1753 
1754  HeaderBuffer->Length = Length;
1755  HeaderBuffer->BaseVA = BaseVA;
1756  HeaderBuffer->LogicalAddress = LogicalAddress;
1757 
1758  HeaderBuffer->BufferLength = BufferLength + LengthPadded;
1759  HeaderBuffer->VirtualAddress = StartBufferVA;
1760  HeaderBuffer->PhysicalAddress = StartBufferPA;
1761 
1762  RtlZeroMemory((PVOID)StartBufferVA, BufferLength + LengthPadded);
1763 
1764 Exit:
1765  return HeaderBuffer;
1766 }
PALLOCATE_COMMON_BUFFER AllocateCommonBuffer
Definition: iotypes.h:2635
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3767
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define TRUE
Definition: types.h:120
struct _USBPORT_COMMON_BUFFER_HEADER USBPORT_COMMON_BUFFER_HEADER
struct _USBPORT_COMMON_BUFFER_HEADER * PUSBPORT_COMMON_BUFFER_HEADER
struct _DMA_OPERATIONS * DmaOperations
Definition: iotypes.h:2295
uint32_t ULONG_PTR
Definition: typedefs.h:65
static void Exit(void)
Definition: sock.c:1331
ULONG LowPart
Definition: typedefs.h:106
#define PAGE_SIZE
Definition: env_spec_w32.h:49
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define ROUND_TO_PAGES(Size)
#define NULL
Definition: types.h:112
PHYSICAL_ADDRESS LogicalAddress
Definition: usbport.h:149
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define ULONG_PTR
Definition: config.h:101
#define DPRINT
Definition: sndvol32.h:71

Referenced by USBPORT_OpenPipe(), USBPORT_ReopenPipe(), and USBPORT_StartDevice().

◆ USBPORT_AllocateTransfer()

USBD_STATUS NTAPI USBPORT_AllocateTransfer ( IN PDEVICE_OBJECT  FdoDevice,
IN PURB  Urb,
IN PUSBPORT_DEVICE_HANDLE  DeviceHandle,
IN PIRP  Irp,
IN PRKEVENT  Event 
)

Definition at line 2543 of file usbport.c.

2548 {
2550  SIZE_T TransferLength;
2551  PMDL Mdl;
2552  ULONG_PTR VirtualAddr;
2553  ULONG PagesNeed = 0;
2554  SIZE_T PortTransferLength;
2555  SIZE_T FullTransferLength;
2556  PUSBPORT_TRANSFER Transfer;
2558  USBD_STATUS USBDStatus;
2559  SIZE_T IsoBlockLen = 0;
2560 
2561  DPRINT_CORE("USBPORT_AllocateTransfer: FdoDevice - %p, Urb - %p, DeviceHandle - %p, Irp - %p, Event - %p\n",
2562  FdoDevice,
2563  Urb,
2564  DeviceHandle,
2565  Irp,
2566  Event);
2567 
2568  FdoExtension = FdoDevice->DeviceExtension;
2569 
2570  TransferLength = Urb->UrbControlTransfer.TransferBufferLength;
2571  PipeHandle = Urb->UrbControlTransfer.PipeHandle;
2572 
2573  if (TransferLength)
2574  {
2575  Mdl = Urb->UrbControlTransfer.TransferBufferMDL;
2576  VirtualAddr = (ULONG_PTR)MmGetMdlVirtualAddress(Mdl);
2577 
2578  PagesNeed = ADDRESS_AND_SIZE_TO_SPAN_PAGES(VirtualAddr,
2579  TransferLength);
2580  if (PagesNeed > 0)
2581  {
2582  PagesNeed--;
2583  }
2584  }
2585 
2586  if (Urb->UrbHeader.Function == URB_FUNCTION_ISOCH_TRANSFER)
2587  {
2588  DPRINT1("USBPORT_AllocateTransfer: ISOCH_TRANSFER UNIMPLEMENTED. FIXME\n");
2589 
2590  //IsoBlockLen = sizeof(USBPORT_ISO_BLOCK) +
2591  // Urb->UrbIsochronousTransfer.NumberOfPackets *
2592  // sizeof(USBPORT_ISO_BLOCK_PACKET);
2593  }
2594 
2595  PortTransferLength = sizeof(USBPORT_TRANSFER) +
2596  PagesNeed * sizeof(USBPORT_SCATTER_GATHER_ELEMENT) +
2597  IsoBlockLen;
2598 
2599  FullTransferLength = PortTransferLength +
2600  FdoExtension->MiniPortInterface->Packet.MiniPortTransferSize;
2601 
2603  FullTransferLength,
2604  USB_PORT_TAG);
2605 
2606  if (!Transfer)
2607  {
2608  DPRINT1("USBPORT_AllocateTransfer: Transfer not allocated!\n");
2610  }
2611 
2612  RtlZeroMemory(Transfer, FullTransferLength);
2613 
2614  Transfer->Irp = Irp;
2615  Transfer->Urb = Urb;
2616  Transfer->Endpoint = PipeHandle->Endpoint;
2617  Transfer->Event = Event;
2618  Transfer->PortTransferLength = PortTransferLength;
2619  Transfer->FullTransferLength = FullTransferLength;
2620  Transfer->IsoBlockPtr = NULL;
2621  Transfer->Period = 0;
2622  Transfer->ParentTransfer = Transfer;
2623 
2624  if (IsoBlockLen)
2625  {
2626  Transfer->IsoBlockPtr = (PVOID)((ULONG_PTR)Transfer +
2627  PortTransferLength - IsoBlockLen);
2628 
2629  Transfer->Period = PipeHandle->Endpoint->EndpointProperties.Period;
2630  Transfer->Flags |= TRANSFER_FLAG_ISO;
2631  }
2632 
2633  Transfer->MiniportTransfer = (PVOID)((ULONG_PTR)Transfer +
2634  PortTransferLength);
2635 
2637 
2638  Urb->UrbControlTransfer.hca.Reserved8[0] = Transfer;
2639  Urb->UrbHeader.UsbdFlags |= USBD_FLAG_ALLOCATED_TRANSFER;
2640 
2641  USBDStatus = USBD_STATUS_SUCCESS;
2642 
2643  DPRINT_CORE("USBPORT_AllocateTransfer: return USBDStatus - %x\n",
2644  USBDStatus);
2645 
2646  return USBDStatus;
2647 }
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
struct _USBPORT_TRANSFER USBPORT_TRANSFER
_Inout_ PUSB_DEVICE_HANDLE DeviceHandle
Definition: hubbusif.h:121
#define MmGetMdlVirtualAddress(_Mdl)
#define USBD_FLAG_ALLOCATED_TRANSFER
Definition: usbport.h:123
PRKEVENT Event
Definition: usbport.h:249
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define USBD_STATUS_INSUFFICIENT_RESOURCES
Definition: usb.h:204
#define USB_PORT_TAG
Definition: usbport.h:44
struct _USBPORT_TRANSFER * ParentTransfer
Definition: usbport.h:264
_In_ PIRP Irp
Definition: csq.h:116
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:467
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:238
void * PVOID
Definition: retypes.h:9
#define ADDRESS_AND_SIZE_TO_SPAN_PAGES(_Va, _Size)
SIZE_T PortTransferLength
Definition: usbport.h:251
PUSBPORT_ENDPOINT Endpoint
Definition: usbport.h:253
PVOID MiniportTransfer
Definition: usbport.h:250
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define USBD_STATUS_SUCCESS
Definition: usb.h:170
LONG USBD_STATUS
Definition: usb.h:165
#define TRANSFER_FLAG_ISO
Definition: usbport.h:135
SIZE_T FullTransferLength
Definition: usbport.h:252
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define URB_FUNCTION_ISOCH_TRANSFER
Definition: usb.h:96
static HANDLE PipeHandle
Definition: dhcpcsvc.c:22
#define NULL
Definition: types.h:112
_In_ WDFDEVICE _In_ PVOID _In_opt_ PMDL Mdl
#define DPRINT1
Definition: precomp.h:8
PUSBPORT_ISO_BLOCK IsoBlockPtr
Definition: usbport.h:269
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define ULONG_PTR
Definition: config.h:101
KSPIN_LOCK TransferSpinLock
Definition: usbport.h:265

Referenced by USBPORT_SendSetupPacket(), and USBPORT_ValidateURB().

◆ USBPORT_AsyncTimerDpc()

VOID NTAPI USBPORT_AsyncTimerDpc ( IN PRKDPC  Dpc,
IN PVOID  DeferredContext,
IN PVOID  SystemArgument1,
IN PVOID  SystemArgument2 
)

Definition at line 2056 of file usbport.c.

2060 {
2061  PDEVICE_OBJECT FdoDevice;
2063  PUSBPORT_ASYNC_CALLBACK_DATA AsyncCallbackData;
2064 
2065  DPRINT("USBPORT_AsyncTimerDpc: ...\n");
2066 
2067  AsyncCallbackData = DeferredContext;
2068  FdoDevice = AsyncCallbackData->FdoDevice;
2069  FdoExtension = FdoDevice->DeviceExtension;
2070 
2071  (*AsyncCallbackData->CallbackFunction)(FdoExtension->MiniPortExt,
2072  &AsyncCallbackData->CallbackContext);
2073 
2074  ExFreePoolWithTag(AsyncCallbackData, USB_PORT_TAG);
2075 }
PDEVICE_OBJECT FdoDevice
Definition: usbport.h:434
#define USB_PORT_TAG
Definition: usbport.h:44
PVOID DeviceExtension
Definition: env_spec_w32.h:418
ASYNC_TIMER_CALLBACK * CallbackFunction
Definition: usbport.h:437
#define DPRINT
Definition: sndvol32.h:71
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
_In_opt_ PVOID DeferredContext
Definition: ketypes.h:675

Referenced by USBPORT_RequestAsyncCallback().

◆ USBPORT_CompleteTransfer()

VOID NTAPI USBPORT_CompleteTransfer ( IN PURB  Urb,
IN USBD_STATUS  TransferStatus 
)

Definition at line 2198 of file usbport.c.

2200 {
2201  struct _URB_CONTROL_TRANSFER *UrbTransfer;
2202  PUSBPORT_TRANSFER Transfer;
2203  NTSTATUS Status;
2204  PIRP Irp;
2205  KIRQL OldIrql;
2206  PRKEVENT Event;
2208  BOOLEAN IsFlushSuccess;
2209  PMDL Mdl;
2210  ULONG_PTR CurrentVa;
2211  SIZE_T TransferLength;
2212  PUSBPORT_ENDPOINT Endpoint;
2213  PDEVICE_OBJECT FdoDevice;
2215  PDMA_OPERATIONS DmaOperations;
2216 
2217  DPRINT("USBPORT_CompleteTransfer: Urb - %p, TransferStatus - %X\n",
2218  Urb,
2219  TransferStatus);
2220 
2221  UrbTransfer = &Urb->UrbControlTransfer;
2222  Transfer = UrbTransfer->hca.Reserved8[0];
2223 
2224  Transfer->USBDStatus = TransferStatus;
2225  Status = USBPORT_USBDStatusToNtStatus(Urb, TransferStatus);
2226 
2227  UrbTransfer->TransferBufferLength = Transfer->CompletedTransferLen;
2228 
2229  if (Transfer->Flags & TRANSFER_FLAG_DMA_MAPPED)
2230  {
2231  Endpoint = Transfer->Endpoint;
2232  FdoDevice = Endpoint->FdoDevice;
2233  FdoExtension = FdoDevice->DeviceExtension;
2234  DmaOperations = FdoExtension->DmaAdapter->DmaOperations;
2235 
2237  Mdl = UrbTransfer->TransferBufferMDL;
2238  CurrentVa = (ULONG_PTR)MmGetMdlVirtualAddress(Mdl);
2239  TransferLength = UrbTransfer->TransferBufferLength;
2240 
2241  IsFlushSuccess = DmaOperations->FlushAdapterBuffers(FdoExtension->DmaAdapter,
2242  Mdl,
2243  Transfer->MapRegisterBase,
2244  (PVOID)CurrentVa,
2245  TransferLength,
2246  WriteToDevice);
2247 
2248  if (!IsFlushSuccess)
2249  {
2250  DPRINT("USBPORT_CompleteTransfer: no FlushAdapterBuffers !!!\n");
2251  ASSERT(FALSE);
2252  }
2253 
2255 
2256  DmaOperations->FreeMapRegisters(FdoExtension->DmaAdapter,
2257  Transfer->MapRegisterBase,
2258  Transfer->NumberOfMapRegisters);
2259 
2261  }
2262 
2263  if (Urb->UrbHeader.UsbdFlags & USBD_FLAG_ALLOCATED_MDL)
2264  {
2265  IoFreeMdl(Transfer->TransferBufferMDL);
2266  Urb->UrbHeader.UsbdFlags |= ~USBD_FLAG_ALLOCATED_MDL;
2267  }
2268 
2269  Urb->UrbControlTransfer.hca.Reserved8[0] = NULL;
2270  Urb->UrbHeader.UsbdFlags |= ~USBD_FLAG_ALLOCATED_TRANSFER;
2271 
2272  Irp = Transfer->Irp;
2273 
2274  if (Irp)
2275  {
2276  if (!NT_SUCCESS(Status))
2277  {
2278  //DbgBreakPoint();
2279  DPRINT1("USBPORT_CompleteTransfer: Irp - %p complete with Status - %lx\n",
2280  Irp,
2281  Status);
2282 
2283  USBPORT_DumpingURB(Urb);
2284  }
2285 
2286  Irp->IoStatus.Status = Status;
2287  Irp->IoStatus.Information = 0;
2288 
2292  }
2293 
2294  Event = Transfer->Event;
2295 
2296  if (Event)
2297  {
2299  }
2300 
2301  ExFreePoolWithTag(Transfer, USB_PORT_TAG);
2302 
2303  DPRINT_CORE("USBPORT_CompleteTransfer: exit\n");
2304 }
ULONG NumberOfMapRegisters
Definition: usbport.h:260
#define USBPORT_DMA_DIRECTION_TO_DEVICE
Definition: usbport.h:42
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
VOID NTAPI USBPORT_DumpingURB(IN PURB Urb)
Definition: debug.c:225
#define MmGetMdlVirtualAddress(_Mdl)
PFREE_MAP_REGISTERS FreeMapRegisters
Definition: iotypes.h:2640
LONG NTSTATUS
Definition: precomp.h:26
#define USBD_FLAG_ALLOCATED_TRANSFER
Definition: usbport.h:123
PMDL TransferBufferMDL
Definition: usbport.h:255
PRKEVENT Event
Definition: usbport.h:249
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define TRANSFER_FLAG_DMA_MAPPED
Definition: usbport.h:131
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define USB_PORT_TAG
Definition: usbport.h:44
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
PDEVICE_OBJECT FdoDevice
Definition: usbport.h:206
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:467
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
#define IoCompleteRequest
Definition: irp.c:1240
struct _URB_HCD_AREA hca
Definition: usb.h:474
KIRQL OldIrql
Definition: mm.h:1502
PUSBPORT_ENDPOINT Endpoint
Definition: usbport.h:253
PFLUSH_ADAPTER_BUFFERS FlushAdapterBuffers
Definition: iotypes.h:2638
Status
Definition: gdiplustypes.h:24
PMDL TransferBufferMDL
Definition: usb.h:472
#define USBD_FLAG_ALLOCATED_MDL
Definition: usbport.h:121
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID NTAPI IoFreeMdl(PMDL Mdl)
Definition: iomdl.c:146
NTSTATUS NTAPI USBPORT_USBDStatusToNtStatus(IN PURB Urb, IN USBD_STATUS USBDStatus)
Definition: usbport.c:485
_In_ PSCSI_REQUEST_BLOCK _In_opt_ PVOID _In_ ULONG _In_ BOOLEAN WriteToDevice
Definition: cdrom.h:989
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define EVENT_INCREMENT
Definition: iotypes.h:597
#define NULL
Definition: types.h:112
VOID NTAPI KeRaiseIrql(KIRQL NewIrql, PKIRQL OldIrql)
Definition: spinlock.c:27
_In_ WDFDEVICE _In_ PVOID _In_opt_ PMDL Mdl
#define DPRINT1
Definition: precomp.h:8
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define ULONG_PTR
Definition: config.h:101
#define DPRINT
Definition: sndvol32.h:71
USBD_STATUS USBDStatus
Definition: usbport.h:258
VOID NTAPI KeLowerIrql(KIRQL NewIrql)
Definition: spinlock.c:39
ULONG CompletedTransferLen
Definition: usbport.h:259
PVOID MapRegisterBase
Definition: usbport.h:261
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
ULONG TransferBufferLength
Definition: usb.h:470

Referenced by USBPORT_CancelPendingTransferIrp(), USBPORT_DoneTransfer(), USBPORT_FlushCancelList(), USBPORT_FlushPendingTransfers(), and USBPORT_QueuePendingTransferIrp().

◆ USBPORT_CreateWorkerThread()

NTSTATUS NTAPI USBPORT_CreateWorkerThread ( IN PDEVICE_OBJECT  FdoDevice)

Definition at line 1427 of file usbport.c.

1428 {
1430  NTSTATUS Status;
1431 
1432  DPRINT("USBPORT_CreateWorkerThread ...\n");
1433 
1434  FdoExtension = FdoDevice->DeviceExtension;
1435 
1437 
1438  KeInitializeEvent(&FdoExtension->WorkerThreadEvent,
1440  FALSE);
1441 
1442  Status = PsCreateSystemThread(&FdoExtension->WorkerThreadHandle,
1444  NULL,
1445  NULL,
1446  NULL,
1448  (PVOID)FdoDevice);
1449 
1450  return Status;
1451 }
#define THREAD_ALL_ACCESS
Definition: nt_native.h:1339
LONG NTSTATUS
Definition: precomp.h:26
#define FALSE
Definition: types.h:117
Status
Definition: gdiplustypes.h:24
#define USBPORT_FLAG_WORKER_THREAD_ON
Definition: usbport.h:69
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
VOID NTAPI USBPORT_WorkerThread(IN PVOID StartContext)
Definition: usbport.c:1368
NTSTATUS NTAPI PsCreateSystemThread(OUT PHANDLE ThreadHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN HANDLE ProcessHandle, IN PCLIENT_ID ClientId, IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext)
Definition: thread.c:602
#define NULL
Definition: types.h:112
#define DPRINT
Definition: sndvol32.h:71

Referenced by USBPORT_StartDevice().

◆ USBPORT_Dispatch()

NTSTATUS NTAPI USBPORT_Dispatch ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 2651 of file usbport.c.

2653 {
2654  PUSBPORT_COMMON_DEVICE_EXTENSION DeviceExtension;
2655  PIO_STACK_LOCATION IoStack;
2657 
2658  DeviceExtension = DeviceObject->DeviceExtension;
2659  IoStack = IoGetCurrentIrpStackLocation(Irp);
2660 
2661  if (DeviceExtension->PnpStateFlags & USBPORT_PNP_STATE_FAILED)
2662  {
2663  DPRINT1("USBPORT_Dispatch: USBPORT_PNP_STATE_FAILED\n");
2664  DbgBreakPoint();
2665  }
2666 
2667  switch (IoStack->MajorFunction)
2668  {
2669  case IRP_MJ_DEVICE_CONTROL:
2670  if (DeviceExtension->IsPDO)
2671  {
2672  DPRINT("USBPORT_Dispatch: PDO IRP_MJ_DEVICE_CONTROL. Major - %d, Minor - %d\n",
2673  IoStack->MajorFunction,
2674  IoStack->MinorFunction);
2675 
2677  }
2678  else
2679  {
2680  DPRINT("USBPORT_Dispatch: FDO IRP_MJ_DEVICE_CONTROL. Major - %d, Minor - %d\n",
2681  IoStack->MajorFunction,
2682  IoStack->MinorFunction);
2683 
2685  }
2686 
2687  break;
2688 
2690  if (DeviceExtension->IsPDO)
2691  {
2692  DPRINT("USBPORT_Dispatch: PDO IRP_MJ_INTERNAL_DEVICE_CONTROL. Major - %d, Minor - %d\n",
2693  IoStack->MajorFunction,
2694  IoStack->MinorFunction);
2695 
2697  }
2698  else
2699  {
2700  DPRINT("USBPORT_Dispatch: FDO IRP_MJ_INTERNAL_DEVICE_CONTROL. Major - %d, Minor - %d\n",
2701  IoStack->MajorFunction,
2702  IoStack->MinorFunction);
2703 
2705  }
2706 
2707  break;
2708 
2709  case IRP_MJ_POWER:
2710  if (DeviceExtension->IsPDO)
2711  {
2712  DPRINT("USBPORT_Dispatch: PDO IRP_MJ_POWER. Major - %d, Minor - %d\n",
2713  IoStack->MajorFunction,
2714  IoStack->MinorFunction);
2715 
2717  }
2718  else
2719  {
2720  DPRINT("USBPORT_Dispatch: FDO IRP_MJ_POWER. Major - %d, Minor - %d\n",
2721  IoStack->MajorFunction,
2722  IoStack->MinorFunction);
2723 
2725  }
2726 
2727  break;
2728 
2729  case IRP_MJ_SYSTEM_CONTROL:
2730  if (DeviceExtension->IsPDO)
2731  {
2732  DPRINT("USBPORT_Dispatch: PDO IRP_MJ_SYSTEM_CONTROL. Major - %d, Minor - %d\n",
2733  IoStack->MajorFunction,
2734  IoStack->MinorFunction);
2735 
2736  Status = Irp->IoStatus.Status;
2738  }
2739  else
2740  {
2741  DPRINT("USBPORT_Dispatch: FDO IRP_MJ_SYSTEM_CONTROL. Major - %d, Minor - %d\n",
2742  IoStack->MajorFunction,
2743  IoStack->MinorFunction);
2744 
2746  Status = IoCallDriver(DeviceExtension->LowerDevice, Irp);
2747  }
2748 
2749  break;
2750 
2751  case IRP_MJ_PNP:
2752  if (DeviceExtension->IsPDO)
2753  {
2754  DPRINT("USBPORT_Dispatch: PDO IRP_MJ_PNP. Major - %d, Minor - %d\n",
2755  IoStack->MajorFunction,
2756  IoStack->MinorFunction);
2757 
2759  }
2760  else
2761  {
2762  DPRINT("USBPORT_Dispatch: FDO IRP_MJ_PNP. Major - %d, Minor - %d\n",
2763  IoStack->MajorFunction,
2764  IoStack->MinorFunction);
2765 
2767  }
2768 
2769  break;
2770 
2771  case IRP_MJ_CREATE:
2772  case IRP_MJ_CLOSE:
2773  DPRINT("USBPORT_Dispatch: IRP_MJ_CREATE | IRP_MJ_CLOSE\n");
2774  Irp->IoStatus.Status = Status;
2776  break;
2777 
2778  default:
2779  if (DeviceExtension->IsPDO)
2780  {
2781  DPRINT("USBPORT_Dispatch: PDO unhandled IRP_MJ_???. Major - %d, Minor - %d\n",
2782  IoStack->MajorFunction,
2783  IoStack->MinorFunction);
2784  }
2785  else
2786  {
2787  DPRINT("USBPORT_Dispatch: FDO unhandled IRP_MJ_???. Major - %d, Minor - %d\n",
2788  IoStack->MajorFunction,
2789  IoStack->MinorFunction);
2790  }
2791 
2793  Irp->IoStatus.Status = Status;
2795  break;
2796  }
2797 
2798  DPRINT("USBPORT_Dispatch: Status - %x\n", Status);
2799  return Status;
2800 }
NTSTATUS NTAPI USBPORT_PdoPower(IN PDEVICE_OBJECT PdoDevice, IN PIRP Irp)
Definition: power.c:322
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
NTSTATUS NTAPI USBPORT_PdoInternalDeviceControl(IN PDEVICE_OBJECT PdoDevice, IN PIRP Irp)
Definition: ioctl.c:317
NTSTATUS NTAPI USBPORT_FdoDeviceControl(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp)
Definition: ioctl.c:396
NTSTATUS NTAPI USBPORT_FdoPnP(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp)
Definition: pnp.c:1110
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define USBPORT_PNP_STATE_FAILED
Definition: usbport.h:89
_In_ PIRP Irp
Definition: csq.h:116
VOID NTAPI DbgBreakPoint(VOID)
#define IoCompleteRequest
Definition: irp.c:1240
NTSTATUS NTAPI USBPORT_PdoPnP(IN PDEVICE_OBJECT PdoDevice, IN PIRP Irp)
Definition: pnp.c:1517
Status
Definition: gdiplustypes.h:24
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
#define IRP_MJ_POWER
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define IRP_MJ_SYSTEM_CONTROL
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define DPRINT1
Definition: precomp.h:8
NTSTATUS NTAPI USBPORT_FdoPower(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp)
Definition: power.c:489
NTSTATUS NTAPI USBPORT_PdoDeviceControl(IN PDEVICE_OBJECT PdoDevice, IN PIRP Irp)
Definition: ioctl.c:308
#define IO_NO_INCREMENT
Definition: iotypes.h:598
NTSTATUS NTAPI USBPORT_FdoInternalDeviceControl(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp)
Definition: ioctl.c:454
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52

Referenced by USBPORT_RegisterUSBPortDriver().

◆ USBPORT_DoneTransfer()

VOID NTAPI USBPORT_DoneTransfer ( IN PUSBPORT_TRANSFER  Transfer)

Definition at line 724 of file usbport.c.

725 {
726  PUSBPORT_ENDPOINT Endpoint;
727  PDEVICE_OBJECT FdoDevice;
729  PURB Urb;
730  PIRP Irp;
731  KIRQL CancelIrql;
732  KIRQL OldIrql;
733 
734  DPRINT_CORE("USBPORT_DoneTransfer: Transfer - %p\n", Transfer);
735 
736  Endpoint = Transfer->Endpoint;
737  FdoDevice = Endpoint->FdoDevice;
738  FdoExtension = FdoDevice->DeviceExtension;
739 
740  Urb = Transfer->Urb;
741  Irp = Transfer->Irp;
742 
743  KeAcquireSpinLock(&FdoExtension->FlushTransferSpinLock, &OldIrql);
744 
745  if (Irp)
746  {
747  IoAcquireCancelSpinLock(&CancelIrql);
749  IoReleaseCancelSpinLock(CancelIrql);
750 
752  }
753 
754  KeReleaseSpinLock(&FdoExtension->FlushTransferSpinLock, OldIrql);
755 
756  USBPORT_USBDStatusToNtStatus(Transfer->Urb, Transfer->USBDStatus);
757  USBPORT_CompleteTransfer(Urb, Urb->UrbHeader.Status);
758 
759  DPRINT_CORE("USBPORT_DoneTransfer: exit\n");
760 }
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
VOID NTAPI USBPORT_CompleteTransfer(IN PURB Urb, IN USBD_STATUS TransferStatus)
Definition: usbport.c:2198
VOID NTAPI IoAcquireCancelSpinLock(OUT PKIRQL Irql)
Definition: util.c:56
VOID NTAPI KeAcquireSpinLock(PKSPIN_LOCK SpinLock, PKIRQL OldIrql)
Definition: spinlock.c:50
IoSetCancelRoutine(Irp, CancelRoutine)
UCHAR KIRQL
Definition: env_spec_w32.h:591
_In_ PIRP Irp
Definition: csq.h:116
PDEVICE_OBJECT FdoDevice
Definition: usbport.h:206
PVOID DeviceExtension
Definition: env_spec_w32.h:418
KIRQL OldIrql
Definition: mm.h:1502
struct _URB_HEADER UrbHeader
Definition: usb.h:531
NTSTATUS NTAPI USBPORT_USBDStatusToNtStatus(IN PURB Urb, IN USBD_STATUS USBDStatus)
Definition: usbport.c:485
VOID NTAPI IoReleaseCancelSpinLock(IN KIRQL Irql)
Definition: util.c:150
Definition: usb.h:529
#define NULL
Definition: types.h:112
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
PIRP NTAPI USBPORT_RemoveActiveTransferIrp(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp)
Definition: queue.c:357

Referenced by USBPORT_DoneSplitTransfer(), and USBPORT_FlushDoneTransfers().

◆ USBPORT_DoRootHubCallback()

VOID NTAPI USBPORT_DoRootHubCallback ( IN PDEVICE_OBJECT  FdoDevice)

Definition at line 1222 of file usbport.c.

1223 {
1225  PDEVICE_OBJECT PdoDevice;
1227  PRH_INIT_CALLBACK RootHubInitCallback;
1228  PVOID RootHubInitContext;
1229 
1230  FdoExtension = FdoDevice->DeviceExtension;
1231 
1232  DPRINT("USBPORT_DoRootHubCallback: FdoDevice - %p\n", FdoDevice);
1233 
1234  PdoDevice = FdoExtension->RootHubPdo;
1235 
1236  if (PdoDevice)
1237  {
1238  PdoExtension = PdoDevice->DeviceExtension;
1239 
1240  RootHubInitContext = PdoExtension->RootHubInitContext;
1241  RootHubInitCallback = PdoExtension->RootHubInitCallback;
1242 
1243  PdoExtension->RootHubInitCallback = NULL;
1244  PdoExtension->RootHubInitContext = NULL;
1245 
1246  if (RootHubInitCallback)
1247  {
1248  RootHubInitCallback(RootHubInitContext);
1249  }
1250  }
1251 
1252  DPRINT("USBPORT_DoRootHubCallback: exit\n");
1253 }
PVOID DeviceExtension
Definition: env_spec_w32.h:418
RH_INIT_CALLBACK * PRH_INIT_CALLBACK
Definition: hubbusif.h:270
#define NULL
Definition: types.h:112
#define DPRINT
Definition: sndvol32.h:71

Referenced by USBPORT_SynchronizeRootHubCallback().

◆ USBPORT_DpcHandler()

VOID NTAPI USBPORT_DpcHandler ( IN PDEVICE_OBJECT  FdoDevice)

Definition at line 864 of file usbport.c.

865 {
867  PUSBPORT_ENDPOINT Endpoint;
870  LONG LockCounter;
871 
872  DPRINT_CORE("USBPORT_DpcHandler: ...\n");
873 
874  FdoExtension = FdoDevice->DeviceExtension;
875 
877 
878  KeAcquireSpinLockAtDpcLevel(&FdoExtension->EndpointListSpinLock);
879  Entry = FdoExtension->EndpointList.Flink;
880 
881  while (Entry && Entry != &FdoExtension->EndpointList)
882  {
883  Endpoint = CONTAINING_RECORD(Entry,
885  EndpointLink);
886 
887  LockCounter = InterlockedIncrement(&Endpoint->LockCounter);
888 
890  LockCounter ||
891  Endpoint->Flags & ENDPOINT_FLAG_ROOTHUB_EP0)
892  {
893  InterlockedDecrement(&Endpoint->LockCounter);
894  }
895  else
896  {
897  InsertTailList(&List, &Endpoint->DispatchLink);
898 
899  if (Endpoint->WorkerLink.Flink && Endpoint->WorkerLink.Blink)
900  {
901  RemoveEntryList(&Endpoint->WorkerLink);
902 
903  Endpoint->WorkerLink.Flink = NULL;
904  Endpoint->WorkerLink.Blink = NULL;
905  }
906  }
907 
908  Entry = Endpoint->EndpointLink.Flink;
909  }
910 
911  KeReleaseSpinLockFromDpcLevel(&FdoExtension->EndpointListSpinLock);
912 
913  while (!IsListEmpty(&List))
914  {
915  Endpoint = CONTAINING_RECORD(List.Flink,
917  DispatchLink);
918 
919  RemoveEntryList(List.Flink);
920  Endpoint->DispatchLink.Flink = NULL;
921  Endpoint->DispatchLink.Blink = NULL;
922 
923  USBPORT_EndpointWorker(Endpoint, TRUE);
925  }
926 
927  KeAcquireSpinLockAtDpcLevel(&FdoExtension->EndpointListSpinLock);
928 
929  if (!IsListEmpty(&FdoExtension->WorkerList))
930  {
931  USBPORT_SignalWorkerThread(FdoDevice);
932  }
933 
934  KeReleaseSpinLockFromDpcLevel(&FdoExtension->EndpointListSpinLock);
935 
936  USBPORT_FlushDoneTransfers(FdoDevice);
937 }
#define USBPORT_ENDPOINT_ACTIVE
Definition: usbmport.h:15
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
LIST_ENTRY EndpointLink
Definition: usbport.h:232
LIST_ENTRY WorkerLink
Definition: usbport.h:233
struct _Entry Entry
Definition: kefuncs.h:627
#define TRUE
Definition: types.h:120
struct _LIST_ENTRY * Blink
Definition: typedefs.h:122
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:198
BOOLEAN NTAPI USBPORT_EndpointWorker(IN PUSBPORT_ENDPOINT Endpoint, IN BOOLEAN LockNotChecked)
Definition: endpoint.c:1656
#define ENDPOINT_FLAG_ROOTHUB_EP0
Definition: usbport.h:112
#define InsertTailList(ListHead, Entry)
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
LIST_ENTRY DispatchLink
Definition: usbport.h:235
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
long LONG
Definition: pedump.c:60
VOID NTAPI USBPORT_FlushDoneTransfers(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:764
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
VOID NTAPI USBPORT_FlushPendingTransfers(IN PUSBPORT_ENDPOINT Endpoint)
Definition: queue.c:785
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:221
VOID NTAPI USBPORT_SignalWorkerThread(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:1111
ULONG NTAPI USBPORT_GetEndpointState(IN PUSBPORT_ENDPOINT Endpoint)
Definition: endpoint.c:332
#define InterlockedDecrement
Definition: armddk.h:52
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
Definition: typedefs.h:119
#define InterlockedIncrement
Definition: armddk.h:53
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define NULL
Definition: types.h:112
base of all file and directory entries
Definition: entries.h:82

Referenced by USBPORT_IsrDpcHandler(), and USBPORT_WorkerRequestDpc().

◆ USBPORT_FindCompanionControllers()

PDEVICE_RELATIONS NTAPI USBPORT_FindCompanionControllers ( IN PDEVICE_OBJECT  USB2FdoDevice,
IN BOOLEAN  IsObRefer,
IN BOOLEAN  IsFDOsReturned 
)

Definition at line 136 of file usbport.c.

139 {
140  PLIST_ENTRY USB1FdoList;
141  PUSBPORT_DEVICE_EXTENSION USB1FdoExtension;
142  ULONG NumControllers = 0;
144  PDEVICE_RELATIONS ControllersList = NULL;
145  KIRQL OldIrql;
146 
147  DPRINT("USBPORT_FindCompanionControllers: USB2Fdo - %p, IsObRefer - %x, IsFDOs - %x\n",
148  USB2FdoDevice,
149  IsObRefer,
150  IsFDOsReturned);
151 
153 
154  USB1FdoList = USBPORT_USB1FdoList.Flink;
155 
156  while (USB1FdoList && USB1FdoList != &USBPORT_USB1FdoList)
157  {
158  USB1FdoExtension = CONTAINING_RECORD(USB1FdoList,
160  ControllerLink);
161 
162  if (USB1FdoExtension->Flags & USBPORT_FLAG_COMPANION_HC &&
163  USBPORT_IsCompanionFdoExtension(USB2FdoDevice, USB1FdoExtension))
164  {
165  ++NumControllers;
166  }
167 
168  USB1FdoList = USB1FdoExtension->ControllerLink.Flink;
169  }
170 
171  DPRINT("USBPORT_FindCompanionControllers: NumControllers - %x\n",
172  NumControllers);
173 
174  if (!NumControllers)
175  {
176  goto Exit;
177  }
178 
179  ControllersList = ExAllocatePoolWithTag(NonPagedPool,
180  NumControllers * sizeof(DEVICE_RELATIONS),
181  USB_PORT_TAG);
182 
183  if (!ControllersList)
184  {
185  goto Exit;
186  }
187 
188  RtlZeroMemory(ControllersList, NumControllers * sizeof(DEVICE_RELATIONS));
189 
190  ControllersList->Count = NumControllers;
191 
192  USB1FdoList = USBPORT_USB1FdoList.Flink;
193 
194  Entry = &ControllersList->Objects[0];
195 
196  while (USB1FdoList && USB1FdoList != &USBPORT_USB1FdoList)
197  {
198  USB1FdoExtension = CONTAINING_RECORD(USB1FdoList,
200  ControllerLink);
201 
202  if (USB1FdoExtension->Flags & USBPORT_FLAG_COMPANION_HC &&
203  USBPORT_IsCompanionFdoExtension(USB2FdoDevice, USB1FdoExtension))
204  {
205  *Entry = USB1FdoExtension->CommonExtension.LowerPdoDevice;
206 
207  if (IsObRefer)
208  {
210  }
211 
212  if (IsFDOsReturned)
213  {
214  *Entry = USB1FdoExtension->CommonExtension.SelfDevice;
215  }
216 
217  ++Entry;
218  }
219 
220  USB1FdoList = USB1FdoExtension->ControllerLink.Flink;
221  }
222 
223 Exit:
224 
226 
227  return ControllersList;
228 }
struct _Entry Entry
Definition: kefuncs.h:627
LIST_ENTRY ControllerLink
Definition: usbport.h:302
PDEVICE_OBJECT LowerPdoDevice
Definition: usbport.h:282
PDEVICE_OBJECT Objects[1]
Definition: iotypes.h:2163
LIST_ENTRY USBPORT_USB1FdoList
Definition: usbport.c:19
VOID NTAPI KeAcquireSpinLock(PKSPIN_LOCK SpinLock, PKIRQL OldIrql)
Definition: spinlock.c:50
USBPORT_COMMON_DEVICE_EXTENSION CommonExtension
Definition: usbport.h:292
#define USB_PORT_TAG
Definition: usbport.h:44
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define USBPORT_FLAG_COMPANION_HC
Definition: usbport.h:78
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
KIRQL OldIrql
Definition: mm.h:1502
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
static void Exit(void)
Definition: sock.c:1331
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
BOOLEAN NTAPI USBPORT_IsCompanionFdoExtension(IN PDEVICE_OBJECT USB2FdoDevice, IN PUSBPORT_DEVICE_EXTENSION USB1FdoExtension)
Definition: usbport.c:119
Definition: typedefs.h:119
#define NULL
Definition: types.h:112
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define ObReferenceObject
Definition: obfuncs.h:204
KSPIN_LOCK USBPORT_SpinLock
Definition: usbport.c:22
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define DPRINT
Definition: sndvol32.h:71
base of all file and directory entries
Definition: entries.h:82

Referenced by USBPORT_RH_SetFeatureUSB2PortPower(), USBPORT_RootHubPowerAndChirpAllCcPorts(), and USBPORT_SynchronizeRootHubCallback().

◆ USBPORT_FindMiniPort()

PUSBPORT_MINIPORT_INTERFACE NTAPI USBPORT_FindMiniPort ( IN PDRIVER_OBJECT  DriverObject)

Definition at line 1793 of file usbport.c.

1794 {
1795  KIRQL OldIrql;
1796  PLIST_ENTRY List;
1797  PUSBPORT_MINIPORT_INTERFACE MiniPortInterface;
1798  BOOLEAN IsFound = FALSE;
1799 
1800  DPRINT("USBPORT_FindMiniPort: ...\n");
1801 
1803 
1806  List = List->Flink)
1807  {
1808  MiniPortInterface = CONTAINING_RECORD(List,
1810  DriverLink);
1811 
1812  if (MiniPortInterface->DriverObject == DriverObject)
1813  {
1814  DPRINT("USBPORT_FindMiniPort: find MiniPortInterface - %p\n",
1815  MiniPortInterface);
1816 
1817  IsFound = TRUE;
1818  break;
1819  }
1820  }
1821 
1823 
1824  if (IsFound)
1825  return MiniPortInterface;
1826  else
1827  return NULL;
1828 
1829 }
#define TRUE
Definition: types.h:120
VOID NTAPI KeAcquireSpinLock(PKSPIN_LOCK SpinLock, PKIRQL OldIrql)
Definition: spinlock.c:50
PDRIVER_OBJECT DriverObject
Definition: usbmport.h:640
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
KIRQL OldIrql
Definition: mm.h:1502
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
Definition: typedefs.h:119
#define NULL
Definition: types.h:112
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
KSPIN_LOCK USBPORT_SpinLock
Definition: usbport.c:22
#define DPRINT
Definition: sndvol32.h:71
LIST_ENTRY USBPORT_MiniPortDrivers
Definition: usbport.c:18

Referenced by USBPORT_AddDevice(), and USBPORT_Unload().

◆ USBPORT_FindUSB2Controller()

PDEVICE_OBJECT NTAPI USBPORT_FindUSB2Controller ( IN PDEVICE_OBJECT  FdoDevice)

Definition at line 27 of file usbport.c.

28 {
30  PUSBPORT_DEVICE_EXTENSION USB2FdoExtension;
31  KIRQL OldIrql;
32  PLIST_ENTRY USB2FdoEntry;
33  PDEVICE_OBJECT USB2FdoDevice = NULL;
34 
35  DPRINT("USBPORT_FindUSB2Controller: FdoDevice - %p\n", FdoDevice);
36 
37  FdoExtension = FdoDevice->DeviceExtension;
38 
40 
41  USB2FdoEntry = USBPORT_USB2FdoList.Flink;
42 
43  while (USB2FdoEntry && USB2FdoEntry != &USBPORT_USB2FdoList)
44  {
45  USB2FdoExtension = CONTAINING_RECORD(USB2FdoEntry,
47  ControllerLink);
48 
49  if (USB2FdoExtension->BusNumber == FdoExtension->BusNumber &&
50  USB2FdoExtension->PciDeviceNumber == FdoExtension->PciDeviceNumber)
51  {
52  USB2FdoDevice = USB2FdoExtension->CommonExtension.SelfDevice;
53  break;
54  }
55 
56  USB2FdoEntry = USB2FdoEntry->Flink;
57  }
58 
60 
61  return USB2FdoDevice;
62 }
VOID NTAPI KeAcquireSpinLock(PKSPIN_LOCK SpinLock, PKIRQL OldIrql)
Definition: spinlock.c:50
LIST_ENTRY USBPORT_USB2FdoList
Definition: usbport.c:20
USBPORT_COMMON_DEVICE_EXTENSION CommonExtension
Definition: usbport.h:292
UCHAR KIRQL
Definition: env_spec_w32.h:591
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
KIRQL OldIrql
Definition: mm.h:1502
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
Definition: typedefs.h:119
#define NULL
Definition: types.h:112
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
KSPIN_LOCK USBPORT_SpinLock
Definition: usbport.c:22
#define DPRINT
Definition: sndvol32.h:71

Referenced by USBHI_GetExtendedHubInformation(), USBPORT_SynchronizeControllersStart(), and USBPORT_WorkerThread().

◆ USBPORT_FlushDoneTransfers()

VOID NTAPI USBPORT_FlushDoneTransfers ( IN PDEVICE_OBJECT  FdoDevice)

Definition at line 764 of file usbport.c.

765 {
767  PLIST_ENTRY DoneTransferList;
768  PUSBPORT_TRANSFER Transfer;
769  PUSBPORT_ENDPOINT Endpoint;
770  ULONG TransferCount;
771  KIRQL OldIrql;
772  BOOLEAN IsHasTransfers;
773 
774  DPRINT_CORE("USBPORT_FlushDoneTransfers: ...\n");
775 
776  FdoExtension = FdoDevice->DeviceExtension;
777  DoneTransferList = &FdoExtension->DoneTransferList;
778 
779  while (TRUE)
780  {
781  KeAcquireSpinLock(&FdoExtension->DoneTransferSpinLock, &OldIrql);
782 
783  if (IsListEmpty(DoneTransferList))
784  break;
785 
786  Transfer = CONTAINING_RECORD(DoneTransferList->Flink,
788  TransferLink);
789 
790  RemoveHeadList(DoneTransferList);
791  KeReleaseSpinLock(&FdoExtension->DoneTransferSpinLock, OldIrql);
792 
793  if (Transfer)
794  {
795  Endpoint = Transfer->Endpoint;
796 
797  if ((Transfer->Flags & TRANSFER_FLAG_SPLITED))
798  {
799  USBPORT_DoneSplitTransfer(Transfer);
800  }
801  else
802  {
803  USBPORT_DoneTransfer(Transfer);
804  }
805 
806  IsHasTransfers = USBPORT_EndpointHasQueuedTransfers(FdoDevice,
807  Endpoint,
808  &TransferCount);
809 
810  if (IsHasTransfers && !TransferCount)
811  {
813  Endpoint,
815  }
816  }
817  }
818 
819  KeReleaseSpinLock(&FdoExtension->DoneTransferSpinLock, OldIrql);
820 }
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
#define TRUE
Definition: types.h:120
VOID NTAPI KeAcquireSpinLock(PKSPIN_LOCK SpinLock, PKIRQL OldIrql)
Definition: spinlock.c:50
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
UCHAR KIRQL
Definition: env_spec_w32.h:591
unsigned char BOOLEAN
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
KIRQL OldIrql
Definition: mm.h:1502
PUSBPORT_ENDPOINT Endpoint
Definition: usbport.h:253
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
VOID NTAPI USBPORT_DoneTransfer(IN PUSBPORT_TRANSFER Transfer)
Definition: usbport.c:724
VOID NTAPI USBPORT_DoneSplitTransfer(IN PUSBPORT_TRANSFER SplitTransfer)
Definition: trfsplit.c:278
Definition: typedefs.h:119
#define TRANSFER_FLAG_SPLITED
Definition: usbport.h:137
BOOLEAN NTAPI USBPORT_EndpointHasQueuedTransfers(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint, IN PULONG TransferCount)
Definition: endpoint.c:254
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
unsigned int ULONG
Definition: retypes.h:1
#define INVALIDATE_ENDPOINT_WORKER_DPC
Definition: usbport.h:38
VOID NTAPI USBPORT_InvalidateEndpointHandler(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint, IN ULONG Type)
Definition: endpoint.c:1317

Referenced by USBPORT_DpcHandler(), and USBPORT_TransferFlushDpc().

◆ USBPORT_FlushMapTransfers()

VOID NTAPI USBPORT_FlushMapTransfers ( IN PDEVICE_OBJECT  FdoDevice)

Definition at line 2483 of file usbport.c.

2484 {
2486  PLIST_ENTRY MapTransferList;
2487  PUSBPORT_TRANSFER Transfer;
2488  ULONG NumMapRegisters;
2489  PMDL Mdl;
2491  ULONG_PTR VirtualAddr;
2492  KIRQL OldIrql;
2493  NTSTATUS Status;
2494  PDMA_OPERATIONS DmaOperations;
2495 
2496  DPRINT_CORE("USBPORT_FlushMapTransfers: ...\n");
2497 
2498  FdoExtension = FdoDevice->DeviceExtension;
2499  DmaOperations = FdoExtension->DmaAdapter->DmaOperations;
2500 
2502 
2503  while (TRUE)
2504  {
2505  MapTransferList = &FdoExtension->MapTransferList;
2506 
2507  if (IsListEmpty(&FdoExtension->MapTransferList))
2508  {
2510  return;
2511  }
2512 
2513  Transfer = CONTAINING_RECORD(MapTransferList->Flink,
2515  TransferLink);
2516 
2517  RemoveHeadList(MapTransferList);
2518 
2519  Mdl = Transfer->Urb->UrbControlTransfer.TransferBufferMDL;
2521  VirtualAddr = (ULONG_PTR)MmGetMdlVirtualAddress(Mdl);
2522 
2523  NumMapRegisters = ADDRESS_AND_SIZE_TO_SPAN_PAGES(VirtualAddr,
2525 
2526  Transfer->NumberOfMapRegisters = NumMapRegisters;
2527 
2528  Status = DmaOperations->AllocateAdapterChannel(FdoExtension->DmaAdapter,
2529  FdoDevice,
2530  NumMapRegisters,
2532  Transfer);
2533 
2534  if (!NT_SUCCESS(Status))
2535  ASSERT(FALSE);
2536  }
2537 
2539 }
ULONG NumberOfMapRegisters
Definition: usbport.h:260
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
#define MmGetMdlVirtualAddress(_Mdl)
#define TRUE
Definition: types.h:120
USBPORT_TRANSFER_PARAMETERS TransferParameters
Definition: usbport.h:254
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
uint32_t ULONG_PTR
Definition: typedefs.h:65
IO_ALLOCATION_ACTION NTAPI USBPORT_MapTransfer(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp, IN PVOID MapRegisterBase, IN PVOID Context)
Definition: usbport.c:2308
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define FALSE
Definition: types.h:117
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define ADDRESS_AND_SIZE_TO_SPAN_PAGES(_Va, _Size)
KIRQL OldIrql
Definition: mm.h:1502
Status
Definition: gdiplustypes.h:24
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
struct _URB_CONTROL_TRANSFER UrbControlTransfer
Definition: usb.h:539
Definition: typedefs.h:119
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
ULONG_PTR SIZE_T
Definition: typedefs.h:80
PALLOCATE_ADAPTER_CHANNEL AllocateAdapterChannel
Definition: iotypes.h:2637
VOID NTAPI KeRaiseIrql(KIRQL NewIrql, PKIRQL OldIrql)
Definition: spinlock.c:27
_In_ WDFDEVICE _In_ PVOID _In_opt_ PMDL Mdl
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
VOID NTAPI KeLowerIrql(KIRQL NewIrql)
Definition: spinlock.c:39
ULONG TransferBufferLength
Definition: usb.h:470

Referenced by USBPORT_AbortTransfers(), and USBPORT_FlushPendingTransfers().

◆ USBPORT_FreeCommonBuffer()

VOID NTAPI USBPORT_FreeCommonBuffer ( IN PDEVICE_OBJECT  FdoDevice,
IN PUSBPORT_COMMON_BUFFER_HEADER  HeaderBuffer 
)

Definition at line 1770 of file usbport.c.

1772 {
1774  PDMA_ADAPTER DmaAdapter;
1775  PDMA_OPERATIONS DmaOperations;
1776 
1777  DPRINT("USBPORT_FreeCommonBuffer: ...\n");
1778 
1779  FdoExtension = FdoDevice->DeviceExtension;
1780 
1781  DmaAdapter = FdoExtension->DmaAdapter;
1782  DmaOperations = DmaAdapter->DmaOperations;
1783 
1784  DmaOperations->FreeCommonBuffer(FdoExtension->DmaAdapter,
1785  HeaderBuffer->Length,
1786  HeaderBuffer->LogicalAddress,
1787  (PVOID)HeaderBuffer->VirtualAddress,
1788  TRUE);
1789 }
PFREE_COMMON_BUFFER FreeCommonBuffer
Definition: iotypes.h:2636
#define TRUE
Definition: types.h:120
struct _DMA_OPERATIONS * DmaOperations
Definition: iotypes.h:2295
#define DPRINT
Definition: sndvol32.h:71

Referenced by USBPORT_DeleteEndpoint(), USBPORT_ReopenPipe(), and USBPORT_StartDevice().

◆ USBPORT_GetHciMn()

ULONG NTAPI USBPORT_GetHciMn ( VOID  )

Definition at line 2804 of file usbport.c.

2805 {
2806  return USBPORT_HCI_MN;
2807 }
#define USBPORT_HCI_MN
Definition: usbmport.h:4

Referenced by DriverEntry().

◆ USBPORT_GetMappedVirtualAddress()

PVOID NTAPI USBPORT_GetMappedVirtualAddress ( IN ULONG  PhysicalAddress,
IN PVOID  MiniPortExtension,
IN PVOID  MiniPortEndpoint 
)

Definition at line 2135 of file usbport.c.

2138 {
2139  PUSBPORT_COMMON_BUFFER_HEADER HeaderBuffer;
2140  PUSBPORT_ENDPOINT Endpoint;
2141  ULONG Offset;
2143 
2144  DPRINT_CORE("USBPORT_GetMappedVirtualAddress ...\n");
2145 
2146  Endpoint = (PUSBPORT_ENDPOINT)((ULONG_PTR)MiniPortEndpoint -
2147  sizeof(USBPORT_ENDPOINT));
2148 
2149  if (!Endpoint)
2150  {
2151  ASSERT(FALSE);
2152  }
2153 
2154  HeaderBuffer = Endpoint->HeaderBuffer;
2155 
2156  Offset = PhysicalAddress - HeaderBuffer->PhysicalAddress;
2157  VirtualAddress = HeaderBuffer->VirtualAddress + Offset;
2158 
2159  return (PVOID)VirtualAddress;
2160 }
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define FALSE
Definition: types.h:117
PUSBPORT_COMMON_BUFFER_HEADER HeaderBuffer
Definition: usbport.h:207
_Must_inspect_result_ _In_ WDFDMATRANSACTION _In_ PFN_WDF_PROGRAM_DMA _In_ WDF_DMA_DIRECTION _In_ PMDL _In_ PVOID VirtualAddress
#define ASSERT(a)
Definition: mode.c:44
struct _USBPORT_ENDPOINT USBPORT_ENDPOINT
struct _USBPORT_ENDPOINT * PUSBPORT_ENDPOINT
Definition: usbport.h:155
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS PhysicalAddress
Definition: iotypes.h:1098
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
unsigned int ULONG
Definition: retypes.h:1

Referenced by USBPORT_RegisterUSBPortDriver().

◆ USBPORT_GetMiniportRegistryKeyValue()

MPSTATUS NTAPI USBPORT_GetMiniportRegistryKeyValue ( IN PVOID  MiniPortExtension,
IN BOOL  UseDriverKey,
IN PCWSTR  SourceString,
IN SIZE_T  LengthStr,
IN PVOID  Buffer,
IN SIZE_T  BufferLength 
)

Definition at line 373 of file usbport.c.

379 {
381  PDEVICE_OBJECT FdoDevice;
383 
384  DPRINT("USBPORT_GetMiniportRegistryKeyValue: MiniPortExtension - %p, UseDriverKey - %x, SourceString - %S, LengthStr - %x, Buffer - %p, BufferLength - %x\n",
385  MiniPortExtension,
386  UseDriverKey,
387  SourceString,
388  LengthStr,
389  Buffer,
390  BufferLength);
391 
392  FdoExtension = (PUSBPORT_DEVICE_EXTENSION)((ULONG_PTR)MiniPortExtension -
393  sizeof(USBPORT_DEVICE_EXTENSION));
394 
395  FdoDevice = FdoExtension->CommonExtension.SelfDevice;
396 
398  FdoExtension->CommonExtension.LowerPdoDevice,
399  UseDriverKey,
400  SourceString,
401  LengthStr,
402  Buffer,
403  BufferLength);
404 
406 }
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3767
LONG NTSTATUS
Definition: precomp.h:26
uint32_t ULONG_PTR
Definition: typedefs.h:65
struct _USBPORT_DEVICE_EXTENSION USBPORT_DEVICE_EXTENSION
Definition: bufpool.h:45
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI USBPORT_GetRegistryKeyValueFullInfo(IN PDEVICE_OBJECT FdoDevice, IN PDEVICE_OBJECT PdoDevice, IN BOOL UseDriverKey, IN PCWSTR SourceString, IN ULONG LengthStr, IN PVOID Buffer, IN ULONG BufferLength)
Definition: usbport.c:296
MPSTATUS NTAPI USBPORT_NtStatusToMpStatus(NTSTATUS NtStatus)
Definition: usbport.c:232
struct _USBPORT_DEVICE_EXTENSION * PUSBPORT_DEVICE_EXTENSION
_Out_ _Inout_ POEM_STRING _In_ PCUNICODE_STRING SourceString
Definition: rtlfuncs.h:1868
#define DPRINT
Definition: sndvol32.h:71

Referenced by USBPORT_RegisterUSBPortDriver().

◆ USBPORT_GetRegistryKeyValueFullInfo()

NTSTATUS NTAPI USBPORT_GetRegistryKeyValueFullInfo ( IN PDEVICE_OBJECT  FdoDevice,
IN PDEVICE_OBJECT  PdoDevice,
IN BOOL  UseDriverKey,
IN PCWSTR  SourceString,
IN ULONG  LengthStr,
IN PVOID  Buffer,
IN ULONG  BufferLength 
)

Definition at line 296 of file usbport.c.

303 {
308  ULONG LengthKey;
309 
310  DPRINT("USBPORT_GetRegistryKeyValue: UseDriverKey - %x, SourceString - %S, LengthStr - %x, Buffer - %p, BufferLength - %x\n",
311  UseDriverKey,
312  SourceString,
313  LengthStr,
314  Buffer,
315  BufferLength);
316 
317  if (UseDriverKey)
318  {
319  Status = IoOpenDeviceRegistryKey(PdoDevice,
322  &KeyHandle);
323  }
324  else
325  {
326  Status = IoOpenDeviceRegistryKey(PdoDevice,
329  &KeyHandle);
330  }
331 
332  if (NT_SUCCESS(Status))
333  {
335 
336  LengthKey = sizeof(KEY_VALUE_FULL_INFORMATION) +
337  LengthStr +
338  BufferLength;
339 
340  KeyValue = ExAllocatePoolWithTag(PagedPool,
341  LengthKey,
342  USB_PORT_TAG);
343 
344  if (KeyValue)
345  {
346  RtlZeroMemory(KeyValue, LengthKey);
347 
348  Status = ZwQueryValueKey(KeyHandle,
349  &ValueName,
351  KeyValue,
352  LengthKey,
353  &LengthKey);
354 
355  if (NT_SUCCESS(Status))
356  {
358  (PUCHAR)KeyValue + KeyValue->DataOffset,
359  BufferLength);
360  }
361 
362  ExFreePoolWithTag(KeyValue, USB_PORT_TAG);
363  }
364 
366  }
367 
368  return Status;
369 }
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3767
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4711
struct _KEY_VALUE_FULL_INFORMATION KEY_VALUE_FULL_INFORMATION
#define PLUGPLAY_REGKEY_DEVICE
Definition: iofuncs.h:2786
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
#define USB_PORT_TAG
Definition: usbport.h:44
Definition: bufpool.h:45
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:240
_Out_ _Inout_ POEM_STRING _In_ PCUNICODE_STRING SourceString
Definition: rtlfuncs.h:1868
#define PLUGPLAY_REGKEY_DRIVER
Definition: usbd.c:42
#define STANDARD_RIGHTS_ALL
Definition: nt_native.h:69
NTSTATUS NTAPI IoOpenDeviceRegistryKey(IN PDEVICE_OBJECT DeviceObject, IN ULONG DevInstKeyType, IN ACCESS_MASK DesiredAccess, OUT PHANDLE DevInstRegKey)
Definition: pnpmgr.c:2191
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define DPRINT
Definition: sndvol32.h:71
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099

Referenced by USBHI_GetExtendedHubInformation(), USBPORT_GetMiniportRegistryKeyValue(), USBPORT_IsSelectiveSuspendEnabled(), and USBPORT_StartDevice().

◆ USBPORT_GetSetConfigSpaceData()

NTSTATUS NTAPI USBPORT_GetSetConfigSpaceData ( IN PDEVICE_OBJECT  FdoDevice,
IN BOOLEAN  IsReadData,
IN PVOID  Buffer,
IN ULONG  Offset,
IN ULONG  Length 
)

Definition at line 410 of file usbport.c.

415 {
417  ULONG BytesReadWrite;
418 
419  DPRINT("USBPORT_GetSetConfigSpaceData ...\n");
420 
421  FdoExtension = FdoDevice->DeviceExtension;
422 
423  BytesReadWrite = Length;
424 
425  if (IsReadData)
426  {
428 
429  BytesReadWrite = (*FdoExtension->BusInterface.GetBusData)
430  (FdoExtension->BusInterface.Context,
432  Buffer,
433  Offset,
434  Length);
435  }
436  else
437  {
438  BytesReadWrite = (*FdoExtension->BusInterface.SetBusData)
439  (FdoExtension->BusInterface.Context,
441  Buffer,
442  Offset,
443  Length);
444  }
445 
446  if (BytesReadWrite == Length)
447  {
448  return STATUS_SUCCESS;
449  }
450 
451  return STATUS_UNSUCCESSFUL;
452 }
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
Definition: bufpool.h:45
#define PCI_WHICHSPACE_CONFIG
Definition: iotypes.h:3644
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71

Referenced by USBPORT_ReadWriteConfigSpace().

◆ USBPORT_InterruptService()

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

Definition at line 1077 of file usbport.c.

1079 {
1080  PDEVICE_OBJECT FdoDevice;
1083  BOOLEAN Result = FALSE;
1084 
1085  FdoDevice = ServiceContext;
1086  FdoExtension = FdoDevice->DeviceExtension;
1087  Packet = &FdoExtension->MiniPortInterface->Packet;
1088 
1089  DPRINT_INT("USBPORT_InterruptService: FdoExtension[%p]->Flags - %08X\n",
1090  FdoExtension,
1091  FdoExtension->Flags);
1092 
1095  {
1096  Result = Packet->InterruptService(FdoExtension->MiniPortExt);
1097 
1098  if (Result)
1099  {
1100  KeInsertQueueDpc(&FdoExtension->IsrDpc, NULL, NULL);
1101  }
1102  }
1103 
1104  DPRINT_INT("USBPORT_InterruptService: return - %x\n", Result);
1105 
1106  return Result;
1107 }
#define DPRINT_INT(...)
Definition: usbdebug.h:146
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
BOOLEAN NTAPI KeInsertQueueDpc(IN PKDPC Dpc, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: dpc.c:725
#define FALSE
Definition: types.h:117
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
_In_ PKSERVICE_ROUTINE _In_opt_ PVOID ServiceContext
Definition: iofuncs.h:800
#define USBPORT_FLAG_INTERRUPT_ENABLED
Definition: usbport.h:72
#define USBPORT_MPFLAG_INTERRUPTS_ENABLED
Definition: usbport.h:102
#define NULL
Definition: types.h:112

Referenced by USBPORT_StartDevice().

◆ USBPORT_InvalidateController()

ULONG NTAPI USBPORT_InvalidateController ( IN PVOID  MiniPortExtension,
IN ULONG  Type 
)

Definition at line 670 of file usbport.c.

672 {
674  PDEVICE_OBJECT FdoDevice;
675 
676  DPRINT("USBPORT_InvalidateController: Invalidate Type - %x\n", Type);
677 
678  //FdoExtension->MiniPortExt = (PVOID)((ULONG_PTR)FdoExtension + sizeof(USBPORT_DEVICE_EXTENSION));
679  FdoExtension = (PUSBPORT_DEVICE_EXTENSION)((ULONG_PTR)MiniPortExtension -
680  sizeof(USBPORT_DEVICE_EXTENSION));
681  FdoDevice = FdoExtension->CommonExtension.SelfDevice;
682 
684 
685  return 0;
686 }
uint32_t ULONG_PTR
Definition: typedefs.h:65
VOID NTAPI USBPORT_InvalidateControllerHandler(IN PDEVICE_OBJECT FdoDevice, IN ULONG Type)
Definition: usbport.c:635
struct _USBPORT_DEVICE_EXTENSION USBPORT_DEVICE_EXTENSION
Type
Definition: Type.h:6
struct _USBPORT_DEVICE_EXTENSION * PUSBPORT_DEVICE_EXTENSION
#define DPRINT
Definition: sndvol32.h:71

Referenced by USBPORT_RegisterUSBPortDriver().

◆ USBPORT_InvalidateControllerHandler()

VOID NTAPI USBPORT_InvalidateControllerHandler ( IN PDEVICE_OBJECT  FdoDevice,
IN ULONG  Type 
)

Definition at line 635 of file usbport.c.

637 {
639 
640  DPRINT_CORE("USBPORT_InvalidateControllerHandler: Invalidate Type - %x\n",
641  Type);
642 
643  FdoExtension = FdoDevice->DeviceExtension;
644 
645  switch (Type)
646  {
648  DPRINT1("USBPORT_InvalidateControllerHandler: INVALIDATE_CONTROLLER_RESET UNIMPLEMENTED. FIXME.\n");
649  break;
650 
652  DPRINT1("USBPORT_InvalidateControllerHandler: INVALIDATE_CONTROLLER_SURPRISE_REMOVE UNIMPLEMENTED. FIXME.\n");
653  break;
654 
656  if (InterlockedIncrement(&FdoExtension->IsrDpcCounter))
657  {
658  InterlockedDecrement(&FdoExtension->IsrDpcCounter);
659  }
660  else
661  {
662  USBPORT_SoftInterrupt(FdoDevice);
663  }
664  break;
665  }
666 }
#define USBPORT_INVALIDATE_CONTROLLER_SOFT_INTERRUPT
Definition: usbmport.h:491
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
VOID NTAPI USBPORT_SoftInterrupt(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:611
#define USBPORT_INVALIDATE_CONTROLLER_SURPRISE_REMOVE
Definition: usbmport.h:490
Type
Definition: Type.h:6
#define InterlockedDecrement
Definition: armddk.h:52
#define InterlockedIncrement
Definition: armddk.h:53
#define DPRINT1
Definition: precomp.h:8
#define USBPORT_INVALIDATE_CONTROLLER_RESET
Definition: usbmport.h:489

Referenced by USBPORT_FdoPnP(), and USBPORT_InvalidateController().

◆ USBPORT_InvalidateEndpoint()

ULONG NTAPI USBPORT_InvalidateEndpoint ( IN PVOID  MiniPortExtension,
IN PVOID  MiniPortEndpoint 
)

Definition at line 2164 of file usbport.c.

2166 {
2168  PDEVICE_OBJECT FdoDevice;
2169  PUSBPORT_ENDPOINT Endpoint;
2170 
2171  DPRINT_CORE("USBPORT_InvalidateEndpoint: ...\n");
2172 
2173  FdoExtension = (PUSBPORT_DEVICE_EXTENSION)((ULONG_PTR)MiniPortExtension -
2174  sizeof(USBPORT_DEVICE_EXTENSION));
2175 
2176  FdoDevice = FdoExtension->CommonExtension.SelfDevice;
2177 
2178  if (!MiniPortEndpoint)
2179  {
2181  NULL,
2183  return 0;
2184  }
2185 
2186  Endpoint = (PUSBPORT_ENDPOINT)((ULONG_PTR)MiniPortEndpoint -
2187  sizeof(USBPORT_ENDPOINT));
2188 
2190  Endpoint,
2192 
2193  return 0;
2194 }
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
uint32_t ULONG_PTR
Definition: typedefs.h:65
struct _USBPORT_DEVICE_EXTENSION USBPORT_DEVICE_EXTENSION
#define INVALIDATE_ENDPOINT_ONLY
Definition: usbport.h:36
struct _USBPORT_ENDPOINT USBPORT_ENDPOINT
struct _USBPORT_ENDPOINT * PUSBPORT_ENDPOINT
Definition: usbport.h:155
struct _USBPORT_DEVICE_EXTENSION * PUSBPORT_DEVICE_EXTENSION
#define NULL
Definition: types.h:112
VOID NTAPI USBPORT_InvalidateEndpointHandler(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint, IN ULONG Type)
Definition: endpoint.c:1317

Referenced by USBPORT_RegisterUSBPortDriver().

◆ USBPORT_IsCompanionFdoExtension()

BOOLEAN NTAPI USBPORT_IsCompanionFdoExtension ( IN PDEVICE_OBJECT  USB2FdoDevice,
IN PUSBPORT_DEVICE_EXTENSION  USB1FdoExtension 
)

Definition at line 119 of file usbport.c.

121 {
122  PUSBPORT_DEVICE_EXTENSION USB2FdoExtension;
123 
124  DPRINT("USBPORT_IsCompanionFdoExtension: USB2Fdo - %p, USB1FdoExtension - %p\n",
125  USB2FdoDevice,
126  USB1FdoExtension);
127 
128  USB2FdoExtension = USB2FdoDevice->DeviceExtension;
129 
130  return USB2FdoExtension->BusNumber == USB1FdoExtension->BusNumber &&
131  USB2FdoExtension->PciDeviceNumber == USB1FdoExtension->PciDeviceNumber;
132 }
#define DPRINT
Definition: sndvol32.h:71

Referenced by USBPORT_FindCompanionControllers().

◆ USBPORT_IsrDpc()

VOID NTAPI USBPORT_IsrDpc ( IN PRKDPC  Dpc,
IN PVOID  DeferredContext,
IN PVOID  SystemArgument1,
IN PVOID  SystemArgument2 
)

Definition at line 1031 of file usbport.c.

1035 {
1036  PDEVICE_OBJECT FdoDevice;
1039  BOOLEAN InterruptEnable;
1040 
1041  DPRINT_INT("USBPORT_IsrDpc: DeferredContext - %p, SystemArgument2 - %p\n",
1043  SystemArgument2);
1044 
1045  FdoDevice = DeferredContext;
1046  FdoExtension = FdoDevice->DeviceExtension;
1047  Packet = &FdoExtension->MiniPortInterface->Packet;
1048 
1049  if (SystemArgument2)
1050  {
1051  InterlockedDecrement(&FdoExtension->IsrDpcCounter);
1052  }
1053 
1054  KeAcquireSpinLockAtDpcLevel(&FdoExtension->MiniportInterruptsSpinLock);
1055  InterruptEnable = (FdoExtension->Flags & USBPORT_FLAG_INTERRUPT_ENABLED) ==
1057 
1058  Packet->InterruptDpc(FdoExtension->MiniPortExt, InterruptEnable);
1059 
1060  KeReleaseSpinLockFromDpcLevel(&FdoExtension->MiniportInterruptsSpinLock);
1061 
1062  if (FdoExtension->Flags & USBPORT_FLAG_HC_SUSPEND &&
1063  FdoExtension->TimerFlags & USBPORT_TMFLAG_WAKE)
1064  {
1065  USBPORT_CompletePdoWaitWake(FdoDevice);
1066  }
1067  else
1068  {
1069  USBPORT_IsrDpcHandler(FdoDevice, TRUE);
1070  }
1071 
1072  DPRINT_INT("USBPORT_IsrDpc: exit\n");
1073 }
#define DPRINT_INT(...)
Definition: usbdebug.h:146
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
#define USBPORT_TMFLAG_WAKE
Definition: usbport.h:98
#define TRUE
Definition: types.h:120
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:198
VOID NTAPI USBPORT_CompletePdoWaitWake(IN PDEVICE_OBJECT FdoDevice)
Definition: power.c:15
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:221
#define InterlockedDecrement
Definition: armddk.h:52
#define USBPORT_FLAG_INTERRUPT_ENABLED
Definition: usbport.h:72
_In_opt_ PVOID _In_opt_ PVOID _In_opt_ PVOID SystemArgument2
Definition: ketypes.h:675
#define USBPORT_FLAG_HC_SUSPEND
Definition: usbport.h:71
VOID NTAPI USBPORT_IsrDpcHandler(IN PDEVICE_OBJECT FdoDevice, IN BOOLEAN IsDpcHandler)
Definition: usbport.c:941
_In_opt_ PVOID DeferredContext
Definition: ketypes.h:675

Referenced by USBPORT_StartDevice().

◆ USBPORT_IsrDpcHandler()

VOID NTAPI USBPORT_IsrDpcHandler ( IN PDEVICE_OBJECT  FdoDevice,
IN BOOLEAN  IsDpcHandler 
)

Definition at line 941 of file usbport.c.

943 {
946  PUSBPORT_ENDPOINT Endpoint;
948  ULONG FrameNumber;
949 
951 
952  DPRINT_CORE("USBPORT_IsrDpcHandler: IsDpcHandler - %x\n", IsDpcHandler);
953 
954  FdoExtension = FdoDevice->DeviceExtension;
955  Packet = &FdoExtension->MiniPortInterface->Packet;
956 
957  if (InterlockedIncrement(&FdoExtension->IsrDpcHandlerCounter))
958  {
960  InterlockedDecrement(&FdoExtension->IsrDpcHandlerCounter);
961  return;
962  }
963 
964  for (List = ExInterlockedRemoveHeadList(&FdoExtension->EpStateChangeList,
965  &FdoExtension->EpStateChangeSpinLock);
966  List != NULL;
967  List = ExInterlockedRemoveHeadList(&FdoExtension->EpStateChangeList,
968  &FdoExtension->EpStateChangeSpinLock))
969  {
970  Endpoint = CONTAINING_RECORD(List,
972  StateChangeLink);
973 
974  DPRINT_CORE("USBPORT_IsrDpcHandler: Endpoint - %p\n", Endpoint);
975 
977 
978  KeAcquireSpinLockAtDpcLevel(&FdoExtension->MiniportSpinLock);
979  FrameNumber = Packet->Get32BitFrameNumber(FdoExtension->MiniPortExt);
980  KeReleaseSpinLockFromDpcLevel(&FdoExtension->MiniportSpinLock);
981 
982  if (FrameNumber <= Endpoint->FrameNumber &&
983  !(Endpoint->Flags & ENDPOINT_FLAG_NUKE))
984  {
986 
987  ExInterlockedInsertHeadList(&FdoExtension->EpStateChangeList,
988  &Endpoint->StateChangeLink,
989  &FdoExtension->EpStateChangeSpinLock);
990 
991  KeAcquireSpinLockAtDpcLevel(&FdoExtension->MiniportSpinLock);
992  Packet->InterruptNextSOF(FdoExtension->MiniPortExt);
993  KeReleaseSpinLockFromDpcLevel(&FdoExtension->MiniportSpinLock);
994 
995  break;
996  }
997 
999 
1001  Endpoint->StateLast = Endpoint->StateNext;
1003 
1004  DPRINT_CORE("USBPORT_IsrDpcHandler: Endpoint->StateLast - %x\n",
1005  Endpoint->StateLast);
1006 
1007  if (IsDpcHandler)
1008  {
1010  Endpoint,
1012  }
1013  else
1014  {
1016  Endpoint,
1018  }
1019  }
1020 
1021  if (IsDpcHandler)
1022  {
1023  USBPORT_DpcHandler(FdoDevice);
1024  }
1025 
1026  InterlockedDecrement(&FdoExtension->IsrDpcHandlerCounter);
1027 }
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
VOID NTAPI USBPORT_DpcHandler(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:864
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:198
BOOLEAN NTAPI KeInsertQueueDpc(IN PKDPC Dpc, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: dpc.c:725
KSPIN_LOCK StateChangeSpinLock
Definition: usbport.h:225
PLIST_ENTRY NTAPI ExInterlockedRemoveHeadList(IN OUT PLIST_ENTRY ListHead, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:166
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define INVALIDATE_ENDPOINT_ONLY
Definition: usbport.h:36
#define ASSERT(a)
Definition: mode.c:44
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:221
#define ENDPOINT_FLAG_NUKE
Definition: usbport.h:113
#define InterlockedDecrement
Definition: armddk.h:52
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
Definition: typedefs.h:119
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
#define InterlockedIncrement
Definition: armddk.h:53
LIST_ENTRY StateChangeLink
Definition: usbport.h:224
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1
#define INVALIDATE_ENDPOINT_WORKER_THREAD
Definition: usbport.h:37
VOID NTAPI USBPORT_InvalidateEndpointHandler(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint, IN ULONG Type)
Definition: endpoint.c:1317
KSPIN_LOCK EndpointSpinLock
Definition: usbport.h:215
PLIST_ENTRY NTAPI ExInterlockedInsertHeadList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:114

Referenced by USBPORT_IsrDpc(), and USBPORT_TimerDpc().

◆ USBPORT_MapTransfer()

IO_ALLOCATION_ACTION NTAPI USBPORT_MapTransfer ( IN PDEVICE_OBJECT  FdoDevice,
IN PIRP  Irp,
IN PVOID  MapRegisterBase,
IN PVOID  Context 
)

Definition at line 2308 of file usbport.c.

2312 {
2314  PDMA_ADAPTER DmaAdapter;
2315  PUSBPORT_TRANSFER Transfer;
2316  PURB Urb;
2317  PUSBPORT_ENDPOINT Endpoint;
2318  PMDL Mdl;
2319  ULONG_PTR CurrentVa;
2321  SIZE_T CurrentLength;
2322  ULONG ix;
2324  PHYSICAL_ADDRESS PhAddr = {{0, 0}};
2325  PHYSICAL_ADDRESS PhAddress = {{0, 0}};
2326  ULONG TransferLength;
2327  SIZE_T SgCurrentLength;
2328  SIZE_T ElementLength;
2330  PDMA_OPERATIONS DmaOperations;
2331  USBD_STATUS USBDStatus;
2332  LIST_ENTRY List;
2333  PUSBPORT_TRANSFER transfer;
2334 
2335  DPRINT_CORE("USBPORT_MapTransfer: ...\n");
2336 
2337  FdoExtension = FdoDevice->DeviceExtension;
2338  DmaAdapter = FdoExtension->DmaAdapter;
2339  DmaOperations = DmaAdapter->DmaOperations;
2340 
2341  Transfer = Context;
2342 
2343  Urb = Transfer->Urb;
2344  Endpoint = Transfer->Endpoint;
2345  TransferLength = Transfer->TransferParameters.TransferBufferLength;
2346 
2347  Mdl = Urb->UrbControlTransfer.TransferBufferMDL;
2348  CurrentVa = (ULONG_PTR)MmGetMdlVirtualAddress(Mdl);
2349 
2350  sgList = &Transfer->SgList;
2351 
2352  sgList->Flags = 0;
2353  sgList->CurrentVa = CurrentVa;
2356  Transfer->MapRegisterBase = MapRegisterBase;
2357 
2358  ix = 0;
2359  CurrentLength = 0;
2360 
2361  do
2362  {
2364  ASSERT(Transfer->Direction != 0);
2365 
2366  PhAddress = DmaOperations->MapTransfer(DmaAdapter,
2367  Mdl,
2369  (PVOID)CurrentVa,
2370  &TransferLength,
2371  WriteToDevice);
2372 
2373  DPRINT_CORE("USBPORT_MapTransfer: PhAddress.LowPart - %p, PhAddress.HighPart - %x, TransferLength - %x\n",
2374  PhAddress.LowPart,
2375  PhAddress.HighPart,
2376  TransferLength);
2377 
2378  PhAddress.HighPart = 0;
2379  SgCurrentLength = TransferLength;
2380 
2381  do
2382  {
2383  ElementLength = PAGE_SIZE - (PhAddress.LowPart & (PAGE_SIZE - 1));
2384 
2385  if (ElementLength > SgCurrentLength)
2386  ElementLength = SgCurrentLength;
2387 
2388  DPRINT_CORE("USBPORT_MapTransfer: PhAddress.LowPart - %p, HighPart - %x, ElementLength - %x\n",
2389  PhAddress.LowPart,
2390  PhAddress.HighPart,
2391  ElementLength);
2392 
2393  sgList->SgElement[ix].SgPhysicalAddress = PhAddress;
2394  sgList->SgElement[ix].SgTransferLength = ElementLength;
2395  sgList->SgElement[ix].SgOffset = CurrentLength +
2396  (TransferLength - SgCurrentLength);
2397 
2398  PhAddress.LowPart += ElementLength;
2399  SgCurrentLength -= ElementLength;
2400 
2401  ++ix;
2402  }
2403  while (SgCurrentLength);
2404 
2405  if (PhAddr.QuadPart == PhAddress.QuadPart)
2406  {
2407  DPRINT1("USBPORT_MapTransfer: PhAddr == PhAddress\n");
2408  ASSERT(FALSE);
2409  }
2410 
2411  PhAddr = PhAddress;
2412 
2413  CurrentLength += TransferLength;
2414  CurrentVa += TransferLength;
2415 
2416  TransferLength = Transfer->TransferParameters.TransferBufferLength -
2417  CurrentLength;
2418  }
2419  while (CurrentLength != Transfer->TransferParameters.TransferBufferLength);
2420 
2421  sgList->SgElementCount = ix;
2422 
2423  if (Endpoint->EndpointProperties.DeviceSpeed == UsbHighSpeed)
2424  {
2425  Transfer->Flags |= TRANSFER_FLAG_HIGH_SPEED;
2426  }
2427 
2428  Transfer->Flags |= TRANSFER_FLAG_DMA_MAPPED;
2429 
2430  if ((Transfer->Flags & TRANSFER_FLAG_ISO) == 0)
2431  {
2433  &Endpoint->EndpointOldIrql);
2434 
2435  USBPORT_SplitTransfer(FdoDevice, Endpoint, Transfer, &List);
2436 
2437  while (!IsListEmpty(&List))
2438  {
2439  transfer = CONTAINING_RECORD(List.Flink,
2441  TransferLink);
2442 
2443  RemoveHeadList(&List);
2444  InsertTailList(&Endpoint->TransferList, &transfer->TransferLink);
2445  }
2446 
2448  Endpoint->EndpointOldIrql);
2449  }
2450  else
2451  {
2452  USBDStatus = USBPORT_InitializeIsoTransfer(FdoDevice,
2453  &Urb->UrbIsochronousTransfer,
2454  Transfer);
2455 
2456  if (USBDStatus != USBD_STATUS_SUCCESS)
2457  {
2459  &Endpoint->EndpointOldIrql);
2460 
2461  USBPORT_QueueDoneTransfer(Transfer, USBDStatus);
2462 
2464  Endpoint->EndpointOldIrql);
2465  }
2466  }
2467 
2468  DeviceHandle = Urb->UrbHeader.UsbdDeviceHandle;
2469  InterlockedDecrement(&DeviceHandle->DeviceHandleLock);
2470 
2471  if (USBPORT_EndpointWorker(Endpoint, 0))
2472  {
2474  Endpoint,
2476  }
2477 
2479 }
#define USBPORT_DMA_DIRECTION_TO_DEVICE
Definition: usbport.h:42
USBPORT_SCATTER_GATHER_LIST SgList
Definition: usbport.h:271
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
_Inout_ PUSB_DEVICE_HANDLE DeviceHandle
Definition: hubbusif.h:121
#define MmGetMdlVirtualAddress(_Mdl)
USBD_STATUS NTAPI USBPORT_InitializeIsoTransfer(PDEVICE_OBJECT FdoDevice, struct _URB_ISOCH_TRANSFER *Urb, PUSBPORT_TRANSFER Transfer)
Definition: iso.c:15
USBPORT_TRANSFER_PARAMETERS TransferParameters
Definition: usbport.h:254
VOID NTAPI KeAcquireSpinLock(PKSPIN_LOCK SpinLock, PKIRQL OldIrql)
Definition: spinlock.c:50
BOOLEAN NTAPI USBPORT_EndpointWorker(IN PUSBPORT_ENDPOINT Endpoint, IN BOOLEAN LockNotChecked)
Definition: endpoint.c:1656
PHYSICAL_ADDRESS SgPhysicalAddress
Definition: usbmport.h:107
#define InsertTailList(ListHead, Entry)
USB_DEVICE_SPEED DeviceSpeed
Definition: usbmport.h:73
#define MmGetSystemAddressForMdlSafe(_Mdl, _Priority)
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
struct _DMA_OPERATIONS * DmaOperations
Definition: iotypes.h:2295
#define TRANSFER_FLAG_DMA_MAPPED
Definition: usbport.h:131
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define FALSE
Definition: types.h:117
#define TRANSFER_FLAG_HIGH_SPEED
Definition: usbport.h:132
PMAP_TRANSFER MapTransfer
Definition: iotypes.h:2641
LIST_ENTRY TransferList
Definition: usbport.h:228
KIRQL EndpointOldIrql
Definition: usbport.h:216
unsigned char BOOLEAN
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
PUSBPORT_ENDPOINT Endpoint
Definition: usbport.h:253
struct _URB_HEADER UrbHeader
Definition: usb.h:531
LIST_ENTRY TransferLink
Definition: usbport.h:257
#define ASSERT(a)
Definition: mode.c:44
struct _URB_CONTROL_TRANSFER UrbControlTransfer
Definition: usb.h:539
VOID NTAPI USBPORT_SplitTransfer(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint, IN PUSBPORT_TRANSFER Transfer, IN PLIST_ENTRY List)
Definition: trfsplit.c:232
#define USBD_STATUS_SUCCESS
Definition: usb.h:170
#define InterlockedDecrement
Definition: armddk.h:52
LONG USBD_STATUS
Definition: usb.h:165
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
ULONG LowPart
Definition: typedefs.h:106
#define PAGE_SIZE
Definition: env_spec_w32.h:49
Definition: typedefs.h:119
USBPORT_ENDPOINT_PROPERTIES EndpointProperties
Definition: usbport.h:211
_In_ PSCSI_REQUEST_BLOCK _In_opt_ PVOID _In_ ULONG _In_ BOOLEAN WriteToDevice
Definition: cdrom.h:989
#define TRANSFER_FLAG_ISO
Definition: usbport.h:135
ULONG_PTR SIZE_T
Definition: typedefs.h:80
struct _URB_ISOCH_TRANSFER UrbIsochronousTransfer
Definition: usb.h:544
_Inout_ struct _IRP _In_ PVOID MapRegisterBase
Definition: iotypes.h:212
Definition: usb.h:529
BOOLEAN NTAPI USBPORT_QueueDoneTransfer(IN PUSBPORT_TRANSFER Transfer, IN USBD_STATUS USBDStatus)
Definition: usbport.c:839
USBPORT_SCATTER_GATHER_ELEMENT SgElement[2]
Definition: usbmport.h:121
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
_In_ WDFDEVICE _In_ PVOID _In_opt_ PMDL Mdl
#define DPRINT1
Definition: precomp.h:8
struct tagContext Context
Definition: acpixf.h:1034
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
#define INVALIDATE_ENDPOINT_WORKER_THREAD
Definition: usbport.h:37
PVOID MapRegisterBase
Definition: usbport.h:261
VOID NTAPI USBPORT_InvalidateEndpointHandler(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint, IN ULONG Type)
Definition: endpoint.c:1317
KSPIN_LOCK EndpointSpinLock
Definition: usbport.h:215
LONGLONG QuadPart
Definition: typedefs.h:114

Referenced by USBPORT_FlushMapTransfers().

◆ USBPORT_MiniportCompleteTransfer()

VOID NTAPI USBPORT_MiniportCompleteTransfer ( IN PVOID  MiniPortExtension,
IN PVOID  MiniPortEndpoint,
IN PVOID  TransferParameters,
IN USBD_STATUS  USBDStatus,
IN ULONG  TransferLength 
)

Definition at line 1990 of file usbport.c.

1995 {
1996  PUSBPORT_TRANSFER Transfer;
1997  PUSBPORT_TRANSFER ParentTransfer;
1998  PUSBPORT_TRANSFER SplitTransfer;
1999  PLIST_ENTRY SplitHead;
2001  KIRQL OldIrql;
2002 
2003  DPRINT_CORE("USBPORT_MiniportCompleteTransfer: USBDStatus - %x, TransferLength - %x\n",
2004  USBDStatus,
2005  TransferLength);
2006 
2007  Transfer = CONTAINING_RECORD(TransferParameters,
2009  TransferParameters);
2010 
2011  Transfer->Flags |= TRANSFER_FLAG_COMPLETED;
2012  Transfer->CompletedTransferLen = TransferLength;
2013 
2014  if (((Transfer->Flags & TRANSFER_FLAG_SPLITED) == 0) ||
2015  TransferLength >= Transfer->TransferParameters.TransferBufferLength)
2016  {
2017  goto Exit;
2018  }
2019 
2020  ParentTransfer = Transfer->ParentTransfer;
2021 
2022  KeAcquireSpinLock(&ParentTransfer->TransferSpinLock, &OldIrql);
2023 
2024  if (IsListEmpty(&ParentTransfer->SplitTransfersList))
2025  {
2026  goto Exit;
2027  }
2028 
2029  SplitHead = &ParentTransfer->SplitTransfersList;
2030  Entry = SplitHead->Flink;
2031 
2032  while (Entry && !IsListEmpty(SplitHead))
2033  {
2034  SplitTransfer = CONTAINING_RECORD(Entry,
2036  SplitLink);
2037 
2038  if (!(SplitTransfer->Flags & TRANSFER_FLAG_SUBMITED))
2039  {
2040  DPRINT1("USBPORT_MiniportCompleteTransfer: SplitTransfer->Flags - %X\n",
2041  SplitTransfer->Flags);
2042  //Add TRANSFER_FLAG_xxx
2043  }
2044 
2045  Entry = Entry->Flink;
2046  }
2047 
2048  KeReleaseSpinLock(&ParentTransfer->TransferSpinLock, OldIrql);
2049 
2050 Exit:
2051  USBPORT_QueueDoneTransfer(Transfer, USBDStatus);
2052 }
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
struct _Entry Entry
Definition: kefuncs.h:627
USBPORT_TRANSFER_PARAMETERS TransferParameters
Definition: usbport.h:254
VOID NTAPI KeAcquireSpinLock(PKSPIN_LOCK SpinLock, PKIRQL OldIrql)
Definition: spinlock.c:50
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
UCHAR KIRQL
Definition: env_spec_w32.h:591
struct _USBPORT_TRANSFER * ParentTransfer
Definition: usbport.h:264
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
KIRQL OldIrql
Definition: mm.h:1502
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
static void Exit(void)
Definition: sock.c:1331
Definition: typedefs.h:119
#define TRANSFER_FLAG_SPLITED
Definition: usbport.h:137
BOOLEAN NTAPI USBPORT_QueueDoneTransfer(IN PUSBPORT_TRANSFER Transfer, IN USBD_STATUS USBDStatus)
Definition: usbport.c:839
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
LIST_ENTRY SplitTransfersList
Definition: usbport.h:266
#define DPRINT1
Definition: precomp.h:8
KSPIN_LOCK TransferSpinLock
Definition: usbport.h:265
#define TRANSFER_FLAG_COMPLETED
Definition: usbport.h:138
ULONG CompletedTransferLen
Definition: usbport.h:259
base of all file and directory entries
Definition: entries.h:82
#define TRANSFER_FLAG_SUBMITED
Definition: usbport.h:133

Referenced by USBPORT_RegisterUSBPortDriver().

◆ USBPORT_MiniportInterrupts()

VOID NTAPI USBPORT_MiniportInterrupts ( IN PDEVICE_OBJECT  FdoDevice,
IN BOOLEAN  IsEnable 
)

Definition at line 555 of file usbport.c.

557 {
560  BOOLEAN IsLock;
561  KIRQL OldIrql;
562 
563  DPRINT_INT("USBPORT_MiniportInterrupts: IsEnable - %p\n", IsEnable);
564 
565  FdoExtension = FdoDevice->DeviceExtension;
566  Packet = &FdoExtension->MiniPortInterface->Packet;
567 
568  IsLock = (Packet->MiniPortFlags & USB_MINIPORT_FLAGS_NOT_LOCK_INT) == 0;
569 
570  if (IsLock)
571  KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
572 
573  if (IsEnable)
574  {
576  Packet->EnableInterrupts(FdoExtension->MiniPortExt);
577  }
578  else
579  {
580  Packet->DisableInterrupts(FdoExtension->MiniPortExt);
582  }
583 
584  if (IsLock)
585  KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
586 }
#define DPRINT_INT(...)
Definition: usbdebug.h:146
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
VOID NTAPI KeAcquireSpinLock(PKSPIN_LOCK SpinLock, PKIRQL OldIrql)
Definition: spinlock.c:50
UCHAR KIRQL
Definition: env_spec_w32.h:591
unsigned char BOOLEAN
KIRQL OldIrql
Definition: mm.h:1502
#define USBPORT_FLAG_INTERRUPT_ENABLED
Definition: usbport.h:72
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define USB_MINIPORT_FLAGS_NOT_LOCK_INT
Definition: usbmport.h:536

Referenced by USBPORT_ResumeController(), and USBPORT_StartDevice().

◆ USBPORT_NotifyDoubleBuffer()

ULONG NTAPI USBPORT_NotifyDoubleBuffer ( IN PVOID  MiniPortExtension,
IN PVOID  MiniPortTransfer,
IN PVOID  Buffer,
IN SIZE_T  Length 
)

Definition at line 690 of file usbport.c.

694 {
695  DPRINT1("USBPORT_NotifyDoubleBuffer: UNIMPLEMENTED. FIXME.\n");
696  return 0;
697 }
#define DPRINT1
Definition: precomp.h:8

Referenced by USBPORT_RegisterUSBPortDriver().

◆ USBPORT_NtStatusToMpStatus()

MPSTATUS NTAPI USBPORT_NtStatusToMpStatus ( NTSTATUS  NtStatus)

Definition at line 232 of file usbport.c.

233 {
234  DPRINT("USBPORT_NtStatusToMpStatus: NtStatus - %x\n", NtStatus);
235 
236  if (NtStatus == STATUS_SUCCESS)
237  {
238  return MP_STATUS_SUCCESS;
239  }
240  else
241  {
242  return MP_STATUS_UNSUCCESSFUL;
243  }
244 }
#define MP_STATUS_UNSUCCESSFUL
Definition: usbmport.h:142
#define MP_STATUS_SUCCESS
Definition: usbmport.h:134
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71

Referenced by USBPORT_GetMiniportRegistryKeyValue(), and USBPORT_ReadWriteConfigSpace().

◆ USBPORT_QueueDoneTransfer()

BOOLEAN NTAPI USBPORT_QueueDoneTransfer ( IN PUSBPORT_TRANSFER  Transfer,
IN USBD_STATUS  USBDStatus 
)

Definition at line 839 of file usbport.c.

841 {
842  PDEVICE_OBJECT FdoDevice;
844 
845  DPRINT_CORE("USBPORT_QueueDoneTransfer: Transfer - %p, USBDStatus - %p\n",
846  Transfer,
847  USBDStatus);
848 
849  FdoDevice = Transfer->Endpoint->FdoDevice;
850  FdoExtension = FdoDevice->DeviceExtension;
851 
852  RemoveEntryList(&Transfer->TransferLink);
853  Transfer->USBDStatus = USBDStatus;
854 
855  ExInterlockedInsertTailList(&FdoExtension->DoneTransferList,
856  &Transfer->TransferLink,
857  &FdoExtension->DoneTransferSpinLock);
858 
859  return KeInsertQueueDpc(&FdoExtension->TransferFlushDpc, NULL, NULL);
860 }
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
BOOLEAN NTAPI KeInsertQueueDpc(IN PKDPC Dpc, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: dpc.c:725
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
PVOID DeviceExtension
Definition: env_spec_w32.h:418
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
#define NULL
Definition: types.h:112

Referenced by USBPORT_MapTransfer(), USBPORT_MiniportCompleteTransfer(), and USBPORT_RootHubEndpointWorker().

◆ USBPORT_ReadWriteConfigSpace()

MPSTATUS NTAPI USBPORT_ReadWriteConfigSpace ( IN PVOID  MiniPortExtension,
IN BOOLEAN  IsReadData,
IN PVOID  Buffer,
IN ULONG  Offset,
IN ULONG  Length 
)

Definition at line 456 of file usbport.c.

461 {
464  PDEVICE_OBJECT FdoDevice;
465 
466  DPRINT("USBPORT_ReadWriteConfigSpace: ...\n");
467 
468  //FdoExtension->MiniPortExt = (PVOID)((ULONG_PTR)FdoExtension + sizeof(USBPORT_DEVICE_EXTENSION));
469  FdoExtension = (PUSBPORT_DEVICE_EXTENSION)((ULONG_PTR)MiniPortExtension -
470  sizeof(USBPORT_DEVICE_EXTENSION));
471 
472  FdoDevice = FdoExtension->CommonExtension.SelfDevice;
473 
475  IsReadData,
476  Buffer,
477  Offset,
478  Length);
479 
481 }
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
NTSTATUS NTAPI USBPORT_GetSetConfigSpaceData(IN PDEVICE_OBJECT FdoDevice, IN BOOLEAN IsReadData, IN PVOID Buffer, IN ULONG Offset, IN ULONG Length)
Definition: usbport.c:410
LONG NTSTATUS
Definition: precomp.h:26
uint32_t ULONG_PTR
Definition: typedefs.h:65
struct _USBPORT_DEVICE_EXTENSION USBPORT_DEVICE_EXTENSION
Definition: bufpool.h:45
Status
Definition: gdiplustypes.h:24
MPSTATUS NTAPI USBPORT_NtStatusToMpStatus(NTSTATUS NtStatus)
Definition: usbport.c:232
struct _USBPORT_DEVICE_EXTENSION * PUSBPORT_DEVICE_EXTENSION
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define DPRINT
Definition: sndvol32.h:71

Referenced by USBPORT_RegisterUSBPortDriver().

◆ USBPORT_RegisterUSBPortDriver()

NTSTATUS NTAPI USBPORT_RegisterUSBPortDriver ( IN PDRIVER_OBJECT  DriverObject,
IN ULONG  Version,
IN PUSBPORT_REGISTRATION_PACKET  RegPacket 
)

Definition at line 2811 of file usbport.c.

2814 {
2815  PUSBPORT_MINIPORT_INTERFACE MiniPortInterface;
2816 
2817  DPRINT("USBPORT_RegisterUSBPortDriver: DriverObject - %p, Version - %p, RegPacket - %p\n",
2818  DriverObject,
2819  Version,
2820  RegPacket);
2821 
2822  DPRINT("USBPORT_RegisterUSBPortDriver: sizeof(USBPORT_MINIPORT_INTERFACE) - %x\n",
2823  sizeof(USBPORT_MINIPORT_INTERFACE));
2824 
2825  DPRINT("USBPORT_RegisterUSBPortDriver: sizeof(USBPORT_DEVICE_EXTENSION) - %x\n",
2826  sizeof(USBPORT_DEVICE_EXTENSION));
2827 
2829  {
2830  return STATUS_UNSUCCESSFUL;
2831  }
2832 
2833  if (!USBPORT_Initialized)
2834  {
2838 
2841  }
2842 
2843  MiniPortInterface = ExAllocatePoolWithTag(NonPagedPool,
2845  USB_PORT_TAG);
2846  if (!MiniPortInterface)
2847  {
2849  }
2850 
2851  RtlZeroMemory(MiniPortInterface, sizeof(USBPORT_MINIPORT_INTERFACE));
2852 
2853  MiniPortInterface->DriverObject = DriverObject;
2854  MiniPortInterface->DriverUnload = DriverObject->DriverUnload;
2855  MiniPortInterface->Version = Version;
2856 
2858  &MiniPortInterface->DriverLink,
2859  &USBPORT_SpinLock);
2860 
2861  DriverObject->DriverExtension->AddDevice = USBPORT_AddDevice;
2862  DriverObject->DriverUnload = USBPORT_Unload;
2863 
2864  DriverObject->MajorFunction[IRP_MJ_CREATE] = USBPORT_Dispatch;
2865  DriverObject->MajorFunction[IRP_MJ_CLOSE] = USBPORT_Dispatch;
2868  DriverObject->MajorFunction[IRP_MJ_PNP] = USBPORT_Dispatch;
2869  DriverObject->MajorFunction[IRP_MJ_POWER] = USBPORT_Dispatch;
2871 
2888 
2889  RtlCopyMemory(&MiniPortInterface->Packet,
2890  RegPacket,
2891  sizeof(USBPORT_REGISTRATION_PACKET));
2892 
2893  return STATUS_SUCCESS;
2894 }
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
USBPORT_REGISTRATION_PACKET RegPacket
Definition: usbehci.c:16
PUSBPORT_TEST_DEBUG_BREAK UsbPortTestDebugBreak
Definition: usbmport.h:611
PUSBPORT_GET_MAPPED_VIRTUAL_ADDRESS UsbPortGetMappedVirtualAddress
Definition: usbmport.h:619
PUSBPORT_ASSERT_FAILURE UsbPortAssertFailure
Definition: usbmport.h:612
PUSBPORT_COMPLETE_ISO_TRANSFER UsbPortCompleteIsoTransfer
Definition: usbmport.h:617
#define TRUE
Definition: types.h:120
PUSBPORT_INVALIDATE_ENDPOINT UsbPortInvalidateEndpoint
Definition: usbmport.h:615
LIST_ENTRY USBPORT_USB1FdoList
Definition: usbport.c:19
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
VOID NTAPI USBPORT_Unload(IN PDRIVER_OBJECT DriverObject)
Definition: usbport.c:1970
PUSBPORT_COMPLETE_TRANSFER UsbPortCompleteTransfer
Definition: usbmport.h:616
USBPORT_REGISTRATION_PACKET Packet
Definition: usbmport.h:644
PDRIVER_OBJECT DriverObject
Definition: usbmport.h:640
ULONG NTAPI USBPORT_CompleteIsoTransfer(IN PVOID MiniPortExtension, IN PVOID MiniPortEndpoint, IN PVOID TransferParameters, IN ULONG TransferLength)
Definition: iso.c:25
PDRIVER_UNLOAD DriverUnload
Definition: usbmport.h:642
ULONG NTAPI USBPORT_TestDebugBreak(IN PVOID MiniPortExtension)
Definition: debug.c:31
PUSBPORT_NOTIFY_DOUBLE_BUFFER UsbPortNotifyDoubleBuffer
Definition: usbmport.h:625
MPSTATUS NTAPI USBPORT_ReadWriteConfigSpace(IN PVOID MiniPortExtension, IN BOOLEAN IsReadData, IN PVOID Buffer, IN ULONG Offset, IN ULONG Length)
Definition: usbport.c:456
LIST_ENTRY USBPORT_USB2FdoList
Definition: usbport.c:20
PUSBPORT_READ_WRITE_CONFIG_SPACE UsbPortReadWriteConfigSpace
Definition: usbmport.h:621
BOOLEAN USBPORT_Initialized
Definition: usbport.c:23
#define USB_PORT_TAG
Definition: usbport.h:44
NTSTATUS NTAPI USBPORT_Wait(IN PVOID MiniPortExtension, IN ULONG Milliseconds)
Definition: usbport.c:543
PUSBPORT_DBG_PRINT UsbPortDbgPrint
Definition: usbmport.h:610
PUSBPORT_LOG_ENTRY UsbPortLogEntry
Definition: usbmport.h:618
PUSBPORT_REQUEST_ASYNC_CALLBACK UsbPortRequestAsyncCallback
Definition: usbmport.h:620
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:238
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
ULONG NTAPI USBPORT_InvalidateRootHub(PVOID MiniPortExtension)
Definition: roothub.c:917
PVOID NTAPI USBPORT_GetMappedVirtualAddress(IN ULONG PhysicalAddress, IN PVOID MiniPortExtension, IN PVOID MiniPortEndpoint)
Definition: usbport.c:2135
PUSBPORT_INVALIDATE_ROOT_HUB UsbPortInvalidateRootHub
Definition: usbmport.h:614
VOID NTAPI USBPORT_MiniportCompleteTransfer(IN PVOID MiniPortExtension, IN PVOID MiniPortEndpoint, IN PVOID TransferParameters, IN USBD_STATUS USBDStatus, IN ULONG TransferLength)
Definition: usbport.c:1990
ULONG NTAPI USBPORT_RequestAsyncCallback(IN PVOID MiniPortExtension, IN ULONG TimerValue, IN PVOID Buffer, IN SIZE_T Length, IN ASYNC_TIMER_CALLBACK *Callback)
Definition: usbport.c:2079
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
ULONG NTAPI USBPORT_NotifyDoubleBuffer(IN PVOID MiniPortExtension, IN PVOID MiniPortTransfer, IN PVOID Buffer, IN SIZE_T Length)
Definition: usbport.c:690
NTSTATUS NTAPI USBPORT_Dispatch(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: usbport.c:2651
IN PVOID IN PVOID IN USHORT Version
Definition: pci.h:361
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
PUSBPORT_INVALIDATE_CONTROLLER UsbPortInvalidateController
Definition: usbmport.h:623
#define IRP_MJ_POWER
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define IRP_MJ_SYSTEM_CONTROL
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
ULONG NTAPI USBPORT_AssertFailure(PVOID MiniPortExtension, PVOID FailedAssertion, PVOID FileName, ULONG LineNumber, PCHAR Message)
Definition: debug.c:39
ULONG NTAPI USBPORT_DbgPrint(IN PVOID MiniPortExtension, IN ULONG Level, IN PCH Format,...)
Definition: debug.c:20
PUSBPORT_GET_MINIPORT_REGISTRY_KEY_VALUE UsbPortGetMiniportRegistryKeyValue
Definition: usbmport.h:613
ULONG NTAPI USBPORT_InvalidateEndpoint(IN PVOID MiniPortExtension, IN PVOID MiniPortEndpoint)
Definition: usbport.c:2164
VOID NTAPI USBPORT_BugCheck(IN PVOID MiniPortExtension)
Definition: debug.c:52
KSPIN_LOCK USBPORT_SpinLock
Definition: usbport.c:22
ULONG NTAPI USBPORT_InvalidateController(IN PVOID MiniPortExtension, IN ULONG Type)
Definition: usbport.c:670
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_SUCCESS
Definition: shellext.h:65
PUSBPORT_WAIT UsbPortWait
Definition: usbmport.h:622
#define DPRINT
Definition: sndvol32.h:71
PUSBPORT_BUG_CHECK UsbPortBugCheck
Definition: usbmport.h:624
NTSTATUS NTAPI USBPORT_AddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject)
Definition: usbport.c:1833
#define USB10_MINIPORT_INTERFACE_VERSION
Definition: usbmport.h:636
LIST_ENTRY USBPORT_MiniPortDrivers
Definition: usbport.c:18
ULONG NTAPI USBPORT_LogEntry(IN PVOID MiniPortExtension, IN ULONG DriverTag, IN ULONG EnumTag, IN ULONG P1, IN ULONG P2, IN ULONG P3)
Definition: debug.c:61
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
MPSTATUS NTAPI USBPORT_GetMiniportRegistryKeyValue(IN PVOID MiniPortExtension, IN BOOL UseDriverKey, IN PCWSTR SourceString, IN SIZE_T LengthStr, IN PVOID Buffer, IN SIZE_T BufferLength)
Definition: usbport.c:373

Referenced by DriverEntry().

◆ USBPORT_RemoveUSBxFdo()

VOID NTAPI USBPORT_RemoveUSBxFdo ( IN PDEVICE_OBJECT  FdoDevice)

Definition at line 98 of file usbport.c.

99 {
101  KIRQL OldIrql;
102 
103  DPRINT("USBPORT_RemoveUSBxFdo: FdoDevice - %p\n", FdoDevice);
104 
105  FdoExtension = FdoDevice->DeviceExtension;
106 
108  RemoveEntryList(&FdoExtension->ControllerLink);
110 
112 
113  FdoExtension->ControllerLink.Flink = NULL;
114  FdoExtension->ControllerLink.Blink = NULL;
115 }
VOID NTAPI KeAcquireSpinLock(PKSPIN_LOCK SpinLock, PKIRQL OldIrql)
Definition: spinlock.c:50
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
UCHAR KIRQL
Definition: env_spec_w32.h:591
KIRQL OldIrql
Definition: mm.h:1502
#define USBPORT_FLAG_REGISTERED_FDO
Definition: usbport.h:79
#define NULL
Definition: types.h:112
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
KSPIN_LOCK USBPORT_SpinLock
Definition: usbport.c:22
#define DPRINT
Definition: sndvol32.h:71

◆ USBPORT_RequestAsyncCallback()

ULONG NTAPI USBPORT_RequestAsyncCallback ( IN PVOID  MiniPortExtension,
IN ULONG  TimerValue,
IN PVOID  Buffer,
IN SIZE_T  Length,
IN ASYNC_TIMER_CALLBACK *  Callback 
)

Definition at line 2079 of file usbport.c.

2084 {
2086  PDEVICE_OBJECT FdoDevice;
2087  PUSBPORT_ASYNC_CALLBACK_DATA AsyncCallbackData;
2088  LARGE_INTEGER DueTime = {{0, 0}};
2089 
2090  DPRINT("USBPORT_RequestAsyncCallback: ...\n");
2091 
2092  FdoExtension = (PUSBPORT_DEVICE_EXTENSION)((ULONG_PTR)MiniPortExtension -
2093  sizeof(USBPORT_DEVICE_EXTENSION));
2094 
2095  FdoDevice = FdoExtension->CommonExtension.SelfDevice;
2096 
2097  AsyncCallbackData = ExAllocatePoolWithTag(NonPagedPool,
2099  USB_PORT_TAG);
2100 
2101  if (!AsyncCallbackData)
2102  {
2103  DPRINT1("USBPORT_RequestAsyncCallback: Not allocated AsyncCallbackData!\n");
2104  return 0;
2105  }
2106 
2107  RtlZeroMemory(AsyncCallbackData,
2109 
2110  if (Length)
2111  {
2112  RtlCopyMemory(&AsyncCallbackData->CallbackContext, Buffer, Length);
2113  }
2114 
2115  AsyncCallbackData->FdoDevice = FdoDevice;
2116  AsyncCallbackData->CallbackFunction = Callback;
2117 
2118  KeInitializeTimer(&AsyncCallbackData->AsyncTimer);
2119 
2120  KeInitializeDpc(&AsyncCallbackData->AsyncTimerDpc,
2122  AsyncCallbackData);
2123 
2124  DueTime.QuadPart -= (KeQueryTimeIncrement() - 1) + 10000 * TimerValue;
2125 
2126  KeSetTimer(&AsyncCallbackData->AsyncTimer,
2127  DueTime,
2128  &AsyncCallbackData->AsyncTimerDpc);
2129 
2130  return 0;
2131 }
BOOLEAN NTAPI KeSetTimer(IN OUT PKTIMER Timer, IN LARGE_INTEGER DueTime, IN PKDPC Dpc OPTIONAL)
Definition: timerobj.c:281
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
VOID NTAPI USBPORT_AsyncTimerDpc(IN PRKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: usbport.c:2056
ULONG NTAPI KeQueryTimeIncrement(VOID)
Definition: clock.c:153
PDEVICE_OBJECT FdoDevice
Definition: usbport.h:434
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define USB_PORT_TAG
Definition: usbport.h:44
struct _USBPORT_DEVICE_EXTENSION USBPORT_DEVICE_EXTENSION
VOID NTAPI KeInitializeTimer(OUT PKTIMER Timer)
Definition: timerobj.c:233
Definition: bufpool.h:45
ASYNC_TIMER_CALLBACK * CallbackFunction
Definition: usbport.h:437
struct _USBPORT_DEVICE_EXTENSION * PUSBPORT_DEVICE_EXTENSION
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
Definition: wdfinterrupt.h:456
_In_ WDFTIMER _In_ LONGLONG DueTime
Definition: wdftimer.h:187
#define DPRINT1
Definition: precomp.h:8
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define DPRINT
Definition: sndvol32.h:71
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:712

Referenced by USBPORT_RegisterUSBPortDriver().

◆ USBPORT_SetRegistryKeyValue()

NTSTATUS NTAPI USBPORT_SetRegistryKeyValue ( IN PDEVICE_OBJECT  DeviceObject,
IN BOOL  UseDriverKey,
IN ULONG  Type,
IN PCWSTR  ValueNameString,
IN PVOID  Data,
IN ULONG  DataSize 
)

Definition at line 248 of file usbport.c.

254 {
258 
259  DPRINT("USBPORT_SetRegistryKeyValue: ValueNameString - %S\n",
260  ValueNameString);
261 
262  if (UseDriverKey)
263  {
267  &KeyHandle);
268  }
269  else
270  {
274  &KeyHandle);
275  }
276 
277  if (NT_SUCCESS(Status))
278  {
279  RtlInitUnicodeString(&ValueName, ValueNameString);
280 
281  Status = ZwSetValueKey(KeyHandle,
282  &ValueName,
283  0,
284  Type,
285  Data,
286  DataSize);
287 
289  }
290 
291  return Status;
292 }
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4711
#define PLUGPLAY_REGKEY_DEVICE
Definition: iofuncs.h:2786
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
LONG NTSTATUS
Definition: precomp.h:26
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Type
Definition: Type.h:6
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:240
#define PLUGPLAY_REGKEY_DRIVER
Definition: usbd.c:42
#define STANDARD_RIGHTS_ALL
Definition: nt_native.h:69
NTSTATUS NTAPI IoOpenDeviceRegistryKey(IN PDEVICE_OBJECT DeviceObject, IN ULONG DevInstKeyType, IN ACCESS_MASK DesiredAccess, OUT PHANDLE DevInstRegKey)
Definition: pnpmgr.c:2191
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define DPRINT
Definition: sndvol32.h:71
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4751

Referenced by USBHI_ControllerSelectiveSuspend(), USBPORT_RegisterDeviceInterface(), and USBPORT_StartDevice().

◆ USBPORT_SignalWorkerThread()

VOID NTAPI USBPORT_SignalWorkerThread ( IN PDEVICE_OBJECT  FdoDevice)

Definition at line 1111 of file usbport.c.

1112 {
1114  KIRQL OldIrql;
1115 
1116  DPRINT_CORE("USBPORT_SignalWorkerThread ...\n");
1117 
1118  FdoExtension = FdoDevice->DeviceExtension;
1119 
1120  KeAcquireSpinLock(&FdoExtension->WorkerThreadEventSpinLock, &OldIrql);
1121  KeSetEvent(&FdoExtension->WorkerThreadEvent, EVENT_INCREMENT, FALSE);
1122  KeReleaseSpinLock(&FdoExtension->WorkerThreadEventSpinLock, OldIrql);
1123 }
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
VOID NTAPI KeAcquireSpinLock(PKSPIN_LOCK SpinLock, PKIRQL OldIrql)
Definition: spinlock.c:50
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define FALSE
Definition: types.h:117
KIRQL OldIrql
Definition: mm.h:1502
#define EVENT_INCREMENT
Definition: iotypes.h:597
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627

Referenced by USBPORT_ClosePipe(), USBPORT_DpcHandler(), USBPORT_InvalidateEndpointHandler(), USBPORT_StopWorkerThread(), USBPORT_SynchronizeControllersStart(), USBPORT_SynchronizeRootHubCallback(), and USBPORT_WorkerThreadHandler().

◆ USBPORT_SoftInterrupt()

VOID NTAPI USBPORT_SoftInterrupt ( IN PDEVICE_OBJECT  FdoDevice)

Definition at line 611 of file usbport.c.

612 {
614  LARGE_INTEGER DueTime = {{0, 0}};
615 
616  DPRINT_INT("USBPORT_SoftInterrupt: ...\n");
617 
618  FdoExtension = FdoDevice->DeviceExtension;
619 
620  KeInitializeTimer(&FdoExtension->TimerSoftInterrupt);
621 
622  KeInitializeDpc(&FdoExtension->SoftInterruptDpc,
624  FdoDevice);
625 
626  DueTime.QuadPart -= 10000 + (KeQueryTimeIncrement() - 1);
627 
628  KeSetTimer(&FdoExtension->TimerSoftInterrupt,
629  DueTime,
630  &FdoExtension->SoftInterruptDpc);
631 }
#define DPRINT_INT(...)
Definition: usbdebug.h:146
BOOLEAN NTAPI KeSetTimer(IN OUT PKTIMER Timer, IN LARGE_INTEGER DueTime, IN PKDPC Dpc OPTIONAL)
Definition: timerobj.c:281
ULONG NTAPI KeQueryTimeIncrement(VOID)
Definition: clock.c:153
VOID NTAPI KeInitializeTimer(OUT PKTIMER Timer)
Definition: timerobj.c:233
VOID NTAPI USBPORT_SoftInterruptDpc(IN PRKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: usbport.c:590
_In_ WDFTIMER _In_ LONGLONG DueTime
Definition: wdftimer.h:187
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:712

Referenced by USBPORT_InvalidateControllerHandler().

◆ USBPORT_SoftInterruptDpc()

VOID NTAPI USBPORT_SoftInterruptDpc ( IN PRKDPC  Dpc,
IN PVOID  DeferredContext,
IN PVOID  SystemArgument1,
IN PVOID  SystemArgument2 
)

Definition at line 590 of file usbport.c.

594 {
595  PDEVICE_OBJECT FdoDevice;
597 
598  DPRINT_INT("USBPORT_SoftInterruptDpc: ...\n");
599 
600  FdoDevice = DeferredContext;
601  FdoExtension = FdoDevice->DeviceExtension;
602 
603  if (!KeInsertQueueDpc(&FdoExtension->IsrDpc, NULL, (PVOID)1))
604  {
605  InterlockedDecrement(&FdoExtension->IsrDpcCounter);
606  }
607 }
#define DPRINT_INT(...)
Definition: usbdebug.h:146
BOOLEAN NTAPI KeInsertQueueDpc(IN PKDPC Dpc, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: dpc.c:725
PVOID DeviceExtension
Definition: env_spec_w32.h:418
#define InterlockedDecrement
Definition: armddk.h:52
#define NULL
Definition: types.h:112
_In_opt_ PVOID DeferredContext
Definition: ketypes.h:675

Referenced by USBPORT_SoftInterrupt().

◆ USBPORT_StartTimer()

BOOLEAN NTAPI USBPORT_StartTimer ( IN PDEVICE_OBJECT  FdoDevice,
IN ULONG  Time 
)

Definition at line 1675 of file usbport.c.

1677 {
1679  LARGE_INTEGER DueTime = {{0, 0}};
1680  ULONG TimeIncrement;
1681  BOOLEAN Result;
1682 
1683  DPRINT_TIMER("USBPORT_StartTimer: FdoDevice - %p, Time - %x\n",
1684  FdoDevice,
1685  Time);
1686 
1687  FdoExtension = FdoDevice->DeviceExtension;
1688 
1689  TimeIncrement = KeQueryTimeIncrement();
1690 
1692  FdoExtension->TimerValue = Time;
1693 
1694  KeInitializeTimer(&FdoExtension->TimerObject);
1695  KeInitializeDpc(&FdoExtension->TimerDpc, USBPORT_TimerDpc, FdoDevice);
1696 
1697  DueTime.QuadPart -= 10000 * Time + (TimeIncrement - 1);
1698 
1699  Result = KeSetTimer(&FdoExtension->TimerObject,
1700  DueTime,
1701  &FdoExtension->TimerDpc);
1702 
1703  return Result;
1704 }
BOOLEAN NTAPI KeSetTimer(IN OUT PKTIMER Timer, IN LARGE_INTEGER DueTime, IN PKDPC Dpc OPTIONAL)
Definition: timerobj.c:281
ULONG NTAPI KeQueryTimeIncrement(VOID)
Definition: clock.c:153
unsigned char BOOLEAN
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
VOID NTAPI KeInitializeTimer(OUT PKTIMER Timer)
Definition: timerobj.c:233
#define DPRINT_TIMER(...)
Definition: usbdebug.h:147
_In_ WDFTIMER _In_ LONGLONG DueTime
Definition: wdftimer.h:187
unsigned int ULONG
Definition: retypes.h:1
VOID NTAPI USBPORT_TimerDpc(IN PRKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: usbport.c:1556
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:712
static PLARGE_INTEGER Time
Definition: time.c:105
#define USBPORT_TMFLAG_TIMER_QUEUED
Definition: usbport.h:93

Referenced by USBPORT_StartDevice().

◆ USBPORT_StopWorkerThread()

VOID NTAPI USBPORT_StopWorkerThread ( IN PDEVICE_OBJECT  FdoDevice)

Definition at line 1455 of file usbport.c.

1456 {
1458  NTSTATUS Status;
1459 
1460  DPRINT("USBPORT_StopWorkerThread ...\n");
1461 
1462  FdoExtension = FdoDevice->DeviceExtension;
1463 
1465  USBPORT_SignalWorkerThread(FdoDevice);
1466  Status = ZwWaitForSingleObject(FdoExtension->WorkerThreadHandle, FALSE, NULL);
1468 }
LONG NTSTATUS
Definition: precomp.h:26
#define FALSE
Definition: types.h:117
Status
Definition: gdiplustypes.h:24
#define USBPORT_FLAG_WORKER_THREAD_EXIT
Definition: usbport.h:70
VOID NTAPI USBPORT_SignalWorkerThread(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:1111
#define NULL
Definition: types.h:112
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
#define NT_ASSERT
Definition: rtlfuncs.h:3310

Referenced by USBPORT_StartDevice().

◆ USBPORT_SynchronizeControllersStart()

VOID NTAPI USBPORT_SynchronizeControllersStart ( IN PDEVICE_OBJECT  FdoDevice)

Definition at line 1472 of file usbport.c.

1473 {
1475  PDEVICE_OBJECT PdoDevice;
1477  PDEVICE_OBJECT USB2FdoDevice = NULL;
1478  PUSBPORT_DEVICE_EXTENSION USB2FdoExtension;
1479  BOOLEAN IsOn;
1480 
1481  DPRINT_TIMER("USBPORT_SynchronizeControllersStart: FdoDevice - %p\n",
1482  FdoDevice);
1483 
1484  FdoExtension = FdoDevice->DeviceExtension;
1485 
1486  PdoDevice = FdoExtension->RootHubPdo;
1487 
1488  if (!PdoDevice)
1489  {
1490  return;
1491  }
1492 
1493  PdoExtension = PdoDevice->DeviceExtension;
1494 
1495  if (PdoExtension->RootHubInitCallback == NULL ||
1497  {
1498  return;
1499  }
1500 
1501  DPRINT_TIMER("USBPORT_SynchronizeControllersStart: Flags - %p\n",
1502  FdoExtension->Flags);
1503 
1505  {
1506  IsOn = FALSE;
1507 
1508  USB2FdoDevice = USBPORT_FindUSB2Controller(FdoDevice);
1509 
1510  DPRINT_TIMER("USBPORT_SynchronizeControllersStart: USB2FdoDevice - %p\n",
1511  USB2FdoDevice);
1512 
1513  if (USB2FdoDevice)
1514  {
1515  USB2FdoExtension = USB2FdoDevice->DeviceExtension;
1516 
1517  if (USB2FdoExtension->CommonExtension.PnpStateFlags &
1519  {
1520  IsOn = TRUE;
1521  }
1522  }
1523 
1524  if (!(FdoExtension->Flags & USBPORT_FLAG_NO_HACTION))
1525  {
1526  goto Start;
1527  }
1528 
1529  USB2FdoDevice = NULL;
1530  }
1531 
1532  IsOn = TRUE;
1533 
1534  Start:
1535 
1536  if (IsOn &&
1537  !InterlockedCompareExchange(&FdoExtension->RHInitCallBackLock, 1, 0))
1538  {
1540  USBPORT_SignalWorkerThread(FdoDevice);
1541 
1542  if (USB2FdoDevice)
1543  {
1544  USB2FdoExtension = USB2FdoDevice->DeviceExtension;
1545 
1546  USB2FdoExtension->Flags |= USBPORT_FLAG_RH_INIT_CALLBACK;
1547  USBPORT_SignalWorkerThread(USB2FdoDevice);
1548  }
1549  }
1550 
1551  DPRINT_TIMER("USBPORT_SynchronizeControllersStart: exit\n");
1552 }
PDEVICE_OBJECT NTAPI USBPORT_FindUSB2Controller(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:27
#define TRUE
Definition: types.h:120
#define InterlockedCompareExchange
Definition: interlocked.h:104
#define USBPORT_FLAG_RH_INIT_CALLBACK
Definition: usbport.h:84
USBPORT_COMMON_DEVICE_EXTENSION CommonExtension
Definition: usbport.h:292
#define FALSE
Definition: types.h:117
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
#define USBPORT_FLAG_COMPANION_HC
Definition: usbport.h:78
#define DPRINT_TIMER(...)
Definition: usbdebug.h:147
Definition: partlist.h:33
VOID NTAPI USBPORT_SignalWorkerThread(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:1111
#define USBPORT_FLAG_NO_HACTION
Definition: usbport.h:80
#define NULL
Definition: types.h:112
#define USBPORT_PNP_STATE_STARTED
Definition: usbport.h:88

Referenced by USBPORT_TimerDpc().

◆ USBPORT_SynchronizeRootHubCallback()

VOID NTAPI USBPORT_SynchronizeRootHubCallback ( IN PDEVICE_OBJECT  FdoDevice,
IN PDEVICE_OBJECT  Usb2FdoDevice 
)

Definition at line 1257 of file usbport.c.

1259 {
1262  PUSBPORT_DEVICE_EXTENSION Usb2FdoExtension;
1263  PDEVICE_RELATIONS CompanionControllersList;
1264  PUSBPORT_DEVICE_EXTENSION CompanionFdoExtension;
1266  ULONG ix;
1267 
1268  DPRINT("USBPORT_SynchronizeRootHubCallback: FdoDevice - %p, Usb2FdoDevice - %p\n",
1269  FdoDevice,
1270  Usb2FdoDevice);
1271 
1272  FdoExtension = FdoDevice->DeviceExtension;
1273  Packet = &FdoExtension->MiniPortInterface->Packet;
1274 
1275  if (Usb2FdoDevice == NULL &&
1276  !(Packet->MiniPortFlags & USB_MINIPORT_FLAGS_USB2))
1277  {
1278  /* Not Companion USB11 Controller */
1279  USBPORT_DoRootHubCallback(FdoDevice);
1280 
1282  InterlockedCompareExchange(&FdoExtension->RHInitCallBackLock, 0, 1);
1283 
1284  DPRINT("USBPORT_SynchronizeRootHubCallback: exit\n");
1285  return;
1286  }
1287 
1288  /* USB2 or Companion USB11 */
1289 
1290  DPRINT("USBPORT_SynchronizeRootHubCallback: FdoExtension->Flags - %p\n",
1291  FdoExtension->Flags);
1292 
1293  if (!(FdoExtension->Flags & USBPORT_FLAG_COMPANION_HC))
1294  {
1295  KeWaitForSingleObject(&FdoExtension->ControllerSemaphore,
1296  Executive,
1297  KernelMode,
1298  FALSE,
1299  NULL);
1300 
1302 
1303  if (!(FdoExtension->Flags & (USBPORT_FLAG_HC_SUSPEND |
1305  {
1308  }
1309 
1311 
1312  KeReleaseSemaphore(&FdoExtension->ControllerSemaphore,
1314  1,
1315  FALSE);
1316 
1317  CompanionControllersList = USBPORT_FindCompanionControllers(FdoDevice,
1318  FALSE,
1319  TRUE);
1320 
1321  if (CompanionControllersList)
1322  {
1323  Entry = &CompanionControllersList->Objects[0];
1324 
1325  for (ix = 0; ix < CompanionControllersList->Count; ++ix)
1326  {
1327  CompanionFdoExtension = ((*Entry)->DeviceExtension);
1328 
1329  InterlockedCompareExchange(&CompanionFdoExtension->RHInitCallBackLock,
1330  0,
1331  1);
1332 
1333  ++Entry;
1334  }
1335 
1336  ExFreePoolWithTag(CompanionControllersList, USB_PORT_TAG);
1337  }
1338 
1339  USBPORT_DoRootHubCallback(FdoDevice);
1340 
1342  InterlockedCompareExchange(&FdoExtension->RHInitCallBackLock, 0, 1);
1343  }
1344  else
1345  {
1346  Usb2FdoExtension = Usb2FdoDevice->DeviceExtension;
1347 
1348  USBPORT_Wait(FdoDevice, 50);
1349 
1350  while (FdoExtension->RHInitCallBackLock)
1351  {
1352  USBPORT_Wait(FdoDevice, 10);
1353 
1354  Usb2FdoExtension->Flags |= USBPORT_FLAG_RH_INIT_CALLBACK;
1355  USBPORT_SignalWorkerThread(Usb2FdoDevice);
1356  }
1357 
1358  USBPORT_DoRootHubCallback(FdoDevice);
1359 
1361  }
1362 
1363  DPRINT("USBPORT_SynchronizeRootHubCallback: exit\n");
1364 }
#define USBPORT_FLAG_POWER_AND_CHIRP_OK
Definition: usbport.h:83
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
struct _Entry Entry
Definition: kefuncs.h:627
#define TRUE
Definition: types.h:120
PDEVICE_OBJECT Objects[1]
Definition: iotypes.h:2163
#define InterlockedCompareExchange
Definition: interlocked.h:104
VOID NTAPI USBPORT_DoRootHubCallback(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:1222
#define LOW_REALTIME_PRIORITY
#define USBPORT_FLAG_RH_INIT_CALLBACK
Definition: usbport.h:84
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
#define USB_PORT_TAG
Definition: usbport.h:44
NTSTATUS NTAPI USBPORT_Wait(IN PVOID MiniPortExtension, IN ULONG Milliseconds)
Definition: usbport.c:543
#define FALSE
Definition: types.h:117
#define USB_MINIPORT_FLAGS_USB2
Definition: usbmport.h:534
#define USBPORT_FLAG_PWR_AND_CHIRP_LOCK
Definition: usbport.h:82
#define USBPORT_FLAG_COMPANION_HC
Definition: usbport.h:78
VOID NTAPI USBPORT_RootHubPowerAndChirpAllCcPorts(IN PDEVICE_OBJECT FdoDevice)
Definition: roothub.c:963
VOID NTAPI USBPORT_SignalWorkerThread(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:1111
PDEVICE_RELATIONS NTAPI USBPORT_FindCompanionControllers(IN PDEVICE_OBJECT USB2FdoDevice, IN BOOLEAN IsObRefer, IN BOOLEAN IsFDOsReturned)
Definition: usbport.c:136
#define USBPORT_FLAG_HC_SUSPEND
Definition: usbport.h:71
LONG NTAPI KeReleaseSemaphore(IN PKSEMAPHORE Semaphore, IN KPRIORITY Increment, IN LONG Adjustment, IN BOOLEAN Wait)
Definition: semphobj.c:54
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1
#define DPRINT
Definition: sndvol32.h:71
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
base of all file and directory entries
Definition: entries.h:82

Referenced by USBPORT_WorkerThread().

◆ USBPORT_TimerDpc()

VOID NTAPI USBPORT_TimerDpc ( IN PRKDPC  Dpc,