1/*
2 * Copyright 2014, General Dynamics C4 Systems
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 */
6
7#pragma once
8
9#include <config.h>
10#include <util.h>
11#include <arch/kernel/tlb_bitmap_defs.h>
12
13/*
14 * 2^32 +-------------------+
15 *      | Kernel Page Table | --+
16 *      +-------------------+   |
17 *      |    TLB Bitmaps    |   |
18 *      +-------------------+   |
19 *      |    Log Buffer     |   |
20 *      +-------------------+ PPTR_TOP
21 *      |                   |   |
22 *      |  Physical Memory  |   |
23 *      |       Window      |   |
24 *      |                   |   |
25 *      +-------------------+   |
26 *      |    Kernel ELF     |   |
27 *      +-------------------+ USER_TOP / PPTR_BASE / KERNEL_ELF_BASE
28 *      |                   |   |
29 *      |       User        |   |
30 *      |                   |   |
31 *  0x0 +-------------------+   |
32 *                              |
33 *                        +-----+
34 *                        |
35 *                        v
36 *         2^32 +-------------------+
37 *              |  Kernel Devices   |
38 *  2^32 - 2^22 +-------------------+ KDEV_BASE
39 */
40
41/* WARNING: some of these constants are also defined in linker.lds */
42
43/* The mask here, 0xFFC00000 represents the mask for a 4MiB page. */
44#define USER_TOP (PPTR_BASE & UL_CONST(0xFFC00000))
45
46/* The first physical address to map into the kernel's physical memory
47 * window */
48#define PADDR_BASE UL_CONST(0x00000000)
49
50/* The base address in virtual memory to use for the 1:1 physical memory
51 * mapping */
52#define PPTR_BASE UL_CONST(0xe0000000)
53
54/* This is a page table mapping at the end of the virtual address space
55 * to map objects with 4KiB pages rather than 4MiB large pages. */
56#define KERNEL_PT_BASE UL_CONST(0xffc00000)
57
58/* Calculate virtual address space reserved for TLB Bitmap. ROOT_ENTRIES
59 * will be zero in the case where the bitmap is unused */
60#define TLBBITMAP_PD_RESERVED (TLBBITMAP_ROOT_ENTRIES * BIT(seL4_LargePageBits))
61
62/* Calculate virtual address space reserved for dynamic log buffer mapping */
63#ifdef CONFIG_KERNEL_LOG_BUFFER
64#define LOGBUFFER_PD_RESERVED BIT(seL4_LargePageBits)
65#else
66#define LOGBUFFER_PD_RESERVED UL_CONST(0)
67#endif
68
69/* TLB bitmap is in the PD slots before the kernel page table */
70#define TLBBITMAP_PPTR (KERNEL_PT_BASE - TLBBITMAP_PD_RESERVED)
71/* Before TLB bitmap is the log buffer */
72#define KS_LOG_PPTR (TLBBITMAP_PPTR - LOGBUFFER_PD_RESERVED)
73/* The log buffer marks the end of the kernel physical memory window */
74#define PPTR_TOP KS_LOG_PPTR
75
76/* The physical memory address to use for mapping the kernel ELF */
77#define KERNEL_ELF_PADDR_BASE UL_CONST(0x00100000)
78
79/* The base address in virtual memory to use for the kernel ELF mapping */
80#define KERNEL_ELF_BASE (PPTR_BASE + KERNEL_ELF_PADDR_BASE)
81
82/* The base address in virtual memory to use for the kernel device
83 * mapping region. These are mapped in the kernel page table. */
84#define KDEV_BASE KERNEL_PT_BASE
85
86/* For a 32-bit system there is no difference in how we translates
87 * physical address for the kernel symbols or anything else */
88#define paddr_to_kpptr(x) paddr_to_pptr(x)
89#define kpptr_to_paddr(x) pptr_to_paddr(x)
90