mirror of
https://github.com/lkl/linux.git
synced 2025-12-19 16:13:19 +09:00
of/address: Add of_range_count() helper
Some users need a count of the number of ranges entries before iterating over the entries. Typically this is for allocating some data structure based on the size. Add a helper, of_range_count(), to get the count. The helper must be called with an struct of_range_parser initialized by of_range_parser_init(). Link: https://lore.kernel.org/r/20230328-dt-address-helpers-v1-4-e2456c3e77ab@kernel.org Signed-off-by: Rob Herring <robh@kernel.org>
This commit is contained in:
@@ -1014,7 +1014,7 @@ static void __init of_unittest_bus_ranges(void)
|
|||||||
struct of_range range;
|
struct of_range range;
|
||||||
struct of_range_parser parser;
|
struct of_range_parser parser;
|
||||||
struct resource res;
|
struct resource res;
|
||||||
int ret, i = 0;
|
int ret, count, i = 0;
|
||||||
|
|
||||||
np = of_find_node_by_path("/testcase-data/address-tests");
|
np = of_find_node_by_path("/testcase-data/address-tests");
|
||||||
if (!np) {
|
if (!np) {
|
||||||
@@ -1040,6 +1040,11 @@ static void __init of_unittest_bus_ranges(void)
|
|||||||
"of_range_to_resource wrong resource start address on node %pOF res=%pR\n",
|
"of_range_to_resource wrong resource start address on node %pOF res=%pR\n",
|
||||||
np, &res);
|
np, &res);
|
||||||
|
|
||||||
|
count = of_range_count(&parser);
|
||||||
|
unittest(count == 2,
|
||||||
|
"of_range_count wrong size on node %pOF count=%d\n",
|
||||||
|
np, count);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the "ranges" from the device tree
|
* Get the "ranges" from the device tree
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -35,6 +35,22 @@ struct of_pci_range {
|
|||||||
for (; of_pci_range_parser_one(parser, range);)
|
for (; of_pci_range_parser_one(parser, range);)
|
||||||
#define for_each_of_range for_each_of_pci_range
|
#define for_each_of_range for_each_of_pci_range
|
||||||
|
|
||||||
|
/*
|
||||||
|
* of_range_count - Get the number of "ranges" or "dma-ranges" entries
|
||||||
|
* @parser: Parser state initialized by of_range_parser_init()
|
||||||
|
*
|
||||||
|
* Returns the number of entries or 0 if none.
|
||||||
|
*
|
||||||
|
* Note that calling this within or after the for_each_of_range() iterator will
|
||||||
|
* be inaccurate giving the number of entries remaining.
|
||||||
|
*/
|
||||||
|
static inline int of_range_count(const struct of_range_parser *parser)
|
||||||
|
{
|
||||||
|
if (!parser || !parser->node || !parser->range || parser->range == parser->end)
|
||||||
|
return 0;
|
||||||
|
return (parser->end - parser->range) / (parser->na + parser->pna + parser->ns);
|
||||||
|
}
|
||||||
|
|
||||||
/* Translate a DMA address from device space to CPU space */
|
/* Translate a DMA address from device space to CPU space */
|
||||||
extern u64 of_translate_dma_address(struct device_node *dev,
|
extern u64 of_translate_dma_address(struct device_node *dev,
|
||||||
const __be32 *in_addr);
|
const __be32 *in_addr);
|
||||||
|
|||||||
Reference in New Issue
Block a user