ReactOS 0.4.17-dev-1281-g065abb3
UcxRootHub Class Reference

#include <rhub.h>

Collaboration diagram for UcxRootHub:

Public Member Functions

VOID PortChanged ()
 
UcxUsbDevice * Device () const
 
VOID FailIo ()
 
VOID ResumeIo ()
 
VOID FinishPortResetRequest (_In_ BOOLEAN Succeeded)
 
NTSTATUS EnableForwardProgress ()
 
VOID DispatchGetInfo (_In_ WDFREQUEST Request, _Inout_ PUCXHUB_ROOTHUB_INFO Info)
 
NTSTATUS ReferenceSymbolicName (_Out_ WDFSTRING *Name)
 
WDFDEVICE Pdo () const
 

Static Public Member Functions

static _Must_inspect_result_ NTSTATUS Create (_In_ UCXCONTROLLER Controller, _In_ PUCX_ROOTHUB_CONFIG Config, _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes, _Out_ UCXROOTHUB *RootHub)
 
static UcxRootHub * FromHandle (_In_ UCXROOTHUB Handle)
 

Public Attributes

UCXROOTHUB m_Handle
 
UcxController * m_Controller
 
UCX_ROOTHUB_CONFIG m_Config
 
UcxUsbDevice * m_Device
 
UcxEndpoint * m_ControlEndpoint
 
UcxEndpoint * m_InterruptEndpoint
 
WDFQUEUE m_ControlQueue
 
WDFQUEUE m_InterruptQueue
 
UcxInterruptQueueState * m_InterruptState
 
USHORT m_NumberOf20Ports
 
USHORT m_NumberOf30Ports
 
WDF_DEVICE_PNP_CAPABILITIES m_PnpCaps
 
WDF_DEVICE_POWER_CAPABILITIES m_PowerCaps
 
KSPIN_LOCK m_PdoInfoLock
 
WDFDEVICE m_Pdo
 
BOOLEAN m_PdoStarted
 
WDFSTRING m_SymbolicName
 
PIRP m_PendingAsyncReset
 
SYSTEM_POWER_STATE m_LastSystemSleepState
 
POWER_ACTION m_SystemPowerAction
 

Private Member Functions

NTSTATUS Initialize (_In_ UcxController *Controller, _In_ PUCX_ROOTHUB_CONFIG Config)
 
NTSTATUS CreateEndpoint (_In_ BOOLEAN Interrupt)
 
NTSTATUS CreatePdo ()
 
VOID BuildPowerCapabilities ()
 
NTSTATUS AddQueryInterfaces ()
 

Static Private Attributes

static EVT_WDF_OBJECT_CONTEXT_CLEANUP EvtCleanup
 

Friends

class UcxRootHubPdo
 

Detailed Description

Definition at line 47 of file rhub.h.

Member Function Documentation

◆ AddQueryInterfaces()

NTSTATUS UcxRootHub::AddQueryInterfaces ( )
private

Definition at line 518 of file hubinterface.cpp.

519{
522 UCXHUB_STACK_INTERFACE StackTemplate;
523 USBD_CLIENT_INTERFACE ClientTemplate;
524 PNP_LOCATION_INTERFACE Location;
526
527 /* Templates use the smallest accepted size; KMDF rejects anything below it */
528 RtlZeroMemory(&ParentTemplate, sizeof(ParentTemplate));
529 ParentTemplate.Header.Size = sizeof(ParentTemplate);
532 (PINTERFACE)&ParentTemplate,
533 &GUID_UCXHUB_PARENT_INTERFACE,
535 Config.ImportInterface = TRUE;
536 Status = WdfDeviceAddQueryInterface(m_Pdo, &Config);
537 if (!NT_SUCCESS(Status))
538 {
539 DPRINT1("Root hub PDO %p parent interface add failed 0x%lx\n", m_Pdo, Status);
540 return Status;
541 }
542
543 RtlZeroMemory(&StackTemplate, sizeof(StackTemplate));
547 (PINTERFACE)&StackTemplate,
548 &GUID_UCXHUB_STACK_INTERFACE,
550 Config.ImportInterface = TRUE;
551 Status = WdfDeviceAddQueryInterface(m_Pdo, &Config);
552 if (!NT_SUCCESS(Status))
553 {
554 DPRINT1("Root hub PDO %p stack interface add failed 0x%lx\n", m_Pdo, Status);
555 return Status;
556 }
557
558 WDF_QUERY_INTERFACE_CONFIG_INIT(&Config, NULL, &USB_BUS_INTERFACE_USBDI_GUID, UcxEvtQueryUsbdiInterface);
559 Config.ImportInterface = TRUE;
560 Status = WdfDeviceAddQueryInterface(m_Pdo, &Config);
561 if (!NT_SUCCESS(Status))
562 {
563 DPRINT1("Root hub PDO %p USBDI interface add failed 0x%lx\n", m_Pdo, Status);
564 return Status;
565 }
566
567 RtlZeroMemory(&ClientTemplate, sizeof(ClientTemplate));
568 ClientTemplate.Header.Size = sizeof(ClientTemplate);
571 (PINTERFACE)&ClientTemplate,
572 &GUID_USBD_CLIENT_INTERFACE,
574 Config.ImportInterface = TRUE;
575 Status = WdfDeviceAddQueryInterface(m_Pdo, &Config);
576 if (!NT_SUCCESS(Status))
577 {
578 DPRINT1("Root hub PDO %p USBD client interface add failed 0x%lx\n", m_Pdo, Status);
579 return Status;
580 }
581
582 RtlZeroMemory(&Location, sizeof(Location));
583 Location.Size = sizeof(Location);
588 WDF_QUERY_INTERFACE_CONFIG_INIT(&Config, (PINTERFACE)&Location, &GUID_PNP_LOCATION_INTERFACE, NULL);
589 Config.ImportInterface = FALSE;
590
591 Status = WdfDeviceAddQueryInterface(m_Pdo, &Config);
592 if (!NT_SUCCESS(Status))
593 DPRINT1("Root hub PDO %p location interface add failed 0x%lx\n", m_Pdo, Status);
594
595 return Status;
596}
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
WDFDEVICE m_Pdo
Definition: rhub.h:135
#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
Status
Definition: gdiplustypes.h:24
static NTSTATUS NTAPI UcxGetLocationString(_Inout_ PVOID Context, _Outptr_ PZZWSTR *LocationStrings)
VOID NTAPI UcxInterfaceNoOp(_In_ PVOID Context)
#define UCXHUB_STACK_INTERFACE_SIZE_ORIGINAL
Definition: hubucx.h:469
#define UCXHUB_PARENT_INTERFACE_VERSION
Definition: hubucx.h:493
#define UCXHUB_STACK_INTERFACE_VERSION_1
Definition: hubucx.h:417
EVT_WDF_DEVICE_PROCESS_QUERY_INTERFACE_REQUEST UcxEvtQueryParentInterface
Definition: rhub.h:190
EVT_WDF_DEVICE_PROCESS_QUERY_INTERFACE_REQUEST UcxEvtQueryStackInterface
Definition: rhub.h:191
EVT_WDF_DEVICE_PROCESS_QUERY_INTERFACE_REQUEST UcxEvtQueryUsbdClientInterface
Definition: rhub.h:193
EVT_WDF_DEVICE_PROCESS_QUERY_INTERFACE_REQUEST UcxEvtQueryUsbdiInterface
Definition: rhub.h:192
USHORT Version
Definition: miniport.h:122
USHORT Size
Definition: miniport.h:121
PGET_LOCATION_STRING GetLocationString
Definition: iotypes.h:4559
PINTERFACE_REFERENCE InterfaceReference
Definition: iotypes.h:4557
PINTERFACE_DEREFERENCE InterfaceDereference
Definition: iotypes.h:4558
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
_Must_inspect_result_ _In_ WDFDEVICE _In_ PUCX_CONTROLLER_CONFIG Config
#define USBD_CLIENT_INTERFACE_VERSION
Definition: usbdclient.h:18
FORCEINLINE VOID WDF_QUERY_INTERFACE_CONFIG_INIT(_Out_ PWDF_QUERY_INTERFACE_CONFIG InterfaceConfig, _In_opt_ PINTERFACE Interface, _In_ CONST GUID *InterfaceType, _In_opt_ PFN_WDF_DEVICE_PROCESS_QUERY_INTERFACE_REQUEST EvtDeviceProcessQueryInterfaceRequest)
#define PNP_LOCATION_INTERFACE_VERSION
Definition: iotypes.h:5536

Referenced by AddQueryInterfaces(), and CreatePdo().

◆ BuildPowerCapabilities()

VOID UcxRootHub::BuildPowerCapabilities ( )
private

D2 is the wake state for every S state the controller can wake from.

Definition at line 87 of file rhubpdo.cpp.

88{
90 SYSTEM_POWER_STATE FirstWake;
92
101
102 FirstWake = (Hc->SystemWake == PowerSystemUnspecified) ? PowerSystemWorking : Hc->SystemWake;
103 m_PowerCaps.SystemWake = FirstWake;
104
106 {
107 if (State <= (ULONG)Hc->SystemWake && Hc->DeviceState[State] != PowerDeviceUnspecified)
108 {
110 if (FirstWake == PowerSystemShutdown)
112 }
113 else
114 {
116 }
117 }
118
119 /* Hybrid sleep: waking from S3 means waking from S4 too */
122 {
125 }
126}
DEVICE_CAPABILITIES m_HcCaps
Definition: hostctl.h:303
WDF_DEVICE_POWER_CAPABILITIES m_PowerCaps
Definition: rhub.h:131
UcxController * m_Controller
Definition: rhub.h:115
@ PowerSystemUnspecified
Definition: ntpoapi.h:35
@ PowerSystemSleeping1
Definition: ntpoapi.h:37
@ PowerSystemSleeping3
Definition: ntpoapi.h:39
@ PowerSystemShutdown
Definition: ntpoapi.h:41
@ PowerSystemWorking
Definition: ntpoapi.h:36
@ PowerSystemHibernate
Definition: ntpoapi.h:40
@ PowerDeviceUnspecified
Definition: ntpoapi.h:48
@ PowerDeviceD2
Definition: ntpoapi.h:51
@ PowerDeviceD3
Definition: ntpoapi.h:52
enum _SYSTEM_POWER_STATE SYSTEM_POWER_STATE
DEVICE_POWER_STATE DeviceWake
Definition: wdfdevice.h:1590
SYSTEM_POWER_STATE SystemWake
Definition: wdfdevice.h:1591
DEVICE_POWER_STATE DeviceState[PowerSystemMaximum]
Definition: wdfdevice.h:1584
uint32_t ULONG
Definition: typedefs.h:59
for(Attempt=0;Attempt< UCX_LEGACY_NAME_ATTEMPTS;Attempt++)
Definition: userreq.cpp:715
FORCEINLINE VOID WDF_DEVICE_POWER_CAPABILITIES_INIT(_Out_ PWDF_DEVICE_POWER_CAPABILITIES Caps)
Definition: wdfdevice.h:1612
@ WdfTrue
Definition: wdftypes.h:88
@ WdfFalse
Definition: wdftypes.h:87
DEVICE_CAPABILITIES
Definition: iotypes.h:965

Referenced by BuildPowerCapabilities(), and CreatePdo().

◆ Create()

_Must_inspect_result_ NTSTATUS UcxRootHub::Create ( _In_ UCXCONTROLLER  Controller,
_In_ PUCX_ROOTHUB_CONFIG  Config,
_In_opt_ PWDF_OBJECT_ATTRIBUTES  Attributes,
_Out_ UCXROOTHUB *  RootHub 
)
static

Definition at line 22 of file rhub.cpp.

27{
28 WDF_OBJECT_ATTRIBUTES UcxAttributes;
35
36 PAGED_CODE();
37
38 *RootHub = NULL;
39
42
43 if (Attributes != NULL)
44 Attributes->ParentObject = Controller;
45 else
46 UcxAttributes.ParentObject = Controller;
47
49 Attributes != NULL ? &UcxAttributes : NULL,
50 &Object);
51 if (!NT_SUCCESS(Status))
52 {
53 DPRINT1("Root hub object create failed 0x%lx\n", Status);
54 return Status;
55 }
56
57 Context = new (UcxGetRootHubContext(Object)) UcxRootHub();
58 Context->m_Handle = (UCXROOTHUB)Object;
59
60 /* The same handle doubles as the root hub's UCXUSBDEVICE */
63 if (NT_SUCCESS(Status))
64 {
65 Context->m_Device = new (DeviceContext) UcxUsbDevice();
66 Status = Context->Initialize(ControllerContext, Config);
67 }
68 else
69 {
70 DPRINT1("Root hub device context allocation failed 0x%lx\n", Status);
71 }
72
73 if (!NT_SUCCESS(Status))
74 {
76 return Status;
77 }
78
79 {
80 SpinLockGuard Guard(&ControllerContext->m_TopologyLock);
81
82 ControllerContext->m_RootHub = Context;
83 ControllerContext->m_ChildDeviceCount = 1;
84 }
85
86 *RootHub = Context->m_Handle;
87 DPRINT("Root hub %p created for controller %p\n", Context, ControllerContext);
88 return STATUS_SUCCESS;
89}
#define PAGED_CODE()
UcxRootHub * m_RootHub
Definition: hostctl.h:302
static UcxController * FromHandle(_In_ UCXCONTROLLER Handle)
Definition: hostctl.cpp:14
KSPIN_LOCK m_TopologyLock
Definition: hostctl.h:310
ULONG m_ChildDeviceCount
Definition: hostctl.h:311
static EVT_WDF_OBJECT_CONTEXT_CLEANUP EvtCleanup
Definition: rhub.h:165
UCXROOTHUB m_Handle
Definition: rhub.h:114
_In_ ULONG Attributes
Definition: dispmprt.h:1077
_In_ UCXHUB_DEVICE_CONTEXT DeviceContext
Definition: hubucx.h:237
_In_ PIRP _In_ PIO_COMPLETION_ROUTINE _In_ PVOID Context
Definition: kse.h:81
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
WDFOBJECT ParentObject
Definition: wdfobject.h:130
PFN_WDF_OBJECT_CONTEXT_CLEANUP EvtCleanupCallback
Definition: wdfobject.h:109
_Must_inspect_result_ _In_ WDFDEVICE _In_ PUCX_CONTROLLER_CONFIG _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ UCXCONTROLLER * Controller
_Must_inspect_result_ _In_ UCXCONTROLLER _In_ PUCX_ROOTHUB_CONFIG _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ UCXROOTHUB * RootHub
Definition: ucxroothub.h:299
_Must_inspect_result_ NTSTATUS NTAPI UcxCreateObjectWithTwoContexts(_In_ PWDF_OBJECT_ATTRIBUTES Primary, _In_opt_ PWDF_OBJECT_ATTRIBUTES Secondary, _Out_ WDFOBJECT *Object)
Definition: ucxutil.cpp:19
WdfObjectDelete(String)
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object
_Must_inspect_result_ _Inout_ PWDFDEVICE_INIT _In_opt_ PWDF_OBJECT_ATTRIBUTES DeviceAttributes
Definition: wdfdevice.h:3569
#define WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(_attributes, _contexttype)
Definition: wdfobject.h:170
FORCEINLINE NTSTATUS WdfObjectAllocateContext(_In_ WDFOBJECT Handle, _In_ PWDF_OBJECT_ATTRIBUTES ContextAttributes, _Outptr_opt_ PVOID *Context)
Definition: wdfobject.h:587

Referenced by Create().

◆ CreateEndpoint()

NTSTATUS UcxRootHub::CreateEndpoint ( _In_ BOOLEAN  Interrupt)
private

One of the two endpoints the hub talks to; their queues live on the controller FDO.

Definition at line 121 of file rhub.cpp.

123{
126 WDF_IO_QUEUE_CONFIG QueueConfig;
129 UCXENDPOINT EndpointHandle;
130 WDFQUEUE Queue;
132
133 if (Interrupt)
134 {
138 }
139 else
140 {
142 QueueConfig.Settings.Parallel.NumberOfPresentedRequests =
146 }
147 QueueAttributes.ParentObject = m_Handle;
148
149 Status = WdfIoQueueCreate(m_Controller->m_Fdo, &QueueConfig, &QueueAttributes, &Queue);
150 if (!NT_SUCCESS(Status))
151 {
152 DPRINT1("Root hub %s queue create failed 0x%lx\n", Interrupt ? "interrupt" : "control", Status);
153 return Status;
154 }
155
157 Status = WdfIoQueueAssignForwardProgressPolicy(Queue, &Policy);
158 if (!NT_SUCCESS(Status))
159 {
160 DPRINT1("Root hub %s queue forward progress setup failed 0x%lx\n", Interrupt ? "interrupt" : "control", Status);
161 return Status;
162 }
163
164 RtlZeroMemory(&Init, sizeof(Init));
165 Init.Kind = Interrupt ? UcxEndpointKind::Generic : UcxEndpointKind::Default;
166 Init.TransferType = Interrupt ? UcxTransferType::Interrupt : UcxTransferType::Control;
167 Init.Device = (UCXUSBDEVICE)m_Handle;
168 Init.CreateMachine = FALSE;
169
170 Status = UcxEndpoint::Create((UCXUSBDEVICE)m_Handle, &InitPointer, NULL, &EndpointHandle);
171 if (!NT_SUCCESS(Status))
172 {
173 DPRINT1("Root hub %s endpoint create failed 0x%lx\n", Interrupt ? "interrupt" : "control", Status);
174 return Status;
175 }
176
178
179 if (Interrupt)
180 {
181 UcxInterruptQueueState* State = UcxGetInterruptQueueState(Queue);
182
183 KeInitializeSpinLock(&State->PortChangeLock);
184
185 /* Different start values, so the very first transfer always reaches the HCD */
186 State->PortChangeGeneration = 1;
187 State->PortChangeGenerationProcessed = 0;
188 KeInitializeEvent(&State->NoIndicateWakeInProgress, NotificationEvent, TRUE);
189 State->RootHub = this;
190
194 DPRINT("Root hub %p interrupt endpoint %p\n", this, m_InterruptEndpoint);
195 }
196 else
197 {
198 UcxGetControlQueueContext(Queue)->RootHub = this;
199
202 DPRINT("Root hub %p control endpoint %p\n", this, m_ControlEndpoint);
203 }
204
205 return STATUS_SUCCESS;
206}
WDFDEVICE m_Fdo
Definition: hostctl.h:288
VOID SetWdfIoQueue(_In_ WDFQUEUE Queue)
Definition: pipe.cpp:313
static UcxEndpoint * FromHandle(_In_ UCXENDPOINT Handle)
Definition: pipe.cpp:91
static _Must_inspect_result_ NTSTATUS Create(_In_ UCXUSBDEVICE UsbDevice, _Inout_ PUCXENDPOINT_INIT *EndpointInit, _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes, _Out_ UCXENDPOINT *Endpoint)
Definition: pipe.cpp:195
UcxEndpoint * m_ControlEndpoint
Definition: rhub.h:121
WDFQUEUE m_InterruptQueue
Definition: rhub.h:124
WDFQUEUE m_ControlQueue
Definition: rhub.h:123
UcxInterruptQueueState * m_InterruptState
Definition: rhub.h:125
UCX_ROOTHUB_CONFIG m_Config
Definition: rhub.h:116
UcxEndpoint * m_InterruptEndpoint
Definition: rhub.h:122
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define KeInitializeSpinLock(sl)
Definition: env_spec_w32.h:604
@ NotificationEvent
EVT_WDF_IO_QUEUE_IO_INTERNAL_DEVICE_CONTROL UcxEvtRootHubControlTransfer
Definition: rhub.h:174
EVT_WDF_IO_QUEUE_IO_INTERNAL_DEVICE_CONTROL UcxEvtRootHubInterruptTransfer
Definition: rhub.h:173
ULONG NumberOfPresentedControlUrbCallbacks
Definition: ucxroothub.h:191
PFN_WDF_IO_QUEUE_IO_INTERNAL_DEVICE_CONTROL EvtIoInternalDeviceControl
Definition: wdfio.h:407
struct _WDF_IO_QUEUE_CONFIG::@4710::@4711 Parallel
union _WDF_IO_QUEUE_CONFIG::@4710 Settings
BOOL InitPointer(PPDEV ppdev)
Definition: pointer.c:143
_Must_inspect_result_ _In_ WDFDEVICE _In_ PIRP _In_ WDFQUEUE Queue
Definition: wdfdevice.h:2231
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_INTERRUPT_CONFIG _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFINTERRUPT * Interrupt
Definition: wdfinterrupt.h:379
_In_ WDFINTERRUPT _In_ WDF_INTERRUPT_POLICY Policy
Definition: wdfinterrupt.h:653
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_IO_QUEUE_CONFIG _In_opt_ PWDF_OBJECT_ATTRIBUTES QueueAttributes
Definition: wdfio.h:617
FORCEINLINE VOID WDF_IO_QUEUE_FORWARD_PROGRESS_POLICY_DEFAULT_INIT(_Out_ PWDF_IO_QUEUE_FORWARD_PROGRESS_POLICY Policy, _In_ ULONG TotalForwardProgressRequests)
Definition: wdfio.h:556
FORCEINLINE VOID WDF_IO_QUEUE_CONFIG_INIT(_Out_ PWDF_IO_QUEUE_CONFIG Config, _In_ WDF_IO_QUEUE_DISPATCH_TYPE DispatchType)
Definition: wdfio.h:426
@ WdfIoQueueDispatchSequential
Definition: wdfio.h:78
@ WdfIoQueueDispatchParallel
Definition: wdfio.h:79

Referenced by CreateEndpoint(), and Initialize().

◆ CreatePdo()

NTSTATUS UcxRootHub::CreatePdo ( )
private

Definition at line 129 of file rhubpdo.cpp.

130{
131 static const UNICODE_STRING InstanceId = RTL_CONSTANT_STRING(L"0\0");
132 static const UNICODE_STRING DeviceId = RTL_CONSTANT_STRING(UCX_ROOT_HUB_ID L"\0");
133 static UCHAR PnpMinor = IRP_MN_QUERY_INTERFACE;
134 static UCHAR PowerMinor = IRP_MN_SET_POWER;
136 WDF_PDO_EVENT_CALLBACKS PdoCallbacks;
138 WDF_IO_QUEUE_CONFIG QueueConfig;
139 PNP_BUS_INFORMATION BusInfo;
141 WCHAR NameBuffer[64];
142 UNICODE_STRING HardwareIds;
145 UcxRootHubPdoContext* PdoContext;
146 WDFDEVICE Pdo = NULL;
147 WDFDEVICE Fdo = m_Controller->m_Fdo;
148 ULONG Index;
150
151 BusInfo.BusTypeGuid = GUID_BUS_TYPE_USB;
152 BusInfo.LegacyBusType = PNPBus;
153 BusInfo.BusNumber = 0;
154 WdfDeviceSetBusInformationForChildren(Fdo, &BusInfo);
155
156 Init = WdfPdoInitAllocate(Fdo);
157 if (Init == NULL)
158 {
159 DPRINT1("Root hub PDO init allocation failed\n");
161 }
162
163 Status = WdfPdoInitAssignInstanceID(Init, &InstanceId);
164 if (NT_SUCCESS(Status))
165 Status = WdfPdoInitAssignDeviceID(Init, &DeviceId);
166 if (NT_SUCCESS(Status))
167 {
168 UcxBuildRootHubHardwareIds(&m_Controller->m_Config, IdBuffer, ARRAYSIZE(IdBuffer), &HardwareIds);
169 Status = WdfPdoInitAddHardwareID(Init, &HardwareIds);
170 }
171
172 if (NT_SUCCESS(Status))
173 {
174 /* The root hub's queues live on the controller FDO */
176
177 Status = WdfDeviceInitAssignWdmIrpPreprocessCallback(Init,
180 NULL,
181 0);
182 }
183 if (NT_SUCCESS(Status))
184 {
185 Status = WdfDeviceInitAssignWdmIrpPreprocessCallback(Init,
188 &PnpMinor,
189 1);
190 }
191 if (NT_SUCCESS(Status))
192 {
193 Status = WdfDeviceInitAssignWdmIrpPreprocessCallback(Init,
196 &PowerMinor,
197 1);
198 }
199
200 if (!NT_SUCCESS(Status))
201 {
202 DPRINT1("Root hub PDO ID or preprocess setup failed 0x%lx\n", Status);
203 WdfDeviceInitFree(Init);
204 return Status;
205 }
206
207 /* Every request reaching the HCD then carries the HCD's request context */
208 WdfDeviceInitSetRequestAttributes(Init, &m_Config.WdfRequestAttributes);
209
215 WdfDeviceInitSetPnpPowerEventCallbacks(Init, &PnpPower);
216
217 WDF_PDO_EVENT_CALLBACKS_INIT(&PdoCallbacks);
220 WdfPdoInitSetEventCallbacks(Init, &PdoCallbacks);
221
223
224 /* USBPDO-n is shared with the PDOs the hub creates; take the first free one */
225 for (Index = 0;; Index++)
226 {
227 Status = RtlStringCchPrintfW(NameBuffer, ARRAYSIZE(NameBuffer), L"\\Device\\USBPDO-%d", Index);
228 if (!NT_SUCCESS(Status))
229 break;
230
231 RtlInitUnicodeString(&Name, NameBuffer);
232 Status = WdfDeviceInitAssignName(Init, &Name);
233 if (!NT_SUCCESS(Status))
234 break;
235
236 Status = WdfDeviceInitAssignSDDLString(Init, &UcxRootHubPdoSddl);
237 if (!NT_SUCCESS(Status))
238 break;
239
240 Status = WdfDeviceCreate(&Init, &Attributes, &Pdo);
242 break;
243 }
244
245 if (!NT_SUCCESS(Status))
246 {
247 DPRINT1("Root hub PDO create failed at USBPDO-%lu 0x%lx\n", Index, Status);
248 if (Init != NULL)
249 WdfDeviceInitFree(Init);
250 return Status;
251 }
252
253 DPRINT("Root hub PDO %p is %wZ\n", Pdo, &Name);
254
255 /* User mode IOCTLs on the root hub PDO are not served */
258 Status = WdfIoQueueCreate(Pdo, &QueueConfig, WDF_NO_OBJECT_ATTRIBUTES, WDF_NO_HANDLE);
259 if (!NT_SUCCESS(Status))
260 {
261 DPRINT1("Root hub PDO %p queue create failed 0x%lx\n", Pdo, Status);
263 return Status;
264 }
265
270
273 m_PnpCaps.Address = 0;
275 WdfDeviceSetPnpCapabilities(Pdo, &m_PnpCaps);
276
278 WdfDeviceSetPowerCapabilities(Pdo, &m_PowerCaps);
279
280 PdoContext = UcxGetRootHubPdoContext(Pdo);
281 PdoContext->RootHub = this;
282 PdoContext->Controller = m_Controller;
284
285 Status = WdfDeviceCreateDeviceInterface(Pdo, &GUID_DEVINTERFACE_USB_HUB, NULL);
286 if (!NT_SUCCESS(Status))
287 {
288 DPRINT1("Root hub PDO %p hub interface create failed 0x%lx\n", Pdo, Status);
290 return Status;
291 }
292
293 {
295
296 m_Pdo = Pdo;
297 }
298
299 Status = WdfFdoAddStaticChild(Fdo, Pdo);
300 if (!NT_SUCCESS(Status))
301 {
302 DPRINT1("Root hub PDO %p static child add failed 0x%lx\n", Pdo, Status);
303 m_Pdo = NULL;
305 return Status;
306 }
307
308 /* From here the PDO belongs to the FDO and is not deleted on failure */
309 return AddQueryInterfaces();
310}
#define ARRAYSIZE(a)
Definition: cat.c:25
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
WdfPdoInitAllowForwardingRequestToParent(Init)
WdfDeviceSetSpecialFileSupport(Device, WdfSpecialFilePaging, TRUE)
UCX_CONTROLLER_CONFIG m_Config
Definition: hostctl.h:289
WDF_DEVICE_PNP_CAPABILITIES m_PnpCaps
Definition: rhub.h:130
VOID BuildPowerCapabilities()
Definition: rhubpdo.cpp:87
KSPIN_LOCK m_PdoInfoLock
Definition: rhub.h:134
POWER_ACTION m_SystemPowerAction
Definition: rhub.h:143
NTSTATUS AddQueryInterfaces()
WDFDEVICE Pdo() const
Definition: rhub.h:108
LPWSTR Name
Definition: desk.c:124
#define RTL_CONSTANT_STRING(s)
Definition: combase.c:35
#define L(x)
Definition: resources.c:13
_Must_inspect_result_ _In_opt_ PVOID _In_opt_ PVOID InstanceId
Definition: fsrtlfuncs.h:908
_In_ UCXUSBDEVICE _In_ PDEVICE_OBJECT Pdo
Definition: hubucx.h:280
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
@ PowerActionNone
Definition: ntpoapi.h:123
NTSTRSAFEVAPI RtlStringCchPrintfW(_Out_writes_(cchDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cchDest, _In_ _Printf_format_string_ NTSTRSAFE_PCWSTR pszFormat,...)
Definition: ntstrsafe.h:1110
short WCHAR
Definition: pedump.c:58
@ PNPBus
Definition: restypes.h:137
EVT_WDFDEVICE_WDM_IRP_PREPROCESS UcxEvtRootHubPreprocessInternalIoctl
Definition: rhub.h:184
EVT_WDF_DEVICE_PREPARE_HARDWARE UcxEvtRootHubPrepareHardware
Definition: rhub.h:178
EVT_WDF_DEVICE_RELEASE_HARDWARE UcxEvtRootHubReleaseHardware
Definition: rhub.h:179
EVT_WDF_DEVICE_DISABLE_WAKE_AT_BUS UcxEvtRootHubDisableWakeAtBus
Definition: rhub.h:183
EVT_WDF_IO_QUEUE_IO_DEVICE_CONTROL UcxEvtRootHubPdoIoDeviceControl
Definition: rhub.h:187
EVT_WDF_DEVICE_D0_ENTRY UcxEvtRootHubD0Entry
Definition: rhub.h:180
EVT_WDF_DEVICE_ENABLE_WAKE_AT_BUS UcxEvtRootHubEnableWakeAtBus
Definition: rhub.h:182
EVT_WDF_DEVICE_D0_EXIT UcxEvtRootHubD0Exit
Definition: rhub.h:181
EVT_WDFDEVICE_WDM_IRP_PREPROCESS UcxEvtRootHubPreprocessSetPower
Definition: rhub.h:186
EVT_WDFDEVICE_WDM_IRP_PREPROCESS UcxEvtRootHubPreprocessQueryInterface
Definition: rhub.h:185
#define UCX_ROOT_HUB_ID
Definition: rhubpdo.cpp:21
static VOID NTAPI UcxBuildRootHubHardwareIds(_In_ const UCX_CONTROLLER_CONFIG *Config, _Out_writes_(BufferChars) PWCHAR Buffer, _In_ SIZE_T BufferChars, _Out_ PUNICODE_STRING Ids)
Definition: rhubpdo.cpp:44
#define UCX_HWID_BUFFER_CHARS
Definition: rhubpdo.cpp:30
UcxController * Controller
Definition: rhub.h:42
UcxRootHub * RootHub
Definition: rhub.h:41
INTERFACE_TYPE LegacyBusType
Definition: cmtypes.h:366
WDF_OBJECT_ATTRIBUTES WdfRequestAttributes
Definition: ucxroothub.h:204
PFN_WDF_IO_QUEUE_IO_DEVICE_CONTROL EvtIoDeviceControl
Definition: wdfio.h:405
PFN_WDF_DEVICE_ENABLE_WAKE_AT_BUS EvtDeviceEnableWakeAtBus
Definition: wdfpdo.h:181
PFN_WDF_DEVICE_DISABLE_WAKE_AT_BUS EvtDeviceDisableWakeAtBus
Definition: wdfpdo.h:187
PFN_WDF_DEVICE_D0_ENTRY EvtDeviceD0Entry
Definition: wdfdevice.h:1164
PFN_WDF_DEVICE_D0_EXIT EvtDeviceD0Exit
Definition: wdfdevice.h:1166
PFN_WDF_DEVICE_PREPARE_HARDWARE EvtDevicePrepareHardware
Definition: wdfdevice.h:1168
PFN_WDF_DEVICE_RELEASE_HARDWARE EvtDeviceReleaseHardware
Definition: wdfdevice.h:1169
unsigned char UCHAR
Definition: typedefs.h:53
#define STATUS_OBJECT_NAME_COLLISION
Definition: udferr_usr.h:150
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ WDFCOLLECTION _In_ ULONG Index
FORCEINLINE VOID WDF_DEVICE_PNP_CAPABILITIES_INIT(_Out_ PWDF_DEVICE_PNP_CAPABILITIES Caps)
Definition: wdfdevice.h:1545
@ WdfSpecialFileBoot
Definition: wdfdevice.h:445
@ WdfSpecialFileHibernation
Definition: wdfdevice.h:443
@ WdfSpecialFileDump
Definition: wdfdevice.h:444
@ WdfSpecialFilePaging
Definition: wdfdevice.h:442
FORCEINLINE VOID WDF_PNPPOWER_EVENT_CALLBACKS_INIT(_Out_ PWDF_PNPPOWER_EVENT_CALLBACKS Callbacks)
Definition: wdfdevice.h:1214
_Must_inspect_result_ _In_ WDFDEVICE Fdo
Definition: wdffdo.h:461
FORCEINLINE VOID WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE(_Out_ PWDF_IO_QUEUE_CONFIG Config, _In_ WDF_IO_QUEUE_DISPATCH_TYPE DispatchType)
Definition: wdfio.h:443
FORCEINLINE VOID WDF_PDO_EVENT_CALLBACKS_INIT(_Out_ PWDF_PDO_EVENT_CALLBACKS Callbacks)
Definition: wdfpdo.h:199
#define WDF_NO_HANDLE
Definition: wdftypes.h:107
#define WDF_NO_OBJECT_ATTRIBUTES
Definition: wdftypes.h:105
#define IRP_MN_QUERY_INTERFACE
#define IRP_MN_SET_POWER
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
#define IRP_MJ_POWER

Referenced by CreatePdo(), and Initialize().

◆ Device()

UcxUsbDevice * UcxRootHub::Device ( ) const
inline

Definition at line 71 of file rhub.h.

72 {
73 return m_Device;
74 }
UcxUsbDevice * m_Device
Definition: rhub.h:119

Referenced by UcxController::SetFailed(), and UcxController::WalkDevices().

◆ DispatchGetInfo()

VOID UcxRootHub::DispatchGetInfo ( _In_ WDFREQUEST  Request,
_Inout_ PUCXHUB_ROOTHUB_INFO  Info 
)

Definition at line 526 of file rhub.cpp.

529{
530 /* The HCD only knows ROOTHUB_INFO; the completion routine restores the size */
531 Info->Info.Size = sizeof(Info->Info);
532 Info->InterruptPipe = m_InterruptEndpoint->m_Pipe.Handle();
533
534 DPRINT("Root hub %p GetInfo request %p to HCD\n", this, Request);
536}
UcxPipe m_Pipe
Definition: pipe.h:284
USBD_PIPE_HANDLE Handle()
Definition: pipe.h:60
PFN_UCX_ROOTHUB_GET_INFO EvtRootHubGetInfo
Definition: ucxroothub.h:201
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFREQUEST Request
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
Definition: wdfchildlist.h:690

Referenced by DispatchGetInfo().

◆ EnableForwardProgress()

NTSTATUS UcxRootHub::EnableForwardProgress ( )
inline

Definition at line 90 of file rhub.h.

91 {
92 return STATUS_SUCCESS;
93 }

Referenced by _IRQL_requires_().

◆ FailIo()

VOID UcxRootHub::FailIo ( )

Definition at line 477 of file rhub.cpp.

478{
479 DPRINT("Root hub %p failing I/O for controller reset\n", this);
480 WdfIoQueuePurge(m_InterruptQueue, NULL, NULL);
481 WdfIoQueuePurge(m_ControlQueue, NULL, NULL);
482}

Referenced by FailIo(), and ControllerResetMachine::FailRootHubIo().

◆ FinishPortResetRequest()

VOID UcxRootHub::FinishPortResetRequest ( _In_ BOOLEAN  Succeeded)

Definition at line 500 of file rhub.cpp.

502{
505
507
509 Flags->AsUlong = 0;
510
512 Flags->HostContextLost = 1;
513
515
516 if (!Succeeded)
517 DPRINT1("Root hub %p async reset IRP %p failed\n", this, Irp);
518
519 Irp->IoStatus.Status = Succeeded ? STATUS_SUCCESS : STATUS_NO_SUCH_DEVICE;
520 Irp->IoStatus.Information = 0;
522}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
#define InterlockedExchange
Definition: armddk.h:54
LONG m_RootHubResetSeen
Definition: hostctl.h:321
LONG m_DeviceContextsLost
Definition: hostctl.h:320
PIRP m_PendingAsyncReset
Definition: rhub.h:140
_In_ D3DDDI_VIDEO_PRESENT_TARGET_ID _In_ ULONG _In_ ULONG Flags
Definition: dispmprt.h:245
union _UCXHUB_RESET_FLAGS * PUCXHUB_RESET_FLAGS
_In_ PIRP Irp
Definition: kse.h:79
if(dx< 0)
Definition: linetemp.h:194
#define IoCompleteRequest
Definition: irp.c:1272
struct _IO_STACK_LOCATION::@5100::@5139 Others
union _IO_STACK_LOCATION::@1823 Parameters
#define STATUS_NO_SUCH_DEVICE
Definition: udferr_usr.h:136
#define IO_NO_INCREMENT
Definition: iotypes.h:598

Referenced by ControllerResetMachine::CompleteHubReset(), and FinishPortResetRequest().

◆ FromHandle()

UcxRootHub * UcxRootHub::FromHandle ( _In_ UCXROOTHUB  Handle)
static

Definition at line 14 of file rhub.cpp.

16{
17 return UcxGetRootHubContext(Handle);
18}
ULONG Handle
Definition: gdb_input.c:15

Referenced by FromHandle().

◆ Initialize()

NTSTATUS UcxRootHub::Initialize ( _In_ UcxController *  Controller,
_In_ PUCX_ROOTHUB_CONFIG  Config 
)
private

Definition at line 92 of file rhub.cpp.

95{
97
100
101 /* The HCD's size is trusted only as far as the structure we know */
103 RtlCopyMemory(&m_Config, Config, min(Config->Size, (ULONG)sizeof(m_Config)));
104
105 /* Speed is set first so the endpoints get the SuperSpeed transfer limits */
107
109 if (!NT_SUCCESS(Status))
110 return Status;
111
113 if (!NT_SUCCESS(Status))
114 return Status;
115
116 return CreatePdo();
117}
NTSTATUS CreatePdo()
Definition: rhubpdo.cpp:129
NTSTATUS CreateEndpoint(_In_ BOOLEAN Interrupt)
Definition: rhub.cpp:121
VOID InitializeAsRootHub(_In_ UCXROOTHUB Handle, _In_ UcxController *Controller)
Definition: devobj.cpp:50
#define min(a, b)
Definition: monoChain.cc:55
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263

Referenced by Initialize().

◆ Pdo()

WDFDEVICE UcxRootHub::Pdo ( ) const
inline

Definition at line 108 of file rhub.h.

109 {
110 return m_Pdo;
111 }

Referenced by UcxEndpoint::CloseStaticStreams(), CreatePdo(), and UcxEndpoint::OpenStaticStreams().

◆ PortChanged()

VOID UcxRootHub::PortChanged ( )

Port change from the HCD, or one the reset machine simulates.

Definition at line 227 of file rhub.cpp.

228{
230 WDFREQUEST Release = NULL;
231 BOOLEAN IndicateWake;
232
233 DPRINT("Root hub %p port change\n", this);
234
235 {
236 SpinLockGuard Guard(&State->PortChangeLock);
237
238 State->PortChangeGeneration++;
239
240 /* If the cancel routine already owns the held transfer, it completes it */
241 if (State->HeldTransfer != NULL &&
242 NT_SUCCESS(WdfRequestUnmarkCancelable(State->HeldTransfer)))
243 {
244 Release = State->HeldTransfer;
245 State->HeldTransfer = NULL;
246 State->PortChangeGenerationProcessed = State->PortChangeGeneration;
247 }
248
249 IndicateWake = State->IndicateWakeEnabled;
250 if (IndicateWake)
251 KeClearEvent(&State->NoIndicateWakeInProgress);
252 }
253
254 if (IndicateWake)
255 {
256 /* Raised so a D0 IRP the wake triggers never runs inline on this thread */
257 {
258 DispatchLevelGuard Raise;
259
260 WdfDeviceIndicateWakeStatus(m_Pdo, STATUS_SUCCESS);
261 }
262 KeSetEvent(&State->NoIndicateWakeInProgress, IO_NO_INCREMENT, FALSE);
263 }
264
265 if (Release == NULL)
266 return;
267
268 if (!m_Controller->BlockReset())
269 {
270 DPRINT1("Root hub %p failing held status change transfer %p, controller resetting\n", this, Release);
271 WdfRequestComplete(Release, STATUS_NO_SUCH_DEVICE);
272 return;
273 }
274
277}
unsigned char BOOLEAN
Definition: actypes.h:127
_In_ BOOLEAN Release
Definition: cdrom.h:920
BOOLEAN BlockReset()
Definition: hostctl.cpp:507
VOID UnblockReset()
Definition: hostctl.cpp:522
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
PFN_UCX_ROOTHUB_INTERRUPT_TX EvtRootHubInterruptTx
Definition: ucxroothub.h:200

Referenced by PortChanged(), ControllerResetMachine::SignalPortChange(), and UcxApiRootHubPortChanged().

◆ ReferenceSymbolicName()

NTSTATUS UcxRootHub::ReferenceSymbolicName ( _Out_ WDFSTRING *  Name)

Hands out the root hub's interface name with a reference the caller drops.

Definition at line 540 of file rhub.cpp.

542{
544
546 {
547 *Name = NULL;
548 return STATUS_UNSUCCESSFUL;
549 }
550
553 return STATUS_SUCCESS;
554}
WDFSTRING m_SymbolicName
Definition: rhub.h:137
BOOLEAN m_PdoStarted
Definition: rhub.h:136
#define UCX_POOL_TAG
Definition: ucxutil.h:11
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define WdfObjectReferenceWithTag(Handle, Tag)
Definition: wdfobject.h:806

Referenced by ReferenceSymbolicName().

◆ ResumeIo()

VOID UcxRootHub::ResumeIo ( )

Definition at line 485 of file rhub.cpp.

486{
487 {
489
490 /* The next status change transfer goes to the HCD even if flagged */
492 }
493
494 DPRINT("Root hub %p resuming I/O\n", this);
495 WdfIoQueueStart(m_InterruptQueue);
496 WdfIoQueueStart(m_ControlQueue);
497}
KSPIN_LOCK PortChangeLock
Definition: rhub.h:13
USHORT PortChangeGeneration
Definition: rhub.h:16

Referenced by ResumeIo(), and ControllerResetMachine::UnblockRootHubTraffic().

Friends And Related Function Documentation

◆ UcxRootHubPdo

friend class UcxRootHubPdo
friend

Definition at line 167 of file rhub.h.

Member Data Documentation

◆ EvtCleanup

VOID UcxRootHub::EvtCleanup
staticprivate

Definition at line 165 of file rhub.h.

Referenced by Create().

◆ m_Config

UCX_ROOTHUB_CONFIG UcxRootHub::m_Config

Definition at line 116 of file rhub.h.

Referenced by CreateEndpoint(), CreatePdo(), DispatchGetInfo(), Initialize(), and PortChanged().

◆ m_ControlEndpoint

UcxEndpoint* UcxRootHub::m_ControlEndpoint

Definition at line 121 of file rhub.h.

Referenced by CreateEndpoint().

◆ m_Controller

◆ m_ControlQueue

WDFQUEUE UcxRootHub::m_ControlQueue

Definition at line 123 of file rhub.h.

Referenced by CreateEndpoint(), FailIo(), and ResumeIo().

◆ m_Device

UcxUsbDevice* UcxRootHub::m_Device

Definition at line 119 of file rhub.h.

Referenced by Device(), and Initialize().

◆ m_Handle

UCXROOTHUB UcxRootHub::m_Handle

Definition at line 114 of file rhub.h.

Referenced by Create(), CreateEndpoint(), DispatchGetInfo(), Initialize(), and PortChanged().

◆ m_InterruptEndpoint

UcxEndpoint* UcxRootHub::m_InterruptEndpoint

Definition at line 122 of file rhub.h.

Referenced by CreateEndpoint(), and DispatchGetInfo().

◆ m_InterruptQueue

WDFQUEUE UcxRootHub::m_InterruptQueue

Definition at line 124 of file rhub.h.

Referenced by CreateEndpoint(), FailIo(), and ResumeIo().

◆ m_InterruptState

UcxInterruptQueueState* UcxRootHub::m_InterruptState

Definition at line 125 of file rhub.h.

Referenced by CreateEndpoint(), PortChanged(), and ResumeIo().

◆ m_LastSystemSleepState

SYSTEM_POWER_STATE UcxRootHub::m_LastSystemSleepState

Definition at line 142 of file rhub.h.

◆ m_NumberOf20Ports

USHORT UcxRootHub::m_NumberOf20Ports

Definition at line 127 of file rhub.h.

◆ m_NumberOf30Ports

USHORT UcxRootHub::m_NumberOf30Ports

Definition at line 128 of file rhub.h.

◆ m_Pdo

WDFDEVICE UcxRootHub::m_Pdo

Definition at line 135 of file rhub.h.

Referenced by AddQueryInterfaces(), CreatePdo(), Pdo(), and PortChanged().

◆ m_PdoInfoLock

KSPIN_LOCK UcxRootHub::m_PdoInfoLock

Definition at line 134 of file rhub.h.

Referenced by CreatePdo(), Initialize(), and ReferenceSymbolicName().

◆ m_PdoStarted

BOOLEAN UcxRootHub::m_PdoStarted

Definition at line 136 of file rhub.h.

Referenced by ReferenceSymbolicName().

◆ m_PendingAsyncReset

PIRP UcxRootHub::m_PendingAsyncReset

Definition at line 140 of file rhub.h.

Referenced by FinishPortResetRequest().

◆ m_PnpCaps

WDF_DEVICE_PNP_CAPABILITIES UcxRootHub::m_PnpCaps

Definition at line 130 of file rhub.h.

Referenced by CreatePdo().

◆ m_PowerCaps

WDF_DEVICE_POWER_CAPABILITIES UcxRootHub::m_PowerCaps

Definition at line 131 of file rhub.h.

Referenced by BuildPowerCapabilities(), and CreatePdo().

◆ m_SymbolicName

WDFSTRING UcxRootHub::m_SymbolicName

Definition at line 137 of file rhub.h.

Referenced by ReferenceSymbolicName().

◆ m_SystemPowerAction

POWER_ACTION UcxRootHub::m_SystemPowerAction

Definition at line 143 of file rhub.h.

Referenced by CreatePdo().


The documentation for this class was generated from the following files: