xref: /netbsd/sys/arch/i386/stand/lib/gatea20.c (revision bf9ec67e)
1 /*	$NetBSD: gatea20.c,v 1.4 2001/05/19 18:15:14 jdolecek 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 #ifdef	SUPPORT_PS2
36 	/*
37 	 * Check if the machine is PS/2 L40 via biosmca_model, which is
38 	 * initialized before gateA20() is called.
39 	 */
40 	if (biosmca_ps2model == 0xf82)
41 		outb(0x92, 0x2);
42 	else {
43 #endif
44 	while (inb(K_STATUS) & K_IBUF_FUL);
45 	while (inb(K_STATUS) & K_OBUF_FUL)
46 		(void)inb(K_RDWR);
47 
48 	outb(K_CMD, KC_CMD_WOUT);
49 	delay(100);
50 	while (inb(K_STATUS) & K_IBUF_FUL);
51 	outb(K_RDWR, x_20);
52 	delay(100);
53 	while (inb(K_STATUS) & K_IBUF_FUL);
54 #ifdef SUPPORT_PS2
55 	}
56 #endif
57 	__asm("popfl");
58 }
59