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>
|
|
|
|
#include <asm/arch/hardware.h>
|
|
|
|
#include <asm/arch/sys_proto.h>
|
2016-03-04 00:09:49 +00:00
|
|
|
#include <asm/armv8/mmu.h>
|
2015-01-15 09:01:51 +00:00
|
|
|
#include <asm/io.h>
|
|
|
|
|
|
|
|
#define ZYNQ_SILICON_VER_MASK 0xF000
|
|
|
|
#define ZYNQ_SILICON_VER_SHIFT 12
|
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2016-03-04 00:09:49 +00:00
|
|
|
static struct mm_region zynqmp_mem_map[] = {
|
2018-01-12 10:05:46 +00:00
|
|
|
#if !defined(CONFIG_ZYNQMP_NO_DDR)
|
2016-03-04 00:09:49 +00:00
|
|
|
{
|
2016-06-24 23:46:22 +00:00
|
|
|
.virt = 0x0UL,
|
|
|
|
.phys = 0x0UL,
|
2016-03-04 00:09:49 +00:00
|
|
|
.size = 0x80000000UL,
|
|
|
|
.attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
|
|
|
|
PTE_BLOCK_INNER_SHARE
|
2018-01-12 10:05:46 +00:00
|
|
|
},
|
|
|
|
#endif
|
|
|
|
{
|
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-01-12 10:05:46 +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
|
|
|
|
}, {
|
2017-07-13 13:31:10 +00:00
|
|
|
#if defined(CONFIG_DEFINE_TCM_OCM_MMAP)
|
|
|
|
.virt = 0xffe00000UL,
|
|
|
|
.phys = 0xffe00000UL,
|
|
|
|
.size = 0x00200000UL,
|
|
|
|
.attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
|
|
|
|
PTE_BLOCK_INNER_SHARE
|
|
|
|
}, {
|
|
|
|
#endif
|
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-01-12 10:05:46 +00:00
|
|
|
},
|
|
|
|
#if !defined(CONFIG_ZYNQMP_NO_DDR)
|
|
|
|
{
|
2017-12-19 16:24:41 +00:00
|
|
|
.virt = 0x800000000UL,
|
|
|
|
.phys = 0x800000000UL,
|
2016-03-04 00:09:49 +00:00
|
|
|
.size = 0x800000000UL,
|
|
|
|
.attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
|
|
|
|
PTE_BLOCK_INNER_SHARE
|
2018-01-12 10:05:46 +00:00
|
|
|
},
|
|
|
|
#endif
|
|
|
|
{
|
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
|
|
|
|
}, {
|
|
|
|
/* List terminator */
|
|
|
|
0,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
struct mm_region *mem_map = zynqmp_mem_map;
|
|
|
|
|
2016-05-30 08:41:26 +00:00
|
|
|
u64 get_page_table_size(void)
|
|
|
|
{
|
|
|
|
return 0x14000;
|
|
|
|
}
|
|
|
|
|
2017-07-13 13:31:11 +00:00
|
|
|
#ifdef CONFIG_SYS_MEM_RSVD_FOR_MMU
|
|
|
|
int reserve_mmu(void)
|
|
|
|
{
|
|
|
|
initialize_tcm(TCM_LOCK);
|
|
|
|
memset((void *)ZYNQMP_TCM_BASE_ADDR, 0, ZYNQMP_TCM_SIZE);
|
|
|
|
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) {
|
2015-04-15 12:59:19 +00:00
|
|
|
case 0 ... 1000000:
|
|
|
|
return ZYNQMP_CSU_VERSION_VELOCE;
|
2015-01-15 09:01:51 +00:00
|
|
|
case 50000000:
|
|
|
|
return ZYNQMP_CSU_VERSION_QEMU;
|
2015-08-20 12:01:39 +00:00
|
|
|
case 4000000:
|
|
|
|
return ZYNQMP_CSU_VERSION_EP108;
|
2015-01-15 09:01:51 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
#define ZYNQMP_MMIO_READ 0xC2000014
|
|
|
|
#define ZYNQMP_MMIO_WRITE 0xC2000013
|
|
|
|
|
2017-07-13 13:31:12 +00:00
|
|
|
int __maybe_unused invoke_smc(u32 pm_api_id, u32 arg0, u32 arg1, u32 arg2,
|
|
|
|
u32 arg3, u32 *ret_payload)
|
2017-02-01 19:40:46 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Added SIP service call Function Identifier
|
|
|
|
* Make sure to stay in x0 register
|
|
|
|
*/
|
|
|
|
struct pt_regs regs;
|
|
|
|
|
|
|
|
regs.regs[0] = pm_api_id;
|
|
|
|
regs.regs[1] = ((u64)arg1 << 32) | arg0;
|
|
|
|
regs.regs[2] = ((u64)arg3 << 32) | arg2;
|
|
|
|
|
|
|
|
smc_call(®s);
|
|
|
|
|
|
|
|
if (ret_payload != NULL) {
|
|
|
|
ret_payload[0] = (u32)regs.regs[0];
|
|
|
|
ret_payload[1] = upper_32_bits(regs.regs[0]);
|
|
|
|
ret_payload[2] = (u32)regs.regs[1];
|
|
|
|
ret_payload[3] = upper_32_bits(regs.regs[1]);
|
|
|
|
ret_payload[4] = (u32)regs.regs[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
return regs.regs[0];
|
|
|
|
}
|
|
|
|
|
2017-02-07 13:32:26 +00:00
|
|
|
#define ZYNQMP_SIP_SVC_GET_API_VERSION 0xC2000001
|
|
|
|
|
|
|
|
#define ZYNQMP_PM_VERSION_MAJOR 0
|
|
|
|
#define ZYNQMP_PM_VERSION_MINOR 3
|
|
|
|
#define ZYNQMP_PM_VERSION_MAJOR_SHIFT 16
|
|
|
|
#define ZYNQMP_PM_VERSION_MINOR_MASK 0xFFFF
|
|
|
|
|
|
|
|
#define ZYNQMP_PM_VERSION \
|
|
|
|
((ZYNQMP_PM_VERSION_MAJOR << ZYNQMP_PM_VERSION_MAJOR_SHIFT) | \
|
|
|
|
ZYNQMP_PM_VERSION_MINOR)
|
|
|
|
|
|
|
|
#if defined(CONFIG_CLK_ZYNQMP)
|
|
|
|
void zynqmp_pmufw_version(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
u32 ret_payload[PAYLOAD_ARG_CNT];
|
|
|
|
u32 pm_api_version;
|
|
|
|
|
|
|
|
ret = invoke_smc(ZYNQMP_SIP_SVC_GET_API_VERSION, 0, 0, 0, 0,
|
|
|
|
ret_payload);
|
|
|
|
pm_api_version = ret_payload[1];
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
panic("PMUFW is not found - Please load it!\n");
|
|
|
|
|
|
|
|
printf("PMUFW:\tv%d.%d\n",
|
|
|
|
pm_api_version >> ZYNQMP_PM_VERSION_MAJOR_SHIFT,
|
|
|
|
pm_api_version & ZYNQMP_PM_VERSION_MINOR_MASK);
|
|
|
|
|
2018-02-08 07:51:36 +00:00
|
|
|
if (pm_api_version < ZYNQMP_PM_VERSION)
|
2017-02-07 13:32:26 +00:00
|
|
|
panic("PMUFW version error. Expected: v%d.%d\n",
|
|
|
|
ZYNQMP_PM_VERSION_MAJOR, ZYNQMP_PM_VERSION_MINOR);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
zynqmp_mmio_read(address, &data);
|
|
|
|
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);
|
2017-10-12 23:14:27 +00:00
|
|
|
else
|
2017-07-13 13:31:12 +00:00
|
|
|
return invoke_smc(ZYNQMP_MMIO_WRITE, address, mask,
|
|
|
|
value, 0, NULL);
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int zynqmp_mmio_read(const u32 address, u32 *value)
|
|
|
|
{
|
|
|
|
u32 ret_payload[PAYLOAD_ARG_CNT];
|
|
|
|
u32 ret;
|
|
|
|
|
|
|
|
if (!value)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_SPL_BUILD) || current_el() == 3) {
|
|
|
|
ret = zynqmp_mmio_rawread(address, value);
|
2017-10-12 23:14:27 +00:00
|
|
|
} else {
|
2017-07-13 13:31:12 +00:00
|
|
|
ret = invoke_smc(ZYNQMP_MMIO_READ, address, 0, 0,
|
|
|
|
0, ret_payload);
|
|
|
|
*value = ret_payload[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|