blob: ea77afb564e63a6dea79fd3fd340902ede4ffa6c [file] [log] [blame]
Samuel Hollandb8566642017-08-12 04:07:39 -05001/*
2 * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Andre Przywarac2366b92018-06-22 00:47:08 +01007#include <mmio.h>
Samuel Hollandb8566642017-08-12 04:07:39 -05008#include <platform.h>
9#include <platform_def.h>
10#include <sunxi_def.h>
Andre Przywara456208a2018-10-14 12:02:02 +010011#include <sunxi_private.h>
Samuel Hollandb8566642017-08-12 04:07:39 -050012#include <xlat_tables_v2.h>
13
Samuel Hollandb8566642017-08-12 04:07:39 -050014static mmap_region_t sunxi_mmap[PLATFORM_MMAP_REGIONS + 1] = {
Samuel Hollandb8566642017-08-12 04:07:39 -050015 MAP_REGION_FLAT(SUNXI_SRAM_BASE, SUNXI_SRAM_SIZE,
16 MT_MEMORY | MT_RW | MT_SECURE),
17 MAP_REGION_FLAT(SUNXI_DEV_BASE, SUNXI_DEV_SIZE,
18 MT_DEVICE | MT_RW | MT_SECURE),
Andre Przywarab3fddff2018-09-20 21:13:55 +010019 MAP_REGION(SUNXI_DRAM_BASE, SUNXI_DRAM_VIRT_BASE, SUNXI_DRAM_SEC_SIZE,
20 MT_MEMORY | MT_RW | MT_SECURE),
21 MAP_REGION(PLAT_SUNXI_NS_IMAGE_OFFSET,
22 SUNXI_DRAM_VIRT_BASE + SUNXI_DRAM_SEC_SIZE,
23 SUNXI_DRAM_MAP_SIZE,
24 MT_MEMORY | MT_RO | MT_NS),
Samuel Hollandb8566642017-08-12 04:07:39 -050025 {},
26};
27
28unsigned int plat_get_syscnt_freq2(void)
29{
30 return SUNXI_OSC24M_CLK_IN_HZ;
31}
32
33uintptr_t plat_get_ns_image_entrypoint(void)
34{
35#ifdef PRELOADED_BL33_BASE
36 return PRELOADED_BL33_BASE;
37#else
38 return PLAT_SUNXI_NS_IMAGE_OFFSET;
39#endif
40}
41
42void sunxi_configure_mmu_el3(int flags)
43{
44 mmap_add_region(BL31_BASE, BL31_BASE,
45 BL31_LIMIT - BL31_BASE,
46 MT_MEMORY | MT_RW | MT_SECURE);
47 mmap_add_region(BL_CODE_BASE, BL_CODE_BASE,
48 BL_CODE_END - BL_CODE_BASE,
49 MT_CODE | MT_SECURE);
50 mmap_add_region(BL_RO_DATA_BASE, BL_RO_DATA_BASE,
51 BL_RO_DATA_END - BL_RO_DATA_BASE,
52 MT_RO_DATA | MT_SECURE);
Samuel Hollandb8566642017-08-12 04:07:39 -050053 mmap_add(sunxi_mmap);
54 init_xlat_tables();
55
56 enable_mmu_el3(0);
57}
Andre Przywarac2366b92018-06-22 00:47:08 +010058
59#define SRAM_VER_REG (SUNXI_SYSCON_BASE + 0x24)
60uint16_t sunxi_read_soc_id(void)
61{
62 uint32_t reg = mmio_read_32(SRAM_VER_REG);
63
64 /* Set bit 15 to prepare for the SOCID read. */
65 mmio_write_32(SRAM_VER_REG, reg | BIT(15));
66
67 reg = mmio_read_32(SRAM_VER_REG);
68
69 /* deactivate the SOCID access again */
70 mmio_write_32(SRAM_VER_REG, reg & ~BIT(15));
71
72 return reg >> 16;
73}