X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Fdrv%2Fpci.c;h=73e3a40cb2c0c72341adf6a57d933da46bb0a150;hb=9d85201216cb35e1b1e051b1d7cdc38eaa5befa4;hp=e09d61dc36b76f56c0a42c8dc7c0c24029f5feee;hpb=deb8a310abcb8ef8b6afef74a1fa058777740b3f;p=tpg%2Facess2.git diff --git a/Kernel/drv/pci.c b/Kernel/drv/pci.c index e09d61dc..73e3a40c 100644 --- a/Kernel/drv/pci.c +++ b/Kernel/drv/pci.c @@ -34,22 +34,25 @@ typedef struct sPCIDevice // === PROTOTYPES === int PCI_Install(char **Arguments); - int PCI_ScanBus(int ID); + int PCI_ScanBus(int ID, int bFill); char *PCI_ReadDirRoot(tVFS_Node *node, int pos); -tVFS_Node *PCI_FindDirRoot(tVFS_Node *node, char *filename); +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); @@ -79,8 +82,8 @@ Uint32 gaPCI_BusBitmap[256/32]; // === CODE === /** - * \fn int PCI_Install() * \brief Scan the PCI Bus for devices + * \param Arguments Boot-time parameters */ int PCI_Install(char **Arguments) { @@ -99,8 +102,8 @@ int PCI_Install(char **Arguments) for( i = 0; i < MAX_RESERVED_PORT % 32; i ++ ) gaPCI_PortBitmap[MAX_RESERVED_PORT / 32] = 1 << i; - // Scan Bus - i = PCI_ScanBus(0); + // Scan Bus (Bus 0, Don't fill gPCI_Devices) + i = PCI_ScanBus(0, 0); if(i != MODULE_ERR_OK) return i; if(giPCI_DeviceCount == 0) { @@ -108,12 +111,23 @@ int PCI_Install(char **Arguments) return MODULE_ERR_NOTNEEDED; } - // Ensure the buffer is nice and tight - tmpPtr = realloc(gPCI_Devices, giPCI_DeviceCount*sizeof(tPCIDevice)); - if(tmpPtr == NULL) + // Allocate device buffer + tmpPtr = malloc(giPCI_DeviceCount * sizeof(tPCIDevice)); + if(tmpPtr == NULL) { + Log_Warning("PCI", "Malloc ERROR"); return MODULE_ERR_MALLOC; + } gPCI_Devices = tmpPtr; + Log_Log("PCI", "%i devices, filling structure", giPCI_DeviceCount); + + // Reset counts + giPCI_DeviceCount = 0; + giPCI_BusCount = 0; + memset(gaPCI_BusBitmap, 0, sizeof(gaPCI_BusBitmap)); + // Rescan, filling the PCI device array + PCI_ScanBus(0, 1); + // Complete Driver Structure gPCI_DriverStruct.RootNode.Size = giPCI_DeviceCount; @@ -125,12 +139,13 @@ int PCI_Install(char **Arguments) /** * \brief Scans a specific PCI Bus + * \param BusID PCI Bus ID to scan + * \param bFill Fill the \a gPCI_Devices array? */ -int PCI_ScanBus(int BusID) +int PCI_ScanBus(int BusID, int bFill) { int dev, fcn; tPCIDevice devInfo; - void *tmpPtr = NULL; if( gaPCI_BusBitmap[BusID/32] & (1 << (BusID%32)) ) return MODULE_ERR_OK; @@ -145,12 +160,6 @@ int PCI_ScanBus(int BusID) if(!PCI_EnumDevice(BusID, dev, fcn, &devInfo)) continue; - // Allocate - tmpPtr = realloc(gPCI_Devices, (giPCI_DeviceCount+1)*sizeof(tPCIDevice)); - if(tmpPtr == NULL) - return MODULE_ERR_MALLOC; - gPCI_Devices = tmpPtr; - if(devInfo.oc == PCI_OC_PCIBRIDGE) { #if LIST_DEVICES @@ -158,8 +167,8 @@ int PCI_ScanBus(int BusID) BusID, dev, fcn, devInfo.vendor, devInfo.device); #endif //TODO: Handle PCI-PCI Bridges - //PCI_ScanBus( ); - giPCI_BusCount++; + //PCI_ScanBus(devInfo.???, bFill); + giPCI_BusCount ++; } else { @@ -169,8 +178,10 @@ int PCI_ScanBus(int BusID) #endif } - devInfo.Node.Inode = giPCI_DeviceCount; - memcpy(&gPCI_Devices[giPCI_DeviceCount], &devInfo, sizeof(tPCIDevice)); + if( bFill ) { + devInfo.Node.Inode = giPCI_DeviceCount; + memcpy(&gPCI_Devices[giPCI_DeviceCount], &devInfo, sizeof(tPCIDevice)); + } giPCI_DeviceCount ++; // WTF is this for? @@ -202,9 +213,9 @@ char *PCI_ReadDirRoot(tVFS_Node *Node, int Pos) return strdup( gPCI_Devices[Pos].Name ); } /** - * \fn tVFS_Node *PCI_FindDirRoot(tVFS_Node *node, char *filename) + * \fn tVFS_Node *PCI_FindDirRoot(tVFS_Node *node, const char *filename) */ -tVFS_Node *PCI_FindDirRoot(tVFS_Node *node, char *filename) +tVFS_Node *PCI_FindDirRoot(tVFS_Node *node, const char *filename) { int bus,slot,fcn; int i; @@ -460,7 +471,6 @@ int PCI_EnumDevice(Uint16 bus, Uint16 slot, Uint16 fcn, tPCIDevice *info) { Uint16 vendor; int i; - Uint32 addr; vendor = PCI_CfgReadWord(bus, slot, fcn, 0x0|0); if(vendor == 0xFFFF) // Invalid Device @@ -475,16 +485,9 @@ int PCI_EnumDevice(Uint16 bus, Uint16 slot, Uint16 fcn, tPCIDevice *info) info->oc = PCI_CfgReadWord(bus, slot, fcn, 0x8|2); // Load Config Bytes - addr = 0x80000000 | ((Uint)bus<<16) | ((Uint)slot<<11) | ((Uint)fcn<<8); for(i=0;i<256/4;i++) { - #if 0 - outd(0xCF8, addr); - info->ConfigCache[i] = ind(0xCFC); - addr += 4; - #else info->ConfigCache[i] = PCI_CfgReadDWord(bus, slot, fcn, i*4); - #endif } //#if LIST_DEVICES