1 /*
2  * Copyright (c) 2012-2014 Travis Geiselbrecht
3  *
4  * Use of this source code is governed by a MIT-style
5  * license that can be found in the LICENSE file or at
6  * https://opensource.org/licenses/MIT
7  */
8 #include <lk/err.h>
9 #include <lk/debug.h>
10 #include <assert.h>
11 #include <lk/trace.h>
12 #include <arch/arm/mmu.h>
13 #include <dev/uart.h>
14 #include <dev/interrupt/arm_gic.h>
15 #include <dev/timer/arm_cortex_a9.h>
16 #include <kernel/vm.h>
17 #include <platform.h>
18 #include <platform/alterasoc.h>
19 #include "platform_p.h"
20 
21 /* initial memory mappings. parsed by start.S */
22 struct mmu_initial_mapping mmu_initial_mappings[] = {
23     /* 1GB of sdram space */
24     {
25         .phys = 0x0,
26         .virt = KERNEL_BASE,
27         .size = 1024*1024*1024,
28         .flags = 0,
29         .name = "memory"
30     },
31 
32     /* HPS peripherals */
33     {
34         .phys = 0xfc000000,
35         .virt = 0xfc000000,
36         .size = 0x04000000,
37         .flags = MMU_INITIAL_MAPPING_FLAG_DEVICE,
38         .name = "hps_periphs"
39     },
40 
41     /* identity map to let the boot code run */
42     {
43         .phys = 0,
44         .virt = 0,
45         .size = 1024*1024*1024,
46         .flags = MMU_INITIAL_MAPPING_TEMPORARY
47     },
48 
49     /* null entry to terminate the list */
50     { 0 }
51 };
52 
53 static pmm_arena_t sdram_arena = {
54     .name = "sdram",
55     .base = 0,
56     .size = MEMSIZE,
57     .flags = PMM_ARENA_FLAG_KMAP
58 };
59 
platform_init_mmu_mappings(void)60 void platform_init_mmu_mappings(void) {
61 }
62 
platform_early_init(void)63 void platform_early_init(void) {
64     uart_init_early();
65 
66     printf("stat 0x%x\n", *REG32(0xffd05000));
67 
68     /* initialize the interrupt controller */
69     arm_gic_init();
70 
71     /* initialize the timer block */
72     arm_cortex_a9_timer_init(CPUPRIV_BASE, TIMER_CLOCK_FREQ);
73 
74     pmm_add_arena(&sdram_arena);
75 
76     /* start the secondary cpu */
77     *REG32(0xffd05010) = 0;
78 }
79 
platform_init(void)80 void platform_init(void) {
81     uart_init();
82 }
83 
84