From bc8dfca64d07185304a5acfe87a039c8a6649a4c Mon Sep 17 00:00:00 2001 From: Nicolas Le Bayon Date: Wed, 17 May 2023 12:36:01 +0200 Subject: [PATCH] feat(fdt-wrappers): add function to read uint64 with default value MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds a new utility function fdt_read_uint64_default() to read a uint64 value with a default value, as it is already done for uint32. Signed-off-by: Nicolas Le Bayon Signed-off-by: Maxime Méré Change-Id: Ibc85e30c3e4dd4b5171bdec106f4e32eb78c579f --- common/fdt_wrappers.c | 15 ++++++++++++++- include/common/fdt_wrappers.h | 4 +++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/common/fdt_wrappers.c b/common/fdt_wrappers.c index 783b660ee..b213ffa47 100644 --- a/common/fdt_wrappers.c +++ b/common/fdt_wrappers.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2023, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2018-2024, Arm Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -88,6 +88,19 @@ int fdt_read_uint64(const void *dtb, int node, const char *prop_name, return 0; } +uint64_t fdt_read_uint64_default(const void *dtb, int node, + const char *prop_name, uint64_t dflt_value) +{ + uint64_t ret = dflt_value; + int err = fdt_read_uint64(dtb, node, prop_name, &ret); + + if (err < 0) { + return dflt_value; + } + + return ret; +} + /* * Read bytes from a given property of the given node. Any number of * bytes of the property can be read. The fdt pointer is updated. diff --git a/include/common/fdt_wrappers.h b/include/common/fdt_wrappers.h index abbf9764b..de08f1db5 100644 --- a/include/common/fdt_wrappers.h +++ b/include/common/fdt_wrappers.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2023, Arm Limited and Contributors. All rights reserved. + * Copyright (c) 2018-2024, Arm Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -21,6 +21,8 @@ uint32_t fdt_read_uint32_default(const void *dtb, int node, const char *prop_name, uint32_t dflt_value); int fdt_read_uint64(const void *dtb, int node, const char *prop_name, uint64_t *value); +uint64_t fdt_read_uint64_default(const void *dtb, int node, + const char *prop_name, uint64_t dflt_value); int fdt_read_uint32_array(const void *dtb, int node, const char *prop_name, unsigned int cells, uint32_t *value); int fdtw_read_string(const void *dtb, int node, const char *prop,