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

205 lines
4.0 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. ospower.c
  5. Abstract:
  6. This module abstracts the power information structures to each of the
  7. OSes
  8. Author:
  9. Stephane Plante (splante)
  10. Environment:
  11. NT Kernel Model Driver only
  12. --*/
  13. #include "pch.h"
  14. PACPI_POWER_INFO
  15. OSPowerFindPowerInfo(
  16. PNSOBJ AcpiObject
  17. )
  18. /*++
  19. Routine Description:
  20. Return the Power Information (which contains the device state and the
  21. device dependencies)
  22. Arguments:
  23. AcpiObject - The NameSpace object that we want to know about
  24. Return Value:
  25. PACPI_POWER_INFO
  26. --*/
  27. {
  28. KIRQL oldIrql;
  29. PDEVICE_EXTENSION deviceExtension;
  30. ASSERT( AcpiObject != NULL);
  31. //
  32. // Grab the spinlock
  33. //
  34. KeAcquireSpinLock( &AcpiDeviceTreeLock, &oldIrql );
  35. //
  36. // Check for the case that there is no device object associated with
  37. // this AcpiObject - can happen if there is no HID associated with
  38. // the device in the AML.
  39. //
  40. deviceExtension = AcpiObject->Context;
  41. if (deviceExtension) {
  42. ASSERT( deviceExtension->Signature == ACPI_SIGNATURE );
  43. KeReleaseSpinLock( &AcpiDeviceTreeLock, oldIrql );
  44. return &(deviceExtension->PowerInfo);
  45. }
  46. //
  47. // Done with the spinlock
  48. //
  49. KeReleaseSpinLock( &AcpiDeviceTreeLock, oldIrql );
  50. return NULL;
  51. }
  52. PACPI_POWER_INFO
  53. OSPowerFindPowerInfoByContext(
  54. PVOID Context
  55. )
  56. /*++
  57. Routine Description:
  58. Return the Power Information (which contains the device state and the
  59. device dependencies)
  60. The difference between this function and the previous is that it searches
  61. the list based on the context pointer. On NT, this is a NOP since the
  62. context pointer is actually an NT device object, and we store the structure
  63. within the device extension. But this isn't the same for Win9x <sigh>
  64. Arguments:
  65. Context - Actually is a DeviceObject
  66. Return Value:
  67. PACPI_POWER_INFO
  68. --*/
  69. {
  70. PDEVICE_OBJECT deviceObject = (PDEVICE_OBJECT) Context;
  71. PDEVICE_EXTENSION deviceExtension = (PDEVICE_EXTENSION) Context;
  72. ASSERT( Context != NULL );
  73. //
  74. // Get the real extension
  75. //
  76. deviceExtension = ACPIInternalGetDeviceExtension( deviceObject );
  77. ASSERT( deviceExtension->Signature == ACPI_SIGNATURE );
  78. //
  79. // We store the Power info in the device extension
  80. //
  81. return &(deviceExtension->PowerInfo);
  82. }
  83. PACPI_POWER_DEVICE_NODE
  84. OSPowerFindPowerNode(
  85. PNSOBJ PowerObject
  86. )
  87. /*++
  88. Routine Description:
  89. Return the Power Device Node (which contains the current state of the
  90. power resource, the power resource, and the use counts)
  91. Arguments:
  92. PowerObject - The NameSpace object that we want to know about
  93. Return Value:
  94. PACPI_POWER_DEVICE_NODE
  95. --*/
  96. {
  97. KIRQL oldIrql;
  98. PACPI_POWER_DEVICE_NODE powerNode = NULL;
  99. //
  100. // Before we touch the power list, we need to have a spinlock
  101. //
  102. KeAcquireSpinLock( &AcpiPowerLock, &oldIrql );
  103. //
  104. // Boundary check
  105. //
  106. if (AcpiPowerNodeList.Flink == &AcpiPowerNodeList) {
  107. //
  108. // At end
  109. //
  110. goto OSPowerFindPowerNodeExit;
  111. }
  112. //
  113. // Start from the first node and check to see if they match the
  114. // required NameSpace object
  115. //
  116. powerNode = (PACPI_POWER_DEVICE_NODE) AcpiPowerNodeList.Flink;
  117. while (powerNode != (PACPI_POWER_DEVICE_NODE) &AcpiPowerNodeList) {
  118. //
  119. // Check to see if the node that we are looking at matches the
  120. // name space object in question
  121. //
  122. if (powerNode->PowerObject == PowerObject) {
  123. //
  124. // Match
  125. //
  126. goto OSPowerFindPowerNodeExit;
  127. }
  128. //
  129. // Next object
  130. //
  131. powerNode = (PACPI_POWER_DEVICE_NODE) powerNode->ListEntry.Flink;
  132. }
  133. //
  134. // No match
  135. //
  136. powerNode = NULL;
  137. OSPowerFindPowerNodeExit:
  138. //
  139. // No longer need the spin lock
  140. //
  141. KeReleaseSpinLock( &AcpiPowerLock, oldIrql );
  142. //
  143. // Return the node we found
  144. //
  145. return powerNode;
  146. }