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