Fix reboot command on the Raspberry Pi series.
The Raspbery Pi computers do not properly implement PSCI. The canonical way to reset them is to set a watchdog timer and allow it to expire. Submitted by: Robert Crowston <crowston_protonmail.com> Differential Revision: https://reviews.freebsd.org/D25268
This commit is contained in:
parent
5b990a9463
commit
fc0804f18b
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=362489
@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/lock.h>
|
||||
#include <sys/module.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/reboot.h>
|
||||
#include <sys/rman.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/watchdog.h>
|
||||
@ -89,10 +90,12 @@ struct bcmwd_softc {
|
||||
static struct ofw_compat_data compat_data[] = {
|
||||
{"broadcom,bcm2835-wdt", BSD_DTB},
|
||||
{"brcm,bcm2835-pm-wdt", UPSTREAM_DTB},
|
||||
{"brcm,bcm2835-pm", UPSTREAM_DTB},
|
||||
{NULL, 0}
|
||||
};
|
||||
|
||||
static void bcmwd_watchdog_fn(void *private, u_int cmd, int *error);
|
||||
static void bcmwd_reboot_system(void *, int);
|
||||
|
||||
static int
|
||||
bcmwd_probe(device_t dev)
|
||||
@ -143,6 +146,15 @@ bcmwd_attach(device_t dev)
|
||||
mtx_init(&sc->mtx, "BCM2835 Watchdog", "bcmwd", MTX_DEF);
|
||||
EVENTHANDLER_REGISTER(watchdog_list, bcmwd_watchdog_fn, sc, 0);
|
||||
|
||||
/*
|
||||
* Handle reboot events. This needs to happen with slightly greater
|
||||
* priority than the PSCI handler, since PSCI reset is not properly
|
||||
* implemented on the Pi and it just puts the Pi into a halt
|
||||
* state.
|
||||
*/
|
||||
EVENTHANDLER_REGISTER(shutdown_final, bcmwd_reboot_system, sc,
|
||||
SHUTDOWN_PRI_LAST-1);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -171,6 +183,7 @@ bcmwd_watchdog_fn(void *private, u_int cmd, int *error)
|
||||
(BCM2835_PASSWORD << BCM2835_PASSWORD_SHIFT) |
|
||||
BCM2835_RSTC_RESET);
|
||||
mtx_unlock(&sc->mtx);
|
||||
*error = EINVAL;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -210,6 +223,27 @@ bcmwd_watchdog_reset(void)
|
||||
BCM2835_RSTC_WRCFG_FULL_RESET);
|
||||
}
|
||||
|
||||
static void
|
||||
bcmwd_reboot_system(void *sc, int howto)
|
||||
{
|
||||
int cmd, error = 0;
|
||||
|
||||
/* Only handle reset. */
|
||||
if (howto & RB_HALT || howto & RB_POWEROFF)
|
||||
return;
|
||||
|
||||
printf("Resetting system ... ");
|
||||
|
||||
cmd = WD_TO_1SEC;
|
||||
bcmwd_watchdog_fn(sc, cmd, &error);
|
||||
|
||||
/* Wait for watchdog timeout. */
|
||||
DELAY(2000000);
|
||||
|
||||
/* Not reached ... one hopes. */
|
||||
printf("failed to reset (errno %d).\n", error);
|
||||
}
|
||||
|
||||
static device_method_t bcmwd_methods[] = {
|
||||
DEVMETHOD(device_probe, bcmwd_probe),
|
||||
DEVMETHOD(device_attach, bcmwd_attach),
|
||||
|
Loading…
Reference in New Issue
Block a user