Rev 4130 | Rev 4638 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 4130 | Rev 4614 | ||
|---|---|---|---|
| Line 35... | Line 35... | ||
| 35 | 35 | ||
| 36 | #include <smp/smp.h> |
36 | #include <smp/smp.h> |
| 37 | #include <genarch/ofw/ofw_tree.h> |
37 | #include <genarch/ofw/ofw_tree.h> |
| 38 | #include <cpu.h> |
38 | #include <cpu.h> |
| 39 | #include <arch/cpu.h> |
39 | #include <arch/cpu.h> |
| - | 40 | #include <arch/boot/boot.h> |
|
| 40 | #include <arch.h> |
41 | #include <arch.h> |
| 41 | #include <config.h> |
42 | #include <config.h> |
| 42 | #include <macros.h> |
43 | #include <macros.h> |
| 43 | #include <arch/types.h> |
44 | #include <arch/types.h> |
| 44 | #include <synch/synch.h> |
45 | #include <synch/synch.h> |
| 45 | #include <synch/waitq.h> |
46 | #include <synch/waitq.h> |
| 46 | #include <print.h> |
47 | #include <print.h> |
| - | 48 | #include <arch/sun4v/hypercall.h> |
|
| - | 49 | #include <arch/sun4v/md.h> |
|
| - | 50 | #include <time/delay.h> |
|
| - | 51 | ||
| - | 52 | #define CPU_STATE_RUNNING 2 |
|
| - | 53 | ||
| - | 54 | extern void kernel_image_start(void); |
|
| - | 55 | extern void *trap_table; |
|
| 47 | 56 | ||
| 48 | /** Determine number of processors. */ |
57 | /** Determine number of processors. */ |
| 49 | void smp_init(void) |
58 | void smp_init(void) |
| 50 | { |
59 | { |
| - | 60 | md_node_t node = md_get_root(); |
|
| - | 61 | count_t cpu_count = 0; |
|
| - | 62 | ||
| 51 | // TODO: replace with a real # of CPUs as soon as the MD walkthrough is implemented |
63 | /* walk through MD, find the current CPU node & its clock-frequency */ |
| - | 64 | while(md_next_node(&node, "cpu")) { |
|
| - | 65 | cpu_count++; |
|
| - | 66 | } |
|
| - | 67 | ||
| 52 | config.cpu_count = 1; |
68 | config.cpu_count = cpu_count; |
| 53 | } |
69 | } |
| 54 | 70 | ||
| 55 | 71 | ||
| 56 | /** Wake application processors up. */ |
72 | /** Wake application processors up. */ |
| 57 | void kmp(void *arg) |
73 | void kmp(void *arg) |
| 58 | { |
74 | { |
| - | 75 | (void) arg; |
|
| - | 76 | ||
| - | 77 | uint64_t myid; |
|
| - | 78 | __hypercall_fast_ret1(0, 0, 0, 0, 0, CPU_MYID, &myid); |
|
| - | 79 | ||
| 59 | // TODO: implement as soon as the MD walkthrough is implemented |
80 | /* stop the CPUs before making them execute our code */ |
| - | 81 | uint64_t i; |
|
| - | 82 | for (i = 0; i < config.cpu_count; i++) { |
|
| - | 83 | if (i == myid) |
|
| - | 84 | continue; |
|
| - | 85 | ||
| - | 86 | if (__hypercall_fast1(CPU_STOP, i) != 0) |
|
| - | 87 | continue; |
|
| - | 88 | ||
| - | 89 | uint64_t state; |
|
| - | 90 | __hypercall_fast_ret1(i, 0, 0, 0, 0, CPU_STATE, &state); |
|
| - | 91 | while (state == CPU_STATE_RUNNING) { |
|
| - | 92 | __hypercall_fast_ret1(i, 0, 0, 0, 0, CPU_STATE, &state); |
|
| - | 93 | } |
|
| - | 94 | } |
|
| - | 95 | ||
| - | 96 | /* wake the processors up, one by one */ |
|
| - | 97 | uint64_t state; |
|
| - | 98 | for (i = 1; i < config.cpu_count; i++) { |
|
| - | 99 | __hypercall_fast_ret1(i, 0, 0, 0, 0, CPU_STATE, &state); |
|
| - | 100 | printf("Starting CPU %d, error code = %d.\n", i, __hypercall_fast4( |
|
| - | 101 | CPU_START, |
|
| - | 102 | i, |
|
| - | 103 | (uint64_t) KA2PA(kernel_image_start), |
|
| - | 104 | KA2PA(trap_table), |
|
| - | 105 | bootinfo.physmem_start |
|
| - | 106 | )); |
|
| - | 107 | ||
| - | 108 | if (waitq_sleep_timeout(&ap_completion_wq, 10000000, SYNCH_FLAGS_NONE) == |
|
| - | 109 | ESYNCH_TIMEOUT) |
|
| - | 110 | printf("%s: waiting for processor (cpuid = %" PRIu32 |
|
| - | 111 | ") timed out\n", __func__, i); |
|
| - | 112 | ||
| - | 113 | } |
|
| - | 114 | ||
| 60 | } |
115 | } |
| 61 | 116 | ||
| 62 | /** @} |
117 | /** @} |
| 63 | */ |
118 | */ |