Files
lk/platform/amlogic-s912d/platform.c
2018-03-22 14:48:15 -07:00

116 lines
3.0 KiB
C

/*
* Copyright (c) 2018 The Fuchsia Authors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <arch/arm64.h>
#include <trace.h>
#include <assert.h>
#include <err.h>
#include <bits.h>
#include <kernel/spinlock.h>
#include <kernel/thread.h>
#include <kernel/mp.h>
#include <platform/interrupts.h>
#include <lk/init.h>
#include <kernel/vm.h>
#include <kernel/spinlock.h>
#include <dev/timer/arm_generic.h>
#include <platform.h>
#include <dev/interrupt/arm_gic.h>
#include <dev/timer/arm_generic.h>
#include <platform/s912d.h>
#include <dev/uart.h>
typedef struct arm64_iframe_long arm_platform_iframe_t;
/* initial memory mappings. parsed by start.S */
struct mmu_initial_mapping mmu_initial_mappings[] = {
{
.phys = SDRAM_BASE,
.virt = KERNEL_BASE,
.size = MEMSIZE,
.flags = 0,
.name = "memory"
},
/* peripherals */
{
.phys = AML_S912D_PERIPH_BASE_PHYS,
.virt = AML_S912D_PERIPH_BASE_VIRT,
.size = AML_S912D_PERIPH_BASE_SIZE,
.flags = MMU_INITIAL_MAPPING_FLAG_DEVICE,
.name = "peripherals"
},
/* null entry to terminate the list */
{ 0 }
};
static pmm_arena_t arena = {
.name = "sdram",
.base = SDRAM_BASE,
.size = MEMSIZE,
.flags = PMM_ARENA_FLAG_KMAP,
};
#define DEBUG_UART 0
void platform_dputc(char c)
{
if (c == '\n')
uart_putc(DEBUG_UART, '\r');
uart_putc(DEBUG_UART, c);
}
int platform_dgetc(char *c, bool wait)
{
int ret = uart_getc(DEBUG_UART, wait);
if (ret == -1)
return -1;
*c = ret;
return 0;
}
void platform_init(void)
{
uart_init();
}
void platform_early_init(void)
{
uart_init_early();
/* initialize the interrupt controller */
arm_gic_init();
arm_generic_timer_init(30, 0);
pmm_add_arena(&arena);
// TODO: Reserve memory regions if needed
struct list_node list = LIST_INITIAL_VALUE(list);
pmm_alloc_range(0x01080000, 0x01A80000 / PAGE_SIZE, &list);
}