From: "H. Peter Anvin" <hpa@zytor.com>
To: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org,
andi@firstfloor.org, akpm@linux-foundation.org
Cc: "H. Peter Anvin" <hpa@zytor.com>
Subject: [x86 setup 17/33] A20 handling code
Date: Mon, 9 Jul 2007 19:51:56 -0700 [thread overview]
Message-ID: <11840377211519-git-send-email-hpa@zytor.com> (raw)
Message-ID: <17db5b2c8a43cf36b2eb36afc142ce9ca0552282.1184032749.git.hpa@zytor.com> (raw)
In-Reply-To: <11840376162370-git-send-email-hpa@zytor.com>
In-Reply-To: <2034f71d414def30de582fb59573295cadbdabb4.1184032748.git.hpa@zytor.com>
From: H. Peter Anvin <hpa@zytor.com>
A20 handling code for the new x86 setup code. This implements the same
algorithms as the assembly version.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
arch/i386/boot/a20.c | 161 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 161 insertions(+), 0 deletions(-)
create mode 100644 arch/i386/boot/a20.c
diff --git a/arch/i386/boot/a20.c b/arch/i386/boot/a20.c
new file mode 100644
index 0000000..31348d0
--- /dev/null
+++ b/arch/i386/boot/a20.c
@@ -0,0 +1,161 @@
+/* -*- linux-c -*- ------------------------------------------------------- *
+ *
+ * Copyright (C) 1991, 1992 Linus Torvalds
+ * Copyright 2007 rPath, Inc. - All Rights Reserved
+ *
+ * This file is part of the Linux kernel, and is made available under
+ * the terms of the GNU General Public License version 2.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * arch/i386/boot/a20.c
+ *
+ * Enable A20 gate (return -1 on failure)
+ */
+
+#include "boot.h"
+
+#define MAX_8042_LOOPS 100000
+
+static int empty_8042(void)
+{
+ u8 status;
+ int loops = MAX_8042_LOOPS;
+
+ while (loops--) {
+ io_delay();
+
+ status = inb(0x64);
+ if (status & 1) {
+ /* Read and discard input data */
+ io_delay();
+ (void)inb(0x60);
+ } else if (!(status & 2)) {
+ /* Buffers empty, finished! */
+ return 0;
+ }
+ }
+
+ return -1;
+}
+
+/* Returns nonzero if the A20 line is enabled. The memory address
+ used as a test is the int $0x80 vector, which should be safe. */
+
+#define A20_TEST_ADDR (4*0x80)
+#define A20_TEST_SHORT 32
+#define A20_TEST_LONG 2097152 /* 2^21 */
+
+static int a20_test(int loops)
+{
+ int ok = 0;
+ int saved, ctr;
+
+ set_fs(0x0000);
+ set_gs(0xffff);
+
+ saved = ctr = rdfs32(A20_TEST_ADDR);
+
+ while (loops--) {
+ wrfs32(++ctr, A20_TEST_ADDR);
+ io_delay(); /* Serialize and make delay constant */
+ ok = rdgs32(A20_TEST_ADDR+0x10) ^ ctr;
+ if (ok)
+ break;
+ }
+
+ wrfs32(saved, A20_TEST_ADDR);
+ return ok;
+}
+
+/* Quick test to see if A20 is already enabled */
+static int a20_test_short(void)
+{
+ return a20_test(A20_TEST_SHORT);
+}
+
+/* Longer test that actually waits for A20 to come on line; this
+ is useful when dealing with the KBC or other slow external circuitry. */
+static int a20_test_long(void)
+{
+ return a20_test(A20_TEST_LONG);
+}
+
+static void enable_a20_bios(void)
+{
+ asm volatile("pushfl; int $0x15; popfl"
+ : : "a" ((u16)0x2401));
+}
+
+static void enable_a20_kbc(void)
+{
+ empty_8042();
+
+ outb(0xd1, 0x64); /* Command write */
+ empty_8042();
+
+ outb(0xdf, 0x60); /* A20 on */
+ empty_8042();
+}
+
+static void enable_a20_fast(void)
+{
+ u8 port_a;
+
+ port_a = inb(0x92); /* Configuration port A */
+ port_a |= 0x02; /* Enable A20 */
+ port_a &= ~0x01; /* Do not reset machine */
+ outb(port_a, 0x92);
+}
+
+/*
+ * Actual routine to enable A20; return 0 on ok, -1 on failure
+ */
+
+#define A20_ENABLE_LOOPS 255 /* Number of times to try */
+
+int enable_a20(void)
+{
+ int loops = A20_ENABLE_LOOPS;
+
+#if defined(CONFIG_X86_ELAN)
+ /* Elan croaks if we try to touch the KBC */
+ enable_a20_fast();
+ while (!a20_test_long())
+ ;
+ return 0;
+#elif defined(CONFIG_X86_VOYAGER)
+ /* On Voyager, a20_test() is unsafe? */
+ enable_a20_kbc();
+ return 0;
+#else
+ while (loops--) {
+ /* First, check to see if A20 is already enabled
+ (legacy free, etc.) */
+ if (a20_test_short())
+ return 0;
+
+ /* Next, try the BIOS (INT 0x15, AX=0x2401) */
+ enable_a20_bios();
+ if (a20_test_short())
+ return 0;
+
+ /* Try enabling A20 through the keyboard controller */
+ empty_8042();
+ if (a20_test_short())
+ return 0; /* BIOS worked, but with delayed reaction */
+
+ enable_a20_kbc();
+ if (a20_test_long())
+ return 0;
+
+ /* Finally, try enabling the "fast A20 gate" */
+ enable_a20_fast();
+ if (a20_test_long())
+ return 0;
+ }
+
+ return -1;
+#endif
+}
--
1.5.2.2
next prev parent reply other threads:[~2007-07-10 3:28 UTC|newest]
Thread overview: 71+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-10 2:51 x86 setup code rewrite in C H. Peter Anvin
2007-07-10 2:51 ` [x86 setup 01/33] x86 setup: MAINTAINERS: formally take responsibility for the i386 boot code H. Peter Anvin
2007-07-10 2:51 ` H. Peter Anvin
2007-07-10 2:51 ` [x86 setup 02/33] hd.c: remove BIOS/CMOS queries H. Peter Anvin
2007-07-10 2:51 ` H. Peter Anvin
2007-07-10 2:51 ` [x86 setup 03/33] include/asm-i386/boot.h: This is <asm/boot.h>, not <linux/boot.h> H. Peter Anvin
2007-07-10 2:51 ` H. Peter Anvin
2007-07-10 2:51 ` [x86 setup 04/33] Unify the CPU features vectors between i386 and x86-64 H. Peter Anvin
2007-07-10 2:51 ` H. Peter Anvin
2007-07-10 2:51 ` [x86 setup 05/33] Change CONFIG_X86_MINIMUM_CPU_MODEL to CONFIG_X86_MINIMUM_CPU_FAMILY H. Peter Anvin
2007-07-10 2:51 ` H. Peter Anvin
2007-07-10 2:51 ` [x86 setup 06/33] Clean up struct screen_info (<linux/screen_info.h>) H. Peter Anvin
2007-07-10 2:51 ` H. Peter Anvin
2007-07-10 2:51 ` [x86 setup 07/33] Use a new CPU feature word to cover all Intel features that are spread around H. Peter Anvin
2007-07-10 2:51 ` H. Peter Anvin
2007-07-10 2:51 ` [x86 setup 08/33] Define zero-page offset 0x1e4 as a scratch field, and use it H. Peter Anvin
2007-07-10 2:51 ` H. Peter Anvin
2007-07-10 2:51 ` [x86 setup 09/33] Make definitions for struct e820entry and struct e820map consistent H. Peter Anvin
2007-07-10 2:51 ` H. Peter Anvin
2007-07-10 11:48 ` Andi Kleen
2007-07-10 2:51 ` [x86 setup 10/33] Make struct boot_params a real structure, and remove obsolete fields H. Peter Anvin
2007-07-10 2:51 ` H. Peter Anvin
2007-07-10 2:51 ` [x86 setup 11/33] x86-64: add CONFIG_PHYSICAL_ALIGN for consistency with i386 H. Peter Anvin
2007-07-10 2:51 ` H. Peter Anvin
2007-07-10 2:51 ` [x86 setup 12/33] x86-64: add symbolic constants for the boot segment selectors H. Peter Anvin
2007-07-10 2:51 ` H. Peter Anvin
2007-07-10 2:51 ` [x86 setup 13/33] Header file to produce 16-bit code with gcc H. Peter Anvin
2007-07-10 2:51 ` H. Peter Anvin
2007-07-10 14:16 ` Segher Boessenkool
2007-07-10 15:21 ` Andi Kleen
2007-07-10 15:48 ` H. Peter Anvin
2007-07-10 15:53 ` H. Peter Anvin
2007-07-10 20:08 ` Segher Boessenkool
2007-07-10 20:43 ` H. Peter Anvin
2007-07-10 21:08 ` Pawel Dziepak
2007-07-10 21:20 ` H. Peter Anvin
2007-07-11 0:26 ` Brian Gerst
2007-07-10 19:57 ` Segher Boessenkool
2007-07-10 20:42 ` H. Peter Anvin
2007-07-10 21:10 ` Segher Boessenkool
2007-07-10 21:40 ` H. Peter Anvin
2007-07-10 22:06 ` Segher Boessenkool
2007-07-10 21:43 ` Adrian Bunk
2007-07-10 21:46 ` H. Peter Anvin
2007-07-11 0:30 ` Brian Gerst
2007-07-10 2:51 ` [x86 setup 14/33] Top header file for new x86 setup code H. Peter Anvin
2007-07-10 2:51 ` H. Peter Anvin
2007-07-10 2:51 ` [x86 setup 15/33] Simple bitops for the " H. Peter Anvin
2007-07-10 2:51 ` H. Peter Anvin
2007-07-10 2:51 ` [x86 setup 16/33] String-handling functions " H. Peter Anvin
2007-07-10 2:51 ` H. Peter Anvin
2007-07-10 18:25 ` Jan Engelhardt
2007-07-10 18:35 ` H. Peter Anvin
2007-07-10 20:10 ` Segher Boessenkool
2007-07-10 20:44 ` H. Peter Anvin
2007-07-10 21:14 ` Segher Boessenkool
2007-07-11 12:46 ` Andi Kleen
2007-07-10 2:51 ` H. Peter Anvin [this message]
2007-07-10 2:51 ` [x86 setup 17/33] A20 handling code H. Peter Anvin
2007-07-10 18:27 ` Jan Engelhardt
2007-07-10 18:33 ` H. Peter Anvin
2007-07-10 18:36 ` H. Peter Anvin
2007-07-10 2:51 ` [x86 setup 18/33] APM probing code H. Peter Anvin
2007-07-10 2:51 ` H. Peter Anvin
2007-07-10 2:51 ` [x86 setup 19/33] Command-line parsing code for the new x86 setup code H. Peter Anvin
2007-07-10 2:51 ` H. Peter Anvin
2007-07-10 2:51 ` [x86 setup 20/33] Console-writing " H. Peter Anvin
2007-07-10 2:51 ` H. Peter Anvin
2007-07-10 18:35 ` Jan Engelhardt
2007-07-10 18:48 ` H. Peter Anvin
2007-07-10 2:52 ` [x86 setup 21/33] Version string " H. Peter Anvin
2007-07-10 2:52 ` H. Peter Anvin
2007-07-10 2:52 ` [x86 setup 22/33] CPU features verification " H. Peter Anvin
2007-07-10 2:52 ` H. Peter Anvin
2007-07-10 7:37 ` Sébastien Dugué
2007-07-10 7:37 ` Sébastien Dugué
2007-07-10 2:52 ` [x86 setup 23/33] EDD probing code " H. Peter Anvin
2007-07-10 2:52 ` H. Peter Anvin
2007-07-10 2:52 ` [x86 setup 24/33] MCA support for " H. Peter Anvin
2007-07-10 2:52 ` H. Peter Anvin
2007-07-10 2:52 ` [x86 setup 25/33] Memory probing support for the " H. Peter Anvin
2007-07-10 2:52 ` H. Peter Anvin
2007-07-10 2:52 ` [x86 setup 26/33] Voyager " H. Peter Anvin
2007-07-10 2:52 ` H. Peter Anvin
2007-07-10 2:52 ` [x86 setup 27/33] Video mode probing " H. Peter Anvin
2007-07-10 2:52 ` H. Peter Anvin
2007-07-10 2:52 ` [x86 setup 28/33] Code for actual protected-mode entry H. Peter Anvin
2007-07-10 2:52 ` H. Peter Anvin
2007-07-10 2:52 ` [x86 setup 29/33] Assembly header and main routine for new x86 setup code H. Peter Anvin
2007-07-10 2:52 ` H. Peter Anvin
2007-07-10 2:52 ` [x86 setup 30/33] Linker script for the " H. Peter Anvin
2007-07-10 2:52 ` H. Peter Anvin
2007-07-10 2:52 ` [x86 setup 31/33] Use the new x86 setup code for i386 H. Peter Anvin
2007-07-10 2:52 ` H. Peter Anvin
2007-07-10 7:55 ` Tilman Schmidt
2007-07-10 2:52 ` [x86 setup 32/33] Use the new x86 setup code for x86-64; unify with i386 H. Peter Anvin
2007-07-10 2:52 ` H. Peter Anvin
2007-07-10 2:52 ` [x86 setup 33/33] Remove old i386 setup code H. Peter Anvin
2007-07-10 2:52 ` H. Peter Anvin
2007-07-10 4:24 ` x86 setup code rewrite in C Yinghai Lu
2007-07-10 4:39 ` H. Peter Anvin
2007-07-10 5:25 ` Jeff Garzik
2007-07-10 16:24 ` Jeremy Fitzhardinge
-- strict thread matches above, loose matches on Subject: below --
2007-07-11 19:18 x86 setup code rewrite in C - revised H. Peter Anvin
2007-07-11 19:18 ` [x86 setup 01/33] x86 setup: MAINTAINERS: formally take responsibility for the i386 boot code H. Peter Anvin
2007-07-11 19:18 ` [x86 setup 02/33] hd.c: remove BIOS/CMOS queries H. Peter Anvin
2007-07-11 19:18 ` [x86 setup 03/33] include/asm-i386/boot.h: This is <asm/boot.h>, not <linux/boot.h> H. Peter Anvin
2007-07-11 19:18 ` [x86 setup 04/33] Unify the CPU features vectors between i386 and x86-64 H. Peter Anvin
2007-07-11 19:18 ` [x86 setup 05/33] Change CONFIG_X86_MINIMUM_CPU_MODEL to CONFIG_X86_MINIMUM_CPU_FAMILY H. Peter Anvin
2007-07-11 19:18 ` [x86 setup 06/33] Clean up struct screen_info (<linux/screen_info.h>) H. Peter Anvin
2007-07-11 19:18 ` [x86 setup 07/33] Use a new CPU feature word to cover all Intel features that are spread around H. Peter Anvin
2007-07-11 19:18 ` [x86 setup 08/33] Define zero-page offset 0x1e4 as a scratch field, and use it H. Peter Anvin
2007-07-11 19:18 ` [x86 setup 09/33] Make definitions for struct e820entry and struct e820map consistent H. Peter Anvin
2007-07-11 19:18 ` [x86 setup 10/33] Make struct boot_params a real structure, and remove obsolete fields H. Peter Anvin
2007-07-11 19:18 ` [x86 setup 11/33] x86-64: add CONFIG_PHYSICAL_ALIGN for consistency with i386 H. Peter Anvin
2007-07-11 19:18 ` [x86 setup 12/33] x86-64: add symbolic constants for the boot segment selectors H. Peter Anvin
2007-07-11 19:18 ` [x86 setup 13/33] Header file to produce 16-bit code with gcc H. Peter Anvin
2007-07-11 19:18 ` [x86 setup 14/33] Top header file for new x86 setup code H. Peter Anvin
2007-07-11 19:18 ` [x86 setup 15/33] Simple bitops for the " H. Peter Anvin
2007-07-11 19:18 ` [x86 setup 16/33] String-handling functions " H. Peter Anvin
2007-07-11 19:18 ` [x86 setup 01/33] x86 setup: MAINTAINERS: formally take responsibility for the i386 boot code H. Peter Anvin
2007-07-11 19:18 ` [x86 setup 17/33] A20 handling code H. Peter Anvin
2007-07-11 19:18 ` H. Peter Anvin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=11840377211519-git-send-email-hpa@zytor.com \
--to=hpa@zytor.com \
--cc=akpm@linux-foundation.org \
--cc=andi@firstfloor.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.