From: Rob Herring <robh@kernel.org>
To: devicetree@vger.kernel.org, Frank Rowand <frowand.list@gmail.com>
Cc: Michal Simek <monstr@monstr.eu>, Arnd Bergmann <arnd@arndb.de>,
Linus Walleij <linus.walleij@linaro.org>,
linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org,
Paul Mackerras <paulus@samba.org>,
Robin Murphy <robin.murphy@arm.com>,
Christoph Hellwig <hch@lst.de>
Subject: [PATCH 5/7] of/address: Rework of_pci_range parsing for non-PCI buses
Date: Fri, 14 Feb 2020 16:43:20 -0600 [thread overview]
Message-ID: <20200214224322.20030-6-robh@kernel.org> (raw)
In-Reply-To: <20200214224322.20030-1-robh@kernel.org>
The only PCI specific part of of_pci_range_parser_one() is the handling
of the 3rd address cell. Rework it to work on regular 1 and 2 cell
addresses.
Use defines and a union to avoid a treewide renaming of the parsing
helpers and struct.
Signed-off-by: Rob Herring <robh@kernel.org>
---
drivers/of/address.c | 33 +++++++++++++++++++++------------
include/linux/of_address.h | 12 +++++++++---
2 files changed, 30 insertions(+), 15 deletions(-)
diff --git a/drivers/of/address.c b/drivers/of/address.c
index 5d608d7c10d6..6d33f849f114 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -694,12 +694,12 @@ EXPORT_SYMBOL(of_get_address);
static int parser_init(struct of_pci_range_parser *parser,
struct device_node *node, const char *name)
{
- const int na = 3, ns = 2;
int rlen;
parser->node = node;
parser->pna = of_n_addr_cells(node);
- parser->np = parser->pna + na + ns;
+ parser->na = of_bus_n_addr_cells(node);
+ parser->ns = of_bus_n_size_cells(node);
parser->dma = !strcmp(name, "dma-ranges");
parser->range = of_get_property(node, name, &rlen);
@@ -724,20 +724,28 @@ int of_pci_dma_range_parser_init(struct of_pci_range_parser *parser,
return parser_init(parser, node, "dma-ranges");
}
EXPORT_SYMBOL_GPL(of_pci_dma_range_parser_init);
+#define of_dma_range_parser_init of_pci_dma_range_parser_init
struct of_pci_range *of_pci_range_parser_one(struct of_pci_range_parser *parser,
struct of_pci_range *range)
{
- const int na = 3, ns = 2;
+ int na = parser->na;
+ int ns = parser->ns;
+ int np = parser->pna + na + ns;
if (!range)
return NULL;
- if (!parser->range || parser->range + parser->np > parser->end)
+ if (!parser->range || parser->range + np > parser->end)
return NULL;
- range->flags = of_bus_pci_get_flags(parser->range);
- range->pci_addr = of_read_number(parser->range + 1, ns);
+ if (parser->na == 3)
+ range->flags = of_bus_pci_get_flags(parser->range);
+ else
+ range->flags = 0;
+
+ range->pci_addr = of_read_number(parser->range, na);
+
if (parser->dma)
range->cpu_addr = of_translate_dma_address(parser->node,
parser->range + na);
@@ -746,15 +754,16 @@ struct of_pci_range *of_pci_range_parser_one(struct of_pci_range_parser *parser,
parser->range + na);
range->size = of_read_number(parser->range + parser->pna + na, ns);
- parser->range += parser->np;
+ parser->range += np;
/* Now consume following elements while they are contiguous */
- while (parser->range + parser->np <= parser->end) {
- u32 flags;
+ while (parser->range + np <= parser->end) {
+ u32 flags = 0;
u64 pci_addr, cpu_addr, size;
- flags = of_bus_pci_get_flags(parser->range);
- pci_addr = of_read_number(parser->range + 1, ns);
+ if (parser->na == 3)
+ flags = of_bus_pci_get_flags(parser->range);
+ pci_addr = of_read_number(parser->range, na);
if (parser->dma)
cpu_addr = of_translate_dma_address(parser->node,
parser->range + na);
@@ -770,7 +779,7 @@ struct of_pci_range *of_pci_range_parser_one(struct of_pci_range_parser *parser,
break;
range->size += size;
- parser->range += parser->np;
+ parser->range += np;
}
return range;
diff --git a/include/linux/of_address.h b/include/linux/of_address.h
index 8d12bf18e80b..763022ed3456 100644
--- a/include/linux/of_address.h
+++ b/include/linux/of_address.h
@@ -10,20 +10,27 @@ struct of_pci_range_parser {
struct device_node *node;
const __be32 *range;
const __be32 *end;
- int np;
+ int na;
+ int ns;
int pna;
bool dma;
};
+#define of_range_parser of_pci_range_parser
struct of_pci_range {
- u64 pci_addr;
+ union {
+ u64 pci_addr;
+ u64 bus_addr;
+ };
u64 cpu_addr;
u64 size;
u32 flags;
};
+#define of_range of_pci_range
#define for_each_of_pci_range(parser, range) \
for (; of_pci_range_parser_one(parser, range);)
+#define for_each_of_range for_each_of_pci_range
/* Translate a DMA address from device space to CPU space */
extern u64 of_translate_dma_address(struct device_node *dev,
@@ -142,4 +149,3 @@ static inline int of_pci_range_to_resource(struct of_pci_range *range,
#endif /* CONFIG_OF_ADDRESS && CONFIG_PCI */
#endif /* __OF_ADDRESS_H */
-
--
2.20.1
next prev parent reply other threads:[~2020-02-14 22:54 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-14 22:43 [PATCH 0/7] of: Support multiple dma-ranges entries Rob Herring
2020-02-14 22:43 ` [PATCH 1/7] of/address: Move range parser code out of CONFIG_PCI Rob Herring
2020-02-14 22:43 ` [PATCH 2/7] microblaze: Drop using struct of_pci_range.pci_space field Rob Herring
2020-02-14 22:43 ` [PATCH 3/7] powerpc: " Rob Herring
2020-02-14 22:43 ` [PATCH 4/7] of: Drop " Rob Herring
2020-02-14 22:43 ` Rob Herring [this message]
2020-02-14 22:43 ` [PATCH 6/7] of/address: use range parser for of_dma_get_range Rob Herring
2020-02-14 22:43 ` [PATCH 7/7] of/address: Support multiple 'dma-ranges' entries Rob Herring
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200214224322.20030-6-robh@kernel.org \
--to=robh@kernel.org \
--cc=arnd@arndb.de \
--cc=devicetree@vger.kernel.org \
--cc=frowand.list@gmail.com \
--cc=hch@lst.de \
--cc=linus.walleij@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=monstr@monstr.eu \
--cc=paulus@samba.org \
--cc=robin.murphy@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).