diff --git a/src/sys/include/pci/pci.h b/src/sys/include/pci/pci.h index 862585b..684b7bb 100644 --- a/src/sys/include/pci/pci.h +++ b/src/sys/include/pci/pci.h @@ -53,12 +53,17 @@ uint32_t bar[6]; uint32_t cbPointer; + uint16_t subsysVendorID; uint16_t subsysID; + uint32_t epromAddr; + uint16_t capabilites; uint16_t res1; + uint32_t res2; + uint8_t intLine; uint8_t intPin; uint8_t minGrant; @@ -100,7 +105,7 @@ int pci_init(); -bool pciProbe(int bus,int dev,int func,struct pciConfig *cfg); +uint32_t pciProbe(int bus,int dev,int func); uInt32 pciRead(int bus, int dev, int func, int reg, int bytes); void pciWrite(int bus,int dev,int func,int reg,uInt32 v,int bytes); diff --git a/src/sys/pci/lnc.c b/src/sys/pci/lnc.c index ddbfba6..99e0d99 100644 --- a/src/sys/pci/lnc.c +++ b/src/sys/pci/lnc.c @@ -91,6 +91,7 @@ lnc->bufferSize = 1548; lnc->ioAddr = 0xD000; + lnc->nic.ic = lnc_probe(lnc); //kprintf("ID: %i\n", lnc->nic.ic); @@ -129,6 +130,7 @@ iW = lnc_readBCR32(lnc, 0x2); iW |= 0x2; + iW |= 0x40; lnc_writeBCR32(lnc, 0x2, iW); lnc->init.mode = 0x0; @@ -163,28 +165,29 @@ break; if (lnc_readCSR32(lnc, CSR0) & IDON) { - setVector(&lnc_isr, mVec + 0x9, (dInt + dPresent + dDpl0)); + setVector(&lnc_isr, mVec + 0x5, (dInt + dPresent + dDpl3)); + irqEnable(0x5); lnc_writeCSR32(lnc, CSR0, STRT | INEA); - irqEnable(0x9); - /* - * sc->arpcom.ac_if.if_flags |= IFF_RUNNING; - * sc->arpcom.ac_if.if_flags &= ~IFF_OACTIVE; - * lnc_start(&sc->arpcom.ac_if); - */ } else { kprintf("LNC: init Error\n"); return (-1); } - /* - kprintf("SENDING PACKET"); + + kprintf("SENDING PACKET [0x%X]", lnc_readCSR32(lnc, CSR3)); + iW = lnc_sendPacket(lnc, &data, strlen(data), 0x0); + + while (1) + asm("nop"); + while (1) { iW = lnc_sendPacket(lnc, &data, strlen(data), 0x0); - if (!iW) +/* + if (iW == 0) kprintf("Sending Failed"); +*/ } - */ return (0); } @@ -277,24 +280,6 @@ } asm( - ".global _lncInt \n" - "_lncInt : \n" - - " pusha \n" /* Save all registers */ - " pushw %ds \n" /* Set up the data segment */ - " pushw %es \n" - " pushw %ss \n" /* Note that ss is always valid */ - " pushw %ss \n" - " popw %ds \n" - " popw %es \n" - " call lncInt \n" - " popw %es \n" - " popw %ds \n" /* Restore registers */ - " popa \n" - " iret \n" /* Exit interrupt */ -); - -asm( ".globl lnc_isr \n" "lnc_isr: \n" " pusha \n" /* Save all registers */ @@ -346,7 +331,7 @@ bcnt = (uint16_t) (-lnc->bufferSize); bcnt &= 0x0FFF; bcnt |= 0xF000; -//kprintf("rxR[%i].addr = 0x%X, BCNT 0x%X", i, lnc->rxRing[i].addr,bcnt); + //kprintf("rxR[%i].addr = 0x%X, BCNT 0x%X", i, lnc->rxRing[i].addr,bcnt); lnc->rxRing[i].bcnt = bcnt; lnc->rxRing[i].md[1] = 0x80; } @@ -398,26 +383,6 @@ lnc->nic.mode = NORMAL; - /* Fill in arpcom structure entries */ - /* - lnc->arpcom.ac_if.if_softc = sc; - lnc->arpcom.ac_if.if_name = lncdriver.name; - lnc->arpcom.ac_if.if_unit = unit; - lnc->arpcom.ac_if.if_mtu = ETHERMTU; - lnc->arpcom.ac_if.if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; - lnc->arpcom.ac_if.if_timer = 0; - lnc->arpcom.ac_if.if_output = ether_output; - lnc->arpcom.ac_if.if_start = lnc_start; - lnc->arpcom.ac_if.if_ioctl = lnc_ioctl; - lnc->arpcom.ac_if.if_watchdog = lnc_watchdog; - lnc->arpcom.ac_if.if_init = lnc_init; - lnc->arpcom.ac_if.if_type = IFT_ETHER; - lnc->arpcom.ac_if.if_addrlen = ETHER_ADDR_LEN; - lnc->arpcom.ac_if.if_hdrlen = ETHER_HDR_LEN; - lnc->arpcom.ac_if.if_snd.ifq_maxlen = IFQ_MAXLEN; - */ - /* ether_ifattach(&sc->arpcom.ac_if, ETHER_BPF_SUPPORTED); */ - kprintf("lnc%d: ", unit); if (lnc->nic.ic == LANCE || lnc->nic.ic == C_LANCE) kprintf("%s (%s)", nicIdent[lnc->nic.ident], icIdent[lnc->nic.ic]); @@ -452,19 +417,14 @@ lnc->txRing[lnc->txPtr].md[1] |= 0x2; lnc->txRing[lnc->txPtr].md[1] |= 0x1; - //tdes[(tx_ptr * 16) + 7] |= 0x2; - //tdes[(tx_ptr * 16) + 7] |= 0x1; uint16_t bcnt = (uint16_t) (-len); bcnt &= 0xFFF; bcnt |= 0xF000; lnc->txRing[lnc->txPtr].bcnt = bcnt; - //*(uint16_t *) &tdes[tx_ptr * 16 + 4] = bcnt; lnc->txRing[lnc->txPtr].md[1] |= 0x80; - //tdes[tx_ptr * 16 + 7] |= 0x80; - lnc_nextTxPtr(lnc); return (len); } diff --git a/src/sys/pci/pci.c b/src/sys/pci/pci.c index fa5b9d9..ac9f307 100644 --- a/src/sys/pci/pci.c +++ b/src/sys/pci/pci.c @@ -137,45 +137,56 @@ } } -bool pciProbe(int bus, int dev, int func, struct pciConfig *cfg) { - uint32_t *word = (uint32_t *) cfg; +uint32_t pciProbe(int bus, int dev, int func) { + struct pciConfig *cfg = 0x0; uint32_t v; int i; - for (i = 0; i < 4; i++) { + cfg = kmalloc(sizeof(struct pciConfig)); + memset(cfg, 0x0, sizeof(struct pciConfig)); + uint32_t *word = (uint32_t *)cfg; + + for (i = 0; i < 4; i++) { word[i] = pciRead(bus, dev, func, 4 * i, 4); /* This is TEMPORARY */ if (cfg->vendorID == 0x1022 && i == 1) { kprintf("got it: 0x%X", word[i]); word[i] &= 0xffff0000; - word[i] |= 0x5; + word[i] |= 0x5; //0x1 //0x5; pciWrite(bus, dev, func, 4 * i, word[i], 4); - kprintf("set it: 0x%X[0x%X]", word[i], pciRead(bus, dev, func, 0x10, 4)); + kprintf("set it: 0x%X\n", word[i]); } } - if (cfg->vendorID == 0xffff) - return FALSE; + if (cfg->vendorID == 0xffff) { + kfree(cfg); + return 0x0; + } - if (cfg->vendorID == 0x0) - return FALSE; /* Quick Hack */ + if (cfg->vendorID == 0x0) { + kfree(cfg); + return 0x0; + } cfg->bus = bus; cfg->dev = dev; cfg->func = func; + if (cfg->vendorID == 0x1022) + pciWrite(bus, dev, func, 0x3C, 0x5,1); switch(cfg->headerType & 0x7F) { case 0x0: /* normal device */ - for (i = 4;i<12;i++) { + for (i = 4;i<=16;i++) { word[i] = pciRead(bus, dev, func, 4 * i, 4); } if (cfg->vendorID == 0x1022) { kprintf("Device Info: /bus/pci/%d/%d/%d\n", bus, dev, func); kprintf(" * Vendor: %X Device: %X Class/SubClass/Interface %X/%X/%X\n", cfg->vendorID, cfg->deviceID, cfg->classCode, cfg->subClass, cfg->progIf); kprintf(" * Status: %X Command: %X BIST/Type/Lat/CLS: %X/%X/%X/%X\n", cfg->status, cfg->command, cfg->bist, cfg->headerType, cfg->latencyTimer, cfg->cacheLineSize); + kprintf(" * IRQ: 0x%X.0x%X\n", cfg->intLine, cfg->intPin); } break; case 0x1: @@ -190,6 +201,7 @@ } + /* switch (cfg->headerType & 0x7F) { case 0: // normal device @@ -226,7 +238,7 @@ } */ - return (TRUE); + return ((uint32_t)cfg); } int pci_init() { @@ -234,17 +246,18 @@ int i = 0x0; - struct pciConfig pcfg; + struct pciConfig *pcfg; - for (bus = 0x0; bus < 0x2; bus++) { /* 255 */ - for (dev = 0; dev < 32; dev++) { /* 32 */ - for (func = 0; func < 8; func++) { /* 8 */ - if (pciProbe(bus, dev, func, &pcfg) == TRUE) { - /* kprintf(" * Vendor: %X Device: %X Class/SubClass/Interface %X/%X/%X\n",pcfg.vendorId,pcfg.deviceId,pcfg.baseClass,pcfg.subClass,pcfg.interface); */ + for (bus = 0x0; bus < 0x2; bus++) { + for (dev = 0; dev < 32; dev++) { + for (func = 0; func < 8; func++) { + pcfg = (struct pciConfig *)pciProbe(bus, dev, func); + if (pcfg != 0x0) { for (i = 0x0; i < countof(pciClasses); i++) { - if (pcfg.classCode == pciClasses[i].baseClass && pcfg.subClass == pciClasses[i].subClass && pcfg.progIf == pciClasses[i].interface) { - if (pcfg.vendorID == 0x1022) - kprintf("PCI Device: %s @ IRQ: 0x%X.0x%X\n", pciClasses[i].name, pcfg.intPin, pcfg.intLine); + if (pcfg->classCode == pciClasses[i].baseClass && pcfg->subClass == pciClasses[i].subClass && pcfg->progIf == pciClasses[i].interface) { + if (pcfg->vendorID == 0x1022) { + kprintf("PCI Device: %s @ IRQ: 0x%X.0x%X\n", pciClasses[i].name, pcfg->intPin, pcfg->intLine); + } break; } }