diff --git a/src/sys/include/pci/pci.h b/src/sys/include/pci/pci.h index a75e317..862585b 100644 --- a/src/sys/include/pci/pci.h +++ b/src/sys/include/pci/pci.h @@ -34,16 +34,16 @@ struct pciConfig { - uint16_t vendorId; - uint16_t deviceId; + uint16_t vendorID; + uint16_t deviceID; uint16_t command; uint16_t status; - uint8_t revisionId; - uint8_t interface; + uint8_t revisionID; + uint8_t progIf; uint8_t subClass; - uint8_t baseClass; + uint8_t classCode; uint8_t cacheLineSize; uint8_t latencyTimer; @@ -52,9 +52,9 @@ uint32_t bar[6]; - uint32_t cisPointer; + uint32_t cbPointer; uint16_t subsysVendorID; - uint16_t subsystemID; + uint16_t subsysID; uint32_t epromAddr; uint16_t capabilites; uint16_t res1; @@ -78,6 +78,12 @@ //uint16_t subsysVendor; //uint16_t subsys; + /* Device Info */ + //Move this to anotther struct eventually + uint8_t bus; + uint8_t dev; + uint8_t func; + }; struct confadd { diff --git a/src/sys/pci/pci.c b/src/sys/pci/pci.c index 0b6821b..fa5b9d9 100644 --- a/src/sys/pci/pci.c +++ b/src/sys/pci/pci.c @@ -25,7 +25,7 @@ $Id: pci.c 79 2016-01-11 16:21:27Z reddawg $ -*****************************************************************************************/ + *****************************************************************************************/ #include #include @@ -36,155 +36,51 @@ uInt8 subClass; uInt8 interface; const char* name; - } pciClasses[] = { - { 0x00, 0x00, 0x00, "Undefined" }, - { 0x00, 0x01, 0x00, "VGA" }, +} pciClasses[] = { { 0x00, 0x00, 0x00, "Undefined" }, { 0x00, 0x01, 0x00, "VGA" }, - { 0x01, 0x00, 0x00, "SCSI" }, - { 0x01, 0x01, 0x00, "IDE" }, - { 0x01, 0x01, 0x8A, "IDE" }, - { 0x01, 0x02, 0x00, "Floppy" }, - { 0x01, 0x03, 0x00, "IPI" }, - { 0x01, 0x04, 0x00, "RAID" }, - { 0x01, 0x80, 0x00, "Other" }, +{ 0x01, 0x00, 0x00, "SCSI" }, { 0x01, 0x01, 0x00, "IDE" }, { 0x01, 0x01, 0x8A, "IDE" }, { 0x01, 0x02, 0x00, "Floppy" }, { 0x01, 0x03, 0x00, "IPI" }, { 0x01, 0x04, 0x00, "RAID" }, { 0x01, 0x80, 0x00, "Other" }, - { 0x02, 0x00, 0x00, "Ethernet" }, - { 0x02, 0x01, 0x00, "Token Ring" }, - { 0x02, 0x02, 0x00, "FDDI" }, - { 0x02, 0x03, 0x00, "ATM" }, - { 0x02, 0x04, 0x00, "ISDN" }, - { 0x02, 0x80, 0x00, "Other" }, +{ 0x02, 0x00, 0x00, "Ethernet" }, { 0x02, 0x01, 0x00, "Token Ring" }, { 0x02, 0x02, 0x00, "FDDI" }, { 0x02, 0x03, 0x00, "ATM" }, { 0x02, 0x04, 0x00, "ISDN" }, { 0x02, 0x80, 0x00, "Other" }, - { 0x03, 0x00, 0x00, "VGA" }, - { 0x03, 0x00, 0x01, "VGA+8514" }, - { 0x03, 0x01, 0x00, "XGA" }, - { 0x03, 0x02, 0x00, "3D" }, - { 0x03, 0x80, 0x00, "VGA Other" }, +{ 0x03, 0x00, 0x00, "VGA" }, { 0x03, 0x00, 0x01, "VGA+8514" }, { 0x03, 0x01, 0x00, "XGA" }, { 0x03, 0x02, 0x00, "3D" }, { 0x03, 0x80, 0x00, "VGA Other" }, - { 0x04, 0x00, 0x00, "Video" }, - { 0x04, 0x01, 0x00, "Audio" }, - { 0x04, 0x02, 0x00, "Telephony" }, - { 0x04, 0x80, 0x00, "Other" }, +{ 0x04, 0x00, 0x00, "Video" }, { 0x04, 0x01, 0x00, "Audio" }, { 0x04, 0x02, 0x00, "Telephony" }, { 0x04, 0x80, 0x00, "Other" }, - { 0x05, 0x00, 0x00, "RAM" }, - { 0x05, 0x01, 0x00, "Flash" }, - { 0x05, 0x80, 0x00, "Other" }, - - { 0x06, 0x00, 0x00, "PCI to HOST" }, - { 0x06, 0x01, 0x00, "PCI to ISA" }, - { 0x06, 0x02, 0x00, "PCI to EISA" }, - { 0x06, 0x03, 0x00, "PCI to MCA" }, - { 0x06, 0x04, 0x00, "PCI to PCI" }, - { 0x06, 0x04, 0x01, "PCI to PCI (Subtractive Decode)" }, - { 0x06, 0x05, 0x00, "PCI to PCMCIA" }, - { 0x06, 0x06, 0x00, "PCI to NuBUS" }, - { 0x06, 0x07, 0x00, "PCI to Cardbus" }, - { 0x06, 0x08, 0x00, "PCI to RACEway" }, - { 0x06, 0x09, 0x00, "PCI to PCI" }, - { 0x06, 0x0A, 0x00, "PCI to InfiBand" }, - { 0x06, 0x80, 0x00, "PCI to Other" }, +{ 0x05, 0x00, 0x00, "RAM" }, { 0x05, 0x01, 0x00, "Flash" }, { 0x05, 0x80, 0x00, "Other" }, - { 0x07, 0x00, 0x00, "Serial" }, - { 0x07, 0x00, 0x01, "Serial - 16450" }, - { 0x07, 0x00, 0x02, "Serial - 16550" }, - { 0x07, 0x00, 0x03, "Serial - 16650" }, - { 0x07, 0x00, 0x04, "Serial - 16750" }, - { 0x07, 0x00, 0x05, "Serial - 16850" }, - { 0x07, 0x00, 0x06, "Serial - 16950" }, - { 0x07, 0x01, 0x00, "Parallel" }, - { 0x07, 0x01, 0x01, "Parallel - BiDir" }, - { 0x07, 0x01, 0x02, "Parallel - ECP" }, - { 0x07, 0x01, 0x03, "Parallel - IEEE1284" }, - { 0x07, 0x01, 0xFE, "Parallel - IEEE1284 Target" }, - { 0x07, 0x02, 0x00, "Multiport Serial" }, - { 0x07, 0x03, 0x00, "Hayes Compatible Modem" }, - { 0x07, 0x03, 0x01, "Hayes Compatible Modem, 16450" }, - { 0x07, 0x03, 0x02, "Hayes Compatible Modem, 16550" }, - { 0x07, 0x03, 0x03, "Hayes Compatible Modem, 16650" }, - { 0x07, 0x03, 0x04, "Hayes Compatible Modem, 16750" }, - { 0x07, 0x80, 0x00, "Other" }, +{ 0x06, 0x00, 0x00, "PCI to HOST" }, { 0x06, 0x01, 0x00, "PCI to ISA" }, { 0x06, 0x02, 0x00, "PCI to EISA" }, { 0x06, 0x03, 0x00, "PCI to MCA" }, { 0x06, 0x04, 0x00, "PCI to PCI" }, { 0x06, 0x04, 0x01, "PCI to PCI (Subtractive Decode)" }, { 0x06, 0x05, 0x00, "PCI to PCMCIA" }, { 0x06, 0x06, 0x00, "PCI to NuBUS" }, { 0x06, 0x07, 0x00, "PCI to Cardbus" }, { 0x06, 0x08, 0x00, "PCI to RACEway" }, { 0x06, 0x09, 0x00, "PCI to PCI" }, { 0x06, 0x0A, 0x00, "PCI to InfiBand" }, { 0x06, 0x80, 0x00, "PCI to Other" }, - { 0x08, 0x00, 0x00, "PIC" }, - { 0x08, 0x00, 0x01, "ISA PIC" }, - { 0x08, 0x00, 0x02, "EISA PIC" }, - { 0x08, 0x00, 0x10, "I/O APIC" }, - { 0x08, 0x00, 0x20, "I/O(x) APIC" }, - { 0x08, 0x01, 0x00, "DMA" }, - { 0x08, 0x01, 0x01, "ISA DMA" }, - { 0x08, 0x01, 0x02, "EISA DMA" }, - { 0x08, 0x02, 0x00, "Timer" }, - { 0x08, 0x02, 0x01, "ISA Timer" }, - { 0x08, 0x02, 0x02, "EISA Timer" }, - { 0x08, 0x03, 0x00, "RTC" }, - { 0x08, 0x03, 0x00, "ISA RTC" }, - { 0x08, 0x03, 0x00, "Hot-Plug" }, - { 0x08, 0x80, 0x00, "Other" }, +{ 0x07, 0x00, 0x00, "Serial" }, { 0x07, 0x00, 0x01, "Serial - 16450" }, { 0x07, 0x00, 0x02, "Serial - 16550" }, { 0x07, 0x00, 0x03, "Serial - 16650" }, { 0x07, 0x00, 0x04, "Serial - 16750" }, { 0x07, 0x00, 0x05, "Serial - 16850" }, { 0x07, 0x00, 0x06, "Serial - 16950" }, { 0x07, 0x01, 0x00, "Parallel" }, { 0x07, 0x01, 0x01, "Parallel - BiDir" }, { 0x07, 0x01, 0x02, "Parallel - ECP" }, { 0x07, 0x01, 0x03, "Parallel - IEEE1284" }, { 0x07, 0x01, 0xFE, "Parallel - IEEE1284 Target" }, { 0x07, 0x02, 0x00, "Multiport Serial" }, { 0x07, 0x03, 0x00, "Hayes Compatible Modem" }, { 0x07, 0x03, 0x01, "Hayes Compatible Modem, 16450" }, { 0x07, 0x03, 0x02, "Hayes Compatible Modem, 16550" }, { 0x07, 0x03, 0x03, "Hayes Compatible Modem, 16650" }, { 0x07, 0x03, 0x04, "Hayes Compatible Modem, 16750" }, { 0x07, 0x80, 0x00, "Other" }, - { 0x09, 0x00, 0x00, "Keyboard" }, - { 0x09, 0x01, 0x00, "Pen" }, - { 0x09, 0x02, 0x00, "Mouse" }, - { 0x09, 0x03, 0x00, "Scanner" }, - { 0x09, 0x04, 0x00, "Game Port" }, - { 0x09, 0x80, 0x00, "Other" }, +{ 0x08, 0x00, 0x00, "PIC" }, { 0x08, 0x00, 0x01, "ISA PIC" }, { 0x08, 0x00, 0x02, "EISA PIC" }, { 0x08, 0x00, 0x10, "I/O APIC" }, { 0x08, 0x00, 0x20, "I/O(x) APIC" }, { 0x08, 0x01, 0x00, "DMA" }, { 0x08, 0x01, 0x01, "ISA DMA" }, { 0x08, 0x01, 0x02, "EISA DMA" }, { 0x08, 0x02, 0x00, "Timer" }, { 0x08, 0x02, 0x01, "ISA Timer" }, { 0x08, 0x02, 0x02, "EISA Timer" }, { 0x08, 0x03, 0x00, "RTC" }, { 0x08, 0x03, 0x00, "ISA RTC" }, { 0x08, 0x03, 0x00, "Hot-Plug" }, { 0x08, 0x80, 0x00, "Other" }, - { 0x0a, 0x00, 0x00, "Generic" }, - { 0x0a, 0x80, 0x00, "Other" }, +{ 0x09, 0x00, 0x00, "Keyboard" }, { 0x09, 0x01, 0x00, "Pen" }, { 0x09, 0x02, 0x00, "Mouse" }, { 0x09, 0x03, 0x00, "Scanner" }, { 0x09, 0x04, 0x00, "Game Port" }, { 0x09, 0x80, 0x00, "Other" }, - { 0x0b, 0x00, 0x00, "386" }, - { 0x0b, 0x01, 0x00, "486" }, - { 0x0b, 0x02, 0x00, "Pentium" }, - { 0x0b, 0x03, 0x00, "PentiumPro" }, - { 0x0b, 0x10, 0x00, "DEC Alpha" }, - { 0x0b, 0x20, 0x00, "PowerPC" }, - { 0x0b, 0x30, 0x00, "MIPS" }, - { 0x0b, 0x40, 0x00, "Coprocessor" }, - { 0x0b, 0x80, 0x00, "Other" }, +{ 0x0a, 0x00, 0x00, "Generic" }, { 0x0a, 0x80, 0x00, "Other" }, - { 0x0c, 0x00, 0x00, "FireWire" }, - { 0x0c, 0x00, 0x10, "OHCI FireWire" }, - { 0x0c, 0x01, 0x00, "Access.bus" }, - { 0x0c, 0x02, 0x00, "SSA" }, - { 0x0c, 0x03, 0x00, "USB (UHCI)" }, - { 0x0c, 0x03, 0x10, "USB (OHCI)" }, - { 0x0c, 0x03, 0x80, "USB" }, - { 0x0c, 0x03, 0xFE, "USB Device" }, - { 0x0c, 0x04, 0x00, "Fiber" }, - { 0x0c, 0x05, 0x00, "SMBus Controller" }, - { 0x0c, 0x06, 0x00, "InfiniBand" }, - { 0x0c, 0x80, 0x00, "Other" }, +{ 0x0b, 0x00, 0x00, "386" }, { 0x0b, 0x01, 0x00, "486" }, { 0x0b, 0x02, 0x00, "Pentium" }, { 0x0b, 0x03, 0x00, "PentiumPro" }, { 0x0b, 0x10, 0x00, "DEC Alpha" }, { 0x0b, 0x20, 0x00, "PowerPC" }, { 0x0b, 0x30, 0x00, "MIPS" }, { 0x0b, 0x40, 0x00, "Coprocessor" }, { 0x0b, 0x80, 0x00, "Other" }, - { 0x0d, 0x00, 0x00, "iRDA" }, - { 0x0d, 0x01, 0x00, "Consumer IR" }, - { 0x0d, 0x10, 0x00, "RF" }, - { 0x0d, 0x80, 0x00, "Other" }, +{ 0x0c, 0x00, 0x00, "FireWire" }, { 0x0c, 0x00, 0x10, "OHCI FireWire" }, { 0x0c, 0x01, 0x00, "Access.bus" }, { 0x0c, 0x02, 0x00, "SSA" }, { 0x0c, 0x03, 0x00, "USB (UHCI)" }, { 0x0c, 0x03, 0x10, "USB (OHCI)" }, { 0x0c, 0x03, 0x80, "USB" }, { 0x0c, 0x03, 0xFE, "USB Device" }, { 0x0c, 0x04, 0x00, "Fiber" }, { 0x0c, 0x05, 0x00, "SMBus Controller" }, { 0x0c, 0x06, 0x00, "InfiniBand" }, { 0x0c, 0x80, 0x00, "Other" }, - { 0x0e, 0x00, 0x00, "I2O" }, - { 0x0e, 0x80, 0x00, "Other" }, +{ 0x0d, 0x00, 0x00, "iRDA" }, { 0x0d, 0x01, 0x00, "Consumer IR" }, { 0x0d, 0x10, 0x00, "RF" }, { 0x0d, 0x80, 0x00, "Other" }, - { 0x0f, 0x01, 0x00, "TV" }, - { 0x0f, 0x02, 0x00, "Audio" }, - { 0x0f, 0x03, 0x00, "Voice" }, - { 0x0f, 0x04, 0x00, "Data" }, - { 0x0f, 0x80, 0x00, "Other" }, +{ 0x0e, 0x00, 0x00, "I2O" }, { 0x0e, 0x80, 0x00, "Other" }, - { 0x10, 0x00, 0x00, "Network" }, - { 0x10, 0x10, 0x00, "Entertainment" }, - { 0x10, 0x80, 0x00, "Other" }, +{ 0x0f, 0x01, 0x00, "TV" }, { 0x0f, 0x02, 0x00, "Audio" }, { 0x0f, 0x03, 0x00, "Voice" }, { 0x0f, 0x04, 0x00, "Data" }, { 0x0f, 0x80, 0x00, "Other" }, - { 0x11, 0x00, 0x00, "DPIO Modules" }, - { 0x11, 0x01, 0x00, "Performance Counters" }, - { 0x11, 0x10, 0x00, "Comm Sync, Time+Frequency Measurement" }, - { 0x11, 0x80, 0x00, "Other" }, - - }; +{ 0x10, 0x00, 0x00, "Network" }, { 0x10, 0x10, 0x00, "Entertainment" }, { 0x10, 0x80, 0x00, "Other" }, -uInt32 pciRead(int bus,int dev,int func,int reg,int bytes) { +{ 0x11, 0x00, 0x00, "DPIO Modules" }, { 0x11, 0x01, 0x00, "Performance Counters" }, { 0x11, 0x10, 0x00, "Comm Sync, Time+Frequency Measurement" }, { 0x11, 0x80, 0x00, "Other" }, + +}; + +uInt32 pciRead(int bus, int dev, int func, int reg, int bytes) { uInt16 base; union { struct confadd c; uInt32 n; - } u; + } u; u.n = 0; u.c.enable = 1; @@ -193,26 +89,30 @@ u.c.dev = dev; u.c.func = func; u.c.reg = reg & 0xFC; - + outportDWord(0xCF8, u.n); base = 0xCFC + (reg & 0x03); - switch(bytes){ - case 1: return(inportByte(base)); - case 2: return(inportWord(base)); - case 4: return(inportDWord(base)); - default: return 0; - } + switch (bytes) { + case 1: + return (inportByte(base)); + case 2: + return (inportWord(base)); + case 4: + return (inportDWord(base)); + default: + return 0; } +} -void pciWrite(int bus,int dev,int func,int reg,uInt32 v,int bytes) { +void pciWrite(int bus, int dev, int func, int reg, uInt32 v, int bytes) { uInt16 base; union { struct confadd c; uInt32 n; - } u; + } u; u.n = 0; u.c.enable = 1; @@ -224,131 +124,133 @@ base = 0xCFC + (reg & 0x03); outportDWord(0xCF8, u.n); - switch(bytes){ - case 1: outportByte(base, (uInt8) v); break; - case 2: outportWord(base, (uInt16) v); break; - case 4: outportDWord(base, v); break; - } + switch (bytes) { + case 1: + outportByte(base, (uInt8) v); + break; + case 2: + outportWord(base, (uInt16) v); + break; + case 4: + outportDWord(base, v); + break; } +} - -bool pciProbe(int bus, int dev, int func,struct pciConfig *cfg) { - uInt32 *word = (uInt32 *) cfg; - uInt32 v; +bool pciProbe(int bus, int dev, int func, struct pciConfig *cfg) { + uint32_t *word = (uint32_t *) cfg; + uint32_t v; int i; - for(i=0;i<4;i++) { - word[i] = pciRead(bus,dev,func,4*i,4); - if (cfg->vendorId == 0x1022 && i == 1) { + + 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; - pciWrite(bus,dev,func,4*i,word[i],4); - kprintf("set it: 0x%X[0x%X]", word[i], pciRead(bus,dev,func,0x10,4)); + pciWrite(bus, dev, func, 4 * i, word[i], 4); + kprintf("set it: 0x%X[0x%X]", word[i], pciRead(bus, dev, func, 0x10, 4)); } } - if(cfg->vendorId == 0xffff) return FALSE; - if(cfg->vendorId == 0x0) return FALSE; /* Quick Hack */ + + if (cfg->vendorID == 0xffff) + return FALSE; + + if (cfg->vendorID == 0x0) + return FALSE; /* Quick Hack */ cfg->bus = bus; cfg->dev = dev; cfg->func = func; - cfg->subsysVendor = pciRead(bus, dev, func, 0x2c, 2); - cfg->subsys = pciRead(bus, dev, func, 0x2e, 2); -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->baseClass,cfg->subClass,cfg->interface); - 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); -} - switch(cfg->headerType & 0x7F){ - case 0: /* normal device */ - for(i=0;i<6;i++) { - v = pciRead(bus,dev,func,i*4 + 0x10, 4); - if(v) { - int v2; - pciWrite(bus,dev,func,i*4 + 0x10, 0xffffffff, 4); - v2 = pciRead(bus,dev,func,i*4+0x10, 4) & 0xfffffff0; - pciWrite(bus,dev,func,i*4 + 0x10, v, 4); - v2 = 1 + ~v2; - if(v & 1) { - cfg->base[i] = v & 0xffff; - cfg->size[i] = v2 & 0xffff; - } - else { - cfg->base[i] = v; - cfg->size[i] = v2; - } - } - else { - cfg->base[i] = 0; - cfg->size[i] = 0; - } + + + switch(cfg->headerType & 0x7F) { + case 0x0: /* normal device */ + for (i = 4;i<12;i++) { + word[i] = pciRead(bus, dev, func, 4 * i, 4); } - v = pciRead(bus,dev,func,0x3c,1); - cfg->irq = (v == 0xff ? 0 : v); - v = pciRead(bus,dev,func,0x40,1); - cfg->irqLine = (v == 0xff ? 0 : v); + 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); + } break; - case 1: + case 0x1: kprintf(" * PCI <-> PCI Bridge\n"); break; + case 0x2: + kprintf(" * PCI <-> CardBus Bridge\n"); + break; default: kprintf(" * Unknown Header Type\n"); break; - } - return(TRUE); } + /* + switch (cfg->headerType & 0x7F) { + case 0: // normal device + for (i = 0; i < 6; i++) { + v = pciRead(bus, dev, func, i * 4 + 0x10, 4); + if (v) { + int v2; + pciWrite(bus, dev, func, i * 4 + 0x10, 0xffffffff, 4); + v2 = pciRead(bus, dev, func, i * 4 + 0x10, 4) & 0xfffffff0; + pciWrite(bus, dev, func, i * 4 + 0x10, v, 4); + v2 = 1 + ~v2; + if (v & 1) { + cfg->base[i] = v & 0xffff; + cfg->size[i] = v2 & 0xffff; + } + else { + cfg->base[i] = v; + cfg->size[i] = v2; + } + } + else { + cfg->base[i] = 0; + cfg->size[i] = 0; + } + } + v = pciRead(bus, dev, func, 0x3c, 1); + cfg->irq = (v == 0xff ? 0 : v); + v = pciRead(bus, dev, func, 0x40, 1); + cfg->irqLine = (v == 0xff ? 0 : v); + break; + case 1: + + + } + */ + + return (TRUE); +} + int pci_init() { - uInt16 bus,dev,func; + uint16_t bus, dev, func; + int i = 0x0; + struct pciConfig pcfg; + for (bus = 0x0; bus < 0x2; bus++) { /* 255 */ - for (dev = 0; dev < 32; dev++) { - for (func = 0; func < 8; func++) { + 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 (i=0x0;i