iseries_pci.c
来自「Linux Kernel 2.6.9 for OMAP1710」· C语言 代码 · 共 818 行 · 第 1/2 页
C
818 行
node->Irq = Irq; node->LogicalSlot = BridgeInfo->logicalSlotNumber; } /* for (Function = 0; Function < 8; ++Function) */ } /* for (IdSel = 1; IdSel <= MaxAgents; ++IdSel) */ return HvRc;}/* * I/0 Memory copy MUST use mmio commands on iSeries * To do; For performance, include the hv call directly */void iSeries_memset_io(volatile void __iomem *dest, char c, size_t Count){ u8 ByteValue = c; long NumberOfBytes = Count; while (NumberOfBytes > 0) { iSeries_Write_Byte(ByteValue, dest++); -- NumberOfBytes; }}EXPORT_SYMBOL(iSeries_memset_io);void iSeries_memcpy_toio(volatile void __iomem *dest, void *source, size_t count){ char *src = source; long NumberOfBytes = count; while (NumberOfBytes > 0) { iSeries_Write_Byte(*src++, dest++); -- NumberOfBytes; }}EXPORT_SYMBOL(iSeries_memcpy_toio);void iSeries_memcpy_fromio(void *dest, const volatile void __iomem *src, size_t count){ char *dst = dest; long NumberOfBytes = count; while (NumberOfBytes > 0) { *dst++ = iSeries_Read_Byte(src++); -- NumberOfBytes; }}EXPORT_SYMBOL(iSeries_memcpy_fromio);/* * Look down the chain to find the matching Device Device */static struct iSeries_Device_Node *find_Device_Node(int bus, int devfn){ struct list_head *pos; list_for_each(pos, &iSeries_Global_Device_List) { struct iSeries_Device_Node *node = list_entry(pos, struct iSeries_Device_Node, Device_List); if ((bus == ISERIES_BUS(node)) && (devfn == node->DevFn)) return node; } return NULL;}#if 0/* * Returns the device node for the passed pci_dev * Sanity Check Node PciDev to passed pci_dev * If none is found, returns a NULL which the client must handle. */static struct iSeries_Device_Node *get_Device_Node(struct pci_dev *pdev){ struct iSeries_Device_Node *node; node = pdev->sysdata; if (node == NULL || node->PciDev != pdev) node = find_Device_Node(pdev->bus->number, pdev->devfn); return node;}#endif/* * Config space read and write functions. * For now at least, we look for the device node for the bus and devfn * that we are asked to access. It may be possible to translate the devfn * to a subbus and deviceid more directly. */static u64 hv_cfg_read_func[4] = { HvCallPciConfigLoad8, HvCallPciConfigLoad16, HvCallPciConfigLoad32, HvCallPciConfigLoad32};static u64 hv_cfg_write_func[4] = { HvCallPciConfigStore8, HvCallPciConfigStore16, HvCallPciConfigStore32, HvCallPciConfigStore32};/* * Read PCI config space */static int iSeries_pci_read_config(struct pci_bus *bus, unsigned int devfn, int offset, int size, u32 *val){ struct iSeries_Device_Node *node = find_Device_Node(bus->number, devfn); u64 fn; struct HvCallPci_LoadReturn ret; if (node == NULL) return PCIBIOS_DEVICE_NOT_FOUND; fn = hv_cfg_read_func[(size - 1) & 3]; HvCall3Ret16(fn, &ret, node->DsaAddr.DsaAddr, offset, 0); if (ret.rc != 0) { *val = ~0; return PCIBIOS_DEVICE_NOT_FOUND; /* or something */ } *val = ret.value; return 0;}/* * Write PCI config space */static int iSeries_pci_write_config(struct pci_bus *bus, unsigned int devfn, int offset, int size, u32 val){ struct iSeries_Device_Node *node = find_Device_Node(bus->number, devfn); u64 fn; u64 ret; if (node == NULL) return PCIBIOS_DEVICE_NOT_FOUND; fn = hv_cfg_write_func[(size - 1) & 3]; ret = HvCall4(fn, node->DsaAddr.DsaAddr, offset, val, 0); if (ret != 0) return PCIBIOS_DEVICE_NOT_FOUND; return 0;}static struct pci_ops iSeries_pci_ops = { .read = iSeries_pci_read_config, .write = iSeries_pci_write_config};/* * Check Return Code * -> On Failure, print and log information. * Increment Retry Count, if exceeds max, panic partition. * -> If in retry, print and log success * * PCI: Device 23.90 ReadL I/O Error( 0): 0x1234 * PCI: Device 23.90 ReadL Retry( 1) * PCI: Device 23.90 ReadL Retry Successful(1) */static int CheckReturnCode(char *TextHdr, struct iSeries_Device_Node *DevNode, u64 ret){ if (ret != 0) { ++Pci_Error_Count; ++DevNode->IoRetry; printk("PCI: %s: Device 0x%04X:%02X I/O Error(%2d): 0x%04X\n", TextHdr, DevNode->DsaAddr.Dsa.busNumber, DevNode->DevFn, DevNode->IoRetry, (int)ret); /* * Bump the retry and check for retry count exceeded. * If, Exceeded, panic the system. */ if ((DevNode->IoRetry > Pci_Retry_Max) && (Pci_Error_Flag > 0)) { mf_displaySrc(0xB6000103); panic_timeout = 0; panic("PCI: Hardware I/O Error, SRC B6000103, " "Automatic Reboot Disabled.\n"); } return -1; /* Retry Try */ } /* If retry was in progress, log success and rest retry count */ if (DevNode->IoRetry > 0) { PCIFR("%s: Device 0x%04X:%02X Retry Successful(%2d).", TextHdr, DevNode->DsaAddr.Dsa.busNumber, DevNode->DevFn, DevNode->IoRetry); DevNode->IoRetry = 0; } return 0; }/* * Translate the I/O Address into a device node, bar, and bar offset. * Note: Make sure the passed variable end up on the stack to avoid * the exposure of being device global. */static inline struct iSeries_Device_Node *xlateIoMmAddress(const volatile void __iomem *IoAddress, u64 *dsaptr, u64 *BarOffsetPtr){ unsigned long OrigIoAddr; unsigned long BaseIoAddr; unsigned long TableIndex; struct iSeries_Device_Node *DevNode; OrigIoAddr = (unsigned long __force)IoAddress; if ((OrigIoAddr < iSeries_Base_Io_Memory) || (OrigIoAddr >= iSeries_Max_Io_Memory)) return NULL; BaseIoAddr = OrigIoAddr - iSeries_Base_Io_Memory; TableIndex = BaseIoAddr / iSeries_IoMmTable_Entry_Size; DevNode = iSeries_IoMmTable[TableIndex]; if (DevNode != NULL) { int barnum = iSeries_IoBarTable[TableIndex]; *dsaptr = DevNode->DsaAddr.DsaAddr | (barnum << 24); *BarOffsetPtr = BaseIoAddr % iSeries_IoMmTable_Entry_Size; } else panic("PCI: Invalid PCI IoAddress detected!\n"); return DevNode;}/* * Read MM I/O Instructions for the iSeries * On MM I/O error, all ones are returned and iSeries_pci_IoError is cal * else, data is returned in big Endian format. * * iSeries_Read_Byte = Read Byte ( 8 bit) * iSeries_Read_Word = Read Word (16 bit) * iSeries_Read_Long = Read Long (32 bit) */u8 iSeries_Read_Byte(const volatile void __iomem *IoAddress){ u64 BarOffset; u64 dsa; struct HvCallPci_LoadReturn ret; struct iSeries_Device_Node *DevNode = xlateIoMmAddress(IoAddress, &dsa, &BarOffset); if (DevNode == NULL) { static unsigned long last_jiffies; static int num_printed; if ((jiffies - last_jiffies) > 60 * HZ) { last_jiffies = jiffies; num_printed = 0; } if (num_printed++ < 10) printk(KERN_ERR "iSeries_Read_Byte: invalid access at IO address %p\n", IoAddress); return 0xff; } do { ++Pci_Io_Read_Count; HvCall3Ret16(HvCallPciBarLoad8, &ret, dsa, BarOffset, 0); } while (CheckReturnCode("RDB", DevNode, ret.rc) != 0); return (u8)ret.value;}EXPORT_SYMBOL(iSeries_Read_Byte);u16 iSeries_Read_Word(const volatile void __iomem *IoAddress){ u64 BarOffset; u64 dsa; struct HvCallPci_LoadReturn ret; struct iSeries_Device_Node *DevNode = xlateIoMmAddress(IoAddress, &dsa, &BarOffset); if (DevNode == NULL) { static unsigned long last_jiffies; static int num_printed; if ((jiffies - last_jiffies) > 60 * HZ) { last_jiffies = jiffies; num_printed = 0; } if (num_printed++ < 10) printk(KERN_ERR "iSeries_Read_Word: invalid access at IO address %p\n", IoAddress); return 0xffff; } do { ++Pci_Io_Read_Count; HvCall3Ret16(HvCallPciBarLoad16, &ret, dsa, BarOffset, 0); } while (CheckReturnCode("RDW", DevNode, ret.rc) != 0); return swab16((u16)ret.value);}EXPORT_SYMBOL(iSeries_Read_Word);u32 iSeries_Read_Long(const volatile void __iomem *IoAddress){ u64 BarOffset; u64 dsa; struct HvCallPci_LoadReturn ret; struct iSeries_Device_Node *DevNode = xlateIoMmAddress(IoAddress, &dsa, &BarOffset); if (DevNode == NULL) { static unsigned long last_jiffies; static int num_printed; if ((jiffies - last_jiffies) > 60 * HZ) { last_jiffies = jiffies; num_printed = 0; } if (num_printed++ < 10) printk(KERN_ERR "iSeries_Read_Long: invalid access at IO address %p\n", IoAddress); return 0xffffffff; } do { ++Pci_Io_Read_Count; HvCall3Ret16(HvCallPciBarLoad32, &ret, dsa, BarOffset, 0); } while (CheckReturnCode("RDL", DevNode, ret.rc) != 0); return swab32((u32)ret.value);}EXPORT_SYMBOL(iSeries_Read_Long);/* * Write MM I/O Instructions for the iSeries * * iSeries_Write_Byte = Write Byte (8 bit) * iSeries_Write_Word = Write Word(16 bit) * iSeries_Write_Long = Write Long(32 bit) */void iSeries_Write_Byte(u8 data, volatile void __iomem *IoAddress){ u64 BarOffset; u64 dsa; u64 rc; struct iSeries_Device_Node *DevNode = xlateIoMmAddress(IoAddress, &dsa, &BarOffset); if (DevNode == NULL) { static unsigned long last_jiffies; static int num_printed; if ((jiffies - last_jiffies) > 60 * HZ) { last_jiffies = jiffies; num_printed = 0; } if (num_printed++ < 10) printk(KERN_ERR "iSeries_Write_Byte: invalid access at IO address %p\n", IoAddress); return; } do { ++Pci_Io_Write_Count; rc = HvCall4(HvCallPciBarStore8, dsa, BarOffset, data, 0); } while (CheckReturnCode("WWB", DevNode, rc) != 0);}EXPORT_SYMBOL(iSeries_Write_Byte);void iSeries_Write_Word(u16 data, volatile void __iomem *IoAddress){ u64 BarOffset; u64 dsa; u64 rc; struct iSeries_Device_Node *DevNode = xlateIoMmAddress(IoAddress, &dsa, &BarOffset); if (DevNode == NULL) { static unsigned long last_jiffies; static int num_printed; if ((jiffies - last_jiffies) > 60 * HZ) { last_jiffies = jiffies; num_printed = 0; } if (num_printed++ < 10) printk(KERN_ERR "iSeries_Write_Word: invalid access at IO address %p\n", IoAddress); return; } do { ++Pci_Io_Write_Count; rc = HvCall4(HvCallPciBarStore16, dsa, BarOffset, swab16(data), 0); } while (CheckReturnCode("WWW", DevNode, rc) != 0);}EXPORT_SYMBOL(iSeries_Write_Word);void iSeries_Write_Long(u32 data, volatile void __iomem *IoAddress){ u64 BarOffset; u64 dsa; u64 rc; struct iSeries_Device_Node *DevNode = xlateIoMmAddress(IoAddress, &dsa, &BarOffset); if (DevNode == NULL) { static unsigned long last_jiffies; static int num_printed; if ((jiffies - last_jiffies) > 60 * HZ) { last_jiffies = jiffies; num_printed = 0; } if (num_printed++ < 10) printk(KERN_ERR "iSeries_Write_Long: invalid access at IO address %p\n", IoAddress); return; } do { ++Pci_Io_Write_Count; rc = HvCall4(HvCallPciBarStore32, dsa, BarOffset, swab32(data), 0); } while (CheckReturnCode("WWL", DevNode, rc) != 0);}EXPORT_SYMBOL(iSeries_Write_Long);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?