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.

965 lines
32 KiB

  1. /*****************************************************************************
  2. * private.h - WDM Audio class driver
  3. *****************************************************************************
  4. * Copyright (c) 1996-2000 Microsoft Corporation. All rights reserved.
  5. */
  6. #ifndef _PORTCLS_PRIVATE_H_
  7. #define _PORTCLS_PRIVATE_H_
  8. #include "portclsp.h"
  9. #include "dmusicks.h"
  10. #include "stdunk.h"
  11. #ifndef PC_KDEXT
  12. #if (DBG)
  13. #define STR_MODULENAME "PortCls: "
  14. #define DEBUG_VARIABLE PORTCLSDebug
  15. #endif
  16. #endif // PC_KDEXT
  17. #include <ksdebug.h>
  18. #include <wchar.h>
  19. #define PORTCLS_DEVICE_EXTENSION_SIGNATURE 0x000BABEE
  20. #ifndef DEBUGLVL_LIFETIME
  21. #define DEBUGLVL_LIFETIME DEBUGLVL_VERBOSE
  22. #endif
  23. // BUGBUG - the default idle times are currently set to 0 to effectively
  24. // disable inactivity timeouts until the ntkern\configmg appy-time
  25. // deadlock bug is resolved.
  26. #if 1
  27. #define DEFAULT_CONSERVATION_IDLE_TIME 0
  28. #define DEFAULT_PERFORMANCE_IDLE_TIME 0
  29. #else
  30. #define DEFAULT_CONSERVATION_IDLE_TIME 30
  31. #define DEFAULT_PERFORMANCE_IDLE_TIME 300
  32. #endif
  33. #define DEFAULT_IDLE_DEVICE_POWER_STATE PowerDeviceD3
  34. typedef enum
  35. {
  36. DeviceRemoved,
  37. DeviceSurpriseRemoved,
  38. DeviceRemovePending,
  39. DeviceAdded
  40. } DEVICE_REMOVE_STATE,*PDEVICE_REMOVE_STATE;
  41. typedef enum
  42. {
  43. DeviceStopped,
  44. DeviceStopPending,
  45. DevicePausedForRebalance,
  46. DeviceStarted,
  47. DeviceStartPending // StartDevice has not yet finished
  48. } DEVICE_STOP_STATE,*PDEVICE_STOP_STATE;
  49. /*****************************************************************************
  50. * PHYSICALCONNECTION
  51. *****************************************************************************
  52. * List entry for list of physical connections.
  53. */
  54. typedef struct
  55. {
  56. LIST_ENTRY ListEntry; // Must be first.
  57. PSUBDEVICE FromSubdevice;
  58. PUNICODE_STRING FromString;
  59. ULONG FromPin;
  60. PSUBDEVICE ToSubdevice;
  61. PUNICODE_STRING ToString;
  62. ULONG ToPin;
  63. }
  64. PHYSICALCONNECTION, *PPHYSICALCONNECTION;
  65. /*****************************************************************************
  66. * DEVICEINTERFACE
  67. *****************************************************************************
  68. * List entry for list of physical connections.
  69. */
  70. typedef struct
  71. {
  72. LIST_ENTRY ListEntry; // Must be first.
  73. GUID Interface;
  74. UNICODE_STRING SymbolicLinkName;
  75. PSUBDEVICE Subdevice;
  76. }
  77. DEVICEINTERFACE, *PDEVICEINTERFACE;
  78. /*****************************************************************************
  79. * TIMEOUTCALLBACK
  80. *****************************************************************************
  81. * List entry for list of IoTimeout clients.
  82. */
  83. typedef struct
  84. {
  85. LIST_ENTRY ListEntry;
  86. PIO_TIMER_ROUTINE TimerRoutine;
  87. PVOID Context;
  88. } TIMEOUTCALLBACK,*PTIMEOUTCALLBACK;
  89. /*****************************************************************************
  90. * DEVICE_CONTEXT
  91. *****************************************************************************
  92. * This is the context structure for the device object that represents an
  93. * entire adapter. It consists primarily of the create dispatch table (in
  94. * device header) used by KS to create new filters. Each item in the table
  95. * represents a port, i.e. a pairing of a port driver and a miniport driver.
  96. * The table's item structure contains a user-defined pointer, which is used
  97. * in this case to point to the subdevice context (SUBDEVICE_CONTEXT). The
  98. * subdevice context is extended as required for the port driver and miniport
  99. * in question.
  100. */
  101. typedef struct // 32 64 struct packing for 32-bit and 64-bit architectures
  102. {
  103. PVOID pDeviceHeader; // 4 8 KS mystery device header.
  104. PIRPTARGETFACTORY pIrpTargetFactory; // 4 8 Not used.
  105. PDEVICE_OBJECT PhysicalDeviceObject; // 4 8 Physical Device Object
  106. PCPFNSTARTDEVICE StartDevice; // 4 8 Adapter's StartDevice fn, initialized at
  107. // DriverEntry & called at PnP Start_Device time.
  108. PVOID MinidriverReserved[4]; // 16 32 Reserved for multiple binding.
  109. PDEVICE_OBJECT NextDeviceInStack; // 4 8 Member of the stack below us.
  110. PKSOBJECT_CREATE_ITEM CreateItems; // 4 8 Subdevice create table entries;
  111. ULONG Signature; // 4 4 DeviceExtension Signature
  112. ULONG MaxObjects; // 4 4 Maximum number of subdevices.
  113. PUNICODE_STRING SymbolicLinkNames; // 4 8 Link names of subdevices.
  114. LIST_ENTRY DeviceInterfaceList; // 8 16 List of device interfaces.
  115. LIST_ENTRY PhysicalConnectionList; // 8 16 List of physical connections.
  116. KEVENT kEventDevice; // 16 24 Device synchronization.
  117. KEVENT kEventRemove; // 16 24 Device removal.
  118. PVOID pWorkQueueItemStart; // 4 8 Work queue item for pnp start.
  119. PIRP IrpStart; // 4 8 Start IRP.
  120. DEVICE_REMOVE_STATE DeviceRemoveState; // 4 4 Device remove state.
  121. DEVICE_STOP_STATE DeviceStopState; // 4 4 Device stop state.
  122. BOOLEAN PauseForRebalance; // 1 1 Whether to pause or turn card off during rebalance.
  123. BOOLEAN PendCreates; // 1 1 Whether to pend creates.
  124. BOOLEAN AllowRegisterDeviceInterface; // 1 1 Whether to allow registering device interfaces.
  125. BOOLEAN IoTimeoutsOk; // 1 1 Whether or not the IoInitializeTimeout failed.
  126. ULONG ExistingObjectCount; // 4 4 Number of existing objects.
  127. ULONG ActivePinCount; // 4 4 Number of active pins.
  128. ULONG PendingIrpCount; // 4 4 Number of pending IRPs.
  129. PADAPTERPOWERMANAGEMENT pAdapterPower; // 4 8 Pointer to the adapter's
  130. // power-management interface.
  131. PVOID SystemStateHandle; // 4 8 Used with PoRegisterSystemState.
  132. PULONG IdleTimer; // 4 8 A pointer to the idle timer.
  133. DEVICE_POWER_STATE CurrentDeviceState; // 4 4 The current state of the device.
  134. SYSTEM_POWER_STATE CurrentSystemState; // 4 4 The current system power state.
  135. DEVICE_POWER_STATE DeviceStateMap[PowerSystemMaximum]; // 28 28 System to device power state map.
  136. DEVICE_POWER_STATE IdleDeviceState; // 4 4 The device state to transition to when idle.
  137. ULONG ConservationIdleTime; // 4 4 Idle timeout period for conservation mode.
  138. ULONG PerformanceIdleTime; // 4 4 Idle timeout period for performance mode.
  139. LIST_ENTRY PendedIrpList; // 8 16 Pended IRP queue.
  140. KSPIN_LOCK PendedIrpLock; // 4 8 Spinlock for pended IRP list.
  141. USHORT SuspendCount; // 2 2 PM/ACPI power down count for debugging.
  142. USHORT StopCount; // 2 2 PnP stop count for debugging.
  143. // (4 pad)
  144. LIST_ENTRY TimeoutList; // 8 16 List of IoTimeout callback clients
  145. KSPIN_LOCK TimeoutLock; // 4 8 IoTimeout list spinlock
  146. PKSPIN_LOCK DriverDmaLock; // 4 8 A pointer to the DriverObject DMA spinlock
  147. KDPC DevicePowerRequestDpc; // 32 64 DPC to handle deferred device power irps (Fast Resume)
  148. }
  149. DEVICE_CONTEXT, *PDEVICE_CONTEXT; // 256 416
  150. // NOTE! For legacy reasons, can never be more than 256/512.
  151. // If we need to add more members, change an existing member
  152. // to a pointer to an additional expansion piece of memory.
  153. /*****************************************************************************
  154. * POWER_IRP_CONTEXT
  155. *****************************************************************************
  156. * This is the context structure for processing power irps.
  157. */
  158. typedef struct
  159. {
  160. PKEVENT PowerSyncEvent;
  161. NTSTATUS Status;
  162. PIRP PendingSystemPowerIrp;
  163. PDEVICE_CONTEXT DeviceContext;
  164. }
  165. POWER_IRP_CONTEXT,*PPOWER_IRP_CONTEXT;
  166. /*****************************************************************************
  167. * IResourceListInit
  168. *****************************************************************************
  169. * Initialization interface for list of resources.
  170. */
  171. DECLARE_INTERFACE_(IResourceListInit,IResourceList)
  172. {
  173. DEFINE_ABSTRACT_UNKNOWN() // For IUnknown
  174. // For IResourceList
  175. STDMETHOD_(ULONG,NumberOfEntries)
  176. ( THIS
  177. ) PURE;
  178. STDMETHOD_(ULONG,NumberOfEntriesOfType)
  179. ( THIS_
  180. IN CM_RESOURCE_TYPE Type
  181. ) PURE;
  182. STDMETHOD_(PCM_PARTIAL_RESOURCE_DESCRIPTOR,FindTranslatedEntry)
  183. ( THIS_
  184. IN CM_RESOURCE_TYPE Type,
  185. IN ULONG Index
  186. ) PURE;
  187. STDMETHOD_(PCM_PARTIAL_RESOURCE_DESCRIPTOR,FindUntranslatedEntry)
  188. ( THIS_
  189. IN CM_RESOURCE_TYPE Type,
  190. IN ULONG Index
  191. ) PURE;
  192. STDMETHOD_(NTSTATUS,AddEntry)
  193. ( THIS_
  194. IN PCM_PARTIAL_RESOURCE_DESCRIPTOR Translated,
  195. IN PCM_PARTIAL_RESOURCE_DESCRIPTOR Untranslated
  196. ) PURE;
  197. STDMETHOD_(NTSTATUS,AddEntryFromParent)
  198. ( THIS_
  199. IN struct IResourceList * Parent,
  200. IN CM_RESOURCE_TYPE Type,
  201. IN ULONG Index
  202. ) PURE;
  203. STDMETHOD_(PCM_RESOURCE_LIST,TranslatedList)
  204. ( THIS
  205. ) PURE;
  206. STDMETHOD_(PCM_RESOURCE_LIST,UntranslatedList)
  207. ( THIS
  208. ) PURE;
  209. // For IResourceListInit
  210. STDMETHOD_(NTSTATUS,Init)
  211. ( THIS_
  212. IN PCM_RESOURCE_LIST TranslatedResources,
  213. IN PCM_RESOURCE_LIST UntranslatedResources,
  214. IN POOL_TYPE PoolType
  215. ) PURE;
  216. STDMETHOD_(NTSTATUS,InitFromParent)
  217. ( THIS_
  218. IN PRESOURCELIST ParentList,
  219. IN ULONG MaximumEntries,
  220. IN POOL_TYPE PoolType
  221. ) PURE;
  222. };
  223. typedef IResourceListInit *PRESOURCELISTINIT;
  224. /*****************************************************************************
  225. * CResourceList
  226. *****************************************************************************
  227. * Resource list implementation.
  228. */
  229. class CResourceList
  230. : public IResourceListInit,
  231. public CUnknown
  232. {
  233. private:
  234. PCM_RESOURCE_LIST Untranslated;
  235. PCM_RESOURCE_LIST Translated;
  236. ULONG EntriesAllocated;
  237. ULONG EntriesInUse;
  238. public:
  239. DECLARE_STD_UNKNOWN();
  240. DEFINE_STD_CONSTRUCTOR(CResourceList);
  241. ~CResourceList();
  242. /*************************************************************************
  243. * IResourceListInit methods
  244. */
  245. STDMETHODIMP_(NTSTATUS) Init
  246. (
  247. IN PCM_RESOURCE_LIST TranslatedResources,
  248. IN PCM_RESOURCE_LIST UntranslatedResources,
  249. IN POOL_TYPE PoolType
  250. );
  251. STDMETHODIMP_(NTSTATUS) InitFromParent
  252. (
  253. IN PRESOURCELIST ParentList,
  254. IN ULONG MaximumEntries,
  255. IN POOL_TYPE PoolType
  256. );
  257. /*************************************************************************
  258. * IResourceList methods
  259. */
  260. STDMETHODIMP_(ULONG) NumberOfEntries
  261. ( void
  262. );
  263. STDMETHODIMP_(ULONG) NumberOfEntriesOfType
  264. (
  265. IN CM_RESOURCE_TYPE Type
  266. );
  267. STDMETHODIMP_(PCM_PARTIAL_RESOURCE_DESCRIPTOR) FindTranslatedEntry
  268. (
  269. IN CM_RESOURCE_TYPE Type,
  270. IN ULONG Index
  271. );
  272. STDMETHODIMP_(PCM_PARTIAL_RESOURCE_DESCRIPTOR) FindUntranslatedEntry
  273. (
  274. IN CM_RESOURCE_TYPE Type,
  275. IN ULONG Index
  276. );
  277. STDMETHODIMP_(NTSTATUS) AddEntry
  278. (
  279. IN PCM_PARTIAL_RESOURCE_DESCRIPTOR Translated,
  280. IN PCM_PARTIAL_RESOURCE_DESCRIPTOR Untranslated
  281. );
  282. STDMETHODIMP_(NTSTATUS) AddEntryFromParent
  283. (
  284. IN PRESOURCELIST Parent,
  285. IN CM_RESOURCE_TYPE Type,
  286. IN ULONG Index
  287. );
  288. STDMETHODIMP_(PCM_RESOURCE_LIST) TranslatedList
  289. ( void
  290. );
  291. STDMETHODIMP_(PCM_RESOURCE_LIST) UntranslatedList
  292. ( void
  293. );
  294. };
  295. /*****************************************************************************
  296. * IRegistryKeyInit
  297. *****************************************************************************
  298. * Interface for registry key with Init.
  299. */
  300. DECLARE_INTERFACE_(IRegistryKeyInit,IRegistryKey)
  301. {
  302. DEFINE_ABSTRACT_UNKNOWN() // For IUnknown
  303. // For IRegistryKey
  304. STDMETHOD_(NTSTATUS,QueryKey)
  305. ( THIS_
  306. IN KEY_INFORMATION_CLASS KeyInformationClass,
  307. OUT PVOID KeyInformation,
  308. IN ULONG Length,
  309. OUT PULONG ResultLength
  310. ) PURE;
  311. STDMETHOD_(NTSTATUS,EnumerateKey)
  312. ( THIS_
  313. IN ULONG Index,
  314. IN KEY_INFORMATION_CLASS KeyInformationClass,
  315. OUT PVOID KeyInformation,
  316. IN ULONG Length,
  317. OUT PULONG ResultLength
  318. ) PURE;
  319. STDMETHOD_(NTSTATUS,QueryValueKey)
  320. ( THIS_
  321. IN PUNICODE_STRING ValueName,
  322. IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
  323. OUT PVOID KeyValueInformation,
  324. IN ULONG Length,
  325. OUT PULONG ResultLength
  326. ) PURE;
  327. STDMETHOD_(NTSTATUS,EnumerateValueKey)
  328. ( THIS_
  329. IN ULONG Index,
  330. IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
  331. OUT PVOID KeyValueInformation,
  332. IN ULONG Length,
  333. OUT PULONG ResultLength
  334. ) PURE;
  335. STDMETHOD_(NTSTATUS,SetValueKey)
  336. ( THIS_
  337. IN PUNICODE_STRING ValueName OPTIONAL,
  338. IN ULONG Type,
  339. IN PVOID Data,
  340. IN ULONG DataSize
  341. ) PURE;
  342. STDMETHOD_(NTSTATUS,QueryRegistryValues)
  343. ( THIS_
  344. IN PRTL_QUERY_REGISTRY_TABLE QueryTable,
  345. IN PVOID Context OPTIONAL
  346. ) PURE;
  347. STDMETHOD_(NTSTATUS,NewSubKey)
  348. ( THIS_
  349. OUT IRegistryKey ** RegistrySubKey,
  350. IN PUNKNOWN OuterUnknown,
  351. IN ACCESS_MASK DesiredAccess,
  352. IN PUNICODE_STRING SubKeyName,
  353. IN ULONG CreateOptions,
  354. OUT PULONG Disposition OPTIONAL
  355. ) PURE;
  356. STDMETHOD_(NTSTATUS,DeleteKey)
  357. ( THIS
  358. ) PURE;
  359. // For IRegistryKeyInit
  360. STDMETHOD_(NTSTATUS,Init)
  361. ( THIS_
  362. IN ULONG RegistryKeyType,
  363. IN ACCESS_MASK DesiredAccess,
  364. IN PDEVICE_OBJECT DeviceObject OPTIONAL,
  365. IN PSUBDEVICE SubDevice OPTIONAL,
  366. IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
  367. IN ULONG CreateOptions OPTIONAL,
  368. OUT PULONG Disposition OPTIONAL
  369. ) PURE;
  370. };
  371. typedef IRegistryKeyInit *PREGISTRYKEYINIT;
  372. /*****************************************************************************
  373. * CRegistryKey
  374. *****************************************************************************
  375. * Registry Key implementation.
  376. */
  377. class CRegistryKey
  378. : public IRegistryKeyInit,
  379. public CUnknown
  380. {
  381. private:
  382. HANDLE m_KeyHandle; // Key Handle
  383. BOOLEAN m_KeyDeleted; // Key Deleted Flag
  384. BOOLEAN m_GeneralKey; // Only general keys may be deleted
  385. public:
  386. DECLARE_STD_UNKNOWN();
  387. DEFINE_STD_CONSTRUCTOR(CRegistryKey);
  388. ~CRegistryKey();
  389. /*************************************************************************
  390. * IRegistryKeyInit methods
  391. */
  392. STDMETHODIMP_(NTSTATUS) Init
  393. (
  394. IN ULONG RegistryKeyType,
  395. IN ACCESS_MASK DesiredAccess,
  396. IN PDEVICE_OBJECT DeviceObject OPTIONAL,
  397. IN PSUBDEVICE SubDevice OPTIONAL,
  398. IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
  399. IN ULONG CreateOptions OPTIONAL,
  400. OUT PULONG Disposition OPTIONAL
  401. );
  402. /*************************************************************************
  403. * IRegistryKey methods
  404. */
  405. STDMETHODIMP_(NTSTATUS) QueryKey
  406. (
  407. IN KEY_INFORMATION_CLASS KeyInformationClass,
  408. OUT PVOID KeyInformation,
  409. IN ULONG Length,
  410. OUT PULONG ResultLength
  411. );
  412. STDMETHODIMP_(NTSTATUS) EnumerateKey
  413. (
  414. IN ULONG Index,
  415. IN KEY_INFORMATION_CLASS KeyInformationClass,
  416. OUT PVOID KeyInformation,
  417. IN ULONG Length,
  418. OUT PULONG ResultLength
  419. );
  420. STDMETHODIMP_(NTSTATUS) QueryValueKey
  421. (
  422. IN PUNICODE_STRING ValueName,
  423. IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
  424. OUT PVOID KeyValueInformation,
  425. IN ULONG Length,
  426. OUT PULONG ResultLength
  427. );
  428. STDMETHODIMP_(NTSTATUS) EnumerateValueKey
  429. (
  430. IN ULONG Index,
  431. IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
  432. OUT PVOID KeyValueInformation,
  433. IN ULONG Length,
  434. OUT PULONG ResultLength
  435. );
  436. STDMETHODIMP_(NTSTATUS) SetValueKey
  437. (
  438. IN PUNICODE_STRING ValueName OPTIONAL,
  439. IN ULONG Type,
  440. IN PVOID Data,
  441. IN ULONG DataSize
  442. );
  443. STDMETHODIMP_(NTSTATUS) QueryRegistryValues
  444. (
  445. IN PRTL_QUERY_REGISTRY_TABLE QueryTable,
  446. IN PVOID Context OPTIONAL
  447. );
  448. STDMETHODIMP_(NTSTATUS) NewSubKey
  449. (
  450. OUT PREGISTRYKEY * RegistrySubKey,
  451. IN PUNKNOWN OuterUnknown,
  452. IN ACCESS_MASK DesiredAccess,
  453. IN PUNICODE_STRING SubKeyName,
  454. IN ULONG CreateOptions,
  455. OUT PULONG Disposition OPTIONAL
  456. );
  457. STDMETHODIMP_(NTSTATUS) DeleteKey
  458. ( void
  459. );
  460. };
  461. /*****************************************************************************
  462. * Functions
  463. */
  464. /*****************************************************************************
  465. * AcquireDevice()
  466. *****************************************************************************
  467. * Acquire exclusive access to the device.
  468. */
  469. VOID
  470. AcquireDevice
  471. (
  472. IN PDEVICE_CONTEXT pDeviceContext
  473. );
  474. /*****************************************************************************
  475. * ReleaseDevice()
  476. *****************************************************************************
  477. * Release exclusive access to the device.
  478. */
  479. VOID
  480. ReleaseDevice
  481. (
  482. IN PDEVICE_CONTEXT pDeviceContext
  483. );
  484. /*****************************************************************************
  485. * IncrementPendingIrpCount()
  486. *****************************************************************************
  487. * Increment the pending IRP count for the device.
  488. */
  489. VOID
  490. IncrementPendingIrpCount
  491. (
  492. IN PDEVICE_CONTEXT pDeviceContext
  493. );
  494. /*****************************************************************************
  495. * DecrementPendingIrpCount()
  496. *****************************************************************************
  497. * Decrement the pending IRP count for the device.
  498. */
  499. VOID
  500. DecrementPendingIrpCount
  501. (
  502. IN PDEVICE_CONTEXT pDeviceContext
  503. );
  504. /*****************************************************************************
  505. * SubdeviceIndex()
  506. *****************************************************************************
  507. * Returns the index of a subdevice in the create items list or ULONG(-1) if
  508. * not found.
  509. */
  510. ULONG
  511. SubdeviceIndex
  512. (
  513. IN PDEVICE_OBJECT DeviceObject,
  514. IN PSUBDEVICE Subdevice
  515. );
  516. /*****************************************************************************
  517. * GetDeviceACPIInfo()
  518. *****************************************************************************
  519. * Called in response to a PnP - IRP_MN_QUERY_CAPABILITIES
  520. * Call the bus driver to fill out the inital info,
  521. * Then overwrite with our own...
  522. *
  523. */
  524. NTSTATUS
  525. GetDeviceACPIInfo
  526. (
  527. IN PIRP pIrp,
  528. IN PDEVICE_OBJECT pDeviceObject
  529. );
  530. NTSTATUS
  531. GetIdleInfoFromRegistry
  532. (
  533. IN PDEVICE_CONTEXT DeviceContext,
  534. OUT PULONG ConservationIdleTime,
  535. OUT PULONG PerformanceIdleTime,
  536. OUT PDEVICE_POWER_STATE IdleDeviceState
  537. );
  538. NTSTATUS
  539. CheckCurrentPowerState
  540. (
  541. IN PDEVICE_OBJECT pDeviceObject
  542. );
  543. NTSTATUS
  544. UpdateActivePinCount
  545. (
  546. IN PDEVICE_CONTEXT DeviceContext,
  547. IN BOOL Increment
  548. );
  549. NTSTATUS
  550. DispatchCreate
  551. (
  552. IN PDEVICE_OBJECT pDeviceObject,
  553. IN PIRP pIrp
  554. );
  555. NTSTATUS
  556. DispatchDeviceIoControl
  557. (
  558. IN PDEVICE_OBJECT pDeviceObject,
  559. IN PIRP pIrp
  560. );
  561. BOOLEAN
  562. DispatchFastDeviceIoControl
  563. (
  564. IN PFILE_OBJECT FileObject,
  565. IN BOOLEAN Wait,
  566. IN PVOID InputBuffer OPTIONAL,
  567. IN ULONG InputBufferLength,
  568. OUT PVOID OutputBuffer OPTIONAL,
  569. IN ULONG OutputBufferLength,
  570. IN ULONG IoControlCode,
  571. OUT PIO_STATUS_BLOCK IoStatus,
  572. IN PDEVICE_OBJECT DeviceObject
  573. );
  574. NTSTATUS
  575. DispatchRead
  576. (
  577. IN PDEVICE_OBJECT pDeviceObject,
  578. IN PIRP pIrp
  579. );
  580. BOOLEAN
  581. DispatchFastRead
  582. (
  583. IN PFILE_OBJECT FileObject,
  584. IN PLARGE_INTEGER FileOffset,
  585. IN ULONG Length,
  586. IN BOOLEAN Wait,
  587. IN ULONG LockKey,
  588. OUT PVOID Buffer,
  589. OUT PIO_STATUS_BLOCK IoStatus,
  590. IN PDEVICE_OBJECT DeviceObject
  591. );
  592. NTSTATUS
  593. DispatchWrite
  594. (
  595. IN PDEVICE_OBJECT pDeviceObject,
  596. IN PIRP pIrp
  597. );
  598. BOOLEAN
  599. DispatchFastWrite
  600. (
  601. IN PFILE_OBJECT FileObject,
  602. IN PLARGE_INTEGER FileOffset,
  603. IN ULONG Length,
  604. IN BOOLEAN Wait,
  605. IN ULONG LockKey,
  606. IN PVOID Buffer,
  607. OUT PIO_STATUS_BLOCK IoStatus,
  608. IN PDEVICE_OBJECT DeviceObject
  609. );
  610. NTSTATUS
  611. DispatchFlush
  612. (
  613. IN PDEVICE_OBJECT pDeviceObject,
  614. IN PIRP pIrp
  615. );
  616. NTSTATUS
  617. DispatchClose
  618. (
  619. IN PDEVICE_OBJECT pDeviceObject,
  620. IN PIRP pIrp
  621. );
  622. NTSTATUS
  623. DispatchQuerySecurity
  624. (
  625. IN PDEVICE_OBJECT pDeviceObject,
  626. IN PIRP pIrp
  627. );
  628. NTSTATUS
  629. DispatchSetSecurity
  630. (
  631. IN PDEVICE_OBJECT pDeviceObject,
  632. IN PIRP pIrp
  633. );
  634. /*****************************************************************************
  635. * DispatchPower()
  636. *****************************************************************************
  637. * The dispatch function for all MN_POWER irps.
  638. *
  639. */
  640. NTSTATUS
  641. DispatchPower
  642. (
  643. IN PDEVICE_OBJECT pDeviceObject,
  644. IN PIRP pIrp
  645. );
  646. /*****************************************************************************
  647. * CompleteIrp()
  648. *****************************************************************************
  649. * Complete an IRP unless status is STATUS_PENDING.
  650. */
  651. NTSTATUS
  652. CompleteIrp
  653. (
  654. IN PDEVICE_CONTEXT pDeviceContext,
  655. IN PIRP pIrp,
  656. IN NTSTATUS ntStatus
  657. );
  658. /*****************************************************************************
  659. * ForwardIrpSynchronous()
  660. *****************************************************************************
  661. * Forward a PnP IRP to the PDO. The IRP is not completed at this level,
  662. * this function does not return until the lower driver has completed the IRP,
  663. * and DecrementPendingIrpCount() is not called.
  664. */
  665. NTSTATUS
  666. ForwardIrpSynchronous
  667. (
  668. IN PDEVICE_CONTEXT pDeviceContext,
  669. IN PIRP pIrp
  670. );
  671. /*****************************************************************************
  672. * ForwardIrpAsynchronous()
  673. *****************************************************************************
  674. * Forward a PnP IRP to the PDO. The IRP is completed at this level
  675. * regardless of the outcome, this function returns immediately regardless of
  676. * whether the IRP is pending in the lower driver, and
  677. * DecrementPendingIrpCount() is called in all cases.
  678. */
  679. NTSTATUS
  680. ForwardIrpAsynchronous
  681. (
  682. IN PDEVICE_CONTEXT pDeviceContext,
  683. IN PIRP pIrp
  684. );
  685. /*****************************************************************************
  686. * PcRequestNewPowerState()
  687. *****************************************************************************
  688. * This routine is used to request a new power state for the device. It is
  689. * normally used internally by portcls but is also exported to adapters so
  690. * that the adapters can also request power state changes.
  691. */
  692. PORTCLASSAPI
  693. NTSTATUS
  694. NTAPI
  695. PcRequestNewPowerState
  696. (
  697. IN PDEVICE_OBJECT pDeviceObject,
  698. IN DEVICE_POWER_STATE RequestedNewState
  699. );
  700. /*****************************************************************************
  701. * RequestNewPowerState()
  702. *****************************************************************************
  703. * Called by the policy manager to
  704. * request a change in the power state of the
  705. * device.
  706. *
  707. */
  708. NTSTATUS
  709. RequestNewPowerState
  710. (
  711. IN PDEVICE_CONTEXT pDeviceContext,
  712. IN DEVICE_POWER_STATE RequestedNewState
  713. );
  714. /*****************************************************************************
  715. * DevicePowerRequestRoutine()
  716. *****************************************************************************
  717. * DPC used by the power routines to defer request for a device power
  718. * change.
  719. */
  720. VOID
  721. DevicePowerRequestRoutine(
  722. IN PKDPC Dpc,
  723. IN PVOID Context,
  724. IN PVOID SystemContext1,
  725. IN PVOID SystemContext2
  726. );
  727. /*****************************************************************************
  728. * PcDispatchProperty()
  729. *****************************************************************************
  730. * Dispatch a property via a PCPROPERTY_ITEM entry.
  731. */
  732. PORTCLASSAPI
  733. NTSTATUS
  734. NTAPI
  735. PcDispatchProperty
  736. (
  737. IN PIRP pIrp OPTIONAL,
  738. IN PPROPERTY_CONTEXT pPropertyContext,
  739. IN const KSPROPERTY_SET * pKsPropertySet OPTIONAL,
  740. IN ULONG ulIdentifierSize,
  741. IN PKSIDENTIFIER pKsIdentifier,
  742. IN OUT PULONG pulDataSize,
  743. IN OUT PVOID pvData OPTIONAL
  744. );
  745. /*****************************************************************************
  746. * PcValidateDeviceContext()
  747. *****************************************************************************
  748. * Probes DeviceContext for writing.
  749. */
  750. PORTCLASSAPI
  751. NTSTATUS
  752. NTAPI
  753. PcValidateDeviceContext
  754. (
  755. IN PDEVICE_CONTEXT pDeviceContext,
  756. IN PIRP pIrp
  757. );
  758. /*****************************************************************************
  759. * CompletePendedIrps
  760. *****************************************************************************
  761. * This pulls pended irps off the queue and passes them back to the appropriate
  762. * dispatcher via KsoDispatchIrp.
  763. */
  764. typedef enum {
  765. EMPTY_QUEUE_AND_PROCESS = 0,
  766. EMPTY_QUEUE_AND_FAIL
  767. } COMPLETE_STYLE;
  768. void
  769. CompletePendedIrps
  770. (
  771. IN PDEVICE_OBJECT pDeviceObject,
  772. IN PDEVICE_CONTEXT pDeviceContext,
  773. IN COMPLETE_STYLE CompleteStyle
  774. );
  775. typedef enum {
  776. QUEUED_CALLBACK_FREE = 0,
  777. QUEUED_CALLBACK_RETAIN,
  778. QUEUED_CALLBACK_REISSUE
  779. } QUEUED_CALLBACK_RETURN;
  780. typedef QUEUED_CALLBACK_RETURN (*PFNQUEUED_CALLBACK)(
  781. IN PDEVICE_OBJECT DeviceObject,
  782. IN PVOID Context
  783. );
  784. #define MAX_THREAD_REENTRANCY 20
  785. typedef struct {
  786. union {
  787. PIO_WORKITEM IoWorkItem;
  788. KDPC Dpc;
  789. }; // unnamed union
  790. PFNQUEUED_CALLBACK QueuedCallback;
  791. PDEVICE_OBJECT DeviceObject;
  792. PVOID Context;
  793. ULONG Flags;
  794. KIRQL Irql;
  795. LONG Enqueued;
  796. ULONG ReentrancyCount;
  797. } QUEUED_CALLBACK_ITEM, *PQUEUED_CALLBACK_ITEM;
  798. #define EQCM_SUPPORT_OR_FAIL_FLAGS 0xFFFF0000
  799. #define EQCM_SUPPORT_OR_IGNORE_FLAGS 0x0000FFFF
  800. #define EQCF_REUSE_HANDLE 0x00010000
  801. #define EQCF_DIFFERENT_THREAD_REQUIRED 0x00020000
  802. #define EQCM_SUPPORTED_FLAGS \
  803. ( EQCF_REUSE_HANDLE | EQCF_DIFFERENT_THREAD_REQUIRED)
  804. NTSTATUS
  805. CallbackEnqueue(
  806. IN PVOID *pCallbackHandle,
  807. IN PFNQUEUED_CALLBACK CallbackRoutine,
  808. IN PDEVICE_OBJECT DeviceObject,
  809. IN PVOID Context,
  810. IN KIRQL Irql,
  811. IN ULONG Flags
  812. );
  813. NTSTATUS
  814. CallbackCancel(
  815. IN PVOID pCallbackHandle
  816. );
  817. VOID
  818. CallbackFree(
  819. IN PVOID pCallbackHandle
  820. );
  821. typedef enum {
  822. IRPDISP_NOTREADY = 1,
  823. IRPDISP_QUEUE,
  824. IRPDISP_PROCESS
  825. } IRPDISP;
  826. IRPDISP
  827. GetIrpDisposition(
  828. IN PDEVICE_OBJECT DeviceObject,
  829. IN UCHAR MinorFunction
  830. );
  831. typedef enum {
  832. STOPSTYLE_PAUSE_FOR_REBALANCE,
  833. STOPSTYLE_DISABLE
  834. } PNPSTOP_STYLE;
  835. NTSTATUS
  836. PnpStopDevice
  837. (
  838. IN PDEVICE_OBJECT pDeviceObject,
  839. IN PNPSTOP_STYLE StopStyle
  840. );
  841. #endif