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 *******************************************************************/
16 /* FUNCTIONS ******************************************************************/
20 GetDwordElement(IN PACPI_METHOD_ARGUMENT Argument
,
25 /* Must have an integer */
26 if (Argument
->Type
!= ACPI_METHOD_ARGUMENT_INTEGER
)
28 /* Not an integer, fail */
29 Status
= STATUS_ACPI_INVALID_DATA
;
30 if (CmBattDebug
& 0x4C)
31 DbgPrint("GetDwordElement: Object contained wrong data type - %d\n",
36 /* Read the integer value */
37 *Value
= Argument
->Argument
;
38 Status
= STATUS_SUCCESS
;
47 GetStringElement(IN PACPI_METHOD_ARGUMENT Argument
,
52 /* Must have a string of buffer */
53 if ((Argument
->Type
== ACPI_METHOD_ARGUMENT_STRING
) ||
54 (Argument
->Type
== ACPI_METHOD_ARGUMENT_BUFFER
))
56 /* String must be less than 256 characters */
57 if (Argument
->DataLength
< 256)
60 RtlCopyMemory(Value
, Argument
->Data
, Argument
->DataLength
);
61 Status
= STATUS_SUCCESS
;
65 /* The buffer is too small (the string is too large) */
66 Status
= STATUS_BUFFER_TOO_SMALL
;
67 if (CmBattDebug
& 0x4C)
68 DbgPrint("GetStringElement: return buffer not big enough - %d\n", Argument
->DataLength
);
73 /* Not valid string data */
74 Status
= STATUS_ACPI_INVALID_DATA
;
75 if (CmBattDebug
& 0x4C)
76 DbgPrint("GetStringElement: Object contained wrong data type - %d\n", Argument
->Type
);
79 /* Return the status */
85 CmBattSendDownStreamIrp(IN PDEVICE_OBJECT DeviceObject
,
86 IN ULONG IoControlCode
,
88 IN ULONG InputBufferLength
,
89 IN PACPI_EVAL_OUTPUT_BUFFER OutputBuffer
,
90 IN ULONG OutputBufferLength
)
95 IO_STATUS_BLOCK IoStatusBlock
;
98 /* Initialize our wait event */
99 KeInitializeEvent(&Event
, SynchronizationEvent
, 0);
101 /* Allocate the IRP */
102 Irp
= IoBuildDeviceIoControlRequest(IoControlCode
,
114 if (CmBattDebug
& 0x4C)
115 DbgPrint("CmBattSendDownStreamIrp: Failed to allocate Irp\n");
116 return STATUS_INSUFFICIENT_RESOURCES
;
120 if (CmBattDebug
& 0x40)
121 DbgPrint("CmBattSendDownStreamIrp: Irp %x [Tid] %x\n",
122 Irp
, KeGetCurrentThread());
123 Status
= IoCallDriver(DeviceObject
, Irp
);
124 if (Status
== STATUS_PENDING
)
126 /* Wait for completion */
127 KeWaitForSingleObject(&Event
,
132 Status
= Irp
->IoStatus
.Status
;
135 /* Check if caller wanted output */
138 /* Make sure it's valid ACPI output buffer */
139 if ((OutputBuffer
->Signature
!= ACPI_EVAL_OUTPUT_BUFFER_SIGNATURE
) ||
140 !(OutputBuffer
->Count
))
142 /* It isn't, so set failure code */
143 Status
= STATUS_ACPI_INVALID_DATA
;
148 if (CmBattDebug
& 0x40)
149 DbgPrint("CmBattSendDownStreamIrp: Irp %x completed %x! [Tid] %x\n",
150 Irp
, Status
, KeGetCurrentThread());
156 CmBattGetPsrData(IN PDEVICE_OBJECT DeviceObject
,
160 ACPI_EVAL_OUTPUT_BUFFER OutputBuffer
;
161 ACPI_EVAL_INPUT_BUFFER InputBuffer
;
163 if (CmBattDebug
& 0x40)
164 DbgPrint("CmBattGetPsrData: Entered with Pdo %x Tid %x\n",
165 DeviceObject
, KeGetCurrentThread());
167 /* Initialize to zero */
168 ASSERT(PsrData
!= NULL
);
171 /* Request the _PSR method */
172 *(PULONG
)InputBuffer
.MethodName
= 'RSP_';
173 InputBuffer
.Signature
= ACPI_EVAL_INPUT_BUFFER_SIGNATURE
;
175 /* Send it to ACPI */
176 Status
= CmBattSendDownStreamIrp(DeviceObject
,
177 IOCTL_ACPI_EVAL_METHOD
,
181 sizeof(OutputBuffer
));
182 if (NT_SUCCESS(Status
))
184 /* Read the result */
185 Status
= GetDwordElement(OutputBuffer
.Argument
, PsrData
);
186 if (CmBattDebug
& 0x440)
187 DbgPrint("CmBattGetPsrData: _PSR method returned %x \n", *PsrData
);
189 else if (CmBattDebug
& 0x44C)
192 DbgPrint("CmBattGetPsrData: Failed _PSR method - Status (0x%x)\n", Status
);
201 CmBattGetStaData(IN PDEVICE_OBJECT DeviceObject
,
205 ACPI_EVAL_OUTPUT_BUFFER OutputBuffer
;
206 ACPI_EVAL_INPUT_BUFFER InputBuffer
;
208 if (CmBattDebug
& 0x40)
209 DbgPrint("CmBattGetStaData: Entered with Pdo %x Tid %x\n",
210 DeviceObject
, KeGetCurrentThread());
212 /* Initialize to zero */
213 ASSERT(StaData
!= NULL
);
216 /* Request the _PSR method */
217 *(PULONG
)InputBuffer
.MethodName
= 'ATS_';
218 InputBuffer
.Signature
= ACPI_EVAL_INPUT_BUFFER_SIGNATURE
;
220 /* Send it to ACPI */
221 Status
= CmBattSendDownStreamIrp(DeviceObject
,
222 IOCTL_ACPI_EVAL_METHOD
,
226 sizeof(OutputBuffer
));
227 if (NT_SUCCESS(Status
))
229 /* Read the result */
230 Status
= GetDwordElement(OutputBuffer
.Argument
, StaData
);
231 if (CmBattDebug
& 0x440)
232 DbgPrint("CmBattGetStaData: _STA method returned %x \n", *StaData
);
234 else if (CmBattDebug
& 0x44C)
237 DbgPrint("CmBattGetStaData: Failed _STA method - Status (0x%x)\n", Status
);
238 Status
= STATUS_NO_SUCH_DEVICE
;
247 CmBattGetUniqueId(IN PDEVICE_OBJECT DeviceObject
,
251 ACPI_EVAL_OUTPUT_BUFFER OutputBuffer
;
252 ACPI_EVAL_INPUT_BUFFER InputBuffer
;
254 if (CmBattDebug
& 0x40)
255 DbgPrint("CmBattGetUniqueId: Entered with Pdo %x Tid %x\n",
256 DeviceObject
, KeGetCurrentThread());
258 /* Initialize to zero */
259 ASSERT(UniqueId
!= NULL
);
262 /* Request the _PSR method */
263 *(PULONG
)InputBuffer
.MethodName
= 'DIU_';
264 InputBuffer
.Signature
= ACPI_EVAL_INPUT_BUFFER_SIGNATURE
;
266 /* Send it to ACPI */
267 Status
= CmBattSendDownStreamIrp(DeviceObject
,
268 IOCTL_ACPI_EVAL_METHOD
,
272 sizeof(OutputBuffer
));
273 if (NT_SUCCESS(Status
))
275 /* Read the result */
276 Status
= GetDwordElement(OutputBuffer
.Argument
, UniqueId
);
277 if (CmBattDebug
& 0x440)
278 DbgPrint("CmBattGetUniqueId: _UID method returned %x \n", *UniqueId
);
280 else if (CmBattDebug
& 0x44C)
283 DbgPrint("CmBattGetUniqueId: Failed _UID method - Status (0x%x)\n", Status
);
284 Status
= STATUS_NO_SUCH_DEVICE
;
293 CmBattSetTripPpoint(IN PCMBATT_DEVICE_EXTENSION DeviceExtension
,
297 ACPI_EVAL_INPUT_BUFFER_SIMPLE_INTEGER InputBuffer
;
299 if (CmBattDebug
& 0x440)
300 DbgPrint("CmBattSetTripPpoint: _BTP Alarm Value %x Device %x Tid %x\n",
301 AlarmValue
, DeviceExtension
->DeviceId
, KeGetCurrentThread
);
303 /* Request the _BTP method */
304 *(PULONG
)InputBuffer
.MethodName
= 'PTB_';
305 InputBuffer
.Signature
= ACPI_EVAL_INPUT_BUFFER_SIMPLE_INTEGER_SIGNATURE
;
306 InputBuffer
.IntegerArgument
= AlarmValue
;
308 /* Send it to ACPI */
309 Status
= CmBattSendDownStreamIrp(DeviceExtension
->AttachedDevice
,
310 IOCTL_ACPI_EVAL_METHOD
,
315 if (!(NT_SUCCESS(Status
)) && (CmBattDebug
& 0x440))
316 DbgPrint("CmBattSetTripPpoint: Failed _BTP method on device %x - Status (0x%x)\n",
317 DeviceExtension
->DeviceId
, Status
);
325 CmBattGetBifData(PCMBATT_DEVICE_EXTENSION DeviceExtension
,
326 PACPI_BIF_DATA BifData
)
329 return STATUS_NOT_IMPLEMENTED
;
334 CmBattGetBstData(PCMBATT_DEVICE_EXTENSION DeviceExtension
,
335 PACPI_BST_DATA BstData
)
338 return STATUS_NOT_IMPLEMENTED
;