xref: /netbsd-src/sys/arch/i386/stand/lib/gatea20.c (revision bf1e9b32e27832f0c493206710fb8b58a980838a)
1 /*	$NetBSD: gatea20.c,v 1.6 2005/06/24 13:00:01 manu Exp $	*/
2 
3 /* extracted from freebsd:sys/i386/boot/biosboot/io.c */
4 
5 #include <sys/types.h>
6 #include <machine/pio.h>
7 
8 #include <lib/libsa/stand.h>
9 
10 #include "libi386.h"
11 #include "biosmca.h"
12 
13 #define K_RDWR 		0x60		/* keyboard data & cmds (read/write) */
14 #define K_STATUS 	0x64		/* keyboard status */
15 #define K_CMD	 	0x64		/* keybd ctlr command (write-only) */
16 
17 #define K_OBUF_FUL 	0x01		/* output buffer full */
18 #define K_IBUF_FUL 	0x02		/* input buffer full */
19 
20 #define KC_CMD_WIN	0xd0		/* read  output port */
21 #define KC_CMD_WOUT	0xd1		/* write output port */
22 #define KB_A20		0x9f		/* enable A20,
23 					   reset (!),
24 					   enable output buffer full interrupt
25 					   enable data line
26 					   disable clock line */
27 
28 /*
29  * Gate A20 for high memory
30  */
31 static unsigned char	x_20 = KB_A20;
32 void gateA20()
33 {
34 	__asm("pushfl ; cli");
35 	/*
36 	 * Not all systems enable A20 via the keyboard controller.
37 	 *	* IBM PS/2 L40
38 	 *	* AMD Elan SC520-based systems
39 	 */
40 	if (
41 #ifdef SUPPORT_PS2
42 	    biosmca_ps2model == 0xf82 ||
43 #endif
44 	    (inb(K_STATUS) == 0xff && inb(K_RDWR) == 0xff)) {
45 		int data;
46 
47 		data = inb(0x92);
48 		outb(0x92, data | 0x2);
49 	} else {
50 		while (inb(K_STATUS) & K_IBUF_FUL);
51 
52 		while (inb(K_STATUS) & K_OBUF_FUL)
53 			(void)inb(K_RDWR);
54 
55 		outb(K_CMD, KC_CMD_WOUT);
56 
57 		delay(100);
58 		while (inb(K_STATUS) & K_IBUF_FUL);
59 
60 		outb(K_RDWR, x_20);
61 
62 		delay(100);
63 		while (inb(K_STATUS) & K_IBUF_FUL);
64 
65 		while (inb(K_STATUS) & K_OBUF_FUL)
66 			(void)inb(K_RDWR);
67 	}
68 	__asm("popfl");
69 }
70