Skip to contentSkip to conversation

kvm-unit-tests/arm: initial drop

PATCH Superseded Andrew Jones 3 participants 44 messages Dec 4, 2013 – Jan 3, 2014

Subsystems (3)

v2 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v2 cover kvm-unit-tests/arm: initial drop

This is a v2 of a series that introduces arm to kvm-unit-tests. First, it does some tidying up of the repo. Then, it adds support for virtio-testdev, which a v2 of was just posted to qemu-devel[1]. Next, it adds the basic infrastructure for booting a test case (guest), and adds a single simple test.

The v1 of this series also added support for vectors. This time I'm posting the initial drop without it, but will be sending the vector support separately soon.

This initial drop doesn't require kvmarm. Only qemu-system-arm, with the most recent mach-virt patches[2] and the previously mentioned virtio-testdev, is required.

[1] http://lists.nongnu.org/archive/html/qemu-devel/2013-12/msg00690.html
[2] http://lists.nongnu.org/archive/html/qemu-devel/2013-11/msg02912.html

These patches are also available from a git repo here
https://github.com/rhdrjones/kvm-unit-tests/commits/arm-branch/master

Andrew Jones (9):
remove unused files
makefile and run_tests tweaks
clean root dir of all x86-ness
move x86's simple heap management to common code Introduce libio to common code for io read/write Introduce a simple iomap structure
Add halt() and some error codes Introduce virtio-testdev
arm: initial drop

 Makefile                      |  19 +-
 README                        |  56 ++--
 arm/boot.c                    |  17 +
 arm/cstart.S                  |  38 +++
 arm/flat.lds                  |  18 ++
 arm/run                       |  19 ++
 arm/unittests.cfg             |  11 +
 config-i386.mak               |  13 -
 config-ia64.mak               |   7 -
 config-powerpc-440.mak        |  15 -
 config-powerpc.mak            |  39 ---
 config-x86-common.mak         | 122 --------
 config-x86_64.mak             |  14 -
 config/config-arm.mak         |  73 +++++
 config/config-i386.mak        |  12 +
 config/config-x86-common.mak  | 121 ++++++++
 config/config-x86_64.mak      |  13 +
 configure                     |  27 +-
 docs/testdev.txt              |  11 +
 flat.lds                      |  21 --
 formats                       |  31 --
 iotable.c                     |  53 ----
 iotable.h                     |  40 ---
 kvmtrace.c                    | 706 ------------------------------------------
 kvmtrace_format               | 532 -------------------------------
 lib/arm/eabi_compat.c         |  20 ++
 lib/arm/io.c                  |  31 ++
 lib/arm/io.h                  |  24 ++
 lib/arm/setup.c               |  85 +++++
 lib/arm/sysinfo.h             |  19 ++
 lib/errno.h                   |  22 ++
 lib/fwcfg.c                   |  58 ----
 lib/heap.c                    |  43 +++
 lib/heap.h                    |   8 +
 lib/iomaps.c                  |  31 ++
 lib/iomaps.h                  |  14 +
 lib/libcflat.h                |   8 +-
 lib/libio.c                   |  67 ++++
 lib/libio.h                   | 180 +++++++++++
 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/test_util.c               |  34 ++
 lib/test_util.h               |  13 +
 lib/virtio-testdev.c          | 139 +++++++++
 lib/virtio-testdev.h          |   9 +
 lib/virtio.c                  |  70 +++++
 lib/virtio.h                  |  74 +++++
 lib/x86/vm.c                  |  33 +-
 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                  |  19 +-
 scripts/gen-devtree-iomaps.pl | 105 +++++++
 testdev.txt                   |  14 -
 x86-run                       |  41 ---
 x86/README                    |  60 +++-
 x86/flat.lds                  |  21 ++
 x86/print.h                   |  19 --
 x86/run                       |  41 +++
 x86/run-kvm-unit-tests        |   6 -
 72 files changed, 1502 insertions(+), 2651 deletions(-)
 create mode 100644 arm/boot.c
 create mode 100644 arm/cstart.S
 create mode 100644 arm/flat.lds
 create mode 100755 arm/run
 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/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/eabi_compat.c
 create mode 100644 lib/arm/io.c
 create mode 100644 lib/arm/io.h
 create mode 100644 lib/arm/setup.c
 create mode 100644 lib/arm/sysinfo.h
 create mode 100644 lib/errno.h
 delete mode 100644 lib/fwcfg.c
 create mode 100644 lib/heap.c
 create mode 100644 lib/heap.h
 create mode 100644 lib/iomaps.c
 create mode 100644 lib/iomaps.h
 create mode 100644 lib/libio.c
 create mode 100644 lib/libio.h
 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/test_util.c
 create mode 100644 lib/test_util.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
 create mode 100755 scripts/gen-devtree-iomaps.pl
 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
#1 lore raw

PATCH v2 1/9 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
index b6e87598721a6..278791dbbef23 100644
@@ -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
 cflatobjs += lib/argv.o
@@ -39,11 +38,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 $@ $^
 
@@ -57,4 +51,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
deleted file mode 100644
index d9350fcc5a9ec..0000000000000
@@ -1,7 +0,0 @@
-bits = 64
-CFLAGS += -m64
-CFLAGS += -D__ia64__
-CFLAGS += -I../include/ia64
-
-all:
-
config-powerpc-440.mak deleted +0 -15
deleted file mode 100644
index bb8597153b30e..0000000000000
@@ -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
deleted file mode 100644
index d053569b8aa3c..0000000000000
@@ -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
deleted file mode 100644
index 7f4ebdbcedaa2..0000000000000
@@ -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
deleted file mode 100644
index cb18f23789be1..0000000000000
@@ -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
index fadc33d30f85b..140c172e77d54 100644
@@ -38,7 +38,6 @@ typedef _Bool bool;
 #define false 0
 
 extern 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
deleted file mode 100644
index 6e0b29ebed503..0000000000000
@@ -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
deleted file mode 100644
index 385904da3c161..0000000000000
@@ -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
deleted file mode 100644
index ce85347bd17c5..0000000000000
@@ -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
deleted file mode 100644
index 3790374eb5c61..0000000000000
@@ -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
deleted file mode 100644
index 8bd239521f25f..0000000000000
@@ -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
deleted file mode 100644
index b15874b18b74c..0000000000000
@@ -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
deleted file mode 100644
index ec6ef5c57fc47..0000000000000
@@ -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
deleted file mode 100644
index 1bd10bf17a187..0000000000000
@@ -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
deleted file mode 100644
index 5efd30357daa9..0000000000000
@@ -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
deleted file mode 100644
index 70a0e9fcd47c9..0000000000000
@@ -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
deleted file mode 100644
index 804ee04d9f88e..0000000000000
@@ -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
deleted file mode 100644
index f8630f7c5381f..0000000000000
@@ -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
deleted file mode 100644
index 97567cb6c73f2..0000000000000
@@ -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
deleted file mode 100644
index 4406641c2711c..0000000000000
@@ -1,4 +0,0 @@
-
-.global _start
-_start:
-	b	.
powerpc/sprg.S deleted +0 -7
deleted file mode 100644
index d0414a480342a..0000000000000
@@ -1,7 +0,0 @@
-
-.global _start
-_start:
-	li	r3, 42
-	mtsprg	0, r3
-	mfsprg	r4, 0
-	b	.
x86/print.h deleted +0 -19
deleted file mode 100644
index d5bd2f9978dc4..0000000000000
@@ -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
deleted file mode 100644
index fed925a3d70fe..0000000000000
@@ -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
#2 lore raw

PATCH v2 2/9 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

---
 Makefile              |  8 ++++----
 config-x86-common.mak | 16 +++++++---------
 run_tests.sh          |  2 +-
 3 files changed, 12 insertions(+), 14 deletions(-)
Makefile +4 -4
index 278791dbbef23..697fc2a766966 100644
@@ -12,9 +12,9 @@ libgcc := $(shell $(CC) --print-libgcc-file-name)
 
 libcflat := lib/libcflat.a
 cflatobjs := \
+	lib/argv.o \
 	lib/printf.o \
 	lib/string.o
-cflatobjs += lib/argv.o
 
 #include architecure specific make rules
 include config-$(ARCH).mak
@@ -25,8 +25,8 @@ 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 += $(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.
@@ -51,4 +51,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
index bf88c672de472..7e481192a0737 100644
@@ -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 \
@@ -105,7 +103,7 @@ $(TEST_DIR)/vmx.elf: $(cstart.o) $(TEST_DIR)/vmx.o $(TEST_DIR)/vmx_tests.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 +1 -1
index 55ecac5bed3a4..f373c533b75b2 100755
@@ -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
Signature · 1 line
1.8.1.4
#3 lore raw

Re: [PATCH 2/9] makefile and run_tests tweaks

On Wed, Dec 04, 2013 at 05:42:50PM +0100, Andrew Jones wrote:

This is a really short commit message, for anyone not super-familiar with the make system in this toolset, it makes it quite hard to understand the change. See some examples below:

Quoted 3 lines

- remove a redundant '-display none'
- remove a redundant -g from CFLAGS
- remove a useless -I../include/x86 from CFLAGS

why is this include useless?

Quoted 1 line

- remove lib autodep files on make clean

why?

Quoted 24 lines
---
 Makefile              |  8 ++++----
 config-x86-common.mak | 16 +++++++---------
 run_tests.sh          |  2 +-
 3 files changed, 12 insertions(+), 14 deletions(-)
Makefile +1 -1
index 278791dbbef23..697fc2a766966 100644
@@ -12,9 +12,9 @@ libgcc := $(shell $(CC) --print-libgcc-file-name)
 
 libcflat := lib/libcflat.a
 cflatobjs := \
+	lib/argv.o \
 	lib/printf.o \
 	lib/string.o
-cflatobjs += lib/argv.o
 
 #include architecure specific make rules
 include config-$(ARCH).mak

Makefile include config-$(ARCH).mak · line 28

Quoted 4 lines
Makefile +0 -1
@@ -25,8 +25,8 @@ 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

seems like a good idea to compile test code without optimizations, is that what you're trying to achieve here? Seems to me this should be a separate change or at least motivated in the commit text.

Makefile include config-$(ARCH).mak · line 29

Quoted 1 line
Makefile +0 -1
-CFLAGS += $(autodepend-flags) -g -fomit-frame-pointer -Wall

I like removing the redundant -g but wouldn't it be cleaner to set the CFLAGS to an empty string in the beginning of the file and then have a seprate line for -g where all the CFLAGS are set?

Quoted 80 lines
Makefile +3 -1
+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.
@@ -51,4 +51,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
index bf88c672de472..7e481192a0737 100644
@@ -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 \
@@ -105,7 +103,7 @@ $(TEST_DIR)/vmx.elf: $(cstart.o) $(TEST_DIR)/vmx.o $(TEST_DIR)/vmx_tests.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 +1 -1
index 55ecac5bed3a4..f373c533b75b2 100755
@@ -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
Signature · 6 lines
1.8.1.4

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/cucslists/listinfo/kvmarm
Signature · 1 line
Christoffer
#4 lore raw

Re: [PATCH 2/9] makefile and run_tests tweaks

Quoted 11 lines · Christoffer Dall

On Wed, Dec 04, 2013 at 05:42:50PM +0100, Andrew Jones wrote:

This is a really short commit message, for anyone not super-familiar with the make system in this toolset, it makes it quite hard to understand the change. See some examples below:

Quoted 3 lines

- remove a redundant '-display none'
- remove a redundant -g from CFLAGS
- remove a useless -I../include/x86 from CFLAGS

why is this include useless?

The directory doesn't exist.

Quoted 4 lines
Quoted 2 lines

- remove lib autodep files on make clean

why?

There should be a way to get rid of them. Maybe add a 'realclean' target? I think that would be overkill though, as 'make clean' isn't something I expect people to run all that frequently anyway.

Quoted 28 lines
Quoted 28 lines
---
 Makefile              |  8 ++++----
 config-x86-common.mak | 16 +++++++---------
 run_tests.sh          |  2 +-
 3 files changed, 12 insertions(+), 14 deletions(-)
Makefile +1 -1
index 278791dbbef23..697fc2a766966 100644
@@ -12,9 +12,9 @@ libgcc := $(shell $(CC) --print-libgcc-file-name)
 
 libcflat := lib/libcflat.a
 cflatobjs := \
+	lib/argv.o \
 	lib/printf.o \
 	lib/string.o
-cflatobjs += lib/argv.o
 
 #include architecure specific make rules
 include config-$(ARCH).mak
@@ -25,8 +25,8 @@ 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 ;)
 
Quoted 5 lines

Makefile include config-$(ARCH).mak · line 28

Quoted 1 line
Makefile +0 -1
-CFLAGS += -O1

seems like a good idea to compile test code without optimizations, is that what you're trying to achieve here? Seems to me this should be a separate change or at least motivated in the commit text.

No, I keep the -O1, but it gets moved to an x86 specific file in order to give each arch their own choice.

Quoted 6 lines

Makefile include config-$(ARCH).mak · line 29

Quoted 2 lines
Makefile +0 -1
-CFLAGS += $(autodepend-flags) -g -fomit-frame-pointer -Wall

I like removing the redundant -g but wouldn't it be cleaner to set the CFLAGS to an empty string in the beginning of the file and then have a seprate line for -g where all the CFLAGS are set?

OK, done for v3.

drew

#5 lore raw

PATCH v2 3/9 clean root dir of all x86-ness

In reply to 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.

---
v2:
- tests' images => test images [Christoffer Dall]

TODO:
- more documentation is still needed, we should add
* an overview of the framework
* improve the quickstart guide for running the tests
* add a quickstart guide for developing tests

---
 Makefile                     |   7 ++-
 README                       |  55 +++++++++-----------
 config-i386.mak              |  13 -----
 config-x86-common.mak        | 120 -------------------------------------------
 config-x86_64.mak            |  14 -----
 config/config-i386.mak       |  12 +++++
 config/config-x86-common.mak | 120 +++++++++++++++++++++++++++++++++++++++++++
 config/config-x86_64.mak     |  13 +++++
 configure                    |  17 ++++++
 docs/testdev.txt             |  11 ++++
 flat.lds                     |  21 --------
 run_tests.sh                 |  19 ++++---
 testdev.txt                  |  14 -----
 x86-run                      |  41 ---------------
 x86/README                   |  60 +++++++++++++++++-----
 x86/flat.lds                 |  21 ++++++++
 x86/run                      |  41 +++++++++++++++
 17 files changed, 316 insertions(+), 283 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
index 697fc2a766966..7a5ec8e6348bf 100644
@@ -17,7 +17,7 @@ cflatobjs := \
 	lib/string.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)
@@ -29,7 +29,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)
 
@@ -44,11 +43,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 -32

59 lines not on this page · raw message

config-i386.mak deleted +0 -13
deleted file mode 100644
index de52f3d53cff8..0000000000000
@@ -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 -120

120 lines not on this page · raw message

config-x86_64.mak deleted +0 -14
deleted file mode 100644
index bb8ee89713abd..0000000000000
@@ -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
-tests += $(TEST_DIR)/svm.flat
-tests += $(TEST_DIR)/vmx.flat
-
-include config-x86-common.mak
config/config-i386.mak new file +12 -0
new file mode 100644
index 0000000000000..82fed0f5a48b0
@@ -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 +120 -0

120 lines not on this page · raw message

config/config-x86_64.mak new file +13 -0
new file mode 100644
index 0000000000000..f089b05a178c3
@@ -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
+tests += $(TEST_DIR)/svm.flat
+tests += $(TEST_DIR)/vmx.flat
+
+include config/config-x86-common.mak
configure +17 -0
index d0c62e24dd1d2..6cfc64943f6e6 100755
@@ -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 +11 -0
new file mode 100644
index 0000000000000..854b5c774b60c
@@ -0,0 +1,11 @@
+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
flat.lds deleted +0 -21
deleted file mode 100644
index a278b56c9a4e3..0000000000000
@@ -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 +9 -10
index f373c533b75b2..400c62458ae18 100755
@@ -1,8 +1,10 @@
 #!/bin/bash
 
-testroot=x86
-config=$testroot/unittests.cfg
-qemu=${qemu:-qemu-system-x86_64}
+# As it happens, config.mak is valid shell script code, too :-)
+source config.mak
+
+config=$TEST_DIR/unittests.cfg
+qemu=${QEMU:-qemu-system-$ARCH}
 verbose=0
 
 function run()
@@ -27,7 +29,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 +67,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 +94,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 allow the
-internally used x86-run to pick up the right qemu binary.
+Set the environment variable QEMU=/path/to/qemu-system-ARCH to allow the
+internally used ARCH-run to pick up the right qemu binary.
 
 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
deleted file mode 100644
index ac436efadb633..0000000000000
@@ -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 +46 -14

63 lines not on this page · raw message

x86/flat.lds new file +21 -0
new file mode 100644
index 0000000000000..a278b56c9a4e3
@@ -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
#6 lore raw

Re: [PATCH 3/9] clean root dir of all x86-ness

Quoted 73 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.

---
v2:
- tests' images => test images [Christoffer Dall]

TODO:
- more documentation is still needed, we should add
* an overview of the framework
* improve the quickstart guide for running the tests
* add a quickstart guide for developing tests

---
 Makefile                     |   7 ++-
 README                       |  55 +++++++++-----------
 config-i386.mak              |  13 -----
 config-x86-common.mak        | 120 -------------------------------------------
 config-x86_64.mak            |  14 -----
 config/config-i386.mak       |  12 +++++
 config/config-x86-common.mak | 120 +++++++++++++++++++++++++++++++++++++++++++
 config/config-x86_64.mak     |  13 +++++
 configure                    |  17 ++++++
 docs/testdev.txt             |  11 ++++
 flat.lds                     |  21 --------
 run_tests.sh                 |  19 ++++---
 testdev.txt                  |  14 -----
 x86-run                      |  41 ---------------
 x86/README                   |  60 +++++++++++++++++-----
 x86/flat.lds                 |  21 ++++++++
 x86/run                      |  41 +++++++++++++++
 17 files changed, 316 insertions(+), 283 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 +1 -2
index 697fc2a766966..7a5ec8e6348bf 100644
@@ -17,7 +17,7 @@ cflatobjs := \
 	lib/string.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)
@@ -29,7 +29,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)
 
@@ -44,11 +43,11 @@ $(libcflat): $(cflatobjs)
 %.o: %.S
 	$(CC) $(CFLAGS) -c -nostdlib -o $@ $<
 

Makefile $(libcflat): $(cflatobjs) · line 53

Quoted 10 lines
Makefile +2 -2
--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)

so above you're referencing */.*.d and */*/.*.d but in make arch_clean we're only removing lib/.*.d ?

Quoted 397 lines
README +23 -32
index db525e3bbb79d..0174679c05021 100644
@@ -1,36 +1,27 @@
 This directory contains sources for a kvm test suite.
 
-Tests for x86 architecture are run as kernel images for qemu that supports multiboot format.
-Tests uses an infrastructure called from the bios code. The infrastructure initialize the system/cpu's,
-switch to long-mode and calls the 'main' function of the individual test.
-Tests uses a qemu's virtual test device, named testdev, for services like printing, exiting, query memory size etc.
-See file testdev.txt for more details.
-
-To create the tests' images just type 'make' in this directory.
-Tests' images created in ./<ARCH>/*.flat
-
-An example of a test invocation:
-Using qemu-kvm:
-
-qemu-kvm -device testdev,chardev=testlog -chardev file,id=testlog,path=msr.out -serial stdio -kernel ./x86/msr.flat
-This invocation runs the msr test case. The test outputs to stdio.
-
-Using qemu (supported since qemu 1.3):
-qemu-system-x86_64 -enable-kvm -device pc-testdev -serial stdio -device isa-debug-exit,iobase=0xf4,iosize=0x4 -kernel ./x86/msr.flat
-
-Or use a runner script to detect the correct invocation:
-./x86-run ./x86/msr.flat
-To select a specific qemu binary, specify the QEMU=<path> environment:
-QEMU=/tmp/qemu/x86_64-softmmu/qemu-system-x86_64 ./x86-run ./x86/msr.flat
-
-The exit status of the binary (and the script) is inconsistent: with
-qemu-system, after the unittest is done, the exit status of qemu is 1,
-different from the 'old style' qemu-kvm, whose exit status in successful
-completion is 0.
+To create the test images do
+  ./configure
+  make
+in this directory. Test images are created in ./<ARCH>/*.flat
+
+Then use the runner script to detect the correct invocation and
+invoke the test, e.g.
+  ./x86-run ./x86/msr.flat
+or
+  ./run_tests.sh
+to run them all.
+
+To select a specific qemu binary, specify the QEMU=<path>
+environment, e.g.
+  QEMU=/tmp/qemu/x86_64-softmmu/qemu-system-x86_64 ./x86-run ./x86/msr.flat
 
 Directory structure:
-.:  Makefile and config files for the tests
-./lib: general services for the tests
-./lib/<ARCH>: architecture dependent services for the tests
-./<ARCH>: the sources of the tests and the created objects/images
-
+.:		Makefile and config files for the tests
+./config:	config files for the tests
+./docs:		documentation files
+./lib:		general services for the tests
+./lib/<ARCH>:	architecture dependent services for the tests
+./<ARCH>:	the sources of the tests and the created objects/images
+
+See <ARCH>/README for arch specific documentation.
config-i386.mak deleted +0 -13
deleted file mode 100644
index de52f3d53cff8..0000000000000
@@ -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 -120
deleted file mode 100644
index 7e481192a0737..0000000000000
@@ -1,120 +0,0 @@
-#This is a make file with common rules for both x86 & x86-64
-
-all: test_cases
-
-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
-cflatobjs += lib/x86/atomic.o
-cflatobjs += lib/x86/desc.o
-cflatobjs += lib/x86/isr.o
-cflatobjs += lib/x86/pci.o
-
-$(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)
-
-%.flat: %.elf
-	$(OBJCOPY) -O elf32-i386 $^ $@
-
-tests-common = $(TEST_DIR)/vmexit.flat $(TEST_DIR)/tsc.flat \
-               $(TEST_DIR)/smptest.flat  $(TEST_DIR)/port80.flat \
-               $(TEST_DIR)/realmode.flat $(TEST_DIR)/msr.flat \
-               $(TEST_DIR)/hypercall.flat $(TEST_DIR)/sieve.flat \
-               $(TEST_DIR)/kvmclock_test.flat  $(TEST_DIR)/eventinj.flat \
-               $(TEST_DIR)/s3.flat $(TEST_DIR)/pmu.flat \
-               $(TEST_DIR)/tsc_adjust.flat $(TEST_DIR)/asyncpf.flat \
-               $(TEST_DIR)/init.flat
-
-ifdef API
-tests-common += api/api-sample
-tests-common += api/dirty-log
-tests-common += api/dirty-log-perf
-endif
-
-tests_and_config = $(TEST_DIR)/*.flat $(TEST_DIR)/unittests.cfg
-
-test_cases: $(tests-common) $(tests)
-
-$(TEST_DIR)/%.o: CFLAGS += -std=gnu99 -ffreestanding -I lib -I lib/x86
-
-$(TEST_DIR)/access.elf: $(cstart.o) $(TEST_DIR)/access.o
-
-$(TEST_DIR)/hypercall.elf: $(cstart.o) $(TEST_DIR)/hypercall.o
-
-$(TEST_DIR)/sieve.elf: $(cstart.o) $(TEST_DIR)/sieve.o
-
-$(TEST_DIR)/vmexit.elf: $(cstart.o) $(TEST_DIR)/vmexit.o
-
-$(TEST_DIR)/smptest.elf: $(cstart.o) $(TEST_DIR)/smptest.o
-
-$(TEST_DIR)/emulator.elf: $(cstart.o) $(TEST_DIR)/emulator.o
-
-$(TEST_DIR)/port80.elf: $(cstart.o) $(TEST_DIR)/port80.o
-
-$(TEST_DIR)/tsc.elf: $(cstart.o) $(TEST_DIR)/tsc.o
-
-$(TEST_DIR)/tsc_adjust.elf: $(cstart.o) $(TEST_DIR)/tsc_adjust.o
-
-$(TEST_DIR)/apic.elf: $(cstart.o) $(TEST_DIR)/apic.o
-
-$(TEST_DIR)/init.elf: $(cstart.o) $(TEST_DIR)/init.o
-
-$(TEST_DIR)/realmode.elf: $(TEST_DIR)/realmode.o
-	$(CC) -m32 -nostdlib -o $@ -Wl,-T,$(TEST_DIR)/realmode.lds $^
-
-$(TEST_DIR)/realmode.o: bits = 32
-
-$(TEST_DIR)/msr.elf: $(cstart.o) $(TEST_DIR)/msr.o
-
-$(TEST_DIR)/idt_test.elf: $(cstart.o) $(TEST_DIR)/idt_test.o
-
-$(TEST_DIR)/xsave.elf: $(cstart.o) $(TEST_DIR)/xsave.o
-
-$(TEST_DIR)/rmap_chain.elf: $(cstart.o) $(TEST_DIR)/rmap_chain.o
-
-$(TEST_DIR)/svm.elf: $(cstart.o)
-
-$(TEST_DIR)/kvmclock_test.elf: $(cstart.o) $(TEST_DIR)/kvmclock.o \
-                                $(TEST_DIR)/kvmclock_test.o
-
-$(TEST_DIR)/eventinj.elf: $(cstart.o) $(TEST_DIR)/eventinj.o
-
-$(TEST_DIR)/s3.elf: $(cstart.o) $(TEST_DIR)/s3.o
-
-$(TEST_DIR)/pmu.elf: $(cstart.o) $(TEST_DIR)/pmu.o
-
-$(TEST_DIR)/asyncpf.elf: $(cstart.o) $(TEST_DIR)/asyncpf.o
-
-$(TEST_DIR)/pcid.elf: $(cstart.o) $(TEST_DIR)/pcid.o
-
-$(TEST_DIR)/vmx.elf: $(cstart.o) $(TEST_DIR)/vmx.o $(TEST_DIR)/vmx_tests.o
-
-arch_clean:
-	$(RM) $(TEST_DIR)/*.o $(TEST_DIR)/*.flat $(TEST_DIR)/*.elf \
-	$(TEST_DIR)/.*.d lib/x86/.*.d
-
-api/%.o: CFLAGS += -m32
-
-api/%: LDLIBS += -lstdc++ -lboost_thread-mt -lpthread -lrt
-api/%: LDFLAGS += -m32
-
-api/libapi.a: api/kvmxx.o api/identity.o api/exception.o api/memmap.o
-	$(AR) rcs $@ $^
-
-api/api-sample: api/api-sample.o api/libapi.a
-
-api/dirty-log: api/dirty-log.o api/libapi.a
-
-api/dirty-log-perf: api/dirty-log-perf.o api/libapi.a
config-x86_64.mak deleted +0 -14
deleted file mode 100644
index bb8ee89713abd..0000000000000
@@ -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
-tests += $(TEST_DIR)/svm.flat
-tests += $(TEST_DIR)/vmx.flat
-
-include config-x86-common.mak
config/config-i386.mak new file +12 -0
new file mode 100644
index 0000000000000..82fed0f5a48b0
@@ -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 +120 -0
new file mode 100644
index 0000000000000..917cbbf801a65
@@ -0,0 +1,120 @@
+#This is a make file with common rules for both x86 & x86-64
+
+all: test_cases
+
+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
+cflatobjs += lib/x86/atomic.o
+cflatobjs += lib/x86/desc.o
+cflatobjs += lib/x86/isr.o
+cflatobjs += lib/x86/pci.o
+
+$(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) x86/flat.lds
+	$(CC) $(CFLAGS) -nostdlib -o $@ -Wl,-T,x86/flat.lds \
+		$(filter %.o, $^) $(FLATLIBS)
+
+%.flat: %.elf
+	$(OBJCOPY) -O elf32-i386 $^ $@
+
+tests-common = $(TEST_DIR)/vmexit.flat $(TEST_DIR)/tsc.flat \
+               $(TEST_DIR)/smptest.flat  $(TEST_DIR)/port80.flat \
+               $(TEST_DIR)/realmode.flat $(TEST_DIR)/msr.flat \
+               $(TEST_DIR)/hypercall.flat $(TEST_DIR)/sieve.flat \
+               $(TEST_DIR)/kvmclock_test.flat  $(TEST_DIR)/eventinj.flat \
+               $(TEST_DIR)/s3.flat $(TEST_DIR)/pmu.flat \
+               $(TEST_DIR)/tsc_adjust.flat $(TEST_DIR)/asyncpf.flat \
+               $(TEST_DIR)/init.flat
+
+ifdef API
+tests-common += api/api-sample
+tests-common += api/dirty-log
+tests-common += api/dirty-log-perf
+endif
+
+tests_and_config = $(TEST_DIR)/*.flat $(TEST_DIR)/unittests.cfg
+
+test_cases: $(tests-common) $(tests)
+
+$(TEST_DIR)/%.o: CFLAGS += -std=gnu99 -ffreestanding -I lib -I lib/x86
+
+$(TEST_DIR)/access.elf: $(cstart.o) $(TEST_DIR)/access.o
+
+$(TEST_DIR)/hypercall.elf: $(cstart.o) $(TEST_DIR)/hypercall.o
+
+$(TEST_DIR)/sieve.elf: $(cstart.o) $(TEST_DIR)/sieve.o
+
+$(TEST_DIR)/vmexit.elf: $(cstart.o) $(TEST_DIR)/vmexit.o
+
+$(TEST_DIR)/smptest.elf: $(cstart.o) $(TEST_DIR)/smptest.o
+
+$(TEST_DIR)/emulator.elf: $(cstart.o) $(TEST_DIR)/emulator.o
+
+$(TEST_DIR)/port80.elf: $(cstart.o) $(TEST_DIR)/port80.o
+
+$(TEST_DIR)/tsc.elf: $(cstart.o) $(TEST_DIR)/tsc.o
+
+$(TEST_DIR)/tsc_adjust.elf: $(cstart.o) $(TEST_DIR)/tsc_adjust.o
+
+$(TEST_DIR)/apic.elf: $(cstart.o) $(TEST_DIR)/apic.o
+
+$(TEST_DIR)/init.elf: $(cstart.o) $(TEST_DIR)/init.o
+
+$(TEST_DIR)/realmode.elf: $(TEST_DIR)/realmode.o
+	$(CC) -m32 -nostdlib -o $@ -Wl,-T,$(TEST_DIR)/realmode.lds $^
+
+$(TEST_DIR)/realmode.o: bits = 32
+
+$(TEST_DIR)/msr.elf: $(cstart.o) $(TEST_DIR)/msr.o
+
+$(TEST_DIR)/idt_test.elf: $(cstart.o) $(TEST_DIR)/idt_test.o
+
+$(TEST_DIR)/xsave.elf: $(cstart.o) $(TEST_DIR)/xsave.o
+
+$(TEST_DIR)/rmap_chain.elf: $(cstart.o) $(TEST_DIR)/rmap_chain.o
+
+$(TEST_DIR)/svm.elf: $(cstart.o)
+
+$(TEST_DIR)/kvmclock_test.elf: $(cstart.o) $(TEST_DIR)/kvmclock.o \
+                                $(TEST_DIR)/kvmclock_test.o
+
+$(TEST_DIR)/eventinj.elf: $(cstart.o) $(TEST_DIR)/eventinj.o
+
+$(TEST_DIR)/s3.elf: $(cstart.o) $(TEST_DIR)/s3.o
+
+$(TEST_DIR)/pmu.elf: $(cstart.o) $(TEST_DIR)/pmu.o
+
+$(TEST_DIR)/asyncpf.elf: $(cstart.o) $(TEST_DIR)/asyncpf.o
+
+$(TEST_DIR)/pcid.elf: $(cstart.o) $(TEST_DIR)/pcid.o
+
+$(TEST_DIR)/vmx.elf: $(cstart.o) $(TEST_DIR)/vmx.o $(TEST_DIR)/vmx_tests.o
+
+arch_clean:
+	$(RM) $(TEST_DIR)/*.o $(TEST_DIR)/*.flat $(TEST_DIR)/*.elf \
+	$(TEST_DIR)/.*.d lib/x86/.*.d
+
+api/%.o: CFLAGS += -m32
+
+api/%: LDLIBS += -lstdc++ -lboost_thread-mt -lpthread -lrt
+api/%: LDFLAGS += -m32
+
+api/libapi.a: api/kvmxx.o api/identity.o api/exception.o api/memmap.o
+	$(AR) rcs $@ $^
+
+api/api-sample: api/api-sample.o api/libapi.a
+
+api/dirty-log: api/dirty-log.o api/libapi.a
+
+api/dirty-log-perf: api/dirty-log-perf.o api/libapi.a
config/config-x86_64.mak new file +13 -0
new file mode 100644
index 0000000000000..f089b05a178c3
@@ -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
+tests += $(TEST_DIR)/svm.flat
+tests += $(TEST_DIR)/vmx.flat
+
+include config/config-x86-common.mak
configure +0 -0
index d0c62e24dd1d2..6cfc64943f6e6 100755

configure usage() { · line 18

Quoted 4 lines
configure +1 -0
@@ -15,6 +15,7 @@ usage() {
 	Usage: $0 [options]
 
 	Options include:
+	    --test-dir=DIR         the main directory for tests ($arch)

huh? why would you want to specify something different from arch here?

Quoted 45 lines
configure +16 -0
 	    --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 +1 -0
new file mode 100644
index 0000000000000..854b5c774b60c
@@ -0,0 +1,11 @@
+This file describes the virtual device of qemu for supporting this test suite.

docs/testdev.txt line 11

Quoted 10 lines
docs/testdev.txt new file +10 -0
+
+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

what do you mean by this last sentence?

Quoted 32 lines
flat.lds deleted +0 -21
deleted file mode 100644
index a278b56c9a4e3..0000000000000
@@ -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 +0 -0
index f373c533b75b2..400c62458ae18 100755

run_tests.sh line 4

Quoted 7 lines
run_tests.sh +2 -3
@@ -1,8 +1,10 @@
 #!/bin/bash
 
-testroot=x86
-config=$testroot/unittests.cfg
-qemu=${qemu:-qemu-system-x86_64}
+# As it happens, config.mak is valid shell script code, too :-)
+source config.mak

is this a well-established method of doing things or a hack? If the latter, sems like something that could quickly come and bite us.

Quoted 25 lines
run_tests.sh +5 -2
+
+config=$TEST_DIR/unittests.cfg
+qemu=${QEMU:-qemu-system-$ARCH}
 verbose=0
 
 function run()
@@ -27,7 +29,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 +67,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

run_tests.sh Usage: $0 [-g group] [-h] [-v] · line 98

Quoted 7 lines
run_tests.sh +2 -2
@@ -92,15 +94,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 allow the
-internally used x86-run to pick up the right qemu binary.
+Set the environment variable QEMU=/path/to/qemu-system-ARCH to allow the
+internally used ARCH-run to pick up the right qemu binary.

this message may not make a lot of sense to non kvm-unit-test devevelopers, why not say that it allows the user to specify which QEMU binary to use?

run_tests.sh Usage: $0 [-g group] [-h] [-v] · line 103

Quoted 7 lines
run_tests.sh +0 -3
 EOF
 }
 
-# As it happens, config.mak is valid shell script code, too :-)
-source config.mak
-

ah, I see, this hack/method was used before too, still relevant to consider if it's a good approach though...

Quoted 75 lines
run_tests.sh +0 -0
 echo > test.log
 while getopts "g:hv" opt; do
     case $opt in
testdev.txt deleted +0 -14
deleted file mode 100644
index ac436efadb633..0000000000000
@@ -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
deleted file mode 100755
index 646c5770ed03f..0000000000000
@@ -1,41 +0,0 @@
-#!/bin/bash
-
-qemukvm="${QEMU:-qemu-kvm}"
-qemusystem="${QEMU:-qemu-system-x86_64}"
-if
-	${qemukvm} -device '?' 2>&1 | grep -F -e \"testdev\" -e \"pc-testdev\" > /dev/null;
-then
-	qemu="${qemukvm}"
-else
-	if
-		${qemusystem} -device '?' 2>&1 | grep -F -e \"testdev\" -e \"pc-testdev\" > /dev/null;
-	then
-		qemu="${qemusystem}"
-	else
-		echo QEMU binary ${QEMU} has no support for test device. Exiting.
-		exit 2
-	fi
-fi
-
-if
-	${qemu} -device '?' 2>&1 | grep -F "pci-testdev" > /dev/null;
-then
-	pci_testdev="-device pci-testdev"
-else
-	pci_testdev=""
-fi
-
-if
-	${qemu} -device '?' 2>&1 | grep -F "pc-testdev" > /dev/null;
-then
-	pc_testdev="-device pc-testdev -device isa-debug-exit,iobase=0xf4,iosize=0x4"
-else
-	pc_testdev="-device testdev,chardev=testlog -chardev file,id=testlog,path=msr.out"
-fi
-
-command="${qemu} -enable-kvm $pc_testdev -display none -serial stdio $pci_testdev -kernel"
-echo ${command} "$@"
-${command} "$@"
-ret=$?
-echo Return value from qemu: $ret
-exit $ret
x86/README +0 -0
index d644abdf31708..2f4baa46c6ed1 100644

x86/README line 5

Quoted 5 lines
x86/README +5 -0
@@ -1,16 +1,48 @@
+
+Tests for x86 architecture are run as kernel images for qemu that supports
+multiboot format. Tests uses an infrastructure called from the bios code.
+The infrastructure initialize the system/cpu's, switch to long-mode and calls
+the 'main' function of the individual test. Tests uses a qemu's virtual test

Tests use

Quoted 139 lines
x86/README +41 -14
+device, named testdev, for services like printing, exiting, query memory
+size etc. See file docs/testdev.txt for more details.
+
+An example of a test invocation:
+Using qemu-kvm:
+
+qemu-kvm -device testdev,chardev=testlog \
+         -chardev file,id=testlog,path=msr.out \
+         -serial stdio -kernel ./x86/msr.flat
+This invocation runs the msr test case. The test outputs to stdio.
+
+Using qemu (supported since qemu 1.3):
+qemu-system-x86_64 -enable-kvm -device pc-testdev -serial stdio \
+                   -device isa-debug-exit,iobase=0xf4,iosize=0x4 \
+                   -kernel ./x86/msr.flat
+
 Tests in this directory and what they do:
 
-access: lots of page table related access (pte/pde) (read/write)
-apic: enable x2apic, self ipi, ioapic intr, ioapic simultaneous
-emulator: move to/from regs, cmps, push, pop, to/from cr8, smsw and lmsw
-hypercall: intel and amd hypercall insn
-msr: write to msr (only KERNEL_GS_BASE for now)
-port80: lots of out to port 80
-realmode: goes back to realmode, shld, push/pop, mov immediate, cmp immediate, add immediate,
-         io, eflags instructions (clc, cli, etc.), jcc short, jcc near, call, long jmp, xchg
-sieve: heavy memory access with no paging and with paging static and with paging vmalloc'ed
-smptest: run smp_id() on every cpu and compares return value to number
-tsc: write to tsc(0) and write to tsc(100000000000) and read it back
-vmexit: long loops for each: cpuid, vmcall, mov_from_cr8, mov_to_cr8, inl_pmtimer, ipi, ipi+halt
-kvmclock_test: test of wallclock, monotonic cycle and performance of kvmclock
-pcid: basic functionality test of PCID/INVPCID feature
\ No newline at end of file
+  access:	lots of page table related access (pte/pde) (read/write)
+  apic:		enable x2apic, self ipi, ioapic intr, ioapic simultaneous
+  emulator:	move to/from regs, cmps, push, pop, to/from cr8, smsw and lmsw
+  hypercall:	intel and amd hypercall insn
+  msr:		write to msr (only KERNEL_GS_BASE for now)
+  port80:	lots of out to port 80
+  realmode:	goes back to realmode, shld, push/pop, mov immediate,
+		cmp immediate, add immediate, io, eflags instructions
+		(clc, cli, etc.), jcc short, jcc near, call, long jmp, xchg
+  sieve:	heavy memory access with no paging and with paging static and
+		with paging vmalloc'ed
+  smptest:	run smp_id() on every cpu and compares return value to number
+  tsc:		write to tsc(0) and write to tsc(100000000000) and read it back
+  vmexit:	long loops for each: cpuid, vmcall, mov_from_cr8, mov_to_cr8,
+		inl_pmtimer, ipi, ipi+halt
+  kvmclock_test: test of wallclock, monotonic cycle and performance of kvmclock
+  pcid:		basic functionality test of PCID/INVPCID featureThis directory
+		contains sources for a kvm test suite.
+
+Legacy notes:
+
+  The exit status of the binary (and the script) is inconsistent: with
+  qemu-system, after the unittest is done, the exit status of qemu is 1,
+  different from the 'old style' qemu-kvm, whose exit status in successful
+  completion is 0.
x86/flat.lds new file +21 -0
new file mode 100644
index 0000000000000..a278b56c9a4e3
@@ -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
new file mode 100755
index 0000000000000..646c5770ed03f
@@ -0,0 +1,41 @@
+#!/bin/bash
+
+qemukvm="${QEMU:-qemu-kvm}"
+qemusystem="${QEMU:-qemu-system-x86_64}"
+if
+	${qemukvm} -device '?' 2>&1 | grep -F -e \"testdev\" -e \"pc-testdev\" > /dev/null;
+then
+	qemu="${qemukvm}"
+else
+	if
+		${qemusystem} -device '?' 2>&1 | grep -F -e \"testdev\" -e \"pc-testdev\" > /dev/null;
+	then
+		qemu="${qemusystem}"
+	else
+		echo QEMU binary ${QEMU} has no support for test device. Exiting.
+		exit 2
+	fi
+fi
+
+if
+	${qemu} -device '?' 2>&1 | grep -F "pci-testdev" > /dev/null;
+then
+	pci_testdev="-device pci-testdev"
+else
+	pci_testdev=""
+fi
+
+if
+	${qemu} -device '?' 2>&1 | grep -F "pc-testdev" > /dev/null;
+then
+	pc_testdev="-device pc-testdev -device isa-debug-exit,iobase=0xf4,iosize=0x4"
+else
+	pc_testdev="-device testdev,chardev=testlog -chardev file,id=testlog,path=msr.out"
+fi
+
+command="${qemu} -enable-kvm $pc_testdev -display none -serial stdio $pci_testdev -kernel"
+echo ${command} "$@"
+${command} "$@"
+ret=$?
+echo Return value from qemu: $ret
+exit $ret
Signature · 6 lines
1.8.1.4

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/cucslists/listinfo/kvmarm
Signature · 1 line
Christoffer
#7 lore raw

Re: [PATCH 3/9] clean root dir of all x86-ness

Quoted 7 lines · Christoffer Dall

Makefile $(libcflat): $(cflatobjs) · line 53

Quoted 4 lines

clean: arch_clean

Makefile +1 -1
-	$(RM) *.o *.a .*.d lib/.*.d $(libcflat) $(cflatobjs)
+	$(RM) lib/.*.d $(libcflat) $(cflatobjs)

so above you're referencing */.*.d and */*/.*.d but in make arch_clean we're only removing lib/.*.d ?

There are no longer any source files in the root dir, allowing us to remove the 'rm *.o *.a .*.d' from this top-level makefile. arch_clean doesn't remove lib/.*.d. It only removes its arch-specific files, e.g. $(TEST_DIR)/* and lib/$(ARCH)/*.

Quoted 5 lines

configure usage() { · line 18

Quoted 3 lines
configure +1 -0
 	Options include:
+	    --test-dir=DIR         the main directory for tests ($arch)

huh? why would you want to specify something different from arch here?

$(TEST_DIR) isn't new with this patch, only the ability to specify it is. As a separate tidyup patch we could s/r TEST_DIR with ARCH to get rid of it, but it wouldn't gain us much, and would lose the ability to have a second testdir for the same arch (for what I don't know - maybe just for a scratch dir?)

Quoted 11 lines

docs/testdev.txt line 11

Quoted 9 lines
docs/testdev.txt new file +9 -0
+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

what do you mean by this last sentence?

Don't shoot the file-mover :-) I didn't write it, but it looks like it's referring to how testdev (as opposed to pc-testdev) works, i.e. '-device testdev,chardev=testlog -chardev file,id=testlog,path=msr.out'

Quoted 5 lines

run_tests.sh line 4

Quoted 2 lines
run_tests.sh +2 -0
+# As it happens, config.mak is valid shell script code, too :-)
+source config.mak

is this a well-established method of doing things or a hack? If the latter, sems like something that could quickly come and bite us.

As long as config.mak is only ever a list of 'key=value's, then I guess we're pretty safe.

Quoted 9 lines

run_tests.sh Usage: $0 [-g group] [-h] [-v] · line 98

Quoted 5 lines
run_tests.sh +2 -2
-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-ARCH to allow the
+internally used ARCH-run to pick up the right qemu binary.

this message may not make a lot of sense to non kvm-unit-test devevelopers, why not say that it allows the user to specify which QEMU binary to use?

OK, tweaked it to
Set the environment variable QEMU=/path/to/qemu-system-ARCH to specify the appropriate qemu binary for ARCH-run.

Quoted 11 lines

run_tests.sh Usage: $0 [-g group] [-h] [-v] · line 103

Quoted 8 lines

EOF
}

run_tests.sh +0 -3
-# As it happens, config.mak is valid shell script code, too :-)
-source config.mak
-

ah, I see, this hack/method was used before too, still relevant to consider if it's a good approach though...

yup, I think it's OK.

Quoted 7 lines

x86/README line 5

Quoted 5 lines
x86/README +5 -0
+
+Tests for x86 architecture are run as kernel images for qemu that supports
+multiboot format. Tests uses an infrastructure called from the bios code.
+The infrastructure initialize the system/cpu's, switch to long-mode and calls
+the 'main' function of the individual test. Tests uses a qemu's virtual test

Tests use

fixed

drew

#8 lore raw

Re: [PATCH 3/9] clean root dir of all x86-ness

Quoted 9 lines · Andrew Jones
Quoted 7 lines · Christoffer Dall

Makefile $(libcflat): $(cflatobjs) · line 53

Quoted 4 lines

clean: arch_clean

Makefile +1 -1
-	$(RM) *.o *.a .*.d lib/.*.d $(libcflat) $(cflatobjs)
+	$(RM) lib/.*.d $(libcflat) $(cflatobjs)

so above you're referencing */.*.d and */*/.*.d but in make arch_clean we're only removing lib/.*.d ?

Quoted 5 lines

There are no longer any source files in the root dir, allowing us to remove the 'rm *.o *.a .*.d' from this top-level makefile. arch_clean doesn't remove lib/.*.d. It only removes its arch-specific files, e.g. $(TEST_DIR)/* and lib/$(ARCH)/*.

ah ok.

Quoted 6 lines
Quoted 5 lines

configure usage() { · line 18

Quoted 3 lines
configure +1 -0
 	Options include:
+	    --test-dir=DIR         the main directory for tests ($arch)

huh? why would you want to specify something different from arch here?

Quoted 6 lines

$(TEST_DIR) isn't new with this patch, only the ability to specify it is. As a separate tidyup patch we could s/r TEST_DIR with ARCH to get rid of it, but it wouldn't gain us much, and would lose the ability to have a second testdir for the same arch (for what I don't know - maybe just for a scratch dir?)

hmm, ok, I don't know what the original intention with this patch was then.

Quoted 12 lines
Quoted 11 lines

docs/testdev.txt line 11

Quoted 9 lines
docs/testdev.txt new file +9 -0
+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

what do you mean by this last sentence?

Quoted 4 lines

Don't shoot the file-mover :-) I didn't write it, but it looks like it's referring to how testdev (as opposed to pc-testdev) works, i.e. '-device testdev,chardev=testlog -chardev file,id=testlog,path=msr.out'

ok, I'll let you off on that one then :)

Quoted 19 lines
Quoted 5 lines

run_tests.sh line 4

Quoted 2 lines
run_tests.sh +2 -0
+# As it happens, config.mak is valid shell script code, too :-)
+source config.mak

is this a well-established method of doing things or a hack? If the latter, sems like something that could quickly come and bite us.

As long as config.mak is only ever a list of 'key=value's, then I guess we're pretty safe.

Quoted 9 lines

run_tests.sh Usage: $0 [-g group] [-h] [-v] · line 98

Quoted 5 lines
run_tests.sh +2 -2
-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-ARCH to allow the
+internally used ARCH-run to pick up the right qemu binary.

this message may not make a lot of sense to non kvm-unit-test devevelopers, why not say that it allows the user to specify which QEMU binary to use?

Quoted 3 lines

OK, tweaked it to
Set the environment variable QEMU=/path/to/qemu-system-ARCH to specify the appropriate qemu binary for ARCH-run.

thanks!

Quoted 26 lines
Quoted 6 lines
Quoted 6 lines

EOF
}

Quoted 6 lines

run_tests.sh Usage: $0 [-g group] [-h] [-v] · line 103

Quoted 3 lines
run_tests.sh +0 -3
-# As it happens, config.mak is valid shell script code, too :-)
-source config.mak
-

ah, I see, this hack/method was used before too, still relevant to consider if it's a good approach though...

yup, I think it's OK.

Quoted 7 lines

x86/README line 5

Quoted 5 lines
x86/README +5 -0
+
+Tests for x86 architecture are run as kernel images for qemu that supports
+multiboot format. Tests uses an infrastructure called from the bios code.
+The infrastructure initialize the system/cpu's, switch to long-mode and calls
+the 'main' function of the individual test. Tests uses a qemu's virtual test

Tests use

fixed

drew

Signature · 1 line
Christoffer
#9 lore raw

PATCH v2 4/9 move x86's simple heap management to common code

In reply to Andrew Jones
---
 config/config-x86-common.mak |  1 +
 lib/heap.c                   | 43 +++++++++++++++++++++++++++++++++++++++++++
 lib/heap.h                   |  8 ++++++++
 lib/x86/vm.c                 | 33 ++-------------------------------
 4 files changed, 54 insertions(+), 31 deletions(-)
 create mode 100644 lib/heap.c
 create mode 100644 lib/heap.h
config/config-x86-common.mak +1 -0
index 917cbbf801a65..8a78f7a6c8849 100644
@@ -2,6 +2,7 @@
 
 all: test_cases
 
+cflatobjs += lib/heap.o
 cflatobjs += lib/x86/io.o
 cflatobjs += lib/x86/smp.o
 cflatobjs += lib/x86/vm.o
lib/heap.c new file +43 -0

43 lines not on this page · raw message

lib/heap.h new file +8 -0
new file mode 100644
index 0000000000000..78b893021ae92
@@ -0,0 +1,8 @@
+#ifndef _HEAP_H_
+#define _HEAP_H_
+#include "libcflat.h"
+
+extern void heap_init(void *start, size_t size, size_t page_size);
+extern void *alloc_page(void);
+extern void free_page(void *page);
+#endif
lib/x86/vm.c +2 -31
index 188bf57587aa7..725cfe33259c2 100644
@@ -1,6 +1,7 @@
 #include "fwcfg.h"
 #include "vm.h"
 #include "libcflat.h"
+#include "heap.h"
 
 #define PAGE_SIZE 4096ul
 #ifdef __x86_64__
@@ -9,38 +10,8 @@
 #define LARGE_PAGE_SIZE (1024 * PAGE_SIZE)
 #endif
 
-static void *free = 0;
 static void *vfree_top = 0;
 
-static void free_memory(void *mem, unsigned long size)
-{
-    while (size >= PAGE_SIZE) {
-	*(void **)mem = free;
-	free = mem;
-	mem += PAGE_SIZE;
-	size -= PAGE_SIZE;
-    }
-}
-
-void *alloc_page()
-{
-    void *p;
-
-    if (!free)
-	return 0;
-
-    p = free;
-    free = *(void **)free;
-
-    return p;
-}
-
-void free_page(void *page)
-{
-    *(void **)page = free;
-    free = page;
-}
-
 extern char edata;
 static unsigned long end_of_memory;
 
@@ -185,7 +156,7 @@ static void setup_mmu(unsigned long len)
 void setup_vm()
 {
     end_of_memory = fwcfg_get_u64(FW_CFG_RAM_SIZE);
-    free_memory(&edata, end_of_memory - (unsigned long)&edata);
+    heap_init(&edata, end_of_memory - (unsigned long)&edata, PAGE_SIZE);
     setup_mmu(end_of_memory);
 }
 
Signature · 1 line
1.8.1.4
#10 lore raw

Re: [PATCH 4/9] move x86's simple heap management to common code

Quoted 31 lines · Andrew Jones
---
 config/config-x86-common.mak |  1 +
 lib/heap.c                   | 43 +++++++++++++++++++++++++++++++++++++++++++
 lib/heap.h                   |  8 ++++++++
 lib/x86/vm.c                 | 33 ++-------------------------------
 4 files changed, 54 insertions(+), 31 deletions(-)
 create mode 100644 lib/heap.c
 create mode 100644 lib/heap.h
config/config-x86-common.mak +1 -0
index 917cbbf801a65..8a78f7a6c8849 100644
@@ -2,6 +2,7 @@
 
 all: test_cases
 
+cflatobjs += lib/heap.o
 cflatobjs += lib/x86/io.o
 cflatobjs += lib/x86/smp.o
 cflatobjs += lib/x86/vm.o
lib/heap.c new file +3 -0
new file mode 100644
index 0000000000000..e52ee0edba163
@@ -0,0 +1,43 @@
+#include "libcflat.h"
+
+static size_t pagesize;

lib/heap.c line 13

Quoted 10 lines
lib/heap.c new file +10 -0
+static void *free_head;
+
+void heap_init(void *start, size_t size, size_t page_size)
+{
+	unsigned long s = (unsigned long)start;
+	void *p = start;
+
+	pagesize = page_size;
+
+	if (s != (s & ~(pagesize - 1))) {

you're just testing 'if (s & (pagesize -1))' right?

lib/heap.c line 17

Quoted 4 lines
lib/heap.c new file +4 -0
+		s += pagesize;
+		s &= ~(pagesize - 1);
+		p = (void *)s;
+	}

a one-line comment on this block saying 'page-align start of heap would be nice.

lib/heap.c line 24

Quoted 7 lines
lib/heap.c new file +7 -0
+
+	while (size >= pagesize) {
+		*(void **)p = free_head;
+		free_head = p;
+		p += pagesize;
+		size -= pagesize;
+	}

you could also be nice and comment this block of code, saying something like "set up linked list of free pages using the pages themselves as the data structure" if you should feel so inclined.

why are you not trusting start to be page aligned but you are trusting size to be? If size is smaller than pagesize then this loop will go nuts won't it?

Quoted 100 lines
lib/heap.c new file +19 -0
+}
+
+void *alloc_page(void)
+{
+	void *p;
+
+	if (!free_head)
+		return NULL;
+
+	p = free_head;
+	free_head = *(void **)free_head;
+	return p;
+}
+
+void free_page(void *page)
+{
+	*(void **)page = free_head;
+	free_head = page;
+}
lib/heap.h new file +8 -0
new file mode 100644
index 0000000000000..78b893021ae92
@@ -0,0 +1,8 @@
+#ifndef _HEAP_H_
+#define _HEAP_H_
+#include "libcflat.h"
+
+extern void heap_init(void *start, size_t size, size_t page_size);
+extern void *alloc_page(void);
+extern void free_page(void *page);
+#endif
lib/x86/vm.c +2 -31
index 188bf57587aa7..725cfe33259c2 100644
@@ -1,6 +1,7 @@
 #include "fwcfg.h"
 #include "vm.h"
 #include "libcflat.h"
+#include "heap.h"
 
 #define PAGE_SIZE 4096ul
 #ifdef __x86_64__
@@ -9,38 +10,8 @@
 #define LARGE_PAGE_SIZE (1024 * PAGE_SIZE)
 #endif
 
-static void *free = 0;
 static void *vfree_top = 0;
 
-static void free_memory(void *mem, unsigned long size)
-{
-    while (size >= PAGE_SIZE) {
-	*(void **)mem = free;
-	free = mem;
-	mem += PAGE_SIZE;
-	size -= PAGE_SIZE;
-    }
-}
-
-void *alloc_page()
-{
-    void *p;
-
-    if (!free)
-	return 0;
-
-    p = free;
-    free = *(void **)free;
-
-    return p;
-}
-
-void free_page(void *page)
-{
-    *(void **)page = free;
-    free = page;
-}
-
 extern char edata;
 static unsigned long end_of_memory;
 
@@ -185,7 +156,7 @@ static void setup_mmu(unsigned long len)
 void setup_vm()
 {
     end_of_memory = fwcfg_get_u64(FW_CFG_RAM_SIZE);
-    free_memory(&edata, end_of_memory - (unsigned long)&edata);
+    heap_init(&edata, end_of_memory - (unsigned long)&edata, PAGE_SIZE);
     setup_mmu(end_of_memory);
 }
 
Signature · 6 lines
1.8.1.4

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/cucslists/listinfo/kvmarm
Signature · 1 line
Christoffer
#11 lore raw

Re: [PATCH 4/9] move x86's simple heap management to common code

Quoted 4 lines · Christoffer Dall

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+	if (s != (s & ~(pagesize - 1))) {

you're just testing 'if (s & (pagesize -1))' right?

yeah, I'll simplify that.

Quoted 8 lines

lib/heap.c line 17

Quoted 5 lines
lib/heap.c new file +4 -0
+		s += pagesize;
+		s &= ~(pagesize - 1);
+		p = (void *)s;
+	}

a one-line comment on this block saying 'page-align start of heap would be nice.

added

Quoted 12 lines

lib/heap.c line 24

Quoted 8 lines
lib/heap.c new file +7 -0
+
+	while (size >= pagesize) {
+		*(void **)p = free_head;
+		free_head = p;
+		p += pagesize;
+		size -= pagesize;
+	}

you could also be nice and comment this block of code, saying something like "set up linked list of free pages using the pages themselves as the data structure" if you should feel so inclined.

added "link free pages"

Quoted 4 lines

why are you not trusting start to be page aligned but you are trusting size to be? If size is smaller than pagesize then this loop will go nuts won't it?

I don't see how. As soon as size is less than pagesize we won't [re]enter the loop, and thus it can never go negative (big positive).

drew

#12 lore raw

Re: [PATCH 4/9] move x86's simple heap management to common code

Quoted 35 lines · Andrew Jones
Quoted 4 lines · Christoffer Dall

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+	if (s != (s & ~(pagesize - 1))) {

you're just testing 'if (s & (pagesize -1))' right?

yeah, I'll simplify that.

Quoted 8 lines

lib/heap.c line 17

Quoted 5 lines
lib/heap.c new file +4 -0
+		s += pagesize;
+		s &= ~(pagesize - 1);
+		p = (void *)s;
+	}

a one-line comment on this block saying 'page-align start of heap would be nice.

added

Quoted 12 lines

lib/heap.c line 24

Quoted 8 lines
lib/heap.c new file +7 -0
+
+	while (size >= pagesize) {
+		*(void **)p = free_head;
+		free_head = p;
+		p += pagesize;
+		size -= pagesize;
+	}

you could also be nice and comment this block of code, saying something like "set up linked list of free pages using the pages themselves as the data structure" if you should feel so inclined.

added "link free pages"

Quoted 1 line
Quoted 7 lines
Quoted 3 lines

why are you not trusting start to be page aligned but you are trusting size to be? If size is smaller than pagesize then this loop will go nuts won't it?

I don't see how. As soon as size is less than pagesize we won't [re]enter the loop, and thus it can never go negative (big positive).

yeah you're right. duh.

#13 lore raw

PATCH v2 5/9 Introduce libio to common code for io read/write

In reply to Andrew Jones
---
 lib/libio.c |  67 +++++++++++++++++++++++
 lib/libio.h | 176 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 243 insertions(+)
 create mode 100644 lib/libio.c
 create mode 100644 lib/libio.h
lib/libio.c new file +67 -0
new file mode 100644
index 0000000000000..e450e984fefb1
@@ -0,0 +1,67 @@
+#include "libcflat.h"
+#include "libio.h"
+
+void read_len(const volatile void *addr, void *buf, unsigned len)
+{
+	unsigned long val;
+
+	switch (len) {
+	case 1:
+		val = readb(addr);
+		break;
+	case 2:
+		val = readw(addr);
+		break;
+	case 4:
+		val = readl(addr);
+		break;
+#ifdef CONFIG_64BIT
+	case 8:
+		val = readq(addr);
+		break;
+#endif
+	default:
+	{
+		u8 *p = buf;
+		unsigned i;
+
+		for (i = 0; i < len; ++i)
+			p[i] = readb(addr + i);
+		return;
+	}
+	}
+	memcpy(buf, &val, len);
+}
+
+void write_len(volatile void *addr, const void *buf, unsigned len)
+{
+	unsigned long val;
+
+	if (len <= sizeof(unsigned long))
+		memcpy(&val, buf, len);
+
+	switch (len) {
+	case 1:
+		writeb(val, addr);
+		break;
+	case 2:
+		writew(val, addr);
+		break;
+	case 4:
+		writel(val, addr);
+		break;
+#ifdef CONFIG_64BIT
+	case 8:
+		writeq(val, addr);
+		break;
+#endif
+	default:
+	{
+		const u8 *p = buf;
+		unsigned i;
+
+		for (i = 0; i < len; ++i)
+			writeb(p[i], addr + i);
+	}
+	}
+}
lib/libio.h new file +176 -0

176 lines not on this page · raw message

Signature · 1 line
1.8.1.4
#14 lore raw

Re: [PATCH 5/9] Introduce libio to common code for io read/write

On Wed, Dec 04, 2013 at 05:42:53PM +0100, Andrew Jones wrote:

Wow, are you being charged extra taxes per commit message keystroke over there? ;)

Quoted 34 lines
---
 lib/libio.c |  67 +++++++++++++++++++++++
 lib/libio.h | 176 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 243 insertions(+)
 create mode 100644 lib/libio.c
 create mode 100644 lib/libio.h
lib/libio.c new file +20 -0
new file mode 100644
index 0000000000000..e450e984fefb1
@@ -0,0 +1,67 @@
+#include "libcflat.h"
+#include "libio.h"
+
+void read_len(const volatile void *addr, void *buf, unsigned len)
+{
+	unsigned long val;
+
+	switch (len) {
+	case 1:
+		val = readb(addr);
+		break;
+	case 2:
+		val = readw(addr);
+		break;
+	case 4:
+		val = readl(addr);
+		break;
+#ifdef CONFIG_64BIT
+	case 8:
+		val = readq(addr);

lib/libio.c line 30

Quoted 10 lines
lib/libio.c new file +10 -0
+		break;
+#endif
+	default:
+	{
+		u8 *p = buf;
+		unsigned i;
+
+		for (i = 0; i < len; ++i)
+			p[i] = readb(addr + i);
+		return;

are you taking proper care of endianness in the common case?

lib/libio.c line 41

Quoted 11 lines
lib/libio.c new file +11 -0
+	}
+	}
+	memcpy(buf, &val, len);
+}
+
+void write_len(volatile void *addr, const void *buf, unsigned len)
+{
+	unsigned long val;
+
+	if (len <= sizeof(unsigned long))
+		memcpy(&val, buf, len);

Does this work with big-endian for sizes smaller than sizeof(unsigned long)?

Take a look at arch/arm/kvm/mmio.c and see how Marc uses a union to solve this issue.

Quoted 13 lines
lib/libio.c new file +13 -0
+
+	switch (len) {
+	case 1:
+		writeb(val, addr);
+		break;
+	case 2:
+		writew(val, addr);
+		break;
+	case 4:
+		writel(val, addr);
+		break;
+#ifdef CONFIG_64BIT
+	case 8:

lib/libio.c line 64

Quoted 10 lines
lib/libio.c new file +10 -0
+		writeq(val, addr);
+		break;
+#endif
+	default:
+	{
+		const u8 *p = buf;
+		unsigned i;
+
+		for (i = 0; i < len; ++i)
+			writeb(p[i], addr + i);

same as above?

Quoted 9 lines
lib/libio.c new file +3 -0
+	}
+	}
+}
lib/libio.h new file +0 -0
new file mode 100644
index 0000000000000..210b8d78af43f

lib/libio.h line 9

Quoted 9 lines
lib/libio.h new file +9 -0
@@ -0,0 +1,176 @@
+#ifndef _LIBIO_H_
+#define _LIBIO_H_
+/*
+ * Adapted from the Linux kernel's include/asm-generic/io.h and
+ * arch/arm/include/asm/io.h
+ */
+#include "libcflat.h"
+
+typedef u32 compat_ptr_t;

How is this going to be used here? The compat ptr stuff in the kernel deals with user space pointer iirc, but I'm not an expert on the details. Does typedef'ing a pointer to a u32 in generic code work on a 64-bit platform?

Quoted 169 lines
lib/libio.h new file +167 -0
+
+static inline void *compat_ptr(compat_ptr_t ptr)
+{
+	return (void *)(unsigned long)ptr;
+}
+
+static inline compat_ptr_t ptr_to_compat(void *ptr)
+{
+	return (u32)(unsigned long)ptr;
+}
+
+#ifndef __raw_readb
+static inline u8 __raw_readb(const volatile void *addr)
+{
+	return *(const volatile u8 *)addr;
+}
+#endif
+
+#ifndef __raw_readw
+static inline u16 __raw_readw(const volatile void *addr)
+{
+	return *(const volatile u16 *)addr;
+}
+#endif
+
+#ifndef __raw_readl
+static inline u32 __raw_readl(const volatile void *addr)
+{
+	return *(const volatile u32 *)addr;
+}
+#endif
+
+#ifdef CONFIG_64BIT
+#ifndef __raw_readq
+static inline u64 __raw_readq(const volatile void *addr)
+{
+	return *(const volatile u64 *)addr;
+}
+#endif
+#endif
+
+#ifndef __raw_writeb
+static inline void __raw_writeb(u8 b, volatile void *addr)
+{
+	*(volatile u8 *)addr = b;
+}
+#endif
+
+#ifndef __raw_writew
+static inline void __raw_writew(u16 b, volatile void *addr)
+{
+	*(volatile u16 *)addr = b;
+}
+#endif
+
+#ifndef __raw_writel
+static inline void __raw_writel(u32 b, volatile void *addr)
+{
+	*(volatile u32 *)addr = b;
+}
+#endif
+
+#ifdef CONFIG_64BIT
+#ifndef __raw_writeq
+static inline void __raw_writeq(u64 b, volatile void *addr)
+{
+	*(volatile u64 *)addr = b;
+}
+#endif
+#endif
+
+#ifndef __bswap16
+static inline u16 __bswap16(u16 x)
+{
+	return ((x >> 8) & 0xff) | ((x & 0xff) << 8);
+}
+#endif
+
+#ifndef __bswap32
+static inline u32 __bswap32(u32 x)
+{
+	return ((x & 0xff000000) >> 24) | ((x & 0x00ff0000) >>  8) |
+	       ((x & 0x0000ff00) <<  8) | ((x & 0x000000ff) << 24);
+}
+#endif
+
+#ifdef CONFIG_64BIT
+#ifndef __bswap64
+static inline u64 __bswap64(u64 x)
+{
+	return ((x & 0x00000000000000ffULL) << 56) |
+	       ((x & 0x000000000000ff00ULL) << 40) |
+	       ((x & 0x0000000000ff0000ULL) << 24) |
+	       ((x & 0x00000000ff000000ULL) <<  8) |
+	       ((x & 0x000000ff00000000ULL) >>  8) |
+	       ((x & 0x0000ff0000000000ULL) >> 24) |
+	       ((x & 0x00ff000000000000ULL) >> 40) |
+	       ((x & 0xff00000000000000ULL) >> 56);
+}
+#endif
+#endif
+
+#ifndef cpu_is_be
+#define cpu_is_be 0
+#endif
+
+#define le16_to_cpu(x) \
+	({ u16 __r = cpu_is_be ? __bswap16(x) : (x); __r; })
+#define cpu_to_le16 le16_to_cpu
+
+#define le32_to_cpu(x) \
+	({ u32 __r = cpu_is_be ? __bswap32(x) : (x); __r; })
+#define cpu_to_le32 le32_to_cpu
+
+#ifdef CONFIG_64BIT
+#define le64_to_cpu \
+	({ u64 __r = cpu_is_be ? __bswap64(x) : (x); __r; })
+#define cpu_to_le64 le64_to_cpu
+#endif
+
+#define be16_to_cpu(x) \
+	({ u16 __r = !cpu_is_be ? __bswap16(x) : (x); __r; })
+#define cpu_to_be16 be16_to_cpu
+
+#define be32_to_cpu(x) \
+	({ u32 __r = !cpu_is_be ? __bswap32(x) : (x); __r; })
+#define cpu_to_be32 be32_to_cpu
+
+#ifdef CONFIG_64BIT
+#define be64_to_cpu \
+	({ u64 __r = !cpu_is_be ? __bswap64(x) : (x); __r; })
+#define cpu_to_be64 be64_to_cpu
+#endif
+
+#ifndef rmb
+#define rmb() do { } while (0)
+#endif
+#ifndef wmb
+#define wmb() do { } while (0)
+#endif
+
+#define readb(addr) \
+	({ u8 __r = __raw_readb(addr); rmb(); __r; })
+#define readw(addr) \
+	({ u16 __r = le16_to_cpu(__raw_readw(addr)); rmb(); __r; })
+#define readl(addr) \
+	({ u32 __r = le32_to_cpu(__raw_readl(addr)); rmb(); __r; })
+#ifdef CONFIG_64BIT
+#define readq(addr) \
+	({ u64 __r = le64_to_cpu(__raw_readq(addr)); rmb(); __r; })
+#endif
+
+#define writeb(b, addr) \
+	({ wmb(); __raw_writeb(b, addr); })
+#define writew(b, addr) \
+	({ wmb(); __raw_writew(cpu_to_le16(b), addr); })
+#define writel(b, addr) \
+	({ wmb(); __raw_writel(cpu_to_le32(b), addr); })
+#ifdef CONFIG_64BIT
+#define writeq(b, addr) \
+	({ wmb(); __raw_writeq(cpu_to_le64(b), addr); })
+#endif
+
+extern void read_len(const volatile void *addr, void *buf, unsigned len);
+extern void write_len(volatile void *addr, const void *buf, unsigned len);
+
+#endif
Signature · 1 line
1.8.1.4

I didn't review all these defines and raw_ functions carefully as I assume the individual functions and defines are copied verbatim from the kernel?

Signature · 1 line
Christoffer
#15 lore raw

Re: [PATCH 5/9] Introduce libio to common code for io read/write

Quoted 30 lines · Christoffer Dall
Quoted 30 lines
lib/libio.c new file +24 -0
new file mode 100644
index 0000000000000..e450e984fefb1
@@ -0,0 +1,67 @@
+#include "libcflat.h"
+#include "libio.h"
+
+void read_len(const volatile void *addr, void *buf, unsigned len)
+{
+	unsigned long val;
+
+	switch (len) {
+	case 1:
+		val = readb(addr);
+		break;
+	case 2:
+		val = readw(addr);
+		break;
+	case 4:
+		val = readl(addr);
+		break;
+#ifdef CONFIG_64BIT
+	case 8:
+		val = readq(addr);
+		break;
+#endif
+	default:
+	{
Quoted 8 lines

lib/libio.c line 30

Quoted 6 lines
lib/libio.c new file +6 -0
+		u8 *p = buf;
+		unsigned i;
+
+		for (i = 0; i < len; ++i)
+			p[i] = readb(addr + i);
+		return;

are you taking proper care of endianness in the common case?

Nope, and on second thought I'll change the default to be an error instead. Something like this doesn't really belong in an io lib.

Quoted 15 lines

lib/libio.c line 41

Quoted 12 lines
lib/libio.c new file +11 -0
+	}
+	}
+	memcpy(buf, &val, len);
+}
+
+void write_len(volatile void *addr, const void *buf, unsigned len)
+{
+	unsigned long val;
+
+	if (len <= sizeof(unsigned long))
+		memcpy(&val, buf, len);

Does this work with big-endian for sizes smaller than sizeof(unsigned long)?

Dunno. I didn't test it. Looking at Marc's code makes me suspect is does not though...

Quoted 3 lines

Take a look at arch/arm/kvm/mmio.c and see how Marc uses a union to solve this issue.

I'll rework this with some shameless theft from Marc.

Quoted 4 lines
Quoted 4 lines
lib/libio.c new file +4 -0
+/*
+ * Adapted from the Linux kernel's include/asm-generic/io.h and
+ * arch/arm/include/asm/io.h
+ */
Quoted 8 lines

lib/libio.c line 48

Quoted 3 lines
lib/libio.c new file +3 -0
+#include "libcflat.h"
+
+typedef u32 compat_ptr_t;

How is this going to be used here? The compat ptr stuff in the kernel deals with user space pointer iirc, but I'm not an expert on the details. Does typedef'ing a pointer to a u32 in generic code work on a 64-bit platform?

This is necessary to eliminate compiler warnings when casting 64-bit pointers to u32s.

Quoted 166 lines
Quoted 166 lines
lib/libio.c new file +165 -0
+
+static inline void *compat_ptr(compat_ptr_t ptr)
+{
+	return (void *)(unsigned long)ptr;
+}
+
+static inline compat_ptr_t ptr_to_compat(void *ptr)
+{
+	return (u32)(unsigned long)ptr;
+}
+
+#ifndef __raw_readb
+static inline u8 __raw_readb(const volatile void *addr)
+{
+	return *(const volatile u8 *)addr;
+}
+#endif
+
+#ifndef __raw_readw
+static inline u16 __raw_readw(const volatile void *addr)
+{
+	return *(const volatile u16 *)addr;
+}
+#endif
+
+#ifndef __raw_readl
+static inline u32 __raw_readl(const volatile void *addr)
+{
+	return *(const volatile u32 *)addr;
+}
+#endif
+
+#ifdef CONFIG_64BIT
+#ifndef __raw_readq
+static inline u64 __raw_readq(const volatile void *addr)
+{
+	return *(const volatile u64 *)addr;
+}
+#endif
+#endif
+
+#ifndef __raw_writeb
+static inline void __raw_writeb(u8 b, volatile void *addr)
+{
+	*(volatile u8 *)addr = b;
+}
+#endif
+
+#ifndef __raw_writew
+static inline void __raw_writew(u16 b, volatile void *addr)
+{
+	*(volatile u16 *)addr = b;
+}
+#endif
+
+#ifndef __raw_writel
+static inline void __raw_writel(u32 b, volatile void *addr)
+{
+	*(volatile u32 *)addr = b;
+}
+#endif
+
+#ifdef CONFIG_64BIT
+#ifndef __raw_writeq
+static inline void __raw_writeq(u64 b, volatile void *addr)
+{
+	*(volatile u64 *)addr = b;
+}
+#endif
+#endif
+
+#ifndef __bswap16
+static inline u16 __bswap16(u16 x)
+{
+	return ((x >> 8) & 0xff) | ((x & 0xff) << 8);
+}
+#endif
+
+#ifndef __bswap32
+static inline u32 __bswap32(u32 x)
+{
+	return ((x & 0xff000000) >> 24) | ((x & 0x00ff0000) >>  8) |
+	       ((x & 0x0000ff00) <<  8) | ((x & 0x000000ff) << 24);
+}
+#endif
+
+#ifdef CONFIG_64BIT
+#ifndef __bswap64
+static inline u64 __bswap64(u64 x)
+{
+	return ((x & 0x00000000000000ffULL) << 56) |
+	       ((x & 0x000000000000ff00ULL) << 40) |
+	       ((x & 0x0000000000ff0000ULL) << 24) |
+	       ((x & 0x00000000ff000000ULL) <<  8) |
+	       ((x & 0x000000ff00000000ULL) >>  8) |
+	       ((x & 0x0000ff0000000000ULL) >> 24) |
+	       ((x & 0x00ff000000000000ULL) >> 40) |
+	       ((x & 0xff00000000000000ULL) >> 56);
+}
+#endif
+#endif
+
+#ifndef cpu_is_be
+#define cpu_is_be 0
+#endif
+
+#define le16_to_cpu(x) \
+	({ u16 __r = cpu_is_be ? __bswap16(x) : (x); __r; })
+#define cpu_to_le16 le16_to_cpu
+
+#define le32_to_cpu(x) \
+	({ u32 __r = cpu_is_be ? __bswap32(x) : (x); __r; })
+#define cpu_to_le32 le32_to_cpu
+
+#ifdef CONFIG_64BIT
+#define le64_to_cpu \
+	({ u64 __r = cpu_is_be ? __bswap64(x) : (x); __r; })
+#define cpu_to_le64 le64_to_cpu
+#endif
+
+#define be16_to_cpu(x) \
+	({ u16 __r = !cpu_is_be ? __bswap16(x) : (x); __r; })
+#define cpu_to_be16 be16_to_cpu
+
+#define be32_to_cpu(x) \
+	({ u32 __r = !cpu_is_be ? __bswap32(x) : (x); __r; })
+#define cpu_to_be32 be32_to_cpu
+
+#ifdef CONFIG_64BIT
+#define be64_to_cpu \
+	({ u64 __r = !cpu_is_be ? __bswap64(x) : (x); __r; })
+#define cpu_to_be64 be64_to_cpu
+#endif
+
+#ifndef rmb
+#define rmb() do { } while (0)
+#endif
+#ifndef wmb
+#define wmb() do { } while (0)
+#endif
+
+#define readb(addr) \
+	({ u8 __r = __raw_readb(addr); rmb(); __r; })
+#define readw(addr) \
+	({ u16 __r = le16_to_cpu(__raw_readw(addr)); rmb(); __r; })
+#define readl(addr) \
+	({ u32 __r = le32_to_cpu(__raw_readl(addr)); rmb(); __r; })
+#ifdef CONFIG_64BIT
+#define readq(addr) \
+	({ u64 __r = le64_to_cpu(__raw_readq(addr)); rmb(); __r; })
+#endif
+
+#define writeb(b, addr) \
+	({ wmb(); __raw_writeb(b, addr); })
+#define writew(b, addr) \
+	({ wmb(); __raw_writew(cpu_to_le16(b), addr); })
+#define writel(b, addr) \
+	({ wmb(); __raw_writel(cpu_to_le32(b), addr); })
+#ifdef CONFIG_64BIT
+#define writeq(b, addr) \
+	({ wmb(); __raw_writeq(cpu_to_le64(b), addr); })
+#endif
+
+extern void read_len(const volatile void *addr, void *buf, unsigned len);
+extern void write_len(volatile void *addr, const void *buf, unsigned len);
Quoted 9 lines
Quoted 4 lines
lib/libio.c new file +2 -0
+
+#endif
Signature · 1 line
1.8.1.4

I didn't review all these defines and raw_ functions carefully as I assume the individual functions and defines are copied verbatim from the kernel?

You should take a look, as they're not verbatim - although almost. I can't recall where I might have diverged, I just know I didn't copy+paste :-)

drew

#16 lore raw

Re: [PATCH 5/9] Introduce libio to common code for io read/write

Quoted 81 lines · Andrew Jones
Quoted 30 lines · Christoffer Dall
Quoted 30 lines
lib/libio.c new file +24 -0
new file mode 100644
index 0000000000000..e450e984fefb1
@@ -0,0 +1,67 @@
+#include "libcflat.h"
+#include "libio.h"
+
+void read_len(const volatile void *addr, void *buf, unsigned len)
+{
+	unsigned long val;
+
+	switch (len) {
+	case 1:
+		val = readb(addr);
+		break;
+	case 2:
+		val = readw(addr);
+		break;
+	case 4:
+		val = readl(addr);
+		break;
+#ifdef CONFIG_64BIT
+	case 8:
+		val = readq(addr);
+		break;
+#endif
+	default:
+	{
Quoted 8 lines

lib/libio.c line 30

Quoted 6 lines
lib/libio.c new file +6 -0
+		u8 *p = buf;
+		unsigned i;
+
+		for (i = 0; i < len; ++i)
+			p[i] = readb(addr + i);
+		return;

are you taking proper care of endianness in the common case?

Nope, and on second thought I'll change the default to be an error instead. Something like this doesn't really belong in an io lib.

Quoted 15 lines

lib/libio.c line 41

Quoted 12 lines
lib/libio.c new file +11 -0
+	}
+	}
+	memcpy(buf, &val, len);
+}
+
+void write_len(volatile void *addr, const void *buf, unsigned len)
+{
+	unsigned long val;
+
+	if (len <= sizeof(unsigned long))
+		memcpy(&val, buf, len);

Does this work with big-endian for sizes smaller than sizeof(unsigned long)?

Dunno. I didn't test it. Looking at Marc's code makes me suspect is does not though...

Quoted 3 lines

Take a look at arch/arm/kvm/mmio.c and see how Marc uses a union to solve this issue.

I'll rework this with some shameless theft from Marc.

Quoted 4 lines
Quoted 4 lines
lib/libio.c new file +4 -0
+/*
+ * Adapted from the Linux kernel's include/asm-generic/io.h and
+ * arch/arm/include/asm/io.h
+ */
Quoted 8 lines

lib/libio.c line 48

Quoted 3 lines
lib/libio.c new file +3 -0
+#include "libcflat.h"
+
+typedef u32 compat_ptr_t;

How is this going to be used here? The compat ptr stuff in the kernel deals with user space pointer iirc, but I'm not an expert on the details. Does typedef'ing a pointer to a u32 in generic code work on a 64-bit platform?

Quoted 3 lines

This is necessary to eliminate compiler warnings when casting 64-bit pointers to u32s.

ah, ok, a comment to that effect would be nice for us neandertals still mostly stuck in the 32-bit worlds.

Quoted 176 lines
Quoted 166 lines
Quoted 166 lines
lib/libio.c new file +165 -0
+
+static inline void *compat_ptr(compat_ptr_t ptr)
+{
+	return (void *)(unsigned long)ptr;
+}
+
+static inline compat_ptr_t ptr_to_compat(void *ptr)
+{
+	return (u32)(unsigned long)ptr;
+}
+
+#ifndef __raw_readb
+static inline u8 __raw_readb(const volatile void *addr)
+{
+	return *(const volatile u8 *)addr;
+}
+#endif
+
+#ifndef __raw_readw
+static inline u16 __raw_readw(const volatile void *addr)
+{
+	return *(const volatile u16 *)addr;
+}
+#endif
+
+#ifndef __raw_readl
+static inline u32 __raw_readl(const volatile void *addr)
+{
+	return *(const volatile u32 *)addr;
+}
+#endif
+
+#ifdef CONFIG_64BIT
+#ifndef __raw_readq
+static inline u64 __raw_readq(const volatile void *addr)
+{
+	return *(const volatile u64 *)addr;
+}
+#endif
+#endif
+
+#ifndef __raw_writeb
+static inline void __raw_writeb(u8 b, volatile void *addr)
+{
+	*(volatile u8 *)addr = b;
+}
+#endif
+
+#ifndef __raw_writew
+static inline void __raw_writew(u16 b, volatile void *addr)
+{
+	*(volatile u16 *)addr = b;
+}
+#endif
+
+#ifndef __raw_writel
+static inline void __raw_writel(u32 b, volatile void *addr)
+{
+	*(volatile u32 *)addr = b;
+}
+#endif
+
+#ifdef CONFIG_64BIT
+#ifndef __raw_writeq
+static inline void __raw_writeq(u64 b, volatile void *addr)
+{
+	*(volatile u64 *)addr = b;
+}
+#endif
+#endif
+
+#ifndef __bswap16
+static inline u16 __bswap16(u16 x)
+{
+	return ((x >> 8) & 0xff) | ((x & 0xff) << 8);
+}
+#endif
+
+#ifndef __bswap32
+static inline u32 __bswap32(u32 x)
+{
+	return ((x & 0xff000000) >> 24) | ((x & 0x00ff0000) >>  8) |
+	       ((x & 0x0000ff00) <<  8) | ((x & 0x000000ff) << 24);
+}
+#endif
+
+#ifdef CONFIG_64BIT
+#ifndef __bswap64
+static inline u64 __bswap64(u64 x)
+{
+	return ((x & 0x00000000000000ffULL) << 56) |
+	       ((x & 0x000000000000ff00ULL) << 40) |
+	       ((x & 0x0000000000ff0000ULL) << 24) |
+	       ((x & 0x00000000ff000000ULL) <<  8) |
+	       ((x & 0x000000ff00000000ULL) >>  8) |
+	       ((x & 0x0000ff0000000000ULL) >> 24) |
+	       ((x & 0x00ff000000000000ULL) >> 40) |
+	       ((x & 0xff00000000000000ULL) >> 56);
+}
+#endif
+#endif
+
+#ifndef cpu_is_be
+#define cpu_is_be 0
+#endif
+
+#define le16_to_cpu(x) \
+	({ u16 __r = cpu_is_be ? __bswap16(x) : (x); __r; })
+#define cpu_to_le16 le16_to_cpu
+
+#define le32_to_cpu(x) \
+	({ u32 __r = cpu_is_be ? __bswap32(x) : (x); __r; })
+#define cpu_to_le32 le32_to_cpu
+
+#ifdef CONFIG_64BIT
+#define le64_to_cpu \
+	({ u64 __r = cpu_is_be ? __bswap64(x) : (x); __r; })
+#define cpu_to_le64 le64_to_cpu
+#endif
+
+#define be16_to_cpu(x) \
+	({ u16 __r = !cpu_is_be ? __bswap16(x) : (x); __r; })
+#define cpu_to_be16 be16_to_cpu
+
+#define be32_to_cpu(x) \
+	({ u32 __r = !cpu_is_be ? __bswap32(x) : (x); __r; })
+#define cpu_to_be32 be32_to_cpu
+
+#ifdef CONFIG_64BIT
+#define be64_to_cpu \
+	({ u64 __r = !cpu_is_be ? __bswap64(x) : (x); __r; })
+#define cpu_to_be64 be64_to_cpu
+#endif
+
+#ifndef rmb
+#define rmb() do { } while (0)
+#endif
+#ifndef wmb
+#define wmb() do { } while (0)
+#endif
+
+#define readb(addr) \
+	({ u8 __r = __raw_readb(addr); rmb(); __r; })
+#define readw(addr) \
+	({ u16 __r = le16_to_cpu(__raw_readw(addr)); rmb(); __r; })
+#define readl(addr) \
+	({ u32 __r = le32_to_cpu(__raw_readl(addr)); rmb(); __r; })
+#ifdef CONFIG_64BIT
+#define readq(addr) \
+	({ u64 __r = le64_to_cpu(__raw_readq(addr)); rmb(); __r; })
+#endif
+
+#define writeb(b, addr) \
+	({ wmb(); __raw_writeb(b, addr); })
+#define writew(b, addr) \
+	({ wmb(); __raw_writew(cpu_to_le16(b), addr); })
+#define writel(b, addr) \
+	({ wmb(); __raw_writel(cpu_to_le32(b), addr); })
+#ifdef CONFIG_64BIT
+#define writeq(b, addr) \
+	({ wmb(); __raw_writeq(cpu_to_le64(b), addr); })
+#endif
+
+extern void read_len(const volatile void *addr, void *buf, unsigned len);
+extern void write_len(volatile void *addr, const void *buf, unsigned len);
Quoted 9 lines
Quoted 4 lines
lib/libio.c new file +2 -0
+
+#endif
Signature · 1 line
1.8.1.4

I didn't review all these defines and raw_ functions carefully as I assume the individual functions and defines are copied verbatim from the kernel?

Quoted 3 lines

You should take a look, as they're not verbatim - although almost. I can't recall where I might have diverged, I just know I didn't copy+paste :-)

Wonderful, I'll take a look :)

#17 lore raw

Re: [PATCH 5/9] Introduce libio to common code for io read/write

Quoted 11 lines · Christoffer Dall
Quoted 8 lines
Quoted 4 lines

How is this going to be used here? The compat ptr stuff in the kernel deals with user space pointer iirc, but I'm not an expert on the details. Does typedef'ing a pointer to a u32 in generic code work on a 64-bit platform?

This is necessary to eliminate compiler warnings when casting 64-bit pointers to u32s.

ah, ok, a comment to that effect would be nice for us neandertals still mostly stuck in the 32-bit worlds.

OK

Quoted 5 lines
Quoted 3 lines

You should take a look, as they're not verbatim - although almost. I can't recall where I might have diverged, I just know I didn't copy+paste :-)

Wonderful, I'll take a look :)

Thanks!!

#18 lore raw

PATCH v2 6/9 Introduce a simple iomap structure

In reply to Andrew Jones

Add a simple structure and search function to the common code that can be used for looking up a set of addresses by type. The user must supply the iomaps[] table, e.g.

struct iomap iomaps[] = {

{
    .type = "virtio_mmio",
    .nr = 4,
    .addrs = { 0x2000000, 0x2000200, 0x2000400, 0x2000600, },
},

{
.type = NULL,
},
};

Also add a script scripts/gen-devtree-iomaps.pl that can generate the iomaps table from an fdt, e.g.

fdtdump dtb | scripts/gen-devtree-iomaps.pl - virtio_mmio

---
v2:
- switch to kernel coding style
- rework fdt parsing to enable extraction of properties. Extract the 'compatible' property.
- add iomaps_find_compatible() to allow searching for iomaps by its 'compatible' property.

---
 README                        |   1 +
 lib/iomaps.c                  |  31 +++++++++++++
 lib/iomaps.h                  |  14 ++++++
 scripts/gen-devtree-iomaps.pl | 105 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 151 insertions(+)
 create mode 100644 lib/iomaps.c
 create mode 100644 lib/iomaps.h
 create mode 100755 scripts/gen-devtree-iomaps.pl
README +1 -0
index 0174679c05021..f834c61dc6112 100644
@@ -20,6 +20,7 @@ Directory structure:
 .:		Makefile and config files for the tests
 ./config:	config files for the tests
 ./docs:		documentation files
+./scripts:	misc helper scripts
 ./lib:		general services for the tests
 ./lib/<ARCH>:	architecture dependent services for the tests
 ./<ARCH>:	the sources of the tests and the created objects/images
lib/iomaps.c new file +31 -0
new file mode 100644
index 0000000000000..f2263b79dce96
@@ -0,0 +1,31 @@
+#include "libcflat.h"
+#include "iomaps.h"
+
+extern const struct iomap iomaps[];
+
+const struct iomap *iomaps_find_type(const char *type)
+{
+	const struct iomap *m = &iomaps[0];
+
+	while (m->type) {
+		if (strcmp(m->type, type) == 0)
+			return m;
+		++m;
+	}
+	return NULL;
+}
+
+const struct iomap *iomaps_find_compatible(const char *compat)
+{
+	const struct iomap *m = &iomaps[0];
+	const char *c;
+	int i;
+
+	while (m->type) {
+		for (i = 0, c = m->compats[0]; c != NULL; c = m->compats[++i])
+			if (strcmp(c, compat) == 0)
+				return m;
+		++m;
+	}
+	return NULL;
+}
lib/iomaps.h new file +14 -0
new file mode 100644
index 0000000000000..76a1aa4720337
@@ -0,0 +1,14 @@
+#ifndef _IOMAPS_H_
+#define _IOMAPS_H_
+#include "libcflat.h"
+
+struct iomap {
+	const char *type;
+	const char *compats[5];
+	u32 nr;
+	u32 addrs[64];
+};
+
+const struct iomap *iomaps_find_type(const char *type);
+const struct iomap *iomaps_find_compatible(const char *compat);
+#endif
scripts/gen-devtree-iomaps.pl new file +105 -0

105 lines not on this page · raw message

Signature · 1 line
1.8.1.4
#19 lore raw

Re: [PATCH 6/9] Introduce a simple iomap structure

Quoted 94 lines · Andrew Jones

Add a simple structure and search function to the common code that can be used for looking up a set of addresses by type. The user must supply the iomaps[] table, e.g.

struct iomap iomaps[] = {

{
    .type = "virtio_mmio",
    .nr = 4,
    .addrs = { 0x2000000, 0x2000200, 0x2000400, 0x2000600, },
},

{
.type = NULL,
},
};

Also add a script scripts/gen-devtree-iomaps.pl that can generate the iomaps table from an fdt, e.g.

fdtdump dtb | scripts/gen-devtree-iomaps.pl - virtio_mmio

---
v2:
- switch to kernel coding style
- rework fdt parsing to enable extraction of properties. Extract the 'compatible' property.
- add iomaps_find_compatible() to allow searching for iomaps by its 'compatible' property.

---
 README                        |   1 +
 lib/iomaps.c                  |  31 +++++++++++++
 lib/iomaps.h                  |  14 ++++++
 scripts/gen-devtree-iomaps.pl | 105 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 151 insertions(+)
 create mode 100644 lib/iomaps.c
 create mode 100644 lib/iomaps.h
 create mode 100755 scripts/gen-devtree-iomaps.pl
README +1 -0
index 0174679c05021..f834c61dc6112 100644
@@ -20,6 +20,7 @@ Directory structure:
 .:		Makefile and config files for the tests
 ./config:	config files for the tests
 ./docs:		documentation files
+./scripts:	misc helper scripts
 ./lib:		general services for the tests
 ./lib/<ARCH>:	architecture dependent services for the tests
 ./<ARCH>:	the sources of the tests and the created objects/images
lib/iomaps.c new file +31 -0
new file mode 100644
index 0000000000000..f2263b79dce96
@@ -0,0 +1,31 @@
+#include "libcflat.h"
+#include "iomaps.h"
+
+extern const struct iomap iomaps[];
+
+const struct iomap *iomaps_find_type(const char *type)
+{
+	const struct iomap *m = &iomaps[0];
+
+	while (m->type) {
+		if (strcmp(m->type, type) == 0)
+			return m;
+		++m;
+	}
+	return NULL;
+}
+
+const struct iomap *iomaps_find_compatible(const char *compat)
+{
+	const struct iomap *m = &iomaps[0];
+	const char *c;
+	int i;
+
+	while (m->type) {
+		for (i = 0, c = m->compats[0]; c != NULL; c = m->compats[++i])
+			if (strcmp(c, compat) == 0)
+				return m;
+		++m;
+	}
+	return NULL;
+}
lib/iomaps.h new file +0 -0
new file mode 100644
index 0000000000000..76a1aa4720337

lib/iomaps.h line 7

Quoted 7 lines
lib/iomaps.h new file +7 -0
@@ -0,0 +1,14 @@
+#ifndef _IOMAPS_H_
+#define _IOMAPS_H_
+#include "libcflat.h"
+
+struct iomap {
+	const char *type;
+	const char *compats[5];

I would name the field compatible to be more in-line with the DT-representation, but OK.

it looks from the above like the array must be null terminated?

how about #define IOMAP_MAX_COMPATS 5
and then turn your loop above into:

for (i = 0; i < IOMAP_MAX_COMPATS; i++, m++) {
	if (!m->compats[i])
		break;
	if (strcmp(m->compats[i], compat) == 0)
		return m;
}

lib/iomaps.h line 9

Quoted 2 lines
lib/iomaps.h new file +2 -0
+	u32 nr;
+	u32 addrs[64];

why are we limiting ourselves to a 32 bit physical address space?

Quoted 106 lines
lib/iomaps.h new file +5 -0
+};
+
+const struct iomap *iomaps_find_type(const char *type);
+const struct iomap *iomaps_find_compatible(const char *compat);
+#endif
scripts/gen-devtree-iomaps.pl new file +95 -0
new file mode 100755
index 0000000000000..b48e85e48ab34
@@ -0,0 +1,105 @@
+#!/usr/bin/perl -w
+use strict;
+use File::Temp qw/:POSIX/;
+
+my $dts = shift @ARGV;
+my @types = @ARGV;
+my $max_nr_addrs = 64;
+my $max_nr_compats = 4;
+
+if (!defined $dts || $#types < 0) {
+	print STDERR "Usage: gen-devtree-iomaps ".
+		"<dts-file|-> <addr-type> [addr-types...]\n";
+	exit 1;
+}
+
+my $dtb = tmpnam();
+system "dtc -I dts -O dtb $dts -o $dtb";
+
+my $g = join '|', map { $_ . '@' } @types;
+my @devs = grep { /$g/ } `fdtget -l $dtb / 2>/dev/null`;
+
+my %iomaps;
+foreach my $dev (@devs) {
+
+	chomp($dev);
+	my ($type, $addr) = split /@/, $dev;
+
+	if (!exists $iomaps{$type}) {
+
+		my $compatible = `fdtget $dtb /$dev compatible 2>/dev/null`;
+		chomp($compatible);
+		my @compats = split ' ', $compatible;
+
+		$iomaps{$type}{compats} = \@compats;
+		$iomaps{$type}{addrs} = [$addr];
+	} else {
+		push @{ $iomaps{$type}{addrs} }, $addr;
+	}
+}
+unlink $dtb;
+
+print <<EOF;
+/*
+ * Generated file. See gen-devtree-iomaps.pl
+ */
+#include "iomaps.h"
+EOF
+print "\nconst struct iomap iomaps[] = {\n";
+foreach my $type (keys %iomaps) {
+
+	my $compats = $iomaps{$type}{compats};
+	my $addrs = $iomaps{$type}{addrs};
+
+	my $nr_compats = $#{ $compats } + 1;
+	if ($nr_compats > $max_nr_compats) {
+		print STDERR "$type has $nr_compats compats, but iomaps can ".
+			"only support up to $max_nr_compats.\n";
+		splice @{ $compats }, $max_nr_compats;
+	}
+
+	@{ $addrs } = sort @{ $addrs };
+
+	my $nr = $#{ $addrs } + 1;
+	if ($nr > $max_nr_addrs) {
+		print STDERR "$type has $nr addrs, but iomaps can ".
+			"only support up to $max_nr_addrs.\n";
+		$nr = $max_nr_addrs;
+		splice @{ $addrs }, $nr;
+	}
+
+	@{ $addrs } = map { $_ = sprintf '0x%.8x', hex($_) } @{ $addrs };
+
+	print "{\n";
+	print "\t.type = \"$type\",\n";
+
+	print "\t.compats = {";
+	foreach my $compat (@{ $compats }) {
+		print " \"$compat\",";
+	}
+	print " NULL, },\n";
+
+	print "\t.nr = $nr,\n";
+	print "\t.addrs = {";
+	if ($nr < 5) {
+		print ' ';
+		print join ', ', @{ $addrs };
+		print ", },\n";
+	} else {
+		print "\n";
+		for (my $i = 0; $i < $nr; $i += 5) {
+			print "\t\t";
+			my $j = $i;
+			while ($j < $i + 4 && $j < $nr - 1) {
+				print $addrs->[$j] . ", ";
+				++$j;

scripts/gen-devtree-iomaps.pl line 105

Quoted 10 lines
scripts/gen-devtree-iomaps.pl new file +10 -0
+			}
+			print $addrs->[$j] . ",\n";
+		}
+		print "\t},\n";
+	}
+	print "},\n";
+}
+print "{\n\t.type = NULL,\n},\n";
+print "};\n";
+exit 0;

This script doesn't work on either of the Ubuntu distros I run. The reasons are that the dumpfdt tool is not processing the multi-compatible strings output from the dtb correctly and the fdtget utility included does not yet have the -l option to list subnodes.

I spent a fair amount of time trying to fix this, changing dumpfdt to 'dtc -I dtb -O dts', and I tried it on the newest Ubuntu distro, tried compiling fdtget from the kernel sources etc. and failed miserably.

I think at the very least we need to check the tools available on the build machine as part of the configure script or test it a little broader.

Thanks,

Signature · 1 line
Christoffer
#20 lore raw

Re: [PATCH 6/9] Introduce a simple iomap structure

Quoted 10 lines · Christoffer Dall

lib/iomaps.h line 7

Quoted 3 lines
lib/iomaps.h new file +3 -0
+struct iomap {
+	const char *type;
+	const char *compats[5];

I would name the field compatible to be more in-line with the DT-representation, but OK.

it looks from the above like the array must be null terminated?

how about #define IOMAP_MAX_COMPATS 5

defines are good.

Quoted 5 lines

and then turn your loop above into:

for (i = 0; i < IOMAP_MAX_COMPATS; i++, m++) {
	if (!m->compats[i])
		break;

Doesn't improve the loop conditions much, IMO.

Quoted 8 lines
	if (strcmp(m->compats[i], compat) == 0)
		return m;
}

lib/iomaps.h line 9

Quoted 2 lines
lib/iomaps.h new file +2 -0
+	u32 nr;
+	u32 addrs[64];

why are we limiting ourselves to a 32 bit physical address space?

I have had this mentally noted from the beginning as something I'll need to deal with when getting aarch64 going. Anyway, I think a lot of this is going to change as I teach kvm-unit-tests more and more about DT.

<snip>

Quoted 9 lines

scripts/gen-devtree-iomaps.pl line 105

Quoted 3 lines
scripts/gen-devtree-iomaps.pl new file +3 -0
+print "{\n\t.type = NULL,\n},\n";
+print "};\n";
+exit 0;

This script doesn't work on either of the Ubuntu distros I run. The reasons are that the dumpfdt tool is not processing the multi-compatible strings output from the dtb correctly and the fdtget utility included does not yet have the -l option to list subnodes.

Quoted 8 lines

I spent a fair amount of time trying to fix this, changing dumpfdt to 'dtc -I dtb -O dts', and I tried it on the newest Ubuntu distro, tried compiling fdtget from the kernel sources etc. and failed miserably.

I think at the very least we need to check the tools available on the build machine as part of the configure script or test it a little broader.

Drat. I've preferred the idea of using the tools to parse the DT during the build - avoiding the need for [cross-compiled] libfdt as a dep, but I guess as we need more and more from the DT, or when particular tests want to look at the DT itself, and there are already dependency problems, then it's looking more and more like we should just use libfdt.

drew

#21 lore raw

Re: [PATCH 6/9] Introduce a simple iomap structure

Quoted 14 lines · Andrew Jones
Quoted 10 lines · Christoffer Dall

lib/iomaps.h line 7

Quoted 3 lines
lib/iomaps.h new file +3 -0
+struct iomap {
+	const char *type;
+	const char *compats[5];

I would name the field compatible to be more in-line with the DT-representation, but OK.

it looks from the above like the array must be null terminated?

how about #define IOMAP_MAX_COMPATS 5

defines are good.

Quoted 8 lines
Quoted 5 lines

and then turn your loop above into:

for (i = 0; i < IOMAP_MAX_COMPATS; i++, m++) {
	if (!m->compats[i])
		break;

Doesn't improve the loop conditions much, IMO.

I think it's much simpler to read a for loop of the typical form of until "i < CONSTANT"; what you had before was a data structure with an assumption of null-termination that could only be realized by looking at the code that deals with it.

Quoted 9 lines
Quoted 8 lines
	if (strcmp(m->compats[i], compat) == 0)
		return m;
}

lib/iomaps.h line 9

Quoted 2 lines
lib/iomaps.h new file +2 -0
+	u32 nr;
+	u32 addrs[64];

why are we limiting ourselves to a 32 bit physical address space?

Quoted 4 lines

I have had this mentally noted from the beginning as something I'll need to deal with when getting aarch64 going. Anyway, I think a lot of this is going to change as I teach kvm-unit-tests more and more about DT.

Shouldn't be a big change to just support u64 in your iomap instead.

Quoted 20 lines

<snip>

Quoted 9 lines

scripts/gen-devtree-iomaps.pl line 105

Quoted 3 lines
scripts/gen-devtree-iomaps.pl new file +3 -0
+print "{\n\t.type = NULL,\n},\n";
+print "};\n";
+exit 0;

This script doesn't work on either of the Ubuntu distros I run. The reasons are that the dumpfdt tool is not processing the multi-compatible strings output from the dtb correctly and the fdtget utility included does not yet have the -l option to list subnodes.

Quoted 8 lines

I spent a fair amount of time trying to fix this, changing dumpfdt to 'dtc -I dtb -O dts', and I tried it on the newest Ubuntu distro, tried compiling fdtget from the kernel sources etc. and failed miserably.

I think at the very least we need to check the tools available on the build machine as part of the configure script or test it a little broader.

Quoted 6 lines

Drat. I've preferred the idea of using the tools to parse the DT during the build - avoiding the need for [cross-compiled] libfdt as a dep, but I guess as we need more and more from the DT, or when particular tests want to look at the DT itself, and there are already dependency problems, then it's looking more and more like we should just use libfdt.

Yes, after working with this for a while that's the same conclusion I came to. From the ARM perspective, anything running in a VM will be device-tree driven (this is not the time for anybody to say anything about ACPI), so we could just feed the VM the device tree directly if we support libfdt in the guest and avoid another point of failure. I can try to find some time to help you hack that up if you want.

#22 lore raw

Re: [PATCH 6/9] Introduce a simple iomap structure

Quoted 71 lines · Christoffer Dall
Quoted 14 lines · Andrew Jones
Quoted 10 lines · Christoffer Dall

lib/iomaps.h line 7

Quoted 3 lines
lib/iomaps.h new file +3 -0
+struct iomap {
+	const char *type;
+	const char *compats[5];

I would name the field compatible to be more in-line with the DT-representation, but OK.

it looks from the above like the array must be null terminated?

how about #define IOMAP_MAX_COMPATS 5

defines are good.

Quoted 8 lines
Quoted 5 lines

and then turn your loop above into:

for (i = 0; i < IOMAP_MAX_COMPATS; i++, m++) {
	if (!m->compats[i])
		break;

Doesn't improve the loop conditions much, IMO.

I think it's much simpler to read a for loop of the typical form of until "i < CONSTANT"; what you had before was a data structure with an assumption of null-termination that could only be realized by looking at the code that deals with it.

Quoted 9 lines
Quoted 8 lines
	if (strcmp(m->compats[i], compat) == 0)
		return m;
}

lib/iomaps.h line 9

Quoted 2 lines
lib/iomaps.h new file +2 -0
+	u32 nr;
+	u32 addrs[64];

why are we limiting ourselves to a 32 bit physical address space?

Quoted 4 lines

I have had this mentally noted from the beginning as something I'll need to deal with when getting aarch64 going. Anyway, I think a lot of this is going to change as I teach kvm-unit-tests more and more about DT.

Shouldn't be a big change to just support u64 in your iomap instead.

Quoted 20 lines

<snip>

Quoted 9 lines

scripts/gen-devtree-iomaps.pl line 105

Quoted 3 lines
scripts/gen-devtree-iomaps.pl new file +3 -0
+print "{\n\t.type = NULL,\n},\n";
+print "};\n";
+exit 0;

This script doesn't work on either of the Ubuntu distros I run. The reasons are that the dumpfdt tool is not processing the multi-compatible strings output from the dtb correctly and the fdtget utility included does not yet have the -l option to list subnodes.

Quoted 8 lines

I spent a fair amount of time trying to fix this, changing dumpfdt to 'dtc -I dtb -O dts', and I tried it on the newest Ubuntu distro, tried compiling fdtget from the kernel sources etc. and failed miserably.

I think at the very least we need to check the tools available on the build machine as part of the configure script or test it a little broader.

Quoted 6 lines

Drat. I've preferred the idea of using the tools to parse the DT during the build - avoiding the need for [cross-compiled] libfdt as a dep, but I guess as we need more and more from the DT, or when particular tests want to look at the DT itself, and there are already dependency problems, then it's looking more and more like we should just use libfdt.

Quoted 6 lines

Yes, after working with this for a while that's the same conclusion I came to. From the ARM perspective, anything running in a VM will be device-tree driven (this is not the time for anybody to say anything about ACPI), so we could just feed the VM the device tree directly if we support libfdt in the guest and avoid another point of failure. I can try to find some time to help you hack that up if you want.

I'll start this work right away. Peter's import libfdt idea sounds like the perfect solution.

drew

#23 lore raw

Re: [PATCH 6/9] Introduce a simple iomap structure

Quoted 79 lines · Andrew Jones
Quoted 71 lines · Christoffer Dall
Quoted 14 lines · Andrew Jones
Quoted 10 lines · Christoffer Dall

lib/iomaps.h line 7

Quoted 3 lines
lib/iomaps.h new file +3 -0
+struct iomap {
+	const char *type;
+	const char *compats[5];

I would name the field compatible to be more in-line with the DT-representation, but OK.

it looks from the above like the array must be null terminated?

how about #define IOMAP_MAX_COMPATS 5

defines are good.

Quoted 8 lines
Quoted 5 lines

and then turn your loop above into:

for (i = 0; i < IOMAP_MAX_COMPATS; i++, m++) {
	if (!m->compats[i])
		break;

Doesn't improve the loop conditions much, IMO.

I think it's much simpler to read a for loop of the typical form of until "i < CONSTANT"; what you had before was a data structure with an assumption of null-termination that could only be realized by looking at the code that deals with it.

Quoted 9 lines
Quoted 8 lines
	if (strcmp(m->compats[i], compat) == 0)
		return m;
}

lib/iomaps.h line 9

Quoted 2 lines
lib/iomaps.h new file +2 -0
+	u32 nr;
+	u32 addrs[64];

why are we limiting ourselves to a 32 bit physical address space?

Quoted 4 lines

I have had this mentally noted from the beginning as something I'll need to deal with when getting aarch64 going. Anyway, I think a lot of this is going to change as I teach kvm-unit-tests more and more about DT.

Shouldn't be a big change to just support u64 in your iomap instead.

Quoted 20 lines

<snip>

Quoted 9 lines

scripts/gen-devtree-iomaps.pl line 105

Quoted 3 lines
scripts/gen-devtree-iomaps.pl new file +3 -0
+print "{\n\t.type = NULL,\n},\n";
+print "};\n";
+exit 0;

This script doesn't work on either of the Ubuntu distros I run. The reasons are that the dumpfdt tool is not processing the multi-compatible strings output from the dtb correctly and the fdtget utility included does not yet have the -l option to list subnodes.

Quoted 8 lines

I spent a fair amount of time trying to fix this, changing dumpfdt to 'dtc -I dtb -O dts', and I tried it on the newest Ubuntu distro, tried compiling fdtget from the kernel sources etc. and failed miserably.

I think at the very least we need to check the tools available on the build machine as part of the configure script or test it a little broader.

Quoted 6 lines

Drat. I've preferred the idea of using the tools to parse the DT during the build - avoiding the need for [cross-compiled] libfdt as a dep, but I guess as we need more and more from the DT, or when particular tests want to look at the DT itself, and there are already dependency problems, then it's looking more and more like we should just use libfdt.

Quoted 6 lines

Yes, after working with this for a while that's the same conclusion I came to. From the ARM perspective, anything running in a VM will be device-tree driven (this is not the time for anybody to say anything about ACPI), so we could just feed the VM the device tree directly if we support libfdt in the guest and avoid another point of failure. I can try to find some time to help you hack that up if you want.

Quoted 3 lines

I'll start this work right away. Peter's import libfdt idea sounds like the perfect solution.

Agreed.

-Christoffer

#24 lore raw

Re: [PATCH 6/9] Introduce a simple iomap structure

In reply to Andrew Jones
Quoted 5 lines · Andrew Jones

Drat. I've preferred the idea of using the tools to parse the DT during the build - avoiding the need for [cross-compiled] libfdt as a dep, but I guess as we need more and more from the DT, or when particular tests want to look at the DT itself, and there are already dependency problems, then it's looking more and more like we should just use libfdt.

You can just have a local copy of the libfdt sources and compile them in -- libfdt is written to support that (since you need to use it that way for bootloaders and the like), and QEMU does that as a fallback if there's no system libfdt. So you don't necessarily need to require a cross-libfdt to be provided externally.

thanks
-- PMM

#25 lore raw

PATCH v2 7/9 Add halt() and some error codes

In reply to Andrew Jones

Define a halt function that can be implemented by the test framework for use on error paths before exit() works. Also add some error codes that can be passed to halt() in case the serial isn't working either. Then, on register inspection of the halted guest we may be able to quickly determine the problem without having to find the halt() call-site. The error codes may of course also be used with exit().

---
v2:
- keep the error numbers more consistent with the standard numbers

---
 lib/errno.h    | 22 ++++++++++++++++++++++
 lib/libcflat.h |  2 ++
 2 files changed, 24 insertions(+)
 create mode 100644 lib/errno.h
lib/errno.h new file +22 -0
new file mode 100644
index 0000000000000..f60845cdc61f6
@@ -0,0 +1,22 @@
+#ifndef _ERRNO_H_
+#define _ERRNO_H_
+/*
+ * Define some error codes for the test framework's use. qemu
+ * exits with ((code << 1) | 1) when this framework calls
+ * exit(code), so we reserve codes 64 to 126. 127 is left
+ * for exit(-1).
+ *
+ * (Ab)use the standard E* names for syntax highlighting...
+ * The errno descriptions in [] are for non-standard semantics.
+ */
+#define EINTR	(64 + 4)	/* [unhandled exception] */
+#define EIO	(64 + 5)	/* I/O error */
+#define ENXIO	(64 + 6)	/* No such device or address [no serial] */
+#define ENOEXEC	(64 + 8)	/* Exec format error [bad flat file] */
+#define ENOMEM	(64 + 12)	/* Out of memory */
+#define ENODEV	(64 + 19)	/* No such device */
+#define EINVAL	(64 + 22)	/* Invalid argument */
+#define ENOSPC	(64 + 28)	/* No space left on device */
+#define ERANGE	(64 + 34)	/* Math result not representable
+				   [divide by zero] */
+#endif
lib/libcflat.h +2 -0
index 140c172e77d54..a1be635ab4ee9 100644
@@ -37,6 +37,7 @@ typedef _Bool bool;
 #define true 1
 #define false 0
 
+extern void halt(int code);
 extern void exit(int code);
 
 extern unsigned long strlen(const char *buf);
@@ -57,4 +58,5 @@ extern long atol(const char *ptr);
 #define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER)
 
 #define NULL ((void *)0UL)
+#include "errno.h"
 #endif
Signature · 1 line
1.8.1.4
#26 lore raw

Re: [PATCH 7/9] Add halt() and some error codes

Quoted 6 lines · Andrew Jones

Define a halt function that can be implemented by the test framework for use on error paths before exit() works. Also add some error codes that can be passed to halt() in case the serial isn't working either. Then, on register inspection of the halted guest we may be able to quickly determine the problem without having to find the halt() call-site. The error codes may of course also be used with exit().

Looks good to me.

-Christoffer

Quoted 61 lines

---
v2:
- keep the error numbers more consistent with the standard numbers

---
 lib/errno.h    | 22 ++++++++++++++++++++++
 lib/libcflat.h |  2 ++
 2 files changed, 24 insertions(+)
 create mode 100644 lib/errno.h
lib/errno.h new file +22 -0
new file mode 100644
index 0000000000000..f60845cdc61f6
@@ -0,0 +1,22 @@
+#ifndef _ERRNO_H_
+#define _ERRNO_H_
+/*
+ * Define some error codes for the test framework's use. qemu
+ * exits with ((code << 1) | 1) when this framework calls
+ * exit(code), so we reserve codes 64 to 126. 127 is left
+ * for exit(-1).
+ *
+ * (Ab)use the standard E* names for syntax highlighting...
+ * The errno descriptions in [] are for non-standard semantics.
+ */
+#define EINTR	(64 + 4)	/* [unhandled exception] */
+#define EIO	(64 + 5)	/* I/O error */
+#define ENXIO	(64 + 6)	/* No such device or address [no serial] */
+#define ENOEXEC	(64 + 8)	/* Exec format error [bad flat file] */
+#define ENOMEM	(64 + 12)	/* Out of memory */
+#define ENODEV	(64 + 19)	/* No such device */
+#define EINVAL	(64 + 22)	/* Invalid argument */
+#define ENOSPC	(64 + 28)	/* No space left on device */
+#define ERANGE	(64 + 34)	/* Math result not representable
+				   [divide by zero] */
+#endif
lib/libcflat.h +2 -0
index 140c172e77d54..a1be635ab4ee9 100644
@@ -37,6 +37,7 @@ typedef _Bool bool;
 #define true 1
 #define false 0
 
+extern void halt(int code);
 extern void exit(int code);
 
 extern unsigned long strlen(const char *buf);
@@ -57,4 +58,5 @@ extern long atol(const char *ptr);
 #define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER)
 
 #define NULL ((void *)0UL)
+#include "errno.h"
 #endif
Signature · 1 line
1.8.1.4
#27 lore raw

PATCH v2 8/9 Introduce virtio-testdev

In reply to 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.

---
v2:
- use readl/writel framework (libio) [Christoffer Dall]
- keep the virtio abstraction in virtio-testdev [Alexander Graf]

---
 lib/libcflat.h       |   3 ++
 lib/virtio-testdev.c | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/virtio-testdev.h |   9 ++++
 lib/virtio.c         |  70 ++++++++++++++++++++++++++
 lib/virtio.h         |  74 +++++++++++++++++++++++++++
 5 files changed, 295 insertions(+)
 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
lib/libcflat.h +3 -0
index a1be635ab4ee9..197b703e53b46 100644
@@ -56,6 +56,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)
 #include "errno.h"
lib/virtio-testdev.c new file +139 -0

139 lines not on this page · raw message

lib/virtio-testdev.h new file +9 -0
new file mode 100644
index 0000000000000..c10bbfb591d0b
@@ -0,0 +1,9 @@
+#ifndef _VIRTIO_TESTDEV_H_
+#define _VIRTIO_TESTDEV_H_
+#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
lib/virtio.c new file +70 -0

70 lines not on this page · raw message

lib/virtio.h new file +74 -0

74 lines not on this page · raw message

Signature · 1 line
1.8.1.4
#28 lore raw

Re: [PATCH 8/9] Introduce virtio-testdev

Quoted 80 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.

---
v2:
- use readl/writel framework (libio) [Christoffer Dall]
- keep the virtio abstraction in virtio-testdev [Alexander Graf]

---
 lib/libcflat.h       |   3 ++
 lib/virtio-testdev.c | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/virtio-testdev.h |   9 ++++
 lib/virtio.c         |  70 ++++++++++++++++++++++++++
 lib/virtio.h         |  74 +++++++++++++++++++++++++++
 5 files changed, 295 insertions(+)
 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
lib/libcflat.h +3 -0
index a1be635ab4ee9..197b703e53b46 100644
@@ -56,6 +56,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)
 #include "errno.h"
lib/virtio-testdev.c new file +37 -0
new file mode 100644
index 0000000000000..93731a3565b81
@@ -0,0 +1,139 @@
+#include "libcflat.h"
+#include "virtio.h"
+
+#define TESTDEV_MAJOR_VER 1
+#define TESTDEV_MINOR_VER 1
+
+#define VIRTIO_ID_TESTDEV 0xffff
+
+#define 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 virtio_dev *testdev;
+
+static u32 testdev_readl(unsigned offset)
+{
+	if (offset > (CONFIG_SIZE - 4)) {
+		printf("%s: offset 0x%x to big!\n", __func__, offset);
+		exit(EINVAL);
+	}
+
+	return virtio_config_readl(testdev, offset);
+}
+
+static void testdev_writel(unsigned offset, u32 val)
+{
+	if (offset > (CONFIG_SIZE - 4)) {

lib/virtio-testdev.c line 47

Quoted 10 lines
lib/virtio-testdev.c new file +10 -0
+		printf("%s: offset 0x%x to big!\n", __func__, offset);
+		exit(EINVAL);
+	}
+
+	virtio_config_writel(testdev, offset, val);
+}
+
+/*
+ * We have to write all args; nargs, nrets, ... first to
+ * avoid executing token's operation until all args are in

the token's ?

lib/virtio-testdev.c line 48

Quoted 1 line
lib/virtio-testdev.c new file +1 -0
+ * place. Then issue the op, and then read the rets. Reading

rets? return values?

Quoted 112 lines
lib/virtio-testdev.c new file +91 -0
+ * the rets (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 (!testdev)
+		return;
+
+	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);
+
+	/* sanity check */
+	if (testdev_readl(TOKEN_OFFSET) != 0) {
+		printf("virtio-testdev token should always read as zero!\n");
+		halt(EIO);
+	}
+
+	off = __RET_OFFSET(nargs, 0);
+	n = nrets;
+	while (n--) {
+		u32 *r = va_arg(va, unsigned *);
+		*r = testdev_readl(off);
+		off += 4;
+	}
+
+	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;
+
+	testdev = virtio_bind(VIRTIO_ID_TESTDEV);
+	if (testdev == NULL) {
+		printf("Can't find virtio-testdev. "
+		       "Is '-device virtio-testdev' "
+		       "on the qemu command line?\n");
+		halt(ENODEV);
+	}
+
+	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("Incompatible version of virtio-testdev: major = %d, "
+		       "minor = %d\n", major, minor);
+		printf("Update %s.\n", u);
+		exit(ENODEV);
+	}
+
+	if (minor > TESTDEV_MINOR_VER)
+		printf("testdev has new features. "
+		       "An update of kvm-unit-tests may be possible.\n");
+}
lib/virtio-testdev.h new file +9 -0
new file mode 100644
index 0000000000000..c10bbfb591d0b
@@ -0,0 +1,9 @@
+#ifndef _VIRTIO_TESTDEV_H_
+#define _VIRTIO_TESTDEV_H_
+#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
lib/virtio.c new file +0 -0
new file mode 100644
index 0000000000000..c5ad1c85ff9a1

lib/virtio.c line 8

Quoted 8 lines
lib/virtio.c new file +8 -0
@@ -0,0 +1,70 @@
+#include "libcflat.h"
+#include "libio.h"
+#include "iomaps.h"
+#include "heap.h"
+#include "virtio.h"
+
+#define to_virtio_mmio_dev(vdev) \
+	container_of(vdev, struct virtio_mmio_dev, vdev)

argh, macro pain, can you rename the parameter to _vdev or vdev_ptr or something like that?

Quoted 23 lines
lib/virtio.c new file +23 -0
+
+static void vm_get(struct virtio_dev *vdev, unsigned offset,
+		   void *buf, unsigned len)
+{
+	struct virtio_mmio_dev *vmdev = to_virtio_mmio_dev(vdev);
+	void *addr = vmdev->base + VIRTIO_MMIO_CONFIG + offset;
+	read_len(addr, buf, len);
+}
+
+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);
+	void *addr = vmdev->base + VIRTIO_MMIO_CONFIG + offset;
+	write_len(addr, buf, len);
+}
+
+static struct virtio_dev *virtio_mmio_bind(const struct iomap *m, u32 device)
+{
+	struct virtio_mmio_dev *vmdev;
+	void *page;
+	u32 devid, i;
+

lib/virtio.c line 41

Quoted 10 lines
lib/virtio.c new file +10 -0
+	page = alloc_page();
+	vmdev = page;
+	vmdev->vdev.config = page + sizeof(struct virtio_mmio_dev);
+
+	vmdev->vdev.id.device = device;
+	vmdev->vdev.id.vendor = -1;
+	vmdev->vdev.config->get = vm_get;
+	vmdev->vdev.config->set = vm_set;
+
+	device &= 0xffff;

what is this mask again? Is this to correspond to the virtio PCI device ID specs, but then shouldn't we also check the range, seems strange to me to just ignore upper-bits garbage?

lib/virtio.c line 50

Quoted 9 lines
lib/virtio.c new file +9 -0
+
+	for (i = 0; i < m->nr; ++i) {
+		vmdev->base = compat_ptr(m->addrs[i]);
+		devid = readl(vmdev->base + VIRTIO_MMIO_DEVICE_ID);
+		if ((devid & 0xffff) == device)
+			break;
+	}
+
+	if (i >= m->nr) {

this can just be 'if (i == m->nr)' right?

lib/virtio.c line 51

Quoted 1 line
lib/virtio.c new file +1 -0
+		printf("%s: Can't find device 0x%x.\n", __func__, device);

I would ditch the '.'

Quoted 106 lines
lib/virtio.c new file +19 -0
+		free_page(page);
+		return NULL;
+	}
+
+	return &vmdev->vdev;
+}
+
+struct virtio_dev *virtio_bind(u32 device)
+{
+	const struct iomap *m;
+
+	/* currently we only support virtio-mmio */
+	m = iomaps_find_compatible("virtio,mmio");
+	if (!m) {
+		printf("%s: No virtio-mmio transports found!\n", __func__);
+		return NULL;
+	}
+	return virtio_mmio_bind(m, device);
+}
lib/virtio.h new file +74 -0
new file mode 100644
index 0000000000000..c30a8dcd105cd
@@ -0,0 +1,74 @@
+#ifndef _VIRTIO_H_
+#define _VIRTIO_H_
+#include "libcflat.h"
+
+#define VIRTIO_MMIO_DEVICE_ID	0x008
+#define VIRTIO_MMIO_CONFIG	0x100
+
+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);
+};
+
+struct virtio_mmio_dev {
+	struct virtio_dev vdev;
+	void *base;
+};
+
+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);
+}
+
+extern struct virtio_dev *virtio_bind(u32 device);
+
+#endif
Signature · 6 lines
1.8.1.4

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/cucslists/listinfo/kvmarm
Signature · 1 line
Christoffer
#29 lore raw

Re: [PATCH 8/9] Introduce virtio-testdev

Quoted 6 lines · Christoffer Dall

lib/virtio-testdev.c line 47

Quoted 4 lines
lib/virtio-testdev.c new file +4 -0
+
+/*
+ * We have to write all args; nargs, nrets, ... first to
+ * avoid executing token's operation until all args are in

the token's ?

ok

Quoted 4 lines
Quoted 2 lines

+ * place. Then issue the op, and then read the rets. Reading

rets? return values?

ok

Quoted 6 lines

lib/virtio.c line 8

Quoted 3 lines
lib/virtio.c new file +3 -0
+
+#define to_virtio_mmio_dev(vdev) \
+	container_of(vdev, struct virtio_mmio_dev, vdev)

argh, macro pain, can you rename the parameter to _vdev or vdev_ptr or something like that?

ok

Quoted 12 lines
Quoted 12 lines
lib/virtio.c new file +12 -0
+static struct virtio_dev *virtio_mmio_bind(const struct iomap *m, u32 device)
+{
+	struct virtio_mmio_dev *vmdev;
+	void *page;
+	u32 devid, i;
+
+	page = alloc_page();
+	vmdev = page;
+	vmdev->vdev.config = page + sizeof(struct virtio_mmio_dev);
+
+	vmdev->vdev.id.device = device;
+	vmdev->vdev.id.vendor = -1;
Quoted 8 lines

lib/virtio.c line 41

Quoted 4 lines
lib/virtio.c new file +4 -0
+	vmdev->vdev.config->get = vm_get;
+	vmdev->vdev.config->set = vm_set;
+
+	device &= 0xffff;

what is this mask again? Is this to correspond to the virtio PCI device ID specs, but then shouldn't we also check the range, seems strange to me to just ignore upper-bits garbage?

Right, we're ignoring the upper bits to comply with the spec (and to actually find the device if the upper bits weren't zero). Strangely, at least to me, struct virtio_device_id in the kernel has device as a u32, even though the spec has it as a u16. So I allow u32 devices to be put in the device id, but then throw out the upper bits before searching.

Quoted 12 lines

lib/virtio.c line 50

Quoted 10 lines
lib/virtio.c new file +9 -0
+
+	for (i = 0; i < m->nr; ++i) {
+		vmdev->base = compat_ptr(m->addrs[i]);
+		devid = readl(vmdev->base + VIRTIO_MMIO_DEVICE_ID);
+		if ((devid & 0xffff) == device)
+			break;
+	}
+
+	if (i >= m->nr) {

this can just be 'if (i == m->nr)' right?

yeah, I just prefer to choose the broader condition when possible.

Quoted 4 lines

lib/virtio.c line 51

Quoted 2 lines
lib/virtio.c new file +1 -0
+		printf("%s: Can't find device 0x%x.\n", __func__, device);

I would ditch the '.'

ditched

drew

#30 lore raw

Re: [PATCH 8/9] Introduce virtio-testdev

Quoted 47 lines · Andrew Jones
Quoted 6 lines · Christoffer Dall

lib/virtio-testdev.c line 47

Quoted 4 lines
lib/virtio-testdev.c new file +4 -0
+
+/*
+ * We have to write all args; nargs, nrets, ... first to
+ * avoid executing token's operation until all args are in

the token's ?

ok

Quoted 4 lines
Quoted 2 lines

+ * place. Then issue the op, and then read the rets. Reading

rets? return values?

ok

Quoted 6 lines

lib/virtio.c line 8

Quoted 3 lines
lib/virtio.c new file +3 -0
+
+#define to_virtio_mmio_dev(vdev) \
+	container_of(vdev, struct virtio_mmio_dev, vdev)

argh, macro pain, can you rename the parameter to _vdev or vdev_ptr or something like that?

ok

Quoted 12 lines
Quoted 12 lines
lib/virtio.c new file +12 -0
+static struct virtio_dev *virtio_mmio_bind(const struct iomap *m, u32 device)
+{
+	struct virtio_mmio_dev *vmdev;
+	void *page;
+	u32 devid, i;
+
+	page = alloc_page();
+	vmdev = page;
+	vmdev->vdev.config = page + sizeof(struct virtio_mmio_dev);
+
+	vmdev->vdev.id.device = device;
+	vmdev->vdev.id.vendor = -1;
Quoted 8 lines

lib/virtio.c line 41

Quoted 4 lines
lib/virtio.c new file +4 -0
+	vmdev->vdev.config->get = vm_get;
+	vmdev->vdev.config->set = vm_set;
+
+	device &= 0xffff;

what is this mask again? Is this to correspond to the virtio PCI device ID specs, but then shouldn't we also check the range, seems strange to me to just ignore upper-bits garbage?

Quoted 6 lines

Right, we're ignoring the upper bits to comply with the spec (and to actually find the device if the upper bits weren't zero). Strangely, at least to me, struct virtio_device_id in the kernel has device as a u32, even though the spec has it as a u16. So I allow u32 devices to be put in the device id, but then throw out the upper bits before searching.

Can you use a define for this mask instead then?

Quoted 13 lines
Quoted 12 lines

lib/virtio.c line 50

Quoted 10 lines
lib/virtio.c new file +9 -0
+
+	for (i = 0; i < m->nr; ++i) {
+		vmdev->base = compat_ptr(m->addrs[i]);
+		devid = readl(vmdev->base + VIRTIO_MMIO_DEVICE_ID);
+		if ((devid & 0xffff) == device)
+			break;
+	}
+
+	if (i >= m->nr) {

this can just be 'if (i == m->nr)' right?

Quoted 2 lines

yeah, I just prefer to choose the broader condition when possible.

hmmm.

Quoted 7 lines
Quoted 4 lines

lib/virtio.c line 51

Quoted 2 lines
lib/virtio.c new file +1 -0
+		printf("%s: Can't find device 0x%x.\n", __func__, device);

I would ditch the '.'

ditched

Thanks,
-Christoffer

#31 lore raw

Re: [PATCH 8/9] Introduce virtio-testdev

Quoted 48 lines · Christoffer Dall
Quoted 47 lines · Andrew Jones
Quoted 6 lines · Christoffer Dall

lib/virtio-testdev.c line 47

Quoted 4 lines
lib/virtio-testdev.c new file +4 -0
+
+/*
+ * We have to write all args; nargs, nrets, ... first to
+ * avoid executing token's operation until all args are in

the token's ?

ok

Quoted 4 lines
Quoted 2 lines

+ * place. Then issue the op, and then read the rets. Reading

rets? return values?

ok

Quoted 6 lines

lib/virtio.c line 8

Quoted 3 lines
lib/virtio.c new file +3 -0
+
+#define to_virtio_mmio_dev(vdev) \
+	container_of(vdev, struct virtio_mmio_dev, vdev)

argh, macro pain, can you rename the parameter to _vdev or vdev_ptr or something like that?

ok

Quoted 20 lines
Quoted 6 lines
lib/virtio.c new file +6 -0
+static struct virtio_dev *virtio_mmio_bind(const struct iomap *m, u32 device)
+{
+	struct virtio_mmio_dev *vmdev;
+	void *page;
+	u32 devid, i;
+

lib/virtio.c line 41

Quoted 10 lines
lib/virtio.c new file +10 -0
+	page = alloc_page();
+	vmdev = page;
+	vmdev->vdev.config = page + sizeof(struct virtio_mmio_dev);
+
+	vmdev->vdev.id.device = device;
+	vmdev->vdev.id.vendor = -1;
+	vmdev->vdev.config->get = vm_get;
+	vmdev->vdev.config->set = vm_set;
+
+	device &= 0xffff;

what is this mask again? Is this to correspond to the virtio PCI device ID specs, but then shouldn't we also check the range, seems strange to me to just ignore upper-bits garbage?

Quoted 8 lines
Quoted 6 lines

Right, we're ignoring the upper bits to comply with the spec (and to actually find the device if the upper bits weren't zero). Strangely, at least to me, struct virtio_device_id in the kernel has device as a u32, even though the spec has it as a u16. So I allow u32 devices to be put in the device id, but then throw out the upper bits before searching.

Can you use a define for this mask instead then?

yup. done.

Quoted 29 lines
Quoted 14 lines
Quoted 13 lines

lib/virtio.c line 50

Quoted 11 lines
lib/virtio.c new file +9 -0
+
+	for (i = 0; i < m->nr; ++i) {
+		vmdev->base = compat_ptr(m->addrs[i]);
+		devid = readl(vmdev->base + VIRTIO_MMIO_DEVICE_ID);
+		if ((devid & 0xffff) == device)
+			break;
+	}
+
+	if (i >= m->nr) {

this can just be 'if (i == m->nr)' right?

Quoted 2 lines

yeah, I just prefer to choose the broader condition when possible.

hmmm.

Quoted 7 lines
Quoted 4 lines

lib/virtio.c line 51

Quoted 2 lines
lib/virtio.c new file +1 -0
+		printf("%s: Can't find device 0x%x.\n", __func__, device);

I would ditch the '.'

ditched

Thanks,
-Christoffer

#32 lore raw

PATCH v2 9/9 arm: initial drop

In reply to Andrew Jones

This is the initial arm test framework and a first simple test that checks some bootinfo. kvm isn't needed to run this test. This patch also adds a common build environment variable, $QEMU_BIN, which allows makefiles to call on qemu when needed.

Try it out with
yum install gcc-arm-linux-gnu dtc
export QEMU=[qemu with mach-virt and virtio-testdev] ./configure --cross-prefix=arm-linux-gnu- --arch=arm make
./run_tests.sh

---
v2:
- add eabi utility functions needed for some toolchains, this allows us to drop the divmod hacks that were in v1
- switch to kernel coding style
- some refactoring of setup code for heap init
- some refactoring of the simple bootinfo test for clarity and reuse opportunity
- update base addr for the new mach-virt version

---
 arm/boot.c            | 17 +++++++++++
 arm/cstart.S          | 38 +++++++++++++++++++++++
 arm/flat.lds          | 18 +++++++++++
 arm/run               | 19 ++++++++++++
 arm/unittests.cfg     | 11 +++++++
 config/config-arm.mak | 73 +++++++++++++++++++++++++++++++++++++++++++
 configure             | 10 ++++--
 lib/arm/eabi_compat.c | 20 ++++++++++++
 lib/arm/io.c          | 31 +++++++++++++++++++
 lib/arm/io.h          | 24 +++++++++++++++
 lib/arm/setup.c       | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/arm/sysinfo.h     | 19 ++++++++++++
 lib/libcflat.h        |  2 ++
 lib/libio.h           |  4 +++
 lib/test_util.c       | 34 +++++++++++++++++++++
 lib/test_util.h       | 13 ++++++++
 16 files changed, 416 insertions(+), 2 deletions(-)
 create mode 100644 arm/boot.c
 create mode 100644 arm/cstart.S
 create mode 100644 arm/flat.lds
 create mode 100755 arm/run
 create mode 100644 arm/unittests.cfg
 create mode 100644 config/config-arm.mak
 create mode 100644 lib/arm/eabi_compat.c
 create mode 100644 lib/arm/io.c
 create mode 100644 lib/arm/io.h
 create mode 100644 lib/arm/setup.c
 create mode 100644 lib/arm/sysinfo.h
 create mode 100644 lib/test_util.c
 create mode 100644 lib/test_util.h
arm/boot.c new file +17 -0
new file mode 100644
index 0000000000000..dc42dfc232366
@@ -0,0 +1,17 @@
+#include "libcflat.h"
+#include "test_util.h"
+#include "arm/sysinfo.h"
+
+int main(int argc, char **argv)
+{
+	int ret = FAIL;
+
+	if (argc >= 1) {
+		--argc;
+		if (!strcmp(argv[0], "mem") && enough_args(argc, 1)) {
+			if (check_u32(mem32.size/1024/1024, 10, argv[1]))
+				ret = PASS;
+		}
+	}
+	return ret;
+}
arm/cstart.S new file +38 -0
new file mode 100644
index 0000000000000..05d4bb5becaa0
@@ -0,0 +1,38 @@
+
+#define CR_B	(1 << 7)	/* Big endian */
+
+.arm
+
+.section .init
+
+.globl start
+start:
+	/* bootloader params are in r0-r2 */
+	ldr	sp, =stacktop
+
+	mrc	p15, 0, r8, c1, c0, 0	@r8 = sctrl
+	ands	r3, r8, #CR_B		@set BE, if necessary
+	ldrne	r3, =cpu_is_be
+	movne	r4, #1
+	strne	r4, [r3]
+	bl	setup			@complete setup
+
+	/* start 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
+
+.data
+
+.globl cpu_is_be
+cpu_is_be:	.word 0
arm/flat.lds new file +18 -0
new file mode 100644
index 0000000000000..3e5d72e24989b
@@ -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 +19 -0
new file mode 100755
index 0000000000000..64446e8907564
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+qemu="${QEMU:-qemu-system-arm}"
+testdev='virtio-testdev'
+
+if ! $qemu -device '?' 2>&1 | grep $testdev > /dev/null; then
+    echo \"$qemu\" has no support for the virtio test device. Exiting.
+    exit 2
+fi
+
+command="$qemu -device $testdev -display none -serial stdio "
+command+="-M virt -cpu cortex-a15 "
+#command+="-enable-kvm "
+command+="-kernel"
+echo $command "$@"
+$command "$@"
+ret=$?
+echo Return value from qemu: $ret
+exit $ret
arm/unittests.cfg new file +11 -0
new file mode 100644
index 0000000000000..c328657b7944a
@@ -0,0 +1,11 @@
+# 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 the test case works only on one of them
+# groups = group1 group2 # Used to identify test cases with run_tests -g ...
+
+[boot_info]
+file = boot.flat
+extra_params = -m 256 -append 'mem 256'
config/config-arm.mak new file +73 -0

73 lines not on this page · raw message

configure +8 -2
index 6cfc64943f6e6..296c70182ea1d 100755
@@ -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,9 @@ while [[ "$1" = -* ]]; do
 	    ;;
     esac
 done
+[ -z "$processor" ] && processor="$arch"
+qemu="${QEMU:-qemu-system-$arch}"
+
 if [ -z "$testdir" -a \( "$arch" = "i386" -o "$arch" = "x86_64" \) ]; then
     testdir=x86
 elif [ -z "$testdir" ]; then
@@ -80,6 +83,7 @@ if [ -f $testdir/run ]; then
 fi
 
 # check for dependent 32 bit libraries
+if [ "$arch" = "i386" -o "$arch" = "x86_64" ]; then
 cat << EOF > lib_test.c
 #include <stdc++.h>
 #include <boost_thread-mt.h>
@@ -94,6 +98,7 @@ if [ $exit -eq 0 ]; then
     api=true
 fi
 rm -f lib_test.c
+fi
 
 cat <<EOF > config.mak
 PREFIX=$prefix
@@ -106,4 +111,5 @@ OBJCOPY=$cross_prefix$objcopy
 AR=$cross_prefix$ar
 API=$api
 TEST_DIR=$testdir
+QEMU_BIN=$qemu
 EOF
lib/arm/eabi_compat.c new file +20 -0
new file mode 100644
index 0000000000000..76e04f5543ee1
@@ -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");
+	exit(ERANGE);
+	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 +31 -0
new file mode 100644
index 0000000000000..32c896c29450a
@@ -0,0 +1,31 @@
+#include "libcflat.h"
+#include "libio.h"
+#include "iomaps.h"
+#include "virtio-testdev.h"
+
+static volatile u8 *uart0_base;
+
+void puts(const char *s)
+{
+	while (*s)
+		*uart0_base = *s++;
+}
+
+void exit(int code)
+{
+	virtio_testdev_exit(code);
+	halt(code);
+}
+
+void io_init_early(void)
+{
+	const struct iomap *m = iomaps_find_compatible("arm,pl011");
+	if (!m)
+		halt(ENXIO);
+	uart0_base = (u8 *)compat_ptr(m->addrs[0]);
+}
+
+void io_init(void)
+{
+	virtio_testdev_init();
+}
lib/arm/io.h new file +24 -0
new file mode 100644
index 0000000000000..f058f7e54d4a7
@@ -0,0 +1,24 @@
+#ifndef _ARM_IO_H_
+#define _ARM_IO_H_
+
+#define cpu_is_be cpu_is_be
+extern bool cpu_is_be;
+
+#define __bswap16 bswap16
+static inline u16 bswap16(u16 val)
+{
+	u16 ret;
+	asm volatile("rev16 %0, %1" : "=r" (ret) :  "r" (val));
+	return ret;
+}
+
+#define __bswap32 bswap32
+static inline u32 bswap32(u32 val)
+{
+	u32 ret;
+	asm volatile("rev %0, %1" : "=r" (ret) :  "r" (val));
+	return ret;
+}
+
+#include "libio.h"
+#endif
lib/arm/setup.c new file +85 -0

85 lines not on this page · raw message

lib/arm/sysinfo.h new file +19 -0
new file mode 100644
index 0000000000000..f3b076e1a34c4
@@ -0,0 +1,19 @@
+#ifndef _ARM_SYSINFO_H_
+#define _ARM_SYSINFO_H_
+#include "libcflat.h"
+
+struct tag_core {
+	u32 flags;		/* bit 0 = read-only */
+	u32 pagesize;
+	u32 rootdev;
+};
+
+struct tag_mem32 {
+	u32   size;
+	u32   start;	/* physical start address */
+};
+
+extern u32 mach_type_id;
+extern struct tag_core core;
+extern struct tag_mem32 mem32;
+#endif
lib/libcflat.h +2 -0
index 197b703e53b46..8c6cf1f0735ba 100644
@@ -45,6 +45,7 @@ extern char *strcat(char *dest, const char *src);
 extern int strcmp(const char *a, const char *b);
 
 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 void puts(const char *s);
@@ -60,6 +61,7 @@ extern long atol(const char *ptr);
 		const typeof( ((type *)0)->member ) *__mptr = (ptr);	\
 		(type *)( (char *)__mptr - offsetof(type,member) );})
 
+#define __unused __attribute__((__unused__))
 #define NULL ((void *)0UL)
 #include "errno.h"
 #endif
lib/libio.h +4 -0
index 210b8d78af43f..5ac1056e7002f 100644
@@ -6,6 +6,10 @@
  */
 #include "libcflat.h"
 
+#ifdef __arm__
+#include "arm/io.h"
+#endif
+
 typedef u32 compat_ptr_t;
 
 static inline void *compat_ptr(compat_ptr_t ptr)
lib/test_util.c new file +34 -0
new file mode 100644
index 0000000000000..3de1f74f83455
@@ -0,0 +1,34 @@
+#include "libcflat.h"
+#include "test_util.h"
+
+bool enough_args(int nargs, int needed)
+{
+	if (nargs >= needed)
+		return true;
+
+	fail("Not enough arguments.\n");
+	return false;
+}
+
+/*
+ * Typically one would compare val == strtoul(expected, endp, base),
+ * but we don't have, nor at this point really need, strtoul, so we
+ * convert val to a string instead. base can only be 10 or 16.
+ */
+bool check_u32(u32 val, int base, char *expected)
+{
+	char *fmt = base == 10 ? "%d" : "%x";
+	char val_str[16];
+
+	snprintf(val_str, 16, fmt, val);
+
+	if (base == 16)
+		while (*expected == '0' || *expected == 'x')
+			++expected;
+
+	if (strcmp(val_str, expected) == 0)
+		return true;
+
+	fail("expected %s, but have %s\n", expected, val_str);
+	return false;
+}
lib/test_util.h new file +13 -0
new file mode 100644
index 0000000000000..0e3e6c4a80d51
@@ -0,0 +1,13 @@
+#ifndef _TEST_UTIL_H_
+#define _TEST_UTIL_H_
+#include "libcflat.h"
+
+#define PASS 0
+#define FAIL 1
+
+#define pass(fmt...) printf("PASS: " fmt)
+#define fail(fmt...) printf("FAIL: " fmt)
+
+bool enough_args(int nargs, int needed);
+bool check_u32(u32 val, int base, char *expected);
+#endif
Signature · 1 line
1.8.1.4
#33 lore raw

Re: [PATCH 9/9] arm: initial drop

Quoted 11 lines · Andrew Jones

This is the initial arm test framework and a first simple test that checks some bootinfo. kvm isn't needed to run this test. This patch also adds a common build environment variable, $QEMU_BIN, which allows makefiles to call on qemu when needed.

Try it out with
yum install gcc-arm-linux-gnu dtc
export QEMU=[qemu with mach-virt and virtio-testdev] ./configure --cross-prefix=arm-linux-gnu- --arch=arm make
./run_tests.sh

You refer to QEMU_BIN but your example uses QEMU= ?

It's getting to be a pretty heavy chunk this patch, it would have been slightly easier to review if it was broken up into multiple patches, but ok.

Quoted 57 lines

---
v2:
- add eabi utility functions needed for some toolchains, this allows us to drop the divmod hacks that were in v1
- switch to kernel coding style
- some refactoring of setup code for heap init
- some refactoring of the simple bootinfo test for clarity and reuse opportunity
- update base addr for the new mach-virt version

---
 arm/boot.c            | 17 +++++++++++
 arm/cstart.S          | 38 +++++++++++++++++++++++
 arm/flat.lds          | 18 +++++++++++
 arm/run               | 19 ++++++++++++
 arm/unittests.cfg     | 11 +++++++
 config/config-arm.mak | 73 +++++++++++++++++++++++++++++++++++++++++++
 configure             | 10 ++++--
 lib/arm/eabi_compat.c | 20 ++++++++++++
 lib/arm/io.c          | 31 +++++++++++++++++++
 lib/arm/io.h          | 24 +++++++++++++++
 lib/arm/setup.c       | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/arm/sysinfo.h     | 19 ++++++++++++
 lib/libcflat.h        |  2 ++
 lib/libio.h           |  4 +++
 lib/test_util.c       | 34 +++++++++++++++++++++
 lib/test_util.h       | 13 ++++++++
 16 files changed, 416 insertions(+), 2 deletions(-)
 create mode 100644 arm/boot.c
 create mode 100644 arm/cstart.S
 create mode 100644 arm/flat.lds
 create mode 100755 arm/run
 create mode 100644 arm/unittests.cfg
 create mode 100644 config/config-arm.mak
 create mode 100644 lib/arm/eabi_compat.c
 create mode 100644 lib/arm/io.c
 create mode 100644 lib/arm/io.h
 create mode 100644 lib/arm/setup.c
 create mode 100644 lib/arm/sysinfo.h
 create mode 100644 lib/test_util.c
 create mode 100644 lib/test_util.h
arm/boot.c new file +7 -0
new file mode 100644
index 0000000000000..dc42dfc232366
@@ -0,0 +1,17 @@
+#include "libcflat.h"
+#include "test_util.h"
+#include "arm/sysinfo.h"
+
+int main(int argc, char **argv)
+{
+	int ret = FAIL;

arm/boot.c line 17

Quoted 10 lines
arm/boot.c new file +10 -0
+
+	if (argc >= 1) {
+		--argc;
+		if (!strcmp(argv[0], "mem") && enough_args(argc, 1)) {
+			if (check_u32(mem32.size/1024/1024, 10, argv[1]))
+				ret = PASS;
+		}
+	}
+	return ret;
+}

consider renaming this file to boottest.c to avoid the confusion that this file is needed to boot anything that runs tests...

Quoted 6 lines
arm/cstart.S new file +0 -0
new file mode 100644
index 0000000000000..05d4bb5becaa0

arm/cstart.S line 10

Quoted 10 lines
arm/cstart.S new file +10 -0
@@ -0,0 +1,38 @@
+
+#define CR_B	(1 << 7)	/* Big endian */
+
+.arm
+
+.section .init
+
+.globl start
+start:
+	/* bootloader params are in r0-r2 */

which bootlaoder params are they? What boot protocol is used, what are you expecting to be in the various registers?

I assume this tool expects r0-r2 to follow the definitions in Documentation/arm/Booting in the kernel?

arm/cstart.S line 13

Quoted 3 lines
arm/cstart.S new file +3 -0
+	ldr	sp, =stacktop
+
+	mrc	p15, 0, r8, c1, c0, 0	@r8 = sctrl

that's sctlr, not sctrl.

arm/cstart.S line 16

Quoted 3 lines
arm/cstart.S new file +3 -0
+	ands	r3, r8, #CR_B		@set BE, if necessary
+	ldrne	r3, =cpu_is_be
+	movne	r4, #1

This is deprecated for ARMv7 according to the ARM ARM. What is the intention here? Does qemu support running this test tool with the system configured for big-endian? If so, I think this is a build option for this binary or you need to come up with some other architecture-compliant method of detecting the endian-state.

Quoted 77 lines
arm/cstart.S new file +22 -0
+	strne	r4, [r3]
+	bl	setup			@complete setup
+
+	/* start 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
+
+.data
+
+.globl cpu_is_be
+cpu_is_be:	.word 0
arm/flat.lds new file +18 -0
new file mode 100644
index 0000000000000..3e5d72e24989b
@@ -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 +19 -0
new file mode 100755
index 0000000000000..64446e8907564
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+qemu="${QEMU:-qemu-system-arm}"
+testdev='virtio-testdev'
+
+if ! $qemu -device '?' 2>&1 | grep $testdev > /dev/null; then
+    echo \"$qemu\" has no support for the virtio test device. Exiting.
+    exit 2
+fi
+
+command="$qemu -device $testdev -display none -serial stdio "
+command+="-M virt -cpu cortex-a15 "
+#command+="-enable-kvm "
+command+="-kernel"
+echo $command "$@"
+$command "$@"
+ret=$?
+echo Return value from qemu: $ret
+exit $ret
arm/unittests.cfg new file +0 -0
new file mode 100644
index 0000000000000..c328657b7944a

arm/unittests.cfg line 5

Quoted 5 lines
arm/unittests.cfg new file +5 -0
@@ -0,0 +1,11 @@
+# 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

used to QEMU I presume?

arm/unittests.cfg line 6

Quoted 1 line
arm/unittests.cfg new file +1 -0
+# arch = arm/arm64 # Only if the test case works only on one of them

Do we have any verified support for arm64 yet?

Quoted 34 lines
arm/unittests.cfg new file +5 -0
+# groups = group1 group2 # Used to identify test cases with run_tests -g ...
+
+[boot_info]
+file = boot.flat
+extra_params = -m 256 -append 'mem 256'
config/config-arm.mak new file +23 -0
new file mode 100644
index 0000000000000..d0814186b279c
@@ -0,0 +1,73 @@
+mach = mach-virt
+iodevs = pl011 virtio_mmio
+phys_base = 0x40000000
+
+cstart.o = $(TEST_DIR)/cstart.o
+bits = 32
+ldarch = elf32-littlearm
+kernel_offset = 0x10000
+CFLAGS += -D__arm__
+
+all: test_cases
+
+cflatobjs += \
+	lib/$(TEST_DIR)/iomaps.gen.o \
+	lib/heap.o \
+	lib/iomaps.o \
+	lib/libio.o \
+	lib/virtio.o \
+	lib/virtio-testdev.o \
+	lib/test_util.o \
+	lib/arm/io.o \
+	lib/arm/setup.o
+

config/config-arm.mak line 33

Quoted 10 lines
config/config-arm.mak new file +10 -0
+libeabi := lib/arm/libeabi.a
+eabiobjs += \
+	lib/arm/eabi_compat.o
+
+$(libcflat) $(libeabi): LDFLAGS += -nostdlib
+$(libcflat) $(libeabi): CFLAGS += -ffreestanding -I lib
+
+CFLAGS += -Wextra
+CFLAGS += -marm
+#CFLAGS += -mcpu=$(PROCESSOR)

This looks weird, should it not be $(PROCESSOR) and default to cortex-a15 if it's not set?

(also note that you can now use -cpu host with mach-virt which may make your life easier).

config/config-arm.mak line 35

Quoted 2 lines
config/config-arm.mak new file +2 -0
+CFLAGS += -mcpu=cortex-a15
+CFLAGS += -O2

Why do we choose this particular optimzation-level in the arch-specific config?

config/config-arm.mak line 44

Quoted 9 lines
config/config-arm.mak new file +9 -0
+
+libgcc := $(shell $(CC) -m$(ARCH) --print-libgcc-file-name)
+start_addr := $(shell printf "%x\n" $$(( $(phys_base) + $(kernel_offset) )))
+
+FLATLIBS = $(libcflat) $(libgcc) $(libeabi)
+%.elf: %.o $(FLATLIBS) arm/flat.lds
+	$(CC) $(CFLAGS) -nostdlib -o $@ \
+		-Wl,-T,arm/flat.lds,--build-id=none,-Ttext=$(start_addr) \
+		$(filter %.o, $^) $(FLATLIBS)

I have no idea what the above rules are doing :-(

config/config-arm.mak line 56

Quoted 12 lines
config/config-arm.mak new file +12 -0
+
+$(libeabi): $(eabiobjs)
+	$(AR) rcs $@ $^
+
+%.flat: %.elf
+	$(OBJCOPY) -O binary $^ $@
+
+tests-common = $(TEST_DIR)/boot.flat
+
+tests_and_config = $(TEST_DIR)/*.flat $(TEST_DIR)/unittests.cfg
+
+test_cases: $(tests-common) $(tests)

what's the distinction between tests-common and tests? arm/arm64 vs. one or the other, or?

Quoted 119 lines
config/config-arm.mak new file +17 -0
+
+$(TEST_DIR)/%.o: CFLAGS += -std=gnu99 -ffreestanding -I lib
+
+$(TEST_DIR)/boot.elf: $(cstart.o) $(TEST_DIR)/boot.o
+
+lib/$(TEST_DIR)/iomaps.gen.c: lib/$(TEST_DIR)/$(mach).dts
+	scripts/gen-devtree-iomaps.pl $^ $(iodevs) > $@
+
+lib/$(TEST_DIR)/mach-virt.dts: dtb = $(subst .dts,.dtb,$@)
+lib/$(TEST_DIR)/mach-virt.dts:
+	$(QEMU_BIN) -kernel /dev/null -M virt -machine dumpdtb=$(dtb)
+	fdtdump $(dtb) > $@
+
+arch_clean:
+	$(RM) $(TEST_DIR)/*.o $(TEST_DIR)/*.flat $(TEST_DIR)/*.elf \
+	$(libeabi) $(eabiobjs) $(TEST_DIR)/.*.d lib/arm/.*.d \
+	lib/$(TEST_DIR)/iomaps.gen.c lib/$(TEST_DIR)/mach-virt.*
configure +8 -2
index 6cfc64943f6e6..296c70182ea1d 100755
@@ -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,9 @@ while [[ "$1" = -* ]]; do
 	    ;;
     esac
 done
+[ -z "$processor" ] && processor="$arch"
+qemu="${QEMU:-qemu-system-$arch}"
+
 if [ -z "$testdir" -a \( "$arch" = "i386" -o "$arch" = "x86_64" \) ]; then
     testdir=x86
 elif [ -z "$testdir" ]; then
@@ -80,6 +83,7 @@ if [ -f $testdir/run ]; then
 fi
 
 # check for dependent 32 bit libraries
+if [ "$arch" = "i386" -o "$arch" = "x86_64" ]; then
 cat << EOF > lib_test.c
 #include <stdc++.h>
 #include <boost_thread-mt.h>
@@ -94,6 +98,7 @@ if [ $exit -eq 0 ]; then
     api=true
 fi
 rm -f lib_test.c
+fi
 
 cat <<EOF > config.mak
 PREFIX=$prefix
@@ -106,4 +111,5 @@ OBJCOPY=$cross_prefix$objcopy
 AR=$cross_prefix$ar
 API=$api
 TEST_DIR=$testdir
+QEMU_BIN=$qemu
 EOF
lib/arm/eabi_compat.c new file +20 -0
new file mode 100644
index 0000000000000..76e04f5543ee1
@@ -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");
+	exit(ERANGE);
+	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 +16 -0
new file mode 100644
index 0000000000000..32c896c29450a
@@ -0,0 +1,31 @@
+#include "libcflat.h"
+#include "libio.h"
+#include "iomaps.h"
+#include "virtio-testdev.h"
+
+static volatile u8 *uart0_base;
+
+void puts(const char *s)
+{
+	while (*s)
+		*uart0_base = *s++;
+}
+
+void exit(int code)
+{
+	virtio_testdev_exit(code);

lib/arm/io.c line 26

Quoted 10 lines
lib/arm/io.c new file +10 -0
+	halt(code);
+}
+
+void io_init_early(void)
+{
+	const struct iomap *m = iomaps_find_compatible("arm,pl011");
+	if (!m)
+		halt(ENXIO);
+	uart0_base = (u8 *)compat_ptr(m->addrs[0]);
+}

is io_init_early going to do something else later on or is it just early_console_init? If the latter, then name the function as such.

Quoted 11 lines
lib/arm/io.c new file +5 -0
+
+void io_init(void)
+{
+	virtio_testdev_init();
+}
lib/arm/io.h new file +0 -0
new file mode 100644
index 0000000000000..f058f7e54d4a7

lib/arm/io.h line 4

Quoted 4 lines
lib/arm/io.h new file +4 -0
@@ -0,0 +1,24 @@
+#ifndef _ARM_IO_H_
+#define _ARM_IO_H_
+
+#define cpu_is_be cpu_is_be

huh?

Quoted 57 lines
lib/arm/io.h new file +20 -0
+extern bool cpu_is_be;
+
+#define __bswap16 bswap16
+static inline u16 bswap16(u16 val)
+{
+	u16 ret;
+	asm volatile("rev16 %0, %1" : "=r" (ret) :  "r" (val));
+	return ret;
+}
+
+#define __bswap32 bswap32
+static inline u32 bswap32(u32 val)
+{
+	u32 ret;
+	asm volatile("rev %0, %1" : "=r" (ret) :  "r" (val));
+	return ret;
+}
+
+#include "libio.h"
+#endif
lib/arm/setup.c new file +31 -0
new file mode 100644
index 0000000000000..32fa84bd0bb5b
@@ -0,0 +1,85 @@
+#include "libcflat.h"
+#include "libio.h"
+#include "heap.h"
+#include "arm/sysinfo.h"
+
+#define FDT_SIG			0xd00dfeed
+
+#define KERNEL_OFFSET		0x00010000
+#define ATAG_OFFSET		0x00000100
+
+#define ATAG_CORE		0x54410001
+#define ATAG_MEM		0x54410002
+#define ATAG_CMDLINE		0x54410009
+
+extern void start(void);
+extern unsigned long stacktop;
+extern char *__args;
+
+extern void io_init_early(void);
+extern void io_init(void);
+extern void __setup_args(void);
+
+u32 mach_type_id;
+struct tag_core core;
+struct tag_mem32 mem32;
+
+static void read_atags(u32 id, u32 *info)
+{
+	u32 *p = info;
+
+	if (!p) {

lib/arm/setup.c line 41

Quoted 10 lines
lib/arm/setup.c new file +10 -0
+		printf("Can't find bootinfo. mach-type = %x\n", id);
+		exit(ENOEXEC);
+	}
+
+	/*
+	 * p[0]	count of words for the tag
+	 * p[1]	tag id
+	 * p[2..]	tag data
+	 */
+	for (; p[0] != 0; p += p[0])

braces, please.

Quoted 18 lines
lib/arm/setup.c new file +18 -0
+		switch (p[1]) {
+		case ATAG_CORE:
+			core.flags = p[2];
+			core.pagesize = p[3];
+			core.rootdev = p[4];
+			break;
+		case ATAG_MEM:
+			mem32.size = p[2];
+			mem32.start = p[3];
+			break;
+		case ATAG_CMDLINE:
+			__args = (char *)&p[2];
+			break;
+		}
+}
+
+static void read_bootinfo(u32 id, u32 *info)
+{

lib/arm/setup.c line 69

Quoted 10 lines
lib/arm/setup.c new file +10 -0
+	u32 *atags = NULL;
+
+	mach_type_id = id;
+
+	if (info[0] == be32_to_cpu(FDT_SIG)) {
+		/*
+		 * fdt reading is not [yet?] implemented. So calculate
+		 * the ATAGS addr to read that instead.
+		 */
+		atags = (u32 *)(start - KERNEL_OFFSET + ATAG_OFFSET);

are the atags always supposed to be loaded even for device-tree booting? I could not find this in any ARM booting documents, and QEMU does seem to do this, but only for auto-generated device trees, which could just be a bug in do_cpu_reset?

Quoted 138 lines
lib/arm/setup.c new file +16 -0
+	} else if (info[1] == ATAG_CORE)
+		atags = info;
+
+	read_atags(id, atags);
+}
+
+void setup(u32 arg __unused, u32 id, u32 *info)
+{
+	io_init_early();
+	read_bootinfo(id, info);
+	__setup_args();
+	heap_init(&stacktop,
+		  mem32.size - (ptr_to_compat(&stacktop) - mem32.start),
+		  core.pagesize);
+	io_init();
+}
lib/arm/sysinfo.h new file +19 -0
new file mode 100644
index 0000000000000..f3b076e1a34c4
@@ -0,0 +1,19 @@
+#ifndef _ARM_SYSINFO_H_
+#define _ARM_SYSINFO_H_
+#include "libcflat.h"
+
+struct tag_core {
+	u32 flags;		/* bit 0 = read-only */
+	u32 pagesize;
+	u32 rootdev;
+};
+
+struct tag_mem32 {
+	u32   size;
+	u32   start;	/* physical start address */
+};
+
+extern u32 mach_type_id;
+extern struct tag_core core;
+extern struct tag_mem32 mem32;
+#endif
lib/libcflat.h +2 -0
index 197b703e53b46..8c6cf1f0735ba 100644
@@ -45,6 +45,7 @@ extern char *strcat(char *dest, const char *src);
 extern int strcmp(const char *a, const char *b);
 
 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 void puts(const char *s);
@@ -60,6 +61,7 @@ extern long atol(const char *ptr);
 		const typeof( ((type *)0)->member ) *__mptr = (ptr);	\
 		(type *)( (char *)__mptr - offsetof(type,member) );})
 
+#define __unused __attribute__((__unused__))
 #define NULL ((void *)0UL)
 #include "errno.h"
 #endif
lib/libio.h +4 -0
index 210b8d78af43f..5ac1056e7002f 100644
@@ -6,6 +6,10 @@
  */
 #include "libcflat.h"
 
+#ifdef __arm__
+#include "arm/io.h"
+#endif
+
 typedef u32 compat_ptr_t;
 
 static inline void *compat_ptr(compat_ptr_t ptr)
lib/test_util.c new file +34 -0
new file mode 100644
index 0000000000000..3de1f74f83455
@@ -0,0 +1,34 @@
+#include "libcflat.h"
+#include "test_util.h"
+
+bool enough_args(int nargs, int needed)
+{
+	if (nargs >= needed)
+		return true;
+
+	fail("Not enough arguments.\n");
+	return false;
+}
+
+/*
+ * Typically one would compare val == strtoul(expected, endp, base),
+ * but we don't have, nor at this point really need, strtoul, so we
+ * convert val to a string instead. base can only be 10 or 16.
+ */
+bool check_u32(u32 val, int base, char *expected)
+{
+	char *fmt = base == 10 ? "%d" : "%x";
+	char val_str[16];
+
+	snprintf(val_str, 16, fmt, val);
+
+	if (base == 16)
+		while (*expected == '0' || *expected == 'x')
+			++expected;
+
+	if (strcmp(val_str, expected) == 0)
+		return true;
+
+	fail("expected %s, but have %s\n", expected, val_str);
+	return false;
+}
lib/test_util.h new file +13 -0
new file mode 100644
index 0000000000000..0e3e6c4a80d51
@@ -0,0 +1,13 @@
+#ifndef _TEST_UTIL_H_
+#define _TEST_UTIL_H_
+#include "libcflat.h"
+
+#define PASS 0
+#define FAIL 1
+
+#define pass(fmt...) printf("PASS: " fmt)
+#define fail(fmt...) printf("FAIL: " fmt)
+
+bool enough_args(int nargs, int needed);
+bool check_u32(u32 val, int base, char *expected);
+#endif
Signature · 1 line
1.8.1.4

I was expecting to see a __raw_... IO accessor definitions for ARM here, specifically so we avoid the register-writeback versions that are not supported on ARM.

See arch/arm/include/asm/io.h in the kernel.

Signature · 1 line
Christoffer
#34 lore raw

Re: [PATCH 9/9] arm: initial drop

Quoted 4 lines · Christoffer Dall

are the atags always supposed to be loaded even for device-tree booting? I could not find this in any ARM booting documents, and QEMU does seem to do this, but only for auto-generated device trees, which could just be a bug in do_cpu_reset?

Heh, yes, that's just a bug in QEMU -- I didn't notice when I added the support for autogenerated device trees that we were using "is there a dtb filename?" to trigger whether to write ATAGS info in reset. I'll fix that at some point soon...

thanks
-- PMM

#35 lore raw

Re: [PATCH 9/9] arm: initial drop

In reply to Christoffer Dall
Quoted 6 lines · Christoffer Dall
Quoted 5 lines · Andrew Jones

This is the initial arm test framework and a first simple test that checks some bootinfo. kvm isn't needed to run this test. This patch also adds a common build environment variable, $QEMU_BIN, which allows makefiles to call on qemu when needed.

Quoted 8 lines
Quoted 6 lines

Try it out with
yum install gcc-arm-linux-gnu dtc
export QEMU=[qemu with mach-virt and virtio-testdev] ./configure --cross-prefix=arm-linux-gnu- --arch=arm make
./run_tests.sh

You refer to QEMU_BIN but your example uses QEMU= ?

Two different vars. QEMU_BIN is an internal makefile var set in config.mak. QEMU is an ENV. Hmm, I guess I could reuse the QEMU name in the makefiles too...

<snip>

Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	return ret;
+}

consider renaming this file to boottest.c to avoid the confusion that this file is needed to boot anything that runs tests...

I think I'll rename it to selftest.c, as it's really just a test framework selftest.

Quoted 21 lines
Quoted 7 lines
arm/cstart.S new file +0 -0
new file mode 100644
index 0000000000000..05d4bb5becaa0

arm/cstart.S line 10

Quoted 10 lines
arm/cstart.S new file +10 -0
@@ -0,0 +1,38 @@
+
+#define CR_B	(1 << 7)	/* Big endian */
+
+.arm
+
+.section .init
+
+.globl start
+start:
+	/* bootloader params are in r0-r2 */

which bootlaoder params are they? What boot protocol is used, what are you expecting to be in the various registers?

Quoted 2 lines

I assume this tool expects r0-r2 to follow the definitions in Documentation/arm/Booting in the kernel?

Correct. I guess I can add a 'see Documentation/arm/Booting comment'

Quoted 6 lines

arm/cstart.S line 13

Quoted 4 lines
arm/cstart.S new file +3 -0
+	ldr	sp, =stacktop
+
+	mrc	p15, 0, r8, c1, c0, 0	@r8 = sctrl

that's sctlr, not sctrl.

fixed

Quoted 10 lines

arm/cstart.S line 16

Quoted 4 lines
arm/cstart.S new file +3 -0
+	ands	r3, r8, #CR_B		@set BE, if necessary
+	ldrne	r3, =cpu_is_be
+	movne	r4, #1

This is deprecated for ARMv7 according to the ARM ARM. What is the intention here? Does qemu support running this test tool with the system configured for big-endian? If so, I think this is a build option for this binary or you need to come up with some other architecture-compliant method of detecting the endian-state.

Yes, qemu allows big-endian. I haven't tested it though, but suspect someday we will want big-endian guests tested as well. I'll fix the detection.

Quoted 9 lines

arm/cstart.S line 5

Quoted 7 lines
arm/cstart.S new file +6 -0
+++ b/arm/unittests.cfg
@@ -0,0 +1,11 @@
+# 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

used to QEMU I presume?

correct

Quoted 4 lines

arm/cstart.S line 6

Quoted 2 lines
arm/cstart.S new file +1 -0
+# arch = arm/arm64 # Only if the test case works only on one of them

Do we have any verified support for arm64 yet?

not yet, high on my TODO list though.

Quoted 7 lines

arm/cstart.S line 10

Quoted 4 lines
arm/cstart.S new file +4 -0
+
+CFLAGS += -Wextra
+CFLAGS += -marm
+#CFLAGS += -mcpu=$(PROCESSOR)

This looks weird, should it not be $(PROCESSOR) and default to cortex-a15 if it's not set?

Agreed.

Quoted 3 lines

(also note that you can now use -cpu host with mach-virt which may make your life easier).

I'll think about how we might/must use '-cpu host'.

Quoted 6 lines

arm/cstart.S

Quoted 3 lines
arm/cstart.S new file +2 -0
+CFLAGS += -mcpu=cortex-a15
+CFLAGS += -O2

Why do we choose this particular optimzation-level in the arch-specific config?

My cross-compiler was generating broken code with anything less. I haven't checked later compilers yet to see if it's fixed or not.

Quoted 12 lines

arm/cstart.S

Quoted 10 lines
arm/cstart.S new file +9 -0
+
+libgcc := $(shell $(CC) -m$(ARCH) --print-libgcc-file-name)
+start_addr := $(shell printf "%x\n" $$(( $(phys_base) + $(kernel_offset) )))
+
+FLATLIBS = $(libcflat) $(libgcc) $(libeabi)
+%.elf: %.o $(FLATLIBS) arm/flat.lds
+	$(CC) $(CFLAGS) -nostdlib -o $@ \
+		-Wl,-T,arm/flat.lds,--build-id=none,-Ttext=$(start_addr) \
+		$(filter %.o, $^) $(FLATLIBS)

I have no idea what the above rules are doing :-(

Calls the linker on the *.o files with the supplied linker script, and a .text addr of $(start_addr). Also gets rid of the build-id section, which messes up the start address. And supplies libs to link with, which need to be in a particular order (defined in FLATLIBS).

Quoted 16 lines

arm/cstart.S

Quoted 13 lines
arm/cstart.S new file +12 -0
+
+$(libeabi): $(eabiobjs)
+	$(AR) rcs $@ $^
+
+%.flat: %.elf
+	$(OBJCOPY) -O binary $^ $@
+
+tests-common = $(TEST_DIR)/boot.flat
+
+tests_and_config = $(TEST_DIR)/*.flat $(TEST_DIR)/unittests.cfg
+
+test_cases: $(tests-common) $(tests)

what's the distinction between tests-common and tests? arm/arm64 vs. one or the other, or?

Correct. Eventually we'll have tests-common, which will be the majority and apply to both, and also tests which are specific to one.

Quoted 10 lines

arm/cstart.S

Quoted 7 lines
arm/cstart.S new file +7 -0
+void io_init_early(void)
+{
+	const struct iomap *m = iomaps_find_compatible("arm,pl011");
+	if (!m)
+		halt(ENXIO);
+	uart0_base = (u8 *)compat_ptr(m->addrs[0]);
+}

is io_init_early going to do something else later on or is it just early_console_init? If the latter, then name the function as such.

I'll rename for now, as I don't know if it will do something else yet. I guess we can rename it again if it ever does.

Quoted 10 lines
Quoted 10 lines
arm/cstart.S new file +5 -0
+
+void io_init(void)
+{
+	virtio_testdev_init();
+}
lib/arm/io.h new file +0 -1
new file mode 100644
index 0000000000000..f058f7e54d4a7
--- /dev/null
Quoted 10 lines

lib/arm/io.h line 4

Quoted 6 lines

+++ b/lib/arm/io.h

lib/arm/io.h new file +4 -0
@@ -0,0 +1,24 @@
+#ifndef _ARM_IO_H_
+#define _ARM_IO_H_
+
+#define cpu_is_be cpu_is_be

huh?

Quoted 1 line
lib/arm/io.h new file +1 -0
+extern bool cpu_is_be;

See lib/libio.h, it has

#ifndef cpu_is_be
#define cpu_is_be 0
#endif

Quoted 9 lines
Quoted 9 lines
lib/arm/io.h new file +9 -0
+static void read_atags(u32 id, u32 *info)
+{
+	u32 *p = info;
+
+	if (!p) {
+		printf("Can't find bootinfo. mach-type = %x\n", id);
+		exit(ENOEXEC);
+	}
+
Quoted 8 lines

lib/arm/io.h line 20

Quoted 6 lines
lib/arm/io.h new file +6 -0
+	/*
+	 * p[0]	count of words for the tag
+	 * p[1]	tag id
+	 * p[2..]	tag data
+	 */
+	for (; p[0] != 0; p += p[0])

braces, please.

added.

Quoted 26 lines
Quoted 26 lines
lib/arm/io.h new file +25 -0
+		switch (p[1]) {
+		case ATAG_CORE:
+			core.flags = p[2];
+			core.pagesize = p[3];
+			core.rootdev = p[4];
+			break;
+		case ATAG_MEM:
+			mem32.size = p[2];
+			mem32.start = p[3];
+			break;
+		case ATAG_CMDLINE:
+			__args = (char *)&p[2];
+			break;
+		}
+}
+
+static void read_bootinfo(u32 id, u32 *info)
+{
+	u32 *atags = NULL;
+
+	mach_type_id = id;
+
+	if (info[0] == be32_to_cpu(FDT_SIG)) {
+		/*
+		 * fdt reading is not [yet?] implemented. So calculate
Quoted 8 lines

lib/arm/io.h

Quoted 3 lines
lib/arm/io.h new file +3 -0
+		 * the ATAGS addr to read that instead.
+		 */
+		atags = (u32 *)(start - KERNEL_OFFSET + ATAG_OFFSET);

are the atags always supposed to be loaded even for device-tree booting? I could not find this in any ARM booting documents, and QEMU does seem to do this, but only for auto-generated device trees, which could just be a bug in do_cpu_reset?

Looks like Peter confirms I can't rely on this anymore. I guess it's time to just be one with libfdt.

Quoted 67 lines
Quoted 62 lines
lib/test_util.c new file +34 -0
new file mode 100644
index 0000000000000..3de1f74f83455
@@ -0,0 +1,34 @@
+#include "libcflat.h"
+#include "test_util.h"
+
+bool enough_args(int nargs, int needed)
+{
+	if (nargs >= needed)
+		return true;
+
+	fail("Not enough arguments.\n");
+	return false;
+}
+
+/*
+ * Typically one would compare val == strtoul(expected, endp, base),
+ * but we don't have, nor at this point really need, strtoul, so we
+ * convert val to a string instead. base can only be 10 or 16.
+ */
+bool check_u32(u32 val, int base, char *expected)
+{
+	char *fmt = base == 10 ? "%d" : "%x";
+	char val_str[16];
+
+	snprintf(val_str, 16, fmt, val);
+
+	if (base == 16)
+		while (*expected == '0' || *expected == 'x')
+			++expected;
+
+	if (strcmp(val_str, expected) == 0)
+		return true;
+
+	fail("expected %s, but have %s\n", expected, val_str);
+	return false;
+}
lib/test_util.h new file +13 -0
new file mode 100644
index 0000000000000..0e3e6c4a80d51
@@ -0,0 +1,13 @@
+#ifndef _TEST_UTIL_H_
+#define _TEST_UTIL_H_
+#include "libcflat.h"
+
+#define PASS 0
+#define FAIL 1
+
+#define pass(fmt...) printf("PASS: " fmt)
+#define fail(fmt...) printf("FAIL: " fmt)
+
+bool enough_args(int nargs, int needed);
+bool check_u32(u32 val, int base, char *expected);
+#endif
Signature · 1 line
1.8.1.4

I was expecting to see a __raw_... IO accessor definitions for ARM here, specifically so we avoid the register-writeback versions that are not supported on ARM.

Quoted 1 line

See arch/arm/include/asm/io.h in the kernel.

k, I'll grab them, but they'll go in lib/arm/io.h. I think I'll drop these lib/test_util.* in v3, so far they're fairly useless cruft. We can bring them back if they have enough purpose later.

drew

#36 lore raw

Re: [PATCH 9/9] arm: initial drop

Quoted 12 lines · Andrew Jones
Quoted 10 lines · Christoffer Dall

arm/cstart.S line 16

Quoted 3 lines · Andrew Jones
arm/cstart.S new file +3 -0
+   ands    r3, r8, #CR_B           @set BE, if necessary
+   ldrne   r3, =cpu_is_be
+   movne   r4, #1

This is deprecated for ARMv7 according to the ARM ARM. What is the intention here? Does qemu support running this test tool with the system configured for big-endian? If so, I think this is a build option for this binary or you need to come up with some other architecture-compliant method of detecting the endian-state.

Quoted 3 lines

Yes, qemu allows big-endian. I haven't tested it though, but suspect someday we will want big-endian guests tested as well. I'll fix the detection.

QEMU does not support system mode big-endian. (Some of the pieces are there for it but we have no board that needs it.)

Also, you should read up in the ARM ARM about the differences between old style BE32 and new BE8. (The quick summary is here:
http://translatedcode.wordpress.com/2012/04/)
What you're trying to do here is enable old-style BE32. This is not supported on any ARMv7 or later CPU, which means it does not overlap at all with virtualization support.

We probably do care about BE8 big-endian guest support testing. (kvmtool can run guests in this mode; QEMU doesn't currently).

thanks
-- PMM

#37 lore raw

Re: [PATCH 9/9] arm: initial drop

Quoted 27 lines · Peter Maydell
Quoted 12 lines · Andrew Jones
Quoted 10 lines · Christoffer Dall

arm/cstart.S line 16

Quoted 3 lines · Andrew Jones
arm/cstart.S new file +3 -0
+   ands    r3, r8, #CR_B           @set BE, if necessary
+   ldrne   r3, =cpu_is_be
+   movne   r4, #1

This is deprecated for ARMv7 according to the ARM ARM. What is the intention here? Does qemu support running this test tool with the system configured for big-endian? If so, I think this is a build option for this binary or you need to come up with some other architecture-compliant method of detecting the endian-state.

Quoted 3 lines

Yes, qemu allows big-endian. I haven't tested it though, but suspect someday we will want big-endian guests tested as well. I'll fix the detection.

QEMU does not support system mode big-endian. (Some of the pieces are there for it but we have no board that needs it.)

Also, you should read up in the ARM ARM about the differences between old style BE32 and new BE8. (The quick summary is here:
http://translatedcode.wordpress.com/2012/04/)
What you're trying to do here is enable old-style BE32. This is not supported on any ARMv7 or later CPU, which means it does not overlap at all with virtualization support.

Quoted 3 lines

We probably do care about BE8 big-endian guest support testing. (kvmtool can run guests in this mode; QEMU doesn't currently).

Yeah, so I think this logic should go away from the test suite for now, focs on getting a decent set of actual functional tests up and running, and then probably add aarch64 support before looking at big-endian support.

Thanks,
-Christoffer

#38 lore raw

Re: [PATCH 9/9] arm: initial drop

Quoted 28 lines · Christoffer Dall
Quoted 27 lines · Peter Maydell
Quoted 12 lines · Andrew Jones
Quoted 10 lines · Christoffer Dall

arm/cstart.S line 16

Quoted 3 lines · Andrew Jones
arm/cstart.S new file +3 -0
+   ands    r3, r8, #CR_B           @set BE, if necessary
+   ldrne   r3, =cpu_is_be
+   movne   r4, #1

This is deprecated for ARMv7 according to the ARM ARM. What is the intention here? Does qemu support running this test tool with the system configured for big-endian? If so, I think this is a build option for this binary or you need to come up with some other architecture-compliant method of detecting the endian-state.

Quoted 3 lines

Yes, qemu allows big-endian. I haven't tested it though, but suspect someday we will want big-endian guests tested as well. I'll fix the detection.

QEMU does not support system mode big-endian. (Some of the pieces are there for it but we have no board that needs it.)

Also, you should read up in the ARM ARM about the differences between old style BE32 and new BE8. (The quick summary is here:
http://translatedcode.wordpress.com/2012/04/)
What you're trying to do here is enable old-style BE32. This is not supported on any ARMv7 or later CPU, which means it does not overlap at all with virtualization support.

Quoted 8 lines
Quoted 3 lines

We probably do care about BE8 big-endian guest support testing. (kvmtool can run guests in this mode; QEMU doesn't currently).

Yeah, so I think this logic should go away from the test suite for now, focs on getting a decent set of actual functional tests up and running, and then probably add aarch64 support before looking at big-endian support.

OK, sounds good. The cpu_is_be stuff scattered about should still be fine to leave in, and we can go about actually detecting BE and setting cpu_is_be whenever.

thanks,
drew

#39 lore raw

Re: [PATCH 9/9] arm: initial drop

In reply to Andrew Jones
Quoted 116 lines · Andrew Jones
Quoted 6 lines · Christoffer Dall
Quoted 5 lines · Andrew Jones

This is the initial arm test framework and a first simple test that checks some bootinfo. kvm isn't needed to run this test. This patch also adds a common build environment variable, $QEMU_BIN, which allows makefiles to call on qemu when needed.

Quoted 8 lines
Quoted 6 lines

Try it out with
yum install gcc-arm-linux-gnu dtc
export QEMU=[qemu with mach-virt and virtio-testdev] ./configure --cross-prefix=arm-linux-gnu- --arch=arm make
./run_tests.sh

You refer to QEMU_BIN but your example uses QEMU= ?

Two different vars. QEMU_BIN is an internal makefile var set in config.mak. QEMU is an ENV. Hmm, I guess I could reuse the QEMU name in the makefiles too...

<snip>

Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	return ret;
+}

consider renaming this file to boottest.c to avoid the confusion that this file is needed to boot anything that runs tests...

I think I'll rename it to selftest.c, as it's really just a test framework selftest.

Quoted 21 lines
Quoted 7 lines
arm/cstart.S new file +0 -0
new file mode 100644
index 0000000000000..05d4bb5becaa0

arm/cstart.S line 10

Quoted 10 lines
arm/cstart.S new file +10 -0
@@ -0,0 +1,38 @@
+
+#define CR_B	(1 << 7)	/* Big endian */
+
+.arm
+
+.section .init
+
+.globl start
+start:
+	/* bootloader params are in r0-r2 */

which bootlaoder params are they? What boot protocol is used, what are you expecting to be in the various registers?

Quoted 2 lines

I assume this tool expects r0-r2 to follow the definitions in Documentation/arm/Booting in the kernel?

Correct. I guess I can add a 'see Documentation/arm/Booting comment'

Quoted 6 lines

arm/cstart.S line 13

Quoted 4 lines
arm/cstart.S new file +3 -0
+	ldr	sp, =stacktop
+
+	mrc	p15, 0, r8, c1, c0, 0	@r8 = sctrl

that's sctlr, not sctrl.

fixed

Quoted 10 lines

arm/cstart.S line 16

Quoted 4 lines
arm/cstart.S new file +3 -0
+	ands	r3, r8, #CR_B		@set BE, if necessary
+	ldrne	r3, =cpu_is_be
+	movne	r4, #1

This is deprecated for ARMv7 according to the ARM ARM. What is the intention here? Does qemu support running this test tool with the system configured for big-endian? If so, I think this is a build option for this binary or you need to come up with some other architecture-compliant method of detecting the endian-state.

Yes, qemu allows big-endian. I haven't tested it though, but suspect someday we will want big-endian guests tested as well. I'll fix the detection.

Quoted 9 lines

arm/cstart.S line 5

Quoted 7 lines
arm/cstart.S new file +6 -0
+++ b/arm/unittests.cfg
@@ -0,0 +1,11 @@
+# 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

used to QEMU I presume?

correct

Quoted 4 lines

arm/cstart.S line 6

Quoted 2 lines
arm/cstart.S new file +1 -0
+# arch = arm/arm64 # Only if the test case works only on one of them

Do we have any verified support for arm64 yet?

not yet, high on my TODO list though.

Quoted 7 lines

arm/cstart.S line 10

Quoted 4 lines
arm/cstart.S new file +4 -0
+
+CFLAGS += -Wextra
+CFLAGS += -marm
+#CFLAGS += -mcpu=$(PROCESSOR)

This looks weird, should it not be $(PROCESSOR) and default to cortex-a15 if it's not set?

Agreed.

Quoted 3 lines

(also note that you can now use -cpu host with mach-virt which may make your life easier).

I'll think about how we might/must use '-cpu host'.

Quoted 1 line
Quoted 9 lines
Quoted 5 lines

arm/cstart.S

Quoted 2 lines
arm/cstart.S new file +2 -0
+CFLAGS += -mcpu=cortex-a15
+CFLAGS += -O2

Why do we choose this particular optimzation-level in the arch-specific config?

My cross-compiler was generating broken code with anything less. I haven't checked later compilers yet to see if it's fixed or not.

which GCC version?

Quoted 13 lines
Quoted 12 lines

arm/cstart.S

Quoted 10 lines
arm/cstart.S new file +9 -0
+
+libgcc := $(shell $(CC) -m$(ARCH) --print-libgcc-file-name)
+start_addr := $(shell printf "%x\n" $$(( $(phys_base) + $(kernel_offset) )))
+
+FLATLIBS = $(libcflat) $(libgcc) $(libeabi)
+%.elf: %.o $(FLATLIBS) arm/flat.lds
+	$(CC) $(CFLAGS) -nostdlib -o $@ \
+		-Wl,-T,arm/flat.lds,--build-id=none,-Ttext=$(start_addr) \
+		$(filter %.o, $^) $(FLATLIBS)

I have no idea what the above rules are doing :-(

Quoted 5 lines

Calls the linker on the *.o files with the supplied linker script, and a .text addr of $(start_addr). Also gets rid of the build-id section, which messes up the start address. And supplies libs to link with, which need to be in a particular order (defined in FLATLIBS).

thanks.

Quoted 53 lines
Quoted 16 lines

arm/cstart.S

Quoted 13 lines
arm/cstart.S new file +12 -0
+
+$(libeabi): $(eabiobjs)
+	$(AR) rcs $@ $^
+
+%.flat: %.elf
+	$(OBJCOPY) -O binary $^ $@
+
+tests-common = $(TEST_DIR)/boot.flat
+
+tests_and_config = $(TEST_DIR)/*.flat $(TEST_DIR)/unittests.cfg
+
+test_cases: $(tests-common) $(tests)

what's the distinction between tests-common and tests? arm/arm64 vs. one or the other, or?

Correct. Eventually we'll have tests-common, which will be the majority and apply to both, and also tests which are specific to one.

Quoted 10 lines

arm/cstart.S

Quoted 7 lines
arm/cstart.S new file +7 -0
+void io_init_early(void)
+{
+	const struct iomap *m = iomaps_find_compatible("arm,pl011");
+	if (!m)
+		halt(ENXIO);
+	uart0_base = (u8 *)compat_ptr(m->addrs[0]);
+}

is io_init_early going to do something else later on or is it just early_console_init? If the latter, then name the function as such.

I'll rename for now, as I don't know if it will do something else yet. I guess we can rename it again if it ever does.

Quoted 19 lines
Quoted 12 lines
arm/cstart.S new file +5 -0
+
+void io_init(void)
+{
+	virtio_testdev_init();
+}
lib/arm/io.h new file +0 -0
new file mode 100644
index 0000000000000..f058f7e54d4a7

lib/arm/io.h line 4

Quoted 4 lines
lib/arm/io.h new file +4 -0
@@ -0,0 +1,24 @@
+#ifndef _ARM_IO_H_
+#define _ARM_IO_H_
+
+#define cpu_is_be cpu_is_be

huh?

Quoted 8 lines
Quoted 1 line

lib/arm/io.h line 5

Quoted 1 line
lib/arm/io.h new file +1 -0
+extern bool cpu_is_be;

See lib/libio.h, it has

#ifndef cpu_is_be
#define cpu_is_be 0
#endif

ah, yuck.

Quoted 125 lines
Quoted 9 lines
Quoted 9 lines
lib/arm/io.h new file +9 -0
+static void read_atags(u32 id, u32 *info)
+{
+	u32 *p = info;
+
+	if (!p) {
+		printf("Can't find bootinfo. mach-type = %x\n", id);
+		exit(ENOEXEC);
+	}
+
Quoted 8 lines

lib/arm/io.h line 20

Quoted 6 lines
lib/arm/io.h new file +6 -0
+	/*
+	 * p[0]	count of words for the tag
+	 * p[1]	tag id
+	 * p[2..]	tag data
+	 */
+	for (; p[0] != 0; p += p[0])

braces, please.

added.

Quoted 26 lines
Quoted 26 lines
lib/arm/io.h new file +25 -0
+		switch (p[1]) {
+		case ATAG_CORE:
+			core.flags = p[2];
+			core.pagesize = p[3];
+			core.rootdev = p[4];
+			break;
+		case ATAG_MEM:
+			mem32.size = p[2];
+			mem32.start = p[3];
+			break;
+		case ATAG_CMDLINE:
+			__args = (char *)&p[2];
+			break;
+		}
+}
+
+static void read_bootinfo(u32 id, u32 *info)
+{
+	u32 *atags = NULL;
+
+	mach_type_id = id;
+
+	if (info[0] == be32_to_cpu(FDT_SIG)) {
+		/*
+		 * fdt reading is not [yet?] implemented. So calculate
Quoted 8 lines

lib/arm/io.h

Quoted 3 lines
lib/arm/io.h new file +3 -0
+		 * the ATAGS addr to read that instead.
+		 */
+		atags = (u32 *)(start - KERNEL_OFFSET + ATAG_OFFSET);

are the atags always supposed to be loaded even for device-tree booting? I could not find this in any ARM booting documents, and QEMU does seem to do this, but only for auto-generated device trees, which could just be a bug in do_cpu_reset?

Looks like Peter confirms I can't rely on this anymore. I guess it's time to just be one with libfdt.

Quoted 67 lines
Quoted 62 lines
lib/test_util.c new file +34 -0
new file mode 100644
index 0000000000000..3de1f74f83455
@@ -0,0 +1,34 @@
+#include "libcflat.h"
+#include "test_util.h"
+
+bool enough_args(int nargs, int needed)
+{
+	if (nargs >= needed)
+		return true;
+
+	fail("Not enough arguments.\n");
+	return false;
+}
+
+/*
+ * Typically one would compare val == strtoul(expected, endp, base),
+ * but we don't have, nor at this point really need, strtoul, so we
+ * convert val to a string instead. base can only be 10 or 16.
+ */
+bool check_u32(u32 val, int base, char *expected)
+{
+	char *fmt = base == 10 ? "%d" : "%x";
+	char val_str[16];
+
+	snprintf(val_str, 16, fmt, val);
+
+	if (base == 16)
+		while (*expected == '0' || *expected == 'x')
+			++expected;
+
+	if (strcmp(val_str, expected) == 0)
+		return true;
+
+	fail("expected %s, but have %s\n", expected, val_str);
+	return false;
+}
lib/test_util.h new file +13 -0
new file mode 100644
index 0000000000000..0e3e6c4a80d51
@@ -0,0 +1,13 @@
+#ifndef _TEST_UTIL_H_
+#define _TEST_UTIL_H_
+#include "libcflat.h"
+
+#define PASS 0
+#define FAIL 1
+
+#define pass(fmt...) printf("PASS: " fmt)
+#define fail(fmt...) printf("FAIL: " fmt)
+
+bool enough_args(int nargs, int needed);
+bool check_u32(u32 val, int base, char *expected);
+#endif
Signature · 1 line
1.8.1.4

I was expecting to see a __raw_... IO accessor definitions for ARM here, specifically so we avoid the register-writeback versions that are not supported on ARM.

Quoted 6 lines
Quoted 1 line

See arch/arm/include/asm/io.h in the kernel.

k, I'll grab them, but they'll go in lib/arm/io.h. I think I'll drop these lib/test_util.* in v3, so far they're fairly useless cruft. We can bring them back if they have enough purpose later.

I already did that for my WIP, see commit
680054064db4dd710991f064a88a12012944d376 in:

https://github.com/columbia/kvm-unit-tests.git

-Christoffer

#40 lore raw

Re: [PATCH 9/9] arm: initial drop

Quoted 5 lines · Christoffer Dall
Quoted 3 lines

My cross-compiler was generating broken code with anything less. I haven't checked later compilers yet to see if it's fixed or not.

which GCC version?

$ arm-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=arm-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/arm-linux-gnueabi/4.8.1/lto-wrapper
Target: arm-linux-gnueabi
Configured with: ../gcc-4.8.1-20130717/configure --bindir=/usr/bin
--build=x86_64-redhat-linux-gnu --datadir=/usr/share
--disable-decimal-float --disable-dependency-tracking --disable-gold
--disable-libgomp --disable-libmudflap --disable-libquadmath
--disable-libssp --disable-nls --disable-plugin --disable-shared
--disable-silent-rules --disable-sjlj-exceptions --disable-threads
--enable-checking= --enable-gnu-unique-object --enable-initfini-array
--enable-languages=c --enable-linker-build-id --enable-nls
--enable-obsolete --enable-targets=all --exec-prefix=/usr
--host=x86_64-redhat-linux-gnu --includedir=/usr/include
--infodir=/usr/share/info --libexecdir=/usr/libexec --localstatedir=/var
--mandir=/usr/share/man --prefix=/usr --program-prefix=arm-linux-gnu-
--sbindir=/usr/sbin --sharedstatedir=/var/lib --sysconfdir=/etc
--target=arm-linux-gnueabi
--with-bugurl=http://bugzilla.redhat.com/bugzilla/
--with-linker-hash-style=gnu --with-newlib --with-system-libunwind
--with-system-zlib --without-headers
--with-isl=/builddir/build/BUILD/gcc-4.8.1-20130717/isl-install
--with-cloog=/builddir/build/BUILD/gcc-4.8.1-20130717/cloog-install
Thread model: single
gcc version 4.8.1 20130717 (Red Hat 4.8.1-5) (GCC)
Quoted 11 lines
Quoted 10 lines
Quoted 5 lines

I was expecting to see a __raw_... IO accessor definitions for ARM here, specifically so we avoid the register-writeback versions that are not supported on ARM.

See arch/arm/include/asm/io.h in the kernel.

k, I'll grab them, but they'll go in lib/arm/io.h. I think I'll drop these lib/test_util.* in v3, so far they're fairly useless cruft. We can bring them back if they have enough purpose later.

Quoted 4 lines

I already did that for my WIP, see commit
680054064db4dd710991f064a88a12012944d376 in:

https://github.com/columbia/kvm-unit-tests.git

I'll fetch your tree and start going through it tomorrow. Thanks for jumping in!!

drew

#41 lore raw

Re: [PATCH 9/9] arm: initial drop

Quoted 45 lines · Andrew Jones
Quoted 5 lines · Christoffer Dall
Quoted 3 lines

My cross-compiler was generating broken code with anything less. I haven't checked later compilers yet to see if it's fixed or not.

which GCC version?

$ arm-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=arm-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/arm-linux-gnueabi/4.8.1/lto-wrapper
Target: arm-linux-gnueabi
Configured with: ../gcc-4.8.1-20130717/configure --bindir=/usr/bin
--build=x86_64-redhat-linux-gnu --datadir=/usr/share
--disable-decimal-float --disable-dependency-tracking --disable-gold
--disable-libgomp --disable-libmudflap --disable-libquadmath
--disable-libssp --disable-nls --disable-plugin --disable-shared
--disable-silent-rules --disable-sjlj-exceptions --disable-threads
--enable-checking= --enable-gnu-unique-object --enable-initfini-array
--enable-languages=c --enable-linker-build-id --enable-nls
--enable-obsolete --enable-targets=all --exec-prefix=/usr
--host=x86_64-redhat-linux-gnu --includedir=/usr/include
--infodir=/usr/share/info --libexecdir=/usr/libexec --localstatedir=/var
--mandir=/usr/share/man --prefix=/usr --program-prefix=arm-linux-gnu-
--sbindir=/usr/sbin --sharedstatedir=/var/lib --sysconfdir=/etc
--target=arm-linux-gnueabi
--with-bugurl=http://bugzilla.redhat.com/bugzilla/
--with-linker-hash-style=gnu --with-newlib --with-system-libunwind
--with-system-zlib --without-headers
--with-isl=/builddir/build/BUILD/gcc-4.8.1-20130717/isl-install
--with-cloog=/builddir/build/BUILD/gcc-4.8.1-20130717/cloog-install
Thread model: single
gcc version 4.8.1 20130717 (Red Hat 4.8.1-5) (GCC)
Quoted 11 lines
Quoted 10 lines
Quoted 5 lines

I was expecting to see a __raw_... IO accessor definitions for ARM here, specifically so we avoid the register-writeback versions that are not supported on ARM.

See arch/arm/include/asm/io.h in the kernel.

k, I'll grab them, but they'll go in lib/arm/io.h. I think I'll drop these lib/test_util.* in v3, so far they're fairly useless cruft. We can bring them back if they have enough purpose later.

Quoted 8 lines
Quoted 4 lines

I already did that for my WIP, see commit
680054064db4dd710991f064a88a12012944d376 in:

https://github.com/columbia/kvm-unit-tests.git

I'll fetch your tree and start going through it tomorrow. Thanks for jumping in!!

Sure, if you fix anything in your existing series, I'll be happy to rebase my patches and take a pass at squashing some of them and such so we can get them out as an RFC.

-Christoffer

#42 lore raw

Re: [PATCH 9/9] arm: initial drop

Quoted 49 lines · Christoffer Dall
Quoted 48 lines · Andrew Jones
Quoted 5 lines · Christoffer Dall
Quoted 3 lines

My cross-compiler was generating broken code with anything less. I haven't checked later compilers yet to see if it's fixed or not.

which GCC version?

$ arm-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=arm-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/arm-linux-gnueabi/4.8.1/lto-wrapper
Target: arm-linux-gnueabi
Configured with: ../gcc-4.8.1-20130717/configure --bindir=/usr/bin
--build=x86_64-redhat-linux-gnu --datadir=/usr/share
--disable-decimal-float --disable-dependency-tracking --disable-gold
--disable-libgomp --disable-libmudflap --disable-libquadmath
--disable-libssp --disable-nls --disable-plugin --disable-shared
--disable-silent-rules --disable-sjlj-exceptions --disable-threads
--enable-checking= --enable-gnu-unique-object --enable-initfini-array
--enable-languages=c --enable-linker-build-id --enable-nls
--enable-obsolete --enable-targets=all --exec-prefix=/usr
--host=x86_64-redhat-linux-gnu --includedir=/usr/include
--infodir=/usr/share/info --libexecdir=/usr/libexec --localstatedir=/var
--mandir=/usr/share/man --prefix=/usr --program-prefix=arm-linux-gnu-
--sbindir=/usr/sbin --sharedstatedir=/var/lib --sysconfdir=/etc
--target=arm-linux-gnueabi
--with-bugurl=http://bugzilla.redhat.com/bugzilla/
--with-linker-hash-style=gnu --with-newlib --with-system-libunwind
--with-system-zlib --without-headers
--with-isl=/builddir/build/BUILD/gcc-4.8.1-20130717/isl-install
--with-cloog=/builddir/build/BUILD/gcc-4.8.1-20130717/cloog-install
Thread model: single
gcc version 4.8.1 20130717 (Red Hat 4.8.1-5) (GCC)
Quoted 14 lines
Quoted 10 lines
Quoted 5 lines

I was expecting to see a __raw_... IO accessor definitions for ARM here, specifically so we avoid the register-writeback versions that are not supported on ARM.

See arch/arm/include/asm/io.h in the kernel.

k, I'll grab them, but they'll go in lib/arm/io.h. I think I'll drop these lib/test_util.* in v3, so far they're fairly useless cruft. We can bring them back if they have enough purpose later.

I already did that for my WIP, see commit
680054064db4dd710991f064a88a12012944d376 in:

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

https://github.com/columbia/kvm-unit-tests.git

I'll fetch your tree and start going through it tomorrow. Thanks for jumping in!!

Sure, if you fix anything in your existing series, I'll be happy to rebase my patches and take a pass at squashing some of them and such so we can get them out as an RFC.

Lot's of good stuff in there. I also had a start on the psci/smp stuff (in the form of notes, not code) before the holiday break, so I might have some more suggestions there once we get the patches rebased and cleaned up. I'd like to get a v3 posted [and committed] of this series, a version that uses libfdt, before we get too far along, allowing us to build on a clean base.

Thanks,
drew

#43 lore raw

Re: [PATCH 9/9] arm: initial drop

Quoted 59 lines · Andrew Jones
Quoted 49 lines · Christoffer Dall
Quoted 48 lines · Andrew Jones
Quoted 5 lines · Christoffer Dall
Quoted 3 lines

My cross-compiler was generating broken code with anything less. I haven't checked later compilers yet to see if it's fixed or not.

which GCC version?

$ arm-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=arm-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/arm-linux-gnueabi/4.8.1/lto-wrapper
Target: arm-linux-gnueabi
Configured with: ../gcc-4.8.1-20130717/configure --bindir=/usr/bin
--build=x86_64-redhat-linux-gnu --datadir=/usr/share
--disable-decimal-float --disable-dependency-tracking --disable-gold
--disable-libgomp --disable-libmudflap --disable-libquadmath
--disable-libssp --disable-nls --disable-plugin --disable-shared
--disable-silent-rules --disable-sjlj-exceptions --disable-threads
--enable-checking= --enable-gnu-unique-object --enable-initfini-array
--enable-languages=c --enable-linker-build-id --enable-nls
--enable-obsolete --enable-targets=all --exec-prefix=/usr
--host=x86_64-redhat-linux-gnu --includedir=/usr/include
--infodir=/usr/share/info --libexecdir=/usr/libexec --localstatedir=/var
--mandir=/usr/share/man --prefix=/usr --program-prefix=arm-linux-gnu-
--sbindir=/usr/sbin --sharedstatedir=/var/lib --sysconfdir=/etc
--target=arm-linux-gnueabi
--with-bugurl=http://bugzilla.redhat.com/bugzilla/
--with-linker-hash-style=gnu --with-newlib --with-system-libunwind
--with-system-zlib --without-headers
--with-isl=/builddir/build/BUILD/gcc-4.8.1-20130717/isl-install
--with-cloog=/builddir/build/BUILD/gcc-4.8.1-20130717/cloog-install
Thread model: single
gcc version 4.8.1 20130717 (Red Hat 4.8.1-5) (GCC)
Quoted 14 lines
Quoted 10 lines
Quoted 5 lines

I was expecting to see a __raw_... IO accessor definitions for ARM here, specifically so we avoid the register-writeback versions that are not supported on ARM.

See arch/arm/include/asm/io.h in the kernel.

k, I'll grab them, but they'll go in lib/arm/io.h. I think I'll drop these lib/test_util.* in v3, so far they're fairly useless cruft. We can bring them back if they have enough purpose later.

I already did that for my WIP, see commit
680054064db4dd710991f064a88a12012944d376 in:

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

https://github.com/columbia/kvm-unit-tests.git

I'll fetch your tree and start going through it tomorrow. Thanks for jumping in!!

Sure, if you fix anything in your existing series, I'll be happy to rebase my patches and take a pass at squashing some of them and such so we can get them out as an RFC.

Quoted 7 lines

Lot's of good stuff in there. I also had a start on the psci/smp stuff (in the form of notes, not code) before the holiday break, so I might have some more suggestions there once we get the patches rebased and cleaned up. I'd like to get a v3 posted [and committed] of this series, a version that uses libfdt, before we get too far along, allowing us to build on a clean base.

Sounds fine, I'll keep building the stuff I need for other measurements, but fear not, I have magic powers in rebasing complex systems on top of evolving code bases :)

-Christoffer