blob: 442427bc1106be57cee58b46c8f476fc58744de0 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Michal Simek84c72042015-01-15 10:01:51 +01002/*
3 * (C) Copyright 2014 - 2015 Xilinx, Inc.
4 * Michal Simek <michal.simek@xilinx.com>
Michal Simek84c72042015-01-15 10:01:51 +01005 */
6
7#include <common.h>
Simon Glass049f8d62019-12-28 10:44:59 -07008#include <time.h>
Michal Simek84c72042015-01-15 10:01:51 +01009#include <asm/arch/hardware.h>
10#include <asm/arch/sys_proto.h>
Alexander Graf96519f32016-03-04 01:09:49 +010011#include <asm/armv8/mmu.h>
Michal Simek84c72042015-01-15 10:01:51 +010012#include <asm/io.h>
Ibai Erkiaga009ab7b2019-09-27 11:37:01 +010013#include <zynqmp_firmware.h>
Michal Simek84c72042015-01-15 10:01:51 +010014
15#define ZYNQ_SILICON_VER_MASK 0xF000
16#define ZYNQ_SILICON_VER_SHIFT 12
17
18DECLARE_GLOBAL_DATA_PTR;
19
Nitin Jain06789412018-04-20 12:30:40 +053020/*
21 * Number of filled static entries and also the first empty
22 * slot in zynqmp_mem_map.
23 */
24#define ZYNQMP_MEM_MAP_USED 4
25
Siva Durga Prasad Paladugu3b644a32018-01-12 15:35:46 +053026#if !defined(CONFIG_ZYNQMP_NO_DDR)
Nitin Jain06789412018-04-20 12:30:40 +053027#define DRAM_BANKS CONFIG_NR_DRAM_BANKS
28#else
29#define DRAM_BANKS 0
Siva Durga Prasad Paladugu3b644a32018-01-12 15:35:46 +053030#endif
Nitin Jain06789412018-04-20 12:30:40 +053031
32#if defined(CONFIG_DEFINE_TCM_OCM_MMAP)
33#define TCM_MAP 1
34#else
35#define TCM_MAP 0
36#endif
37
38/* +1 is end of list which needs to be empty */
39#define ZYNQMP_MEM_MAP_MAX (ZYNQMP_MEM_MAP_USED + DRAM_BANKS + TCM_MAP + 1)
40
41static struct mm_region zynqmp_mem_map[ZYNQMP_MEM_MAP_MAX] = {
Siva Durga Prasad Paladugu3b644a32018-01-12 15:35:46 +053042 {
York Suncd4b0c52016-06-24 16:46:22 -070043 .virt = 0x80000000UL,
44 .phys = 0x80000000UL,
Alexander Graf96519f32016-03-04 01:09:49 +010045 .size = 0x70000000UL,
46 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
47 PTE_BLOCK_NON_SHARE |
48 PTE_BLOCK_PXN | PTE_BLOCK_UXN
Nitin Jain06789412018-04-20 12:30:40 +053049 }, {
York Suncd4b0c52016-06-24 16:46:22 -070050 .virt = 0xf8000000UL,
51 .phys = 0xf8000000UL,
Alexander Graf96519f32016-03-04 01:09:49 +010052 .size = 0x07e00000UL,
53 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
54 PTE_BLOCK_NON_SHARE |
55 PTE_BLOCK_PXN | PTE_BLOCK_UXN
56 }, {
York Suncd4b0c52016-06-24 16:46:22 -070057 .virt = 0x400000000UL,
58 .phys = 0x400000000UL,
Anders Hedlund501fbc62017-12-19 17:24:41 +010059 .size = 0x400000000UL,
Alexander Graf96519f32016-03-04 01:09:49 +010060 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
61 PTE_BLOCK_NON_SHARE |
62 PTE_BLOCK_PXN | PTE_BLOCK_UXN
Nitin Jain06789412018-04-20 12:30:40 +053063 }, {
Anders Hedlund501fbc62017-12-19 17:24:41 +010064 .virt = 0x1000000000UL,
65 .phys = 0x1000000000UL,
66 .size = 0xf000000000UL,
Alexander Graf96519f32016-03-04 01:09:49 +010067 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
68 PTE_BLOCK_NON_SHARE |
69 PTE_BLOCK_PXN | PTE_BLOCK_UXN
Alexander Graf96519f32016-03-04 01:09:49 +010070 }
71};
Nitin Jain06789412018-04-20 12:30:40 +053072
73void mem_map_fill(void)
74{
75 int banks = ZYNQMP_MEM_MAP_USED;
76
77#if defined(CONFIG_DEFINE_TCM_OCM_MMAP)
78 zynqmp_mem_map[banks].virt = 0xffe00000UL;
79 zynqmp_mem_map[banks].phys = 0xffe00000UL;
80 zynqmp_mem_map[banks].size = 0x00200000UL;
81 zynqmp_mem_map[banks].attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
82 PTE_BLOCK_INNER_SHARE;
83 banks = banks + 1;
84#endif
85
86#if !defined(CONFIG_ZYNQMP_NO_DDR)
87 for (int i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
88 /* Zero size means no more DDR that's this is end */
89 if (!gd->bd->bi_dram[i].size)
90 break;
91
92 zynqmp_mem_map[banks].virt = gd->bd->bi_dram[i].start;
93 zynqmp_mem_map[banks].phys = gd->bd->bi_dram[i].start;
94 zynqmp_mem_map[banks].size = gd->bd->bi_dram[i].size;
95 zynqmp_mem_map[banks].attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
96 PTE_BLOCK_INNER_SHARE;
97 banks = banks + 1;
98 }
99#endif
100}
101
Alexander Graf96519f32016-03-04 01:09:49 +0100102struct mm_region *mem_map = zynqmp_mem_map;
103
Michal Simek9c152ed2016-05-30 10:41:26 +0200104u64 get_page_table_size(void)
105{
106 return 0x14000;
107}
108
Siva Durga Prasad Paladugu5860bc12018-10-05 15:09:05 +0530109#if defined(CONFIG_SYS_MEM_RSVD_FOR_MMU) || defined(CONFIG_DEFINE_TCM_OCM_MMAP)
110void tcm_init(u8 mode)
Siva Durga Prasad Paladugu12ad2992018-10-05 15:09:04 +0530111{
112 puts("WARNING: Initializing TCM overwrites TCM content\n");
113 initialize_tcm(mode);
114 memset((void *)ZYNQMP_TCM_BASE_ADDR, 0, ZYNQMP_TCM_SIZE);
115}
Siva Durga Prasad Paladugu5860bc12018-10-05 15:09:05 +0530116#endif
Siva Durga Prasad Paladugu12ad2992018-10-05 15:09:04 +0530117
Siva Durga Prasad Paladugu5860bc12018-10-05 15:09:05 +0530118#ifdef CONFIG_SYS_MEM_RSVD_FOR_MMU
Siva Durga Prasad Paladugue042d362017-07-13 19:01:11 +0530119int reserve_mmu(void)
120{
Siva Durga Prasad Paladugu12ad2992018-10-05 15:09:04 +0530121 tcm_init(TCM_LOCK);
Siva Durga Prasad Paladugue042d362017-07-13 19:01:11 +0530122 gd->arch.tlb_size = PGTABLE_SIZE;
123 gd->arch.tlb_addr = ZYNQMP_TCM_BASE_ADDR;
124
125 return 0;
126}
127#endif
128
Michal Simek0785dfd2015-11-05 08:34:35 +0100129static unsigned int zynqmp_get_silicon_version_secure(void)
130{
131 u32 ver;
132
133 ver = readl(&csu_base->version);
134 ver &= ZYNQMP_SILICON_VER_MASK;
135 ver >>= ZYNQMP_SILICON_VER_SHIFT;
136
137 return ver;
138}
139
Michal Simek84c72042015-01-15 10:01:51 +0100140unsigned int zynqmp_get_silicon_version(void)
141{
Michal Simek0785dfd2015-11-05 08:34:35 +0100142 if (current_el() == 3)
143 return zynqmp_get_silicon_version_secure();
144
Michal Simek84c72042015-01-15 10:01:51 +0100145 gd->cpu_clk = get_tbclk();
146
147 switch (gd->cpu_clk) {
148 case 50000000:
149 return ZYNQMP_CSU_VERSION_QEMU;
150 }
151
Michal Simekbe6f6af2015-08-20 14:01:39 +0200152 return ZYNQMP_CSU_VERSION_SILICON;
Michal Simek84c72042015-01-15 10:01:51 +0100153}
Siva Durga Prasad Paladugue0752bc2017-02-02 01:10:46 +0530154
Siva Durga Prasad Paladugucb186e72017-07-13 19:01:12 +0530155static int zynqmp_mmio_rawwrite(const u32 address,
Siva Durga Prasad Paladugue0752bc2017-02-02 01:10:46 +0530156 const u32 mask,
157 const u32 value)
158{
159 u32 data;
160 u32 value_local = value;
Michal Simeke3c26b82018-06-13 10:38:33 +0200161 int ret;
Siva Durga Prasad Paladugue0752bc2017-02-02 01:10:46 +0530162
Michal Simeke3c26b82018-06-13 10:38:33 +0200163 ret = zynqmp_mmio_read(address, &data);
164 if (ret)
165 return ret;
166
Siva Durga Prasad Paladugue0752bc2017-02-02 01:10:46 +0530167 data &= ~mask;
168 value_local &= mask;
169 value_local |= data;
170 writel(value_local, (ulong)address);
171 return 0;
172}
173
Siva Durga Prasad Paladugucb186e72017-07-13 19:01:12 +0530174static int zynqmp_mmio_rawread(const u32 address, u32 *value)
Siva Durga Prasad Paladugue0752bc2017-02-02 01:10:46 +0530175{
176 *value = readl((ulong)address);
177 return 0;
178}
Siva Durga Prasad Paladugucb186e72017-07-13 19:01:12 +0530179
180int zynqmp_mmio_write(const u32 address,
181 const u32 mask,
182 const u32 value)
183{
184 if (IS_ENABLED(CONFIG_SPL_BUILD) || current_el() == 3)
185 return zynqmp_mmio_rawwrite(address, mask, value);
Michal Simek866225f2019-10-04 15:45:29 +0200186#if defined(CONFIG_ZYNQMP_FIRMWARE)
Heinrich Schuchardt549d6842017-10-13 01:14:27 +0200187 else
Michal Simek40361952019-10-04 15:35:45 +0200188 return xilinx_pm_request(PM_MMIO_WRITE, address, mask,
189 value, 0, NULL);
Michal Simek866225f2019-10-04 15:45:29 +0200190#endif
Siva Durga Prasad Paladugucb186e72017-07-13 19:01:12 +0530191
192 return -EINVAL;
193}
194
195int zynqmp_mmio_read(const u32 address, u32 *value)
196{
Michal Simek866225f2019-10-04 15:45:29 +0200197 u32 ret = -EINVAL;
Siva Durga Prasad Paladugucb186e72017-07-13 19:01:12 +0530198
199 if (!value)
Michal Simek866225f2019-10-04 15:45:29 +0200200 return ret;
Siva Durga Prasad Paladugucb186e72017-07-13 19:01:12 +0530201
202 if (IS_ENABLED(CONFIG_SPL_BUILD) || current_el() == 3) {
203 ret = zynqmp_mmio_rawread(address, value);
Michal Simek866225f2019-10-04 15:45:29 +0200204 }
205#if defined(CONFIG_ZYNQMP_FIRMWARE)
206 else {
207 u32 ret_payload[PAYLOAD_ARG_CNT];
208
Michal Simek40361952019-10-04 15:35:45 +0200209 ret = xilinx_pm_request(PM_MMIO_READ, address, 0, 0,
210 0, ret_payload);
Siva Durga Prasad Paladugucb186e72017-07-13 19:01:12 +0530211 *value = ret_payload[1];
212 }
Michal Simek866225f2019-10-04 15:45:29 +0200213#endif
Siva Durga Prasad Paladugucb186e72017-07-13 19:01:12 +0530214
215 return ret;
216}