[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Minios-devel] [UNIKRAFT RFC PATCH] plat/common:Add helper to simplify accessing fdt for arm
Hi Simon, Any comments ? : ) > -----Original Message----- > From: Minios-devel <minios-devel-bounces@xxxxxxxxxxxxxxxxxxxx> On Behalf Of > Jianyong Wu > Sent: 2018年11月3日 14:58 > To: minios-devel@xxxxxxxxxxxxxxxxxxxx; simon.kuenzer@xxxxxxxxx > Cc: Kaly Xin (Arm Technology China) <Kaly.Xin@xxxxxxx>; nd <nd@xxxxxxx>; > Jianyong Wu (Arm Technology China) <Jianyong.Wu@xxxxxxx>; Wei Chen (Arm > Technology China) <Wei.Chen@xxxxxxx> > Subject: [Minios-devel] [UNIKRAFT RFC PATCH] plat/common:Add helper to > simplify accessing fdt for arm > > From: Jianyong Wu <Jianyong.Wu@xxxxxxx> > > 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 | 111 ++++++++++++++++++++++++++++++++++ > plat/common/include/arm/fdt.h | 52 ++++++++++++++++ > plat/kvm/Makefile.uk | 1 + > 3 files changed, 164 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..3ab5343 > --- /dev/null > +++ b/plat/common/arm/fdt.c > @@ -0,0 +1,111 @@ > +/* 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> > + > +/* > + * uk_dtb_find_device find device offset in dtb by > + * searching device list > + */ > +int uk_dtb_find_device(void *dtb, 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(dtb, -1, > + device_list[idx]); > + if (device >= 0) > + break; > + } > + > + return device; > +} > + > +/* > + * uk_dtb_read_region read cell size of device address > + * and its length in dtb by input device offset. > + */ > +uint32_t uk_dtb_read_region(void *dtb, int device, > + uint32_t *nsize, fdt32_t **regs) > +{ > + int prop_len, prop_min_len; > + uint32_t naddr; > + > + UK_ASSERT(device != -1); > + naddr = fdt_address_cells(dtb, device); > + UK_ASSERT(naddr < FDT_MAX_NCELLS); > + > + *nsize = fdt_size_cells(dtb, device); > + UK_ASSERT(*nsize < FDT_MAX_NCELLS); > + > + *regs = fdt_getprop(dtb, device, "reg", &prop_len); > + /* > + * The property must contain at least the start > + * address and size of distributor and cpu interface > + */ > + prop_min_len = (int)sizeof(fdt32_t) * (naddr + *nsize) * 2; > + UK_ASSERT(*regs != NULL && prop_len >= prop_min_len); > + return naddr; > +} > + > +/* > + * this read reg part in device property and output > + * address and size of term specified by index. > + */ > +uint64_t uk_dtb_read_term(fdt32_t *regs, uint32_t index, > + uint32_t naddr, uint32_t nsize, uint64_t *size) > +{ > + uint64_t addr, term_size; > + > + term_size = nsize + naddr; > + index = index * term_size; > + addr = uk_dtb_read_number(regs + index, naddr); > + > + *size = uk_dtb_read_number(regs + index + naddr, nsize); > + > + return addr; > +} > + > +/* this reads a number from 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..d3a704b > --- /dev/null > +++ b/plat/common/include/arm/fdt.h > @@ -0,0 +1,52 @@ > +/* 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; > +extern void *_libkvmplat_pagetable; > +extern void *_libkvmplat_heap_start; > +extern void *_libkvmplat_stack_top; > +extern void *_libkvmplat_mem_end; > + > +int uk_dtb_find_device(void *dtb, const char *device_list[], > + uint32_t size); > +uint32_t uk_dtb_read_region(void *dtb, int device, > + uint32_t *nsize, fdt32_t **regs); > +uint64_t uk_dtb_read_term(fdt32_t *regs, uint32_t index, > + uint32_t naddr, uint32_t nsize, 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.17.1 > > > _______________________________________________ > Minios-devel mailing list > Minios-devel@xxxxxxxxxxxxxxxxxxxx > https://lists.xenproject.org/mailman/listinfo/minios-devel _______________________________________________ Minios-devel mailing list Minios-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/minios-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |