📄 pci_v3.c
字号:
*val = v; return PCIBIOS_SUCCESSFUL;}static int v3_read_config_dword(struct pci_dev *dev, int where, u32 *val){ unsigned long addr; unsigned long flags; u32 v; spin_lock_irqsave(&v3_lock, flags); addr = v3_open_config_window(dev, where); v = __raw_readl(addr); v3_close_config_window(); spin_unlock_irqrestore(&v3_lock, flags); *val = v; return PCIBIOS_SUCCESSFUL;}static int v3_write_config_byte(struct pci_dev *dev, int where, u8 val){ unsigned long addr; unsigned long flags; spin_lock_irqsave(&v3_lock, flags); addr = v3_open_config_window(dev, where); __raw_writeb(val, addr); __raw_readb(addr); v3_close_config_window(); spin_unlock_irqrestore(&v3_lock, flags); return PCIBIOS_SUCCESSFUL;}static int v3_write_config_word(struct pci_dev *dev, int where, u16 val){ unsigned long addr; unsigned long flags; spin_lock_irqsave(&v3_lock, flags); addr = v3_open_config_window(dev, where); __raw_writew(val, addr); __raw_readw(addr); v3_close_config_window(); spin_unlock_irqrestore(&v3_lock, flags); return PCIBIOS_SUCCESSFUL;}static int v3_write_config_dword(struct pci_dev *dev, int where, u32 val){ unsigned long addr; unsigned long flags; spin_lock_irqsave(&v3_lock, flags); addr = v3_open_config_window(dev, where); __raw_writel(val, addr); __raw_readl(addr); v3_close_config_window(); spin_unlock_irqrestore(&v3_lock, flags); return PCIBIOS_SUCCESSFUL;}static struct pci_ops pci_v3_ops = { read_byte: v3_read_config_byte, read_word: v3_read_config_word, read_dword: v3_read_config_dword, write_byte: v3_write_config_byte, write_word: v3_write_config_word, write_dword: v3_write_config_dword,};static struct resource non_mem = { name: "PCI non-prefetchable", start: 0x40000000 + PCI_BUS_NONMEM_START, end: 0x40000000 + PCI_BUS_NONMEM_START + PCI_BUS_NONMEM_SIZE - 1, flags: IORESOURCE_MEM,};static struct resource pre_mem = { name: "PCI prefetchable", start: 0x40000000 + PCI_BUS_PREMEM_START, end: 0x40000000 + PCI_BUS_PREMEM_START + PCI_BUS_PREMEM_SIZE - 1, flags: IORESOURCE_MEM | IORESOURCE_PREFETCH,};int __init pci_v3_setup_resources(struct resource **resource){ if (request_resource(&iomem_resource, &non_mem)) { printk(KERN_ERR "PCI: unable to allocate non-prefetchable " "memory region\n"); return -EBUSY; } if (request_resource(&iomem_resource, &pre_mem)) { release_resource(&non_mem); printk(KERN_ERR "PCI: unable to allocate prefetchable " "memory region\n"); return -EBUSY; } /* * bus->resource[0] is the IO resource for this bus * bus->resource[1] is the mem resource for this bus * bus->resource[2] is the prefetch mem resource for this bus */ resource[0] = &ioport_resource; resource[1] = &non_mem; resource[2] = &pre_mem; return 1;}/* * These don't seem to be implemented on the Integrator I have, which * means I can't get additional information on the reason for the pm2fb * problems. I suppose I'll just have to mind-meld with the machine. ;) */#define SC_PCI (IO_ADDRESS(INTEGRATOR_SC_BASE) + INTEGRATOR_SC_PCIENABLE_OFFSET)#define SC_LBFADDR (IO_ADDRESS(INTEGRATOR_SC_BASE) + 0x20)#define SC_LBFCODE (IO_ADDRESS(INTEGRATOR_SC_BASE) + 0x24)static int v3_fault(unsigned long addr, struct pt_regs *regs){ unsigned long pc = instruction_pointer(regs); unsigned long instr = *(unsigned long *)pc;#if 0 char buf[128]; sprintf(buf, "V3 fault: address=0x%08lx, pc=0x%08lx [%08lx] LBFADDR=%08x LBFCODE=%02x ISTAT=%02x\n", addr, pc, instr, __raw_readl(SC_LBFADDR), __raw_readl(SC_LBFCODE) & 255, v3_readb(V3_LB_ISTAT)); printk(KERN_DEBUG "%s", buf); printascii(buf);#endif v3_writeb(V3_LB_ISTAT, 0); __raw_writel(3, SC_PCI); /* * If the instruction being executed was a read, * make it look like it read all-ones. */ if ((instr & 0x0c100000) == 0x04100000) { int reg = (instr >> 12) & 15; unsigned long val; if (instr & 0x00400000) val = 255; else val = -1; regs->uregs[reg] = val; regs->ARM_pc += 4; return 0; } if ((instr & 0x0e100090) == 0x00100090) { int reg = (instr >> 12) & 15; regs->uregs[reg] = -1; regs->ARM_pc += 4; return 0; } return 1;}static void v3_irq(int irq, void *devid, struct pt_regs *regs){#ifdef CONFIG_DEBUG_LL unsigned long pc = instruction_pointer(regs); unsigned long instr = *(unsigned long *)pc; char buf[128]; sprintf(buf, "V3 int %d: pc=0x%08lx [%08lx] LBFADDR=%08x LBFCODE=%02x ISTAT=%02x\n", irq, pc, instr, __raw_readl(SC_LBFADDR), __raw_readl(SC_LBFCODE) & 255, v3_readb(V3_LB_ISTAT)); printascii(buf);#endif v3_writew(V3_PCI_STAT, 0xf000); v3_writeb(V3_LB_ISTAT, 0); __raw_writel(3, SC_PCI);#ifdef CONFIG_DEBUG_LL /* * If the instruction being executed was a read, * make it look like it read all-ones. */ if ((instr & 0x0c100000) == 0x04100000) { int reg = (instr >> 16) & 15; sprintf(buf, " reg%d = %08lx\n", reg, regs->uregs[reg]); printascii(buf); }#endif}extern int (*external_fault)(unsigned long addr, struct pt_regs *regs);/* * V3_LB_BASE? - local bus address * V3_LB_MAP? - pci bus address */void __init pci_v3_init(void *sysdata){ unsigned int pci_cmd; unsigned long flags; unsigned int temp; int ret; /* * Hook in our fault handler for PCI errors */ external_fault = v3_fault; spin_lock_irqsave(&v3_lock, flags); /* * Unlock V3 registers, but only if they were previously locked. */ if (v3_readw(V3_SYSTEM) & V3_SYSTEM_M_LOCK) v3_writew(V3_SYSTEM, 0xa05f); /* * Setup window 0 - PCI non-prefetchable memory * Local: 0x40000000 Bus: 0x00000000 Size: 256MB */ v3_writel(V3_LB_BASE0, v3_addr_to_lb_base(PHYS_PCI_MEM_BASE) | V3_LB_BASE_ADR_SIZE_256MB | V3_LB_BASE_ENABLE); v3_writew(V3_LB_MAP0, v3_addr_to_lb_map(PCI_BUS_NONMEM_START) | V3_LB_MAP_TYPE_MEM); /* * Setup window 1 - PCI prefetchable memory * Local: 0x50000000 Bus: 0x10000000 Size: 256MB */ v3_writel(V3_LB_BASE1, v3_addr_to_lb_base(PHYS_PCI_MEM_BASE + SZ_256M) | V3_LB_BASE_ADR_SIZE_256MB | V3_LB_BASE_PREFETCH | V3_LB_BASE_ENABLE); v3_writew(V3_LB_MAP1, v3_addr_to_lb_map(PCI_BUS_PREMEM_START) | V3_LB_MAP_TYPE_MEM_MULTIPLE); /* * Setup window 2 - PCI IO */ v3_writel(V3_LB_BASE2, v3_addr_to_lb_base2(PHYS_PCI_IO_BASE) | V3_LB_BASE_ENABLE); v3_writew(V3_LB_MAP2, v3_addr_to_lb_map2(0)); /* * Disable PCI to host IO cycles */ temp = v3_readw(V3_PCI_CFG) & ~V3_PCI_CFG_M_I2O_EN; temp |= V3_PCI_CFG_M_IO_REG_DIS | V3_PCI_CFG_M_IO_DIS; v3_writew(V3_PCI_CFG, temp); printk(KERN_DEBUG "FIFO_CFG: %04x FIFO_PRIO: %04x\n", v3_readw(V3_FIFO_CFG), v3_readw(V3_FIFO_PRIORITY)); /* * Set the V3 FIFO such that writes have higher priority than * reads, and local bus write causes local bus read fifo flush. * Same for PCI. */ v3_writew(V3_FIFO_PRIORITY, 0x0a0a); /* * Re-lock the system register. */ temp = v3_readw(V3_SYSTEM) | V3_SYSTEM_M_LOCK; v3_writew(V3_SYSTEM, temp); /* * Clear any error conditions, and enable write errors. */ v3_writeb(V3_LB_ISTAT, 0); v3_writew(V3_LB_CFG, v3_readw(V3_LB_CFG) | (1 << 10)); v3_writeb(V3_LB_IMASK, 0x28); __raw_writel(3, SC_PCI); /* * Grab the PCI error interrupt. */ ret = request_irq(IRQ_V3INT, v3_irq, 0, "V3 error", NULL); if (ret) printk(KERN_ERR "PCI: unable to grab PCI error " "interrupt: %d\n", ret); spin_unlock_irqrestore(&v3_lock, flags); pci_scan_bus(0, &pci_v3_ops, sysdata); pci_cmd = PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER | PCI_COMMAND_INVALIDATE; v3_writew(V3_PCI_CMD, pci_cmd); v3_writeb(V3_LB_ISTAT, ~0x40); v3_writeb(V3_LB_IMASK, 0x68);#if 0 ret = request_irq(IRQ_LBUSTIMEOUT, lb_timeout, 0, "bus timeout", NULL); if (ret) printk(KERN_ERR "PCI: unable to grab local bus timeout ". "interrupt: %d\n", ret);#endif}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -