update for HEAD-2003091401
[reactos.git] / ntoskrnl / po / power.c
1 /*
2  *  ReactOS kernel
3  *  Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19 /* $Id$
20  * PROJECT:         ReactOS kernel
21  * FILE:            ntoskrnl/po/power.c
22  * PURPOSE:         Power Manager
23  * PROGRAMMER:      Casper S. Hornstrup (chorns@users.sourceforge.net)
24  * UPDATE HISTORY:
25  *   20/08/1999 EA  Created
26  *   16/04/2001 CSH Stubs added
27  */
28 #include <ddk/ntddk.h>
29 #include <roscfg.h>
30 #include <internal/io.h>
31 #include <internal/po.h>
32
33 #define NDEBUG
34 #include <internal/debug.h>
35
36
37 PDEVICE_NODE PopSystemPowerDeviceNode = NULL;
38
39
40 NTSTATUS
41 STDCALL
42 PoCallDriver(
43   IN PDEVICE_OBJECT DeviceObject,
44   IN OUT PIRP Irp)
45 {
46   NTSTATUS Status;
47
48   Status = IoCallDriver(DeviceObject, Irp);
49
50   return Status;
51 }
52
53 /*
54  * @unimplemented
55  */
56 PULONG
57 STDCALL
58 PoRegisterDeviceForIdleDetection(
59   IN PDEVICE_OBJECT DeviceObject,
60   IN ULONG ConservationIdleTime,
61   IN ULONG PerformanceIdleTime,
62   IN DEVICE_POWER_STATE State)
63 {
64   return NULL;
65 }
66
67 /*
68  * @unimplemented
69  */
70 PVOID
71 STDCALL
72 PoRegisterSystemState(
73   IN PVOID StateHandle,
74   IN EXECUTION_STATE Flags)
75 {
76   return NULL;
77 }
78
79 /*
80  * @unimplemented
81  */
82 NTSTATUS
83 STDCALL
84 PoRequestPowerIrp(
85   IN PDEVICE_OBJECT DeviceObject,
86   IN UCHAR MinorFunction,  
87   IN POWER_STATE PowerState,
88   IN PREQUEST_POWER_COMPLETE CompletionFunction,
89   IN PVOID Context,
90   OUT PIRP *Irp   OPTIONAL)
91 {
92   return STATUS_NOT_IMPLEMENTED;
93 }
94
95 VOID
96 STDCALL
97 PoSetDeviceBusy(
98   PULONG IdlePointer)
99 {
100 }
101
102 /*
103  * @unimplemented
104  */
105 POWER_STATE
106 STDCALL
107 PoSetPowerState(
108   IN PDEVICE_OBJECT DeviceObject,
109   IN POWER_STATE_TYPE Type,
110   IN POWER_STATE State)
111 {
112   POWER_STATE ps;
113
114   ps.SystemState = PowerSystemWorking;  // Fully on
115   ps.DeviceState = PowerDeviceD0;       // Fully on
116
117   return ps;
118 }
119
120 /*
121  * @unimplemented
122  */
123 VOID
124 STDCALL
125 PoSetSystemState(
126   IN EXECUTION_STATE Flags)
127 {
128 }
129
130 /*
131  * @unimplemented
132  */
133 VOID
134 STDCALL
135 PoStartNextPowerIrp(
136   IN PIRP Irp)
137 {
138 }
139
140 /*
141  * @unimplemented
142  */
143 VOID
144 STDCALL
145 PoUnregisterSystemState(
146   IN PVOID StateHandle)
147 {
148 }
149
150 NTSTATUS
151 PopSetSystemPowerState(
152   SYSTEM_POWER_STATE PowerState)
153 {
154
155 #ifdef ACPI
156
157   IO_STATUS_BLOCK IoStatusBlock;
158   PDEVICE_OBJECT DeviceObject;
159   PIO_STACK_LOCATION IrpSp;
160   PDEVICE_OBJECT Fdo;
161   NTSTATUS Status;
162   KEVENT Event;
163   PIRP Irp;
164
165   Status = IopGetSystemPowerDeviceObject(&DeviceObject);
166   if (!NT_SUCCESS(Status)) {
167     CPRINT("No system power driver available\n");
168     return STATUS_UNSUCCESSFUL;
169   }
170
171   Fdo = IoGetAttachedDeviceReference(DeviceObject);
172
173   if (Fdo == DeviceObject)
174     {
175       DPRINT("An FDO was not attached\n");
176       return STATUS_UNSUCCESSFUL;
177     }
178
179   KeInitializeEvent(&Event,
180           NotificationEvent,
181           FALSE);
182
183   Irp = IoBuildSynchronousFsdRequest(IRP_MJ_POWER,
184     Fdo,
185           NULL,
186           0,
187           NULL,
188           &Event,
189           &IoStatusBlock);
190
191   IrpSp = IoGetNextIrpStackLocation(Irp);
192   IrpSp->MinorFunction = IRP_MN_SET_POWER;
193   IrpSp->Parameters.Power.Type = SystemPowerState;
194   IrpSp->Parameters.Power.State.SystemState = PowerState;
195
196         Status = PoCallDriver(Fdo, Irp);
197         if (Status == STATUS_PENDING)
198           {
199                   KeWaitForSingleObject(&Event,
200                                         Executive,
201                                         KernelMode,
202                                         FALSE,
203                                         NULL);
204       Status = IoStatusBlock.Status;
205     }
206
207   ObDereferenceObject(Fdo);
208
209   return Status;
210
211 #endif /* ACPI */
212
213   return STATUS_NOT_IMPLEMENTED;
214 }
215
216 VOID
217 PoInit(VOID)
218 {
219 }
220
221 /* EOF */