More cleanup.
[akaros.git] / kern / drivers / dev / acpi.c
index a058f71..18d978e 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},
 };
 
 /*
@@ -212,11 +214,6 @@ ioset32(uintptr_t p, uint32_t v, void*unused)
        outl(p, v);
 }
 
-#define explode_tbdf(tbdf) {pcidev.bus = tbdf >> 16;\
-               pcidev.dev = (tbdf>>11)&0x1f;\
-               pcidev.func = (tbdf>>8)&3;}
-
-
 static uint8_t
 cfgget8(uintptr_t p, void* r)
 {
@@ -628,10 +625,12 @@ acpifadt(uint8_t *p, int unused)
        gasget(&fp->xgpe0blk, p+220);
        gasget(&fp->xgpe1blk, p+232);
 
+#if 0
        static char buf[8192]; // XXX
        char *out;
        out = dumpfadt(buf, &buf[8191], fp);
        printk("%s\n", out);
+#endif
        if(fp->xfacs != 0)
                loadfacs(fp->xfacs);
        else
@@ -671,7 +670,7 @@ acpimsct(uint8_t *p, int len)
        uint8_t *pe;
        struct Mdom **stl, *st;
        int off;
-       char *dump;
+
 
        msct = kzmalloc(sizeof(struct Msct), KMALLOC_WAIT);
        msct->ndoms = l32get(p+40) + 1;
@@ -691,11 +690,14 @@ acpimsct(uint8_t *p, int len)
                *stl = st;
                stl = &st->next;
        }
-
+#if 0
+       // no longer works if called from init.c
+       char *dump;
        dump = kzmalloc(1024, KMALLOC_WAIT);
        dumpmsct(dump, &dump[1023], msct);
        printk("%s\n", dump);
        kfree(dump);
+#endif
        return NULL;    /* can be unmapped once parsed */
 }
 
@@ -731,7 +733,7 @@ dumpsrat(char *start, char *end, struct Srat *st)
 static struct Atable*
 acpisrat(uint8_t *p, int len)
 {
-       char *dump;
+
        struct Srat **stl, *st;
        uint8_t *pe;
        int stlen, flags;
@@ -792,10 +794,13 @@ acpisrat(uint8_t *p, int len)
                }
        }
 
+#if 0
+       char *dump;
        dump = kzmalloc(8192, KMALLOC_WAIT);
        dumpsrat(dump, &dump[8192], srat);
        printk("%s\n", dump);
        kfree(dump);
+#endif
        return NULL;    /* can be unmapped once parsed */
 }
 
@@ -828,7 +833,7 @@ cmpslitent(void* v1, void* v2)
 static struct Atable*
 acpislit(uint8_t *p, int len)
 {
-       char *dump;
+
        uint8_t *pe;
        int i, j, k;
        struct SlEntry *se;
@@ -848,12 +853,14 @@ acpislit(uint8_t *p, int len)
                se->dom = k;
                se->dist = *p;
        }
+
+#warning "no qsort"
+#if 0
+       char *dump;
        dump = kzmalloc(8192, KMALLOC_WAIT);
        dumpslit(dump, &dump[8191], slit);
        printk("%s", dump);
        kfree(dump);
-#warning "no qsort"
-#if 0
        for(i = 0; i < slit->rowlen; i++)
                qsort(slit->e[i], slit->rowlen, sizeof(slit->e[0][0]), cmpslitent);
        
@@ -925,6 +932,28 @@ pickcore(int mycolor, int index)
 }
 
 
+static char *polarity[4] = {
+       "polarity/trigger like in ISA",
+       "active high",
+       "BOGUS POLARITY",
+       "active low"
+};
+
+static char *trigger[] = {
+       "BOGUS TRIGGER",
+       "edge",
+       "BOGUS TRIGGER",
+       "level"
+};
+
+static char *printiflags(char *start, char *end, int flags)
+{
+
+       return seprintf(start, end, "[%s,%s]",
+               polarity[flags & AFpmask], 
+               trigger[(flags & AFtmask)>>2]);
+}
+
 static char *
 dumpmadt(char *start, char *end, struct Madt *apics)
 {
@@ -932,6 +961,7 @@ dumpmadt(char *start, char *end, struct Madt *apics)
 
        start = seprintf(start, end, "acpi: madt lapic paddr %llux pcat %d:\n", apics->lapicpa, apics->pcat);
        for(st = apics->st; st != NULL; st = st->next)
+
                switch(st->type){
                case ASlapic:
                        start = seprintf(start, end, "\tlapic pid %d id %d\n", st->lapic.pid, st->lapic.id);
@@ -939,11 +969,13 @@ dumpmadt(char *start, char *end, struct Madt *apics)
                case ASioapic:
                case ASiosapic:
                        start = seprintf(start, end, "\tioapic id %d addr %#llux ibase %d\n",
-                               st->ioapic.id, st->ioapic.addr, st->ioapic.ibase);
+                                        st->ioapic.id, st->ioapic.addr, st->ioapic.ibase);
                        break;
                case ASintovr:
-                       start = seprintf(start, end, "\tintovr irq %d intr %d flags $%p\n",
-                               st->intovr.irq, st->intovr.intr,st->intovr.flags);
+                       start = seprintf(start, end, "\tintovr irq %d intr %d flags $%p",
+                                        st->intovr.irq, st->intovr.intr,st->intovr.flags);
+                       start = printiflags(start, end, st->intovr.flags);
+                       start = seprintf(start, end, "\n");
                        break;
                case ASnmi:
                        start = seprintf(start, end, "\tnmi intr %d flags $%p\n",
@@ -964,6 +996,8 @@ dumpmadt(char *start, char *end, struct Madt *apics)
                                st->type, st->intsrc.pid,
                                st->intsrc.peid, st->intsrc.iosv,
                                st->intsrc.intr, st->intsrc.flags);
+                       start = printiflags(start, end, st->intsrc.flags);
+                       start = seprintf(start, end, "\n");
                        break;
                case ASlx2apic:
                        start = seprintf(start, end, "\tlx2apic puid %d id %d\n", st->lx2apic.puid, st->lx2apic.id);
@@ -982,7 +1016,7 @@ dumpmadt(char *start, char *end, struct Madt *apics)
 static struct Atable*
 acpimadt(uint8_t *p, int len)
 {
-       char *dump;
+
        uint8_t *pe;
        struct Apicst *st, *l, **stl;
        int stlen, id;
@@ -1095,10 +1129,13 @@ acpimadt(uint8_t *p, int len)
                        stl = &st->next;
                }
        }
+#if 0
+       char *dump;
        dump = kzmalloc(8192, KMALLOC_WAIT);
        dumpmadt(dump, &dump[8191], apics);
        printk("%s\n", dump);
        kfree(dump);
+#endif
        return NULL;    /* can be unmapped once parsed */
 }
 
@@ -1185,7 +1222,7 @@ acpixsdtload(char *sig)
                        printk("acpi: %s addr %#p\n", tsig, sdt);
                        for(t = 0; t < ARRAY_SIZE(ptables); t++)
                                if(strcmp(tsig, ptables[t].sig) == 0){
-                                       dumptable(table, &table[127], tsig, sdt, l);
+                                       //dumptable(table, &table[127], tsig, sdt, l);
                                        unmap = ptables[t].f(sdt, l) == NULL;
                                        found = 1;
                                        break;
@@ -1550,6 +1587,7 @@ acpiioalloc(unsigned int addr, int len)
 int
 acpiinit(void)
 {
+       /* this smicmd test implements 'run once' for now. */
        if(fadt.smicmd == 0){
                //fmtinstall('G', Gfmt);
                acpirsdptr();
@@ -1645,55 +1683,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)