ReactOS 0.4.15-dev-8138-g1e75ea8
cmexec.c
Go to the documentation of this file.
1/*
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
7 */
8
9/* INCLUDES *******************************************************************/
10
11#include "cmbatt.h"
12
13#include <acpiioct.h>
14#include <debug.h>
15
16/* FUNCTIONS ******************************************************************/
17
22{
24
25 /* Must have an integer */
26 if (Argument->Type != ACPI_METHOD_ARGUMENT_INTEGER)
27 {
28 /* Not an integer, fail */
30 if (CmBattDebug & 0x4C)
31 DbgPrint("GetDwordElement: Object contained wrong data type - %d\n",
32 Argument->Type);
33 }
34 else
35 {
36 /* Read the integer value */
37 *Value = Argument->Argument;
39 }
40
41 /* Return status */
42 return Status;
43}
44
49{
51
52 /* Must have a string of buffer */
53 if ((Argument->Type == ACPI_METHOD_ARGUMENT_STRING) ||
54 (Argument->Type == ACPI_METHOD_ARGUMENT_BUFFER))
55 {
56 /* String must be less than 256 characters */
57 if (Argument->DataLength < 256)
58 {
59 /* Copy the buffer */
60 RtlCopyMemory(Value, Argument->Data, Argument->DataLength);
62 }
63 else
64 {
65 /* The buffer is too small (the string is too large) */
67 if (CmBattDebug & 0x4C)
68 DbgPrint("GetStringElement: return buffer not big enough - %d\n", Argument->DataLength);
69 }
70 }
71 else
72 {
73 /* Not valid string data */
75 if (CmBattDebug & 0x4C)
76 DbgPrint("GetStringElement: Object contained wrong data type - %d\n", Argument->Type);
77 }
78
79 /* Return the status */
80 return Status;
81}
82
91{
92 PIRP Irp;
96 PAGED_CODE();
97
98 /* Initialize our wait event */
100
101 /* Allocate the IRP */
108 0,
109 &Event,
111 if (!Irp)
112 {
113 /* No IRP, fail */
114 if (CmBattDebug & 0x4C)
115 DbgPrint("CmBattSendDownStreamIrp: Failed to allocate Irp\n");
117 }
118
119 /* Call ACPI */
120 if (CmBattDebug & 0x40)
121 DbgPrint("CmBattSendDownStreamIrp: Irp %x [Tid] %x\n",
124 if (Status == STATUS_PENDING)
125 {
126 /* Wait for completion */
128 Executive,
130 FALSE,
131 NULL);
132 Status = Irp->IoStatus.Status;
133 }
134
135 /* Check if caller wanted output */
136 if (OutputBuffer)
137 {
138 /* Make sure it's valid ACPI output buffer */
140 !(OutputBuffer->Count))
141 {
142 /* It isn't, so set failure code */
144 }
145 }
146
147 /* Return status */
148 if (CmBattDebug & 0x40)
149 DbgPrint("CmBattSendDownStreamIrp: Irp %x completed %x! [Tid] %x\n",
151 return Status;
152}
153
155NTAPI
157 OUT PULONG PsrData)
158{
162 PAGED_CODE();
163 if (CmBattDebug & 0x40)
164 DbgPrint("CmBattGetPsrData: Entered with Pdo %x Tid %x\n",
166
167 /* Initialize to zero */
168 ASSERT(PsrData != NULL);
169 *PsrData = 0;
170
171 /* Request the _PSR method */
172 *(PULONG)InputBuffer.MethodName = 'RSP_';
174
175 /* Send it to ACPI */
179 sizeof(InputBuffer),
181 sizeof(OutputBuffer));
182 if (NT_SUCCESS(Status))
183 {
184 /* Read the result */
185 Status = GetDwordElement(OutputBuffer.Argument, PsrData);
186 if (CmBattDebug & 0x440)
187 DbgPrint("CmBattGetPsrData: _PSR method returned %x \n", *PsrData);
188 }
189 else if (CmBattDebug & 0x44C)
190 {
191 /* Failure */
192 DbgPrint("CmBattGetPsrData: Failed _PSR method - Status (0x%x)\n", Status);
193 }
194
195 /* Return status */
196 return Status;
197}
198
200NTAPI
202 OUT PULONG StaData)
203{
207 PAGED_CODE();
208 if (CmBattDebug & 0x40)
209 DbgPrint("CmBattGetStaData: Entered with Pdo %x Tid %x\n",
211
212 /* Initialize to zero */
213 ASSERT(StaData != NULL);
214 *StaData = 0;
215
216 /* Request the _PSR method */
217 *(PULONG)InputBuffer.MethodName = 'ATS_';
219
220 /* Send it to ACPI */
224 sizeof(InputBuffer),
226 sizeof(OutputBuffer));
227 if (NT_SUCCESS(Status))
228 {
229 /* Read the result */
230 Status = GetDwordElement(OutputBuffer.Argument, StaData);
231 if (CmBattDebug & 0x440)
232 DbgPrint("CmBattGetStaData: _STA method returned %x \n", *StaData);
233 }
234 else if (CmBattDebug & 0x44C)
235 {
236 /* Failure */
237 DbgPrint("CmBattGetStaData: Failed _STA method - Status (0x%x)\n", Status);
239 }
240
241 /* Return status */
242 return Status;
243}
244
246NTAPI
248 OUT PULONG UniqueId)
249{
253 PAGED_CODE();
254 if (CmBattDebug & 0x40)
255 DbgPrint("CmBattGetUniqueId: Entered with Pdo %x Tid %x\n",
257
258 /* Initialize to zero */
259 ASSERT(UniqueId != NULL);
260 *UniqueId = 0;
261
262 /* Request the _PSR method */
263 *(PULONG)InputBuffer.MethodName = 'DIU_';
265
266 /* Send it to ACPI */
270 sizeof(InputBuffer),
272 sizeof(OutputBuffer));
273 if (NT_SUCCESS(Status))
274 {
275 /* Read the result */
276 Status = GetDwordElement(OutputBuffer.Argument, UniqueId);
277 if (CmBattDebug & 0x440)
278 DbgPrint("CmBattGetUniqueId: _UID method returned %x \n", *UniqueId);
279 }
280 else if (CmBattDebug & 0x44C)
281 {
282 /* Failure */
283 DbgPrint("CmBattGetUniqueId: Failed _UID method - Status (0x%x)\n", Status);
285 }
286
287 /* Return status */
288 return Status;
289}
290
292NTAPI
294 IN ULONG AlarmValue)
295{
298 PAGED_CODE();
299 if (CmBattDebug & 0x440)
300 DbgPrint("CmBattSetTripPpoint: _BTP Alarm Value %x Device %x Tid %x\n",
301 AlarmValue, DeviceExtension->DeviceId, KeGetCurrentThread);
302
303 /* Request the _BTP method */
304 *(PULONG)InputBuffer.MethodName = 'PTB_';
306 InputBuffer.IntegerArgument = AlarmValue;
307
308 /* Send it to ACPI */
309 Status = CmBattSendDownStreamIrp(DeviceExtension->AttachedDevice,
312 sizeof(InputBuffer),
313 NULL,
314 0);
315 if (!(NT_SUCCESS(Status)) && (CmBattDebug & 0x440))
316 DbgPrint("CmBattSetTripPpoint: Failed _BTP method on device %x - Status (0x%x)\n",
317 DeviceExtension->DeviceId, Status);
318
319 /* Return status */
320 return Status;
321}
322
324NTAPI
326 PACPI_BIF_DATA BifData)
327{
330}
331
333NTAPI
335 PACPI_BST_DATA BstData)
336{
339}
340
341/* EOF */
#define PAGED_CODE()
ACPI_METHOD_ARGUMENT UNALIGNED * PACPI_METHOD_ARGUMENT
Definition: acpiioct.h:71
#define ACPI_METHOD_ARGUMENT_STRING
Definition: acpiioct.h:22
#define ACPI_METHOD_ARGUMENT_INTEGER
Definition: acpiioct.h:21
#define ACPI_EVAL_INPUT_BUFFER_SIMPLE_INTEGER_SIGNATURE
Definition: acpiioct.h:8
#define ACPI_EVAL_INPUT_BUFFER_SIGNATURE
Definition: acpiioct.h:7
#define ACPI_METHOD_ARGUMENT_BUFFER
Definition: acpiioct.h:23
#define ACPI_EVAL_OUTPUT_BUFFER_SIGNATURE
Definition: acpiioct.h:11
#define IOCTL_ACPI_EVAL_METHOD
Definition: acpiioct.h:178
ACPI_EVAL_OUTPUT_BUFFER UNALIGNED * PACPI_EVAL_OUTPUT_BUFFER
Definition: acpiioct.h:90
LONG NTSTATUS
Definition: precomp.h:26
#define UNIMPLEMENTED
Definition: debug.h:118
ULONG CmBattDebug
Definition: cmbatt.c:17
NTSTATUS NTAPI CmBattSendDownStreamIrp(IN PDEVICE_OBJECT DeviceObject, IN ULONG IoControlCode, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PACPI_EVAL_OUTPUT_BUFFER OutputBuffer, IN ULONG OutputBufferLength)
Definition: cmexec.c:85
NTSTATUS NTAPI GetDwordElement(IN PACPI_METHOD_ARGUMENT Argument, OUT PULONG Value)
Definition: cmexec.c:20
NTSTATUS NTAPI CmBattGetBifData(PCMBATT_DEVICE_EXTENSION DeviceExtension, PACPI_BIF_DATA BifData)
Definition: cmexec.c:325
NTSTATUS NTAPI CmBattGetUniqueId(IN PDEVICE_OBJECT DeviceObject, OUT PULONG UniqueId)
Definition: cmexec.c:247
NTSTATUS NTAPI CmBattGetBstData(PCMBATT_DEVICE_EXTENSION DeviceExtension, PACPI_BST_DATA BstData)
Definition: cmexec.c:334
NTSTATUS NTAPI CmBattSetTripPpoint(IN PCMBATT_DEVICE_EXTENSION DeviceExtension, IN ULONG AlarmValue)
Definition: cmexec.c:293
NTSTATUS NTAPI CmBattGetStaData(IN PDEVICE_OBJECT DeviceObject, OUT PULONG StaData)
Definition: cmexec.c:201
NTSTATUS NTAPI GetStringElement(IN PACPI_METHOD_ARGUMENT Argument, OUT PCHAR Value)
Definition: cmexec.c:47
NTSTATUS NTAPI CmBattGetPsrData(IN PDEVICE_OBJECT DeviceObject, OUT PULONG PsrData)
Definition: cmexec.c:156
_In_ PIRP Irp
Definition: csq.h:116
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
Status
Definition: gdiplustypes.h:25
#define DbgPrint
Definition: hal.h:12
#define KeGetCurrentThread
Definition: hal.h:55
#define ASSERT(a)
Definition: mode.c:44
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define KernelMode
Definition: asm.h:34
@ SynchronizationEvent
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881
#define IoCallDriver
Definition: irp.c:1225
#define STATUS_PENDING
Definition: ntstatus.h:82
#define STATUS_ACPI_INVALID_DATA
Definition: ntstatus.h:1306
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
uint32_t * PULONG
Definition: typedefs.h:59
#define NTAPI
Definition: typedefs.h:36
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
char * PCHAR
Definition: typedefs.h:51
#define STATUS_NO_SUCH_DEVICE
Definition: udferr_usr.h:136
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ WDFREQUEST _In_ size_t _In_ size_t _In_ ULONG IoControlCode
Definition: wdfio.h:325
_In_ WDFREQUEST _In_ size_t OutputBufferLength
Definition: wdfio.h:320
_In_ WDFREQUEST _In_ size_t _In_ size_t InputBufferLength
Definition: wdfio.h:322
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR OutputBuffer
Definition: wdfiotarget.h:863
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR InputBuffer
Definition: wdfiotarget.h:953
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
@ Executive
Definition: ketypes.h:415