Commit e4ab08be authored by Rob Herring's avatar Rob Herring Committed by Michael Ellerman

powerpc/isa-bridge: Remove open coded "ranges" parsing

"ranges" is a standard property with common parsing functions. Users
shouldn't be implementing their own parsing of it. Reimplement the
ISA brige "ranges" parsing using the common ranges iterator functions.

The common routines are flexible enough to work on PCI and non-PCI to
ISA bridges, so refactor pci_process_ISA_OF_ranges() and
isa_bridge_init_non_pci() into a single implementation.
Signed-off-by: default avatarRob Herring <robh@kernel.org>
[mpe: Unsplit some strings and use pr_xxx()]
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/20230327223045.819852-1-robh@kernel.org
parent 2837dbce
...@@ -55,80 +55,49 @@ static void remap_isa_base(phys_addr_t pa, unsigned long size) ...@@ -55,80 +55,49 @@ static void remap_isa_base(phys_addr_t pa, unsigned long size)
} }
} }
static void pci_process_ISA_OF_ranges(struct device_node *isa_node, static int process_ISA_OF_ranges(struct device_node *isa_node,
unsigned long phb_io_base_phys) unsigned long phb_io_base_phys)
{ {
/* We should get some saner parsing here and remove these structs */
struct pci_address {
u32 a_hi;
u32 a_mid;
u32 a_lo;
};
struct isa_address {
u32 a_hi;
u32 a_lo;
};
struct isa_range {
struct isa_address isa_addr;
struct pci_address pci_addr;
unsigned int size;
};
const struct isa_range *range;
unsigned long pci_addr;
unsigned int isa_addr;
unsigned int size; unsigned int size;
int rlen = 0; struct of_range_parser parser;
struct of_range range;
range = of_get_property(isa_node, "ranges", &rlen); if (of_range_parser_init(&parser, isa_node))
if (range == NULL || (rlen < sizeof(struct isa_range)))
goto inval_range; goto inval_range;
/* From "ISA Binding to 1275" for_each_of_range(&parser, &range) {
* The ranges property is laid out as an array of elements, if ((range.flags & ISA_SPACE_MASK) != ISA_SPACE_IO)
* each of which comprises: continue;
* cells 0 - 1: an ISA address
* cells 2 - 4: a PCI address
* (size depending on dev->n_addr_cells)
* cell 5: the size of the range
*/
if ((range->isa_addr.a_hi & ISA_SPACE_MASK) != ISA_SPACE_IO) {
range++;
rlen -= sizeof(struct isa_range);
if (rlen < sizeof(struct isa_range))
goto inval_range;
}
if ((range->isa_addr.a_hi & ISA_SPACE_MASK) != ISA_SPACE_IO)
goto inval_range;
isa_addr = range->isa_addr.a_lo; if (range.cpu_addr == OF_BAD_ADDR) {
pci_addr = (unsigned long) range->pci_addr.a_mid << 32 | pr_err("ISA: Bad CPU mapping: %s\n", __func__);
range->pci_addr.a_lo; return -EINVAL;
}
/* Assume these are both zero. Note: We could fix that and /* We need page alignment */
* do a proper parsing instead ... oh well, that will do for if ((range.bus_addr & ~PAGE_MASK) || (range.cpu_addr & ~PAGE_MASK)) {
* now as nobody uses fancy mappings for ISA bridges pr_warn("ISA: bridge %pOF has non aligned IO range\n", isa_node);
*/ return -EINVAL;
if ((pci_addr != 0) || (isa_addr != 0)) { }
printk(KERN_ERR "unexpected isa to pci mapping: %s\n",
__func__);
return;
}
/* Align size and make sure it's cropped to 64K */ /* Align size and make sure it's cropped to 64K */
size = PAGE_ALIGN(range->size); size = PAGE_ALIGN(range.size);
if (size > 0x10000) if (size > 0x10000)
size = 0x10000; size = 0x10000;
remap_isa_base(phb_io_base_phys, size); if (!phb_io_base_phys)
return; phb_io_base_phys = range.cpu_addr;
remap_isa_base(phb_io_base_phys, size);
return 0;
}
inval_range: inval_range:
printk(KERN_ERR "no ISA IO ranges or unexpected isa range, " if (!phb_io_base_phys) {
"mapping 64k\n"); pr_err("no ISA IO ranges or unexpected isa range, mapping 64k\n");
remap_isa_base(phb_io_base_phys, 0x10000); remap_isa_base(phb_io_base_phys, 0x10000);
}
return 0;
} }
...@@ -170,7 +139,7 @@ void __init isa_bridge_find_early(struct pci_controller *hose) ...@@ -170,7 +139,7 @@ void __init isa_bridge_find_early(struct pci_controller *hose)
isa_bridge_devnode = np; isa_bridge_devnode = np;
/* Now parse the "ranges" property and setup the ISA mapping */ /* Now parse the "ranges" property and setup the ISA mapping */
pci_process_ISA_OF_ranges(np, hose->io_base_phys); process_ISA_OF_ranges(np, hose->io_base_phys);
/* Set the global ISA io base to indicate we have an ISA bridge */ /* Set the global ISA io base to indicate we have an ISA bridge */
isa_io_base = ISA_IO_BASE; isa_io_base = ISA_IO_BASE;
...@@ -186,75 +155,15 @@ void __init isa_bridge_find_early(struct pci_controller *hose) ...@@ -186,75 +155,15 @@ void __init isa_bridge_find_early(struct pci_controller *hose)
*/ */
void __init isa_bridge_init_non_pci(struct device_node *np) void __init isa_bridge_init_non_pci(struct device_node *np)
{ {
const __be32 *ranges, *pbasep = NULL; int ret;
int rlen, i, rs;
u32 na, ns, pna;
u64 cbase, pbase, size = 0;
/* If we already have an ISA bridge, bail off */ /* If we already have an ISA bridge, bail off */
if (isa_bridge_devnode != NULL) if (isa_bridge_devnode != NULL)
return; return;
pna = of_n_addr_cells(np); ret = process_ISA_OF_ranges(np, 0);
if (of_property_read_u32(np, "#address-cells", &na) || if (ret)
of_property_read_u32(np, "#size-cells", &ns)) {
pr_warn("ISA: Non-PCI bridge %pOF is missing address format\n",
np);
return;
}
/* Check it's a supported address format */
if (na != 2 || ns != 1) {
pr_warn("ISA: Non-PCI bridge %pOF has unsupported address format\n",
np);
return;
}
rs = na + ns + pna;
/* Grab the ranges property */
ranges = of_get_property(np, "ranges", &rlen);
if (ranges == NULL || rlen < rs) {
pr_warn("ISA: Non-PCI bridge %pOF has absent or invalid ranges\n",
np);
return;
}
/* Parse it. We are only looking for IO space */
for (i = 0; (i + rs - 1) < rlen; i += rs) {
if (be32_to_cpup(ranges + i) != 1)
continue;
cbase = be32_to_cpup(ranges + i + 1);
size = of_read_number(ranges + i + na + pna, ns);
pbasep = ranges + i + na;
break;
}
/* Got something ? */
if (!size || !pbasep) {
pr_warn("ISA: Non-PCI bridge %pOF has no usable IO range\n",
np);
return; return;
}
/* Align size and make sure it's cropped to 64K */
size = PAGE_ALIGN(size);
if (size > 0x10000)
size = 0x10000;
/* Map pbase */
pbase = of_translate_address(np, pbasep);
if (pbase == OF_BAD_ADDR) {
pr_warn("ISA: Non-PCI bridge %pOF failed to translate IO base\n",
np);
return;
}
/* We need page alignment */
if ((cbase & ~PAGE_MASK) || (pbase & ~PAGE_MASK)) {
pr_warn("ISA: Non-PCI bridge %pOF has non aligned IO range\n",
np);
return;
}
/* Got it */ /* Got it */
isa_bridge_devnode = np; isa_bridge_devnode = np;
...@@ -263,7 +172,6 @@ void __init isa_bridge_init_non_pci(struct device_node *np) ...@@ -263,7 +172,6 @@ void __init isa_bridge_init_non_pci(struct device_node *np)
* and map it * and map it
*/ */
isa_io_base = ISA_IO_BASE; isa_io_base = ISA_IO_BASE;
remap_isa_base(pbase, size);
pr_debug("ISA: Non-PCI bridge is %pOF\n", np); pr_debug("ISA: Non-PCI bridge is %pOF\n", np);
} }
...@@ -282,7 +190,7 @@ static void isa_bridge_find_late(struct pci_dev *pdev, ...@@ -282,7 +190,7 @@ static void isa_bridge_find_late(struct pci_dev *pdev,
isa_bridge_pcidev = pdev; isa_bridge_pcidev = pdev;
/* Now parse the "ranges" property and setup the ISA mapping */ /* Now parse the "ranges" property and setup the ISA mapping */
pci_process_ISA_OF_ranges(devnode, hose->io_base_phys); process_ISA_OF_ranges(devnode, hose->io_base_phys);
/* Set the global ISA io base to indicate we have an ISA bridge */ /* Set the global ISA io base to indicate we have an ISA bridge */
isa_io_base = ISA_IO_BASE; isa_io_base = ISA_IO_BASE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment