Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

686 lines
14 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. DBCLASS.H
  5. Abstract:
  6. This module contains the PRIVATE definitions for the
  7. code that implements the DeviceBay Filter Driver
  8. Environment:
  9. Kernel & user mode
  10. Revision History:
  11. --*/
  12. //
  13. // Instance specific Data for the controller
  14. //
  15. #define DBCLASS_EJECT_TIMEOUT 10000 //timeout in ms
  16. //use a 10 second timeout
  17. #define DBC_CONTEXT_SIG 0x4c434244 //'DBCL'
  18. #define DBC_WORKITEM_SIG 0x4b574244 //'DBWK'
  19. // HW branch registry Keys
  20. #define IS_DEVICE_BAY_KEY L"IsDeviceBay"
  21. #define DBC_GUID_KEY L"DBCGuid"
  22. #define INSTALLED_KEY L"installed"
  23. #define ACPI_HUB_KEY L"acpiHubParentPort"
  24. // SW branch registry keys
  25. #define RELEASE_ON_SHUTDOWN L"releaseshutdown"
  26. // class global registry keys
  27. // these are found in HKLM\CCS\Services\Class\dbc
  28. #define DEBUG_LEVEL_KEY L"debuglevel"
  29. #define DEBUG_WIN9X_KEY L"debugWin9x"
  30. #define DEBUG_BREAK_ON L"breakon"
  31. #ifdef DEBUG3
  32. #define MAX_DEBUG
  33. #endif /* DEBUG3 */
  34. #ifndef ANY_SIZE_ARRAY
  35. #define ANY_SIZE_ARRAY 1
  36. #endif
  37. typedef struct _DBC_BAY_INFORMATION {
  38. ULONG Sig;
  39. DBC_BAY_DESCRIPTOR BayDescriptor;
  40. BAY_STATUS LastBayStatus;
  41. PDEVICE_OBJECT DeviceFilterObject;
  42. PDEVICE_OBJECT UsbHubPdo;
  43. ULONG UsbHubPort;
  44. } DBC_BAY_INFORMATION, *PDBC_BAY_INFORMATION;
  45. #define MAX_DBC_1394_PORTS 16
  46. //
  47. // values for Flags in BUS1394_PORT_INFO
  48. //
  49. #define DBCLASS_PORTFLAG_DEVICE_CONNECTED 0x0000001
  50. typedef struct _BUS1394_PORT_INFO {
  51. USHORT NodeId; // 1394 nodeID for device on this port
  52. USHORT BayNumber; // Bay number tied to this port
  53. ULONG Flags;
  54. } BUS1394_PORT_INFO , *PBUS1394_PORT_INFO;
  55. typedef struct _DBC_CONTEXT {
  56. ULONG Sig;
  57. ULONG Flags;
  58. ULONG ControllerSig;
  59. // Top of the DB controller stack
  60. // this is who we call when talking to
  61. // the db controller.
  62. // This will be the controller FDO or
  63. // an OEM filter FDO
  64. PDEVICE_OBJECT TopOfStack;
  65. // the controllers FDO
  66. PDEVICE_OBJECT ControllerFdo;
  67. // Physical Device Object passed
  68. // to controllers AddDevice
  69. PDEVICE_OBJECT ControllerPdo;
  70. // Top of PDO stack ie top of stack
  71. // returned when controller attaches
  72. // to the PDO passed to AddDevice
  73. PDEVICE_OBJECT TopOfPdoStack;
  74. struct _DBC_CONTEXT *Next;
  75. PIRP ChangeIrp;
  76. ULONG PendingIoCount;
  77. DEVICE_POWER_STATE CurrentDevicePowerState;
  78. // device object that sits on the PDO for the bus
  79. // extender
  80. PDEVICE_OBJECT BusFilterMdo1394;
  81. PDEVICE_OBJECT BusFilterMdoUSB;
  82. PDRIVER_OBJECT BusFilterDriverObject;
  83. PDEVICE_OBJECT LinkDeviceObject;
  84. KSEMAPHORE DrbSemaphore;
  85. KEVENT RemoveEvent;
  86. KEVENT PowerEvent;
  87. NTSTATUS LastSetDXntStatus;
  88. DBC_SUBSYSTEM_DESCRIPTOR SubsystemDescriptor;
  89. DBC_BAY_INFORMATION BayInformation[MAX_BAY_NUMBER+1];
  90. ULONG NumberOf1394Ports;
  91. PBUS1394_PORT_INFO Bus1394PortInfo;
  92. PIRP PowerIrp;
  93. struct _DRB_CHANGE_REQUEST ChangeDrb;
  94. // guid for the 1394c bus this controller is on
  95. UCHAR Guid1394Bus[8];
  96. KSPIN_LOCK FlagsSpin;
  97. BOOLEAN Stopped;
  98. BOOLEAN EjectRequested;
  99. } DBC_CONTEXT, *PDBC_CONTEXT;
  100. typedef struct _EJECT_CONTEXT {
  101. PDBC_CONTEXT DbcContext;
  102. USHORT Bay;
  103. } EJECT_CONTEXT, *PEJECT_CONTEXT;
  104. typedef struct _DBCLASS_WORKITEM {
  105. ULONG Sig;
  106. WORK_QUEUE_ITEM WorkQueueItem;
  107. PDBC_CONTEXT DbcContext;
  108. NTSTATUS IrpStatus;
  109. struct _DBC_EJECT_TIMEOUT_CONTEXT *TimeoutContext;
  110. } DBCLASS_WORKITEM, *PDBCLASS_WORKITEM;
  111. typedef struct _DBCLASS_PDO_LIST {
  112. LIST_ENTRY ListEntry;
  113. PDEVICE_OBJECT PdoDeviceObject;
  114. PDEVICE_OBJECT FilterDeviceObject;
  115. } DBCLASS_PDO_LIST, *PDBCLASS_PDO_LIST;
  116. // DBC_CONTEXT Flags values
  117. #define DBCLASS_FLAG_STOPPING 0x00000001
  118. #define DBCLASS_FLAG_REQ_PENDING 0x00000002
  119. #define DBCLASS_FLAG_RELEASE_ON_SHUTDOWN 0x00000004
  120. #define INITIALIZE_DRB_SERIALIZATION(dc) KeInitializeSemaphore(&(dc)->DrbSemaphore, 1, 1);
  121. #define DBCLASS_BEGIN_SERIALIZED_DRB(dc) { DBCLASS_KdPrint((3, "'***WAIT DRB SEM%x\n", &(dc)->DrbSemaphore)); \
  122. KeWaitForSingleObject(&(dc)->DrbSemaphore, \
  123. Executive,\
  124. KernelMode, \
  125. FALSE, \
  126. NULL); \
  127. }
  128. #define DBCLASS_END_SERIALIZED_DRB(dc) { DBCLASS_KdPrint((3, "'***RELEASE DRB SEM %x\n", &(dc)->DrbSemaphore));\
  129. KeReleaseSemaphore(&(dc)->DrbSemaphore,\
  130. LOW_REALTIME_PRIORITY,\
  131. 1,\
  132. FALSE);\
  133. }
  134. #define NUMBER_OF_BAYS(dbc) ((dbc)->SubsystemDescriptor.bmAttributes.BayCount)
  135. #define DBC_TAG ' cbD'
  136. /*
  137. Debug Macros
  138. */
  139. #if DBG
  140. #ifndef DEBUG_LOG
  141. #define DEBUG_LOG
  142. #endif
  143. VOID
  144. DBCLASS_Assert(
  145. IN PVOID FailedAssertion,
  146. IN PVOID FileName,
  147. IN ULONG LineNumber,
  148. IN PCHAR Message
  149. );
  150. #define DBCLASS_ASSERT(exp) \
  151. if (!(exp)) { \
  152. DBCLASS_Assert( #exp, __FILE__, __LINE__, NULL );\
  153. }
  154. #define LOGENTRY(mask, sig, info1, info2, info3)
  155. // DBCLASS_Debug_LogEntry(mask, sig, (ULONG)info1, (ULONG)info2, (ULONG)info3)
  156. ULONG
  157. _cdecl
  158. DBCLASS_KdPrintX(
  159. ULONG l,
  160. PCH Format,
  161. ...
  162. );
  163. VOID
  164. DBCLASS_LogInit(
  165. );
  166. VOID
  167. DBCLASS_Debug_LogEntry(
  168. IN ULONG Mask,
  169. IN ULONG Sig,
  170. IN ULONG Info1,
  171. IN ULONG Info2,
  172. IN ULONG Info3
  173. );
  174. #define LOG_MISC 0x00000001 //debug log entries
  175. #define DBCLASS_KdPrint(_x_) DBCLASS_KdPrintX _x_
  176. #define TEST_TRAP() { DbgPrint( "DBCLASS: Code coverage trap %s line: %d\n", __FILE__, __LINE__);\
  177. TRAP();}
  178. extern ULONG DBCLASS_BreakOn;
  179. #define BRK_ON_TRAP() \
  180. {\
  181. if (DBCLASS_BreakOn) {\
  182. DbgPrint( "DBCLASS: DEBUG TEST BREAK %s line: %d\n", __FILE__, __LINE__ );\
  183. DbgBreakPoint();\
  184. }\
  185. }
  186. #define TRAP() DbgBreakPoint()
  187. #define DEBUG_HEAP
  188. extern ULONG DBCLASS_TotalHeapSace;
  189. #define DBCLASS_HEAP_SIG 0x12344321
  190. #define DBCLASS_FREE_TAG 0x11111111
  191. #define DbcExAllocatePool(p, l) DBCLASS_GetHeap((p), (l), DBCLASS_HEAP_SIG, \
  192. &DBCLASS_TotalHeapSace)
  193. #define DbcExFreePool(l) DBCLASS_RetHeap((l), DBCLASS_HEAP_SIG, \
  194. &DBCLASS_TotalHeapSace)
  195. VOID
  196. DBCLASS_Warning(
  197. PVOID Context,
  198. PUCHAR Message,
  199. BOOLEAN DebugBreak
  200. );
  201. #else
  202. // NOT DEBUG
  203. #define LOGENTRY(mask, sig, info1, info2, info3)
  204. #define DBCLASS_ASSERT(exp)
  205. #define DBCLASS_KdPrint(_x_)
  206. #define DBCLASS_KdPrintGuid(_x_, _y_)
  207. #define TRAP()
  208. #define TEST_TRAP()
  209. #define BRK_ON_TRAP()
  210. #define DbcExAllocatePool(p, l) ExAllocatePoolWithTag((p), (l), DBC_TAG)
  211. #define DbcExFreePool(l) ExFreePool((l))
  212. #define DBCLASS_Warning(x, y, z)
  213. #endif
  214. VOID
  215. DBCLASS_Unload(
  216. IN PDRIVER_OBJECT DriverObject
  217. );
  218. PDBC_CONTEXT
  219. DBCLASS_GetDbcContext(
  220. IN PDEVICE_OBJECT ControllerFdo
  221. );
  222. NTSTATUS
  223. DBCLASS_StopController(
  224. IN PDBC_CONTEXT DbcContext,
  225. IN PIRP Irp,
  226. IN PBOOLEAN HandledByClass
  227. );
  228. NTSTATUS
  229. DBCLASS_StartController(
  230. IN PDBC_CONTEXT DbcContext,
  231. IN PIRP Irp,
  232. IN PBOOLEAN HandledByClass
  233. );
  234. NTSTATUS
  235. DBCLASS_UsbhubBusFilterDispatch(
  236. PDEVICE_OBJECT DeviceObject,
  237. PIRP Irp,
  238. PBOOLEAN Handled
  239. );
  240. NTSTATUS
  241. DBCLASS_SyncSubmitDrb(
  242. IN PDBC_CONTEXT DbcContext,
  243. IN PDEVICE_OBJECT DeviceObject,
  244. IN PDRB Drb
  245. );
  246. NTSTATUS
  247. DBCLASS_CleanupController(
  248. IN PDBC_CONTEXT DbcContext
  249. );
  250. NTSTATUS
  251. DBCLASS_SyncGetSubsystemDescriptor(
  252. IN PDBC_CONTEXT DbcContext
  253. );
  254. NTSTATUS
  255. DBCLASS_CreateDeviceFilterObject(
  256. IN PDRIVER_OBJECT DriverObject,
  257. IN OUT PDEVICE_OBJECT *DeviceObject,
  258. IN PDEVICE_OBJECT DevicePdo,
  259. IN PDBC_CONTEXT DbcContext,
  260. IN ULONG BusTypeSig
  261. );
  262. NTSTATUS
  263. DBCLASS_SyncGetBayDescriptor(
  264. IN PDBC_CONTEXT DbcContext,
  265. IN USHORT BayNumber,
  266. IN PDBC_BAY_DESCRIPTOR BayDescriptor
  267. );
  268. NTSTATUS
  269. DBCLASS_SyncGetAllBayDescriptors(
  270. IN PDBC_CONTEXT DbcContext
  271. );
  272. VOID
  273. DBCLASS_ChangeIndicationWorker(
  274. IN PVOID Context
  275. );
  276. NTSTATUS
  277. DBCLASS_SyncGetBayStatus(
  278. IN PDBC_CONTEXT DbcContext,
  279. IN USHORT BayNumber,
  280. IN PBAY_STATUS BayStatus
  281. );
  282. NTSTATUS
  283. DBCLASS_SyncBayFeatureRequest(
  284. IN PDBC_CONTEXT DbcContext,
  285. IN USHORT Op,
  286. IN USHORT BayNumber,
  287. IN USHORT FeatureSelector
  288. );
  289. NTSTATUS
  290. DBCLASS_ChangeIndication(
  291. IN PDEVICE_OBJECT PNull,
  292. IN PIRP Irp,
  293. IN PVOID Context
  294. );
  295. VOID
  296. DBCLASS_PostChangeRequest(
  297. IN PDBC_CONTEXT DbcContext
  298. );
  299. NTSTATUS
  300. DBCLASS_ProcessCurrentBayState(
  301. IN PDBC_CONTEXT DbcContext,
  302. IN BAY_STATUS BayStatus,
  303. IN USHORT Bay,
  304. IN PBOOLEAN PostChgangeRequest
  305. );
  306. NTSTATUS
  307. DBCLASS_1394BusFilterDispatch(
  308. PDEVICE_OBJECT DeviceObject,
  309. PIRP Irp,
  310. PBOOLEAN Handled
  311. );
  312. NTSTATUS
  313. DBCLASS_PdoFilterDispatch(
  314. PDEVICE_OBJECT DeviceObject,
  315. PIRP Irp,
  316. PBOOLEAN Handled
  317. );
  318. NTSTATUS
  319. DBCLASS_EjectPdo(
  320. IN PDEVICE_OBJECT DeviceFilterObject
  321. );
  322. NTSTATUS
  323. DBCLASS_EnableDevice(
  324. IN PDEVICE_OBJECT DeviceFilterObject
  325. );
  326. USHORT
  327. DBCLASS_GetBayNumber(
  328. IN PDEVICE_OBJECT DeviceFilterObject
  329. );
  330. NTSTATUS
  331. DBCLASS_DeferIrpCompletion(
  332. IN PDEVICE_OBJECT DeviceObject,
  333. IN PIRP Irp,
  334. IN PVOID Context
  335. );
  336. USHORT
  337. DBCLASS_GetBayFor1394Pdo(
  338. PDEVICE_OBJECT BusFilterMdo,
  339. PDBC_CONTEXT DbcContext,
  340. PDEVICE_OBJECT Pdo1394
  341. );
  342. NTSTATUS
  343. DBCLASS_DevicePdoQCapsComplete(
  344. IN PDEVICE_OBJECT DeviceObject,
  345. IN PIRP Irp,
  346. IN PVOID Context
  347. );
  348. PDEVICE_OBJECT
  349. DBCLASS_FindDevicePdo(
  350. PDEVICE_OBJECT PdoDeviceObject
  351. );
  352. NTSTATUS
  353. DBCLASS_BusFilterDispatch(
  354. PDEVICE_OBJECT DeviceObject,
  355. PIRP Irp,
  356. PBOOLEAN Handled
  357. );
  358. NTSTATUS
  359. DBCLASS_GetRegistryKeyValueForPdo(
  360. IN PDEVICE_OBJECT PhysicalDeviceObject,
  361. IN BOOLEAN SoftwareBranch,
  362. IN PWCHAR KeyNameString,
  363. IN ULONG KeyNameStringLength,
  364. IN PVOID Data,
  365. IN ULONG DataLength
  366. );
  367. PDBC_CONTEXT
  368. DBCLASS_FindController1394DevicePdo(
  369. PDRIVER_OBJECT FilterDriverObject,
  370. PDEVICE_OBJECT FilterMdo,
  371. PDEVICE_OBJECT DevicePdo1394,
  372. PUCHAR BusGuid
  373. );
  374. NTSTATUS
  375. DBCLASS_Check1394DevicePDO(
  376. PDEVICE_OBJECT FilterDeviceObject,
  377. PDBC_CONTEXT DbcContext,
  378. PDEVICE_OBJECT DevicePDO
  379. );
  380. BOOLEAN
  381. DBCLASS_IsHubPartOfACPI_DBC(
  382. PDEVICE_OBJECT DeviceObject
  383. );
  384. USHORT
  385. DBCLASS_GetBayForUSBPdo(
  386. PDBC_CONTEXT DbcContext,
  387. PDEVICE_OBJECT PdoUSB
  388. );
  389. #if DBG
  390. VOID
  391. DBCLASS_AssertBaysEmpty(
  392. PDBC_CONTEXT DbcContext
  393. );
  394. #else
  395. #define DBCLASS_AssertBaysEmpty(d)
  396. #endif
  397. PVOID
  398. DBCLASS_GetHeap(
  399. IN POOL_TYPE PoolType,
  400. IN ULONG NumberOfBytes,
  401. IN ULONG Signature,
  402. IN PLONG TotalAllocatedHeapSpace
  403. );
  404. VOID
  405. DBCLASS_RetHeap(
  406. IN PVOID P,
  407. IN ULONG Signature,
  408. IN PLONG TotalAllocatedHeapSpace
  409. );
  410. #if DBG
  411. VOID
  412. DBCLASS_KdPrintGuid(
  413. ULONG Level,
  414. PUCHAR P
  415. );
  416. #endif
  417. NTSTATUS
  418. DBCLASS_1394GetBusGuid(
  419. PDEVICE_OBJECT DeviceObject,
  420. PUCHAR BusGuid
  421. );
  422. NTSTATUS
  423. DBCLASS_Find1394DbcLinks(
  424. PDEVICE_OBJECT DevicePdo1394
  425. );
  426. NTSTATUS
  427. DBCLASS_EjectBay(
  428. IN PDBC_CONTEXT DbcContext,
  429. IN USHORT Bay
  430. );
  431. NTSTATUS
  432. DBCLASS_SetEjectTimeout(
  433. PDEVICE_OBJECT DeviceFilterMDO
  434. );
  435. NTSTATUS
  436. DBCLASS_CancelEjectTimeout(
  437. PDEVICE_OBJECT DeviceFilterMDO
  438. );
  439. NTSTATUS
  440. DBCLASS_SetRegistryKeyValueForPdo(
  441. IN PDEVICE_OBJECT PhysicalDeviceObject,
  442. IN BOOLEAN SoftwareBranch,
  443. IN ULONG Type,
  444. IN PWCHAR KeyNameString,
  445. IN ULONG KeyNameStringLength,
  446. IN PVOID Data,
  447. IN ULONG DataLength
  448. );
  449. NTSTATUS
  450. DBCLASS_SetupUSB_DBC(
  451. PDBC_CONTEXT DbcContext
  452. );
  453. NTSTATUS
  454. DBCLASS_GetHubDBCGuid(
  455. PDEVICE_OBJECT DeviceObject,
  456. PUCHAR DbcGuid
  457. );
  458. PDBC_CONTEXT
  459. DBCLASS_FindControllerUSB(
  460. PDRIVER_OBJECT FilterDriverObject,
  461. PDEVICE_OBJECT FilterMdo,
  462. PDEVICE_OBJECT UsbHubPdo
  463. );
  464. BOOLEAN
  465. DBCLASS_IsHubPartOfUSB_DBC(
  466. PDEVICE_OBJECT DeviceObject
  467. );
  468. NTSTATUS
  469. DBCLASS_CheckPhyLink(
  470. PDEVICE_OBJECT DevicePdo1394
  471. );
  472. BOOLEAN
  473. DBCLASS_IsLinkDeviceObject(
  474. PDBC_CONTEXT DbcContext,
  475. PDEVICE_OBJECT Pdo1394
  476. );
  477. NTSTATUS
  478. DBCLASS_AddDevicePDOToList(
  479. IN PDEVICE_OBJECT FilterDeviceObject,
  480. IN PDEVICE_OBJECT PdoDeviceObject
  481. );
  482. VOID
  483. DBCLASS_RemoveDevicePDOFromList(
  484. IN PDEVICE_OBJECT PdoDeviceObject
  485. );
  486. VOID
  487. DBCLASS_Refresh1394(
  488. VOID
  489. );
  490. NTSTATUS
  491. DBCLASS_AddBusFilterMDOToList(
  492. PDEVICE_OBJECT BusFilterMdo
  493. );
  494. VOID
  495. DBCLASS_RemoveBusFilterMDOFromList(
  496. PDEVICE_OBJECT BusFilterMdo
  497. );
  498. NTSTATUS
  499. DBCLASS_ClassPower(
  500. IN PDEVICE_OBJECT ControllerFdo,
  501. IN PIRP Irp,
  502. IN PBOOLEAN HandledByClass
  503. );
  504. NTSTATUS
  505. DBCLASS_CheckForAcpiDeviceBayHubs(
  506. PDEVICE_OBJECT HubPdo,
  507. ULONG AcpiDBCHubParentPort
  508. );
  509. NTSTATUS
  510. DBCLASS_GetClassGlobalDebugRegistryParameters(
  511. );
  512. NTSTATUS
  513. DBCLASS_GetConfigValue(
  514. IN PWSTR ValueName,
  515. IN ULONG ValueType,
  516. IN PVOID ValueData,
  517. IN ULONG ValueLength,
  518. IN PVOID Context,
  519. IN PVOID EntryContext
  520. );
  521. NTSTATUS
  522. DBCLASS_GetClassGlobalRegistryParameters(
  523. );
  524. NTSTATUS
  525. DBCLASS_EjectBayComplete(
  526. IN PDEVICE_OBJECT DeviceObject,
  527. IN PIRP Irp,
  528. IN PVOID Context
  529. );
  530. VOID
  531. DBCLASS_RemoveControllerFromMdo(PDBC_CONTEXT DbcContext);
  532.