| 1 |
|
| 2 |
|
| 3 |
#include <console/console.h> |
| 4 |
#include <cpu/x86/lapic.h> |
| 5 |
#include <delay.h> |
| 6 |
#include <halt.h> |
| 7 |
#include <stdint.h> |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#define DEBUG_HALT_SELF 0 |
| 21 |
|
| 22 |
#if DEBUG_HALT_SELF |
| 23 |
#define dprintk(LEVEL, args...) do { printk(LEVEL, ##args); } while (0) |
| 24 |
#else |
| 25 |
#define dprintk(LEVEL, args...) do { } while (0) |
| 26 |
#endif |
| 27 |
|
| 28 |
static void wait_for_ipi_completion_without_printk(const int timeout_ms) |
| 29 |
{ |
| 30 |
int loops = timeout_ms * 10; |
| 31 |
uint32_t send_status; |
| 32 |
|
| 33 |
|
| 34 |
dprintk(BIOS_SPEW, "Waiting for send to finish...\n"); |
| 35 |
do { |
| 36 |
dprintk(BIOS_SPEW, "+"); |
| 37 |
udelay(100); |
| 38 |
send_status = lapic_busy(); |
| 39 |
} while (send_status && (--loops > 0)); |
| 40 |
|
| 41 |
if (send_status) |
| 42 |
dprintk(BIOS_ERR, "timed out\n"); |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
void stop_this_cpu(void) |
| 52 |
{ |
| 53 |
const int timeout_100ms = 100; |
| 54 |
unsigned long id = lapicid(); |
| 55 |
|
| 56 |
printk(BIOS_DEBUG, "CPU %ld going down...\n", id); |
| 57 |
|
| 58 |
|
| 59 |
lapic_send_ipi_self(LAPIC_INT_LEVELTRIG | LAPIC_INT_ASSERT | LAPIC_MT_INIT); |
| 60 |
wait_for_ipi_completion_without_printk(timeout_100ms); |
| 61 |
|
| 62 |
mdelay(10); |
| 63 |
|
| 64 |
dprintk(BIOS_SPEW, "Deasserting INIT.\n"); |
| 65 |
|
| 66 |
|
| 67 |
lapic_send_ipi_self(LAPIC_INT_LEVELTRIG | LAPIC_MT_INIT); |
| 68 |
wait_for_ipi_completion_without_printk(timeout_100ms); |
| 69 |
|
| 70 |
halt(); |
| 71 |
} |