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.

198 lines
4.3 KiB

  1. /*++
  2. Copyright (c) 1996-2000 Microsoft Corporation
  3. Module Name:
  4. dispatch.c
  5. Abstract:
  6. This module contains dispatch code for PCI.SYS.
  7. Author:
  8. Ken Reneris (kenr) 4-Dec-1997
  9. Revision History:
  10. --*/
  11. #include "pcip.h"
  12. #ifdef ALLOC_PRAGMA
  13. #pragma alloc_text(PAGE, PciLocalDeviceUsage)
  14. #pragma alloc_text(PAGE, PciPdoDeviceUsage)
  15. #endif
  16. NTSTATUS
  17. PciLocalDeviceUsage (
  18. IN PPCI_POWER_STATE PowerState,
  19. IN PIRP Irp
  20. )
  21. {
  22. PIO_STACK_LOCATION irpSp;
  23. PLONG Addend;
  24. LONG Increment;
  25. LONG Junk;
  26. PAGED_CODE();
  27. irpSp = IoGetCurrentIrpStackLocation(Irp);
  28. Increment = irpSp->Parameters.UsageNotification.InPath ? 1 : -1;
  29. switch (irpSp->Parameters.UsageNotification.Type) {
  30. case DeviceUsageTypePaging: Addend = &PowerState->Paging; break;
  31. case DeviceUsageTypeHibernation: Addend = &PowerState->Hibernate; break;
  32. case DeviceUsageTypeDumpFile: Addend = &PowerState->CrashDump; break;
  33. default:
  34. return STATUS_NOT_SUPPORTED;
  35. }
  36. Junk = InterlockedExchangeAdd (Addend, Increment);
  37. #if DBG
  38. if (Increment == -1) {
  39. PCI_ASSERT(Junk > 0);
  40. }
  41. #endif
  42. return STATUS_SUCCESS;
  43. }
  44. NTSTATUS
  45. PciPdoDeviceUsage (
  46. IN PPCI_PDO_EXTENSION pdoExtension,
  47. IN PIRP Irp
  48. )
  49. {
  50. PDEVICE_OBJECT ParentFdo;
  51. PIO_STACK_LOCATION IrpSp;
  52. PIO_STACK_LOCATION NewIrpSp;
  53. PIRP NewIrp;
  54. KEVENT Event;
  55. NTSTATUS Status = STATUS_SUCCESS;
  56. IO_STATUS_BLOCK LocalIoStatus;
  57. PAGED_CODE();
  58. //
  59. // Do we have a parent that we must notify?
  60. //
  61. if (pdoExtension->ParentFdoExtension != NULL &&
  62. pdoExtension->ParentFdoExtension->PhysicalDeviceObject != NULL) {
  63. //
  64. // Get a referenced object to the parent
  65. //
  66. ParentFdo = IoGetAttachedDeviceReference(
  67. pdoExtension->ParentFdoExtension->PhysicalDeviceObject
  68. );
  69. if (ParentFdo == NULL) {
  70. Status = STATUS_NO_SUCH_DEVICE;
  71. goto PciPdoDeviceUsageExit;
  72. }
  73. //
  74. // Initialize the event to wait on
  75. //
  76. KeInitializeEvent( &Event, SynchronizationEvent, FALSE );
  77. //
  78. // Build an Irp
  79. //
  80. NewIrp = IoBuildSynchronousFsdRequest(
  81. IRP_MJ_PNP,
  82. ParentFdo,
  83. NULL,
  84. 0,
  85. NULL,
  86. &Event,
  87. &LocalIoStatus
  88. );
  89. if (NewIrp == NULL) {
  90. Status = STATUS_INSUFFICIENT_RESOURCES;
  91. ObDereferenceObject( ParentFdo );
  92. goto PciPdoDeviceUsageExit;
  93. }
  94. //
  95. // Get the top of the stacks
  96. //
  97. NewIrpSp = IoGetNextIrpStackLocation( NewIrp );
  98. IrpSp = IoGetCurrentIrpStackLocation(Irp);
  99. //
  100. // Set the top of stack
  101. //
  102. *NewIrpSp = *IrpSp;
  103. //
  104. // Clear any completion routines from the new stack
  105. //
  106. IoSetCompletionRoutine(
  107. NewIrp,
  108. NULL,
  109. NULL,
  110. FALSE,
  111. FALSE,
  112. FALSE
  113. );
  114. NewIrp->IoStatus.Status = STATUS_NOT_SUPPORTED;
  115. //
  116. // Send the request down
  117. //
  118. Status = IoCallDriver( ParentFdo, NewIrp );
  119. if (Status == STATUS_PENDING) {
  120. //
  121. // Wait for the request to be done
  122. //
  123. KeWaitForSingleObject(
  124. &Event,
  125. Executive,
  126. KernelMode,
  127. FALSE,
  128. NULL
  129. );
  130. Status = LocalIoStatus.Status;
  131. }
  132. //
  133. // Deference the target
  134. //
  135. ObDereferenceObject( ParentFdo );
  136. }
  137. PciPdoDeviceUsageExit:
  138. //
  139. // If we succeeded, then apply the usages locally
  140. //
  141. if (NT_SUCCESS(Status)) {
  142. //
  143. // Apply the usage locally
  144. //
  145. Status = PciLocalDeviceUsage(&pdoExtension->PowerState, Irp);
  146. }
  147. //
  148. // Done
  149. //
  150. return Status;
  151. }