1 /*
2  * Copyright (c) 2018 The Fuchsia Authors
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 
9 #include <arch/arm64.h>
10 #include <lk/trace.h>
11 #include <assert.h>
12 #include <lk/err.h>
13 #include <lk/bits.h>
14 #include <kernel/spinlock.h>
15 #include <kernel/thread.h>
16 #include <kernel/mp.h>
17 #include <platform/interrupts.h>
18 #include <lk/init.h>
19 #include <kernel/vm.h>
20 #include <kernel/spinlock.h>
21 #include <dev/timer/arm_generic.h>
22 #include <platform.h>
23 #include <dev/interrupt/arm_gic.h>
24 #include <dev/timer/arm_generic.h>
25 #include <platform/s912d.h>
26 #include <dev/uart.h>
27 
28 typedef struct arm64_iframe_long arm_platform_iframe_t;
29 
30 /* initial memory mappings. parsed by start.S */
31 struct mmu_initial_mapping mmu_initial_mappings[] = {
32     {
33         .phys = SDRAM_BASE,
34         .virt = KERNEL_BASE,
35         .size = MEMSIZE,
36         .flags = 0,
37         .name = "memory"
38     },
39 
40     /* peripherals */
41     {
42         .phys = AML_S912D_PERIPH_BASE_PHYS,
43         .virt = AML_S912D_PERIPH_BASE_VIRT,
44         .size = AML_S912D_PERIPH_BASE_SIZE,
45         .flags = MMU_INITIAL_MAPPING_FLAG_DEVICE,
46         .name = "peripherals"
47     },
48     /* null entry to terminate the list */
49     { 0 }
50 };
51 
52 static pmm_arena_t arena = {
53     .name = "sdram",
54     .base = SDRAM_BASE,
55     .size = MEMSIZE,
56     .flags = PMM_ARENA_FLAG_KMAP,
57 };
58 
59 #define DEBUG_UART 0
60 
platform_dputc(char c)61 void platform_dputc(char c) {
62     if (c == '\n')
63         uart_putc(DEBUG_UART, '\r');
64     uart_putc(DEBUG_UART, c);
65 }
66 
platform_dgetc(char * c,bool wait)67 int platform_dgetc(char *c, bool wait) {
68     int ret = uart_getc(DEBUG_UART, wait);
69     if (ret == -1)
70         return -1;
71     *c = ret;
72     return 0;
73 }
74 
platform_init(void)75 void platform_init(void) {
76     uart_init();
77 
78 }
79 
platform_early_init(void)80 void platform_early_init(void) {
81     uart_init_early();
82 
83     /* initialize the interrupt controller */
84     arm_gic_init();
85 
86     arm_generic_timer_init(30, 0);
87 
88     pmm_add_arena(&arena);
89 
90     // TODO: Reserve memory regions if needed
91 }
92 
93