Improve visibility of apics/ioapics
authorRonald G. Minnich <rminnich@google.com>
Mon, 3 Mar 2014 18:07:52 +0000 (10:07 -0800)
committerRonald G. Minnich <rminnich@google.com>
Mon, 3 Mar 2014 18:07:52 +0000 (10:07 -0800)
if you cat '#a/ioapic' and '#a/apic', you'll see some useful
info about them. This is much better than the simple kernel dump.

Signed-off-by: Ronald G. Minnich <rminnich@google.com>
kern/arch/x86/apic.h
kern/arch/x86/apic9.c
kern/arch/x86/ioapic.c
kern/arch/x86/ioapic.h
kern/drivers/dev/acpi.c
kern/include/acpi.h

index d2d2dc9..d1fc60b 100644 (file)
@@ -403,9 +403,8 @@ extern      struct apic     xioapic[Napic];
 
 #include <arch/ioapic.h>
 
-void apicdump(void);
+char *apicdump(char *, char *);
 void apictimerenab(void);
-void ioapicdump(void);
 void apicinit(int apicno, uintptr_t pa, int isbp);
 
 /*
index 72be190..3143c0a 100644 (file)
@@ -144,50 +144,56 @@ apicinit(int apicno, uintptr_t pa, int isbp)
                printk("apicinit%d: apicbase %#p -> %#p\n", apicno, pa, apicbase);
        }
        apic->useable = 1;
+       printk("apicinit%d: it's useable\n", apicno);
 
        /*
         * Assign a machno to the processor associated with this
         * APIC, it may not be an identity map.
         * Machno 0 is always the bootstrap processor.
+        */
 
        if(isbp){
                apic->machno = 0;
-               m->apicno = apicno;
+#warning "where in pcpui do we put the apicno?"
+               //m->apicno = apicno;
        }
        else
                apic->machno = apmachno++;
-        */
 }
-#if 0
-static void
-apicdump0(struct apic *apic, int i)
+
+static char *
+apicdump0(char *start, char *end, struct apic *apic, int i)
 {
        if(!apic->useable || apic->addr != 0)
-               return;
-       printk("apic%d: machno %d lint0 %#8.8ux lint1 %#8.8ux\n",
+               return start;
+       start = seprintf(start, end, "apic%d: machno %d lint0 %#8.8p lint1 %#8.8p\n",
                i, apic->machno, apic->lvt[0], apic->lvt[1]);
-       printk(" tslvt %#8.8ux pclvt %#8.8ux elvt %#8.8ux\n",
+       start = seprintf(start, end, " tslvt %#8.8p pclvt %#8.8p elvt %#8.8p\n",
                apicrget(Tslvt), apicrget(Pclvt), apicrget(Elvt));
-       printk(" tlvt %#8.8ux lint0 %#8.8ux lint1 %#8.8ux siv %#8.8ux\n",
+       start = seprintf(start, end, " tlvt %#8.8p lint0 %#8.8p lint1 %#8.8p siv %#8.8p\n",
                apicrget(Tlvt), apicrget(Lint0),
                apicrget(Lint1), apicrget(Siv));
+       return start;
 }
 
-void
-apicdump(void)
+char *
+apicdump(char *start, char *end)
 {
        int i;
 
        if(!2)
-               return;
+               return start;
 
-       printk("apicbase %#p apmachno %d\n", apicbase, apmachno);
+       start = seprintf(start, end, "apicbase %#p apmachno %d\n", apicbase, apmachno);
        for(i = 0; i < Napic; i++)
-               apicdump0(xlapic + i, i);
+               start = apicdump0(start, end, xlapic + i, i);
+       /* endxioapic?
        for(i = 0; i < Napic; i++)
-               apicdump0(xioapic + i, i);
+               start = apicdump0(start, endxioapic + i, i);
+       */
+       return start;
 }
-
+#if 0
 static void
 apictimer(Ureg* ureg, void*)
 {
index 2bf9530..b256922 100644 (file)
@@ -178,8 +178,8 @@ ioapicinit(int id, int ibase, uintptr_t pa)
        spin_unlock(&apic->lock);
 }
 
-void
-ioapicdump(void)
+char *
+ioapicdump(char *start, char *end)
 {
        int i, n;
        struct Rbus *rbus;
@@ -188,31 +188,33 @@ ioapicdump(void)
        uint32_t hi, lo;
 
        if(!2)
-               return;
+               return start;
        for(i = 0; i < Napic; i++){
                apic = &xioapic[i];
                if(!apic->useable || apic->addr == 0)
                        continue;
-               printd("ioapic %d addr %#p nrdt %d ibase %d\n",
+               start = seprintf(start, end, "ioapic %d addr %#p nrdt %d ibase %d\n",
                        i, apic->addr, apic->nrdt, apic->ibase);
                for(n = 0; n < apic->nrdt; n++){
                        spin_lock(&apic->lock);
                        rtblget(apic, n, &hi, &lo);
                        spin_unlock(&apic->lock);
-                       printd(" rdt %2.2d %#8.8ux %#8.8ux\n", n, hi, lo);
+                       start = seprintf(start, end, " rdt %2.2d %#8.8p %#8.8p\n", n, hi, lo);
                }
        }
        for(i = 0; i < Nbus; i++){
                if((rbus = rdtbus[i]) == NULL)
                        continue;
-               printd("iointr bus %d:\n", i);
+               start = seprintf(start, end, "iointr bus %d:\n", i);
                for(; rbus != NULL; rbus = rbus->next){
                        rdt = rbus->rdt;
-                       printd(" apic %ld devno %#ux (%d %d) intin %d lo %#ux ref %d\n",
+                       start = seprintf(start, end,
+                               " apic %ld devno %#p (%d %d) intin %d lo %#p ref %d\n",
                                rdt->apic-xioapic, rbus->devno, rbus->devno>>2,
                                rbus->devno & 0x03, rdt->intin, rdt->lo, rdt->ref);
                }
        }
+       return start;
 }
 
 void
@@ -230,7 +232,6 @@ ioapiconline(void)
                        spin_unlock(&apic->lock);
                }
        }
-       ioapicdump();
 }
 
 static int dfpolicy = 0;
index c1c98a7..80bad71 100644 (file)
@@ -53,8 +53,9 @@ enum {
        IOAPIC_PBASE    = 0xfec00000, /* default *physical* address */
 };
 
-extern void ioapicinit(int id, int ibase, uintptr_t pa);
-extern void ioapicrdtr(struct apic*, int unused_int, int*, int*);
-extern void ioapicrdtw(struct apic*, int unused_int, int, int);
+void ioapicinit(int id, int ibase, uintptr_t pa);
+void ioapicrdtr(struct apic*, int unused_int, int*, int*);
+void ioapicrdtw(struct apic*, int unused_int, int, int);
+char *ioapicdump(char *start, char *end);
 
 #endif /* ROS_KERN_IOAPIC_H */
index 19bd2e9..5275771 100644 (file)
@@ -55,6 +55,8 @@ static struct dirtab acpidir[]={
        {"acpitbl",     {Qtbl},                 0,      0444},
        {"acpiregio",   {Qio},                  0,      0666},
        {"acpipretty",  {Qpretty},              0,      0444},
+       {"ioapic",      {Qioapic},              0,      0444},
+       {"apic",        {Qapic},                0,      0444},
 };
 
 /*
@@ -1684,55 +1686,51 @@ acpiread(struct chan *c, void *a, long n, int64_t off)
        struct Atable *t;
        char *ns, *s, *e, *ntext;
 
+       if (ttext == NULL) {
+               tlen = 32768;
+               ttext = kzmalloc(tlen, KMALLOC_WAIT);
+       }
+       if (ttext == NULL) {
+               error("acpiread: no memory");
+       }
        q = c->qid.path;
        switch(q){
        case Qdir:
                return devdirread(c, a, n, acpidir, ARRAY_SIZE(acpidir), acpigen);
        case Qtbl:
-               if(ttext == NULL){ // XXXXXX
-                       tlen = 32768;
-                       ttext = kzmalloc(tlen, 0);
-                       if(ttext == NULL){
-                               printd("acpi: no memory\n");
-                               return 0;
-                       }
-                       s = ttext;
-                       e = ttext + tlen;
-                       strncpy(s,  "no tables\n", sizeof(s));
-                       for(t = tfirst; t != NULL; t = t->next){
+               s = ttext;
+               e = ttext + tlen;
+               strncpy(s,  "no tables\n", sizeof(s));
+               for(t = tfirst; t != NULL; t = t->next){
+                       ns = seprinttable(s, e, t);
+                       while(ns == e - 1){
+                               printk("acpiread: allocated %d\n", tlen*2);
+                               ntext = krealloc(ttext, tlen*2, 0);
+                               if(ntext == NULL)
+                                       panic("acpi: no memory\n");
+                               s = ntext + (ttext - s);
+                               ttext = ntext;
+                               tlen *= 2;
+                               e = ttext + tlen;
                                ns = seprinttable(s, e, t);
-                               while(ns == e - 1){
-                                       printk("acpiread: allocated %d\n", tlen*2);
-                                       ntext = krealloc(ttext, tlen*2, 0);
-                                       if(ntext == NULL)
-                                               panic("acpi: no memory\n");
-                                       s = ntext + (ttext - s);
-                                       ttext = ntext;
-                                       tlen *= 2;
-                                       e = ttext + tlen;
-                                       ns = seprinttable(s, e, t);
-                               }
-                               s = ns;
                        }
-                                       
+                       s = ns;
                }
                return readstr(off, a, n, ttext);
        case Qpretty:
-               if(ttext == NULL){
-                       tlen = 32768;
-                       ttext = kzmalloc(tlen, 0);
-                       if(ttext == NULL){
-                               printd("acpi: no memory\n");
-                               return 0;
-                       }
-                       s = ttext;
-                       e = ttext + tlen;
-                       s = dumpfadt(s, e, &fadt);
-                       s = dumpmadt(s, e, apics);
-                       s = dumpslit(s, e, slit);
-                       s = dumpsrat(s, e, srat);
-                       dumpmsct(s, e, msct);
-               }
+               s = ttext;
+               e = ttext + tlen;
+               s = dumpfadt(s, e, &fadt);
+               s = dumpmadt(s, e, apics);
+               s = dumpslit(s, e, slit);
+               s = dumpsrat(s, e, srat);
+               dumpmsct(s, e, msct);
+               return readstr(off, a, n, ttext);
+       case Qioapic:
+               s = ioapicdump(ttext, ttext + tlen);
+               return readstr(off, a, n, ttext);
+       case Qapic:
+               s = apicdump(ttext, ttext + tlen);
                return readstr(off, a, n, ttext);
        case Qio:
                if(reg == NULL)
index f01ed04..e580c0a 100644 (file)
@@ -77,6 +77,8 @@ enum
        Qtbl,
        Qio,
        Qpretty,
+       Qioapic,
+       Qapic,
 };
 
 /*