vfs: Remove KFS, blockdev and devfs
[akaros.git] / kern / arch / x86 / mpacpi.c
1 /* This file is part of the UCB release of Plan 9. It is subject to the license
2  * terms in the LICENSE file found in the top-level directory of this
3  * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
4  * part of the UCB release of Plan 9, including this file, may be copied,
5  * modified, propagated, or distributed except according to the terms contained
6  * in the LICENSE file. */
7
8 #include <vfs.h>
9 #include <slab.h>
10 #include <kmalloc.h>
11 #include <kref.h>
12 #include <string.h>
13 #include <stdio.h>
14 #include <assert.h>
15 #include <error.h>
16 #include <cpio.h>
17 #include <pmap.h>
18 #include <smp.h>
19 #include <net/ip.h>
20 #include <acpi.h>
21 #include <arch/ioapic.h>
22 #include <arch/topology.h>
23
24 int mpacpi(int ncleft)
25 {
26         char *already;
27         int np, bp;
28         struct apic *apic;
29         struct Apicst *st;
30         struct Madt *mt;
31
32         /* If we don't have an mpisabusno yet, it's because the MP tables failed to
33          * parse.  So we'll just take the last one available.  I think we're
34          * supposed to parse the ACPI shit with the AML to figure out the buses and
35          * find a clear one, but fuck that.  Note this busno is just for our own
36          * RDT/Rbus bookkeeping. */
37         if (mpisabusno == -1)
38                 mpisabusno = Nbus - 1;
39
40         if (apics == NULL)
41                 return ncleft;
42         mt = apics->tbl;
43         if (mt == NULL)
44                 return ncleft;
45
46         printd("APIC lapic paddr %#.8llux, flags %#.8ux\n",
47                    mt->lapicpa, mt->pcat);
48         np = 0;
49         printd("apics->st %p\n", apics->st);
50         for (int i = 0; i < apics->nchildren; i++) {
51                 st = apics->children[i]->tbl;
52                 already = "";
53                 switch (st->type) {
54                         case ASlapic:
55                                 printd("ASlapic %d\n", st->lapic.id);
56                                 /* this table is supposed to have all of them if it exists */
57                                 if (st->lapic.id > MaxAPICNO)
58                                         break;
59                                 apic = xlapic + st->lapic.id;
60                                 bp = (np++ == 0);
61                                 if (apic->useable) {
62                                         already = "(mp)";
63                                 } else if (ncleft != 0) {
64                                         ncleft--;
65                                         apicinit(st->lapic.id, mt->lapicpa, bp);
66                                 } else
67                                         already = "(off)";
68
69                                 printd("apic proc %d/%d apicid %d %s\n", np - 1, apic->machno,
70                                            st->lapic.id, already);
71                                 break;
72                         case ASioapic:
73                                 printd("ASioapic %d\n", st->ioapic.id);
74                                 if (st->ioapic.id > Napic)
75                                         break;
76                                 apic = xioapic + st->ioapic.id;
77                                 if (apic->useable) {
78                                         apic->ibase = st->ioapic.ibase; /* gnarly */
79                                         already = "(mp)";
80                                         goto pr1;
81                                 }
82                                 ioapicinit(st->ioapic.id, st->ioapic.ibase, st->ioapic.addr);
83 pr1:
84                                 printd("ioapic %d ", st->ioapic.id);
85                                 printd("addr %p base %d %s\n", apic->paddr, apic->ibase,
86                                            already);
87                                 break;
88                 }
89         }
90         return ncleft;
91 }