1 /*
2 * Copyright (c) 2009 Corey Tabaka
3 * Copyright (c) 2015-2018 Intel Corporation
4 * Copyright (c) 2016 Travis Geiselbrecht
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files
8 * (the "Software"), to deal in the Software without restriction,
9 * including without limitation the rights to use, copy, modify, merge,
10 * publish, distribute, sublicense, and/or sell copies of the Software,
11 * and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25 #include <arch/x86.h>
26 #include <arch/x86/mmu.h>
27 #include <assert.h>
28 #include <dev/interrupt/x86_interrupts.h>
29 #include <dev/timer/x86_pit.h>
30 #include <kernel/vm.h>
31 #include <string.h>
32
33 #ifdef WITH_KERNEL_VM
34 struct mmu_initial_mapping mmu_initial_mappings[] = {
35 /*
36 * This entry will be used in pmm arena
37 * structure member size will be updated in bootstrap code.
38 */
39 {
40 .phys = MEMBASE + KERNEL_LOAD_OFFSET,
41 .virt = KERNEL_BASE + KERNEL_LOAD_OFFSET,
42 .size = MEMSIZE,
43 .flags = MMU_INITIAL_MAPPING_FLAG_DYNAMIC,
44 .name = "ram",
45 },
46 {0, 0, 0, 0, 0}};
47
48 static pmm_arena_t ram_arena = {
49 .name = "ram",
50 .base = MEMBASE,
51 .size = 0,
52 .priority = 1,
53 .flags = PMM_ARENA_FLAG_KMAP,
54 };
55
platform_init_mmu_mappings(void)56 void platform_init_mmu_mappings(void) {
57 struct mmu_initial_mapping* m = mmu_initial_mappings;
58
59 for (uint i = 0; i < countof(mmu_initial_mappings); i++, m++) {
60 if (!(m->flags & MMU_INITIAL_MAPPING_FLAG_DYNAMIC))
61 continue;
62
63 if (strcmp(m->name, ram_arena.name) == 0) {
64 /* update ram_arena */
65 ram_arena.base = m->phys;
66 ram_arena.size = m->size;
67 ram_arena.flags = PMM_ARENA_FLAG_KMAP;
68
69 break;
70 }
71 }
72 pmm_add_arena(&ram_arena);
73 }
74 #endif
75
platform_early_init(void)76 void platform_early_init(void) {
77 /* initialize the interrupt controller */
78 x86_init_interrupts();
79
80 /* initialize the timer */
81 x86_init_pit();
82 }
83
platform_init(void)84 void platform_init(void) {}
85