mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Andrey Smirnov <andrew.smirnov@gmail.com>
To: barebox@lists.infradead.org
Cc: Andrey Smirnov <andrew.smirnov@gmail.com>
Subject: [PATCH 3/6] ARM: Fix exception table setup in MMU-less mode
Date: Thu, 31 Dec 2015 21:58:35 -0800	[thread overview]
Message-ID: <1451627918-31967-3-git-send-email-andrew.smirnov@gmail.com> (raw)
In-Reply-To: <1451627918-31967-1-git-send-email-andrew.smirnov@gmail.com>

Add code necessary for correct initialization of exception vector
table when MMU is disabled.

Note: Please be aware that non ARMv7 implementation of this
functionality was not fully tested due to the lack of any such
hardware. It should theoretically work, but only testing that I did
was to test place_vector_table() failure path (the best I could do on
a i.MX6)

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 arch/arm/cpu/Makefile |   6 +++
 arch/arm/cpu/no-mmu.c | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 126 insertions(+)
 create mode 100644 arch/arm/cpu/no-mmu.c

diff --git a/arch/arm/cpu/Makefile b/arch/arm/cpu/Makefile
index 418bcab..f708e8f 100644
--- a/arch/arm/cpu/Makefile
+++ b/arch/arm/cpu/Makefile
@@ -11,6 +11,12 @@ obj-$(CONFIG_CMD_ARM_MMUINFO) += mmuinfo.o
 obj-$(CONFIG_OFDEVICE) += dtb.o
 obj-$(CONFIG_MMU) += mmu.o cache.o mmu-early.o
 pbl-$(CONFIG_MMU) += mmu-early.o
+
+ifeq ($(CONFIG_MMU),)
+obj-y += no-mmu.o
+pbl-y += no-mmu.o
+endif
+
 obj-$(CONFIG_CPU_32v4T) += cache-armv4.o
 pbl-$(CONFIG_CPU_32v4T) += cache-armv4.o
 obj-$(CONFIG_CPU_32v5) += cache-armv5.o
diff --git a/arch/arm/cpu/no-mmu.c b/arch/arm/cpu/no-mmu.c
new file mode 100644
index 0000000..591cc2c
--- /dev/null
+++ b/arch/arm/cpu/no-mmu.c
@@ -0,0 +1,120 @@
+/*
+ * Copyright (c) 2015 Zodiac Inflight Innovation
+ * Author: Andrey Smirnov <andrew.smirnov@gmail.com>
+ *
+ * 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.
+ *
+ */
+
+#define pr_fmt(fmt)	"nommu: " fmt
+
+#include <common.h>
+#include <dma-dir.h>
+#include <init.h>
+#include <mmu.h>
+#include <errno.h>
+#include <linux/sizes.h>
+#include <asm/memory.h>
+#include <asm/barebox-arm.h>
+#include <asm/system.h>
+#include <asm/cache.h>
+#include <memory.h>
+#include <asm/system_info.h>
+#include <debug_ll.h>
+
+
+#define __exceptions_size (__exceptions_stop - __exceptions_start)
+
+#if __LINUX_ARM_ARCH__ >= 7
+
+static int nommu_v7_vectors_init(void)
+{
+	void *vectors;
+	u32 cr;
+
+	/*
+	   High vectors cannot be re-mapped, so we have to use normal
+	   vectors
+	 */
+	cr = get_cr();
+	cr &= ~CR_V;
+	set_cr(cr);
+
+	arm_fixup_vectors();
+
+	vectors = xmemalign(PAGE_SIZE, PAGE_SIZE);
+	memset(vectors, 0, PAGE_SIZE);
+	memcpy(vectors, __exceptions_start, __exceptions_size);
+
+	set_vbar((unsigned int)vectors);
+
+	return 0;
+}
+mmu_initcall(nommu_v7_vectors_init);
+
+#else
+
+#warning "This code has seen only rudimentary testing (only failure path). Proceed with caution"
+
+static struct resource *place_vector_table(void)
+{
+	int i;
+	struct resource *vectors = NULL;
+	resource_size_t addr[2] = { 0x00000000, 0xFFFF0000 };
+
+	for (i = 0; i < ARRAY_SIZE(addr); i++) {
+		vectors = request_sdram_region("exceptions",
+					       addr[i],
+					       __exceptions_size);
+		if (vectors)
+			break;
+	}
+
+	return vectors;
+}
+
+static int nommu_v4_vectors_init(void)
+{
+	u32 cr;
+	struct resource *vectors;
+
+	vectors = place_vector_table();
+	if (!vectors) {
+		pr_crit("Critical Error: Can't place exception vector table\n");
+		return 0;
+	}
+
+	cr = get_cr();
+
+	if (vectors->start) {
+		cr |= CR_V;
+		set_cr(cr);
+
+		if (!(get_cr() & CR_V)) {
+			pr_crit("Critical Error: "
+				"High vector table is unavailble\n");
+			release_sdram_region(vectors);
+			return 0;
+		}
+	} else {
+		cr &= ~CR_V;
+		set_cr(cr);
+	}
+
+	arm_fixup_vectors();
+
+	memcpy((void *)vectors->start,
+	       __exceptions_start, resource_size(vectors));
+
+	return 0;
+}
+mmu_initcall(nommu_v4_vectors_init);
+
+#endif
--
2.5.0

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2016-01-01  5:59 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-01  5:58 [PATCH 1/6] ARM: asm: Add convenience fucntions to access VBAR Andrey Smirnov
2016-01-01  5:58 ` [PATCH 2/6] ARM: mmu: Add VBAR setup Andrey Smirnov
2016-01-04  9:04   ` Sascha Hauer
2016-01-01  5:58 ` Andrey Smirnov [this message]
2016-01-04  9:27   ` [PATCH 3/6] ARM: Fix exception table setup in MMU-less mode Sascha Hauer
2016-01-04 17:01     ` Andrey Smirnov
2016-01-05  7:40       ` Sascha Hauer
2016-01-01  5:58 ` [PATCH 4/6] i.MX6: pci: Replace magic number with a named constant Andrey Smirnov
2016-01-07  9:04   ` Lucas Stach
2016-01-08  7:53     ` Sascha Hauer
2016-01-01  5:58 ` [PATCH 5/6] i.MX6: pci: Reconcile imx6_pcie_start_link with the kernel code Andrey Smirnov
2016-01-07  9:08   ` Lucas Stach
2016-01-01  5:58 ` [PATCH 6/6] i.MX6: pci: Avoid aborts when asserting PCIe reset Andrey Smirnov
2016-01-04  9:30   ` Sascha Hauer
2016-01-07  9:13   ` Lucas Stach

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1451627918-31967-3-git-send-email-andrew.smirnov@gmail.com \
    --to=andrew.smirnov@gmail.com \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox