ARM: Split out ARMv7 code and make it possible to have other arch versions.

We don't always want to use ARMv7 code when building for ARM, so we should
separate out the ARMv7 code so it can be excluded, and also make it possible
to include code for some other version of the architecture instead, all per
build component for cases where we need more than one architecture version
at a time.

The tegra124 bootblock will ultimately need to be ARMv4, but until we have
some ARMv4 code to switch over to we can leave it set to ARMv7.

BUG=chrome-os-partner:23009
TEST=Built for link, falco, pit, snow, and nyan. Built into the bootblock on
nyan.

Change-Id: Ia982c91057fac9c252397b7c866224f103761cc7
Reviewed-on: https://chromium-review.googlesource.com/171400
Reviewed-by: Gabe Black <gabeblack@chromium.org>
Tested-by: Gabe Black <gabeblack@chromium.org>
Commit-Queue: Gabe Black <gabeblack@chromium.org>
diff --git a/src/arch/arm/Kconfig b/src/arch/arm/Kconfig
index 28444d4..a59ad79 100644
--- a/src/arch/arm/Kconfig
+++ b/src/arch/arm/Kconfig
@@ -8,6 +8,8 @@
 	select HAVE_ARCH_MEMCPY
 	select HAVE_ARCH_MEMMOVE
 
+source src/arch/arm/armv7/Kconfig
+
 # Maximum reboot count
 # TODO: Improve description.
 config MAX_REBOOT_CNT
diff --git a/src/arch/arm/Makefile.inc b/src/arch/arm/Makefile.inc
index b6fd84c..b10115c 100644
--- a/src/arch/arm/Makefile.inc
+++ b/src/arch/arm/Makefile.inc
@@ -25,35 +25,23 @@
 # Take care of subdirectories
 subdirs-y += boot/
 subdirs-y += lib/
+subdirs-y += armv7/
 
 # Things that appear in every board
-ramstage-y += exception.c
-ramstage-y += exception_asm.S
-
 bootblock-$(CONFIG_BOOTBLOCK_CONSOLE) += early_console.c
-bootblock-y += cache.c
-bootblock-y += mmu.c
 
-ifneq ($(CONFIG_ARM_BOOTBLOCK_CUSTOM),y)
-bootblock-y += bootblock.S
-endif
 bootblock-y += id.S
 $(obj)/arch/arm/id.bootblock.o: $(obj)/build.h
-bootblock-$(CONFIG_ARM_BOOTBLOCK_SIMPLE) += bootblock_simple.c
-bootblock-$(CONFIG_ARM_BOOTBLOCK_NORMAL) += bootblock_normal.c
 
 bootblock-y += stages.c
 romstage-y += stages.c
 ramstage-y += stages.c
 
-romstage-y += cache.c
 romstage-y += div0.c
 romstage-$(CONFIG_EARLY_CONSOLE) += early_console.c
 
 ramstage-y += div0.c
-ramstage-y += cache.c
 ramstage-y += cpu.c
-ramstage-y += mmu.c
 
 bootblock-y += eabi_compat.c
 romstage-y += eabi_compat.c
@@ -92,13 +80,7 @@
 ################################################################################
 # Common recipes for all stages
 
-CFLAGS += \
-	-ffixed-r8\
-	-march=armv7-a\
-	-marm\
-	-mno-unaligned-access\
-	-mthumb\
-	-mthumb-interwork
+CFLAGS += -ffixed-r8 -mno-unaligned-access
 
 $(objcbfs)/%.bin: $(objcbfs)/%.elf
 	@printf "    OBJCOPY    $(subst $(obj)/,,$(@))\n"
diff --git a/src/arch/arm/armv7/Kconfig b/src/arch/arm/armv7/Kconfig
new file mode 100644
index 0000000..cbba7dd
--- /dev/null
+++ b/src/arch/arm/armv7/Kconfig
@@ -0,0 +1,6 @@
+config ARM_BOOTBLOCK_ARMV7
+	def_bool n
+config ARM_ROMSTAGE_ARMV7
+	def_bool n
+config ARM_RAMSTAGE_ARMV7
+	def_bool n
diff --git a/src/arch/arm/armv7/Makefile.inc b/src/arch/arm/armv7/Makefile.inc
new file mode 100644
index 0000000..d3ff071
--- /dev/null
+++ b/src/arch/arm/armv7/Makefile.inc
@@ -0,0 +1,66 @@
+################################################################################
+##
+## This file is part of the coreboot project.
+##
+## Copyright (C) 2013 The ChromiumOS Authors
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; version 2 of the License.
+##
+## 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, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+##
+################################################################################
+
+armv7_flags = -march=armv7-a -mthumb -mthumb-interwork \
+	-I$(src)/arch/arm/include/armv7/
+
+################################################################################
+## Bootblock
+################################################################################
+ifeq ($(CONFIG_ARM_BOOTBLOCK_ARMV7),y)
+
+ifneq ($(CONFIG_ARM_BOOTBLOCK_CUSTOM),y)
+bootblock-y += bootblock.S
+endif
+bootblock-$(CONFIG_ARM_BOOTBLOCK_SIMPLE) += bootblock_simple.c
+bootblock-$(CONFIG_ARM_BOOTBLOCK_NORMAL) += bootblock_normal.c
+bootblock-y += cache.c
+bootblock-y += mmu.c
+
+bootblock-c-ccopts += $(armv7_flags)
+bootblock-S-ccopts += $(armv7_flags)
+
+endif
+################################################################################
+## ROM stage
+################################################################################
+ifeq ($(CONFIG_ARM_ROMSTAGE_ARMV7),y)
+
+romstage-y += cache.c
+
+romstage-c-ccopts += $(armv7_flags)
+romstage-S-ccopts += $(armv7_flags)
+
+endif
+################################################################################
+## RAM stage
+################################################################################
+ifeq ($(CONFIG_ARM_RAMSTAGE_ARMV7),y)
+
+ramstage-y += cache.c
+ramstage-y += exception.c
+ramstage-y += exception_asm.S
+ramstage-y += mmu.c
+
+ramstage-c-ccopts += $(armv7_flags)
+ramstage-S-ccopts += $(armv7_flags)
+
+endif
diff --git a/src/arch/arm/bootblock.S b/src/arch/arm/armv7/bootblock.S
similarity index 100%
rename from src/arch/arm/bootblock.S
rename to src/arch/arm/armv7/bootblock.S
diff --git a/src/arch/arm/bootblock_simple.c b/src/arch/arm/armv7/bootblock_simple.c
similarity index 100%
rename from src/arch/arm/bootblock_simple.c
rename to src/arch/arm/armv7/bootblock_simple.c
diff --git a/src/arch/arm/cache.c b/src/arch/arm/armv7/cache.c
similarity index 100%
rename from src/arch/arm/cache.c
rename to src/arch/arm/armv7/cache.c
diff --git a/src/arch/arm/exception.c b/src/arch/arm/armv7/exception.c
similarity index 100%
rename from src/arch/arm/exception.c
rename to src/arch/arm/armv7/exception.c
diff --git a/src/arch/arm/exception_asm.S b/src/arch/arm/armv7/exception_asm.S
similarity index 100%
rename from src/arch/arm/exception_asm.S
rename to src/arch/arm/armv7/exception_asm.S
diff --git a/src/arch/arm/mmu.c b/src/arch/arm/armv7/mmu.c
similarity index 100%
rename from src/arch/arm/mmu.c
rename to src/arch/arm/armv7/mmu.c
diff --git a/src/arch/arm/thread.c b/src/arch/arm/armv7/thread.c
similarity index 100%
rename from src/arch/arm/thread.c
rename to src/arch/arm/armv7/thread.c
diff --git a/src/arch/arm/include/arch/io.h b/src/arch/arm/include/arch/io.h
index e044090..e537297 100644
--- a/src/arch/arm/include/arch/io.h
+++ b/src/arch/arm/include/arch/io.h
@@ -23,48 +23,9 @@
 #ifndef __ASM_ARM_IO_H
 #define __ASM_ARM_IO_H
 
-#include <types.h>
-#include <arch/cache.h>		/* for dmb() */
 #include <arch/byteorder.h>
-
-static inline uint8_t read8(const void *addr)
-{
-	dmb();
-	return *(volatile uint8_t *)addr;
-}
-
-static inline uint16_t read16(const void *addr)
-{
-	dmb();
-	return *(volatile uint16_t *)addr;
-}
-
-static inline uint32_t read32(const void *addr)
-{
-	dmb();
-	return *(volatile uint32_t *)addr;
-}
-
-static inline void write8(uint8_t val, void *addr)
-{
-	dmb();
-	*(volatile uint8_t *)addr = val;
-	dmb();
-}
-
-static inline void write16(uint16_t val, void *addr)
-{
-	dmb();
-	*(volatile uint16_t *)addr = val;
-	dmb();
-}
-
-static inline void write32(uint32_t val, void *addr)
-{
-	dmb();
-	*(volatile uint32_t *)addr = val;
-	dmb();
-}
+#include <arch/arch_io.h>
+#include <stdint.h>
 
 /*
  * FIXME: These are to avoid breaking existing ARM code. We should eventually
diff --git a/src/arch/arm/include/armv7/arch/arch_io.h b/src/arch/arm/include/armv7/arch/arch_io.h
new file mode 100644
index 0000000..360fa64
--- /dev/null
+++ b/src/arch/arm/include/armv7/arch/arch_io.h
@@ -0,0 +1,68 @@
+/*
+ * Originally imported from linux/include/asm-arm/io.h. This file has changed
+ * substantially since then.
+ *
+ *  Copyright 2013 Google Inc.
+ *  Copyright (C) 1996-2000 Russell King
+ *
+ * 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.
+ *
+ * Modifications:
+ *  08-Apr-2013	G	Replaced several macros with inlines for type safety.
+ *  16-Sep-1996	RMK	Inlined the inx/outx functions & optimised for both
+ *			constant addresses and variable addresses.
+ *  04-Dec-1997	RMK	Moved a lot of this stuff to the new architecture
+ *			specific IO header files.
+ *  27-Mar-1999	PJB	Second parameter of memcpy_toio is const..
+ *  04-Apr-1999	PJB	Added check_signature.
+ *  12-Dec-1999	RMK	More cleanups
+ *  18-Jun-2000 RMK	Removed virt_to_* and friends definitions
+ */
+#ifndef __ASM_ARM_ARCH_IO_H
+#define __ASM_ARM_ARCH_IO_H
+
+#include <arch/cache.h>		/* for dmb() */
+#include <stdint.h>
+
+static inline uint8_t read8(const void *addr)
+{
+	dmb();
+	return *(volatile uint8_t *)addr;
+}
+
+static inline uint16_t read16(const void *addr)
+{
+	dmb();
+	return *(volatile uint16_t *)addr;
+}
+
+static inline uint32_t read32(const void *addr)
+{
+	dmb();
+	return *(volatile uint32_t *)addr;
+}
+
+static inline void write8(uint8_t val, void *addr)
+{
+	dmb();
+	*(volatile uint8_t *)addr = val;
+	dmb();
+}
+
+static inline void write16(uint16_t val, void *addr)
+{
+	dmb();
+	*(volatile uint16_t *)addr = val;
+	dmb();
+}
+
+static inline void write32(uint32_t val, void *addr)
+{
+	dmb();
+	*(volatile uint32_t *)addr = val;
+	dmb();
+}
+
+#endif	/* __ASM_ARM_ARCH_IO_H */
diff --git a/src/arch/arm/include/arch/cache.h b/src/arch/arm/include/armv7/arch/cache.h
similarity index 100%
rename from src/arch/arm/include/arch/cache.h
rename to src/arch/arm/include/armv7/arch/cache.h
diff --git a/src/arch/arm/include/arch/cpu.h b/src/arch/arm/include/armv7/arch/cpu.h
similarity index 100%
rename from src/arch/arm/include/arch/cpu.h
rename to src/arch/arm/include/armv7/arch/cpu.h
diff --git a/src/arch/arm/include/arch/types.h b/src/arch/arm/include/armv7/arch/types.h
similarity index 100%
rename from src/arch/arm/include/arch/types.h
rename to src/arch/arm/include/armv7/arch/types.h
diff --git a/src/soc/nvidia/tegra124/Kconfig b/src/soc/nvidia/tegra124/Kconfig
index c789245..c75db27 100644
--- a/src/soc/nvidia/tegra124/Kconfig
+++ b/src/soc/nvidia/tegra124/Kconfig
@@ -7,6 +7,9 @@
 	select BOOTBLOCK_CONSOLE
 	select EARLY_CONSOLE
 	select ARM_BOOTBLOCK_CUSTOM
+	select ARM_BOOTBLOCK_ARMV7
+	select ARM_ROMSTAGE_ARMV7
+	select ARM_RAMSTAGE_ARMV7
 
 if SOC_NVIDIA_TEGRA124
 
diff --git a/src/soc/samsung/exynos5250/Kconfig b/src/soc/samsung/exynos5250/Kconfig
index 99966f5..982008b 100644
--- a/src/soc/samsung/exynos5250/Kconfig
+++ b/src/soc/samsung/exynos5250/Kconfig
@@ -6,6 +6,9 @@
 	select EARLY_CONSOLE
 	select DYNAMIC_CBMEM
 	select CAR_MIGRATION
+	select ARM_BOOTBLOCK_ARMV7
+	select ARM_ROMSTAGE_ARMV7
+	select ARM_RAMSTAGE_ARMV7
 	bool
 	default n
 
diff --git a/src/soc/samsung/exynos5420/Kconfig b/src/soc/samsung/exynos5420/Kconfig
index a60636a..d53064a 100644
--- a/src/soc/samsung/exynos5420/Kconfig
+++ b/src/soc/samsung/exynos5420/Kconfig
@@ -7,6 +7,9 @@
 	select RELOCATABLE_MODULES
 	select DYNAMIC_CBMEM
 	select CAR_MIGRATION
+	select ARM_BOOTBLOCK_ARMV7
+	select ARM_ROMSTAGE_ARMV7
+	select ARM_RAMSTAGE_ARMV7
 	bool
 	default n