kvm-unit-tests/arm: initial drop
Subsystems (4)
v4 cover kvm-unit-tests/arm: initial drop
This is a v4 of a series that introduces arm to kvm-unit-tests. First, it does some tidying up of the repo. Then, it adds support for device trees (libfdt), and for virtio-testdev[1]. Next, it adds the basic infrastructure for booting a test case (guest), and adds a first test case, a self-test to confirm setup was completed successfully. Finally, it further prepares the framework for more complicated tests by adding vector support, and extends the self-test to test that too.
This initial drop doesn't require kvmarm. qemu-system-arm is enough, but it must have mach-virt, and the virtio-testdev patch[1].
These patches (v4) are also available from a git repo here
https://github.com/rhdrjones/kvm-unit-tests/commits/arm/v4-initial-drop
The v3 patches are available for reference here
https://github.com/rhdrjones/kvm-unit-tests/commits/arm/v3-initial-drop
Major v3->v4 differences are noted in each patch that has some under the '---'. There are also some new patches since v3 in this series, and a few v3 patches were dropped.
Some more interesting v3->v4 changes are:
* rebased to "7505ea2: realmode: make performance test run..."
* generation of asm-offsets.h now done like Kbuild
* cleaner build in general (new asm dir, no libfdt changes)
* introduction of memregions
* introduction of spinlocks
* determination of nr_cpus on setup
* reworked devicetree.[ch] to cleanup api and better document
* a more general virtio_bind() implementation
* more code comments and commit messages
Thanks in advance for reviews!
[1] http://lists.nongnu.org/archive/html/qemu-devel/2013-12/msg00690.html
Andrew Jones (17):
remove unused files
makefile and run_tests tweaks
clean root dir of all x86-ness
add distclean target and gitignore more add 'make cscope' support
libfdt: Import libfdt source
libfdt: get libfdt to build
add support for Linux device trees
libcflat: add abort() and assert() Introduce asm-generic/*.h files
add minimal virtio support for devtree virtio-mmio Introduce virtio-testdev
libcflat: clean up libcflat.h and add string.h
printf: support field padding
arm: initial drop
arm: add useful headers from the Linux kernel
arm: vectors support
Christoffer Dall (2):
arm: Add spinlock implementation
arm: Add IO accessors to avoid register-writeback
.gitignore | 6 + Makefile | 55 +- README | 59 +- arm/cstart.S | 209 ++++++ arm/flat.lds | 23 + arm/run | 31 + arm/selftest.c | 207 ++++++ arm/unittests.cfg | 30 + config-i386.mak | 13 - config-ia64.mak | 7 - config-powerpc-440.mak | 15 - config-powerpc.mak | 39 -- config-x86-common.mak | 124 ---- config-x86_64.mak | 14 - config/asm-offsets.mak | 41 ++ config/config-arm.mak | 79 +++ config/config-i386.mak | 12 + config/config-x86-common.mak | 122 ++++ config/config-x86_64.mak | 13 + configure | 40 +- docs/testdev.txt | 13 + flat.lds | 21 - formats | 31 - iotable.c | 53 -- iotable.h | 40 -- kvmtrace.c | 706 -------------------- kvmtrace_format | 532 --------------- lib/argv.c | 6 + lib/arm/.gitignore | 1 + lib/arm/asm-offsets.c | 39 ++ lib/arm/asm/asm-offsets.h | 1 + lib/arm/asm/barrier.h | 18 + lib/arm/asm/cp15.h | 37 ++ lib/arm/asm/io.h | 81 +++ lib/arm/asm/processor.h | 40 ++ lib/arm/asm/ptrace.h | 100 +++ lib/arm/asm/setup.h | 39 ++ lib/arm/asm/spinlock.h | 11 + lib/arm/eabi_compat.c | 20 + lib/arm/io.c | 66 ++ lib/arm/processor.c | 115 ++++ lib/arm/setup.c | 142 ++++ lib/arm/spinlock.c | 28 + lib/asm-generic/io.h | 154 +++++ lib/asm-generic/spinlock.h | 4 + lib/devicetree.c | 289 ++++++++ lib/devicetree.h | 230 +++++++ lib/fwcfg.c | 58 -- lib/generated/.gitignore | 1 + lib/libcflat.h | 59 +- lib/libfdt/Makefile.libfdt | 10 + lib/libfdt/README | 4 + lib/libfdt/fdt.c | 250 +++++++ lib/libfdt/fdt.h | 111 ++++ lib/libfdt/fdt_empty_tree.c | 84 +++ lib/libfdt/fdt_ro.c | 573 ++++++++++++++++ lib/libfdt/fdt_rw.c | 492 ++++++++++++++ lib/libfdt/fdt_strerror.c | 96 +++ lib/libfdt/fdt_sw.c | 256 +++++++ lib/libfdt/fdt_wip.c | 118 ++++ lib/libfdt/libfdt.h | 1514 ++++++++++++++++++++++++++++++++++++++++++ lib/libfdt/libfdt_env.h | 111 ++++ lib/libfdt/libfdt_internal.h | 95 +++ lib/libfdt/version.lds | 60 ++ lib/panic.c | 13 - lib/powerpc/44x/map.c | 51 -- lib/powerpc/44x/timebase.S | 28 - lib/powerpc/44x/timebase.h | 25 - lib/powerpc/44x/tlbwe.S | 29 - lib/powerpc/io.c | 35 - lib/printf.c | 82 ++- lib/string.c | 54 ++ lib/string.h | 15 + lib/virtio-testdev.c | 137 ++++ lib/virtio-testdev.h | 18 + lib/virtio.c | 166 +++++ lib/virtio.h | 89 +++ main-ppc.c | 383 ----------- powerpc/44x/tlbsx.S | 33 - powerpc/44x/tlbwe.S | 27 - powerpc/44x/tlbwe_16KB.S | 35 - powerpc/44x/tlbwe_hole.S | 27 - powerpc/cstart.S | 38 -- powerpc/exit.c | 23 - powerpc/helloworld.c | 27 - powerpc/io.S | 32 - powerpc/spin.S | 4 - powerpc/sprg.S | 7 - run_tests.sh | 22 +- testdev.txt | 14 - x86-run | 41 -- x86/README | 59 +- x86/flat.lds | 21 + x86/print.h | 19 - x86/run | 41 ++ x86/run-kvm-unit-tests | 6 - 96 files changed, 6782 insertions(+), 2667 deletions(-) create mode 100644 arm/cstart.S create mode 100644 arm/flat.lds create mode 100755 arm/run create mode 100644 arm/selftest.c create mode 100644 arm/unittests.cfg delete mode 100644 config-i386.mak delete mode 100644 config-ia64.mak delete mode 100644 config-powerpc-440.mak delete mode 100644 config-powerpc.mak delete mode 100644 config-x86-common.mak delete mode 100644 config-x86_64.mak create mode 100644 config/asm-offsets.mak create mode 100644 config/config-arm.mak create mode 100644 config/config-i386.mak create mode 100644 config/config-x86-common.mak create mode 100644 config/config-x86_64.mak create mode 100644 docs/testdev.txt delete mode 100644 flat.lds delete mode 100644 formats delete mode 100644 iotable.c delete mode 100644 iotable.h delete mode 100644 kvmtrace.c delete mode 100755 kvmtrace_format create mode 100644 lib/arm/.gitignore create mode 100644 lib/arm/asm-offsets.c create mode 100644 lib/arm/asm/asm-offsets.h create mode 100644 lib/arm/asm/barrier.h create mode 100644 lib/arm/asm/cp15.h create mode 100644 lib/arm/asm/io.h create mode 100644 lib/arm/asm/processor.h create mode 100644 lib/arm/asm/ptrace.h create mode 100644 lib/arm/asm/setup.h create mode 100644 lib/arm/asm/spinlock.h create mode 100644 lib/arm/eabi_compat.c create mode 100644 lib/arm/io.c create mode 100644 lib/arm/processor.c create mode 100644 lib/arm/setup.c create mode 100644 lib/arm/spinlock.c create mode 100644 lib/asm-generic/io.h create mode 100644 lib/asm-generic/spinlock.h create mode 100644 lib/devicetree.c create mode 100644 lib/devicetree.h delete mode 100644 lib/fwcfg.c create mode 100644 lib/generated/.gitignore create mode 100644 lib/libfdt/Makefile.libfdt create mode 100644 lib/libfdt/README create mode 100644 lib/libfdt/fdt.c create mode 100644 lib/libfdt/fdt.h create mode 100644 lib/libfdt/fdt_empty_tree.c create mode 100644 lib/libfdt/fdt_ro.c create mode 100644 lib/libfdt/fdt_rw.c create mode 100644 lib/libfdt/fdt_strerror.c create mode 100644 lib/libfdt/fdt_sw.c create mode 100644 lib/libfdt/fdt_wip.c create mode 100644 lib/libfdt/libfdt.h create mode 100644 lib/libfdt/libfdt_env.h create mode 100644 lib/libfdt/libfdt_internal.h create mode 100644 lib/libfdt/version.lds delete mode 100644 lib/panic.c delete mode 100644 lib/powerpc/44x/map.c delete mode 100644 lib/powerpc/44x/timebase.S delete mode 100644 lib/powerpc/44x/timebase.h delete mode 100644 lib/powerpc/44x/tlbwe.S delete mode 100644 lib/powerpc/io.c create mode 100644 lib/string.h create mode 100644 lib/virtio-testdev.c create mode 100644 lib/virtio-testdev.h create mode 100644 lib/virtio.c create mode 100644 lib/virtio.h delete mode 100644 main-ppc.c delete mode 100644 powerpc/44x/tlbsx.S delete mode 100644 powerpc/44x/tlbwe.S delete mode 100644 powerpc/44x/tlbwe_16KB.S delete mode 100644 powerpc/44x/tlbwe_hole.S delete mode 100644 powerpc/cstart.S delete mode 100644 powerpc/exit.c delete mode 100644 powerpc/helloworld.c delete mode 100644 powerpc/io.S delete mode 100644 powerpc/spin.S delete mode 100644 powerpc/sprg.S delete mode 100644 testdev.txt delete mode 100755 x86-run create mode 100644 x86/flat.lds delete mode 100644 x86/print.h create mode 100755 x86/run delete mode 100644 x86/run-kvm-unit-tests
Signature · 1 line
1.8.1.4
PATCH v4 1/19 remove unused files
There are several unused files, primarily because powerpc is an unused arch. The exceptions are config-ia64.mak, which is also an unused arch file, lib/fwcfg.c, lib/panic.c, x86/print.h and x86/run-kvm-unit-tests, which are just unused. Remove them all in order to tidy things up.
--- Makefile | 8 +- config-ia64.mak | 7 - config-powerpc-440.mak | 15 - config-powerpc.mak | 39 --- formats | 31 -- iotable.c | 53 ---- iotable.h | 40 --- kvmtrace.c | 706 --------------------------------------------- kvmtrace_format | 532 ---------------------------------- lib/fwcfg.c | 58 ---- lib/libcflat.h | 1 - lib/panic.c | 13 - lib/powerpc/44x/map.c | 51 ---- lib/powerpc/44x/timebase.S | 28 -- lib/powerpc/44x/timebase.h | 25 -- lib/powerpc/44x/tlbwe.S | 29 -- lib/powerpc/io.c | 35 --- main-ppc.c | 383 ------------------------ powerpc/44x/tlbsx.S | 33 --- powerpc/44x/tlbwe.S | 27 -- powerpc/44x/tlbwe_16KB.S | 35 --- powerpc/44x/tlbwe_hole.S | 27 -- powerpc/cstart.S | 38 --- powerpc/exit.c | 23 -- powerpc/helloworld.c | 27 -- powerpc/io.S | 32 -- powerpc/spin.S | 4 - powerpc/sprg.S | 7 - x86/print.h | 19 -- x86/run-kvm-unit-tests | 6 - 30 files changed, 1 insertion(+), 2331 deletions(-) delete mode 100644 config-ia64.mak delete mode 100644 config-powerpc-440.mak delete mode 100644 config-powerpc.mak delete mode 100644 formats delete mode 100644 iotable.c delete mode 100644 iotable.h delete mode 100644 kvmtrace.c delete mode 100755 kvmtrace_format delete mode 100644 lib/fwcfg.c delete mode 100644 lib/panic.c delete mode 100644 lib/powerpc/44x/map.c delete mode 100644 lib/powerpc/44x/timebase.S delete mode 100644 lib/powerpc/44x/timebase.h delete mode 100644 lib/powerpc/44x/tlbwe.S delete mode 100644 lib/powerpc/io.c delete mode 100644 main-ppc.c delete mode 100644 powerpc/44x/tlbsx.S delete mode 100644 powerpc/44x/tlbwe.S delete mode 100644 powerpc/44x/tlbwe_16KB.S delete mode 100644 powerpc/44x/tlbwe_hole.S delete mode 100644 powerpc/cstart.S delete mode 100644 powerpc/exit.c delete mode 100644 powerpc/helloworld.c delete mode 100644 powerpc/io.S delete mode 100644 powerpc/spin.S delete mode 100644 powerpc/sprg.S delete mode 100644 x86/print.h delete mode 100644 x86/run-kvm-unit-tests
Makefile +1 -7
@@ -12,7 +12,6 @@ libgcc := $(shell $(CC) --print-libgcc-file-name) libcflat := lib/libcflat.a cflatobjs := \ - lib/panic.o \ lib/printf.o \ lib/string.o \ lib/report.o
@@ -40,11 +39,6 @@ autodepend-flags = -MMD -MF $(dir $*).$(notdir $*).d LDFLAGS += $(CFLAGS) LDFLAGS += -pthread -lrt -kvmtrace_objs= kvmtrace.o - -kvmtrace: $(kvmtrace_objs) - $(CC) $(LDFLAGS) $^ -o $@ - $(libcflat): $(cflatobjs) $(AR) rcs $@ $^
@@ -58,4 +52,4 @@ install: install $(tests_and_config) $(DESTDIR) clean: arch_clean - $(RM) kvmtrace *.o *.a .*.d $(libcflat) $(cflatobjs) + $(RM) *.o *.a .*.d $(libcflat) $(cflatobjs)
config-ia64.mak deleted +0 -7
@@ -1,7 +0,0 @@ -bits = 64 -CFLAGS += -m64 -CFLAGS += -D__ia64__ -CFLAGS += -I../include/ia64 - -all: -
config-powerpc-440.mak deleted +0 -15
@@ -1,15 +0,0 @@ - - -# for some reason binutils hates tlbsx unless we say we're 405 :( -CFLAGS += -Wa,-m405 -I lib/powerpc/44x - -cflatobjs += \ - lib/powerpc/44x/map.o \ - lib/powerpc/44x/tlbwe.o \ - lib/powerpc/44x/timebase.o - -simpletests += \ - powerpc/44x/tlbsx.bin \ - powerpc/44x/tlbwe_16KB.bin \ - powerpc/44x/tlbwe_hole.bin \ - powerpc/44x/tlbwe.bin
config-powerpc.mak deleted +0 -39
@@ -1,39 +0,0 @@ -CFLAGS += -I../include/powerpc -CFLAGS += -Wa,-mregnames -I lib -CFLAGS += -ffreestanding - -cstart := powerpc/cstart.o - -cflatobjs += \ - lib/powerpc/io.o - -$(libcflat): LDFLAGS += -nostdlib - -# these tests do not use libcflat -simpletests := \ - powerpc/spin.bin \ - powerpc/io.bin \ - powerpc/sprg.bin - -# theses tests use cstart.o, libcflat, and libgcc -tests := \ - powerpc/exit.bin \ - powerpc/helloworld.bin - -include config-powerpc-$(PROCESSOR).mak - - -all: kvmtrace kvmctl $(libcflat) $(simpletests) $(tests) - -$(simpletests): %.bin: %.o - $(CC) -nostdlib $^ -Wl,-T,flat.lds -o $@ - -$(tests): %.bin: $(cstart) %.o $(libcflat) - $(CC) -nostdlib $^ $(libgcc) -Wl,-T,flat.lds -o $@ - -kvmctl_objs = main-ppc.o iotable.o ../libkvm/libkvm.a - -arch_clean: - $(RM) $(simpletests) $(tests) $(cstart) - $(RM) $(patsubst %.bin, %.elf, $(simpletests) $(tests)) - $(RM) $(patsubst %.bin, %.o, $(simpletests) $(tests))
formats deleted +0 -31
@@ -1,31 +0,0 @@ -0x00000000 %(ts)d (+%(relts)12d) unknown (0x%(event)016x) vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ 0x%(1)08x 0x%(2)08x 0x%(3)08x 0x%(4)08x 0x%(5)08x ] - -0x00010001 %(ts)d (+%(relts)12d) VMENTRY vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x -0x00010002 %(ts)d (+%(relts)12d) VMEXIT vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ exitcode = 0x%(1)08x, rip = 0x%(3)08x %(2)08x ] -0x00020001 %(ts)d (+%(relts)12d) PAGE_FAULT vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ errorcode = 0x%(1)08x, virt = 0x%(3)08x %(2)08x ] -0x00020002 %(ts)d (+%(relts)12d) INJ_VIRQ vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ vector = 0x%(1)02x ] -0x00020003 %(ts)d (+%(relts)12d) REDELIVER_EVT vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ vector = 0x%(1)02x ] -0x00020004 %(ts)d (+%(relts)12d) PEND_INTR vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ vector = 0x%(1)02x ] -0x00020005 %(ts)d (+%(relts)12d) IO_READ vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ port = 0x%(1)04x, size = %(2)d ] -0x00020006 %(ts)d (+%(relts)12d) IO_WRITE vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ port = 0x%(1)04x, size = %(2)d ] -0x00020007 %(ts)d (+%(relts)12d) CR_READ vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ CR# = %(1)d, value = 0x%(3)08x %(2)08x ] -0x00020008 %(ts)d (+%(relts)12d) CR_WRITE vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ CR# = %(1)d, value = 0x%(3)08x %(2)08x ] -0x00020009 %(ts)d (+%(relts)12d) DR_READ vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ DR# = %(1)d, value = 0x%(2)08x ] -0x0002000A %(ts)d (+%(relts)12d) DR_WRITE vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ DR# = %(1)d, value = 0x%(2)08x ] -0x0002000B %(ts)d (+%(relts)12d) MSR_READ vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ MSR# = 0x%(1)08x, data = 0x%(3)08x %(2)08x ] -0x0002000C %(ts)d (+%(relts)12d) MSR_WRITE vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ MSR# = 0x%(1)08x, data = 0x%(3)08x %(2)08x ] -0x0002000D %(ts)d (+%(relts)12d) CPUID vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ func = 0x%(1)08x, eax = 0x%(2)08x, ebx = 0x%(3)08x, ecx = 0x%(4)08x edx = 0x%(5)08x] -0x0002000E %(ts)d (+%(relts)12d) INTR vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ vector = 0x%(1)02x ] -0x0002000F %(ts)d (+%(relts)12d) NMI vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x -0x00020010 %(ts)d (+%(relts)12d) VMMCALL vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ func = 0x%(1)08x ] -0x00020011 %(ts)d (+%(relts)12d) HLT vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x -0x00020012 %(ts)d (+%(relts)12d) CLTS vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x -0x00020013 %(ts)d (+%(relts)12d) LMSW vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ value = 0x%(1)08x ] -0x00020014 %(ts)d (+%(relts)12d) APIC_ACCESS vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ offset = 0x%(1)08x ] -0x00020015 %(ts)d (+%(relts)12d) TDP_FAULT vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ errorcode = 0x%(1)08x, virt = 0x%(3)08x %(2)08x ] -# ppc: tlb traces -0x00020016 GTLB_WRITE vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ index = 0x%(1)08x, tid = 0x%(2)08x, word1=0x%(3)08x, word2=0x%(4)08x, word3=0x%(5)08x ] -0x00020017 STLB_WRITE vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ index = 0x%(1)08x, tid = 0x%(2)08x, word1=0x%(3)08x, word2=0x%(4)08x, word3=0x%(5)08x ] -0x00020018 STLB_INVAL vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ index = 0x%(1)08x, tid = 0x%(2)08x, word1=0x%(3)08x, word2=0x%(4)08x, word3=0x%(5)08x ] -# ppc: instruction emulation - this type is handled more complex in kvmtrace_format, but listed to show the eventid and transported data -#0x00020019 %(ts)d (+%(relts)12d) PPC_INSTR vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ instr = 0x%(1)08x, pc = 0x%(2)08x, emul = 0x%(3)08x, nsec = %(4)08d ]
iotable.c deleted +0 -53
53 lines not on this page · raw message
iotable.h deleted +0 -40
@@ -1,40 +0,0 @@ -/* -* Kernel-based Virtual Machine test driver -* -* This test driver provides a simple way of testing kvm, without a full -* device model. -* -* Copyright (C) 2006 Qumranet -* -* Authors: -* -* Avi Kivity <[email protected]> -* Yaniv Kamay <[email protected]> -* -* This work is licensed under the GNU LGPL license, version 2. -*/ - -#include <stdint.h> - -#define MAX_IO_TABLE 50 - -typedef int (io_table_handler_t )(void *,int ,int ,uint64_t ,uint64_t *); - -struct io_table_entry -{ -uint64_t start; -uint64_t end; -io_table_handler_t *handler; -void *opaque; -}; - -struct io_table -{ -int nr_entries; -struct io_table_entry entries[MAX_IO_TABLE ]; -}; - -struct io_table_entry *io_table_lookup (struct io_table *io_table, -uint64_t addr); -int io_table_register (struct io_table *io_table,uint64_t start,uint64_t size, -io_table_handler_t *handler,void *opaque);
kvmtrace.c deleted +0 -706
706 lines not on this page · raw message
kvmtrace_format deleted +0 -532
532 lines not on this page · raw message
lib/fwcfg.c deleted +0 -58
58 lines not on this page · raw message
lib/libcflat.h +0 -1
@@ -38,7 +38,6 @@ typedef _Bool bool;#define false 0extern void exit (int code); -extern void panic (char *fmt, ...);extern unsigned long strlen (const char *buf);extern char *strcat (char *dest,const char *src);
lib/panic.c deleted +0 -13
@@ -1,13 +0,0 @@ -#include "libcflat.h" - -void panic (char *fmt, ...) -{ -va_list va; -char buf[2000 ]; - -va_start (va, fmt); -vsnprintf (buf,sizeof (buf), fmt, va); -va_end (va); -puts (buf); -exit (-1 ); -}
lib/powerpc/44x/map.c deleted +0 -51
51 lines not on this page · raw message
lib/powerpc/44x/timebase.S deleted +0 -28
@@ -1,28 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Copyright IBM Corp. 2008 - * - * Authors: Hollis Blanchard <[email protected]> - */ - -/* unsigned long long mftb(void); */ -.global mftb -mftb: - mftbu r5 - mftbl r4 - mftbu r3 - cmpw r3, r5 - bne mftb - blr
lib/powerpc/44x/timebase.h deleted +0 -25
@@ -1,25 +0,0 @@ -/* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License, version 2, as -* published by the Free Software Foundation. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -* -* Copyright IBM Corp. 2008 -* -* Authors: Hollis Blanchard <[email protected]> -*/ - -#ifndef __TIMEBASE_H__ -#define __TIMEBASE_H__ - -unsigned long long mftb (void ); - -#endif /* __TIMEBASE_H__ */
lib/powerpc/44x/tlbwe.S deleted +0 -29
@@ -1,29 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Copyright IBM Corp. 2008 - * - * Authors: Hollis Blanchard <[email protected]> - */ - -#define SPRN_MMUCR 0x3b2 - -/* tlbwe(uint index, uint8_t tid, uint word0, uint word1, uint word2) */ -.global tlbwe -tlbwe: - mtspr SPRN_MMUCR, r4 - tlbwe r5, r3, 0 - tlbwe r6, r3, 1 - tlbwe r7, r3, 2 - blr
lib/powerpc/io.c deleted +0 -35
@@ -1,35 +0,0 @@ -/* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License, version 2, as -* published by the Free Software Foundation. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -* -* Copyright IBM Corp. 2008 -* -* Authors: Hollis Blanchard <[email protected]> -*/ - -#include "libcflat.h" - -#define BASE 0xf0000000 -#define _putc ((volatile char *)(BASE)) -#define _exit ((volatile char *)(BASE+1)) - -void puts (const char *s) -{ -while (*s !='\0' ) - *_putc = *s++; -} - -void exit (int code) -{ - *_exit = code; -}
main-ppc.c deleted +0 -383
383 lines not on this page · raw message
powerpc/44x/tlbsx.S deleted +0 -33
@@ -1,33 +0,0 @@ -#define SPRN_MMUCR 0x3b2 - -#define TLBWORD0 0x10000210 -#define TLBWORD1 0x10000000 -#define TLBWORD2 0x00000003 - -.global _start -_start: - li r4, 0 - mtspr SPRN_MMUCR, r4 - - li r3, 23 - - lis r4, TLBWORD0@h - ori r4, r4, TLBWORD0@l - tlbwe r4, r3, 0 - - lis r4, TLBWORD1@h - ori r4, r4, TLBWORD1@l - tlbwe r4, r3, 1 - - lis r4, TLBWORD2@h - ori r4, r4, TLBWORD2@l - tlbwe r4, r3, 2 - - lis r4, 0x1000 - tlbsx r5, r4, r0 - cmpwi r5, 23 - beq good - trap - -good: - b .
powerpc/44x/tlbwe.S deleted +0 -27
@@ -1,27 +0,0 @@ -#define SPRN_MMUCR 0x3b2 - -/* Create a mapping at 4MB */ -#define TLBWORD0 0x00400210 -#define TLBWORD1 0x00400000 -#define TLBWORD2 0x00000003 - -.global _start -_start: - li r4, 0 - mtspr SPRN_MMUCR, r4 - - li r3, 23 - - lis r4, TLBWORD0@h - ori r4, r4, TLBWORD0@l - tlbwe r4, r3, 0 - - lis r4, TLBWORD1@h - ori r4, r4, TLBWORD1@l - tlbwe r4, r3, 1 - - lis r4, TLBWORD2@h - ori r4, r4, TLBWORD2@l - tlbwe r4, r3, 2 - - b .
powerpc/44x/tlbwe_16KB.S deleted +0 -35
@@ -1,35 +0,0 @@ -#define SPRN_MMUCR 0x3b2 - -/* 16KB mapping at 4MB */ -#define TLBWORD0 0x00400220 -#define TLBWORD1 0x00400000 -#define TLBWORD2 0x00000003 - -.global _start -_start: - li r4, 0 - mtspr SPRN_MMUCR, r4 - - li r3, 5 - - lis r4, TLBWORD0@h - ori r4, r4, TLBWORD0@l - tlbwe r4, r3, 0 - - lis r4, TLBWORD1@h - ori r4, r4, TLBWORD1@l - tlbwe r4, r3, 1 - - lis r4, TLBWORD2@h - ori r4, r4, TLBWORD2@l - tlbwe r4, r3, 2 - - /* load from 4MB */ - lis r3, 0x0040 - lwz r4, 0(r3) - - /* load from 4MB+8KB */ - ori r3, r3, 0x2000 - lwz r4, 0(r3) - - b .
powerpc/44x/tlbwe_hole.S deleted +0 -27
@@ -1,27 +0,0 @@ -#define SPRN_MMUCR 0x3b2 - -/* Try to map real address 1GB. */ -#define TLBWORD0 0x40000210 -#define TLBWORD1 0x40000000 -#define TLBWORD2 0x00000003 - -.global _start -_start: - li r4, 0 - mtspr SPRN_MMUCR, r4 - - li r3, 23 - - lis r4, TLBWORD0@h - ori r4, r4, TLBWORD0@l - tlbwe r4, r3, 0 - - lis r4, TLBWORD1@h - ori r4, r4, TLBWORD1@l - tlbwe r4, r3, 1 - - lis r4, TLBWORD2@h - ori r4, r4, TLBWORD2@l - tlbwe r4, r3, 2 - - b .
powerpc/cstart.S deleted +0 -38
@@ -1,38 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, as - * published by the Free Software Foundation; - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Copyright IBM Corp. 2008 - * - * Authors: Hollis Blanchard <[email protected]> - */ - -#define OUTPUT_VADDR 0xf0000000 -#define OUTPUT_PADDR 0xf0000000 - -.globl _start -_start: - /* In the future we might need to assign a stack and zero BSS here. */ - - /* Map the debug page 1:1. */ - lis r3, OUTPUT_VADDR@h - ori r3, r3, OUTPUT_VADDR@l - lis r4, OUTPUT_PADDR@h - ori r4, r4, OUTPUT_PADDR@l - bl map - - /* Call main() and pass return code to exit(). */ - bl main - bl exit - - b .
powerpc/exit.c deleted +0 -23
@@ -1,23 +0,0 @@ -/* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License, version 2, as -* published by the Free Software Foundation; -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -* -* Copyright IBM Corp. 2008 -* -* Authors: Hollis Blanchard <[email protected]> -*/ - -int main (void ) -{ -return 1 ; -}
powerpc/helloworld.c deleted +0 -27
@@ -1,27 +0,0 @@ -/* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License, version 2, as -* published by the Free Software Foundation; -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -* -* Copyright IBM Corp. 2008 -* -* Authors: Deepa Srinivasan <[email protected]> -*/ - -#include "libcflat.h" - -int main () -{ -printf ("Hello World\n" ); - -return 1 ; -}
powerpc/io.S deleted +0 -32
@@ -1,32 +0,0 @@ -#define SPRN_MMUCR 0x3b2 - -#define TLBWORD0 0xf0000210 -#define TLBWORD1 0xf0000000 -#define TLBWORD2 0x00000003 - -.global _start -_start: - li r4, 0 - mtspr SPRN_MMUCR, r4 - - li r3, 2 - - lis r4, TLBWORD0@h - ori r4, r4, TLBWORD0@l - tlbwe r4, r3, 0 - - lis r4, TLBWORD1@h - ori r4, r4, TLBWORD1@l - tlbwe r4, r3, 1 - - lis r4, TLBWORD2@h - ori r4, r4, TLBWORD2@l - tlbwe r4, r3, 2 - - lis r3, 0xf000 - lis r4, 0x1234 - ori r4, r4, 0x5678 - stb r4, 0(r3) - lbz r5, 0(r3) - - b .
powerpc/spin.S deleted +0 -4
@@ -1,4 +0,0 @@ - -.global _start -_start: - b .
powerpc/sprg.S deleted +0 -7
@@ -1,7 +0,0 @@ - -.global _start -_start: - li r3, 42 - mtsprg 0, r3 - mfsprg r4, 0 - b .
x86/print.h deleted +0 -19
@@ -1,19 +0,0 @@ -#ifndef PRINT_H -#define PRINT_H - -.macro PRINT text - -.data - -333: .asciz "\text\n" - -.previous - - push %rdi - lea 333b, %rdi - call print - pop %rdi - -.endm - -#endif
x86/run-kvm-unit-tests deleted +0 -6
@@ -1,6 +0,0 @@ -#!/usr/bin/python - -import sys, os, os.path - -prog = sys.argv[0] -dir = os.path.dirname(prog)
Signature · 1 line
1.8.1.4
PATCH v4 2/19 makefile and run_tests tweaks
In reply to Andrew Jones- remove a redundant '-display none'
- remove a redundant -g from CFLAGS
- remove a useless -I../include/x86 from CFLAGS
- remove lib autodep files on make clean
---
v4: no change other than rebase
v3: reword run_tests.sh help text [Christoffer Dall]
--- Makefile | 11 ++++++----- config-x86-common.mak | 16 +++++++--------- run_tests.sh | 6 +++--- 3 files changed, 16 insertions(+), 17 deletions(-)
Makefile +6 -5
@@ -6,16 +6,16 @@ DESTDIR := $(PREFIX)/share/qemu/tests .PHONY: arch_clean clean #make sure env CFLAGS variable is not used -CFLAGS = -g +CFLAGS = libgcc := $(shell $(CC) --print-libgcc-file-name) libcflat := lib/libcflat.a cflatobjs := \ + lib/argv.o \ lib/printf.o \ lib/string.o \ lib/report.o -cflatobjs += lib/argv.o #include architecure specific make rules include config-$(ARCH).mak
@@ -26,8 +26,9 @@ include config-$(ARCH).mak cc-option = $(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null \ > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;) -CFLAGS += -O1 -CFLAGS += $(autodepend-flags) -g -fomit-frame-pointer -Wall +CFLAGS += -g +CFLAGS += $(autodepend-flags) -Wall +CFLAGS += $(call cc-option, -fomit-frame-pointer, "") CFLAGS += $(call cc-option, -fno-stack-protector, "") CFLAGS += $(call cc-option, -fno-stack-protector-all, "") CFLAGS += -I.
@@ -52,4 +53,4 @@ install: install $(tests_and_config) $(DESTDIR) clean: arch_clean - $(RM) *.o *.a .*.d $(libcflat) $(cflatobjs) + $(RM) *.o *.a .*.d lib/.*.d $(libcflat) $(cflatobjs)
config-x86-common.mak +7 -9
@@ -1,13 +1,9 @@ #This is a make file with common rules for both x86 & x86-64 -CFLAGS += -I../include/x86 - all: test_cases -cflatobjs += \ - lib/x86/io.o \ - lib/x86/smp.o - +cflatobjs += lib/x86/io.o +cflatobjs += lib/x86/smp.o cflatobjs += lib/x86/vm.o cflatobjs += lib/x86/fwcfg.o cflatobjs += lib/x86/apic.o
@@ -20,15 +16,17 @@ $(libcflat): LDFLAGS += -nostdlib $(libcflat): CFLAGS += -ffreestanding -I lib CFLAGS += -m$(bits) +CFLAGS += -O1 libgcc := $(shell $(CC) -m$(bits) --print-libgcc-file-name) FLATLIBS = lib/libcflat.a $(libgcc) %.elf: %.o $(FLATLIBS) flat.lds - $(CC) $(CFLAGS) -nostdlib -o $@ -Wl,-T,flat.lds $(filter %.o, $^) $(FLATLIBS) + $(CC) $(CFLAGS) -nostdlib -o $@ -Wl,-T,flat.lds \ + $(filter %.o, $^) $(FLATLIBS) %.flat: %.elf - objcopy -O elf32-i386 $^ $@ + $(OBJCOPY) -O elf32-i386 $^ $@ tests-common = $(TEST_DIR)/vmexit.flat $(TEST_DIR)/tsc.flat \ $(TEST_DIR)/smptest.flat $(TEST_DIR)/port80.flat \
@@ -107,7 +105,7 @@ $(TEST_DIR)/debug.elf: $(cstart.o) $(TEST_DIR)/debug.o arch_clean: $(RM) $(TEST_DIR)/*.o $(TEST_DIR)/*.flat $(TEST_DIR)/*.elf \ - $(TEST_DIR)/.*.d $(TEST_DIR)/lib/.*.d $(TEST_DIR)/lib/*.o + $(TEST_DIR)/.*.d lib/x86/.*.d api/%.o: CFLAGS += -m32
run_tests.sh +3 -3
@@ -27,7 +27,7 @@ function run() return fi - cmdline="./x86-run $kernel -smp $smp -display none $opts" + cmdline="./x86-run $kernel -smp $smp $opts" if [ $verbose != 0 ]; then echo $cmdline fi
@@ -92,8 +92,8 @@ Usage: $0 [-g group] [-h] [-v] -h: Output this help text -v: Enables verbose mode -Set the environment variable QEMU=/path/to/qemu-system-x86_64 to allow the -internally used x86-run to pick up the right qemu binary. +Set the environment variable QEMU=/path/to/qemu-system-x86_64 to +specify the appropriate qemu binary for x86-run. EOF }
Signature · 1 line
1.8.1.4
PATCH v4 3/19 clean root dir of all x86-ness
In reply to Andrew JonesRemove all references to x86 from the root dir (except from in configure). Also remove references from the root dir README by moving that documentation to the x86/README, and touch up the READMEs at the same time.
---
v4: some more doc touch-ups, check for config.mak in run_tests.sh
--- Makefile | 7 ++- README | 59 ++++++++------------- config-i386.mak | 13 ----- config-x86-common.mak | 122 ------------------------------------------- config-x86_64.mak | 14 ----- config/config-i386.mak | 12 +++++ config/config-x86-common.mak | 122 +++++++++++++++++++++++++++++++++++++++++++ config/config-x86_64.mak | 13 +++++ configure | 17 ++++++ docs/testdev.txt | 13 +++++ flat.lds | 21 -------- run_tests.sh | 22 ++++---- testdev.txt | 14 ----- x86-run | 41 --------------- x86/README | 59 ++++++++++++++++----- x86/flat.lds | 21 ++++++++ x86/run | 41 +++++++++++++++ 17 files changed, 322 insertions(+), 289 deletions(-) delete mode 100644 config-i386.mak delete mode 100644 config-x86-common.mak delete mode 100644 config-x86_64.mak create mode 100644 config/config-i386.mak create mode 100644 config/config-x86-common.mak create mode 100644 config/config-x86_64.mak create mode 100644 docs/testdev.txt delete mode 100644 flat.lds delete mode 100644 testdev.txt delete mode 100755 x86-run create mode 100644 x86/flat.lds create mode 100755 x86/run
Makefile +3 -4
@@ -18,7 +18,7 @@ cflatobjs := \ lib/report.o #include architecure specific make rules -include config-$(ARCH).mak +include config/config-$(ARCH).mak # cc-option # Usage: OP_CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0)
@@ -31,7 +31,6 @@ CFLAGS += $(autodepend-flags) -Wall CFLAGS += $(call cc-option, -fomit-frame-pointer, "") CFLAGS += $(call cc-option, -fno-stack-protector, "") CFLAGS += $(call cc-option, -fno-stack-protector-all, "") -CFLAGS += -I. CXXFLAGS += $(CFLAGS)
@@ -46,11 +45,11 @@ $(libcflat): $(cflatobjs) %.o: %.S $(CC) $(CFLAGS) -c -nostdlib -o $@ $< --include .*.d */.*.d */*/.*.d +-include */.*.d */*/.*.d install: mkdir -p $(DESTDIR) install $(tests_and_config) $(DESTDIR) clean: arch_clean - $(RM) *.o *.a .*.d lib/.*.d $(libcflat) $(cflatobjs) + $(RM) lib/.*.d $(libcflat) $(cflatobjs)
README +23 -36
63 lines not on this page · raw message
config-i386.mak deleted +0 -13
@@ -1,13 +0,0 @@ -TEST_DIR=x86 -cstart.o = $(TEST_DIR)/cstart.o -bits = 32 -ldarch = elf32-i386 -CFLAGS += -D__i386__ -CFLAGS += -I $(KERNELDIR)/include - -tests = $(TEST_DIR)/taskswitch.flat $(TEST_DIR)/taskswitch2.flat - -include config-x86-common.mak - -$(TEST_DIR)/taskswitch.elf: $(cstart.o) $(TEST_DIR)/taskswitch.o -$(TEST_DIR)/taskswitch2.elf: $(cstart.o) $(TEST_DIR)/taskswitch2.o
config-x86-common.mak deleted +0 -122
122 lines not on this page · raw message
config-x86_64.mak deleted +0 -14
@@ -1,14 +0,0 @@ -TEST_DIR=x86 -cstart.o = $(TEST_DIR)/cstart64.o -bits = 64 -ldarch = elf64-x86-64 -CFLAGS += -D__x86_64__ - -tests = $(TEST_DIR)/access.flat $(TEST_DIR)/apic.flat \ - $(TEST_DIR)/emulator.flat $(TEST_DIR)/idt_test.flat \ - $(TEST_DIR)/xsave.flat $(TEST_DIR)/rmap_chain.flat \ - $(TEST_DIR)/pcid.flat $(TEST_DIR)/debug.flat -tests += $(TEST_DIR)/svm.flat -tests += $(TEST_DIR)/vmx.flat - -include config-x86-common.mak
config/config-i386.mak new file +12 -0
@@ -0,0 +1,12 @@ +cstart.o = $(TEST_DIR)/cstart.o +bits = 32 +ldarch = elf32-i386 +CFLAGS += -D__i386__ +CFLAGS += -I $(KERNELDIR)/include + +tests = $(TEST_DIR)/taskswitch.flat $(TEST_DIR)/taskswitch2.flat + +include config/config-x86-common.mak + +$(TEST_DIR)/taskswitch.elf: $(cstart.o) $(TEST_DIR)/taskswitch.o +$(TEST_DIR)/taskswitch2.elf: $(cstart.o) $(TEST_DIR)/taskswitch2.o
config/config-x86-common.mak new file +122 -0
122 lines not on this page · raw message
config/config-x86_64.mak new file +13 -0
@@ -0,0 +1,13 @@ +cstart.o = $(TEST_DIR)/cstart64.o +bits = 64 +ldarch = elf64-x86-64 +CFLAGS += -D__x86_64__ + +tests = $(TEST_DIR)/access.flat $(TEST_DIR)/apic.flat \ + $(TEST_DIR)/emulator.flat $(TEST_DIR)/idt_test.flat \ + $(TEST_DIR)/xsave.flat $(TEST_DIR)/rmap_chain.flat \ + $(TEST_DIR)/pcid.flat $(TEST_DIR)/debug.flat +tests += $(TEST_DIR)/svm.flat +tests += $(TEST_DIR)/vmx.flat + +include config/config-x86-common.mak
configure +17 -0
@@ -15,6 +15,7 @@ usage() { Usage: $0 [options] Options include: + --test-dir=DIR the main directory for tests ($arch) --arch=ARCH architecture to compile for ($arch) --cross-prefix=PREFIX cross compiler prefix --cc=CC c compiler to use ($cc)
@@ -33,6 +34,9 @@ while [[ "$1" = -* ]]; do opt="${opt%%=*}" fi case "$opt" in + --test-dir) + testdir="$arg" + ;; --prefix) prefix="$arg" ;;
@@ -62,6 +66,18 @@ while [[ "$1" = -* ]]; do ;; esac done +if [ -z "$testdir" -a \( "$arch" = "i386" -o "$arch" = "x86_64" \) ]; then + testdir=x86 +elif [ -z "$testdir" ]; then + testdir=$arch +fi +if [ ! -d $testdir ]; then + echo "$testdir does not exist!" + exit 1 +fi +if [ -f $testdir/run ]; then + ln -fs $testdir/run $testdir-run +fi # check for dependent 32 bit libraries cat << EOF > lib_test.c
@@ -89,4 +105,5 @@ LD=$cross_prefix$ld OBJCOPY=$cross_prefix$objcopy AR=$cross_prefix$ar API=$api +TEST_DIR=$testdir EOF
docs/testdev.txt new file +13 -0
@@ -0,0 +1,13 @@ +This file describes the virtual device of qemu for supporting this +test suite. + +Services supplied by the testdev device: + serial output: write-only, on io port 0xf1 + exit process: write-only, on io port 0xf4, value used as + the exit code + ram size: read-only, on io port 0xd1, 4 bytes' size + irq line setting: write-only, on io ports 0x2000 - 0x2018, + value to set/clear + simple io: read/write, on io port 0xe0, 1/2/4 bytes + +The test device uses a char device for actual output.
flat.lds deleted +0 -21
@@ -1,21 +0,0 @@ -SECTIONS -{ - . = 4M + SIZEOF_HEADERS; - stext = .; - .text : { *(.init) *(.text) *(.text.*) } - . = ALIGN(4K); - .data : { - *(.data) - exception_table_start = .; - *(.data.ex) - exception_table_end = .; - } - . = ALIGN(16); - .rodata : { *(.rodata) } - . = ALIGN(16); - .bss : { *(.bss) } - . = ALIGN(4K); - edata = .; -} - -ENTRY(start)
run_tests.sh +12 -10
@@ -1,8 +1,13 @@ #!/bin/bash -testroot=x86 -config=$testroot/unittests.cfg -qemu=${qemu:-qemu-system-x86_64} +if [ ! -f config.mak ]; then + echo "run ./configure && make first. See ./configure -h" + exit +fi +source config.mak + +config=$TEST_DIR/unittests.cfg +qemu=${QEMU:-qemu-system-$ARCH} verbose=0 function run()
@@ -27,7 +32,7 @@ function run() return fi - cmdline="./x86-run $kernel -smp $smp $opts" + cmdline="./$TEST_DIR-run $kernel -smp $smp $opts" if [ $verbose != 0 ]; then echo $cmdline fi
@@ -65,7 +70,7 @@ function run_all() groups="" arch="" elif [[ $line =~ ^file\ *=\ *(.*)$ ]]; then - kernel=$testroot/${BASH_REMATCH[1]} + kernel=$TEST_DIR/${BASH_REMATCH[1]} elif [[ $line =~ ^smp\ *=\ *(.*)$ ]]; then smp=${BASH_REMATCH[1]} elif [[ $line =~ ^extra_params\ *=\ *(.*)$ ]]; then
@@ -92,15 +97,12 @@ Usage: $0 [-g group] [-h] [-v] -h: Output this help text -v: Enables verbose mode -Set the environment variable QEMU=/path/to/qemu-system-x86_64 to -specify the appropriate qemu binary for x86-run. +Set the environment variable QEMU=/path/to/qemu-system-ARCH to +specify the appropriate qemu binary for ARCH-run. EOF } -# As it happens, config.mak is valid shell script code, too :-) -source config.mak - echo > test.log while getopts "g:hv" opt; do case $opt in
testdev.txt deleted +0 -14
@@ -1,14 +0,0 @@ -This file describes the virtual device of qemu for supporting this test suite. - -Services supplied by the testdev device: - -serial output: write only, on io port 0xf1 -exit process: write only, on io port 0xf4, value used as exit code -ram size: read-only, on io port 0xd1, 4 bytes' size -irq line setting: write only, on io ports 0x2000 - 0x2018, value to set/clear -simple io: read/write, on io port 0xe0, 1/2/4 bytes - -Test device used a char device for actual output - - -
x86-run deleted +0 -41
41 lines not on this page · raw message
x86/README +45 -14
62 lines not on this page · raw message
x86/flat.lds new file +21 -0
@@ -0,0 +1,21 @@ +SECTIONS +{ + . = 4M + SIZEOF_HEADERS; + stext = .; + .text : { *(.init) *(.text) *(.text.*) } + . = ALIGN(4K); + .data : { + *(.data) + exception_table_start = .; + *(.data.ex) + exception_table_end = .; + } + . = ALIGN(16); + .rodata : { *(.rodata) } + . = ALIGN(16); + .bss : { *(.bss) } + . = ALIGN(4K); + edata = .; +} + +ENTRY(start)
x86/run new file +41 -0
41 lines not on this page · raw message
Signature · 1 line
1.8.1.4
PATCH v4 4/19 add distclean target and gitignore more
In reply to Andrew Jonesalso add a check for config.mak in Makefile
--- .gitignore | 5 +++++ Makefile | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-)
.gitignore +5 -0
@@ -8,3 +8,8 @@ patches .stgit-* cscope.* +*.swp +/config.mak +/*-run +/test.log +/msr.out
Makefile +8 -1
@@ -1,9 +1,13 @@ +ifeq ($(wildcard config.mak),) +$(error run ./configure first. See ./configure -h) +endif + include config.mak DESTDIR := $(PREFIX)/share/qemu/tests -.PHONY: arch_clean clean +.PHONY: arch_clean clean distclean #make sure env CFLAGS variable is not used CFLAGS =
@@ -53,3 +57,6 @@ install: clean: arch_clean $(RM) lib/.*.d $(libcflat) $(cflatobjs) + +distclean: clean + $(RM) config.mak $(TEST_DIR)-run test.log msr.out
Signature · 1 line
1.8.1.4
PATCH v4 5/19 add 'make cscope' support
In reply to Andrew JonesAdd a Makefile target to quickly generate arch-specific cscope for kvm-unit-tests. Assumes a mostly flat directory structure, i.e. uses '-maxdepth 1' in the file search.
--- Makefile | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
Makefile +9 -2
@@ -7,7 +7,7 @@ include config.mak DESTDIR := $(PREFIX)/share/qemu/tests -.PHONY: arch_clean clean distclean +.PHONY: arch_clean clean distclean cscope #make sure env CFLAGS variable is not used CFLAGS =
@@ -59,4 +59,11 @@ clean: arch_clean $(RM) lib/.*.d $(libcflat) $(cflatobjs) distclean: clean - $(RM) config.mak $(TEST_DIR)-run test.log msr.out + $(RM) config.mak $(TEST_DIR)-run test.log msr.out cscope.* + +cscope: common_dirs = lib +cscope: + $(RM) ./cscope.* + find $(TEST_DIR) lib/$(TEST_DIR) $(common_dirs) -maxdepth 1 \ + -name '*.[chsS]' -print | sed 's,^\./,,' > ./cscope.files + cscope -bk
Signature · 1 line
1.8.1.4
PATCH v4 7/19 libfdt: get libfdt to build
In reply to Andrew JonesAdd string functions needed for libfdt, and add a make target.
---
v4: rewrite strchr w/out use of strlen, drop libfdt_env.h modifications
--- Makefile | 21 +++++++++++++++++++-- lib/libcflat.h | 4 ++++ lib/string.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 2 deletions(-)
Makefile +19 -2
@@ -21,6 +21,13 @@ cflatobjs := \ lib/string.o \ lib/report.o +# libfdt paths +LIBFDT_objdir = lib/libfdt +LIBFDT_srcdir = lib/libfdt +LIBFDT_archive = $(LIBFDT_objdir)/libfdt.a +LIBFDT_include = $(addprefix $(LIBFDT_srcdir)/,$(LIBFDT_INCLUDES)) +LIBFDT_version = $(addprefix $(LIBFDT_srcdir)/,$(LIBFDT_VERSION)) + #include architecure specific make rules include config/config-$(ARCH).mak
@@ -46,6 +53,11 @@ LDFLAGS += -pthread -lrt $(libcflat): $(cflatobjs) $(AR) rcs $@ $^ +include $(LIBFDT_srcdir)/Makefile.libfdt +$(LIBFDT_archive): CFLAGS += -ffreestanding -I lib -I lib/libfdt -Wno-sign-compare +$(LIBFDT_archive): $(addprefix $(LIBFDT_objdir)/,$(LIBFDT_OBJS)) + $(AR) rcs $@ $^ + %.o: %.S $(CC) $(CFLAGS) -c -nostdlib -o $@ $<
@@ -58,10 +70,15 @@ install: clean: arch_clean $(RM) lib/.*.d $(libcflat) $(cflatobjs) -distclean: clean +libfdt_clean: + $(RM) $(LIBFDT_archive) \ + $(addprefix $(LIBFDT_objdir)/,$(LIBFDT_OBJS)) \ + $(LIBFDT_objdir)/.*.d + +distclean: clean libfdt_clean $(RM) config.mak $(TEST_DIR)-run test.log msr.out cscope.* -cscope: common_dirs = lib +cscope: common_dirs = lib lib/libfdt cscope: $(RM) ./cscope.* find $(TEST_DIR) lib/$(TEST_DIR) $(common_dirs) -maxdepth 1 \
lib/libcflat.h +4 -0
@@ -42,6 +42,7 @@ extern void exit(int code);extern unsigned long strlen (const char *buf);extern char *strcat (char *dest,const char *src);extern int strcmp (const char *a,const char *b); +extern char *strchr (const char *s,int c);extern int printf (const char *fmt, ...);extern int snprintf (char *buf,int size,const char *fmt, ...);
@@ -51,6 +52,9 @@ extern void puts(const char *s);extern void *memset (void *s,int c,size_t n);extern void *memcpy (void *dest,const void *src,size_t n); +extern int memcmp (const void *s1,const void *s2,size_t n); +extern void *memmove (void *dest,const void *src,size_t n); +extern void *memchr (const void *s,int c,size_t n);extern long atol (const char *ptr);#define ARRAY_SIZE (_a) (sizeof(_a)/sizeof((_a)[0]))
lib/string.c +48 -0
60 lines not on this page · raw message
Signature · 1 line
1.8.1.4
PATCH v4 8/19 add support for Linux device trees
In reply to Andrew JonesAdd some device tree functions, built on libfdt, to the arch-neutral lib code in order to facilitate the extraction of boot info and device base addresses. These functions should work on device trees conforming to section III of the kernel doc Documentation/devicetree/booting-without-of.txt.
---
v4: reworked everything, added lots of comments to devicetree.h
--- lib/devicetree.c | 289 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/devicetree.h | 230 +++++++++++++++++++++++++++++++++++++++++++ lib/libcflat.h | 2 + 3 files changed, 521 insertions(+) create mode 100644 lib/devicetree.c create mode 100644 lib/devicetree.h
lib/devicetree.c new file +289 -0
@@ -0,0 +1,289 @@ +/* +* Copyright (C) 2014, Red Hat Inc, Andrew Jones <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2. +*/ +#include "libcflat.h" +#include "libfdt/libfdt.h" +#include "devicetree.h" + +static const void *fdt; +static u32 root_nr_address_cells, root_nr_size_cells; + +const void *dt_fdt (void ) +{ +return fdt; +} + +bool dt_available (void ) +{ +return fdt_check_header (fdt) ==0 ; +} + +int dt_get_nr_cells (int fdtnode,u32 *nr_address_cells,u32 *nr_size_cells) +{ +const struct fdt_property *prop; +u32 *nr_cells; +int len; + + prop =fdt_get_property (fdt, fdtnode,"#address-cells" , &len); +if (prop ==NULL ) +return len; + + nr_cells = (u32 *)prop->data; + *nr_address_cells =fdt32_to_cpu (*nr_cells); + + prop =fdt_get_property (fdt, fdtnode,"#size-cells" , &len); +if (prop ==NULL ) +return len; + + nr_cells = (u32 *)prop->data; + *nr_size_cells =fdt32_to_cpu (*nr_cells); + +return 0 ; +} + +void dt_reg_init (struct dt_reg *reg,u32 nr_address_cells,u32 nr_size_cells) +{ +memset (reg,0 ,sizeof (struct dt_reg )); + reg->nr_address_cells = nr_address_cells; + reg->nr_size_cells = nr_size_cells; +} + +int dt_get_reg (int fdtnode,int regidx,struct dt_reg *reg) +{ +const struct fdt_property *prop; +u32 *cells, i; +unsigned nr_tuple_cells; +int len; + + prop =fdt_get_property (fdt, fdtnode,"reg" , &len); +if (prop ==NULL ) +return len; + + cells = (u32 *)prop->data; + nr_tuple_cells = reg->nr_address_cells + reg->nr_size_cells; + regidx *= nr_tuple_cells; + +if (regidx + nr_tuple_cells > len/sizeof (u32)) +return -FDT_ERR_NOTFOUND ; + +for (i =0 ; i < reg->nr_address_cells; ++i) + reg->address_cells[i] =fdt32_to_cpu (cells[regidx + i]); + + regidx += reg->nr_address_cells; +for (i =0 ; i < reg->nr_size_cells; ++i) + reg->size_cells[i] =fdt32_to_cpu (cells[regidx + i]); + +return 0 ; +} + +int dt_pbus_translate_node (int fdtnode,int regidx,void *reg) +{ +struct dt_pbus_reg *pbus_reg = (struct dt_pbus_reg *)reg; +struct dt_reg raw_reg; +int ret; + +dt_reg_init (&raw_reg, root_nr_address_cells, root_nr_size_cells); + + ret =dt_get_reg (fdtnode, regidx, &raw_reg); +if (ret <0 ) +return ret; + + pbus_reg->addr =dt_pbus_read_cells (raw_reg.nr_address_cells, + raw_reg.address_cells); + pbus_reg->size =dt_pbus_read_cells (raw_reg.nr_size_cells, + raw_reg.size_cells); + +return 0 ; +} + +int dt_pbus_translate (const struct dt_device *dev,int regidx, +void *reg) +{ +return dt_pbus_translate_node (dev->fdtnode, regidx, reg); +} + +int dt_pbus_get_baseaddr (const struct dt_device *dev,dt_pbus_addr_t *base) +{ +struct dt_pbus_reg reg; +int ret; + + ret =dt_pbus_translate (dev,0 , ®); +if (ret <0 ) +return ret; + + *base = reg.addr; +return 0 ; +} + +int dt_bus_match_any(const struct dt_device *dev __unused, int fdtnode) +{ +/* matches any device with a valid node */ +return fdtnode <0 ? fdtnode :1 ; +} + +static const struct dt_bus dt_default_bus = { + .match = dt_bus_match_any, + .translate = dt_pbus_translate, +}; + +void dt_bus_init_defaults (struct dt_bus *bus) +{ +memcpy (bus, &dt_default_bus,sizeof (struct dt_bus )); +} + +void dt_device_init (struct dt_device *dev,const struct dt_bus *bus, +const void *info) +{ +memset (dev,0 ,sizeof (struct dt_device )); + dev->bus = bus; + dev->info = (void *)info; +} + +int dt_device_find_compatible (const struct dt_device *dev, +const char *compatible) +{ +int node, ret; + + node =fdt_node_offset_by_compatible (fdt,-1 , compatible); +while (node >=0 ) { + ret = dev->bus->match (dev, node); +if (ret <0 ) +return ret; +else if (ret) +break ; + node =fdt_node_offset_by_compatible (fdt, node, compatible); + } +return node; +} + +int dt_pbus_get_baseaddr_compatible (const char *compatible, +dt_pbus_addr_t *baseaddr) +{ +struct dt_device dev; +int node, ret; + +dt_device_init (&dev, &dt_default_bus,NULL ); + + node =dt_device_find_compatible (&dev, compatible); +if (node <0 ) +return node; + +dt_device_bind_node (&dev, node); + + ret =dt_pbus_get_baseaddr (&dev, baseaddr); +if (ret <0 ) +return ret; + +return 0 ; +} + +int dt_get_memory_params (struct dt_pbus_reg *regs,int nr_regs) +{ +const char *pn ="device_type" , *pv ="memory" ; +int node, ret, pl =strlen (pv) +1 , nr =0 ; +struct dt_pbus_reg reg; + + node =fdt_node_offset_by_prop_value (fdt,-1 , pn, pv, pl); + +while (node >=0 ) { + +while (nr < nr_regs) { + ret =dt_pbus_translate_node (node, nr, ®); +if (ret == -FDT_ERR_NOTFOUND ) +break ; +if (ret <0 ) +return ret; + regs[nr].addr = reg.addr; + regs[nr].size = reg.size; + ++nr; + } + + node =fdt_node_offset_by_prop_value (fdt, node, pn, pv, pl); + } + +return node != -FDT_ERR_NOTFOUND ? node : nr; +} + +int dt_for_each_cpu_node (void (*func)(int fdtnode,u32 regval,void *info), +void *info) +{ +const struct fdt_property *prop; +int cpus, cpu, ret, len; +struct dt_reg raw_reg; +u32 nac, nsc; + + cpus =fdt_path_offset (fdt,"/cpus" ); +if (cpus <0 ) +return cpus; + + ret =dt_get_nr_cells (cpus, &nac, &nsc); +if (ret <0 ) +return ret; + +dt_reg_init (&raw_reg, nac, nsc); + +dt_for_each_subnode (cpus, cpu) { + + prop =fdt_get_property (fdt, cpu,"device_type" , &len); +if (prop ==NULL ) +return len; + +if (len !=4 ||strcmp ((char *)prop->data,"cpu" )) +continue ; + + ret =dt_get_reg (cpu,0 , &raw_reg); +if (ret <0 ) +return ret; + +func (cpu, raw_reg.address_cells[0 ], info); + } + +return 0 ; +} + +int dt_get_bootargs (const char **bootargs) +{ +const struct fdt_property *prop; +int node, len; + + *bootargs =NULL ; + + node =fdt_path_offset (fdt,"/chosen" ); +if (node <0 ) +return node; + + prop =fdt_get_property (fdt, node,"bootargs" , &len); +if (prop) + *bootargs = (char *)prop->data; +else if (len <0 && len != -FDT_ERR_NOTFOUND ) +return len; + +return 0 ; +} + +int dt_init (const void *fdt_ptr) +{ +struct dt_bus *defbus = (struct dt_bus *)&dt_default_bus; +int root, ret; + + ret =fdt_check_header (fdt_ptr); +if (ret <0 ) +return ret; + fdt = fdt_ptr; + + root =fdt_path_offset (fdt,"/" ); +if (root <0 ) +return root; + + ret =dt_get_nr_cells (root, &root_nr_address_cells, + &root_nr_size_cells); +if (ret <0 ) +return ret; + + defbus->nr_address_cells = root_nr_address_cells; + defbus->nr_size_cells = root_nr_size_cells; + +return 0 ; +}
lib/devicetree.h new file +230 -0
230 lines not on this page · raw message
lib/libcflat.h +2 -0
@@ -22,6 +22,8 @@#include <stdarg.h> +#define __unused __attribute__((__unused__)) +typedef unsigned char u8 ;typedef signed char s8 ;typedef unsigned short u16 ;
Signature · 1 line
1.8.1.4
PATCH v4 9/19 libcflat: add abort() and assert()
In reply to Andrew JonesThe test framework may have external dependencies. assert() provides the ability to abort when those dependencies aren't met. However, assert() should only be used for unlikely conditions. We can provide more informative messages with printf() for the more likely problems.
--- lib/libcflat.h | 9 +++++++++ 1 file changed, 9 insertions(+)
lib/libcflat.h +9 -0
@@ -67,4 +67,13 @@ extern long atol(const char *ptr);void report (const char *msg_fmt,bool pass, ...);int report_summary (void ); + +#define abort () exit(64)/* 129 exit status from qemu */ +#define assert (cond) \ +do { \ + if (!(cond)) \ + printf("%s:%d: assert failed\n", __FILE__, __LINE__), \ + abort(); \ +} while (0) +#endif
Signature · 1 line
1.8.1.4
PATCH v4 11/19 add minimal virtio support for devtree virtio-mmio
In reply to Andrew JonesSupport the bare minimum of virtio to enable access to the virtio-mmio config space of a device. Currently this implementation must use a device tree to find the device.
---
v4:
- split from the virtio-testdev patch
- search a table to "discover" that the device must be DT/virtio-mmio, which doesn't change anything, but looks less hacky than comments saying the device must be DT/virtio-mmio...
- manage own pool of virtio-mmio pre-allocated device structures in order to avoid needing access to the heap
--- lib/libcflat.h | 3 ++ lib/virtio.c | 166 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/virtio.h | 89 +++++++++++++++++++++++++++++++ 3 files changed, 258 insertions(+) create mode 100644 lib/virtio.c create mode 100644 lib/virtio.h
lib/libcflat.h +3 -0
@@ -62,6 +62,9 @@ extern long atol(const char *ptr);#define ARRAY_SIZE (_a) (sizeof(_a)/sizeof((_a)[0]))#define offsetof (TYPE ,MEMBER ) __builtin_offsetof (TYPE, MEMBER) +#define container_of (ptr, type, member) ({ \ + const typeof( ((type *)0)->member ) *__mptr = (ptr); \ + (type *)( (char *)__mptr - offsetof(type,member) );})#define NULL ((void *)0UL)
lib/virtio.c new file +166 -0
166 lines not on this page · raw message
lib/virtio.h new file +89 -0
89 lines not on this page · raw message
Signature · 1 line
1.8.1.4
PATCH v4 10/19 Introduce asm-generic/*.h files
In reply to Andrew JonesArchitecture neutral code may need to call low-level io accessors, or use spinlocks. Create a generic io.h to ensure those accessors are defined, and a generic spinlock.h that complains when included, as we can't write a generic spinlock. These files can be overridden or extended by architecture specific versions placed in lib/$ARCH/asm/.
---
v4: introduce lib/asm symlink to get rid of #ifdef __arm__,
add spinlock.h too
v3: wrt to io.h (was libio.[ch]) only
- get rid of CONFIG_64BIT, replace with asserts
- get rid of {read,write}_len() [libio.c]
- fix bad *64_to_cpu macros
--- .gitignore | 1 + Makefile | 6 +- configure | 11 ++++ lib/asm-generic/io.h | 154 +++++++++++++++++++++++++++++++++++++++++++++ lib/asm-generic/spinlock.h | 4 ++ 5 files changed, 173 insertions(+), 3 deletions(-) create mode 100644 lib/asm-generic/io.h create mode 100644 lib/asm-generic/spinlock.h
.gitignore +1 -0
@@ -9,6 +9,7 @@ patches .stgit-* cscope.* *.swp +/lib/asm /config.mak /*-run /test.log
Makefile +3 -3
@@ -76,11 +76,11 @@ libfdt_clean: $(LIBFDT_objdir)/.*.d distclean: clean libfdt_clean - $(RM) config.mak $(TEST_DIR)-run test.log msr.out cscope.* + $(RM) lib/asm config.mak $(TEST_DIR)-run test.log msr.out cscope.* -cscope: common_dirs = lib lib/libfdt +cscope: common_dirs = lib lib/libfdt lib/asm lib/asm-generic cscope: $(RM) ./cscope.* - find $(TEST_DIR) lib/$(TEST_DIR) $(common_dirs) -maxdepth 1 \ + find -L $(TEST_DIR) lib/$(TEST_DIR) $(common_dirs) -maxdepth 1 \ -name '*.[chsS]' -print | sed 's,^\./,,' > ./cscope.files cscope -bk
configure +11 -0
@@ -95,6 +95,17 @@ if [ $exit -eq 0 ]; then fi rm -f lib_test.c +# link lib/asm for the architecture +rm -f lib/asm +asm=asm-generic +if [ -d lib/$arch/asm ]; then + asm=$arch/asm +elif [ -d lib/$testdir/asm ]; then + asm=$testdir/asm +fi +ln -s $asm lib/asm + +# create the config cat <<EOF > config.mak PREFIX=$prefix KERNELDIR=$(readlink -f $kerneldir)
lib/asm-generic/io.h new file +154 -0
154 lines not on this page · raw message
lib/asm-generic/spinlock.h new file +4 -0
@@ -0,0 +1,4 @@ +#ifndef _ASM_GENERIC_SPINLOCK_H_ +#define _ASM_GENERIC_SPINLOCK_H_ +#error need architecture specific asm/spinlock.h +#endif
Signature · 1 line
1.8.1.4
PATCH v4 12/19 Introduce virtio-testdev
In reply to Andrew Jonesvirtio-testdev is a communication channel to qemu through virtio that can be used by test code to send commands. The only command currently implemented is EXIT, which allows the test code to exit with a given status code.
---
v4: couple tweaks (added spinlock), no functional changes
--- lib/virtio-testdev.c | 137 +++++++++++++++++++++++++++++++++++++++++++++++++++ lib/virtio-testdev.h | 18 +++++++ 2 files changed, 155 insertions(+) create mode 100644 lib/virtio-testdev.c create mode 100644 lib/virtio-testdev.h
lib/virtio-testdev.c new file +137 -0
@@ -0,0 +1,137 @@ +/* +* Copyright (C) 2014, Red Hat Inc, Andrew Jones <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2. +*/ +#include "libcflat.h" +#include "asm/spinlock.h" +#include "virtio.h" + +#define TESTDEV_NAME "virtio-testdev" +#define VIRTIO_ID_TESTDEV 0xffff +#define TESTDEV_MAJOR_VER 1 +#define TESTDEV_MINOR_VER 1 + +#define VIRTIO_CONFIG_SIZE 64 + +enum { +VERSION =1 , +CLEAR , +EXIT , +}; + +#define TOKEN_OFFSET 0x0 +#define NARGS_OFFSET 0x4 +#define NRETS_OFFSET 0x8 +#define ARG_OFFSET (n) (0xc + (n) * 4) +#define __RET_OFFSET (nargs, n) (ARG_OFFSET(nargs) + (n) * 4) + +static struct spinlock lock; +static struct virtio_dev *vdev; + +static u32 testdev_readl (unsigned offset) +{ +assert (offset <= (VIRTIO_CONFIG_SIZE -4 )); +return virtio_config_readl (vdev, offset); +} + +static void testdev_writel (unsigned offset,u32 val) +{ +assert (offset <= (VIRTIO_CONFIG_SIZE -4 )); +virtio_config_writel (vdev, offset, val); +} + +/* +* We have to write all args; nargs, nrets, ... first to avoid executing +* the token's operation until all args are in place. Then issue the op, +* and then read the return values. Reading the return values (or just +* sanity checking by reading token) will read a zero into qemu's copy +* of the token, which allows us to prepare additional ops without +* re-executing the last one. +*/ +void virtio_testdev (u32 token,u32 nargs,u32 nrets, ...) +{ +va_list va; +unsigned off; +u32 n; + +if (!vdev) +return ; + +spin_lock (&lock); + +testdev_writel (NARGS_OFFSET , nargs); +testdev_writel (NRETS_OFFSET , nrets); + +va_start (va, nrets); + + off =ARG_OFFSET (0 ); + n = nargs; +while (n--) { +testdev_writel (off,va_arg (va, unsigned)); + off +=4 ; + } + +/* this runs the op, but then resets token to zero */ +testdev_writel (TOKEN_OFFSET , token); +assert (testdev_readl (TOKEN_OFFSET ) ==0 ); + + off =__RET_OFFSET (nargs,0 ); + n = nrets; +while (n--) { + u32 *r = va_arg(va, unsigned *); + *r =testdev_readl (off); + off +=4 ; + } + +spin_unlock (&lock); +va_end (va); +} + +void virtio_testdev_version (u32 *version) +{ +virtio_testdev (VERSION ,0 ,1 , version); +} + +void virtio_testdev_clear (void ) +{ +virtio_testdev (CLEAR ,0 ,0 ); +} + +void virtio_testdev_exit (int code) +{ +virtio_testdev (EXIT ,1 ,0 , code); +} + +void virtio_testdev_init (void ) +{ +u16 major, minor; +u32 version; + + vdev =virtio_bind (VIRTIO_ID_TESTDEV ); +if (vdev ==NULL ) { +printf ("%s: can't find " TESTDEV_NAME ". " +"Is '-device " TESTDEV_NAME "' " +"on the qemu command line?\n" , __func__); +abort (); + } + +virtio_testdev_version (&version); + major = version >>16 ; + minor = version &0xffff ; + +if (major !=TESTDEV_MAJOR_VER || minor <TESTDEV_MINOR_VER ) { +char *u ="qemu" ; +if (major >TESTDEV_MAJOR_VER ) + u ="kvm-unit-tests" ; +printf ("%s: incompatible version of " TESTDEV_NAME ": " +"major = %d, minor = %d. Update %s\n" , + __func__, major, minor, u); +abort (); + } + +if (minor >TESTDEV_MINOR_VER ) +printf ("%s: " TESTDEV_NAME " has new features. " +"An update of kvm-unit-tests may be possible.\n" , + __func__); +}
lib/virtio-testdev.h new file +18 -0
@@ -0,0 +1,18 @@ +#ifndef _VIRTIO_TESTDEV_H_ +#define _VIRTIO_TESTDEV_H_ +/* +* virtio-testdev is a driver for the virtio-testdev qemu device. +* The virtio-testdev device exposes a simple control interface to +* qemu for kvm-unit-tests through virtio. +* +* Copyright (C) 2014, Red Hat Inc, Andrew Jones <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2. +*/ +#include "libcflat.h" + +extern void virtio_testdev_init (void ); +extern void virtio_testdev_version (u32 *version); +extern void virtio_testdev_clear (void ); +extern void virtio_testdev_exit (int code); +#endif
Signature · 1 line
1.8.1.4
PATCH v4 13/19 libcflat: clean up libcflat.h and add string.h
In reply to Andrew JonesUse libgcc's stddef.h and stdint.h, and then remove the redundant defines from libcflat.h. Also separate out the string function declarations into a new file string.h. These changes have no affect on code including libcflat.h, but are needed in order to compile an unmodified libfdt for kvm-unit-tests using an arm cross-compiler. While at it, add strcpy.
--- lib/libcflat.h | 55 +++++++++++++++++++++---------------------------------- lib/string.c | 6 ++++++ lib/string.h | 15 +++++++++++++++ 3 files changed, 42 insertions(+), 34 deletions(-) create mode 100644 lib/string.h
lib/libcflat.h +21 -34
@@ -21,57 +21,44 @@#define __LIBCFLAT_H#include <stdarg.h> +#include <stddef.h> +#include <stdint.h> +#include "string.h" #define __unused __attribute__((__unused__)) -typedef unsigned char u8 ; -typedef signed char s8 ; -typedef unsigned short u16 ; -typedef signed short s16 ; -typedef unsigned u32 ; -typedef signed s32 ; -typedef unsigned long ulong ; -typedef unsigned long long u64 ; -typedef signed long long s64 ; -typedef unsigned long size_t ; -typedef _Bool bool ; - -#define true 1 +typedef uint8_t u8 ; +typedef int8_t s8 ; +typedef uint16_t u16 ; +typedef int16_t s16 ; +typedef uint32_t u32 ; +typedef int32_t s32 ; +typedef uint64_t u64 ; +typedef int64_t s64 ; +typedef unsigned long ulong ; + +typedef _Bool bool ;#define false 0 +#define true 1 +extern void puts (const char *s);extern void exit (int code); -extern unsigned long strlen (const char *buf); -extern char *strcat (char *dest,const char *src); -extern int strcmp (const char *a,const char *b); -extern char *strchr (const char *s,int c); -extern int printf (const char *fmt, ...);extern int snprintf (char *buf,int size,const char *fmt, ...);extern int vsnprintf (char *buf,int size,const char *fmt,va_list va); +extern long atol (const char *ptr); -extern void puts (const char *s); - -extern void *memset (void *s,int c,size_t n); -extern void *memcpy (void *dest,const void *src,size_t n); -extern int memcmp (const void *s1,const void *s2,size_t n); -extern void *memmove (void *dest,const void *src,size_t n); -extern void *memchr (const void *s,int c,size_t n); +void report (const char *msg_fmt,bool pass, ...); +int report_summary (void ); -extern long atol (const char *ptr); -#define ARRAY_SIZE (_a) (sizeof(_a)/sizeof((_a)[0])) +#define ARRAY_SIZE (_a) (sizeof(_a)/sizeof((_a)[0])) -#define offsetof (TYPE ,MEMBER ) __builtin_offsetof (TYPE, MEMBER)#define container_of (ptr, type, member) ({ \ const typeof( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr - offsetof(type,member) );}) -#define NULL ((void *)0UL) - -void report (const char *msg_fmt,bool pass, ...); -int report_summary (void ); - -#define abort () exit(64)/* 129 exit status from qemu */ +#define abort () exit(64)/* 129 exit status from qemu */ #define assert (cond) \ do { \ if (!(cond)) \
lib/string.c +6 -0
@@ -20,6 +20,12 @@ char *strcat(char *dest, const char *src)return dest; } +char *strcpy (char *dest,const char *src) +{ + *dest =0 ; +return strcat (dest, src); +} +int strcmp (const char *a,const char *b) {while (*a == *b) {
lib/string.h new file +15 -0
@@ -0,0 +1,15 @@ +#ifndef __STRING_H +#define __STRING_H + +extern unsigned long strlen (const char *buf); +extern char *strcat (char *dest,const char *src); +extern char *strcpy (char *dest,const char *src); +extern int strcmp (const char *a,const char *b); +extern char *strchr (const char *s,int c); +extern void *memset (void *s,int c,size_t n); +extern void *memcpy (void *dest,const void *src,size_t n); +extern int memcmp (const void *s1,const void *s2,size_t n); +extern void *memmove (void *dest,const void *src,size_t n); +extern void *memchr (const void *s,int c,size_t n); + +#endif /* _STRING_H */
Signature · 1 line
1.8.1.4
PATCH v4 14/19 printf: support field padding
In reply to Andrew JonesSupport format flags for field padding, such as "%08x", allowing register dumps to be easier on the eyes.
--- lib/printf.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 68 insertions(+), 14 deletions(-)
lib/printf.c +68 -14
@@ -6,6 +6,11 @@ typedef struct pstream {int added; } pstream_t; +typedef struct strprops { +char pad; +int npad; +}strprops_t ; +static void addchar (pstream_t *p,char c) {if (p->remain) {
@@ -15,15 +20,35 @@ static void addchar(pstream_t *p, char c) ++p->added; } -void print_str (pstream_t *p,const char *s) +void print_str (pstream_t *p,const char *s,strprops_t props) { +const char *s_orig = s; +int npad = props.npad; + +if (npad >0 ) { + npad -=strlen (s_orig); +while (npad >0 ) { +addchar (p, props.pad); + --npad; + } + } +while (*s)addchar (p, *s++); + +if (npad <0 ) { + props.pad =' ' ;/* ignore '0' flag with '-' flag */ + npad +=strlen (s_orig); +while (npad <0 ) { +addchar (p, props.pad); + ++npad; + } + } }static char digits[16 ] ="0123456789abcdef" ; -void print_int (pstream_t *ps,long long n,int base) +void print_int (pstream_t *ps,long long n,int base,strprops_t props) {char buf[sizeof (long ) *3 +2 ], *p = buf;int s =0 , i;
@@ -54,10 +79,11 @@ void print_int(pstream_t *ps, long long n, int base) *p =0 ; -print_str (ps, buf); +print_str (ps, buf, props); } -void print_unsigned (pstream_t *ps,unsigned long long n,int base) +void print_unsigned (pstream_t *ps,unsigned long long n,int base, +strprops_t props) {char buf[sizeof (long ) *3 +1 ], *p = buf;int i;
@@ -80,7 +106,23 @@ void print_unsigned(pstream_t *ps, unsigned long long n, int base) *p =0 ; -print_str (ps, buf); +print_str (ps, buf, props); +} + +static int fmtnum (const char **fmt) +{ +const char *f = *fmt; +int len =0 , num; + +if (*f =='-' ) + ++f, ++len; + +while (*f >='0' && *f <='9' ) + ++f, ++len; + + num =atol (*fmt); + *fmt += len; +return num; }int vsnprintf (char *buf,int size,const char *fmt,va_list va)
@@ -93,6 +135,9 @@ int vsnprintf(char *buf, int size, const char *fmt, va_list va)while (*fmt) {char f = *fmt++;int nlong =0 ; +strprops_t props; +memset (&props,0 ,sizeof (props)); + props.pad =' ' ;if (f !='%' ) {addchar (&s, f);
@@ -110,41 +155,50 @@ int vsnprintf(char *buf, int size, const char *fmt, va_list va)case '\0' : --fmt;break ; +case '0' : + props.pad ='0' ; + ++fmt; +/* fall through */ + case '1'...'9': +case '-' : + --fmt; + props.npad =fmtnum (&fmt); + goto morefmt;case 'l' : ++nlong; goto morefmt;case 'd' :switch (nlong) {case 0 : -print_int (&s,va_arg (va, int),10 ); +print_int (&s,va_arg (va, int),10 , props);break ;case 1 : -print_int (&s,va_arg (va, long),10 ); +print_int (&s,va_arg (va, long),10 , props);break ;default : - print_int(&s, va_arg(va, long long), 10); + print_int(&s, va_arg(va, long long), 10, props);break ; }break ;case 'x' :switch (nlong) {case 0 : -print_unsigned (&s,va_arg (va, unsigned),16 ); +print_unsigned (&s,va_arg (va, unsigned),16 , props);break ;case 1 : - print_unsigned(&s, va_arg(va, unsigned long), 16); + print_unsigned(&s, va_arg(va, unsigned long), 16, props);break ;default : - print_unsigned(&s, va_arg(va, unsigned long long), 16); + print_unsigned(&s, va_arg(va, unsigned long long), 16, props);break ; }break ;case 'p' : -print_str (&s,"0x" ); - print_unsigned(&s, (unsigned long)va_arg(va, void *), 16); +print_str (&s,"0x" , props); + print_unsigned(&s, (unsigned long)va_arg(va, void *), 16, props);break ;case 's' : - print_str(&s, va_arg(va, const char *)); + print_str(&s, va_arg(va, const char *), props);break ;default :addchar (&s, f);
Signature · 1 line
1.8.1.4
PATCH v4 15/19 arm: initial drop
In reply to Andrew JonesThis is the initial drop of the arm test framework and a first test that just checks that setup completed (a selftest). kvm isn't needed to run this test unless testing with smp > 1.
Try it out with
yum install gcc-arm-linux-gnu
export QEMU=[qemu with mach-virt and virtio-testdev] ./configure --cross-prefix=arm-linux-gnu- --arch=arm make
./run_tests.sh
---
v4:
- moved fdt to just after stacktop (it was in the middle of free memory)
- switched from using heap to memregions
- get nr_cpus and added smp=<num> test
- added barrier.h
- use new report()/report_summary()
- config/config-arm.mak cleanup
--- arm/cstart.S | 35 ++++++++++++ arm/flat.lds | 18 +++++++ arm/run | 31 +++++++++++ arm/selftest.c | 87 ++++++++++++++++++++++++++++++ arm/unittests.cfg | 18 +++++++ config/config-arm.mak | 72 +++++++++++++++++++++++++ configure | 12 ++++- lib/argv.c | 6 +++ lib/arm/asm/barrier.h | 18 +++++++ lib/arm/asm/io.h | 24 +++++++++ lib/arm/asm/setup.h | 39 ++++++++++++++ lib/arm/asm/spinlock.h | 16 ++++++ lib/arm/eabi_compat.c | 20 +++++++ lib/arm/io.c | 66 +++++++++++++++++++++++ lib/arm/setup.c | 142 +++++++++++++++++++++++++++++++++++++++++++++++++ 15 files changed, 602 insertions(+), 2 deletions(-) create mode 100644 arm/cstart.S create mode 100644 arm/flat.lds create mode 100755 arm/run create mode 100644 arm/selftest.c create mode 100644 arm/unittests.cfg create mode 100644 config/config-arm.mak create mode 100644 lib/arm/asm/barrier.h create mode 100644 lib/arm/asm/io.h create mode 100644 lib/arm/asm/setup.h create mode 100644 lib/arm/asm/spinlock.h create mode 100644 lib/arm/eabi_compat.c create mode 100644 lib/arm/io.c create mode 100644 lib/arm/setup.c
arm/cstart.S new file +35 -0
@@ -0,0 +1,35 @@ +/* + * Boot entry point and assembler functions for armv7 tests. + * + * Copyright (C) 2014, Red Hat Inc, Andrew Jones <[email protected]> + * + * This work is licensed under the terms of the GNU LGPL, version 2. + */ + +.arm + +.section .init + +.globl start +start: + /* + * bootloader params are in r0-r2 + * See the kernel doc Documentation/arm/Booting + */ + ldr sp, =stacktop + bl setup + + /* run the test */ + ldr r0, =__argc + ldr r0, [r0] + ldr r1, =__argv + bl main + bl exit + b halt + +.text + +.globl halt +halt: +1: wfi + b 1b
arm/flat.lds new file +18 -0
@@ -0,0 +1,18 @@ + +SECTIONS +{ + .text : { *(.init) *(.text) *(.text.*) } + . = ALIGN(4K); + .data : { *(.data) } + . = ALIGN(16); + .rodata : { *(.rodata) } + . = ALIGN(16); + .bss : { *(.bss) } + . = ALIGN(4K); + edata = .; + . += 8K; + . = ALIGN(4K); + stacktop = .; +} + +ENTRY(start)
arm/run new file +31 -0
@@ -0,0 +1,31 @@ +#!/bin/bash + +if [ ! -f config.mak ]; then + echo run ./configure first. See ./configure -h + exit 2 +fi +source config.mak + +qemu="${QEMU:-qemu-system-arm}" +testdev=virtio-testdev + +if ! $qemu -device '?' 2>&1 | grep $testdev > /dev/null; then + qpath=$(which $qemu 2>/dev/null) + if [ "$qpath" ]; then + echo $qpath doesn\'t support virtio-testdev. Exiting. + else + echo $qemu not found. + fi + exit 2 +fi + +command="$qemu -device $testdev -display none -serial stdio " +command+="-M virt -cpu $PROCESSOR " +#command+="-enable-kvm " +command+="-kernel" + +echo $command "$@" +$command "$@" +ret=$? +echo Return value from qemu: $ret +exit $ret
arm/selftest.c new file +87 -0
87 lines not on this page · raw message
arm/unittests.cfg new file +18 -0
@@ -0,0 +1,18 @@ +# Define your new unittest following the convention: +# [unittest_name] +# file = foo.flat # Name of the flat file to be used +# smp = 2 # Number of processors the VM will use during this test +# extra_params = -append <params...> # Additional parameters used +# arch = arm/arm64 # Only if test case is specific to one +# groups = group1 group2 # Used to identify test cases with run_tests -g ... + +# +# Test that the configured number of processors (smp = <num>), and +# that the configured amount of memory (-m <MB>) are correctly setup +# by the framework. +# +[selftest::setup] +file = selftest.flat +smp = 1 +extra_params = -m 256 -append 'setup smp=1 mem=256' +groups = selftest
config/config-arm.mak new file +72 -0
72 lines not on this page · raw message
configure +10 -2
@@ -6,8 +6,7 @@ cc=gcc ld=ld objcopy=objcopy ar=ar -arch=`uname -m | sed -e s/i.86/i386/` -processor="$arch" +arch=`uname -m | sed -e s/i.86/i386/ | sed -e 's/arm.*/arm/'` cross_prefix= usage() {
@@ -17,6 +16,7 @@ usage() { Options include: --test-dir=DIR the main directory for tests ($arch) --arch=ARCH architecture to compile for ($arch) + --processor=PROCESSOR processor to compile for ($arch) --cross-prefix=PREFIX cross compiler prefix --cc=CC c compiler to use ($cc) --ld=LD ld linker to use ($ld)
@@ -66,6 +66,12 @@ while [[ "$1" = -* ]]; do ;; esac done +[ -z "$processor" ] && processor="$arch" + +if [ "$processor" = "arm" ]; then + processor="cortex-a15" +fi + if [ -z "$testdir" -a \( "$arch" = "i386" -o "$arch" = "x86_64" \) ]; then testdir=x86 elif [ -z "$testdir" ]; then
@@ -80,6 +86,7 @@ if [ -f $testdir/run ]; then fi # check for dependent 32 bit libraries +if [ "$arch" != "arm" ]; then cat << EOF > lib_test.c #include <stdc++.h> #include <boost_thread-mt.h>
@@ -94,6 +101,7 @@ if [ $exit -eq 0 ]; then api=true fi rm -f lib_test.c +fi # link lib/asm for the architecture rm -f lib/asm
lib/argv.c +6 -0
@@ -31,3 +31,9 @@ void __setup_args(void) } __argc = argv - __argv; } + +void setup_args (char *args) +{ + __args = args; +__setup_args (); +}
lib/arm/asm/barrier.h new file +18 -0
@@ -0,0 +1,18 @@ +#ifndef _ASMARM_BARRIER_H_ +#define _ASMARM_BARRIER_H_ +/* +* Adapted form arch/arm/include/asm/barrier.h +*/ + +#define isb (option) __asm__ __volatile__ ("isb " #option : : : "memory") +#define dsb (option) __asm__ __volatile__ ("dsb " #option : : : "memory") +#define dmb (option) __asm__ __volatile__ ("dmb " #option : : : "memory") + +#define mb () dsb() +#define rmb () dsb() +#define wmb () dsb(st) +#define smp_mb () dmb(ish) +#define smp_rmb () smp_mb() +#define smp_wmb () dmb(ishst) + +#endif /* _ASMARM_BARRIER_H_ */
lib/arm/asm/io.h new file +24 -0
@@ -0,0 +1,24 @@ +#ifndef _ASMARM_IO_H_ +#define _ASMARM_IO_H_ +#include "libcflat.h" +#include "asm/barrier.h" + +#define __bswap16 bswap16 +static inline u16 bswap16 (u16 val) +{ +u16 ret; + asmvolatile ("rev16 %0, %1" :"=r" (ret) :"r" (val)); +return ret; +} + +#define __bswap32 bswap32 +static inline u32 bswap32 (u32 val) +{ +u32 ret; + asmvolatile ("rev %0, %1" :"=r" (ret) :"r" (val)); +return ret; +} + +#include "asm-generic/io.h" + +#endif /* _ASMARM_IO_H_ */
lib/arm/asm/setup.h new file +39 -0
@@ -0,0 +1,39 @@ +#ifndef _ASMARM_SETUP_H_ +#define _ASMARM_SETUP_H_ +/* +* Copyright (C) 2014, Red Hat Inc, Andrew Jones <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2. +*/ +#include "libcflat.h" + +#define NR_CPUS 8 +extern u32 cpus[NR_CPUS ]; +extern int nr_cpus; + +typedef u64 phys_addr_t ; + +#define NR_MEMREGIONS 16 +struct memregion { +phys_addr_t addr; +phys_addr_t size; +bool free; +}; + +extern struct memregion memregions[NR_MEMREGIONS ]; +extern int nr_memregions; + +extern struct memregion *memregion_new (phys_addr_t size); +extern void memregions_show (void ); + +#define PHYS_OFFSET ({ memregions[0].addr; }) +#define PHYS_SHIFT 40 +#define PHYS_SIZE (1ULL << PHYS_SHIFT) +#define PHYS_MASK (PHYS_SIZE - 1ULL) + +#define PAGE_SHIFT 12 +#define PAGE_SIZE (1UL << PAGE_SHIFT) +#define PAGE_MASK (~(PAGE_SIZE - 1UL)) +#define PAGE_ALIGN (addr) (((addr) + (PAGE_SIZE-1UL)) & PAGE_MASK) + +#endif /* _ASMARM_SETUP_H_ */
lib/arm/asm/spinlock.h new file +16 -0
@@ -0,0 +1,16 @@ +#ifndef _ASMARM_SPINLOCK_H_ +#define _ASMARM_SPINLOCK_H_ + +struct spinlock { +int v; +}; + +//TODO +static inline void spin_lock(struct spinlock *lock __unused) +{ +} +static inline void spin_unlock(struct spinlock *lock __unused) +{ +} + +#endif /* _ASMARM_SPINLOCK_H_ */
lib/arm/eabi_compat.c new file +20 -0
@@ -0,0 +1,20 @@ +/* +* Adapted from u-boot's arch/arm/lib/eabi_compat.c +*/ +#include "libcflat.h" + +int raise(int signum __unused) +{ +printf ("Divide by zero!\n" ); +abort (); +return 0 ; +} + +/* Dummy functions to avoid linker complaints */ +void __aeabi_unwind_cpp_pr0 (void ) +{ +} + +void __aeabi_unwind_cpp_pr1 (void ) +{ +}
lib/arm/io.c new file +66 -0
66 lines not on this page · raw message
lib/arm/setup.c new file +142 -0
142 lines not on this page · raw message
Signature · 1 line
1.8.1.4
PATCH v4 16/19 arm: Add spinlock implementation
In reply to Andrew JonesFrom: Christoffer Dall <[email protected]>
Add simple busy-wait spinlock implementation for ARM.
--- config/config-arm.mak | 3 ++- lib/arm/asm/spinlock.h | 9 ++------- lib/arm/spinlock.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 lib/arm/spinlock.c
config/config-arm.mak +2 -1
@@ -35,7 +35,8 @@ cflatobjs += \ lib/virtio.o \ lib/virtio-testdev.o \ lib/arm/io.o \ - lib/arm/setup.o + lib/arm/setup.o \ + lib/arm/spinlock.o libeabi = lib/arm/libeabi.a eabiobjs = lib/arm/eabi_compat.o
lib/arm/asm/spinlock.h +2 -7
@@ -5,12 +5,7 @@ struct spinlock { int v; }; -//TODO -static inline void spin_lock(struct spinlock *lock __unused) -{ -} -static inline void spin_unlock(struct spinlock *lock __unused) -{ -} +extern void spin_lock (struct spinlock *lock); +extern void spin_unlock (struct spinlock *lock);#endif /* _ASMARM_SPINLOCK_H_ */
lib/arm/spinlock.c new file +28 -0
@@ -0,0 +1,28 @@ +#include "libcflat.h" +#include "asm/spinlock.h" +#include "asm/barrier.h" + +void spin_lock (struct spinlock *lock) +{ +u32 val, fail; + +dmb (); +do { + asmvolatile ( +"1: ldrex %0, [%2]\n" +" teq %0, #0\n" +" bne 1b\n" +" mov %0, #1\n" +" strex %1, %0, [%2]\n" + :"=&r" (val),"=&r" (fail) + :"r" (&lock->v) + :"cc" ); + }while (fail); +dmb (); +} + +void spin_unlock (struct spinlock *lock) +{ + lock->v =0 ; +dmb (); +}
Signature · 1 line
1.8.1.4
PATCH v4 17/19 arm: Add IO accessors to avoid register-writeback
In reply to Andrew JonesFrom: Christoffer Dall <[email protected]>
Add IO accessor functions to the arm library functions to avoid register-writeback IO accessors that are not yet supported by the kernel.
--- lib/arm/asm/io.h | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+)
lib/arm/asm/io.h +57 -0
@@ -3,6 +3,9 @@#include "libcflat.h" #include "asm/barrier.h" +#define __iomem +#define __force +#define __bswap16 bswap16static inline u16 bswap16 (u16 val) {
@@ -19,6 +22,60 @@ static inline u32 bswap32(u32 val)return ret; } +#define __raw_readb __raw_readb +static inline u8 __raw_readb (const volatile void __iomem *addr) +{ +u8 val; + asmvolatile ("ldrb %1, %0" + :"+Qo" (*(volatile u8 __force *)addr), +"=r" (val)); +return val; +} + +#define __raw_readw __raw_readw +static inline u16 __raw_readw (const volatile void __iomem *addr) +{ +u16 val; + asmvolatile ("ldrh %1, %0" + :"+Q" (*(volatile u16 __force *)addr), +"=r" (val)); +return val; +} + +#define __raw_readl __raw_readl +static inline u32 __raw_readl (const volatile void __iomem *addr) +{ +u32 val; + asmvolatile ("ldr %1, %0" + :"+Qo" (*(volatile u32 __force *)addr), +"=r" (val)); +return val; +} + +#define __raw_writeb __raw_writeb +static inline void __raw_writeb (u8 val,volatile void __iomem *addr) +{ + asmvolatile ("strb %1, %0" + :"+Qo" (*(volatile u8 __force *)addr) + :"r" (val)); +} + +#define __raw_writew __raw_writew +static inline void __raw_writew (u16 val,volatile void __iomem *addr) +{ + asmvolatile ("strh %1, %0" + :"+Q" (*(volatile u16 __force *)addr) + :"r" (val)); +} + +#define __raw_writel __raw_writel +static inline void __raw_writel (u32 val,volatile void __iomem *addr) +{ + asmvolatile ("str %1, %0" + :"+Qo" (*(volatile u32 __force *)addr) + :"r" (val)); +} +#include "asm-generic/io.h" #endif /* _ASMARM_IO_H_ */
Signature · 1 line
1.8.1.4
PATCH v4 18/19 arm: add useful headers from the Linux kernel
In reply to Andrew JonesWe're going to need PSR bit defines and pt_regs. We'll also need pt_regs offsets in assembly code. This patch adapts the Linux kernel's ptrace.h and generated/asm-offsets.h to this framework. It also adapts cp15.h from the kernel, since we'll need bit defines from there too.
---
v4: much improved asm-offsets.h generation based on Kbuild
--- config/asm-offsets.mak | 41 +++++++++++++++++++ config/config-arm.mak | 9 ++++- lib/arm/.gitignore | 1 + lib/arm/asm-offsets.c | 39 ++++++++++++++++++ lib/arm/asm/asm-offsets.h | 1 + lib/arm/asm/cp15.h | 37 +++++++++++++++++ lib/arm/asm/ptrace.h | 100 ++++++++++++++++++++++++++++++++++++++++++++++ lib/generated/.gitignore | 1 + 8 files changed, 227 insertions(+), 2 deletions(-) create mode 100644 config/asm-offsets.mak create mode 100644 lib/arm/.gitignore create mode 100644 lib/arm/asm-offsets.c create mode 100644 lib/arm/asm/asm-offsets.h create mode 100644 lib/arm/asm/cp15.h create mode 100644 lib/arm/asm/ptrace.h create mode 100644 lib/generated/.gitignore
config/asm-offsets.mak new file +41 -0
@@ -0,0 +1,41 @@ +# +# asm-offsets adapted from the kernel, see +# Kbuild +# scripts/Kbuild.include +# scripts/Makefile.build +# +# Authors: Andrew Jones <[email protected]> +# + +define sed-y + "/^->/{s:->#\(.*\):/* \1 */:; \ + s:^->\([^ ]*\) [\$$#]*\([-0-9]*\) \(.*\):#define \1 \2 /* \3 */:; \ + s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \ + s:->::; p;}" +endef + +define make_asm_offsets + (set -e; \ + echo "#ifndef __ASM_OFFSETS_H__"; \ + echo "#define __ASM_OFFSETS_H__"; \ + echo "/*"; \ + echo " * Generated file. DO NOT MODIFY."; \ + echo " *"; \ + echo " */"; \ + echo ""; \ + sed -ne $(sed-y) $<; \ + echo ""; \ + echo "#endif" ) > $@ +endef + +$(asm-offsets:.h=.s): $(asm-offsets:.h=.c) + $(CC) $(CFLAGS) -fverbose-asm -S -o $@ $< + +$(asm-offsets): $(asm-offsets:.h=.s) + $(call make_asm_offsets) + cp -f $(asm-offsets) lib/generated + +asm_offsets_clean: + $(RM) $(asm-offsets) $(asm-offsets:.h=.s) \ + $(addprefix lib/generated/,$(notdir $(asm-offsets))) +
config/config-arm.mak +7 -2
@@ -30,6 +30,9 @@ CFLAGS += -Wextra CFLAGS += -O2 CFLAGS += -I lib -I lib/libfdt +asm-offsets = lib/arm/asm-offsets.h +include config/asm-offsets.mak + cflatobjs += \ lib/devicetree.o \ lib/virtio.o \
@@ -57,7 +60,7 @@ FLATLIBS = $(libcflat) $(LIBFDT_archive) $(libgcc) $(libeabi) $(libeabi): $(eabiobjs) $(AR) rcs $@ $^ -arch_clean: libfdt_clean +arch_clean: libfdt_clean asm_offsets_clean $(RM) $(TEST_DIR)/*.{o,flat,elf} $(libeabi) $(eabiobjs) \ $(TEST_DIR)/.*.d lib/arm/.*.d
@@ -67,7 +70,9 @@ tests_and_config = $(TEST_DIR)/*.flat $(TEST_DIR)/unittests.cfg cstart.o = $(TEST_DIR)/cstart.o -test_cases: $(tests-common) $(tests) +generated_files = $(asm-offsets) + +test_cases: $(generated_files) $(tests-common) $(tests) $(TEST_DIR)/selftest.elf: $(cstart.o) $(TEST_DIR)/selftest.o
lib/arm/.gitignore new file +1 -0
@@ -0,0 +1 @@ +asm-offsets.[hs]
lib/arm/asm-offsets.c new file +39 -0
@@ -0,0 +1,39 @@ +/* +* Adapted from arch/arm/kernel/asm-offsets.c +* +* Copyright (C) 2014, Red Hat Inc, Andrew Jones <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2. +*/ +#include "libcflat.h" +#include "asm/ptrace.h" + +#define DEFINE (sym, val) \ + asm volatile("\n->" #sym " %0 " #val : : "i" (val)) +#define OFFSET (sym, str, mem) DEFINE(sym, offsetof(struct str, mem)) +#define COMMENT (x) asm volatile("\n->#" x) +#define BLANK () asm volatile("\n->" : : ) + +int main (void ) +{ +OFFSET (S_R0 , pt_regs, ARM_r0); +OFFSET (S_R1 , pt_regs, ARM_r1); +OFFSET (S_R2 , pt_regs, ARM_r2); +OFFSET (S_R3 , pt_regs, ARM_r3); +OFFSET (S_R4 , pt_regs, ARM_r4); +OFFSET (S_R5 , pt_regs, ARM_r5); +OFFSET (S_R6 , pt_regs, ARM_r6); +OFFSET (S_R7 , pt_regs, ARM_r7); +OFFSET (S_R8 , pt_regs, ARM_r8); +OFFSET (S_R9 , pt_regs, ARM_r9); +OFFSET (S_R10 , pt_regs, ARM_r10); +OFFSET (S_FP , pt_regs, ARM_fp); +OFFSET (S_IP , pt_regs, ARM_ip); +OFFSET (S_SP , pt_regs, ARM_sp); +OFFSET (S_LR , pt_regs, ARM_lr); +OFFSET (S_PC , pt_regs, ARM_pc); +OFFSET (S_PSR , pt_regs, ARM_cpsr); +OFFSET (S_OLD_R0 , pt_regs, ARM_ORIG_r0); +DEFINE (S_FRAME_SIZE ,sizeof (struct pt_regs )); +return 0 ; +}
lib/arm/asm/asm-offsets.h new file +1 -0
@@ -0,0 +1 @@ +#include "generated/asm-offsets.h"
lib/arm/asm/cp15.h new file +37 -0
@@ -0,0 +1,37 @@ +#ifndef _ASMARM_CP15_H_ +#define _ASMARM_CP15_H_ +/* +* From the Linux kernel arch/arm/include/asm/cp15.h +* +* CR1 bits (CP#15 CR1) +*/ +#define CR_M (1 << 0)/* MMU enable */ +#define CR_A (1 << 1)/* Alignment abort enable */ +#define CR_C (1 << 2)/* Dcache enable */ +#define CR_W (1 << 3)/* Write buffer enable */ +#define CR_P (1 << 4)/* 32-bit exception handler */ +#define CR_D (1 << 5)/* 32-bit data address range */ +#define CR_L (1 << 6)/* Implementation defined */ +#define CR_B (1 << 7)/* Big endian */ +#define CR_S (1 << 8)/* System MMU protection */ +#define CR_R (1 << 9)/* ROM MMU protection */ +#define CR_F (1 << 10)/* Implementation defined */ +#define CR_Z (1 << 11)/* Implementation defined */ +#define CR_I (1 << 12)/* Icache enable */ +#define CR_V (1 << 13)/* Vectors relocated to 0xffff0000 */ +#define CR_RR (1 << 14)/* Round Robin cache replacement */ +#define CR_L4 (1 << 15)/* LDR pc can set T bit */ +#define CR_DT (1 << 16) +#define CR_HA (1 << 17)/* Hardware management of Access Flag */ +#define CR_IT (1 << 18) +#define CR_ST (1 << 19) +#define CR_FI (1 << 21)/* Fast interrupt (lower latency mode) */ +#define CR_U (1 << 22)/* Unaligned access operation */ +#define CR_XP (1 << 23)/* Extended page tables */ +#define CR_VE (1 << 24)/* Vectored interrupts */ +#define CR_EE (1 << 25)/* Exception (Big) Endian */ +#define CR_TRE (1 << 28)/* TEX remap enable */ +#define CR_AFE (1 << 29)/* Access flag enable */ +#define CR_TE (1 << 30)/* Thumb exception enable */ + +#endif /* _ASMARM_CP15_H_ */
lib/arm/asm/ptrace.h new file +100 -0
100 lines not on this page · raw message
lib/generated/.gitignore new file +1 -0
@@ -0,0 +1 @@ +*
Signature · 1 line
1.8.1.4
PATCH v4 19/19 arm: vectors support
In reply to Andrew JonesAdd support for tests to use exception handlers using install_exception_handler(). This patch also adds phys_start_usr(), which can be used to start a function in USR mode, using a stack set up in a new memregion. phys_start_usr() is used by new selftest tests that check the new vector support.
---
v4: a couple tweaks to fit changes in the other patches,
vectors-usr test now has an 8K usr stack
v3:
- squashed in 'arm: Simplify exceptions_init in cstart.S' [Christoffer Dall]
- suggested function name changes and comment additions [Christoffer Dall]
- fix a bug with stack restore from usr mode exceptions that Christoffer pointed out. Add a get_sp() accessor too.
--- arm/cstart.S | 174 ++++++++++++++++++++++++++++++++++++++++++++++++ arm/flat.lds | 7 +- arm/selftest.c | 122 ++++++++++++++++++++++++++++++++- arm/unittests.cfg | 12 ++++ config/config-arm.mak | 3 +- lib/arm/asm/processor.h | 40 +++++++++++ lib/arm/processor.c | 115 ++++++++++++++++++++++++++++++++ lib/libcflat.h | 3 + 8 files changed, 473 insertions(+), 3 deletions(-) create mode 100644 lib/arm/asm/processor.h create mode 100644 lib/arm/processor.c
arm/cstart.S +174 -0
@@ -5,6 +5,10 @@ * * This work is licensed under the terms of the GNU LGPL, version 2. */ +#define __ASSEMBLY__ +#include "asm/asm-offsets.h" +#include "asm/ptrace.h" +#include "asm/cp15.h" .arm
@@ -17,6 +21,13 @@ start: * See the kernel doc Documentation/arm/Booting */ ldr sp, =stacktop + push {r0-r3} + + /* set up vector table and mode stacks */ + bl exceptions_init + + /* complete setup */ + pop {r0-r3} bl setup /* run the test */
@@ -27,9 +38,172 @@ start: bl exit b halt + +.macro set_mode_stack mode, stack + add \stack, #S_FRAME_SIZE + msr cpsr_c, #(\mode | PSR_I_BIT | PSR_F_BIT) + mov sp, \stack +.endm + +exceptions_init: + mrc p15, 0, r2, c1, c0, 0 @ read SCTLR + bic r2, #CR_V @ SCTLR.V := 0 + mcr p15, 0, r2, c1, c0, 0 @ write SCTLR + ldr r2, =vector_table + mcr p15, 0, r2, c12, c0, 0 @ write VBAR + + mrs r2, cpsr + ldr r1, =exception_stacks + + /* first frame reserved for svc mode */ + set_mode_stack UND_MODE, r1 + set_mode_stack ABT_MODE, r1 + set_mode_stack IRQ_MODE, r1 + set_mode_stack FIQ_MODE, r1 + + msr cpsr_cxsf, r2 @ back to svc mode + mov pc, lr + .text .globl halt halt: 1: wfi b 1b + +/* + * Vector stubs + * Simplified version of the Linux kernel implementation + * arch/arm/kernel/entry-armv.S + * + * Each mode has an S_FRAME_SIZE sized stack initialized + * in exceptions_init + */ +.macro vector_stub, name, vec, mode, correction=0 +.align 5 +vector_\name: +.if \correction + sub lr, lr, #\correction +.endif + /* + * Save r0, r1, lr_<exception> (parent PC) + * and spsr_<exception> (parent CPSR) + */ + str r0, [sp, #S_R0] + str r1, [sp, #S_R1] + str lr, [sp, #S_PC] + mrs r0, spsr + str r0, [sp, #S_PSR] + + /* Prepare for SVC32 mode. */ + mrs r0, cpsr + bic r0, #MODE_MASK + orr r0, #SVC_MODE + msr spsr_cxsf, r0 + + /* Branch to handler in SVC mode */ + mov r0, #\vec + mov r1, sp + ldr lr, =vector_common + movs pc, lr +.endm + +vector_stub rst, 0, UND_MODE +vector_stub und, 1, UND_MODE +vector_stub pabt, 3, ABT_MODE, 4 +vector_stub dabt, 4, ABT_MODE, 8 +vector_stub irq, 6, IRQ_MODE, 4 +vector_stub fiq, 7, FIQ_MODE, 4 + +.align 5 +vector_svc: + /* + * Save r0, r1, lr_<exception> (parent PC) + * and spsr_<exception> (parent CPSR) + */ + push { r1 } + ldr r1, =exception_stacks + str r0, [r1, #S_R0] + pop { r0 } + str r0, [r1, #S_R1] + str lr, [r1, #S_PC] + mrs r0, spsr + str r0, [r1, #S_PSR] + + /* + * Branch to handler, still in SVC mode. + * r0 := 2 is the svc vector number. + */ + mov r0, #2 + ldr lr, =vector_common + mov pc, lr + +vector_common: + /* make room for pt_regs */ + sub sp, #S_FRAME_SIZE + tst sp, #4 @ check stack alignment + subne sp, #4 + + /* store registers r0-r12 */ + stmia sp, { r0-r12 } @ stored wrong r0 and r1, fix later + + /* get registers saved in the stub */ + ldr r2, [r1, #S_R0] @ r0 + ldr r3, [r1, #S_R1] @ r1 + ldr r4, [r1, #S_PC] @ lr_<exception> (parent PC) + ldr r5, [r1, #S_PSR] @ spsr_<exception> (parent CPSR) + + /* fix r0 and r1 */ + str r2, [sp, #S_R0] + str r3, [sp, #S_R1] + + /* store sp_svc, if we were in usr mode we'll fix this later */ + add r6, sp, #S_FRAME_SIZE + addne r6, #4 @ stack wasn't aligned + str r6, [sp, #S_SP] + + str lr, [sp, #S_LR] @ store lr_svc, fix later for usr mode + str r4, [sp, #S_PC] @ store lr_<exception> + str r5, [sp, #S_PSR] @ store spsr_<exception> + + /* set ORIG_r0 */ + mov r2, #-1 + str r2, [sp, #S_OLD_R0] + + /* if we were in usr mode then we need sp_usr and lr_usr instead */ + and r1, r5, #MODE_MASK + cmp r1, #USR_MODE + bne 1f + add r1, sp, #S_SP + stmia r1, { sp,lr }^ + + /* Call the handler. r0 is the vector number, r1 := pt_regs */ +1: mov r1, sp + bl do_handle_exception + + /* + * make sure we restore sp_svc on mode change. No need to + * worry about lr_svc though, as that gets clobbered on + * exception entry anyway. + */ + str r6, [sp, #S_SP] + + /* return from exception */ + msr spsr_cxsf, r5 + ldmia sp, { r0-pc }^ + +.align 5 +vector_addrexcptn: + b vector_addrexcptn + +.section .text.ex +.align 5 +vector_table: + b vector_rst + b vector_und + b vector_svc + b vector_pabt + b vector_dabt + b vector_addrexcptn @ should never happen + b vector_irq + b vector_fiq
arm/flat.lds +6 -1
@@ -3,7 +3,12 @@ SECTIONS { .text : { *(.init) *(.text) *(.text.*) } . = ALIGN(4K); - .data : { *(.data) } + .data : { + exception_stacks = .; + . += 4K; + exception_stacks_end = .; + *(.data) + } . = ALIGN(16); .rodata : { *(.rodata) } . = ALIGN(16);
arm/selftest.c +121 -1
141 lines not on this page · raw message
arm/unittests.cfg +12 -0
@@ -16,3 +16,15 @@ file = selftest.flat smp = 1 extra_params = -m 256 -append 'setup smp=1 mem=256' groups = selftest + +# Test vector setup and exception handling (svc mode). +[selftest::vectors-svc] +file = selftest.flat +extra_params = -append 'vectors-svc' +groups = selftest + +# Test vector setup and exception handling (usr mode). +[selftest::vectors-usr] +file = selftest.flat +extra_params = -append 'vectors-usr' +groups = selftest
config/config-arm.mak +2 -1
@@ -39,7 +39,8 @@ cflatobjs += \ lib/virtio-testdev.o \ lib/arm/io.o \ lib/arm/setup.o \ - lib/arm/spinlock.o + lib/arm/spinlock.o \ + lib/arm/processor.o libeabi = lib/arm/libeabi.a eabiobjs = lib/arm/eabi_compat.o
lib/arm/asm/processor.h new file +40 -0
@@ -0,0 +1,40 @@ +#ifndef _ASMARM_PROCESSOR_H_ +#define _ASMARM_PROCESSOR_H_ +/* +* Copyright (C) 2014, Red Hat Inc, Andrew Jones <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2. +*/ +#include "ptrace.h" + +enum vector { +EXCPTN_RST , +EXCPTN_UND , +EXCPTN_SVC , +EXCPTN_PABT , +EXCPTN_DABT , +EXCPTN_ADDREXCPTN , +EXCPTN_IRQ , +EXCPTN_FIQ , +EXCPTN_MAX , +}; + +typedef void (*exception_fn )(struct pt_regs *); +extern void install_exception_handler (enum vector v,exception_fn fn); + +extern void show_regs (struct pt_regs *regs); +extern void *get_sp (void ); + +static inline unsigned long current_cpsr (void ) +{ +unsigned long cpsr; + asmvolatile ("mrs %0, cpsr" :"=r" (cpsr)); +return cpsr; +} + +#define current_mode () (current_cpsr() & MODE_MASK) + +extern void +phys_start_usr (size_t stacksize,void (*func)(void *arg),void *arg); + +#endif /* _ASMARM_PROCESSOR_H_ */
lib/arm/processor.c new file +115 -0
115 lines not on this page · raw message
lib/libcflat.h +3 -0
@@ -66,4 +66,7 @@ do { \abort (); \ } while (0) +#define __stringify_1(x...) #x +#define __stringify(x...) __stringify_1(x) +#endif
Signature · 1 line
1.8.1.4
Re: [PATCH v4 01/19] remove unused files
In reply to Andrew JonesQuoted 6 lines · Andrew Jones
There are several unused files, primarily because powerpc is an unused arch. The exceptions are config-ia64.mak, which is also an unused arch file,
lib/fwcfg.c,lib/panic.c,x86/print.hand x86/run-kvm-unit-tests, which are just unused. Remove them all in order to tidy things up.Signed-off-by Andrew Jones <[email protected]>
Sounds reasonable enough for me, but you probably want an acked-by from the people who actually know if they should care about these files or not.
In any case:
Re: [PATCH v4 02/19] makefile and run_tests tweaks
In reply to Andrew JonesQuoted 6 lines · Andrew Jones
- remove a redundant '-display none'
- remove a redundant -g from CFLAGS
- remove a useless -I../include/x86 from CFLAGS
- remove lib autodep files on make cleanSigned-off-by Andrew Jones <[email protected]>
Re: [PATCH v4 03/19] clean root dir of all x86-ness
In reply to Andrew JonesQuoted 6 lines · Andrew Jones
Remove all references to x86 from the root dir (except from in configure). Also remove references from the root dir README by moving that documentation to the x86/README, and touch up the READMEs at the same time.
Signed-off-by Andrew Jones <[email protected]>
looks reasonable to me.
-Christoffer
Re: [PATCH v4 04/19] add distclean target and gitignore more
In reply to Andrew JonesQuoted 3 lines · Andrew Jones
also add a check for config.mak in
MakefileSigned-off-by Andrew Jones <[email protected]>
Re: [PATCH v4 05/19] add 'make cscope' support
In reply to Andrew JonesQuoted 5 lines · Andrew Jones
Add a
Makefiletarget to quickly generate arch-specific cscope for kvm-unit-tests. Assumes a mostly flat directory structure, i.e. uses '-maxdepth 1' in the file search.Signed-off-by Andrew Jones <[email protected]>
Christoffer Dall
Acked-byRe: [PATCH v4 06/19] libfdt: Import libfdt source
In reply to a message not in the archiveQuoted 7 lines · Andrew Jones
This adds the applicable libfdt source files (unmodified) and a README to explain where the source came from. The README says
The code in this directory is originally imported from the libfdt directory of
git://git.jdl.com/software/dtc.git- version 1.4.0.Signed-off-by Andrew Jones <[email protected]>
obviously I didn't review the libfdt sources, but I agree with the approach:
Re: [PATCH v4 07/19] libfdt: get libfdt to build
In reply to Andrew JonesQuoted 3 lines · Andrew Jones
Add string functions needed for libfdt, and add a make target.
Signed-off-by Andrew Jones <[email protected]>
Re: [PATCH v4 08/19] add support for Linux device trees
In reply to Andrew JonesQuoted 9 lines · Andrew Jones
Add some device tree functions, built on libfdt, to the arch-neutral lib code in order to facilitate the extraction of boot info and device base addresses. These functions should work on device trees conforming to section III of the kernel doc
Documentation/devicetree/booting-without-of.txt.Signed-off-by Andrew Jones <[email protected]>---
v4: reworked everything, added lots of comments todevicetree.h
=> reworked everything
that will make it easy to review again ;)
Quoted 72 lines
--- lib/devicetree.c | 289 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/devicetree.h | 230 +++++++++++++++++++++++++++++++++++++++++++ lib/libcflat.h | 2 + 3 files changed, 521 insertions(+) create mode 100644 lib/devicetree.c create mode 100644 lib/devicetree.hlib/devicetree.c new file +58
-0@@ -0,0 +1,289 @@ +/* +* Copyright (C) 2014, Red Hat Inc, Andrew Jones <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2. +*/ +#include "libcflat.h" +#include "libfdt/libfdt.h" +#include "devicetree.h" + +static const void *fdt; +static u32 root_nr_address_cells, root_nr_size_cells; + +const void *dt_fdt (void ) +{ +return fdt; +} + +bool dt_available (void ) +{ +return fdt_check_header (fdt) ==0 ; +} + +int dt_get_nr_cells (int fdtnode,u32 *nr_address_cells,u32 *nr_size_cells) +{ +const struct fdt_property *prop; +u32 *nr_cells; +int len; + + prop =fdt_get_property (fdt, fdtnode,"#address-cells" , &len); +if (prop ==NULL ) +return len; + + nr_cells = (u32 *)prop->data; + *nr_address_cells =fdt32_to_cpu (*nr_cells); + + prop =fdt_get_property (fdt, fdtnode,"#size-cells" , &len); +if (prop ==NULL ) +return len; + + nr_cells = (u32 *)prop->data; + *nr_size_cells =fdt32_to_cpu (*nr_cells); + +return 0 ; +} + +void dt_reg_init (struct dt_reg *reg,u32 nr_address_cells,u32 nr_size_cells) +{ +memset (reg,0 ,sizeof (struct dt_reg )); + reg->nr_address_cells = nr_address_cells; + reg->nr_size_cells = nr_size_cells; +} + +int dt_get_reg (int fdtnode,int regidx,struct dt_reg *reg) +{ +const struct fdt_property *prop; +u32 *cells, i; +unsigned nr_tuple_cells; +int len;
lib/devicetree.c line 68
Quoted 10 lines
lib/devicetree.c new file +10
-0+ + prop =fdt_get_property (fdt, fdtnode,"reg" , &len); +if (prop ==NULL ) +return len; + + cells = (u32 *)prop->data; + nr_tuple_cells = reg->nr_address_cells + reg->nr_size_cells; + regidx *= nr_tuple_cells; + +if (regidx + nr_tuple_cells > len/sizeof (u32))
Shouldn't this be >= ?
lib/devicetree.c line 81
Quoted 13 lines
lib/devicetree.c new file +13
-0+return -FDT_ERR_NOTFOUND ; + +for (i =0 ; i < reg->nr_address_cells; ++i) + reg->address_cells[i] =fdt32_to_cpu (cells[regidx + i]); + + regidx += reg->nr_address_cells; +for (i =0 ; i < reg->nr_size_cells; ++i) + reg->size_cells[i] =fdt32_to_cpu (cells[regidx + i]); + +return 0 ; +} + +int dt_pbus_translate_node (int fdtnode,int regidx,void *reg)
why doesn't this function take a struct dt_pbus_reg * instead of a void *?
Quoted 170 lines
lib/devicetree.c new file +170
-0+{ +struct dt_pbus_reg *pbus_reg = (struct dt_pbus_reg *)reg; +struct dt_reg raw_reg; +int ret; + +dt_reg_init (&raw_reg, root_nr_address_cells, root_nr_size_cells); + + ret =dt_get_reg (fdtnode, regidx, &raw_reg); +if (ret <0 ) +return ret; + + pbus_reg->addr =dt_pbus_read_cells (raw_reg.nr_address_cells, + raw_reg.address_cells); + pbus_reg->size =dt_pbus_read_cells (raw_reg.nr_size_cells, + raw_reg.size_cells); + +return 0 ; +} + +int dt_pbus_translate (const struct dt_device *dev,int regidx, +void *reg) +{ +return dt_pbus_translate_node (dev->fdtnode, regidx, reg); +} + +int dt_pbus_get_baseaddr (const struct dt_device *dev,dt_pbus_addr_t *base) +{ +struct dt_pbus_reg reg; +int ret; + + ret =dt_pbus_translate (dev,0 , ®); +if (ret <0 ) +return ret; + + *base = reg.addr; +return 0 ; +} + +int dt_bus_match_any(const struct dt_device *dev __unused, int fdtnode) +{ +/* matches any device with a valid node */ +return fdtnode <0 ? fdtnode :1 ; +} + +static const struct dt_bus dt_default_bus = { + .match = dt_bus_match_any, + .translate = dt_pbus_translate, +}; + +void dt_bus_init_defaults (struct dt_bus *bus) +{ +memcpy (bus, &dt_default_bus,sizeof (struct dt_bus )); +} + +void dt_device_init (struct dt_device *dev,const struct dt_bus *bus, +const void *info) +{ +memset (dev,0 ,sizeof (struct dt_device )); + dev->bus = bus; + dev->info = (void *)info; +} + +int dt_device_find_compatible (const struct dt_device *dev, +const char *compatible) +{ +int node, ret; + + node =fdt_node_offset_by_compatible (fdt,-1 , compatible); +while (node >=0 ) { + ret = dev->bus->match (dev, node); +if (ret <0 ) +return ret; +else if (ret) +break ; + node =fdt_node_offset_by_compatible (fdt, node, compatible); + } +return node; +} + +int dt_pbus_get_baseaddr_compatible (const char *compatible, +dt_pbus_addr_t *baseaddr) +{ +struct dt_device dev; +int node, ret; + +dt_device_init (&dev, &dt_default_bus,NULL ); + + node =dt_device_find_compatible (&dev, compatible); +if (node <0 ) +return node; + +dt_device_bind_node (&dev, node); + + ret =dt_pbus_get_baseaddr (&dev, baseaddr); +if (ret <0 ) +return ret; + +return 0 ; +} + +int dt_get_memory_params (struct dt_pbus_reg *regs,int nr_regs) +{ +const char *pn ="device_type" , *pv ="memory" ; +int node, ret, pl =strlen (pv) +1 , nr =0 ; +struct dt_pbus_reg reg; + + node =fdt_node_offset_by_prop_value (fdt,-1 , pn, pv, pl); + +while (node >=0 ) { + +while (nr < nr_regs) { + ret =dt_pbus_translate_node (node, nr, ®); +if (ret == -FDT_ERR_NOTFOUND ) +break ; +if (ret <0 ) +return ret; + regs[nr].addr = reg.addr; + regs[nr].size = reg.size; + ++nr; + } + + node =fdt_node_offset_by_prop_value (fdt, node, pn, pv, pl); + } + +return node != -FDT_ERR_NOTFOUND ? node : nr; +} + +int dt_for_each_cpu_node (void (*func)(int fdtnode,u32 regval,void *info), +void *info) +{ +const struct fdt_property *prop; +int cpus, cpu, ret, len; +struct dt_reg raw_reg; +u32 nac, nsc; + + cpus =fdt_path_offset (fdt,"/cpus" ); +if (cpus <0 ) +return cpus; + + ret =dt_get_nr_cells (cpus, &nac, &nsc); +if (ret <0 ) +return ret; + +dt_reg_init (&raw_reg, nac, nsc); + +dt_for_each_subnode (cpus, cpu) { + + prop =fdt_get_property (fdt, cpu,"device_type" , &len); +if (prop ==NULL ) +return len; + +if (len !=4 ||strcmp ((char *)prop->data,"cpu" )) +continue ; + + ret =dt_get_reg (cpu,0 , &raw_reg); +if (ret <0 ) +return ret; + +func (cpu, raw_reg.address_cells[0 ], info); + } + +return 0 ; +} + +int dt_get_bootargs (const char **bootargs) +{ +const struct fdt_property *prop; +int node, len; + + *bootargs =NULL ;
lib/devicetree.c line 261
Quoted 10 lines
lib/devicetree.c new file +10
-0+ + node =fdt_path_offset (fdt,"/chosen" ); +if (node <0 ) +return node; + + prop =fdt_get_property (fdt, node,"bootargs" , &len); +if (prop) + *bootargs = (char *)prop->data; +else if (len <0 && len != -FDT_ERR_NOTFOUND ) +return len;
so if you get FDT_ERR_NOTFOUND you still return success but the bootargs won't be set? why?
Quoted 48 lines
lib/devicetree.c new file +28
-0+ +return 0 ; +} + +int dt_init (const void *fdt_ptr) +{ +struct dt_bus *defbus = (struct dt_bus *)&dt_default_bus; +int root, ret; + + ret =fdt_check_header (fdt_ptr); +if (ret <0 ) +return ret; + fdt = fdt_ptr; + + root =fdt_path_offset (fdt,"/" ); +if (root <0 ) +return root; + + ret =dt_get_nr_cells (root, &root_nr_address_cells, + &root_nr_size_cells); +if (ret <0 ) +return ret; + + defbus->nr_address_cells = root_nr_address_cells; + defbus->nr_size_cells = root_nr_size_cells; + +return 0 ; +}lib/devicetree.h new file +14
-0@@ -0,0 +1,230 @@ +#ifndef _DEVICETREE_H_ +#define _DEVICETREE_H_ +/* +* devicetree builds on libfdt to implement abstractions and accessors +* for Linux required device tree content. The accessors provided are +* common across architectures. See section III of the kernel doc +* Documentation/devicetree/booting-without-of.txt +* +* Copyright (C) 2014, Red Hat Inc, Andrew Jones <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2. +*/ +#include "libcflat.h" +#include "libfdt/libfdt.h"
lib/devicetree.h line 24
Quoted 10 lines
lib/devicetree.h new file +10
-0+ +/********************************************************************** +* devicetree init and libfdt helpers +**********************************************************************/ + +/* dt_init initializes devicetree with a pointer to an fdt, @fdt_ptr */ +extern int dt_init (const void *fdt_ptr); + +/* get the fdt pointer that devicetree is using */ +const void *dt_fdt (void );
nit: why no extern here?
Quoted 53 lines
lib/devicetree.h new file +53
-0+ +/* check for an initialized, valid devicetree */ +extern bool dt_available (void ); + +/* traverse child nodes */ +#define dt_for_each_subnode (n, s) \ + for (s = fdt_first_subnode(dt_fdt(), n); \ + s != -FDT_ERR_NOTFOUND; \ + s = fdt_next_subnode(dt_fdt(), s)) + +/********************************************************************** +* Abstractions for required node types and properties +**********************************************************************/ + +struct dt_device { +int fdtnode; +const struct dt_bus *bus; + +/* +* info is a pointer to device specific data, which may be +* used by the bus match() and translate() functions +*/ +void *info; +}; + +struct dt_bus { +/* +* match a device @dev to an fdt node @fdtnode +* returns +* - a positive value on match +* - zero on no match +* - a negative FDT_ERR_* value on failure +*/ +int (*match)(const struct dt_device *dev,int fdtnode); + +/* +* translate the @regidx'th "address size" tuple of +* @dev's fdt node's "reg" property, and store the result +* in @reg, a bus specific structure +* returns +* - zero on success +* - a negative FDT_ERR_* value on failure +*/ +int (*translate)(const struct dt_device *dev,int regidx,void *reg); + +/* the bus #address-cells and #size-cells properties */ +u32 nr_address_cells, nr_size_cells; +}; + +/* dt_bus_match_any matches any fdt node, i.e. it always returns true */ +extern int dt_bus_match_any (const struct dt_device *dev,int fdtnode); + +/* the processor bus (pbus) address type and register tuple */
lib/devicetree.h line 87
Quoted 10 lines
lib/devicetree.h new file +10
-0+typedef u64 dt_pbus_addr_t ; +struct dt_pbus_reg { +dt_pbus_addr_t addr; +dt_pbus_addr_t size; +}; + +static inline dt_pbus_addr_t dt_pbus_read_cells (u32 nr_cells,u32 *cells) +{ +return nr_cells ==2 ? ((u64 )cells[0 ] <<32 ) | cells[1 ] + : nr_cells ==1 ? cells[0 ] : (~0ULL );
Why the tertiary operator here? A simple if or select statement should make the code much easier to read and you don't seem to handle #address-cells == 4or #size-cells == 4, despite the fact that you define MAX_ADDRESS_CELLS=4 etc. This seems a bit weird to me.
Quoted 159 lines
lib/devicetree.h new file +143
-0+} + +/* +* dt_pbus_translate translates device node regs for the +* processor bus using the root node's #address-cells and +* #size-cells and dt_pbus_read_cells() +* returns +* - zero on success +* - a negative FDT_ERR_* value on failure +*/ +extern int dt_pbus_translate (const struct dt_device *dev,int regidx, +void *reg); + +/* +* dt_pbus_translate_node is the same as dt_pbus_translate but +* operates on an fdt node instead of a dt_device +*/ +extern int dt_pbus_translate_node (int fdtnode,int regidx,void *reg); + +/* +* dt_pbus_get_baseaddr is a shortcut for +* dt_pbus_translate(dev, 0, ®); +* *base = reg.addr; +* returns +* - zero on success +* - a negative FDT_ERR_* value on failure +*/ +extern int dt_pbus_get_baseaddr (const struct dt_device *dev, +dt_pbus_addr_t *base); + +/* +* dt_bus_init_defaults initializes @bus with +* match <- dt_bus_match_any +* translate <- dt_pbus_translate +* nr_address_cells <- #address-cells of the root node +* nr_size_cells <- #size-cells of the root node +*/ +extern void dt_bus_init_defaults (struct dt_bus *bus); + +/* +* dt_device_init initializes a dt_device with the given parameters +*/ +extern void dt_device_init (struct dt_device *dev,const struct dt_bus *bus, +const void *info); + +static inline void dt_device_bind_node (struct dt_device *dev,int fdtnode) +{ + dev->fdtnode = fdtnode; +} + +/* +* dt_device_find_compatible finds a @compatible node +* returns +* - node (>= 0) on success +* - a negative FDT_ERR_* value on failure +*/ +extern int dt_device_find_compatible (const struct dt_device *dev, +const char *compatible); + +/* +* dt_pbus_get_baseaddr_compatible simply bundles many functions into +* one. It finds the first @compatible fdt node and then translates the +* 0th reg tuple (the base address) using the processor bus translation, +* and finally stores that address in @baseaddr. +* returns +* - zero on success +* - a negative FDT_ERR_* value on failure +*/ +extern int dt_pbus_get_baseaddr_compatible (const char *compatible, +dt_pbus_addr_t *baseaddr); + +/********************************************************************** +* Low-level accessors for required node types and properties +**********************************************************************/ + +/* +* dt_get_nr_cells sets @nr_address_cells and @nr_size_cells to the +* #address-cells and #size-cells properties of @fdtnode +* returns +* - zero on success +* - a negative FDT_ERR_* value on failure +*/ +extern int dt_get_nr_cells (int fdtnode,u32 *nr_address_cells, +u32 *nr_size_cells); + +/* dt_reg is a structure for "raw" reg tuples */ +#define MAX_ADDRESS_CELLS 4 +#define MAX_SIZE_CELLS 4 +struct dt_reg { +u32 nr_address_cells, nr_size_cells; +u32 address_cells[MAX_ADDRESS_CELLS ]; +u32 size_cells[MAX_SIZE_CELLS ]; +}; + +/* +* dt_reg_init initialize a dt_reg struct to zero and sets +* nr_address_cells and nr_size_cells to @nr_address_cells and +* @nr_size_cells respectively. +*/ +extern void dt_reg_init (struct dt_reg *reg,u32 nr_address_cells, +u32 nr_size_cells); + +/* +* dt_get_reg gets the @regidx'th reg tuple of @fdtnode's reg property +* and stores it in @reg. @reg must be initialized. +* returns +* - zero on success +* - a negative FDT_ERR_* value on failure +*/ +extern int dt_get_reg (int fdtnode,int regidx,struct dt_reg *reg); + +/********************************************************************** +* High-level accessors for required node types and properties +**********************************************************************/ + +/* +* dt_get_bootargs gets a pointer to /chosen/bootargs +* returns +* - zero on success +* - a negative FDT_ERR_* value on failure +*/ +extern int dt_get_bootargs (const char **bootargs); + +/* +* dt_get_memory_params gets the memory parameters from the /memory node(s) +* storing each memory region ("address size" tuple) in consecutive entries +* of @regs, up to @nr_regs +* returns +* - number of memory regions found on success +* - a negative FDT_ERR_* value on failure +*/ +extern int dt_get_memory_params (struct dt_pbus_reg *regs,int nr_regs); + +/* +* dt_for_each_cpu_node runs @func on each cpu node in the /cpus node +* passing it its fdt node, its reg property value, and @info +* - zero on success +* - a negative FDT_ERR_* value on failure +*/ +extern int dt_for_each_cpu_node (void (*func)(int fdtnode,u32 regval, +void *info),void *info); + +#endif /* _DEVICETREE_H_ */ lib/libcflat.h +2
-0@@ -22,6 +22,8 @@#include <stdarg.h> +#define __unused __attribute__((__unused__)) +typedef unsigned char u8 ;typedef signed char s8 ;typedef unsigned short u16 ;Signature · 1 line
1.8.1.4
-Christoffer
Re: [PATCH v4 09/19] libcflat: add abort() and assert()
In reply to Andrew JonesQuoted 7 lines · Andrew Jones
The test framework may have external dependencies.
assert()provides the ability to abort when those dependencies aren't met. However,assert()should only be used for unlikely conditions. We can provide more informative messages withprintf()for the more likely problems.Signed-off-by Andrew Jones <[email protected]>---
Re: [PATCH v4 10/19] Introduce asm-generic/*.h files
In reply to Andrew JonesQuoted 61 lines · Andrew Jones
Architecture neutral code may need to call low-level io accessors, or use spinlocks. Create a generic
io.hto ensure those accessors are defined, and a genericspinlock.hthat complains when included, as we can't write a generic spinlock. These files can be overridden or extended by architecture specific versions placed inlib/$ARCH/asm/.Signed-off-by Andrew Jones <[email protected]>---
v4: introduce lib/asm symlink to get rid of #ifdef__arm__,
addspinlock.htoo
v3: wrt toio.h(was libio.[ch]) only
- get rid ofCONFIG_64BIT, replace with asserts
- get rid of {read,write}_len() [libio.c]
- fix bad *64_to_cpu macros--- .gitignore | 1 + Makefile | 6 +- configure | 11 ++++ lib/asm-generic/io.h | 154 +++++++++++++++++++++++++++++++++++++++++++++ lib/asm-generic/spinlock.h | 4 ++ 5 files changed, 173 insertions(+), 3 deletions(-) create mode 100644 lib/asm-generic/io.h create mode 100644 lib/asm-generic/spinlock.h.gitignore +1
-0@@ -9,6 +9,7 @@ patches .stgit-* cscope.* *.swp +/lib/asm /config.mak /*-run /test.logMakefile +3
-3@@ -76,11 +76,11 @@ libfdt_clean: $(LIBFDT_objdir)/.*.d distclean: clean libfdt_clean - $(RM) config.mak $(TEST_DIR)-run test.log msr.out cscope.* + $(RM) lib/asm config.mak $(TEST_DIR)-run test.log msr.out cscope.* -cscope: common_dirs = lib lib/libfdt +cscope: common_dirs = lib lib/libfdt lib/asm lib/asm-generic cscope: $(RM) ./cscope.* - find $(TEST_DIR) lib/$(TEST_DIR) $(common_dirs) -maxdepth 1 \ + find -L $(TEST_DIR) lib/$(TEST_DIR) $(common_dirs) -maxdepth 1 \ -name '*.[chsS]' -print | sed 's,^\./,,' > ./cscope.files cscope -bkconfigure +0
-0
configure if [ $exit -eq 0 ]; then · line 104
Quoted 10 lines
configure +7
-0@@ -95,6 +95,17 @@ if [ $exit -eq 0 ]; then fi rm -f lib_test.c +# link lib/asm for the architecture +rm -f lib/asm +asm=asm-generic +if [ -d lib/$arch/asm ]; then + asm=$arch/asm +elif [ -d lib/$testdir/asm ]; then + asm=$testdir/asm
why do you need this elif? can you not make sure arch is always set?
configure if [ $exit -eq 0 ]; then · line 111
Quoted 7 lines
configure +4
-0+fi +ln -s $asm lib/asm + +# create the config cat <<EOF > config.mak PREFIX=$prefix KERNELDIR=$(readlink -f $kerneldir)
[...]
-Christoffer
Re: [PATCH v4 11/19] add minimal virtio support for devtree virtio-mmio
In reply to Andrew JonesQuoted 136 lines · Andrew Jones
Support the bare minimum of virtio to enable access to the virtio-mmio config space of a device. Currently this implementation must use a device tree to find the device.
Signed-off-by Andrew Jones <[email protected]>---
v4:
- split from the virtio-testdev patch
- search a table to "discover" that the device must be DT/virtio-mmio, which doesn't change anything, but looks less hacky than comments saying the device must be DT/virtio-mmio...
- manage own pool of virtio-mmio pre-allocated device structures in order to avoid needing access to the heap--- lib/libcflat.h | 3 ++ lib/virtio.c | 166 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/virtio.h | 89 +++++++++++++++++++++++++++++++ 3 files changed, 258 insertions(+) create mode 100644 lib/virtio.c create mode 100644 lib/virtio.hlib/libcflat.h +3
-0@@ -62,6 +62,9 @@ extern long atol(const char *ptr);#define ARRAY_SIZE (_a) (sizeof(_a)/sizeof((_a)[0]))#define offsetof (TYPE ,MEMBER ) __builtin_offsetof (TYPE, MEMBER) +#define container_of (ptr, type, member) ({ \ + const typeof( ((type *)0)->member ) *__mptr = (ptr); \ + (type *)( (char *)__mptr - offsetof(type,member) );})#define NULL ((void *)0UL)lib/virtio.c new file +95
-0@@ -0,0 +1,166 @@ +/* +* Copyright (C) 2014, Red Hat Inc, Andrew Jones <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2. +*/ +#include "libcflat.h" +#include "devicetree.h" +#include "asm/spinlock.h" +#include "asm/io.h" +#include "virtio.h" + +enum virtio_hwdesc_type { +VIRTIO_HWDESC_TYPE_DT =0 ,/* device tree */ +NR_VIRTIO_HWDESC_TYPES , +}; + +enum virtio_bus_type { +VIRTIO_BUS_TYPE_MMIO =0 ,/* virtio-mmio */ +NR_VIRTIO_BUS_TYPES , +}; + +struct virtio_bind_bus { +bool (*hwdesc_probe)(void ); +struct virtio_dev *(*device_bind)(u32 devid); +}; + +static struct virtio_dev *vm_dt_device_bind (u32 devid); + +static struct virtio_bind_bus +virtio_bind_busses[NR_VIRTIO_HWDESC_TYPES ][NR_VIRTIO_BUS_TYPES ] = { + +[VIRTIO_HWDESC_TYPE_DT ] = { + + [VIRTIO_BUS_TYPE_MMIO ] = { + .hwdesc_probe = dt_available, + .device_bind = vm_dt_device_bind, + }, +}, +}; + +struct virtio_dev *virtio_bind (u32 devid) +{ +struct virtio_bind_bus *bus; +struct virtio_dev *dev; +int i, j; + +for (i =0 ; i <NR_VIRTIO_HWDESC_TYPES ; ++i) { +for (j =0 ; j <NR_VIRTIO_BUS_TYPES ; ++j) { + + bus = &virtio_bind_busses[i][j]; + +if (!bus->hwdesc_probe ()) +continue ; + + dev = bus->device_bind (devid); +if (dev) +return dev; + } + } + +return NULL ; +} + +/****************************************************** +* virtio-mmio support (config space only) +******************************************************/ + +static void vm_get (struct virtio_dev *vdev,unsigned offset, +void *buf,unsigned len) +{ +struct virtio_mmio_dev *vmdev =to_virtio_mmio_dev (vdev); +u8 *p = buf; +unsigned i; + +for (i =0 ; i < len; ++i) + p[i] =readb (vmdev->base +VIRTIO_MMIO_CONFIG + offset + i); +} + +static void vm_set (struct virtio_dev *vdev,unsigned offset, +const void *buf,unsigned len) +{ +struct virtio_mmio_dev *vmdev =to_virtio_mmio_dev (vdev); +const u8 *p = buf; +unsigned i; + +for (i =0 ; i < len; ++i) +writeb (p[i], vmdev->base +VIRTIO_MMIO_CONFIG + offset + i); +} + +#define NR_VM_DEVICES 32 +static struct spinlock vm_lock; +static struct virtio_mmio_dev vm_devs[NR_VM_DEVICES ]; +static struct virtio_conf_ops vm_confs[NR_VM_DEVICES ]; +static int nr_vm_devs; +
lib/virtio.c line 105
Quoted 10 lines
lib/virtio.c new file +10
-0+static struct virtio_mmio_dev *vm_new_device (u32 devid) +{ +struct virtio_mmio_dev *vmdev; + +if (nr_vm_devs >=NR_VM_DEVICES ) +return NULL ; + +spin_lock (&vm_lock); + vmdev = &vm_devs[nr_vm_devs]; + vmdev->vdev.config = &vm_confs[nr_vm_devs];
this seems a bit weird, will we ever share vm_confs between vm_devs or change the vm_conf pointer later on? Could vm_conf just be part of the vm_dev struct and you could just have a virtio_mmio_conf_init() to set the get/set functions?
Quoted 8 lines
lib/virtio.c new file +8
-0+ ++nr_vm_devs; +spin_unlock (&vm_lock); + + vmdev->vdev.id.device = devid; + vmdev->vdev.id.vendor =-1 ; + vmdev->vdev.config->get = vm_get; + vmdev->vdev.config->set = vm_set; +
lib/virtio.c line 123
Quoted 10 lines
lib/virtio.c new file +10
-0+return vmdev; +} + +/****************************************************** +* virtio-mmio device tree support +******************************************************/ + +struct vm_dt_info { +u32 devid; +void *base;
won't work for LPAE and 32-bit arm systems, can't you use dt_device_bind_node?
I guess that requires you to have an ioremap function, but it sure seems cleaner to give up there if you don't have proper memory mapping features yet....
lib/virtio.c line 134
Quoted 11 lines
lib/virtio.c new file +11
-0+}; + +static int vm_dt_match (const struct dt_device *dev,int fdtnode) +{ +struct vm_dt_info *info = (struct vm_dt_info *)dev->info; +dt_pbus_addr_t base; + +dt_device_bind_node ((struct dt_device *)dev, fdtnode); + +assert (dt_pbus_get_baseaddr (dev, &base) ==0 ); +assert (sizeof (long ) ==8 || !(base >>32 ));
again, this assert will break with >32bit LPAE addresses on 32-bit arm systems.
so, not sure if it's an assert, or if you should test for it and print a more benign error for these types of devices.
lib/virtio.c line 136
Quoted 2 lines
lib/virtio.c new file +2
-0+ + info->base = (void *)(unsigned long )base;
why do you need to cast it twice?
Quoted 128 lines
lib/virtio.c new file +30
-0+ +return readl (info->base +VIRTIO_MMIO_DEVICE_ID ) == info->devid; +} + +static struct virtio_dev *vm_dt_device_bind (u32 devid) +{ +struct virtio_mmio_dev *vmdev; +struct dt_device dt_dev; +struct dt_bus dt_bus; +struct vm_dt_info info; +int node; + +dt_bus_init_defaults (&dt_bus); + dt_bus.match = vm_dt_match; + + info.devid = devid; + +dt_device_init (&dt_dev, &dt_bus, &info); + + node =dt_device_find_compatible (&dt_dev,"virtio,mmio" ); +assert (node >=0 || node == -FDT_ERR_NOTFOUND ); + +if (node == -FDT_ERR_NOTFOUND ) +return NULL ; + + vmdev =vm_new_device (devid); + vmdev->base = info.base; + +return &vmdev->vdev; +}lib/virtio.h new file +89
-0@@ -0,0 +1,89 @@ +#ifndef _VIRTIO_H_ +#define _VIRTIO_H_ +/* +* A minimal implementation of virtio for virtio-mmio config space +* access. +* +* Copyright (C) 2014, Red Hat Inc, Andrew Jones <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2. +*/ +#include "libcflat.h" + +struct virtio_devid { +u32 device; +u32 vendor; +}; + +struct virtio_dev { +struct virtio_devid id; +struct virtio_conf_ops *config; +}; + +struct virtio_conf_ops { +void (*get)(struct virtio_dev *vdev,unsigned offset, +void *buf,unsigned len); +void (*set)(struct virtio_dev *vdev,unsigned offset, +const void *buf,unsigned len); +}; + +extern struct virtio_dev *virtio_bind (u32 devid); + +static inline u8 +virtio_config_readb (struct virtio_dev *vdev,unsigned offset) +{ +u8 val; + vdev->config->get (vdev, offset, &val,1 ); +return val; +} + +static inline u16 +virtio_config_readw (struct virtio_dev *vdev,unsigned offset) +{ +u16 val; + vdev->config->get (vdev, offset, &val,2 ); +return val; +} + +static inline u32 +virtio_config_readl (struct virtio_dev *vdev,unsigned offset) +{ +u32 val; + vdev->config->get (vdev, offset, &val,4 ); +return val; +} + +static inline void +virtio_config_writeb (struct virtio_dev *vdev,unsigned offset,u8 val) +{ + vdev->config->set (vdev, offset, &val,1 ); +} + +static inline void +virtio_config_writew (struct virtio_dev *vdev,unsigned offset,u16 val) +{ + vdev->config->set (vdev, offset, &val,2 ); +} + +static inline void +virtio_config_writel (struct virtio_dev *vdev,unsigned offset,u32 val) +{ + vdev->config->set (vdev, offset, &val,4 ); +} + +/****************************************************** +* virtio-mmio +******************************************************/ + +#define VIRTIO_MMIO_DEVICE_ID 0x008 +#define VIRTIO_MMIO_CONFIG 0x100 + +#define to_virtio_mmio_dev (vdev_ptr) \ + container_of(vdev_ptr, struct virtio_mmio_dev, vdev) + +struct virtio_mmio_dev { +struct virtio_dev vdev; +void *base; +}; + +#endif /* _VIRTIO_H_ */ Signature · 1 line
1.8.1.4
-Christoffer
Re: [PATCH v4 12/19] Introduce virtio-testdev
In reply to Andrew JonesQuoted 6 lines · Andrew Jones
virtio-testdev is a communication channel to qemu through virtio that can be used by test code to send commands. The only command currently implemented is EXIT, which allows the test code to exit with a given status code.
Signed-off-by Andrew Jones <[email protected]>
Re: [PATCH v4 13/19] libcflat: clean up libcflat.h and add string.h
In reply to Andrew JonesQuoted 8 lines · Andrew Jones
Use libgcc's
stddef.handstdint.h, and then remove the redundant defines fromlibcflat.h. Also separate out the string function declarations into a new filestring.h. These changes have no affect on code includinglibcflat.h, but are needed in order to compile an unmodified libfdt for kvm-unit-tests using an arm cross-compiler. While at it, add strcpy.Signed-off-by Andrew Jones <[email protected]>
Re: [PATCH v4 14/19] printf: support field padding
In reply to Andrew JonesQuoted 4 lines · Andrew Jones
Support format flags for field padding, such as "%08x", allowing register dumps to be easier on the eyes.
Signed-off-by Andrew Jones <[email protected]>
I think I gave this my Reviewed-by in the last round, and there is no changelog. If anything changed here, let me know, otherwise apply the tag.
-Christoffer
Re: [PATCH v4 15/19] arm: initial drop
In reply to Andrew JonesQuoted 162 lines · Andrew Jones
This is the initial drop of the arm test framework and a first test that just checks that setup completed (a selftest). kvm isn't needed to run this test unless testing with smp > 1.
Try it out with
yum install gcc-arm-linux-gnu
export QEMU=[qemu with mach-virt and virtio-testdev] ./configure --cross-prefix=arm-linux-gnu- --arch=arm make
./run_tests.shSigned-off-by Andrew Jones <[email protected]>---
v4:
- moved fdt to just after stacktop (it was in the middle of free memory)
- switched from using heap to memregions
- getnr_cpusand added smp=<num> test
- addedbarrier.h
- use new report()/report_summary()
- config/config-arm.mak cleanup--- arm/cstart.S | 35 ++++++++++++ arm/flat.lds | 18 +++++++ arm/run | 31 +++++++++++ arm/selftest.c | 87 ++++++++++++++++++++++++++++++ arm/unittests.cfg | 18 +++++++ config/config-arm.mak | 72 +++++++++++++++++++++++++ configure | 12 ++++- lib/argv.c | 6 +++ lib/arm/asm/barrier.h | 18 +++++++ lib/arm/asm/io.h | 24 +++++++++ lib/arm/asm/setup.h | 39 ++++++++++++++ lib/arm/asm/spinlock.h | 16 ++++++ lib/arm/eabi_compat.c | 20 +++++++ lib/arm/io.c | 66 +++++++++++++++++++++++ lib/arm/setup.c | 142 +++++++++++++++++++++++++++++++++++++++++++++++++ 15 files changed, 602 insertions(+), 2 deletions(-) create mode 100644 arm/cstart.S create mode 100644 arm/flat.lds create mode 100755 arm/run create mode 100644 arm/selftest.c create mode 100644 arm/unittests.cfg create mode 100644 config/config-arm.mak create mode 100644 lib/arm/asm/barrier.h create mode 100644 lib/arm/asm/io.h create mode 100644 lib/arm/asm/setup.h create mode 100644 lib/arm/asm/spinlock.h create mode 100644 lib/arm/eabi_compat.c create mode 100644 lib/arm/io.c create mode 100644 lib/arm/setup.carm/cstart.S new file +35
-0@@ -0,0 +1,35 @@ +/* + * Boot entry point and assembler functions for armv7 tests. + * + * Copyright (C) 2014, Red Hat Inc, Andrew Jones <[email protected]> + * + * This work is licensed under the terms of the GNU LGPL, version 2. + */ + +.arm + +.section .init + +.globl start +start: + /* + * bootloader params are in r0-r2 + * See the kernel doc Documentation/arm/Booting + */ + ldr sp, =stacktop + bl setup + + /* run the test */ + ldr r0, =__argc + ldr r0, [r0] + ldr r1, =__argv + bl main + bl exit + b halt + +.text + +.globl halt +halt: +1: wfi + b 1barm/flat.lds new file +18
-0@@ -0,0 +1,18 @@ + +SECTIONS +{ + .text : { *(.init) *(.text) *(.text.*) } + . = ALIGN(4K); + .data : { *(.data) } + . = ALIGN(16); + .rodata : { *(.rodata) } + . = ALIGN(16); + .bss : { *(.bss) } + . = ALIGN(4K); + edata = .; + . += 8K; + . = ALIGN(4K); + stacktop = .; +} + +ENTRY(start)arm/run new file +31
-0@@ -0,0 +1,31 @@ +#!/bin/bash + +if [ ! -f config.mak ]; then + echo run ./configure first. See ./configure -h + exit 2 +fi +source config.mak + +qemu="${QEMU:-qemu-system-arm}" +testdev=virtio-testdev + +if ! $qemu -device '?' 2>&1 | grep $testdev > /dev/null; then + qpath=$(which $qemu 2>/dev/null) + if [ "$qpath" ]; then + echo $qpath doesn\'t support virtio-testdev. Exiting. + else + echo $qemu not found. + fi + exit 2 +fi + +command="$qemu -device $testdev -display none -serial stdio " +command+="-M virt -cpu $PROCESSOR " +#command+="-enable-kvm " +command+="-kernel" + +echo $command "$@" +$command "$@" +ret=$? +echo Return value from qemu: $ret +exit $retarm/selftest.c new file +3
-0@@ -0,0 +1,87 @@ +/* +* Test the framework itself. These tests confirm that setup works. +*
arm/selftest.c line 13
Quoted 10 lines
arm/selftest.c new file +10
-0+* Copyright (C) 2014, Red Hat Inc, Andrew Jones <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2. +*/ +#include "libcflat.h" +#include "asm/setup.h" + +#define TESTGRP "selftest" + +static char testnam[64 ];
is testnam testname?
Quoted 323 lines
arm/selftest.c new file +74
-0+ +static void testnam_set (const char *subtest) +{ +strcpy (testnam,TESTGRP ); +strcat (testnam,"::" ); +strcat (testnam, subtest); +} + +static void assert_args (int num_args,int needed_args) +{ +if (num_args < needed_args) { +printf ("%s: not enough arguments\n" , testnam); +abort (); + } +} + +static char *split_var (char *s,long *val) +{ +char *p; + + p =strchr (s,'=' ); +if (!p) +return NULL ; + + *val =atol (p+1 ); + *p ='\0' ; + +return s; +} + +static void check_setup (int argc,char **argv) +{ +int nr_tests =0 , i; +char *var; +long val; + +for (i =0 ; i < argc; ++i) { + + var =split_var (argv[i], &val); +if (!var) +continue ; + +if (strcmp (argv[i],"mem" ) ==0 ) { + +phys_addr_t memsize = + memregions[nr_memregions-1 ].addr + + memregions[nr_memregions-1 ].size + -PHYS_OFFSET ; +phys_addr_t expected = ((phys_addr_t )val)*1024 *1024 ; + +report ("%s[%s]" , memsize == expected, testnam,"mem" ); + ++nr_tests; + + }else if (strcmp (argv[i],"smp" ) ==0 ) { + +report ("%s[%s]" , nr_cpus == (int )val, testnam,"smp" ); + ++nr_tests; + } + } + +assert_args (nr_tests,2 ); +} + +int main (int argc,char **argv) +{ +assert_args (argc,1 ); + +testnam_set (argv[0 ]); + +if (strcmp (argv[0 ],"setup" ) ==0 ) +check_setup (argc-1 , &argv[1 ]); + +return report_summary (); +}arm/unittests.cfg new file +18
-0@@ -0,0 +1,18 @@ +# Define your new unittest following the convention: +# [unittest_name] +# file = foo.flat # Name of the flat file to be used +# smp = 2 # Number of processors the VM will use during this test +# extra_params = -append <params...> # Additional parameters used +# arch = arm/arm64 # Only if test case is specific to one +# groups = group1 group2 # Used to identify test cases with run_tests -g ... + +# +# Test that the configured number of processors (smp = <num>), and +# that the configured amount of memory (-m <MB>) are correctly setup +# by the framework. +# +[selftest::setup] +file = selftest.flat +smp = 1 +extra_params = -m 256 -append 'setup smp=1 mem=256' +groups = selftestconfig/config-arm.mak new file +72
-0@@ -0,0 +1,72 @@ +# +# arm makefile +# +# Authors: Andrew Jones <[email protected]> +# + +tests-common = \ + $(TEST_DIR)/selftest.flat + +tests = + +all: test_cases + +################################################################## +bits = 32 +ldarch = elf32-littlearm + +ifeq ($(LOADADDR),) + LOADADDR = 0x40000000 +endif +phys_base = $(LOADADDR) +kernel_offset = 0x10000 + +CFLAGS += -D__arm__ +CFLAGS += -marm +CFLAGS += -mcpu=$(PROCESSOR) +CFLAGS += -std=gnu99 +CFLAGS += -ffreestanding +CFLAGS += -Wextra +CFLAGS += -O2 +CFLAGS += -I lib -I lib/libfdt + +cflatobjs += \ + lib/devicetree.o \ + lib/virtio.o \ + lib/virtio-testdev.o \ + lib/arm/io.o \ + lib/arm/setup.o + +libeabi = lib/arm/libeabi.a +eabiobjs = lib/arm/eabi_compat.o + +libgcc := $(shell $(CC) -m$(ARCH) --print-libgcc-file-name) +start_addr := $(shell printf "%x\n" $$(( $(phys_base) + $(kernel_offset) ))) + +FLATLIBS = $(libcflat) $(LIBFDT_archive) $(libgcc) $(libeabi) +%.elf: LDFLAGS = $(CFLAGS) -nostdlib +%.elf: %.o $(FLATLIBS) arm/flat.lds + $(CC) $(LDFLAGS) -o $@ \ + -Wl,-T,arm/flat.lds,--build-id=none,-Ttext=$(start_addr) \ + $(filter %.o, $^) $(FLATLIBS) + +%.flat: %.elf + $(OBJCOPY) -O binary $^ $@ + +$(libeabi): $(eabiobjs) + $(AR) rcs $@ $^ + +arch_clean: libfdt_clean + $(RM) $(TEST_DIR)/*.{o,flat,elf} $(libeabi) $(eabiobjs) \ + $(TEST_DIR)/.*.d lib/arm/.*.d + +################################################################## + +tests_and_config = $(TEST_DIR)/*.flat $(TEST_DIR)/unittests.cfg + +cstart.o = $(TEST_DIR)/cstart.o + +test_cases: $(tests-common) $(tests) + +$(TEST_DIR)/selftest.elf: $(cstart.o) $(TEST_DIR)/selftest.o +configure +10
-2@@ -6,8 +6,7 @@ cc=gcc ld=ld objcopy=objcopy ar=ar -arch=`uname -m | sed -e s/i.86/i386/` -processor="$arch" +arch=`uname -m | sed -e s/i.86/i386/ | sed -e 's/arm.*/arm/'` cross_prefix= usage() {@@ -17,6 +16,7 @@ usage() { Options include: --test-dir=DIR the main directory for tests ($arch) --arch=ARCH architecture to compile for ($arch) + --processor=PROCESSOR processor to compile for ($arch) --cross-prefix=PREFIX cross compiler prefix --cc=CC c compiler to use ($cc) --ld=LD ld linker to use ($ld)@@ -66,6 +66,12 @@ while [[ "$1" = -* ]]; do ;; esac done +[ -z "$processor" ] && processor="$arch" + +if [ "$processor" = "arm" ]; then + processor="cortex-a15" +fi + if [ -z "$testdir" -a \( "$arch" = "i386" -o "$arch" = "x86_64" \) ]; then testdir=x86 elif [ -z "$testdir" ]; then@@ -80,6 +86,7 @@ if [ -f $testdir/run ]; then fi # check for dependent 32 bit libraries +if [ "$arch" != "arm" ]; then cat << EOF > lib_test.c #include <stdc++.h> #include <boost_thread-mt.h>@@ -94,6 +101,7 @@ if [ $exit -eq 0 ]; then api=true fi rm -f lib_test.c +fi # link lib/asm for the architecture rm -f lib/asmlib/argv.c +6
-0@@ -31,3 +31,9 @@ void __setup_args(void) } __argc = argv - __argv; } + +void setup_args (char *args) +{ + __args = args; +__setup_args (); +}lib/arm/asm/barrier.h new file +18
-0@@ -0,0 +1,18 @@ +#ifndef _ASMARM_BARRIER_H_ +#define _ASMARM_BARRIER_H_ +/* +* Adapted form arch/arm/include/asm/barrier.h +*/ + +#define isb (option) __asm__ __volatile__ ("isb " #option : : : "memory") +#define dsb (option) __asm__ __volatile__ ("dsb " #option : : : "memory") +#define dmb (option) __asm__ __volatile__ ("dmb " #option : : : "memory") + +#define mb () dsb() +#define rmb () dsb() +#define wmb () dsb(st) +#define smp_mb () dmb(ish) +#define smp_rmb () smp_mb() +#define smp_wmb () dmb(ishst) + +#endif /* _ASMARM_BARRIER_H_ */ lib/arm/asm/io.h new file +24
-0@@ -0,0 +1,24 @@ +#ifndef _ASMARM_IO_H_ +#define _ASMARM_IO_H_ +#include "libcflat.h" +#include "asm/barrier.h" + +#define __bswap16 bswap16 +static inline u16 bswap16 (u16 val) +{ +u16 ret; + asmvolatile ("rev16 %0, %1" :"=r" (ret) :"r" (val)); +return ret; +} + +#define __bswap32 bswap32 +static inline u32 bswap32 (u32 val) +{ +u32 ret; + asmvolatile ("rev %0, %1" :"=r" (ret) :"r" (val)); +return ret; +} + +#include "asm-generic/io.h" + +#endif /* _ASMARM_IO_H_ */ lib/arm/asm/setup.h new file +22
-0@@ -0,0 +1,39 @@ +#ifndef _ASMARM_SETUP_H_ +#define _ASMARM_SETUP_H_ +/* +* Copyright (C) 2014, Red Hat Inc, Andrew Jones <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2. +*/ +#include "libcflat.h" + +#define NR_CPUS 8 +extern u32 cpus[NR_CPUS ]; +extern int nr_cpus; + +typedef u64 phys_addr_t ; + +#define NR_MEMREGIONS 16 +struct memregion { +phys_addr_t addr; +phys_addr_t size; +bool free; +}; +
lib/arm/asm/setup.h line 32
Quoted 10 lines
lib/arm/asm/setup.h new file +10
-0+extern struct memregion memregions[NR_MEMREGIONS ]; +extern int nr_memregions; + +extern struct memregion *memregion_new (phys_addr_t size); +extern void memregions_show (void ); + +#define PHYS_OFFSET ({ memregions[0].addr; }) +#define PHYS_SHIFT 40 +#define PHYS_SIZE (1ULL << PHYS_SHIFT) +#define PHYS_MASK (PHYS_SIZE - 1ULL)
it's pretty funky that you define PHYS_MASK the opposite of PAGE_MASK?
Quoted 90 lines
lib/arm/asm/setup.h new file +7
-0+ +#define PAGE_SHIFT 12 +#define PAGE_SIZE (1UL << PAGE_SHIFT) +#define PAGE_MASK (~(PAGE_SIZE - 1UL)) +#define PAGE_ALIGN (addr) (((addr) + (PAGE_SIZE-1UL)) & PAGE_MASK) + +#endif /* _ASMARM_SETUP_H_ */ lib/arm/asm/spinlock.h new file +16
-0@@ -0,0 +1,16 @@ +#ifndef _ASMARM_SPINLOCK_H_ +#define _ASMARM_SPINLOCK_H_ + +struct spinlock { +int v; +}; + +//TODO +static inline void spin_lock(struct spinlock *lock __unused) +{ +} +static inline void spin_unlock(struct spinlock *lock __unused) +{ +} + +#endif /* _ASMARM_SPINLOCK_H_ */ lib/arm/eabi_compat.c new file +20
-0@@ -0,0 +1,20 @@ +/* +* Adapted from u-boot's arch/arm/lib/eabi_compat.c +*/ +#include "libcflat.h" + +int raise(int signum __unused) +{ +printf ("Divide by zero!\n" ); +abort (); +return 0 ; +} + +/* Dummy functions to avoid linker complaints */ +void __aeabi_unwind_cpp_pr0 (void ) +{ +} + +void __aeabi_unwind_cpp_pr1 (void ) +{ +}lib/arm/io.c new file +29
-0@@ -0,0 +1,66 @@ +/* +* Each architecture must implement puts() and exit() with the I/O +* devices exposed from QEMU, e.g. pl011 and virtio-testdev. That's +* what's done here, along with initialization functions for those +* devices. +* +* Copyright (C) 2014, Red Hat Inc, Andrew Jones <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2. +*/ +#include "libcflat.h" +#include "devicetree.h" +#include "virtio-testdev.h" +#include "asm/spinlock.h" +#include "asm/io.h" + +extern void halt (int code); + +/* +* Use this guess for the pl011 base in order to make an attempt at +* having earlier printf support. We'll overwrite it with the real +* base address that we read from the device tree later. +*/ +#define QEMU_MACH_VIRT_PL011_BASE 0x09000000UL + +static struct spinlock uart_lock; +static volatile u8 *uart0_base = (u8 *)QEMU_MACH_VIRT_PL011_BASE ; + +static void uart0_init (void )
lib/arm/io.c line 39
Quoted 10 lines
lib/arm/io.c new file +10
-0+{ +const char *compatible ="arm,pl011" ; +dt_pbus_addr_t base; +int ret; + + ret =dt_pbus_get_baseaddr_compatible (compatible, &base); +assert (ret ==0 || ret == -FDT_ERR_NOTFOUND ); + +if (ret ==0 ) { +assert (sizeof (long ) ==8 || !(base >>32 ));
didn't we already check this somewhere? Or was that virtio specific?
This confirms my suspicion that you should add a dummy identity ioremap function that can do this check once.
lib/arm/io.c line 40
Quoted 1 line
lib/arm/io.c new file +1
-0+ uart0_base = (u8 *)(unsigned long )base;
hmmm, u8*, I guess that sort of makes sense...
lib/arm/io.c line 44
Quoted 4 lines
lib/arm/io.c new file +4
-0+ }else { +printf ("%s: %s not found in the device tree, aborting...\n" , + __func__, compatible); +abort ();
I think this function would read nicer if you did this right after your assert:
if (ret) {
printf(....);
abort();
}uart0_base = ....;
Quoted 28 lines
lib/arm/io.c new file +22
-0+ } +} + +void io_init (void ) +{ +uart0_init (); +virtio_testdev_init (); +} + +void puts (const char *s) +{ +spin_lock (&uart_lock); +while (*s) +writel (*s++, uart0_base); +spin_unlock (&uart_lock); +} + +void exit (int code) +{ +virtio_testdev_exit (code); +halt (code); +}lib/arm/setup.c new file +0
-0
lib/arm/setup.c line 4
Quoted 4 lines
lib/arm/setup.c new file +4
-0@@ -0,0 +1,142 @@ +/* +* Initialize machine setup information and I/O. +* +* After running setup() a flat file knows how many cpus it has
'a flat file knows' ?
Quoted 19 lines
lib/arm/setup.c new file +19
-0+* (nr_cpus), how much free memory it has, and at what physical +* address that free memory starts (memregions[1].{addr,size}), +* printf() and exit() will both work, and (argc, argv) are ready +* to be passed to main(). +* +* Copyright (C) 2014, Red Hat Inc, Andrew Jones <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2. +*/ +#include "libcflat.h" +#include "libfdt/libfdt.h" +#include "devicetree.h" +#include "asm/spinlock.h" +#include "asm/setup.h" + +extern unsigned long stacktop; +extern void io_init (void ); +extern void setup_args (const char *args); +
lib/arm/setup.c line 33
Quoted 10 lines
lib/arm/setup.c new file +10
-0+u32 cpus[NR_CPUS ] = { [0 ...NR_CPUS -1 ] = (~0UL ) }; +int nr_cpus; + +static struct spinlock memregion_lock; +struct memregion memregions[NR_MEMREGIONS ]; +int nr_memregions; + +static void cpu_set(int fdtnode __unused, u32 regval, void *info) +{ +unsigned *i = (unsigned *)info;
shouldn't you assert (*i) < NR_CPUS?
lib/arm/setup.c line 35
Quoted 2 lines
lib/arm/setup.c new file +2
-0+ cpus[*i] = regval; + *i +=1 ;
holy cow that's a convoluted way of counting. Can't you just bump the nr_cpus here?
Quoted 17 lines
lib/arm/setup.c new file +17
-0+} + +static void cpu_init (void ) +{ +unsigned i =0 ; +assert (dt_for_each_cpu_node (cpu_set, &i) ==0 ); + nr_cpus = i; +} + +static void memregions_init (phys_addr_t freemem_start) +{ +/* we only expect one membank to be defined in the DT */ +struct dt_pbus_reg regs[1 ]; +phys_addr_t addr, size, mem_end; + + nr_memregions =dt_get_memory_params (regs,1 ); +
lib/arm/setup.c line 62
Quoted 10 lines
lib/arm/setup.c new file +10
-0+assert (nr_memregions >0 ); + + addr = regs[0 ].addr; + size = regs[0 ].size; + mem_end = addr + size; + +assert (!(addr & ~PHYS_MASK ) && !((mem_end-1 ) & ~PHYS_MASK )); + +#ifdef __arm__ +/* TODO: support highmem? */
I don't think highmem is the right term here, the concept is LPAE
lib/arm/setup.c line 69
Quoted 7 lines
lib/arm/setup.c new file +7
-0+assert (!((u64 )addr >>32 ) && !((u64)(mem_end-1 ) >>32 )); +#endif + + freemem_start =PAGE_ALIGN (freemem_start); + + memregions[0 ].addr =PAGE_ALIGN (addr); + memregions[0 ].size = freemem_start -PHYS_OFFSET ;
don't you want to assert that the membank found in the dt actually covers the addresses we're loaded at?
lib/arm/setup.c line 73
Quoted 4 lines
lib/arm/setup.c new file +4
-0+ + memregions[1 ].addr = freemem_start; + memregions[1 ].size = mem_end - freemem_start; + memregions[1 ].free = true;
you could have defines for 0 and 1 here if you have already decided these places have special meanings.
lib/arm/setup.c line 76
Quoted 3 lines
lib/arm/setup.c new file +3
-0+ nr_memregions =2 ; +} +
this is an allocator of sorts, essentially, right? It would be most helpful to document this seemingly very important function.
Quoted 69 lines
lib/arm/setup.c new file +66
-0+struct memregion *memregion_new (phys_addr_t size) +{ +phys_addr_t freemem_start, freemem_size, mem_end; +struct memregion *m; + +spin_lock (&memregion_lock); + +assert (memregions[nr_memregions-1 ].free); +assert (memregions[nr_memregions-1 ].size >= size); + + mem_end = memregions[nr_memregions-1 ].addr + + memregions[nr_memregions-1 ].size; + + freemem_start =PAGE_ALIGN (memregions[nr_memregions-1 ].addr + size); + freemem_size = mem_end - freemem_start; + + memregions[nr_memregions-1 ].size = freemem_start + - memregions[nr_memregions-1 ].addr; + memregions[nr_memregions-1 ].free = false; + + m = &memregions[nr_memregions-1 ]; + +if (nr_memregions <NR_MEMREGIONS ) { + memregions[nr_memregions].addr = freemem_start; + memregions[nr_memregions].size = freemem_size; + memregions[nr_memregions].free = true; + ++nr_memregions; + } + +spin_unlock (&memregion_lock); + +return m; +} + +void memregions_show (void ) +{ +int i; +for (i =0 ; i < nr_memregions; ++i) +printf ("%016llx-%016llx [%s]\n" , + memregions[i].addr, + memregions[i].addr + memregions[i].size -1 , + memregions[i].free ?"FREE" :"USED" ); +} + +void setup (unsigned long arg __unused,unsigned long id __unused, +const void *fdt) +{ +const char *bootargs; +u32 fdt_size; + +/* +* Move the fdt to just above the stack. The free memory +* then starts just after the fdt. +*/ + fdt_size =fdt_totalsize (fdt); +assert (fdt_move (fdt, &stacktop, fdt_size) ==0 ); +assert (dt_init (&stacktop) ==0 ); + +memregions_init ((unsigned long )&stacktop + fdt_size); + +io_init (); +cpu_init (); + +assert (dt_get_bootargs (&bootargs) ==0 ); +setup_args (bootargs); +}Signature · 1 line
1.8.1.4
Thanks,
-Christoffer
Re: [PATCH v4 18/19] arm: add useful headers from the Linux kernel
In reply to Andrew JonesQuoted 9 lines · Andrew Jones
We're going to need PSR bit defines and
pt_regs. We'll also needpt_regsoffsets in assembly code. This patch adapts the Linux kernel'sptrace.handgenerated/asm-offsets.hto this framework. It also adaptscp15.hfrom the kernel, since we'll need bit defines from there too.Signed-off-by Andrew Jones <[email protected]>---
v4: much improvedasm-offsets.hgeneration based onKbuild
Wonderful!
Re: [PATCH v4 19/19] arm: vectors support
In reply to Andrew JonesQuoted 10 lines · Andrew Jones
Add support for tests to use exception handlers using
install_exception_handler(). This patch also addsphys_start_usr(), which can be used to start a function in USR mode, using a stack set up in a new memregion.phys_start_usr()is used by new selftest tests that check the new vector support.Signed-off-by Andrew Jones <[email protected]>---
v4: a couple tweaks to fit changes in the other patches,
vectors-usr test now has an 8K usr stack
would have appreciated something more concrete than 'a couple tweaks' in a 600+ lines patch.
But it's looking good:
Quoted 11 lines · Andrew Jones
This is a v4 of a series that introduces arm to kvm-unit-tests. First, it does some tidying up of the repo. Then, it adds support for device trees (libfdt), and for virtio-testdev[1]. Next, it adds the basic infrastructure for booting a test case (guest), and adds a first test case, a self-test to confirm setup was completed successfully. Finally, it further prepares the framework for more complicated tests by adding vector support, and extends the self-test to test that too.
This initial drop doesn't require kvmarm. qemu-system-arm is enough, but it must have mach-virt, and the virtio-testdev patch[1].
This is overall looking really good!
I only had a few comments and questions, but you should be able to sort that out quickly.
It's a lot of code and growing for every iteration, and this time it was a long gap since the last review, so it took me a while.
I think it would be great if you can address my comments quickly and we can this merged without futher churn and let new functionality come as separate extra patches afterwards.
Thanks,
-Christoffer
Re: [PATCH v4 01/19] remove unused files
In reply to Christoffer DallQuoted 11 lines · Christoffer Dall
Quoted 6 lines · Andrew Jones
There are several unused files, primarily because powerpc is an unused arch. The exceptions are config-ia64.mak, which is also an unused arch file,
lib/fwcfg.c,lib/panic.c,x86/print.hand x86/run-kvm-unit-tests, which are just unused. Remove them all in order to tidy things up.Signed-off-by Andrew Jones <[email protected]>Sounds reasonable enough for me, but you probably want an acked-by from the people who actually know if they should care about these files or not.
Agreed. Alex? Paolo?
Quoted 4 lines
In any case:
Acked-by Christoffer Dall <[email protected]>
Thanks!
drew
Re: [PATCH v4 10/19] Introduce asm-generic/*.h files
In reply to Christoffer DallQuoted 65 lines · Christoffer Dall
Quoted 64 lines · Andrew Jones
Architecture neutral code may need to call low-level io accessors, or use spinlocks. Create a generic
io.hto ensure those accessors are defined, and a genericspinlock.hthat complains when included, as we can't write a generic spinlock. These files can be overridden or extended by architecture specific versions placed inlib/$ARCH/asm/.Signed-off-by Andrew Jones <[email protected]>---
v4: introduce lib/asm symlink to get rid of #ifdef__arm__,
addspinlock.htoo
v3: wrt toio.h(was libio.[ch]) only
- get rid ofCONFIG_64BIT, replace with asserts
- get rid of {read,write}_len() [libio.c]
- fix bad *64_to_cpu macros--- .gitignore | 1 + Makefile | 6 +- configure | 11 ++++ lib/asm-generic/io.h | 154 +++++++++++++++++++++++++++++++++++++++++++++ lib/asm-generic/spinlock.h | 4 ++ 5 files changed, 173 insertions(+), 3 deletions(-) create mode 100644 lib/asm-generic/io.h create mode 100644 lib/asm-generic/spinlock.h.gitignore +1
-0@@ -9,6 +9,7 @@ patches .stgit-* cscope.* *.swp +/lib/asm /config.mak /*-run /test.logMakefile +3
-3@@ -76,11 +76,11 @@ libfdt_clean: $(LIBFDT_objdir)/.*.d distclean: clean libfdt_clean - $(RM) config.mak $(TEST_DIR)-run test.log msr.out cscope.* + $(RM) lib/asm config.mak $(TEST_DIR)-run test.log msr.out cscope.* -cscope: common_dirs = lib lib/libfdt +cscope: common_dirs = lib lib/libfdt lib/asm lib/asm-generic cscope: $(RM) ./cscope.* - find $(TEST_DIR) lib/$(TEST_DIR) $(common_dirs) -maxdepth 1 \ + find -L $(TEST_DIR) lib/$(TEST_DIR) $(common_dirs) -maxdepth 1 \ -name '*.[chsS]' -print | sed 's,^\./,,' > ./cscope.files cscope -bkconfigure +0
-0@@ -95,6 +95,17 @@ if [ $exit -eq 0 ]; then fi rm -f lib_test.c
Quoted 9 lines
configure if [ $exit -eq 0 ]; then · line 104
Quoted 7 lines
configure +7
-0+# link lib/asm for the architecture +rm -f lib/asm +asm=asm-generic +if [ -d lib/$arch/asm ]; then + asm=$arch/asm +elif [ -d lib/$testdir/asm ]; then + asm=$testdir/asmwhy do you need this elif? can you not make sure arch is always set?
arch is always set, but there's a chance some arch may not add it's own lib/$arch dir. It's a pretty small chance... but the elif shouldn't hurt.
drew
Re: [PATCH v4 11/19] add minimal virtio support for devtree virtio-mmio
In reply to Christoffer DallQuoted 144 lines · Christoffer Dall
Quoted 143 lines · Andrew Jones
Support the bare minimum of virtio to enable access to the virtio-mmio config space of a device. Currently this implementation must use a device tree to find the device.
Signed-off-by Andrew Jones <[email protected]>---
v4:
- split from the virtio-testdev patch
- search a table to "discover" that the device must be DT/virtio-mmio, which doesn't change anything, but looks less hacky than comments saying the device must be DT/virtio-mmio...
- manage own pool of virtio-mmio pre-allocated device structures in order to avoid needing access to the heap--- lib/libcflat.h | 3 ++ lib/virtio.c | 166 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/virtio.h | 89 +++++++++++++++++++++++++++++++ 3 files changed, 258 insertions(+) create mode 100644 lib/virtio.c create mode 100644 lib/virtio.hlib/libcflat.h +3
-0@@ -62,6 +62,9 @@ extern long atol(const char *ptr);#define ARRAY_SIZE (_a) (sizeof(_a)/sizeof((_a)[0]))#define offsetof (TYPE ,MEMBER ) __builtin_offsetof (TYPE, MEMBER) +#define container_of (ptr, type, member) ({ \ + const typeof( ((type *)0)->member ) *__mptr = (ptr); \ + (type *)( (char *)__mptr - offsetof(type,member) );})#define NULL ((void *)0UL)lib/virtio.c new file +102
-0@@ -0,0 +1,166 @@ +/* +* Copyright (C) 2014, Red Hat Inc, Andrew Jones <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2. +*/ +#include "libcflat.h" +#include "devicetree.h" +#include "asm/spinlock.h" +#include "asm/io.h" +#include "virtio.h" + +enum virtio_hwdesc_type { +VIRTIO_HWDESC_TYPE_DT =0 ,/* device tree */ +NR_VIRTIO_HWDESC_TYPES , +}; + +enum virtio_bus_type { +VIRTIO_BUS_TYPE_MMIO =0 ,/* virtio-mmio */ +NR_VIRTIO_BUS_TYPES , +}; + +struct virtio_bind_bus { +bool (*hwdesc_probe)(void ); +struct virtio_dev *(*device_bind)(u32 devid); +}; + +static struct virtio_dev *vm_dt_device_bind (u32 devid); + +static struct virtio_bind_bus +virtio_bind_busses[NR_VIRTIO_HWDESC_TYPES ][NR_VIRTIO_BUS_TYPES ] = { + +[VIRTIO_HWDESC_TYPE_DT ] = { + + [VIRTIO_BUS_TYPE_MMIO ] = { + .hwdesc_probe = dt_available, + .device_bind = vm_dt_device_bind, + }, +}, +}; + +struct virtio_dev *virtio_bind (u32 devid) +{ +struct virtio_bind_bus *bus; +struct virtio_dev *dev; +int i, j; + +for (i =0 ; i <NR_VIRTIO_HWDESC_TYPES ; ++i) { +for (j =0 ; j <NR_VIRTIO_BUS_TYPES ; ++j) { + + bus = &virtio_bind_busses[i][j]; + +if (!bus->hwdesc_probe ()) +continue ; + + dev = bus->device_bind (devid); +if (dev) +return dev; + } + } + +return NULL ; +} + +/****************************************************** +* virtio-mmio support (config space only) +******************************************************/ + +static void vm_get (struct virtio_dev *vdev,unsigned offset, +void *buf,unsigned len) +{ +struct virtio_mmio_dev *vmdev =to_virtio_mmio_dev (vdev); +u8 *p = buf; +unsigned i; + +for (i =0 ; i < len; ++i) + p[i] =readb (vmdev->base +VIRTIO_MMIO_CONFIG + offset + i); +} + +static void vm_set (struct virtio_dev *vdev,unsigned offset, +const void *buf,unsigned len) +{ +struct virtio_mmio_dev *vmdev =to_virtio_mmio_dev (vdev); +const u8 *p = buf; +unsigned i; + +for (i =0 ; i < len; ++i) +writeb (p[i], vmdev->base +VIRTIO_MMIO_CONFIG + offset + i); +} + +#define NR_VM_DEVICES 32 +static struct spinlock vm_lock; +static struct virtio_mmio_dev vm_devs[NR_VM_DEVICES ]; +static struct virtio_conf_ops vm_confs[NR_VM_DEVICES ]; +static int nr_vm_devs; + +static struct virtio_mmio_dev *vm_new_device (u32 devid) +{ +struct virtio_mmio_dev *vmdev; + +if (nr_vm_devs >=NR_VM_DEVICES ) +return NULL ; +
Quoted 8 lines
lib/virtio.c line 105
Quoted 3 lines
lib/virtio.c new file +3
-0+spin_lock (&vm_lock); + vmdev = &vm_devs[nr_vm_devs]; + vmdev->vdev.config = &vm_confs[nr_vm_devs];this seems a bit weird, will we ever share
vm_confsbetweenvm_devsor change thevm_confpointer later on? Couldvm_confjust be part of thevm_devstruct and you could just have avirtio_mmio_conf_init()to set the get/set functions?
I can do that, but it'll require a typedef for struct virtio_dev to appease the compiler.
Quoted 23 lines
Quoted 9 lines
lib/virtio.c new file +8
-0+ ++nr_vm_devs; +spin_unlock (&vm_lock); + + vmdev->vdev.id.device = devid; + vmdev->vdev.id.vendor =-1 ; + vmdev->vdev.config->get = vm_get; + vmdev->vdev.config->set = vm_set; +lib/virtio.c line 123
Quoted 10 lines
lib/virtio.c new file +10
-0+return vmdev; +} + +/****************************************************** +* virtio-mmio device tree support +******************************************************/ + +struct vm_dt_info { +u32 devid; +void *base;won't work for LPAE and 32-bit arm systems, can't you use
dt_device_bind_node?
Quoted 3 lines
I guess that requires you to have an ioremap function, but it sure seems cleaner to give up there if you don't have proper memory mapping features yet....
Right. I was just skipping past that complexity for now, as mach-virt's DT is currently "nice" (32-bit only addrs). I agree we need to handle LPAE addrs on arm eventually though.
Quoted 15 lines
lib/virtio.c line 134
Quoted 12 lines
lib/virtio.c new file +11
-0+}; + +static int vm_dt_match (const struct dt_device *dev,int fdtnode) +{ +struct vm_dt_info *info = (struct vm_dt_info *)dev->info; +dt_pbus_addr_t base; + +dt_device_bind_node ((struct dt_device *)dev, fdtnode); + +assert (dt_pbus_get_baseaddr (dev, &base) ==0 ); +assert (sizeof (long ) ==8 || !(base >>32 ));again, this assert will break with >32bit LPAE addresses on 32-bit arm systems.
Quoted 2 lines
so, not sure if it's an assert, or if you should test for it and print a more benign error for these types of devices.
It's supposed to be a crash-and-burn assert, but a message stating something like >32-bit addrs on arm is not yet supported would certainly be nicer. Of course that message would only make it out at this point if our uart address guess is correct.
Quoted 5 lines
lib/virtio.c line 136
Quoted 3 lines
lib/virtio.c new file +2
-0+ + info->base = (void *)(unsigned long )base;why do you need to cast it twice?
Same as above (as we still don't support >32-bit addrs on arm). This keeps the compiler from complaining when casting a dt_pbus_addr_t (u64) to void* on 32-bit.
Quoted 131 lines
Quoted 129 lines
lib/virtio.c new file +30
-0+ +return readl (info->base +VIRTIO_MMIO_DEVICE_ID ) == info->devid; +} + +static struct virtio_dev *vm_dt_device_bind (u32 devid) +{ +struct virtio_mmio_dev *vmdev; +struct dt_device dt_dev; +struct dt_bus dt_bus; +struct vm_dt_info info; +int node; + +dt_bus_init_defaults (&dt_bus); + dt_bus.match = vm_dt_match; + + info.devid = devid; + +dt_device_init (&dt_dev, &dt_bus, &info); + + node =dt_device_find_compatible (&dt_dev,"virtio,mmio" ); +assert (node >=0 || node == -FDT_ERR_NOTFOUND ); + +if (node == -FDT_ERR_NOTFOUND ) +return NULL ; + + vmdev =vm_new_device (devid); + vmdev->base = info.base; + +return &vmdev->vdev; +}lib/virtio.h new file +89
-0@@ -0,0 +1,89 @@ +#ifndef _VIRTIO_H_ +#define _VIRTIO_H_ +/* +* A minimal implementation of virtio for virtio-mmio config space +* access. +* +* Copyright (C) 2014, Red Hat Inc, Andrew Jones <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2. +*/ +#include "libcflat.h" + +struct virtio_devid { +u32 device; +u32 vendor; +}; + +struct virtio_dev { +struct virtio_devid id; +struct virtio_conf_ops *config; +}; + +struct virtio_conf_ops { +void (*get)(struct virtio_dev *vdev,unsigned offset, +void *buf,unsigned len); +void (*set)(struct virtio_dev *vdev,unsigned offset, +const void *buf,unsigned len); +}; + +extern struct virtio_dev *virtio_bind (u32 devid); + +static inline u8 +virtio_config_readb (struct virtio_dev *vdev,unsigned offset) +{ +u8 val; + vdev->config->get (vdev, offset, &val,1 ); +return val; +} + +static inline u16 +virtio_config_readw (struct virtio_dev *vdev,unsigned offset) +{ +u16 val; + vdev->config->get (vdev, offset, &val,2 ); +return val; +} + +static inline u32 +virtio_config_readl (struct virtio_dev *vdev,unsigned offset) +{ +u32 val; + vdev->config->get (vdev, offset, &val,4 ); +return val; +} + +static inline void +virtio_config_writeb (struct virtio_dev *vdev,unsigned offset,u8 val) +{ + vdev->config->set (vdev, offset, &val,1 ); +} + +static inline void +virtio_config_writew (struct virtio_dev *vdev,unsigned offset,u16 val) +{ + vdev->config->set (vdev, offset, &val,2 ); +} + +static inline void +virtio_config_writel (struct virtio_dev *vdev,unsigned offset,u32 val) +{ + vdev->config->set (vdev, offset, &val,4 ); +} + +/****************************************************** +* virtio-mmio +******************************************************/ + +#define VIRTIO_MMIO_DEVICE_ID 0x008 +#define VIRTIO_MMIO_CONFIG 0x100 + +#define to_virtio_mmio_dev (vdev_ptr) \ + container_of(vdev_ptr, struct virtio_mmio_dev, vdev) + +struct virtio_mmio_dev { +struct virtio_dev vdev; +void *base; +}; + +#endif /* _VIRTIO_H_ */ Signature · 1 line
1.8.1.4-Christoffer
Re: [PATCH v4 10/19] Introduce asm-generic/*.h files
In reply to Andrew JonesQuoted 76 lines · Andrew Jones
Quoted 65 lines · Christoffer Dall
Quoted 64 lines · Andrew Jones
Architecture neutral code may need to call low-level io accessors, or use spinlocks. Create a generic
io.hto ensure those accessors are defined, and a genericspinlock.hthat complains when included, as we can't write a generic spinlock. These files can be overridden or extended by architecture specific versions placed inlib/$ARCH/asm/.Signed-off-by Andrew Jones <[email protected]>---
v4: introduce lib/asm symlink to get rid of #ifdef__arm__,
addspinlock.htoo
v3: wrt toio.h(was libio.[ch]) only
- get rid ofCONFIG_64BIT, replace with asserts
- get rid of {read,write}_len() [libio.c]
- fix bad *64_to_cpu macros--- .gitignore | 1 + Makefile | 6 +- configure | 11 ++++ lib/asm-generic/io.h | 154 +++++++++++++++++++++++++++++++++++++++++++++ lib/asm-generic/spinlock.h | 4 ++ 5 files changed, 173 insertions(+), 3 deletions(-) create mode 100644 lib/asm-generic/io.h create mode 100644 lib/asm-generic/spinlock.h.gitignore +1
-0@@ -9,6 +9,7 @@ patches .stgit-* cscope.* *.swp +/lib/asm /config.mak /*-run /test.logMakefile +3
-3@@ -76,11 +76,11 @@ libfdt_clean: $(LIBFDT_objdir)/.*.d distclean: clean libfdt_clean - $(RM) config.mak $(TEST_DIR)-run test.log msr.out cscope.* + $(RM) lib/asm config.mak $(TEST_DIR)-run test.log msr.out cscope.* -cscope: common_dirs = lib lib/libfdt +cscope: common_dirs = lib lib/libfdt lib/asm lib/asm-generic cscope: $(RM) ./cscope.* - find $(TEST_DIR) lib/$(TEST_DIR) $(common_dirs) -maxdepth 1 \ + find -L $(TEST_DIR) lib/$(TEST_DIR) $(common_dirs) -maxdepth 1 \ -name '*.[chsS]' -print | sed 's,^\./,,' > ./cscope.files cscope -bkconfigure +0
-0@@ -95,6 +95,17 @@ if [ $exit -eq 0 ]; then fi rm -f lib_test.cQuoted 9 lines
configure if [ $exit -eq 0 ]; then · line 104
Quoted 7 lines
configure +7
-0+# link lib/asm for the architecture +rm -f lib/asm +asm=asm-generic +if [ -d lib/$arch/asm ]; then + asm=$arch/asm +elif [ -d lib/$testdir/asm ]; then + asm=$testdir/asmwhy do you need this elif? can you not make sure arch is always set?
Quoted 3 lines
arch is always set, but there's a chance some arch may not add it's own lib/$arch dir. It's a pretty small chance... but the elif shouldn't hurt.
If we don't have any code that uses this scheme now then let's now have Makefile rules that encourages non-standard behavior (unless I'm missing the point and this provides a 'feature' for specific archs or something like that).
-Christoffer
Re: [PATCH v4 11/19] add minimal virtio support for devtree virtio-mmio
In reply to Andrew JonesQuoted 180 lines · Andrew Jones
Quoted 144 lines · Christoffer Dall
Quoted 143 lines · Andrew Jones
Support the bare minimum of virtio to enable access to the virtio-mmio config space of a device. Currently this implementation must use a device tree to find the device.
Signed-off-by Andrew Jones <[email protected]>---
v4:
- split from the virtio-testdev patch
- search a table to "discover" that the device must be DT/virtio-mmio, which doesn't change anything, but looks less hacky than comments saying the device must be DT/virtio-mmio...
- manage own pool of virtio-mmio pre-allocated device structures in order to avoid needing access to the heap--- lib/libcflat.h | 3 ++ lib/virtio.c | 166 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/virtio.h | 89 +++++++++++++++++++++++++++++++ 3 files changed, 258 insertions(+) create mode 100644 lib/virtio.c create mode 100644 lib/virtio.hlib/libcflat.h +3
-0@@ -62,6 +62,9 @@ extern long atol(const char *ptr);#define ARRAY_SIZE (_a) (sizeof(_a)/sizeof((_a)[0]))#define offsetof (TYPE ,MEMBER ) __builtin_offsetof (TYPE, MEMBER) +#define container_of (ptr, type, member) ({ \ + const typeof( ((type *)0)->member ) *__mptr = (ptr); \ + (type *)( (char *)__mptr - offsetof(type,member) );})#define NULL ((void *)0UL)lib/virtio.c new file +102
-0@@ -0,0 +1,166 @@ +/* +* Copyright (C) 2014, Red Hat Inc, Andrew Jones <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2. +*/ +#include "libcflat.h" +#include "devicetree.h" +#include "asm/spinlock.h" +#include "asm/io.h" +#include "virtio.h" + +enum virtio_hwdesc_type { +VIRTIO_HWDESC_TYPE_DT =0 ,/* device tree */ +NR_VIRTIO_HWDESC_TYPES , +}; + +enum virtio_bus_type { +VIRTIO_BUS_TYPE_MMIO =0 ,/* virtio-mmio */ +NR_VIRTIO_BUS_TYPES , +}; + +struct virtio_bind_bus { +bool (*hwdesc_probe)(void ); +struct virtio_dev *(*device_bind)(u32 devid); +}; + +static struct virtio_dev *vm_dt_device_bind (u32 devid); + +static struct virtio_bind_bus +virtio_bind_busses[NR_VIRTIO_HWDESC_TYPES ][NR_VIRTIO_BUS_TYPES ] = { + +[VIRTIO_HWDESC_TYPE_DT ] = { + + [VIRTIO_BUS_TYPE_MMIO ] = { + .hwdesc_probe = dt_available, + .device_bind = vm_dt_device_bind, + }, +}, +}; + +struct virtio_dev *virtio_bind (u32 devid) +{ +struct virtio_bind_bus *bus; +struct virtio_dev *dev; +int i, j; + +for (i =0 ; i <NR_VIRTIO_HWDESC_TYPES ; ++i) { +for (j =0 ; j <NR_VIRTIO_BUS_TYPES ; ++j) { + + bus = &virtio_bind_busses[i][j]; + +if (!bus->hwdesc_probe ()) +continue ; + + dev = bus->device_bind (devid); +if (dev) +return dev; + } + } + +return NULL ; +} + +/****************************************************** +* virtio-mmio support (config space only) +******************************************************/ + +static void vm_get (struct virtio_dev *vdev,unsigned offset, +void *buf,unsigned len) +{ +struct virtio_mmio_dev *vmdev =to_virtio_mmio_dev (vdev); +u8 *p = buf; +unsigned i; + +for (i =0 ; i < len; ++i) + p[i] =readb (vmdev->base +VIRTIO_MMIO_CONFIG + offset + i); +} + +static void vm_set (struct virtio_dev *vdev,unsigned offset, +const void *buf,unsigned len) +{ +struct virtio_mmio_dev *vmdev =to_virtio_mmio_dev (vdev); +const u8 *p = buf; +unsigned i; + +for (i =0 ; i < len; ++i) +writeb (p[i], vmdev->base +VIRTIO_MMIO_CONFIG + offset + i); +} + +#define NR_VM_DEVICES 32 +static struct spinlock vm_lock; +static struct virtio_mmio_dev vm_devs[NR_VM_DEVICES ]; +static struct virtio_conf_ops vm_confs[NR_VM_DEVICES ]; +static int nr_vm_devs; + +static struct virtio_mmio_dev *vm_new_device (u32 devid) +{ +struct virtio_mmio_dev *vmdev; + +if (nr_vm_devs >=NR_VM_DEVICES ) +return NULL ; +Quoted 8 lines
lib/virtio.c line 105
Quoted 3 lines
lib/virtio.c new file +3
-0+spin_lock (&vm_lock); + vmdev = &vm_devs[nr_vm_devs]; + vmdev->vdev.config = &vm_confs[nr_vm_devs];this seems a bit weird, will we ever share
vm_confsbetweenvm_devsor change thevm_confpointer later on? Couldvm_confjust be part of thevm_devstruct and you could just have avirtio_mmio_conf_init()to set the get/set functions?I can do that, but it'll require a typedef for struct
virtio_devto appease the compiler.Quoted 23 lines
Quoted 9 lines
lib/virtio.c new file +8
-0+ ++nr_vm_devs; +spin_unlock (&vm_lock); + + vmdev->vdev.id.device = devid; + vmdev->vdev.id.vendor =-1 ; + vmdev->vdev.config->get = vm_get; + vmdev->vdev.config->set = vm_set; +lib/virtio.c line 123
Quoted 10 lines
lib/virtio.c new file +10
-0+return vmdev; +} + +/****************************************************** +* virtio-mmio device tree support +******************************************************/ + +struct vm_dt_info { +u32 devid; +void *base;won't work for LPAE and 32-bit arm systems, can't you use
dt_device_bind_node?
Quoted 8 lines
Quoted 3 lines
I guess that requires you to have an ioremap function, but it sure seems cleaner to give up there if you don't have proper memory mapping features yet....
Right. I was just skipping past that complexity for now, as mach-virt's DT is currently "nice" (32-bit only addrs). I agree we need to handle LPAE addrs on arm eventually though.
So I think the tradeoff here is very small, it's super easy to fix it so you can support physical addresses > 32 bits in this part of the code. The difficult thing comes when you start dereferencing them, but since we may add virtual addresses at some point too, I really think adding a trivial ioremap function and start using that will make our lives much easier down the line:
/* We don't support virtual addresses yet, trivial identity implementation */ void __iomem *ioremap(phys_addr_t phys_addr)
{
assert(sizeof(long) == 8 || !(base >> 32));
return (void *)(unsigned long)phys_addr;
}But I can submit that patch after this code goes in if you think it's too much of a headache at this point?
Thanks,
-Christoffer
Re: [PATCH v4 15/19] arm: initial drop
In reply to Christoffer DallQuoted 167 lines · Christoffer Dall
Quoted 166 lines · Andrew Jones
This is the initial drop of the arm test framework and a first test that just checks that setup completed (a selftest). kvm isn't needed to run this test unless testing with smp > 1.
Try it out with
yum install gcc-arm-linux-gnu
export QEMU=[qemu with mach-virt and virtio-testdev] ./configure --cross-prefix=arm-linux-gnu- --arch=arm make
./run_tests.shSigned-off-by Andrew Jones <[email protected]>---
v4:
- moved fdt to just after stacktop (it was in the middle of free memory)
- switched from using heap to memregions
- getnr_cpusand added smp=<num> test
- addedbarrier.h
- use new report()/report_summary()
- config/config-arm.mak cleanup--- arm/cstart.S | 35 ++++++++++++ arm/flat.lds | 18 +++++++ arm/run | 31 +++++++++++ arm/selftest.c | 87 ++++++++++++++++++++++++++++++ arm/unittests.cfg | 18 +++++++ config/config-arm.mak | 72 +++++++++++++++++++++++++ configure | 12 ++++- lib/argv.c | 6 +++ lib/arm/asm/barrier.h | 18 +++++++ lib/arm/asm/io.h | 24 +++++++++ lib/arm/asm/setup.h | 39 ++++++++++++++ lib/arm/asm/spinlock.h | 16 ++++++ lib/arm/eabi_compat.c | 20 +++++++ lib/arm/io.c | 66 +++++++++++++++++++++++ lib/arm/setup.c | 142 +++++++++++++++++++++++++++++++++++++++++++++++++ 15 files changed, 602 insertions(+), 2 deletions(-) create mode 100644 arm/cstart.S create mode 100644 arm/flat.lds create mode 100755 arm/run create mode 100644 arm/selftest.c create mode 100644 arm/unittests.cfg create mode 100644 config/config-arm.mak create mode 100644 lib/arm/asm/barrier.h create mode 100644 lib/arm/asm/io.h create mode 100644 lib/arm/asm/setup.h create mode 100644 lib/arm/asm/spinlock.h create mode 100644 lib/arm/eabi_compat.c create mode 100644 lib/arm/io.c create mode 100644 lib/arm/setup.carm/cstart.S new file +35
-0@@ -0,0 +1,35 @@ +/* + * Boot entry point and assembler functions for armv7 tests. + * + * Copyright (C) 2014, Red Hat Inc, Andrew Jones <[email protected]> + * + * This work is licensed under the terms of the GNU LGPL, version 2. + */ + +.arm + +.section .init + +.globl start +start: + /* + * bootloader params are in r0-r2 + * See the kernel doc Documentation/arm/Booting + */ + ldr sp, =stacktop + bl setup + + /* run the test */ + ldr r0, =__argc + ldr r0, [r0] + ldr r1, =__argv + bl main + bl exit + b halt + +.text + +.globl halt +halt: +1: wfi + b 1barm/flat.lds new file +18
-0@@ -0,0 +1,18 @@ + +SECTIONS +{ + .text : { *(.init) *(.text) *(.text.*) } + . = ALIGN(4K); + .data : { *(.data) } + . = ALIGN(16); + .rodata : { *(.rodata) } + . = ALIGN(16); + .bss : { *(.bss) } + . = ALIGN(4K); + edata = .; + . += 8K; + . = ALIGN(4K); + stacktop = .; +} + +ENTRY(start)arm/run new file +31
-0@@ -0,0 +1,31 @@ +#!/bin/bash + +if [ ! -f config.mak ]; then + echo run ./configure first. See ./configure -h + exit 2 +fi +source config.mak + +qemu="${QEMU:-qemu-system-arm}" +testdev=virtio-testdev + +if ! $qemu -device '?' 2>&1 | grep $testdev > /dev/null; then + qpath=$(which $qemu 2>/dev/null) + if [ "$qpath" ]; then + echo $qpath doesn\'t support virtio-testdev. Exiting. + else + echo $qemu not found. + fi + exit 2 +fi + +command="$qemu -device $testdev -display none -serial stdio " +command+="-M virt -cpu $PROCESSOR " +#command+="-enable-kvm " +command+="-kernel" + +echo $command "$@" +$command "$@" +ret=$? +echo Return value from qemu: $ret +exit $retarm/selftest.c new file +7
-0@@ -0,0 +1,87 @@ +/* +* Test the framework itself. These tests confirm that setup works. +* +* Copyright (C) 2014, Red Hat Inc, Andrew Jones <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2. +*/
Quoted 8 lines
arm/selftest.c line 13
Quoted 6 lines
arm/selftest.c new file +6
-0+#include "libcflat.h" +#include "asm/setup.h" + +#define TESTGRP "selftest" + +static char testnam[64 ];is testnam testname?
:-) You're not a fan of single char saving abbreviations, eh? I can add the 'e' back.
Quoted 328 lines
Quoted 328 lines
arm/selftest.c new file +74
-0+ +static void testnam_set (const char *subtest) +{ +strcpy (testnam,TESTGRP ); +strcat (testnam,"::" ); +strcat (testnam, subtest); +} + +static void assert_args (int num_args,int needed_args) +{ +if (num_args < needed_args) { +printf ("%s: not enough arguments\n" , testnam); +abort (); + } +} + +static char *split_var (char *s,long *val) +{ +char *p; + + p =strchr (s,'=' ); +if (!p) +return NULL ; + + *val =atol (p+1 ); + *p ='\0' ; + +return s; +} + +static void check_setup (int argc,char **argv) +{ +int nr_tests =0 , i; +char *var; +long val; + +for (i =0 ; i < argc; ++i) { + + var =split_var (argv[i], &val); +if (!var) +continue ; + +if (strcmp (argv[i],"mem" ) ==0 ) { + +phys_addr_t memsize = + memregions[nr_memregions-1 ].addr + + memregions[nr_memregions-1 ].size + -PHYS_OFFSET ; +phys_addr_t expected = ((phys_addr_t )val)*1024 *1024 ; + +report ("%s[%s]" , memsize == expected, testnam,"mem" ); + ++nr_tests; + + }else if (strcmp (argv[i],"smp" ) ==0 ) { + +report ("%s[%s]" , nr_cpus == (int )val, testnam,"smp" ); + ++nr_tests; + } + } + +assert_args (nr_tests,2 ); +} + +int main (int argc,char **argv) +{ +assert_args (argc,1 ); + +testnam_set (argv[0 ]); + +if (strcmp (argv[0 ],"setup" ) ==0 ) +check_setup (argc-1 , &argv[1 ]); + +return report_summary (); +}arm/unittests.cfg new file +18
-0@@ -0,0 +1,18 @@ +# Define your new unittest following the convention: +# [unittest_name] +# file = foo.flat # Name of the flat file to be used +# smp = 2 # Number of processors the VM will use during this test +# extra_params = -append <params...> # Additional parameters used +# arch = arm/arm64 # Only if test case is specific to one +# groups = group1 group2 # Used to identify test cases with run_tests -g ... + +# +# Test that the configured number of processors (smp = <num>), and +# that the configured amount of memory (-m <MB>) are correctly setup +# by the framework. +# +[selftest::setup] +file = selftest.flat +smp = 1 +extra_params = -m 256 -append 'setup smp=1 mem=256' +groups = selftestconfig/config-arm.mak new file +72
-0@@ -0,0 +1,72 @@ +# +# arm makefile +# +# Authors: Andrew Jones <[email protected]> +# + +tests-common = \ + $(TEST_DIR)/selftest.flat + +tests = + +all: test_cases + +################################################################## +bits = 32 +ldarch = elf32-littlearm + +ifeq ($(LOADADDR),) + LOADADDR = 0x40000000 +endif +phys_base = $(LOADADDR) +kernel_offset = 0x10000 + +CFLAGS += -D__arm__ +CFLAGS += -marm +CFLAGS += -mcpu=$(PROCESSOR) +CFLAGS += -std=gnu99 +CFLAGS += -ffreestanding +CFLAGS += -Wextra +CFLAGS += -O2 +CFLAGS += -I lib -I lib/libfdt + +cflatobjs += \ + lib/devicetree.o \ + lib/virtio.o \ + lib/virtio-testdev.o \ + lib/arm/io.o \ + lib/arm/setup.o + +libeabi = lib/arm/libeabi.a +eabiobjs = lib/arm/eabi_compat.o + +libgcc := $(shell $(CC) -m$(ARCH) --print-libgcc-file-name) +start_addr := $(shell printf "%x\n" $$(( $(phys_base) + $(kernel_offset) ))) + +FLATLIBS = $(libcflat) $(LIBFDT_archive) $(libgcc) $(libeabi) +%.elf: LDFLAGS = $(CFLAGS) -nostdlib +%.elf: %.o $(FLATLIBS) arm/flat.lds + $(CC) $(LDFLAGS) -o $@ \ + -Wl,-T,arm/flat.lds,--build-id=none,-Ttext=$(start_addr) \ + $(filter %.o, $^) $(FLATLIBS) + +%.flat: %.elf + $(OBJCOPY) -O binary $^ $@ + +$(libeabi): $(eabiobjs) + $(AR) rcs $@ $^ + +arch_clean: libfdt_clean + $(RM) $(TEST_DIR)/*.{o,flat,elf} $(libeabi) $(eabiobjs) \ + $(TEST_DIR)/.*.d lib/arm/.*.d + +################################################################## + +tests_and_config = $(TEST_DIR)/*.flat $(TEST_DIR)/unittests.cfg + +cstart.o = $(TEST_DIR)/cstart.o + +test_cases: $(tests-common) $(tests) + +$(TEST_DIR)/selftest.elf: $(cstart.o) $(TEST_DIR)/selftest.o +configure +10
-2@@ -6,8 +6,7 @@ cc=gcc ld=ld objcopy=objcopy ar=ar -arch=`uname -m | sed -e s/i.86/i386/` -processor="$arch" +arch=`uname -m | sed -e s/i.86/i386/ | sed -e 's/arm.*/arm/'` cross_prefix= usage() {@@ -17,6 +16,7 @@ usage() { Options include: --test-dir=DIR the main directory for tests ($arch) --arch=ARCH architecture to compile for ($arch) + --processor=PROCESSOR processor to compile for ($arch) --cross-prefix=PREFIX cross compiler prefix --cc=CC c compiler to use ($cc) --ld=LD ld linker to use ($ld)@@ -66,6 +66,12 @@ while [[ "$1" = -* ]]; do ;; esac done +[ -z "$processor" ] && processor="$arch" + +if [ "$processor" = "arm" ]; then + processor="cortex-a15" +fi + if [ -z "$testdir" -a \( "$arch" = "i386" -o "$arch" = "x86_64" \) ]; then testdir=x86 elif [ -z "$testdir" ]; then@@ -80,6 +86,7 @@ if [ -f $testdir/run ]; then fi # check for dependent 32 bit libraries +if [ "$arch" != "arm" ]; then cat << EOF > lib_test.c #include <stdc++.h> #include <boost_thread-mt.h>@@ -94,6 +101,7 @@ if [ $exit -eq 0 ]; then api=true fi rm -f lib_test.c +fi # link lib/asm for the architecture rm -f lib/asmlib/argv.c +6
-0@@ -31,3 +31,9 @@ void __setup_args(void) } __argc = argv - __argv; } + +void setup_args (char *args) +{ + __args = args; +__setup_args (); +}lib/arm/asm/barrier.h new file +18
-0@@ -0,0 +1,18 @@ +#ifndef _ASMARM_BARRIER_H_ +#define _ASMARM_BARRIER_H_ +/* +* Adapted form arch/arm/include/asm/barrier.h +*/ + +#define isb (option) __asm__ __volatile__ ("isb " #option : : : "memory") +#define dsb (option) __asm__ __volatile__ ("dsb " #option : : : "memory") +#define dmb (option) __asm__ __volatile__ ("dmb " #option : : : "memory") + +#define mb () dsb() +#define rmb () dsb() +#define wmb () dsb(st) +#define smp_mb () dmb(ish) +#define smp_rmb () smp_mb() +#define smp_wmb () dmb(ishst) + +#endif /* _ASMARM_BARRIER_H_ */ lib/arm/asm/io.h new file +24
-0@@ -0,0 +1,24 @@ +#ifndef _ASMARM_IO_H_ +#define _ASMARM_IO_H_ +#include "libcflat.h" +#include "asm/barrier.h" + +#define __bswap16 bswap16 +static inline u16 bswap16 (u16 val) +{ +u16 ret; + asmvolatile ("rev16 %0, %1" :"=r" (ret) :"r" (val)); +return ret; +} + +#define __bswap32 bswap32 +static inline u32 bswap32 (u32 val) +{ +u32 ret; + asmvolatile ("rev %0, %1" :"=r" (ret) :"r" (val)); +return ret; +} + +#include "asm-generic/io.h" + +#endif /* _ASMARM_IO_H_ */ lib/arm/asm/setup.h new file +26
-0@@ -0,0 +1,39 @@ +#ifndef _ASMARM_SETUP_H_ +#define _ASMARM_SETUP_H_ +/* +* Copyright (C) 2014, Red Hat Inc, Andrew Jones <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2. +*/ +#include "libcflat.h" + +#define NR_CPUS 8 +extern u32 cpus[NR_CPUS ]; +extern int nr_cpus; + +typedef u64 phys_addr_t ; + +#define NR_MEMREGIONS 16 +struct memregion { +phys_addr_t addr; +phys_addr_t size; +bool free; +}; + +extern struct memregion memregions[NR_MEMREGIONS ]; +extern int nr_memregions; + +extern struct memregion *memregion_new (phys_addr_t size);
Quoted 8 lines
lib/arm/asm/setup.h line 32
Quoted 6 lines
lib/arm/asm/setup.h new file +6
-0+extern void memregions_show (void ); + +#define PHYS_OFFSET ({ memregions[0].addr; }) +#define PHYS_SHIFT 40 +#define PHYS_SIZE (1ULL << PHYS_SHIFT) +#define PHYS_MASK (PHYS_SIZE - 1ULL)it's pretty funky that you define
PHYS_MASKthe opposite ofPAGE_MASK?
I agree. I had a brain flip-flop when I first read it - but then stole it as is from the kernel. I'm trying to keep all these types of things identical to the kernel in order to avoid doing even more flip-flops when bouncing back and forth.
Quoted 95 lines
Quoted 95 lines
lib/arm/asm/setup.h new file +7
-0+ +#define PAGE_SHIFT 12 +#define PAGE_SIZE (1UL << PAGE_SHIFT) +#define PAGE_MASK (~(PAGE_SIZE - 1UL)) +#define PAGE_ALIGN (addr) (((addr) + (PAGE_SIZE-1UL)) & PAGE_MASK) + +#endif /* _ASMARM_SETUP_H_ */ lib/arm/asm/spinlock.h new file +16
-0@@ -0,0 +1,16 @@ +#ifndef _ASMARM_SPINLOCK_H_ +#define _ASMARM_SPINLOCK_H_ + +struct spinlock { +int v; +}; + +//TODO +static inline void spin_lock(struct spinlock *lock __unused) +{ +} +static inline void spin_unlock(struct spinlock *lock __unused) +{ +} + +#endif /* _ASMARM_SPINLOCK_H_ */ lib/arm/eabi_compat.c new file +20
-0@@ -0,0 +1,20 @@ +/* +* Adapted from u-boot's arch/arm/lib/eabi_compat.c +*/ +#include "libcflat.h" + +int raise(int signum __unused) +{ +printf ("Divide by zero!\n" ); +abort (); +return 0 ; +} + +/* Dummy functions to avoid linker complaints */ +void __aeabi_unwind_cpp_pr0 (void ) +{ +} + +void __aeabi_unwind_cpp_pr1 (void ) +{ +}lib/arm/io.c new file +33
-0@@ -0,0 +1,66 @@ +/* +* Each architecture must implement puts() and exit() with the I/O +* devices exposed from QEMU, e.g. pl011 and virtio-testdev. That's +* what's done here, along with initialization functions for those +* devices. +* +* Copyright (C) 2014, Red Hat Inc, Andrew Jones <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2. +*/ +#include "libcflat.h" +#include "devicetree.h" +#include "virtio-testdev.h" +#include "asm/spinlock.h" +#include "asm/io.h" + +extern void halt (int code); + +/* +* Use this guess for the pl011 base in order to make an attempt at +* having earlier printf support. We'll overwrite it with the real +* base address that we read from the device tree later. +*/ +#define QEMU_MACH_VIRT_PL011_BASE 0x09000000UL + +static struct spinlock uart_lock; +static volatile u8 *uart0_base = (u8 *)QEMU_MACH_VIRT_PL011_BASE ; + +static void uart0_init (void ) +{ +const char *compatible ="arm,pl011" ; +dt_pbus_addr_t base; +int ret;
Quoted 8 lines
lib/arm/io.c line 39
Quoted 6 lines
lib/arm/io.c new file +6
-0+ + ret =dt_pbus_get_baseaddr_compatible (compatible, &base); +assert (ret ==0 || ret == -FDT_ERR_NOTFOUND ); + +if (ret ==0 ) { +assert (sizeof (long ) ==8 || !(base >>32 ));didn't we already check this somewhere? Or was that virtio specific?
yeah, last one was virtio.
Quoted 3 lines
This confirms my suspicion that you should add a dummy identity ioremap function that can do this check once.
Good idea. Will do.
Quoted 13 lines
lib/arm/io.c line 40
Quoted 2 lines
lib/arm/io.c new file +1
-0+ uart0_base = (u8 *)(unsigned long )base;hmmm, u8*, I guess that sort of makes sense...
lib/arm/io.c line 44
Quoted 4 lines
lib/arm/io.c new file +4
-0+ }else { +printf ("%s: %s not found in the device tree, aborting...\n" , + __func__, compatible); +abort ();I think this function would read nicer if you did this right after your assert:
Quoted 6 lines
if (ret) { printf(....); abort(); }
uart0_base= ....;
OK
Quoted 27 lines
Quoted 27 lines
lib/arm/io.c new file +22
-0+ } +} + +void io_init (void ) +{ +uart0_init (); +virtio_testdev_init (); +} + +void puts (const char *s) +{ +spin_lock (&uart_lock); +while (*s) +writel (*s++, uart0_base); +spin_unlock (&uart_lock); +} + +void exit (int code) +{ +virtio_testdev_exit (code); +halt (code); +}lib/arm/setup.c new file +0
-1--- /dev/null
Quoted 8 lines
lib/arm/setup.c line 4
Quoted 6 lines
+++
b/lib/arm/setup.clib/arm/setup.c new file +4
-0@@ -0,0 +1,142 @@ +/* +* Initialize machine setup information and I/O. +* +* After running setup() a flat file knows how many cpus it has 'a flat file knows' ?
yeah, I can do better than that :-)
After running setup() unit tests may query...
Quoted 24 lines
Quoted 24 lines
lib/arm/setup.c new file +23
-0+* (nr_cpus), how much free memory it has, and at what physical +* address that free memory starts (memregions[1].{addr,size}), +* printf() and exit() will both work, and (argc, argv) are ready +* to be passed to main(). +* +* Copyright (C) 2014, Red Hat Inc, Andrew Jones <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2. +*/ +#include "libcflat.h" +#include "libfdt/libfdt.h" +#include "devicetree.h" +#include "asm/spinlock.h" +#include "asm/setup.h" + +extern unsigned long stacktop; +extern void io_init (void ); +extern void setup_args (const char *args); + +u32 cpus[NR_CPUS ] = { [0 ...NR_CPUS -1 ] = (~0UL ) }; +int nr_cpus; + +static struct spinlock memregion_lock;
Quoted 8 lines
lib/arm/setup.c line 33
Quoted 6 lines
lib/arm/setup.c new file +6
-0+struct memregion memregions[NR_MEMREGIONS ]; +int nr_memregions; + +static void cpu_set(int fdtnode __unused, u32 regval, void *info) +{ +unsigned *i = (unsigned *)info;shouldn't you assert (*i) <
NR_CPUS?
yup. will do.
Quoted 6 lines
lib/arm/setup.c line 35
Quoted 3 lines
lib/arm/setup.c new file +2
-0+ cpus[*i] = regval; + *i +=1 ;holy cow that's a convoluted way of counting. Can't you just bump the
nr_cpushere?
true. I might as well just dump 'i' and use nr_cpus.
Quoted 22 lines
Quoted 22 lines
lib/arm/setup.c new file +21
-0+} + +static void cpu_init (void ) +{ +unsigned i =0 ; +assert (dt_for_each_cpu_node (cpu_set, &i) ==0 ); + nr_cpus = i; +} + +static void memregions_init (phys_addr_t freemem_start) +{ +/* we only expect one membank to be defined in the DT */ +struct dt_pbus_reg regs[1 ]; +phys_addr_t addr, size, mem_end; + + nr_memregions =dt_get_memory_params (regs,1 ); + +assert (nr_memregions >0 ); + + addr = regs[0 ].addr; + size = regs[0 ].size;
Quoted 8 lines
lib/arm/setup.c line 62
Quoted 6 lines
lib/arm/setup.c new file +6
-0+ mem_end = addr + size; + +assert (!(addr & ~PHYS_MASK ) && !((mem_end-1 ) & ~PHYS_MASK )); + +#ifdef __arm__ +/* TODO: support highmem? */ I don't think highmem is the right term here, the concept is LPAE
comment changed.
Quoted 20 lines
lib/arm/setup.c line 69
Quoted 8 lines
lib/arm/setup.c new file +7
-0+assert (!((u64 )addr >>32 ) && !((u64)(mem_end-1 ) >>32 )); +#endif + + freemem_start =PAGE_ALIGN (freemem_start); + + memregions[0 ].addr =PAGE_ALIGN (addr); + memregions[0 ].size = freemem_start -PHYS_OFFSET ;don't you want to assert that the membank found in the dt actually covers the addresses we're loaded at?
lib/arm/setup.c line 73
Quoted 4 lines
lib/arm/setup.c new file +4
-0+ + memregions[1 ].addr = freemem_start; + memregions[1 ].size = mem_end - freemem_start; + memregions[1 ].free = true;you could have defines for 0 and 1 here if you have already decided these places have special meanings.
Quoted 6 lines
lib/arm/setup.c line 76
Quoted 3 lines
lib/arm/setup.c new file +3
-0+ nr_memregions =2 ; +} +this is an allocator of sorts, essentially, right? It would be most helpful to document this seemingly very important function.
I have some tweaks to this in a v4 fixups branch. I'll integrate those changes, your suggestions, and some documentation into v5.
Quoted 73 lines
Quoted 70 lines
lib/arm/setup.c new file +66
-0+struct memregion *memregion_new (phys_addr_t size) +{ +phys_addr_t freemem_start, freemem_size, mem_end; +struct memregion *m; + +spin_lock (&memregion_lock); + +assert (memregions[nr_memregions-1 ].free); +assert (memregions[nr_memregions-1 ].size >= size); + + mem_end = memregions[nr_memregions-1 ].addr + + memregions[nr_memregions-1 ].size; + + freemem_start =PAGE_ALIGN (memregions[nr_memregions-1 ].addr + size); + freemem_size = mem_end - freemem_start; + + memregions[nr_memregions-1 ].size = freemem_start + - memregions[nr_memregions-1 ].addr; + memregions[nr_memregions-1 ].free = false; + + m = &memregions[nr_memregions-1 ]; + +if (nr_memregions <NR_MEMREGIONS ) { + memregions[nr_memregions].addr = freemem_start; + memregions[nr_memregions].size = freemem_size; + memregions[nr_memregions].free = true; + ++nr_memregions; + } + +spin_unlock (&memregion_lock); + +return m; +} + +void memregions_show (void ) +{ +int i; +for (i =0 ; i < nr_memregions; ++i) +printf ("%016llx-%016llx [%s]\n" , + memregions[i].addr, + memregions[i].addr + memregions[i].size -1 , + memregions[i].free ?"FREE" :"USED" ); +} + +void setup (unsigned long arg __unused,unsigned long id __unused, +const void *fdt) +{ +const char *bootargs; +u32 fdt_size; + +/* +* Move the fdt to just above the stack. The free memory +* then starts just after the fdt. +*/ + fdt_size =fdt_totalsize (fdt); +assert (fdt_move (fdt, &stacktop, fdt_size) ==0 ); +assert (dt_init (&stacktop) ==0 ); + +memregions_init ((unsigned long )&stacktop + fdt_size); + +io_init (); +cpu_init (); + +assert (dt_get_bootargs (&bootargs) ==0 ); +setup_args (bootargs); +}Signature · 1 line
1.8.1.4Thanks,
-Christoffer
Quoted 18 lines · Christoffer Dall
Quoted 11 lines · Andrew Jones
This is a v4 of a series that introduces arm to kvm-unit-tests. First, it does some tidying up of the repo. Then, it adds support for device trees (libfdt), and for virtio-testdev[1]. Next, it adds the basic infrastructure for booting a test case (guest), and adds a first test case, a self-test to confirm setup was completed successfully. Finally, it further prepares the framework for more complicated tests by adding vector support, and extends the self-test to test that too.
This initial drop doesn't require kvmarm. qemu-system-arm is enough, but it must have mach-virt, and the virtio-testdev patch[1].
This is overall looking really good!
I only had a few comments and questions, but you should be able to sort that out quickly.
Quoted 6 lines
It's a lot of code and growing for every iteration, and this time it was a long gap since the last review, so it took me a while.
I think it would be great if you can address my comments quickly and we can this merged without futher churn and let new functionality come as separate extra patches afterwards.
Thanks a million for the reviewing! I'll get v5 with your acked-by's and reviewed-by's and comments addressed sent out today or tomorrow.
drew
Re: [PATCH v4 10/19] Introduce asm-generic/*.h files
In reply to Christoffer DallQuoted 77 lines · Christoffer Dall
Quoted 76 lines · Andrew Jones
Quoted 74 lines · Christoffer Dall
Quoted 61 lines · Andrew Jones
Architecture neutral code may need to call low-level io accessors, or use spinlocks. Create a generic
io.hto ensure those accessors are defined, and a genericspinlock.hthat complains when included, as we can't write a generic spinlock. These files can be overridden or extended by architecture specific versions placed inlib/$ARCH/asm/.Signed-off-by Andrew Jones <[email protected]>---
v4: introduce lib/asm symlink to get rid of #ifdef__arm__,
addspinlock.htoo
v3: wrt toio.h(was libio.[ch]) only
- get rid ofCONFIG_64BIT, replace with asserts
- get rid of {read,write}_len() [libio.c]
- fix bad *64_to_cpu macros--- .gitignore | 1 + Makefile | 6 +- configure | 11 ++++ lib/asm-generic/io.h | 154 +++++++++++++++++++++++++++++++++++++++++++++ lib/asm-generic/spinlock.h | 4 ++ 5 files changed, 173 insertions(+), 3 deletions(-) create mode 100644 lib/asm-generic/io.h create mode 100644 lib/asm-generic/spinlock.h.gitignore +1
-0@@ -9,6 +9,7 @@ patches .stgit-* cscope.* *.swp +/lib/asm /config.mak /*-run /test.logMakefile +3
-3@@ -76,11 +76,11 @@ libfdt_clean: $(LIBFDT_objdir)/.*.d distclean: clean libfdt_clean - $(RM) config.mak $(TEST_DIR)-run test.log msr.out cscope.* + $(RM) lib/asm config.mak $(TEST_DIR)-run test.log msr.out cscope.* -cscope: common_dirs = lib lib/libfdt +cscope: common_dirs = lib lib/libfdt lib/asm lib/asm-generic cscope: $(RM) ./cscope.* - find $(TEST_DIR) lib/$(TEST_DIR) $(common_dirs) -maxdepth 1 \ + find -L $(TEST_DIR) lib/$(TEST_DIR) $(common_dirs) -maxdepth 1 \ -name '*.[chsS]' -print | sed 's,^\./,,' > ./cscope.files cscope -bkconfigure +0
-0configure if [ $exit -eq 0 ]; then · line 104
Quoted 10 lines
configure +7
-0@@ -95,6 +95,17 @@ if [ $exit -eq 0 ]; then fi rm -f lib_test.c +# link lib/asm for the architecture +rm -f lib/asm +asm=asm-generic +if [ -d lib/$arch/asm ]; then + asm=$arch/asm +elif [ -d lib/$testdir/asm ]; then + asm=$testdir/asmwhy do you need this elif? can you not make sure arch is always set?
Quoted 8 lines
Quoted 3 lines
arch is always set, but there's a chance some arch may not add it's own lib/$arch dir. It's a pretty small chance... but the elif shouldn't hurt.
If we don't have any code that uses this scheme now then let's now have
Makefilerules that encourages non-standard behavior (unless I'm missing the point and this provides a 'feature' for specific archs or something like that).
It would be something of a feature for some imaginary arch. However, as that imaginary arch doesn't exist right now, then I'm fine removing it. Whoever makes the imaginary arch a reality can bring it back.
drew
Quoted 22 lines · Andrew Jones
Quoted 21 lines · Christoffer Dall
Quoted 11 lines · Andrew Jones
This is a v4 of a series that introduces arm to kvm-unit-tests. First, it does some tidying up of the repo. Then, it adds support for device trees (libfdt), and for virtio-testdev[1]. Next, it adds the basic infrastructure for booting a test case (guest), and adds a first test case, a self-test to confirm setup was completed successfully. Finally, it further prepares the framework for more complicated tests by adding vector support, and extends the self-test to test that too.
This initial drop doesn't require kvmarm. qemu-system-arm is enough, but it must have mach-virt, and the virtio-testdev patch[1].
This is overall looking really good!
I only had a few comments and questions, but you should be able to sort that out quickly.
It's a lot of code and growing for every iteration, and this time it was a long gap since the last review, so it took me a while.
Quoted 7 lines
Quoted 3 lines
I think it would be great if you can address my comments quickly and we can this merged without futher churn and let new functionality come as separate extra patches afterwards.
Thanks a million for the reviewing! I'll get v5 with your acked-by's and reviewed-by's and comments addressed sent out today or tomorrow.
Awesome!
-Christoffer
Re: [PATCH v4 08/19] add support for Linux device trees
In reply to Christoffer DallQuoted 90 lines · Christoffer Dall
Quoted 9 lines · Andrew Jones
Add some device tree functions, built on libfdt, to the arch-neutral lib code in order to facilitate the extraction of boot info and device base addresses. These functions should work on device trees conforming to section III of the kernel doc
Documentation/devicetree/booting-without-of.txt.Signed-off-by Andrew Jones <[email protected]>---
v4: reworked everything, added lots of comments todevicetree.h=> reworked everything
that will make it easy to review again ;)Quoted 76 lines
--- lib/devicetree.c | 289 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/devicetree.h | 230 +++++++++++++++++++++++++++++++++++++++++++ lib/libcflat.h | 2 + 3 files changed, 521 insertions(+) create mode 100644 lib/devicetree.c create mode 100644 lib/devicetree.hlib/devicetree.c new file +62
-0@@ -0,0 +1,289 @@ +/* +* Copyright (C) 2014, Red Hat Inc, Andrew Jones <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2. +*/ +#include "libcflat.h" +#include "libfdt/libfdt.h" +#include "devicetree.h" + +static const void *fdt; +static u32 root_nr_address_cells, root_nr_size_cells; + +const void *dt_fdt (void ) +{ +return fdt; +} + +bool dt_available (void ) +{ +return fdt_check_header (fdt) ==0 ; +} + +int dt_get_nr_cells (int fdtnode,u32 *nr_address_cells,u32 *nr_size_cells) +{ +const struct fdt_property *prop; +u32 *nr_cells; +int len; + + prop =fdt_get_property (fdt, fdtnode,"#address-cells" , &len); +if (prop ==NULL ) +return len; + + nr_cells = (u32 *)prop->data; + *nr_address_cells =fdt32_to_cpu (*nr_cells); + + prop =fdt_get_property (fdt, fdtnode,"#size-cells" , &len); +if (prop ==NULL ) +return len; + + nr_cells = (u32 *)prop->data; + *nr_size_cells =fdt32_to_cpu (*nr_cells); + +return 0 ; +} + +void dt_reg_init (struct dt_reg *reg,u32 nr_address_cells,u32 nr_size_cells) +{ +memset (reg,0 ,sizeof (struct dt_reg )); + reg->nr_address_cells = nr_address_cells; + reg->nr_size_cells = nr_size_cells; +} + +int dt_get_reg (int fdtnode,int regidx,struct dt_reg *reg) +{ +const struct fdt_property *prop; +u32 *cells, i; +unsigned nr_tuple_cells; +int len; + + prop =fdt_get_property (fdt, fdtnode,"reg" , &len); +if (prop ==NULL ) +return len;
Quoted 8 lines
lib/devicetree.c line 68
Quoted 6 lines
lib/devicetree.c new file +6
-0+ + cells = (u32 *)prop->data; + nr_tuple_cells = reg->nr_address_cells + reg->nr_size_cells; + regidx *= nr_tuple_cells; + +if (regidx + nr_tuple_cells > len/sizeof (u32))Shouldn't this be >= ?
Not this time. The LHS is the total number of words needed (not an index).
Quoted 17 lines
Quoted 4 lines
lib/devicetree.c new file +3
-0+return -FDT_ERR_NOTFOUND ; + +for (i =0 ; i < reg->nr_address_cells; ++i)lib/devicetree.c line 81
Quoted 10 lines
lib/devicetree.c new file +10
-0+ reg->address_cells[i] =fdt32_to_cpu (cells[regidx + i]); + + regidx += reg->nr_address_cells; +for (i =0 ; i < reg->nr_size_cells; ++i) + reg->size_cells[i] =fdt32_to_cpu (cells[regidx + i]); + +return 0 ; +} + +int dt_pbus_translate_node (int fdtnode,int regidx,void *reg)why doesn't this function take a struct
dt_pbus_reg* instead of a void *?
Guess I forgot my coffee when I wrote it... I'll change that.
Quoted 176 lines
Quoted 176 lines
lib/devicetree.c new file +175
-0+{ +struct dt_pbus_reg *pbus_reg = (struct dt_pbus_reg *)reg; +struct dt_reg raw_reg; +int ret; + +dt_reg_init (&raw_reg, root_nr_address_cells, root_nr_size_cells); + + ret =dt_get_reg (fdtnode, regidx, &raw_reg); +if (ret <0 ) +return ret; + + pbus_reg->addr =dt_pbus_read_cells (raw_reg.nr_address_cells, + raw_reg.address_cells); + pbus_reg->size =dt_pbus_read_cells (raw_reg.nr_size_cells, + raw_reg.size_cells); + +return 0 ; +} + +int dt_pbus_translate (const struct dt_device *dev,int regidx, +void *reg) +{ +return dt_pbus_translate_node (dev->fdtnode, regidx, reg); +} + +int dt_pbus_get_baseaddr (const struct dt_device *dev,dt_pbus_addr_t *base) +{ +struct dt_pbus_reg reg; +int ret; + + ret =dt_pbus_translate (dev,0 , ®); +if (ret <0 ) +return ret; + + *base = reg.addr; +return 0 ; +} + +int dt_bus_match_any(const struct dt_device *dev __unused, int fdtnode) +{ +/* matches any device with a valid node */ +return fdtnode <0 ? fdtnode :1 ; +} + +static const struct dt_bus dt_default_bus = { + .match = dt_bus_match_any, + .translate = dt_pbus_translate, +}; + +void dt_bus_init_defaults (struct dt_bus *bus) +{ +memcpy (bus, &dt_default_bus,sizeof (struct dt_bus )); +} + +void dt_device_init (struct dt_device *dev,const struct dt_bus *bus, +const void *info) +{ +memset (dev,0 ,sizeof (struct dt_device )); + dev->bus = bus; + dev->info = (void *)info; +} + +int dt_device_find_compatible (const struct dt_device *dev, +const char *compatible) +{ +int node, ret; + + node =fdt_node_offset_by_compatible (fdt,-1 , compatible); +while (node >=0 ) { + ret = dev->bus->match (dev, node); +if (ret <0 ) +return ret; +else if (ret) +break ; + node =fdt_node_offset_by_compatible (fdt, node, compatible); + } +return node; +} + +int dt_pbus_get_baseaddr_compatible (const char *compatible, +dt_pbus_addr_t *baseaddr) +{ +struct dt_device dev; +int node, ret; + +dt_device_init (&dev, &dt_default_bus,NULL ); + + node =dt_device_find_compatible (&dev, compatible); +if (node <0 ) +return node; + +dt_device_bind_node (&dev, node); + + ret =dt_pbus_get_baseaddr (&dev, baseaddr); +if (ret <0 ) +return ret; + +return 0 ; +} + +int dt_get_memory_params (struct dt_pbus_reg *regs,int nr_regs) +{ +const char *pn ="device_type" , *pv ="memory" ; +int node, ret, pl =strlen (pv) +1 , nr =0 ; +struct dt_pbus_reg reg; + + node =fdt_node_offset_by_prop_value (fdt,-1 , pn, pv, pl); + +while (node >=0 ) { + +while (nr < nr_regs) { + ret =dt_pbus_translate_node (node, nr, ®); +if (ret == -FDT_ERR_NOTFOUND ) +break ; +if (ret <0 ) +return ret; + regs[nr].addr = reg.addr; + regs[nr].size = reg.size; + ++nr; + } + + node =fdt_node_offset_by_prop_value (fdt, node, pn, pv, pl); + } + +return node != -FDT_ERR_NOTFOUND ? node : nr; +} + +int dt_for_each_cpu_node (void (*func)(int fdtnode,u32 regval,void *info), +void *info) +{ +const struct fdt_property *prop; +int cpus, cpu, ret, len; +struct dt_reg raw_reg; +u32 nac, nsc; + + cpus =fdt_path_offset (fdt,"/cpus" ); +if (cpus <0 ) +return cpus; + + ret =dt_get_nr_cells (cpus, &nac, &nsc); +if (ret <0 ) +return ret; + +dt_reg_init (&raw_reg, nac, nsc); + +dt_for_each_subnode (cpus, cpu) { + + prop =fdt_get_property (fdt, cpu,"device_type" , &len); +if (prop ==NULL ) +return len; + +if (len !=4 ||strcmp ((char *)prop->data,"cpu" )) +continue ; + + ret =dt_get_reg (cpu,0 , &raw_reg); +if (ret <0 ) +return ret; + +func (cpu, raw_reg.address_cells[0 ], info); + } + +return 0 ; +} + +int dt_get_bootargs (const char **bootargs) +{ +const struct fdt_property *prop; +int node, len; + + *bootargs =NULL ; + + node =fdt_path_offset (fdt,"/chosen" ); +if (node <0 ) +return node; +
Quoted 8 lines
lib/devicetree.c line 261
Quoted 5 lines
lib/devicetree.c new file +5
-0+ prop =fdt_get_property (fdt, node,"bootargs" , &len); +if (prop) + *bootargs = (char *)prop->data; +else if (len <0 && len != -FDT_ERR_NOTFOUND ) +return len;so if you get
FDT_ERR_NOTFOUNDyou still return success but the bootargs won't be set? why?
bootargs will be NULL in that case, which is enough to know there wasn't any. I also wanted to be able to easily check for any other error without having to filter FDT_ERR_NOTFOUND at every call site. I can skip this special behavior though, if a more consistent interface is preferred.
Quoted 53 lines
Quoted 53 lines
lib/devicetree.c new file +28
-0+ +return 0 ; +} + +int dt_init (const void *fdt_ptr) +{ +struct dt_bus *defbus = (struct dt_bus *)&dt_default_bus; +int root, ret; + + ret =fdt_check_header (fdt_ptr); +if (ret <0 ) +return ret; + fdt = fdt_ptr; + + root =fdt_path_offset (fdt,"/" ); +if (root <0 ) +return root; + + ret =dt_get_nr_cells (root, &root_nr_address_cells, + &root_nr_size_cells); +if (ret <0 ) +return ret; + + defbus->nr_address_cells = root_nr_address_cells; + defbus->nr_size_cells = root_nr_size_cells; + +return 0 ; +}lib/devicetree.h new file +18
-0@@ -0,0 +1,230 @@ +#ifndef _DEVICETREE_H_ +#define _DEVICETREE_H_ +/* +* devicetree builds on libfdt to implement abstractions and accessors +* for Linux required device tree content. The accessors provided are +* common across architectures. See section III of the kernel doc +* Documentation/devicetree/booting-without-of.txt +* +* Copyright (C) 2014, Red Hat Inc, Andrew Jones <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2. +*/ +#include "libcflat.h" +#include "libfdt/libfdt.h" + +/********************************************************************** +* devicetree init and libfdt helpers +**********************************************************************/
Quoted 8 lines
lib/devicetree.h line 24
Quoted 6 lines
lib/devicetree.h new file +6
-0+ +/* dt_init initializes devicetree with a pointer to an fdt, @fdt_ptr */ +extern int dt_init (const void *fdt_ptr); + +/* get the fdt pointer that devicetree is using */ +const void *dt_fdt (void );nit: why no extern here?
Just forgot it. Will add it.
Quoted 59 lines
Quoted 59 lines
lib/devicetree.h new file +58
-0+ +/* check for an initialized, valid devicetree */ +extern bool dt_available (void ); + +/* traverse child nodes */ +#define dt_for_each_subnode (n, s) \ + for (s = fdt_first_subnode(dt_fdt(), n); \ + s != -FDT_ERR_NOTFOUND; \ + s = fdt_next_subnode(dt_fdt(), s)) + +/********************************************************************** +* Abstractions for required node types and properties +**********************************************************************/ + +struct dt_device { +int fdtnode; +const struct dt_bus *bus; + +/* +* info is a pointer to device specific data, which may be +* used by the bus match() and translate() functions +*/ +void *info; +}; + +struct dt_bus { +/* +* match a device @dev to an fdt node @fdtnode +* returns +* - a positive value on match +* - zero on no match +* - a negative FDT_ERR_* value on failure +*/ +int (*match)(const struct dt_device *dev,int fdtnode); + +/* +* translate the @regidx'th "address size" tuple of +* @dev's fdt node's "reg" property, and store the result +* in @reg, a bus specific structure +* returns +* - zero on success +* - a negative FDT_ERR_* value on failure +*/ +int (*translate)(const struct dt_device *dev,int regidx,void *reg); + +/* the bus #address-cells and #size-cells properties */ +u32 nr_address_cells, nr_size_cells; +}; + +/* dt_bus_match_any matches any fdt node, i.e. it always returns true */ +extern int dt_bus_match_any (const struct dt_device *dev,int fdtnode); + +/* the processor bus (pbus) address type and register tuple */ +typedef u64 dt_pbus_addr_t ; +struct dt_pbus_reg { +dt_pbus_addr_t addr; +dt_pbus_addr_t size; +};
Quoted 8 lines
lib/devicetree.h line 87
Quoted 5 lines
lib/devicetree.h new file +5
-0+ +static inline dt_pbus_addr_t dt_pbus_read_cells (u32 nr_cells,u32 *cells) +{ +return nr_cells ==2 ? ((u64 )cells[0 ] <<32 ) | cells[1 ] + : nr_cells ==1 ? cells[0 ] : (~0ULL );Why the tertiary operator here? A simple if or select statement should make the code much easier to read and you don't seem to handle
I'll change it.
Quoted 2 lines
#address-cells == 4or #size-cells == 4, despite the fact that you define MAX_ADDRESS_CELLS=4 etc. This seems a bit weird to me.
The default translator only knows how to handle nr_cells==2 or nr_cells==1. DT may have nodes with nr_cells > 2 (up to 4), but users will have to provide their own translators for those.
Quoted 162 lines
Quoted 160 lines
lib/devicetree.h new file +143
-0+} + +/* +* dt_pbus_translate translates device node regs for the +* processor bus using the root node's #address-cells and +* #size-cells and dt_pbus_read_cells() +* returns +* - zero on success +* - a negative FDT_ERR_* value on failure +*/ +extern int dt_pbus_translate (const struct dt_device *dev,int regidx, +void *reg); + +/* +* dt_pbus_translate_node is the same as dt_pbus_translate but +* operates on an fdt node instead of a dt_device +*/ +extern int dt_pbus_translate_node (int fdtnode,int regidx,void *reg); + +/* +* dt_pbus_get_baseaddr is a shortcut for +* dt_pbus_translate(dev, 0, ®); +* *base = reg.addr; +* returns +* - zero on success +* - a negative FDT_ERR_* value on failure +*/ +extern int dt_pbus_get_baseaddr (const struct dt_device *dev, +dt_pbus_addr_t *base); + +/* +* dt_bus_init_defaults initializes @bus with +* match <- dt_bus_match_any +* translate <- dt_pbus_translate +* nr_address_cells <- #address-cells of the root node +* nr_size_cells <- #size-cells of the root node +*/ +extern void dt_bus_init_defaults (struct dt_bus *bus); + +/* +* dt_device_init initializes a dt_device with the given parameters +*/ +extern void dt_device_init (struct dt_device *dev,const struct dt_bus *bus, +const void *info); + +static inline void dt_device_bind_node (struct dt_device *dev,int fdtnode) +{ + dev->fdtnode = fdtnode; +} + +/* +* dt_device_find_compatible finds a @compatible node +* returns +* - node (>= 0) on success +* - a negative FDT_ERR_* value on failure +*/ +extern int dt_device_find_compatible (const struct dt_device *dev, +const char *compatible); + +/* +* dt_pbus_get_baseaddr_compatible simply bundles many functions into +* one. It finds the first @compatible fdt node and then translates the +* 0th reg tuple (the base address) using the processor bus translation, +* and finally stores that address in @baseaddr. +* returns +* - zero on success +* - a negative FDT_ERR_* value on failure +*/ +extern int dt_pbus_get_baseaddr_compatible (const char *compatible, +dt_pbus_addr_t *baseaddr); + +/********************************************************************** +* Low-level accessors for required node types and properties +**********************************************************************/ + +/* +* dt_get_nr_cells sets @nr_address_cells and @nr_size_cells to the +* #address-cells and #size-cells properties of @fdtnode +* returns +* - zero on success +* - a negative FDT_ERR_* value on failure +*/ +extern int dt_get_nr_cells (int fdtnode,u32 *nr_address_cells, +u32 *nr_size_cells); + +/* dt_reg is a structure for "raw" reg tuples */ +#define MAX_ADDRESS_CELLS 4 +#define MAX_SIZE_CELLS 4 +struct dt_reg { +u32 nr_address_cells, nr_size_cells; +u32 address_cells[MAX_ADDRESS_CELLS ]; +u32 size_cells[MAX_SIZE_CELLS ]; +}; + +/* +* dt_reg_init initialize a dt_reg struct to zero and sets +* nr_address_cells and nr_size_cells to @nr_address_cells and +* @nr_size_cells respectively. +*/ +extern void dt_reg_init (struct dt_reg *reg,u32 nr_address_cells, +u32 nr_size_cells); + +/* +* dt_get_reg gets the @regidx'th reg tuple of @fdtnode's reg property +* and stores it in @reg. @reg must be initialized. +* returns +* - zero on success +* - a negative FDT_ERR_* value on failure +*/ +extern int dt_get_reg (int fdtnode,int regidx,struct dt_reg *reg); + +/********************************************************************** +* High-level accessors for required node types and properties +**********************************************************************/ + +/* +* dt_get_bootargs gets a pointer to /chosen/bootargs +* returns +* - zero on success +* - a negative FDT_ERR_* value on failure +*/ +extern int dt_get_bootargs (const char **bootargs); + +/* +* dt_get_memory_params gets the memory parameters from the /memory node(s) +* storing each memory region ("address size" tuple) in consecutive entries +* of @regs, up to @nr_regs +* returns +* - number of memory regions found on success +* - a negative FDT_ERR_* value on failure +*/ +extern int dt_get_memory_params (struct dt_pbus_reg *regs,int nr_regs); + +/* +* dt_for_each_cpu_node runs @func on each cpu node in the /cpus node +* passing it its fdt node, its reg property value, and @info +* - zero on success +* - a negative FDT_ERR_* value on failure +*/ +extern int dt_for_each_cpu_node (void (*func)(int fdtnode,u32 regval, +void *info),void *info); + +#endif /* _DEVICETREE_H_ */ lib/libcflat.h +2
-0@@ -22,6 +22,8 @@#include <stdarg.h> +#define __unused __attribute__((__unused__)) +typedef unsigned char u8 ;typedef signed char s8 ;typedef unsigned short u16 ;Signature · 1 line
1.8.1.4-Christoffer
Re: [PATCH v4 11/19] add minimal virtio support for devtree virtio-mmio
In reply to Christoffer DallQuoted 199 lines · Christoffer Dall
Quoted 180 lines · Andrew Jones
Quoted 144 lines · Christoffer Dall
Quoted 143 lines · Andrew Jones
Support the bare minimum of virtio to enable access to the virtio-mmio config space of a device. Currently this implementation must use a device tree to find the device.
Signed-off-by Andrew Jones <[email protected]>---
v4:
- split from the virtio-testdev patch
- search a table to "discover" that the device must be DT/virtio-mmio, which doesn't change anything, but looks less hacky than comments saying the device must be DT/virtio-mmio...
- manage own pool of virtio-mmio pre-allocated device structures in order to avoid needing access to the heap--- lib/libcflat.h | 3 ++ lib/virtio.c | 166 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/virtio.h | 89 +++++++++++++++++++++++++++++++ 3 files changed, 258 insertions(+) create mode 100644 lib/virtio.c create mode 100644 lib/virtio.hlib/libcflat.h +3
-0@@ -62,6 +62,9 @@ extern long atol(const char *ptr);#define ARRAY_SIZE (_a) (sizeof(_a)/sizeof((_a)[0]))#define offsetof (TYPE ,MEMBER ) __builtin_offsetof (TYPE, MEMBER) +#define container_of (ptr, type, member) ({ \ + const typeof( ((type *)0)->member ) *__mptr = (ptr); \ + (type *)( (char *)__mptr - offsetof(type,member) );})#define NULL ((void *)0UL)lib/virtio.c new file +102
-0@@ -0,0 +1,166 @@ +/* +* Copyright (C) 2014, Red Hat Inc, Andrew Jones <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2. +*/ +#include "libcflat.h" +#include "devicetree.h" +#include "asm/spinlock.h" +#include "asm/io.h" +#include "virtio.h" + +enum virtio_hwdesc_type { +VIRTIO_HWDESC_TYPE_DT =0 ,/* device tree */ +NR_VIRTIO_HWDESC_TYPES , +}; + +enum virtio_bus_type { +VIRTIO_BUS_TYPE_MMIO =0 ,/* virtio-mmio */ +NR_VIRTIO_BUS_TYPES , +}; + +struct virtio_bind_bus { +bool (*hwdesc_probe)(void ); +struct virtio_dev *(*device_bind)(u32 devid); +}; + +static struct virtio_dev *vm_dt_device_bind (u32 devid); + +static struct virtio_bind_bus +virtio_bind_busses[NR_VIRTIO_HWDESC_TYPES ][NR_VIRTIO_BUS_TYPES ] = { + +[VIRTIO_HWDESC_TYPE_DT ] = { + + [VIRTIO_BUS_TYPE_MMIO ] = { + .hwdesc_probe = dt_available, + .device_bind = vm_dt_device_bind, + }, +}, +}; + +struct virtio_dev *virtio_bind (u32 devid) +{ +struct virtio_bind_bus *bus; +struct virtio_dev *dev; +int i, j; + +for (i =0 ; i <NR_VIRTIO_HWDESC_TYPES ; ++i) { +for (j =0 ; j <NR_VIRTIO_BUS_TYPES ; ++j) { + + bus = &virtio_bind_busses[i][j]; + +if (!bus->hwdesc_probe ()) +continue ; + + dev = bus->device_bind (devid); +if (dev) +return dev; + } + } + +return NULL ; +} + +/****************************************************** +* virtio-mmio support (config space only) +******************************************************/ + +static void vm_get (struct virtio_dev *vdev,unsigned offset, +void *buf,unsigned len) +{ +struct virtio_mmio_dev *vmdev =to_virtio_mmio_dev (vdev); +u8 *p = buf; +unsigned i; + +for (i =0 ; i < len; ++i) + p[i] =readb (vmdev->base +VIRTIO_MMIO_CONFIG + offset + i); +} + +static void vm_set (struct virtio_dev *vdev,unsigned offset, +const void *buf,unsigned len) +{ +struct virtio_mmio_dev *vmdev =to_virtio_mmio_dev (vdev); +const u8 *p = buf; +unsigned i; + +for (i =0 ; i < len; ++i) +writeb (p[i], vmdev->base +VIRTIO_MMIO_CONFIG + offset + i); +} + +#define NR_VM_DEVICES 32 +static struct spinlock vm_lock; +static struct virtio_mmio_dev vm_devs[NR_VM_DEVICES ]; +static struct virtio_conf_ops vm_confs[NR_VM_DEVICES ]; +static int nr_vm_devs; + +static struct virtio_mmio_dev *vm_new_device (u32 devid) +{ +struct virtio_mmio_dev *vmdev; + +if (nr_vm_devs >=NR_VM_DEVICES ) +return NULL ; +Quoted 8 lines
lib/virtio.c line 105
Quoted 3 lines
lib/virtio.c new file +3
-0+spin_lock (&vm_lock); + vmdev = &vm_devs[nr_vm_devs]; + vmdev->vdev.config = &vm_confs[nr_vm_devs];this seems a bit weird, will we ever share
vm_confsbetweenvm_devsor change thevm_confpointer later on? Couldvm_confjust be part of thevm_devstruct and you could just have avirtio_mmio_conf_init()to set the get/set functions?I can do that, but it'll require a typedef for struct
virtio_devto appease the compiler.Quoted 23 lines
Quoted 9 lines
lib/virtio.c new file +8
-0+ ++nr_vm_devs; +spin_unlock (&vm_lock); + + vmdev->vdev.id.device = devid; + vmdev->vdev.id.vendor =-1 ; + vmdev->vdev.config->get = vm_get; + vmdev->vdev.config->set = vm_set; +lib/virtio.c line 123
Quoted 10 lines
lib/virtio.c new file +10
-0+return vmdev; +} + +/****************************************************** +* virtio-mmio device tree support +******************************************************/ + +struct vm_dt_info { +u32 devid; +void *base;won't work for LPAE and 32-bit arm systems, can't you use
dt_device_bind_node?Quoted 8 lines
Quoted 3 lines
I guess that requires you to have an ioremap function, but it sure seems cleaner to give up there if you don't have proper memory mapping features yet....
Right. I was just skipping past that complexity for now, as mach-virt's DT is currently "nice" (32-bit only addrs). I agree we need to handle LPAE addrs on arm eventually though.
So I think the tradeoff here is very small, it's super easy to fix it so you can support physical addresses > 32 bits in this part of the code. The difficult thing comes when you start dereferencing them, but since we may add virtual addresses at some point too, I really think adding a trivial ioremap function and start using that will make our lives much easier down the line:
/* We don't support virtual addresses yet, trivial identity implementation */ void
__iomem*ioremap(phys_addr_tphys_addr)
Quoted 7 lines
{ assert(sizeof(long) == 8 || !(base >> 32)); return (void *)(unsigned long)phys_addr; }But I can submit that patch after this code goes in if you think it's too much of a headache at this point?
Nah, I'll steal your idea and do it now :-)
Quoted 3 lines
Thanks,
-Christoffer
Re: [PATCH v4 08/19] add support for Linux device trees
In reply to Andrew JonesQuoted 100 lines · Andrew Jones
Quoted 90 lines · Christoffer Dall
Quoted 9 lines · Andrew Jones
Add some device tree functions, built on libfdt, to the arch-neutral lib code in order to facilitate the extraction of boot info and device base addresses. These functions should work on device trees conforming to section III of the kernel doc
Documentation/devicetree/booting-without-of.txt.Signed-off-by Andrew Jones <[email protected]>---
v4: reworked everything, added lots of comments todevicetree.h=> reworked everything
that will make it easy to review again ;)Quoted 76 lines
--- lib/devicetree.c | 289 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/devicetree.h | 230 +++++++++++++++++++++++++++++++++++++++++++ lib/libcflat.h | 2 + 3 files changed, 521 insertions(+) create mode 100644 lib/devicetree.c create mode 100644 lib/devicetree.hlib/devicetree.c new file +62
-0@@ -0,0 +1,289 @@ +/* +* Copyright (C) 2014, Red Hat Inc, Andrew Jones <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2. +*/ +#include "libcflat.h" +#include "libfdt/libfdt.h" +#include "devicetree.h" + +static const void *fdt; +static u32 root_nr_address_cells, root_nr_size_cells; + +const void *dt_fdt (void ) +{ +return fdt; +} + +bool dt_available (void ) +{ +return fdt_check_header (fdt) ==0 ; +} + +int dt_get_nr_cells (int fdtnode,u32 *nr_address_cells,u32 *nr_size_cells) +{ +const struct fdt_property *prop; +u32 *nr_cells; +int len; + + prop =fdt_get_property (fdt, fdtnode,"#address-cells" , &len); +if (prop ==NULL ) +return len; + + nr_cells = (u32 *)prop->data; + *nr_address_cells =fdt32_to_cpu (*nr_cells); + + prop =fdt_get_property (fdt, fdtnode,"#size-cells" , &len); +if (prop ==NULL ) +return len; + + nr_cells = (u32 *)prop->data; + *nr_size_cells =fdt32_to_cpu (*nr_cells); + +return 0 ; +} + +void dt_reg_init (struct dt_reg *reg,u32 nr_address_cells,u32 nr_size_cells) +{ +memset (reg,0 ,sizeof (struct dt_reg )); + reg->nr_address_cells = nr_address_cells; + reg->nr_size_cells = nr_size_cells; +} + +int dt_get_reg (int fdtnode,int regidx,struct dt_reg *reg) +{ +const struct fdt_property *prop; +u32 *cells, i; +unsigned nr_tuple_cells; +int len; + + prop =fdt_get_property (fdt, fdtnode,"reg" , &len); +if (prop ==NULL ) +return len;Quoted 8 lines
lib/devicetree.c line 68
Quoted 6 lines
lib/devicetree.c new file +6
-0+ + cells = (u32 *)prop->data; + nr_tuple_cells = reg->nr_address_cells + reg->nr_size_cells; + regidx *= nr_tuple_cells; + +if (regidx + nr_tuple_cells > len/sizeof (u32))Shouldn't this be >= ?
Quoted 3 lines
Not this time. The LHS is the total number of words needed (not an index).
I see, you're right.
Quoted 205 lines
Quoted 17 lines
Quoted 4 lines
lib/devicetree.c new file +3
-0+return -FDT_ERR_NOTFOUND ; + +for (i =0 ; i < reg->nr_address_cells; ++i)lib/devicetree.c line 81
Quoted 10 lines
lib/devicetree.c new file +10
-0+ reg->address_cells[i] =fdt32_to_cpu (cells[regidx + i]); + + regidx += reg->nr_address_cells; +for (i =0 ; i < reg->nr_size_cells; ++i) + reg->size_cells[i] =fdt32_to_cpu (cells[regidx + i]); + +return 0 ; +} + +int dt_pbus_translate_node (int fdtnode,int regidx,void *reg)why doesn't this function take a struct
dt_pbus_reg* instead of a void *?Guess I forgot my coffee when I wrote it... I'll change that.
Quoted 176 lines
Quoted 176 lines
lib/devicetree.c new file +175
-0+{ +struct dt_pbus_reg *pbus_reg = (struct dt_pbus_reg *)reg; +struct dt_reg raw_reg; +int ret; + +dt_reg_init (&raw_reg, root_nr_address_cells, root_nr_size_cells); + + ret =dt_get_reg (fdtnode, regidx, &raw_reg); +if (ret <0 ) +return ret; + + pbus_reg->addr =dt_pbus_read_cells (raw_reg.nr_address_cells, + raw_reg.address_cells); + pbus_reg->size =dt_pbus_read_cells (raw_reg.nr_size_cells, + raw_reg.size_cells); + +return 0 ; +} + +int dt_pbus_translate (const struct dt_device *dev,int regidx, +void *reg) +{ +return dt_pbus_translate_node (dev->fdtnode, regidx, reg); +} + +int dt_pbus_get_baseaddr (const struct dt_device *dev,dt_pbus_addr_t *base) +{ +struct dt_pbus_reg reg; +int ret; + + ret =dt_pbus_translate (dev,0 , ®); +if (ret <0 ) +return ret; + + *base = reg.addr; +return 0 ; +} + +int dt_bus_match_any(const struct dt_device *dev __unused, int fdtnode) +{ +/* matches any device with a valid node */ +return fdtnode <0 ? fdtnode :1 ; +} + +static const struct dt_bus dt_default_bus = { + .match = dt_bus_match_any, + .translate = dt_pbus_translate, +}; + +void dt_bus_init_defaults (struct dt_bus *bus) +{ +memcpy (bus, &dt_default_bus,sizeof (struct dt_bus )); +} + +void dt_device_init (struct dt_device *dev,const struct dt_bus *bus, +const void *info) +{ +memset (dev,0 ,sizeof (struct dt_device )); + dev->bus = bus; + dev->info = (void *)info; +} + +int dt_device_find_compatible (const struct dt_device *dev, +const char *compatible) +{ +int node, ret; + + node =fdt_node_offset_by_compatible (fdt,-1 , compatible); +while (node >=0 ) { + ret = dev->bus->match (dev, node); +if (ret <0 ) +return ret; +else if (ret) +break ; + node =fdt_node_offset_by_compatible (fdt, node, compatible); + } +return node; +} + +int dt_pbus_get_baseaddr_compatible (const char *compatible, +dt_pbus_addr_t *baseaddr) +{ +struct dt_device dev; +int node, ret; + +dt_device_init (&dev, &dt_default_bus,NULL ); + + node =dt_device_find_compatible (&dev, compatible); +if (node <0 ) +return node; + +dt_device_bind_node (&dev, node); + + ret =dt_pbus_get_baseaddr (&dev, baseaddr); +if (ret <0 ) +return ret; + +return 0 ; +} + +int dt_get_memory_params (struct dt_pbus_reg *regs,int nr_regs) +{ +const char *pn ="device_type" , *pv ="memory" ; +int node, ret, pl =strlen (pv) +1 , nr =0 ; +struct dt_pbus_reg reg; + + node =fdt_node_offset_by_prop_value (fdt,-1 , pn, pv, pl); + +while (node >=0 ) { + +while (nr < nr_regs) { + ret =dt_pbus_translate_node (node, nr, ®); +if (ret == -FDT_ERR_NOTFOUND ) +break ; +if (ret <0 ) +return ret; + regs[nr].addr = reg.addr; + regs[nr].size = reg.size; + ++nr; + } + + node =fdt_node_offset_by_prop_value (fdt, node, pn, pv, pl); + } + +return node != -FDT_ERR_NOTFOUND ? node : nr; +} + +int dt_for_each_cpu_node (void (*func)(int fdtnode,u32 regval,void *info), +void *info) +{ +const struct fdt_property *prop; +int cpus, cpu, ret, len; +struct dt_reg raw_reg; +u32 nac, nsc; + + cpus =fdt_path_offset (fdt,"/cpus" ); +if (cpus <0 ) +return cpus; + + ret =dt_get_nr_cells (cpus, &nac, &nsc); +if (ret <0 ) +return ret; + +dt_reg_init (&raw_reg, nac, nsc); + +dt_for_each_subnode (cpus, cpu) { + + prop =fdt_get_property (fdt, cpu,"device_type" , &len); +if (prop ==NULL ) +return len; + +if (len !=4 ||strcmp ((char *)prop->data,"cpu" )) +continue ; + + ret =dt_get_reg (cpu,0 , &raw_reg); +if (ret <0 ) +return ret; + +func (cpu, raw_reg.address_cells[0 ], info); + } + +return 0 ; +} + +int dt_get_bootargs (const char **bootargs) +{ +const struct fdt_property *prop; +int node, len; + + *bootargs =NULL ; + + node =fdt_path_offset (fdt,"/chosen" ); +if (node <0 ) +return node; +Quoted 8 lines
lib/devicetree.c line 261
Quoted 5 lines
lib/devicetree.c new file +5
-0+ prop =fdt_get_property (fdt, node,"bootargs" , &len); +if (prop) + *bootargs = (char *)prop->data; +else if (len <0 && len != -FDT_ERR_NOTFOUND ) +return len;so if you get
FDT_ERR_NOTFOUNDyou still return success but the bootargs won't be set? why?
Quoted 5 lines
bootargs will be NULL in that case, which is enough to know there wasn't any. I also wanted to be able to easily check for any other error without having to filter
FDT_ERR_NOTFOUNDat every call site. I can skip this special behavior though, if a more consistent interface is preferred.
didn't think about the fact that it's valid not to specify any bootargs. Not sure if it's nicer to return an empty string or NULL, but it works either way.
Quoted 132 lines
Quoted 53 lines
Quoted 53 lines
lib/devicetree.c new file +28
-0+ +return 0 ; +} + +int dt_init (const void *fdt_ptr) +{ +struct dt_bus *defbus = (struct dt_bus *)&dt_default_bus; +int root, ret; + + ret =fdt_check_header (fdt_ptr); +if (ret <0 ) +return ret; + fdt = fdt_ptr; + + root =fdt_path_offset (fdt,"/" ); +if (root <0 ) +return root; + + ret =dt_get_nr_cells (root, &root_nr_address_cells, + &root_nr_size_cells); +if (ret <0 ) +return ret; + + defbus->nr_address_cells = root_nr_address_cells; + defbus->nr_size_cells = root_nr_size_cells; + +return 0 ; +}lib/devicetree.h new file +18
-0@@ -0,0 +1,230 @@ +#ifndef _DEVICETREE_H_ +#define _DEVICETREE_H_ +/* +* devicetree builds on libfdt to implement abstractions and accessors +* for Linux required device tree content. The accessors provided are +* common across architectures. See section III of the kernel doc +* Documentation/devicetree/booting-without-of.txt +* +* Copyright (C) 2014, Red Hat Inc, Andrew Jones <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2. +*/ +#include "libcflat.h" +#include "libfdt/libfdt.h" + +/********************************************************************** +* devicetree init and libfdt helpers +**********************************************************************/ Quoted 8 lines
lib/devicetree.h line 24
Quoted 6 lines
lib/devicetree.h new file +6
-0+ +/* dt_init initializes devicetree with a pointer to an fdt, @fdt_ptr */ +extern int dt_init (const void *fdt_ptr); + +/* get the fdt pointer that devicetree is using */ +const void *dt_fdt (void );nit: why no extern here?
Just forgot it. Will add it.
Quoted 59 lines
Quoted 59 lines
lib/devicetree.h new file +58
-0+ +/* check for an initialized, valid devicetree */ +extern bool dt_available (void ); + +/* traverse child nodes */ +#define dt_for_each_subnode (n, s) \ + for (s = fdt_first_subnode(dt_fdt(), n); \ + s != -FDT_ERR_NOTFOUND; \ + s = fdt_next_subnode(dt_fdt(), s)) + +/********************************************************************** +* Abstractions for required node types and properties +**********************************************************************/ + +struct dt_device { +int fdtnode; +const struct dt_bus *bus; + +/* +* info is a pointer to device specific data, which may be +* used by the bus match() and translate() functions +*/ +void *info; +}; + +struct dt_bus { +/* +* match a device @dev to an fdt node @fdtnode +* returns +* - a positive value on match +* - zero on no match +* - a negative FDT_ERR_* value on failure +*/ +int (*match)(const struct dt_device *dev,int fdtnode); + +/* +* translate the @regidx'th "address size" tuple of +* @dev's fdt node's "reg" property, and store the result +* in @reg, a bus specific structure +* returns +* - zero on success +* - a negative FDT_ERR_* value on failure +*/ +int (*translate)(const struct dt_device *dev,int regidx,void *reg); + +/* the bus #address-cells and #size-cells properties */ +u32 nr_address_cells, nr_size_cells; +}; + +/* dt_bus_match_any matches any fdt node, i.e. it always returns true */ +extern int dt_bus_match_any (const struct dt_device *dev,int fdtnode); + +/* the processor bus (pbus) address type and register tuple */ +typedef u64 dt_pbus_addr_t ; +struct dt_pbus_reg { +dt_pbus_addr_t addr; +dt_pbus_addr_t size; +};Quoted 8 lines
lib/devicetree.h line 87
Quoted 5 lines
lib/devicetree.h new file +5
-0+ +static inline dt_pbus_addr_t dt_pbus_read_cells (u32 nr_cells,u32 *cells) +{ +return nr_cells ==2 ? ((u64 )cells[0 ] <<32 ) | cells[1 ] + : nr_cells ==1 ? cells[0 ] : (~0ULL );Why the tertiary operator here? A simple if or select statement should make the code much easier to read and you don't seem to handle
Quoted 9 lines
I'll change it.
Quoted 2 lines
#address-cells == 4or #size-cells == 4, despite the fact that you define MAX_ADDRESS_CELLS=4 etc. This seems a bit weird to me.
The default translator only knows how to handle nr_cells==2 or nr_cells==1. DT may have nodes with
nr_cells> 2 (up to 4), but users will have to provide their own translators for those.
ok
Quoted 160 lines
Quoted 160 lines
Quoted 160 lines
lib/devicetree.h new file +143
-0+} + +/* +* dt_pbus_translate translates device node regs for the +* processor bus using the root node's #address-cells and +* #size-cells and dt_pbus_read_cells() +* returns +* - zero on success +* - a negative FDT_ERR_* value on failure +*/ +extern int dt_pbus_translate (const struct dt_device *dev,int regidx, +void *reg); + +/* +* dt_pbus_translate_node is the same as dt_pbus_translate but +* operates on an fdt node instead of a dt_device +*/ +extern int dt_pbus_translate_node (int fdtnode,int regidx,void *reg); + +/* +* dt_pbus_get_baseaddr is a shortcut for +* dt_pbus_translate(dev, 0, ®); +* *base = reg.addr; +* returns +* - zero on success +* - a negative FDT_ERR_* value on failure +*/ +extern int dt_pbus_get_baseaddr (const struct dt_device *dev, +dt_pbus_addr_t *base); + +/* +* dt_bus_init_defaults initializes @bus with +* match <- dt_bus_match_any +* translate <- dt_pbus_translate +* nr_address_cells <- #address-cells of the root node +* nr_size_cells <- #size-cells of the root node +*/ +extern void dt_bus_init_defaults (struct dt_bus *bus); + +/* +* dt_device_init initializes a dt_device with the given parameters +*/ +extern void dt_device_init (struct dt_device *dev,const struct dt_bus *bus, +const void *info); + +static inline void dt_device_bind_node (struct dt_device *dev,int fdtnode) +{ + dev->fdtnode = fdtnode; +} + +/* +* dt_device_find_compatible finds a @compatible node +* returns +* - node (>= 0) on success +* - a negative FDT_ERR_* value on failure +*/ +extern int dt_device_find_compatible (const struct dt_device *dev, +const char *compatible); + +/* +* dt_pbus_get_baseaddr_compatible simply bundles many functions into +* one. It finds the first @compatible fdt node and then translates the +* 0th reg tuple (the base address) using the processor bus translation, +* and finally stores that address in @baseaddr. +* returns +* - zero on success +* - a negative FDT_ERR_* value on failure +*/ +extern int dt_pbus_get_baseaddr_compatible (const char *compatible, +dt_pbus_addr_t *baseaddr); + +/********************************************************************** +* Low-level accessors for required node types and properties +**********************************************************************/ + +/* +* dt_get_nr_cells sets @nr_address_cells and @nr_size_cells to the +* #address-cells and #size-cells properties of @fdtnode +* returns +* - zero on success +* - a negative FDT_ERR_* value on failure +*/ +extern int dt_get_nr_cells (int fdtnode,u32 *nr_address_cells, +u32 *nr_size_cells); + +/* dt_reg is a structure for "raw" reg tuples */ +#define MAX_ADDRESS_CELLS 4 +#define MAX_SIZE_CELLS 4 +struct dt_reg { +u32 nr_address_cells, nr_size_cells; +u32 address_cells[MAX_ADDRESS_CELLS ]; +u32 size_cells[MAX_SIZE_CELLS ]; +}; + +/* +* dt_reg_init initialize a dt_reg struct to zero and sets +* nr_address_cells and nr_size_cells to @nr_address_cells and +* @nr_size_cells respectively. +*/ +extern void dt_reg_init (struct dt_reg *reg,u32 nr_address_cells, +u32 nr_size_cells); + +/* +* dt_get_reg gets the @regidx'th reg tuple of @fdtnode's reg property +* and stores it in @reg. @reg must be initialized. +* returns +* - zero on success +* - a negative FDT_ERR_* value on failure +*/ +extern int dt_get_reg (int fdtnode,int regidx,struct dt_reg *reg); + +/********************************************************************** +* High-level accessors for required node types and properties +**********************************************************************/ + +/* +* dt_get_bootargs gets a pointer to /chosen/bootargs +* returns +* - zero on success +* - a negative FDT_ERR_* value on failure +*/ +extern int dt_get_bootargs (const char **bootargs); + +/* +* dt_get_memory_params gets the memory parameters from the /memory node(s) +* storing each memory region ("address size" tuple) in consecutive entries +* of @regs, up to @nr_regs +* returns +* - number of memory regions found on success +* - a negative FDT_ERR_* value on failure +*/ +extern int dt_get_memory_params (struct dt_pbus_reg *regs,int nr_regs); + +/* +* dt_for_each_cpu_node runs @func on each cpu node in the /cpus node +* passing it its fdt node, its reg property value, and @info +* - zero on success +* - a negative FDT_ERR_* value on failure +*/ +extern int dt_for_each_cpu_node (void (*func)(int fdtnode,u32 regval, +void *info),void *info); + +#endif /* _DEVICETREE_H_ */ lib/libcflat.h +2
-0@@ -22,6 +22,8 @@#include <stdarg.h> +#define __unused __attribute__((__unused__)) +typedef unsigned char u8 ;typedef signed char s8 ;typedef unsigned short u16 ;Signature · 1 line
1.8.1.4
Re: [PATCH v4 10/19] Introduce asm-generic/*.h files
In reply to Andrew JonesQuoted 87 lines · Andrew Jones
Quoted 77 lines · Christoffer Dall
Quoted 76 lines · Andrew Jones
Quoted 74 lines · Christoffer Dall
Quoted 61 lines · Andrew Jones
Architecture neutral code may need to call low-level io accessors, or use spinlocks. Create a generic
io.hto ensure those accessors are defined, and a genericspinlock.hthat complains when included, as we can't write a generic spinlock. These files can be overridden or extended by architecture specific versions placed inlib/$ARCH/asm/.Signed-off-by Andrew Jones <[email protected]>---
v4: introduce lib/asm symlink to get rid of #ifdef__arm__,
addspinlock.htoo
v3: wrt toio.h(was libio.[ch]) only
- get rid ofCONFIG_64BIT, replace with asserts
- get rid of {read,write}_len() [libio.c]
- fix bad *64_to_cpu macros--- .gitignore | 1 + Makefile | 6 +- configure | 11 ++++ lib/asm-generic/io.h | 154 +++++++++++++++++++++++++++++++++++++++++++++ lib/asm-generic/spinlock.h | 4 ++ 5 files changed, 173 insertions(+), 3 deletions(-) create mode 100644 lib/asm-generic/io.h create mode 100644 lib/asm-generic/spinlock.h.gitignore +1
-0@@ -9,6 +9,7 @@ patches .stgit-* cscope.* *.swp +/lib/asm /config.mak /*-run /test.logMakefile +3
-3@@ -76,11 +76,11 @@ libfdt_clean: $(LIBFDT_objdir)/.*.d distclean: clean libfdt_clean - $(RM) config.mak $(TEST_DIR)-run test.log msr.out cscope.* + $(RM) lib/asm config.mak $(TEST_DIR)-run test.log msr.out cscope.* -cscope: common_dirs = lib lib/libfdt +cscope: common_dirs = lib lib/libfdt lib/asm lib/asm-generic cscope: $(RM) ./cscope.* - find $(TEST_DIR) lib/$(TEST_DIR) $(common_dirs) -maxdepth 1 \ + find -L $(TEST_DIR) lib/$(TEST_DIR) $(common_dirs) -maxdepth 1 \ -name '*.[chsS]' -print | sed 's,^\./,,' > ./cscope.files cscope -bkconfigure +0
-0configure if [ $exit -eq 0 ]; then · line 104
Quoted 10 lines
configure +7
-0@@ -95,6 +95,17 @@ if [ $exit -eq 0 ]; then fi rm -f lib_test.c +# link lib/asm for the architecture +rm -f lib/asm +asm=asm-generic +if [ -d lib/$arch/asm ]; then + asm=$arch/asm +elif [ -d lib/$testdir/asm ]; then + asm=$testdir/asmwhy do you need this elif? can you not make sure arch is always set?
Quoted 8 lines
Quoted 3 lines
arch is always set, but there's a chance some arch may not add it's own lib/$arch dir. It's a pretty small chance... but the elif shouldn't hurt.
If we don't have any code that uses this scheme now then let's now have
Makefilerules that encourages non-standard behavior (unless I'm missing the point and this provides a 'feature' for specific archs or something like that).
Quoted 4 lines
It would be something of a feature for some imaginary arch. However, as that imaginary arch doesn't exist right now, then I'm fine removing it. Whoever makes the imaginary arch a reality can bring it back.
Oh wait, it's actually not imaginary (just unused). x86 is an example of such a testdir that doesn't == arch. So, if either i386 or x86_64 wanted to use lib/asm, then they need this elif.
drew
Re: [PATCH v4 10/19] Introduce asm-generic/*.h files
Quoted 88 lines · Andrew Jones
Quoted 87 lines · Andrew Jones
Quoted 85 lines · Christoffer Dall
Quoted 76 lines · Andrew Jones
Quoted 65 lines · Christoffer Dall
Quoted 64 lines · Andrew Jones
Architecture neutral code may need to call low-level io accessors, or use spinlocks. Create a generic
io.hto ensure those accessors are defined, and a genericspinlock.hthat complains when included, as we can't write a generic spinlock. These files can be overridden or extended by architecture specific versions placed inlib/$ARCH/asm/.Signed-off-by Andrew Jones <[email protected]>---
v4: introduce lib/asm symlink to get rid of #ifdef__arm__,
addspinlock.htoo
v3: wrt toio.h(was libio.[ch]) only
- get rid ofCONFIG_64BIT, replace with asserts
- get rid of {read,write}_len() [libio.c]
- fix bad *64_to_cpu macros--- .gitignore | 1 + Makefile | 6 +- configure | 11 ++++ lib/asm-generic/io.h | 154 +++++++++++++++++++++++++++++++++++++++++++++ lib/asm-generic/spinlock.h | 4 ++ 5 files changed, 173 insertions(+), 3 deletions(-) create mode 100644 lib/asm-generic/io.h create mode 100644 lib/asm-generic/spinlock.h.gitignore +1
-0@@ -9,6 +9,7 @@ patches .stgit-* cscope.* *.swp +/lib/asm /config.mak /*-run /test.logMakefile +3
-3@@ -76,11 +76,11 @@ libfdt_clean: $(LIBFDT_objdir)/.*.d distclean: clean libfdt_clean - $(RM) config.mak $(TEST_DIR)-run test.log msr.out cscope.* + $(RM) lib/asm config.mak $(TEST_DIR)-run test.log msr.out cscope.* -cscope: common_dirs = lib lib/libfdt +cscope: common_dirs = lib lib/libfdt lib/asm lib/asm-generic cscope: $(RM) ./cscope.* - find $(TEST_DIR) lib/$(TEST_DIR) $(common_dirs) -maxdepth 1 \ + find -L $(TEST_DIR) lib/$(TEST_DIR) $(common_dirs) -maxdepth 1 \ -name '*.[chsS]' -print | sed 's,^\./,,' > ./cscope.files cscope -bkconfigure +0
-0@@ -95,6 +95,17 @@ if [ $exit -eq 0 ]; then fi rm -f lib_test.cQuoted 9 lines
configure if [ $exit -eq 0 ]; then · line 104
Quoted 7 lines
configure +7
-0+# link lib/asm for the architecture +rm -f lib/asm +asm=asm-generic +if [ -d lib/$arch/asm ]; then + asm=$arch/asm +elif [ -d lib/$testdir/asm ]; then + asm=$testdir/asmwhy do you need this elif? can you not make sure arch is always set?
Quoted 3 lines
arch is always set, but there's a chance some arch may not add it's own lib/$arch dir. It's a pretty small chance... but the elif shouldn't hurt.
If we don't have any code that uses this scheme now then let's now have
Makefilerules that encourages non-standard behavior (unless I'm missing the point and this provides a 'feature' for specific archs or something like that).
Quoted 9 lines
Quoted 4 lines
It would be something of a feature for some imaginary arch. However, as that imaginary arch doesn't exist right now, then I'm fine removing it. Whoever makes the imaginary arch a reality can bring it back.
Oh wait, it's actually not imaginary (just unused). x86 is an example of such a testdir that doesn't == arch. So, if either i386 or
x86_64wanted to use lib/asm, then they need this elif.
ah, ok. I'll shut up then.
-Christoffer
Re: [PATCH v4 10/19] Introduce asm-generic/*.h files
Quoted 94 lines · Christoffer Dall
Quoted 93 lines · Andrew Jones
Quoted 91 lines · Andrew Jones
Quoted 77 lines · Christoffer Dall
Quoted 76 lines · Andrew Jones
Quoted 74 lines · Christoffer Dall
Quoted 61 lines · Andrew Jones
Architecture neutral code may need to call low-level io accessors, or use spinlocks. Create a generic
io.hto ensure those accessors are defined, and a genericspinlock.hthat complains when included, as we can't write a generic spinlock. These files can be overridden or extended by architecture specific versions placed inlib/$ARCH/asm/.Signed-off-by Andrew Jones <[email protected]>---
v4: introduce lib/asm symlink to get rid of #ifdef__arm__,
addspinlock.htoo
v3: wrt toio.h(was libio.[ch]) only
- get rid ofCONFIG_64BIT, replace with asserts
- get rid of {read,write}_len() [libio.c]
- fix bad *64_to_cpu macros--- .gitignore | 1 + Makefile | 6 +- configure | 11 ++++ lib/asm-generic/io.h | 154 +++++++++++++++++++++++++++++++++++++++++++++ lib/asm-generic/spinlock.h | 4 ++ 5 files changed, 173 insertions(+), 3 deletions(-) create mode 100644 lib/asm-generic/io.h create mode 100644 lib/asm-generic/spinlock.h.gitignore +1
-0@@ -9,6 +9,7 @@ patches .stgit-* cscope.* *.swp +/lib/asm /config.mak /*-run /test.logMakefile +3
-3@@ -76,11 +76,11 @@ libfdt_clean: $(LIBFDT_objdir)/.*.d distclean: clean libfdt_clean - $(RM) config.mak $(TEST_DIR)-run test.log msr.out cscope.* + $(RM) lib/asm config.mak $(TEST_DIR)-run test.log msr.out cscope.* -cscope: common_dirs = lib lib/libfdt +cscope: common_dirs = lib lib/libfdt lib/asm lib/asm-generic cscope: $(RM) ./cscope.* - find $(TEST_DIR) lib/$(TEST_DIR) $(common_dirs) -maxdepth 1 \ + find -L $(TEST_DIR) lib/$(TEST_DIR) $(common_dirs) -maxdepth 1 \ -name '*.[chsS]' -print | sed 's,^\./,,' > ./cscope.files cscope -bkconfigure +0
-0configure if [ $exit -eq 0 ]; then · line 104
Quoted 10 lines
configure +7
-0@@ -95,6 +95,17 @@ if [ $exit -eq 0 ]; then fi rm -f lib_test.c +# link lib/asm for the architecture +rm -f lib/asm +asm=asm-generic +if [ -d lib/$arch/asm ]; then + asm=$arch/asm +elif [ -d lib/$testdir/asm ]; then + asm=$testdir/asmwhy do you need this elif? can you not make sure arch is always set?
Quoted 8 lines
Quoted 3 lines
arch is always set, but there's a chance some arch may not add it's own lib/$arch dir. It's a pretty small chance... but the elif shouldn't hurt.
If we don't have any code that uses this scheme now then let's now have
Makefilerules that encourages non-standard behavior (unless I'm missing the point and this provides a 'feature' for specific archs or something like that).It would be something of a feature for some imaginary arch. However, as that imaginary arch doesn't exist right now, then I'm fine removing it. Whoever makes the imaginary arch a reality can bring it back.
Quoted 5 lines
Quoted 4 lines
Oh wait, it's actually not imaginary (just unused). x86 is an example of such a testdir that doesn't == arch. So, if either i386 or
x86_64wanted to use lib/asm, then they need this elif.ah, ok. I'll shut up then.
Before you go completely silent on it, how about an Ack?
drew
Quoted 5 lines
-Christoffer
--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Christoffer Dall
Acked-byRe: [PATCH v4 10/19] Introduce asm-generic/*.h files
Quoted 95 lines · Andrew Jones
Quoted 94 lines · Christoffer Dall
Quoted 93 lines · Andrew Jones
Quoted 91 lines · Andrew Jones
Quoted 77 lines · Christoffer Dall
Quoted 76 lines · Andrew Jones
Quoted 74 lines · Christoffer Dall
Quoted 61 lines · Andrew Jones
Architecture neutral code may need to call low-level io accessors, or use spinlocks. Create a generic
io.hto ensure those accessors are defined, and a genericspinlock.hthat complains when included, as we can't write a generic spinlock. These files can be overridden or extended by architecture specific versions placed inlib/$ARCH/asm/.Signed-off-by Andrew Jones <[email protected]>---
v4: introduce lib/asm symlink to get rid of #ifdef__arm__,
addspinlock.htoo
v3: wrt toio.h(was libio.[ch]) only
- get rid ofCONFIG_64BIT, replace with asserts
- get rid of {read,write}_len() [libio.c]
- fix bad *64_to_cpu macros--- .gitignore | 1 + Makefile | 6 +- configure | 11 ++++ lib/asm-generic/io.h | 154 +++++++++++++++++++++++++++++++++++++++++++++ lib/asm-generic/spinlock.h | 4 ++ 5 files changed, 173 insertions(+), 3 deletions(-) create mode 100644 lib/asm-generic/io.h create mode 100644 lib/asm-generic/spinlock.h.gitignore +1
-0@@ -9,6 +9,7 @@ patches .stgit-* cscope.* *.swp +/lib/asm /config.mak /*-run /test.logMakefile +3
-3@@ -76,11 +76,11 @@ libfdt_clean: $(LIBFDT_objdir)/.*.d distclean: clean libfdt_clean - $(RM) config.mak $(TEST_DIR)-run test.log msr.out cscope.* + $(RM) lib/asm config.mak $(TEST_DIR)-run test.log msr.out cscope.* -cscope: common_dirs = lib lib/libfdt +cscope: common_dirs = lib lib/libfdt lib/asm lib/asm-generic cscope: $(RM) ./cscope.* - find $(TEST_DIR) lib/$(TEST_DIR) $(common_dirs) -maxdepth 1 \ + find -L $(TEST_DIR) lib/$(TEST_DIR) $(common_dirs) -maxdepth 1 \ -name '*.[chsS]' -print | sed 's,^\./,,' > ./cscope.files cscope -bkconfigure +0
-0configure if [ $exit -eq 0 ]; then · line 104
Quoted 10 lines
configure +7
-0@@ -95,6 +95,17 @@ if [ $exit -eq 0 ]; then fi rm -f lib_test.c +# link lib/asm for the architecture +rm -f lib/asm +asm=asm-generic +if [ -d lib/$arch/asm ]; then + asm=$arch/asm +elif [ -d lib/$testdir/asm ]; then + asm=$testdir/asmwhy do you need this elif? can you not make sure arch is always set?
Quoted 8 lines
Quoted 3 lines
arch is always set, but there's a chance some arch may not add it's own lib/$arch dir. It's a pretty small chance... but the elif shouldn't hurt.
If we don't have any code that uses this scheme now then let's now have
Makefilerules that encourages non-standard behavior (unless I'm missing the point and this provides a 'feature' for specific archs or something like that).It would be something of a feature for some imaginary arch. However, as that imaginary arch doesn't exist right now, then I'm fine removing it. Whoever makes the imaginary arch a reality can bring it back.
Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
Oh wait, it's actually not imaginary (just unused). x86 is an example of such a testdir that doesn't == arch. So, if either i386 or
x86_64wanted to use lib/asm, then they need this elif.ah, ok. I'll shut up then.
Before you go completely silent on it, how about an Ack?
ack
Alexander Graf
Acked-byRe: [PATCH v4 01/19] remove unused files
In reply to Andrew JonesQuoted 7 lines · Andrew Jones
Quoted 6 lines · Christoffer Dall
Quoted 5 lines · Andrew Jones
There are several unused files, primarily because powerpc is an unused arch. The exceptions are config-ia64.mak, which is also an unused arch file,
lib/fwcfg.c,lib/panic.c,x86/print.hand x86/run-kvm-unit-tests, which are just unused. Remove them all in order to tidy things up.
Quoted 5 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Andrew Jones <[email protected]>Sounds reasonable enough for me, but you probably want an acked-by from the people who actually know if they should care about these files or not.
Agreed. Alex? Paolo?
We haven't managed to revive the test cases in all the years, so yeah :(
Alex