ReactOS 0.4.16-dev-297-gc569aee
pnp.c File Reference
#include "usbport.h"
#include <debug.h>
#include "usbdebug.h"
Include dependency graph for pnp.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define NDEBUG_USBPORT_CORE
 

Functions

NTSTATUS NTAPI USBPORT_FdoStartCompletion (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
 
NTSTATUS NTAPI USBPORT_RegisterDeviceInterface (IN PDEVICE_OBJECT PdoDevice, IN PDEVICE_OBJECT DeviceObject, IN CONST GUID *InterfaceClassGuid, IN BOOLEAN Enable)
 
BOOLEAN NTAPI USBPORT_IsSelectiveSuspendEnabled (IN PDEVICE_OBJECT FdoDevice)
 
NTSTATUS NTAPI USBPORT_GetConfigValue (IN PWSTR ValueName, IN ULONG ValueType, IN PVOID ValueData, IN ULONG ValueLength, IN PVOID Context, IN PVOID EntryContext)
 
NTSTATUS NTAPI USBPORT_GetDefaultBIOSx (IN PDEVICE_OBJECT FdoDevice, IN PULONG UsbBIOSx, IN PULONG DisableSelectiveSuspend, IN PULONG DisableCcDetect, IN PULONG IdleEpSupport, IN PULONG IdleEpSupportEx, IN PULONG SoftRetry)
 
NTSTATUS NTAPI USBPORT_IsCompanionController (IN PDEVICE_OBJECT DeviceObject, IN BOOLEAN *IsCompanion)
 
NTSTATUS NTAPI USBPORT_QueryPciBusInterface (IN PDEVICE_OBJECT FdoDevice)
 
NTSTATUS NTAPI USBPORT_QueryCapabilities (IN PDEVICE_OBJECT FdoDevice, IN PDEVICE_CAPABILITIES Capabilities)
 
NTSTATUS NTAPI USBPORT_CreateLegacySymbolicLink (IN PDEVICE_OBJECT FdoDevice)
 
NTSTATUS NTAPI USBPORT_StopDevice (IN PDEVICE_OBJECT FdoDevice)
 
NTSTATUS NTAPI USBPORT_StartDevice (IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_RESOURCES UsbPortResources)
 
NTSTATUS NTAPI USBPORT_ParseResources (IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp, IN PUSBPORT_RESOURCES UsbPortResources)
 
NTSTATUS NTAPI USBPORT_CreatePdo (IN PDEVICE_OBJECT FdoDevice, OUT PDEVICE_OBJECT *RootHubPdo)
 
NTSTATUS NTAPI USBPORT_FdoPnP (IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp)
 
PVOID NTAPI USBPORT_GetDeviceHwIds (IN PDEVICE_OBJECT FdoDevice, IN USHORT VendorID, IN USHORT DeviceID, IN USHORT RevisionID)
 
NTSTATUS NTAPI USBPORT_PdoPnP (IN PDEVICE_OBJECT PdoDevice, IN PIRP Irp)
 

Variables

IO_COMPLETION_ROUTINE USBPORT_FdoStartCompletion
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 10 of file pnp.c.

◆ NDEBUG_USBPORT_CORE

#define NDEBUG_USBPORT_CORE

Definition at line 13 of file pnp.c.

Function Documentation

◆ USBPORT_CreateLegacySymbolicLink()

NTSTATUS NTAPI USBPORT_CreateLegacySymbolicLink ( IN PDEVICE_OBJECT  FdoDevice)

Definition at line 449 of file pnp.c.

450{
452 WCHAR CharName[255] = {0};
453 WCHAR CharDosName[255] = {0};
456
457 FdoExtension = FdoDevice->DeviceExtension;
458
459 RtlStringCbPrintfW(CharName,
460 sizeof(CharName),
461 L"\\Device\\USBFDO-%d",
462 FdoExtension->FdoNameNumber);
463
465
466 RtlStringCbPrintfW(CharDosName,
467 sizeof(CharDosName),
468 L"\\DosDevices\\HCD%d",
469 FdoExtension->FdoNameNumber);
470
471 RtlInitUnicodeString(&FdoExtension->DosDeviceSymbolicName, CharDosName);
472
473 DPRINT("USBPORT_CreateLegacySymbolicLink: DeviceName - %wZ, DosSymbolicName - %wZ\n",
474 &DeviceName,
475 &FdoExtension->DosDeviceSymbolicName);
476
477 Status = IoCreateSymbolicLink(&FdoExtension->DosDeviceSymbolicName,
478 &DeviceName);
479
480 if (NT_SUCCESS(Status))
481 {
483 }
484
485 return Status;
486}
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
@ FdoExtension
Definition: precomp.h:48
Status
Definition: gdiplustypes.h:25
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
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 L(x)
Definition: ntvdm.h:50
#define DPRINT
Definition: sndvol32.h:73
#define USBPORT_FLAG_DOS_SYMBOLIC_NAME
Definition: usbport.h:74
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3275
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by USBPORT_StartDevice().

◆ USBPORT_CreatePdo()

NTSTATUS NTAPI USBPORT_CreatePdo ( IN PDEVICE_OBJECT  FdoDevice,
OUT PDEVICE_OBJECT RootHubPdo 
)

Definition at line 1028 of file pnp.c.

1030{
1034 ULONG DeviceNumber = 0;
1036 WCHAR CharDeviceName[64];
1038
1039 DPRINT("USBPORT_CreatePdo: FdoDevice - %p, RootHubPdo - %p\n",
1040 FdoDevice,
1041 RootHubPdo);
1042
1043 FdoExtension = FdoDevice->DeviceExtension;
1044
1045 do
1046 {
1047 RtlStringCbPrintfW(CharDeviceName,
1048 sizeof(CharDeviceName),
1049 L"\\Device\\USBPDO-%d",
1050 DeviceNumber);
1051
1052 RtlInitUnicodeString(&DeviceName, CharDeviceName);
1053
1054 DPRINT("USBPORT_CreatePdo: DeviceName - %wZ\n", &DeviceName);
1055
1056 Status = IoCreateDevice(FdoExtension->MiniPortInterface->DriverObject,
1058 &DeviceName,
1060 0,
1061 FALSE,
1062 &DeviceObject);
1063
1064 ++DeviceNumber;
1065 }
1067
1068 if (!NT_SUCCESS(Status))
1069 {
1070 *RootHubPdo = NULL;
1071 DPRINT1("USBPORT_CreatePdo: Filed create HubPdo!\n");
1072 return Status;
1073 }
1074
1075 if (DeviceObject)
1076 {
1077 PdoExtension = DeviceObject->DeviceExtension;
1078
1080
1081 PdoExtension->CommonExtension.SelfDevice = DeviceObject;
1082 PdoExtension->CommonExtension.IsPDO = TRUE;
1083
1084 PdoExtension->FdoDevice = FdoDevice;
1085 PdoExtension->PdoNameNumber = DeviceNumber;
1086
1088
1089 DeviceObject->StackSize = FdoDevice->StackSize;
1090
1092 DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
1093 }
1094 else
1095 {
1097 }
1098
1099 if (!NT_SUCCESS(Status))
1100 *RootHubPdo = NULL;
1101 else
1102 *RootHubPdo = DeviceObject;
1103
1104 DPRINT("USBPORT_CreatePdo: HubPdo - %p\n", DeviceObject);
1105 return Status;
1106}
#define DPRINT1
Definition: precomp.h:8
_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
@ PdoExtension
Definition: precomp.h:49
VOID NTAPI USBPORT_AdjustDeviceCapabilities(IN PDEVICE_OBJECT FdoDevice, IN PDEVICE_OBJECT PdoDevice)
Definition: power.c:668
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
#define FILE_DEVICE_BUS_EXTENDER
Definition: winioctl.h:87
#define STATUS_SUCCESS
Definition: shellext.h:65
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
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
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define DO_POWER_PAGABLE

Referenced by USBPORT_FdoPnP().

◆ USBPORT_FdoPnP()

NTSTATUS NTAPI USBPORT_FdoPnP ( IN PDEVICE_OBJECT  FdoDevice,
IN PIRP  Irp 
)

Definition at line 1110 of file pnp.c.

1112{
1114 PUSBPORT_COMMON_DEVICE_EXTENSION FdoCommonExtension;
1116 PUSBPORT_RESOURCES UsbPortResources;
1117 PIO_STACK_LOCATION IoStack;
1118 UCHAR Minor;
1119 KEVENT Event;
1122 PDEVICE_RELATIONS DeviceRelations;
1123 PDEVICE_OBJECT RootHubPdo;
1124
1125 FdoExtension = FdoDevice->DeviceExtension;
1126 FdoCommonExtension = &FdoExtension->CommonExtension;
1127 UsbPortResources = &FdoExtension->UsbPortResources;
1128 Packet = &FdoExtension->MiniPortInterface->Packet;
1129
1131 Minor = IoStack->MinorFunction;
1132
1133 DPRINT("USBPORT_FdoPnP: FdoDevice - %p, Minor - %x\n", FdoDevice, Minor);
1134
1136
1137 switch (Minor)
1138 {
1140 DPRINT("IRP_MN_START_DEVICE\n");
1141
1143
1145
1148 &Event,
1149 TRUE,
1150 TRUE,
1151 TRUE);
1152
1153 Status = IoCallDriver(FdoCommonExtension->LowerDevice,
1154 Irp);
1155
1156 if (Status == STATUS_PENDING)
1157 {
1159 Suspended,
1160 KernelMode,
1161 FALSE,
1162 NULL);
1163
1164 Status = Irp->IoStatus.Status;
1165 }
1166
1167 if (!NT_SUCCESS(Status))
1168 {
1169 goto Exit;
1170 }
1171
1172 Status = USBPORT_ParseResources(FdoDevice,
1173 Irp,
1174 UsbPortResources);
1175
1176 if (!NT_SUCCESS(Status))
1177 {
1178 FdoCommonExtension->PnpStateFlags |= USBPORT_PNP_STATE_STOPPED;
1179 goto Exit;
1180 }
1181
1182 Status = USBPORT_StartDevice(FdoDevice, UsbPortResources);
1183
1184 if (!NT_SUCCESS(Status))
1185 {
1186 FdoCommonExtension->PnpStateFlags |= USBPORT_PNP_STATE_STOPPED;
1187 goto Exit;
1188 }
1189
1190 FdoCommonExtension->PnpStateFlags &= ~USBPORT_PNP_STATE_NOT_INIT;
1191 FdoCommonExtension->PnpStateFlags |= USBPORT_PNP_STATE_STARTED;
1192
1193 FdoCommonExtension->DevicePowerState = PowerDeviceD0;
1194
1195 if (Packet->MiniPortFlags & USB_MINIPORT_FLAGS_USB2)
1196 {
1197 USBPORT_AddUSB2Fdo(FdoDevice);
1198 }
1199 else
1200 {
1201 USBPORT_AddUSB1Fdo(FdoDevice);
1202 }
1203
1204Exit:
1205 Irp->IoStatus.Status = Status;
1207 return Status;
1208
1210 DPRINT("IRP_MN_QUERY_REMOVE_DEVICE\n");
1211 if (Packet->MiniPortFlags & USB_MINIPORT_FLAGS_USB2)
1212 {
1213 DPRINT1("USBPORT_FdoPnP: Haction registry write FIXME\n");
1214 }
1215
1216 Irp->IoStatus.Status = STATUS_SUCCESS;
1217 goto ForwardIrp;
1218
1220 DPRINT("USBPORT_FdoPnP: IRP_MN_REMOVE_DEVICE\n");
1221 FdoCommonExtension->PnpStateFlags |= USBPORT_PNP_STATE_FAILED;
1222
1223 if (FdoCommonExtension->PnpStateFlags & USBPORT_PNP_STATE_STARTED &&
1224 !(FdoCommonExtension->PnpStateFlags & USBPORT_PNP_STATE_NOT_INIT))
1225 {
1226 DPRINT1("USBPORT_FdoPnP: stop fdo FIXME\n");
1227 FdoCommonExtension->PnpStateFlags |= USBPORT_PNP_STATE_NOT_INIT;
1228 }
1229
1230 Irp->IoStatus.Status = STATUS_SUCCESS;
1232 Status = IoCallDriver(FdoCommonExtension->LowerDevice, Irp);
1233
1234 IoDetachDevice(FdoCommonExtension->LowerDevice);
1235
1236 RootHubPdo = FdoExtension->RootHubPdo;
1237
1238 IoDeleteDevice(FdoDevice);
1239
1240 if (RootHubPdo)
1241 {
1242 IoDeleteDevice(RootHubPdo);
1243 }
1244
1245 return Status;
1246
1248 DPRINT("IRP_MN_CANCEL_REMOVE_DEVICE\n");
1249 Irp->IoStatus.Status = STATUS_SUCCESS;
1250 goto ForwardIrp;
1251
1252 case IRP_MN_STOP_DEVICE:
1253 DPRINT("IRP_MN_STOP_DEVICE\n");
1254 if (FdoCommonExtension->PnpStateFlags & USBPORT_PNP_STATE_STARTED)
1255 {
1256 DPRINT1("USBPORT_FdoPnP: stop fdo FIXME\n");
1257
1258 FdoCommonExtension->PnpStateFlags &= ~USBPORT_PNP_STATE_STARTED;
1259 FdoCommonExtension->PnpStateFlags |= USBPORT_PNP_STATE_NOT_INIT;
1260 }
1261
1262 Irp->IoStatus.Status = STATUS_SUCCESS;
1263 goto ForwardIrp;
1264
1266 DPRINT("IRP_MN_QUERY_STOP_DEVICE\n");
1267 Irp->IoStatus.Status = STATUS_SUCCESS;
1268 goto ForwardIrp;
1269
1271 DPRINT("IRP_MN_CANCEL_STOP_DEVICE\n");
1272 Irp->IoStatus.Status = STATUS_SUCCESS;
1273 goto ForwardIrp;
1274
1276 DPRINT("IRP_MN_QUERY_DEVICE_RELATIONS\n");
1278 {
1279 DeviceRelations = ExAllocatePoolWithTag(PagedPool,
1280 sizeof(DEVICE_RELATIONS),
1281 USB_PORT_TAG);
1282
1283 if (!DeviceRelations)
1284 {
1286 Irp->IoStatus.Status = Status;
1288 return Status;
1289 }
1290
1291 DeviceRelations->Count = 0;
1292 DeviceRelations->Objects[0] = NULL;
1293
1294 if (!FdoExtension->RootHubPdo)
1295 {
1296 Status = USBPORT_CreatePdo(FdoDevice,
1297 &FdoExtension->RootHubPdo);
1298
1299 if (!NT_SUCCESS(Status))
1300 {
1301 ExFreePoolWithTag(DeviceRelations, USB_PORT_TAG);
1302 goto ForwardIrp;
1303 }
1304 }
1305 else
1306 {
1308 }
1309
1310 DeviceRelations->Count = 1;
1311 DeviceRelations->Objects[0] = FdoExtension->RootHubPdo;
1312
1313 ObReferenceObject(FdoExtension->RootHubPdo);
1314 Irp->IoStatus.Information = (ULONG_PTR)DeviceRelations;
1315 }
1316 else
1317 {
1319 {
1320 DPRINT1("USBPORT_FdoPnP: FIXME IRP_MN_QUERY_DEVICE_RELATIONS/RemovalRelations\n");
1321 }
1322
1323 goto ForwardIrp;
1324 }
1325
1326 Irp->IoStatus.Status = Status;
1327 goto ForwardIrp;
1328
1330 DPRINT("IRP_MN_QUERY_INTERFACE\n");
1331 goto ForwardIrp;
1332
1334 DPRINT("IRP_MN_QUERY_CAPABILITIES\n");
1335 goto ForwardIrp;
1336
1338 DPRINT("IRP_MN_QUERY_RESOURCES\n");
1339 goto ForwardIrp;
1340
1342 DPRINT("IRP_MN_QUERY_RESOURCE_REQUIREMENTS\n");
1343 goto ForwardIrp;
1344
1346 DPRINT("IRP_MN_QUERY_DEVICE_TEXT\n");
1347 goto ForwardIrp;
1348
1350 DPRINT("IRP_MN_FILTER_RESOURCE_REQUIREMENTS\n");
1351 goto ForwardIrp;
1352
1353 case IRP_MN_READ_CONFIG:
1354 DPRINT("IRP_MN_READ_CONFIG\n");
1355 goto ForwardIrp;
1356
1358 DPRINT("IRP_MN_WRITE_CONFIG\n");
1359 goto ForwardIrp;
1360
1361 case IRP_MN_EJECT:
1362 DPRINT("IRP_MN_EJECT\n");
1363 goto ForwardIrp;
1364
1365 case IRP_MN_SET_LOCK:
1366 DPRINT("IRP_MN_SET_LOCK\n");
1367 goto ForwardIrp;
1368
1369 case IRP_MN_QUERY_ID:
1370 DPRINT("IRP_MN_QUERY_ID\n");
1371 goto ForwardIrp;
1372
1374 DPRINT("IRP_MN_QUERY_PNP_DEVICE_STATE\n");
1375 goto ForwardIrp;
1376
1378 DPRINT("IRP_MN_QUERY_BUS_INFORMATION\n");
1379 goto ForwardIrp;
1380
1382 DPRINT("IRP_MN_DEVICE_USAGE_NOTIFICATION\n");
1383 goto ForwardIrp;
1384
1386 DPRINT1("IRP_MN_SURPRISE_REMOVAL\n");
1387 if (!(FdoCommonExtension->PnpStateFlags & USBPORT_PNP_STATE_FAILED))
1388 {
1391 }
1392 goto ForwardIrp;
1393
1394 default:
1395 DPRINT("unknown IRP_MN_???\n");
1396ForwardIrp:
1397 /* forward irp to next device object */
1399 break;
1400 }
1401
1402 return IoCallDriver(FdoCommonExtension->LowerDevice, Irp);
1403}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_PENDING
Definition: d3dkmdt.h:43
#define ULONG_PTR
Definition: config.h:101
NTSTATUS NTAPI USBPORT_StartDevice(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_RESOURCES UsbPortResources)
Definition: pnp.c:498
NTSTATUS NTAPI USBPORT_ParseResources(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp, IN PUSBPORT_RESOURCES UsbPortResources)
Definition: pnp.c:912
NTSTATUS NTAPI USBPORT_CreatePdo(IN PDEVICE_OBJECT FdoDevice, OUT PDEVICE_OBJECT *RootHubPdo)
Definition: pnp.c:1028
IO_COMPLETION_ROUTINE USBPORT_FdoStartCompletion
Definition: pnp.c:16
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define PagedPool
Definition: env_spec_w32.h:308
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:490
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1549
#define KernelMode
Definition: asm.h:34
@ NotificationEvent
#define IRP_MN_SURPRISE_REMOVAL
Definition: ntifs_ex.h:408
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define IoCopyCurrentIrpStackLocationToNext(Irp)
Definition: ntifs_ex.h:413
VOID NTAPI IoDetachDevice(IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:1296
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
#define IoCompleteRequest
Definition: irp.c:1240
#define IoCallDriver
Definition: irp.c:1225
@ PowerDeviceD0
Definition: ntpoapi.h:49
static void Exit(void)
Definition: sock.c:1330
PDEVICE_OBJECT Objects[1]
Definition: iotypes.h:2163
union _IO_STACK_LOCATION::@1579 Parameters
struct _IO_STACK_LOCATION::@3978::@4003 QueryDeviceRelations
DEVICE_POWER_STATE DevicePowerState
Definition: usbport.h:287
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define USB_MINIPORT_FLAGS_USB2
Definition: usbmport.h:534
#define USBPORT_INVALIDATE_CONTROLLER_SURPRISE_REMOVE
Definition: usbmport.h:490
VOID NTAPI USBPORT_AddUSB2Fdo(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:82
VOID NTAPI USBPORT_AddUSB1Fdo(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:66
VOID NTAPI USBPORT_InvalidateControllerHandler(IN PDEVICE_OBJECT FdoDevice, IN ULONG Type)
Definition: usbport.c:635
#define USB_PORT_TAG
Definition: usbport.h:44
#define USBPORT_PNP_STATE_STARTED
Definition: usbport.h:88
#define USBPORT_PNP_STATE_FAILED
Definition: usbport.h:89
#define USBPORT_PNP_STATE_STOPPED
Definition: usbport.h:90
#define USBPORT_PNP_STATE_NOT_INIT
Definition: usbport.h:87
_In_ DEVICE_RELATION_TYPE RelationType
Definition: wdfdevice.h:1059
_Out_opt_ PULONG Minor
Definition: cmfuncs.h:44
#define IRP_MN_CANCEL_STOP_DEVICE
@ RemovalRelations
Definition: iotypes.h:2155
@ BusRelations
Definition: iotypes.h:2152
#define IRP_MN_QUERY_PNP_DEVICE_STATE
#define IRP_MN_EJECT
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define IRP_MN_QUERY_INTERFACE
#define IRP_MN_START_DEVICE
#define IRP_MN_DEVICE_USAGE_NOTIFICATION
#define IRP_MN_READ_CONFIG
#define IRP_MN_WRITE_CONFIG
#define IRP_MN_QUERY_RESOURCE_REQUIREMENTS
#define IRP_MN_QUERY_ID
#define IRP_MN_REMOVE_DEVICE
#define IRP_MN_FILTER_RESOURCE_REQUIREMENTS
#define IRP_MN_QUERY_DEVICE_RELATIONS
#define IRP_MN_QUERY_STOP_DEVICE
#define IRP_MN_QUERY_DEVICE_TEXT
#define IRP_MN_QUERY_CAPABILITIES
#define IRP_MN_QUERY_RESOURCES
#define IRP_MN_CANCEL_REMOVE_DEVICE
#define IRP_MN_STOP_DEVICE
#define IRP_MN_SET_LOCK
enum _DEVICE_RELATION_TYPE DEVICE_RELATION_TYPE
#define IRP_MN_QUERY_BUS_INFORMATION
#define IRP_MN_QUERY_REMOVE_DEVICE
@ Suspended
Definition: ketypes.h:420
#define ObReferenceObject
Definition: obfuncs.h:204
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by USBPORT_Dispatch().

◆ USBPORT_FdoStartCompletion()

NTSTATUS NTAPI USBPORT_FdoStartCompletion ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp,
IN PVOID  Context 
)

Definition at line 20 of file pnp.c.

23{
26}
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
#define EVENT_INCREMENT
Definition: iotypes.h:597

◆ USBPORT_GetConfigValue()

NTSTATUS NTAPI USBPORT_GetConfigValue ( IN PWSTR  ValueName,
IN ULONG  ValueType,
IN PVOID  ValueData,
IN ULONG  ValueLength,
IN PVOID  Context,
IN PVOID  EntryContext 
)

Definition at line 110 of file pnp.c.

116{
118
119 DPRINT("USBPORT_GetConfigValue \n");
120
121 if (ValueType == REG_DWORD)
122 {
124 }
125 else
126 {
128 }
129
130 return Status;
131}
_In_ GUID _In_ PVOID ValueData
Definition: hubbusif.h:312
_In_ PCWSTR _Inout_ _At_ QueryTable EntryContext
Definition: rtlfuncs.h:4219
#define REG_DWORD
Definition: sdbapi.c:596
uint32_t * PULONG
Definition: typedefs.h:59
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_ ULONG _Out_opt_ PULONG _Out_opt_ PULONG ValueType
Definition: wdfregistry.h:282

Referenced by USBPORT_GetDefaultBIOSx().

◆ USBPORT_GetDefaultBIOSx()

NTSTATUS NTAPI USBPORT_GetDefaultBIOSx ( IN PDEVICE_OBJECT  FdoDevice,
IN PULONG  UsbBIOSx,
IN PULONG  DisableSelectiveSuspend,
IN PULONG  DisableCcDetect,
IN PULONG  IdleEpSupport,
IN PULONG  IdleEpSupportEx,
IN PULONG  SoftRetry 
)

Definition at line 135 of file pnp.c.

142{
144
145 DPRINT("USBPORT_GetDefaultBIOS_X: ... \n");
146
148
149 *UsbBIOSx = 2;
150
152 QueryTable[0].Flags = 0;
153 QueryTable[0].Name = L"UsbBIOSx";
154 QueryTable[0].EntryContext = UsbBIOSx;
156 QueryTable[0].DefaultData = UsbBIOSx;
157 QueryTable[0].DefaultLength = sizeof(ULONG);
158
160 QueryTable[1].Flags = 0;
161 QueryTable[1].Name = L"DisableSelectiveSuspend";
162 QueryTable[1].EntryContext = DisableSelectiveSuspend;
164 QueryTable[1].DefaultData = DisableSelectiveSuspend;
165 QueryTable[1].DefaultLength = sizeof(ULONG);
166
168 QueryTable[2].Flags = 0;
169 QueryTable[2].Name = L"DisableCcDetect";
170 QueryTable[2].EntryContext = DisableCcDetect;
172 QueryTable[2].DefaultData = DisableCcDetect;
173 QueryTable[2].DefaultLength = sizeof(ULONG);
174
176 QueryTable[3].Flags = 0;
177 QueryTable[3].Name = L"EnIdleEndpointSupport";
178 QueryTable[3].EntryContext = IdleEpSupport;
180 QueryTable[3].DefaultData = IdleEpSupport;
181 QueryTable[3].DefaultLength = sizeof(ULONG);
182
184 QueryTable[4].Flags = 0;
185 QueryTable[4].Name = L"EnIdleEndpointSupportEx";
186 QueryTable[4].EntryContext = IdleEpSupportEx;
188 QueryTable[4].DefaultData = IdleEpSupportEx;
189 QueryTable[4].DefaultLength = sizeof(ULONG);
190
192 QueryTable[5].Flags = 0;
193 QueryTable[5].Name = L"EnSoftRetry";
194 QueryTable[5].EntryContext = SoftRetry;
196 QueryTable[5].DefaultData = SoftRetry;
197 QueryTable[5].DefaultLength = sizeof(ULONG);
198
200 L"usb",
202 NULL,
203 NULL);
204}
NTSTATUS NTAPI USBPORT_GetConfigValue(IN PWSTR ValueName, IN ULONG ValueType, IN PVOID ValueData, IN ULONG ValueLength, IN PVOID Context, IN PVOID EntryContext)
Definition: pnp.c:110
NTSYSAPI NTSTATUS WINAPI RtlQueryRegistryValues(ULONG, PCWSTR, PRTL_QUERY_REGISTRY_TABLE, PVOID, PVOID)
_In_ PCWSTR _Inout_ _At_ QueryTable _Pre_unknown_ PRTL_QUERY_REGISTRY_TABLE QueryTable
Definition: rtlfuncs.h:4220
#define RTL_REGISTRY_SERVICES
Definition: nt_native.h:162
PRTL_QUERY_REGISTRY_ROUTINE QueryRoutine
Definition: nt_native.h:109

Referenced by USBPORT_StartDevice().

◆ USBPORT_GetDeviceHwIds()

PVOID NTAPI USBPORT_GetDeviceHwIds ( IN PDEVICE_OBJECT  FdoDevice,
IN USHORT  VendorID,
IN USHORT  DeviceID,
IN USHORT  RevisionID 
)

Definition at line 1407 of file pnp.c.

1411{
1414 PVOID Id;
1415 WCHAR Buffer[300] = {0};
1416 SIZE_T Length = 0;
1417 size_t Remaining = sizeof(Buffer);
1418 PWCHAR EndBuffer;
1419
1420 FdoExtension = FdoDevice->DeviceExtension;
1421 Packet = &FdoExtension->MiniPortInterface->Packet;
1422
1423 DPRINT("USBPORT_GetDeviceHwIds: FdoDevice - %p, Packet->MiniPortFlags - %p\n",
1424 FdoDevice,
1425 Packet->MiniPortFlags);
1426
1427 if (Packet->MiniPortFlags & USB_MINIPORT_FLAGS_USB2)
1428 {
1430 Remaining,
1431 &EndBuffer,
1432 &Remaining,
1433 0,
1434 L"USB\\ROOT_HUB20&VID%04x&PID%04x&REV%04x",
1435 VendorID,
1436 DeviceID,
1437 RevisionID);
1438
1439 EndBuffer++;
1440 Remaining -= sizeof(UNICODE_NULL);
1441
1442 RtlStringCbPrintfExW(EndBuffer,
1443 Remaining,
1444 &EndBuffer,
1445 &Remaining,
1446 0,
1447 L"USB\\ROOT_HUB20&VID%04x&PID%04x",
1448 VendorID,
1449 DeviceID);
1450
1451 EndBuffer++;
1452 Remaining -= sizeof(UNICODE_NULL);
1453
1454 RtlStringCbPrintfExW(EndBuffer,
1455 Remaining,
1456 NULL,
1457 &Remaining,
1458 0,
1459 L"USB\\ROOT_HUB20");
1460 }
1461 else
1462 {
1464 Remaining,
1465 &EndBuffer,
1466 &Remaining,
1467 0,
1468 L"USB\\ROOT_HUB&VID%04x&PID%04x&REV%04x",
1469 VendorID,
1470 DeviceID,
1471 RevisionID);
1472
1473 EndBuffer++;
1474 Remaining -= sizeof(UNICODE_NULL);
1475
1476 RtlStringCbPrintfExW(EndBuffer,
1477 Remaining,
1478 &EndBuffer,
1479 &Remaining,
1480 0,
1481 L"USB\\ROOT_HUB&VID%04x&PID%04x",
1482 VendorID,
1483 DeviceID);
1484
1485 EndBuffer++;
1486 Remaining -= sizeof(UNICODE_NULL);
1487
1488 RtlStringCbPrintfExW(EndBuffer,
1489 Remaining,
1490 NULL,
1491 &Remaining,
1492 0,
1493 L"USB\\ROOT_HUB");
1494 }
1495
1496 Length = (sizeof(Buffer) - Remaining + 2 * sizeof(UNICODE_NULL));
1497
1498 /* for debug only */
1499 if (FALSE)
1500 {
1501 DPRINT("Hardware IDs:\n");
1503 }
1504
1506
1507 if (!Id)
1508 return NULL;
1509
1511
1512 return Id;
1513}
DWORD Id
Definition: bufpool.h:45
VOID NTAPI USBPORT_DumpingIDs(IN PVOID Buffer)
Definition: debug.c:257
#define UNICODE_NULL
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
NTSTRSAFEVAPI RtlStringCbPrintfExW(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _Outptr_opt_result_bytebuffer_(*pcbRemaining) NTSTRSAFE_PWSTR *ppszDestEnd, _Out_opt_ size_t *pcbRemaining, _In_ STRSAFE_DWORD dwFlags, _In_ _Printf_format_string_ NTSTRSAFE_PCWSTR pszFormat,...)
Definition: ntstrsafe.h:1335
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
uint16_t * PWCHAR
Definition: typedefs.h:56
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_ PCUNICODE_STRING DeviceID
Definition: wdfpdo.h:278
_In_ USHORT _In_ UCHAR RevisionID
Definition: iotypes.h:893

Referenced by USBPORT_PdoPnP().

◆ USBPORT_IsCompanionController()

NTSTATUS NTAPI USBPORT_IsCompanionController ( IN PDEVICE_OBJECT  DeviceObject,
IN BOOLEAN IsCompanion 
)

Definition at line 208 of file pnp.c.

210{
211 PDEVICE_OBJECT HighestDevice;
212 PIRP Irp;
214 PIO_STACK_LOCATION IoStack;
215 PCI_DEVICE_PRESENT_INTERFACE PciInterface = {0};
220
221 DPRINT("USBPORT_IsCompanionController: ... \n");
222
223 *IsCompanion = FALSE;
224
226
228
230 HighestDevice,
231 NULL,
232 0,
233 NULL,
234 &Event,
236
237 if (!Irp)
238 {
240 ObDereferenceObject(HighestDevice);
241 return Status;
242 }
243
245
246 Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
247 Irp->IoStatus.Information = 0;
248
250
251 IoStack->Parameters.QueryInterface.InterfaceType = &GUID_PCI_DEVICE_PRESENT_INTERFACE;
253 IoStack->Parameters.QueryInterface.Version = 1;
254 IoStack->Parameters.QueryInterface.Interface = (PINTERFACE)&PciInterface;
255 IoStack->Parameters.QueryInterface.InterfaceSpecificData = 0;
256
257 Status = IoCallDriver(HighestDevice, Irp);
258
259 if (Status == STATUS_PENDING)
260 {
263 }
264
265 if (!NT_SUCCESS(Status))
266 {
267 DPRINT1("USBPORT_IsCompanionController: query interface failed\\n");
268 ObDereferenceObject(HighestDevice);
269 return Status;
270 }
271
272 DPRINT("USBPORT_IsCompanionController: query interface succeeded\n");
273
274 if (PciInterface.Size < sizeof(PCI_DEVICE_PRESENT_INTERFACE))
275 {
276 DPRINT1("USBPORT_IsCompanionController: old version\n");
277 ObDereferenceObject(HighestDevice);
278 return Status;
279 }
280
282
286
291
292 IsPresent = (PciInterface.IsDevicePresentEx)(PciInterface.Context,
293 &Parameters);
294
295 if (IsPresent)
296 {
297 DPRINT("USBPORT_IsCompanionController: Present EHCI controller for FDO - %p\n",
299 }
300 else
301 {
302 DPRINT("USBPORT_IsCompanionController: No EHCI controller for FDO - %p\n",
304 }
305
306 *IsCompanion = IsPresent;
307
308 (PciInterface.InterfaceDereference)(PciInterface.Context);
309
310 ObDereferenceObject(HighestDevice);
311
312 return Status;
313}
unsigned char BOOLEAN
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
#define STATUS_NOT_SUPPORTED
Definition: d3dkmdt.h:48
_Must_inspect_result_ _In_ WDFDEVICE _In_ BOOLEAN IsPresent
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
@ SynchronizationEvent
PDEVICE_OBJECT NTAPI IoGetAttachedDeviceReference(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1406
PIRP NTAPI IoBuildSynchronousFsdRequest(IN ULONG MajorFunction, IN PDEVICE_OBJECT DeviceObject, IN PVOID Buffer, IN ULONG Length, IN PLARGE_INTEGER StartingOffset, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:1069
struct _INTERFACE * PINTERFACE
struct _IO_STACK_LOCATION::@3978::@4004 QueryInterface
PINTERFACE_DEREFERENCE InterfaceDereference
Definition: iotypes.h:924
PPCI_IS_DEVICE_PRESENT_EX IsDevicePresentEx
Definition: iotypes.h:926
#define PCI_INTERFACE_USB_ID_EHCI
Definition: usbport.h:25
_Must_inspect_result_ _In_ WDFQUEUE _In_opt_ WDFREQUEST _In_opt_ WDFFILEOBJECT _Inout_opt_ PWDF_REQUEST_PARAMETERS Parameters
Definition: wdfio.h:869
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2695
#define PCI_USE_PROGIF
Definition: iotypes.h:870
struct _PCI_DEVICE_PRESENT_INTERFACE PCI_DEVICE_PRESENT_INTERFACE
#define PCI_USE_CLASS_SUBCLASS
Definition: iotypes.h:869
#define PCI_SUBCLASS_SB_USB
Definition: iotypes.h:4207
#define PCI_CLASS_SERIAL_BUS_CTLR
Definition: iotypes.h:4115
#define PCI_USE_LOCAL_DEVICE
Definition: iotypes.h:872
#define PCI_USE_LOCAL_BUS
Definition: iotypes.h:871
@ Executive
Definition: ketypes.h:415
#define ObDereferenceObject
Definition: obfuncs.h:203

Referenced by USBPORT_StartDevice().

◆ USBPORT_IsSelectiveSuspendEnabled()

BOOLEAN NTAPI USBPORT_IsSelectiveSuspendEnabled ( IN PDEVICE_OBJECT  FdoDevice)

Definition at line 88 of file pnp.c.

89{
91 ULONG Disabled = 0;
92
93 DPRINT("USBPORT_IsSelectiveSuspendEnabled: ... \n");
94
95 FdoExtension = FdoDevice->DeviceExtension;
96
98 FdoExtension->CommonExtension.LowerPdoDevice,
99 TRUE,
100 L"HcDisableSelectiveSuspend",
101 sizeof(L"HcDisableSelectiveSuspend"),
102 &Disabled,
103 sizeof(Disabled));
104
105 return (Disabled == 0);
106}
@ Disabled
Definition: mountmgr.h:178
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

Referenced by USBPORT_StartDevice().

◆ USBPORT_ParseResources()

NTSTATUS NTAPI USBPORT_ParseResources ( IN PDEVICE_OBJECT  FdoDevice,
IN PIRP  Irp,
IN PUSBPORT_RESOURCES  UsbPortResources 
)

Definition at line 912 of file pnp.c.

915{
918 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
919 PCM_PARTIAL_RESOURCE_DESCRIPTOR PortDescriptor = NULL;
921 PCM_PARTIAL_RESOURCE_DESCRIPTOR InterruptDescriptor = NULL;
922 PIO_STACK_LOCATION IoStack;
923 ULONG ix;
925
926 DPRINT("USBPORT_ParseResources: ... \n");
927
929 AllocatedResourcesTranslated = IoStack->Parameters.StartDevice.AllocatedResourcesTranslated;
930
932 {
933 RtlZeroMemory(UsbPortResources, sizeof(USBPORT_RESOURCES));
934
935 ResourceList = &AllocatedResourcesTranslated->List[0].PartialResourceList;
936
937 PartialDescriptor = &ResourceList->PartialDescriptors[0];
938
939 for (ix = 0; ix < ResourceList->Count; ++ix)
940 {
941 if (PartialDescriptor->Type == CmResourceTypePort)
942 {
943 if (!PortDescriptor)
944 PortDescriptor = PartialDescriptor;
945 }
946 else if (PartialDescriptor->Type == CmResourceTypeInterrupt)
947 {
948 if (!InterruptDescriptor)
949 InterruptDescriptor = PartialDescriptor;
950 }
951 else if (PartialDescriptor->Type == CmResourceTypeMemory)
952 {
953 if (!MemoryDescriptor)
954 MemoryDescriptor = PartialDescriptor;
955 }
956
957 PartialDescriptor += 1;
958 }
959
960 if (PortDescriptor)
961 {
962 if (PortDescriptor->Flags & CM_RESOURCE_PORT_IO)
963 {
964 UsbPortResources->ResourceBase = (PVOID)(ULONG_PTR)PortDescriptor->u.Port.Start.QuadPart;
965 }
966 else
967 {
968 UsbPortResources->ResourceBase = MmMapIoSpace(PortDescriptor->u.Port.Start,
969 PortDescriptor->u.Port.Length,
970 0);
971 }
972
973 UsbPortResources->IoSpaceLength = PortDescriptor->u.Port.Length;
974
975 if (UsbPortResources->ResourceBase)
976 {
977 UsbPortResources->ResourcesTypes |= USBPORT_RESOURCES_PORT;
978 }
979 else
980 {
982 }
983 }
984
986 {
987 UsbPortResources->IoSpaceLength = MemoryDescriptor->u.Memory.Length;
988
989 UsbPortResources->ResourceBase = MmMapIoSpace(MemoryDescriptor->u.Memory.Start,
990 MemoryDescriptor->u.Memory.Length,
991 0);
992
993 if (UsbPortResources->ResourceBase)
994 {
995 UsbPortResources->ResourcesTypes |= USBPORT_RESOURCES_MEMORY;
996 }
997 else
998 {
1000 }
1001 }
1002
1003 if (InterruptDescriptor && NT_SUCCESS(Status))
1004 {
1005 UsbPortResources->ResourcesTypes |= USBPORT_RESOURCES_INTERRUPT;
1006
1007 UsbPortResources->InterruptVector = InterruptDescriptor->u.Interrupt.Vector;
1008 UsbPortResources->InterruptLevel = InterruptDescriptor->u.Interrupt.Level;
1009 UsbPortResources->InterruptAffinity = InterruptDescriptor->u.Interrupt.Affinity;
1010
1011 UsbPortResources->ShareVector = InterruptDescriptor->ShareDisposition ==
1013
1014 UsbPortResources->InterruptMode = InterruptDescriptor->Flags ==
1016 }
1017 }
1018 else
1019 {
1021 }
1022
1023 return Status;
1024}
#define CmResourceTypeMemory
Definition: hwresource.cpp:125
#define CmResourceTypePort
Definition: hwresource.cpp:123
#define CmResourceTypeInterrupt
Definition: hwresource.cpp:124
PVOID NTAPI MmMapIoSpace(IN PHYSICAL_ADDRESS PhysicalAddress, IN SIZE_T NumberOfBytes, IN MEMORY_CACHING_TYPE CacheType)
Definition: iosup.c:47
_Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PCM_RESOURCE_LIST _Inout_opt_ PCM_RESOURCE_LIST * AllocatedResourcesTranslated
Definition: ndis.h:4644
#define CM_RESOURCE_PORT_IO
Definition: cmtypes.h:109
#define CM_RESOURCE_INTERRUPT_LATCHED
Definition: cmtypes.h:144
#define STATUS_NONE_MAPPED
Definition: ntstatus.h:351
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@391::@393 Port
union _CM_PARTIAL_RESOURCE_DESCRIPTOR::@391 u
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@391::@394 Interrupt
struct _IO_STACK_LOCATION::@3978::@4015 StartDevice
void * PVOID
Definition: typedefs.h:50
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define USBPORT_RESOURCES_PORT
Definition: usbmport.h:40
#define USBPORT_RESOURCES_MEMORY
Definition: usbmport.h:42
#define USBPORT_RESOURCES_INTERRUPT
Definition: usbmport.h:41
_Must_inspect_result_ _In_ WDFIORESREQLIST _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFIORESLIST * ResourceList
Definition: wdfresource.h:309
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_opt_ WDFREQUEST _In_opt_ PWDF_REQUEST_SEND_OPTIONS _In_ PWDF_USB_CONTROL_SETUP_PACKET _In_opt_ PWDF_MEMORY_DESCRIPTOR MemoryDescriptor
Definition: wdfusb.h:1339
@ CmResourceShareShared
Definition: cmtypes.h:243

Referenced by USBPORT_FdoPnP().

◆ USBPORT_PdoPnP()

NTSTATUS NTAPI USBPORT_PdoPnP ( IN PDEVICE_OBJECT  PdoDevice,
IN PIRP  Irp 
)

Definition at line 1517 of file pnp.c.

1519{
1521 PUSBPORT_COMMON_DEVICE_EXTENSION PdoCommonExtension;
1522 PDEVICE_OBJECT FdoDevice;
1524 PIO_STACK_LOCATION IoStack;
1525 UCHAR Minor;
1529
1530 PdoExtension = PdoDevice->DeviceExtension;
1531 PdoCommonExtension = &PdoExtension->CommonExtension;
1532
1533 FdoDevice = PdoExtension->FdoDevice;
1534 FdoExtension = FdoDevice->DeviceExtension;
1535
1537 Minor = IoStack->MinorFunction;
1538
1539 Status = Irp->IoStatus.Status;
1540
1541 DPRINT("USBPORT_PdoPnP: PdoDevice - %p, Minor - %x\n", PdoDevice, Minor);
1542
1543 switch (Minor)
1544 {
1546 DPRINT("IRP_MN_START_DEVICE\n");
1547
1548 Status = USBPORT_RootHubCreateDevice(FdoDevice, PdoDevice);
1549
1550 if (NT_SUCCESS(Status))
1551 {
1553 PdoDevice,
1554 &GUID_DEVINTERFACE_USB_HUB,
1555 TRUE);
1556
1557 if (NT_SUCCESS(Status))
1558 {
1559 PdoCommonExtension->DevicePowerState = PowerDeviceD0;
1560 PdoCommonExtension->PnpStateFlags = USBPORT_PNP_STATE_STARTED;
1561 }
1562 }
1563
1564 break;
1565
1567 DPRINT("USBPORT_PdoPnP: IRP_MN_QUERY_REMOVE_DEVICE\n");
1569 break;
1570
1572 DPRINT1("USBPORT_PdoPnP: IRP_MN_REMOVE_DEVICE UNIMPLEMENTED. FIXME. \n");
1573 //USBPORT_StopRootHub();
1575 break;
1576
1578 DPRINT("IRP_MN_CANCEL_REMOVE_DEVICE\n");
1580 break;
1581
1582 case IRP_MN_STOP_DEVICE:
1583 DPRINT1("USBPORT_PdoPnP: IRP_MN_STOP_DEVICE UNIMPLEMENTED. FIXME. \n");
1584 //USBPORT_StopRootHub();
1586 break;
1587
1589 DPRINT("IRP_MN_QUERY_STOP_DEVICE\n");
1591 break;
1592
1594 DPRINT("IRP_MN_CANCEL_STOP_DEVICE\n");
1596 break;
1597
1599 {
1600 PDEVICE_RELATIONS DeviceRelations;
1601
1602 DPRINT("IRP_MN_QUERY_DEVICE_RELATIONS\n");
1604 {
1605 break;
1606 }
1607
1608 DeviceRelations = ExAllocatePoolWithTag(PagedPool,
1609 sizeof(DEVICE_RELATIONS),
1610 USB_PORT_TAG);
1611
1612 if (!DeviceRelations)
1613 {
1615 Irp->IoStatus.Information = 0;
1616 break;
1617 }
1618
1619 DeviceRelations->Count = 1;
1620 DeviceRelations->Objects[0] = PdoDevice;
1621
1622 ObReferenceObject(PdoDevice);
1623
1625 Irp->IoStatus.Information = (ULONG_PTR)DeviceRelations;
1626 break;
1627 }
1628
1630 DPRINT("IRP_MN_QUERY_INTERFACE\n");
1631 Status = USBPORT_PdoQueryInterface(FdoDevice, PdoDevice, Irp);
1632 break;
1633
1635 DPRINT("IRP_MN_QUERY_CAPABILITIES\n");
1636
1637 DeviceCapabilities = IoStack->Parameters.DeviceCapabilities.Capabilities;
1638
1640 &PdoExtension->Capabilities,
1641 sizeof(DEVICE_CAPABILITIES));
1642
1644 break;
1645
1647 DPRINT("USBPORT_PdoPnP: IRP_MN_QUERY_RESOURCES\n");
1648 break;
1649
1651 DPRINT("IRP_MN_QUERY_RESOURCE_REQUIREMENTS\n");
1652 break;
1653
1655 DPRINT("IRP_MN_QUERY_DEVICE_TEXT\n");
1656 break;
1657
1659 DPRINT("IRP_MN_FILTER_RESOURCE_REQUIREMENTS\n");
1660 break;
1661
1662 case IRP_MN_READ_CONFIG:
1663 DPRINT("IRP_MN_READ_CONFIG\n");
1664 ASSERT(FALSE);
1665 break;
1666
1668 DPRINT("IRP_MN_WRITE_CONFIG\n");
1669 ASSERT(FALSE);
1670 break;
1671
1672 case IRP_MN_EJECT:
1673 DPRINT("IRP_MN_EJECT\n");
1674 ASSERT(FALSE);
1675 break;
1676
1677 case IRP_MN_SET_LOCK:
1678 DPRINT("IRP_MN_SET_LOCK\n");
1679 ASSERT(FALSE);
1680 break;
1681
1682 case IRP_MN_QUERY_ID:
1683 {
1684 ULONG IdType;
1685 LONG Length;
1686 WCHAR Buffer[64] = {0};
1687 PVOID Id;
1688
1690 IdType = IoStack->Parameters.QueryId.IdType;
1691
1692 DPRINT("IRP_MN_QUERY_ID/Type %x\n", IdType);
1693
1694 if (IdType == BusQueryDeviceID)
1695 {
1697 Packet = &FdoExtension->MiniPortInterface->Packet;
1698
1699 if (Packet->MiniPortFlags & USB_MINIPORT_FLAGS_USB2)
1700 {
1702 sizeof(Buffer),
1703 L"USB\\ROOT_HUB20");
1704 }
1705 else
1706 {
1708 sizeof(Buffer),
1709 L"USB\\ROOT_HUB");
1710 }
1711
1712 Length = (LONG)(wcslen(Buffer) + 1);
1713
1715 Length * sizeof(WCHAR),
1716 USB_PORT_TAG);
1717
1718 if (Id)
1719 {
1720 RtlZeroMemory(Id, Length * sizeof(WCHAR));
1721 RtlStringCbCopyW(Id, Length * sizeof(WCHAR), Buffer);
1722
1723 DPRINT("BusQueryDeviceID - %S, TotalLength - %hu\n",
1724 Id,
1725 Length);
1726 }
1727
1728 Irp->IoStatus.Information = (ULONG_PTR)Id;
1729 break;
1730 }
1731
1733 {
1734 Id = USBPORT_GetDeviceHwIds(FdoDevice,
1735 FdoExtension->VendorID,
1736 FdoExtension->DeviceID,
1737 FdoExtension->RevisionID);
1738
1739 Irp->IoStatus.Information = (ULONG_PTR)Id;
1740 break;
1741 }
1742
1745 {
1746 Irp->IoStatus.Information = 0;
1747 break;
1748 }
1749
1750 /* IdType == BusQueryDeviceSerialNumber */
1751 Status = Irp->IoStatus.Status;
1752 break;
1753 }
1754
1756 DPRINT("IRP_MN_QUERY_PNP_DEVICE_STATE\n");
1758 break;
1759
1761 DPRINT("IRP_MN_QUERY_BUS_INFORMATION\n");
1762
1763 /* Allocate buffer for bus information */
1765 sizeof(PNP_BUS_INFORMATION),
1766 USB_PORT_TAG);
1767
1768 if (!BusInformation)
1769 {
1770 /* No memory */
1772 break;
1773 }
1774
1776
1777 /* Copy BUS GUID */
1778 RtlMoveMemory(&BusInformation->BusTypeGuid,
1779 &GUID_BUS_TYPE_USB,
1780 sizeof(GUID));
1781
1782 /* Set bus type */
1783 BusInformation->LegacyBusType = PNPBus;
1784 BusInformation->BusNumber = 0;
1785
1787 Irp->IoStatus.Information = (ULONG_PTR)BusInformation;
1788 break;
1789
1791 DPRINT("IRP_MN_DEVICE_USAGE_NOTIFICATION\n");
1792 break;
1793
1795 DPRINT("USBPORT_PdoPnP: IRP_MN_SURPRISE_REMOVAL\n");
1797 break;
1798
1799 default:
1800 DPRINT("unknown IRP_MN_???\n");
1801 break;
1802 }
1803
1804 Irp->IoStatus.Status = Status;
1806 return Status;
1807}
_In_ BUS_QUERY_ID_TYPE IdType
Definition: classpnp.h:374
PVOID NTAPI USBPORT_GetDeviceHwIds(IN PDEVICE_OBJECT FdoDevice, IN USHORT VendorID, IN USHORT DeviceID, IN USHORT RevisionID)
Definition: pnp.c:1407
NTSTATUS NTAPI USBPORT_RegisterDeviceInterface(IN PDEVICE_OBJECT PdoDevice, IN PDEVICE_OBJECT DeviceObject, IN CONST GUID *InterfaceClassGuid, IN BOOLEAN Enable)
Definition: pnp.c:30
@ PNPBus
Definition: hwresource.cpp:152
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define ASSERT(a)
Definition: mode.c:44
NTSTRSAFEAPI RtlStringCbCopyW(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCWSTR pszSrc)
Definition: ntstrsafe.h:174
long LONG
Definition: pedump.c:60
PVOID DeviceExtension
Definition: env_spec_w32.h:418
struct _IO_STACK_LOCATION::@3978::@4005 DeviceCapabilities
struct _IO_STACK_LOCATION::@3978::@4009 QueryId
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
NTSTATUS NTAPI USBPORT_PdoQueryInterface(IN PDEVICE_OBJECT FdoDevice, IN PDEVICE_OBJECT PdoDevice, IN PIRP Irp)
Definition: iface.c:782
NTSTATUS NTAPI USBPORT_RootHubCreateDevice(IN PDEVICE_OBJECT FdoDevice, IN PDEVICE_OBJECT PdoDevice)
Definition: roothub.c:747
_In_ WDFDEVICE _In_ PPNP_BUS_INFORMATION BusInformation
Definition: wdfdevice.h:3915
#define DeviceCapabilities
Definition: wingdi.h:4449
DEVICE_CAPABILITIES
Definition: iotypes.h:965
@ TargetDeviceRelation
Definition: iotypes.h:2156
* PDEVICE_CAPABILITIES
Definition: iotypes.h:965
@ BusQueryCompatibleIDs
Definition: iotypes.h:2938
@ BusQueryInstanceID
Definition: iotypes.h:2939
@ BusQueryDeviceID
Definition: iotypes.h:2936
@ BusQueryHardwareIDs
Definition: iotypes.h:2937

Referenced by USBPORT_Dispatch().

◆ USBPORT_QueryCapabilities()

NTSTATUS NTAPI USBPORT_QueryCapabilities ( IN PDEVICE_OBJECT  FdoDevice,
IN PDEVICE_CAPABILITIES  Capabilities 
)

Definition at line 382 of file pnp.c.

384{
385 PUSBPORT_DEVICE_EXTENSION FdoExtention;
386 PIRP Irp;
388 PIO_STACK_LOCATION IoStack;
390
391 DPRINT("USBPORT_QueryCapabilities: ... \n");
392
393 FdoExtention = FdoDevice->DeviceExtension;
394
396
397 Capabilities->Size = sizeof(DEVICE_CAPABILITIES);
398 Capabilities->Version = 1;
399 Capabilities->Address = MAXULONG;
400 Capabilities->UINumber = MAXULONG;
401
403 FALSE);
404
405 if (!Irp)
406 {
407 DPRINT1("USBPORT_QueryCapabilities: No resources - IoAllocateIrp!\n");
409 }
410
412 Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
413
415 IoStack->MajorFunction = IRP_MJ_PNP;
417
419
422 &Event,
423 TRUE,
424 TRUE,
425 TRUE);
426
427 IoStack->Parameters.DeviceCapabilities.Capabilities = Capabilities;
428
430
431 if (Status == STATUS_PENDING)
432 {
434 Status = Irp->IoStatus.Status;
435 }
436
438 {
440 }
441
442 IoFreeIrp(Irp);
443
444 return Status;
445}
VOID NTAPI USBPORT_DumpingCapabilities(IN PDEVICE_CAPABILITIES Capabilities)
Definition: debug.c:170
_Must_inspect_result_ typedef _Out_ PHIDP_CAPS Capabilities
Definition: hidclass.h:103
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
USBPORT_COMMON_DEVICE_EXTENSION CommonExtension
Definition: usbport.h:292
#define MAXULONG
Definition: typedefs.h:251

Referenced by USBPORT_StartDevice().

◆ USBPORT_QueryPciBusInterface()

NTSTATUS NTAPI USBPORT_QueryPciBusInterface ( IN PDEVICE_OBJECT  FdoDevice)

Definition at line 317 of file pnp.c.

318{
320 PBUS_INTERFACE_STANDARD BusInterface;
321 PIO_STACK_LOCATION IoStack;
323 PDEVICE_OBJECT HighestDevice;
325 PIRP Irp;
327
328 DPRINT("USBPORT_QueryPciBusInterface: ... \n");
329
330 FdoExtension = FdoDevice->DeviceExtension;
331 BusInterface = &FdoExtension->BusInterface;
332
333 RtlZeroMemory(BusInterface, sizeof(BUS_INTERFACE_STANDARD));
335 HighestDevice = IoGetAttachedDeviceReference(FdoDevice);
336
338 HighestDevice,
339 NULL,
340 0,
341 NULL,
342 &Event,
344
345 if (Irp)
346 {
348
349 Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
350 Irp->IoStatus.Information = 0;
351
353
354 IoStack->Parameters.QueryInterface.InterfaceType = &GUID_BUS_INTERFACE_STANDARD;
355 IoStack->Parameters.QueryInterface.Size = sizeof(BUS_INTERFACE_STANDARD);
356 IoStack->Parameters.QueryInterface.Version = 1;
357 IoStack->Parameters.QueryInterface.Interface = (PINTERFACE)BusInterface;
358 IoStack->Parameters.QueryInterface.InterfaceSpecificData = 0;
359
360 Status = IoCallDriver(HighestDevice, Irp);
361
362 if (Status == STATUS_PENDING)
363 {
366 }
367 }
368 else
369 {
371 }
372
373 ObDereferenceObject(HighestDevice);
374
375 DPRINT("USBPORT_QueryPciBusInterface: return Status - %x\n", Status);
376
377 return Status;
378}
struct _BUS_INTERFACE_STANDARD BUS_INTERFACE_STANDARD

Referenced by USBPORT_StartDevice().

◆ USBPORT_RegisterDeviceInterface()

NTSTATUS NTAPI USBPORT_RegisterDeviceInterface ( IN PDEVICE_OBJECT  PdoDevice,
IN PDEVICE_OBJECT  DeviceObject,
IN CONST GUID InterfaceClassGuid,
IN BOOLEAN  Enable 
)

Definition at line 30 of file pnp.c.

34{
35 PUSBPORT_RHDEVICE_EXTENSION DeviceExtension;
38
39 DPRINT("USBPORT_RegisterDeviceInterface: Enable - %x\n", Enable);
40
41 DeviceExtension = DeviceObject->DeviceExtension;
43
44 if (Enable)
45 {
48 NULL,
50
51 if (NT_SUCCESS(Status))
52 {
53 DeviceExtension->CommonExtension.IsInterfaceEnabled = 1;
54
56 FALSE,
57 REG_SZ,
58 L"SymbolicName",
59 SymbolicLinkName->Buffer,
60 SymbolicLinkName->Length);
61
62 if (NT_SUCCESS(Status))
63 {
64 DPRINT("USBPORT_RegisterDeviceInterface: LinkName - %wZ\n",
65 &DeviceExtension->CommonExtension.SymbolicLinkName);
66
68 }
69 }
70 }
71 else
72 {
73 /* Disable device interface */
75
76 if (NT_SUCCESS(Status))
77 {
79 DeviceExtension->CommonExtension.IsInterfaceEnabled = 0; // Disabled interface
80 }
81 }
82
83 return Status;
84}
#define REG_SZ
Definition: layer.c:22
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
_In_ ULONGLONG _In_ ULONGLONG _In_ BOOLEAN Enable
Definition: ntddpcm.h:142
NTSTATUS NTAPI IoRegisterDeviceInterface(IN PDEVICE_OBJECT PhysicalDeviceObject, IN CONST GUID *InterfaceClassGuid, IN PUNICODE_STRING ReferenceString OPTIONAL, OUT PUNICODE_STRING SymbolicLinkName)
Definition: deviface.c:955
NTSTATUS NTAPI IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName, IN BOOLEAN Enable)
Definition: deviface.c:1311
UNICODE_STRING SymbolicLinkName
Definition: usbport.h:285
USBPORT_COMMON_DEVICE_EXTENSION CommonExtension
Definition: usbport.h:418
NTSTATUS NTAPI USBPORT_SetRegistryKeyValue(IN PDEVICE_OBJECT DeviceObject, IN BOOL UseDriverKey, IN ULONG Type, IN PCWSTR ValueNameString, IN PVOID Data, IN ULONG DataSize)
Definition: usbport.c:248
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING SymbolicLinkName
Definition: wdfdevice.h:3739
_In_ CONST GUID * InterfaceClassGuid
Definition: iofuncs.h:1136

Referenced by USBPORT_PdoPnP(), and USBPORT_StartDevice().

◆ USBPORT_StartDevice()

NTSTATUS NTAPI USBPORT_StartDevice ( IN PDEVICE_OBJECT  FdoDevice,
IN PUSBPORT_RESOURCES  UsbPortResources 
)

Definition at line 498 of file pnp.c.

500{
504 PCI_COMMON_CONFIG PciConfig;
507 PDMA_ADAPTER DmaAdapter = NULL;
508 ULONG MiniPortStatus;
511 ULONG DisableSelectiveSuspend = 0;
512 ULONG DisableCcDetect = 0;
513 ULONG IdleEpSupport = 0;
514 ULONG IdleEpSupportEx = 0;
515 ULONG SoftRetry = 0;
516 ULONG Limit2GB = 0;
517 ULONG TotalBusBandwidth = 0;
518 BOOLEAN IsCompanion = FALSE;
519 ULONG LegacyBIOS;
520 ULONG MiniportFlags;
521 ULONG ix;
522
523 DPRINT("USBPORT_StartDevice: FdoDevice - %p, UsbPortResources - %p\n",
524 FdoDevice,
525 UsbPortResources);
526
527 FdoExtension = FdoDevice->DeviceExtension;
528 Packet = &FdoExtension->MiniPortInterface->Packet;
529
531 if (!NT_SUCCESS(Status))
532 goto ExitWithError;
533
534 BytesRead = (*FdoExtension->BusInterface.GetBusData)(FdoExtension->BusInterface.Context,
536 &PciConfig,
537 0,
539
541 {
542 DPRINT1("USBPORT_StartDevice: Failed to get pci config information!\n");
543 goto ExitWithError;
544 }
545
546 FdoExtension->VendorID = PciConfig.VendorID;
547 FdoExtension->DeviceID = PciConfig.DeviceID;
548 FdoExtension->RevisionID = PciConfig.RevisionID;
549 FdoExtension->ProgIf = PciConfig.ProgIf;
550 FdoExtension->SubClass = PciConfig.SubClass;
551 FdoExtension->BaseClass = PciConfig.BaseClass;
552
554
556 DeviceDescription.Master = TRUE;
557 DeviceDescription.ScatterGather = TRUE;
558 DeviceDescription.Dma32BitAddresses = TRUE;
559 DeviceDescription.InterfaceType = PCIBus;
561 DeviceDescription.DmaSpeed = Compatible;
562 DeviceDescription.MaximumLength = MAXULONG;
563
564 DmaAdapter = IoGetDmaAdapter(FdoExtension->CommonExtension.LowerPdoDevice,
566 &FdoExtension->NumberMapRegs);
567
568 FdoExtension->DmaAdapter = DmaAdapter;
569
570 if (!DmaAdapter)
571 {
572 DPRINT1("USBPORT_StartDevice: Failed to get DmaAdapter!\n");
574 goto ExitWithError;
575 }
576
578 if (!NT_SUCCESS(Status))
579 goto ExitWithError;
580
581 Status = USBPORT_QueryCapabilities(FdoDevice, &FdoExtension->Capabilities);
582 if (!NT_SUCCESS(Status))
583 goto ExitWithError;
584
585 FdoExtension->PciDeviceNumber = FdoExtension->Capabilities.Address >> 16;
586 FdoExtension->PciFunctionNumber = FdoExtension->Capabilities.Address & 0xFFFF;
587
588 Status = IoGetDeviceProperty(FdoExtension->CommonExtension.LowerPdoDevice,
590 sizeof(ULONG),
591 &FdoExtension->BusNumber,
592 &ResultLength);
593
594 if (!NT_SUCCESS(Status))
595 goto ExitWithError;
596
597 KeInitializeSpinLock(&FdoExtension->EndpointListSpinLock);
598 KeInitializeSpinLock(&FdoExtension->EpStateChangeSpinLock);
599 KeInitializeSpinLock(&FdoExtension->EndpointClosedSpinLock);
600 KeInitializeSpinLock(&FdoExtension->DeviceHandleSpinLock);
601 KeInitializeSpinLock(&FdoExtension->IdleIoCsqSpinLock);
602 KeInitializeSpinLock(&FdoExtension->BadRequestIoCsqSpinLock);
603 KeInitializeSpinLock(&FdoExtension->MapTransferSpinLock);
604 KeInitializeSpinLock(&FdoExtension->FlushTransferSpinLock);
605 KeInitializeSpinLock(&FdoExtension->FlushPendingTransferSpinLock);
606 KeInitializeSpinLock(&FdoExtension->DoneTransferSpinLock);
607 KeInitializeSpinLock(&FdoExtension->WorkerThreadEventSpinLock);
608 KeInitializeSpinLock(&FdoExtension->MiniportSpinLock);
609 KeInitializeSpinLock(&FdoExtension->TimerFlagsSpinLock);
610 KeInitializeSpinLock(&FdoExtension->PowerWakeSpinLock);
611 KeInitializeSpinLock(&FdoExtension->SetPowerD0SpinLock);
612 KeInitializeSpinLock(&FdoExtension->RootHubCallbackSpinLock);
614
615 KeInitializeDpc(&FdoExtension->IsrDpc, USBPORT_IsrDpc, FdoDevice);
616
617 KeInitializeDpc(&FdoExtension->TransferFlushDpc,
619 FdoDevice);
620
621 KeInitializeDpc(&FdoExtension->WorkerRequestDpc,
623 FdoDevice);
624
625 KeInitializeDpc(&FdoExtension->HcWakeDpc,
627 FdoDevice);
628
629 IoCsqInitialize(&FdoExtension->IdleIoCsq,
636
637 IoCsqInitialize(&FdoExtension->BadRequestIoCsq,
644
645 FdoExtension->IsrDpcCounter = -1;
646 FdoExtension->IsrDpcHandlerCounter = -1;
647 FdoExtension->IdleLockCounter = -1;
648 FdoExtension->BadRequestLockCounter = -1;
649 FdoExtension->ChirpRootPortLock = -1;
650
651 FdoExtension->RHInitCallBackLock = 0;
652
653 FdoExtension->UsbAddressBitMap[0] = 1;
654 FdoExtension->UsbAddressBitMap[1] = 0;
655 FdoExtension->UsbAddressBitMap[2] = 0;
656 FdoExtension->UsbAddressBitMap[3] = 0;
657
658 USBPORT_GetDefaultBIOSx(FdoDevice,
659 &FdoExtension->UsbBIOSx,
660 &DisableSelectiveSuspend,
661 &DisableCcDetect,
662 &IdleEpSupport,
663 &IdleEpSupportEx,
664 &SoftRetry);
665
666 if (DisableSelectiveSuspend)
668
669 if (!DisableSelectiveSuspend &&
671 {
673 }
674
675 MiniportFlags = Packet->MiniPortFlags;
676
677 if (MiniportFlags & USB_MINIPORT_FLAGS_POLLING)
679
680 if (MiniportFlags & USB_MINIPORT_FLAGS_WAKE_SUPPORT)
682
683 if (MiniportFlags & USB_MINIPORT_FLAGS_DISABLE_SS)
684 FdoExtension->Flags = (FdoExtension->Flags & ~USBPORT_FLAG_SELECTIVE_SUSPEND) |
686
687 USBPORT_SetRegistryKeyValue(FdoExtension->CommonExtension.LowerPdoDevice,
688 TRUE,
689 REG_DWORD,
690 L"EnIdleEndpointSupport",
691 &IdleEpSupport,
692 sizeof(IdleEpSupport));
693
694 USBPORT_SetRegistryKeyValue(FdoExtension->CommonExtension.LowerPdoDevice,
695 TRUE,
696 REG_DWORD,
697 L"EnIdleEndpointSupportEx",
698 &IdleEpSupportEx,
699 sizeof(IdleEpSupportEx));
700
701 USBPORT_SetRegistryKeyValue(FdoExtension->CommonExtension.LowerPdoDevice,
702 TRUE,
703 REG_DWORD,
704 L"EnSoftRetry",
705 &SoftRetry,
706 sizeof(SoftRetry));
707
709 FdoExtension->CommonExtension.LowerPdoDevice,
710 TRUE,
711 L"CommonBuffer2GBLimit",
712 sizeof(L"CommonBuffer2GBLimit"),
713 &Limit2GB,
714 sizeof(Limit2GB));
715
716 FdoExtension->CommonBufferLimit = (Limit2GB != 0);
717
718 if (FdoExtension->BaseClass == PCI_CLASS_SERIAL_BUS_CTLR &&
719 FdoExtension->SubClass == PCI_SUBCLASS_SB_USB &&
721 {
722 Status = USBPORT_IsCompanionController(FdoDevice, &IsCompanion);
723
724 if (!NT_SUCCESS(Status))
725 {
726 if (IsCompanion)
727 {
729 }
730 else
731 {
732 FdoExtension->Flags &= ~USBPORT_FLAG_COMPANION_HC;
733 }
734 }
735 }
736
737 if (DisableCcDetect)
738 {
739 FdoExtension->Flags &= ~USBPORT_FLAG_COMPANION_HC;
740 }
741
742 TotalBusBandwidth = Packet->MiniPortBusBandwidth;
743 FdoExtension->TotalBusBandwidth = TotalBusBandwidth;
744
746 FdoExtension->CommonExtension.LowerPdoDevice,
747 TRUE,
748 L"TotalBusBandwidth",
749 sizeof(L"TotalBusBandwidth"),
750 &TotalBusBandwidth,
751 sizeof(TotalBusBandwidth));
752
753 if (TotalBusBandwidth != FdoExtension->TotalBusBandwidth)
754 {
755 FdoExtension->TotalBusBandwidth = TotalBusBandwidth;
756 }
757
758 for (ix = 0; ix < USB2_FRAMES; ix++)
759 {
760 FdoExtension->Bandwidth[ix] = FdoExtension->TotalBusBandwidth -
761 FdoExtension->TotalBusBandwidth / 10;
762 }
763
765 sizeof(USBPORT_IRP_TABLE),
767
768 if (!FdoExtension->ActiveIrpTable)
769 {
770 DPRINT1("USBPORT_StartDevice: Allocate ActiveIrpTable failed!\n");
771 goto ExitWithError;
772 }
773
774 RtlZeroMemory(FdoExtension->ActiveIrpTable, sizeof(USBPORT_IRP_TABLE));
775
777 sizeof(USBPORT_IRP_TABLE),
779
780 if (!FdoExtension->PendingIrpTable)
781 {
782 DPRINT1("USBPORT_StartDevice: Allocate PendingIrpTable failed!\n");
783 goto ExitWithError;
784 }
785
786 RtlZeroMemory(FdoExtension->PendingIrpTable, sizeof(USBPORT_IRP_TABLE));
787
788 Status = IoConnectInterrupt(&FdoExtension->InterruptObject,
790 (PVOID)FdoDevice,
791 0,
792 UsbPortResources->InterruptVector,
793 UsbPortResources->InterruptLevel,
794 UsbPortResources->InterruptLevel,
795 UsbPortResources->InterruptMode,
796 UsbPortResources->ShareVector,
797 UsbPortResources->InterruptAffinity,
798 0);
799
800
801 if (!NT_SUCCESS(Status))
802 {
803 DPRINT1("USBPORT_StartDevice: IoConnectInterrupt failed!\n");
804 goto ExitWithError;
805 }
806
807 FdoExtension->Flags &= ~USBPORT_FLAG_INT_CONNECTED;
808
809 if (Packet->MiniPortExtensionSize)
810 {
811 RtlZeroMemory(FdoExtension->MiniPortExt, Packet->MiniPortExtensionSize);
812 }
813
814 if (Packet->MiniPortResourcesSize)
815 {
816 HeaderBuffer = USBPORT_AllocateCommonBuffer(FdoDevice,
817 Packet->MiniPortResourcesSize);
818
819 if (!HeaderBuffer)
820 {
821 DPRINT1("USBPORT_StartDevice: Failed to AllocateCommonBuffer!\n");
823 goto ExitWithError;
824 }
825
826 UsbPortResources->StartVA = HeaderBuffer->VirtualAddress;
827 UsbPortResources->StartPA = HeaderBuffer->PhysicalAddress;
828
829 FdoExtension->MiniPortCommonBuffer = HeaderBuffer;
830 }
831 else
832 {
833 FdoExtension->MiniPortCommonBuffer = NULL;
834 }
835
836 MiniPortStatus = Packet->StartController(FdoExtension->MiniPortExt,
837 UsbPortResources);
838
839 if (UsbPortResources->LegacySupport)
840 {
842 LegacyBIOS = 1;
843 }
844 else
845 {
846 LegacyBIOS = 0;
847 }
848
849 USBPORT_SetRegistryKeyValue(FdoExtension->CommonExtension.LowerPdoDevice,
850 FALSE,
851 REG_DWORD,
852 L"DetectedLegacyBIOS",
853 &LegacyBIOS,
854 sizeof(LegacyBIOS));
855
856 if (MiniPortStatus)
857 {
858 DPRINT1("USBPORT_StartDevice: Failed to Start MiniPort. MiniPortStatus - %x\n",
859 MiniPortStatus);
860
862 {
863 IoDisconnectInterrupt(FdoExtension->InterruptObject);
864 FdoExtension->Flags &= ~USBPORT_FLAG_INT_CONNECTED;
865 }
866
867 if (FdoExtension->MiniPortCommonBuffer)
868 {
869 USBPORT_FreeCommonBuffer(FdoDevice, FdoExtension->MiniPortCommonBuffer);
870 FdoExtension->MiniPortCommonBuffer = NULL;
871 }
872
873 goto ExitWithError;
874 }
875 else
876 {
879 }
880
881 FdoExtension->TimerValue = 500;
882 USBPORT_StartTimer((PVOID)FdoDevice, 500);
883
884 Status = USBPORT_RegisterDeviceInterface(FdoExtension->CommonExtension.LowerPdoDevice,
885 FdoDevice,
886 &GUID_DEVINTERFACE_USB_HOST_CONTROLLER,
887 TRUE);
888
889 if (!NT_SUCCESS(Status))
890 {
891 DPRINT1("USBPORT_StartDevice: RegisterDeviceInterface failed!\n");
892 goto ExitWithError;
893 }
894
896
898
899 DPRINT("USBPORT_StartDevice: Exit Status - %p\n", Status);
900 return Status;
901
902ExitWithError:
903 USBPORT_StopWorkerThread(FdoDevice);
904 USBPORT_StopDevice(FdoDevice);
905
906 DPRINT1("USBPORT_StartDevice: ExitWithError Status - %lx\n", Status);
907 return Status;
908}
NTKERNELAPI NTSTATUS NTAPI IoCsqInitialize(_Out_ PIO_CSQ Csq, _In_ PIO_CSQ_INSERT_IRP CsqInsertIrp, _In_ PIO_CSQ_REMOVE_IRP CsqRemoveIrp, _In_ PIO_CSQ_PEEK_NEXT_IRP CsqPeekNextIrp, _In_ PIO_CSQ_ACQUIRE_LOCK CsqAcquireLock, _In_ PIO_CSQ_RELEASE_LOCK CsqReleaseLock, _In_ PIO_CSQ_COMPLETE_CANCELED_IRP CsqCompleteCanceledIrp)
Set up a CSQ struct to initialize the queue.
Definition: csq.c:103
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:712
NTSTATUS NTAPI USBPORT_IsCompanionController(IN PDEVICE_OBJECT DeviceObject, IN BOOLEAN *IsCompanion)
Definition: pnp.c:208
BOOLEAN NTAPI USBPORT_IsSelectiveSuspendEnabled(IN PDEVICE_OBJECT FdoDevice)
Definition: pnp.c:88
NTSTATUS NTAPI USBPORT_QueryCapabilities(IN PDEVICE_OBJECT FdoDevice, IN PDEVICE_CAPABILITIES Capabilities)
Definition: pnp.c:382
NTSTATUS NTAPI USBPORT_QueryPciBusInterface(IN PDEVICE_OBJECT FdoDevice)
Definition: pnp.c:317
NTSTATUS NTAPI USBPORT_GetDefaultBIOSx(IN PDEVICE_OBJECT FdoDevice, IN PULONG UsbBIOSx, IN PULONG DisableSelectiveSuspend, IN PULONG DisableCcDetect, IN PULONG IdleEpSupport, IN PULONG IdleEpSupportEx, IN PULONG SoftRetry)
Definition: pnp.c:135
NTSTATUS NTAPI USBPORT_CreateLegacySymbolicLink(IN PDEVICE_OBJECT FdoDevice)
Definition: pnp.c:449
NTSTATUS NTAPI USBPORT_StopDevice(IN PDEVICE_OBJECT FdoDevice)
Definition: pnp.c:490
VOID NTAPI USBPORT_HcWakeDpc(IN PRKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: power.c:52
VOID NTAPI USBPORT_ReleaseIdleLock(IN PIO_CSQ Csq, IN KIRQL Irql)
Definition: queue.c:107
VOID NTAPI USBPORT_RemoveBadRequest(IN PIO_CSQ Csq, IN PIRP Irp)
Definition: queue.c:160
VOID NTAPI USBPORT_InsertIdleIrp(IN PIO_CSQ Csq, IN PIRP Irp)
Definition: queue.c:20
PIRP NTAPI USBPORT_PeekNextBadRequest(IN PIO_CSQ Csq, IN PIRP Irp, IN PVOID PeekContext)
Definition: queue.c:169
PIRP NTAPI USBPORT_PeekNextIdleIrp(IN PIO_CSQ Csq, IN PIRP Irp, IN PVOID PeekContext)
Definition: queue.c:46
VOID NTAPI USBPORT_InsertBadRequest(IN PIO_CSQ Csq, IN PIRP Irp)
Definition: queue.c:143
VOID NTAPI USBPORT_CompleteCanceledBadRequest(IN PIO_CSQ Csq, IN PIRP Irp)
Definition: queue.c:246
VOID NTAPI USBPORT_ReleaseBadRequestLock(IN PIO_CSQ Csq, IN KIRQL Irql)
Definition: queue.c:230
VOID NTAPI USBPORT_CompleteCanceledIdleIrp(IN PIO_CSQ Csq, IN PIRP Irp)
Definition: queue.c:123
VOID NTAPI USBPORT_AcquireBadRequestLock(IN PIO_CSQ Csq, IN PKIRQL Irql)
Definition: queue.c:214
VOID NTAPI USBPORT_AcquireIdleLock(IN PIO_CSQ Csq, IN PKIRQL Irql)
Definition: queue.c:91
VOID NTAPI USBPORT_RemoveIdleIrp(IN PIO_CSQ Csq, IN PIRP Irp)
Definition: queue.c:37
#define NonPagedPool
Definition: env_spec_w32.h:307
#define KeInitializeSpinLock(sl)
Definition: env_spec_w32.h:604
@ PCIBus
Definition: hwresource.cpp:142
VOID NTAPI IoDisconnectInterrupt(PKINTERRUPT InterruptObject)
Definition: irq.c:142
NTSTATUS NTAPI IoConnectInterrupt(OUT PKINTERRUPT *InterruptObject, IN PKSERVICE_ROUTINE ServiceRoutine, IN PVOID ServiceContext, IN PKSPIN_LOCK SpinLock, IN ULONG Vector, IN KIRQL Irql, IN KIRQL SynchronizeIrql, IN KINTERRUPT_MODE InterruptMode, IN BOOLEAN ShareVector, IN KAFFINITY ProcessorEnableMask, IN BOOLEAN FloatingSave)
Definition: irq.c:23
PDMA_ADAPTER NTAPI IoGetDmaAdapter(IN PDEVICE_OBJECT PhysicalDeviceObject, IN PDEVICE_DESCRIPTION DeviceDescription, IN OUT PULONG NumberOfMapRegisters)
Definition: pnpdma.c:23
NTSTATUS NTAPI IoGetDeviceProperty(IN PDEVICE_OBJECT DeviceObject, IN DEVICE_REGISTRY_PROPERTY DeviceProperty, IN ULONG BufferLength, OUT PVOID PropertyBuffer, OUT PULONG ResultLength)
Definition: pnpmgr.c:1382
@ Width32Bits
Definition: miniport.h:107
@ Compatible
Definition: miniport.h:112
#define USB_MINIPORT_FLAGS_POLLING
Definition: usbmport.h:537
#define USB_MINIPORT_FLAGS_DISABLE_SS
Definition: usbmport.h:535
#define USB_MINIPORT_FLAGS_WAKE_SUPPORT
Definition: usbmport.h:539
VOID NTAPI USBPORT_TransferFlushDpc(IN PRKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: usbport.c:825
PUSBPORT_COMMON_BUFFER_HEADER NTAPI USBPORT_AllocateCommonBuffer(IN PDEVICE_OBJECT FdoDevice, IN SIZE_T BufferLength)
Definition: usbport.c:1708
VOID NTAPI USBPORT_IsrDpc(IN PRKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: usbport.c:1031
VOID NTAPI USBPORT_StopWorkerThread(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:1455
BOOLEAN NTAPI USBPORT_InterruptService(IN PKINTERRUPT Interrupt, IN PVOID ServiceContext)
Definition: usbport.c:1077
VOID NTAPI USBPORT_FreeCommonBuffer(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_COMMON_BUFFER_HEADER HeaderBuffer)
Definition: usbport.c:1770
NTSTATUS NTAPI USBPORT_CreateWorkerThread(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:1427
VOID NTAPI USBPORT_MiniportInterrupts(IN PDEVICE_OBJECT FdoDevice, IN BOOLEAN IsEnable)
Definition: usbport.c:555
VOID NTAPI USBPORT_WorkerRequestDpc(IN PRKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: usbport.c:701
BOOLEAN NTAPI USBPORT_StartTimer(IN PDEVICE_OBJECT FdoDevice, IN ULONG Time)
Definition: usbport.c:1675
#define USBPORT_FLAG_HC_WAKE_SUPPORT
Definition: usbport.h:76
#define USBPORT_MPFLAG_INTERRUPTS_ENABLED
Definition: usbport.h:102
#define USBPORT_FLAG_HC_POLLING
Definition: usbport.h:68
#define USBPORT_FLAG_LEGACY_SUPPORT
Definition: usbport.h:75
#define USBPORT_FLAG_BIOS_DISABLE_SS
Definition: usbport.h:81
#define USBPORT_FLAG_HC_STARTED
Definition: usbport.h:67
#define USBPORT_FLAG_COMPANION_HC
Definition: usbport.h:78
#define USB2_FRAMES
Definition: usbport.h:452
#define USBPORT_FLAG_SELECTIVE_SUSPEND
Definition: usbport.h:73
#define USBPORT_FLAG_INT_CONNECTED
Definition: usbport.h:66
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG _Out_ PULONG ResultLength
Definition: wdfdevice.h:3776
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesRead
Definition: wdfiotarget.h:870
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_ PCUNICODE_STRING DeviceDescription
Definition: wdfpdo.h:432
#define PCI_WHICHSPACE_CONFIG
Definition: iotypes.h:3644
#define DEVICE_DESCRIPTION_VERSION
Definition: iotypes.h:2063
@ DevicePropertyBusNumber
Definition: iotypes.h:1209
#define PCI_COMMON_HDR_LENGTH
Definition: iotypes.h:3594

Referenced by USBPORT_FdoPnP().

◆ USBPORT_StopDevice()

NTSTATUS NTAPI USBPORT_StopDevice ( IN PDEVICE_OBJECT  FdoDevice)

Definition at line 490 of file pnp.c.

491{
492 DPRINT1("USBPORT_StopDevice: UNIMPLEMENTED. FIXME\n");
493 return STATUS_SUCCESS;
494}

Referenced by USBPORT_StartDevice().

Variable Documentation

◆ USBPORT_FdoStartCompletion

IO_COMPLETION_ROUTINE USBPORT_FdoStartCompletion

Definition at line 16 of file pnp.c.

Referenced by USBPORT_FdoPnP(), and USBPORT_QueryCapabilities().