summaryrefslogtreecommitdiffstats
path: root/drivers/of/address.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 17:35:05 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 17:39:31 +0000
commit85c675d0d09a45a135bddd15d7b385f8758c32fb (patch)
tree76267dbc9b9a130337be3640948fe397b04ac629 /drivers/of/address.c
parentAdding upstream version 6.6.15. (diff)
downloadlinux-85c675d0d09a45a135bddd15d7b385f8758c32fb.tar.xz
linux-85c675d0d09a45a135bddd15d7b385f8758c32fb.zip
Adding upstream version 6.7.7.upstream/6.7.7
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'drivers/of/address.c')
-rw-r--r--drivers/of/address.c81
1 files changed, 18 insertions, 63 deletions
diff --git a/drivers/of/address.c b/drivers/of/address.c
index 3219c51777..b59956310f 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -43,9 +43,9 @@ struct of_bus {
void (*count_cells)(struct device_node *child,
int *addrc, int *sizec);
u64 (*map)(__be32 *addr, const __be32 *range,
- int na, int ns, int pna);
+ int na, int ns, int pna, int fna);
int (*translate)(__be32 *addr, u64 offset, int na);
- bool has_flags;
+ int flag_cells;
unsigned int (*get_flags)(const __be32 *addr);
};
@@ -63,13 +63,13 @@ static void of_bus_default_count_cells(struct device_node *dev,
}
static u64 of_bus_default_map(__be32 *addr, const __be32 *range,
- int na, int ns, int pna)
+ int na, int ns, int pna, int fna)
{
u64 cp, s, da;
- cp = of_read_number(range, na);
+ cp = of_read_number(range + fna, na - fna);
s = of_read_number(range + na + pna, ns);
- da = of_read_number(addr, na);
+ da = of_read_number(addr + fna, na - fna);
pr_debug("default map, cp=%llx, s=%llx, da=%llx\n", cp, s, da);
@@ -101,24 +101,13 @@ static unsigned int of_bus_default_get_flags(const __be32 *addr)
}
static u64 of_bus_default_flags_map(__be32 *addr, const __be32 *range, int na,
- int ns, int pna)
+ int ns, int pna, int fna)
{
- u64 cp, s, da;
-
/* Check that flags match */
if (*addr != *range)
return OF_BAD_ADDR;
- /* Read address values, skipping high cell */
- cp = of_read_number(range + 1, na - 1);
- s = of_read_number(range + na + pna, ns);
- da = of_read_number(addr + 1, na - 1);
-
- pr_debug("default flags map, cp=%llx, s=%llx, da=%llx\n", cp, s, da);
-
- if (da < cp || da >= (cp + s))
- return OF_BAD_ADDR;
- return da - cp;
+ return of_bus_default_map(addr, range, na, ns, pna, fna);
}
static int of_bus_default_flags_translate(__be32 *addr, u64 offset, int na)
@@ -192,9 +181,8 @@ static void of_bus_pci_count_cells(struct device_node *np,
}
static u64 of_bus_pci_map(__be32 *addr, const __be32 *range, int na, int ns,
- int pna)
+ int pna, int fna)
{
- u64 cp, s, da;
unsigned int af, rf;
af = of_bus_pci_get_flags(addr);
@@ -204,22 +192,9 @@ static u64 of_bus_pci_map(__be32 *addr, const __be32 *range, int na, int ns,
if ((af ^ rf) & (IORESOURCE_MEM | IORESOURCE_IO))
return OF_BAD_ADDR;
- /* Read address values, skipping high cell */
- cp = of_read_number(range + 1, na - 1);
- s = of_read_number(range + na + pna, ns);
- da = of_read_number(addr + 1, na - 1);
-
- pr_debug("PCI map, cp=%llx, s=%llx, da=%llx\n", cp, s, da);
-
- if (da < cp || da >= (cp + s))
- return OF_BAD_ADDR;
- return da - cp;
+ return of_bus_default_map(addr, range, na, ns, pna, fna);
}
-static int of_bus_pci_translate(__be32 *addr, u64 offset, int na)
-{
- return of_bus_default_translate(addr + 1, offset, na - 1);
-}
#endif /* CONFIG_PCI */
/*
@@ -323,29 +298,13 @@ static void of_bus_isa_count_cells(struct device_node *child,
}
static u64 of_bus_isa_map(__be32 *addr, const __be32 *range, int na, int ns,
- int pna)
+ int pna, int fna)
{
- u64 cp, s, da;
-
/* Check address type match */
if ((addr[0] ^ range[0]) & cpu_to_be32(1))
return OF_BAD_ADDR;
- /* Read address values, skipping high cell */
- cp = of_read_number(range + 1, na - 1);
- s = of_read_number(range + na + pna, ns);
- da = of_read_number(addr + 1, na - 1);
-
- pr_debug("ISA map, cp=%llx, s=%llx, da=%llx\n", cp, s, da);
-
- if (da < cp || da >= (cp + s))
- return OF_BAD_ADDR;
- return da - cp;
-}
-
-static int of_bus_isa_translate(__be32 *addr, u64 offset, int na)
-{
- return of_bus_default_translate(addr + 1, offset, na - 1);
+ return of_bus_default_map(addr, range, na, ns, pna, fna);
}
static unsigned int of_bus_isa_get_flags(const __be32 *addr)
@@ -378,8 +337,8 @@ static struct of_bus of_busses[] = {
.match = of_bus_pci_match,
.count_cells = of_bus_pci_count_cells,
.map = of_bus_pci_map,
- .translate = of_bus_pci_translate,
- .has_flags = true,
+ .translate = of_bus_default_flags_translate,
+ .flag_cells = 1,
.get_flags = of_bus_pci_get_flags,
},
#endif /* CONFIG_PCI */
@@ -390,8 +349,8 @@ static struct of_bus of_busses[] = {
.match = of_bus_isa_match,
.count_cells = of_bus_isa_count_cells,
.map = of_bus_isa_map,
- .translate = of_bus_isa_translate,
- .has_flags = true,
+ .translate = of_bus_default_flags_translate,
+ .flag_cells = 1,
.get_flags = of_bus_isa_get_flags,
},
/* Default with flags cell */
@@ -402,7 +361,7 @@ static struct of_bus of_busses[] = {
.count_cells = of_bus_default_count_cells,
.map = of_bus_default_flags_map,
.translate = of_bus_default_flags_translate,
- .has_flags = true,
+ .flag_cells = 1,
.get_flags = of_bus_default_flags_get_flags,
},
/* Default */
@@ -495,7 +454,7 @@ static int of_translate_one(struct device_node *parent, struct of_bus *bus,
rlen /= 4;
rone = na + pna + ns;
for (; rlen >= rone; rlen -= rone, ranges += rone) {
- offset = bus->map(addr, ranges, na, ns, pna);
+ offset = bus->map(addr, ranges, na, ns, pna, bus->flag_cells);
if (offset != OF_BAD_ADDR)
break;
}
@@ -835,7 +794,7 @@ struct of_pci_range *of_pci_range_parser_one(struct of_pci_range_parser *parser,
int na = parser->na;
int ns = parser->ns;
int np = parser->pna + na + ns;
- int busflag_na = 0;
+ int busflag_na = parser->bus->flag_cells;
if (!range)
return NULL;
@@ -845,10 +804,6 @@ struct of_pci_range *of_pci_range_parser_one(struct of_pci_range_parser *parser,
range->flags = parser->bus->get_flags(parser->range);
- /* A extra cell for resource flags */
- if (parser->bus->has_flags)
- busflag_na = 1;
-
range->bus_addr = of_read_number(parser->range + busflag_na, na - busflag_na);
if (parser->dma)