summaryrefslogtreecommitdiffstats
path: root/common/restart.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/restart.c')
-rw-r--r--common/restart.c70
1 files changed, 43 insertions, 27 deletions
diff --git a/common/restart.c b/common/restart.c
index 8fd5ffd1a2..35cfb54251 100644
--- a/common/restart.c
+++ b/common/restart.c
@@ -1,18 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (c) 2015 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
*/
#define pr_fmt(fmt) "restart: " fmt
@@ -22,6 +10,7 @@
#include <of.h>
static LIST_HEAD(restart_handler_list);
+static unsigned resetidx;
/**
* restart_handler_register() - register a handler for restarting the system
@@ -34,20 +23,30 @@ static LIST_HEAD(restart_handler_list);
int restart_handler_register(struct restart_handler *rst)
{
if (!rst->name)
- rst->name = RESTART_DEFAULT_NAME;
+ rst->name = basprintf("reset%u", resetidx);
if (!rst->priority)
rst->priority = RESTART_DEFAULT_PRIORITY;
+ if (rst->of_node) {
+ of_property_read_u32(rst->of_node, "restart-priority",
+ &rst->priority);
+ if (of_property_read_bool(rst->of_node,
+ "barebox,restart-warm-bootrom"))
+ rst->flags |= RESTART_FLAG_WARM_BOOTROM;
+ }
+
list_add_tail(&rst->list, &restart_handler_list);
pr_debug("registering restart handler \"%s\" with priority %d\n",
rst->name, rst->priority);
+ resetidx++;
return 0;
}
/**
* restart_handler_register_fn() - register a handler function
+ * @name: restart method name or NULL if name should be auto-generated
* @restart_fn: The restart function
*
* convenience wrapper for restart_handler_register() to register a handler
@@ -55,13 +54,15 @@ int restart_handler_register(struct restart_handler *rst)
*
* return: 0 for success or negative error code
*/
-int restart_handler_register_fn(void (*restart_fn)(struct restart_handler *))
+int restart_handler_register_fn(const char *name,
+ void (*restart_fn)(struct restart_handler *))
{
struct restart_handler *rst;
int ret;
rst = xzalloc(sizeof(*rst));
+ rst->name = xstrdup(name);
rst->restart = restart_fn;
ret = restart_handler_register(rst);
@@ -73,20 +74,35 @@ int restart_handler_register_fn(void (*restart_fn)(struct restart_handler *))
}
/**
- * restart_machine() - reset the whole system
+ * restart_handler_get_by_name() - get highest priority `name'
*/
-void __noreturn restart_machine(void)
+struct restart_handler *restart_handler_get_by_name(const char *name, int flags)
{
struct restart_handler *rst = NULL, *tmp;
unsigned int priority = 0;
list_for_each_entry(tmp, &restart_handler_list, list) {
+ if (name && tmp->name && strcmp(name, tmp->name))
+ continue;
+ if (flags && (tmp->flags & flags) != flags)
+ continue;
if (tmp->priority > priority) {
priority = tmp->priority;
rst = tmp;
}
}
+ return rst;
+}
+
+/**
+ * restart_machine() - reset the whole system
+ */
+void __noreturn restart_machine(void)
+{
+ struct restart_handler *rst;
+
+ rst = restart_handler_get_by_name(NULL, 0);
if (rst) {
pr_debug("%s: using restart handler %s\n", __func__, rst->name);
console_flush();
@@ -96,17 +112,17 @@ void __noreturn restart_machine(void)
hang();
}
-/**
- * of_get_restart_priority() - get the desired restart priority from device tree
- * @node: The device_node to read the property from
- *
- * return: The priority
+/*
+ * restart_handlers_print - print informations about all restart handlers
*/
-unsigned int of_get_restart_priority(struct device_node *node)
+void restart_handlers_print(void)
{
- unsigned int priority = RESTART_DEFAULT_PRIORITY;
-
- of_property_read_u32(node, "restart-priority", &priority);
+ struct restart_handler *tmp;
- return priority;
+ list_for_each_entry(tmp, &restart_handler_list, list) {
+ printf("%-20s %6d ", tmp->name, tmp->priority);
+ if (tmp->flags & RESTART_FLAG_WARM_BOOTROM)
+ putchar('W');
+ putchar('\n');
+ }
}