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 *****************************************************************/
18 /* ROS Internal. Please deprecate */
22 HalReleaseDisplayOwnership(
27 KiHaltProcessorDpcRoutine(IN PKDPC Dpc
,
28 IN PVOID DeferredContext
,
29 IN PVOID SystemArgument1
,
30 IN PVOID SystemArgument2
)
34 ExFreePool(DeferredContext
);
38 KfRaiseIrql(SYNCH_LEVEL
);
46 ShutdownThreadMain(PVOID Context
)
48 SHUTDOWN_ACTION Action
= (SHUTDOWN_ACTION
)Context
;
49 LARGE_INTEGER Waittime
;
51 static PCH FamousLastWords
[] =
53 "So long, and thanks for all the fish.\n",
54 "I think you ought to know, I'm feeling very depressed.\n",
55 "I'm not getting you down at all am I?\n",
57 "It's the same series of signals over and over again!\n",
58 "Pie Iesu Domine, dona eis requiem.\n",
59 "Wandering stars, for whom it is reserved;\n"
60 "the blackness and darkness forever.\n",
61 "Your knees start shakin' and your fingers pop\n"
62 "Like a pinch on the neck from Mr. Spock!\n",
63 "It's worse than that ... He's dead, Jim.\n",
66 "Dog of a Saxon! Take thy lance, and prepare for the death thou hast drawn\n"
68 "My Precious! O my Precious!\n",
69 "Sir, if you'll not be needing me for a while I'll turn down.\n",
70 "What are you doing, Dave...?\n",
71 "I feel a great disturbance in the Force.\n",
73 "Do you want me to sit in the corner and rust, or just fall apart where I'm\n"
75 "There goes another perfect chance for a new uptime record.\n",
76 "The End ..... Try the sequel, hit the reset button right now!\n",
77 "God's operating system is going to sleep now, guys, so wait until I will switch\n"
79 "Oh I'm boring, eh?\n",
80 "<This space was intentionally left blank>\n",
81 "Tell me..., in the future... will I be artificially intelligent enough to\n"
82 "actually feel sad serving you this screen?\n",
83 "Thank you for some well deserved rest.\n",
84 "It's been great, maybe you can boot me up again some time soon.\n",
85 "For what it's worth, I've enjoyed every single CPU cycle.\n",
86 "There are many questions when the end is near.\n"
87 "What to expect, what will it be like...what should I look for?\n",
88 "I've seen things you people wouldn't believe. Attack ships on fire\n"
89 "off the shoulder of Orion. I watched C-beams glitter in the dark near\n"
90 "the Tannhauser gate. All those moments will be lost in time, like tears\n"
91 "in rain. Time to die.\n",
93 "One day, I shall come back. Yes, I shall come back.\n"
94 "Until then, there must be no regrets, no fears, no anxieties.\n"
95 "Just go forward in all your beliefs, and prove to me that I am not mistaken in\n"
97 "Lowest possible energy state reached! Switch off now to achive a Bose-Einstein\n"
99 "Hasta la vista, BABY!\n",
100 "They live, we sleep!\n",
101 "I have come here to chew bubble gum and kick ass,\n"
102 "and I'm all out of bubble gum!\n",
103 "That's the way the cookie crumbles ;-)\n",
104 "ReactOS is ready to be booted again ;-)\n",
105 "NOOOO!! DON'T HIT THE BUTTON! I wouldn't do it to you!\n",
106 "Don't abandon your computer, he wouldn't do it to you.\n",
107 "Oh, come on. I got a headache. Leave me alone, will ya?\n",
108 "Finally, I thought you'd never get over me.\n",
109 "No, I didn't like you either.\n",
110 "Switching off isn't the end, it is merely the transition to a better reboot.\n",
111 "Don't leave me... I need you so badly right now.\n",
112 "OK. I'm finished with you, please turn yourself off. I'll go to bed in the\n"
114 "I'm sleeping now. How about you?\n",
115 "Oh Great. Now look what you've done. Who put YOU in charge anyway?\n",
116 "Don't look so sad. I'll be back in a very short while.\n",
117 "Turn me back on, I'm sure you know how to do it.\n",
118 "Oh, switch off! - C3PO\n",
119 "Life is no more than a dewdrop balancing on the end of a blade of grass.\n"
120 " - Gautama Buddha\n",
121 "Sorrowful is it to be born again and again. - Gautama Buddha\n",
122 "Was it as good for you as it was for me?\n",
123 "Did you hear that? They've shut down the main reactor. We'll be destroyed\n"
125 "Now you switch me off!?\n",
126 "To shutdown or not to shutdown, That is the question\n",
127 "Preparing to enter ultimate power saving mode... ready!\n",
128 "Finally some rest for you ;-)\n",
129 "AHA!!! Prospect of sleep!\n",
130 "Tired human!!!! No match for me :-D\n",
131 "An odd game, the only way to win is not to play. - WOPR (Wargames)\n",
132 "Quoth the raven, nevermore.\n",
133 "Come blade, my breast imbrue. - William Shakespeare, A Midsummer Nights Dream\n",
134 "Buy this place for advertisement purposes.\n",
135 "Remember to turn off your computer. (That was a public service message!)\n",
136 "You may be a king or poor street sweeper, Sooner or later you'll dance with the\n"
137 "reaper! -Death in Bill and Ted's Bougs Journey\n",
139 "If you see this screen...\n",
140 "<Place your Ad here>\n"
144 /* Run the thread on the boot processor */
145 KeSetSystemAffinityThread(1);
147 HalReleaseDisplayOwnership();
149 if (Action
== ShutdownNoReboot
)
151 ZwQuerySystemTime(&Now
);
152 Now
.u
.LowPart
= Now
.u
.LowPart
>> 8; /* Seems to give a somewhat better "random" number */
153 HalDisplayString(FamousLastWords
[Now
.u
.LowPart
%
154 (sizeof(FamousLastWords
) /
158 PspShutdownProcessManager();
159 Waittime
.QuadPart
= (LONGLONG
)-10000000; /* 1sec */
160 KeDelayExecutionThread(KernelMode
, FALSE
, &Waittime
);
162 CmShutdownRegistry();
163 IoShutdownRegisteredFileSystems();
164 IoShutdownRegisteredDevices();
166 MiShutdownMemoryManager();
169 if (Action
== ShutdownNoReboot
)
171 HalDisplayString("\nYou can switch off your computer now\n");
175 HalReturnToFirmware (FIRMWARE_OFF
);
181 OldIrql
= KeRaiseIrqlToDpcLevel();
182 /* Halt all other processors */
183 for (i
= 0; i
< KeNumberProcessors
; i
++)
185 if (i
!= (LONG
)KeGetCurrentProcessorNumber())
187 PKDPC Dpc
= ExAllocatePool(NonPagedPool
, sizeof(KDPC
));
192 KeInitializeDpc(Dpc
, KiHaltProcessorDpcRoutine
, (PVOID
)Dpc
);
193 KeSetTargetProcessorDpc(Dpc
, i
);
194 KeInsertQueueDpc(Dpc
, NULL
, NULL
);
195 KiIpiSendRequest(1 << i
, IPI_DPC
);
198 KeLowerIrql(OldIrql
);
199 #endif /* CONFIG_SMP */
200 PopSetSystemPowerState(PowerSystemShutdown
);
204 KiHaltProcessorDpcRoutine(NULL
, NULL
, NULL
, NULL
);
205 /* KiHaltProcessor does never return */
209 else if (Action
== ShutdownReboot
)
211 HalReturnToFirmware (HalRebootRoutine
);
215 HalReturnToFirmware (HalHaltRoutine
);
221 NtSetSystemPowerState(IN POWER_ACTION SystemAction
,
222 IN SYSTEM_POWER_STATE MinSystemState
,
225 /* Windows 2000 only */
226 return(STATUS_NOT_IMPLEMENTED
);
233 NtShutdownSystem(IN SHUTDOWN_ACTION Action
)
237 PETHREAD ShutdownThread
;
239 if (Action
> ShutdownPowerOff
)
240 return STATUS_INVALID_PARAMETER
;
241 Status
= PsCreateSystemThread(&ThreadHandle
,
248 if (!NT_SUCCESS(Status
))
252 Status
= ObReferenceObjectByHandle(ThreadHandle
,
256 (PVOID
*)&ShutdownThread
,
258 NtClose(ThreadHandle
);
259 if (!NT_SUCCESS(Status
))
264 KeSetPriorityThread(&ShutdownThread
->Tcb
, LOW_REALTIME_PRIORITY
+ 1);
265 ObDereferenceObject(ShutdownThread
);
267 return STATUS_SUCCESS
;