xref: /openbsd/sys/arch/i386/stand/libsa/gateA20.c (revision b27348b2)
1*b27348b2Sderaadt /*	$OpenBSD: gateA20.c,v 1.11 2017/09/08 05:36:52 deraadt Exp $	*/
2df1f5d3aSweingart 
3df1f5d3aSweingart /*
4df1f5d3aSweingart  * Ported to boot 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
5df1f5d3aSweingart  *
6df1f5d3aSweingart  * Mach Operating System
7df1f5d3aSweingart  * Copyright (c) 1992, 1991 Carnegie Mellon University
8df1f5d3aSweingart  * All Rights Reserved.
9df1f5d3aSweingart  *
10df1f5d3aSweingart  * Permission to use, copy, modify and distribute this software and its
11df1f5d3aSweingart  * documentation is hereby granted, provided that both the copyright
12df1f5d3aSweingart  * notice and this permission notice appear in all copies of the
13df1f5d3aSweingart  * software, derivative works or modified versions, and any portions
14df1f5d3aSweingart  * thereof, and that both notices appear in supporting documentation.
15df1f5d3aSweingart  *
16df1f5d3aSweingart  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
17df1f5d3aSweingart  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
18df1f5d3aSweingart  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
19df1f5d3aSweingart  *
20df1f5d3aSweingart  * Carnegie Mellon requests users of this software to return to
21df1f5d3aSweingart  *
22df1f5d3aSweingart  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
23df1f5d3aSweingart  *  School of Computer Science
24df1f5d3aSweingart  *  Carnegie Mellon University
25df1f5d3aSweingart  *  Pittsburgh PA 15213-3890
26df1f5d3aSweingart  *
27df1f5d3aSweingart  * any improvements or extensions that they make and grant Carnegie Mellon
28df1f5d3aSweingart  * the rights to redistribute these changes.
29df1f5d3aSweingart  */
30df1f5d3aSweingart 
317040ffa9Sweingart #include <sys/param.h>
32df1f5d3aSweingart #include <machine/pio.h>
3384d5fab2Smickey #include <dev/ic/i8042reg.h>
34e4e5690aSaaron #include <dev/isa/isareg.h>
35df1f5d3aSweingart 
367040ffa9Sweingart #include "libsa.h"
377040ffa9Sweingart 
38df1f5d3aSweingart #define KB_A20		0xdf		/* enable A20,
39df1f5d3aSweingart 					   enable output buffer full interrupt
40df1f5d3aSweingart 					   enable data line
41df1f5d3aSweingart 					   enable clock line */
42df1f5d3aSweingart 
437040ffa9Sweingart 
447040ffa9Sweingart /*
45ef7aef7bStom  * "Probe"-style routine (no parameters) to turn A20 on
46ef7aef7bStom  */
47ef7aef7bStom void
gateA20on(void)48ef7aef7bStom gateA20on(void)
49ef7aef7bStom {
50ef7aef7bStom 	gateA20(1);
51ef7aef7bStom }
52ef7aef7bStom 
53ef7aef7bStom 
54ef7aef7bStom /*
555adc64b9Smickey  * Gate A20 for high memory
567040ffa9Sweingart  */
575adc64b9Smickey void
gateA20(int on)58599546b3Sderaadt gateA20(int on)
59df1f5d3aSweingart {
605adc64b9Smickey 	if (ps2model == 0xf82 ||
615adc64b9Smickey 	    (inb(IO_KBD + KBSTATP) == 0xff && inb(IO_KBD + KBDATAP) == 0xff)) {
625adc64b9Smickey 		int data;
637040ffa9Sweingart 
645adc64b9Smickey 		/* Try to use 0x92 to turn on A20 */
655adc64b9Smickey 		if (on) {
665adc64b9Smickey 			data = inb(0x92);
675adc64b9Smickey 			outb(0x92, data | 0x2);
685adc64b9Smickey 		} else {
695adc64b9Smickey 			data = inb(0x92);
705adc64b9Smickey 			outb(0x92, data & ~0x2);
715adc64b9Smickey 		}
725adc64b9Smickey 	} else {
735adc64b9Smickey 
745adc64b9Smickey 		while (inb(IO_KBD + KBSTATP) & KBS_IBF);
75df1f5d3aSweingart 
76e4e5690aSaaron 		while (inb(IO_KBD + KBSTATP) & KBS_DIB)
77e4e5690aSaaron 			(void)inb(IO_KBD + KBDATAP);
78df1f5d3aSweingart 
795adc64b9Smickey 		outb(IO_KBD + KBCMDP, KBC_CMDWOUT);
80e4e5690aSaaron 		while (inb(IO_KBD + KBSTATP) & KBS_IBF);
81df1f5d3aSweingart 
82df1f5d3aSweingart 		if (on)
83e4e5690aSaaron 			outb(IO_KBD + KBDATAP, KB_A20);
84df1f5d3aSweingart 		else
85e4e5690aSaaron 			outb(IO_KBD + KBDATAP, 0xcd);
86e4e5690aSaaron 		while (inb(IO_KBD + KBSTATP) & KBS_IBF);
87df1f5d3aSweingart 
88e4e5690aSaaron 		while (inb(IO_KBD + KBSTATP) & KBS_DIB)
89e4e5690aSaaron 			(void)inb(IO_KBD + KBDATAP);
90df1f5d3aSweingart 	}
917040ffa9Sweingart }
92