ReactOS 0.4.16-dev-2208-g6350669
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 2933 of file usbport.c.

2935{
2936 return STATUS_SUCCESS;
2937}
#define STATUS_SUCCESS
Definition: shellext.h:65

◆ USBPORT_AddDevice()

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

Definition at line 1868 of file usbport.c.

1870{
1872 PUSBPORT_MINIPORT_INTERFACE MiniPortInterface;
1873 ULONG DeviceNumber = 0;
1874 WCHAR CharDeviceName[64];
1878 PUSBPORT_COMMON_DEVICE_EXTENSION FdoCommonExtension;
1879 PDEVICE_OBJECT LowerDevice;
1880 ULONG Length;
1881
1882 DPRINT("USBPORT_AddDevice: DriverObject - %p, PhysicalDeviceObject - %p\n",
1885
1886 MiniPortInterface = USBPORT_FindMiniPort(DriverObject);
1887
1888 if (!MiniPortInterface)
1889 {
1890 DPRINT("USBPORT_AddDevice: USBPORT_FindMiniPort not found MiniPortInterface\n");
1891 return STATUS_UNSUCCESSFUL;
1892 }
1893
1894 while (TRUE)
1895 {
1896 /* Construct device name */
1897 RtlStringCbPrintfW(CharDeviceName,
1898 sizeof(CharDeviceName),
1899 L"\\Device\\USBFDO-%d",
1900 DeviceNumber);
1901
1902 RtlInitUnicodeString(&DeviceName, CharDeviceName);
1903
1904 ASSERT(MiniPortInterface->Packet.MiniPortExtensionSize <=
1907 MiniPortInterface->Packet.MiniPortExtensionSize +
1908 sizeof(USB2_HC_EXTENSION));
1909
1910 /* Create device */
1912 Length,
1913 &DeviceName,
1915 0,
1916 FALSE,
1917 &DeviceObject);
1918
1919 /* Check for success */
1920 if (NT_SUCCESS(Status)) break;
1921
1922 /* Is there a device object with that same name */
1925 {
1926 /* Try the next name */
1927 DeviceNumber++;
1928 continue;
1929 }
1930
1931 /* Bail out on other errors */
1932 if (!NT_SUCCESS(Status))
1933 {
1934 DPRINT1("USBPORT_AddDevice: failed to create %wZ, Status %x\n",
1935 &DeviceName,
1936 Status);
1937
1938 return Status;
1939 }
1940 }
1941
1942 DPRINT("USBPORT_AddDevice: created device %p <%wZ>, Status %x\n",
1944 &DeviceName,
1945 Status);
1946
1947 FdoExtension = DeviceObject->DeviceExtension;
1948 FdoCommonExtension = &FdoExtension->CommonExtension;
1949
1951
1952 FdoCommonExtension->SelfDevice = DeviceObject;
1953 FdoCommonExtension->LowerPdoDevice = PhysicalDeviceObject;
1954 FdoCommonExtension->IsPDO = FALSE;
1955
1958
1959 FdoCommonExtension->LowerDevice = LowerDevice;
1960
1961 FdoCommonExtension->DevicePowerState = PowerDeviceD3;
1962
1963 FdoExtension->MiniPortExt = (PVOID)((ULONG_PTR)FdoExtension +
1964 sizeof(USBPORT_DEVICE_EXTENSION));
1965
1966 if (MiniPortInterface->Packet.MiniPortFlags & USB_MINIPORT_FLAGS_USB2)
1967 {
1968 FdoExtension->Usb2Extension =
1969 (PUSB2_HC_EXTENSION)((ULONG_PTR)FdoExtension->MiniPortExt +
1970 MiniPortInterface->Packet.MiniPortExtensionSize);
1971
1972 DPRINT("USBPORT_AddDevice: Usb2Extension - %p\n",
1973 FdoExtension->Usb2Extension);
1974
1975 USB2_InitController(FdoExtension->Usb2Extension);
1976 }
1977 else
1978 {
1979 FdoExtension->Usb2Extension = NULL;
1980 }
1981
1982 FdoExtension->MiniPortInterface = MiniPortInterface;
1983 FdoExtension->FdoNameNumber = DeviceNumber;
1984
1985 KeInitializeSemaphore(&FdoExtension->DeviceSemaphore, 1, 1);
1986 KeInitializeSemaphore(&FdoExtension->ControllerSemaphore, 1, 1);
1987
1988 InitializeListHead(&FdoExtension->EndpointList);
1989 InitializeListHead(&FdoExtension->DoneTransferList);
1990 InitializeListHead(&FdoExtension->WorkerList);
1991 InitializeListHead(&FdoExtension->EpStateChangeList);
1992 InitializeListHead(&FdoExtension->MapTransferList);
1993 InitializeListHead(&FdoExtension->DeviceHandleList);
1994 InitializeListHead(&FdoExtension->IdleIrpList);
1995 InitializeListHead(&FdoExtension->BadRequestList);
1996 InitializeListHead(&FdoExtension->EndpointClosedList);
1997
1998 DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
1999
2000 return Status;
2001}
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1157
_In_ PCHAR _In_ ULONG DeviceNumber
Definition: classpnp.h:1230
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define L(x)
Definition: resources.c:13
@ FdoExtension
Definition: precomp.h:48
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
Status
Definition: gdiplustypes.h:25
#define ASSERT(a)
Definition: mode.c:44
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:966
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
@ PowerDeviceD3
Definition: ntpoapi.h:52
#define STATUS_OBJECT_NAME_EXISTS
Definition: ntstatus.h:189
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 FILE_DEVICE_CONTROLLER
Definition: winioctl.h:49
VOID NTAPI KeInitializeSemaphore(IN PKSEMAPHORE Semaphore, IN LONG Count, IN LONG Limit)
Definition: semphobj.c:22
#define DPRINT
Definition: sndvol32.h:73
DEVICE_POWER_STATE DevicePowerState
Definition: usbport.h:287
PDEVICE_OBJECT LowerPdoDevice
Definition: usbport.h:282
USBPORT_REGISTRATION_PACKET Packet
Definition: usbmport.h:644
#define MAXULONG
Definition: typedefs.h:251
void * PVOID
Definition: typedefs.h:50
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_OBJECT_NAME_COLLISION
Definition: udferr_usr.h:150
VOID NTAPI USB2_InitController(IN PUSB2_HC_EXTENSION HcExtension)
Definition: usb2.c:2217
#define USB_MINIPORT_FLAGS_USB2
Definition: usbmport.h:534
PUSBPORT_MINIPORT_INTERFACE NTAPI USBPORT_FindMiniPort(IN PDRIVER_OBJECT DriverObject)
Definition: usbport.c:1828
struct _USBPORT_DEVICE_EXTENSION USBPORT_DEVICE_EXTENSION
struct _USB2_HC_EXTENSION * PUSB2_HC_EXTENSION
Definition: usbport.h:157
struct _USB2_HC_EXTENSION USB2_HC_EXTENSION
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2061
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3281
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
__wchar_t WCHAR
Definition: xmlstorage.h:180

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}
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
KSPIN_LOCK USBPORT_SpinLock
Definition: usbport.c:22
LIST_ENTRY USBPORT_USB1FdoList
Definition: usbport.c:19
#define USBPORT_FLAG_REGISTERED_FDO
Definition: usbport.h:79

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

Referenced by USBPORT_FdoPnP().

◆ USBPORT_AllocateCommonBuffer()

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

Definition at line 1743 of file usbport.c.

1745{
1746 PUSBPORT_COMMON_BUFFER_HEADER HeaderBuffer = NULL;
1748 PDMA_ADAPTER DmaAdapter;
1749 PDMA_OPERATIONS DmaOperations;
1750 SIZE_T HeaderSize;
1751 ULONG Length = 0;
1752 ULONG LengthPadded;
1753 PHYSICAL_ADDRESS LogicalAddress;
1754 ULONG_PTR BaseVA;
1755 ULONG_PTR StartBufferVA;
1756 ULONG StartBufferPA;
1757
1758 DPRINT("USBPORT_AllocateCommonBuffer: FdoDevice - %p, BufferLength - %p\n",
1759 FdoDevice,
1760 BufferLength);
1761
1762 if (BufferLength == 0)
1763 goto Exit;
1764
1765 FdoExtension = FdoDevice->DeviceExtension;
1766
1767 DmaAdapter = FdoExtension->DmaAdapter;
1768 DmaOperations = DmaAdapter->DmaOperations;
1769
1770 HeaderSize = sizeof(USBPORT_COMMON_BUFFER_HEADER);
1771 Length = ROUND_TO_PAGES(BufferLength + HeaderSize);
1772 LengthPadded = Length - (BufferLength + HeaderSize);
1773
1774 BaseVA = (ULONG_PTR)DmaOperations->AllocateCommonBuffer(DmaAdapter,
1775 Length,
1776 &LogicalAddress,
1777 TRUE);
1778
1779 if (!BaseVA)
1780 goto Exit;
1781
1782 StartBufferVA = BaseVA & ~(PAGE_SIZE - 1);
1783 StartBufferPA = LogicalAddress.LowPart & ~(PAGE_SIZE - 1);
1784
1785 HeaderBuffer = (PUSBPORT_COMMON_BUFFER_HEADER)(StartBufferVA +
1786 BufferLength +
1787 LengthPadded);
1788
1789 HeaderBuffer->Length = Length;
1790 HeaderBuffer->BaseVA = BaseVA;
1791 HeaderBuffer->LogicalAddress = LogicalAddress;
1792
1793 HeaderBuffer->BufferLength = BufferLength + LengthPadded;
1794 HeaderBuffer->VirtualAddress = StartBufferVA;
1795 HeaderBuffer->PhysicalAddress = StartBufferPA;
1796
1797 RtlZeroMemory((PVOID)StartBufferVA, BufferLength + LengthPadded);
1798
1799Exit:
1800 return HeaderBuffer;
1801}
#define ULONG_PTR
Definition: config.h:101
#define PAGE_SIZE
Definition: env_spec_w32.h:49
static void Exit(void)
Definition: sock.c:1330
struct _DMA_OPERATIONS * DmaOperations
Definition: iotypes.h:2297
PALLOCATE_COMMON_BUFFER AllocateCommonBuffer
Definition: iotypes.h:2637
PHYSICAL_ADDRESS LogicalAddress
Definition: usbport.h:149
ULONG_PTR SIZE_T
Definition: typedefs.h:80
ULONG LowPart
Definition: typedefs.h:106
struct _USBPORT_COMMON_BUFFER_HEADER * PUSBPORT_COMMON_BUFFER_HEADER
struct _USBPORT_COMMON_BUFFER_HEADER USBPORT_COMMON_BUFFER_HEADER
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3777
#define ROUND_TO_PAGES(Size)

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 2578 of file usbport.c.

2583{
2585 SIZE_T TransferLength;
2586 PMDL Mdl;
2587 ULONG_PTR VirtualAddr;
2588 ULONG PagesNeed = 0;
2589 SIZE_T PortTransferLength;
2590 SIZE_T FullTransferLength;
2591 PUSBPORT_TRANSFER Transfer;
2592 PUSBPORT_PIPE_HANDLE PipeHandle;
2593 USBD_STATUS USBDStatus;
2594 SIZE_T IsoBlockLen = 0;
2595
2596 DPRINT_CORE("USBPORT_AllocateTransfer: FdoDevice - %p, Urb - %p, DeviceHandle - %p, Irp - %p, Event - %p\n",
2597 FdoDevice,
2598 Urb,
2600 Irp,
2601 Event);
2602
2603 FdoExtension = FdoDevice->DeviceExtension;
2604
2605 TransferLength = Urb->UrbControlTransfer.TransferBufferLength;
2606 PipeHandle = Urb->UrbControlTransfer.PipeHandle;
2607
2608 if (TransferLength)
2609 {
2610 Mdl = Urb->UrbControlTransfer.TransferBufferMDL;
2611 VirtualAddr = (ULONG_PTR)MmGetMdlVirtualAddress(Mdl);
2612
2613 PagesNeed = ADDRESS_AND_SIZE_TO_SPAN_PAGES(VirtualAddr,
2614 TransferLength);
2615 if (PagesNeed > 0)
2616 {
2617 PagesNeed--;
2618 }
2619 }
2620
2621 if (Urb->UrbHeader.Function == URB_FUNCTION_ISOCH_TRANSFER)
2622 {
2623 DPRINT1("USBPORT_AllocateTransfer: ISOCH_TRANSFER UNIMPLEMENTED. FIXME\n");
2624
2625 //IsoBlockLen = sizeof(USBPORT_ISO_BLOCK) +
2626 // Urb->UrbIsochronousTransfer.NumberOfPackets *
2627 // sizeof(USBPORT_ISO_BLOCK_PACKET);
2628 }
2629
2630 PortTransferLength = sizeof(USBPORT_TRANSFER) +
2631 PagesNeed * sizeof(USBPORT_SCATTER_GATHER_ELEMENT) +
2632 IsoBlockLen;
2633
2634 FullTransferLength = PortTransferLength +
2635 FdoExtension->MiniPortInterface->Packet.MiniPortTransferSize;
2636
2638 FullTransferLength,
2639 USB_PORT_TAG);
2640
2641 if (!Transfer)
2642 {
2643 DPRINT1("USBPORT_AllocateTransfer: Transfer not allocated!\n");
2645 }
2646
2647 RtlZeroMemory(Transfer, FullTransferLength);
2648
2649 Transfer->Irp = Irp;
2650 Transfer->Urb = Urb;
2651 Transfer->Endpoint = PipeHandle->Endpoint;
2652 Transfer->Event = Event;
2653 Transfer->PortTransferLength = PortTransferLength;
2654 Transfer->FullTransferLength = FullTransferLength;
2655 Transfer->IsoBlockPtr = NULL;
2656 Transfer->Period = 0;
2657 Transfer->ParentTransfer = Transfer;
2658
2659 if (IsoBlockLen)
2660 {
2661 Transfer->IsoBlockPtr = (PVOID)((ULONG_PTR)Transfer +
2662 PortTransferLength - IsoBlockLen);
2663
2664 Transfer->Period = PipeHandle->Endpoint->EndpointProperties.Period;
2665 Transfer->Flags |= TRANSFER_FLAG_ISO;
2666 }
2667
2668 Transfer->MiniportTransfer = (PVOID)((ULONG_PTR)Transfer +
2669 PortTransferLength);
2670
2672
2673 Urb->UrbControlTransfer.hca.Reserved8[0] = Transfer;
2674 Urb->UrbHeader.UsbdFlags |= USBD_FLAG_ALLOCATED_TRANSFER;
2675
2676 USBDStatus = USBD_STATUS_SUCCESS;
2677
2678 DPRINT_CORE("USBPORT_AllocateTransfer: return USBDStatus - %x\n",
2679 USBDStatus);
2680
2681 return USBDStatus;
2682}
_In_ PIRP Irp
Definition: csq.h:116
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define NonPagedPool
Definition: env_spec_w32.h:307
#define KeInitializeSpinLock(sl)
Definition: env_spec_w32.h:604
_Inout_ PUSB_DEVICE_HANDLE DeviceHandle
Definition: hubbusif.h:121
USBPORT_ENDPOINT_PROPERTIES EndpointProperties
Definition: usbport.h:211
PUSBPORT_ENDPOINT Endpoint
Definition: usbport.h:167
SIZE_T PortTransferLength
Definition: usbport.h:251
PUSBPORT_ISO_BLOCK IsoBlockPtr
Definition: usbport.h:269
PRKEVENT Event
Definition: usbport.h:249
KSPIN_LOCK TransferSpinLock
Definition: usbport.h:265
struct _USBPORT_TRANSFER * ParentTransfer
Definition: usbport.h:264
PVOID MiniportTransfer
Definition: usbport.h:250
PUSBPORT_ENDPOINT Endpoint
Definition: usbport.h:253
SIZE_T FullTransferLength
Definition: usbport.h:252
#define USBD_STATUS_SUCCESS
Definition: usb.h:170
#define USBD_STATUS_INSUFFICIENT_RESOURCES
Definition: usb.h:204
LONG USBD_STATUS
Definition: usb.h:165
#define URB_FUNCTION_ISOCH_TRANSFER
Definition: usb.h:96
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
_In_ PIO_STACK_LOCATION _In_ PURB Urb
Definition: usbdlib.h:267
#define USB_PORT_TAG
Definition: usbport.h:44
struct _USBPORT_TRANSFER USBPORT_TRANSFER
#define USBD_FLAG_ALLOCATED_TRANSFER
Definition: usbport.h:123
#define TRANSFER_FLAG_ISO
Definition: usbport.h:135
_In_ WDFDEVICE _In_ PVOID _In_opt_ PMDL Mdl
#define MmGetMdlVirtualAddress(_Mdl)
#define ADDRESS_AND_SIZE_TO_SPAN_PAGES(_Va, _Size)

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 2091 of file usbport.c.

2095{
2096 PDEVICE_OBJECT FdoDevice;
2098 PUSBPORT_ASYNC_CALLBACK_DATA AsyncCallbackData;
2099
2100 DPRINT("USBPORT_AsyncTimerDpc: ...\n");
2101
2102 AsyncCallbackData = DeferredContext;
2103 FdoDevice = AsyncCallbackData->FdoDevice;
2104 FdoExtension = FdoDevice->DeviceExtension;
2105
2106 (*AsyncCallbackData->CallbackFunction)(FdoExtension->MiniPortExt,
2107 &AsyncCallbackData->CallbackContext);
2108
2109 ExFreePoolWithTag(AsyncCallbackData, USB_PORT_TAG);
2110}
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
PVOID DeviceExtension
Definition: env_spec_w32.h:418
PDEVICE_OBJECT FdoDevice
Definition: usbport.h:434
ASYNC_TIMER_CALLBACK * CallbackFunction
Definition: usbport.h:437
_In_opt_ PVOID DeferredContext
Definition: ketypes.h:739

Referenced by USBPORT_RequestAsyncCallback().

◆ USBPORT_CompleteTransfer()

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

Definition at line 2233 of file usbport.c.

2235{
2236 struct _URB_CONTROL_TRANSFER *UrbTransfer;
2237 PUSBPORT_TRANSFER Transfer;
2239 PIRP Irp;
2240 KIRQL OldIrql;
2243 BOOLEAN IsFlushSuccess;
2244 PMDL Mdl;
2245 ULONG_PTR CurrentVa;
2246 SIZE_T TransferLength;
2247 PUSBPORT_ENDPOINT Endpoint;
2248 PDEVICE_OBJECT FdoDevice;
2250 PDMA_OPERATIONS DmaOperations;
2251
2252 DPRINT("USBPORT_CompleteTransfer: Urb - %p, TransferStatus - %X\n",
2253 Urb,
2254 TransferStatus);
2255
2256 UrbTransfer = &Urb->UrbControlTransfer;
2257 Transfer = UrbTransfer->hca.Reserved8[0];
2258
2259 Transfer->USBDStatus = TransferStatus;
2260 Status = USBPORT_USBDStatusToNtStatus(Urb, TransferStatus);
2261
2262 UrbTransfer->TransferBufferLength = Transfer->CompletedTransferLen;
2263
2264 if (Transfer->Flags & TRANSFER_FLAG_DMA_MAPPED)
2265 {
2266 Endpoint = Transfer->Endpoint;
2267 FdoDevice = Endpoint->FdoDevice;
2268 FdoExtension = FdoDevice->DeviceExtension;
2269 DmaOperations = FdoExtension->DmaAdapter->DmaOperations;
2270
2272 Mdl = UrbTransfer->TransferBufferMDL;
2273 CurrentVa = (ULONG_PTR)MmGetMdlVirtualAddress(Mdl);
2274 TransferLength = UrbTransfer->TransferBufferLength;
2275
2276 IsFlushSuccess = DmaOperations->FlushAdapterBuffers(FdoExtension->DmaAdapter,
2277 Mdl,
2278 Transfer->MapRegisterBase,
2279 (PVOID)CurrentVa,
2280 TransferLength,
2282
2283 if (!IsFlushSuccess)
2284 {
2285 DPRINT("USBPORT_CompleteTransfer: no FlushAdapterBuffers !!!\n");
2286 ASSERT(FALSE);
2287 }
2288
2290
2291 DmaOperations->FreeMapRegisters(FdoExtension->DmaAdapter,
2292 Transfer->MapRegisterBase,
2293 Transfer->NumberOfMapRegisters);
2294
2296 }
2297
2298 if (Urb->UrbHeader.UsbdFlags & USBD_FLAG_ALLOCATED_MDL)
2299 {
2300 IoFreeMdl(Transfer->TransferBufferMDL);
2301 Urb->UrbHeader.UsbdFlags |= ~USBD_FLAG_ALLOCATED_MDL;
2302 }
2303
2304 Urb->UrbControlTransfer.hca.Reserved8[0] = NULL;
2305 Urb->UrbHeader.UsbdFlags |= ~USBD_FLAG_ALLOCATED_TRANSFER;
2306
2307 Irp = Transfer->Irp;
2308
2309 if (Irp)
2310 {
2311 if (!NT_SUCCESS(Status))
2312 {
2313 //DbgBreakPoint();
2314 DPRINT1("USBPORT_CompleteTransfer: Irp - %p complete with Status - %lx\n",
2315 Irp,
2316 Status);
2317
2319 }
2320
2321 Irp->IoStatus.Status = Status;
2322 Irp->IoStatus.Information = 0;
2323
2327 }
2328
2329 Event = Transfer->Event;
2330
2331 if (Event)
2332 {
2334 }
2335
2337
2338 DPRINT_CORE("USBPORT_CompleteTransfer: exit\n");
2339}
unsigned char BOOLEAN
_In_ PSCSI_REQUEST_BLOCK _In_opt_ PVOID _In_ ULONG _In_ BOOLEAN WriteToDevice
Definition: cdrom.h:992
VOID NTAPI USBPORT_DumpingURB(IN PURB Urb)
Definition: debug.c:224
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
#define IoFreeMdl
Definition: fxmdl.h:89
#define IoCompleteRequest
Definition: irp.c:1240
PFLUSH_ADAPTER_BUFFERS FlushAdapterBuffers
Definition: iotypes.h:2640
PFREE_MAP_REGISTERS FreeMapRegisters
Definition: iotypes.h:2642
PMDL TransferBufferMDL
Definition: usb.h:472
struct _URB_HCD_AREA hca
Definition: usb.h:474
ULONG TransferBufferLength
Definition: usb.h:470
PDEVICE_OBJECT FdoDevice
Definition: usbport.h:206
ULONG CompletedTransferLen
Definition: usbport.h:259
PMDL TransferBufferMDL
Definition: usbport.h:255
ULONG NumberOfMapRegisters
Definition: usbport.h:260
USBD_STATUS USBDStatus
Definition: usbport.h:258
PVOID MapRegisterBase
Definition: usbport.h:261
NTSTATUS NTAPI USBPORT_USBDStatusToNtStatus(IN PURB Urb, IN USBD_STATUS USBDStatus)
Definition: usbport.c:485
#define TRANSFER_FLAG_DMA_MAPPED
Definition: usbport.h:131
#define USBPORT_DMA_DIRECTION_TO_DEVICE
Definition: usbport.h:42
#define USBD_FLAG_ALLOCATED_MDL
Definition: usbport.h:121
#define EVENT_INCREMENT
Definition: iotypes.h:597
#define IO_NO_INCREMENT
Definition: iotypes.h:598
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778

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 1462 of file usbport.c.

1463{
1466
1467 DPRINT("USBPORT_CreateWorkerThread ...\n");
1468
1469 FdoExtension = FdoDevice->DeviceExtension;
1470
1471 FdoExtension->Flags &= ~USBPORT_FLAG_WORKER_THREAD_ON;
1472
1473 KeInitializeEvent(&FdoExtension->WorkerThreadEvent,
1475 FALSE);
1476
1477 Status = PsCreateSystemThread(&FdoExtension->WorkerThreadHandle,
1479 NULL,
1480 NULL,
1481 NULL,
1483 (PVOID)FdoDevice);
1484
1485 return Status;
1486}
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define THREAD_ALL_ACCESS
Definition: nt_native.h:1342
@ NotificationEvent
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
VOID NTAPI USBPORT_WorkerThread(IN PVOID StartContext)
Definition: usbport.c:1403

Referenced by USBPORT_StartDevice().

◆ USBPORT_Dispatch()

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

Definition at line 2686 of file usbport.c.

2688{
2689 PUSBPORT_COMMON_DEVICE_EXTENSION DeviceExtension;
2690 PIO_STACK_LOCATION IoStack;
2692
2693 DeviceExtension = DeviceObject->DeviceExtension;
2695
2696 if (DeviceExtension->PnpStateFlags & USBPORT_PNP_STATE_FAILED)
2697 {
2698 DPRINT1("USBPORT_Dispatch: USBPORT_PNP_STATE_FAILED\n");
2699 DbgBreakPoint();
2700 }
2701
2702 switch (IoStack->MajorFunction)
2703 {
2705 if (DeviceExtension->IsPDO)
2706 {
2707 DPRINT("USBPORT_Dispatch: PDO IRP_MJ_DEVICE_CONTROL. Major - %d, Minor - %d\n",
2708 IoStack->MajorFunction,
2709 IoStack->MinorFunction);
2710
2712 }
2713 else
2714 {
2715 DPRINT("USBPORT_Dispatch: FDO IRP_MJ_DEVICE_CONTROL. Major - %d, Minor - %d\n",
2716 IoStack->MajorFunction,
2717 IoStack->MinorFunction);
2718
2720 }
2721
2722 break;
2723
2725 if (DeviceExtension->IsPDO)
2726 {
2727 DPRINT("USBPORT_Dispatch: PDO IRP_MJ_INTERNAL_DEVICE_CONTROL. Major - %d, Minor - %d\n",
2728 IoStack->MajorFunction,
2729 IoStack->MinorFunction);
2730
2732 }
2733 else
2734 {
2735 DPRINT("USBPORT_Dispatch: FDO IRP_MJ_INTERNAL_DEVICE_CONTROL. Major - %d, Minor - %d\n",
2736 IoStack->MajorFunction,
2737 IoStack->MinorFunction);
2738
2740 }
2741
2742 break;
2743
2744 case IRP_MJ_POWER:
2745 if (DeviceExtension->IsPDO)
2746 {
2747 DPRINT("USBPORT_Dispatch: PDO IRP_MJ_POWER. Major - %d, Minor - %d\n",
2748 IoStack->MajorFunction,
2749 IoStack->MinorFunction);
2750
2752 }
2753 else
2754 {
2755 DPRINT("USBPORT_Dispatch: FDO IRP_MJ_POWER. Major - %d, Minor - %d\n",
2756 IoStack->MajorFunction,
2757 IoStack->MinorFunction);
2758
2760 }
2761
2762 break;
2763
2765 if (DeviceExtension->IsPDO)
2766 {
2767 DPRINT("USBPORT_Dispatch: PDO IRP_MJ_SYSTEM_CONTROL. Major - %d, Minor - %d\n",
2768 IoStack->MajorFunction,
2769 IoStack->MinorFunction);
2770
2771 Status = Irp->IoStatus.Status;
2773 }
2774 else
2775 {
2776 DPRINT("USBPORT_Dispatch: FDO IRP_MJ_SYSTEM_CONTROL. Major - %d, Minor - %d\n",
2777 IoStack->MajorFunction,
2778 IoStack->MinorFunction);
2779
2781 Status = IoCallDriver(DeviceExtension->LowerDevice, Irp);
2782 }
2783
2784 break;
2785
2786 case IRP_MJ_PNP:
2787 if (DeviceExtension->IsPDO)
2788 {
2789 DPRINT("USBPORT_Dispatch: PDO IRP_MJ_PNP. Major - %d, Minor - %d\n",
2790 IoStack->MajorFunction,
2791 IoStack->MinorFunction);
2792
2794 }
2795 else
2796 {
2797 DPRINT("USBPORT_Dispatch: FDO IRP_MJ_PNP. Major - %d, Minor - %d\n",
2798 IoStack->MajorFunction,
2799 IoStack->MinorFunction);
2800
2802 }
2803
2804 break;
2805
2806 case IRP_MJ_CREATE:
2807 case IRP_MJ_CLOSE:
2808 DPRINT("USBPORT_Dispatch: IRP_MJ_CREATE | IRP_MJ_CLOSE\n");
2809 Irp->IoStatus.Status = Status;
2811 break;
2812
2813 default:
2814 if (DeviceExtension->IsPDO)
2815 {
2816 DPRINT("USBPORT_Dispatch: PDO unhandled IRP_MJ_???. Major - %d, Minor - %d\n",
2817 IoStack->MajorFunction,
2818 IoStack->MinorFunction);
2819 }
2820 else
2821 {
2822 DPRINT("USBPORT_Dispatch: FDO unhandled IRP_MJ_???. Major - %d, Minor - %d\n",
2823 IoStack->MajorFunction,
2824 IoStack->MinorFunction);
2825 }
2826
2828 Irp->IoStatus.Status = Status;
2830 break;
2831 }
2832
2833 DPRINT("USBPORT_Dispatch: Status - %x\n", Status);
2834 return Status;
2835}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
NTSTATUS NTAPI USBPORT_FdoInternalDeviceControl(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp)
Definition: ioctl.c:454
NTSTATUS NTAPI USBPORT_FdoDeviceControl(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp)
Definition: ioctl.c:396
NTSTATUS NTAPI USBPORT_PdoInternalDeviceControl(IN PDEVICE_OBJECT PdoDevice, IN PIRP Irp)
Definition: ioctl.c:317
NTSTATUS NTAPI USBPORT_PdoDeviceControl(IN PDEVICE_OBJECT PdoDevice, IN PIRP Irp)
Definition: ioctl.c:308
NTSTATUS NTAPI USBPORT_PdoPnP(IN PDEVICE_OBJECT PdoDevice, IN PIRP Irp)
Definition: pnp.c:1517
NTSTATUS NTAPI USBPORT_FdoPnP(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp)
Definition: pnp.c:1110
NTSTATUS NTAPI USBPORT_FdoPower(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp)
Definition: power.c:489
NTSTATUS NTAPI USBPORT_PdoPower(IN PDEVICE_OBJECT PdoDevice, IN PIRP Irp)
Definition: power.c:322
NTSYSAPI void WINAPI DbgBreakPoint(void)
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define IoCallDriver
Definition: irp.c:1225
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define USBPORT_PNP_STATE_FAILED
Definition: usbport.h:89
#define IRP_MJ_SYSTEM_CONTROL
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
#define IRP_MJ_POWER

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;
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}
PIRP NTAPI USBPORT_RemoveActiveTransferIrp(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp)
Definition: queue.c:357
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
IoSetCancelRoutine(Irp, CancelRoutine)
VOID NTAPI IoReleaseCancelSpinLock(IN KIRQL Irql)
Definition: util.c:150
VOID NTAPI IoAcquireCancelSpinLock(OUT PKIRQL Irql)
Definition: util.c:56
Definition: usb.h:529
VOID NTAPI USBPORT_CompleteTransfer(IN PURB Urb, IN USBD_STATUS TransferStatus)
Definition: usbport.c:2233

Referenced by USBPORT_DoneSplitTransfer(), and USBPORT_FlushDoneTransfers().

◆ USBPORT_DoRootHubCallback()

VOID NTAPI USBPORT_DoRootHubCallback ( IN PDEVICE_OBJECT  FdoDevice)

Definition at line 1257 of file usbport.c.

1258{
1260 PDEVICE_OBJECT PdoDevice;
1262 PRH_INIT_CALLBACK RootHubInitCallback;
1263 PVOID RootHubInitContext;
1264
1265 FdoExtension = FdoDevice->DeviceExtension;
1266
1267 DPRINT("USBPORT_DoRootHubCallback: FdoDevice - %p\n", FdoDevice);
1268
1269 PdoDevice = FdoExtension->RootHubPdo;
1270
1271 if (PdoDevice)
1272 {
1273 PdoExtension = PdoDevice->DeviceExtension;
1274
1275 RootHubInitContext = PdoExtension->RootHubInitContext;
1276 RootHubInitCallback = PdoExtension->RootHubInitCallback;
1277
1278 PdoExtension->RootHubInitCallback = NULL;
1279 PdoExtension->RootHubInitContext = NULL;
1280
1281 if (RootHubInitCallback)
1282 {
1283 RootHubInitCallback(RootHubInitContext);
1284 }
1285 }
1286
1287 DPRINT("USBPORT_DoRootHubCallback: exit\n");
1288}
@ PdoExtension
Definition: precomp.h:49
RH_INIT_CALLBACK * PRH_INIT_CALLBACK
Definition: hubbusif.h:270

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 ||
892 {
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 {
932 }
933
934 KeReleaseSpinLockFromDpcLevel(&FdoExtension->EndpointListSpinLock);
935
937}
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
VOID NTAPI USBPORT_FlushPendingTransfers(IN PUSBPORT_ENDPOINT Endpoint)
Definition: queue.c:785
BOOLEAN NTAPI USBPORT_EndpointWorker(IN PUSBPORT_ENDPOINT Endpoint, IN BOOLEAN LockNotChecked)
Definition: endpoint.c:1685
ULONG NTAPI USBPORT_GetEndpointState(IN PUSBPORT_ENDPOINT Endpoint)
Definition: endpoint.c:332
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define InsertTailList(ListHead, Entry)
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
long LONG
Definition: pedump.c:60
#define KeAcquireSpinLockAtDpcLevel(SpinLock)
Definition: ke.h:125
#define KeReleaseSpinLockFromDpcLevel(SpinLock)
Definition: ke.h:135
base of all file and directory entries
Definition: entries.h:83
Definition: typedefs.h:120
struct _LIST_ENTRY * Blink
Definition: typedefs.h:122
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
LIST_ENTRY EndpointLink
Definition: usbport.h:232
LIST_ENTRY DispatchLink
Definition: usbport.h:235
LIST_ENTRY WorkerLink
Definition: usbport.h:233
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
#define USBPORT_ENDPOINT_ACTIVE
Definition: usbmport.h:15
VOID NTAPI USBPORT_FlushDoneTransfers(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:764
VOID NTAPI USBPORT_SignalWorkerThread(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:1146
#define ENDPOINT_FLAG_ROOTHUB_EP0
Definition: usbport.h:112
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550

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;
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),
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
223Exit:
224
226
227 return ControllersList;
228}
PDEVICE_OBJECT Objects[1]
Definition: iotypes.h:2165
USBPORT_COMMON_DEVICE_EXTENSION CommonExtension
Definition: usbport.h:292
LIST_ENTRY ControllerLink
Definition: usbport.h:302
BOOLEAN NTAPI USBPORT_IsCompanionFdoExtension(IN PDEVICE_OBJECT USB2FdoDevice, IN PUSBPORT_DEVICE_EXTENSION USB1FdoExtension)
Definition: usbport.c:119
#define USBPORT_FLAG_COMPANION_HC
Definition: usbport.h:78
#define ObReferenceObject
Definition: obfuncs.h:204

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 1828 of file usbport.c.

1829{
1830 KIRQL OldIrql;
1832 PUSBPORT_MINIPORT_INTERFACE MiniPortInterface;
1833 BOOLEAN IsFound = FALSE;
1834
1835 DPRINT("USBPORT_FindMiniPort: ...\n");
1836
1838
1841 List = List->Flink)
1842 {
1843 MiniPortInterface = CONTAINING_RECORD(List,
1845 DriverLink);
1846
1847 if (MiniPortInterface->DriverObject == DriverObject)
1848 {
1849 DPRINT("USBPORT_FindMiniPort: find MiniPortInterface - %p\n",
1850 MiniPortInterface);
1851
1852 IsFound = TRUE;
1853 break;
1854 }
1855 }
1856
1858
1859 if (IsFound)
1860 return MiniPortInterface;
1861 else
1862 return NULL;
1863
1864}
PDRIVER_OBJECT DriverObject
Definition: usbmport.h:640
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;
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}

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;
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 {
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}
VOID NTAPI USBPORT_InvalidateEndpointHandler(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint, IN ULONG Type)
Definition: endpoint.c:1346
BOOLEAN NTAPI USBPORT_EndpointHasQueuedTransfers(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint, IN PULONG TransferCount)
Definition: endpoint.c:254
#define RemoveHeadList(ListHead)
Definition: env_spec_w32.h:964
VOID NTAPI USBPORT_DoneSplitTransfer(IN PUSBPORT_TRANSFER SplitTransfer)
Definition: trfsplit.c:278
VOID NTAPI USBPORT_DoneTransfer(IN PUSBPORT_TRANSFER Transfer)
Definition: usbport.c:724
#define TRANSFER_FLAG_SPLITED
Definition: usbport.h:137
#define INVALIDATE_ENDPOINT_WORKER_DPC
Definition: usbport.h:38

Referenced by USBPORT_DpcHandler(), and USBPORT_TransferFlushDpc().

◆ USBPORT_FlushMapTransfers()

VOID NTAPI USBPORT_FlushMapTransfers ( IN PDEVICE_OBJECT  FdoDevice)

Definition at line 2518 of file usbport.c.

2519{
2521 PLIST_ENTRY MapTransferList;
2522 PUSBPORT_TRANSFER Transfer;
2523 ULONG NumMapRegisters;
2524 PMDL Mdl;
2525 SIZE_T TransferBufferLength;
2526 ULONG_PTR VirtualAddr;
2527 KIRQL OldIrql;
2529 PDMA_OPERATIONS DmaOperations;
2530
2531 DPRINT_CORE("USBPORT_FlushMapTransfers: ...\n");
2532
2533 FdoExtension = FdoDevice->DeviceExtension;
2534 DmaOperations = FdoExtension->DmaAdapter->DmaOperations;
2535
2537
2538 while (TRUE)
2539 {
2540 MapTransferList = &FdoExtension->MapTransferList;
2541
2542 if (IsListEmpty(&FdoExtension->MapTransferList))
2543 {
2545 return;
2546 }
2547
2548 Transfer = CONTAINING_RECORD(MapTransferList->Flink,
2550 TransferLink);
2551
2552 RemoveHeadList(MapTransferList);
2553
2554 Mdl = Transfer->Urb->UrbControlTransfer.TransferBufferMDL;
2555 TransferBufferLength = Transfer->TransferParameters.TransferBufferLength;
2556 VirtualAddr = (ULONG_PTR)MmGetMdlVirtualAddress(Mdl);
2557
2558 NumMapRegisters = ADDRESS_AND_SIZE_TO_SPAN_PAGES(VirtualAddr,
2559 TransferBufferLength);
2560
2561 Transfer->NumberOfMapRegisters = NumMapRegisters;
2562
2563 Status = DmaOperations->AllocateAdapterChannel(FdoExtension->DmaAdapter,
2564 FdoDevice,
2565 NumMapRegisters,
2567 Transfer);
2568
2569 if (!NT_SUCCESS(Status))
2570 ASSERT(FALSE);
2571 }
2572
2574}
PALLOCATE_ADAPTER_CHANNEL AllocateAdapterChannel
Definition: iotypes.h:2639
struct _URB_CONTROL_TRANSFER UrbControlTransfer
Definition: usb.h:539
USBPORT_TRANSFER_PARAMETERS TransferParameters
Definition: usbport.h:254
IO_ALLOCATION_ACTION NTAPI USBPORT_MapTransfer(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp, IN PVOID MapRegisterBase, IN PVOID Context)
Definition: usbport.c:2343

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 1805 of file usbport.c.

1807{
1809 PDMA_ADAPTER DmaAdapter;
1810 PDMA_OPERATIONS DmaOperations;
1811
1812 DPRINT("USBPORT_FreeCommonBuffer: ...\n");
1813
1814 FdoExtension = FdoDevice->DeviceExtension;
1815
1816 DmaAdapter = FdoExtension->DmaAdapter;
1817 DmaOperations = DmaAdapter->DmaOperations;
1818
1819 DmaOperations->FreeCommonBuffer(FdoExtension->DmaAdapter,
1820 HeaderBuffer->Length,
1821 HeaderBuffer->LogicalAddress,
1822 (PVOID)HeaderBuffer->VirtualAddress,
1823 TRUE);
1824}
PFREE_COMMON_BUFFER FreeCommonBuffer
Definition: iotypes.h:2638

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

◆ USBPORT_GetHciMn()

ULONG NTAPI USBPORT_GetHciMn ( VOID  )

Definition at line 2839 of file usbport.c.

2840{
2841 return USBPORT_HCI_MN;
2842}
#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 2170 of file usbport.c.

2173{
2174 PUSBPORT_COMMON_BUFFER_HEADER HeaderBuffer;
2175 PUSBPORT_ENDPOINT Endpoint;
2176 ULONG Offset;
2178
2179 DPRINT_CORE("USBPORT_GetMappedVirtualAddress ...\n");
2180
2181 Endpoint = (PUSBPORT_ENDPOINT)((ULONG_PTR)MiniPortEndpoint -
2182 sizeof(USBPORT_ENDPOINT));
2183
2184 if (!Endpoint)
2185 {
2186 ASSERT(FALSE);
2187 }
2188
2189 HeaderBuffer = Endpoint->HeaderBuffer;
2190
2191 Offset = PhysicalAddress - HeaderBuffer->PhysicalAddress;
2192 VirtualAddress = HeaderBuffer->VirtualAddress + Offset;
2193
2194 return (PVOID)VirtualAddress;
2195}
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
PUSBPORT_COMMON_BUFFER_HEADER HeaderBuffer
Definition: usbport.h:207
struct _USBPORT_ENDPOINT * PUSBPORT_ENDPOINT
Definition: usbport.h:155
struct _USBPORT_ENDPOINT USBPORT_ENDPOINT
_Must_inspect_result_ _In_ WDFDMATRANSACTION _In_ PFN_WDF_PROGRAM_DMA _In_ WDF_DMA_DIRECTION _In_ PMDL _In_ PVOID VirtualAddress
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS PhysicalAddress
Definition: iotypes.h:1098

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,
388 LengthStr,
389 Buffer,
391
392 FdoExtension = (PUSBPORT_DEVICE_EXTENSION)((ULONG_PTR)MiniPortExtension -
394
395 FdoDevice = FdoExtension->CommonExtension.SelfDevice;
396
398 FdoExtension->CommonExtension.LowerPdoDevice,
399 UseDriverKey,
401 LengthStr,
402 Buffer,
404
406}
Definition: bufpool.h:45
_Out_ _Inout_ POEM_STRING _In_ PCUNICODE_STRING SourceString
Definition: rtlfuncs.h:1957
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

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,
313 LengthStr,
314 Buffer,
316
317 if (UseDriverKey)
318 {
322 &KeyHandle);
323 }
324 else
325 {
329 &KeyHandle);
330 }
331
332 if (NT_SUCCESS(Status))
333 {
335
336 LengthKey = sizeof(KEY_VALUE_FULL_INFORMATION) +
337 LengthStr +
339
341 LengthKey,
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,
360 }
361
363 }
364
366 }
367
368 return Status;
369}
#define PagedPool
Definition: env_spec_w32.h:308
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4715
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
struct _KEY_VALUE_FULL_INFORMATION KEY_VALUE_FULL_INFORMATION
@ KeyValueFullInformation
Definition: nt_native.h:1184
#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:1621
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
unsigned char * PUCHAR
Definition: typedefs.h:53
#define PLUGPLAY_REGKEY_DRIVER
Definition: usbd.c:42
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:243
#define PLUGPLAY_REGKEY_DEVICE
Definition: iofuncs.h:2786

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}
#define PCI_WHICHSPACE_CONFIG
Definition: iotypes.h:3646

Referenced by USBPORT_ReadWriteConfigSpace().

◆ USBPORT_InterruptService()

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

Definition at line 1112 of file usbport.c.

1114{
1115 PDEVICE_OBJECT FdoDevice;
1119
1120 FdoDevice = ServiceContext;
1121 FdoExtension = FdoDevice->DeviceExtension;
1122 Packet = &FdoExtension->MiniPortInterface->Packet;
1123
1124 DPRINT_INT("USBPORT_InterruptService: FdoExtension[%p]->Flags - %08X\n",
1126 FdoExtension->Flags);
1127
1130 {
1131 Result = Packet->InterruptService(FdoExtension->MiniPortExt);
1132
1133 if (Result)
1134 {
1136 }
1137 }
1138
1139 DPRINT_INT("USBPORT_InterruptService: return - %x\n", Result);
1140
1141 return Result;
1142}
BOOLEAN NTAPI KeInsertQueueDpc(IN PKDPC Dpc, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: dpc.c:725
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1549
#define DPRINT_INT(...)
Definition: usbdebug.h:146
#define USBPORT_MPFLAG_INTERRUPTS_ENABLED
Definition: usbport.h:102
#define USBPORT_FLAG_INTERRUPT_ENABLED
Definition: usbport.h:72
_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:409
_In_ PKSERVICE_ROUTINE _In_opt_ PVOID ServiceContext
Definition: iofuncs.h:801

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 -
681 FdoDevice = FdoExtension->CommonExtension.SelfDevice;
682
684
685 return 0;
686}
Type
Definition: Type.h:7
VOID NTAPI USBPORT_InvalidateControllerHandler(IN PDEVICE_OBJECT FdoDevice, IN ULONG Type)
Definition: usbport.c:635

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_RESET
Definition: usbmport.h:489
#define USBPORT_INVALIDATE_CONTROLLER_SURPRISE_REMOVE
Definition: usbmport.h:490
#define USBPORT_INVALIDATE_CONTROLLER_SOFT_INTERRUPT
Definition: usbmport.h:491
VOID NTAPI USBPORT_SoftInterrupt(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:611

Referenced by USBPORT_FdoPnP(), and USBPORT_InvalidateController().

◆ USBPORT_InvalidateEndpoint()

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

Definition at line 2199 of file usbport.c.

2201{
2203 PDEVICE_OBJECT FdoDevice;
2204 PUSBPORT_ENDPOINT Endpoint;
2205
2206 DPRINT_CORE("USBPORT_InvalidateEndpoint: ...\n");
2207
2208 FdoExtension = (PUSBPORT_DEVICE_EXTENSION)((ULONG_PTR)MiniPortExtension -
2209 sizeof(USBPORT_DEVICE_EXTENSION));
2210
2211 FdoDevice = FdoExtension->CommonExtension.SelfDevice;
2212
2213 if (!MiniPortEndpoint)
2214 {
2216 NULL,
2218 return 0;
2219 }
2220
2221 Endpoint = (PUSBPORT_ENDPOINT)((ULONG_PTR)MiniPortEndpoint -
2222 sizeof(USBPORT_ENDPOINT));
2223
2225 Endpoint,
2227
2228 return 0;
2229}
#define INVALIDATE_ENDPOINT_ONLY
Definition: usbport.h:36

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}

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 1066 of file usbport.c.

1070{
1071 PDEVICE_OBJECT FdoDevice;
1074 BOOLEAN InterruptEnable;
1075
1076 DPRINT_INT("USBPORT_IsrDpc: DeferredContext - %p, SystemArgument2 - %p\n",
1079
1080 FdoDevice = DeferredContext;
1081 FdoExtension = FdoDevice->DeviceExtension;
1082 Packet = &FdoExtension->MiniPortInterface->Packet;
1083
1084 if (SystemArgument2)
1085 {
1086 InterlockedDecrement(&FdoExtension->IsrDpcCounter);
1087 }
1088
1089 KeAcquireSpinLockAtDpcLevel(&FdoExtension->MiniportInterruptsSpinLock);
1090 InterruptEnable = (FdoExtension->Flags & USBPORT_FLAG_INTERRUPT_ENABLED) ==
1092
1093 Packet->InterruptDpc(FdoExtension->MiniPortExt, InterruptEnable);
1094
1095 KeReleaseSpinLockFromDpcLevel(&FdoExtension->MiniportInterruptsSpinLock);
1096
1098 FdoExtension->TimerFlags & USBPORT_TMFLAG_WAKE)
1099 {
1100 USBPORT_CompletePdoWaitWake(FdoDevice);
1101 }
1102 else
1103 {
1104 USBPORT_IsrDpcHandler(FdoDevice, TRUE);
1105 }
1106
1107 DPRINT_INT("USBPORT_IsrDpc: exit\n");
1108}
VOID NTAPI USBPORT_CompletePdoWaitWake(IN PDEVICE_OBJECT FdoDevice)
Definition: power.c:15
VOID NTAPI USBPORT_IsrDpcHandler(IN PDEVICE_OBJECT FdoDevice, IN BOOLEAN IsDpcHandler)
Definition: usbport.c:941
#define USBPORT_TMFLAG_WAKE
Definition: usbport.h:98
#define USBPORT_FLAG_HC_SUSPEND
Definition: usbport.h:71
_In_opt_ PVOID _In_opt_ PVOID _In_opt_ PVOID SystemArgument2
Definition: ketypes.h:741

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 /* Process the state change list.
965 * - Always process the list (don't flush during suspend)
966 * - If controller is suspended/off, mark endpoints as ready immediately
967 * - Don't request interrupts if suspended */
968 KeAcquireSpinLockAtDpcLevel(&FdoExtension->EpStateChangeSpinLock);
969 List = FdoExtension->EpStateChangeList.Flink;
970 while (List != &FdoExtension->EpStateChangeList)
971 {
972 BOOLEAN EndpointReady = FALSE;
973 PLIST_ENTRY NextList;
974 BOOLEAN ControllerSuspended;
975
976 Endpoint = CONTAINING_RECORD(List,
978 StateChangeLink);
979
980 DPRINT_CORE("USBPORT_IsrDpcHandler: Endpoint - %p\n", Endpoint);
981
982 /* Save the next entry before we potentially remove this one */
983 NextList = List->Flink;
984
985 /* Check if controller is suspended/off */
986 ControllerSuspended = (FdoExtension->Flags & USBPORT_FLAG_HC_SUSPEND) != 0 ||
987 (FdoExtension->CommonExtension.DevicePowerState == PowerDeviceD3);
988
989 if (ControllerSuspended)
990 {
991 /* Controller is suspended/off - mark endpoint as ready immediately */
992 EndpointReady = TRUE;
993 }
994 else
995 {
996 KeAcquireSpinLockAtDpcLevel(&FdoExtension->MiniportSpinLock);
997 FrameNumber = Packet->Get32BitFrameNumber(FdoExtension->MiniPortExt);
999
1000 /* Check if the endpoint is ready to be processed */
1001 if (FrameNumber > Endpoint->FrameNumber ||
1002 (Endpoint->Flags & ENDPOINT_FLAG_NUKE))
1003 {
1004 EndpointReady = TRUE;
1005 }
1006 }
1007
1008
1009 if (EndpointReady)
1010 {
1011 /* Endpoint is ready - remove it from the list and process it */
1012 RemoveEntryList(&Endpoint->StateChangeLink);
1013 Endpoint->StateChangeLink.Flink = NULL;
1014 Endpoint->StateChangeLink.Blink = NULL;
1015
1017 Endpoint->StateLast = Endpoint->StateNext;
1019
1020 DPRINT_CORE("USBPORT_IsrDpcHandler: Endpoint->StateLast - %x\n",
1021 Endpoint->StateLast);
1022
1023 KeReleaseSpinLockFromDpcLevel(&FdoExtension->EpStateChangeSpinLock);
1024
1025 if (IsDpcHandler)
1026 {
1028 Endpoint,
1030 }
1031 else
1032 {
1034 Endpoint,
1036 }
1037
1038 KeAcquireSpinLockAtDpcLevel(&FdoExtension->EpStateChangeSpinLock);
1039 }
1040 else if (!ControllerSuspended)
1041 {
1042 /* Endpoint is not ready yet - leave it in the list and request interrupt.
1043 * Don't request interrupts if controller is suspended. */
1044 KeAcquireSpinLockAtDpcLevel(&FdoExtension->MiniportSpinLock);
1045 Packet->InterruptNextSOF(FdoExtension->MiniPortExt);
1046 KeReleaseSpinLockFromDpcLevel(&FdoExtension->MiniportSpinLock);
1047 }
1048 /* If suspended and not ready, leave it in list but don't request interrupt */
1049
1050 /* Move to the next entry */
1051 List = NextList;
1052 }
1053
1054 KeReleaseSpinLockFromDpcLevel(&FdoExtension->EpStateChangeSpinLock);
1055
1056 if (IsDpcHandler)
1057 {
1058 USBPORT_DpcHandler(FdoDevice);
1059 }
1060
1061 InterlockedDecrement(&FdoExtension->IsrDpcHandlerCounter);
1062}
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
KSPIN_LOCK StateChangeSpinLock
Definition: usbport.h:225
LIST_ENTRY StateChangeLink
Definition: usbport.h:224
ULONG FrameNumber
Definition: usbport.h:213
VOID NTAPI USBPORT_DpcHandler(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:864
#define INVALIDATE_ENDPOINT_WORKER_THREAD
Definition: usbport.h:37
#define ENDPOINT_FLAG_NUKE
Definition: usbport.h:113

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 2343 of file usbport.c.

2347{
2349 PDMA_ADAPTER DmaAdapter;
2350 PUSBPORT_TRANSFER Transfer;
2351 PURB Urb;
2352 PUSBPORT_ENDPOINT Endpoint;
2353 PMDL Mdl;
2354 ULONG_PTR CurrentVa;
2356 SIZE_T CurrentLength;
2357 ULONG ix;
2359 PHYSICAL_ADDRESS PhAddr = {{0, 0}};
2360 PHYSICAL_ADDRESS PhAddress = {{0, 0}};
2361 ULONG TransferLength;
2362 SIZE_T SgCurrentLength;
2363 SIZE_T ElementLength;
2365 PDMA_OPERATIONS DmaOperations;
2366 USBD_STATUS USBDStatus;
2368 PUSBPORT_TRANSFER transfer;
2369
2370 DPRINT_CORE("USBPORT_MapTransfer: ...\n");
2371
2372 FdoExtension = FdoDevice->DeviceExtension;
2373 DmaAdapter = FdoExtension->DmaAdapter;
2374 DmaOperations = DmaAdapter->DmaOperations;
2375
2376 Transfer = Context;
2377
2378 Urb = Transfer->Urb;
2379 Endpoint = Transfer->Endpoint;
2380 TransferLength = Transfer->TransferParameters.TransferBufferLength;
2381
2382 Mdl = Urb->UrbControlTransfer.TransferBufferMDL;
2383 CurrentVa = (ULONG_PTR)MmGetMdlVirtualAddress(Mdl);
2384
2385 sgList = &Transfer->SgList;
2386
2387 sgList->Flags = 0;
2388 sgList->CurrentVa = CurrentVa;
2391 Transfer->MapRegisterBase = MapRegisterBase;
2392
2393 ix = 0;
2394 CurrentLength = 0;
2395
2396 do
2397 {
2399 ASSERT(Transfer->Direction != 0);
2400
2401 PhAddress = DmaOperations->MapTransfer(DmaAdapter,
2402 Mdl,
2404 (PVOID)CurrentVa,
2405 &TransferLength,
2407
2408 DPRINT_CORE("USBPORT_MapTransfer: PhAddress.LowPart - %p, PhAddress.HighPart - %x, TransferLength - %x\n",
2409 PhAddress.LowPart,
2410 PhAddress.HighPart,
2411 TransferLength);
2412
2413 PhAddress.HighPart = 0;
2414 SgCurrentLength = TransferLength;
2415
2416 do
2417 {
2418 ElementLength = PAGE_SIZE - (PhAddress.LowPart & (PAGE_SIZE - 1));
2419
2420 if (ElementLength > SgCurrentLength)
2421 ElementLength = SgCurrentLength;
2422
2423 DPRINT_CORE("USBPORT_MapTransfer: PhAddress.LowPart - %p, HighPart - %x, ElementLength - %x\n",
2424 PhAddress.LowPart,
2425 PhAddress.HighPart,
2426 ElementLength);
2427
2428 sgList->SgElement[ix].SgPhysicalAddress = PhAddress;
2429 sgList->SgElement[ix].SgTransferLength = ElementLength;
2430 sgList->SgElement[ix].SgOffset = CurrentLength +
2431 (TransferLength - SgCurrentLength);
2432
2433 PhAddress.LowPart += ElementLength;
2434 SgCurrentLength -= ElementLength;
2435
2436 ++ix;
2437 }
2438 while (SgCurrentLength);
2439
2440 if (PhAddr.QuadPart == PhAddress.QuadPart)
2441 {
2442 DPRINT1("USBPORT_MapTransfer: PhAddr == PhAddress\n");
2443 ASSERT(FALSE);
2444 }
2445
2446 PhAddr = PhAddress;
2447
2448 CurrentLength += TransferLength;
2449 CurrentVa += TransferLength;
2450
2451 TransferLength = Transfer->TransferParameters.TransferBufferLength -
2452 CurrentLength;
2453 }
2454 while (CurrentLength != Transfer->TransferParameters.TransferBufferLength);
2455
2456 sgList->SgElementCount = ix;
2457
2459 {
2460 Transfer->Flags |= TRANSFER_FLAG_HIGH_SPEED;
2461 }
2462
2463 Transfer->Flags |= TRANSFER_FLAG_DMA_MAPPED;
2464
2465 if ((Transfer->Flags & TRANSFER_FLAG_ISO) == 0)
2466 {
2468 &Endpoint->EndpointOldIrql);
2469
2470 USBPORT_SplitTransfer(FdoDevice, Endpoint, Transfer, &List);
2471
2472 while (!IsListEmpty(&List))
2473 {
2474 transfer = CONTAINING_RECORD(List.Flink,
2476 TransferLink);
2477
2479 InsertTailList(&Endpoint->TransferList, &transfer->TransferLink);
2480 }
2481
2483 Endpoint->EndpointOldIrql);
2484 }
2485 else
2486 {
2487 USBDStatus = USBPORT_InitializeIsoTransfer(FdoDevice,
2488 &Urb->UrbIsochronousTransfer,
2489 Transfer);
2490
2491 if (USBDStatus != USBD_STATUS_SUCCESS)
2492 {
2494 &Endpoint->EndpointOldIrql);
2495
2496 USBPORT_QueueDoneTransfer(Transfer, USBDStatus);
2497
2499 Endpoint->EndpointOldIrql);
2500 }
2501 }
2502
2503 DeviceHandle = Urb->UrbHeader.UsbdDeviceHandle;
2504 InterlockedDecrement(&DeviceHandle->DeviceHandleLock);
2505
2506 if (USBPORT_EndpointWorker(Endpoint, 0))
2507 {
2509 Endpoint,
2511 }
2512
2514}
USBD_STATUS NTAPI USBPORT_InitializeIsoTransfer(PDEVICE_OBJECT FdoDevice, struct _URB_ISOCH_TRANSFER *Urb, PUSBPORT_TRANSFER Transfer)
Definition: iso.c:15
@ NormalPagePriority
Definition: imports.h:54
PMAP_TRANSFER MapTransfer
Definition: iotypes.h:2643
USB_DEVICE_SPEED DeviceSpeed
Definition: usbmport.h:73
KIRQL EndpointOldIrql
Definition: usbport.h:216
LIST_ENTRY TransferList
Definition: usbport.h:228
KSPIN_LOCK EndpointSpinLock
Definition: usbport.h:215
PHYSICAL_ADDRESS SgPhysicalAddress
Definition: usbmport.h:107
USBPORT_SCATTER_GATHER_ELEMENT SgElement[2]
Definition: usbmport.h:121
LIST_ENTRY TransferLink
Definition: usbport.h:257
USBPORT_SCATTER_GATHER_LIST SgList
Definition: usbport.h:271
VOID NTAPI USBPORT_SplitTransfer(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint, IN PUSBPORT_TRANSFER Transfer, IN PLIST_ENTRY List)
Definition: trfsplit.c:232
LONGLONG QuadPart
Definition: typedefs.h:114
@ UsbHighSpeed
Definition: usb200.h:44
BOOLEAN NTAPI USBPORT_QueueDoneTransfer(IN PUSBPORT_TRANSFER Transfer, IN USBD_STATUS USBDStatus)
Definition: usbport.c:839
#define TRANSFER_FLAG_HIGH_SPEED
Definition: usbport.h:132
_Inout_ struct _IRP _In_ PVOID MapRegisterBase
Definition: iotypes.h:213
@ DeallocateObjectKeepRegisters
Definition: iotypes.h:204
#define MmGetSystemAddressForMdlSafe(_Mdl, _Priority)

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 2025 of file usbport.c.

2030{
2031 PUSBPORT_TRANSFER Transfer;
2032 PUSBPORT_TRANSFER ParentTransfer;
2033 PUSBPORT_TRANSFER SplitTransfer;
2034 PLIST_ENTRY SplitHead;
2036 KIRQL OldIrql;
2037
2038 DPRINT_CORE("USBPORT_MiniportCompleteTransfer: USBDStatus - %x, TransferLength - %x\n",
2039 USBDStatus,
2040 TransferLength);
2041
2042 Transfer = CONTAINING_RECORD(TransferParameters,
2044 TransferParameters);
2045
2046 Transfer->Flags |= TRANSFER_FLAG_COMPLETED;
2047 Transfer->CompletedTransferLen = TransferLength;
2048
2049 if (((Transfer->Flags & TRANSFER_FLAG_SPLITED) == 0) ||
2050 TransferLength >= Transfer->TransferParameters.TransferBufferLength)
2051 {
2052 goto Exit;
2053 }
2054
2055 ParentTransfer = Transfer->ParentTransfer;
2056
2057 KeAcquireSpinLock(&ParentTransfer->TransferSpinLock, &OldIrql);
2058
2059 if (IsListEmpty(&ParentTransfer->SplitTransfersList))
2060 {
2061 goto Exit;
2062 }
2063
2064 SplitHead = &ParentTransfer->SplitTransfersList;
2065 Entry = SplitHead->Flink;
2066
2067 while (Entry && !IsListEmpty(SplitHead))
2068 {
2069 SplitTransfer = CONTAINING_RECORD(Entry,
2071 SplitLink);
2072
2073 if (!(SplitTransfer->Flags & TRANSFER_FLAG_SUBMITED))
2074 {
2075 DPRINT1("USBPORT_MiniportCompleteTransfer: SplitTransfer->Flags - %X\n",
2076 SplitTransfer->Flags);
2077 //Add TRANSFER_FLAG_xxx
2078 }
2079
2080 Entry = Entry->Flink;
2081 }
2082
2083 KeReleaseSpinLock(&ParentTransfer->TransferSpinLock, OldIrql);
2084
2085Exit:
2086 USBPORT_QueueDoneTransfer(Transfer, USBDStatus);
2087}
LIST_ENTRY SplitTransfersList
Definition: usbport.h:266
#define TRANSFER_FLAG_SUBMITED
Definition: usbport.h:133
#define TRANSFER_FLAG_COMPLETED
Definition: usbport.h:138

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;
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);
581 FdoExtension->Flags &= ~USBPORT_FLAG_INTERRUPT_ENABLED;
582 }
583
584 if (IsLock)
585 KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
586}
#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}

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 {
243 }
244}
#define MP_STATUS_UNSUCCESSFUL
Definition: usbmport.h:142
#define MP_STATUS_SUCCESS
Definition: usbmport.h:134

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}

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 -
471
472 FdoDevice = FdoExtension->CommonExtension.SelfDevice;
473
475 IsReadData,
476 Buffer,
477 Offset,
478 Length);
479
481}
NTSTATUS NTAPI USBPORT_GetSetConfigSpaceData(IN PDEVICE_OBJECT FdoDevice, IN BOOLEAN IsReadData, IN PVOID Buffer, IN ULONG Offset, IN ULONG Length)
Definition: usbport.c:410

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 2846 of file usbport.c.

2849{
2850 PUSBPORT_MINIPORT_INTERFACE MiniPortInterface;
2851
2852 DPRINT("USBPORT_RegisterUSBPortDriver: DriverObject - %p, Version - %p, RegPacket - %p\n",
2854 Version,
2855 RegPacket);
2856
2857 DPRINT("USBPORT_RegisterUSBPortDriver: sizeof(USBPORT_MINIPORT_INTERFACE) - %x\n",
2859
2860 DPRINT("USBPORT_RegisterUSBPortDriver: sizeof(USBPORT_DEVICE_EXTENSION) - %x\n",
2861 sizeof(USBPORT_DEVICE_EXTENSION));
2862
2864 {
2865 return STATUS_UNSUCCESSFUL;
2866 }
2867
2869 {
2873
2876 }
2877
2878 MiniPortInterface = ExAllocatePoolWithTag(NonPagedPool,
2880 USB_PORT_TAG);
2881 if (!MiniPortInterface)
2882 {
2884 }
2885
2886 RtlZeroMemory(MiniPortInterface, sizeof(USBPORT_MINIPORT_INTERFACE));
2887
2888 MiniPortInterface->DriverObject = DriverObject;
2889 MiniPortInterface->DriverUnload = DriverObject->DriverUnload;
2890 MiniPortInterface->Version = Version;
2891
2893 &MiniPortInterface->DriverLink,
2895
2896 DriverObject->DriverExtension->AddDevice = USBPORT_AddDevice;
2897 DriverObject->DriverUnload = USBPORT_Unload;
2898
2900 DriverObject->MajorFunction[IRP_MJ_CLOSE] = USBPORT_Dispatch;
2903 DriverObject->MajorFunction[IRP_MJ_PNP] = USBPORT_Dispatch;
2904 DriverObject->MajorFunction[IRP_MJ_POWER] = USBPORT_Dispatch;
2906
2923
2924 RtlCopyMemory(&MiniPortInterface->Packet,
2925 RegPacket,
2927
2928 return STATUS_SUCCESS;
2929}
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:60
VOID NTAPI USBPORT_BugCheck(IN PVOID MiniPortExtension)
Definition: debug.c:51
ULONG NTAPI USBPORT_AssertFailure(PVOID MiniPortExtension, PVOID FailedAssertion, PVOID FileName, ULONG LineNumber, PCHAR Message)
Definition: debug.c:38
ULONG NTAPI USBPORT_TestDebugBreak(IN PVOID MiniPortExtension)
Definition: debug.c:30
ULONG USBPORT_DbgPrint(IN PVOID MiniPortExtension, IN ULONG Level, IN PCH Format,...)
Definition: debug.c:19
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
PUSBPORT_GET_MINIPORT_REGISTRY_KEY_VALUE UsbPortGetMiniportRegistryKeyValue
Definition: usbmport.h:613
PUSBPORT_INVALIDATE_CONTROLLER UsbPortInvalidateController
Definition: usbmport.h:623
PUSBPORT_REQUEST_ASYNC_CALLBACK UsbPortRequestAsyncCallback
Definition: usbmport.h:620
PUSBPORT_TEST_DEBUG_BREAK UsbPortTestDebugBreak
Definition: usbmport.h:611
PUSBPORT_LOG_ENTRY UsbPortLogEntry
Definition: usbmport.h:618
PUSBPORT_BUG_CHECK UsbPortBugCheck
Definition: usbmport.h:624
PUSBPORT_NOTIFY_DOUBLE_BUFFER UsbPortNotifyDoubleBuffer
Definition: usbmport.h:625
PUSBPORT_INVALIDATE_ROOT_HUB UsbPortInvalidateRootHub
Definition: usbmport.h:614
PUSBPORT_COMPLETE_ISO_TRANSFER UsbPortCompleteIsoTransfer
Definition: usbmport.h:617
PUSBPORT_DBG_PRINT UsbPortDbgPrint
Definition: usbmport.h:610
PUSBPORT_WAIT UsbPortWait
Definition: usbmport.h:622
PUSBPORT_COMPLETE_TRANSFER UsbPortCompleteTransfer
Definition: usbmport.h:616
PUSBPORT_READ_WRITE_CONFIG_SPACE UsbPortReadWriteConfigSpace
Definition: usbmport.h:621
PUSBPORT_ASSERT_FAILURE UsbPortAssertFailure
Definition: usbmport.h:612
PUSBPORT_GET_MAPPED_VIRTUAL_ADDRESS UsbPortGetMappedVirtualAddress
Definition: usbmport.h:619
PUSBPORT_INVALIDATE_ENDPOINT UsbPortInvalidateEndpoint
Definition: usbmport.h:615
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
USBPORT_REGISTRATION_PACKET RegPacket
Definition: usbehci.c:16
#define USB10_MINIPORT_INTERFACE_VERSION
Definition: usbmport.h:636
ULONG NTAPI USBPORT_InvalidateRootHub(PVOID MiniPortExtension)
Definition: roothub.c:916
BOOLEAN USBPORT_Initialized
Definition: usbport.c:23
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
MPSTATUS NTAPI USBPORT_ReadWriteConfigSpace(IN PVOID MiniPortExtension, IN BOOLEAN IsReadData, IN PVOID Buffer, IN ULONG Offset, IN ULONG Length)
Definition: usbport.c:456
NTSTATUS NTAPI USBPORT_AddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject)
Definition: usbport.c:1868
ULONG NTAPI USBPORT_InvalidateController(IN PVOID MiniPortExtension, IN ULONG Type)
Definition: usbport.c:670
ULONG NTAPI USBPORT_InvalidateEndpoint(IN PVOID MiniPortExtension, IN PVOID MiniPortEndpoint)
Definition: usbport.c:2199
ULONG NTAPI USBPORT_NotifyDoubleBuffer(IN PVOID MiniPortExtension, IN PVOID MiniPortTransfer, IN PVOID Buffer, IN SIZE_T Length)
Definition: usbport.c:690
PVOID NTAPI USBPORT_GetMappedVirtualAddress(IN ULONG PhysicalAddress, IN PVOID MiniPortExtension, IN PVOID MiniPortEndpoint)
Definition: usbport.c:2170
NTSTATUS NTAPI USBPORT_Dispatch(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: usbport.c:2686
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:2114
VOID NTAPI USBPORT_Unload(IN PDRIVER_OBJECT DriverObject)
Definition: usbport.c:2005
NTSTATUS NTAPI USBPORT_Wait(IN PVOID MiniPortExtension, IN ULONG Milliseconds)
Definition: usbport.c:543
VOID NTAPI USBPORT_MiniportCompleteTransfer(IN PVOID MiniPortExtension, IN PVOID MiniPortEndpoint, IN PVOID TransferParameters, IN USBD_STATUS USBDStatus, IN ULONG TransferLength)
Definition: usbport.c:2025
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE _In_ USHORT _In_ USHORT Version
Definition: wdffdo.h:469

Referenced by DriverEntry().

◆ USBPORT_RemoveUSBxFdo()

VOID NTAPI USBPORT_RemoveUSBxFdo ( IN PDEVICE_OBJECT  FdoDevice)

Definition at line 98 of file usbport.c.

99{
102
103 DPRINT("USBPORT_RemoveUSBxFdo: FdoDevice - %p\n", FdoDevice);
104
105 FdoExtension = FdoDevice->DeviceExtension;
106
108 RemoveEntryList(&FdoExtension->ControllerLink);
110
111 FdoExtension->Flags &= ~USBPORT_FLAG_REGISTERED_FDO;
112
113 FdoExtension->ControllerLink.Flink = NULL;
114 FdoExtension->ControllerLink.Blink = NULL;
115}

◆ 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 2114 of file usbport.c.

2119{
2121 PDEVICE_OBJECT FdoDevice;
2122 PUSBPORT_ASYNC_CALLBACK_DATA AsyncCallbackData;
2123 LARGE_INTEGER DueTime = {{0, 0}};
2124
2125 DPRINT("USBPORT_RequestAsyncCallback: ...\n");
2126
2127 FdoExtension = (PUSBPORT_DEVICE_EXTENSION)((ULONG_PTR)MiniPortExtension -
2128 sizeof(USBPORT_DEVICE_EXTENSION));
2129
2130 FdoDevice = FdoExtension->CommonExtension.SelfDevice;
2131
2132 AsyncCallbackData = ExAllocatePoolWithTag(NonPagedPool,
2134 USB_PORT_TAG);
2135
2136 if (!AsyncCallbackData)
2137 {
2138 DPRINT1("USBPORT_RequestAsyncCallback: Not allocated AsyncCallbackData!\n");
2139 return 0;
2140 }
2141
2142 RtlZeroMemory(AsyncCallbackData,
2144
2145 if (Length)
2146 {
2147 RtlCopyMemory(&AsyncCallbackData->CallbackContext, Buffer, Length);
2148 }
2149
2150 AsyncCallbackData->FdoDevice = FdoDevice;
2151 AsyncCallbackData->CallbackFunction = Callback;
2152
2153 KeInitializeTimer(&AsyncCallbackData->AsyncTimer);
2154
2155 KeInitializeDpc(&AsyncCallbackData->AsyncTimerDpc,
2157 AsyncCallbackData);
2158
2159 DueTime.QuadPart -= (KeQueryTimeIncrement() - 1) + 10000 * TimerValue;
2160
2161 KeSetTimer(&AsyncCallbackData->AsyncTimer,
2162 DueTime,
2163 &AsyncCallbackData->AsyncTimerDpc);
2164
2165 return 0;
2166}
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:712
ULONG NTAPI KeQueryTimeIncrement(VOID)
Definition: clock.c:153
BOOLEAN NTAPI KeSetTimer(IN OUT PKTIMER Timer, IN LARGE_INTEGER DueTime, IN PKDPC Dpc OPTIONAL)
Definition: timerobj.c:282
VOID NTAPI KeInitializeTimer(OUT PKTIMER Timer)
Definition: timerobj.c:233
VOID NTAPI USBPORT_AsyncTimerDpc(IN PRKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: usbport.c:2091
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
Definition: wdfinterrupt.h:458
_In_ WDFTIMER _In_ LONGLONG DueTime
Definition: wdftimer.h:190

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}
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4755

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

◆ USBPORT_SignalWorkerThread()

VOID NTAPI USBPORT_SignalWorkerThread ( IN PDEVICE_OBJECT  FdoDevice)

Definition at line 1146 of file usbport.c.

1147{
1149 KIRQL OldIrql;
1150
1151 DPRINT_CORE("USBPORT_SignalWorkerThread ...\n");
1152
1153 FdoExtension = FdoDevice->DeviceExtension;
1154
1155 KeAcquireSpinLock(&FdoExtension->WorkerThreadEventSpinLock, &OldIrql);
1156 KeSetEvent(&FdoExtension->WorkerThreadEvent, EVENT_INCREMENT, FALSE);
1157 KeReleaseSpinLock(&FdoExtension->WorkerThreadEventSpinLock, OldIrql);
1158}

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}
VOID NTAPI USBPORT_SoftInterruptDpc(IN PRKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: usbport.c:590

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}

Referenced by USBPORT_SoftInterrupt().

◆ USBPORT_StartTimer()

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

Definition at line 1710 of file usbport.c.

1712{
1714 LARGE_INTEGER DueTime = {{0, 0}};
1715 ULONG TimeIncrement;
1717
1718 DPRINT_TIMER("USBPORT_StartTimer: FdoDevice - %p, Time - %x\n",
1719 FdoDevice,
1720 Time);
1721
1722 FdoExtension = FdoDevice->DeviceExtension;
1723
1724 TimeIncrement = KeQueryTimeIncrement();
1725
1727 FdoExtension->TimerValue = Time;
1728
1729 KeInitializeTimer(&FdoExtension->TimerObject);
1730 KeInitializeDpc(&FdoExtension->TimerDpc, USBPORT_TimerDpc, FdoDevice);
1731
1732 DueTime.QuadPart -= 10000 * Time + (TimeIncrement - 1);
1733
1734 Result = KeSetTimer(&FdoExtension->TimerObject,
1735 DueTime,
1736 &FdoExtension->TimerDpc);
1737
1738 return Result;
1739}
static PLARGE_INTEGER Time
Definition: time.c:105
#define DPRINT_TIMER(...)
Definition: usbdebug.h:147
VOID NTAPI USBPORT_TimerDpc(IN PRKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: usbport.c:1591
#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 1490 of file usbport.c.

1491{
1494
1495 DPRINT("USBPORT_StopWorkerThread ...\n");
1496
1497 FdoExtension = FdoDevice->DeviceExtension;
1498
1500 USBPORT_SignalWorkerThread(FdoDevice);
1501 Status = ZwWaitForSingleObject(FdoExtension->WorkerThreadHandle, FALSE, NULL);
1503}
#define USBPORT_FLAG_WORKER_THREAD_EXIT
Definition: usbport.h:70
#define NT_ASSERT
Definition: rtlfuncs.h:3327

Referenced by USBPORT_StartDevice().

◆ USBPORT_SynchronizeControllersStart()

VOID NTAPI USBPORT_SynchronizeControllersStart ( IN PDEVICE_OBJECT  FdoDevice)

Definition at line 1507 of file usbport.c.

1508{
1510 PDEVICE_OBJECT PdoDevice;
1512 PDEVICE_OBJECT USB2FdoDevice = NULL;
1513 PUSBPORT_DEVICE_EXTENSION USB2FdoExtension;
1514 BOOLEAN IsOn;
1515
1516 DPRINT_TIMER("USBPORT_SynchronizeControllersStart: FdoDevice - %p\n",
1517 FdoDevice);
1518
1519 FdoExtension = FdoDevice->DeviceExtension;
1520
1521 PdoDevice = FdoExtension->RootHubPdo;
1522
1523 if (!PdoDevice)
1524 {
1525 return;
1526 }
1527
1528 PdoExtension = PdoDevice->DeviceExtension;
1529
1530 if (PdoExtension->RootHubInitCallback == NULL ||
1532 {
1533 return;
1534 }
1535
1536 DPRINT_TIMER("USBPORT_SynchronizeControllersStart: Flags - %p\n",
1537 FdoExtension->Flags);
1538
1540 {
1541 IsOn = FALSE;
1542
1543 USB2FdoDevice = USBPORT_FindUSB2Controller(FdoDevice);
1544
1545 DPRINT_TIMER("USBPORT_SynchronizeControllersStart: USB2FdoDevice - %p\n",
1546 USB2FdoDevice);
1547
1548 if (USB2FdoDevice)
1549 {
1550 USB2FdoExtension = USB2FdoDevice->DeviceExtension;
1551
1552 if (USB2FdoExtension->CommonExtension.PnpStateFlags &
1554 {
1555 IsOn = TRUE;
1556 }
1557 }
1558
1559 if (!(FdoExtension->Flags & USBPORT_FLAG_NO_HACTION))
1560 {
1561 goto Start;
1562 }
1563
1564 USB2FdoDevice = NULL;
1565 }
1566
1567 IsOn = TRUE;
1568
1569 Start:
1570
1571 if (IsOn &&
1572 !InterlockedCompareExchange(&FdoExtension->RHInitCallBackLock, 1, 0))
1573 {
1575 USBPORT_SignalWorkerThread(FdoDevice);
1576
1577 if (USB2FdoDevice)
1578 {
1579 USB2FdoExtension = USB2FdoDevice->DeviceExtension;
1580
1581 USB2FdoExtension->Flags |= USBPORT_FLAG_RH_INIT_CALLBACK;
1582 USBPORT_SignalWorkerThread(USB2FdoDevice);
1583 }
1584 }
1585
1586 DPRINT_TIMER("USBPORT_SynchronizeControllersStart: exit\n");
1587}
return pTarget Start()
#define InterlockedCompareExchange
Definition: interlocked.h:119
PDEVICE_OBJECT NTAPI USBPORT_FindUSB2Controller(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:27
#define USBPORT_FLAG_RH_INIT_CALLBACK
Definition: usbport.h:84
#define USBPORT_FLAG_NO_HACTION
Definition: usbport.h:80
#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 1292 of file usbport.c.

1294{
1297 PUSBPORT_DEVICE_EXTENSION Usb2FdoExtension;
1298 PDEVICE_RELATIONS CompanionControllersList;
1299 PUSBPORT_DEVICE_EXTENSION CompanionFdoExtension;
1301 ULONG ix;
1302
1303 DPRINT("USBPORT_SynchronizeRootHubCallback: FdoDevice - %p, Usb2FdoDevice - %p\n",
1304 FdoDevice,
1305 Usb2FdoDevice);
1306
1307 FdoExtension = FdoDevice->DeviceExtension;
1308 Packet = &FdoExtension->MiniPortInterface->Packet;
1309
1310 if (Usb2FdoDevice == NULL &&
1311 !(Packet->MiniPortFlags & USB_MINIPORT_FLAGS_USB2))
1312 {
1313 /* Not Companion USB11 Controller */
1314 USBPORT_DoRootHubCallback(FdoDevice);
1315
1316 FdoExtension->Flags &= ~USBPORT_FLAG_RH_INIT_CALLBACK;
1317 InterlockedCompareExchange(&FdoExtension->RHInitCallBackLock, 0, 1);
1318
1319 DPRINT("USBPORT_SynchronizeRootHubCallback: exit\n");
1320 return;
1321 }
1322
1323 /* USB2 or Companion USB11 */
1324
1325 DPRINT("USBPORT_SynchronizeRootHubCallback: FdoExtension->Flags - %p\n",
1326 FdoExtension->Flags);
1327
1329 {
1330 KeWaitForSingleObject(&FdoExtension->ControllerSemaphore,
1331 Executive,
1332 KernelMode,
1333 FALSE,
1334 NULL);
1335
1337
1338 if (!(FdoExtension->Flags & (USBPORT_FLAG_HC_SUSPEND |
1340 {
1343 }
1344
1345 FdoExtension->Flags &= ~USBPORT_FLAG_PWR_AND_CHIRP_LOCK;
1346
1347 KeReleaseSemaphore(&FdoExtension->ControllerSemaphore,
1349 1,
1350 FALSE);
1351
1352 CompanionControllersList = USBPORT_FindCompanionControllers(FdoDevice,
1353 FALSE,
1354 TRUE);
1355
1356 if (CompanionControllersList)
1357 {
1358 Entry = &CompanionControllersList->Objects[0];
1359
1360 for (ix = 0; ix < CompanionControllersList->Count; ++ix)
1361 {
1362 CompanionFdoExtension = ((*Entry)->DeviceExtension);
1363
1364 InterlockedCompareExchange(&CompanionFdoExtension->RHInitCallBackLock,
1365 0,
1366 1);
1367
1368 ++Entry;
1369 }
1370
1371 ExFreePoolWithTag(CompanionControllersList, USB_PORT_TAG);
1372 }
1373
1374 USBPORT_DoRootHubCallback(FdoDevice);
1375
1376 FdoExtension->Flags &= ~USBPORT_FLAG_RH_INIT_CALLBACK;
1377 InterlockedCompareExchange(&FdoExtension->RHInitCallBackLock, 0, 1);
1378 }
1379 else
1380 {
1381 Usb2FdoExtension = Usb2FdoDevice->DeviceExtension;
1382
1383 USBPORT_Wait(FdoDevice, 50);
1384
1385 while (FdoExtension->RHInitCallBackLock)
1386 {
1387 USBPORT_Wait(FdoDevice, 10);
1388
1389 Usb2FdoExtension->Flags |= USBPORT_FLAG_RH_INIT_CALLBACK;
1390 USBPORT_SignalWorkerThread(Usb2FdoDevice);
1391 }
1392
1393 USBPORT_DoRootHubCallback(FdoDevice);
1394
1395 FdoExtension->Flags &= ~USBPORT_FLAG_RH_INIT_CALLBACK;
1396 }
1397
1398 DPRINT("USBPORT_SynchronizeRootHubCallback: exit\n");
1399}
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define LOW_REALTIME_PRIORITY
#define KernelMode
Definition: asm.h:38
LONG NTAPI KeReleaseSemaphore(IN PKSEMAPHORE Semaphore, IN KPRIORITY Increment, IN LONG Adjustment, IN BOOLEAN Wait)
Definition: semphobj.c:54
VOID NTAPI USBPORT_RootHubPowerAndChirpAllCcPorts(IN PDEVICE_OBJECT FdoDevice)
Definition: roothub.c:962
PDEVICE_RELATIONS NTAPI USBPORT_FindCompanionControllers(IN PDEVICE_OBJECT USB2FdoDevice, IN BOOLEAN IsObRefer, IN BOOLEAN IsFDOsReturned)
Definition: usbport.c:136
VOID NTAPI USBPORT_DoRootHubCallback(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:1257
#define USBPORT_FLAG_PWR_AND_CHIRP_LOCK
Definition: usbport.h:82
#define USBPORT_FLAG_POWER_AND_CHIRP_OK
Definition: usbport.h:83
@ Executive
Definition: ketypes.h:467

Referenced by USBPORT_WorkerThread().

◆ USBPORT_TimerDpc()

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

Definition at line 1591 of file usbport.c.

1595{
1596 PDEVICE_OBJECT FdoDevice;
1599 LARGE_INTEGER DueTime = {{0, 0}};
1600 ULONG TimerFlags;
1601 PTIMER_WORK_QUEUE_ITEM IdleQueueItem;
1602 KIRQL OldIrql;
1603 KIRQL TimerOldIrql;
1604
1605 DPRINT_TIMER("USBPORT_TimerDpc: Dpc - %p, DeferredContext - %p\n",
1606 Dpc,
1608
1609 FdoDevice = DeferredContext;
1610 FdoExtension = FdoDevice->DeviceExtension;
1611 Packet = &FdoExtension->MiniPortInterface->Packet;
1612
1613 KeAcquireSpinLock(&FdoExtension->TimerFlagsSpinLock, &TimerOldIrql);
1614
1615 TimerFlags = FdoExtension->TimerFlags;
1616
1617 DPRINT_TIMER("USBPORT_TimerDpc: Flags - %p, TimerFlags - %p\n",
1618 FdoExtension->Flags,
1619 TimerFlags);
1620
1623 !(TimerFlags & USBPORT_TMFLAG_HC_RESUME))
1624 {
1625 KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
1626 Packet->PollController(FdoExtension->MiniPortExt);
1627 KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
1628 }
1629
1631
1632 if (TimerFlags & USBPORT_TMFLAG_HC_SUSPENDED)
1633 {
1634 USBPORT_BadRequestFlush(FdoDevice);
1635 goto Exit;
1636 }
1637
1638 KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
1639
1640 if (!(FdoExtension->Flags & USBPORT_FLAG_HC_SUSPEND))
1641 {
1642 Packet->CheckController(FdoExtension->MiniPortExt);
1643 }
1644
1645 KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
1646
1648 {
1649 KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
1650 Packet->PollController(FdoExtension->MiniPortExt);
1651 KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
1652 }
1653
1654 USBPORT_IsrDpcHandler(FdoDevice, FALSE);
1655
1656 DPRINT_TIMER("USBPORT_TimerDpc: USBPORT_TimeoutAllEndpoints UNIMPLEMENTED.\n");
1657 //USBPORT_TimeoutAllEndpoints(FdoDevice);
1658 DPRINT_TIMER("USBPORT_TimerDpc: USBPORT_CheckIdleEndpoints UNIMPLEMENTED.\n");
1659 //USBPORT_CheckIdleEndpoints(FdoDevice);
1660
1661 USBPORT_BadRequestFlush(FdoDevice);
1662
1663 if (FdoExtension->IdleLockCounter > -1 &&
1664 !(TimerFlags & USBPORT_TMFLAG_IDLE_QUEUEITEM_ON))
1665 {
1666 IdleQueueItem = ExAllocatePoolWithTag(NonPagedPool,
1667 sizeof(TIMER_WORK_QUEUE_ITEM),
1668 USB_PORT_TAG);
1669
1670 DPRINT("USBPORT_TimerDpc: IdleLockCounter - %x, IdleQueueItem - %p\n",
1671 FdoExtension->IdleLockCounter,
1672 IdleQueueItem);
1673
1674 if (IdleQueueItem)
1675 {
1676 RtlZeroMemory(IdleQueueItem, sizeof(TIMER_WORK_QUEUE_ITEM));
1677
1678 IdleQueueItem->WqItem.List.Flink = NULL;
1680 IdleQueueItem->WqItem.Parameter = IdleQueueItem;
1681
1682 IdleQueueItem->FdoDevice = FdoDevice;
1683 IdleQueueItem->Context = 0;
1684
1686
1687 ExQueueWorkItem(&IdleQueueItem->WqItem, CriticalWorkQueue);
1688 }
1689 }
1690
1691Exit:
1692
1693 KeReleaseSpinLock(&FdoExtension->TimerFlagsSpinLock, TimerOldIrql);
1694
1695 if (TimerFlags & USBPORT_TMFLAG_TIMER_QUEUED)
1696 {
1697 DueTime.QuadPart -= FdoExtension->TimerValue * 10000 +
1698 (KeQueryTimeIncrement() - 1);
1699
1700 KeSetTimer(&FdoExtension->TimerObject,
1701 DueTime,
1702 &FdoExtension->TimerDpc);
1703 }
1704
1705 DPRINT_TIMER("USBPORT_TimerDpc: exit\n");
1706}
VOID NTAPI USBPORT_DoIdleNotificationCallback(IN PVOID Context)
Definition: power.c:545
VOID NTAPI USBPORT_BadRequestFlush(IN PDEVICE_OBJECT FdoDevice)
Definition: queue.c:1328
WORK_QUEUE_ITEM WqItem
Definition: usbport.h:444
PDEVICE_OBJECT FdoDevice
Definition: usbport.h:445
volatile PVOID Parameter
Definition: extypes.h:205
LIST_ENTRY List
Definition: extypes.h:203
PWORKER_THREAD_ROUTINE WorkerRoutine
Definition: extypes.h:204
VOID NTAPI USBPORT_SynchronizeControllersStart(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:1507
#define USBPORT_FLAG_HC_WAKE_SUPPORT
Definition: usbport.h:76
#define USBPORT_FLAG_HC_POLLING
Definition: usbport.h:68
#define USBPORT_TMFLAG_HC_SUSPENDED
Definition: usbport.h:94
#define USBPORT_TMFLAG_HC_RESUME
Definition: usbport.h:95
#define USBPORT_TMFLAG_IDLE_QUEUEITEM_ON
Definition: usbport.h:99
_Must_inspect_result_ _In_ PWDF_DPC_CONFIG _In_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFDPC * Dpc
Definition: wdfdpc.h:112
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:723
@ CriticalWorkQueue
Definition: extypes.h:189

Referenced by USBPORT_StartTimer().

◆ USBPORT_TransferFlushDpc()

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

Definition at line 825 of file usbport.c.

829{
830 PDEVICE_OBJECT FdoDevice;
831
832 DPRINT_CORE("USBPORT_TransferFlushDpc: ...\n");
833 FdoDevice = DeferredContext;
835}

Referenced by USBPORT_StartDevice().

◆ USBPORT_Unload()

VOID NTAPI USBPORT_Unload ( IN PDRIVER_OBJECT  DriverObject)

Definition at line 2005 of file usbport.c.

2006{
2007 PUSBPORT_MINIPORT_INTERFACE MiniPortInterface;
2008
2009 DPRINT1("USBPORT_Unload: FIXME!\n");
2010
2011 MiniPortInterface = USBPORT_FindMiniPort(DriverObject);
2012
2013 if (!MiniPortInterface)
2014 {
2015 DPRINT("USBPORT_Unload: CRITICAL ERROR!!! Not found MiniPortInterface\n");
2016 KeBugCheckEx(BUGCODE_USB_DRIVER, 1, 0, 0, 0);
2017 }
2018
2019 DPRINT1("USBPORT_Unload: UNIMPLEMENTED. FIXME.\n");
2020 //MiniPortInterface->DriverUnload(DriverObject); // Call MiniPort _HCI_Unload
2021}
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
Definition: rtlcompat.c:108

Referenced by USBPORT_RegisterUSBPortDriver().

◆ USBPORT_USBDStatusToNtStatus()

NTSTATUS NTAPI USBPORT_USBDStatusToNtStatus ( IN PURB  Urb,
IN USBD_STATUS  USBDStatus 
)

Definition at line 485 of file usbport.c.

487{
489
490 if (USBD_ERROR(USBDStatus))
491 {
492 DPRINT1("USBPORT_USBDStatusToNtStatus: Urb - %p, USBDStatus - %x\n",
493 Urb,
494 USBDStatus);
495 }
496
497 if (Urb)
498 Urb->UrbHeader.Status = USBDStatus;
499
500 switch (USBDStatus)
501 {
504 break;
505
508 break;
509
512 break;
513
516 break;
517
520 break;
521
527 break;
528
529 default:
530 if (USBD_ERROR(USBDStatus))
532 else
534
535 break;
536 }
537
538 return Status;
539}
#define STATUS_NOT_SUPPORTED
Definition: d3dkmdt.h:48
#define STATUS_DEVICE_NOT_CONNECTED
Definition: udferr_usr.h:160
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
#define USBD_STATUS_DEVICE_GONE
Definition: usb.h:210
#define USBD_STATUS_INVALID_PIPE_HANDLE
Definition: usb.h:194
#define USBD_STATUS_CANCELED
Definition: usb.h:213
#define USBD_ERROR(Status)
Definition: usb.h:169
#define USBD_STATUS_NOT_SUPPORTED
Definition: usb.h:202
#define USBD_STATUS_INVALID_PARAMETER
Definition: usb.h:192
#define USBD_STATUS_INVALID_URB_FUNCTION
Definition: usb.h:191
#define USBD_STATUS_BAD_START_FRAME
Definition: usb.h:198

Referenced by USBPORT_AbortPipe(), USBPORT_ClearStall(), USBPORT_CompleteTransfer(), USBPORT_DoneTransfer(), USBPORT_FlushAbortList(), USBPORT_HandleGetCurrentFrame(), USBPORT_HandleGetStatus(), USBPORT_HandleSelectConfiguration(), USBPORT_HandleSelectInterface(), USBPORT_HandleSubmitURB(), USBPORT_OpenInterface(), USBPORT_OpenPipe(), USBPORT_ResetPipe(), USBPORT_RestoreDevice(), USBPORT_SendSetupPacket(), USBPORT_SyncResetPipeAndClearStall(), and USBPORT_ValidateURB().

◆ USBPORT_Wait()

◆ USBPORT_WorkerRequestDpc()

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

Definition at line 701 of file usbport.c.

705{
706 PDEVICE_OBJECT FdoDevice;
708
709 DPRINT("USBPORT_WorkerRequestDpc: ...\n");
710
711 FdoDevice = DeferredContext;
712 FdoExtension = FdoDevice->DeviceExtension;
713
714 if (!InterlockedIncrement(&FdoExtension->IsrDpcHandlerCounter))
715 {
716 USBPORT_DpcHandler(FdoDevice);
717 }
718
719 InterlockedDecrement(&FdoExtension->IsrDpcHandlerCounter);
720}

Referenced by USBPORT_StartDevice().

◆ USBPORT_WorkerThread()

VOID NTAPI USBPORT_WorkerThread ( IN PVOID  StartContext)

Definition at line 1403 of file usbport.c.

1404{
1405 PDEVICE_OBJECT FdoDevice;
1407 LARGE_INTEGER OldTime;
1408 LARGE_INTEGER NewTime;
1409 KIRQL OldIrql;
1410
1411 DPRINT_CORE("USBPORT_WorkerThread ...\n");
1412
1413 FdoDevice = StartContext;
1414 FdoExtension = FdoDevice->DeviceExtension;
1415
1416 FdoExtension->WorkerThread = KeGetCurrentThread();
1417
1418 do
1419 {
1420 KeQuerySystemTime(&OldTime);
1421
1422 KeWaitForSingleObject(&FdoExtension->WorkerThreadEvent,
1423 Suspended,
1424 KernelMode,
1425 FALSE,
1426 NULL);
1427
1429 {
1430 break;
1431 }
1432
1433 KeQuerySystemTime(&NewTime);
1434
1435 KeAcquireSpinLock(&FdoExtension->WorkerThreadEventSpinLock, &OldIrql);
1436 KeClearEvent(&FdoExtension->WorkerThreadEvent);
1437 KeReleaseSpinLock(&FdoExtension->WorkerThreadEventSpinLock, OldIrql);
1438 DPRINT_CORE("USBPORT_WorkerThread: run\n");
1439
1441 {
1442 USBPORT_DoSetPowerD0(FdoDevice);
1443
1445 {
1446 PDEVICE_OBJECT USB2FdoDevice = NULL;
1447
1448 USB2FdoDevice = USBPORT_FindUSB2Controller(FdoDevice);
1449 USBPORT_SynchronizeRootHubCallback(FdoDevice, USB2FdoDevice);
1450 }
1451 }
1452
1453 USBPORT_WorkerThreadHandler(FdoDevice);
1454 }
1455 while (!(FdoExtension->Flags & USBPORT_FLAG_WORKER_THREAD_ON));
1456
1458}
VOID NTAPI USBPORT_DoSetPowerD0(IN PDEVICE_OBJECT FdoDevice)
Definition: power.c:104
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
#define KeGetCurrentThread
Definition: hal.h:55
NTSTATUS NTAPI PsTerminateSystemThread(IN NTSTATUS ExitStatus)
Definition: kill.c:1145
VOID NTAPI USBPORT_SynchronizeRootHubCallback(IN PDEVICE_OBJECT FdoDevice, IN PDEVICE_OBJECT Usb2FdoDevice)
Definition: usbport.c:1292
VOID NTAPI USBPORT_WorkerThreadHandler(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:1162
#define USBPORT_FLAG_WORKER_THREAD_ON
Definition: usbport.h:69
@ Suspended
Definition: ketypes.h:472

Referenced by USBPORT_CreateWorkerThread().

◆ USBPORT_WorkerThreadHandler()

VOID NTAPI USBPORT_WorkerThreadHandler ( IN PDEVICE_OBJECT  FdoDevice)

Definition at line 1162 of file usbport.c.

1163{
1166 PLIST_ENTRY workerList;
1167 KIRQL OldIrql;
1168 PUSBPORT_ENDPOINT Endpoint;
1171
1172 DPRINT_CORE("USBPORT_WorkerThreadHandler: ...\n");
1173
1174 FdoExtension = FdoDevice->DeviceExtension;
1175 Packet = &FdoExtension->MiniPortInterface->Packet;
1176
1177 KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
1178
1179 if (!(FdoExtension->Flags & USBPORT_FLAG_HC_SUSPEND))
1180 {
1181 Packet->CheckController(FdoExtension->MiniPortExt);
1182 }
1183
1184 KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
1185
1187
1188 USBPORT_FlushAllEndpoints(FdoDevice);
1189
1190 while (TRUE)
1191 {
1193 KeAcquireSpinLockAtDpcLevel(&FdoExtension->EndpointListSpinLock);
1194
1195 workerList = &FdoExtension->WorkerList;
1196
1197 if (IsListEmpty(workerList))
1198 break;
1199
1200 Endpoint = CONTAINING_RECORD(workerList->Flink,
1202 WorkerLink);
1203
1204 DPRINT_CORE("USBPORT_WorkerThreadHandler: Endpoint - %p\n", Endpoint);
1205
1206 RemoveHeadList(workerList);
1207 Endpoint->WorkerLink.Blink = NULL;
1208 Endpoint->WorkerLink.Flink = NULL;
1209
1210 KeReleaseSpinLockFromDpcLevel(&FdoExtension->EndpointListSpinLock);
1211
1212 Result = USBPORT_EndpointWorker(Endpoint, FALSE);
1213 KeAcquireSpinLockAtDpcLevel(&FdoExtension->EndpointListSpinLock);
1214
1215 if (Result)
1216 {
1217 if (Endpoint->FlushAbortLink.Flink == NULL ||
1218 Endpoint->FlushAbortLink.Blink == NULL)
1219 {
1220 InsertTailList(&list, &Endpoint->FlushAbortLink);
1221 }
1222 }
1223
1224 while (!IsListEmpty(&list))
1225 {
1226 Endpoint = CONTAINING_RECORD(list.Flink,
1228 FlushAbortLink);
1229
1231
1232 Endpoint->FlushAbortLink.Flink = NULL;
1233 Endpoint->FlushAbortLink.Blink = NULL;
1234
1235 if (Endpoint->WorkerLink.Flink == NULL ||
1236 Endpoint->WorkerLink.Blink == NULL)
1237 {
1238 InsertTailList(&FdoExtension->WorkerList,
1239 &Endpoint->WorkerLink);
1240
1241 USBPORT_SignalWorkerThread(FdoDevice);
1242 }
1243 }
1244
1245 KeReleaseSpinLockFromDpcLevel(&FdoExtension->EndpointListSpinLock);
1247 }
1248
1249 KeReleaseSpinLockFromDpcLevel(&FdoExtension->EndpointListSpinLock);
1251
1253}
Definition: list.h:37
VOID NTAPI USBPORT_FlushAllEndpoints(IN PDEVICE_OBJECT FdoDevice)
Definition: queue.c:1171
VOID NTAPI USBPORT_FlushClosedEndpointList(IN PDEVICE_OBJECT FdoDevice)
Definition: endpoint.c:1310
#define list
Definition: rosglue.h:35
LIST_ENTRY FlushAbortLink
Definition: usbport.h:238

Referenced by USBPORT_WorkerThread().

Variable Documentation

◆ USBPORT_Initialized

BOOLEAN USBPORT_Initialized = FALSE

Definition at line 23 of file usbport.c.

Referenced by USBPORT_RegisterUSBPortDriver().

◆ USBPORT_MiniPortDrivers

LIST_ENTRY USBPORT_MiniPortDrivers = {NULL, NULL}

Definition at line 18 of file usbport.c.

Referenced by USBPORT_FindMiniPort(), and USBPORT_RegisterUSBPortDriver().

◆ USBPORT_SpinLock

◆ USBPORT_USB1FdoList

LIST_ENTRY USBPORT_USB1FdoList = {NULL, NULL}

◆ USBPORT_USB2FdoList

LIST_ENTRY USBPORT_USB2FdoList = {NULL, NULL}