[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Minios-devel] [UNIKRAFT RFC PATCH] plat/common:Add helper to simplify accessing fdt for arm
Wrap some reading ops on dtb like reading property and address conversion op to simplify acquiring device address for arm. Signed-off-by: Wei Chen <wei.chen@xxxxxxx> Signed-off-by: Jianyong Wu <jianyong.wu@xxxxxxx> --- plat/common/arm/fdt.c | 103 ++++++++++++++++++++++++++++++++++++++++++ plat/common/include/arm/fdt.h | 46 +++++++++++++++++++ plat/kvm/Makefile.uk | 1 + 3 files changed, 150 insertions(+) create mode 100644 plat/common/arm/fdt.c create mode 100644 plat/common/include/arm/fdt.h diff --git a/plat/common/arm/fdt.c b/plat/common/arm/fdt.c new file mode 100644 index 0000000..172f344 --- /dev/null +++ b/plat/common/arm/fdt.c @@ -0,0 +1,103 @@ +/* SPDX-License-Identifier: ISC */ +/* + * Authors: Wei Chen <Wei.Chen@xxxxxxx> + * Authors: Jianyong Wu <Jianyong.Wu@xxxxxxx> + * + * Copyright (c) 2018 Arm Ltd. + * + * Permission to use, copy, modify, and/or distribute this software + * for any purpose with or without fee is hereby granted, provided + * that the above copyright notice and this permission notice appear + * in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL + * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE + * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ +#include <libfdt.h> +#include <kvm/console.h> +#include <uk/assert.h> +#include <kvm-arm/mm.h> +#include <arm/cpu.h> +#include <arm/fdt.h> +#include <uk/arch/limits.h> + +void *_libkvmplat_dtb; + +/* + * uk_dtb_find_device find device offset in dtb by + * searching device list + */ +int uk_dtb_find_device(const char *device_list[], + uint32_t size) +{ + uint32_t idx; + int device = -1; + + for (idx = 0; + idx < size / sizeof(device_list[0]); + idx++) { + device = fdt_node_offset_by_compatible(_libkvmplat_dtb, -1, + device_list[idx]); + if (device >= 0) + break; + } + + return device; +} + +/* + * uk_dtb_read_reg read specified device address and + * size in reg region from dtb + */ +uint64_t uk_dtb_read_reg(int device, uint32_t index, + uint64_t *size) +{ + int prop_len, prop_min_len; + uint32_t naddr, nsize, term_size; + uint64_t addr; + fdt32_t *regs; + + UK_ASSERT(device != -1); + naddr = fdt_address_cells(_libkvmplat_dtb, device); + UK_ASSERT(naddr < FDT_MAX_NCELLS); + + nsize = fdt_size_cells(_libkvmplat_dtb, device); + UK_ASSERT(nsize < FDT_MAX_NCELLS); + + regs = fdt_getprop(_libkvmplat_dtb, device, "reg", &prop_len); + prop_min_len = (int)sizeof(fdt32_t) * (naddr + nsize); + UK_ASSERT(regs != NULL && prop_len >= prop_min_len); + + term_size = nsize + naddr; + index = index * term_size; + if(sizeof(fdt32_t) * (index + 1) > prop_len) + UK_CRASH("too large index\n"); + + addr = uk_dtb_read_number(regs + index, naddr); + + *size = uk_dtb_read_number(regs + index + naddr, nsize); + + return addr; +} + +/* this reads a number from a given dtb cell address */ +uint64_t uk_dtb_read_number(fdt32_t *regs, uint32_t size) +{ + uint64_t number = 0; + UK_ASSERT(size < 3 && size > 0); + + for(uint32_t i = 0; i < size; i++) + { + number <<= 32; + number |= fdt32_to_cpu(*regs); + regs++; + } + + return number; +} diff --git a/plat/common/include/arm/fdt.h b/plat/common/include/arm/fdt.h new file mode 100644 index 0000000..a958b6f --- /dev/null +++ b/plat/common/include/arm/fdt.h @@ -0,0 +1,46 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* + * Authors: Wei Chen <wei.chen@xxxxxxx> + * Authors: Jianyong Wu <Jianyong.Wu@xxxxxxx> + * + * Copyright (c) 2018, Arm Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY. + */ + +#ifndef __PLAT_CMN_ARM_FDT_H__ +#define __PLAT_CMN_ARM_FDT_H__ + +extern void *_libkvmplat_dtb; + +int uk_dtb_find_device(const char *device_list[], + uint32_t size); +uint64_t uk_dtb_read_reg(int device, uint32_t index, + uint64_t *size); +uint64_t uk_dtb_read_number(fdt32_t *regs, uint32_t size); +#endif /* __PLAT_CMN_ARM_FDT_H__ */ diff --git a/plat/kvm/Makefile.uk b/plat/kvm/Makefile.uk index 1f9c5dc..8e481b4 100644 --- a/plat/kvm/Makefile.uk +++ b/plat/kvm/Makefile.uk @@ -59,6 +59,7 @@ LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += $(UK_PLAT_COMMON_BASE)/arm/cache64.S|co LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += $(UK_PLAT_COMMON_BASE)/arm/psci_arm64.S|common LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += $(UK_PLAT_COMMON_BASE)/arm/time.c|common LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += $(UK_PLAT_COMMON_BASE)/arm/traps.c|common +LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += $(UK_PLAT_COMMON_BASE)/arm/fdt.c|common LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += $(LIBKVMPLAT_BASE)/arm/entry64.S LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += $(LIBKVMPLAT_BASE)/arm/exceptions.S LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += $(LIBKVMPLAT_BASE)/arm/pagetable.S -- 2.7.4 _______________________________________________ Minios-devel mailing list Minios-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/minios-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |