]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dm: core: add non-translating version of ofnode_get_addr_size_index()
authorMarek Behún <marek.behun@nic.cz>
Wed, 26 May 2021 12:08:17 +0000 (14:08 +0200)
committerJagan Teki <jagan@amarulasolutions.com>
Thu, 24 Jun 2021 06:22:45 +0000 (11:52 +0530)
Add functions ofnode_get_addr_size_index_notrans(), which is a
non-translating version of ofnode_get_addr_size_index().

Some addresses are not meant to be translated, for example those of MTD
fixed-partitions.

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
Tested-by: Patrice Chotard <patrice.chotard@foss.st.com>
Reviewed-by: Jagan Teki <jagan@amarulasolutions.com>
drivers/core/ofnode.c
include/dm/ofnode.h
test/dm/ofnode.c

index 6c771e364fb78af3fd642039c17c8b9bc83442ba..dd34cf8ca3ef68164f99a49ebefa2ab66d316668 100644 (file)
@@ -299,7 +299,8 @@ ofnode ofnode_get_by_phandle(uint phandle)
        return node;
 }
 
-fdt_addr_t ofnode_get_addr_size_index(ofnode node, int index, fdt_size_t *size)
+static fdt_addr_t __ofnode_get_addr_size_index(ofnode node, int index,
+                                              fdt_size_t *size, bool translate)
 {
        int na, ns;
 
@@ -319,7 +320,7 @@ fdt_addr_t ofnode_get_addr_size_index(ofnode node, int index, fdt_size_t *size)
 
                ns = of_n_size_cells(ofnode_to_np(node));
 
-               if (IS_ENABLED(CONFIG_OF_TRANSLATE) && ns > 0) {
+               if (translate && IS_ENABLED(CONFIG_OF_TRANSLATE) && ns > 0) {
                        return of_translate_address(ofnode_to_np(node), prop_val);
                } else {
                        na = of_n_addr_cells(ofnode_to_np(node));
@@ -330,12 +331,24 @@ fdt_addr_t ofnode_get_addr_size_index(ofnode node, int index, fdt_size_t *size)
                ns = ofnode_read_simple_size_cells(ofnode_get_parent(node));
                return fdtdec_get_addr_size_fixed(gd->fdt_blob,
                                                  ofnode_to_offset(node), "reg",
-                                                 index, na, ns, size, true);
+                                                 index, na, ns, size,
+                                                 translate);
        }
 
        return FDT_ADDR_T_NONE;
 }
 
+fdt_addr_t ofnode_get_addr_size_index(ofnode node, int index, fdt_size_t *size)
+{
+       return __ofnode_get_addr_size_index(node, index, size, true);
+}
+
+fdt_addr_t ofnode_get_addr_size_index_notrans(ofnode node, int index,
+                                             fdt_size_t *size)
+{
+       return __ofnode_get_addr_size_index(node, index, size, false);
+}
+
 fdt_addr_t ofnode_get_addr_index(ofnode node, int index)
 {
        fdt_size_t size;
index 8a69fd87da71135076e918cfe38538c7e27b2e33..e3fccb506ea5423a24c48a8dc4b59425a57ed820 100644 (file)
@@ -489,6 +489,23 @@ int ofnode_read_size(ofnode node, const char *propname);
 phys_addr_t ofnode_get_addr_size_index(ofnode node, int index,
                                       fdt_size_t *size);
 
+/**
+ * ofnode_get_addr_size_index_notrans() - get an address/size from a node
+ *                                       based on index, without address
+ *                                       translation
+ *
+ * This reads the register address/size from a node based on index.
+ * The resulting address is not translated. Useful for example for on-disk
+ * addresses.
+ *
+ * @node: node to read from
+ * @index: Index of address to read (0 for first)
+ * @size: Pointer to size of the address
+ * @return address, or FDT_ADDR_T_NONE if not present or invalid
+ */
+phys_addr_t ofnode_get_addr_size_index_notrans(ofnode node, int index,
+                                              fdt_size_t *size);
+
 /**
  * ofnode_get_addr_index() - get an address from a node
  *
index e0b525eeb185eb819948e2f2ac1ff9529c9a79c4..9a69cf70c1e4fe71b9987973af26a1357ca827ae 100644 (file)
@@ -289,6 +289,11 @@ static int dm_test_ofnode_get_reg(struct unit_test_state *uts)
        ut_asserteq(FDT_ADDR_T_NONE, addr);
        ut_asserteq(FDT_SIZE_T_NONE, size);
 
+       node = ofnode_path("/translation-test@8000/noxlatebus@3,300/dev@42");
+       ut_assert(ofnode_valid(node));
+       addr = ofnode_get_addr_size_index_notrans(node, 0, &size);
+       ut_asserteq_64(0x42, addr);
+
        return 0;
 }
 DM_TEST(dm_test_ofnode_get_reg, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);