ReactOS 0.4.17-dev-1037-g720d112
controller.cpp File Reference
#include "usbxhci.h"
#include <debug.h>
Include dependency graph for controller.cpp:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

 _IRQL_requires_ (PASSIVE_LEVEL) static NTSTATUS NTAPI XhciCreateUcxController(_In_ PXHCI_CONTROLLER Controller)
 Sends a synchronous IOCTL to the specified device object.
 
NTSTATUS NTAPI XhciEvtDeviceAdd (_In_ WDFDRIVER Driver, _Inout_ PWDFDEVICE_INIT DeviceInit)
 
NTSTATUS NTAPI XhciEvtDevicePrepareHardware (_In_ WDFDEVICE Device, _In_ WDFCMRESLIST ResourcesRaw, _In_ WDFCMRESLIST ResourcesTranslated)
 
NTSTATUS NTAPI XhciEvtDeviceReleaseHardware (_In_ WDFDEVICE Device, _In_ WDFCMRESLIST ResourcesTranslated)
 
NTSTATUS NTAPI XhciEvtDeviceD0Entry (_In_ WDFDEVICE Device, _In_ WDF_POWER_DEVICE_STATE PreviousState)
 
NTSTATUS NTAPI XhciEvtDeviceD0Exit (_In_ WDFDEVICE Device, _In_ WDF_POWER_DEVICE_STATE TargetState)
 
VOID NTAPI XhciEvtIoDeviceControl (_In_ WDFQUEUE Queue, _In_ WDFREQUEST Request, _In_ size_t OutputBufferLength, _In_ size_t InputBufferLength, _In_ ULONG IoControlCode)
 
NTSTATUS NTAPI XhciEvtControllerQueryUsbCapability (_In_ UCXCONTROLLER UcxController, _In_ PGUID CapabilityType, _In_ ULONG OutputBufferLength, _Out_writes_bytes_opt_(OutputBufferLength) PVOID OutputBuffer, _Out_ PULONG ResultLength)
 
NTSTATUS NTAPI XhciEvtControllerGetCurrentFrameNumber (_In_ UCXCONTROLLER UcxController, _Out_ PULONG FrameNumber)
 
VOID NTAPI XhciEvtControllerReset (_In_ UCXCONTROLLER UcxController)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 10 of file controller.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.

Definition at line 13 of file controller.cpp.

19{
23
24 UCX_CONTROLLER_CONFIG_INIT(&Config, "ReactOS xHCI Host Controller");
25 Config.EvtControllerQueryUsbCapability = XhciEvtControllerQueryUsbCapability;
26 Config.EvtControllerGetCurrentFrameNumber = XhciEvtControllerGetCurrentFrameNumber;
27 Config.EvtControllerUsbDeviceAdd = XhciEvtControllerUsbDeviceAdd;
28 Config.EvtControllerReset = XhciEvtControllerReset;
29
31
32 Status = UcxControllerCreate(Controller->Device, &Config, &Attributes, &Controller->UcxController);
33 if (!NT_SUCCESS(Status))
34 {
35 DPRINT1("UcxControllerCreate failed 0x%lx\n", Status);
36 return Status;
37 }
38
39 XhciGetUcxControllerContext(Controller->UcxController)->Controller = Controller;
40 return STATUS_SUCCESS;
41}
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
_In_ ULONG Attributes
Definition: dispmprt.h:1077
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
Status
Definition: gdiplustypes.h:24
#define STATUS_SUCCESS
Definition: shellext.h:65
_Must_inspect_result_ _In_ WDFDEVICE _In_ PUCX_CONTROLLER_CONFIG _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ UCXCONTROLLER * Controller
FORCEINLINE VOID NTAPI UCX_CONTROLLER_CONFIG_INIT(_Out_ PUCX_CONTROLLER_CONFIG Config, _In_ LPCSTR DeviceDescription)
_Must_inspect_result_ _In_ WDFDEVICE _In_ PUCX_CONTROLLER_CONFIG Config
EVT_UCX_CONTROLLER_GET_CURRENT_FRAMENUMBER XhciEvtControllerGetCurrentFrameNumber
Definition: usbxhci.h:46
EVT_UCX_CONTROLLER_QUERY_USB_CAPABILITY XhciEvtControllerQueryUsbCapability
Definition: usbxhci.h:45
EVT_UCX_CONTROLLER_USBDEVICE_ADD XhciEvtControllerUsbDeviceAdd
Definition: usbxhci.h:70
EVT_UCX_CONTROLLER_RESET XhciEvtControllerReset
Definition: usbxhci.h:47
#define WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(_attributes, _contexttype)
Definition: wdfobject.h:170

◆ XhciEvtControllerGetCurrentFrameNumber()

NTSTATUS NTAPI XhciEvtControllerGetCurrentFrameNumber ( _In_ UCXCONTROLLER  UcxController,
_Out_ PULONG  FrameNumber 
)

Definition at line 196 of file controller.cpp.

199{
200 UNREFERENCED_PARAMETER(UcxController);
201
202 /* MFINDEX >> 3 once the runtime registers are mapped */
203 *FrameNumber = 0;
206}
#define UNIMPLEMENTED
Definition: ntoskrnl.c:15
#define STATUS_NOT_IMPLEMENTED
Definition: d3dkmdt.h:42
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:329
_Out_ PULONG FrameNumber
Definition: ucxcontroller.h:94

◆ XhciEvtControllerQueryUsbCapability()

NTSTATUS NTAPI XhciEvtControllerQueryUsbCapability ( _In_ UCXCONTROLLER  UcxController,
_In_ PGUID  CapabilityType,
_In_ ULONG  OutputBufferLength,
_Out_writes_bytes_opt_(OutputBufferLength) PVOID  OutputBuffer,
_Out_ PULONG  ResultLength 
)

Definition at line 178 of file controller.cpp.

184{
185 UNREFERENCED_PARAMETER(UcxController);
189
190 *ResultLength = 0;
192}
#define STATUS_NOT_SUPPORTED
Definition: d3dkmdt.h:48
_In_ PGUID _In_ ULONG _Out_ PULONG ResultLength
Definition: ucxcontroller.h:83
_In_ PGUID CapabilityType
Definition: ucxcontroller.h:80
_In_ PGUID _In_ ULONG OutputBufferLength
Definition: ucxcontroller.h:81
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR OutputBuffer
Definition: wdfiotarget.h:863

◆ XhciEvtControllerReset()

VOID NTAPI XhciEvtControllerReset ( _In_ UCXCONTROLLER  UcxController)

Definition at line 210 of file controller.cpp.

212{
214
216
218 UcxControllerResetComplete(UcxController, &Info);
219}
#define TRUE
Definition: types.h:120
@ UcxControllerStateLost
Definition: ucxcontroller.h:24
FORCEINLINE VOID NTAPI UCX_CONTROLLER_RESET_COMPLETE_INFO_INIT(_Out_ PUCX_CONTROLLER_RESET_COMPLETE_INFO UcxControllerResetCompleteInfo, _In_ UCX_CONTROLLER_STATE UcxControllerState, _In_ BOOLEAN UcxCoordinated)
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
Definition: wdfchildlist.h:690

◆ XhciEvtDeviceAdd()

NTSTATUS NTAPI XhciEvtDeviceAdd ( _In_ WDFDRIVER  Driver,
_Inout_ PWDFDEVICE_INIT  DeviceInit 
)

Definition at line 45 of file controller.cpp.

48{
51 WDF_IO_QUEUE_CONFIG QueueConfig;
53 WDFDEVICE Device;
55
57 PAGED_CODE();
58
64 WdfDeviceInitSetPnpPowerEventCallbacks(DeviceInit, &PnpPower);
65
66 Status = UcxInitializeDeviceInit(DeviceInit);
67 if (!NT_SUCCESS(Status))
68 {
69 DPRINT1("UcxInitializeDeviceInit failed 0x%lx\n", Status);
70 return Status;
71 }
72
74
75 Status = WdfDeviceCreate(&DeviceInit, &Attributes, &Device);
76 if (!NT_SUCCESS(Status))
77 {
78 DPRINT1("WdfDeviceCreate failed 0x%lx\n", Status);
79 return Status;
80 }
81
82 Controller = XhciGetController(Device);
83 Controller->Device = Device;
84
85 /* UCX gets first look at every IOCTL sent to the controller */
88
89 Status = WdfIoQueueCreate(Device, &QueueConfig, WDF_NO_OBJECT_ATTRIBUTES, WDF_NO_HANDLE);
90 if (!NT_SUCCESS(Status))
91 {
92 DPRINT1("WdfIoQueueCreate failed 0x%lx\n", Status);
93 return Status;
94 }
95
96 Status = XhciCreateUcxController(Controller);
97 if (!NT_SUCCESS(Status))
98 return Status;
99
100 return XhciRootHubCreate(Controller);
101}
#define PAGED_CODE()
_Must_inspect_result_ _In_ PUCXHUB_DEVICE_CREATE_INFO _Out_ UCXUSBDEVICE * Device
Definition: hubucx.h:258
PFN_WDF_IO_QUEUE_IO_DEVICE_CONTROL EvtIoDeviceControl
Definition: wdfio.h:405
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
EVT_WDF_IO_QUEUE_IO_DEVICE_CONTROL XhciEvtIoDeviceControl
Definition: usbxhci.h:44
EVT_WDF_DEVICE_PREPARE_HARDWARE XhciEvtDevicePrepareHardware
Definition: usbxhci.h:40
EVT_WDF_DEVICE_RELEASE_HARDWARE XhciEvtDeviceReleaseHardware
Definition: usbxhci.h:41
EVT_WDF_DEVICE_D0_EXIT XhciEvtDeviceD0Exit
Definition: usbxhci.h:43
EVT_WDF_DEVICE_D0_ENTRY XhciEvtDeviceD0Entry
Definition: usbxhci.h:42
_In_ PWDFDEVICE_INIT DeviceInit
Definition: wdfcontrol.h:113
_Must_inspect_result_ _In_ WDFDRIVER Driver
Definition: wdfcontrol.h:83
FORCEINLINE VOID WDF_PNPPOWER_EVENT_CALLBACKS_INIT(_Out_ PWDF_PNPPOWER_EVENT_CALLBACKS Callbacks)
Definition: wdfdevice.h:1214
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
@ WdfIoQueueDispatchParallel
Definition: wdfio.h:79
#define WDF_NO_HANDLE
Definition: wdftypes.h:107
#define WDF_NO_OBJECT_ATTRIBUTES
Definition: wdftypes.h:105

◆ XhciEvtDeviceD0Entry()

NTSTATUS NTAPI XhciEvtDeviceD0Entry ( _In_ WDFDEVICE  Device,
_In_ WDF_POWER_DEVICE_STATE  PreviousState 
)

Definition at line 134 of file controller.cpp.

137{
140
141 /* Reset and start the controller */
143 return STATUS_SUCCESS;
144}
_In_ WDF_POWER_DEVICE_STATE PreviousState
Definition: wdfdevice.h:829

◆ XhciEvtDeviceD0Exit()

NTSTATUS NTAPI XhciEvtDeviceD0Exit ( _In_ WDFDEVICE  Device,
_In_ WDF_POWER_DEVICE_STATE  TargetState 
)

Definition at line 148 of file controller.cpp.

151{
154
156 return STATUS_SUCCESS;
157}
_In_ WDF_POWER_DEVICE_STATE TargetState
Definition: wdfdevice.h:859

◆ XhciEvtDevicePrepareHardware()

NTSTATUS NTAPI XhciEvtDevicePrepareHardware ( _In_ WDFDEVICE  Device,
_In_ WDFCMRESLIST  ResourcesRaw,
_In_ WDFCMRESLIST  ResourcesTranslated 
)

Definition at line 105 of file controller.cpp.

109{
113
114 /* Map the MMIO BAR, read capability registers, connect the interrupt */
116 return STATUS_SUCCESS;
117}
_In_ WDFCMRESLIST _In_ WDFCMRESLIST ResourcesTranslated
Definition: wdfdevice.h:891
_In_ WDFCMRESLIST ResourcesRaw
Definition: wdfdevice.h:888

◆ XhciEvtDeviceReleaseHardware()

NTSTATUS NTAPI XhciEvtDeviceReleaseHardware ( _In_ WDFDEVICE  Device,
_In_ WDFCMRESLIST  ResourcesTranslated 
)

Definition at line 121 of file controller.cpp.

◆ XhciEvtIoDeviceControl()

VOID NTAPI XhciEvtIoDeviceControl ( _In_ WDFQUEUE  Queue,
_In_ WDFREQUEST  Request,
_In_ size_t  OutputBufferLength,
_In_ size_t  InputBufferLength,
_In_ ULONG  IoControlCode 
)

Definition at line 161 of file controller.cpp.

167{
168 WDFDEVICE Device = WdfIoQueueGetDevice(Queue);
169
171 return;
172
173 WdfRequestComplete(Request, STATUS_INVALID_DEVICE_REQUEST);
174}
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFREQUEST _In_ size_t _In_ size_t _In_ ULONG IoControlCode
_In_ WDFREQUEST _In_ size_t _In_ size_t InputBufferLength
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFREQUEST Request
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
_Must_inspect_result_ _In_ WDFDEVICE _In_ PIRP _In_ WDFQUEUE Queue
Definition: wdfdevice.h:2231