2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2016-05-08 06:30:16 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2016 Beniamino Galvani <b.galvani@gmail.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2018-03-04 16:20:11 +00:00
|
|
|
#include <linux/libfdt.h>
|
2016-05-08 06:30:16 +00:00
|
|
|
#include <linux/err.h>
|
2018-04-11 15:13:45 +00:00
|
|
|
#include <asm/arch/gx.h>
|
2016-05-08 06:30:17 +00:00
|
|
|
#include <asm/arch/sm.h>
|
2016-05-08 06:30:16 +00:00
|
|
|
#include <asm/armv8/mmu.h>
|
|
|
|
#include <asm/unaligned.h>
|
2017-11-27 09:35:46 +00:00
|
|
|
#include <linux/sizes.h>
|
|
|
|
#include <efi_loader.h>
|
|
|
|
#include <asm/io.h>
|
2016-05-08 06:30:16 +00:00
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
|
|
|
int dram_init(void)
|
|
|
|
{
|
|
|
|
const fdt64_t *val;
|
|
|
|
int offset;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
offset = fdt_path_offset(gd->fdt_blob, "/memory");
|
|
|
|
if (offset < 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
val = fdt_getprop(gd->fdt_blob, offset, "reg", &len);
|
|
|
|
if (len < sizeof(*val) * 2)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* Use unaligned access since cache is still disabled */
|
|
|
|
gd->ram_size = get_unaligned_be64(&val[1]);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-11-27 09:35:46 +00:00
|
|
|
phys_size_t get_effective_memsize(void)
|
2016-05-08 06:30:16 +00:00
|
|
|
{
|
2017-11-27 09:35:46 +00:00
|
|
|
/* Size is reported in MiB, convert it in bytes */
|
2018-04-11 15:13:45 +00:00
|
|
|
return ((readl(GX_AO_SEC_GP_CFG0) & GX_AO_MEM_SIZE_MASK)
|
|
|
|
>> GX_AO_MEM_SIZE_SHIFT) * SZ_1M;
|
2017-11-27 09:35:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void meson_board_add_reserved_memory(void *fdt, u64 start, u64 size)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = fdt_add_mem_rsv(fdt, start, size);
|
|
|
|
if (ret)
|
|
|
|
printf("Could not reserve zone @ 0x%llx\n", start);
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_EFI_LOADER)) {
|
|
|
|
efi_add_memory_map(start,
|
|
|
|
ALIGN(size, EFI_PAGE_SIZE) >> EFI_PAGE_SHIFT,
|
|
|
|
EFI_RESERVED_MEMORY_TYPE, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void meson_gx_init_reserved_memory(void *fdt)
|
|
|
|
{
|
|
|
|
u64 bl31_size, bl31_start;
|
|
|
|
u64 bl32_size, bl32_start;
|
|
|
|
u32 reg;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get ARM Trusted Firmware reserved memory zones in :
|
|
|
|
* - AO_SEC_GP_CFG3: bl32 & bl31 size in KiB, can be 0
|
|
|
|
* - AO_SEC_GP_CFG5: bl31 physical start address, can be NULL
|
|
|
|
* - AO_SEC_GP_CFG4: bl32 physical start address, can be NULL
|
|
|
|
*/
|
|
|
|
|
2018-04-11 15:13:45 +00:00
|
|
|
reg = readl(GX_AO_SEC_GP_CFG3);
|
2017-11-27 09:35:46 +00:00
|
|
|
|
2018-04-11 15:13:45 +00:00
|
|
|
bl31_size = ((reg & GX_AO_BL31_RSVMEM_SIZE_MASK)
|
|
|
|
>> GX_AO_BL31_RSVMEM_SIZE_SHIFT) * SZ_1K;
|
|
|
|
bl32_size = (reg & GX_AO_BL32_RSVMEM_SIZE_MASK) * SZ_1K;
|
2017-11-27 09:35:46 +00:00
|
|
|
|
2018-04-11 15:13:45 +00:00
|
|
|
bl31_start = readl(GX_AO_SEC_GP_CFG5);
|
|
|
|
bl32_start = readl(GX_AO_SEC_GP_CFG4);
|
2017-11-27 09:35:46 +00:00
|
|
|
|
|
|
|
/*
|
2018-04-11 15:13:45 +00:00
|
|
|
* Early Meson GX Firmware revisions did not provide the reserved
|
2017-11-27 09:35:46 +00:00
|
|
|
* memory zones in the registers, keep fixed memory zone handling.
|
|
|
|
*/
|
2018-04-11 15:13:45 +00:00
|
|
|
if (IS_ENABLED(CONFIG_MESON_GX) &&
|
2017-11-27 09:35:46 +00:00
|
|
|
!reg && !bl31_start && !bl32_start) {
|
|
|
|
bl31_start = 0x10000000;
|
|
|
|
bl31_size = 0x200000;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add first 16MiB reserved zone */
|
2018-04-11 15:13:45 +00:00
|
|
|
meson_board_add_reserved_memory(fdt, 0, GX_FIRMWARE_MEM_SIZE);
|
2017-11-27 09:35:46 +00:00
|
|
|
|
|
|
|
/* Add BL31 reserved zone */
|
|
|
|
if (bl31_start && bl31_size)
|
|
|
|
meson_board_add_reserved_memory(fdt, bl31_start, bl31_size);
|
|
|
|
|
|
|
|
/* Add BL32 reserved zone */
|
|
|
|
if (bl32_start && bl32_size)
|
|
|
|
meson_board_add_reserved_memory(fdt, bl32_start, bl32_size);
|
2016-05-08 06:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void reset_cpu(ulong addr)
|
|
|
|
{
|
2016-08-16 19:08:46 +00:00
|
|
|
psci_system_reset();
|
2016-05-08 06:30:16 +00:00
|
|
|
}
|
|
|
|
|
2018-04-11 15:13:45 +00:00
|
|
|
static struct mm_region gx_mem_map[] = {
|
2016-05-08 06:30:16 +00:00
|
|
|
{
|
2016-06-24 23:46:22 +00:00
|
|
|
.virt = 0x0UL,
|
|
|
|
.phys = 0x0UL,
|
2016-05-08 06:30:16 +00:00
|
|
|
.size = 0x80000000UL,
|
|
|
|
.attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
|
|
|
|
PTE_BLOCK_INNER_SHARE
|
|
|
|
}, {
|
2016-06-24 23:46:22 +00:00
|
|
|
.virt = 0x80000000UL,
|
|
|
|
.phys = 0x80000000UL,
|
2016-05-08 06:30:16 +00:00
|
|
|
.size = 0x80000000UL,
|
|
|
|
.attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
|
|
|
|
PTE_BLOCK_NON_SHARE |
|
|
|
|
PTE_BLOCK_PXN | PTE_BLOCK_UXN
|
|
|
|
}, {
|
|
|
|
/* List terminator */
|
|
|
|
0,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-04-11 15:13:45 +00:00
|
|
|
struct mm_region *mem_map = gx_mem_map;
|