summaryrefslogtreecommitdiff
path: root/driver/pci.c
diff options
context:
space:
mode:
Diffstat (limited to 'driver/pci.c')
-rw-r--r--driver/pci.c40
1 files changed, 28 insertions, 12 deletions
diff --git a/driver/pci.c b/driver/pci.c
index 1e2f660..b5e5791 100644
--- a/driver/pci.c
+++ b/driver/pci.c
@@ -1,5 +1,3 @@
-
-
#include "kernel/kernel.h"
#include "log.h"
#include "asm_x86.h"
@@ -8,6 +6,17 @@
#define PCI_CONFIG_DATA 0xCFC
#define PCI_CONFIG_ADDRESS 0xCF8
+static uint32_t e1000_addr;
+
+static char *get_class(uint8_t v)
+{
+ switch(v)
+ {
+ case 0x00: return "Unclassified";
+ }
+ return "Unknown";
+}
+
void pciConfigSet (uint8_t bus, uint8_t slot,
uint8_t func, uint8_t offset, uint32_t data)
{
@@ -47,7 +56,7 @@
return (tmp);
}
-void test_bar(uint8_t bus, uint8_t slot, uint8_t offset)
+uint32_t test_bar(uint8_t bus, uint8_t slot, uint8_t offset)
{
uint16_t bar_low=pciConfigReadWord(bus,slot,0,offset);
@@ -64,36 +73,44 @@ void test_bar(uint8_t bus, uint8_t slot, uint8_t offset)
// restore original values
pciConfigSet(bus,slot,0,offset,(bar_high<<16)+bar_low);
-
klog("%s bar: (0x%x 0x%x) size: 0x%x" ,bar_low&1?"i/o":"mem",bar_high, bar_low, size);
+ if((bar_low&1)==0) // mem space
+ {
+ klog("type=0x%x,base_addr=0x%08X",0b110&bar_low,(bar_low+(bar_high<<16))&0xFFFFFFF0);
+ }
+ return (bar_low+(bar_high<<16))&0xFFFFFFF0;
}
uint16_t pciCheck(uint8_t bus, uint8_t slot)
{
- uint16_t vendor, device;
+ uint16_t vendor, device, irq;
/* try and read the first configuration register. Since there are no */
/* vendors that == 0xFFFF, it must be a non-existent device. */
if ((vendor = pciConfigReadWord(bus,slot,0,0)) != 0xFFFF)
{
device = pciConfigReadWord(bus,slot,0,2);
+
+ //pciConfigSet(bus,slot,0,0x3c+2,0x3);
+ irq = pciConfigReadWord(bus,slot,0,0x3c);
+ uint8_t header = pciConfigReadWord(bus,slot,0,0xd)&0xff;
+
klog("[%d,%d]: vendor: 0x%x / device: 0x%x",bus,slot,vendor,device);
+ klog("header_typ=%x, %d,pin=%d , irq=%d",header,irq,irq&0xFf00,irq&0xFf);
+
// check for: E1000 (82540EM). PCI Ethernet Controller
if(vendor==0x8086&&device==0x100e)
{
// uint16_t irq=pciConfigReadWord(bus,slot,0,0x3C);
// uint16_t irq2=pciConfigReadWord(bus,slot,0,0x3E);
//
- init_e1000();
- test_bar(bus,slot,0x10);
+ e1000_addr=test_bar(bus,slot,0x10);
test_bar(bus,slot,0x14);
- test_bar(bus,slot,0x18);
-
// scr_put_hex(irq);
// scr_put_hex(irq2);
// scr_put_string_nl(";");
@@ -110,7 +127,7 @@ uint16_t pciCheck(uint8_t bus, uint8_t slot)
}
-void pci_init()
+uint32_t pci_init()
{
klog("scanning bus");
// todo: recurse on pci to pci bridges!
@@ -124,11 +141,10 @@ void pci_init()
{
for(device = 0; device < 32; device++)
{
-
pciCheck(bus, device);
-
}
}
+ return e1000_addr;
}