ReactOS  0.4.14-dev-297-g23e575c
cmexec.c File Reference
#include "cmbatt.h"
#include <acpiioct.h>
#include <debug.h>
Include dependency graph for cmexec.c:

Go to the source code of this file.

Functions

NTSTATUS NTAPI GetDwordElement (IN PACPI_METHOD_ARGUMENT Argument, OUT PULONG Value)
 
NTSTATUS NTAPI GetStringElement (IN PACPI_METHOD_ARGUMENT Argument, OUT PCHAR Value)
 
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)
 
NTSTATUS NTAPI CmBattGetPsrData (IN PDEVICE_OBJECT DeviceObject, OUT PULONG PsrData)
 
NTSTATUS NTAPI CmBattGetStaData (IN PDEVICE_OBJECT DeviceObject, OUT PULONG StaData)
 
NTSTATUS NTAPI CmBattGetUniqueId (IN PDEVICE_OBJECT DeviceObject, OUT PULONG UniqueId)
 
NTSTATUS NTAPI CmBattSetTripPpoint (IN PCMBATT_DEVICE_EXTENSION DeviceExtension, IN ULONG AlarmValue)
 
NTSTATUS NTAPI CmBattGetBifData (PCMBATT_DEVICE_EXTENSION DeviceExtension, PACPI_BIF_DATA BifData)
 
NTSTATUS NTAPI CmBattGetBstData (PCMBATT_DEVICE_EXTENSION DeviceExtension, PACPI_BST_DATA BstData)
 

Function Documentation

◆ CmBattGetBifData()

NTSTATUS NTAPI CmBattGetBifData ( PCMBATT_DEVICE_EXTENSION  DeviceExtension,
PACPI_BIF_DATA  BifData 
)

Definition at line 325 of file cmexec.c.

327 {
329  return STATUS_NOT_IMPLEMENTED;
330 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define UNIMPLEMENTED
Definition: debug.h:114

Referenced by CmBattIoctl().

◆ CmBattGetBstData()

NTSTATUS NTAPI CmBattGetBstData ( PCMBATT_DEVICE_EXTENSION  DeviceExtension,
PACPI_BST_DATA  BstData 
)

Definition at line 334 of file cmexec.c.

336 {
338  return STATUS_NOT_IMPLEMENTED;
339 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define UNIMPLEMENTED
Definition: debug.h:114

Referenced by CmBattGetBatteryStatus(), CmBattIoctl(), and CmBattSetStatusNotify().

◆ CmBattGetPsrData()

NTSTATUS NTAPI CmBattGetPsrData ( IN PDEVICE_OBJECT  DeviceObject,
OUT PULONG  PsrData 
)

Definition at line 156 of file cmexec.c.

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 }
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 DbgPrint
Definition: loader.c:25
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI GetDwordElement(IN PACPI_METHOD_ARGUMENT Argument, OUT PULONG Value)
Definition: cmexec.c:20
ULONG CmBattDebug
Definition: cmbatt.c:17
#define PAGED_CODE()
Definition: video.h:57
CHAR InputBuffer[80]
Definition: conmgr.c:33
smooth NULL
Definition: ftsmooth.c:416
_Must_inspect_result_ __drv_aliasesMem _In_ PDEVICE_OBJECT _In_opt_ PVOID _In_ ULONG _Out_opt_ PVOID OutputBuffer
Definition: iofuncs.h:713
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define IOCTL_ACPI_EVAL_METHOD
Definition: acpiioct.h:178
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define ACPI_EVAL_INPUT_BUFFER_SIGNATURE
Definition: acpiioct.h:7
unsigned int * PULONG
Definition: retypes.h:1
#define KeGetCurrentThread
Definition: hal.h:44

◆ CmBattGetStaData()

NTSTATUS NTAPI CmBattGetStaData ( IN PDEVICE_OBJECT  DeviceObject,
OUT PULONG  StaData 
)

Definition at line 201 of file cmexec.c.

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 }
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 DbgPrint
Definition: loader.c:25
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI GetDwordElement(IN PACPI_METHOD_ARGUMENT Argument, OUT PULONG Value)
Definition: cmexec.c:20
ULONG CmBattDebug
Definition: cmbatt.c:17
#define PAGED_CODE()
Definition: video.h:57
CHAR InputBuffer[80]
Definition: conmgr.c:33
smooth NULL
Definition: ftsmooth.c:416
_Must_inspect_result_ __drv_aliasesMem _In_ PDEVICE_OBJECT _In_opt_ PVOID _In_ ULONG _Out_opt_ PVOID OutputBuffer
Definition: iofuncs.h:713
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_NO_SUCH_DEVICE
Definition: udferr_usr.h:136
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define IOCTL_ACPI_EVAL_METHOD
Definition: acpiioct.h:178
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define ACPI_EVAL_INPUT_BUFFER_SIGNATURE
Definition: acpiioct.h:7
unsigned int * PULONG
Definition: retypes.h:1
#define KeGetCurrentThread
Definition: hal.h:44

◆ CmBattGetUniqueId()

NTSTATUS NTAPI CmBattGetUniqueId ( IN PDEVICE_OBJECT  DeviceObject,
OUT PULONG  UniqueId 
)

Definition at line 247 of file cmexec.c.

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 }
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 DbgPrint
Definition: loader.c:25
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI GetDwordElement(IN PACPI_METHOD_ARGUMENT Argument, OUT PULONG Value)
Definition: cmexec.c:20
ULONG CmBattDebug
Definition: cmbatt.c:17
#define PAGED_CODE()
Definition: video.h:57
CHAR InputBuffer[80]
Definition: conmgr.c:33
smooth NULL
Definition: ftsmooth.c:416
_Must_inspect_result_ __drv_aliasesMem _In_ PDEVICE_OBJECT _In_opt_ PVOID _In_ ULONG _Out_opt_ PVOID OutputBuffer
Definition: iofuncs.h:713
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_NO_SUCH_DEVICE
Definition: udferr_usr.h:136
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define IOCTL_ACPI_EVAL_METHOD
Definition: acpiioct.h:178
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define ACPI_EVAL_INPUT_BUFFER_SIGNATURE
Definition: acpiioct.h:7
unsigned int * PULONG
Definition: retypes.h:1
#define KeGetCurrentThread
Definition: hal.h:44

◆ CmBattSendDownStreamIrp()

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 at line 85 of file cmexec.c.

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 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG IoControlCode
Definition: fltkernel.h:1383
#define DbgPrint
Definition: loader.c:25
_In_ PIRP Irp
Definition: csq.h:116
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 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
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
smooth NULL
Definition: ftsmooth.c:416
_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 STATUS_PENDING
Definition: ntstatus.h:82
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ ULONG InputBufferLength
Definition: fltkernel.h:1372
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
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 KeGetCurrentThread
Definition: hal.h:44
#define STATUS_ACPI_INVALID_DATA
Definition: ntstatus.h:1087

Referenced by CmBattGetPsrData(), CmBattGetStaData(), CmBattGetUniqueId(), and CmBattSetTripPpoint().

◆ CmBattSetTripPpoint()

NTSTATUS NTAPI CmBattSetTripPpoint ( IN PCMBATT_DEVICE_EXTENSION  DeviceExtension,
IN ULONG  AlarmValue 
)

Definition at line 293 of file cmexec.c.

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 }
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 DbgPrint
Definition: loader.c:25
LONG NTSTATUS
Definition: precomp.h:26
#define ACPI_EVAL_INPUT_BUFFER_SIMPLE_INTEGER_SIGNATURE
Definition: acpiioct.h:8
ULONG CmBattDebug
Definition: cmbatt.c:17
#define PAGED_CODE()
Definition: video.h:57
CHAR InputBuffer[80]
Definition: conmgr.c:33
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define IOCTL_ACPI_EVAL_METHOD
Definition: acpiioct.h:178
Status
Definition: gdiplustypes.h:24
unsigned int * PULONG
Definition: retypes.h:1
#define KeGetCurrentThread
Definition: hal.h:44

◆ GetDwordElement()

NTSTATUS NTAPI GetDwordElement ( IN PACPI_METHOD_ARGUMENT  Argument,
OUT PULONG  Value 
)

Definition at line 20 of file cmexec.c.

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 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2343
#define DbgPrint
Definition: loader.c:25
LONG NTSTATUS
Definition: precomp.h:26
ULONG CmBattDebug
Definition: cmbatt.c:17
Status
Definition: gdiplustypes.h:24
#define ACPI_METHOD_ARGUMENT_INTEGER
Definition: acpiioct.h:21
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define STATUS_ACPI_INVALID_DATA
Definition: ntstatus.h:1087

Referenced by CmBattGetPsrData(), CmBattGetStaData(), and CmBattGetUniqueId().

◆ GetStringElement()

NTSTATUS NTAPI GetStringElement ( IN PACPI_METHOD_ARGUMENT  Argument,
OUT PCHAR  Value 
)

Definition at line 47 of file cmexec.c.

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 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2343
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define ACPI_METHOD_ARGUMENT_BUFFER
Definition: acpiioct.h:23
#define DbgPrint
Definition: loader.c:25
LONG NTSTATUS
Definition: precomp.h:26
ULONG CmBattDebug
Definition: cmbatt.c:17
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:64
#define ACPI_METHOD_ARGUMENT_STRING
Definition: acpiioct.h:22
Status
Definition: gdiplustypes.h:24
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define STATUS_ACPI_INVALID_DATA
Definition: ntstatus.h:1087