summaryrefslogtreecommitdiff
path: root/kernel/smp.c
diff options
context:
space:
mode:
authorMichal Idziorek <m.i@gmx.at>2014-09-03 00:15:51 +0200
committerMichal Idziorek <m.i@gmx.at>2014-09-03 00:15:51 +0200
commitaad04a2208fbde8db2c1a81d6057c1ac4edb390e (patch)
tree87f3b47c5f85d6c7c5921e799571b42906d0eb0a /kernel/smp.c
parent1a3a3a20773a5664c653a8aebcd10d288962285b (diff)
ACPI support !
Diffstat (limited to 'kernel/smp.c')
-rw-r--r--kernel/smp.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/kernel/smp.c b/kernel/smp.c
new file mode 100644
index 0000000..58e37a5
--- /dev/null
+++ b/kernel/smp.c
@@ -0,0 +1,52 @@
+#define FOOLOS_MODULE_NAME "smp"
+
+#include "lib/logger/log.h"
+#include "lib/int/stdint.h"
+#include "smp.h"
+
+#define FOOLOS_APIC_SPUR_INT 0x00f0
+#define FOOLOS_APIC_INT_COMMAND_LOW 0x0300
+#define FOOLOS_APIC_INT_COMMAND_HIGH 0x0310
+
+void smp_log_procdata(smp_processors *procdata)
+{
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"---- smp -----");
+ for(int i=0;i<procdata->processors;i++)
+ {
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"cpu %d : local_apic_id: 0x%X bps: %s local_apic_addr:0x%08X",i,procdata->local_apic_id[i],i==procdata->boot?"yes":"no",procdata->local_apic_address);
+ }
+
+}
+
+// this will start all our application processors!
+void smp_start_aps(smp_processors *pros)
+{
+
+ //bsp (boot processor) enables its local apic
+ uint32_t *reg=pros->local_apic_address+FOOLOS_APIC_SPUR_INT;
+ *reg=0xffffffff; // all bits 1 and interrupt 255
+
+ for(int i=0;i<pros->processors;i++)
+ {
+ if(pros->boot==i)continue;
+
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"starting cpu %d",i);
+
+ uint8_t dest=pros->local_apic_id[i];
+
+ reg=pros->local_apic_address+FOOLOS_APIC_INT_COMMAND_HIGH;
+ *reg=dest<<24; // destination apic.
+
+ reg=pros->local_apic_address+FOOLOS_APIC_INT_COMMAND_LOW;
+ *reg=(5<<8)|(1<<14); // 101 INIT
+
+ // do we really neet this?
+ // todo: use some real sleep (not implemented yet :( )
+ sleep(10);
+
+ // start proc at 0x7000;
+ *reg=(6<<8)|(1<<14)|0x7; // 110 SIPI
+ }
+}
+
+