X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Fdrv%2Fpci.c;h=df5c11444cb51c3448090732bb5199a77eeedd0a;hb=df1d534cfe822903fc38e1cc13c4b18941c91908;hp=1f9e7285607bdc0029e349a924401b4a7d5f7a6b;hpb=05e8b329edc7c55eec967c3caba1982c173025e3;p=tpg%2Facess2.git diff --git a/Kernel/drv/pci.c b/Kernel/drv/pci.c index 1f9e7285..df5c1144 100644 --- a/Kernel/drv/pci.c +++ b/Kernel/drv/pci.c @@ -11,6 +11,12 @@ #define LIST_DEVICES 1 +// === IMPORTS === +extern Uint32 PCI_CfgReadDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset); +extern void PCI_CfgWriteDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset, Uint32 data); +extern Uint16 PCI_CfgReadWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset); +extern Uint8 PCI_CfgReadByte(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset); + // === STRUCTURES === typedef struct sPCIDevice { @@ -39,23 +45,22 @@ typedef struct sPCIDevice char *PCI_ReadDirRoot(tVFS_Node *node, int pos); tVFS_Node *PCI_FindDirRoot(tVFS_Node *node, const char *filename); Uint64 PCI_ReadDevice(tVFS_Node *node, Uint64 pos, Uint64 length, void *buffer); - + +#if 0 int PCI_CountDevices(Uint16 vendor, Uint16 device, Uint16 fcn); int PCI_GetDevice(Uint16 vendor, Uint16 device, Uint16 fcn, int idx); int PCI_GetDeviceByClass(Uint16 class, Uint16 mask, int prev); Uint8 PCI_GetIRQ(int id); Uint32 PCI_GetBAR0(int id); Uint32 PCI_GetBAR1(int id); +Uint32 PCI_GetBAR2(int id); Uint32 PCI_GetBAR3(int id); Uint32 PCI_GetBAR4(int id); Uint32 PCI_GetBAR5(int id); Uint16 PCI_AssignPort(int id, int bar, int count); +#endif int PCI_EnumDevice(Uint16 bus, Uint16 dev, Uint16 fcn, tPCIDevice *info); -Uint32 PCI_CfgReadDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset); -void PCI_CfgWriteDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset, Uint32 data); -Uint16 PCI_CfgReadWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset); -Uint8 PCI_CfgReadByte(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset); // === GLOBALS === MODULE_DEFINE(0, 0x0100, PCI, PCI_Install, NULL, NULL); @@ -181,13 +186,9 @@ int PCI_ScanBus(int BusID, int bFill) } giPCI_DeviceCount ++; - // WTF is this for? - // Maybe bit 23 must be set for the device to be valid? - // - Actually, maybe 23 means that there are sub-functions - if(fcn == 0) { - if( !(devInfo.ConfigCache[3] & 0x00800000) ) - break; - } + // If bit 23 of (soemthing) is set, there are sub-functions + if(fcn == 0 && !(devInfo.ConfigCache[3] & 0x00800000) ) + break; } } @@ -426,8 +427,14 @@ Uint16 PCI_AssignPort(int id, int bar, int count) portVals &= ~1; // Get Granuality + #if ARCHDIR_IS_x86 || ARCHDIR_IS_x86_64 __asm__ __volatile__ ("bsf %%eax, %%ecx" : "=c" (gran) : "a" (portVals) ); gran = 1 << gran; + #else + { + for(gran = 1; gran && !(portVals & gran); gran <<= 1); + } + #endif //LogF(" PCI_AssignPort: gran = 0x%x\n", gran); // Find free space @@ -462,9 +469,10 @@ Uint16 PCI_AssignPort(int id, int bar, int count) } /** - * \fn int PCI_EnumDevice(Uint16 bus, Uint16 slot, Uint16 fcn, tPCIDevice *info) + * \fn int PCI_EnumDevice(Uint16 bus, Uint16 slot, Uint16 fcn, tPCIDevice *info) + * \brief Get device information for a slot/function */ -int PCI_EnumDevice(Uint16 bus, Uint16 slot, Uint16 fcn, tPCIDevice *info) +int PCI_EnumDevice(Uint16 bus, Uint16 slot, Uint16 fcn, tPCIDevice *info) { Uint16 vendor; int i; @@ -515,54 +523,6 @@ int PCI_EnumDevice(Uint16 bus, Uint16 slot, Uint16 fcn, tPCIDevice *info) return 1; } -Uint32 PCI_CfgReadDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset) -{ - Uint32 address; - Uint32 data; - - bus &= 0xFF; // 8 Bits - dev &= 0x1F; // 5 Bits - func &= 0x7; // 3 Bits - offset &= 0xFF; // 8 Bits - - address = 0x80000000 | ((Uint)bus<<16) | ((Uint)dev<<11) | ((Uint)func<<8) | (offset&0xFC); - outd(0xCF8, address); - - data = ind(0xCFC); - //Debug("PCI(0x%x) = 0x%08x", address, data); - return data; -} -void PCI_CfgWriteDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset, Uint32 data) -{ - Uint32 address; - - bus &= 0xFF; // 8 Bits - dev &= 0x1F; // 5 Bits - func &= 0x7; // 3 Bits - offset &= 0xFF; // 8 Bits - - address = 0x80000000 | ((Uint)bus<<16) | ((Uint)dev<<11) | ((Uint)func<<8) | (offset&0xFC); - outd(0xCF8, address); - outd(0xCFC, data); -} -Uint16 PCI_CfgReadWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset) -{ - Uint32 data = PCI_CfgReadDWord(bus, dev, func, offset); - - data >>= (offset&2)*8; // Allow Access to Upper Word - - return (Uint16)data; -} - -Uint8 PCI_CfgReadByte(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset) -{ - Uint32 data = PCI_CfgReadDWord(bus, dev, func, offset); - - data >>= (offset&3)*8; //Allow Access to Upper Word - return (Uint8)data; -} - - // === EXPORTS === //* EXPORT(PCI_CountDevices);