Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1KPyZX-00022z-6l for mharc-grub-devel@gnu.org; Mon, 04 Aug 2008 07:49:55 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KPyZV-00022l-A3 for grub-devel@gnu.org; Mon, 04 Aug 2008 07:49:53 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KPyZU-00022Z-2v for grub-devel@gnu.org; Mon, 04 Aug 2008 07:49:52 -0400 Received: from [199.232.76.173] (port=35288 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KPyZT-00022W-Tt for grub-devel@gnu.org; Mon, 04 Aug 2008 07:49:51 -0400 Received: from aybabtu.com ([69.60.117.155]:39134) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KPyZT-00039c-DY for grub-devel@gnu.org; Mon, 04 Aug 2008 07:49:51 -0400 Received: from [192.168.10.10] (helo=thorin) by aybabtu.com with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1KPySF-0005kK-AC for grub-devel@gnu.org; Mon, 04 Aug 2008 13:42:24 +0200 Received: from rmh by thorin with local (Exim 4.63) (envelope-from ) id 1KPyYD-00013I-9h for grub-devel@gnu.org; Mon, 04 Aug 2008 13:48:33 +0200 Date: Mon, 4 Aug 2008 13:48:33 +0200 From: Robert Millan To: grub-devel@gnu.org Message-ID: <20080804114833.GA3724@thorin> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="OgqxwSJOaUobr8KG" Content-Disposition: inline Organization: free as in freedom X-Message-Flag: Worried about Outlook viruses? Switch to Thunderbird! www.mozilla.com/thunderbird X-Debbugs-No-Ack: true User-Agent: Mutt/1.5.13 (2006-08-11) X-detected-kernel: by monty-python.gnu.org: Genre and OS details not recognized. Subject: [PATCH] power management on coreboot X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Aug 2008 11:49:53 -0000 --OgqxwSJOaUobr8KG Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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." --OgqxwSJOaUobr8KG Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="power_management.diff" 2008-08-04 Robert Millan * 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 `' * commands/reboot.c [!GRUB_MACHINE_IEEE1275 !GRUB_MACHINE_EFI]: Include `' 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 . + */ + +#include +#include +#include + +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 . + */ + +#include +#include +#include + +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 . + */ + +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 . + */ + +#ifndef GRUB_CPU_AT_KEYBOARD_HEADER +#define GRUB_CPU_AT_KEYBOARD_HEADER 1 + +#include + +#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 . + */ + +extern void grub_halt (void); Index: commands/halt.c =================================================================== --- commands/halt.c (revision 1768) +++ commands/halt.c (working copy) @@ -25,6 +25,9 @@ #include #elif defined(GRUB_MACHINE_EFI) #include +#else +/* Platforms shipping standalone halt, such as coreboot. */ +#include #endif static grub_err_t Index: commands/reboot.c =================================================================== --- commands/reboot.c (revision 1768) +++ commands/reboot.c (working copy) @@ -27,6 +27,9 @@ #include #elif defined(GRUB_MACHINE_PCBIOS) #include +#else +/* Platforms shipping standalone reboot, such as coreboot. */ +#include #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 -#include +#include #include #include #include -#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', --OgqxwSJOaUobr8KG--