]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dm: core: Reduce code size with dev_of_offset()
authorSimon Glass <sjg@chromium.org>
Wed, 7 Sep 2022 02:27:12 +0000 (20:27 -0600)
committerTom Rini <trini@konsulko.com>
Thu, 29 Sep 2022 20:11:14 +0000 (16:11 -0400)
Update the function to mark it with the const attribute. Also avoid
calling it multiple times in the devfdt_get_addr_index() function.

Signed-off-by: Simon Glass <sjg@chromium.org>
drivers/core/fdtaddr.c
include/dm/device.h

index c3a50a2b0c1a4b38a6d109e218249b1ca2494d7b..91bcd1a2c21557e4c77a530f0492cb0f9c2c3e9d 100644 (file)
@@ -21,6 +21,8 @@ DECLARE_GLOBAL_DATA_PTR;
 fdt_addr_t devfdt_get_addr_index(const struct udevice *dev, int index)
 {
 #if CONFIG_IS_ENABLED(OF_REAL)
+       int offset = dev_of_offset(dev);
+       int parent = dev_of_offset(dev->parent);
        fdt_addr_t addr;
 
        if (CONFIG_IS_ENABLED(OF_TRANSLATE)) {
@@ -28,21 +30,19 @@ fdt_addr_t devfdt_get_addr_index(const struct udevice *dev, int index)
                int len = 0;
                int na, ns;
 
-               na = fdt_address_cells(gd->fdt_blob,
-                                      dev_of_offset(dev->parent));
+               na = fdt_address_cells(gd->fdt_blob, parent);
                if (na < 1) {
                        debug("bad #address-cells\n");
                        return FDT_ADDR_T_NONE;
                }
 
-               ns = fdt_size_cells(gd->fdt_blob, dev_of_offset(dev->parent));
+               ns = fdt_size_cells(gd->fdt_blob, parent);
                if (ns < 0) {
                        debug("bad #size-cells\n");
                        return FDT_ADDR_T_NONE;
                }
 
-               reg = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "reg",
-                                 &len);
+               reg = fdt_getprop(gd->fdt_blob, offset, "reg", &len);
                if (!reg || (len <= (index * sizeof(fdt32_t) * (na + ns)))) {
                        debug("Req index out of range\n");
                        return FDT_ADDR_T_NONE;
@@ -56,7 +56,7 @@ fdt_addr_t devfdt_get_addr_index(const struct udevice *dev, int index)
                         * bus setups.
                         */
                        addr = fdt_translate_address((void *)gd->fdt_blob,
-                                                    dev_of_offset(dev), reg);
+                                                    offset, reg);
                } else {
                        /* Non translatable if #size-cells == 0 */
                        addr = fdt_read_number(reg, na);
@@ -66,9 +66,9 @@ fdt_addr_t devfdt_get_addr_index(const struct udevice *dev, int index)
                 * Use the "simple" translate function for less complex
                 * bus setups.
                 */
-               addr = fdtdec_get_addr_size_auto_parent(gd->fdt_blob,
-                               dev_of_offset(dev->parent), dev_of_offset(dev),
-                               "reg", index, NULL, false);
+               addr = fdtdec_get_addr_size_auto_parent(gd->fdt_blob, parent,
+                                                       offset, "reg", index,
+                                                       NULL, false);
                if (CONFIG_IS_ENABLED(SIMPLE_BUS) && addr != FDT_ADDR_T_NONE) {
                        if (device_get_uclass_id(dev->parent) ==
                            UCLASS_SIMPLE_BUS)
index 12c6ba37ff37070ee5b2a0e05a6b0e972722419f..f3f953c9afcd4f370d5d3e5a677c21c61d4dea5b 100644 (file)
@@ -253,7 +253,7 @@ static inline void dev_bic_flags(struct udevice *dev, u32 bic)
  * @dev:       device to check
  * Return: reference of the device's DT node
  */
-static inline ofnode dev_ofnode(const struct udevice *dev)
+static inline __attribute_const__ ofnode dev_ofnode(const struct udevice *dev)
 {
 #if CONFIG_IS_ENABLED(OF_REAL)
        return dev->node_;
@@ -273,7 +273,7 @@ static inline ofnode dev_ofnode(const struct udevice *dev)
 #define dev_get_dma_offset(_dev)               0
 #endif
 
-static inline int dev_of_offset(const struct udevice *dev)
+static inline __attribute_const__ int dev_of_offset(const struct udevice *dev)
 {
 #if CONFIG_IS_ENABLED(OF_REAL)
        return ofnode_to_offset(dev_ofnode(dev));
@@ -282,7 +282,7 @@ static inline int dev_of_offset(const struct udevice *dev)
 #endif
 }
 
-static inline bool dev_has_ofnode(const struct udevice *dev)
+static inline __attribute_const__ bool dev_has_ofnode(const struct udevice *dev)
 {
 #if CONFIG_IS_ENABLED(OF_REAL)
        return ofnode_valid(dev_ofnode(dev));