summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorMichael Tretter <m.tretter@pengutronix.de>2020-10-21 16:51:39 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2020-10-22 09:30:49 +0200
commit92e123a3d66bff3f773f0c2b5eec4463aca34052 (patch)
tree19e612e83fe9162a91b89914d236514276488677 /include
parent7ef4cf1a432257f99bee06232929e76292de47ae (diff)
downloadbarebox-92e123a3d66bff3f773f0c2b5eec4463aca34052.tar.gz
barebox-92e123a3d66bff3f773f0c2b5eec4463aca34052.tar.xz
ARM: mmu64: allow to disable null pointer trap on zero page
Barebox uses the zero page to trap NULL pointer dereferences. However, if the SDRAM starts at address 0x0, this makes the first page of the SDRAM inaccessible and makes it impossible to load images to offset 0x0 in the SDRAM. Trapping NULL pointer dereferences on such systems is still desirable. Therefore, add a function to disable the traps if accessing the zero page is necessary and to re-enable the traps after the access is done. The zero_page_memcpy function simplifies copying to the SDRAM, because this is the most common required functionality, but memtest also accesses the zero page and does not use memcpy. Signed-off-by: Michael Tretter <m.tretter@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'include')
-rw-r--r--include/zero_page.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/include/zero_page.h b/include/zero_page.h
new file mode 100644
index 0000000000..ad6861f240
--- /dev/null
+++ b/include/zero_page.h
@@ -0,0 +1,54 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __ZERO_PAGE_H
+#define __ZERO_PAGE_H
+
+#include <common.h>
+
+#if defined CONFIG_ARCH_HAS_ZERO_PAGE
+
+/*
+ * zero_page_faulting - fault when accessing the zero page
+ */
+void zero_page_faulting(void);
+
+/*
+ * zero_page_access - allow accesses to the zero page
+ *
+ * Disable the null pointer trap on the zero page if access to the zero page
+ * is actually required. Disable the trap with care and re-enable it
+ * immediately after the access to properly trap null pointers.
+ */
+void zero_page_access(void);
+
+#else
+
+static inline void zero_page_faulting(void)
+{
+}
+
+static inline void zero_page_access(void)
+{
+}
+
+#endif
+
+static inline bool zero_page_contains(unsigned long addr)
+{
+ return addr < PAGE_SIZE;
+}
+
+/*
+ * zero_page_memcpy - copy to or from an address located in the zero page
+ */
+static inline void *zero_page_memcpy(void *dest, const void *src, size_t count)
+{
+ void *ret;
+
+ zero_page_access();
+ ret = memcpy(dest, src, count);
+ zero_page_faulting();
+
+ return ret;
+}
+
+#endif /* __ZERO_PAGE_H */