Skip to content

Commit 98990d3

Browse files
committed
[OFW] io ranges use ptr array to storage without ofw data
ofw data is private data for every ofw node that the drivers of ofw node will use item. replace the ranges supported to a ptr array. the ptr array size is config by `RT_USING_OFW_BUS_RANGES_NUMBER` Signed-off-by: GuEe-GUI <[email protected]>
1 parent 1a15146 commit 98990d3

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

components/drivers/ofw/Kconfig

+6
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,9 @@ config RT_FDT_EARLYCON_MSG_SIZE
2020
int "Earlycon message buffer size (KB)"
2121
depends on RT_USING_OFW
2222
default 128
23+
24+
config RT_USING_OFW_BUS_RANGES_NUMBER
25+
int "Max bus ranges number"
26+
depends on RT_USING_OFW
27+
default 8 if ARCH_CPU_64BIT
28+
default 4

components/drivers/ofw/io.c

+25-3
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@
1313
#include <drivers/ofw.h>
1414
#include <drivers/ofw_io.h>
1515
#include <drivers/ofw_fdt.h>
16+
#include <drivers/misc.h>
1617

1718
#define DBG_TAG "rtdm.ofw"
1819
#define DBG_LVL DBG_INFO
1920
#include <rtdbg.h>
2021

2122
#include "ofw_internal.h"
2223

24+
static volatile rt_atomic_t _bus_ranges_idx = 0;
25+
static struct bus_ranges *_bus_ranges[RT_USING_OFW_BUS_RANGES_NUMBER] = {};
26+
2327
static int ofw_bus_addr_cells(struct rt_ofw_node *np)
2428
{
2529
int res = OFW_ROOT_NODE_ADDR_CELLS_DEFAULT;
@@ -245,6 +249,7 @@ int rt_ofw_get_address_array(struct rt_ofw_node *np, int nr, rt_uint64_t *out_re
245249

246250
static struct bus_ranges *ofw_bus_ranges(struct rt_ofw_node *np, struct rt_ofw_prop *prop)
247251
{
252+
int id;
248253
const fdt32_t *cell;
249254
struct bus_ranges *ranges = RT_NULL;
250255
int child_address_cells, child_size_cells, parent_address_cells, groups;
@@ -322,7 +327,12 @@ static struct bus_ranges *ofw_bus_ranges(struct rt_ofw_node *np, struct rt_ofw_p
322327
*child_size++ = rt_fdt_next_cell(&cell, child_size_cells);
323328
}
324329

325-
rt_ofw_data(np) = ranges;
330+
ranges->np = np;
331+
332+
id = (int)rt_atomic_add(&_bus_ranges_idx, 1);
333+
RT_ASSERT(id < RT_ARRAY_SIZE(_bus_ranges));
334+
335+
_bus_ranges[id] = ranges;
326336
} while (0);
327337

328338
return ranges;
@@ -341,7 +351,7 @@ rt_uint64_t rt_ofw_translate_address(struct rt_ofw_node *np, const char *range_t
341351
{
342352
rt_ssize_t len;
343353
struct rt_ofw_prop *prop;
344-
struct bus_ranges *ranges;
354+
struct bus_ranges *ranges = RT_NULL;
345355

346356
prop = rt_ofw_get_prop(np, range_type, &len);
347357

@@ -350,7 +360,19 @@ rt_uint64_t rt_ofw_translate_address(struct rt_ofw_node *np, const char *range_t
350360
continue;
351361
}
352362

353-
ranges = rt_ofw_data(np);
363+
for (int i = 0; i < RT_ARRAY_SIZE(_bus_ranges); ++i)
364+
{
365+
if (!_bus_ranges[i])
366+
{
367+
break;
368+
}
369+
370+
if (_bus_ranges[i]->np == np)
371+
{
372+
ranges = _bus_ranges[i];
373+
break;
374+
}
375+
}
354376

355377
if (!ranges)
356378
{

components/drivers/ofw/ofw_internal.h

+3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ struct alias_info
4949

5050
struct bus_ranges
5151
{
52+
rt_list_t list;
53+
5254
rt_size_t nr;
55+
struct rt_ofw_node *np;
5356

5457
rt_uint64_t *child_addr;
5558
rt_uint64_t *parent_addr;

0 commit comments

Comments
 (0)