Home | History | Annotate | Line # | Download | only in lib
gatea20.c revision 1.7.2.1
      1 /*	$NetBSD: gatea20.c,v 1.7.2.1 2007/10/27 11:26:52 yamt Exp $	*/
      2 
      3 /* extracted from freebsd:sys/i386/boot/biosboot/io.c */
      4 
      5 #include <sys/types.h>
      6 
      7 #include <lib/libsa/stand.h>
      8 
      9 #include "libi386.h"
     10 #include "biosmca.h"
     11 #include "cpufunc.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 
     33 void
     34 gateA20(void)
     35 {
     36 	u_long psl;
     37 
     38 	psl = x86_read_psl();
     39 	x86_disable_intr();
     40 	/*
     41 	 * Not all systems enable A20 via the keyboard controller.
     42 	 *	* IBM PS/2 L40
     43 	 *	* AMD Elan SC520-based systems
     44 	 */
     45 	if (
     46 #ifdef SUPPORT_PS2
     47 	    biosmca_ps2model == 0xf82 ||
     48 #endif
     49 	    (inb(K_STATUS) == 0xff && inb(K_RDWR) == 0xff)) {
     50 		int data;
     51 
     52 		data = inb(0x92);
     53 		outb(0x92, data | 0x2);
     54 	} else {
     55 		while (inb(K_STATUS) & K_IBUF_FUL);
     56 
     57 		while (inb(K_STATUS) & K_OBUF_FUL)
     58 			(void)inb(K_RDWR);
     59 
     60 		outb(K_CMD, KC_CMD_WOUT);
     61 
     62 		delay(100);
     63 		while (inb(K_STATUS) & K_IBUF_FUL);
     64 
     65 		outb(K_RDWR, x_20);
     66 
     67 		delay(100);
     68 		while (inb(K_STATUS) & K_IBUF_FUL);
     69 
     70 		while (inb(K_STATUS) & K_OBUF_FUL)
     71 			(void)inb(K_RDWR);
     72 	}
     73 	x86_write_psl(psl);
     74 }
     75