1 /*
2  * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)
3  *
4  * SPDX-License-Identifier: GPL-2.0-only
5  */
6 
7 #pragma once
8 
9 #include <config.h>
10 #include <util.h>
11 #ifndef __ASSEMBLER__
12 #include <arch/machine/hardware.h>
13 #include <sel4/plat/api/constants.h>
14 #endif
15 
16 /*
17  * 0xffe00000 asid id slot (arm/arch/kernel/vspace.h)
18  * 0xfff00000 devices      (plat/machine/devices.h)
19  * 0xffff0000 vectors      (arch/machine/hardware.h)
20  * 0xffffc000 unused       (Used to be armv6 globals frame)
21  *
22  *
23  * 2^32 +-------------------+
24  *      | Kernel Page Table | --+
25  *      +-------------------+   |
26  *      |    Log Buffer     |   |
27  *      +-------------------+ PPTR_TOP
28  *      |                   |   |
29  *      |  Physical Memory  |   |
30  *      |       Window      |   |
31  *      |                   |   |
32  *      +-------------------+   |
33  *      |    Kernel ELF     |   |
34  *      +-------------------+ USER_TOP / PPTR_BASE / KERNEL_ELF_BASE
35  *      |                   |   |
36  *      |       User        |   |
37  *      |                   |   |
38  *  0x0 +-------------------+   |
39  *                              |
40  *                        +-----+
41  *                        |
42  *                        v
43  *         2^32 +-------------------+
44  *              |      Unused       |
45  *              +-------------------+
46  *              |      Vectors      |
47  *              +-------------------+
48  *              |  Kernel Devices   |
49  *  2^32 - 2^20 +-------------------+ KDEV_BASE
50  */
51 
52 /* last accessible virtual address in user space */
53 #define USER_TOP seL4_UserTop
54 
55 /* The first physical address to map into the kernel's physical memory
56  * window */
57 #define PADDR_BASE physBase
58 
59 /* The base address in virtual memory to use for the 1:1 physical memory
60  * mapping */
61 #define PPTR_BASE seL4_UserTop
62 
63 /* Calculate virtual address space reserved for dynamic log buffer mapping */
64 #ifdef CONFIG_KERNEL_LOG_BUFFER
65 #define PPTR_TOP UL_CONST(0xffe00000)
66 #define KS_LOG_PPTR PPTR_TOP
67 #else
68 #define PPTR_TOP UL_CONST(0xfff00000)
69 #endif
70 
71 /* The physical memory address to use for mapping the kernel ELF */
72 #define KERNEL_ELF_PADDR_BASE PADDR_BASE
73 
74 /* The base address in virtual memory to use for the kernel ELF mapping */
75 #define KERNEL_ELF_BASE (USER_TOP + (KERNEL_ELF_PADDR_BASE & MASK(22)))
76 
77 /* This is a page table mapping at the end of the virtual address space
78  * to map objects with 4KiB pages rather than 4MiB large pages. */
79 #define KERNEL_PT_BASE UL_CONST(0xfff00000)
80 
81 /* The base address in virtual memory to use for the kernel device
82  * mapping region. These are mapped in the kernel page table. */
83 #define KDEV_BASE KERNEL_PT_BASE
84 
85 #ifndef __ASSEMBLER__
86 /* It is required that USER_TOP must be aligned to at least 20 bits */
87 compile_assert(USER_TOP_correctly_aligned, IS_ALIGNED(USER_TOP, 20));
88 
89 #include <plat/machine/hardware.h>
90 #endif
91 
92