]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
Shutdown and reboot on yeeloong
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Fri, 12 Mar 2010 13:07:33 +0000 (14:07 +0100)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Fri, 12 Mar 2010 13:07:33 +0000 (14:07 +0100)
conf/mips-yeeloong.rmk
include/grub/mips/loongson.h
include/grub/mips/yeeloong/ec.h [new file with mode: 0644]
include/grub/misc.h
kern/mips/yeeloong/init.c

index 91a2283e8648aa31e7415fe861b3dc0c710a38db..001bae966d7a212e1cd444a1338010e1a050315e 100644 (file)
@@ -98,6 +98,18 @@ linux_mod_CFLAGS = $(COMMON_CFLAGS)
 linux_mod_ASFLAGS = $(COMMON_ASFLAGS)
 linux_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
+# For halt.mod.
+pkglib_MODULES += halt.mod
+halt_mod_SOURCES = commands/halt.c
+halt_mod_CFLAGS = $(COMMON_CFLAGS)
+halt_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+# For reboot.mod.
+pkglib_MODULES += reboot.mod
+reboot_mod_SOURCES = commands/reboot.c
+reboot_mod_CFLAGS = $(COMMON_CFLAGS)
+reboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
 sbin_SCRIPTS += grub-install
 grub_install_SOURCES = util/grub-install.in
 
index 2c69e6c3d859a3c6061033948f93fe65ed26e58b..c2aa276a2aecbdb5ba8f1fd9dcaef9b1569e2c95 100644 (file)
@@ -68,4 +68,7 @@
 #define GRUB_CPU_LOONGSON_ROM_DELAY_OFFSET 2
 #define GRUB_CPU_LOONGSON_ROM_DELAY_MASK 0x1f
 
+#define GRUB_CPU_LOONGSON_GPIOCFG  0xbfe00120
+#define GRUB_CPU_LOONGSON_SHUTDOWN_GPIO 1
+
 #endif
diff --git a/include/grub/mips/yeeloong/ec.h b/include/grub/mips/yeeloong/ec.h
new file mode 100644 (file)
index 0000000..62d1d33
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2010  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB 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.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_EC_MACHINE_HEADER
+#define GRUB_EC_MACHINE_HEADER 1
+
+#define GRUB_MACHINE_EC_MAGIC_PORT1 0x381
+#define GRUB_MACHINE_EC_MAGIC_PORT2 0x382
+#define GRUB_MACHINE_EC_DATA_PORT 0x383
+
+#define GRUB_MACHINE_EC_MAGIC_VAL1 0xf4
+#define GRUB_MACHINE_EC_MAGIC_VAL2 0xec
+
+#define GRUB_MACHINE_EC_COMMAND_REBOOT 1
+
+static inline void
+grub_write_ec (grub_uint8_t value)
+{
+  grub_outb (GRUB_MACHINE_EC_MAGIC_VAL1,
+            GRUB_MACHINE_PCI_IO_BASE + GRUB_MACHINE_EC_MAGIC_PORT1);
+  grub_outb (GRUB_MACHINE_EC_MAGIC_VAL2,
+            GRUB_MACHINE_PCI_IO_BASE + GRUB_MACHINE_EC_MAGIC_PORT2);
+  grub_outb (value, GRUB_MACHINE_PCI_IO_BASE + GRUB_MACHINE_EC_DATA_PORT);
+}
+
+#endif
index dcbafba876f1cfd15384f4c84d9449c44963bb50..1a2105549b26e174661863b8ea621c70ec46d6ed 100644 (file)
@@ -298,9 +298,9 @@ void EXPORT_FUNC (grub_reboot) (void);
 #ifdef GRUB_MACHINE_PCBIOS
 /* Halt the system, using APM if possible. If NO_APM is true, don't
  * use APM even if it is available.  */
-void EXPORT_FUNC (grub_halt) (int no_apm);
+void EXPORT_FUNC (grub_halt) (int no_apm) __attribute__ ((noreturn));
 #else
-void EXPORT_FUNC (grub_halt) (void);
+void EXPORT_FUNC (grub_halt) (void) __attribute__ ((noreturn));
 #endif
 
 #endif /* ! GRUB_MISC_HEADER */
index f931cdb57db5e169a231da8626bef6f4b6c22dcf..8a29be8eb9cef8a9fd1b114d18e4126cd001659d 100644 (file)
@@ -29,6 +29,8 @@
 #include <grub/mips/loongson.h>
 #include <grub/cpu/kernel.h>
 #include <grub/cs5536.h>
+#include <grub/term.h>
+#include <grub/machine/ec.h>
 
 extern void grub_video_sm712_init (void);
 extern void grub_video_video_init (void);
@@ -165,20 +167,29 @@ grub_machine_fini (void)
 }
 
 void
-grub_exit (void)
+grub_halt (void)
 {
+  grub_outb (grub_inb (GRUB_CPU_LOONGSON_GPIOCFG)
+            & ~GRUB_CPU_LOONGSON_SHUTDOWN_GPIO, GRUB_CPU_LOONGSON_GPIOCFG);
+
+  grub_printf ("Shutdown failed\n");
+  grub_refresh ();
   while (1);
 }
 
 void
-grub_halt (void)
+grub_exit (void)
 {
-  while (1);
+  grub_halt ();
 }
 
 void
 grub_reboot (void)
 {
+  grub_write_ec (GRUB_MACHINE_EC_COMMAND_REBOOT);
+
+  grub_printf ("Reboot failed\n");
+  grub_refresh ();
   while (1);
 }