ef50dbd8dffd283a60b5b35a02753bf7b2fdbd6c
[akaros.git] / kern / arch / x86 / mpacpi.c
1 #include <vfs.h>
2 #include <kfs.h>
3 #include <slab.h>
4 #include <kmalloc.h>
5 #include <kref.h>
6 #include <string.h>
7 #include <stdio.h>
8 #include <assert.h>
9 #include <error.h>
10 #include <cpio.h>
11 #include <pmap.h>
12 #include <smp.h>
13 #include <ip.h>
14 #include <acpi.h>
15 #include <arch/ioapic.h>
16
17 extern  struct Madt     *apics;
18
19 int
20 mpacpi(int ncleft)
21 {
22         char *already;
23         int np, bp;
24         struct apic *apic;
25         struct Apicst *st;
26
27         if (apics == NULL)
28                 return ncleft;
29
30         printd("APIC lapic paddr %#.8llux, flags %#.8ux\n",
31                 apics->lapicpa, apics->pcat);
32         np = 0;
33         for(st = apics->st; st != NULL; st = st->next){
34                 already = "";
35                 switch(st->type){
36                 case ASlapic:
37                         /* this table is supposed to have all of them if it exists */
38                         if(st->lapic.id > MaxAPICNO)
39                                 break;
40                         apic = xlapic + st->lapic.id;
41                         bp = (np++ == 0);
42                         if(apic->useable){
43                                 already = "(mp)";
44                         }
45                         else if(ncleft != 0){
46                                 ncleft--;
47 #warning "not calling fictitions acpiinit"
48                                 printk("apicinit(%d, %p, %d);\n", st->lapic.id, apics->lapicpa, bp);
49                                 //apicinit(st->lapic.id, apics->lapicpa, bp);
50                         } else
51                                 already = "(off)";
52
53                         printd("apic proc %d/%d apicid %d %s\n", np-1, apic->machno, st->lapic.id, already);
54                         break;
55                 case ASioapic:
56                         if(st->ioapic.id > Napic)
57                                 break;
58                         apic = xioapic + st->ioapic.id;
59                         if(apic->useable){
60                                 apic->ibase = st->ioapic.ibase; /* gnarly */
61                                 already = "(mp)";
62                                 goto pr1;
63                         }
64                         ioapicinit(st->ioapic.id, st->ioapic.ibase, st->ioapic.addr);
65                 pr1:
66                         printd("ioapic %d ", st->ioapic.id);
67                         printd("addr %p base %d %s\n", apic->paddr, apic->ibase, already);
68                         break;
69                 }
70         }
71         return ncleft;
72 }