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.

1298 lines
33 KiB

  1. /*++ BUILD Version: 0001 // Increment this if a change has global effects
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. pnp.h
  5. Abstract:
  6. This module contains the internal structure definitions and APIs used by
  7. the kernel-mode Plug and Play manager.
  8. This file is included by including "ntos.h".
  9. Author:
  10. Lonny McMichael (lonnym) 02/09/95
  11. Revision History:
  12. --*/
  13. #ifndef _PNP_
  14. #define _PNP_
  15. //
  16. // The following global variables provide/control access to PnP Manager data.
  17. //
  18. extern ERESOURCE PpRegistryDeviceResource;
  19. extern PDRIVER_OBJECT IoPnpDriverObject;
  20. // begin_ntddk begin_nthal begin_ntifs begin_wdm begin_ntosp
  21. //
  22. // Define PnP Device Property for IoGetDeviceProperty
  23. //
  24. typedef enum {
  25. DevicePropertyDeviceDescription,
  26. DevicePropertyHardwareID,
  27. DevicePropertyCompatibleIDs,
  28. DevicePropertyBootConfiguration,
  29. DevicePropertyBootConfigurationTranslated,
  30. DevicePropertyClassName,
  31. DevicePropertyClassGuid,
  32. DevicePropertyDriverKeyName,
  33. DevicePropertyManufacturer,
  34. DevicePropertyFriendlyName,
  35. DevicePropertyLocationInformation,
  36. DevicePropertyPhysicalDeviceObjectName,
  37. DevicePropertyBusTypeGuid,
  38. DevicePropertyLegacyBusType,
  39. DevicePropertyBusNumber,
  40. DevicePropertyEnumeratorName,
  41. DevicePropertyAddress,
  42. DevicePropertyUINumber,
  43. DevicePropertyInstallState,
  44. DevicePropertyRemovalPolicy
  45. } DEVICE_REGISTRY_PROPERTY;
  46. typedef BOOLEAN (*PTRANSLATE_BUS_ADDRESS)(
  47. IN PVOID Context,
  48. IN PHYSICAL_ADDRESS BusAddress,
  49. IN ULONG Length,
  50. IN OUT PULONG AddressSpace,
  51. OUT PPHYSICAL_ADDRESS TranslatedAddress
  52. );
  53. typedef struct _DMA_ADAPTER *(*PGET_DMA_ADAPTER)(
  54. IN PVOID Context,
  55. IN struct _DEVICE_DESCRIPTION *DeviceDescriptor,
  56. OUT PULONG NumberOfMapRegisters
  57. );
  58. typedef ULONG (*PGET_SET_DEVICE_DATA)(
  59. IN PVOID Context,
  60. IN ULONG DataType,
  61. IN PVOID Buffer,
  62. IN ULONG Offset,
  63. IN ULONG Length
  64. );
  65. typedef enum _DEVICE_INSTALL_STATE {
  66. InstallStateInstalled,
  67. InstallStateNeedsReinstall,
  68. InstallStateFailedInstall,
  69. InstallStateFinishInstall
  70. } DEVICE_INSTALL_STATE, *PDEVICE_INSTALL_STATE;
  71. //
  72. // Define structure returned in response to IRP_MN_QUERY_BUS_INFORMATION by a
  73. // PDO indicating the type of bus the device exists on.
  74. //
  75. typedef struct _PNP_BUS_INFORMATION {
  76. GUID BusTypeGuid;
  77. INTERFACE_TYPE LegacyBusType;
  78. ULONG BusNumber;
  79. } PNP_BUS_INFORMATION, *PPNP_BUS_INFORMATION;
  80. //
  81. // Define structure returned in response to IRP_MN_QUERY_LEGACY_BUS_INFORMATION
  82. // by an FDO indicating the type of bus it is. This is normally the same bus
  83. // type as the device's children (i.e., as retrieved from the child PDO's via
  84. // IRP_MN_QUERY_BUS_INFORMATION) except for cases like CardBus, which can
  85. // support both 16-bit (PCMCIABus) and 32-bit (PCIBus) cards.
  86. //
  87. typedef struct _LEGACY_BUS_INFORMATION {
  88. GUID BusTypeGuid;
  89. INTERFACE_TYPE LegacyBusType;
  90. ULONG BusNumber;
  91. } LEGACY_BUS_INFORMATION, *PLEGACY_BUS_INFORMATION;
  92. //
  93. // Defines for IoGetDeviceProperty(DevicePropertyRemovalPolicy).
  94. //
  95. typedef enum _DEVICE_REMOVAL_POLICY {
  96. // end_ntddk end_wdm end_nthal end_ntifs end_ntosp
  97. RemovalPolicyNotDetermined = 0,
  98. // begin_ntddk begin_wdm begin_nthal begin_ntifs begin_ntosp
  99. RemovalPolicyExpectNoRemoval = 1,
  100. RemovalPolicyExpectOrderlyRemoval = 2,
  101. RemovalPolicyExpectSurpriseRemoval = 3
  102. // end_ntddk end_wdm end_nthal end_ntifs end_ntosp
  103. ,
  104. RemovalPolicySuggestOrderlyRemoval = 4,
  105. RemovalPolicySuggestSurpriseRemoval = 5,
  106. RemovalPolicyUnspecified = 6
  107. // begin_ntddk begin_wdm begin_nthal begin_ntifs begin_ntosp
  108. } DEVICE_REMOVAL_POLICY, *PDEVICE_REMOVAL_POLICY;
  109. typedef struct _BUS_INTERFACE_STANDARD {
  110. //
  111. // generic interface header
  112. //
  113. USHORT Size;
  114. USHORT Version;
  115. PVOID Context;
  116. PINTERFACE_REFERENCE InterfaceReference;
  117. PINTERFACE_DEREFERENCE InterfaceDereference;
  118. //
  119. // standard bus interfaces
  120. //
  121. PTRANSLATE_BUS_ADDRESS TranslateBusAddress;
  122. PGET_DMA_ADAPTER GetDmaAdapter;
  123. PGET_SET_DEVICE_DATA SetBusData;
  124. PGET_SET_DEVICE_DATA GetBusData;
  125. } BUS_INTERFACE_STANDARD, *PBUS_INTERFACE_STANDARD;
  126. // end_wdm
  127. typedef struct _AGP_TARGET_BUS_INTERFACE_STANDARD {
  128. //
  129. // generic interface header
  130. //
  131. USHORT Size;
  132. USHORT Version;
  133. PVOID Context;
  134. PINTERFACE_REFERENCE InterfaceReference;
  135. PINTERFACE_DEREFERENCE InterfaceDereference;
  136. //
  137. // config munging routines
  138. //
  139. PGET_SET_DEVICE_DATA SetBusData;
  140. PGET_SET_DEVICE_DATA GetBusData;
  141. UCHAR CapabilityID; // 2 (AGPv2 host) or new 0xE (AGPv3 bridge)
  142. } AGP_TARGET_BUS_INTERFACE_STANDARD, *PAGP_TARGET_BUS_INTERFACE_STANDARD;
  143. // begin_wdm
  144. //
  145. // The following definitions are used in ACPI QueryInterface
  146. //
  147. typedef BOOLEAN (* PGPE_SERVICE_ROUTINE) (
  148. PVOID,
  149. PVOID);
  150. typedef NTSTATUS (* PGPE_CONNECT_VECTOR) (
  151. PDEVICE_OBJECT,
  152. ULONG,
  153. KINTERRUPT_MODE,
  154. BOOLEAN,
  155. PGPE_SERVICE_ROUTINE,
  156. PVOID,
  157. PVOID);
  158. typedef NTSTATUS (* PGPE_DISCONNECT_VECTOR) (
  159. PVOID);
  160. typedef NTSTATUS (* PGPE_ENABLE_EVENT) (
  161. PDEVICE_OBJECT,
  162. PVOID);
  163. typedef NTSTATUS (* PGPE_DISABLE_EVENT) (
  164. PDEVICE_OBJECT,
  165. PVOID);
  166. typedef NTSTATUS (* PGPE_CLEAR_STATUS) (
  167. PDEVICE_OBJECT,
  168. PVOID);
  169. typedef VOID (* PDEVICE_NOTIFY_CALLBACK) (
  170. PVOID,
  171. ULONG);
  172. typedef NTSTATUS (* PREGISTER_FOR_DEVICE_NOTIFICATIONS) (
  173. PDEVICE_OBJECT,
  174. PDEVICE_NOTIFY_CALLBACK,
  175. PVOID);
  176. typedef void (* PUNREGISTER_FOR_DEVICE_NOTIFICATIONS) (
  177. PDEVICE_OBJECT,
  178. PDEVICE_NOTIFY_CALLBACK);
  179. typedef struct _ACPI_INTERFACE_STANDARD {
  180. //
  181. // Generic interface header
  182. //
  183. USHORT Size;
  184. USHORT Version;
  185. PVOID Context;
  186. PINTERFACE_REFERENCE InterfaceReference;
  187. PINTERFACE_DEREFERENCE InterfaceDereference;
  188. //
  189. // ACPI interfaces
  190. //
  191. PGPE_CONNECT_VECTOR GpeConnectVector;
  192. PGPE_DISCONNECT_VECTOR GpeDisconnectVector;
  193. PGPE_ENABLE_EVENT GpeEnableEvent;
  194. PGPE_DISABLE_EVENT GpeDisableEvent;
  195. PGPE_CLEAR_STATUS GpeClearStatus;
  196. PREGISTER_FOR_DEVICE_NOTIFICATIONS RegisterForDeviceNotifications;
  197. PUNREGISTER_FOR_DEVICE_NOTIFICATIONS UnregisterForDeviceNotifications;
  198. } ACPI_INTERFACE_STANDARD, *PACPI_INTERFACE_STANDARD;
  199. // end_wdm end_ntddk
  200. typedef enum _ACPI_REG_TYPE {
  201. PM1a_ENABLE,
  202. PM1b_ENABLE,
  203. PM1a_STATUS,
  204. PM1b_STATUS,
  205. PM1a_CONTROL,
  206. PM1b_CONTROL,
  207. GP_STATUS,
  208. GP_ENABLE,
  209. SMI_CMD,
  210. MaxRegType
  211. } ACPI_REG_TYPE, *PACPI_REG_TYPE;
  212. typedef USHORT (*PREAD_ACPI_REGISTER) (
  213. IN ACPI_REG_TYPE AcpiReg,
  214. IN ULONG Register);
  215. typedef VOID (*PWRITE_ACPI_REGISTER) (
  216. IN ACPI_REG_TYPE AcpiReg,
  217. IN ULONG Register,
  218. IN USHORT Value
  219. );
  220. typedef struct ACPI_REGS_INTERFACE_STANDARD {
  221. //
  222. // generic interface header
  223. //
  224. USHORT Size;
  225. USHORT Version;
  226. PVOID Context;
  227. PINTERFACE_REFERENCE InterfaceReference;
  228. PINTERFACE_DEREFERENCE InterfaceDereference;
  229. //
  230. // READ/WRITE_ACPI_REGISTER functions
  231. //
  232. PREAD_ACPI_REGISTER ReadAcpiRegister;
  233. PWRITE_ACPI_REGISTER WriteAcpiRegister;
  234. } ACPI_REGS_INTERFACE_STANDARD, *PACPI_REGS_INTERFACE_STANDARD;
  235. typedef NTSTATUS (*PHAL_QUERY_ALLOCATE_PORT_RANGE) (
  236. IN BOOLEAN IsSparse,
  237. IN BOOLEAN PrimaryIsMmio,
  238. IN PVOID VirtBaseAddr OPTIONAL,
  239. IN PHYSICAL_ADDRESS PhysBaseAddr, // Only valid if PrimaryIsMmio = TRUE
  240. IN ULONG Length, // Only valid if PrimaryIsMmio = TRUE
  241. OUT PUSHORT NewRangeId
  242. );
  243. typedef VOID (*PHAL_FREE_PORT_RANGE)(
  244. IN USHORT RangeId
  245. );
  246. typedef struct _HAL_PORT_RANGE_INTERFACE {
  247. //
  248. // generic interface header
  249. //
  250. USHORT Size;
  251. USHORT Version;
  252. PVOID Context;
  253. PINTERFACE_REFERENCE InterfaceReference;
  254. PINTERFACE_DEREFERENCE InterfaceDereference;
  255. //
  256. // QueryAllocateRange/FreeRange functions
  257. //
  258. PHAL_QUERY_ALLOCATE_PORT_RANGE QueryAllocateRange;
  259. PHAL_FREE_PORT_RANGE FreeRange;
  260. } HAL_PORT_RANGE_INTERFACE, *PHAL_PORT_RANGE_INTERFACE;
  261. //
  262. // describe the CMOS HAL interface
  263. //
  264. typedef enum _CMOS_DEVICE_TYPE {
  265. CmosTypeStdPCAT,
  266. CmosTypeIntelPIIX4,
  267. CmosTypeDal1501
  268. } CMOS_DEVICE_TYPE;
  269. typedef
  270. ULONG
  271. (*PREAD_ACPI_CMOS) (
  272. IN CMOS_DEVICE_TYPE CmosType,
  273. IN ULONG SourceAddress,
  274. IN PUCHAR DataBuffer,
  275. IN ULONG ByteCount
  276. );
  277. typedef
  278. ULONG
  279. (*PWRITE_ACPI_CMOS) (
  280. IN CMOS_DEVICE_TYPE CmosType,
  281. IN ULONG SourceAddress,
  282. IN PUCHAR DataBuffer,
  283. IN ULONG ByteCount
  284. );
  285. typedef struct _ACPI_CMOS_INTERFACE_STANDARD {
  286. //
  287. // generic interface header
  288. //
  289. USHORT Size;
  290. USHORT Version;
  291. PVOID Context;
  292. PINTERFACE_REFERENCE InterfaceReference;
  293. PINTERFACE_DEREFERENCE InterfaceDereference;
  294. //
  295. // READ/WRITE_ACPI_CMOS functions
  296. //
  297. PREAD_ACPI_CMOS ReadCmos;
  298. PWRITE_ACPI_CMOS WriteCmos;
  299. } ACPI_CMOS_INTERFACE_STANDARD, *PACPI_CMOS_INTERFACE_STANDARD;
  300. //
  301. // These definitions are used for getting PCI Interrupt Routing interfaces
  302. //
  303. typedef struct {
  304. PVOID LinkNode;
  305. ULONG StaticVector;
  306. UCHAR Flags;
  307. } ROUTING_TOKEN, *PROUTING_TOKEN;
  308. //
  309. // Flag indicating that the device supports
  310. // MSI interrupt routing or that the provided token contains
  311. // MSI routing information
  312. //
  313. #define PCI_MSI_ROUTING 0x1
  314. #define PCI_STATIC_ROUTING 0x2
  315. typedef
  316. NTSTATUS
  317. (*PGET_INTERRUPT_ROUTING)(
  318. IN PDEVICE_OBJECT Pdo,
  319. OUT ULONG *Bus,
  320. OUT ULONG *PciSlot,
  321. OUT UCHAR *InterruptLine,
  322. OUT UCHAR *InterruptPin,
  323. OUT UCHAR *ClassCode,
  324. OUT UCHAR *SubClassCode,
  325. OUT PDEVICE_OBJECT *ParentPdo,
  326. OUT ROUTING_TOKEN *RoutingToken,
  327. OUT UCHAR *Flags
  328. );
  329. typedef
  330. NTSTATUS
  331. (*PSET_INTERRUPT_ROUTING_TOKEN)(
  332. IN PDEVICE_OBJECT Pdo,
  333. IN PROUTING_TOKEN RoutingToken
  334. );
  335. typedef
  336. VOID
  337. (*PUPDATE_INTERRUPT_LINE)(
  338. IN PDEVICE_OBJECT Pdo,
  339. IN UCHAR LineRegister
  340. );
  341. typedef struct _INT_ROUTE_INTERFACE_STANDARD {
  342. //
  343. // generic interface header
  344. //
  345. USHORT Size;
  346. USHORT Version;
  347. PVOID Context;
  348. PINTERFACE_REFERENCE InterfaceReference;
  349. PINTERFACE_DEREFERENCE InterfaceDereference;
  350. //
  351. // standard bus interfaces
  352. //
  353. PGET_INTERRUPT_ROUTING GetInterruptRouting;
  354. PSET_INTERRUPT_ROUTING_TOKEN SetInterruptRoutingToken;
  355. PUPDATE_INTERRUPT_LINE UpdateInterruptLine;
  356. } INT_ROUTE_INTERFACE_STANDARD, *PINT_ROUTE_INTERFACE_STANDARD;
  357. // Some well-known interface versions supported by the PCI Bus Driver
  358. #define PCI_INT_ROUTE_INTRF_STANDARD_VER 1
  359. // end_nthal end_ntifs end_ntosp
  360. NTKERNELAPI
  361. BOOLEAN
  362. PpInitSystem (
  363. VOID
  364. );
  365. NTKERNELAPI
  366. NTSTATUS
  367. PpDeviceRegistration(
  368. IN PUNICODE_STRING DeviceInstancePath,
  369. IN BOOLEAN Add,
  370. IN PUNICODE_STRING ServiceKeyName OPTIONAL
  371. );
  372. // begin_ntosp
  373. NTKERNELAPI
  374. NTSTATUS
  375. IoSynchronousInvalidateDeviceRelations(
  376. PDEVICE_OBJECT DeviceObject,
  377. DEVICE_RELATION_TYPE Type
  378. );
  379. // begin_ntddk begin_nthal begin_ntifs
  380. NTKERNELAPI
  381. NTSTATUS
  382. IoReportDetectedDevice(
  383. IN PDRIVER_OBJECT DriverObject,
  384. IN INTERFACE_TYPE LegacyBusType,
  385. IN ULONG BusNumber,
  386. IN ULONG SlotNumber,
  387. IN PCM_RESOURCE_LIST ResourceList,
  388. IN PIO_RESOURCE_REQUIREMENTS_LIST ResourceRequirements OPTIONAL,
  389. IN BOOLEAN ResourceAssigned,
  390. IN OUT PDEVICE_OBJECT *DeviceObject
  391. );
  392. // begin_wdm
  393. NTKERNELAPI
  394. VOID
  395. IoInvalidateDeviceRelations(
  396. IN PDEVICE_OBJECT DeviceObject,
  397. IN DEVICE_RELATION_TYPE Type
  398. );
  399. NTKERNELAPI
  400. VOID
  401. IoRequestDeviceEject(
  402. IN PDEVICE_OBJECT PhysicalDeviceObject
  403. );
  404. NTKERNELAPI
  405. NTSTATUS
  406. IoGetDeviceProperty(
  407. IN PDEVICE_OBJECT DeviceObject,
  408. IN DEVICE_REGISTRY_PROPERTY DeviceProperty,
  409. IN ULONG BufferLength,
  410. OUT PVOID PropertyBuffer,
  411. OUT PULONG ResultLength
  412. );
  413. //
  414. // The following definitions are used in IoOpenDeviceRegistryKey
  415. //
  416. #define PLUGPLAY_REGKEY_DEVICE 1
  417. #define PLUGPLAY_REGKEY_DRIVER 2
  418. #define PLUGPLAY_REGKEY_CURRENT_HWPROFILE 4
  419. NTKERNELAPI
  420. NTSTATUS
  421. IoOpenDeviceRegistryKey(
  422. IN PDEVICE_OBJECT DeviceObject,
  423. IN ULONG DevInstKeyType,
  424. IN ACCESS_MASK DesiredAccess,
  425. OUT PHANDLE DevInstRegKey
  426. );
  427. NTKERNELAPI
  428. NTSTATUS
  429. NTAPI
  430. IoRegisterDeviceInterface(
  431. IN PDEVICE_OBJECT PhysicalDeviceObject,
  432. IN CONST GUID *InterfaceClassGuid,
  433. IN PUNICODE_STRING ReferenceString, OPTIONAL
  434. OUT PUNICODE_STRING SymbolicLinkName
  435. );
  436. NTKERNELAPI
  437. NTSTATUS
  438. IoOpenDeviceInterfaceRegistryKey(
  439. IN PUNICODE_STRING SymbolicLinkName,
  440. IN ACCESS_MASK DesiredAccess,
  441. OUT PHANDLE DeviceInterfaceKey
  442. );
  443. NTKERNELAPI
  444. NTSTATUS
  445. IoSetDeviceInterfaceState(
  446. IN PUNICODE_STRING SymbolicLinkName,
  447. IN BOOLEAN Enable
  448. );
  449. NTKERNELAPI
  450. NTSTATUS
  451. NTAPI
  452. IoGetDeviceInterfaces(
  453. IN CONST GUID *InterfaceClassGuid,
  454. IN PDEVICE_OBJECT PhysicalDeviceObject OPTIONAL,
  455. IN ULONG Flags,
  456. OUT PWSTR *SymbolicLinkList
  457. );
  458. #define DEVICE_INTERFACE_INCLUDE_NONACTIVE 0x00000001
  459. NTKERNELAPI
  460. NTSTATUS
  461. NTAPI
  462. IoGetDeviceInterfaceAlias(
  463. IN PUNICODE_STRING SymbolicLinkName,
  464. IN CONST GUID *AliasInterfaceClassGuid,
  465. OUT PUNICODE_STRING AliasSymbolicLinkName
  466. );
  467. //
  468. // Define PnP notification event categories
  469. //
  470. typedef enum _IO_NOTIFICATION_EVENT_CATEGORY {
  471. EventCategoryReserved,
  472. EventCategoryHardwareProfileChange,
  473. EventCategoryDeviceInterfaceChange,
  474. EventCategoryTargetDeviceChange
  475. } IO_NOTIFICATION_EVENT_CATEGORY;
  476. //
  477. // Define flags that modify the behavior of IoRegisterPlugPlayNotification
  478. // for the various event categories...
  479. //
  480. #define PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES 0x00000001
  481. typedef
  482. NTSTATUS
  483. (*PDRIVER_NOTIFICATION_CALLBACK_ROUTINE) (
  484. IN PVOID NotificationStructure,
  485. IN PVOID Context
  486. );
  487. NTKERNELAPI
  488. NTSTATUS
  489. IoRegisterPlugPlayNotification(
  490. IN IO_NOTIFICATION_EVENT_CATEGORY EventCategory,
  491. IN ULONG EventCategoryFlags,
  492. IN PVOID EventCategoryData OPTIONAL,
  493. IN PDRIVER_OBJECT DriverObject,
  494. IN PDRIVER_NOTIFICATION_CALLBACK_ROUTINE CallbackRoutine,
  495. IN PVOID Context,
  496. OUT PVOID *NotificationEntry
  497. );
  498. NTKERNELAPI
  499. NTSTATUS
  500. IoUnregisterPlugPlayNotification(
  501. IN PVOID NotificationEntry
  502. );
  503. NTKERNELAPI
  504. NTSTATUS
  505. IoReportTargetDeviceChange(
  506. IN PDEVICE_OBJECT PhysicalDeviceObject,
  507. IN PVOID NotificationStructure // always begins with a PLUGPLAY_NOTIFICATION_HEADER
  508. );
  509. typedef
  510. VOID
  511. (*PDEVICE_CHANGE_COMPLETE_CALLBACK)(
  512. IN PVOID Context
  513. );
  514. NTKERNELAPI
  515. VOID
  516. IoInvalidateDeviceState(
  517. IN PDEVICE_OBJECT PhysicalDeviceObject
  518. );
  519. #define IoAdjustPagingPathCount(_count_,_paging_) { \
  520. if (_paging_) { \
  521. InterlockedIncrement(_count_); \
  522. } else { \
  523. InterlockedDecrement(_count_); \
  524. } \
  525. }
  526. NTKERNELAPI
  527. NTSTATUS
  528. IoReportTargetDeviceChangeAsynchronous(
  529. IN PDEVICE_OBJECT PhysicalDeviceObject,
  530. IN PVOID NotificationStructure, // always begins with a PLUGPLAY_NOTIFICATION_HEADER
  531. IN PDEVICE_CHANGE_COMPLETE_CALLBACK Callback, OPTIONAL
  532. IN PVOID Context OPTIONAL
  533. );
  534. // end_wdm end_ntosp
  535. //
  536. // Device location interface declarations
  537. //
  538. typedef
  539. NTSTATUS
  540. (*PGET_LOCATION_STRING) (
  541. IN PVOID Context,
  542. OUT PWCHAR *LocationStrings
  543. );
  544. typedef struct _PNP_LOCATION_INTERFACE {
  545. //
  546. // generic interface header
  547. //
  548. USHORT Size;
  549. USHORT Version;
  550. PVOID Context;
  551. PINTERFACE_REFERENCE InterfaceReference;
  552. PINTERFACE_DEREFERENCE InterfaceDereference;
  553. //
  554. // interface specific entry
  555. //
  556. PGET_LOCATION_STRING GetLocationString;
  557. } PNP_LOCATION_INTERFACE, *PPNP_LOCATION_INTERFACE;
  558. //
  559. // Resource arbiter declarations
  560. //
  561. typedef enum _ARBITER_ACTION {
  562. ArbiterActionTestAllocation,
  563. ArbiterActionRetestAllocation,
  564. ArbiterActionCommitAllocation,
  565. ArbiterActionRollbackAllocation,
  566. ArbiterActionQueryAllocatedResources,
  567. ArbiterActionWriteReservedResources,
  568. ArbiterActionQueryConflict,
  569. ArbiterActionQueryArbitrate,
  570. ArbiterActionAddReserved,
  571. ArbiterActionBootAllocation
  572. } ARBITER_ACTION, *PARBITER_ACTION;
  573. typedef struct _ARBITER_CONFLICT_INFO {
  574. //
  575. // The device object owning the device that is causing the conflict
  576. //
  577. PDEVICE_OBJECT OwningObject;
  578. //
  579. // The start of the conflicting range
  580. //
  581. ULONGLONG Start;
  582. //
  583. // The end of the conflicting range
  584. //
  585. ULONGLONG End;
  586. } ARBITER_CONFLICT_INFO, *PARBITER_CONFLICT_INFO;
  587. //
  588. // The parameters for those actions
  589. //
  590. typedef struct _ARBITER_PARAMETERS {
  591. union {
  592. struct {
  593. //
  594. // Doubly linked list of ARBITER_LIST_ENTRY's
  595. //
  596. IN OUT PLIST_ENTRY ArbitrationList;
  597. //
  598. // The size of the AllocateFrom array
  599. //
  600. IN ULONG AllocateFromCount;
  601. //
  602. // Array of resource descriptors describing the resources available
  603. // to the arbiter for it to arbitrate
  604. //
  605. IN PCM_PARTIAL_RESOURCE_DESCRIPTOR AllocateFrom;
  606. } TestAllocation;
  607. struct {
  608. //
  609. // Doubly linked list of ARBITER_LIST_ENTRY's
  610. //
  611. IN OUT PLIST_ENTRY ArbitrationList;
  612. //
  613. // The size of the AllocateFrom array
  614. //
  615. IN ULONG AllocateFromCount;
  616. //
  617. // Array of resource descriptors describing the resources available
  618. // to the arbiter for it to arbitrate
  619. //
  620. IN PCM_PARTIAL_RESOURCE_DESCRIPTOR AllocateFrom;
  621. } RetestAllocation;
  622. struct {
  623. //
  624. // Doubly linked list of ARBITER_LIST_ENTRY's
  625. //
  626. IN OUT PLIST_ENTRY ArbitrationList;
  627. } BootAllocation;
  628. struct {
  629. //
  630. // The resources that are currently allocated
  631. //
  632. OUT PCM_PARTIAL_RESOURCE_LIST *AllocatedResources;
  633. } QueryAllocatedResources;
  634. struct {
  635. //
  636. // This is the device we are trying to find a conflict for
  637. //
  638. IN PDEVICE_OBJECT PhysicalDeviceObject;
  639. //
  640. // This is the resource to find the conflict for
  641. //
  642. IN PIO_RESOURCE_DESCRIPTOR ConflictingResource;
  643. //
  644. // Number of devices conflicting on the resource
  645. //
  646. OUT PULONG ConflictCount;
  647. //
  648. // Pointer to array describing the conflicting device objects and ranges
  649. //
  650. OUT PARBITER_CONFLICT_INFO *Conflicts;
  651. } QueryConflict;
  652. struct {
  653. //
  654. // Doubly linked list of ARBITER_LIST_ENTRY's - should have
  655. // only one entry
  656. //
  657. IN PLIST_ENTRY ArbitrationList;
  658. } QueryArbitrate;
  659. struct {
  660. //
  661. // Indicates the device whose resources are to be marked as reserved
  662. //
  663. PDEVICE_OBJECT ReserveDevice;
  664. } AddReserved;
  665. } Parameters;
  666. } ARBITER_PARAMETERS, *PARBITER_PARAMETERS;
  667. typedef enum _ARBITER_REQUEST_SOURCE {
  668. ArbiterRequestUndefined = -1,
  669. ArbiterRequestLegacyReported, // IoReportResourceUsage
  670. ArbiterRequestHalReported, // IoReportHalResourceUsage
  671. ArbiterRequestLegacyAssigned, // IoAssignResources
  672. ArbiterRequestPnpDetected, // IoReportResourceForDetection
  673. ArbiterRequestPnpEnumerated // IRP_MN_QUERY_RESOURCE_REQUIREMENTS
  674. } ARBITER_REQUEST_SOURCE;
  675. typedef enum _ARBITER_RESULT {
  676. ArbiterResultUndefined = -1,
  677. ArbiterResultSuccess,
  678. ArbiterResultExternalConflict, // This indicates that the request can never be solved for devices in this list
  679. ArbiterResultNullRequest // The request was for length zero and thus no translation should be attempted
  680. } ARBITER_RESULT;
  681. //
  682. // ARBITER_FLAG_BOOT_CONFIG - this indicates that the request is for the
  683. // resources assigned by the firmware/BIOS. It should be succeeded even if
  684. // it conflicts with another devices boot config.
  685. //
  686. #define ARBITER_FLAG_BOOT_CONFIG 0x00000001
  687. // begin_ntosp
  688. NTKERNELAPI
  689. NTSTATUS
  690. IoReportResourceForDetection(
  691. IN PDRIVER_OBJECT DriverObject,
  692. IN PCM_RESOURCE_LIST DriverList OPTIONAL,
  693. IN ULONG DriverListSize OPTIONAL,
  694. IN PDEVICE_OBJECT DeviceObject OPTIONAL,
  695. IN PCM_RESOURCE_LIST DeviceList OPTIONAL,
  696. IN ULONG DeviceListSize OPTIONAL,
  697. OUT PBOOLEAN ConflictDetected
  698. );
  699. // end_ntosp
  700. typedef struct _ARBITER_LIST_ENTRY {
  701. //
  702. // This is a doubly linked list of entries for easy sorting
  703. //
  704. LIST_ENTRY ListEntry;
  705. //
  706. // The number of alternative allocation
  707. //
  708. ULONG AlternativeCount;
  709. //
  710. // Pointer to an array of resource descriptors for the possible allocations
  711. //
  712. PIO_RESOURCE_DESCRIPTOR Alternatives;
  713. //
  714. // The device object of the device requesting these resources.
  715. //
  716. PDEVICE_OBJECT PhysicalDeviceObject;
  717. //
  718. // Indicates where the request came from
  719. //
  720. ARBITER_REQUEST_SOURCE RequestSource;
  721. //
  722. // Flags these indicate a variety of things (use ARBITER_FLAG_*)
  723. //
  724. ULONG Flags;
  725. //
  726. // Space to aid the arbiter in processing the list it is initialized to 0 when
  727. // the entry is created. The system will not attempt to interpret it.
  728. //
  729. LONG_PTR WorkSpace;
  730. //
  731. // Interface Type, Slot Number and Bus Number from Resource Requirements list,
  732. // used only for reverse identification.
  733. //
  734. INTERFACE_TYPE InterfaceType;
  735. ULONG SlotNumber;
  736. ULONG BusNumber;
  737. //
  738. // A pointer to a descriptor to indicate the resource that was allocated.
  739. // This is allocated by the system and filled in by the arbiter in response to an
  740. // ArbiterActionTestAllocation.
  741. //
  742. PCM_PARTIAL_RESOURCE_DESCRIPTOR Assignment;
  743. //
  744. // Pointer to the alternative that was chosen from to provide the assignment.
  745. // This is filled in by the arbiter in response to an ArbiterActionTestAllocation.
  746. //
  747. PIO_RESOURCE_DESCRIPTOR SelectedAlternative;
  748. //
  749. // The result of the operation
  750. // This is filled in by the arbiter in response to an ArbiterActionTestAllocation.
  751. //
  752. ARBITER_RESULT Result;
  753. } ARBITER_LIST_ENTRY, *PARBITER_LIST_ENTRY;
  754. //
  755. // The arbiter's entry point
  756. //
  757. typedef
  758. NTSTATUS
  759. (*PARBITER_HANDLER) (
  760. IN PVOID Context,
  761. IN ARBITER_ACTION Action,
  762. IN OUT PARBITER_PARAMETERS Parameters
  763. );
  764. //
  765. // Arbiter interface
  766. //
  767. #define ARBITER_PARTIAL 0x00000001
  768. typedef struct _ARBITER_INTERFACE {
  769. //
  770. // Generic interface header
  771. //
  772. USHORT Size;
  773. USHORT Version;
  774. PVOID Context;
  775. PINTERFACE_REFERENCE InterfaceReference;
  776. PINTERFACE_DEREFERENCE InterfaceDereference;
  777. //
  778. // Entry point to the arbiter
  779. //
  780. PARBITER_HANDLER ArbiterHandler;
  781. //
  782. // Other information about the arbiter, use ARBITER_* flags
  783. //
  784. ULONG Flags;
  785. } ARBITER_INTERFACE, *PARBITER_INTERFACE;
  786. //
  787. // The directions translation can take place in
  788. //
  789. typedef enum _RESOURCE_TRANSLATION_DIRECTION { // ntosp
  790. TranslateChildToParent, // ntosp
  791. TranslateParentToChild // ntosp
  792. } RESOURCE_TRANSLATION_DIRECTION; // ntosp
  793. //
  794. // Translation functions
  795. //
  796. // begin_ntosp
  797. typedef
  798. NTSTATUS
  799. (*PTRANSLATE_RESOURCE_HANDLER)(
  800. IN PVOID Context,
  801. IN PCM_PARTIAL_RESOURCE_DESCRIPTOR Source,
  802. IN RESOURCE_TRANSLATION_DIRECTION Direction,
  803. IN ULONG AlternativesCount, OPTIONAL
  804. IN IO_RESOURCE_DESCRIPTOR Alternatives[], OPTIONAL
  805. IN PDEVICE_OBJECT PhysicalDeviceObject,
  806. OUT PCM_PARTIAL_RESOURCE_DESCRIPTOR Target
  807. );
  808. typedef
  809. NTSTATUS
  810. (*PTRANSLATE_RESOURCE_REQUIREMENTS_HANDLER)(
  811. IN PVOID Context,
  812. IN PIO_RESOURCE_DESCRIPTOR Source,
  813. IN PDEVICE_OBJECT PhysicalDeviceObject,
  814. OUT PULONG TargetCount,
  815. OUT PIO_RESOURCE_DESCRIPTOR *Target
  816. );
  817. //
  818. // Translator Interface
  819. //
  820. typedef struct _TRANSLATOR_INTERFACE {
  821. USHORT Size;
  822. USHORT Version;
  823. PVOID Context;
  824. PINTERFACE_REFERENCE InterfaceReference;
  825. PINTERFACE_DEREFERENCE InterfaceDereference;
  826. PTRANSLATE_RESOURCE_HANDLER TranslateResources;
  827. PTRANSLATE_RESOURCE_REQUIREMENTS_HANDLER TranslateResourceRequirements;
  828. } TRANSLATOR_INTERFACE, *PTRANSLATOR_INTERFACE;
  829. // end_ntddk end_ntosp
  830. //
  831. // Legacy Device Detection Handler
  832. //
  833. typedef
  834. NTSTATUS
  835. (*PLEGACY_DEVICE_DETECTION_HANDLER)(
  836. IN PVOID Context,
  837. IN INTERFACE_TYPE LegacyBusType,
  838. IN ULONG BusNumber,
  839. IN ULONG SlotNumber,
  840. OUT PDEVICE_OBJECT *PhysicalDeviceObject
  841. );
  842. //
  843. // Legacy Device Detection Interface
  844. //
  845. typedef struct _LEGACY_DEVICE_DETECTION_INTERFACE {
  846. USHORT Size;
  847. USHORT Version;
  848. PVOID Context;
  849. PINTERFACE_REFERENCE InterfaceReference;
  850. PINTERFACE_DEREFERENCE InterfaceDereference;
  851. PLEGACY_DEVICE_DETECTION_HANDLER LegacyDeviceDetection;
  852. } LEGACY_DEVICE_DETECTION_INTERFACE, *PLEGACY_DEVICE_DETECTION_INTERFACE;
  853. // end_nthal end_ntifs
  854. // begin_wdm begin_ntddk begin_ntifs begin_nthal begin_ntosp
  855. //
  856. // Header structure for all Plug&Play notification events...
  857. //
  858. typedef struct _PLUGPLAY_NOTIFICATION_HEADER {
  859. USHORT Version; // presently at version 1.
  860. USHORT Size; // size (in bytes) of header + event-specific data.
  861. GUID Event;
  862. //
  863. // Event-specific stuff starts here.
  864. //
  865. } PLUGPLAY_NOTIFICATION_HEADER, *PPLUGPLAY_NOTIFICATION_HEADER;
  866. //
  867. // Notification structure for all EventCategoryHardwareProfileChange events...
  868. //
  869. typedef struct _HWPROFILE_CHANGE_NOTIFICATION {
  870. USHORT Version;
  871. USHORT Size;
  872. GUID Event;
  873. //
  874. // (No event-specific data)
  875. //
  876. } HWPROFILE_CHANGE_NOTIFICATION, *PHWPROFILE_CHANGE_NOTIFICATION;
  877. //
  878. // Notification structure for all EventCategoryDeviceInterfaceChange events...
  879. //
  880. typedef struct _DEVICE_INTERFACE_CHANGE_NOTIFICATION {
  881. USHORT Version;
  882. USHORT Size;
  883. GUID Event;
  884. //
  885. // Event-specific data
  886. //
  887. GUID InterfaceClassGuid;
  888. PUNICODE_STRING SymbolicLinkName;
  889. } DEVICE_INTERFACE_CHANGE_NOTIFICATION, *PDEVICE_INTERFACE_CHANGE_NOTIFICATION;
  890. //
  891. // Notification structures for EventCategoryTargetDeviceChange...
  892. //
  893. //
  894. // The following structure is used for TargetDeviceQueryRemove,
  895. // TargetDeviceRemoveCancelled, and TargetDeviceRemoveComplete:
  896. //
  897. typedef struct _TARGET_DEVICE_REMOVAL_NOTIFICATION {
  898. USHORT Version;
  899. USHORT Size;
  900. GUID Event;
  901. //
  902. // Event-specific data
  903. //
  904. PFILE_OBJECT FileObject;
  905. } TARGET_DEVICE_REMOVAL_NOTIFICATION, *PTARGET_DEVICE_REMOVAL_NOTIFICATION;
  906. //
  907. // The following structure header is used for all other (i.e., 3rd-party)
  908. // target device change events. The structure accommodates both a
  909. // variable-length binary data buffer, and a variable-length unicode text
  910. // buffer. The header must indicate where the text buffer begins, so that
  911. // the data can be delivered in the appropriate format (ANSI or Unicode)
  912. // to user-mode recipients (i.e., that have registered for handle-based
  913. // notification via RegisterDeviceNotification).
  914. //
  915. typedef struct _TARGET_DEVICE_CUSTOM_NOTIFICATION {
  916. USHORT Version;
  917. USHORT Size;
  918. GUID Event;
  919. //
  920. // Event-specific data
  921. //
  922. PFILE_OBJECT FileObject; // This field must be set to NULL by callers of
  923. // IoReportTargetDeviceChange. Clients that
  924. // have registered for target device change
  925. // notification on the affected PDO will be
  926. // called with this field set to the file object
  927. // they specified during registration.
  928. //
  929. LONG NameBufferOffset; // offset (in bytes) from beginning of
  930. // CustomDataBuffer where text begins (-1 if none)
  931. //
  932. UCHAR CustomDataBuffer[1]; // variable-length buffer, containing (optionally)
  933. // a binary data at the start of the buffer,
  934. // followed by an optional unicode text buffer
  935. // (word-aligned).
  936. //
  937. } TARGET_DEVICE_CUSTOM_NOTIFICATION, *PTARGET_DEVICE_CUSTOM_NOTIFICATION;
  938. // end_wdm end_ntddk end_ntifs end_nthal end_ntosp
  939. NTSTATUS
  940. PpSetCustomTargetEvent(
  941. IN PDEVICE_OBJECT DeviceObject,
  942. IN PKEVENT SyncEvent OPTIONAL,
  943. OUT PULONG Result OPTIONAL,
  944. IN PDEVICE_CHANGE_COMPLETE_CALLBACK Callback OPTIONAL,
  945. IN PVOID Context OPTIONAL,
  946. IN PTARGET_DEVICE_CUSTOM_NOTIFICATION NotificationStructure
  947. );
  948. NTSTATUS
  949. PpSetTargetDeviceRemove(
  950. IN PDEVICE_OBJECT DeviceObject,
  951. IN BOOLEAN KernelInitiated,
  952. IN BOOLEAN NoRestart,
  953. IN BOOLEAN OnlyRestartRelations,
  954. IN BOOLEAN DoEject,
  955. IN ULONG Problem,
  956. IN PKEVENT SyncEvent OPTIONAL,
  957. OUT PULONG Result OPTIONAL,
  958. OUT PPNP_VETO_TYPE VetoType OPTIONAL,
  959. OUT PUNICODE_STRING VetoName OPTIONAL
  960. );
  961. NTSTATUS
  962. PpSetDeviceRemovalSafe(
  963. IN PDEVICE_OBJECT DeviceObject,
  964. IN PKEVENT SyncEvent OPTIONAL,
  965. OUT PULONG Result OPTIONAL
  966. );
  967. NTSTATUS
  968. PpNotifyUserModeRemovalSafe(
  969. IN PDEVICE_OBJECT DeviceObject
  970. );
  971. #define TDF_DEVICEEJECTABLE 0x00000001
  972. #define TDF_NO_RESTART 0x00000002
  973. #define TDF_KERNEL_INITIATED 0x00000004
  974. //
  975. // This flag is valid only if TDF_NO_RESTART is not set. If set, only relations
  976. // are restarted. If not set, original device and relations are restarted.
  977. //
  978. #define TDF_ONLY_RESTART_RELATIONS 0x00000008
  979. NTSTATUS
  980. PpSetDeviceClassChange(
  981. IN CONST GUID *EventGuid,
  982. IN CONST GUID *ClassGuid,
  983. IN PUNICODE_STRING SymbolicLinkName
  984. );
  985. VOID
  986. PpSetPlugPlayEvent(
  987. IN CONST GUID *EventGuid,
  988. IN PDEVICE_OBJECT DeviceObject
  989. );
  990. NTSTATUS
  991. PpInitializeNotification(
  992. VOID
  993. );
  994. VOID
  995. PpShutdownSystem (
  996. IN BOOLEAN Reboot,
  997. IN ULONG Phase,
  998. IN OUT PVOID *Context
  999. );
  1000. NTSTATUS
  1001. PpSetPowerEvent(
  1002. IN ULONG EventCode,
  1003. IN ULONG EventData,
  1004. IN PKEVENT CompletionEvent OPTIONAL,
  1005. OUT PNTSTATUS CompletionStatus OPTIONAL,
  1006. OUT PPNP_VETO_TYPE VetoType OPTIONAL,
  1007. OUT PUNICODE_STRING VetoName OPTIONAL
  1008. );
  1009. NTSTATUS
  1010. PpSetHwProfileChangeEvent(
  1011. IN CONST GUID *EventGuid,
  1012. IN PKEVENT CompletionEvent OPTIONAL,
  1013. OUT PNTSTATUS CompletionStatus OPTIONAL,
  1014. OUT PPNP_VETO_TYPE VetoType OPTIONAL,
  1015. OUT PUNICODE_STRING VetoName OPTIONAL
  1016. );
  1017. NTSTATUS
  1018. PpSetBlockedDriverEvent(
  1019. IN GUID CONST *BlockedDriverGuid
  1020. );
  1021. NTSTATUS
  1022. PpSynchronizeDeviceEventQueue(
  1023. VOID
  1024. );
  1025. NTSTATUS
  1026. PpSetInvalidIDEvent(
  1027. IN PUNICODE_STRING ParentInstance
  1028. );
  1029. NTSTATUS
  1030. PpSetPowerVetoEvent(
  1031. IN POWER_ACTION VetoedPowerOperation,
  1032. IN PKEVENT CompletionEvent OPTIONAL,
  1033. OUT PNTSTATUS CompletionStatus OPTIONAL,
  1034. IN PDEVICE_OBJECT DeviceObject,
  1035. IN PNP_VETO_TYPE VetoType,
  1036. IN PUNICODE_STRING VetoName OPTIONAL
  1037. );
  1038. NTSTATUS
  1039. PpPagePathAssign(
  1040. IN PFILE_OBJECT FileObject
  1041. );
  1042. NTSTATUS
  1043. PpPagePathRelease(
  1044. IN PFILE_OBJECT FileObject
  1045. );
  1046. //
  1047. // Entry point for USER to deliver notifications (public)
  1048. //
  1049. // begin_ntosp
  1050. ULONG
  1051. IoPnPDeliverServicePowerNotification(
  1052. IN POWER_ACTION PowerOperation,
  1053. IN ULONG PowerNotificationCode,
  1054. IN ULONG PowerNotificationData,
  1055. IN BOOLEAN Synchronous
  1056. );
  1057. // end_ntosp
  1058. #endif // _PNP_