MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / ofw_parse_phandle_cells

Function ofw_parse_phandle_cells

components/drivers/ofw/base.c:1473–1547  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1471}
1472
1473static rt_err_t ofw_parse_phandle_cells(const struct rt_ofw_node *np, const char *list_name, const char *cells_name,
1474 int index, struct rt_ofw_cell_args *out_args)
1475{
1476 rt_err_t err = -RT_EEMPTY;
1477 rt_uint32_t value;
1478 rt_size_t count = 0;
1479 const fdt32_t *cell;
1480 struct rt_ofw_prop *prop;
1481
1482 /*
1483 * List:
1484 *
1485 * phandle1: node1 {
1486 * #list-cells = <2>;
1487 * };
1488 *
1489 * phandle2: node2 {
1490 * #list-cells = <1>;
1491 * };
1492 *
1493 * node3 {
1494 * list = <&phandle1 0xaa 0xbb>, <&phandle2 0xcc>;
1495 * };
1496 *
1497 * if call:
1498 * rt_ofw_parse_phandle_cells(node3, "list", "#list-cells", 0, &args):
1499 *
1500 * args.data = node1;
1501 * args.args_count = 2;
1502 * args.args[0] = 0xaa;
1503 * args.args[1] = 0xbb;
1504 *
1505 * rt_ofw_parse_phandle_cells(node3, "list", "#list-cells", 1, &args):
1506 *
1507 * args.data = node2;
1508 * args.args_count = 1;
1509 * args.args[0] = 0xcc;
1510 */
1511
1512 rt_ofw_foreach_prop_u32(np, list_name, prop, cell, value)
1513 {
1514 rt_uint32_t cells_count = 0;
1515 struct rt_ofw_node *phandle_np = rt_ofw_find_node_by_phandle((rt_phandle)value);
1516
1517 /* if phandle node is undefined, we assume that the cels_count is 0 */
1518 if (cells_name && phandle_np)
1519 {
1520 rt_ofw_prop_read_u32(phandle_np, cells_name, &cells_count);
1521 }
1522
1523 if (count++ == index)
1524 {
1525 for (int idx = 0; idx < cells_count; ++idx)
1526 {
1527 cell = rt_ofw_prop_next_u32(prop, cell, &value);
1528
1529 out_args->args[idx] = value;
1530 }

Callers 2

Calls 3

rt_ofw_prop_read_u32Function · 0.85
rt_ofw_prop_next_u32Function · 0.85

Tested by

no test coverage detected