More ioapic support, will it ever end.
[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                                 apicinit(st->lapic.id, apics->lapicpa, bp);
48                         } else
49                                 already = "(off)";
50
51                         printd("apic proc %d/%d apicid %d %s\n", np-1, apic->machno, st->lapic.id, already);
52                         break;
53                 case ASioapic:
54                         if(st->ioapic.id > Napic)
55                                 break;
56                         apic = xioapic + st->ioapic.id;
57                         if(apic->useable){
58                                 apic->ibase = st->ioapic.ibase; /* gnarly */
59                                 already = "(mp)";
60                                 goto pr1;
61                         }
62                         ioapicinit(st->ioapic.id, st->ioapic.ibase, st->ioapic.addr);
63                 pr1:
64                         printd("ioapic %d ", st->ioapic.id);
65                         printd("addr %p base %d %s\n", apic->paddr, apic->ibase, already);
66                         break;
67                 }
68         }
69         return ncleft;
70 }