Shutdown and reboot on yeeloong

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2010-03-12 14:07:33 +01:00
parent 8d15b3f817
commit f9ef05770a
5 changed files with 72 additions and 5 deletions

View 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

View 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

View file

@ -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

View 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 */

View 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);
}