lkml.org 
[lkml]   [2020]   [Jul]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH 1/5] of_address: Add bus type match for pci ranges parser
On Mon, Jul 20, 2020 at 1:49 AM Jiaxun Yang <jiaxun.yang@flygoat.com> wrote:
>
> So the parser can be used to parse range property of different bus
> types, such as ISA bus.

Regular MMIO buses are actually already supported, but not ISA.

>
> As they're all using PCI-like method of range property, there is no need
> start a new parser.
>
> Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
> ---
> drivers/of/address.c | 15 +++++++++++----
> include/linux/of_address.h | 3 +++
> 2 files changed, 14 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/of/address.c b/drivers/of/address.c
> index 8eea3f6e29a4..250c91767648 100644
> --- a/drivers/of/address.c
> +++ b/drivers/of/address.c
> @@ -702,6 +702,10 @@ static int parser_init(struct of_pci_range_parser *parser,
> parser->ns = of_bus_n_size_cells(node);
> parser->dma = !strcmp(name, "dma-ranges");
>
> + parser->bus = of_match_bus(node);
> + if (!parser->bus)
> + return -ENOENT;

You'll hit BUG() before you get here, so you can assume success.

> +
> parser->range = of_get_property(node, name, &rlen);
> if (parser->range == NULL)
> return -ENOENT;
> @@ -732,6 +736,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 bus_na = 0;
>
> if (!range)
> return NULL;
> @@ -739,8 +744,10 @@ struct of_pci_range *of_pci_range_parser_one(struct of_pci_range_parser *parser,
> if (!parser->range || parser->range + np > parser->end)
> return NULL;
>
> - if (parser->na == 3)
> - range->flags = of_bus_pci_get_flags(parser->range);
> + parser->bus->count_cells(parser->node, &bus_na, NULL);
> +
> + if (parser->na == bus_na)
> + range->flags = parser->bus->get_flags(parser->range);

I think you can just unconditionally call this and drop the else. For
plain MMIO bus, we'd just return IORESOURCE_MEM, but I think the flags
are ignored in that case.

> else
> range->flags = 0;
>
> @@ -761,8 +768,8 @@ struct of_pci_range *of_pci_range_parser_one(struct of_pci_range_parser *parser,
> u32 flags = 0;
> u64 pci_addr, cpu_addr, size;
>
> - if (parser->na == 3)
> - flags = of_bus_pci_get_flags(parser->range);
> + if (parser->na == bus_na)

This too can be unconditional.

> + flags = parser->bus->get_flags(parser->range);
> pci_addr = of_read_number(parser->range, na);

Perhaps rename pci_addr to child_addr and cpu_addr to parent_addr.

> if (parser->dma)
> cpu_addr = of_translate_dma_address(parser->node,
> diff --git a/include/linux/of_address.h b/include/linux/of_address.h
> index 763022ed3456..3929b4637033 100644
> --- a/include/linux/of_address.h
> +++ b/include/linux/of_address.h
> @@ -6,8 +6,11 @@
> #include <linux/of.h>
> #include <linux/io.h>
>
> +struct of_bus;
> +
> struct of_pci_range_parser {
> struct device_node *node;
> + struct of_bus *bus;
> const __be32 *range;
> const __be32 *end;
> int na;
> --
> 2.28.0.rc1
>

\
 
 \ /
  Last update: 2020-07-21 02:22    [W:1.689 / U:0.412 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site