@ -195,7 +195,7 @@ static int save_bsp_msrs(char *start, int size)
msr_count = 2 * num_var_mtrrs + NUM_FIXED_MTRRS + 1 ;
msr_count = 2 * num_var_mtrrs + NUM_FIXED_MTRRS + 1 ;
if ( ( msr_count * sizeof ( struct saved_msr ) ) > size ) {
if ( ( msr_count * sizeof ( struct saved_msr ) ) > size ) {
printf ( " Cannot mirror all %d msrs. \n " , msr_count ) ;
printf ( " Cannot mirror all %d msrs \n " , msr_count ) ;
return - ENOSPC ;
return - ENOSPC ;
}
}
@ -283,21 +283,25 @@ static int check_cpu_devices(int expected_cpus)
}
}
/* Returns 1 for timeout. 0 on success */
/* Returns 1 for timeout. 0 on success */
static int apic_wait_timeout ( int total_delay , int delay_step )
static int apic_wait_timeout ( int total_delay , const char * msg )
{
{
int total = 0 ;
int total = 0 ;
int timeout = 0 ;
if ( ! ( lapic_read ( LAPIC_ICR ) & LAPIC_ICR_BUSY ) )
return 0 ;
debug ( " Waiting for %s... " , msg ) ;
while ( lapic_read ( LAPIC_ICR ) & LAPIC_ICR_BUSY ) {
while ( lapic_read ( LAPIC_ICR ) & LAPIC_ICR_BUSY ) {
udelay ( delay_step ) ;
udelay ( 50 ) ;
total + = delay_step ;
total + = 50 ;
if ( total > = total_delay ) {
if ( total > = total_delay ) {
timeout = 1 ;
debug ( " timed out: aborting \n " ) ;
break ;
return - ETIMEDOUT ;
}
}
}
}
debug ( " done \n " ) ;
return timeout ;
return 0 ;
}
}
static int start_aps ( int ap_count , atomic_t * num_aps )
static int start_aps ( int ap_count , atomic_t * num_aps )
@ -320,73 +324,42 @@ static int start_aps(int ap_count, atomic_t *num_aps)
debug ( " Attempting to start %d APs \n " , ap_count ) ;
debug ( " Attempting to start %d APs \n " , ap_count ) ;
if ( ( lapic_read ( LAPIC_ICR ) & LAPIC_ICR_BUSY ) ) {
if ( apic_wait_timeout ( 1000 , " ICR not to be busy " ) )
debug ( " Waiting for ICR not to be busy... " ) ;
return - ETIMEDOUT ;
if ( apic_wait_timeout ( 1000 , 50 ) ) {
debug ( " timed out. Aborting. \n " ) ;
return - 1 ;
} else {
debug ( " done. \n " ) ;
}
}
/* Send INIT IPI to all but self */
/* Send INIT IPI to all but self */
lapic_write ( LAPIC_ICR2 , SET_LAPIC_DEST_FIELD ( 0 ) ) ;
lapic_write ( LAPIC_ICR2 , SET_LAPIC_DEST_FIELD ( 0 ) ) ;
lapic_write ( LAPIC_ICR , LAPIC_DEST_ALLBUT | LAPIC_INT_ASSERT |
lapic_write ( LAPIC_ICR , LAPIC_DEST_ALLBUT | LAPIC_INT_ASSERT |
LAPIC_DM_INIT ) ;
LAPIC_DM_INIT ) ;
debug ( " Waiting for 10ms after sending INIT. \n " ) ;
debug ( " Waiting for 10ms after sending INIT \n " ) ;
mdelay ( 10 ) ;
mdelay ( 10 ) ;
/* Send 1st SIPI */
/* Send 1st SIPI */
if ( ( lapic_read ( LAPIC_ICR ) & LAPIC_ICR_BUSY ) ) {
if ( apic_wait_timeout ( 1000 , " ICR not to be busy " ) )
debug ( " Waiting for ICR not to be busy... " ) ;
return - ETIMEDOUT ;
if ( apic_wait_timeout ( 1000 , 50 ) ) {
debug ( " timed out. Aborting. \n " ) ;
return - 1 ;
} else {
debug ( " done. \n " ) ;
}
}
lapic_write ( LAPIC_ICR2 , SET_LAPIC_DEST_FIELD ( 0 ) ) ;
lapic_write ( LAPIC_ICR2 , SET_LAPIC_DEST_FIELD ( 0 ) ) ;
lapic_write ( LAPIC_ICR , LAPIC_DEST_ALLBUT | LAPIC_INT_ASSERT |
lapic_write ( LAPIC_ICR , LAPIC_DEST_ALLBUT | LAPIC_INT_ASSERT |
LAPIC_DM_STARTUP | sipi_vector ) ;
LAPIC_DM_STARTUP | sipi_vector ) ;
debug ( " Waiting for 1st SIPI to complete... " ) ;
if ( apic_wait_timeout ( 10000 , " first SIPI to complete " ) )
if ( apic_wait_timeout ( 10000 , 50 ) ) {
return - ETIMEDOUT ;
debug ( " timed out. \n " ) ;
return - 1 ;
} else {
debug ( " done. \n " ) ;
}
/* Wait for CPUs to check in up to 200 us */
/* Wait for CPUs to check in up to 200 us */
wait_for_aps ( num_aps , ap_count , 200 , 15 ) ;
wait_for_aps ( num_aps , ap_count , 200 , 15 ) ;
/* Send 2nd SIPI */
/* Send 2nd SIPI */
if ( ( lapic_read ( LAPIC_ICR ) & LAPIC_ICR_BUSY ) ) {
if ( apic_wait_timeout ( 1000 , " ICR not to be busy " ) )
debug ( " Waiting for ICR not to be busy... " ) ;
return - ETIMEDOUT ;
if ( apic_wait_timeout ( 1000 , 50 ) ) {
debug ( " timed out. Aborting. \n " ) ;
return - 1 ;
} else {
debug ( " done. \n " ) ;
}
}
lapic_write ( LAPIC_ICR2 , SET_LAPIC_DEST_FIELD ( 0 ) ) ;
lapic_write ( LAPIC_ICR2 , SET_LAPIC_DEST_FIELD ( 0 ) ) ;
lapic_write ( LAPIC_ICR , LAPIC_DEST_ALLBUT | LAPIC_INT_ASSERT |
lapic_write ( LAPIC_ICR , LAPIC_DEST_ALLBUT | LAPIC_INT_ASSERT |
LAPIC_DM_STARTUP | sipi_vector ) ;
LAPIC_DM_STARTUP | sipi_vector ) ;
debug ( " Waiting for 2nd SIPI to complete... " ) ;
if ( apic_wait_timeout ( 10000 , " second SIPI to complete " ) )
if ( apic_wait_timeout ( 10000 , 50 ) ) {
return - ETIMEDOUT ;
debug ( " timed out. \n " ) ;
return - 1 ;
} else {
debug ( " done. \n " ) ;
}
/* Wait for CPUs to check in */
/* Wait for CPUs to check in */
if ( wait_for_aps ( num_aps , ap_count , 10000 , 50 ) ) {
if ( wait_for_aps ( num_aps , ap_count , 10000 , 50 ) ) {
debug ( " Not all APs checked in: %d/%d. \n " ,
debug ( " Not all APs checked in: %d/%d \n " ,
atomic_read ( num_aps ) , ap_count ) ;
atomic_read ( num_aps ) , ap_count ) ;
return - 1 ;
return - 1 ;
}
}
@ -410,7 +383,7 @@ static int bsp_do_flight_plan(struct udevice *cpu, struct mp_params *mp_params)
/* Wait for the APs to check in */
/* Wait for the APs to check in */
if ( wait_for_aps ( & rec - > cpus_entered , num_aps ,
if ( wait_for_aps ( & rec - > cpus_entered , num_aps ,
timeout_us , step_us ) ) {
timeout_us , step_us ) ) {
debug ( " MP record %d timeout. \n " , i ) ;
debug ( " MP record %d timeout \n " , i ) ;
ret = - 1 ;
ret = - 1 ;
}
}
}
}
@ -430,7 +403,7 @@ static int init_bsp(struct udevice **devp)
int ret ;
int ret ;
cpu_get_name ( processor_name ) ;
cpu_get_name ( processor_name ) ;
debug ( " CPU: %s. \n " , processor_name ) ;
debug ( " CPU: %s \n " , processor_name ) ;
lapic_setup ( ) ;
lapic_setup ( ) ;