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