Map PTEs for MAP_SHARED | MAP_LOCKED files on fork
[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 <kfs.h>
10 #include <slab.h>
11 #include <kmalloc.h>
12 #include <kref.h>
13 #include <string.h>
14 #include <stdio.h>
15 #include <assert.h>
16 #include <error.h>
17 #include <cpio.h>
18 #include <pmap.h>
19 #include <smp.h>
20 #include <ip.h>
21 #include <acpi.h>
22 #include <arch/ioapic.h>
23 #include <arch/topology.h>
24
25 int mpacpi(int ncleft)
26 {
27         char *already;
28         int np, bp;
29         struct apic *apic;
30         struct Apicst *st;
31         struct Madt *mt;
32
33         /* If we don't have an mpisabusno yet, it's because the MP tables failed to
34          * parse.  So we'll just take the last one available.  I think we're
35          * supposed to parse the ACPI shit with the AML to figure out the buses and
36          * find a clear one, but fuck that.  Note this busno is just for our own
37          * RDT/Rbus bookkeeping. */
38         if (mpisabusno == -1)
39                 mpisabusno = Nbus - 1;
40
41         if (apics == NULL)
42                 return ncleft;
43         mt = apics->tbl;
44         if (mt == NULL)
45                 return ncleft;
46
47         printd("APIC lapic paddr %#.8llux, flags %#.8ux\n",
48                    mt->lapicpa, mt->pcat);
49         np = 0;
50         printd("apics->st %p\n", apics->st);
51         for (int i = 0; i < apics->nchildren; i++) {
52                 st = apics->children[i]->tbl;
53                 already = "";
54                 switch (st->type) {
55                         case ASlapic:
56                                 printd("ASlapic %d\n", st->lapic.id);
57                                 /* this table is supposed to have all of them if it exists */
58                                 if (st->lapic.id > MaxAPICNO)
59                                         break;
60                                 apic = xlapic + st->lapic.id;
61                                 bp = (np++ == 0);
62                                 if (apic->useable) {
63                                         already = "(mp)";
64                                 } else if (ncleft != 0) {
65                                         ncleft--;
66                                         apicinit(st->lapic.id, mt->lapicpa, bp);
67                                 } else
68                                         already = "(off)";
69
70                                 printd("apic proc %d/%d apicid %d %s\n", np - 1, apic->machno,
71                                            st->lapic.id, already);
72                                 break;
73                         case ASioapic:
74                                 printd("ASioapic %d\n", st->ioapic.id);
75                                 if (st->ioapic.id > Napic)
76                                         break;
77                                 apic = xioapic + st->ioapic.id;
78                                 if (apic->useable) {
79                                         apic->ibase = st->ioapic.ibase; /* gnarly */
80                                         already = "(mp)";
81                                         goto pr1;
82                                 }
83                                 ioapicinit(st->ioapic.id, st->ioapic.ibase, st->ioapic.addr);
84 pr1:
85                                 printd("ioapic %d ", st->ioapic.id);
86                                 printd("addr %p base %d %s\n", apic->paddr, apic->ibase,
87                                            already);
88                                 break;
89                 }
90         }
91         return ncleft;
92 }