Leaked source code of windows server 2003
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.

2285 lines
55 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. pnpiop.h
  5. Abstract:
  6. This module contains the plug-and-play macros and constants.
  7. Author:
  8. Shie-Lin Tzong (shielint) 29-Jan-1995
  9. Andrew Thornton (andrewth) 5-Sept-1996
  10. Environment:
  11. Kernel mode
  12. Revision History:
  13. --*/
  14. //
  15. // Pool tags
  16. //
  17. #define IOP_DNOD_TAG 'donD'
  18. #define IOP_DNDT_TAG 'tdnD'
  19. #define IOP_DPWR_TAG 'rwPD'
  20. //
  21. // The DEVICE_NODE is really just some extra stuff that we'd like to keep around
  22. // for each physical device object.
  23. // It is seperated from DEVOBJ_EXTENSION because these fields only apply to
  24. // PDO.
  25. //
  26. typedef enum {
  27. DOCK_NOTDOCKDEVICE,
  28. DOCK_QUIESCENT,
  29. DOCK_ARRIVING,
  30. DOCK_DEPARTING,
  31. DOCK_EJECTIRP_COMPLETED
  32. } PROFILE_STATUS;
  33. typedef enum {
  34. PROFILE_IN_PNPEVENT,
  35. PROFILE_NOT_IN_PNPEVENT,
  36. PROFILE_PERHAPS_IN_PNPEVENT
  37. } PROFILE_NOTIFICATION_TIME;
  38. typedef struct _PENDING_SET_INTERFACE_STATE {
  39. LIST_ENTRY List;
  40. UNICODE_STRING LinkName;
  41. } PENDING_SET_INTERFACE_STATE, *PPENDING_SET_INTERFACE_STATE;
  42. typedef enum _UNLOCK_UNLINK_ACTION {
  43. UnlinkRemovedDeviceNodes,
  44. UnlinkAllDeviceNodesPendingClose,
  45. UnlinkOnlyChildDeviceNodesPendingClose
  46. } UNLOCK_UNLINK_ACTION, *PUNLOCK_UNLINK_ACTION;
  47. typedef enum _PNP_DEVNODE_STATE {
  48. DeviceNodeUnspecified = 0x300, // 768
  49. DeviceNodeUninitialized, // 769
  50. DeviceNodeInitialized, // 770
  51. DeviceNodeDriversAdded, // 771
  52. DeviceNodeResourcesAssigned, // 772 - Operational state for Added
  53. DeviceNodeStartPending, // 773 - Operational state for Added
  54. DeviceNodeStartCompletion, // 774 - Operational state for Added
  55. DeviceNodeStartPostWork, // 775 - Operational state for Added
  56. DeviceNodeStarted, // 776
  57. DeviceNodeQueryStopped, // 777
  58. DeviceNodeStopped, // 778
  59. DeviceNodeRestartCompletion, // 779 - Operational state for Stopped
  60. DeviceNodeEnumeratePending, // 780 - Operational state for Started
  61. DeviceNodeEnumerateCompletion, // 781 - Operational state for Started
  62. DeviceNodeAwaitingQueuedDeletion, // 782
  63. DeviceNodeAwaitingQueuedRemoval, // 783
  64. DeviceNodeQueryRemoved, // 784
  65. DeviceNodeRemovePendingCloses, // 785
  66. DeviceNodeRemoved, // 786
  67. DeviceNodeDeletePendingCloses, // 787
  68. DeviceNodeDeleted, // 788
  69. MaxDeviceNodeState // 788
  70. } PNP_DEVNODE_STATE, *PPNP_DEVNODE_STATE;
  71. #define STATE_HISTORY_SIZE 20
  72. typedef struct _DEVICE_NODE *PDEVICE_NODE;
  73. typedef struct _DEVICE_NODE {
  74. //
  75. // Pointer to another DEVICE_NODE with the same parent as this one.
  76. //
  77. PDEVICE_NODE Sibling;
  78. //
  79. // Pointer to the first child of this DEVICE_NODE.
  80. //
  81. PDEVICE_NODE Child;
  82. //
  83. // Pointer to this DEVICE_NODE's parent.
  84. //
  85. PDEVICE_NODE Parent;
  86. //
  87. // Pointer to the last child of the device node
  88. //
  89. PDEVICE_NODE LastChild;
  90. //
  91. // Depth of DEVICE_NODE in the tree, root is 0
  92. //
  93. ULONG Level;
  94. //
  95. // Power notification order list entry for this device node
  96. //
  97. PPO_DEVICE_NOTIFY Notify;
  98. //
  99. // State
  100. //
  101. PNP_DEVNODE_STATE State;
  102. //
  103. // Previous State
  104. //
  105. PNP_DEVNODE_STATE PreviousState;
  106. //
  107. // Previous State
  108. //
  109. PNP_DEVNODE_STATE StateHistory[STATE_HISTORY_SIZE];
  110. ULONG StateHistoryEntry;
  111. //
  112. // Completion status
  113. //
  114. NTSTATUS CompletionStatus;
  115. //
  116. // Completion status
  117. //
  118. PIRP PendingIrp;
  119. //
  120. // General flags.
  121. //
  122. ULONG Flags;
  123. //
  124. // Flags used by user-mode for volatile state which should go away on a
  125. // reboot or when the device is removed.
  126. //
  127. ULONG UserFlags;
  128. //
  129. // Problem. This is set if DNF_HAS_PROBLEM is set in Flags. Indicates
  130. // which problem exists and uses the same values as the config manager
  131. // CM_PROB_*
  132. //
  133. ULONG Problem;
  134. //
  135. // Pointer to the physical device object that this DEVICE_NODE is associated
  136. // with.
  137. //
  138. PDEVICE_OBJECT PhysicalDeviceObject;
  139. //
  140. // Pointer to the list of resources assigned to the PhysicalDeviceObject.
  141. // This is the Resource list which is passed to driver's start routine.
  142. //
  143. PCM_RESOURCE_LIST ResourceList;
  144. PCM_RESOURCE_LIST ResourceListTranslated;
  145. //
  146. // InstancePath is the path of the instance node in the registry,
  147. // i.e. <EnumBus>\<DeviceId>\<uniqueid>
  148. //
  149. UNICODE_STRING InstancePath;
  150. //
  151. // ServiceName is the name of the driver who controls the device. (Not the
  152. // driver who enumerates/creates the PDO.) This field is mainly for
  153. // convenience.
  154. //
  155. UNICODE_STRING ServiceName;
  156. //
  157. // DuplicatePDO - if the flags have DNF_DUPLICATE set then this fields indicates
  158. // the duplicate PDO which is enumerated by a bus driver. N.B. It is possible
  159. // that DNF_DUPLICATE is set but this field is NULL. In this case, it means that
  160. // we know the device is a duplicate of another device and we have not enumerated
  161. // the DuplicatePDO yet.
  162. //
  163. PDEVICE_OBJECT DuplicatePDO;
  164. //
  165. // ResourceRequirements
  166. //
  167. PIO_RESOURCE_REQUIREMENTS_LIST ResourceRequirements;
  168. //
  169. // Information queried from the LEGACY_BUS_INFORMATION irp.
  170. //
  171. INTERFACE_TYPE InterfaceType;
  172. ULONG BusNumber;
  173. //
  174. // Information queried from the BUS_INFORMATION irp.
  175. //
  176. INTERFACE_TYPE ChildInterfaceType;
  177. ULONG ChildBusNumber;
  178. USHORT ChildBusTypeIndex;
  179. //
  180. // Describes the current removal policy for the device node. This is
  181. // actually type DEVICE_REMOVAL_POLICY.
  182. //
  183. UCHAR RemovalPolicy;
  184. //
  185. // Similar to above, but doesn't reflect any registry overrides.
  186. //
  187. UCHAR HardwareRemovalPolicy;
  188. //
  189. // Linked list of entries that represent each driver that has registered
  190. // for notification on this devnode. Note: drivers (and user-mode) actually
  191. // register based on a FILE_OBJECT handle, which is translated into a PDO
  192. // by sending an IRP_MN_QUERY_DEVICE_RELATIONS for TargetDeviceRelation.
  193. //
  194. LIST_ENTRY TargetDeviceNotify;
  195. //
  196. // DeviceArbiterList - A list of arbiters registered for this physical device object
  197. // Note: The Arbiters must be dereferenced when the device node is going away.
  198. //
  199. LIST_ENTRY DeviceArbiterList;
  200. //
  201. // DeviceTranslatorList - A list of translator for this physical device object
  202. // NOTE: the Translator must be dereferenced when the devic node is going away.
  203. //
  204. LIST_ENTRY DeviceTranslatorList;
  205. //
  206. // NoTranslatorMask - the bit position corresponds to resource type
  207. // if bit is set, there is no translator for the resource type in this devnode
  208. //
  209. USHORT NoTranslatorMask;
  210. //
  211. // QueryTranslatorMask - The bit position corresponds to resource type.
  212. // if bit is set, the translator for the resource type is queried.
  213. //
  214. USHORT QueryTranslatorMask;
  215. //
  216. // NoArbiterMask - the bit position corresponds to resource type
  217. // if bit is set, there is no arbiter for the resource type in this devnode
  218. //
  219. USHORT NoArbiterMask;
  220. //
  221. // QueryArbiterMask - The bit position corresponds to resource type.
  222. // if bit is set, the arbiter for the resource type is queried.
  223. //
  224. USHORT QueryArbiterMask;
  225. //
  226. // The following fields are used to track legacy resource allocation
  227. // LegacyDeviceNode - The real legacy device node.
  228. // NextResourceDeviceNode - link all the made-up device nodes which own part of
  229. // the resources from LegacyDeviceNode.
  230. //
  231. union {
  232. PDEVICE_NODE LegacyDeviceNode;
  233. PDEVICE_RELATIONS PendingDeviceRelations;
  234. } OverUsed1;
  235. union {
  236. PDEVICE_NODE NextResourceDeviceNode;
  237. } OverUsed2;
  238. //
  239. // Remember the BootResources for the device
  240. //
  241. PCM_RESOURCE_LIST BootResources;
  242. //
  243. // When Capabilities have been queried for a device (twice, once before
  244. // start and once after start) the flags are stored here in the same format
  245. // as the query capabilities IRP - use IopDeviceNodeFlagsToCapabilities to
  246. // access.
  247. //
  248. ULONG CapabilityFlags;
  249. //
  250. // Maintain a list of current dock devices and their SerialNumbers
  251. //
  252. struct {
  253. PROFILE_STATUS DockStatus;
  254. LIST_ENTRY ListEntry;
  255. PWCHAR SerialNumber;
  256. } DockInfo;
  257. //
  258. // Maintain a count to determine if either ourselves or any of
  259. // our children are stopping us from being disableable
  260. // count = myself (DNUF_NOT_DISABLEABLE) + 1 for each immediate
  261. // child that has DisableableDepends > 0
  262. //
  263. ULONG DisableableDepends;
  264. //
  265. // List of pended IoSetDeviceInterfaceState calls.
  266. // IoSetDeviceInterfaceState adds an entry to this list whenever it is
  267. // called and we haven't been started yet. Once we do the start we'll
  268. // run down the list.
  269. //
  270. LIST_ENTRY PendedSetInterfaceState;
  271. //
  272. // List of device nodes with same interface type and different bus numbers.
  273. //
  274. LIST_ENTRY LegacyBusListEntry;
  275. #if DBG_SCOPE
  276. ULONG FailureStatus;
  277. PCM_RESOURCE_LIST PreviousResourceList;
  278. PIO_RESOURCE_REQUIREMENTS_LIST PreviousResourceRequirements;
  279. #endif
  280. } DEVICE_NODE;
  281. //
  282. // A device Object is a PDO iff it has a non NULL device node (aka set by
  283. // plug and play during a query device relations.
  284. //
  285. #define IS_PDO(d) \
  286. ((NULL != (d)->DeviceObjectExtension->DeviceNode) && \
  287. (!(((PDEVICE_NODE)(d)->DeviceObjectExtension->DeviceNode)->Flags & DNF_LEGACY_RESOURCE_DEVICENODE)))
  288. #define ASSERT_PDO(d) \
  289. do { \
  290. if ( NULL == (d)->DeviceObjectExtension->DeviceNode || \
  291. (((PDEVICE_NODE)(d)->DeviceObjectExtension->DeviceNode)->Flags & DNF_LEGACY_RESOURCE_DEVICENODE)) { \
  292. KeBugCheckEx(PNP_DETECTED_FATAL_ERROR, PNP_ERR_INVALID_PDO, (ULONG_PTR)d, 0, 0); \
  293. } \
  294. } \
  295. while (0)
  296. //
  297. // DNF_MAKEUP - this devnode's device is created and owned by PnP manager
  298. //
  299. #define DNF_MADEUP 0x00000001
  300. //
  301. // DNF_DUPLICATE - this devnode's device is a duplicate of another enumerate PDO
  302. //
  303. #define DNF_DUPLICATE 0x00000002
  304. //
  305. // DNF_HAL_NODE - a flag to indicate which device node is the root node created by
  306. // the hal
  307. //
  308. #define DNF_HAL_NODE 0x00000004
  309. //
  310. // DNF_REENUMERATE - needs to be reenumerated
  311. //
  312. #define DNF_REENUMERATE 0x00000008
  313. //
  314. // DNF_ENUMERATED - used to track enumeration in IopEnumerateDevice()
  315. //
  316. #define DNF_ENUMERATED 0x00000010
  317. //
  318. // Singal that we need to send driver query id irps
  319. //
  320. #define DNF_IDS_QUERIED 0x00000020
  321. //
  322. // DNF_HAS_BOOT_CONFIG - the device has resource assigned by BIOS. It is considered
  323. // pseudo-started and need to participate in rebalance.
  324. //
  325. #define DNF_HAS_BOOT_CONFIG 0x00000040
  326. //
  327. // DNF_BOOT_CONFIG_RESERVED - Indicates the BOOT resources of the device are reserved.
  328. //
  329. #define DNF_BOOT_CONFIG_RESERVED 0x00000080
  330. //
  331. // DNF_NO_RESOURCE_REQUIRED - this devnode's device does not require resource.
  332. //
  333. #define DNF_NO_RESOURCE_REQUIRED 0x00000100
  334. //
  335. // DNF_RESOURCE_REQUIREMENTS_NEED_FILTERED - to distinguished the
  336. // DeviceNode->ResourceRequirements is a filtered list or not.
  337. //
  338. #define DNF_RESOURCE_REQUIREMENTS_NEED_FILTERED 0x00000200
  339. //
  340. // DNF_RESOURCE_REQUIREMENTS_CHANGED - Indicates the device's resource
  341. // requirements list has been changed.
  342. //
  343. #define DNF_RESOURCE_REQUIREMENTS_CHANGED 0x00000400
  344. //
  345. // DNF_NON_STOPPED_REBALANC - indicates the device can be restarted with new
  346. // resources without being stopped.
  347. //
  348. #define DNF_NON_STOPPED_REBALANCE 0x00000800
  349. //
  350. // The device's controlling driver is a legacy driver
  351. //
  352. #define DNF_LEGACY_DRIVER 0x00001000
  353. //
  354. // This corresponds to the user-mode CM_PROB_WILL_BE_REMOVED problem value and
  355. // the DN_WILL_BE_REMOVED status flag.
  356. //
  357. #define DNF_HAS_PROBLEM 0x00002000
  358. //
  359. // DNF_HAS_PRIVATE_PROBLEM - indicates this device reported PNP_DEVICE_FAILED
  360. // to a IRP_MN_QUERY_PNP_DEVICE_STATE without also reporting
  361. // PNP_DEVICE_RESOURCE_REQUIREMENTS_CHANGED.
  362. //
  363. #define DNF_HAS_PRIVATE_PROBLEM 0x00004000
  364. //
  365. // DNF_HARDWARE_VERIFICATION is set on device nodes that have hardware
  366. // verification (probably via WHQL applet).
  367. //
  368. #define DNF_HARDWARE_VERIFICATION 0x00008000
  369. //
  370. // DNF_DEVICE_GONE is set when a pdo is no longer returned in a query bus
  371. // relations. It will then be processed as a surprise remove if started.
  372. // This flag is used to better detect when a device is resurrected, and when
  373. // processing surprise remove, to determine if the devnode should be removed
  374. // from the tree.
  375. //
  376. #define DNF_DEVICE_GONE 0x00010000
  377. //
  378. // DNF_LEGACY_RESOURCE_DEVICENODE is set for device nodes created for legacy
  379. // resource allocation.
  380. //
  381. #define DNF_LEGACY_RESOURCE_DEVICENODE 0x00020000
  382. //
  383. // DNF_NEEDS_REBALANCE is set for device nodes that trigger rebalance.
  384. //
  385. #define DNF_NEEDS_REBALANCE 0x00040000
  386. //
  387. // DNF_LOCKED_FOR_EJECT is set on device nodes that are being ejected or are
  388. // related to a device being ejected.
  389. //
  390. #define DNF_LOCKED_FOR_EJECT 0x00080000
  391. //
  392. // DNF_DRIVER_BLOCKED is set on device nodes that use one or more drivers that
  393. // have been blocked from loading.
  394. //
  395. #define DNF_DRIVER_BLOCKED 0x00100000
  396. //
  397. // DNF_CHILD_WITH_INVALID_ID is set on device nodes that has one or more children
  398. // that have invalid id(s).
  399. //
  400. #define DNF_CHILD_WITH_INVALID_ID 0x00200000
  401. //
  402. // This corresponds to the user-mode the DN_WILL_BE_REMOVED status flag.
  403. //
  404. #define DNUF_WILL_BE_REMOVED 0x00000001
  405. //
  406. // This corresponds to the user-mode DN_NO_SHOW_IN_DM status flag.
  407. //
  408. #define DNUF_DONT_SHOW_IN_UI 0x00000002
  409. //
  410. // This flag is set when user-mode lets us know that a reboot is required
  411. // for this device.
  412. //
  413. #define DNUF_NEED_RESTART 0x00000004
  414. //
  415. // This flag is set to let the user-mode know when a device can be disabled
  416. // it is still possible for this to be TRUE, yet disable to fail, as it's
  417. // a polled flag (see also PNP_DEVICE_NOT_DISABLEABLE)
  418. //
  419. #define DNUF_NOT_DISABLEABLE 0x00000008
  420. //
  421. // Flags used during shutdown when the IO Verifier is trying to remove all
  422. // PNP devices.
  423. //
  424. // DNUF_SHUTDOWN_QUERIED is set when we issue the QueryRemove to a devnode.
  425. //
  426. // DNUF_SHUTDOWN_SUBTREE_DONE is set once we've issued the QueryRemove to all
  427. // a Devnodes descendants.
  428. //
  429. #define DNUF_SHUTDOWN_QUERIED 0x00000010
  430. #define DNUF_SHUTDOWN_SUBTREE_DONE 0x00000020
  431. //
  432. // PNP Bugcheck Subcodes
  433. //
  434. #define PNP_ERR_DUPLICATE_PDO 1
  435. #define PNP_ERR_INVALID_PDO 2
  436. #define PNP_ERR_BOGUS_ID 3
  437. #define PNP_ERR_PDO_ENUMERATED_AFTER_DELETION 4
  438. #define PNP_ERR_ACTIVE_PDO_FREED 5
  439. #define PNP_ERR_DEVICE_MISSING_FROM_EJECT_LIST 6
  440. #define PNP_ERR_UNEXPECTED_ADD_RELATION_ERR 7
  441. #define MAX_INSTANCE_PATH_LENGTH 260
  442. typedef NTSTATUS (*PENUM_CALLBACK)(
  443. IN PDEVICE_NODE DeviceNode,
  444. IN PVOID Context
  445. );
  446. //
  447. // Define callback routine for PipApplyFunctionToSubKeys &
  448. // PipApplyFunctionToServiceInstances
  449. //
  450. typedef BOOLEAN (*PIOP_SUBKEY_CALLBACK_ROUTINE) (
  451. IN HANDLE,
  452. IN PUNICODE_STRING,
  453. IN OUT PVOID
  454. );
  455. //
  456. // Define context structures for Start and Add device services
  457. //
  458. #define NO_MORE_GROUP ((USHORT) -1)
  459. #define SETUP_RESERVED_GROUP 0
  460. #define BUS_DRIVER_GROUP 1
  461. typedef struct _ADD_CONTEXT {
  462. ULONG DriverStartType;
  463. } ADD_CONTEXT, *PADD_CONTEXT;
  464. typedef struct _START_CONTEXT {
  465. BOOLEAN LoadDriver;
  466. BOOLEAN NewDevice;
  467. ADD_CONTEXT AddContext;
  468. } START_CONTEXT, *PSTART_CONTEXT;
  469. //
  470. // Resource translation and allocation related structures
  471. //
  472. typedef enum _RESOURCE_HANDLER_TYPE {
  473. ResourceHandlerNull,
  474. ResourceTranslator,
  475. ResourceArbiter,
  476. ResourceLegacyDeviceDetection
  477. } RESOURCE_HANDLER_TYPE;
  478. #define PI_MAXIMUM_RESOURCE_TYPE_TRACKED 15
  479. //
  480. // Internal Arbiters tracking structures
  481. // Note the first three fields of PI_RESOURCE_ARBITER_ENTRY and PI_RESOURCE_TRANSLATOR_ENTRY
  482. // must be the same.
  483. //
  484. typedef struct _PI_RESOURCE_ARBITER_ENTRY {
  485. LIST_ENTRY DeviceArbiterList; // Link all the arbiters of a PDO.
  486. UCHAR ResourceType;
  487. PARBITER_INTERFACE ArbiterInterface;
  488. ULONG Level; // Level of the owning device.
  489. LIST_ENTRY ResourceList;
  490. LIST_ENTRY BestResourceList;
  491. LIST_ENTRY BestConfig; // Link all the arbiters which produces the best logconf
  492. LIST_ENTRY ActiveArbiterList; // Link all the arbiters under testing
  493. UCHAR State;
  494. BOOLEAN ResourcesChanged;
  495. } PI_RESOURCE_ARBITER_ENTRY, *PPI_RESOURCE_ARBITER_ENTRY;
  496. //
  497. // Define PI_RESOURCE_ARBITER_ENTRY state
  498. //
  499. #define PI_ARBITER_HAS_SOMETHING 1
  500. #define PI_ARBITER_TEST_FAILED 2
  501. //
  502. // Internal Translator tracking structures
  503. //
  504. typedef struct _PI_RESOURCE_TRANSLATOR_ENTRY {
  505. LIST_ENTRY DeviceTranslatorList;
  506. UCHAR ResourceType;
  507. PTRANSLATOR_INTERFACE TranslatorInterface;
  508. PDEVICE_NODE DeviceNode;
  509. } PI_RESOURCE_TRANSLATOR_ENTRY, *PPI_RESOURCE_TRANSLATOR_ENTRY;
  510. //
  511. // IOP_RESOURCE_REQUEST
  512. //
  513. #define QUERY_RESOURCE_LIST 0
  514. #define QUERY_RESOURCE_REQUIREMENTS 1
  515. #define REGISTRY_ALLOC_CONFIG 1
  516. #define REGISTRY_FORCED_CONFIG 2
  517. #define REGISTRY_BOOT_CONFIG 4
  518. #define REGISTRY_OVERRIDE_CONFIGVECTOR 1
  519. #define REGISTRY_BASIC_CONFIGVECTOR 2
  520. //
  521. // An array of IOP_RESOURCE_REQUEST structures is used to anchor all the
  522. // devices for which resource rerquirement is being attempted.
  523. //
  524. #define IOP_ASSIGN_RETRY 0x00000008 // Retry resource allocation later
  525. #define IOP_ASSIGN_EXCLUDE 0x00000010 // internal IopAssign flag
  526. #define IOP_ASSIGN_IGNORE 0x00000020 // ignore this request
  527. #define IOP_ASSIGN_NO_REBALANCE 0x00000080 // no rebal if assign fails
  528. #define IOP_ASSIGN_RESOURCES_RELEASED 0x00000100 // resources are released for rebalancing
  529. #define IOP_ASSIGN_KEEP_CURRENT_CONFIG 0x00000200 // Indicate non-stopped rebalance. We need to
  530. // preserved the current config.
  531. #define IOP_ASSIGN_CLEAR_RESOURCE_REQUIREMENTS_CHANGE_FLAG \
  532. 0x00000400
  533. typedef struct _IOP_RESOURCE_REQUEST {
  534. PDEVICE_OBJECT PhysicalDevice;
  535. ULONG Flags;
  536. ARBITER_REQUEST_SOURCE AllocationType;
  537. ULONG Priority; // 0 is highest priority
  538. ULONG Position; // used for sorting of entries with same priority
  539. PIO_RESOURCE_REQUIREMENTS_LIST ResourceRequirements;
  540. PVOID ReqList; // PREQ_LIST
  541. PCM_RESOURCE_LIST ResourceAssignment;
  542. PCM_RESOURCE_LIST TranslatedResourceAssignment;
  543. NTSTATUS Status;
  544. } IOP_RESOURCE_REQUEST, *PIOP_RESOURCE_REQUEST;
  545. //
  546. // Misc
  547. //
  548. //
  549. // Enumeration request type
  550. //
  551. typedef enum _DEVICE_REQUEST_TYPE {
  552. AddBootDevices,
  553. AssignResources,
  554. ClearDeviceProblem,
  555. ClearEjectProblem,
  556. HaltDevice,
  557. ReenumerateBootDevices,
  558. ReenumerateDeviceOnly,
  559. ReenumerateDeviceTree,
  560. ReenumerateRootDevices,
  561. RequeryDeviceState,
  562. ResetDevice,
  563. ResourceRequirementsChanged,
  564. RestartEnumeration,
  565. SetDeviceProblem,
  566. ShutdownPnpDevices,
  567. StartDevice,
  568. StartSystemDevices
  569. } DEVICE_REQUEST_TYPE;
  570. #define CmResourceTypeReserved 0xf0
  571. //
  572. // This macro returns the pointer to the beginning of the data
  573. // area of KEY_VALUE_FULL_INFORMATION structure.
  574. // In the macro, k is a pointer to KEY_VALUE_FULL_INFORMATION structure.
  575. //
  576. #define KEY_VALUE_DATA(k) ((PCHAR)(k) + (k)->DataOffset)
  577. //
  578. // Save failure status info.
  579. //
  580. #if DBG_SCOPE
  581. #define SAVE_FAILURE_INFO(DeviceNode, Status) (DeviceNode)->FailureStatus = (Status)
  582. #else
  583. #define SAVE_FAILURE_INFO(DeviceNode, Status)
  584. #endif
  585. BOOLEAN
  586. PipAreDriversLoaded(
  587. IN PDEVICE_NODE DeviceNode
  588. );
  589. BOOLEAN
  590. PipIsDevNodeDNStarted(
  591. IN PDEVICE_NODE DeviceNode
  592. );
  593. VOID
  594. PipClearDevNodeProblem(
  595. IN PDEVICE_NODE DeviceNode
  596. );
  597. VOID
  598. PipSetDevNodeProblem(
  599. IN PDEVICE_NODE DeviceNode,
  600. IN ULONG Problem
  601. );
  602. #define PipIsRequestPending(devnode) FALSE
  603. #define PipDoesDevNodeHaveResources(devnode) \
  604. ((devnode)->ResourceList != NULL || (devnode)->BootResources != NULL || \
  605. ((devnode)->Flags & DNF_HAS_BOOT_CONFIG) != 0)
  606. #define PipDoesDevNodeHaveProblem(devnode) \
  607. ((devnode)->Flags & (DNF_HAS_PROBLEM | DNF_HAS_PRIVATE_PROBLEM))
  608. #define PipIsDevNodeProblem(devnode, problem) \
  609. (((devnode)->Flags & DNF_HAS_PROBLEM) && (devnode)->Problem == (problem))
  610. #define PipIsDevNodeDeleted(d) \
  611. ((d)->State == DeviceNodeDeletePendingCloses ||(d)->State == DeviceNodeDeleted)
  612. VOID
  613. PipSetDevNodeState(
  614. IN PDEVICE_NODE DeviceNode,
  615. IN PNP_DEVNODE_STATE State,
  616. OUT PNP_DEVNODE_STATE *OldState OPTIONAL
  617. );
  618. VOID
  619. PipRestoreDevNodeState(
  620. IN PDEVICE_NODE DeviceNode
  621. );
  622. BOOLEAN
  623. PipIsProblemReadonly(
  624. IN ULONG Problem
  625. );
  626. //++
  627. //
  628. // VOID
  629. // IopRegistryDataToUnicodeString(
  630. // OUT PUNICODE_STRING u,
  631. // IN PWCHAR p,
  632. // IN ULONG l
  633. // )
  634. //
  635. //--
  636. #define IopRegistryDataToUnicodeString(u, p, l) \
  637. { \
  638. ULONG len; \
  639. \
  640. PiRegSzToString((p), (l), &len, NULL); \
  641. (u)->Length = (USHORT)len; \
  642. (u)->MaximumLength = (USHORT)(l); \
  643. (u)->Buffer = (p); \
  644. }
  645. //
  646. // Size of scratch buffer used in this module.
  647. //
  648. #define PNP_SCRATCH_BUFFER_SIZE 512
  649. #define PNP_LARGE_SCRATCH_BUFFER_SIZE (PNP_SCRATCH_BUFFER_SIZE * 8)
  650. //
  651. // Define Device Instance Flags (used by IoQueryDeviceConfiguration apis)
  652. //
  653. #define DEVINSTANCE_FLAG_HWPROFILE_DISABLED 0x1
  654. #define DEVINSTANCE_FLAG_PNP_ENUMERATED 0x2
  655. //
  656. // Define Enumeration Control Flags (used by PipApplyFunctionToSubKeys)
  657. //
  658. #define FUNCTIONSUBKEY_FLAG_IGNORE_NON_CRITICAL_ERRORS 0x1
  659. #define FUNCTIONSUBKEY_FLAG_DELETE_SUBKEYS 0x2
  660. //
  661. // The following definitions are used in IoOpenDeviceInstanceKey
  662. //
  663. #define PLUGPLAY_REGKEY_DEVICE 1
  664. #define PLUGPLAY_REGKEY_DRIVER 2
  665. #define PLUGPLAY_REGKEY_CURRENT_HWPROFILE 4
  666. //
  667. // Define device extension for devices reported with IoReportDetectedDevice.
  668. //
  669. typedef struct _IOPNP_DEVICE_EXTENSION {
  670. PWCHAR CompatibleIdList;
  671. ULONG CompatibleIdListSize;
  672. } IOPNP_DEVICE_EXTENSION, *PIOPNP_DEVICE_EXTENSION;
  673. //
  674. // Reserve Boot Resources
  675. //
  676. typedef struct _IOP_RESERVED_RESOURCES_RECORD IOP_RESERVED_RESOURCES_RECORD, *PIOP_RESERVED_RESOURCES_RECORD;
  677. struct _IOP_RESERVED_RESOURCES_RECORD {
  678. PIOP_RESERVED_RESOURCES_RECORD Next;
  679. PDEVICE_OBJECT DeviceObject;
  680. PCM_RESOURCE_LIST ReservedResources;
  681. };
  682. //
  683. // External References
  684. //
  685. //
  686. // Init data
  687. //
  688. extern PVOID IopPnpScratchBuffer1;
  689. extern PCM_RESOURCE_LIST IopInitHalResources;
  690. extern PDEVICE_NODE IopInitHalDeviceNode;
  691. extern PIOP_RESERVED_RESOURCES_RECORD IopInitReservedResourceList;
  692. extern LOGICAL PiCollectVetoedHandles;
  693. //
  694. // Regular data
  695. //
  696. //
  697. // IopRootDeviceNode - the head of the PnP manager's device node tree.
  698. //
  699. extern PDEVICE_NODE IopRootDeviceNode;
  700. //
  701. // IopPnPDriverObject - the madeup driver object for pnp manager
  702. //
  703. extern PDRIVER_OBJECT IopPnPDriverObject;
  704. //
  705. // IopPnPSpinLock - spinlock for Pnp code.
  706. //
  707. extern KSPIN_LOCK IopPnPSpinLock;
  708. //
  709. // IopPnpEnumerationRequestList - a link list of device enumeration requests to worker thread.
  710. //
  711. extern LIST_ENTRY IopPnpEnumerationRequestList;
  712. //
  713. // PiEngineLock - Synchronizes the start/enum and remove engines.
  714. // (Note that this is a resource as certain acquisition paths are reentrant,
  715. // specifically those that call IopNotifyPnpWhenChainDereferenced.)
  716. //
  717. extern ERESOURCE PiEngineLock;
  718. //
  719. // IopDeviceTreeLock - performs syncronization on the whole device node tree.
  720. // IopAcquireEnumerationLock acquires this lock shared then optionally
  721. // acquires an exclusive lock on a devnode.
  722. // IopAcquireDeviceTreeLock acquires this lock exclusive
  723. //
  724. extern ERESOURCE IopDeviceTreeLock;
  725. //
  726. // IopSurpriseRemoveListLock - synchronizes access to the surprise remove list.
  727. //
  728. extern ERESOURCE IopSurpriseRemoveListLock;
  729. //
  730. // PiEventQueueEmpty - Manual reset event which is set when the queue is empty
  731. //
  732. extern KEVENT PiEventQueueEmpty;
  733. //
  734. // PiEnumerationLock - to synchronize IoInvalidateDeviceRelations in boot phase.
  735. //
  736. extern KEVENT PiEnumerationLock;
  737. //
  738. // IopNumberDeviceNodes - Number of outstanding device nodes in the system
  739. //
  740. extern ULONG IopNumberDeviceNodes;
  741. //
  742. // PnPInitialized - A flag to indicate if PnP initialization is completed.
  743. //
  744. extern BOOLEAN PnPInitialized;
  745. //
  746. // PnPBootDriverInitialied
  747. //
  748. extern BOOLEAN PnPBootDriversInitialized;
  749. //
  750. // PnPBootDriverLoaded
  751. //
  752. extern BOOLEAN PnPBootDriversLoaded;
  753. //
  754. // IopBootConfigsReserved - Indicates whether we have reserved BOOT configs or not.
  755. //
  756. extern BOOLEAN IopBootConfigsReserved;
  757. //
  758. // PnpDefaultInterfaceTYpe - Use this if the interface type of resource list is unknown.
  759. //
  760. extern INTERFACE_TYPE PnpDefaultInterfaceType;
  761. //
  762. // IopPendingEjects - List of pending eject requests
  763. //
  764. extern LIST_ENTRY IopPendingEjects;
  765. //
  766. // IopPendingSurpriseRemovals - List of pending surprise removal requests
  767. //
  768. extern LIST_ENTRY IopPendingSurpriseRemovals;
  769. extern KSEMAPHORE PpRegistrySemaphore;
  770. extern BOOLEAN PpPnpShuttingDown;
  771. BOOLEAN
  772. PipIsDuplicatedDevices(
  773. IN PCM_RESOURCE_LIST Configuration1,
  774. IN PCM_RESOURCE_LIST Configuration2,
  775. IN PHAL_BUS_INFORMATION BusInfo1 OPTIONAL,
  776. IN PHAL_BUS_INFORMATION BusInfo2 OPTIONAL
  777. );
  778. NTSTATUS
  779. PipConcatenateUnicodeStrings(
  780. OUT PUNICODE_STRING Destination,
  781. IN PUNICODE_STRING String1,
  782. IN PUNICODE_STRING String2 OPTIONAL
  783. );
  784. NTSTATUS
  785. PipServiceInstanceToDeviceInstance(
  786. IN HANDLE ServiceKeyHandle OPTIONAL,
  787. IN PUNICODE_STRING ServiceKeyName OPTIONAL,
  788. IN ULONG ServiceInstanceOrdinal,
  789. OUT PUNICODE_STRING DeviceInstanceRegistryPath OPTIONAL,
  790. OUT PHANDLE DeviceInstanceHandle OPTIONAL,
  791. IN ACCESS_MASK DesiredAccess
  792. );
  793. NTSTATUS
  794. PipCreateMadeupNode(
  795. IN PUNICODE_STRING ServiceKeyName,
  796. OUT PHANDLE ReturnedHandle,
  797. OUT PUNICODE_STRING KeyName,
  798. OUT PULONG InstanceOrdinal,
  799. IN BOOLEAN ResourceOwned
  800. );
  801. NTSTATUS
  802. PipOpenServiceEnumKeys(
  803. IN PUNICODE_STRING ServiceKeyName,
  804. IN ACCESS_MASK DesiredAccess,
  805. OUT PHANDLE ServiceHandle OPTIONAL,
  806. OUT PHANDLE ServiceEnumHandle OPTIONAL,
  807. IN BOOLEAN CreateEnum
  808. );
  809. NTSTATUS
  810. IopOpenCurrentHwProfileDeviceInstanceKey(
  811. OUT PHANDLE Handle,
  812. IN PUNICODE_STRING ServiceKeyName,
  813. IN ULONG Instance,
  814. IN ACCESS_MASK DesiredAccess,
  815. IN BOOLEAN Create
  816. );
  817. NTSTATUS
  818. IopGetDeviceInstanceCsConfigFlags(
  819. IN PUNICODE_STRING DeviceInstance,
  820. OUT PULONG CsConfigFlags
  821. );
  822. NTSTATUS
  823. PipGetServiceInstanceCsConfigFlags(
  824. IN PUNICODE_STRING ServiceKeyName,
  825. IN ULONG Instance,
  826. OUT PULONG CsConfigFlags
  827. );
  828. NTSTATUS
  829. PipApplyFunctionToSubKeys(
  830. IN HANDLE BaseHandle OPTIONAL,
  831. IN PUNICODE_STRING KeyName,
  832. IN ACCESS_MASK DesiredAccess,
  833. IN ULONG Flags,
  834. IN PIOP_SUBKEY_CALLBACK_ROUTINE SubKeyCallbackRoutine,
  835. IN OUT PVOID Context
  836. );
  837. NTSTATUS
  838. PipRegMultiSzToUnicodeStrings(
  839. IN PKEY_VALUE_FULL_INFORMATION KeyValueInformation,
  840. IN PUNICODE_STRING *UnicodeStringList,
  841. OUT PULONG UnicodeStringCount
  842. );
  843. NTSTATUS
  844. PipApplyFunctionToServiceInstances(
  845. IN HANDLE ServiceKeyHandle OPTIONAL,
  846. IN PUNICODE_STRING ServiceKeyName OPTIONAL,
  847. IN ACCESS_MASK DesiredAccess,
  848. IN BOOLEAN IgnoreNonCriticalErrors,
  849. IN PIOP_SUBKEY_CALLBACK_ROUTINE DevInstCallbackRoutine,
  850. IN OUT PVOID Context,
  851. OUT PULONG ServiceInstanceOrdinal OPTIONAL
  852. );
  853. VOID
  854. PipFreeUnicodeStringList(
  855. IN PUNICODE_STRING UnicodeStringList,
  856. IN ULONG StringCount
  857. );
  858. NTSTATUS
  859. PipReadDeviceConfiguration(
  860. IN HANDLE Handle,
  861. IN ULONG Flags,
  862. OUT PCM_RESOURCE_LIST *CmResource,
  863. OUT PULONG Length
  864. );
  865. #define PiInitializeEngineLock() \
  866. ExInitializeResourceLite(&PiEngineLock)
  867. typedef enum {
  868. PPL_SIMPLE_READ,
  869. PPL_TREEOP_ALLOW_READS,
  870. PPL_TREEOP_BLOCK_READS,
  871. PPL_TREEOP_BLOCK_READS_FROM_ALLOW
  872. } PNP_LOCK_LEVEL;
  873. VOID
  874. PpDevNodeLockTree(
  875. IN PNP_LOCK_LEVEL LockLevel
  876. );
  877. VOID
  878. PpDevNodeUnlockTree(
  879. IN PNP_LOCK_LEVEL LockLevel
  880. );
  881. #if DBG
  882. VOID
  883. PpDevNodeAssertLockLevel(
  884. IN PNP_LOCK_LEVEL LockLevel,
  885. IN PCSTR File,
  886. IN ULONG Line
  887. );
  888. #define PPDEVNODE_ASSERT_LOCK_HELD(Level) \
  889. PpDevNodeAssertLockLevel(Level, __FILE__, __LINE__)
  890. #else
  891. #define PPDEVNODE_ASSERT_LOCK_HELD(Level)
  892. #endif
  893. VOID
  894. PpDevNodeInsertIntoTree(
  895. IN PDEVICE_NODE ParentNode,
  896. IN PDEVICE_NODE DeviceNode
  897. );
  898. VOID
  899. PpDevNodeRemoveFromTree(
  900. IN PDEVICE_NODE DeviceNode
  901. );
  902. NTSTATUS
  903. PipAllocateDeviceNode(
  904. IN PDEVICE_OBJECT PhysicalDeviceObject,
  905. OUT PDEVICE_NODE *DeviceNode
  906. );
  907. NTSTATUS
  908. PipForAllDeviceNodes(
  909. IN PENUM_CALLBACK Callback,
  910. IN PVOID Context
  911. );
  912. NTSTATUS
  913. PipForDeviceNodeSubtree(
  914. IN PDEVICE_NODE DeviceNode,
  915. IN PENUM_CALLBACK Callback,
  916. IN PVOID Context
  917. );
  918. ULONG
  919. IopDetermineResourceListSize(
  920. IN PCM_RESOURCE_LIST ResourceList
  921. );
  922. PDEVICE_OBJECT
  923. IopDeviceObjectFromDeviceInstance(
  924. IN PUNICODE_STRING DeviceInstance
  925. );
  926. NTSTATUS
  927. IopMapDeviceObjectToDeviceInstance(
  928. IN PDEVICE_OBJECT DeviceObject,
  929. IN PUNICODE_STRING DeviceInstance
  930. );
  931. NTSTATUS
  932. IopDeviceObjectToDeviceInstance(
  933. IN PDEVICE_OBJECT DeviceObject,
  934. IN PHANDLE DeviceInstanceHandle,
  935. IN ACCESS_MASK DesiredAccess
  936. );
  937. BOOLEAN
  938. IopIsDeviceInstanceEnabled(
  939. IN HANDLE DeviceInstanceHandle,
  940. IN PUNICODE_STRING DeviceInstance,
  941. IN BOOLEAN Disable
  942. );
  943. BOOLEAN
  944. IopProcessAssignResources(
  945. IN PDEVICE_NODE DeviceNode,
  946. IN BOOLEAN Reallocation,
  947. OUT PBOOLEAN RebalancePerformed
  948. );
  949. NTSTATUS
  950. IopStartDevice (
  951. IN PDEVICE_OBJECT TargetDevice
  952. );
  953. NTSTATUS
  954. IopEjectDevice(
  955. IN PDEVICE_OBJECT DeviceObject,
  956. PPENDING_RELATIONS_LIST_ENTRY PendingEntry
  957. );
  958. VOID
  959. IopCancelPendingEject(
  960. IN PPENDING_RELATIONS_LIST_ENTRY Entry
  961. );
  962. NTSTATUS
  963. IopRemoveDevice(
  964. IN PDEVICE_OBJECT TargetDevice,
  965. IN ULONG IrpMinorCode
  966. );
  967. NTSTATUS
  968. IopQueryDeviceRelations(
  969. IN DEVICE_RELATION_TYPE Relations,
  970. IN PDEVICE_OBJECT DeviceObject,
  971. IN BOOLEAN Synchronous,
  972. OUT PDEVICE_RELATIONS *DeviceRelations
  973. );
  974. NTSTATUS
  975. IopQueryDeviceState(
  976. IN PDEVICE_OBJECT DeviceObject,
  977. OUT PPNP_DEVICE_STATE DeviceState
  978. );
  979. NTSTATUS
  980. PipForAllChildDeviceNodes(
  981. IN PDEVICE_NODE Parent,
  982. IN PENUM_CALLBACK Callback,
  983. IN PVOID Context
  984. );
  985. NTSTATUS
  986. IopCleanupDeviceRegistryValues(
  987. IN PUNICODE_STRING InstancePath
  988. );
  989. NTSTATUS
  990. IopQueryDeviceResources(
  991. IN PDEVICE_OBJECT DeviceObject,
  992. IN ULONG ResourceType,
  993. OUT PVOID *Resource,
  994. OUT ULONG *Length
  995. );
  996. NTSTATUS
  997. IopGetDeviceResourcesFromRegistry (
  998. IN PDEVICE_OBJECT DeviceObject,
  999. IN ULONG ResourceType,
  1000. IN ULONG Preference,
  1001. OUT PVOID *Resource,
  1002. OUT PULONG Length
  1003. );
  1004. VOID
  1005. IopResourceRequirementsChanged(
  1006. IN PDEVICE_OBJECT PhysicalDeviceObject,
  1007. IN BOOLEAN StopRequired
  1008. );
  1009. NTSTATUS
  1010. IopReleaseDeviceResources(
  1011. IN PDEVICE_NODE DeviceNode,
  1012. IN BOOLEAN ReserveResources
  1013. );
  1014. NTSTATUS
  1015. IopPnPAddDevice(
  1016. IN PDRIVER_OBJECT DriverObject,
  1017. IN PDEVICE_OBJECT DeviceObject
  1018. );
  1019. NTSTATUS
  1020. IopPnPDispatch(
  1021. IN PDEVICE_OBJECT DeviceObject,
  1022. IN OUT PIRP Irp
  1023. );
  1024. NTSTATUS
  1025. IopPowerDispatch(
  1026. IN PDEVICE_OBJECT DeviceObject,
  1027. IN OUT PIRP Irp
  1028. );
  1029. VOID
  1030. IopNewDevice(
  1031. IN PDEVICE_OBJECT DeviceObject
  1032. );
  1033. NTSTATUS
  1034. IopFilterResourceRequirementsList (
  1035. IN PIO_RESOURCE_REQUIREMENTS_LIST IoList,
  1036. IN PCM_RESOURCE_LIST CmList,
  1037. IN OUT PIO_RESOURCE_REQUIREMENTS_LIST *FilteredList,
  1038. OUT PBOOLEAN ExactMatch
  1039. );
  1040. NTSTATUS
  1041. IopMergeFilteredResourceRequirementsList (
  1042. IN PIO_RESOURCE_REQUIREMENTS_LIST IoList1,
  1043. IN PIO_RESOURCE_REQUIREMENTS_LIST IoList2,
  1044. IN OUT PIO_RESOURCE_REQUIREMENTS_LIST *MergedList
  1045. );
  1046. NTSTATUS
  1047. IopMergeCmResourceLists (
  1048. IN PCM_RESOURCE_LIST List1,
  1049. IN PCM_RESOURCE_LIST List2,
  1050. IN OUT PCM_RESOURCE_LIST *MergedList
  1051. );
  1052. PIO_RESOURCE_REQUIREMENTS_LIST
  1053. IopCmResourcesToIoResources (
  1054. IN ULONG SlotNumber,
  1055. IN PCM_RESOURCE_LIST CmResourceList,
  1056. IN ULONG Priority
  1057. );
  1058. NTSTATUS
  1059. IopReportResourceListToPnp(
  1060. IN PDRIVER_OBJECT DriverObject OPTIONAL,
  1061. IN PDEVICE_OBJECT DeviceObject OPTIONAL,
  1062. IN PCM_RESOURCE_LIST ResourceList,
  1063. IN ULONG ListSize,
  1064. IN BOOLEAN Translated
  1065. );
  1066. NTSTATUS
  1067. IopAllocateResources(
  1068. IN PULONG DeviceCountP,
  1069. IN OUT PIOP_RESOURCE_REQUEST *AssignTablePP,
  1070. IN BOOLEAN Locked,
  1071. IN BOOLEAN DoBootConfigs,
  1072. OUT PBOOLEAN RebalancePerformed
  1073. );
  1074. VOID
  1075. IopInitializeResourceMap (
  1076. PLOADER_PARAMETER_BLOCK LoaderBlock
  1077. );
  1078. VOID
  1079. IopReallocateResources(
  1080. IN PDEVICE_NODE DeviceNode
  1081. );
  1082. NTSTATUS
  1083. IopWriteResourceList(
  1084. IN HANDLE ResourceMapKey,
  1085. IN PUNICODE_STRING ClassName,
  1086. IN PUNICODE_STRING DriverName,
  1087. IN PUNICODE_STRING DeviceName,
  1088. IN PCM_RESOURCE_LIST ResourceList,
  1089. IN ULONG ResourceListSize
  1090. );
  1091. VOID
  1092. IopRemoveResourceListFromPnp(
  1093. IN PLIST_ENTRY ResourceList
  1094. );
  1095. NTSTATUS
  1096. IopWriteAllocatedResourcesToRegistry (
  1097. IN PDEVICE_NODE DeviceNode,
  1098. IN PCM_RESOURCE_LIST ResourceList,
  1099. IN ULONG Length
  1100. );
  1101. USHORT
  1102. PpInitGetGroupOrderIndex(
  1103. IN HANDLE ServiceHandle
  1104. );
  1105. VOID
  1106. IopDeleteLegacyKey(
  1107. IN PDRIVER_OBJECT DriverObject
  1108. );
  1109. NTSTATUS
  1110. IopOpenDeviceParametersSubkey(
  1111. OUT HANDLE *ParamKeyHandle,
  1112. IN HANDLE ParentKeyHandle,
  1113. IN PUNICODE_STRING SubKeyString,
  1114. IN ACCESS_MASK DesiredAccess
  1115. );
  1116. NTSTATUS
  1117. IopOpenOrCreateDeviceRegistryKey(
  1118. IN PDEVICE_OBJECT PhysicalDeviceObject,
  1119. IN ULONG DevInstKeyType,
  1120. IN ACCESS_MASK DesiredAccess,
  1121. IN BOOLEAN Create,
  1122. OUT PHANDLE DevInstRegKey
  1123. );
  1124. NTSTATUS
  1125. PipRequestDeviceAction(
  1126. IN PDEVICE_OBJECT DeviceObject OPTIONAL,
  1127. IN DEVICE_REQUEST_TYPE RequestType,
  1128. IN BOOLEAN ReorderingBarrier,
  1129. IN ULONG_PTR Argument,
  1130. IN PKEVENT CompletionEvent OPTIONAL,
  1131. IN PNTSTATUS CompletionStatus OPTIONAL
  1132. );
  1133. VOID
  1134. PipRequestDeviceRemoval(
  1135. IN PDEVICE_NODE DeviceNode,
  1136. IN BOOLEAN TreeDeletion,
  1137. IN ULONG Problem
  1138. );
  1139. BOOLEAN
  1140. PipIsBeingRemovedSafely(
  1141. IN PDEVICE_NODE DeviceNode
  1142. );
  1143. NTSTATUS
  1144. IopRestartDeviceNode(
  1145. IN PDEVICE_NODE DeviceNode
  1146. );
  1147. VOID
  1148. PpResetProblemDevices(
  1149. IN PDEVICE_NODE DeviceNode,
  1150. IN ULONG Problem
  1151. );
  1152. NTSTATUS
  1153. IopDeleteKeyRecursive(
  1154. IN HANDLE SubKeyHandle,
  1155. IN PWCHAR SubKeyName
  1156. );
  1157. NTSTATUS
  1158. IopQueryLegacyBusInformation (
  1159. IN PDEVICE_OBJECT DeviceObject,
  1160. OUT LPGUID InterfaceGuid OPTIONAL,
  1161. OUT INTERFACE_TYPE *InterfaceType OPTIONAL,
  1162. OUT ULONG *BusNumber OPTIONAL
  1163. );
  1164. NTSTATUS
  1165. IopBuildRemovalRelationList(
  1166. IN PDEVICE_OBJECT DeviceObject,
  1167. IN PLUGPLAY_DEVICE_DELETE_TYPE OperationCode,
  1168. OUT PNP_VETO_TYPE *VetoType,
  1169. OUT PUNICODE_STRING VetoName,
  1170. OUT PRELATION_LIST *RelationsList
  1171. );
  1172. NTSTATUS
  1173. IopDeleteLockedDeviceNodes(
  1174. IN PDEVICE_OBJECT DeviceObject,
  1175. IN PRELATION_LIST RelationsList,
  1176. IN PLUGPLAY_DEVICE_DELETE_TYPE OperationCode,
  1177. IN BOOLEAN ProcessIndirectDescendants,
  1178. IN ULONG Problem,
  1179. OUT PNP_VETO_TYPE *VetoType OPTIONAL,
  1180. OUT PUNICODE_STRING VetoName OPTIONAL
  1181. );
  1182. VOID
  1183. IopUnlinkDeviceRemovalRelations(
  1184. IN PDEVICE_OBJECT RemovedDeviceObject,
  1185. IN OUT PRELATION_LIST RelationsList,
  1186. IN UNLOCK_UNLINK_ACTION UnlinkAction
  1187. );
  1188. NTSTATUS
  1189. IopInvalidateRelationsInList(
  1190. IN PRELATION_LIST RelationsList,
  1191. IN PLUGPLAY_DEVICE_DELETE_TYPE OperationCode,
  1192. IN BOOLEAN OnlyIndirectDescendants,
  1193. IN BOOLEAN RestartDevNode
  1194. );
  1195. BOOLEAN
  1196. IopQueuePendingEject(
  1197. PPENDING_RELATIONS_LIST_ENTRY Entry
  1198. );
  1199. VOID
  1200. IopProcessCompletedEject(
  1201. IN PVOID Context
  1202. );
  1203. VOID
  1204. IopQueuePendingSurpriseRemoval(
  1205. IN PDEVICE_OBJECT DeviceObject,
  1206. IN PRELATION_LIST List,
  1207. IN ULONG Problem
  1208. );
  1209. NTSTATUS
  1210. IopUnloadAttachedDriver(
  1211. IN PDRIVER_OBJECT DriverObject
  1212. );
  1213. BOOLEAN
  1214. IopIsAnyDeviceInstanceEnabled(
  1215. IN PUNICODE_STRING ServiceKeyName,
  1216. IN HANDLE ServiceHandle,
  1217. IN BOOLEAN LegacyIncluded
  1218. );
  1219. NTSTATUS
  1220. IopQueryResourceHandlerInterface(
  1221. IN RESOURCE_HANDLER_TYPE HandlerType,
  1222. IN PDEVICE_OBJECT DeviceObject,
  1223. IN UCHAR ResourceType,
  1224. IN OUT PVOID *Interface
  1225. );
  1226. NTSTATUS
  1227. IopQueryReconfiguration(
  1228. IN UCHAR Request,
  1229. IN PDEVICE_OBJECT DeviceObject
  1230. );
  1231. NTSTATUS
  1232. IopLegacyResourceAllocation (
  1233. IN ARBITER_REQUEST_SOURCE AllocationType,
  1234. IN PDRIVER_OBJECT DriverObject,
  1235. IN PDEVICE_OBJECT DeviceObject,
  1236. IN PIO_RESOURCE_REQUIREMENTS_LIST ResourceRequirements,
  1237. IN OUT PCM_RESOURCE_LIST *AllocatedResources OPTIONAL
  1238. );
  1239. NTSTATUS
  1240. IoReportResourceUsageInternal(
  1241. IN ARBITER_REQUEST_SOURCE AllocationType,
  1242. IN PUNICODE_STRING DriverClassName OPTIONAL,
  1243. IN PDRIVER_OBJECT DriverObject,
  1244. IN PCM_RESOURCE_LIST DriverList OPTIONAL,
  1245. IN ULONG DriverListSize OPTIONAL,
  1246. IN PDEVICE_OBJECT DeviceObject OPTIONAL,
  1247. IN PCM_RESOURCE_LIST DeviceList OPTIONAL,
  1248. IN ULONG DeviceListSize OPTIONAL,
  1249. IN BOOLEAN OverrideConflict,
  1250. OUT PBOOLEAN ConflictDetected
  1251. );
  1252. NTSTATUS
  1253. IopDuplicateDetection (
  1254. IN INTERFACE_TYPE LegacyBusType,
  1255. IN ULONG BusNumber,
  1256. IN ULONG SlotNumber,
  1257. OUT PDEVICE_NODE *DeviceNode
  1258. );
  1259. NTSTATUS
  1260. PipLoadBootFilterDriver(
  1261. IN PUNICODE_STRING DriverName,
  1262. IN ULONG GroupIndex,
  1263. OUT PDRIVER_OBJECT *LoadedFilter
  1264. );
  1265. NTSTATUS
  1266. IopQueryAndSaveDeviceNodeCapabilities (
  1267. IN PDEVICE_NODE DeviceNode
  1268. );
  1269. VOID
  1270. IopIncDisableableDepends(
  1271. IN OUT PDEVICE_NODE DeviceNode
  1272. );
  1273. VOID
  1274. IopDecDisableableDepends(
  1275. IN OUT PDEVICE_NODE DeviceNode
  1276. );
  1277. NTSTATUS
  1278. IopQueryDockRemovalInterface(
  1279. IN PDEVICE_OBJECT DeviceObject,
  1280. IN OUT PDOCK_INTERFACE *DockInterface
  1281. );
  1282. #ifndef FIELD_SIZE
  1283. #define FIELD_SIZE(type, field) (sizeof(((type *)0)->field))
  1284. #endif
  1285. #define IopDeviceNodeFlagsToCapabilities(DeviceNode) \
  1286. ((PDEVICE_CAPABILITIES) (((PUCHAR) (&(DeviceNode)->CapabilityFlags)) - \
  1287. FIELD_OFFSET(DEVICE_CAPABILITIES, Version) - \
  1288. FIELD_SIZE(DEVICE_CAPABILITIES, Version)))
  1289. //
  1290. // BOOT allocation related declarations.
  1291. //
  1292. typedef
  1293. NTSTATUS
  1294. (*PIO_ALLOCATE_BOOT_RESOURCES_ROUTINE) (
  1295. IN ARBITER_REQUEST_SOURCE ArbiterRequestSource,
  1296. IN PDEVICE_OBJECT DeviceObject,
  1297. IN PCM_RESOURCE_LIST BootResources
  1298. );
  1299. NTSTATUS
  1300. IopAllocateBootResources (
  1301. IN ARBITER_REQUEST_SOURCE ArbiterRequestSource,
  1302. IN PDEVICE_OBJECT DeviceObject,
  1303. IN PCM_RESOURCE_LIST BootResources
  1304. );
  1305. NTSTATUS
  1306. IopReportBootResources (
  1307. IN ARBITER_REQUEST_SOURCE ArbiterRequestSource,
  1308. IN PDEVICE_OBJECT DeviceObject,
  1309. IN PCM_RESOURCE_LIST BootResources
  1310. );
  1311. NTSTATUS
  1312. IopAllocateLegacyBootResources (
  1313. IN INTERFACE_TYPE InterfaceType,
  1314. IN ULONG BusNumber
  1315. );
  1316. extern PIO_ALLOCATE_BOOT_RESOURCES_ROUTINE IopAllocateBootResourcesRoutine;
  1317. //
  1318. // Legacy Bus information related declarations.
  1319. //
  1320. extern LIST_ENTRY IopLegacyBusInformationTable[];
  1321. VOID
  1322. IopInsertLegacyBusDeviceNode (
  1323. IN PDEVICE_NODE BusDeviceNode,
  1324. IN INTERFACE_TYPE InterfaceType,
  1325. IN ULONG BusNumber
  1326. );
  1327. #define IopRemoveLegacyBusDeviceNode(d) RemoveEntryList(&((PDEVICE_NODE)d)->LegacyBusListEntry)
  1328. //
  1329. // Conflict detection declarations
  1330. //
  1331. NTSTATUS
  1332. IopQueryConflictList(
  1333. PDEVICE_OBJECT PhysicalDeviceObject,
  1334. IN PCM_RESOURCE_LIST ResourceList,
  1335. IN ULONG ResourceListSize,
  1336. OUT PPLUGPLAY_CONTROL_CONFLICT_LIST ConflictList,
  1337. IN ULONG ConflictListSize,
  1338. IN ULONG Flags
  1339. );
  1340. NTSTATUS
  1341. EisaBuildEisaDeviceNode(
  1342. VOID
  1343. );
  1344. //
  1345. // General utility macros
  1346. //
  1347. //
  1348. // This macros calculates the size in bytes of a constant string
  1349. //
  1350. // ULONG
  1351. // IopConstStringSize(
  1352. // IN CONST PWSTR String
  1353. // );
  1354. //
  1355. #define IopConstStringSize(String) ( sizeof(String) - sizeof(UNICODE_NULL) )
  1356. //
  1357. // This macros calculates the number of characters of a constant string
  1358. //
  1359. // ULONG
  1360. // IopConstStringLength(
  1361. // IN CONST PWSTR String
  1362. // );
  1363. //
  1364. #define IopConstStringLength(String) ( ( sizeof(String) - sizeof(UNICODE_NULL) ) / sizeof(WCHAR) )
  1365. //
  1366. // Kernel mode notification
  1367. //
  1368. //
  1369. // This macros maps a guid to a hash value based on the number of hash
  1370. // buckets we are using. It does this by treating the guid as an array of
  1371. // 4 ULONGs, suming them and MOD by the number of hash buckets we are using.
  1372. //
  1373. // ULONG
  1374. // IopHashGuid(
  1375. // LPGUID Guid
  1376. // );
  1377. //
  1378. #define IopHashGuid(_Guid) \
  1379. ( ( ((PULONG)_Guid)[0] + ((PULONG)_Guid)[1] + ((PULONG)_Guid)[2] \
  1380. + ((PULONG)_Guid)[3]) % NOTIFY_DEVICE_CLASS_HASH_BUCKETS)
  1381. // This macros abstracts
  1382. //
  1383. // VOID
  1384. // IopAcquireNotifyLock(
  1385. // PKGUARDED_MUTEX Lock
  1386. // )
  1387. #define IopAcquireNotifyLock(Lock) KeAcquireGuardedMutex(Lock);
  1388. /*
  1389. VOID
  1390. IopReleaseNotifyLock(
  1391. PKGUARDED_MUTEX Lock
  1392. )
  1393. */
  1394. #define IopReleaseNotifyLock(Lock) KeReleaseGuardedMutex(Lock);
  1395. // BOOLEAN
  1396. // IopCompareGuid(
  1397. // IN LPGUID guid1,
  1398. // IN LPGUID guid2
  1399. // );
  1400. #define IopCompareGuid(g1, g2) ( (g1) == (g2) \
  1401. ? TRUE \
  1402. : RtlCompareMemory( (g1), (g2), sizeof(GUID) ) == sizeof(GUID) \
  1403. )
  1404. VOID
  1405. IopInitializePlugPlayNotification(
  1406. VOID
  1407. );
  1408. NTSTATUS
  1409. IopNotifySetupDeviceArrival(
  1410. PDEVICE_OBJECT PhysicalDeviceObject, // PDO of the device
  1411. HANDLE EnumEntryKey, // Handle into the enum branch of the registry for this device
  1412. BOOLEAN InstallDriver // Should setup attempt to install a driver
  1413. );
  1414. NTSTATUS
  1415. IopRequestHwProfileChangeNotification(
  1416. IN LPGUID EventGuid,
  1417. IN PROFILE_NOTIFICATION_TIME NotificationTime,
  1418. OUT PPNP_VETO_TYPE VetoType OPTIONAL,
  1419. OUT PUNICODE_STRING VetoName OPTIONAL
  1420. );
  1421. NTSTATUS
  1422. IopNotifyTargetDeviceChange(
  1423. IN LPCGUID EventGuid,
  1424. IN PDEVICE_OBJECT DeviceObject,
  1425. IN PTARGET_DEVICE_CUSTOM_NOTIFICATION NotificationStructure OPTIONAL,
  1426. OUT PDRIVER_OBJECT *VetoingDriver
  1427. );
  1428. NTSTATUS
  1429. IopGetRelatedTargetDevice(
  1430. IN PFILE_OBJECT FileObject,
  1431. OUT PDEVICE_NODE *DeviceNode
  1432. );
  1433. NTSTATUS
  1434. IopNotifyDeviceClassChange(
  1435. LPGUID EventGuid,
  1436. LPGUID ClassGuid,
  1437. PUNICODE_STRING SymbolicLinkName
  1438. );
  1439. NTSTATUS
  1440. IopRegisterDeviceInterface(
  1441. IN PUNICODE_STRING DeviceInstanceName,
  1442. IN CONST GUID *InterfaceClassGuid,
  1443. IN PUNICODE_STRING ReferenceString OPTIONAL,
  1444. IN BOOLEAN UserModeFormat,
  1445. OUT PUNICODE_STRING SymbolicLinkName
  1446. );
  1447. NTSTATUS
  1448. IopUnregisterDeviceInterface(
  1449. IN PUNICODE_STRING SymbolicLinkName
  1450. );
  1451. NTSTATUS
  1452. IopRemoveDeviceInterfaces(
  1453. IN PUNICODE_STRING DeviceInstancePath
  1454. );
  1455. NTSTATUS
  1456. IopDisableDeviceInterfaces(
  1457. IN PUNICODE_STRING DeviceInstancePath
  1458. );
  1459. NTSTATUS
  1460. IopGetDeviceInterfaces(
  1461. IN CONST GUID *InterfaceClassGuid,
  1462. IN PUNICODE_STRING DevicePath OPTIONAL,
  1463. IN ULONG Flags,
  1464. IN BOOLEAN UserModeFormat,
  1465. OUT PWSTR *SymbolicLinkList,
  1466. OUT PULONG SymbolicLinkListSize OPTIONAL
  1467. );
  1468. NTSTATUS
  1469. IopDoDeferredSetInterfaceState(
  1470. IN PDEVICE_NODE DeviceNode
  1471. );
  1472. NTSTATUS
  1473. IopProcessSetInterfaceState(
  1474. IN PUNICODE_STRING SymbolicLinkName,
  1475. IN BOOLEAN Enable,
  1476. IN BOOLEAN DeferNotStarted
  1477. );
  1478. NTSTATUS
  1479. IopReplaceSeperatorWithPound(
  1480. OUT PUNICODE_STRING OutString,
  1481. IN PUNICODE_STRING InString
  1482. );
  1483. NTSTATUS
  1484. IopNotifyHwProfileChange(
  1485. IN LPGUID EventGuid,
  1486. OUT PPNP_VETO_TYPE VetoType OPTIONAL,
  1487. OUT PUNICODE_STRING VetoName OPTIONAL
  1488. );
  1489. VOID
  1490. IopUncacheInterfaceInformation(
  1491. IN PDEVICE_OBJECT DeviceObject
  1492. );
  1493. //
  1494. // Notify entry header - all notify entries have these
  1495. //
  1496. typedef struct _NOTIFY_ENTRY_HEADER {
  1497. //
  1498. // List Entry structure
  1499. //
  1500. LIST_ENTRY ListEntry;
  1501. //
  1502. // Notification event category for this notification entry.
  1503. //
  1504. IO_NOTIFICATION_EVENT_CATEGORY EventCategory;
  1505. //
  1506. // SessionId.
  1507. //
  1508. ULONG SessionId;
  1509. //
  1510. // Session space object to attach to for sending notification.
  1511. //
  1512. PVOID OpaqueSession;
  1513. //
  1514. // Callback routine passed in at registration
  1515. //
  1516. PDRIVER_NOTIFICATION_CALLBACK_ROUTINE CallbackRoutine;
  1517. //
  1518. // Context passed in at registration
  1519. //
  1520. PVOID Context;
  1521. //
  1522. // Driver object of the driver that registered for notifications. Required
  1523. // so we can dereference it when it unregisters
  1524. //
  1525. PDRIVER_OBJECT DriverObject;
  1526. //
  1527. // RefCount is the number of outstanding pointers to the node and avoids
  1528. // deletion while another notification is taking place
  1529. //
  1530. USHORT RefCount;
  1531. //
  1532. // Unregistered is set if this notification has been unregistered but cannot
  1533. // be removed from the list because other entities are using it
  1534. //
  1535. BOOLEAN Unregistered;
  1536. //
  1537. // Lock is a pointer to the fast mutex which is used to synchronise access
  1538. // to the list this node is a member of and is required so that the correct
  1539. // list can be locked during IoUnregisterPlugPlayNotification. If no locking
  1540. // is required it is NULL
  1541. //
  1542. PKGUARDED_MUTEX Lock;
  1543. } NOTIFY_ENTRY_HEADER, *PNOTIFY_ENTRY_HEADER;
  1544. //
  1545. // Data to store for each target device registration
  1546. //
  1547. typedef struct _TARGET_DEVICE_NOTIFY_ENTRY {
  1548. //
  1549. // Header entries
  1550. //
  1551. LIST_ENTRY ListEntry;
  1552. IO_NOTIFICATION_EVENT_CATEGORY EventCategory;
  1553. ULONG SessionId;
  1554. PVOID OpaqueSession;
  1555. PDRIVER_NOTIFICATION_CALLBACK_ROUTINE CallbackRoutine;
  1556. PVOID Context;
  1557. PDRIVER_OBJECT DriverObject;
  1558. USHORT RefCount;
  1559. BOOLEAN Unregistered;
  1560. PKGUARDED_MUTEX Lock;
  1561. //
  1562. // FileObject - the file object of the target device we are interested in
  1563. //
  1564. PFILE_OBJECT FileObject;
  1565. //
  1566. // PhysicalDeviceObject -- the PDO upon which this notification is hooked.
  1567. // We need to keep this here, so we can dereference it when the refcount
  1568. // on this notification entry drops to zero.
  1569. //
  1570. PDEVICE_OBJECT PhysicalDeviceObject;
  1571. } TARGET_DEVICE_NOTIFY_ENTRY, *PTARGET_DEVICE_NOTIFY_ENTRY;
  1572. //
  1573. // Data to store for each device class registration
  1574. //
  1575. typedef struct _DEVICE_CLASS_NOTIFY_ENTRY {
  1576. //
  1577. // Header entries
  1578. //
  1579. LIST_ENTRY ListEntry;
  1580. IO_NOTIFICATION_EVENT_CATEGORY EventCategory;
  1581. ULONG SessionId;
  1582. PVOID OpaqueSession;
  1583. PDRIVER_NOTIFICATION_CALLBACK_ROUTINE CallbackRoutine;
  1584. PVOID Context;
  1585. PDRIVER_OBJECT DriverObject;
  1586. USHORT RefCount;
  1587. BOOLEAN Unregistered;
  1588. PKGUARDED_MUTEX Lock;
  1589. //
  1590. // ClassGuid - the guid of the device class we are interested in
  1591. //
  1592. GUID ClassGuid;
  1593. } DEVICE_CLASS_NOTIFY_ENTRY, *PDEVICE_CLASS_NOTIFY_ENTRY;
  1594. //
  1595. // Data to store for registration of the Reserved (ie setupdd.sys) variety
  1596. //
  1597. typedef struct _SETUP_NOTIFY_DATA {
  1598. //
  1599. // Header entries
  1600. //
  1601. LIST_ENTRY ListEntry;
  1602. IO_NOTIFICATION_EVENT_CATEGORY EventCategory;
  1603. ULONG SessionId;
  1604. PVOID OpaqueSession;
  1605. PDRIVER_NOTIFICATION_CALLBACK_ROUTINE CallbackRoutine;
  1606. PVOID Context;
  1607. PDRIVER_OBJECT DriverObject;
  1608. USHORT RefCount;
  1609. BOOLEAN Unregistered;
  1610. PKGUARDED_MUTEX Lock;
  1611. } SETUP_NOTIFY_DATA, *PSETUP_NOTIFY_DATA;
  1612. //
  1613. // Data to store for registration for HardwareProfileChange Events
  1614. //
  1615. typedef struct _HWPROFILE_NOTIFY_ENTRY {
  1616. //
  1617. // Header entries
  1618. //
  1619. LIST_ENTRY ListEntry;
  1620. IO_NOTIFICATION_EVENT_CATEGORY EventCategory;
  1621. ULONG SessionId;
  1622. PVOID OpaqueSession;
  1623. PDRIVER_NOTIFICATION_CALLBACK_ROUTINE CallbackRoutine;
  1624. PVOID Context;
  1625. PDRIVER_OBJECT DriverObject;
  1626. USHORT RefCount;
  1627. BOOLEAN Unregistered;
  1628. PKGUARDED_MUTEX Lock;
  1629. } HWPROFILE_NOTIFY_ENTRY, *PHWPROFILE_NOTIFY_ENTRY;
  1630. #define PNP_NOTIFICATION_VERSION 1
  1631. #define NOTIFY_DEVICE_CLASS_HASH_BUCKETS 13
  1632. //
  1633. // IopMaxDeviceNodeLevel - Level number of the DeviceNode deepest in the tree
  1634. //
  1635. extern ULONG IopMaxDeviceNodeLevel;
  1636. extern ULONG IoDeviceNodeTreeSequence;
  1637. //
  1638. // Global notification data
  1639. //
  1640. extern KGUARDED_MUTEX IopDeviceClassNotifyLock;
  1641. extern LIST_ENTRY IopDeviceClassNotifyList[];
  1642. extern PSETUP_NOTIFY_DATA IopSetupNotifyData;
  1643. extern KGUARDED_MUTEX IopTargetDeviceNotifyLock;
  1644. extern LIST_ENTRY IopProfileNotifyList;
  1645. extern KGUARDED_MUTEX IopHwProfileNotifyLock;
  1646. VOID
  1647. IopProcessDeferredRegistrations(
  1648. VOID
  1649. );
  1650. //
  1651. // Generic buffer management
  1652. //
  1653. typedef struct _BUFFER_INFO {
  1654. //
  1655. // Buffer - pointer to the start of the buffer
  1656. //
  1657. PCHAR Buffer;
  1658. //
  1659. // Current - Pointer to the current position in the buffer
  1660. //
  1661. PCHAR Current;
  1662. //
  1663. // MaxSize - Maximum size of the buffer in bytes
  1664. //
  1665. ULONG MaxSize;
  1666. } BUFFER_INFO, *PBUFFER_INFO;
  1667. typedef struct _BUS_TYPE_GUID_LIST {
  1668. //
  1669. // Number of allocated guid slots in the table.
  1670. //
  1671. ULONG Count;
  1672. //
  1673. // Number of entries used so far.
  1674. //
  1675. KGUARDED_MUTEX Lock;
  1676. //
  1677. // Array of bus type guids
  1678. //
  1679. GUID Guid[1];
  1680. } BUS_TYPE_GUID_LIST, *PBUS_TYPE_GUID_LIST;
  1681. //
  1682. // List of queried bus type guids
  1683. //
  1684. extern PBUS_TYPE_GUID_LIST IopBusTypeGuidList;
  1685. //
  1686. // Arbiter entry points
  1687. //
  1688. NTSTATUS
  1689. IopPortInitialize(
  1690. VOID
  1691. );
  1692. NTSTATUS
  1693. IopMemInitialize(
  1694. VOID
  1695. );
  1696. NTSTATUS
  1697. IopIrqInitialize(
  1698. VOID
  1699. );
  1700. NTSTATUS
  1701. IopDmaInitialize(
  1702. VOID
  1703. );
  1704. NTSTATUS
  1705. IopBusNumberInitialize(
  1706. VOID
  1707. );
  1708. //
  1709. // Arbiter state
  1710. //
  1711. extern ARBITER_INSTANCE IopRootPortArbiter;
  1712. extern ARBITER_INSTANCE IopRootMemArbiter;
  1713. extern ARBITER_INSTANCE IopRootIrqArbiter;
  1714. extern ARBITER_INSTANCE IopRootDmaArbiter;
  1715. extern ARBITER_INSTANCE IopRootBusNumberArbiter;
  1716. //
  1717. // Buffer management routines.
  1718. //
  1719. NTSTATUS
  1720. IopAllocateBuffer(
  1721. IN PBUFFER_INFO Info,
  1722. IN ULONG Size
  1723. );
  1724. NTSTATUS
  1725. IopResizeBuffer(
  1726. IN PBUFFER_INFO Info,
  1727. IN ULONG NewSize,
  1728. IN BOOLEAN CopyContents
  1729. );
  1730. VOID
  1731. IopFreeBuffer(
  1732. IN PBUFFER_INFO Info
  1733. );
  1734. //
  1735. // UnicodeString management routines.
  1736. //
  1737. NTSTATUS
  1738. IopAllocateUnicodeString(
  1739. IN OUT PUNICODE_STRING String,
  1740. IN USHORT Length
  1741. );
  1742. //
  1743. // Misc.
  1744. //
  1745. BOOLEAN
  1746. PipFixupDeviceId(
  1747. PWCHAR DeviceId,
  1748. ULONG AllowedSeparators
  1749. );
  1750. VOID
  1751. IopOrphanNotification (
  1752. PDEVICE_NODE DeviceNode
  1753. );
  1754. PVOID
  1755. PiAllocateCriticalMemory(
  1756. IN PLUGPLAY_DEVICE_DELETE_TYPE DeleteType,
  1757. IN POOL_TYPE PoolType,
  1758. IN SIZE_T Size,
  1759. IN ULONG Tag
  1760. );
  1761. //
  1762. // Warm eject externs and function prototypes
  1763. //
  1764. extern KEVENT IopWarmEjectLock;
  1765. extern PDEVICE_OBJECT IopWarmEjectPdo;
  1766. NTSTATUS
  1767. IopWarmEjectDevice(
  1768. IN PDEVICE_OBJECT DeviceToEject,
  1769. IN SYSTEM_POWER_STATE LightestSleepState
  1770. );
  1771. NTSTATUS
  1772. IopSystemControlDispatch(
  1773. IN PDEVICE_OBJECT DeviceObject,
  1774. IN OUT PIRP Irp
  1775. );
  1776. VOID
  1777. PiLockDeviceActionQueue(
  1778. VOID
  1779. );
  1780. VOID
  1781. PiUnlockDeviceActionQueue(
  1782. VOID
  1783. );
  1784. //
  1785. // This macro takes a value and an alignment and rounds the entry up
  1786. // appropriately. The alignment MUST be a power of two!
  1787. //
  1788. #define ALIGN_UP_ULONG(value, alignment) (((value)+(alignment)-1)&(~(alignment-1)))
  1789. #if DBG
  1790. #define PP_DEVNODESTATE_NAME(s) ((s >= DeviceNodeUnspecified && s <= MaxDeviceNodeState)? PpStateToNameTable[(s) - DeviceNodeUnspecified] : PpStateToNameTable[0])
  1791. extern char *PpStateToNameTable[];
  1792. #else
  1793. #define PP_DEVNODESTATE_NAME(s)
  1794. #endif