/* * The IXP4xx has a peculiar address bus that will change the * byte order on SoC peripherals depending on whether the device * operates in big-endian or little-endian mode. That means that * readl() and writel() that always use little-endian access * will not work for SoC peripherals such as the PCI controller * when used in big-endian mode. The accesses to the individual * PCI devices on the other hand, are always little-endian and * can use readl() and writel(). * * For local AHB bus access we need to use __raw_[readl|writel]() * to make sure that we access the SoC devices in the CPU native * endianness.
*/ staticinline u32 ixp4xx_readl(struct ixp4xx_pci *p, u32 reg)
{ return __raw_readl(p->base + reg);
}
if (isr & IXP4XX_PCI_ISR_PFE) { /* Make sure the master abort bit is reset */
ixp4xx_writel(p, IXP4XX_PCI_ISR, IXP4XX_PCI_ISR_PFE);
dev_dbg(p->dev, "master abort detected\n"); return -EINVAL;
}
/* * PCI workaround - only works if NP PCI space reads have * no side effects. Hammer the register and read twice 8 * times. last one will be good.
*/ for (i = 0; i < 8; i++) {
ixp4xx_writel(p, IXP4XX_PCI_NP_CBE, cmd);
*data = ixp4xx_readl(p, IXP4XX_PCI_NP_RDATA);
*data = ixp4xx_readl(p, IXP4XX_PCI_NP_RDATA);
}
} else {
ixp4xx_writel(p, IXP4XX_PCI_NP_CBE, cmd);
*data = ixp4xx_readl(p, IXP4XX_PCI_NP_RDATA);
}
/* Set up the write */
ixp4xx_writel(p, IXP4XX_PCI_NP_CBE, cmd);
/* Execute the write by writing to NP_WDATA */
ixp4xx_writel(p, IXP4XX_PCI_NP_WDATA, data);
return ixp4xx_pci_check_master_abort(p);
}
static u32 ixp4xx_config_addr(u8 bus_num, u16 devfn, int where)
{ /* Root bus is always 0 in this hardware */ if (bus_num == 0) { /* type 0 */ return (PCI_CONF1_ADDRESS(0, 0, PCI_FUNC(devfn), where) &
~PCI_CONF1_ENABLE) | BIT(32-PCI_SLOT(devfn));
} else { /* type 1 */ return (PCI_CONF1_ADDRESS(bus_num, PCI_SLOT(devfn),
PCI_FUNC(devfn), where) &
~PCI_CONF1_ENABLE) | 1;
}
}
/* * CRP functions are "Controller Configuration Port" accesses * initiated from within this driver itself to read/write PCI * control information in the config space.
*/ static u32 ixp4xx_crp_byte_lane_enable_bits(u32 n, int size)
{ if (size == 1) return (0xf & ~BIT(n)) << CRP_AD_CBE_BESL; if (size == 2) return (0xf & ~(BIT(n) | BIT(n+1))) << CRP_AD_CBE_BESL; if (size == 4) return 0; return 0xffffffff;
}
staticint ixp4xx_crp_read_config(struct ixp4xx_pci *p, int where, int size,
u32 *value)
{
u32 n, cmd, val;
/* * Then follows the functions that read and write from the common PCI * configuration space.
*/ static u32 ixp4xx_byte_lane_enable_bits(u32 n, int size)
{ if (size == 1) return (0xf & ~BIT(n)) << 4; if (size == 2) return (0xf & ~(BIT(n) | BIT(n+1))) << 4; if (size == 4) return 0; return 0xffffffff;
}
staticint ixp4xx_pci_read_config(struct pci_bus *bus, unsignedint devfn, int where, int size, u32 *value)
{ struct ixp4xx_pci *p = bus->sysdata;
u32 n, addr, val, cmd;
u8 bus_num = bus->number; int ret;
*value = 0xffffffff;
n = where % 4;
cmd = ixp4xx_byte_lane_enable_bits(n, size); if (cmd == 0xffffffff) return PCIBIOS_BAD_REGISTER_NUMBER;
dev_dbg(dev, "%s window %pR, bus addr %pa\n",
res->name, res, &addr); if (resource_size(res) != SZ_64M) {
dev_err(dev, "memory range is not 64MB\n"); return -EINVAL;
}
win = resource_list_first_type(&bridge->windows, IORESOURCE_IO); if (win) {
res = win->res;
addr = pci_pio_to_address(res->start); if (addr & 0xff) {
dev_err(dev, "IO mem at uneven address: %pa\n", &addr); return -EINVAL;
}
res->name = "IXP4xx PCI IO MEM"; /* * Setup I/O space location for PCI->AHB access, the * upper 24 bits of the address goes into the lower * 24 bits of this register.
*/
ixp4xx_writel(p, IXP4XX_PCI_AHBIOBASE, (addr >> 8));
} else {
dev_info(dev, "no IO space AHB memory mapping defined\n");
}
win = resource_list_first_type(&bridge->dma_ranges, IORESOURCE_MEM); if (win) {
res = win->res;
addr = res->start - win->offset;
if (resource_size(res) != SZ_64M) {
dev_err(dev, "DMA memory range is not 64MB\n"); return -EINVAL;
}
dev_dbg(dev, "DMA MEM BASE: %pa\n", &addr); /* * 4 PCI-to-AHB windows of 16 MB each, write the 8 high bits * into each byte of the PCI_AHBMEMBASE register.
*/
ahbmembase = ixp4xx_pci_addr_to_64mconf(addr); /* Commit AHB membase */
ixp4xx_writel(p, IXP4XX_PCI_AHBMEMBASE, ahbmembase);
} else {
dev_err(dev, "no DMA memory range defined\n");
}
return 0;
}
/* Only used to get context for abort handling */ staticstruct ixp4xx_pci *ixp4xx_pci_abort_singleton;
/* Make sure the Master Abort bit is reset */
ixp4xx_writel(p, IXP4XX_PCI_ISR, IXP4XX_PCI_ISR_PFE);
status |= PCI_STATUS_REC_MASTER_ABORT;
ret = ixp4xx_crp_write_config(p, PCI_STATUS, 2, status); if (ret)
dev_err(p->dev, "unable to clear abort status bit\n");
/* * If it was an imprecise abort, then we need to correct the * return address to be _after_ the instruction.
*/ if (fsr & (1 << 10)) {
dev_err(p->dev, "imprecise abort\n");
regs->ARM_pc += 4;
}
/* * Set up quirk for erratic behaviour in the 42x variant * when accessing config space.
*/ if (of_device_is_compatible(np, "intel,ixp42x-pci")) {
p->errata_hammer = true;
dev_info(dev, "activate hammering errata\n");
}
p->base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(p->base)) return PTR_ERR(p->base);
val = ixp4xx_readl(p, IXP4XX_PCI_CSR);
p->host_mode = !!(val & IXP4XX_PCI_CSR_HOST);
dev_info(dev, "controller is in %s mode\n",
p->host_mode ? "host" : "option");
/* Hook in our fault handler for PCI errors */
ixp4xx_pci_abort_singleton = p;
hook_fault_code(16+6, ixp4xx_pci_abort_handler, SIGBUS, 0, "imprecise external abort");
ret = ixp4xx_pci_parse_map_ranges(p); if (ret) return ret;
ret = ixp4xx_pci_parse_map_dma_ranges(p); if (ret) return ret;
/* This is only configured in host mode */ if (p->host_mode) {
addr = __pa(PAGE_OFFSET); /* This is a noop (0x00) but explains what is going on */
addr |= PCI_BASE_ADDRESS_SPACE_MEMORY;
for (i = 0; i < 4; i++) { /* Write this directly into the config space */
ret = ixp4xx_crp_write_config(p, basereg[i], 4, addr); if (ret)
dev_err(dev, "failed to set up PCI_BASE_ADDRESS_%d\n", i); else
dev_info(dev, "set PCI_BASE_ADDR_%d to %pa\n", i, &addr);
addr += SZ_16M;
}
/* * Enable CSR window at 64 MiB to allow PCI masters to continue * prefetching past the 64 MiB boundary, if all AHB to PCI * windows are consecutive.
*/
ret = ixp4xx_crp_write_config(p, PCI_BASE_ADDRESS_4, 4, addr); if (ret)
dev_err(dev, "failed to set up PCI_BASE_ADDRESS_4\n"); else
dev_info(dev, "set PCI_BASE_ADDR_4 to %pa\n", &addr);
/* * Put the IO memory window at the very end of physical memory * at 0xfffffc00. This is when the system is trying to access IO * memory over AHB.
*/
addr = 0xfffffc00;
addr |= PCI_BASE_ADDRESS_SPACE_IO;
ret = ixp4xx_crp_write_config(p, PCI_BASE_ADDRESS_5, 4, addr); if (ret)
dev_err(dev, "failed to set up PCI_BASE_ADDRESS_5\n"); else
dev_info(dev, "set PCI_BASE_ADDR_5 to %pa\n", &addr);
/* * Retry timeout to 0x80 * Transfer ready timeout to 0xff
*/
ret = ixp4xx_crp_write_config(p, IXP4XX_PCI_RTOTTO, 4,
0x000080ff); if (ret)
dev_err(dev, "failed to set up TRDY limit\n"); else
dev_info(dev, "set TRDY limit to 0x80ff\n");
}
/* * Set Initialize Complete in PCI Control Register: allow IXP4XX to * generate PCI configuration cycles. Specify that the AHB bus is * operating in big-endian mode. Set up byte lane swapping between * little-endian PCI and the big-endian AHB bus.
*/
val = IXP4XX_PCI_CSR_IC | IXP4XX_PCI_CSR_ABE; if (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN))
val |= (IXP4XX_PCI_CSR_PDS | IXP4XX_PCI_CSR_ADS);
ixp4xx_writel(p, IXP4XX_PCI_CSR, val);
ret = ixp4xx_crp_write_config(p, PCI_COMMAND, 2, PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY); if (ret)
dev_err(dev, "unable to initialize master and command memory\n"); else
dev_info(dev, "initialized as master\n");
/* * This driver needs to be a builtin module with suppressed bind * attributes since the probe() is initializing a hard exception * handler and this can only be done from __init-tagged code * sections. This module cannot be removed and inserted at all.
*/ staticstruct platform_driver ixp4xx_pci_driver = {
.driver = {
.name = "ixp4xx-pci",
.suppress_bind_attrs = true,
.of_match_table = ixp4xx_pci_of_match,
},
};
builtin_platform_driver_probe(ixp4xx_pci_driver, ixp4xx_pci_probe);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.