[kvm-unit-tests PATCH v3 1/5] lib: arm: Use UART address from generated config.h

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Generate lib/config.h when configuring kvm-unit-tests. The file is empty
for all architectures except for arm and arm64, where it is used to store
the UART base address. This removes the hardcoded address from lib/arm/io.c
and provides a mechanism for using different UART addresses in the future.

Signed-off-by: Alexandru Elisei <alexandru.elisei@xxxxxxx>
---
 configure    | 17 +++++++++++++++++
 Makefile     |  2 +-
 lib/arm/io.c | 12 ++++++------
 .gitignore   |  1 +
 4 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/configure b/configure
index df8581e3a906..b4732c6c04e4 100755
--- a/configure
+++ b/configure
@@ -198,3 +198,20 @@ ENVIRON_DEFAULT=$environ_default
 ERRATATXT=errata.txt
 U32_LONG_FMT=$u32_long
 EOF
+
+cat <<EOF > lib/config.h
+#ifndef CONFIG_H
+#define CONFIG_H 1
+/*
+ * Generated file. DO NOT MODIFY.
+ *
+ */
+EOF
+if [ "$arch" = "arm" ] || [ "$arch" = "arm64" ]; then
+cat <<EOF >> lib/config.h
+
+#define CONFIG_UART_EARLY_BASE 0x09000000
+
+EOF
+fi
+echo "#endif" >> lib/config.h
diff --git a/Makefile b/Makefile
index e9f02272e156..643af05678ad 100644
--- a/Makefile
+++ b/Makefile
@@ -115,7 +115,7 @@ libfdt_clean:
 	$(LIBFDT_objdir)/.*.d
 
 distclean: clean libfdt_clean
-	$(RM) lib/asm config.mak $(TEST_DIR)-run msr.out cscope.* build-head
+	$(RM) lib/asm lib/config.h config.mak $(TEST_DIR)-run msr.out cscope.* build-head
 	$(RM) -r tests logs logs.old
 
 cscope: cscope_dirs = lib lib/libfdt lib/linux $(TEST_DIR) $(ARCH_LIBDIRS) lib/asm-generic
diff --git a/lib/arm/io.c b/lib/arm/io.c
index d2c1a07c19ee..e84a5c89fcb1 100644
--- a/lib/arm/io.c
+++ b/lib/arm/io.c
@@ -11,6 +11,7 @@
 #include <libcflat.h>
 #include <devicetree.h>
 #include <chr-testdev.h>
+#include <config.h>
 #include <asm/spinlock.h>
 #include <asm/io.h>
 
@@ -18,6 +19,7 @@
 
 extern void halt(int code);
 
+static struct spinlock uart_lock;
 /*
  * Use this guess for the pl011 base in order to make an attempt at
  * having earlier printf support. We'll overwrite it with the real
@@ -25,10 +27,8 @@ extern void halt(int code);
  * the address we expect QEMU's mach-virt machine type to put in
  * its generated device tree.
  */
-#define UART_EARLY_BASE 0x09000000UL
-
-static struct spinlock uart_lock;
-static volatile u8 *uart0_base = (u8 *)UART_EARLY_BASE;
+#define UART_EARLY_BASE (u8 *)(unsigned long)CONFIG_UART_EARLY_BASE
+static volatile u8 *uart0_base = UART_EARLY_BASE;
 
 static void uart0_init(void)
 {
@@ -58,10 +58,10 @@ static void uart0_init(void)
 
 	uart0_base = ioremap(base.addr, base.size);
 
-	if (uart0_base != (u8 *)UART_EARLY_BASE) {
+	if (uart0_base != UART_EARLY_BASE) {
 		printf("WARNING: early print support may not work. "
 		       "Found uart at %p, but early base is %p.\n",
-			uart0_base, (u8 *)UART_EARLY_BASE);
+			uart0_base, UART_EARLY_BASE);
 	}
 }
 
diff --git a/.gitignore b/.gitignore
index 2405a8087ae5..483f7c7a09ea 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,6 +10,7 @@ patches
 cscope.*
 *.swp
 /lib/asm
+/lib/config.h
 /config.mak
 /*-run
 /msr.out
-- 
2.17.0




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux