Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2014 - 2015 Xilinx, Inc. |
| 4 | * Michal Simek <michal.simek@xilinx.com> |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | 049f8d6 | 2019-12-28 10:44:59 -0700 | [diff] [blame^] | 8 | #include <time.h> |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 9 | #include <asm/arch/hardware.h> |
| 10 | #include <asm/arch/sys_proto.h> |
Alexander Graf | 96519f3 | 2016-03-04 01:09:49 +0100 | [diff] [blame] | 11 | #include <asm/armv8/mmu.h> |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 12 | #include <asm/io.h> |
Ibai Erkiaga | 009ab7b | 2019-09-27 11:37:01 +0100 | [diff] [blame] | 13 | #include <zynqmp_firmware.h> |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 14 | |
| 15 | #define ZYNQ_SILICON_VER_MASK 0xF000 |
| 16 | #define ZYNQ_SILICON_VER_SHIFT 12 |
| 17 | |
| 18 | DECLARE_GLOBAL_DATA_PTR; |
| 19 | |
Nitin Jain | 0678941 | 2018-04-20 12:30:40 +0530 | [diff] [blame] | 20 | /* |
| 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 Paladugu | 3b644a3 | 2018-01-12 15:35:46 +0530 | [diff] [blame] | 26 | #if !defined(CONFIG_ZYNQMP_NO_DDR) |
Nitin Jain | 0678941 | 2018-04-20 12:30:40 +0530 | [diff] [blame] | 27 | #define DRAM_BANKS CONFIG_NR_DRAM_BANKS |
| 28 | #else |
| 29 | #define DRAM_BANKS 0 |
Siva Durga Prasad Paladugu | 3b644a3 | 2018-01-12 15:35:46 +0530 | [diff] [blame] | 30 | #endif |
Nitin Jain | 0678941 | 2018-04-20 12:30:40 +0530 | [diff] [blame] | 31 | |
| 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 | |
| 41 | static struct mm_region zynqmp_mem_map[ZYNQMP_MEM_MAP_MAX] = { |
Siva Durga Prasad Paladugu | 3b644a3 | 2018-01-12 15:35:46 +0530 | [diff] [blame] | 42 | { |
York Sun | cd4b0c5 | 2016-06-24 16:46:22 -0700 | [diff] [blame] | 43 | .virt = 0x80000000UL, |
| 44 | .phys = 0x80000000UL, |
Alexander Graf | 96519f3 | 2016-03-04 01:09:49 +0100 | [diff] [blame] | 45 | .size = 0x70000000UL, |
| 46 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 47 | PTE_BLOCK_NON_SHARE | |
| 48 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
Nitin Jain | 0678941 | 2018-04-20 12:30:40 +0530 | [diff] [blame] | 49 | }, { |
York Sun | cd4b0c5 | 2016-06-24 16:46:22 -0700 | [diff] [blame] | 50 | .virt = 0xf8000000UL, |
| 51 | .phys = 0xf8000000UL, |
Alexander Graf | 96519f3 | 2016-03-04 01:09:49 +0100 | [diff] [blame] | 52 | .size = 0x07e00000UL, |
| 53 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 54 | PTE_BLOCK_NON_SHARE | |
| 55 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 56 | }, { |
York Sun | cd4b0c5 | 2016-06-24 16:46:22 -0700 | [diff] [blame] | 57 | .virt = 0x400000000UL, |
| 58 | .phys = 0x400000000UL, |
Anders Hedlund | 501fbc6 | 2017-12-19 17:24:41 +0100 | [diff] [blame] | 59 | .size = 0x400000000UL, |
Alexander Graf | 96519f3 | 2016-03-04 01:09:49 +0100 | [diff] [blame] | 60 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 61 | PTE_BLOCK_NON_SHARE | |
| 62 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
Nitin Jain | 0678941 | 2018-04-20 12:30:40 +0530 | [diff] [blame] | 63 | }, { |
Anders Hedlund | 501fbc6 | 2017-12-19 17:24:41 +0100 | [diff] [blame] | 64 | .virt = 0x1000000000UL, |
| 65 | .phys = 0x1000000000UL, |
| 66 | .size = 0xf000000000UL, |
Alexander Graf | 96519f3 | 2016-03-04 01:09:49 +0100 | [diff] [blame] | 67 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 68 | PTE_BLOCK_NON_SHARE | |
| 69 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
Alexander Graf | 96519f3 | 2016-03-04 01:09:49 +0100 | [diff] [blame] | 70 | } |
| 71 | }; |
Nitin Jain | 0678941 | 2018-04-20 12:30:40 +0530 | [diff] [blame] | 72 | |
| 73 | void 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 Graf | 96519f3 | 2016-03-04 01:09:49 +0100 | [diff] [blame] | 102 | struct mm_region *mem_map = zynqmp_mem_map; |
| 103 | |
Michal Simek | 9c152ed | 2016-05-30 10:41:26 +0200 | [diff] [blame] | 104 | u64 get_page_table_size(void) |
| 105 | { |
| 106 | return 0x14000; |
| 107 | } |
| 108 | |
Siva Durga Prasad Paladugu | 5860bc1 | 2018-10-05 15:09:05 +0530 | [diff] [blame] | 109 | #if defined(CONFIG_SYS_MEM_RSVD_FOR_MMU) || defined(CONFIG_DEFINE_TCM_OCM_MMAP) |
| 110 | void tcm_init(u8 mode) |
Siva Durga Prasad Paladugu | 12ad299 | 2018-10-05 15:09:04 +0530 | [diff] [blame] | 111 | { |
| 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 Paladugu | 5860bc1 | 2018-10-05 15:09:05 +0530 | [diff] [blame] | 116 | #endif |
Siva Durga Prasad Paladugu | 12ad299 | 2018-10-05 15:09:04 +0530 | [diff] [blame] | 117 | |
Siva Durga Prasad Paladugu | 5860bc1 | 2018-10-05 15:09:05 +0530 | [diff] [blame] | 118 | #ifdef CONFIG_SYS_MEM_RSVD_FOR_MMU |
Siva Durga Prasad Paladugu | e042d36 | 2017-07-13 19:01:11 +0530 | [diff] [blame] | 119 | int reserve_mmu(void) |
| 120 | { |
Siva Durga Prasad Paladugu | 12ad299 | 2018-10-05 15:09:04 +0530 | [diff] [blame] | 121 | tcm_init(TCM_LOCK); |
Siva Durga Prasad Paladugu | e042d36 | 2017-07-13 19:01:11 +0530 | [diff] [blame] | 122 | gd->arch.tlb_size = PGTABLE_SIZE; |
| 123 | gd->arch.tlb_addr = ZYNQMP_TCM_BASE_ADDR; |
| 124 | |
| 125 | return 0; |
| 126 | } |
| 127 | #endif |
| 128 | |
Michal Simek | 0785dfd | 2015-11-05 08:34:35 +0100 | [diff] [blame] | 129 | static 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 Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 140 | unsigned int zynqmp_get_silicon_version(void) |
| 141 | { |
Michal Simek | 0785dfd | 2015-11-05 08:34:35 +0100 | [diff] [blame] | 142 | if (current_el() == 3) |
| 143 | return zynqmp_get_silicon_version_secure(); |
| 144 | |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 145 | gd->cpu_clk = get_tbclk(); |
| 146 | |
| 147 | switch (gd->cpu_clk) { |
| 148 | case 50000000: |
| 149 | return ZYNQMP_CSU_VERSION_QEMU; |
| 150 | } |
| 151 | |
Michal Simek | be6f6af | 2015-08-20 14:01:39 +0200 | [diff] [blame] | 152 | return ZYNQMP_CSU_VERSION_SILICON; |
Michal Simek | 84c7204 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 153 | } |
Siva Durga Prasad Paladugu | e0752bc | 2017-02-02 01:10:46 +0530 | [diff] [blame] | 154 | |
Siva Durga Prasad Paladugu | cb186e7 | 2017-07-13 19:01:12 +0530 | [diff] [blame] | 155 | static int zynqmp_mmio_rawwrite(const u32 address, |
Siva Durga Prasad Paladugu | e0752bc | 2017-02-02 01:10:46 +0530 | [diff] [blame] | 156 | const u32 mask, |
| 157 | const u32 value) |
| 158 | { |
| 159 | u32 data; |
| 160 | u32 value_local = value; |
Michal Simek | e3c26b8 | 2018-06-13 10:38:33 +0200 | [diff] [blame] | 161 | int ret; |
Siva Durga Prasad Paladugu | e0752bc | 2017-02-02 01:10:46 +0530 | [diff] [blame] | 162 | |
Michal Simek | e3c26b8 | 2018-06-13 10:38:33 +0200 | [diff] [blame] | 163 | ret = zynqmp_mmio_read(address, &data); |
| 164 | if (ret) |
| 165 | return ret; |
| 166 | |
Siva Durga Prasad Paladugu | e0752bc | 2017-02-02 01:10:46 +0530 | [diff] [blame] | 167 | data &= ~mask; |
| 168 | value_local &= mask; |
| 169 | value_local |= data; |
| 170 | writel(value_local, (ulong)address); |
| 171 | return 0; |
| 172 | } |
| 173 | |
Siva Durga Prasad Paladugu | cb186e7 | 2017-07-13 19:01:12 +0530 | [diff] [blame] | 174 | static int zynqmp_mmio_rawread(const u32 address, u32 *value) |
Siva Durga Prasad Paladugu | e0752bc | 2017-02-02 01:10:46 +0530 | [diff] [blame] | 175 | { |
| 176 | *value = readl((ulong)address); |
| 177 | return 0; |
| 178 | } |
Siva Durga Prasad Paladugu | cb186e7 | 2017-07-13 19:01:12 +0530 | [diff] [blame] | 179 | |
| 180 | int 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 Simek | 866225f | 2019-10-04 15:45:29 +0200 | [diff] [blame] | 186 | #if defined(CONFIG_ZYNQMP_FIRMWARE) |
Heinrich Schuchardt | 549d684 | 2017-10-13 01:14:27 +0200 | [diff] [blame] | 187 | else |
Michal Simek | 4036195 | 2019-10-04 15:35:45 +0200 | [diff] [blame] | 188 | return xilinx_pm_request(PM_MMIO_WRITE, address, mask, |
| 189 | value, 0, NULL); |
Michal Simek | 866225f | 2019-10-04 15:45:29 +0200 | [diff] [blame] | 190 | #endif |
Siva Durga Prasad Paladugu | cb186e7 | 2017-07-13 19:01:12 +0530 | [diff] [blame] | 191 | |
| 192 | return -EINVAL; |
| 193 | } |
| 194 | |
| 195 | int zynqmp_mmio_read(const u32 address, u32 *value) |
| 196 | { |
Michal Simek | 866225f | 2019-10-04 15:45:29 +0200 | [diff] [blame] | 197 | u32 ret = -EINVAL; |
Siva Durga Prasad Paladugu | cb186e7 | 2017-07-13 19:01:12 +0530 | [diff] [blame] | 198 | |
| 199 | if (!value) |
Michal Simek | 866225f | 2019-10-04 15:45:29 +0200 | [diff] [blame] | 200 | return ret; |
Siva Durga Prasad Paladugu | cb186e7 | 2017-07-13 19:01:12 +0530 | [diff] [blame] | 201 | |
| 202 | if (IS_ENABLED(CONFIG_SPL_BUILD) || current_el() == 3) { |
| 203 | ret = zynqmp_mmio_rawread(address, value); |
Michal Simek | 866225f | 2019-10-04 15:45:29 +0200 | [diff] [blame] | 204 | } |
| 205 | #if defined(CONFIG_ZYNQMP_FIRMWARE) |
| 206 | else { |
| 207 | u32 ret_payload[PAYLOAD_ARG_CNT]; |
| 208 | |
Michal Simek | 4036195 | 2019-10-04 15:35:45 +0200 | [diff] [blame] | 209 | ret = xilinx_pm_request(PM_MMIO_READ, address, 0, 0, |
| 210 | 0, ret_payload); |
Siva Durga Prasad Paladugu | cb186e7 | 2017-07-13 19:01:12 +0530 | [diff] [blame] | 211 | *value = ret_payload[1]; |
| 212 | } |
Michal Simek | 866225f | 2019-10-04 15:45:29 +0200 | [diff] [blame] | 213 | #endif |
Siva Durga Prasad Paladugu | cb186e7 | 2017-07-13 19:01:12 +0530 | [diff] [blame] | 214 | |
| 215 | return ret; |
| 216 | } |