1
0
Эх сурвалжийг харах

driver/fdt] add parse reg array, get address and size by index.

xieyangrun 2 жил өмнө
parent
commit
29c7278edc

+ 1 - 0
components/drivers/fdt/inc/dtb_node.h

@@ -329,6 +329,7 @@ struct dtb_node *dtb_node_get_parent(const struct dtb_node *node);
 const char *dtb_node_get_name(const struct dtb_node *node);
 struct dtb_node *dtb_node_get_by_phandle(uint32_t phandle);
 int dtb_node_read_size(const struct dtb_node *node, const char *propname);
+int dtb_node_get_addr_and_size_by_index(const struct dtb_node *node, int index, size_t *addr, size_t *size);
 size_t dtb_node_get_addr_index(const struct dtb_node *node, int index);
 size_t dtb_node_get_addr(const struct dtb_node *node);
 int dtb_node_stringlist_search(const struct dtb_node *node, const char *property,

+ 37 - 0
components/drivers/fdt/src/dtb_base.c

@@ -206,6 +206,43 @@ int dtb_node_read_size(const struct dtb_node *node, const char *propname)
     return -EINVAL;
 }
 
+int dtb_node_get_addr_and_size_by_index(const struct dtb_node *node, int index, size_t *addr, size_t *size)
+{
+    const uint32_t *prop;
+    int psize;
+    int onesize, na, ns;
+
+    na = dtb_node_n_addr_cells(node);
+	ns = dtb_node_n_size_cells(node);
+
+    prop = dtb_node_get_dtb_node_property_value(node, "reg", &psize);
+	if (prop == NULL)
+    {
+		return -1;
+    }
+
+	psize /= 4;
+	onesize = na + ns;
+
+    if (psize >= (index + 1) * onesize)
+    {
+        prop += index * onesize;
+
+        if (addr)
+        {
+            *addr = dtb_node_read_number(prop, na);
+        }
+        if (size)
+        {
+            *size = dtb_node_read_number(prop + na, ns);
+        }
+
+        return 0;
+    }
+
+    return -1;
+}
+
 size_t dtb_node_get_addr_index(const struct dtb_node *node, int index)
 {
     int na;