2 * PROJECT: ReactOS ACPI-Compliant Control Method Battery
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: boot/drivers/bus/acpi/cmbatt/cmexec.c
5 * PURPOSE: ACPI Method Execution/Evaluation Glue
6 * PROGRAMMERS: ReactOS Portable Systems Group
9 /* INCLUDES *******************************************************************/
13 /* FUNCTIONS ******************************************************************/
17 GetDwordElement(IN PACPI_METHOD_ARGUMENT Argument
,
22 /* Must have an integer */
23 if (Argument
->Type
!= ACPI_METHOD_ARGUMENT_INTEGER
)
25 /* Not an integer, fail */
26 Status
= STATUS_ACPI_INVALID_DATA
;
27 if (CmBattDebug
& 0x4C)
28 DbgPrint("GetDwordElement: Object contained wrong data type - %d\n",
33 /* Read the integer value */
34 *Value
= Argument
->Argument
;
35 Status
= STATUS_SUCCESS
;
44 GetStringElement(IN PACPI_METHOD_ARGUMENT Argument
,
49 /* Must have a string of buffer */
50 if ((Argument
->Type
== ACPI_METHOD_ARGUMENT_STRING
) ||
51 (Argument
->Type
== ACPI_METHOD_ARGUMENT_BUFFER
))
53 /* String must be less than 256 characters */
54 if (Argument
->DataLength
< 256)
57 RtlCopyMemory(Value
, Argument
->Data
, Argument
->DataLength
);
58 Status
= STATUS_SUCCESS
;
62 /* The buffer is too small (the string is too large) */
63 Status
= STATUS_BUFFER_TOO_SMALL
;
64 if (CmBattDebug
& 0x4C)
65 DbgPrint("GetStringElement: return buffer not big enough - %d\n", Argument
->DataLength
);
70 /* Not valid string data */
71 Status
= STATUS_ACPI_INVALID_DATA
;
72 if (CmBattDebug
& 0x4C)
73 DbgPrint("GetStringElement: Object contained wrong data type - %d\n", Argument
->Type
);
76 /* Return the status */
82 CmBattSendDownStreamIrp(IN PDEVICE_OBJECT DeviceObject
,
83 IN ULONG IoControlCode
,
85 IN ULONG InputBufferLength
,
86 IN PACPI_EVAL_OUTPUT_BUFFER OutputBuffer
,
87 IN ULONG OutputBufferLength
)
92 IO_STATUS_BLOCK IoStatusBlock
;
95 /* Initialize our wait event */
96 KeInitializeEvent(&Event
, SynchronizationEvent
, 0);
98 /* Allocate the IRP */
99 Irp
= IoBuildDeviceIoControlRequest(IoControlCode
,
111 if (CmBattDebug
& 0x4C)
112 DbgPrint("CmBattSendDownStreamIrp: Failed to allocate Irp\n");
113 return STATUS_INSUFFICIENT_RESOURCES
;
117 if (CmBattDebug
& 0x40)
118 DbgPrint("CmBattSendDownStreamIrp: Irp %x [Tid] %x\n",
119 Irp
, KeGetCurrentThread());
120 Status
= IoCallDriver(DeviceObject
, Irp
);
121 if (Status
== STATUS_PENDING
)
123 /* Wait for completion */
124 KeWaitForSingleObject(&Event
,
129 Status
= Irp
->IoStatus
.Status
;
132 /* Check if caller wanted output */
135 /* Make sure it's valid ACPI output buffer */
136 if ((OutputBuffer
->Signature
!= ACPI_EVAL_OUTPUT_BUFFER_SIGNATURE
) ||
137 !(OutputBuffer
->Count
))
139 /* It isn't, so set failure code */
140 Status
= STATUS_ACPI_INVALID_DATA
;
145 if (CmBattDebug
& 0x40)
146 DbgPrint("CmBattSendDownStreamIrp: Irp %x completed %x! [Tid] %x\n",
147 Irp
, Status
, KeGetCurrentThread());
153 CmBattGetPsrData(IN PDEVICE_OBJECT DeviceObject
,
157 ACPI_EVAL_OUTPUT_BUFFER OutputBuffer
;
158 ACPI_EVAL_INPUT_BUFFER InputBuffer
;
160 if (CmBattDebug
& 0x40)
161 DbgPrint("CmBattGetPsrData: Entered with Pdo %x Tid %x\n",
162 DeviceObject
, KeGetCurrentThread());
164 /* Initialize to zero */
165 ASSERT(PsrData
!= NULL
);
168 /* Request the _PSR method */
169 *(PULONG
)InputBuffer
.MethodName
= 'RSP_';
170 InputBuffer
.Signature
= ACPI_EVAL_INPUT_BUFFER_SIGNATURE
;
172 /* Send it to ACPI */
173 Status
= CmBattSendDownStreamIrp(DeviceObject
,
174 IOCTL_ACPI_EVAL_METHOD
,
178 sizeof(OutputBuffer
));
179 if (NT_SUCCESS(Status
))
181 /* Read the result */
182 Status
= GetDwordElement(OutputBuffer
.Argument
, PsrData
);
183 if (CmBattDebug
& 0x440)
184 DbgPrint("CmBattGetPsrData: _PSR method returned %x \n", *PsrData
);
186 else if (CmBattDebug
& 0x44C)
189 DbgPrint("CmBattGetPsrData: Failed _PSR method - Status (0x%x)\n", Status
);
198 CmBattGetStaData(IN PDEVICE_OBJECT DeviceObject
,
202 ACPI_EVAL_OUTPUT_BUFFER OutputBuffer
;
203 ACPI_EVAL_INPUT_BUFFER InputBuffer
;
205 if (CmBattDebug
& 0x40)
206 DbgPrint("CmBattGetStaData: Entered with Pdo %x Tid %x\n",
207 DeviceObject
, KeGetCurrentThread());
209 /* Initialize to zero */
210 ASSERT(StaData
!= NULL
);
213 /* Request the _PSR method */
214 *(PULONG
)InputBuffer
.MethodName
= 'ATS_';
215 InputBuffer
.Signature
= ACPI_EVAL_INPUT_BUFFER_SIGNATURE
;
217 /* Send it to ACPI */
218 Status
= CmBattSendDownStreamIrp(DeviceObject
,
219 IOCTL_ACPI_EVAL_METHOD
,
223 sizeof(OutputBuffer
));
224 if (NT_SUCCESS(Status
))
226 /* Read the result */
227 Status
= GetDwordElement(OutputBuffer
.Argument
, StaData
);
228 if (CmBattDebug
& 0x440)
229 DbgPrint("CmBattGetStaData: _STA method returned %x \n", *StaData
);
231 else if (CmBattDebug
& 0x44C)
234 DbgPrint("CmBattGetStaData: Failed _STA method - Status (0x%x)\n", Status
);
235 Status
= STATUS_NO_SUCH_DEVICE
;
244 CmBattGetUniqueId(IN PDEVICE_OBJECT DeviceObject
,
248 ACPI_EVAL_OUTPUT_BUFFER OutputBuffer
;
249 ACPI_EVAL_INPUT_BUFFER InputBuffer
;
251 if (CmBattDebug
& 0x40)
252 DbgPrint("CmBattGetUniqueId: Entered with Pdo %x Tid %x\n",
253 DeviceObject
, KeGetCurrentThread());
255 /* Initialize to zero */
256 ASSERT(UniqueId
!= NULL
);
259 /* Request the _PSR method */
260 *(PULONG
)InputBuffer
.MethodName
= 'DIU_';
261 InputBuffer
.Signature
= ACPI_EVAL_INPUT_BUFFER_SIGNATURE
;
263 /* Send it to ACPI */
264 Status
= CmBattSendDownStreamIrp(DeviceObject
,
265 IOCTL_ACPI_EVAL_METHOD
,
269 sizeof(OutputBuffer
));
270 if (NT_SUCCESS(Status
))
272 /* Read the result */
273 Status
= GetDwordElement(OutputBuffer
.Argument
, UniqueId
);
274 if (CmBattDebug
& 0x440)
275 DbgPrint("CmBattGetUniqueId: _UID method returned %x \n", *UniqueId
);
277 else if (CmBattDebug
& 0x44C)
280 DbgPrint("CmBattGetUniqueId: Failed _UID method - Status (0x%x)\n", Status
);
281 Status
= STATUS_NO_SUCH_DEVICE
;
290 CmBattSetTripPpoint(IN PCMBATT_DEVICE_EXTENSION DeviceExtension
,
294 ACPI_EVAL_INPUT_BUFFER_SIMPLE_INTEGER InputBuffer
;
296 if (CmBattDebug
& 0x440)
297 DbgPrint("CmBattSetTripPpoint: _BTP Alarm Value %x Device %x Tid %x\n",
298 AlarmValue
, DeviceExtension
->DeviceId
, KeGetCurrentThread
);
300 /* Request the _BTP method */
301 *(PULONG
)InputBuffer
.MethodName
= 'PTB_';
302 InputBuffer
.Signature
= ACPI_EVAL_INPUT_BUFFER_SIMPLE_INTEGER_SIGNATURE
;
303 InputBuffer
.IntegerArgument
= AlarmValue
;
305 /* Send it to ACPI */
306 Status
= CmBattSendDownStreamIrp(DeviceExtension
->AttachedDevice
,
307 IOCTL_ACPI_EVAL_METHOD
,
312 if (!(NT_SUCCESS(Status
)) && (CmBattDebug
& 0x440))
313 DbgPrint("CmBattSetTripPpoint: Failed _BTP method on device %x - Status (0x%x)\n",
314 DeviceExtension
->DeviceId
, Status
);
322 CmBattGetBifData(PCMBATT_DEVICE_EXTENSION DeviceExtension
,
323 PACPI_BIF_DATA BifData
)
326 return STATUS_NOT_IMPLEMENTED
;
331 CmBattGetBstData(PCMBATT_DEVICE_EXTENSION DeviceExtension
,
332 PACPI_BST_DATA BstData
)
335 return STATUS_NOT_IMPLEMENTED
;