]> git.lizzy.rs Git - plan9front.git/blob - sys/src/9/pc/squidboy.c
sdide: never timeout or retry scsi commands from the controller driver
[plan9front.git] / sys / src / 9 / pc / squidboy.c
1 #include "u.h"
2 #include "../port/lib.h"
3 #include "mem.h"
4 #include "dat.h"
5 #include "fns.h"
6 #include "io.h"
7 #include "ureg.h"
8
9 #include "mp.h"
10
11 extern void checkmtrr(void);
12
13 static void
14 squidboy(Apic* apic)
15 {
16 //      iprint("Hello Squidboy\n");
17
18         machinit();
19         mmuinit();
20
21         cpuidentify();
22         cpuidprint();
23         checkmtrr();
24
25         apic->online = 1;
26         coherence();
27
28         lapicinit(apic);
29         lapiconline();
30         syncclock();
31         timersinit();
32
33         fpoff();
34
35         lock(&active);
36         active.machs |= 1<<m->machno;
37         unlock(&active);
38
39         while(!active.thunderbirdsarego)
40                 microdelay(100);
41
42         schedinit();
43 }
44
45 void
46 mpstartap(Apic* apic)
47 {
48         ulong *apbootp, *pdb, *pte;
49         Mach *mach, *mach0;
50         int i, machno;
51         uchar *p;
52
53         mach0 = MACHP(0);
54
55         /*
56          * Initialise the AP page-tables and Mach structure. The page-tables
57          * are the same as for the bootstrap processor with the exception of
58          * the PTE for the Mach structure.
59          * Xspanalloc will panic if an allocation can't be made.
60          */
61         p = xspanalloc(4*BY2PG, BY2PG, 0);
62         pdb = (ulong*)p;
63         memmove(pdb, mach0->pdb, BY2PG);
64         p += BY2PG;
65
66         if((pte = mmuwalk(pdb, MACHADDR, 1, 0)) == nil)
67                 return;
68         memmove(p, KADDR(PPN(*pte)), BY2PG);
69         *pte = PADDR(p)|PTEWRITE|PTEVALID;
70         if(mach0->havepge)
71                 *pte |= PTEGLOBAL;
72         p += BY2PG;
73
74         mach = (Mach*)p;
75         if((pte = mmuwalk(pdb, MACHADDR, 2, 0)) == nil)
76                 return;
77         *pte = PADDR(mach)|PTEWRITE|PTEVALID;
78         if(mach0->havepge)
79                 *pte |= PTEGLOBAL;
80         p += BY2PG;
81
82         machno = apic->machno;
83         MACHP(machno) = mach;
84         mach->machno = machno;
85         mach->pdb = pdb;
86         mach->gdt = (Segdesc*)p;        /* filled by mmuinit */
87
88         /*
89          * Tell the AP where its kernel vector and pdb are.
90          * The offsets are known in the AP bootstrap code.
91          */
92         apbootp = (ulong*)(APBOOTSTRAP+0x08);
93         *apbootp++ = (ulong)squidboy;   /* assembler jumps here eventually */
94         *apbootp++ = PADDR(pdb);
95         *apbootp = (ulong)apic;
96
97         /*
98          * Universal Startup Algorithm.
99          */
100         p = KADDR(0x467);               /* warm-reset vector */
101         *p++ = PADDR(APBOOTSTRAP);
102         *p++ = PADDR(APBOOTSTRAP)>>8;
103         i = (PADDR(APBOOTSTRAP) & ~0xFFFF)/16;
104         /* code assumes i==0 */
105         if(i != 0)
106                 print("mp: bad APBOOTSTRAP\n");
107         *p++ = i;
108         *p = i>>8;
109         coherence();
110
111         nvramwrite(0x0F, 0x0A);         /* shutdown code: warm reset upon init ipi */
112         lapicstartap(apic, PADDR(APBOOTSTRAP));
113         for(i = 0; i < 1000; i++){
114                 if(apic->online)
115                         break;
116                 delay(10);
117         }
118         nvramwrite(0x0F, 0x00);
119 }