X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=KernelLand%2FKernel%2Fdrv%2Fpci.c;h=702c9ccc51eb7ab1d3b3096983fd18c68953795d;hb=35bd78fa5f141882c43b1bcaa0c90436ff3974f1;hp=8745080b0a3f1f2b808af629b7da6b8d8f1411cb;hpb=51ab5f489bc356940c95cc936fd0508e8f07ea97;p=tpg%2Facess2.git diff --git a/KernelLand/Kernel/drv/pci.c b/KernelLand/Kernel/drv/pci.c index 8745080b..702c9ccc 100644 --- a/KernelLand/Kernel/drv/pci.c +++ b/KernelLand/Kernel/drv/pci.c @@ -10,6 +10,7 @@ #include #include +#define USE_PORT_BITMAP 0 #define LIST_DEVICES 1 // === STRUCTURES === @@ -32,10 +33,10 @@ typedef struct sPCIDevice int PCI_Install(char **Arguments); int PCI_ScanBus(int ID, int bFill); -char *PCI_int_ReadDirRoot(tVFS_Node *node, int pos); + int PCI_int_ReadDirRoot(tVFS_Node *node, int pos, char Dest[FILENAME_MAX]); tVFS_Node *PCI_int_FindDirRoot(tVFS_Node *node, const char *filename); Uint32 PCI_int_GetBusAddr(Uint16 Bus, Uint16 Slot, Uint16 Fcn, Uint8 Offset); -Uint64 PCI_int_ReadDevice(tVFS_Node *node, Uint64 pos, Uint64 length, void *buffer); +size_t PCI_int_ReadDevice(tVFS_Node *node, off_t Offset, size_t Length, void *buffer); int PCI_int_EnumDevice(Uint16 bus, Uint16 dev, Uint16 fcn, tPCIDevice *info); // === GLOBALS === @@ -63,7 +64,9 @@ tDevFS_Driver gPCI_DriverStruct = { .Type = &gPCI_RootNodeType } }; +#if USE_PORT_BITMAP Uint32 *gaPCI_PortBitmap = NULL; +#endif Uint32 gaPCI_BusBitmap[256/32]; // === CODE === @@ -73,9 +76,10 @@ Uint32 gaPCI_BusBitmap[256/32]; */ int PCI_Install(char **Arguments) { - int i; + int ret, bus; void *tmpPtr; + #if USE_PORT_BITMAP // Build Portmap gaPCI_PortBitmap = malloc( 1 << 13 ); if( !gaPCI_PortBitmap ) { @@ -83,14 +87,19 @@ int PCI_Install(char **Arguments) return MODULE_ERR_MALLOC; } memset( gaPCI_PortBitmap, 0, 1 << 13 ); + int i; for( i = 0; i < MAX_RESERVED_PORT / 32; i ++ ) gaPCI_PortBitmap[i] = -1; for( i = 0; i < MAX_RESERVED_PORT % 32; i ++ ) gaPCI_PortBitmap[MAX_RESERVED_PORT / 32] = 1 << i; - + #endif + // Scan Bus (Bus 0, Don't fill gPCI_Devices) - i = PCI_ScanBus(0, 0); - if(i != MODULE_ERR_OK) return i; + for( bus = 0; bus < giPCI_BusCount; bus ++ ) + { + ret = PCI_ScanBus(bus, 0); + if(ret != MODULE_ERR_OK) return ret; + } if(giPCI_DeviceCount == 0) { Log_Notice("PCI", "No devices were found"); @@ -109,10 +118,13 @@ int PCI_Install(char **Arguments) // Reset counts giPCI_DeviceCount = 0; - giPCI_BusCount = 0; + giPCI_BusCount = 1; memset(gaPCI_BusBitmap, 0, sizeof(gaPCI_BusBitmap)); // Rescan, filling the PCI device array - PCI_ScanBus(0, 1); + for( bus = 0; bus < giPCI_BusCount; bus ++ ) + { + PCI_ScanBus(bus, 1); + } // Complete Driver Structure gPCI_DriverStruct.RootNode.Size = giPCI_DeviceCount; @@ -161,8 +173,9 @@ int PCI_ScanBus(int BusID, int bFill) { #if LIST_DEVICES if( !bFill ) - Log_Log("PCI", "Device %i,%i:%i %06x => 0x%04x:0x%04x", - BusID, dev, fcn, devInfo.class, devInfo.vendor, devInfo.device); + Log_Log("PCI", "Device %i,%i:%i %06x => 0x%04x:0x%04x Rev %i", + BusID, dev, fcn, devInfo.class, + devInfo.vendor, devInfo.device, devInfo.revision); #endif } @@ -184,16 +197,16 @@ int PCI_ScanBus(int BusID, int bFill) /** * \brief Read from Root of PCI Driver */ -char *PCI_int_ReadDirRoot(tVFS_Node *Node, int Pos) +int PCI_int_ReadDirRoot(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]) { ENTER("pNode iPos", Node, Pos); if(Pos < 0 || Pos >= giPCI_DeviceCount) { - LEAVE('n'); - return NULL; + LEAVE_RET('i', -EINVAL); } - LEAVE('s', gPCI_Devices[Pos].Name); - return strdup( gPCI_Devices[Pos].Name ); + LOG("Name = %s", gPCI_Devices[Pos].Name); + strncpy(Dest, gPCI_Devices[Pos].Name, FILENAME_MAX); + LEAVE_RET('i', 0); } /** */ @@ -235,8 +248,9 @@ tVFS_Node *PCI_int_FindDirRoot(tVFS_Node *node, const char *filename) } /** + * \brief Read the PCI configuration space of a device */ -Uint64 PCI_int_ReadDevice(tVFS_Node *node, Uint64 pos, Uint64 length, void *buffer) +size_t PCI_int_ReadDevice(tVFS_Node *node, off_t pos, size_t length, void *buffer) { if( pos + length > 256 ) return 0; @@ -481,7 +495,7 @@ int PCI_int_EnumDevice(Uint16 bus, Uint16 slot, Uint16 fcn, tPCIDevice *info) info->Node.NumACLs = 1; info->Node.ACLs = &gVFS_ACL_EveryoneRO; - info->Node.Type = &gPCI_RootNodeType; + info->Node.Type = &gPCI_DevNodeType; return 1; }