ReactOS  0.4.14-dev-583-g2a1ba2c
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 
19 NTAPI
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 
46 NTAPI
48  OUT PCHAR Value)
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 
84 NTAPI
91 {
92  PIRP Irp;
94  KEVENT Event;
96  PAGED_CODE();
97 
98  /* Initialize our wait event */
100 
101  /* Allocate the IRP */
103  DeviceObject,
104  InputBuffer,
106  OutputBuffer,
108  0,
109  &Event,
110  &IoStatusBlock);
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,
129  KernelMode,
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 */
139  if ((OutputBuffer->Signature != ACPI_EVAL_OUTPUT_BUFFER_SIGNATURE) ||
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 
154 NTSTATUS
155 NTAPI
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 */
178  &InputBuffer,
179  sizeof(InputBuffer),
180  &OutputBuffer,
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 
199 NTSTATUS
200 NTAPI
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 */
223  &InputBuffer,
224  sizeof(InputBuffer),
225  &OutputBuffer,
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 
245 NTSTATUS
246 NTAPI
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 */
269  &InputBuffer,
270  sizeof(InputBuffer),
271  &OutputBuffer,
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 
291 NTSTATUS
292 NTAPI
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,
311  &InputBuffer,
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 
323 NTSTATUS
324 NTAPI
326  PACPI_BIF_DATA BifData)
327 {
329  return STATUS_NOT_IMPLEMENTED;
330 }
331 
332 NTSTATUS
333 NTAPI
335  PACPI_BST_DATA BstData)
336 {
338  return STATUS_NOT_IMPLEMENTED;
339 }
340 
341 /* EOF */
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2343
signed char * PCHAR
Definition: retypes.h:7
#define IN
Definition: typedefs.h:38
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG IoControlCode
Definition: fltkernel.h:1383
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
#define ACPI_METHOD_ARGUMENT_BUFFER
Definition: acpiioct.h:23
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define DbgPrint
Definition: loader.c:25
_In_ PIRP Irp
Definition: csq.h:116
ACPI_EVAL_OUTPUT_BUFFER UNALIGNED * PACPI_EVAL_OUTPUT_BUFFER
Definition: acpiioct.h:90
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ ULONG _In_ ULONG OutputBufferLength
Definition: fltkernel.h:1374
NTSTATUS NTAPI GetDwordElement(IN PACPI_METHOD_ARGUMENT Argument, OUT PULONG Value)
Definition: cmexec.c:20
#define ACPI_EVAL_INPUT_BUFFER_SIMPLE_INTEGER_SIGNATURE
Definition: acpiioct.h:8
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
ULONG CmBattDebug
Definition: cmbatt.c:17
#define PAGED_CODE()
Definition: video.h:57
CHAR InputBuffer[80]
Definition: conmgr.c:33
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
NTSTATUS NTAPI CmBattGetBifData(PCMBATT_DEVICE_EXTENSION DeviceExtension, PACPI_BIF_DATA BifData)
Definition: cmexec.c:325
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
smooth NULL
Definition: ftsmooth.c:416
#define ACPI_METHOD_ARGUMENT_STRING
Definition: acpiioct.h:22
_Must_inspect_result_ __drv_aliasesMem _In_ PDEVICE_OBJECT _In_opt_ PVOID _In_ ULONG _Out_opt_ PVOID OutputBuffer
Definition: iofuncs.h:713
#define ACPI_EVAL_OUTPUT_BUFFER_SIGNATURE
Definition: acpiioct.h:11
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define STATUS_NO_SUCH_DEVICE
Definition: udferr_usr.h:136
NTSTATUS NTAPI CmBattGetStaData(IN PDEVICE_OBJECT DeviceObject, OUT PULONG StaData)
Definition: cmexec.c:201
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ ULONG InputBufferLength
Definition: fltkernel.h:1372
#define IOCTL_ACPI_EVAL_METHOD
Definition: acpiioct.h:178
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define ACPI_METHOD_ARGUMENT_INTEGER
Definition: acpiioct.h:21
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define ACPI_EVAL_INPUT_BUFFER_SIGNATURE
Definition: acpiioct.h:7
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
ACPI_METHOD_ARGUMENT UNALIGNED * PACPI_METHOD_ARGUMENT
Definition: acpiioct.h:71
unsigned int * PULONG
Definition: retypes.h:1
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
NTSTATUS NTAPI CmBattGetUniqueId(IN PDEVICE_OBJECT DeviceObject, OUT PULONG UniqueId)
Definition: cmexec.c:247
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 OUT
Definition: typedefs.h:39
unsigned int ULONG
Definition: retypes.h:1
#define UNIMPLEMENTED
Definition: debug.h:114
#define KeGetCurrentThread
Definition: hal.h:44
NTSTATUS NTAPI CmBattGetPsrData(IN PDEVICE_OBJECT DeviceObject, OUT PULONG PsrData)
Definition: cmexec.c:156
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define STATUS_ACPI_INVALID_DATA
Definition: ntstatus.h:1087
NTSTATUS NTAPI CmBattGetBstData(PCMBATT_DEVICE_EXTENSION DeviceExtension, PACPI_BST_DATA BstData)
Definition: cmexec.c:334
NTSTATUS NTAPI GetStringElement(IN PACPI_METHOD_ARGUMENT Argument, OUT PCHAR Value)
Definition: cmexec.c:47
NTSTATUS NTAPI CmBattSetTripPpoint(IN PCMBATT_DEVICE_EXTENSION DeviceExtension, IN ULONG AlarmValue)
Definition: cmexec.c:293