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.

251 lines
5.0 KiB

  1. /*++
  2. Copyright (c) 2000-2001 Microsoft Corporation
  3. Module Name:
  4. acpisim.c
  5. Abstract:
  6. ACPI BIOS Simulator / Generic 3rd Party Operation Region Provider
  7. IO Device Control Handler module
  8. Author(s):
  9. Vincent Geglia
  10. Michael T. Murphy
  11. Chris Burgess
  12. Environment:
  13. Kernel mode
  14. Notes:
  15. Revision History:
  16. --*/
  17. //
  18. // General includes
  19. //
  20. #include "oprghdlr.h"
  21. #include "acpiioct.h"
  22. //
  23. // Specific includes
  24. //
  25. #include "asimlib.h"
  26. #include "acpisim.h"
  27. //
  28. // Globals
  29. //
  30. PVOID g_OpRegionSharedMemory = 0;
  31. PVOID g_OperationRegionObject = 0;
  32. //
  33. // Private function prototypes
  34. //
  35. NTSTATUS
  36. EXPORT
  37. AcpisimOpRegionHandler (
  38. ULONG AccessType,
  39. PVOID OperationRegionObject,
  40. ULONG Address,
  41. ULONG Size,
  42. PULONG Data,
  43. ULONG_PTR Context,
  44. PACPI_OP_REGION_CALLBACK CompletionHandler,
  45. PVOID CompletionContext
  46. );
  47. //
  48. // Code
  49. //
  50. NTSTATUS
  51. AcpisimRegisterOpRegionHandler
  52. (
  53. IN PDEVICE_OBJECT DeviceObject
  54. )
  55. /*++
  56. Routine Description:
  57. This routine is called to register our operation region
  58. handler.
  59. Arguments:
  60. DeviceObject - pointer to the device object the IRP pertains to
  61. Return Value:
  62. STATUS_SUCCESS, if successful
  63. --*/
  64. {
  65. NTSTATUS status = STATUS_UNSUCCESSFUL;
  66. g_OpRegionSharedMemory = ExAllocatePoolWithTag (NonPagedPool,
  67. OPREGION_SIZE,
  68. ACPISIM_POOL_TAG);
  69. status = RegisterOpRegionHandler (AcpisimLibGetNextDevice (DeviceObject),
  70. ACPI_OPREGION_ACCESS_AS_COOKED,
  71. ACPISIM_OPREGION_TYPE,
  72. (PACPI_OP_REGION_HANDLER) AcpisimOpRegionHandler,
  73. (PVOID) ACPISIM_TAG,
  74. 0,
  75. &g_OperationRegionObject);
  76. return status;
  77. }
  78. NTSTATUS
  79. AcpisimUnRegisterOpRegionHandler
  80. (
  81. IN PDEVICE_OBJECT DeviceObject
  82. )
  83. /*++
  84. Routine Description:
  85. This routine is called to unregister our operation region
  86. handler.
  87. Arguments:
  88. DeviceObject - pointer to the device object the IRP pertains to
  89. Return Value:
  90. STATUS_SUCCESS, if successful
  91. --*/
  92. {
  93. NTSTATUS status = STATUS_UNSUCCESSFUL;
  94. status = DeRegisterOpRegionHandler (AcpisimLibGetNextDevice (DeviceObject),
  95. g_OperationRegionObject);
  96. ExFreePool (g_OpRegionSharedMemory);
  97. return status;
  98. }
  99. NTSTATUS
  100. EXPORT
  101. AcpisimOpRegionHandler (
  102. ULONG AccessType,
  103. PVOID OperationRegionObject,
  104. ULONG Address,
  105. ULONG Size,
  106. PULONG Data,
  107. ULONG_PTR Context,
  108. PACPI_OP_REGION_CALLBACK CompletionHandler,
  109. PVOID CompletionContext
  110. )
  111. /*++
  112. Routine Description:
  113. This routine is called when ASL touches the op region.
  114. Arguments:
  115. AccessType - Indicates whether it is a read or write.
  116. OperationRegionObject - A pointer to our op region
  117. Address - Offset into the op region for which the access occurred
  118. Size - Number of bytes of the access
  119. Data - Data being written, or location to store data being read
  120. Context - A user definable context (in this case, device extension)
  121. CompletionHandler - internal, not used
  122. CompletionContext - internal, not used
  123. Return Value:
  124. STATUS_SUCCESS, if successful
  125. --*/
  126. {
  127. NTSTATUS status = STATUS_UNSUCCESSFUL;
  128. ASSERT (AccessType == ACPI_OPREGION_WRITE || AccessType == ACPI_OPREGION_READ);
  129. //
  130. // Insert additional handler code here
  131. //
  132. switch (AccessType) {
  133. case ACPI_OPREGION_WRITE:
  134. RtlCopyMemory ((PVOID) ((ULONG_PTR) g_OpRegionSharedMemory + Address), Data, Size);
  135. status = STATUS_SUCCESS;
  136. break;
  137. case ACPI_OPREGION_READ:
  138. RtlCopyMemory (Data, (PVOID) ((ULONG_PTR) g_OpRegionSharedMemory + Address), Size);
  139. status = STATUS_SUCCESS;
  140. break;
  141. default:
  142. DBG_PRINT (DBG_ERROR,
  143. "Unknown Opregion access type. Ignoring.\n");
  144. status = STATUS_INVALID_DEVICE_REQUEST;
  145. break;
  146. }
  147. return status;
  148. }
  149. NTSTATUS AcpisimHandleIoctl
  150. (
  151. IN PDEVICE_OBJECT DeviceObject,
  152. IN PIRP Irp
  153. )
  154. /*++
  155. Routine Description:
  156. This is the handler for IOCTL requests. This is the "meat" of
  157. the driver so to speak. All of the op-region accesses from user
  158. mode are handled here.
  159. The implementer should perform the action and return an appropriate
  160. status, or return STATUS_UNSUPPORTED if the IOCTL is unrecognized.
  161. Arguments:
  162. DeviceObject - pointer to the device object the IRP pertains to
  163. Irp - pointer to the IRP
  164. Return Value:
  165. result of IRP processing
  166. --*/
  167. {
  168. return STATUS_NOT_SUPPORTED;
  169. }