david/ipxe
david
/
ipxe
Archived
1
0
Fork 0

On advice of hpa: be more patient with the KBC and SCPA methods; retry

in a long loop before giving up on them.  Record method which worked
and default to that method on next attempt.
This commit is contained in:
Michael Brown 2007-07-14 20:56:12 +01:00
parent adf192f566
commit 26473105cd
1 changed files with 71 additions and 47 deletions

View File

@ -24,11 +24,21 @@
#define SCP_A 0x92 /* System Control Port A */ #define SCP_A 0x92 /* System Control Port A */
#define A20_MAX_RETRIES 32
enum { Disable_A20 = 0x2400, Enable_A20 = 0x2401, Query_A20_Status = 0x2402, enum { Disable_A20 = 0x2400, Enable_A20 = 0x2401, Query_A20_Status = 0x2402,
Query_A20_Support = 0x2403 }; Query_A20_Support = 0x2403 };
enum a20_methods {
A20_UNKNOWN = 0,
A20_INT15,
A20_KBC,
A20_SCPA,
};
#define A20_MAX_RETRIES 32
#define A20_INT15_RETRIES 32
#define A20_KBC_RETRIES (2^21)
#define A20_SCPA_RETRIES (2^21)
/** /**
* Drain keyboard controller * Drain keyboard controller
*/ */
@ -47,29 +57,32 @@ static void empty_8042 ( void ) {
/** /**
* Fast test to see if gate A20 is already set * Fast test to see if gate A20 is already set
* *
* @v retries Number of times to retry before giving up
* @ret set Gate A20 is set * @ret set Gate A20 is set
*/ */
static int gateA20_is_set ( void ) { static int gateA20_is_set ( int retries ) {
static uint32_t test_pattern = 0xdeadbeef; static uint32_t test_pattern = 0xdeadbeef;
physaddr_t test_pattern_phys = virt_to_phys ( &test_pattern ); physaddr_t test_pattern_phys = virt_to_phys ( &test_pattern );
physaddr_t verify_pattern_phys = ( test_pattern_phys ^ 0x100000 ); physaddr_t verify_pattern_phys = ( test_pattern_phys ^ 0x100000 );
userptr_t verify_pattern_user = phys_to_user ( verify_pattern_phys ); userptr_t verify_pattern_user = phys_to_user ( verify_pattern_phys );
uint32_t verify_pattern; uint32_t verify_pattern;
/* Check for difference */ do {
copy_from_user ( &verify_pattern, verify_pattern_user, 0, /* Check for difference */
sizeof ( verify_pattern ) ); copy_from_user ( &verify_pattern, verify_pattern_user, 0,
if ( verify_pattern != test_pattern ) sizeof ( verify_pattern ) );
return 1; if ( verify_pattern != test_pattern )
return 1;
/* Invert pattern and retest, just to be sure */ /* Avoid false negatives */
test_pattern ^= 0xffffffff; test_pattern++;
copy_from_user ( &verify_pattern, verify_pattern_user, 0,
sizeof ( verify_pattern ) );
if ( verify_pattern != test_pattern )
return 1;
/* Pattern matched both times; gate A20 is not set */ SLOW_DOWN_IO;
/* Always retry at least once, to avoid false negatives */
} while ( retries-- >= 0 );
/* Pattern matched every time; gate A20 is not set */
return 0; return 0;
} }
@ -83,6 +96,7 @@ static int gateA20_is_set ( void ) {
*/ */
void gateA20_set ( void ) { void gateA20_set ( void ) {
static char reentry_guard = 0; static char reentry_guard = 0;
static int a20_method = A20_UNKNOWN;
unsigned int discard_a; unsigned int discard_a;
unsigned int scp_a; unsigned int scp_a;
int retries = 0; int retries = 0;
@ -93,41 +107,51 @@ void gateA20_set ( void ) {
reentry_guard = 1; reentry_guard = 1;
/* Fast check to see if gate A20 is already enabled */ /* Fast check to see if gate A20 is already enabled */
if ( gateA20_is_set() ) if ( gateA20_is_set ( 0 ) )
goto out; goto out;
for ( ; retries < A20_MAX_RETRIES ; retries++ ) { for ( ; retries < A20_MAX_RETRIES ; retries++ ) {
switch ( a20_method ) {
/* Try INT 15 method first */ case A20_UNKNOWN:
__asm__ __volatile__ ( REAL_CODE ( "int $0x15" ) case A20_INT15:
: "=a" ( discard_a ) /* Try INT 15 method */
: "a" ( Enable_A20 ) ); __asm__ __volatile__ ( REAL_CODE ( "int $0x15" )
if ( gateA20_is_set() ) { : "=a" ( discard_a )
DBG ( "Enabled gate A20 using BIOS\n" ); : "a" ( Enable_A20 ) );
goto out; if ( gateA20_is_set ( A20_INT15_RETRIES ) ) {
} DBG ( "Enabled gate A20 using BIOS\n" );
a20_method = A20_INT15;
/* Try keyboard controller method */ goto out;
empty_8042(); }
outb ( KC_CMD_WOUT, K_CMD ); /* fall through */
empty_8042(); case A20_KBC:
outb ( KB_SET_A20, K_RDWR ); /* Try keyboard controller method */
empty_8042(); empty_8042();
if ( gateA20_is_set() ) { outb ( KC_CMD_WOUT, K_CMD );
DBG ( "Enabled gate A20 using keyboard controller\n" ); empty_8042();
goto out; outb ( KB_SET_A20, K_RDWR );
} empty_8042();
if ( gateA20_is_set ( A20_KBC_RETRIES ) ) {
/* Try "Fast gate A20" method */ DBG ( "Enabled gate A20 using "
scp_a = inb ( SCP_A ); "keyboard controller\n" );
scp_a &= ~0x01; /* Avoid triggering a reset */ a20_method = A20_KBC;
scp_a |= 0x02; /* Enable A20 */ goto out;
SLOW_DOWN_IO; }
outb ( scp_a, SCP_A ); /* fall through */
SLOW_DOWN_IO; case A20_SCPA:
if ( gateA20_is_set() ) { /* Try "Fast gate A20" method */
DBG ( "Enabled gate A20 using Fast Gate A20\n" ); scp_a = inb ( SCP_A );
goto out; scp_a &= ~0x01; /* Avoid triggering a reset */
scp_a |= 0x02; /* Enable A20 */
SLOW_DOWN_IO;
outb ( scp_a, SCP_A );
SLOW_DOWN_IO;
if ( gateA20_is_set ( A20_SCPA_RETRIES ) ) {
DBG ( "Enabled gate A20 using "
"Fast Gate A20\n" );
a20_method = A20_SCPA;
goto out;
}
} }
} }