Show
Ignore:
Timestamp:
02/25/09 19:37:39 (3 years ago)
Author:
mwhitworth
Message:

Add ->driver field, add documentation and remove magic numbers.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • Whitix/trunk/devices/pci/pci_core.c

    r1668 r1925  
    7070                default: return -EINVAL; 
    7171        } 
    72  
     72         
    7373        return 0; 
    7474} 
     
    9292 
    9393        base=0xCFC+(reg & 0x03); 
    94         outd(0xCF8,u.n); 
     94         
     95        outd(0xCF8, u.n); 
     96         
    9597        switch (bytes) 
    9698        { 
     
    126128}; 
    127129 
     130#define PCI_WRITE_TEST  0xFFFFFFFF 
     131#define PCI_BAR_BASE    0x10 
     132 
    128133int PciDeviceProbe(struct PciDevice* device) 
    129134{ 
    130135        /* Fill in device-specific information, such as IRQ, I/O and memory. */ 
    131         DWORD v; 
     136        BYTE irq; 
     137        DWORD v, size; 
    132138        int i; 
    133         int bus, dev, func; 
    134  
    135         bus=device->bus->index; 
    136         dev=device->dev; 
    137         func=device->func; 
    138139 
    139140        for (i=0; i<6; i++) 
    140141        { 
    141                 PciRead(bus, dev, func, (i*4)+0x10, 4, &v); 
    142                 if (v) 
    143                 { 
    144                         DWORD v2; 
    145                         PciWrite(bus, dev, func, i*4+0x10, 0xFFFFFFFF, 4); 
    146                         PciRead(bus, dev, func, i*4+0x10, 4, &v2); 
    147                         v2 &= 0xFFFFFFF0; 
    148                         PciWrite(bus, dev, func, i*4+0x10, v, 4); 
    149                         if (v2 == 0 || v2 == 0xFFFFFFFF) 
    150                                 continue; 
    151  
    152                         if (v == 0xFFFFFFFF) 
    153                                 v=0; 
    154  
    155                         device->spaces[i]=v; 
    156                 } 
    157         } 
    158  
    159         /* Why v? */ 
    160         PciRead(bus, dev, func, 0x3D, 1, &v); 
    161  
    162         if (v) 
    163         { 
    164                 PciRead(bus, dev, func, 0x3C, 1, &v); 
    165                 device->irq=(BYTE)v; 
     142                PciReadConfigDword(device, PCI_BAR_BASE + (i << 2), &v); 
     143         
     144                PciWriteConfigDword(device, PCI_BAR_BASE + (i << 2), PCI_WRITE_TEST); 
     145                PciReadConfigDword(device, PCI_BAR_BASE + (i << 2), &size); 
     146                 
     147                PciWriteConfigDword(device, PCI_BAR_BASE + (i << 2), v); 
     148                 
     149                if (!size || size == 0xFFFFFFFF) 
     150                        continue; 
     151                         
     152                if (v == PCI_WRITE_TEST) 
     153                        v = 0; 
     154                 
     155                size &= 0xFFFFFFF0; 
     156                                                         
     157                /* Parse the base address register. */ 
     158                device->spaces[i] = v; 
     159        } 
     160 
     161        PciReadConfigByte(device, 0x3D, &irq); 
     162 
     163        if (irq) 
     164        { 
     165                PciReadConfigByte(device, 0x3C, &irq); 
     166                device->irq = irq; 
    166167        } 
    167168 
     
    264265{ 
    265266        struct PciDeviceId* currId; 
     267        int ret; 
    266268 
    267269        /* Search through each device id entry, looking for a match. */ 
    268         currId=driver->idTable; 
     270        currId = driver->idTable; 
    269271 
    270272        while (currId->vendorId) 
     
    276278                        ((currId->class ^ device->devClass) & currId->classMask)*/) 
    277279                { 
     280                        device->driver = driver; 
     281                         
    278282                        /* Matched! Start up the device. */ 
    279                         return driver->initOne(device, currId); 
     283                        ret = driver->initOne(device, currId); 
     284                         
     285                        if (ret) 
     286                                device->driver = NULL; 
     287                                 
     288                        return ret; 
    280289                } 
    281290 
     
    364373        PciScanBus(0); 
    365374 
     375        /* Add devices to IcFs */ 
     376 
    366377        return 0; 
    367378}