37,6 → 37,7 |
#include <genarch/ofw/ofw_tree.h> |
#include <cpu.h> |
#include <arch/cpu.h> |
#include <arch/boot/boot.h> |
#include <arch.h> |
#include <config.h> |
#include <macros.h> |
44,12 → 45,27 |
#include <synch/synch.h> |
#include <synch/waitq.h> |
#include <print.h> |
#include <arch/sun4v/hypercall.h> |
#include <arch/sun4v/md.h> |
#include <time/delay.h> |
|
#define CPU_STATE_RUNNING 2 |
|
extern void kernel_image_start(void); |
extern void *trap_table; |
|
/** Determine number of processors. */ |
void smp_init(void) |
{ |
// TODO: replace with a real # of CPUs as soon as the MD walkthrough is implemented |
config.cpu_count = 1; |
md_node_t node = md_get_root(); |
count_t cpu_count = 0; |
|
/* walk through MD, find the current CPU node & its clock-frequency */ |
while(md_next_node(&node, "cpu")) { |
cpu_count++; |
} |
|
config.cpu_count = cpu_count; |
} |
|
|
56,7 → 72,46 |
/** Wake application processors up. */ |
void kmp(void *arg) |
{ |
// TODO: implement as soon as the MD walkthrough is implemented |
(void) arg; |
|
uint64_t myid; |
__hypercall_fast_ret1(0, 0, 0, 0, 0, CPU_MYID, &myid); |
|
/* stop the CPUs before making them execute our code */ |
uint64_t i; |
for (i = 0; i < config.cpu_count; i++) { |
if (i == myid) |
continue; |
|
if (__hypercall_fast1(CPU_STOP, i) != 0) |
continue; |
|
uint64_t state; |
__hypercall_fast_ret1(i, 0, 0, 0, 0, CPU_STATE, &state); |
while (state == CPU_STATE_RUNNING) { |
__hypercall_fast_ret1(i, 0, 0, 0, 0, CPU_STATE, &state); |
} |
} |
|
/* wake the processors up, one by one */ |
uint64_t state; |
for (i = 1; i < config.cpu_count; i++) { |
__hypercall_fast_ret1(i, 0, 0, 0, 0, CPU_STATE, &state); |
printf("Starting CPU %d, error code = %d.\n", i, __hypercall_fast4( |
CPU_START, |
i, |
(uint64_t) KA2PA(kernel_image_start), |
KA2PA(trap_table), |
bootinfo.physmem_start |
)); |
|
if (waitq_sleep_timeout(&ap_completion_wq, 10000000, SYNCH_FLAGS_NONE) == |
ESYNCH_TIMEOUT) |
printf("%s: waiting for processor (cpuid = %" PRIu32 |
") timed out\n", __func__, i); |
|
} |
|
} |
|
/** @} |