fdtdec: Add fdt_{addr, size}_unpack() helpers
authorThierry Reding <treding@nvidia.com>
Thu, 21 Mar 2019 18:10:00 +0000 (19:10 +0100)
committerSimon Glass <sjg@chromium.org>
Fri, 12 Apr 2019 02:10:50 +0000 (20:10 -0600)
These helpers can be used to unpack variables of type fdt_addr_t and
fdt_size_t into a pair of 32-bit variables. This is useful in cases
where such variables need to be written to properties (such as "reg")
of a device tree node where they need to be split into cells.

Signed-off-by: Thierry Reding <treding@nvidia.com>
include/fdtdec.h

index be34dca7560ad483e2c5c4dc359015fb97dd72a3..3f7538734a0a9402dce3c4e6050320da4ba89f8b 100644 (file)
  */
 typedef phys_addr_t fdt_addr_t;
 typedef phys_size_t fdt_size_t;
+
+static inline fdt32_t fdt_addr_unpack(fdt_addr_t addr, fdt32_t *upper)
+{
+       if (upper)
+#ifdef CONFIG_PHYS_64BIT
+               *upper = addr >> 32;
+#else
+               *upper = 0;
+#endif
+
+       return addr;
+}
+
+static inline fdt32_t fdt_size_unpack(fdt_size_t size, fdt32_t *upper)
+{
+       if (upper)
+#ifdef CONFIG_PHYS_64BIT
+               *upper = size >> 32;
+#else
+               *upper = 0;
+#endif
+
+       return size;
+}
+
 #ifdef CONFIG_PHYS_64BIT
 #define FDT_ADDR_T_NONE (-1U)
 #define fdt_addr_to_cpu(reg) be64_to_cpu(reg)