1/**
2 * \file
3 * \brief ARMv7-A address space sizes and offsets
4 *
5 * The layout of the ARM virtual address space can be summarized as
6 * follows:
7 *
8 *
9 * User-space maps user-space programs. Physical memory maps all
10 * available physical memory (up to PADDR_SPACE_LIMIT). Kernel-space
11 * maps only the kernel text and data.
12 *
13 * This partition is static and can only be changed at compile-time.
14 *
15 */
16
17/*
18 * Copyright (c) 2007, 2008, 2009, 2012, 2016 ETH Zurich.
19 * All rights reserved.
20 *
21 * This file is distributed under the terms in the attached LICENSE file.
22 * If you do not find this file, copies can be found by writing to:
23 * ETH Zurich D-INFK, Universitaetstr. 6, CH-8092 Zurich. Attn: Systems Group.
24 */
25
26#ifndef OFFSETS_H
27#define OFFSETS_H
28
29/*
30 * Some general naming conventions:
31 *    *_SIZE is given in bytes.
32 *    *_SPACE_* refers to address space, physical or virtual
33 *    *_PHYS is a physical address.
34 *    *_LIMIT is a highest-possible address, physical or virtual
35 *    *_OFFSET is ....
36 */
37
38/**
39 * GEN_ADDR(bits) gives the size of address space possible with <bits>
40 * bits.
41 */
42#define GEN_ADDR(bits)          (((genpaddr_t)1) << bits)
43
44/**
45 * Absolute size of virtual address space. This is 32-bit on ARM.
46 */
47#define VADDR_SPACE_SIZE        GEN_ADDR(32);
48
49/**
50 * Absolute size of physical address space.
51 */
52#define PADDR_SPACE_SIZE        GEN_ADDR(32)
53
54/**
55 * Maximum physical address space mappable by the kernel.  Adjust this
56 * for a bigger physical address space.
57 */
58#define PADDR_SPACE_LIMIT       (PADDR_SPACE_SIZE - 1)
59
60/**
61 * The size of the kernel's RAM window.
62 */
63#define RAM_WINDOW_SIZE         GEN_ADDR(30)
64
65#ifndef KERNEL_LINK_BASE
66#define KERNEL_LINK_BASE        0
67#endif
68
69/**
70 * Kernel offset - the kernel window is mapped by TTBR1, from 2GB.
71 */
72#define KERNEL_OFFSET           0x80000000
73
74/**
75 * Static address space limit for the init user-space domain. The
76 * static space is used to map in code and static data of the init
77 * module, as well as all loaded multiboot modules. init can freely
78 * allocate dynamic memory as soon as it is running. This is 32 MBytes
79 * right now.
80 *
81 * You should make this constant a multiple of #BASE_PAGE_SIZE *
82 * #PTABLE_SIZE or you'll restrict init's static address space
83 * unneccessarily. init's lowest segment should also be based at these
84 * multiples or it restricts itself.
85 *
86 *
87 * NB 32MB is size of the fast context switch extension
88 * per-process address space.
89 */
90#define INIT_SPACE_LIMIT        (32 * 1024 * 1024)
91
92/**
93 * Base address of init address space in virtual memory. init should
94 * start at 4 MByte. The kernel maps in important structures at 2
95 * MByte. This address should be page-table size aligned (i.e. with 4
96 * KByte pages, a page table maps 2 MBytes. Thus, align it to
97 * multiples of 2 MBytes).
98 */
99#define INIT_VBASE              (2 * 1024 * 1024)
100
101/**
102 * Absolute offset of mapped physical memory within virtual address
103 * space.   Just to clarify, this means that RAM will be mapped into kernel
104 * virtual address space at this address (i.e. 2GB.).
105 */
106#define MEMORY_OFFSET           GEN_ADDR(31)
107// 2G (2 ** 31)
108
109/*
110 * Device offset to map devices in high memory.
111 */
112#define DEVICE_OFFSET			0xff000000
113
114/**
115 * The high exception vector address
116 */
117#define VECTORS_BASE            0xffff0000
118
119/**
120 * Kernel stack size -- 16KB
121 */
122#define KERNEL_STACK_SIZE       0x4000
123
124#ifndef __ASSEMBLER__
125
126/**
127 * Absolute start of RAM in physical memory.
128 */
129extern lpaddr_t phys_memory_start;
130
131static inline lvaddr_t local_phys_to_mem(lpaddr_t addr)
132{
133    // On the PandaBoard, this is a nop, because the physical memory is mapped
134    // at the same address in virtual memory
135    // i.e., MEMORY_OFFSET == phys_memory_start
136    if(PADDR_SPACE_LIMIT - phys_memory_start > 0) {
137        assert(addr < phys_memory_start + PADDR_SPACE_LIMIT);
138    }
139    return (lvaddr_t)(addr + ((lpaddr_t)MEMORY_OFFSET -
140                              (lpaddr_t)phys_memory_start));
141}
142
143/**
144 * Checks whether absolute local physical address `addr` is valid.
145 * \param addr Absolute local physical address
146 * \return True iff addr is a valid local physical address
147 */
148static inline bool local_phys_is_valid(lpaddr_t addr)
149{
150    return addr < phys_memory_start + PADDR_SPACE_LIMIT;
151}
152
153static inline lpaddr_t mem_to_local_phys(lvaddr_t addr)
154{
155    assert(addr >= MEMORY_OFFSET);
156    return (lpaddr_t)(addr - ((lvaddr_t)MEMORY_OFFSET -
157                              (lvaddr_t)phys_memory_start));
158}
159
160static inline lpaddr_t gen_phys_to_local_phys(genpaddr_t addr)
161{
162    //assert(addr < PADDR_SPACE_SIZE);
163    return (lpaddr_t)addr;
164}
165
166static inline genpaddr_t local_phys_to_gen_phys(lpaddr_t addr)
167{
168    return (genpaddr_t)addr;
169}
170
171/**
172 * Symbol: Start of kernel image. This symbol points to the start
173 * address of the kernel image.
174 */
175extern uint8_t kernel_first_byte;
176
177/**
178 * Symbol: End of kernel image. This symbol points to the end address
179 * of the kernel image.
180 */
181extern uint8_t kernel_text_final_byte;
182
183/**
184 * Symbol: End of kernel image. This symbol points to the end address
185 * of the kernel image.
186 */
187extern uint8_t kernel_final_byte;
188
189extern uint8_t kernel_elf_header;
190
191/**
192 * \brief The kernel stack.
193 *
194 * Declared in boot.S.
195 */
196extern uintptr_t kernel_stack[KERNEL_STACK_SIZE/sizeof(uintptr_t)];
197
198#endif  // __ASSEMBLER__
199
200/**
201 * Kernel interrupt jump table
202 */
203#define INT_HANDLER_TABLE	0xFFFF0100
204
205#endif  // OFFSETS_H
206