Arch independent per-cpu initialization
[akaros.git] / kern / arch / sparc / smp.c
index 942bc40..b00ac84 100644 (file)
@@ -3,10 +3,14 @@
 #include <arch/smp.h>
 #include <stdio.h>
 #include <string.h>
-#include <ros/error.h>
+#include <error.h>
 #include <assert.h>
 #include <atomic.h>
 
+#ifdef __SHARC__
+#pragma nosharc
+#endif
+
 #ifdef __DEPUTY__
 #pragma nodeputy
 #endif
@@ -16,30 +20,33 @@ smp_boot(void)
 {
        extern int time_for_smp_init;
        num_cpus = 1;
-       cprintf("Cores, report in!\n");
+       printd("Cores, report in!\n");
        time_for_smp_init = 1;
 
-       while(*(volatile uint8_t*)&num_cpus < num_cores());
+       smp_percpu_init();
 
-       cprintf("All cores reporting!\n");
+       while(*(volatile uint32_t*)&num_cpus < num_cores());
+
+       printd("%d cores reporting!\n",num_cpus);
 }
 
 void
 smp_init(void)
 {
-       static spinlock_t report_in_lock = 0;
-
-       cprintf("Good morning, Vietnam! (core id = %d)\n",core_id());
+       static spinlock_t report_in_lock = SPINLOCK_INITIALIZER;
 
+       smp_percpu_init();
        spin_lock(&report_in_lock);
        num_cpus++;
        spin_unlock(&report_in_lock);
 
+       printd("Good morning, Vietnam! (core id = %d)\n",core_id());
+
        smp_idle();
 }
 
 handler_wrapper_t
-wrapper_pool[MAX_NUM_CPUS*8] = {{0},0};
+wrapper_pool[MAX_NUM_CPUS*8] = {{{0},SPINLOCK_INITIALIZER}};
 
 handler_wrapper_t*
 smp_make_wrapper()
@@ -90,15 +97,13 @@ int smp_call_function_all(isr_t handler, void* data,
                if(i == core_id())
                        continue;
 
-               while(send_active_message(i,(amr_t)smp_call_wrapper,
-                                         (uint32_t)handler,(uint32_t)wrapper,
-                                         (uint32_t)data) != 0);
+               send_kernel_message(i,(amr_t)smp_call_wrapper,
+                                         handler, wrapper, data, KMSG_IMMEDIATE);
        }
 
        // send to me
-       while(send_active_message(core_id(),(amr_t)smp_call_wrapper,
-                                 (uint32_t)handler,(uint32_t)wrapper,
-                                 (uint32_t)data) != 0);
+       send_kernel_message(core_id(),(amr_t)smp_call_wrapper,
+                                 handler,wrapper,data, KMSG_IMMEDIATE);
 
        cpu_relax(); // wait to get the interrupt
 
@@ -107,7 +112,7 @@ int smp_call_function_all(isr_t handler, void* data,
        return 0;
 }
 
-int smp_call_function_single(uint8_t dest, isr_t handler, void* data,
+int smp_call_function_single(uint32_t dest, isr_t handler, void* data,
                              handler_wrapper_t** wait_wrapper)
 {
        int8_t state = 0;
@@ -122,9 +127,8 @@ int smp_call_function_single(uint8_t dest, isr_t handler, void* data,
 
        enable_irqsave(&state);
 
-       while(send_active_message(dest,(amr_t)smp_call_wrapper,
-                                 (uint32_t)handler,(uint32_t)wrapper,
-                                 (uint32_t)data) != 0);
+       send_kernel_message(dest,(amr_t)smp_call_wrapper,
+                                 handler,wrapper,data, KMSG_IMMEDIATE);
 
        cpu_relax(); // wait to get the interrupt, if it's to this core
 
@@ -142,3 +146,10 @@ int smp_call_wait(handler_wrapper_t* wrapper)
        spin_unlock(&wrapper->lock);
        return 0;
 }
+
+/* Perform any initialization needed by per_cpu_info.  Right now, this just
+ * inits the amsg list (which sparc will probably also want).  Make sure every
+ * core calls this at some point in the smp_boot process. */
+void __arch_pcpu_init(uint32_t coreid)
+{
+}