1*79ef8ec5Sskrll /* $NetBSD: arm32_reboot.c,v 1.13 2020/06/20 07:10:36 skrll Exp $ */
21f4278e1Smatt
31f4278e1Smatt /*
41f4278e1Smatt * Copyright (c) 2002, 2003, 2005 Genetec Corporation. All rights reserved.
51f4278e1Smatt * Written by Hiroyuki Bessho for Genetec Corporation.
61f4278e1Smatt *
71f4278e1Smatt * Redistribution and use in source and binary forms, with or without
81f4278e1Smatt * modification, are permitted provided that the following conditions
91f4278e1Smatt * are met:
101f4278e1Smatt * 1. Redistributions of source code must retain the above copyright
111f4278e1Smatt * notice, this list of conditions and the following disclaimer.
121f4278e1Smatt * 2. Redistributions in binary form must reproduce the above copyright
131f4278e1Smatt * notice, this list of conditions and the following disclaimer in the
141f4278e1Smatt * documentation and/or other materials provided with the distribution.
151f4278e1Smatt * 3. The name of Genetec Corporation may not be used to endorse or
161f4278e1Smatt * promote products derived from this software without specific prior
171f4278e1Smatt * written permission.
181f4278e1Smatt *
191f4278e1Smatt * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
201f4278e1Smatt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
211f4278e1Smatt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
221f4278e1Smatt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENETEC CORPORATION
231f4278e1Smatt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
241f4278e1Smatt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
251f4278e1Smatt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
261f4278e1Smatt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
271f4278e1Smatt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
281f4278e1Smatt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
291f4278e1Smatt * POSSIBILITY OF SUCH DAMAGE.
301f4278e1Smatt *
311f4278e1Smatt * Copyright (c) 2001 Wasabi Systems, Inc.
321f4278e1Smatt * All rights reserved.
331f4278e1Smatt *
341f4278e1Smatt * Written by Jason R. Thorpe for Wasabi Systems, Inc.
351f4278e1Smatt *
361f4278e1Smatt * Redistribution and use in source and binary forms, with or without
371f4278e1Smatt * modification, are permitted provided that the following conditions
381f4278e1Smatt * are met:
391f4278e1Smatt * 1. Redistributions of source code must retain the above copyright
401f4278e1Smatt * notice, this list of conditions and the following disclaimer.
411f4278e1Smatt * 2. Redistributions in binary form must reproduce the above copyright
421f4278e1Smatt * notice, this list of conditions and the following disclaimer in the
431f4278e1Smatt * documentation and/or other materials provided with the distribution.
441f4278e1Smatt * 3. All advertising materials mentioning features or use of this software
451f4278e1Smatt * must display the following acknowledgement:
461f4278e1Smatt * This product includes software developed for the NetBSD Project by
471f4278e1Smatt * Wasabi Systems, Inc.
481f4278e1Smatt * 4. The name of Wasabi Systems, Inc. may not be used to endorse
491f4278e1Smatt * or promote products derived from this software without specific prior
501f4278e1Smatt * written permission.
511f4278e1Smatt *
521f4278e1Smatt * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
531f4278e1Smatt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
541f4278e1Smatt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
551f4278e1Smatt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
561f4278e1Smatt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
571f4278e1Smatt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
581f4278e1Smatt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
591f4278e1Smatt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
601f4278e1Smatt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
611f4278e1Smatt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
621f4278e1Smatt * POSSIBILITY OF SUCH DAMAGE.
631f4278e1Smatt *
641f4278e1Smatt * Copyright (c) 1997,1998 Mark Brinicombe.
651f4278e1Smatt * Copyright (c) 1997,1998 Causality Limited.
661f4278e1Smatt * All rights reserved.
671f4278e1Smatt *
681f4278e1Smatt * Redistribution and use in source and binary forms, with or without
691f4278e1Smatt * modification, are permitted provided that the following conditions
701f4278e1Smatt * are met:
711f4278e1Smatt * 1. Redistributions of source code must retain the above copyright
721f4278e1Smatt * notice, this list of conditions and the following disclaimer.
731f4278e1Smatt * 2. Redistributions in binary form must reproduce the above copyright
741f4278e1Smatt * notice, this list of conditions and the following disclaimer in the
751f4278e1Smatt * documentation and/or other materials provided with the distribution.
761f4278e1Smatt * 3. All advertising materials mentioning features or use of this software
771f4278e1Smatt * must display the following acknowledgement:
781f4278e1Smatt * This product includes software developed by Mark Brinicombe
791f4278e1Smatt * for the NetBSD Project.
801f4278e1Smatt * 4. The name of the company nor the name of the author may be used to
811f4278e1Smatt * endorse or promote products derived from this software without specific
821f4278e1Smatt * prior written permission.
831f4278e1Smatt *
841f4278e1Smatt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
851f4278e1Smatt * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
861f4278e1Smatt * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
871f4278e1Smatt * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
881f4278e1Smatt * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
891f4278e1Smatt * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
901f4278e1Smatt * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
911f4278e1Smatt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
921f4278e1Smatt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
931f4278e1Smatt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
941f4278e1Smatt * SUCH DAMAGE.
951f4278e1Smatt *
961f4278e1Smatt * Copyright (c) 2007 Microsoft
971f4278e1Smatt * All rights reserved.
981f4278e1Smatt *
991f4278e1Smatt * Redistribution and use in source and binary forms, with or without
1001f4278e1Smatt * modification, are permitted provided that the following conditions
1011f4278e1Smatt * are met:
1021f4278e1Smatt * 1. Redistributions of source code must retain the above copyright
1031f4278e1Smatt * notice, this list of conditions and the following disclaimer.
1041f4278e1Smatt * 2. Redistributions in binary form must reproduce the above copyright
1051f4278e1Smatt * notice, this list of conditions and the following disclaimer in the
1061f4278e1Smatt * documentation and/or other materials provided with the distribution.
1071f4278e1Smatt * 3. All advertising materials mentioning features or use of this software
1081f4278e1Smatt * must display the following acknowledgement:
1091f4278e1Smatt * This product includes software developed by Microsoft
1101f4278e1Smatt *
1111f4278e1Smatt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
1121f4278e1Smatt * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
1131f4278e1Smatt * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1141f4278e1Smatt * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTERS BE LIABLE FOR ANY DIRECT,
1151f4278e1Smatt * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1161f4278e1Smatt * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1171f4278e1Smatt * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1181f4278e1Smatt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1191f4278e1Smatt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1201f4278e1Smatt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1211f4278e1Smatt * SUCH DAMAGE.
1221f4278e1Smatt */
1231f4278e1Smatt
1241f4278e1Smatt #include <sys/cdefs.h>
125*79ef8ec5Sskrll __KERNEL_RCSID(0, "$NetBSD: arm32_reboot.c,v 1.13 2020/06/20 07:10:36 skrll Exp $");
1261f4278e1Smatt
1271f4278e1Smatt #include <sys/param.h>
128*79ef8ec5Sskrll
129*79ef8ec5Sskrll #include <dev/cons.h>
1301f4278e1Smatt #include <sys/device.h>
1311f4278e1Smatt #include <sys/kernel.h>
1321f4278e1Smatt #include <sys/reboot.h>
1331f4278e1Smatt
1341f4278e1Smatt #include <uvm/uvm_extern.h>
1351f4278e1Smatt
136ab152917Smatt #include <arm/locore.h>
1371f4278e1Smatt #include <arm/arm32/machdep.h>
1381f4278e1Smatt
1396c9f6128Sjmcneill void (*cpu_powerdown_address)(void);
1406c9f6128Sjmcneill
1418be7f282Smrg static void
docpureset(int howto)142242d3e9bSchristos docpureset(int howto)
143242d3e9bSchristos {
14436039cdeSjmcneill if ((howto & RB_POWERDOWN) == RB_POWERDOWN) {
1456c9f6128Sjmcneill if (cpu_powerdown_address) {
1466c9f6128Sjmcneill cpu_powerdown_address();
1476c9f6128Sjmcneill printf("WARNING: powerdown failed\r\n");
1486c9f6128Sjmcneill } else {
149242d3e9bSchristos printf("WARNING: powerdown not supported\r\n");
1506c9f6128Sjmcneill }
1516c9f6128Sjmcneill }
152242d3e9bSchristos
153242d3e9bSchristos if (howto & RB_HALT) {
154242d3e9bSchristos printf("The operating system has halted.\r\n");
155242d3e9bSchristos printf("Please press any key to reboot.\r\n");
156242d3e9bSchristos cnpollc(true); /* for proper keyboard command handling */
157242d3e9bSchristos /* If there is no keyboard, cngetc() returns 0, so loop */
158242d3e9bSchristos while (cngetc() == 0)
159242d3e9bSchristos delay(100000);
160242d3e9bSchristos cnpollc(false);
161242d3e9bSchristos }
162242d3e9bSchristos
163242d3e9bSchristos printf("rebooting...\r\n");
164242d3e9bSchristos if (cpu_reset_address)
165242d3e9bSchristos (*cpu_reset_address)();
166242d3e9bSchristos cpu_reset();
167242d3e9bSchristos /*NOTREACHED*/
168242d3e9bSchristos }
169242d3e9bSchristos
1701f4278e1Smatt void
cpu_reboot(int howto,char * bootstr)1711f4278e1Smatt cpu_reboot(int howto, char *bootstr)
1721f4278e1Smatt {
1731f4278e1Smatt
1741f4278e1Smatt /*
1751f4278e1Smatt * If we are still cold then hit the air brakes
1761f4278e1Smatt * and crash to earth fast
1771f4278e1Smatt */
1781f4278e1Smatt if (cold) {
1791f4278e1Smatt doshutdownhooks();
180242d3e9bSchristos docpureset(RB_HALT | howto);
1811f4278e1Smatt }
1821f4278e1Smatt
1831f4278e1Smatt /*
1841f4278e1Smatt * If RB_NOSYNC was not specified sync the discs.
1851f4278e1Smatt * Note: Unless cold is set to 1 here, syslogd will die during the
1861f4278e1Smatt * unmount. It looks like syslogd is getting woken up only to find
1871f4278e1Smatt * that it cannot page part of the binary in as the filesystem has
1881f4278e1Smatt * been unmounted.
1891f4278e1Smatt */
1901f4278e1Smatt if (!(howto & RB_NOSYNC))
1911f4278e1Smatt bootsync();
1921f4278e1Smatt
19358f97d34Sskrll /* Say NO to interrupts for the duration of the dump */
19458f97d34Sskrll int s = splhigh();
1951f4278e1Smatt
1961f4278e1Smatt /* Do a dump if requested. */
1971f4278e1Smatt if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
1981f4278e1Smatt dumpsys();
1991f4278e1Smatt
20058f97d34Sskrll splx(s);
2011f4278e1Smatt
2026c456018Sskrll pmf_system_shutdown(boothowto);
2036c456018Sskrll
20458f97d34Sskrll /* Say NO to interrupts for good */
20558f97d34Sskrll splhigh();
20658f97d34Sskrll
20758f97d34Sskrll /* Run any shutdown hooks */
20858f97d34Sskrll doshutdownhooks();
20958f97d34Sskrll
2101f4278e1Smatt /* Make sure IRQ's are disabled */
2111f4278e1Smatt IRQdisable;
2121f4278e1Smatt
213242d3e9bSchristos docpureset(howto);
2142080303bSjoerg __unreachable();
2151f4278e1Smatt }
216