actually update pci.c, and catch a few more bits. Reference: /n/atom/patch/applied/pae64bitbar2 Date: Sat Jan 11 19:48:56 CET 2014 Signed-off-by: quanstro@quanstro.net --- /sys/src/9/pcpae/pci.c Sat Jan 11 19:48:24 2014 +++ /sys/src/9/pcpae/pci.c Sat Jan 11 19:48:24 2014 @@ -1,7 +1,4 @@ -/* - * PCI support code. - * Needs a massive rewrite. - */ +/* pci */ #include "u.h" #include "../port/lib.h" #include "mem.h" @@ -10,10 +7,9 @@ #include "io.h" -enum -{ - PciADDR = 0xCF8, /* CONFIG_ADDRESS */ - PciDATA = 0xCFC, /* CONFIG_DATA */ +enum { /* configuration mechanism #1 */ + PciADDR = 0xCF8, + PciDATA = 0xCFC, Maxfn = 7, Maxdev = 31, @@ -130,7 +126,7 @@ return r; } -static uint +static u32int pcibarsize(Pcidev *p, int rno) { u32int v, size; @@ -145,11 +141,37 @@ return -(size & ~0x0F); } +static void +pcibars(Pcidev *p) +{ + int i, o; + u32int bar; + + for(i = 0; i < nelem(p->mem); i++) { + o = PciBAR0+4*i; + p->mem[i].bar = (u32int)pcicfgr32(p, o); + p->mem[i].size = pcibarsize(p, o); + if(i&1 || (p->mem[i].bar & 2<<1) == 0) + continue; + bar = pcicfgr32(p, o+4); + if(sizeof(uintmem) >= sizeof(u64int)) + p->mem[i].bar |= (u64int)bar<<32; + else if(bar != 0){ + print("%T: warning 64-bit bar %d too large\n", p->tbdf, i); + p->mem[i].bar = 0; + p->mem[i].size = 0; + } + i++; + p->mem[i].bar = 0; + p->mem[i].size = 0; + } +} + static int pcilscan(int bno, Pcidev** list) { Pcidev *p, *head, *tail; - int dno, fno, i, hdt, l, maxfno, maxubn, sbn, tbdf, ubn; + int dno, fno, hdt, l, maxfno, maxubn, sbn, tbdf, ubn; maxubn = bno; head = nil; @@ -204,12 +226,8 @@ */ switch(p->ccrb) { default: - if((hdt & 0x7F) != 0) - break; - for(i = 0; i < nelem(p->mem); i++) { - p->mem[i].bar = pcicfgr32(p, PciBAR0+4*i); - p->mem[i].size = pcibarsize(p, PciBAR0+4*i); - } + if((hdt & 0x7F) == 0) + pcibars(p); break; case 0x00: @@ -265,12 +283,9 @@ } else { /* - * You can't go back. - * This shouldn't be possible, but the - * Iwill DK8-HTX seems to have subordinate - * bus numbers which get smaller on the - * way down. Need to look more closely at - * this. + * You can't go back. This shouldn't be possible, but the + * Iwill DK8-HTX seems to have decreasing subordinate + * bus numbers Need to look more closely at his. */ if(ubn > maxubn) maxubn = ubn; @@ -281,7 +296,7 @@ return maxubn; } -static uchar +static uchar pIIxget(Pcidev *router, uchar link) { uchar pirq; @@ -291,13 +306,13 @@ return (pirq < 16)? pirq: 0; } -static void +static void pIIxset(Pcidev *router, uchar link, uchar irq) { pcicfgw8(router, link, irq); } -static uchar +static uchar viaget(Pcidev *router, uchar link) { uchar pirq; @@ -308,7 +323,7 @@ return (link & 1)? (pirq >> 4): (pirq & 15); } -static void +static void viaset(Pcidev *router, uchar link, uchar irq) { uchar pirq; @@ -325,43 +340,42 @@ ushort vid; ushort did; uchar (*get)(Pcidev *, uchar); - void (*set)(Pcidev *, uchar, uchar); + void (*set)(Pcidev *, uchar, uchar); }; static Bridge southbridges[] = { - { 0x8086, 0xffff, pIIxget, pIIxset }, // Intel * - { 0x1106, 0x3227, viaget, viaset }, // Viatech VT8237 + { 0x8086, 0xffff, pIIxget, pIIxset }, /* Intel * */ - { 0x1022, 0x746B, nil, nil }, // AMD 8111 - { 0x10DE, 0x00D1, nil, nil }, // NVIDIA nForce 3 - { 0x1166, 0x0200, nil, nil }, // ServerWorks ServerSet III LE - { 0x1002, 0x4377, nil, nil }, // ATI Radeon Xpress 200M + { 0x1002, 0xffff, nil, nil }, /* ati (amd) */ + { 0x1022, 0xffff, nil, nil }, /* amd */ + { 0x10de, 0x00d1, nil, nil }, /* NVIDIA nForce 3 */ + { 0x1106, 0x3227, viaget, viaset }, /* Viatech VT8237 */ + { 0x1166, 0x0200, nil, nil }, /* ServerWorks ServerSet III LE */ }; typedef struct Slot Slot; struct Slot { - uchar bus; // Pci bus number - uchar dev; // Pci device number - uchar maps[12]; // Avoid structs! Link and mask. - uchar slot; // Add-in/built-in slot + uchar bus; /* Pci bus number */ + uchar dev; /* Pci device number */ + uchar maps[12]; /* Avoid structs! Link and mask. */ + uchar slot; /* Add-in/built-in slot */ uchar reserved; }; typedef struct Router Router; struct Router { - uchar signature[4]; // Routing table signature - uchar version[2]; // Version number - uchar size[2]; // Total table size - uchar bus; // Interrupt router bus number - uchar devfn; // Router's devfunc - uchar pciirqs[2]; // Exclusive PCI irqs - uchar compat[4]; // Compatible PCI interrupt router - uchar miniport[4]; // Miniport data + uchar signature[4]; /* Routing table signature */ + uchar version[2]; /* Version number */ + uchar size[2]; /* Total table size */ + uchar bus; /* Interrupt router bus number */ + uchar devfn; /* Router's devfunc */ + uchar pciirqs[2]; /* Exclusive PCI irqs */ + uchar compat[4]; /* Compatible PCI interrupt router */ + uchar miniport[4]; /* Miniport data */ uchar reserved[11]; uchar checksum; }; - static void pcirouting(void) { @@ -372,8 +386,8 @@ Router *r; Slot *e; - // Search for PCI interrupt routing table in BIOS - for(p = (uchar *)KADDR(0xf0000); p < (uchar *)KADDR(0xfffff); p += 16) + /* Search for PCI interrupt routing table in BIOS */ + for(p = (uchar*)KADDR(0xf0000); p < (uchar*)KADDR(0xfffff); p += 16) if(p[0] == '$' && p[1] == 'P' && p[2] == 'I' && p[3] == 'R') break; @@ -383,8 +397,8 @@ r = (Router *)p; if(0) - print("PCI interrupt routing table version %d.%d at %.6p\n", - r->version[0], r->version[1], (uintptr)r & 0xfffff); + print("PCI interrupt routing table version %d.%d at %#.6ux\n", + r->version[0], r->version[1], (uint)r & 0xfffff); tbdf = (BusPCI << 24)|(r->bus << 16)|(r->devfn << 8); sbpci = pcimatchtbdf(tbdf); @@ -424,7 +438,7 @@ if(pci == nil) continue; pin = pcicfgr8(pci, PciINTP); - if(pin == 0 || pin == 0xff) + if(pin == 0 || pin == 0xff) continue; map = &e->maps[(pin - 1) * 3]; @@ -454,7 +468,7 @@ for(p = nil; p = pcimatch(p, 0, 0); ) for(i=0; imem); i++) if(p->mem[i].bar && (p->mem[i].bar&1) == 0) - upareserve(p->mem[i].bar&~0x0F, p->mem[i].size); + upareserve(p->mem[i].bar&~(uintmem)0xf, p->mem[i].size); } static void @@ -486,7 +500,7 @@ pcicfgmode = 1; } outl(PciADDR, n); - + if(pcicfgmode < 0){ unlock(&pcicfginitlock); return; @@ -497,7 +511,7 @@ sbno = bno; bno = pcilscan(bno, list); - while(*list) + while(*list != nil) list = &(*list)->link; if(sbno != 0) continue; @@ -631,42 +645,32 @@ return p; } -static void -pcilhinv(Pcidev* p) +void +pcihinv(Pcidev* p) { int i; Pcidev *t; + if(p == nil) { + p = pciroot; + print("tbdf: type vid did intl memory\n"); + } for(t = p; t != nil; t = t->link) { - print("%d %2d/%d %.2ux %.2ux %.2ux %.4ux %.4ux %3d ", - BUSBNO(t->tbdf), BUSDNO(t->tbdf), BUSFNO(t->tbdf), - t->ccrb, t->ccru, t->ccrp, t->vid, t->did, t->intl); + print("%T: %.2ux %.4ux/%.4ux %.2d", + t->tbdf, t->ccru, t->vid, t->did, t->intl); for(i = 0; i < nelem(p->mem); i++) { if(t->mem[i].size == 0) continue; - print("%d:%.8lux %d ", i, t->mem[i].bar, t->mem[i].size); + print("%d:%#P %d ", i, t->mem[i].bar, t->mem[i].size); } - if(t->bridge) + if(t->bridge != nil) print("->%d", BUSBNO(t->bridge->tbdf)); print("\n"); } for(; p != nil; p = p->link) if(p->bridge != nil) - pcilhinv(p->bridge); -} - -void -pcihinv(Pcidev* p) -{ - pcicfginit(); - lock(&pcicfginitlock); - if(p == nil){ - p = pciroot; - print("bus dev type vid did intl memory\n"); - } - pcilhinv(p); - unlock(&pcicfginitlock); + pcihinv(p->bridge); } void @@ -678,6 +682,20 @@ /* don't mess with the bridges */ if(p->ccrb != 0x06) pciclrbme(p); +} + +void +pcisetioe(Pcidev* p) +{ + p->pcr |= IOen; + pcicfgw16(p, PciPCR, p->pcr); +} + +void +pciclrioe(Pcidev* p) +{ + p->pcr &= ~IOen; + pcicfgw16(p, PciPCR, p->pcr); } void --- /sys/src/9/pcpae/sdmv50xx.c Sat Jan 11 19:48:24 2014 +++ /sys/src/9/pcpae/sdmv50xx.c Sat Jan 11 19:48:24 2014 @@ -1570,11 +1570,6 @@ { int count, n, status, rw; uvlong lba; - Ctlr *ctlr; - SDunit *unit; - - unit = r->unit; - ctlr = unit->dev->ctlr; if((status = sdfakescsi(r)) != SDnostatus) return r->status = status; --- /sys/src/9/pcpae/audiohda.c Sat Jan 11 19:48:24 2014 +++ /sys/src/9/pcpae/audiohda.c Sat Jan 11 19:48:24 2014 @@ -1624,7 +1624,7 @@ ctlr->no = adev->ctlrno; ctlr->size = p->mem[0].size; ctlr->q = qopen(256, 0, 0, 0); - ctlr->mem = vmap(p->mem[0].bar & ~0x0F, ctlr->size); + ctlr->mem = vmap(p->mem[0].bar & ~(uintmem)0xf, ctlr->size); if(ctlr->mem == nil){ print("#A%d: hda: can't map %.8ux\n", ctlr->no, (uint)p->mem[0].bar); return -1;