From f9ef05770a365f5ba498329eafc5bb186a64e5ca Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 12 Mar 2010 14:07:33 +0100 Subject: [PATCH] Shutdown and reboot on yeeloong --- conf/mips-yeeloong.rmk | 12 ++++++++++ include/grub/mips/loongson.h | 3 +++ include/grub/mips/yeeloong/ec.h | 41 +++++++++++++++++++++++++++++++++ include/grub/misc.h | 4 ++-- kern/mips/yeeloong/init.c | 17 +++++++++++--- 5 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 include/grub/mips/yeeloong/ec.h diff --git a/conf/mips-yeeloong.rmk b/conf/mips-yeeloong.rmk index 91a2283e8..001bae966 100644 --- a/conf/mips-yeeloong.rmk +++ b/conf/mips-yeeloong.rmk @@ -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 diff --git a/include/grub/mips/loongson.h b/include/grub/mips/loongson.h index 2c69e6c3d..c2aa276a2 100644 --- a/include/grub/mips/loongson.h +++ b/include/grub/mips/loongson.h @@ -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 index 000000000..62d1d33d9 --- /dev/null +++ b/include/grub/mips/yeeloong/ec.h @@ -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 . + */ + +#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 diff --git a/include/grub/misc.h b/include/grub/misc.h index dcbafba87..1a2105549 100644 --- a/include/grub/misc.h +++ b/include/grub/misc.h @@ -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 */ diff --git a/kern/mips/yeeloong/init.c b/kern/mips/yeeloong/init.c index f931cdb57..8a29be8eb 100644 --- a/kern/mips/yeeloong/init.c +++ b/kern/mips/yeeloong/init.c @@ -29,6 +29,8 @@ #include #include #include +#include +#include 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); }