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