X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=KernelLand%2FKernel%2Fdrv%2Fpci.c;h=3a4ec865191cae3a85cfc93e787832e75e0c25b4;hb=7b0611393a98399063aefaa87583b05fef13f6e3;hp=1df421ec2c2cc0a0a700cc489af4cfe06bb14ad8;hpb=3be7e2aa30e9c6d6b73290f4881bfea8afce01fd;p=tpg%2Facess2.git diff --git a/KernelLand/Kernel/drv/pci.c b/KernelLand/Kernel/drv/pci.c index 1df421ec..3a4ec865 100644 --- a/KernelLand/Kernel/drv/pci.c +++ b/KernelLand/Kernel/drv/pci.c @@ -39,9 +39,9 @@ typedef struct sPCIDevice int PCI_ScanBus(int ID, int bFill); int PCI_int_ReadDirRoot(tVFS_Node *node, int pos, char Dest[FILENAME_MAX]); -tVFS_Node *PCI_int_FindDirRoot(tVFS_Node *node, const char *filename); +tVFS_Node *PCI_int_FindDirRoot(tVFS_Node *node, const char *filename, Uint Flags); Uint32 PCI_int_GetBusAddr(Uint16 Bus, Uint16 Slot, Uint16 Fcn, Uint8 Offset); -size_t PCI_int_ReadDevice(tVFS_Node *node, off_t Offset, size_t Length, void *buffer); +size_t PCI_int_ReadDevice(tVFS_Node *node, off_t Offset, size_t Length, void *buffer, Uint Flags); int PCI_int_EnumDevice(Uint16 bus, Uint16 dev, Uint16 fcn, tPCIDevice *info); // === GLOBALS === @@ -215,7 +215,7 @@ int PCI_ScanBus(int BusID, int bFill) } giPCI_DeviceCount ++; - switch(devInfo.ConfigCache[3] & 0x007F0000) + switch( (devInfo.ConfigCache[3] >> 16) & 0x7F ) { case 0x00: // Normal device break; @@ -261,12 +261,10 @@ int PCI_int_ReadDirRoot(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]) } /** */ -tVFS_Node *PCI_int_FindDirRoot(tVFS_Node *node, const char *filename) +tVFS_Node *PCI_int_FindDirRoot(tVFS_Node *node, const char *filename, Uint Flags) { - int i; - // Find Match - for(i=0;i 0 ) // Sorted list @@ -282,7 +280,7 @@ tVFS_Node *PCI_int_FindDirRoot(tVFS_Node *node, const char *filename) /** * \brief Read the PCI configuration space of a device */ -size_t PCI_int_ReadDevice(tVFS_Node *node, off_t pos, size_t length, void *buffer) +size_t PCI_int_ReadDevice(tVFS_Node *node, off_t pos, size_t length, void *buffer, Uint Flags) { if( pos + length > 256 ) return 0; @@ -465,6 +463,17 @@ void PCI_ConfigWrite(tPCIDev ID, int Offset, int Size, Uint32 Value) PCI_CfgWriteDWord(addr, dword); } +Uint16 PCI_SetCommand(tPCIDev id, Uint16 SBits, Uint16 CBits) +{ + tPCIDevice *dev = &gPCI_Devices[id]; + dev->ConfigCache[1] &= ~CBits; + dev->ConfigCache[1] |= SBits; + Uint32 addr = PCI_int_GetBusAddr(dev->bus, dev->slot, dev->fcn, 1*4); + PCI_CfgWriteDWord(addr, dev->ConfigCache[1]); + dev->ConfigCache[1] = PCI_CfgReadDWord(addr); + return dev->ConfigCache[1]; +} + /** * \brief Get the IRQ assigned to a device */ @@ -488,6 +497,61 @@ Uint32 PCI_GetBAR(tPCIDev id, int BARNum) return gPCI_Devices[id].ConfigCache[4+BARNum]; } +/** + */ +Uint64 PCI_GetValidBAR(tPCIDev ID, int BARNum, tPCI_BARType Type) +{ + if( ID < 0 || ID >= giPCI_DeviceCount ) + return 0; + if( BARNum < 0 || BARNum >= 6 ) + return 0; + tPCIDevice *dev = &gPCI_Devices[ID]; + Uint32 bar_val = dev->ConfigCache[4+BARNum]; + Uint64 ret = -1; + switch( Type ) + { + case PCI_BARTYPE_IO: + if( !(bar_val & 1) ) + return 0; + ret = bar_val & ~3; + break; + + case PCI_BARTYPE_MEMNP: + if( bar_val & 8 ) return 0; + if(0) + case PCI_BARTYPE_MEMP: + if( !(bar_val & 8) ) return 0; + case PCI_BARTYPE_MEM: + if( bar_val & 1 ) return 0; + if( (bar_val & 6) == 4 ) { + ASSERTCR(BARNum, <, 5, 0); + ret = (bar_val & ~0xF) | ((Uint64)dev->ConfigCache[4+BARNum+1] << 32); + } + else { + ret = bar_val & ~0xF; + } + break; + case PCI_BARTYPE_MEM32: + if( bar_val & 1 ) return 0; + if( (bar_val & 6) != 0 ) return 0; + ret = bar_val & ~0xF; + break; + case PCI_BARTYPE_MEM64: + if( bar_val & 1 ) return 0; + if( (bar_val & 6) != 4 ) return 0; + ASSERTCR(BARNum, <, 5, 0); + ret = (bar_val & ~0xF) | ((Uint64)dev->ConfigCache[4+BARNum+1] << 32); + break; + } + ASSERT(ret != -1); + if( ret == 0 ) { + Log_Error("PCI", "PCI%i BAR%i correct type, but unallocated (0x%x)", + ID, BARNum, bar_val); + return 0; + } + return ret; +} + /** * \brief Get device information for a slot/function */