ReactOS 0.4.17-dev-1281-g065abb3
portconn.cpp File Reference
#include "usbhub3.h"
#include "hubid.h"
#include <debug.h>
Include dependency graph for portconn.cpp:

Go to the source code of this file.

Classes

struct  HubConnectorNode
 

Macros

#define NDEBUG
 
#define HUB_PROTOCOL_USB20   0x200
 
#define HUB_PROTOCOL_USB30   0x300
 

Functions

 _IRQL_requires_ (PASSIVE_LEVEL) VOID NTAPI HubConnectorLock(VOID)
 Sends a synchronous IOCTL to the specified device object.
 
static BOOLEAN NTAPI HubConnectorIdsEqual (_In_ const HubConnectorId *First, _In_ const HubConnectorId *Second)
 
static HubConnectorNode *NTAPI HubConnectorFindById (_In_ const HubConnectorId *Id)
 
static HubConnectorNode *NTAPI HubConnectorFindByPort (_In_ HubPort *Port)
 
static NTSTATUS NTAPI HubConnectorAddUsb20 (_Inout_ HubConnectorNode *Node, _In_ HubPort *Port)
 
static NTSTATUS NTAPI HubConnectorAddUsb30 (_Inout_ HubConnectorNode *Node, _In_ HubPort *Port)
 
HubPort *NTAPI HubConnectorFindCompanion (_In_ HubPort *Port, _In_ ULONG Index)
 
PVOID NTAPI HubConnectorNodeForPort (_In_ HubPort *Port)
 
static VOID NTAPI HubConnectorSetRootId (_In_ HubFdo *Hub, _Inout_ HubPort *Port, _In_ ULONG Usb30Port)
 
static VOID NTAPI HubConnectorCopyParentId (_In_ HubFdo *Hub, _Out_ HubConnectorId *Id)
 

Macro Definition Documentation

◆ HUB_PROTOCOL_USB20

#define HUB_PROTOCOL_USB20   0x200

Definition at line 14 of file portconn.cpp.

◆ HUB_PROTOCOL_USB30

#define HUB_PROTOCOL_USB30   0x300

Definition at line 15 of file portconn.cpp.

◆ NDEBUG

#define NDEBUG

Definition at line 11 of file portconn.cpp.

Function Documentation

◆ _IRQL_requires_()

_IRQL_requires_ ( PASSIVE_LEVEL  )

Sends a synchronous IOCTL to the specified device object.

Parameters
[in]IoControlCodeThe IOCTL to send to the device.
[in]DeviceObjectPointer to the device object that will handle the IOCTL.
[in]InputBufferOptional pointer to a buffer containing input data for the IOCTL. When specified, the buffer should be at least of InputBufferLength size.
[in]InputBufferLengthSize in bytes, of the buffer pointed by InputBuffer.
[out]OutputBufferOptional pointer to a buffer that will receive output data from the IOCTL. When specified, the buffer should be at least of OutputBufferLength size.
[in]OutputBufferLengthSize in bytes, of the buffer pointed by OutputBuffer.
[in]FileObjectOptional pointer to a file object that may be necessary for the IOCTL.
Returns
An NTSTATUS code indicating success or failure of this function.
Note
Must be called at PASSIVE_LEVEL with all APCs enabled.

Nothing is found unless the PCI bus driver publishes the properties.

The root hub name without its prefix; NULL when the PDO has no name.

Grows a private buffer to what the helper asks for.

Lets KMDF handle the IRP, then hands it back here still uncompleted.

Waits for the device machine to answer a PnP or power event; returns the PnP status.

Deletes the UCX endpoints of the disabled pipes, then the interface record.

One 4 byte value; the registry type is not checked.

Reread whenever user experience settings change; the open status is returned.

Sends a synchronous IOCTL to the specified device object.

STATUS_SUCCESS when the caller's token is an administrator's.

Sends a synchronous IOCTL to the specified device object.

Reads one value of a walk. A missing value only clears Present; FALSE means stop.

Reads up to Size bytes of a value into a zeroed buffer; the type is not checked.

Writes a REG_BINARY value into the device's usbflags subkey.

Sets or clears ExtPropertiesInstalled from ExtPropDescSemaphore in the hardware key.

Fails only when a port cannot be bound to the USB4 host router its ACPI node names.

Assigns device, hardware, compatible, container and instance ids to a new child PDO.

Answers IRP_MN_QUERY_DEVICE_TEXT on a child PDO; always completes the IRP.

Takes the connector map lock, needed around HubConnectorFindCompanion.

Device hardware key values read at PDO prepare hardware.

Saves the MS OS 2.0 set info in usbflags when the set asks for alternate enumeration.

MsOs20Flags and EnumerationRetryCount, written at PDO start.

Rereads the UXD record; UpdateRequired says whether the device id changes.

Replacement PnP id of a UXD reserved device, or an empty String. Always succeeds.

Telemetry values under the device's Ceip subkey.

BootPathSurpriseRemovalCount + 1.

This machine's dual role features for a dual role partner.

Tells UCX the WDM PDO of the device; call right after the child PDO was created.

IOCTL_INTERNAL_USB_GET_CONTROLLER_NAME: Argument1 and its length Argument2.

IOCTL_INTERNAL_USB_GET_BUS_INFO for the device: the 16 byte USB_BUS_NOTIFICATION at Argument1.

Registers the GUID_USB_WMI_NODE_INFO instance of a child PDO (not for hubs or composites).

Registers the boot device surprise removal event on an external, non hub boot PDO.

Fires the boot device surprise removal event, if one is registered.

Sends a synchronous IOCTL to the specified device object.

Publishes "<port>#<host>" for every bound port on the hub's PDO. QUIRK: with no bound port an older value is left in place.

Binds USB 3 ports to the host routers named by the USB4 DVSEC; an earlier ACPI mapping wins.

Waits on a PnP handshake event with no timeout, printing a watchdog line every minute so a stuck machine is visible in the debugger.

Copies up to Size bytes of a device property; a failed query leaves the field zero.

Only the controller name length is real; both bandwidth fields read 0.

The answer overlays a USB_HUB_NAME on TotalSize, so TotalSize comes back as the name length + 4.

Evaluates a method without arguments into Output.

Definition at line 30 of file portconn.cpp.

34{
36}
#define NULL
Definition: types.h:112
HubDriverState HubDriver
Definition: entry.cpp:13
WDFWAITLOCK CompanionPortLock
Definition: hubdriver.h:100
_Must_inspect_result_ FORCEINLINE NTSTATUS WdfWaitLockAcquire(_In_ _Requires_lock_not_held_(_Curr_) WDFWAITLOCK Lock, _In_opt_ PLONGLONG Timeout)
Definition: wdfsync.h:173

◆ HubConnectorAddUsb20()

static NTSTATUS NTAPI HubConnectorAddUsb20 ( _Inout_ HubConnectorNode *  Node,
_In_ HubPort *  Port 
)
static

Definition at line 122 of file portconn.cpp.

125{
127
128 if (Node->Usb20 != NULL)
129 {
130 DPRINT1("Port %u: connector already has a USB 2 port (platform compliance)\n", Port->Number());
131 return STATUS_UNSUCCESSFUL;
132 }
133
134 if (TypeC && Node->Usb30 != NULL && !Node->Usb30->HasProperty(PortProperty::TypeCWithoutSwitch))
135 {
136 DPRINT1("Port %u: Type-C USB 2 port paired with a different USB 3 connector type (platform compliance)\n",
137 Port->Number());
138 return STATUS_UNSUCCESSFUL;
139 }
140
141 if (TypeC)
142 Port->m_InstancePortNumber = Port->Number();
143
144 Node->Usb20 = Port;
145 return STATUS_SUCCESS;
146}
unsigned char BOOLEAN
Definition: actypes.h:127
#define DPRINT1
Definition: precomp.h:8
CPPORT Port[4]
Definition: headless.c:38
@ TypeC
Definition: miniport.h:115
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
Definition: dlist.c:348

◆ HubConnectorAddUsb30()

static NTSTATUS NTAPI HubConnectorAddUsb30 ( _Inout_ HubConnectorNode *  Node,
_In_ HubPort *  Port 
)
static

Definition at line 152 of file portconn.cpp.

155{
157 USHORT Shared;
158
159 if (Node->Usb30 == NULL)
160 {
161 if (TypeC && Node->Usb20 != NULL && !Node->Usb20->HasProperty(PortProperty::TypeCWithoutSwitch))
162 {
163 DPRINT1("Port %u: Type-C USB 3 port paired with a different USB 2 connector type (platform compliance)\n",
164 Port->Number());
165 return STATUS_UNSUCCESSFUL;
166 }
167
168 if (TypeC)
169 Port->m_InstancePortNumber = Port->Number();
170
171 Node->Usb30 = Port;
172 return STATUS_SUCCESS;
173 }
174
175 if (!TypeC ||
176 Node->Usb30Second != NULL ||
177 !Node->Usb30->HasProperty(PortProperty::TypeCWithoutSwitch))
178 {
179 DPRINT1("Port %u: connector has no room for another USB 3 port (platform compliance)\n", Port->Number());
180 return STATUS_UNSUCCESSFUL;
181 }
182
183 Shared = min(Port->Number(), Node->Usb30->Number());
184 Port->m_InstancePortNumber = Shared;
185 Node->Usb30->m_InstancePortNumber = Shared;
186 Node->Usb30Second = Port;
187 return STATUS_SUCCESS;
188}
#define min(a, b)
Definition: monoChain.cc:55
unsigned short USHORT
Definition: pedump.c:61

◆ HubConnectorCopyParentId()

static VOID NTAPI HubConnectorCopyParentId ( _In_ HubFdo *  Hub,
_Out_ HubConnectorId *  Id 
)
static

Definition at line 356 of file portconn.cpp.

359{
361
362 if (Parent != NULL)
363 *Id = *Parent;
364 else
365 RtlZeroMemory(Id, sizeof(*Id));
366}
DWORD Id
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn UINT32 *TableIdx UINT32 ACPI_TABLE_HEADER *OutTableHeader ACPI_TABLE_HEADER **OutTable ACPI_HANDLE UINT32 ACPI_WALK_CALLBACK ACPI_WALK_CALLBACK void void **ReturnValue UINT32 ACPI_BUFFER *RetPathPtr ACPI_OBJECT_HANDLER void *Data ACPI_OBJECT_HANDLER void **Data ACPI_STRING ACPI_OBJECT_LIST ACPI_BUFFER *ReturnObjectBuffer ACPI_DEVICE_INFO **ReturnBuffer ACPI_HANDLE Parent
Definition: acpixf.h:732
HubFdo * Hub
Definition: bootdev.cpp:261
UCXHUB_PARENT_INTERFACE m_Parent
Definition: fdo.h:355
if(dx< 0)
Definition: linetemp.h:194
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262

◆ HubConnectorFindById()

static HubConnectorNode *NTAPI HubConnectorFindById ( _In_ const HubConnectorId *  Id)
static

Definition at line 77 of file portconn.cpp.

79{
82
84 {
86 if (HubConnectorIdsEqual(&Node->Id, Id))
87 return Node;
88 }
89
90 return NULL;
91}
PLIST_ENTRY Entry
Definition: devhcd.cpp:1262
union node Node
Definition: types.h:1255
static BOOLEAN NTAPI HubConnectorIdsEqual(_In_ const HubConnectorId *First, _In_ const HubConnectorId *Second)
Definition: portconn.cpp:50
LIST_ENTRY ConnectorMap
Definition: hubdriver.h:99
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

◆ HubConnectorFindByPort()

static HubConnectorNode *NTAPI HubConnectorFindByPort ( _In_ HubPort *  Port)
static

Definition at line 97 of file portconn.cpp.

99{
102
103 if (!Port->HasProperty(PortProperty::InConnectorMap))
104 return NULL;
105
107 {
109 if (Node->Usb20 == Port || Node->Usb30 == Port || Node->Usb30Second == Port)
110 return Node;
111 }
112
113 return NULL;
114}

Referenced by HubConnectorFindCompanion(), and HubConnectorNodeForPort().

◆ HubConnectorFindCompanion()

HubPort *NTAPI HubConnectorFindCompanion ( _In_ HubPort *  Port,
_In_ ULONG  Index 
)

Companion port 0 or 1 sharing Port's connector, or NULL. Only valid under the map lock.

Definition at line 287 of file portconn.cpp.

290{
292
293 if (Index > 1)
294 {
295 DPRINT1("Companion index %lu out of range\n", Index);
296 return NULL;
297 }
298
300 if (Node == NULL)
301 {
302 if (Port->HasProperty(PortProperty::InConnectorMap))
303 DPRINT1("Port %u: registered port has no connector\n", Port->Number());
304
305 return NULL;
306 }
307
308 if (!Port->IsUsb30())
309 return (Index == 0) ? Node->Usb30 : Node->Usb30Second;
310
311 if (Index == 0)
312 return Node->Usb20;
313
314 return (Node->Usb30 == Port) ? Node->Usb30Second : Node->Usb30;
315}
static HubConnectorNode *NTAPI HubConnectorFindByPort(_In_ HubPort *Port)
Definition: portconn.cpp:97
_In_ WDFCOLLECTION _In_ ULONG Index

Referenced by HubIoGetConnectorProperties().

◆ HubConnectorIdsEqual()

static BOOLEAN NTAPI HubConnectorIdsEqual ( _In_ const HubConnectorId *  First,
_In_ const HubConnectorId *  Second 
)
static

Definition at line 50 of file portconn.cpp.

53{
55
56 if (First->Type != Second->Type ||
57 First->Depth != Second->Depth ||
58 First->TypeCConnectorId != Second->TypeCConnectorId ||
59 !RtlEqualMemory(First->Location, Second->Location, sizeof(First->Location)))
60 {
61 return FALSE;
62 }
63
65 {
66 if (First->Path[Index] != Second->Path[Index])
67 return FALSE;
68 }
69
70 return TRUE;
71}
WCHAR Second[]
Definition: FormatMessage.c:12
WCHAR First[]
Definition: FormatMessage.c:11
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define HUB_CONNECTOR_MAX_PATH
Definition: hubport.h:80
#define RtlEqualMemory(dst, src, len)
Definition: kdvm.h:18
uint32_t ULONG
Definition: typedefs.h:59

Referenced by HubConnectorFindById().

◆ HubConnectorNodeForPort()

PVOID NTAPI HubConnectorNodeForPort ( _In_ HubPort *  Port)

Connector map node of a port, or NULL when the port is not mapped.

Definition at line 320 of file portconn.cpp.

322{
324
325 if (!Port->HasProperty(PortProperty::InConnectorMap))
326 return NULL;
327
328 HubConnectorLock();
330 HubConnectorUnlock();
331
332 return Node;
333}

Referenced by DeviceMachine::AddChildToHub().

◆ HubConnectorSetRootId()

static VOID NTAPI HubConnectorSetRootId ( _In_ HubFdo *  Hub,
_Inout_ HubPort *  Port,
_In_ ULONG  Usb30Port 
)
static

Root port key without ACPI: the root hub number and the USB 3 port number.

Definition at line 341 of file portconn.cpp.

345{
346 RtlZeroMemory(&Port->m_ConnectorId, sizeof(Port->m_ConnectorId));
347 Port->m_ConnectorId.Type = HUB_CONNECTOR_ROOT;
348 RtlCopyMemory(Port->m_ConnectorId.Location, &Hub->m_HubNumber, sizeof(Hub->m_HubNumber));
349 Port->m_ConnectorId.Path[0] = Usb30Port;
350}
ULONG m_HubNumber
Definition: fdo.h:351
#define HUB_CONNECTOR_ROOT
Definition: hubport.h:76
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263