source: mainline/kernel/generic/src/main/shutdown.c@ 40043e8

Last change on this file since 40043e8 was 40043e8, checked in by Matthieu Riolo <matthieu.riolo@…>, 6 years ago

Restructering halt/reboot files

The function halt() and reboot() used to be stored
in two different c files and two different header
files which were named differently than the c files.
This commit merges those two functions into the
same file and provides an unique header file (shutdown.h)
for accessing them.

  • Property mode set to 100644
File size: 2.5 KB
Line 
1/*
2 * Copyright (c) 2007 Martin Decky
3 * Copyright (c) 2001-2004 Jakub Jermar
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/** @addtogroup kernel_generic
31 * @{
32 */
33
34/**
35 * @file
36 * @brief Shutdown procedures.
37 */
38
39#include <shutdown.h>
40#include <log.h>
41#include <cpu.h>
42#include <arch/asm.h>
43#include <arch.h>
44#include <console/kconsole.h>
45#include <proc/task.h>
46
47/** Halt flag */
48atomic_t haltstate = 0;
49
50/** Halt wrapper
51 *
52 * Set halt flag and halt the CPU.
53 *
54 */
55void halt(void)
56{
57#if (defined(CONFIG_DEBUG)) && (defined(CONFIG_KCONSOLE))
58 bool rundebugger = false;
59
60 if (!atomic_load(&haltstate)) {
61 atomic_store(&haltstate, 1);
62 rundebugger = true;
63 }
64#else
65 atomic_store(&haltstate, 1);
66#endif
67
68 interrupts_disable();
69
70#if (defined(CONFIG_DEBUG)) && (defined(CONFIG_KCONSOLE))
71 if ((rundebugger) && (kconsole_check_poll()))
72 kconsole("panic", "\nLast resort kernel console ready.\n", false);
73#endif
74
75 if (CPU)
76 log(LF_OTHER, LVL_NOTE, "cpu%u: halted", CPU->id);
77 else
78 log(LF_OTHER, LVL_NOTE, "cpu: halted");
79
80 cpu_halt();
81}
82
83void reboot(void)
84{
85 task_done();
86
87#ifdef CONFIG_DEBUG
88 log(LF_OTHER, LVL_DEBUG, "Rebooting the system");
89#endif
90
91 arch_reboot();
92 halt();
93}
94
95/** @}
96 */
Note: See TracBrowser for help on using the repository browser.