* [PATCH 1/2] of: address: Store number of bus flag cells rather than bool
@ 2023-10-26 13:53 Rob Herring
2023-10-26 13:53 ` [PATCH 2/2] of: address: Consolidate bus .map() functions Rob Herring
2023-10-26 14:15 ` [PATCH 1/2] of: address: Store number of bus flag cells rather than bool Herve Codina
0 siblings, 2 replies; 4+ messages in thread
From: Rob Herring @ 2023-10-26 13:53 UTC (permalink / raw)
To: Frank Rowand; +Cc: Herve Codina, devicetree, linux-kernel
It is more useful to know how many flags cells a bus has rather than
whether a bus has flags or not as ultimately the number of cells is the
information used. Replace 'has_flags' boolean with 'flag_cells' count.
Signed-off-by: Rob Herring <robh@kernel.org>
---
This series applies on top of Herve's[1].
Rob
[1] https://lore.kernel.org/all/20231017110221.189299-1-herve.codina@bootlin.com/
drivers/of/address.c | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)
diff --git a/drivers/of/address.c b/drivers/of/address.c
index d21a3b74ac56..997f431af165 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -45,7 +45,7 @@ struct of_bus {
u64 (*map)(__be32 *addr, const __be32 *range,
int na, int ns, int pna);
int (*translate)(__be32 *addr, u64 offset, int na);
- bool has_flags;
+ int flag_cells;
unsigned int (*get_flags)(const __be32 *addr);
};
@@ -370,7 +370,7 @@ static struct of_bus of_busses[] = {
.count_cells = of_bus_pci_count_cells,
.map = of_bus_pci_map,
.translate = of_bus_default_flags_translate,
- .has_flags = true,
+ .flag_cells = 1,
.get_flags = of_bus_pci_get_flags,
},
#endif /* CONFIG_PCI */
@@ -382,7 +382,7 @@ static struct of_bus of_busses[] = {
.count_cells = of_bus_isa_count_cells,
.map = of_bus_isa_map,
.translate = of_bus_default_flags_translate,
- .has_flags = true,
+ .flag_cells = 1,
.get_flags = of_bus_isa_get_flags,
},
/* Default with flags cell */
@@ -393,7 +393,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 */
@@ -826,7 +826,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;
@@ -836,10 +836,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)
--
2.42.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] of: address: Consolidate bus .map() functions
2023-10-26 13:53 [PATCH 1/2] of: address: Store number of bus flag cells rather than bool Rob Herring
@ 2023-10-26 13:53 ` Rob Herring
2023-10-26 14:24 ` Herve Codina
2023-10-26 14:15 ` [PATCH 1/2] of: address: Store number of bus flag cells rather than bool Herve Codina
1 sibling, 1 reply; 4+ messages in thread
From: Rob Herring @ 2023-10-26 13:53 UTC (permalink / raw)
To: Frank Rowand; +Cc: Herve Codina, devicetree, linux-kernel
The bus .map() functions vary only by checking the flag cells values
and skipping over any flag cells to read the addresses. Otherwise they
all do the same reading 'ranges' address and size and returning the
address's offset if it is within the 'ranges' entry.
Refactor all the .map() functions to pass in the flag cell size so that
each bus can check the bus specific flags and then call a common
function to do everything else.
Signed-off-by: Rob Herring <robh@kernel.org>
---
drivers/of/address.c | 54 +++++++++-----------------------------------
1 file changed, 11 insertions(+), 43 deletions(-)
diff --git a/drivers/of/address.c b/drivers/of/address.c
index 997f431af165..b59956310f66 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -43,7 +43,7 @@ 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);
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,16 +192,7 @@ 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);
}
#endif /* CONFIG_PCI */
@@ -319,24 +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;
+ return of_bus_default_map(addr, range, na, ns, pna, fna);
}
static unsigned int of_bus_isa_get_flags(const __be32 *addr)
@@ -486,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;
}
--
2.42.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] of: address: Store number of bus flag cells rather than bool
2023-10-26 13:53 [PATCH 1/2] of: address: Store number of bus flag cells rather than bool Rob Herring
2023-10-26 13:53 ` [PATCH 2/2] of: address: Consolidate bus .map() functions Rob Herring
@ 2023-10-26 14:15 ` Herve Codina
1 sibling, 0 replies; 4+ messages in thread
From: Herve Codina @ 2023-10-26 14:15 UTC (permalink / raw)
To: Rob Herring; +Cc: Frank Rowand, devicetree, linux-kernel
On Thu, 26 Oct 2023 08:53:58 -0500
Rob Herring <robh@kernel.org> wrote:
> It is more useful to know how many flags cells a bus has rather than
> whether a bus has flags or not as ultimately the number of cells is the
> information used. Replace 'has_flags' boolean with 'flag_cells' count.
>
> Signed-off-by: Rob Herring <robh@kernel.org>
> ---
> This series applies on top of Herve's[1].
Acked-by: Herve Codina <herve.codina@bootlin.com>
Best regards,
Hervé
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] of: address: Consolidate bus .map() functions
2023-10-26 13:53 ` [PATCH 2/2] of: address: Consolidate bus .map() functions Rob Herring
@ 2023-10-26 14:24 ` Herve Codina
0 siblings, 0 replies; 4+ messages in thread
From: Herve Codina @ 2023-10-26 14:24 UTC (permalink / raw)
To: Rob Herring; +Cc: Frank Rowand, devicetree, linux-kernel
Hi Rob,
On Thu, 26 Oct 2023 08:53:59 -0500
Rob Herring <robh@kernel.org> wrote:
> The bus .map() functions vary only by checking the flag cells values
> and skipping over any flag cells to read the addresses. Otherwise they
> all do the same reading 'ranges' address and size and returning the
> address's offset if it is within the 'ranges' entry.
>
> Refactor all the .map() functions to pass in the flag cell size so that
> each bus can check the bus specific flags and then call a common
> function to do everything else.
>
> Signed-off-by: Rob Herring <robh@kernel.org>
Acked-by: Herve Codina <herve.codina@bootlin.com>
Best regards,
Hervé
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-10-26 14:24 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-26 13:53 [PATCH 1/2] of: address: Store number of bus flag cells rather than bool Rob Herring
2023-10-26 13:53 ` [PATCH 2/2] of: address: Consolidate bus .map() functions Rob Herring
2023-10-26 14:24 ` Herve Codina
2023-10-26 14:15 ` [PATCH 1/2] of: address: Store number of bus flag cells rather than bool Herve Codina
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).