All of lore.kernel.org
 help / color / mirror / Atom feed
* Using GRUB2 with CoreBoot (formerly known as LinuxBIOS) 2/4: Keyboard controller
@ 2008-01-12 17:53 Patrick Georgi
  2008-01-15 18:06 ` Robert Millan
  2008-01-16 13:46 ` Robert Millan
  0 siblings, 2 replies; 7+ messages in thread
From: Patrick Georgi @ 2008-01-12 17:53 UTC (permalink / raw)
  To: grub-devel

Hi,

second installement of my mini-series:

The AT keyboard driver assumes that the keyboard is set to scancode set 
#1. It seems like many keyboards use set #2 (or even #3) by default now, 
and some 8042-emulating chipsets don't enable translation (to #1) by 
default. The BIOS then enables it to support the legacy compatibility the 
PC architecture is famous for - but CoreBoot doesn't.

http://osdever.net/ has some information on programming the 8042 (without 
BIOS calls), incl. how to configure the scancode set you want to have.

Also, 0x01 is the scancode for ESC. I didn't look if there's a special 
case for escapes, but a simple "\e" instead of "\0" at that code point 
might help.

Regards,
Patrick




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Using GRUB2 with CoreBoot (formerly known as LinuxBIOS) 2/4: Keyboard controller
  2008-01-12 17:53 Using GRUB2 with CoreBoot (formerly known as LinuxBIOS) 2/4: Keyboard controller Patrick Georgi
@ 2008-01-15 18:06 ` Robert Millan
  2008-01-15 18:36   ` Patrick Georgi
  2008-01-16 13:46 ` Robert Millan
  1 sibling, 1 reply; 7+ messages in thread
From: Robert Millan @ 2008-01-15 18:06 UTC (permalink / raw)
  To: The development of GRUB 2

On Sat, Jan 12, 2008 at 05:53:42PM +0000, Patrick Georgi wrote:
> Hi,
> 
> second installement of my mini-series:
> 
> The AT keyboard driver assumes that the keyboard is set to scancode set 
> #1. It seems like many keyboards use set #2 (or even #3) by default now, 
> and some 8042-emulating chipsets don't enable translation (to #1) by 
> default. The BIOS then enables it to support the legacy compatibility the 
> PC architecture is famous for - but CoreBoot doesn't.
> 
> http://osdever.net/ has some information on programming the 8042 (without 
> BIOS calls), incl. how to configure the scancode set you want to have.
> 
> Also, 0x01 is the scancode for ESC. I didn't look if there's a special 
> case for escapes, but a simple "\e" instead of "\0" at that code point 
> might help.

Is there a way to reproduce this problem without specific hardware?  (with
qemu or so)

-- 
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call, if you are unable to speak?
(as seen on /.)



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Using GRUB2 with CoreBoot (formerly known as LinuxBIOS) 2/4: Keyboard controller
  2008-01-15 18:06 ` Robert Millan
@ 2008-01-15 18:36   ` Patrick Georgi
  2008-01-15 18:43     ` Robert Millan
  0 siblings, 1 reply; 7+ messages in thread
From: Patrick Georgi @ 2008-01-15 18:36 UTC (permalink / raw)
  To: grub-devel

Am Tue, 15 Jan 2008 19:06:25 +0100 schrieb Robert Millan:
> Is there a way to reproduce this problem without specific hardware? 
> (with qemu or so)
qemu 0.9.0 exhibits this issue here (using coreboot v2 and grub2-cvs). 
the keys "1","2","3" lead to "u","a","l" because of table mismatch.


Regards,
Patrick Georgi




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Using GRUB2 with CoreBoot (formerly known as LinuxBIOS) 2/4: Keyboard controller
  2008-01-15 18:36   ` Patrick Georgi
@ 2008-01-15 18:43     ` Robert Millan
  0 siblings, 0 replies; 7+ messages in thread
From: Robert Millan @ 2008-01-15 18:43 UTC (permalink / raw)
  To: The development of GRUB 2

On Tue, Jan 15, 2008 at 06:36:40PM +0000, Patrick Georgi wrote:
> Am Tue, 15 Jan 2008 19:06:25 +0100 schrieb Robert Millan:
> > Is there a way to reproduce this problem without specific hardware? 
> > (with qemu or so)
> qemu 0.9.0 exhibits this issue here (using coreboot v2 and grub2-cvs). 
> the keys "1","2","3" lead to "u","a","l" because of table mismatch.

Ah yes, I didn't remember about this one, though I've seen it.  I'll have
a look.

-- 
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call, if you are unable to speak?
(as seen on /.)



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Using GRUB2 with CoreBoot (formerly known as LinuxBIOS) 2/4: Keyboard controller
  2008-01-12 17:53 Using GRUB2 with CoreBoot (formerly known as LinuxBIOS) 2/4: Keyboard controller Patrick Georgi
  2008-01-15 18:06 ` Robert Millan
@ 2008-01-16 13:46 ` Robert Millan
  2008-01-16 16:21   ` Robert Millan
  1 sibling, 1 reply; 7+ messages in thread
From: Robert Millan @ 2008-01-16 13:46 UTC (permalink / raw)
  To: The development of GRUB 2

[-- Attachment #1: Type: text/plain, Size: 505 bytes --]


See attached patch.

I don't like the way I had to hook initialisation in console.c, but solving
this properly would require some redesign (converting at_keyboard to a
module, and adding abstraction to handle input and output separately, etc).

But for now I think it's a valid compromise.  I'll wait a bit and see if
nobody objects to it before committing.

-- 
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call… if you are unable to speak?
(as seen on /.)

[-- Attachment #2: atkeyboard.diff --]
[-- Type: text/x-diff, Size: 4519 bytes --]


	* include/grub/i386/linuxbios/console.h: Add header protection.
	(grub_keyboard_controller_init): New function prototype.
	* term/i386/pc/at_keyboard.c (KEYBOARD_COMMAND_ISREADY): New macro.
	(KEYBOARD_COMMAND_READ): Likewise.
	(KEYBOARD_COMMAND_WRITE): Likewise.
	(grub_keyboard_controller_write): New function.
	(grub_keyboard_controller_read): Likewise.
	(grub_keyboard_controller_init): Likewise.

	* term/i386/pc/console.c: Include `<grub/machine/machine.h>'.
	(grub_console_init): On CoreBoot/LinuxBIOS, call
	grub_keyboard_controller_init().

diff -ur ../grub2/include/grub/i386/linuxbios/console.h ./include/grub/i386/linuxbios/console.h
--- ../grub2/include/grub/i386/linuxbios/console.h	2007-10-31 23:35:12.000000000 +0100
+++ ./include/grub/i386/linuxbios/console.h	2008-01-16 14:27:39.000000000 +0100
@@ -1 +1,25 @@
+/*
+ *  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/>.
+ */
+
+#ifndef _GRUB_CONSOLE_MACHINE_LB_HEADER
+#define _GRUB_CONSOLE_MACHINE_LB_HEADER 1
 #include <grub/i386/pc/console.h>
+
+void grub_keyboard_controller_init (void);
+
+#endif /* ! _GRUB_CONSOLE_MACHINE_LB_HEADER */
diff -ur ../grub2/term/i386/pc/at_keyboard.c ./term/i386/pc/at_keyboard.c
--- ../grub2/term/i386/pc/at_keyboard.c	2008-01-03 23:43:46.000000000 +0100
+++ ./term/i386/pc/at_keyboard.c	2008-01-16 14:34:41.000000000 +0100
@@ -1,6 +1,6 @@
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 2007  Free Software Foundation, Inc.
+ *  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
@@ -37,6 +37,11 @@
 #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_ISMAKE(x)	!((x) & 0x80)
 #define KEYBOARD_ISREADY(x)	(((x) & 0x01) == 0)
 #define KEYBOARD_SCANCODE(x)	((x) & 0x7f)
@@ -73,6 +78,28 @@
   '2', '3',
 };
 
+static void
+grub_keyboard_controller_write (grub_uint8_t c)
+{
+  while (! KEYBOARD_COMMAND_ISREADY (grub_inb (KEYBOARD_REG_STATUS)));
+  grub_outb (KEYBOARD_COMMAND_WRITE, KEYBOARD_REG_STATUS);
+  grub_outb (c, KEYBOARD_REG_DATA);
+}
+
+static grub_uint8_t
+grub_keyboard_controller_read (void)
+{
+  while (! KEYBOARD_COMMAND_ISREADY (grub_inb (KEYBOARD_REG_STATUS)));
+  grub_outb (KEYBOARD_COMMAND_READ, KEYBOARD_REG_STATUS);
+  return grub_inb (KEYBOARD_REG_DATA);
+}
+
+void
+grub_keyboard_controller_init (void)
+{
+  grub_keyboard_controller_write (grub_keyboard_controller_read () | 0x40);
+}
+
 /* FIXME: This should become an interrupt service routine.  For now
    it's just used to catch events from control keys.  */
 static void
diff -ur ../grub2/term/i386/pc/console.c ./term/i386/pc/console.c
--- ../grub2/term/i386/pc/console.c	2007-12-25 12:10:46.000000000 +0100
+++ ./term/i386/pc/console.c	2008-01-16 14:28:02.000000000 +0100
@@ -1,6 +1,6 @@
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 2002,2003,2005,2007  Free Software Foundation, Inc.
+ *  Copyright (C) 2002,2003,2005,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
@@ -16,6 +16,7 @@
  *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <grub/machine/machine.h>
 #include <grub/machine/console.h>
 #include <grub/term.h>
 #include <grub/types.h>
@@ -148,6 +149,10 @@
 void
 grub_console_init (void)
 {
+#ifdef GRUB_MACHINE_LINUXBIOS
+  grub_keyboard_controller_init ();
+#endif
+
   grub_term_register (&grub_console_term);
   grub_term_set_current (&grub_console_term);
 }

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Using GRUB2 with CoreBoot (formerly known as LinuxBIOS) 2/4: Keyboard controller
  2008-01-16 13:46 ` Robert Millan
@ 2008-01-16 16:21   ` Robert Millan
  2008-01-19 11:44     ` Robert Millan
  0 siblings, 1 reply; 7+ messages in thread
From: Robert Millan @ 2008-01-16 16:21 UTC (permalink / raw)
  To: The development of GRUB 2

[-- Attachment #1: Type: text/plain, Size: 658 bytes --]

On Wed, Jan 16, 2008 at 02:46:41PM +0100, Robert Millan wrote:
> 
> See attached patch.
> 
> I don't like the way I had to hook initialisation in console.c, but solving
> this properly would require some redesign (converting at_keyboard to a
> module, and adding abstraction to handle input and output separately, etc).
> 
> But for now I think it's a valid compromise.  I'll wait a bit and see if
> nobody objects to it before committing.

I forgot to macroify KEYBOARD_SCANCODE_SET1.  Here's an updated patch.

-- 
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call… if you are unable to speak?
(as seen on /.)

[-- Attachment #2: atkeyboard.diff --]
[-- Type: text/x-diff, Size: 4732 bytes --]


	* include/grub/i386/linuxbios/console.h: Add header protection.
	(grub_keyboard_controller_init): New function prototype.
	* term/i386/pc/at_keyboard.c (KEYBOARD_COMMAND_ISREADY): New macro.
	(KEYBOARD_COMMAND_READ): Likewise.
	(KEYBOARD_COMMAND_WRITE): Likewise.
	(KEYBOARD_SCANCODE_SET1): Likewise.
	(grub_keyboard_controller_write): New function.
	(grub_keyboard_controller_read): Likewise.
	(grub_keyboard_controller_init): Likewise.

	* term/i386/pc/console.c: Include `<grub/machine/machine.h>'.
	(grub_console_init): On CoreBoot/LinuxBIOS, call
	grub_keyboard_controller_init().

diff -pur grub2/include/grub/i386/linuxbios/console.h atkeyboard/include/grub/i386/linuxbios/console.h
--- grub2/include/grub/i386/linuxbios/console.h	2007-10-31 23:35:12.000000000 +0100
+++ atkeyboard/include/grub/i386/linuxbios/console.h	2008-01-16 17:15:11.000000000 +0100
@@ -1 +1,25 @@
+/*
+ *  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/>.
+ */
+
+#ifndef _GRUB_CONSOLE_MACHINE_LB_HEADER
+#define _GRUB_CONSOLE_MACHINE_LB_HEADER 1
 #include <grub/i386/pc/console.h>
+
+void grub_keyboard_controller_init (void);
+
+#endif /* ! _GRUB_CONSOLE_MACHINE_LB_HEADER */
diff -pur grub2/term/i386/pc/at_keyboard.c atkeyboard/term/i386/pc/at_keyboard.c
--- grub2/term/i386/pc/at_keyboard.c	2008-01-03 23:43:46.000000000 +0100
+++ atkeyboard/term/i386/pc/at_keyboard.c	2008-01-16 17:19:36.000000000 +0100
@@ -1,6 +1,6 @@
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 2007  Free Software Foundation, Inc.
+ *  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
@@ -37,6 +37,13 @@
 #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)
@@ -73,6 +80,28 @@ static char keyboard_map_shift[128] =
   '2', '3',
 };
 
+static void
+grub_keyboard_controller_write (grub_uint8_t c)
+{
+  while (! KEYBOARD_COMMAND_ISREADY (grub_inb (KEYBOARD_REG_STATUS)));
+  grub_outb (KEYBOARD_COMMAND_WRITE, KEYBOARD_REG_STATUS);
+  grub_outb (c, KEYBOARD_REG_DATA);
+}
+
+static grub_uint8_t
+grub_keyboard_controller_read (void)
+{
+  while (! KEYBOARD_COMMAND_ISREADY (grub_inb (KEYBOARD_REG_STATUS)));
+  grub_outb (KEYBOARD_COMMAND_READ, KEYBOARD_REG_STATUS);
+  return grub_inb (KEYBOARD_REG_DATA);
+}
+
+void
+grub_keyboard_controller_init (void)
+{
+  grub_keyboard_controller_write (grub_keyboard_controller_read () | KEYBOARD_SCANCODE_SET1);
+}
+
 /* FIXME: This should become an interrupt service routine.  For now
    it's just used to catch events from control keys.  */
 static void
diff -pur grub2/term/i386/pc/console.c atkeyboard/term/i386/pc/console.c
--- grub2/term/i386/pc/console.c	2007-12-25 12:10:46.000000000 +0100
+++ atkeyboard/term/i386/pc/console.c	2008-01-16 17:15:11.000000000 +0100
@@ -1,6 +1,6 @@
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 2002,2003,2005,2007  Free Software Foundation, Inc.
+ *  Copyright (C) 2002,2003,2005,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
@@ -16,6 +16,7 @@
  *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <grub/machine/machine.h>
 #include <grub/machine/console.h>
 #include <grub/term.h>
 #include <grub/types.h>
@@ -148,6 +149,10 @@ static struct grub_term grub_console_ter
 void
 grub_console_init (void)
 {
+#ifdef GRUB_MACHINE_LINUXBIOS
+  grub_keyboard_controller_init ();
+#endif
+
   grub_term_register (&grub_console_term);
   grub_term_set_current (&grub_console_term);
 }

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Using GRUB2 with CoreBoot (formerly known as LinuxBIOS) 2/4: Keyboard controller
  2008-01-16 16:21   ` Robert Millan
@ 2008-01-19 11:44     ` Robert Millan
  0 siblings, 0 replies; 7+ messages in thread
From: Robert Millan @ 2008-01-19 11:44 UTC (permalink / raw)
  To: The development of GRUB 2

On Wed, Jan 16, 2008 at 05:21:00PM +0100, Robert Millan wrote:
> On Wed, Jan 16, 2008 at 02:46:41PM +0100, Robert Millan wrote:
> > 
> > See attached patch.
> > 
> > I don't like the way I had to hook initialisation in console.c, but solving
> > this properly would require some redesign (converting at_keyboard to a
> > module, and adding abstraction to handle input and output separately, etc).
> > 
> > But for now I think it's a valid compromise.  I'll wait a bit and see if
> > nobody objects to it before committing.
> 
> I forgot to macroify KEYBOARD_SCANCODE_SET1.  Here's an updated patch.

Ok, committed.  Hopefuly, this will look better when we start using
at_keyboard.c on PC/BIOS systems.

-- 
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call… if you are unable to speak?
(as seen on /.)



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2008-01-19 11:46 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-12 17:53 Using GRUB2 with CoreBoot (formerly known as LinuxBIOS) 2/4: Keyboard controller Patrick Georgi
2008-01-15 18:06 ` Robert Millan
2008-01-15 18:36   ` Patrick Georgi
2008-01-15 18:43     ` Robert Millan
2008-01-16 13:46 ` Robert Millan
2008-01-16 16:21   ` Robert Millan
2008-01-19 11:44     ` Robert Millan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.