Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
David Feng | 3b5458c | 2013-12-14 11:47:37 +0800 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2013 |
| 4 | * David Feng <fenghua@phytium.com.cn> |
| 5 | * Sharma Bhupesh <bhupesh.sharma@freescale.com> |
David Feng | 3b5458c | 2013-12-14 11:47:37 +0800 | [diff] [blame] | 6 | */ |
| 7 | #include <common.h> |
Simon Glass | afb0215 | 2019-12-28 10:45:01 -0700 | [diff] [blame] | 8 | #include <cpu_func.h> |
Simon Glass | 11c89f3 | 2017-05-17 17:18:03 -0600 | [diff] [blame] | 9 | #include <dm.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 10 | #include <init.h> |
David Feng | 3b5458c | 2013-12-14 11:47:37 +0800 | [diff] [blame] | 11 | #include <malloc.h> |
| 12 | #include <errno.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 13 | #include <net.h> |
David Feng | 3b5458c | 2013-12-14 11:47:37 +0800 | [diff] [blame] | 14 | #include <netdev.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 15 | #include <asm/global_data.h> |
David Feng | 3b5458c | 2013-12-14 11:47:37 +0800 | [diff] [blame] | 16 | #include <asm/io.h> |
| 17 | #include <linux/compiler.h> |
Andre Przywara | 87de4b7 | 2022-03-04 16:30:16 +0000 | [diff] [blame] | 18 | #include <linux/sizes.h> |
David Feng | ab33c2c | 2015-01-31 11:55:29 +0800 | [diff] [blame] | 19 | #include <dm/platform_data/serial_pl01x.h> |
Liviu Dudau | 8d1fdc3 | 2015-10-19 11:08:32 +0100 | [diff] [blame] | 20 | #include "pcie.h" |
Alexander Graf | 5889e39 | 2016-03-04 01:09:51 +0100 | [diff] [blame] | 21 | #include <asm/armv8/mmu.h> |
Peter Hoyes | 8194cda | 2021-11-11 09:26:03 +0000 | [diff] [blame] | 22 | #ifdef CONFIG_VIRTIO_NET |
| 23 | #include <virtio_types.h> |
| 24 | #include <virtio.h> |
| 25 | #endif |
David Feng | 3b5458c | 2013-12-14 11:47:37 +0800 | [diff] [blame] | 26 | |
| 27 | DECLARE_GLOBAL_DATA_PTR; |
| 28 | |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 29 | static const struct pl01x_serial_plat serial_plat = { |
David Feng | ab33c2c | 2015-01-31 11:55:29 +0800 | [diff] [blame] | 30 | .base = V2M_UART0, |
| 31 | .type = TYPE_PL011, |
Tom Rini | 5c896ae | 2022-12-04 10:13:30 -0500 | [diff] [blame] | 32 | .clock = CFG_PL011_CLOCK, |
David Feng | ab33c2c | 2015-01-31 11:55:29 +0800 | [diff] [blame] | 33 | }; |
| 34 | |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 35 | U_BOOT_DRVINFO(vexpress_serials) = { |
David Feng | ab33c2c | 2015-01-31 11:55:29 +0800 | [diff] [blame] | 36 | .name = "serial_pl01x", |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 37 | .plat = &serial_plat, |
David Feng | ab33c2c | 2015-01-31 11:55:29 +0800 | [diff] [blame] | 38 | }; |
| 39 | |
Alexander Graf | 5889e39 | 2016-03-04 01:09:51 +0100 | [diff] [blame] | 40 | static struct mm_region vexpress64_mem_map[] = { |
| 41 | { |
Andre Przywara | 87de4b7 | 2022-03-04 16:30:16 +0000 | [diff] [blame] | 42 | .virt = V2M_PA_BASE, |
| 43 | .phys = V2M_PA_BASE, |
| 44 | .size = SZ_2G, |
Alexander Graf | 5889e39 | 2016-03-04 01:09:51 +0100 | [diff] [blame] | 45 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 46 | PTE_BLOCK_NON_SHARE | |
| 47 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 48 | }, { |
Andre Przywara | 87de4b7 | 2022-03-04 16:30:16 +0000 | [diff] [blame] | 49 | .virt = V2M_DRAM_BASE, |
| 50 | .phys = V2M_DRAM_BASE, |
| 51 | .size = SZ_2G, |
| 52 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 53 | PTE_BLOCK_INNER_SHARE |
| 54 | }, { |
| 55 | /* |
| 56 | * DRAM beyond 2 GiB is located high. Let's map just some |
| 57 | * of it, although U-Boot won't realistically use it, and |
| 58 | * the actual available amount might be smaller on the model. |
| 59 | */ |
| 60 | .virt = 0x880000000UL, /* 32 + 2 GiB */ |
| 61 | .phys = 0x880000000UL, |
| 62 | .size = 6UL * SZ_1G, |
Alexander Graf | 5889e39 | 2016-03-04 01:09:51 +0100 | [diff] [blame] | 63 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 64 | PTE_BLOCK_INNER_SHARE |
| 65 | }, { |
| 66 | /* List terminator */ |
| 67 | 0, |
| 68 | } |
| 69 | }; |
| 70 | |
| 71 | struct mm_region *mem_map = vexpress64_mem_map; |
| 72 | |
Ryan Harkin | 8961d50 | 2015-11-18 10:39:06 +0000 | [diff] [blame] | 73 | /* This function gets replaced by platforms supporting PCIe. |
| 74 | * The replacement function, eg. on Juno, initialises the PCIe bus. |
| 75 | */ |
| 76 | __weak void vexpress64_pcie_init(void) |
| 77 | { |
| 78 | } |
| 79 | |
David Feng | 3b5458c | 2013-12-14 11:47:37 +0800 | [diff] [blame] | 80 | int board_init(void) |
| 81 | { |
Liviu Dudau | 8d1fdc3 | 2015-10-19 11:08:32 +0100 | [diff] [blame] | 82 | vexpress64_pcie_init(); |
Peter Hoyes | 8194cda | 2021-11-11 09:26:03 +0000 | [diff] [blame] | 83 | #ifdef CONFIG_VIRTIO_NET |
| 84 | virtio_init(); |
| 85 | #endif |
David Feng | 3b5458c | 2013-12-14 11:47:37 +0800 | [diff] [blame] | 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | int dram_init(void) |
| 90 | { |
Andre Przywara | 2b97f12 | 2022-03-04 16:30:17 +0000 | [diff] [blame] | 91 | return fdtdec_setup_mem_size_base(); |
David Feng | 3b5458c | 2013-12-14 11:47:37 +0800 | [diff] [blame] | 92 | } |
| 93 | |
Simon Glass | 2f949c3 | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 94 | int dram_init_banksize(void) |
Liviu Dudau | 086c977 | 2015-10-19 11:08:31 +0100 | [diff] [blame] | 95 | { |
Andre Przywara | 2b97f12 | 2022-03-04 16:30:17 +0000 | [diff] [blame] | 96 | return fdtdec_setup_memory_banksize(); |
Liviu Dudau | 086c977 | 2015-10-19 11:08:31 +0100 | [diff] [blame] | 97 | } |
| 98 | |
Peter Hoyes | baf62cf | 2021-11-11 09:26:02 +0000 | [diff] [blame] | 99 | /* Assigned in lowlevel_init.S |
| 100 | * Push the variable into the .data section so that it |
| 101 | * does not get cleared later. |
| 102 | */ |
Andre Przywara | 875685e | 2022-09-21 18:09:46 +0100 | [diff] [blame] | 103 | unsigned long __section(".data") prior_stage_fdt_address[2]; |
Peter Hoyes | baf62cf | 2021-11-11 09:26:02 +0000 | [diff] [blame] | 104 | |
Andre Przywara | 94504f4 | 2020-04-27 19:18:01 +0100 | [diff] [blame] | 105 | #ifdef CONFIG_OF_BOARD |
Peter Hoyes | baf62cf | 2021-11-11 09:26:02 +0000 | [diff] [blame] | 106 | |
| 107 | #ifdef CONFIG_TARGET_VEXPRESS64_JUNO |
Andre Przywara | 94504f4 | 2020-04-27 19:18:01 +0100 | [diff] [blame] | 108 | #define JUNO_FLASH_SEC_SIZE (256 * 1024) |
| 109 | static phys_addr_t find_dtb_in_nor_flash(const char *partname) |
| 110 | { |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 111 | phys_addr_t sector = CFG_SYS_FLASH_BASE; |
Andre Przywara | 94504f4 | 2020-04-27 19:18:01 +0100 | [diff] [blame] | 112 | int i; |
| 113 | |
| 114 | for (i = 0; |
| 115 | i < CONFIG_SYS_MAX_FLASH_SECT; |
| 116 | i++, sector += JUNO_FLASH_SEC_SIZE) { |
| 117 | int len = strlen(partname) + 1; |
| 118 | int offs; |
| 119 | phys_addr_t imginfo; |
| 120 | u32 reg; |
| 121 | |
| 122 | reg = readl(sector + JUNO_FLASH_SEC_SIZE - 0x04); |
| 123 | /* This makes up the string "HSLFTOOF" flash footer */ |
| 124 | if (reg != 0x464F4F54U) |
| 125 | continue; |
| 126 | reg = readl(sector + JUNO_FLASH_SEC_SIZE - 0x08); |
| 127 | if (reg != 0x464C5348U) |
| 128 | continue; |
| 129 | |
| 130 | for (offs = 0; offs < 32; offs += 4, len -= 4) { |
| 131 | reg = readl(sector + JUNO_FLASH_SEC_SIZE - 0x30 + offs); |
| 132 | if (strncmp(partname + offs, (char *)®, |
| 133 | len > 4 ? 4 : len)) |
| 134 | break; |
| 135 | |
| 136 | if (len > 4) |
| 137 | continue; |
| 138 | |
| 139 | reg = readl(sector + JUNO_FLASH_SEC_SIZE - 0x10); |
| 140 | imginfo = sector + JUNO_FLASH_SEC_SIZE - 0x30 - reg; |
| 141 | reg = readl(imginfo + 0x54); |
| 142 | |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 143 | return CFG_SYS_FLASH_BASE + |
Andre Przywara | 94504f4 | 2020-04-27 19:18:01 +0100 | [diff] [blame] | 144 | reg * JUNO_FLASH_SEC_SIZE; |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | printf("No DTB found\n"); |
| 149 | |
| 150 | return ~0; |
| 151 | } |
Peter Hoyes | baf62cf | 2021-11-11 09:26:02 +0000 | [diff] [blame] | 152 | #endif |
Andre Przywara | 94504f4 | 2020-04-27 19:18:01 +0100 | [diff] [blame] | 153 | |
Andre Przywara | 875685e | 2022-09-21 18:09:46 +0100 | [diff] [blame] | 154 | /* |
| 155 | * Filter for a valid DTB, as TF-A happens to provide a pointer to some |
| 156 | * data structure using the DTB format, which we cannot use. |
| 157 | * The address of the DTB cannot be 0, in fact this is the reserved value |
| 158 | * for x1 in the kernel boot protocol. |
| 159 | * And while the nt_fw_config.dtb used by TF-A is a valid DTB structure, it |
| 160 | * does not contain the typical nodes and properties, which we test for by |
| 161 | * probing for the mandatory /memory node. |
| 162 | */ |
| 163 | static bool is_valid_dtb(uintptr_t dtb_ptr) |
| 164 | { |
| 165 | if (dtb_ptr == 0 || fdt_magic(dtb_ptr) != FDT_MAGIC) |
| 166 | return false; |
| 167 | |
| 168 | return fdt_subnode_offset((void *)dtb_ptr, 0, "memory") >= 0; |
| 169 | } |
| 170 | |
Ilias Apalodimas | ab5348a | 2021-10-26 09:12:33 +0300 | [diff] [blame] | 171 | void *board_fdt_blob_setup(int *err) |
Andre Przywara | 94504f4 | 2020-04-27 19:18:01 +0100 | [diff] [blame] | 172 | { |
Peter Hoyes | baf62cf | 2021-11-11 09:26:02 +0000 | [diff] [blame] | 173 | #ifdef CONFIG_TARGET_VEXPRESS64_JUNO |
Andre Przywara | 94504f4 | 2020-04-27 19:18:01 +0100 | [diff] [blame] | 174 | phys_addr_t fdt_rom_addr = find_dtb_in_nor_flash(CONFIG_JUNO_DTB_PART); |
| 175 | |
Ilias Apalodimas | ab5348a | 2021-10-26 09:12:33 +0300 | [diff] [blame] | 176 | *err = 0; |
| 177 | if (fdt_rom_addr == ~0UL) { |
| 178 | *err = -ENXIO; |
Andre Przywara | 94504f4 | 2020-04-27 19:18:01 +0100 | [diff] [blame] | 179 | return NULL; |
Ilias Apalodimas | ab5348a | 2021-10-26 09:12:33 +0300 | [diff] [blame] | 180 | } |
Andre Przywara | 94504f4 | 2020-04-27 19:18:01 +0100 | [diff] [blame] | 181 | |
| 182 | return (void *)fdt_rom_addr; |
Peter Hoyes | baf62cf | 2021-11-11 09:26:02 +0000 | [diff] [blame] | 183 | #endif |
| 184 | |
| 185 | #ifdef VEXPRESS_FDT_ADDR |
| 186 | if (fdt_magic(VEXPRESS_FDT_ADDR) == FDT_MAGIC) { |
| 187 | *err = 0; |
| 188 | return (void *)VEXPRESS_FDT_ADDR; |
| 189 | } |
| 190 | #endif |
| 191 | |
Andre Przywara | 875685e | 2022-09-21 18:09:46 +0100 | [diff] [blame] | 192 | if (is_valid_dtb(prior_stage_fdt_address[1])) { |
| 193 | *err = 0; |
| 194 | return (void *)prior_stage_fdt_address[1]; |
| 195 | } else if (is_valid_dtb(prior_stage_fdt_address[0])) { |
Peter Hoyes | baf62cf | 2021-11-11 09:26:02 +0000 | [diff] [blame] | 196 | *err = 0; |
Andre Przywara | 875685e | 2022-09-21 18:09:46 +0100 | [diff] [blame] | 197 | return (void *)prior_stage_fdt_address[0]; |
Peter Hoyes | baf62cf | 2021-11-11 09:26:02 +0000 | [diff] [blame] | 198 | } |
| 199 | |
Andre Przywara | 395e9a9 | 2022-03-04 16:30:11 +0000 | [diff] [blame] | 200 | if (fdt_magic(gd->fdt_blob) == FDT_MAGIC) { |
| 201 | *err = 0; |
| 202 | return (void *)gd->fdt_blob; |
| 203 | } |
| 204 | |
Peter Hoyes | baf62cf | 2021-11-11 09:26:02 +0000 | [diff] [blame] | 205 | *err = -ENXIO; |
| 206 | return NULL; |
Andre Przywara | 94504f4 | 2020-04-27 19:18:01 +0100 | [diff] [blame] | 207 | } |
| 208 | #endif |
| 209 | |
Andre Przywara | 651c91b | 2020-04-27 19:18:02 +0100 | [diff] [blame] | 210 | /* Actual reset is done via PSCI. */ |
Harald Seiler | 6f14d5f | 2020-12-15 16:47:52 +0100 | [diff] [blame] | 211 | void reset_cpu(void) |
David Feng | 3b5458c | 2013-12-14 11:47:37 +0800 | [diff] [blame] | 212 | { |
Darwin Rambo | d32d411 | 2014-06-09 11:12:59 -0700 | [diff] [blame] | 213 | } |
| 214 | |
David Feng | 3b5458c | 2013-12-14 11:47:37 +0800 | [diff] [blame] | 215 | /* |
| 216 | * Board specific ethernet initialization routine. |
| 217 | */ |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 218 | int board_eth_init(struct bd_info *bis) |
David Feng | 3b5458c | 2013-12-14 11:47:37 +0800 | [diff] [blame] | 219 | { |
| 220 | int rc = 0; |
Andre Przywara | d263e76 | 2020-06-11 12:03:18 +0100 | [diff] [blame] | 221 | #ifndef CONFIG_DM_ETH |
Linus Walleij | 48b4755 | 2015-02-17 11:35:25 +0100 | [diff] [blame] | 222 | #ifdef CONFIG_SMC911X |
| 223 | rc = smc911x_initialize(0, CONFIG_SMC911X_BASE); |
| 224 | #endif |
Andre Przywara | d263e76 | 2020-06-11 12:03:18 +0100 | [diff] [blame] | 225 | #endif |
David Feng | 3b5458c | 2013-12-14 11:47:37 +0800 | [diff] [blame] | 226 | return rc; |
| 227 | } |