2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2015-01-15 09:01:51 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2014 - 2015 Xilinx, Inc.
|
|
|
|
* Michal Simek <michal.simek@xilinx.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2020-05-10 17:40:02 +00:00
|
|
|
#include <init.h>
|
2019-12-28 17:44:59 +00:00
|
|
|
#include <time.h>
|
2015-01-15 09:01:51 +00:00
|
|
|
#include <asm/arch/hardware.h>
|
|
|
|
#include <asm/arch/sys_proto.h>
|
2016-03-04 00:09:49 +00:00
|
|
|
#include <asm/armv8/mmu.h>
|
2020-05-10 17:39:56 +00:00
|
|
|
#include <asm/cache.h>
|
2015-01-15 09:01:51 +00:00
|
|
|
#include <asm/io.h>
|
2019-09-27 10:37:01 +00:00
|
|
|
#include <zynqmp_firmware.h>
|
2020-03-29 17:57:40 +00:00
|
|
|
#include <asm/cache.h>
|
2015-01-15 09:01:51 +00:00
|
|
|
|
|
|
|
#define ZYNQ_SILICON_VER_MASK 0xF000
|
|
|
|
#define ZYNQ_SILICON_VER_SHIFT 12
|
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2018-04-20 07:00:40 +00:00
|
|
|
/*
|
|
|
|
* Number of filled static entries and also the first empty
|
|
|
|
* slot in zynqmp_mem_map.
|
|
|
|
*/
|
|
|
|
#define ZYNQMP_MEM_MAP_USED 4
|
|
|
|
|
2018-01-12 10:05:46 +00:00
|
|
|
#if !defined(CONFIG_ZYNQMP_NO_DDR)
|
2018-04-20 07:00:40 +00:00
|
|
|
#define DRAM_BANKS CONFIG_NR_DRAM_BANKS
|
|
|
|
#else
|
|
|
|
#define DRAM_BANKS 0
|
2018-01-12 10:05:46 +00:00
|
|
|
#endif
|
2018-04-20 07:00:40 +00:00
|
|
|
|
|
|
|
#if defined(CONFIG_DEFINE_TCM_OCM_MMAP)
|
|
|
|
#define TCM_MAP 1
|
|
|
|
#else
|
|
|
|
#define TCM_MAP 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* +1 is end of list which needs to be empty */
|
|
|
|
#define ZYNQMP_MEM_MAP_MAX (ZYNQMP_MEM_MAP_USED + DRAM_BANKS + TCM_MAP + 1)
|
|
|
|
|
|
|
|
static struct mm_region zynqmp_mem_map[ZYNQMP_MEM_MAP_MAX] = {
|
2018-01-12 10:05:46 +00:00
|
|
|
{
|
2016-06-24 23:46:22 +00:00
|
|
|
.virt = 0x80000000UL,
|
|
|
|
.phys = 0x80000000UL,
|
2016-03-04 00:09:49 +00:00
|
|
|
.size = 0x70000000UL,
|
|
|
|
.attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
|
|
|
|
PTE_BLOCK_NON_SHARE |
|
|
|
|
PTE_BLOCK_PXN | PTE_BLOCK_UXN
|
2018-04-20 07:00:40 +00:00
|
|
|
}, {
|
2016-06-24 23:46:22 +00:00
|
|
|
.virt = 0xf8000000UL,
|
|
|
|
.phys = 0xf8000000UL,
|
2016-03-04 00:09:49 +00:00
|
|
|
.size = 0x07e00000UL,
|
|
|
|
.attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
|
|
|
|
PTE_BLOCK_NON_SHARE |
|
|
|
|
PTE_BLOCK_PXN | PTE_BLOCK_UXN
|
|
|
|
}, {
|
2016-06-24 23:46:22 +00:00
|
|
|
.virt = 0x400000000UL,
|
|
|
|
.phys = 0x400000000UL,
|
2017-12-19 16:24:41 +00:00
|
|
|
.size = 0x400000000UL,
|
2016-03-04 00:09:49 +00:00
|
|
|
.attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
|
|
|
|
PTE_BLOCK_NON_SHARE |
|
|
|
|
PTE_BLOCK_PXN | PTE_BLOCK_UXN
|
2018-04-20 07:00:40 +00:00
|
|
|
}, {
|
2017-12-19 16:24:41 +00:00
|
|
|
.virt = 0x1000000000UL,
|
|
|
|
.phys = 0x1000000000UL,
|
|
|
|
.size = 0xf000000000UL,
|
2016-03-04 00:09:49 +00:00
|
|
|
.attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
|
|
|
|
PTE_BLOCK_NON_SHARE |
|
|
|
|
PTE_BLOCK_PXN | PTE_BLOCK_UXN
|
|
|
|
}
|
|
|
|
};
|
2018-04-20 07:00:40 +00:00
|
|
|
|
|
|
|
void mem_map_fill(void)
|
|
|
|
{
|
|
|
|
int banks = ZYNQMP_MEM_MAP_USED;
|
|
|
|
|
|
|
|
#if defined(CONFIG_DEFINE_TCM_OCM_MMAP)
|
|
|
|
zynqmp_mem_map[banks].virt = 0xffe00000UL;
|
|
|
|
zynqmp_mem_map[banks].phys = 0xffe00000UL;
|
|
|
|
zynqmp_mem_map[banks].size = 0x00200000UL;
|
|
|
|
zynqmp_mem_map[banks].attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
|
|
|
|
PTE_BLOCK_INNER_SHARE;
|
|
|
|
banks = banks + 1;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(CONFIG_ZYNQMP_NO_DDR)
|
|
|
|
for (int i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
|
|
|
|
/* Zero size means no more DDR that's this is end */
|
|
|
|
if (!gd->bd->bi_dram[i].size)
|
|
|
|
break;
|
|
|
|
|
|
|
|
zynqmp_mem_map[banks].virt = gd->bd->bi_dram[i].start;
|
|
|
|
zynqmp_mem_map[banks].phys = gd->bd->bi_dram[i].start;
|
|
|
|
zynqmp_mem_map[banks].size = gd->bd->bi_dram[i].size;
|
|
|
|
zynqmp_mem_map[banks].attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
|
|
|
|
PTE_BLOCK_INNER_SHARE;
|
|
|
|
banks = banks + 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-03-04 00:09:49 +00:00
|
|
|
struct mm_region *mem_map = zynqmp_mem_map;
|
|
|
|
|
2016-05-30 08:41:26 +00:00
|
|
|
u64 get_page_table_size(void)
|
|
|
|
{
|
|
|
|
return 0x14000;
|
|
|
|
}
|
|
|
|
|
2018-10-05 09:39:05 +00:00
|
|
|
#if defined(CONFIG_SYS_MEM_RSVD_FOR_MMU) || defined(CONFIG_DEFINE_TCM_OCM_MMAP)
|
|
|
|
void tcm_init(u8 mode)
|
2017-07-13 13:31:11 +00:00
|
|
|
{
|
2018-10-05 09:39:04 +00:00
|
|
|
puts("WARNING: Initializing TCM overwrites TCM content\n");
|
|
|
|
initialize_tcm(mode);
|
2017-07-13 13:31:11 +00:00
|
|
|
memset((void *)ZYNQMP_TCM_BASE_ADDR, 0, ZYNQMP_TCM_SIZE);
|
2018-10-05 09:39:04 +00:00
|
|
|
}
|
2018-10-05 09:39:05 +00:00
|
|
|
#endif
|
2018-10-05 09:39:04 +00:00
|
|
|
|
2018-10-05 09:39:05 +00:00
|
|
|
#ifdef CONFIG_SYS_MEM_RSVD_FOR_MMU
|
2020-03-29 17:57:40 +00:00
|
|
|
int arm_reserve_mmu(void)
|
2018-10-05 09:39:04 +00:00
|
|
|
{
|
|
|
|
tcm_init(TCM_LOCK);
|
2017-07-13 13:31:11 +00:00
|
|
|
gd->arch.tlb_size = PGTABLE_SIZE;
|
|
|
|
gd->arch.tlb_addr = ZYNQMP_TCM_BASE_ADDR;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-11-05 07:34:35 +00:00
|
|
|
static unsigned int zynqmp_get_silicon_version_secure(void)
|
|
|
|
{
|
|
|
|
u32 ver;
|
|
|
|
|
|
|
|
ver = readl(&csu_base->version);
|
|
|
|
ver &= ZYNQMP_SILICON_VER_MASK;
|
|
|
|
ver >>= ZYNQMP_SILICON_VER_SHIFT;
|
|
|
|
|
|
|
|
return ver;
|
|
|
|
}
|
|
|
|
|
2015-01-15 09:01:51 +00:00
|
|
|
unsigned int zynqmp_get_silicon_version(void)
|
|
|
|
{
|
2015-11-05 07:34:35 +00:00
|
|
|
if (current_el() == 3)
|
|
|
|
return zynqmp_get_silicon_version_secure();
|
|
|
|
|
2015-01-15 09:01:51 +00:00
|
|
|
gd->cpu_clk = get_tbclk();
|
|
|
|
|
|
|
|
switch (gd->cpu_clk) {
|
|
|
|
case 50000000:
|
|
|
|
return ZYNQMP_CSU_VERSION_QEMU;
|
|
|
|
}
|
|
|
|
|
2015-08-20 12:01:39 +00:00
|
|
|
return ZYNQMP_CSU_VERSION_SILICON;
|
2015-01-15 09:01:51 +00:00
|
|
|
}
|
2017-02-01 19:40:46 +00:00
|
|
|
|
2017-07-13 13:31:12 +00:00
|
|
|
static int zynqmp_mmio_rawwrite(const u32 address,
|
2017-02-01 19:40:46 +00:00
|
|
|
const u32 mask,
|
|
|
|
const u32 value)
|
|
|
|
{
|
|
|
|
u32 data;
|
|
|
|
u32 value_local = value;
|
2018-06-13 08:38:33 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = zynqmp_mmio_read(address, &data);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2017-02-01 19:40:46 +00:00
|
|
|
|
|
|
|
data &= ~mask;
|
|
|
|
value_local &= mask;
|
|
|
|
value_local |= data;
|
|
|
|
writel(value_local, (ulong)address);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-07-13 13:31:12 +00:00
|
|
|
static int zynqmp_mmio_rawread(const u32 address, u32 *value)
|
2017-02-01 19:40:46 +00:00
|
|
|
{
|
|
|
|
*value = readl((ulong)address);
|
|
|
|
return 0;
|
|
|
|
}
|
2017-07-13 13:31:12 +00:00
|
|
|
|
|
|
|
int zynqmp_mmio_write(const u32 address,
|
|
|
|
const u32 mask,
|
|
|
|
const u32 value)
|
|
|
|
{
|
|
|
|
if (IS_ENABLED(CONFIG_SPL_BUILD) || current_el() == 3)
|
|
|
|
return zynqmp_mmio_rawwrite(address, mask, value);
|
2019-10-04 13:45:29 +00:00
|
|
|
#if defined(CONFIG_ZYNQMP_FIRMWARE)
|
2017-10-12 23:14:27 +00:00
|
|
|
else
|
2019-10-04 13:35:45 +00:00
|
|
|
return xilinx_pm_request(PM_MMIO_WRITE, address, mask,
|
|
|
|
value, 0, NULL);
|
2019-10-04 13:45:29 +00:00
|
|
|
#endif
|
2017-07-13 13:31:12 +00:00
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int zynqmp_mmio_read(const u32 address, u32 *value)
|
|
|
|
{
|
2019-10-04 13:45:29 +00:00
|
|
|
u32 ret = -EINVAL;
|
2017-07-13 13:31:12 +00:00
|
|
|
|
|
|
|
if (!value)
|
2019-10-04 13:45:29 +00:00
|
|
|
return ret;
|
2017-07-13 13:31:12 +00:00
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_SPL_BUILD) || current_el() == 3) {
|
|
|
|
ret = zynqmp_mmio_rawread(address, value);
|
2019-10-04 13:45:29 +00:00
|
|
|
}
|
|
|
|
#if defined(CONFIG_ZYNQMP_FIRMWARE)
|
|
|
|
else {
|
|
|
|
u32 ret_payload[PAYLOAD_ARG_CNT];
|
|
|
|
|
2019-10-04 13:35:45 +00:00
|
|
|
ret = xilinx_pm_request(PM_MMIO_READ, address, 0, 0,
|
|
|
|
0, ret_payload);
|
2017-07-13 13:31:12 +00:00
|
|
|
*value = ret_payload[1];
|
|
|
|
}
|
2019-10-04 13:45:29 +00:00
|
|
|
#endif
|
2017-07-13 13:31:12 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|