Commit 3bd323a1 authored by H. Peter Anvin's avatar H. Peter Anvin

x86 setup: a20: early timeout for a nonexistent keyboard controller

When probing the keyboard controller to enable A20, if we get FF back
(which is *possible* as a valid status word, but is extremely
unlikely) then bail after much fewer iterations than we otherwise
would, and abort the attempt to access the KBC.

This hopefully should make it work a lot better for embedded platforms
which don't have a KBC and where the BIOS doesn't implement
INT 15h AX=2401h (and doesn't boot with A20 already enabled.)

If this works, it will be the one remaining use of CONFIG_X86_ELAN as
anything other than a processor type optimization option.
Signed-off-by: default avatarH. Peter Anvin <hpa@linux.intel.com>
parent 042cbaf8
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* *
* Copyright (C) 1991, 1992 Linus Torvalds * Copyright (C) 1991, 1992 Linus Torvalds
* Copyright 2007-2008 rPath, Inc. - All Rights Reserved * Copyright 2007-2008 rPath, Inc. - All Rights Reserved
* Copyright 2009 Intel Corporation
* *
* This file is part of the Linux kernel, and is made available under * This file is part of the Linux kernel, and is made available under
* the terms of the GNU General Public License version 2. * the terms of the GNU General Public License version 2.
...@@ -15,16 +16,23 @@ ...@@ -15,16 +16,23 @@
#include "boot.h" #include "boot.h"
#define MAX_8042_LOOPS 100000 #define MAX_8042_LOOPS 100000
#define MAX_8042_FF 32
static int empty_8042(void) static int empty_8042(void)
{ {
u8 status; u8 status;
int loops = MAX_8042_LOOPS; int loops = MAX_8042_LOOPS;
int ffs = MAX_8042_FF;
while (loops--) { while (loops--) {
io_delay(); io_delay();
status = inb(0x64); status = inb(0x64);
if (status == 0xff) {
/* FF is a plausible, but very unlikely status */
if (!--ffs)
return -1; /* Assume no KBC present */
}
if (status & 1) { if (status & 1) {
/* Read and discard input data */ /* Read and discard input data */
io_delay(); io_delay();
...@@ -118,44 +126,43 @@ static void enable_a20_fast(void) ...@@ -118,44 +126,43 @@ static void enable_a20_fast(void)
int enable_a20(void) int enable_a20(void)
{ {
#if defined(CONFIG_X86_ELAN) #ifdef CONFIG_X86_VOYAGER
/* 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? */ /* On Voyager, a20_test() is unsafe? */
enable_a20_kbc(); enable_a20_kbc();
return 0; return 0;
#else #else
int loops = A20_ENABLE_LOOPS; int loops = A20_ENABLE_LOOPS;
while (loops--) { int kbc_err;
/* First, check to see if A20 is already enabled
(legacy free, etc.) */ while (loops--) {
if (a20_test_short()) /* First, check to see if A20 is already enabled
return 0; (legacy free, etc.) */
if (a20_test_short())
/* Next, try the BIOS (INT 0x15, AX=0x2401) */ return 0;
enable_a20_bios();
if (a20_test_short()) /* Next, try the BIOS (INT 0x15, AX=0x2401) */
return 0; enable_a20_bios();
if (a20_test_short())
/* Try enabling A20 through the keyboard controller */ return 0;
empty_8042();
if (a20_test_short()) /* Try enabling A20 through the keyboard controller */
return 0; /* BIOS worked, but with delayed reaction */ kbc_err = empty_8042();
enable_a20_kbc(); if (a20_test_short())
if (a20_test_long()) return 0; /* BIOS worked, but with delayed reaction */
return 0;
if (!kbc_err) {
/* Finally, try enabling the "fast A20 gate" */ enable_a20_kbc();
enable_a20_fast(); if (a20_test_long())
if (a20_test_long()) return 0;
return 0; }
}
/* Finally, try enabling the "fast A20 gate" */
return -1; enable_a20_fast();
if (a20_test_long())
return 0;
}
return -1;
#endif #endif
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment