3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/ex/power.c
6 * PURPOSE: Power managment
8 * PROGRAMMERS: David Welch (welch@cwcom.net)
11 /* INCLUDES *****************************************************************/
14 #include <internal/debug.h>
16 /* FUNCTIONS *****************************************************************/
19 KeSetTargetProcessorDpc (IN PKDPC Dpc
,
23 KiHaltProcessorDpcRoutine(IN PKDPC Dpc
,
24 IN PVOID DeferredContext
,
25 IN PVOID SystemArgument1
,
26 IN PVOID SystemArgument2
)
30 ExFreePool(DeferredContext
);
34 KfRaiseIrql(SYNCH_LEVEL
);
40 ShutdownThreadMain(PVOID Context
)
42 SHUTDOWN_ACTION Action
= (SHUTDOWN_ACTION
)Context
;
43 LARGE_INTEGER Waittime
;
45 /* Run the thread on the boot processor */
46 KeSetSystemAffinityThread(1);
49 IoShutdownRegisteredFileSystems();
50 IoShutdownRegisteredDevices();
52 PiShutdownProcessManager();
53 MiShutdownMemoryManager();
55 Waittime
.QuadPart
= (LONGLONG
)-10000000; /* 1sec */
56 KeDelayExecutionThread(KernelMode
, FALSE
, &Waittime
);
58 if (Action
== ShutdownNoReboot
)
63 HalReturnToFirmware (FIRMWARE_OFF
);
69 OldIrql
= KeRaiseIrqlToDpcLevel();
70 /* Halt all other processors */
71 for (i
= 0; i
< KeNumberProcessors
; i
++)
73 if (i
!= KeGetCurrentProcessorNumber())
75 PKDPC Dpc
= ExAllocatePool(NonPagedPool
, sizeof(KDPC
));
80 KeInitializeDpc(Dpc
, KiHaltProcessorDpcRoutine
, (PVOID
)Dpc
);
81 KeSetTargetProcessorDpc(Dpc
, i
);
82 KeInsertQueueDpc(Dpc
, NULL
, NULL
);
83 KiIpiSendRequest(1 << i
, IPI_REQUEST_DPC
);
87 #endif /* CONFIG_SMP */
88 PopSetSystemPowerState(PowerSystemShutdown
);
92 KiHaltProcessorDpcRoutine(NULL
, NULL
, NULL
, NULL
);
93 /* KiHaltProcessor does never return */
97 else if (Action
== ShutdownReboot
)
99 HalReturnToFirmware (HalRebootRoutine
);
103 HalReturnToFirmware (HalHaltRoutine
);
109 NtSetSystemPowerState(IN POWER_ACTION SystemAction
,
110 IN SYSTEM_POWER_STATE MinSystemState
,
113 /* Windows 2000 only */
114 return(STATUS_NOT_IMPLEMENTED
);
121 NtShutdownSystem(IN SHUTDOWN_ACTION Action
)
125 PETHREAD ShutdownThread
;
127 static PCH FamousLastWords
[] =
129 "So long, and thanks for all the fish\n",
130 "I think you ought to know I'm feeling very depressed\n",
131 "I'm not getting you down at all am I?\n",
133 "It's the same series of signal over and over again!\n",
134 "Pie Iesu Domine, dona eis requiem\n",
135 "Wandering stars, for whom it is reserved;\n"
136 "the blackness and darkness forever.\n",
137 "Your knees start shakin' and your fingers pop\n"
138 "Like a pinch on the neck from Mr. Spock!\n",
139 "It's worse than that ... He's dead, Jim\n",
142 "Dog of a Saxon! Take thy lance, and prepare for the death thou hast drawn upon thee!\n",
143 "My Precious! O my Precious!\n",
144 "Sir, If you'll not be needing me for a while I'll turn down.\n",
145 "What are you doing, Dave...?\n",
146 "I feel a great disturbance in the Force\n",
148 "Do you want me to sit in the corner and rust, or just fall apart where I'm standing?\n",
149 "There goes another perfect chance for a new uptime record\n",
150 "The end ..... Try the sequel, hit the reset button right now!\n",
151 "God's operating system is going to sleep now, guys, so wait until I will switch on again!\n",
152 "Oh i'm boring eh?\n",
153 "<This space was intentionally left blank>\n",
154 "tell me..., in the future... will I be artificial intelligent enough to actually feel\n"
155 "sad serving you this screen?\n",
156 "Thank you for some well deserved rest.\n",
157 "It's been great, maybe we can boot me up again some time soon.\n",
158 "For what's it worth, I've enjoyed every single CPU cycle.\n",
159 "There are many questions when the end is near.\n"
160 "What to expect, what will it be like...what should I look for?\n",
161 "I've seen things you people wouldn't believe. Attack ships on fire\n"
162 "off the shoulder of Orion. I watched C-beams glitter in the dark near\n"
163 "the Tannhauser gate. All those moments will be lost in time, like tears\n"
164 "in rain. Time to die.\n",
166 "One day, I shall come back. Yes, I shall come back.\n"
167 "Until then, there must be no regrets, no fears, no anxieties.\n"
168 "Just go forward in all your beliefs, and prove to me that I am not mistaken in mine.\n",
169 "Lowest possible energy state reached! Switch off now to achive a Bose-Einstein condensate.\n",
170 "Hasta la vista, BABY!\n",
171 "They live, we sleep!\n",
172 "I have come here to chew bubble gum and kick ass.\n"
173 "And I'm all out of bubble gum!\n"
177 if (Action
> ShutdownPowerOff
)
178 return STATUS_INVALID_PARAMETER
;
180 ZwQuerySystemTime(&Now
);
181 Now
.u
.LowPart
= Now
.u
.LowPart
>> 8; /* Seems to give a somewhat better "random" number */
183 if (Action
== ShutdownNoReboot
)
185 HalReleaseDisplayOwnership();
186 HalDisplayString("\nYou can switch off your computer now\n\n");
187 HalDisplayString(FamousLastWords
[Now
.u
.LowPart
% (sizeof(FamousLastWords
) / sizeof(PCH
))]);
189 Status
= PsCreateSystemThread(&ThreadHandle
,
196 if (!NT_SUCCESS(Status
))
200 Status
= ObReferenceObjectByHandle(ThreadHandle
,
204 (PVOID
*)&ShutdownThread
,
206 NtClose(ThreadHandle
);
207 if (!NT_SUCCESS(Status
))
212 KeSetPriorityThread(&ShutdownThread
->Tcb
, LOW_REALTIME_PRIORITY
+ 1);
213 ObDereferenceObject(ShutdownThread
);
215 return STATUS_SUCCESS
;