1 /* -*- linux-c -*- ------------------------------------------------------- *
3 * Copyright (C) 1991, 1992 Linus Torvalds
4 * Copyright 2007-2008 rPath, Inc. - All Rights Reserved
6 * This file is part of the Linux kernel, and is made available under
7 * the terms of the GNU General Public License version 2.
9 * ----------------------------------------------------------------------- */
12 * Enable A20 gate (return -1 on failure)
17 #define MAX_8042_LOOPS 100000
19 static int empty_8042(void)
22 int loops
= MAX_8042_LOOPS
;
29 /* Read and discard input data */
32 } else if (!(status
& 2)) {
33 /* Buffers empty, finished! */
41 /* Returns nonzero if the A20 line is enabled. The memory address
42 used as a test is the int $0x80 vector, which should be safe. */
44 #define A20_TEST_ADDR (4*0x80)
45 #define A20_TEST_SHORT 32
46 #define A20_TEST_LONG 2097152 /* 2^21 */
48 static int a20_test(int loops
)
56 saved
= ctr
= rdfs32(A20_TEST_ADDR
);
59 wrfs32(++ctr
, A20_TEST_ADDR
);
60 io_delay(); /* Serialize and make delay constant */
61 ok
= rdgs32(A20_TEST_ADDR
+0x10) ^ ctr
;
66 wrfs32(saved
, A20_TEST_ADDR
);
70 /* Quick test to see if A20 is already enabled */
71 static int a20_test_short(void)
73 return a20_test(A20_TEST_SHORT
);
76 /* Longer test that actually waits for A20 to come on line; this
77 is useful when dealing with the KBC or other slow external circuitry. */
78 static int a20_test_long(void)
80 return a20_test(A20_TEST_LONG
);
83 static void enable_a20_bios(void)
85 asm volatile("pushfl; int $0x15; popfl"
86 : : "a" ((u16
)0x2401));
89 static void enable_a20_kbc(void)
93 outb(0xd1, 0x64); /* Command write */
96 outb(0xdf, 0x60); /* A20 on */
99 outb(0xff, 0x64); /* Null command, but UHCI wants it */
103 static void enable_a20_fast(void)
107 port_a
= inb(0x92); /* Configuration port A */
108 port_a
|= 0x02; /* Enable A20 */
109 port_a
&= ~0x01; /* Do not reset machine */
114 * Actual routine to enable A20; return 0 on ok, -1 on failure
117 #define A20_ENABLE_LOOPS 255 /* Number of times to try */
121 #if defined(CONFIG_X86_ELAN)
122 /* Elan croaks if we try to touch the KBC */
124 while (!a20_test_long())
127 #elif defined(CONFIG_X86_VOYAGER)
128 /* On Voyager, a20_test() is unsafe? */
132 int loops
= A20_ENABLE_LOOPS
;
134 /* First, check to see if A20 is already enabled
135 (legacy free, etc.) */
136 if (a20_test_short())
139 /* Next, try the BIOS (INT 0x15, AX=0x2401) */
141 if (a20_test_short())
144 /* Try enabling A20 through the keyboard controller */
146 if (a20_test_short())
147 return 0; /* BIOS worked, but with delayed reaction */
153 /* Finally, try enabling the "fast A20 gate" */