This implements power management on coreboot.  reboot is (AFAIK) fairly
generic, but halt is hardware-specific (currently it only supports bochs
and friends).

-- 
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
2008-08-04  Robert Millan  <[EMAIL PROTECTED]>

	* conf/i386-coreboot.rmk (pkglib_MODULES): Add `reboot.mod' and `halt.mod'.
	(reboot_mod_SOURCES, reboot_mod_CFLAGS, reboot_mod_LDFLAGS)
	(halt_mod_SOURCES, halt_mod_CFLAGS, halt_mod_LDFLAGS): New variables.

	* kern/i386/halt.c: New file.  Standalone halt implementation.
	* kern/i386/reboot.c: New file.  Standalone reboot implementation.

	* include/grub/i386/reboot.h: New file.
	* include/grub/i386/halt.h: New file.

	* term/i386/pc/at_keyboard.c (SHIFT_L, SHIFT_R, CTRL, ALT, CAPS_LOCK)
	(KEYBOARD_REG_DATA, KEYBOARD_REG_STATUS)
	(KEYBOARD_COMMAND_ISREADY, KEYBOARD_COMMAND_READ)
	(KEYBOARD_COMMAND_WRITE, KEYBOARD_COMMAND_REBOOT)
	(KEYBOARD_SCANCODE_SET1, KEYBOARD_ISMAKE, KEYBOARD_ISREADY)
	(KEYBOARD_SCANCODE, OLPC_UP, OLPC_DOWN, OLPC_LEFT, OLPC_RIGHT): Move
	macros from here ...
	* include/grub/i386/at_keyboard.h: ... to here.

	* commands/halt.c [!GRUB_MACHINE_IEEE1275 !GRUB_MACHINE_EFI]: Include
	`<grub/cpu/halt.h>'
	* commands/reboot.c [!GRUB_MACHINE_IEEE1275 !GRUB_MACHINE_EFI]: Include
	`<grub/cpu/reboot.h>'

Index: conf/i386-coreboot.rmk
===================================================================
--- conf/i386-coreboot.rmk	(revision 1770)
+++ conf/i386-coreboot.rmk	(working copy)
@@ -95,7 +95,8 @@
 pkglib_MODULES = _linux.mod linux.mod normal.mod	\
 	_multiboot.mod multiboot.mod aout.mod		\
 	play.mod cpuid.mod serial.mod ata.mod		\
-	memdisk.mod pci.mod lspci.mod
+	memdisk.mod pci.mod lspci.mod reboot.mod	\
+	halt.mod
 
 # For _linux.mod.
 _linux_mod_SOURCES = loader/i386/pc/linux.c
@@ -117,6 +118,16 @@
 normal_mod_ASFLAGS = $(COMMON_ASFLAGS)
 normal_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
+# For reboot.mod.
+reboot_mod_SOURCES = commands/reboot.c kern/i386/reboot.c
+reboot_mod_CFLAGS = $(COMMON_CFLAGS)
+reboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+# For halt.mod.
+halt_mod_SOURCES = commands/halt.c kern/i386/halt.c
+halt_mod_CFLAGS = $(COMMON_CFLAGS)
+halt_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
 # For serial.mod.
 serial_mod_SOURCES = term/i386/pc/serial.c
 serial_mod_CFLAGS = $(COMMON_CFLAGS)
Index: kern/i386/halt.c
===================================================================
--- kern/i386/halt.c	(revision 0)
+++ kern/i386/halt.c	(revision 0)
@@ -0,0 +1,42 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2008  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/>.
+ */
+
+#include <grub/cpu/io.h>
+#include <grub/cpu/halt.h>
+#include <grub/misc.h>
+
+const char bochs_shutdown[] = "Shutdown";
+
+void
+grub_halt (void)
+{
+  char *p;
+
+  /* Disable interrupts.  */
+  __asm__ __volatile__ ("cli");
+
+  /* Bochs, QEMU, etc.  */
+  for (p = bochs_shutdown; *p || *(p-1); p++)
+    grub_outb (*p, 0x8900);
+
+  grub_printf ("GRUB doesn't know how to halt this machine yet!\n");
+
+  /* In order to return we'd have to check what the previous status of IF
+     flag was.  But user most likely doesn't want to return anyway ...  */
+  grub_stop ();
+}
Index: kern/i386/reboot.c
===================================================================
--- kern/i386/reboot.c	(revision 0)
+++ kern/i386/reboot.c	(revision 0)
@@ -0,0 +1,31 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2008  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/>.
+ */
+
+#include <grub/cpu/io.h>
+#include <grub/cpu/at_keyboard.h>
+#include <grub/misc.h>
+
+void
+grub_reboot (void)
+{
+  /* Use the keyboard controller to reboot.  That's what keyboards were
+     designed for, isn't it?  */
+  grub_outb (KEYBOARD_COMMAND_REBOOT, KEYBOARD_REG_STATUS);
+
+  grub_printf ("GRUB doesn't know how to reboot this machine yet!\n");
+}
Index: include/grub/i386/reboot.h
===================================================================
--- include/grub/i386/reboot.h	(revision 0)
+++ include/grub/i386/reboot.h	(revision 0)
@@ -0,0 +1,19 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2008  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/>.
+ */
+
+extern void grub_reboot (void);
Index: include/grub/i386/at_keyboard.h
===================================================================
--- include/grub/i386/at_keyboard.h	(revision 0)
+++ include/grub/i386/at_keyboard.h	(revision 0)
@@ -0,0 +1,57 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2007,2008  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_CPU_AT_KEYBOARD_HEADER
+#define GRUB_CPU_AT_KEYBOARD_HEADER	1
+
+#include <grub/machine/machine.h>
+
+#define SHIFT_L		0x2a
+#define SHIFT_R		0x36
+#define CTRL		0x1d
+#define ALT		0x38
+#define CAPS_LOCK	0x3a
+
+#define KEYBOARD_REG_DATA	0x60
+#define KEYBOARD_REG_STATUS	0x64
+
+/* Used for sending commands to the controller.  */
+#define KEYBOARD_COMMAND_ISREADY(x)	!((x) & 0x02)
+#define KEYBOARD_COMMAND_READ		0x20
+#define KEYBOARD_COMMAND_WRITE		0x60
+#define KEYBOARD_COMMAND_REBOOT		0xfe
+
+#define KEYBOARD_SCANCODE_SET1		0x40
+
+#define KEYBOARD_ISMAKE(x)	!((x) & 0x80)
+#define KEYBOARD_ISREADY(x)	(((x) & 0x01) == 0)
+#define KEYBOARD_SCANCODE(x)	((x) & 0x7f)
+
+#ifdef GRUB_MACHINE_IEEE1275
+#define OLPC_UP		GRUB_TERM_UP
+#define OLPC_DOWN	GRUB_TERM_DOWN
+#define OLPC_LEFT	GRUB_TERM_LEFT
+#define OLPC_RIGHT	GRUB_TERM_RIGHT
+#else
+#define OLPC_UP		'\0'
+#define OLPC_DOWN	'\0'
+#define OLPC_LEFT	'\0'
+#define OLPC_RIGHT	'\0'
+#endif
+
+#endif
Index: include/grub/i386/halt.h
===================================================================
--- include/grub/i386/halt.h	(revision 0)
+++ include/grub/i386/halt.h	(revision 0)
@@ -0,0 +1,19 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2008  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/>.
+ */
+
+extern void grub_halt (void);
Index: commands/halt.c
===================================================================
--- commands/halt.c	(revision 1768)
+++ commands/halt.c	(working copy)
@@ -25,6 +25,9 @@
 #include <grub/machine/kernel.h>
 #elif defined(GRUB_MACHINE_EFI)
 #include <grub/efi/efi.h>
+#else
+/* Platforms shipping standalone halt, such as coreboot.  */
+#include <grub/cpu/halt.h>
 #endif
 
 static grub_err_t
Index: commands/reboot.c
===================================================================
--- commands/reboot.c	(revision 1768)
+++ commands/reboot.c	(working copy)
@@ -27,6 +27,9 @@
 #include <grub/efi/efi.h>
 #elif defined(GRUB_MACHINE_PCBIOS)
 #include <grub/machine/init.h>
+#else
+/* Platforms shipping standalone reboot, such as coreboot.  */
+#include <grub/cpu/reboot.h>
 #endif
 
 
Index: term/i386/pc/at_keyboard.c
===================================================================
--- term/i386/pc/at_keyboard.c	(revision 1768)
+++ term/i386/pc/at_keyboard.c	(working copy)
@@ -17,16 +17,12 @@
  */
 
 #include <grub/machine/console.h>
-#include <grub/machine/machine.h>
+#include <grub/cpu/at_keyboard.h>
 #include <grub/cpu/io.h>
 #include <grub/misc.h>
 #include <grub/term.h>
 
-#define SHIFT_L		0x2a
-#define SHIFT_R		0x36
-#define CTRL		0x1d
-#define ALT		0x38
-#define CAPS_LOCK	0x3a
+static short at_keyboard_status = 0;
 
 #define KEYBOARD_STATUS_SHIFT_L		(1 << 0)
 #define KEYBOARD_STATUS_SHIFT_R		(1 << 1)
@@ -36,34 +32,6 @@
 #define KEYBOARD_STATUS_CTRL_R		(1 << 5)
 #define KEYBOARD_STATUS_CAPS_LOCK	(1 << 6)
 
-#define KEYBOARD_REG_DATA	0x60
-#define KEYBOARD_REG_STATUS	0x64
-
-/* Used for sending commands to the controller.  */
-#define KEYBOARD_COMMAND_ISREADY(x)	!((x) & 0x02)
-#define KEYBOARD_COMMAND_READ		0x20
-#define KEYBOARD_COMMAND_WRITE		0x60
-
-#define KEYBOARD_SCANCODE_SET1		0x40
-
-#define KEYBOARD_ISMAKE(x)	!((x) & 0x80)
-#define KEYBOARD_ISREADY(x)	(((x) & 0x01) == 0)
-#define KEYBOARD_SCANCODE(x)	((x) & 0x7f)
-
-static short at_keyboard_status = 0;
-
-#ifdef GRUB_MACHINE_IEEE1275
-#define OLPC_UP		GRUB_TERM_UP
-#define OLPC_DOWN	GRUB_TERM_DOWN
-#define OLPC_LEFT	GRUB_TERM_LEFT
-#define OLPC_RIGHT	GRUB_TERM_RIGHT
-#else
-#define OLPC_UP		'\0'
-#define OLPC_DOWN	'\0'
-#define OLPC_LEFT	'\0'
-#define OLPC_RIGHT	'\0'
-#endif
-
 static char keyboard_map[128] =
 {
   '\0', GRUB_TERM_ESC, '1', '2', '3', '4', '5', '6',
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to