ReactOS 0.4.17-dev-1281-g065abb3
hostctl.h
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS USB Host Controller Extension
3 * LICENSE: MIT (https://spdx.org/licenses/MIT)
4 * PURPOSE: UCXCONTROLLER object
5 * COPYRIGHT: Copyright 2026 Justin Miller <justin.miller@reactos.org>
6 */
7
8#pragma once
9
10class UcxRootHub;
11class UcxUsbDevice;
12class UcxEndpoint;
13
14/* Callbacks carried in the Reserved slots of UCX_CONTROLLER_CONFIG */
15typedef
18 _In_ UCXCONTROLLER Controller);
19
20typedef
23(NTAPI *PFN_UCX_HCD_ENABLE_FORWARD_PROGRESS)(
24 _In_ UCXCONTROLLER Controller);
25
26typedef
29(NTAPI *PFN_UCX_HCD_GET_DUMP_DATA)(
30 _In_ UCXCONTROLLER Controller,
31 _In_ UCXUSBDEVICE UsbDevice,
34
35typedef
37VOID
38(NTAPI *PFN_UCX_HCD_FREE_DUMP_DATA)(
39 _In_ UCXCONTROLLER Controller,
41
42/* Accepted UCX_CONTROLLER_CONFIG sizes, oldest first */
43#define UCX_CONFIG_SIZE_V1 FIELD_OFFSET(UCX_CONTROLLER_CONFIG, ManufacturerNameString)
44#define UCX_CONFIG_SIZE_V3 FIELD_OFFSET(UCX_CONTROLLER_CONFIG, EvtControllerGetTransportCharacteristics)
45#define UCX_CONFIG_SIZE_V4 sizeof(UCX_CONTROLLER_CONFIG)
46
47/* Forward progress work item, also used by the reset machine to reach PASSIVE_LEVEL */
49{
61
62 static
68
69 VOID
70 Free();
71
72 VOID
73 Enqueue(
77
78 VOID
79 Flush();
80
81 VOID
82 Run();
83};
84
86
89{
91 UCXUSBDEVICE OwnerHub;
92 UCXUSBDEVICE OwnerDevice;
93};
94
96
99{
101};
102
104
105/* Tree walk callback, run under the topology lock */
106typedef
111
113{
114public:
115 /* Exports */
116
118 static
120 Create(
122 _In_ WDFDEVICE Device,
125 _Out_ UCXCONTROLLER* Controller);
126
127 VOID
128 NeedsReset();
129
130 VOID
133
134 VOID
135 SetFailed();
136
139 _In_ PUNICODE_STRING Manufacturer,
140 _In_ PUNICODE_STRING ModelName,
141 _In_ PUNICODE_STRING ModelNumber);
142
143 VOID
146
147 /* Lookups */
148
149 static
152 _In_ UCXCONTROLLER Handle);
153
154 static
156 FromFdo(
157 _In_ WDFDEVICE Fdo);
158
159 /* Reset references: keep a controller reset from starting while held */
160
161 BOOLEAN
162 BlockReset();
163
164 VOID
165 UnblockReset();
166
167 VOID
169
170 VOID
172
173 BOOLEAN
175 {
176 return m_ResetInProgress;
177 }
178
179 BOOLEAN
180 HasFailed() const
181 {
182 return m_Failed != 0;
183 }
184
188
189 /* HCD capability queries */
190
191 BOOLEAN
193
194 BOOLEAN
196
197 /* Controller reset machine glue */
198
199 VOID
202 {
204 }
205
206 VOID
208
209 VOID
211
213 VOID
215
216 /* Device tree, walked under the topology lock */
217
218 VOID
222 _In_ BOOLEAN IncludeDisconnected);
223
224 /* Hub interface functions that act on the controller */
225
226 VOID
228 _In_ UCXUSBDEVICE Hub);
229
231 StopIdle(
233
234 VOID
237
238 VOID
239 GetInfo(
241 _In_ BOOLEAN Grown);
242
243 /* NOTIFY_FORWARD_PROGRESS */
244
247 EnableForwardProgress(
249
250 VOID
253
254 BOOLEAN
256 {
257 return m_WorkerThread != NULL;
258 }
259
260 /* Private config slots */
261
264 {
266 }
267
268 PFN_UCX_HCD_ENABLE_FORWARD_PROGRESS
270 {
271 return (PFN_UCX_HCD_ENABLE_FORWARD_PROGRESS)m_Config.Reserved2;
272 }
273
274 PFN_UCX_HCD_GET_DUMP_DATA
276 {
277 return (PFN_UCX_HCD_GET_DUMP_DATA)m_Config.Reserved3;
278 }
279
280 PFN_UCX_HCD_FREE_DUMP_DATA
282 {
283 return (PFN_UCX_HCD_FREE_DUMP_DATA)m_Config.Reserved4;
284 }
285
286public:
287 UCXCONTROLLER m_Handle;
288 WDFDEVICE m_Fdo;
291
292 /* Queues on the controller driver's FDO, see hostqueues.cpp */
298
299 /* Symbolic link of GUID_DEVINTERFACE_USB_HOST_CONTROLLER */
301
304
305 /* Cancel synchronization for parked abort pipe URBs */
308
309 /* Guards every device and endpoint list of the tree */
313
317
324
332
335
338
339 /* Forward progress system thread */
348
350
351 /* One tree purge at a time, see devobj.cpp */
354
355 /* UcxControllerSetIdStrings, copies owned by the controller */
359
360private:
364 _In_ WDFDEVICE Fdo,
366
368 CreateQueues();
369
372
374 RegisterWmi();
375
376 static
377 EVT_WDF_OBJECT_CONTEXT_DESTROY EvtDestroy;
378
379 VOID
380 Destroy();
381
384
385 static
386 KSTART_ROUTINE WorkerThreadRoutine;
387
388 static
389 UCXHUB_WORKITEM_ROUTINE ResetMachinePassiveRoutine;
390
392};
393
395
396/* Queue handlers, hostqueues.cpp */
397EVT_WDF_IO_QUEUE_IO_INTERNAL_DEVICE_CONTROL UcxEvtAddress0IoInternalDeviceControl;
398EVT_WDF_IO_QUEUE_IO_INTERNAL_DEVICE_CONTROL UcxEvtDefaultIoInternalDeviceControl;
399EVT_WDF_IO_WDM_IRP_FOR_FORWARD_PROGRESS UcxEvtDefaultQueueExamineIrp;
400
401/* Abort pipe cancel safe queue callbacks */
402IO_CSQ_INSERT_IRP UcxCsqInsertAbortIrp;
403IO_CSQ_REMOVE_IRP UcxCsqRemoveAbortIrp;
404IO_CSQ_PEEK_NEXT_IRP UcxCsqPeekAbortIrp;
405IO_CSQ_ACQUIRE_LOCK UcxCsqAcquireAbortLock;
406IO_CSQ_RELEASE_LOCK UcxCsqReleaseAbortLock;
407IO_CSQ_COMPLETE_CANCELED_IRP UcxCsqCompleteCanceledAbortIrp;
#define VOID
Definition: acefi.h:82
unsigned char BOOLEAN
Definition: actypes.h:127
_In_ PATA_DEVICE_REQUEST _In_ BOOLEAN Allocate
Definition: ata_shared.h:437
LONG NTSTATUS
Definition: precomp.h:26
@ Create
Definition: registry.c:563
HubFdo * Hub
Definition: bootdev.cpp:261
BOOLEAN SmPost(_In_ Event Ev)
Definition: smengine.h:370
BOOLEAN m_ResetInitiated
Definition: hostctl.h:329
WDFDEVICE m_Fdo
Definition: hostctl.h:288
KMUTEX m_ForwardProgressMutex
Definition: hostctl.h:346
BOOLEAN BlockReset()
Definition: hostctl.cpp:507
VOID SetFailed()
Definition: hostctl.cpp:439
ULONG m_ResetGeneration
Definition: hostctl.h:326
PFN_UCX_HCD_ENABLE_FORWARD_PROGRESS HcdEnableForwardProgress() const
Definition: hostctl.h:269
KEVENT m_ResetCompleteProcessed
Definition: hostctl.h:319
static UcxController * FromFdo(_In_ WDFDEVICE Fdo)
Definition: hostctl.cpp:21
VOID PostResetEvent(_In_ CrEvent Event)
Definition: hostctl.h:200
NTSTATUS QueryHcCapabilities()
Definition: hostctl.cpp:239
WDFQUEUE m_DeviceMgmtQueue
Definition: hostctl.h:294
NTSTATUS StopIdle(_Inout_ PUCXHUB_STOP_IDLE_CONTEXT Context)
Definition: hostctl.cpp:663
UNICODE_STRING m_ModelNumber
Definition: hostctl.h:358
VOID NotifyTransportCharacteristicsChange(_In_ PUCX_CONTROLLER_TRANSPORT_CHARACTERISTICS Characteristics)
Definition: hostctl.cpp:498
VOID GetInfo(_Out_ PVOID Info, _In_ BOOLEAN Grown)
Definition: hostctl.cpp:692
BOOLEAN IsResetInProgress() const
Definition: hostctl.h:174
LONG m_UsbdInterfaceCount
Definition: hostctl.h:349
UcxRootHub * m_RootHub
Definition: hostctl.h:302
VOID ResumeIdle(_Inout_ PUCXHUB_STOP_IDLE_CONTEXT Context)
Definition: hostctl.cpp:680
VOID Destroy()
Definition: hostctl.cpp:364
BOOLEAN HasFailed() const
Definition: hostctl.h:180
BOOLEAN m_WaitOnResetComplete
Definition: hostctl.h:322
BOOLEAN HasWorkerThread() const
Definition: hostctl.h:255
LIST_ENTRY m_WorkerItems
Definition: hostctl.h:341
WDFQUEUE m_TreePurgeQueue
Definition: hostctl.h:295
VOID WalkDevices(_In_ PFN_UCX_DEVICE_VISITOR Visitor, _In_opt_ PVOID Context, _In_ BOOLEAN IncludeDisconnected)
Definition: hostreset.cpp:74
BOOLEAN m_ResetInProgress
Definition: hostctl.h:328
PKTHREAD m_WorkerThread
Definition: hostctl.h:342
VOID QueueOnWorkerThread(_In_ UcxWorkItem *WorkItem)
Definition: hostctl.cpp:811
NTSTATUS StartWorkerThread()
Definition: hostctl.cpp:772
ULONG m_ChildEndpointCount
Definition: hostctl.h:312
UCX_CONTROLLER_CONFIG m_Config
Definition: hostctl.h:289
BOOLEAN m_ClearTtBufferOnAsyncCancel
Definition: hostctl.h:337
static UcxController * FromHandle(_In_ UCXCONTROLLER Handle)
Definition: hostctl.cpp:14
ControllerResetMachine m_ResetMachine
Definition: hostctl.h:314
LONG m_RootHubResetSeen
Definition: hostctl.h:321
KSPIN_LOCK m_AbortPipeCsqLock
Definition: hostctl.h:307
VOID NotifyDevicesResetDone()
Definition: hostreset.cpp:110
BOOLEAN m_WorkerExit
Definition: hostctl.h:345
static UCXHUB_WORKITEM_ROUTINE ResetMachinePassiveRoutine
Definition: hostctl.h:389
VOID MarkResetFinished()
Definition: hostctl.cpp:551
LONG m_PendingPrepareForReset
Definition: hostctl.h:331
KSPIN_LOCK m_WorkerLock
Definition: hostctl.h:340
WDFREQUEST m_PendingTreePurge
Definition: hostctl.h:352
WDFQUEUE m_Address0Queue
Definition: hostctl.h:293
BOOLEAN QueryStreamsSupported()
Definition: hostctl.cpp:626
PFN_UCX_HCD_FREE_DUMP_DATA HcdFreeDumpData() const
Definition: hostctl.h:281
IO_CSQ m_AbortPipeCsq
Definition: hostctl.h:306
VOID MarkResetInProgress()
Definition: hostctl.cpp:542
PFN_UCX_HCD_GET_BANDWIDTH_INFORMATION HcdGetBandwidthInformation() const
Definition: hostctl.h:263
PFN_UCX_HCD_GET_DUMP_DATA HcdGetDumpData() const
Definition: hostctl.h:275
KSPIN_LOCK m_ResetLock
Definition: hostctl.h:325
UNICODE_STRING m_ModelName
Definition: hostctl.h:357
VOID NeedsReset()
Definition: hostctl.cpp:415
BOOLEAN m_ResetMachineReady
Definition: hostctl.h:315
NTSTATUS GetCurrentFrameNumber(_Out_ PULONG FrameNumber)
Definition: hostctl.cpp:564
UNICODE_STRING m_ManufacturerName
Definition: hostctl.h:356
KSPIN_LOCK m_TopologyLock
Definition: hostctl.h:310
VOID PrepareForResetOperationDone()
Definition: hostreset.cpp:124
ULONG m_SyntheticFrame
Definition: hostctl.h:334
_IRQL_requires_(PASSIVE_LEVEL) NTSTATUS EnableForwardProgress(_In_ PUCXHUB_FORWARD_PROGRESS_INFO Info)
BOOLEAN m_WorkerParked
Definition: hostctl.h:344
VOID PrepareDevicesForReset()
Definition: hostreset.cpp:86
KEVENT m_WorkerWake
Definition: hostctl.h:343
BOOLEAN m_HcdReservedIoReady
Definition: hostctl.h:347
LONG m_PendingTreePurgeEndpoints
Definition: hostctl.h:353
DEVICE_CAPABILITIES m_HcCaps
Definition: hostctl.h:303
LONG m_ResetBlockCount
Definition: hostctl.h:327
LONG m_DeviceContextsLost
Definition: hostctl.h:320
static EVT_WDF_OBJECT_CONTEXT_DESTROY EvtDestroy
Definition: hostctl.h:377
VOID UnblockReset()
Definition: hostctl.cpp:522
ULONG m_CachedFrameNumber
Definition: hostctl.h:333
BOOLEAN m_RootHubInD0
Definition: hostctl.h:323
UCXCONTROLLER m_Handle
Definition: hostctl.h:287
WDFQUEUE m_DefaultQueue
Definition: hostctl.h:297
BOOLEAN m_DriverVerifierEnabled
Definition: hostctl.h:336
VOID Address0Release(_In_ UCXUSBDEVICE Hub)
Definition: hostctl.cpp:647
static KSTART_ROUTINE WorkerThreadRoutine
Definition: hostctl.h:386
NTSTATUS RegisterWmi()
Definition: hostctl.cpp:289
LONG m_Failed
Definition: hostctl.h:330
LIST_ENTRY m_DriverListEntry
Definition: hostctl.h:290
WDFQUEUE m_PendDuringResetQueue
Definition: hostctl.h:296
KEVENT m_RootHubMayExitD0
Definition: hostctl.h:318
ULONG m_ChildDeviceCount
Definition: hostctl.h:311
BOOLEAN QueryClearTtBufferOnCancel()
Definition: hostctl.cpp:610
WDFSTRING m_HostControllerInterfaceName
Definition: hostctl.h:300
UcxWorkItem * m_ResetMachineWorkItem
Definition: hostctl.h:316
NTSTATUS CreateQueues()
Definition: hostqueues.cpp:58
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
CrEvent
Definition: crsm.h:15
_In_ ULONG Attributes
Definition: dispmprt.h:1077
_Check_return_ _In_ DXGK_EVENT_TYPE _In_ ULONG Event
Definition: dispmprt.h:1287
_In_ D3DDDI_VIDEO_PRESENT_TARGET_ID _In_ ULONG _In_ ULONG Flags
Definition: dispmprt.h:245
#define NULL
Definition: types.h:112
#define NTSTATUS
Definition: precomp.h:19
#define _IRQL_requires_(irql)
Definition: driverspecs.h:229
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
ULONG KSPIN_LOCK
Definition: env_spec_w32.h:72
_In_ FLT_SET_CONTEXT_OPERATION _In_ PFLT_CONTEXT NewContext
Definition: fltkernel.h:1468
pFxWorkItem Enqueue()
ULONG Handle
Definition: gdb_input.c:15
EVT_WDF_IO_QUEUE_IO_INTERNAL_DEVICE_CONTROL UcxEvtDefaultIoInternalDeviceControl
Definition: hostctl.h:398
_In_ UCXUSBDEVICE UsbDevice
Definition: hostctl.h:31
IO_CSQ_REMOVE_IRP UcxCsqRemoveAbortIrp
Definition: hostctl.h:403
IO_CSQ_COMPLETE_CANCELED_IRP UcxCsqCompleteCanceledAbortIrp
Definition: hostctl.h:407
VOID(NTAPI * PFN_UCX_DEVICE_VISITOR)(_In_ UcxUsbDevice *Device, _In_opt_ PVOID Context)
Definition: hostctl.h:108
IO_CSQ_INSERT_IRP UcxCsqInsertAbortIrp
Definition: hostctl.h:402
IO_CSQ_RELEASE_LOCK UcxCsqReleaseAbortLock
Definition: hostctl.h:406
EVT_WDF_IO_QUEUE_IO_INTERNAL_DEVICE_CONTROL UcxEvtAddress0IoInternalDeviceControl
Definition: hostctl.h:397
IO_CSQ_PEEK_NEXT_IRP UcxCsqPeekAbortIrp
Definition: hostctl.h:404
NTSTATUS(NTAPI * PFN_UCX_HCD_GET_BANDWIDTH_INFORMATION)(_In_ UCXCONTROLLER Controller)
Definition: hostctl.h:17
_In_ UCXUSBDEVICE _In_ PVOID _Out_ PVOID DumpControllerInfo
Definition: hostctl.h:33
_In_ UCXUSBDEVICE _In_ PVOID DumpDeviceInfo
Definition: hostctl.h:32
EVT_WDF_IO_WDM_IRP_FOR_FORWARD_PROGRESS UcxEvtDefaultQueueExamineIrp
Definition: hostctl.h:399
IO_CSQ_ACQUIRE_LOCK UcxCsqAcquireAbortLock
Definition: hostctl.h:405
_Must_inspect_result_ _In_ PUCXHUB_DEVICE_CREATE_INFO _Out_ UCXUSBDEVICE * Device
Definition: hubucx.h:258
UCXHUB_WORKITEM_ROUTINE * PUCXHUB_WORKITEM_ROUTINE
Definition: hubucx.h:228
_In_opt_ PVOID _In_ PUCXHUB_WORKITEM WorkItem
Definition: hubucx.h:227
enum _UCXHUB_WORKITEM_ENQUEUE_OPTIONS UCXHUB_WORKITEM_ENQUEUE_OPTIONS
_In_ PIRP _In_ PIO_COMPLETION_ROUTINE _In_ PVOID Context
Definition: kse.h:81
#define _Inout_
Definition: no_sal2.h:162
#define _Must_inspect_result_
Definition: no_sal2.h:62
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
#define _In_opt_
Definition: no_sal2.h:212
long LONG
Definition: pedump.c:60
UcxController * Controller
Definition: hostctl.h:90
UCXUSBDEVICE OwnerDevice
Definition: hostctl.h:92
UCXUSBDEVICE OwnerHub
Definition: hostctl.h:91
UcxController * Controller
Definition: hostctl.h:100
Definition: csq.h:222
Definition: typedefs.h:120
PVOID RoutineContext
Definition: hostctl.h:55
PUCXHUB_WORKITEM_ROUTINE Routine
Definition: hostctl.h:54
LIST_ENTRY ThreadQueueEntry
Definition: hostctl.h:50
ULONG RunningCount
Definition: hostctl.h:57
PIO_WORKITEM IoWorkItem
Definition: hostctl.h:53
PDEVICE_OBJECT DeviceObject
Definition: hostctl.h:52
KSPIN_LOCK Lock
Definition: hostctl.h:56
KEVENT Idle
Definition: hostctl.h:58
BOOLEAN NeedsFlush
Definition: hostctl.h:59
BOOLEAN Queued
Definition: hostctl.h:60
UcxController * Controller
Definition: hostctl.h:51
uint32_t * PULONG
Definition: typedefs.h:59
#define NTAPI
Definition: typedefs.h:36
uint32_t ULONG
Definition: typedefs.h:59
_Out_ PULONG FrameNumber
Definition: ucxcontroller.h:94
_Must_inspect_result_ _In_ WDFDEVICE _In_ PUCX_CONTROLLER_CONFIG _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ UCXCONTROLLER * Controller
_Must_inspect_result_ _In_ WDFDEVICE _In_ PUCX_CONTROLLER_CONFIG Config
SetIdStrings
ResetComplete
WDF_EXTERN_C_START struct _UCX_DRIVER_GLOBALS * PUCX_DRIVER_GLOBALS
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
Definition: wdfchildlist.h:690
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2061
_In_ PWDFDEVICE_INIT _In_ PWDF_REMOVE_LOCK_OPTIONS Options
Definition: wdfdevice.h:3540
_Must_inspect_result_ _In_ WDFDEVICE Fdo
Definition: wdffdo.h:461
#define WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(_contexttype, _castingfunction)
Definition: wdfobject.h:350
DEVICE_CAPABILITIES
Definition: iotypes.h:965
static void Initialize()
Definition: xlate.c:212