1 /*
2 * Copyright (c) 2022 Intel Corporation
3 * SPDX-License-Identifier: Apache-2.0
4 * Description:
5 * Adding support for Cyclone V SoC FPGA, buildi mmu table,
6 * creating function to reserve the vector memory area
7 */
8
9 #include <zephyr/device.h>
10 #include <zephyr/devicetree.h>
11 #include <zephyr/init.h>
12 #include <zephyr/sys/util.h>
13 #include <mmu.h>
14 #include <zephyr/arch/arm/mmu/arm_mmu.h>
15 #include "soc.h"
16
17 #include <cmsis_core.h>
18
arch_reserved_pages_update(void)19 void arch_reserved_pages_update(void)
20 {
21 /* Function created to reserve the vector table */
22 uintptr_t addr = 0;
23 size_t len = 0x1000;
24
25 uintptr_t pos = ROUND_DOWN(addr, CONFIG_MMU_PAGE_SIZE);
26 uintptr_t end = ROUND_UP(addr + len, CONFIG_MMU_PAGE_SIZE);
27
28 for (; pos < end; pos += CONFIG_MMU_PAGE_SIZE) {
29 if (!k_mem_is_page_frame(pos)) {
30 continue;
31 }
32 struct k_mem_page_frame *pf = k_mem_phys_to_page_frame(pos);
33
34 k_mem_page_frame_set(pf, K_MEM_PAGE_FRAME_RESERVED);
35 }
36 }
37
38 static const struct arm_mmu_region mmu_regions[] = {
39
40 MMU_REGION_FLAT_ENTRY("vectors",
41 0x00000000,
42 0x1000,
43 MT_STRONGLY_ORDERED | MPERM_R | MPERM_X),
44
45 MMU_REGION_FLAT_ENTRY("mpcore",
46 0xF8F00000,
47 0x2000,
48 MT_STRONGLY_ORDERED | MPERM_R | MPERM_W),
49
50 MMU_REGION_FLAT_ENTRY("devices",
51 0xFF000000,
52 0x1000000,
53 MT_DEVICE | MATTR_SHARED | MPERM_R | MPERM_W
54 /* Adding Executable property to devices when using for testing */
55 #ifndef CONFIG_ASSERT
56 | MPERM_X
57 #endif
58 ),
59 };
60
61 const struct arm_mmu_config mmu_config = {
62 .num_regions = ARRAY_SIZE(mmu_regions),
63 .mmu_regions = mmu_regions,
64 };
65
66 /**
67 * @brief Basic hardware initialization of the Cyclone V SoC FPGA
68 *
69 * Performs the basic initialization of the Cyclone V SoC FPGA.
70 *
71 * @return 0
72 */
soc_early_init_hook(void)73 void soc_early_init_hook(void)
74 {
75 unsigned int sctlr = __get_SCTLR(); /* modifying some registers prior to initialization */
76
77 sctlr &= ~SCTLR_A_Msk;
78 __set_SCTLR(sctlr);
79 __set_VBAR(0);
80 }
81 /* EOF */
82