Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Tuomas Tynkkynen | 28cac52 | 2017-09-19 23:18:07 +0300 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2017 Tuomas Tynkkynen |
Tuomas Tynkkynen | 28cac52 | 2017-09-19 23:18:07 +0300 | [diff] [blame] | 4 | */ |
Bin Meng | a94f6a0 | 2018-10-15 02:21:19 -0700 | [diff] [blame] | 5 | |
Tuomas Tynkkynen | 28cac52 | 2017-09-19 23:18:07 +0300 | [diff] [blame] | 6 | #include <common.h> |
Ard Biesheuvel | 58f0bb9 | 2020-07-07 12:07:09 +0200 | [diff] [blame] | 7 | #include <cpu_func.h> |
Bin Meng | a94f6a0 | 2018-10-15 02:21:19 -0700 | [diff] [blame] | 8 | #include <dm.h> |
Tuomas Tynkkynen | 28cac52 | 2017-09-19 23:18:07 +0300 | [diff] [blame] | 9 | #include <fdtdec.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 10 | #include <init.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Bin Meng | a94f6a0 | 2018-10-15 02:21:19 -0700 | [diff] [blame] | 12 | #include <virtio_types.h> |
| 13 | #include <virtio.h> |
Tuomas Tynkkynen | 28cac52 | 2017-09-19 23:18:07 +0300 | [diff] [blame] | 14 | |
Tuomas Tynkkynen | dfdd46d | 2018-01-11 16:11:23 +0200 | [diff] [blame] | 15 | #ifdef CONFIG_ARM64 |
| 16 | #include <asm/armv8/mmu.h> |
| 17 | |
| 18 | static struct mm_region qemu_arm64_mem_map[] = { |
| 19 | { |
| 20 | /* Flash */ |
| 21 | .virt = 0x00000000UL, |
| 22 | .phys = 0x00000000UL, |
| 23 | .size = 0x08000000UL, |
| 24 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 25 | PTE_BLOCK_INNER_SHARE |
| 26 | }, { |
Tuomas Tynkkynen | e09ca64 | 2018-09-04 18:16:52 +0300 | [diff] [blame] | 27 | /* Lowmem peripherals */ |
Tuomas Tynkkynen | dfdd46d | 2018-01-11 16:11:23 +0200 | [diff] [blame] | 28 | .virt = 0x08000000UL, |
| 29 | .phys = 0x08000000UL, |
| 30 | .size = 0x38000000, |
| 31 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 32 | PTE_BLOCK_NON_SHARE | |
| 33 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 34 | }, { |
| 35 | /* RAM */ |
| 36 | .virt = 0x40000000UL, |
| 37 | .phys = 0x40000000UL, |
Tuomas Tynkkynen | ac92739 | 2018-05-14 18:47:51 +0300 | [diff] [blame] | 38 | .size = 255UL * SZ_1G, |
Tuomas Tynkkynen | dfdd46d | 2018-01-11 16:11:23 +0200 | [diff] [blame] | 39 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 40 | PTE_BLOCK_INNER_SHARE |
| 41 | }, { |
Tuomas Tynkkynen | e09ca64 | 2018-09-04 18:16:52 +0300 | [diff] [blame] | 42 | /* Highmem PCI-E ECAM memory area */ |
| 43 | .virt = 0x4010000000ULL, |
| 44 | .phys = 0x4010000000ULL, |
| 45 | .size = 0x10000000, |
| 46 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 47 | PTE_BLOCK_NON_SHARE | |
| 48 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 49 | }, { |
| 50 | /* Highmem PCI-E MMIO memory area */ |
| 51 | .virt = 0x8000000000ULL, |
| 52 | .phys = 0x8000000000ULL, |
| 53 | .size = 0x8000000000ULL, |
| 54 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 55 | PTE_BLOCK_NON_SHARE | |
| 56 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 57 | }, { |
Tuomas Tynkkynen | dfdd46d | 2018-01-11 16:11:23 +0200 | [diff] [blame] | 58 | /* List terminator */ |
| 59 | 0, |
| 60 | } |
| 61 | }; |
| 62 | |
| 63 | struct mm_region *mem_map = qemu_arm64_mem_map; |
| 64 | #endif |
| 65 | |
Tuomas Tynkkynen | 28cac52 | 2017-09-19 23:18:07 +0300 | [diff] [blame] | 66 | int board_init(void) |
| 67 | { |
Sughosh Ganu | 1316a70 | 2020-12-30 19:27:00 +0530 | [diff] [blame] | 68 | return 0; |
| 69 | } |
| 70 | |
| 71 | int board_late_init(void) |
| 72 | { |
Bin Meng | a94f6a0 | 2018-10-15 02:21:19 -0700 | [diff] [blame] | 73 | /* |
| 74 | * Make sure virtio bus is enumerated so that peripherals |
| 75 | * on the virtio bus can be discovered by their drivers |
| 76 | */ |
| 77 | virtio_init(); |
| 78 | |
Tuomas Tynkkynen | 28cac52 | 2017-09-19 23:18:07 +0300 | [diff] [blame] | 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | int dram_init(void) |
| 83 | { |
Siva Durga Prasad Paladugu | b3d55ea | 2018-07-16 15:56:11 +0530 | [diff] [blame] | 84 | if (fdtdec_setup_mem_size_base() != 0) |
Tuomas Tynkkynen | 28cac52 | 2017-09-19 23:18:07 +0300 | [diff] [blame] | 85 | return -EINVAL; |
| 86 | |
| 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | int dram_init_banksize(void) |
| 91 | { |
| 92 | fdtdec_setup_memory_banksize(); |
| 93 | |
| 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | void *board_fdt_blob_setup(void) |
| 98 | { |
| 99 | /* QEMU loads a generated DTB for us at the start of RAM. */ |
| 100 | return (void *)CONFIG_SYS_SDRAM_BASE; |
| 101 | } |
Sughosh Ganu | 7064a5d | 2019-12-29 00:01:05 +0530 | [diff] [blame] | 102 | |
Ard Biesheuvel | 58f0bb9 | 2020-07-07 12:07:09 +0200 | [diff] [blame] | 103 | void enable_caches(void) |
| 104 | { |
| 105 | icache_enable(); |
| 106 | dcache_enable(); |
| 107 | } |
| 108 | |
Sughosh Ganu | 7064a5d | 2019-12-29 00:01:05 +0530 | [diff] [blame] | 109 | #if defined(CONFIG_EFI_RNG_PROTOCOL) |
| 110 | #include <efi_loader.h> |
| 111 | #include <efi_rng.h> |
| 112 | |
| 113 | #include <dm/device-internal.h> |
| 114 | |
| 115 | efi_status_t platform_get_rng_device(struct udevice **dev) |
| 116 | { |
| 117 | int ret; |
| 118 | efi_status_t status = EFI_DEVICE_ERROR; |
| 119 | struct udevice *bus, *devp; |
| 120 | |
| 121 | for (uclass_first_device(UCLASS_VIRTIO, &bus); bus; |
| 122 | uclass_next_device(&bus)) { |
| 123 | for (device_find_first_child(bus, &devp); devp; |
| 124 | device_find_next_child(&devp)) { |
| 125 | if (device_get_uclass_id(devp) == UCLASS_RNG) { |
| 126 | *dev = devp; |
| 127 | status = EFI_SUCCESS; |
| 128 | break; |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | if (status != EFI_SUCCESS) { |
| 134 | debug("No rng device found\n"); |
| 135 | return EFI_DEVICE_ERROR; |
| 136 | } |
| 137 | |
| 138 | if (*dev) { |
| 139 | ret = device_probe(*dev); |
| 140 | if (ret) |
| 141 | return EFI_DEVICE_ERROR; |
| 142 | } else { |
| 143 | debug("Couldn't get child device\n"); |
| 144 | return EFI_DEVICE_ERROR; |
| 145 | } |
| 146 | |
| 147 | return EFI_SUCCESS; |
| 148 | } |
| 149 | #endif /* CONFIG_EFI_RNG_PROTOCOL */ |
Ard Biesheuvel | cd360da | 2020-07-07 12:07:11 +0200 | [diff] [blame] | 150 | |
| 151 | #ifdef CONFIG_ARM64 |
| 152 | #define __W "w" |
| 153 | #else |
| 154 | #define __W |
| 155 | #endif |
| 156 | |
| 157 | u8 flash_read8(void *addr) |
| 158 | { |
| 159 | u8 ret; |
| 160 | |
| 161 | asm("ldrb %" __W "0, %1" : "=r"(ret) : "m"(*(u8 *)addr)); |
| 162 | return ret; |
| 163 | } |
| 164 | |
| 165 | u16 flash_read16(void *addr) |
| 166 | { |
| 167 | u16 ret; |
| 168 | |
| 169 | asm("ldrh %" __W "0, %1" : "=r"(ret) : "m"(*(u16 *)addr)); |
| 170 | return ret; |
| 171 | } |
| 172 | |
| 173 | u32 flash_read32(void *addr) |
| 174 | { |
| 175 | u32 ret; |
| 176 | |
| 177 | asm("ldr %" __W "0, %1" : "=r"(ret) : "m"(*(u32 *)addr)); |
| 178 | return ret; |
| 179 | } |
| 180 | |
| 181 | void flash_write8(u8 value, void *addr) |
| 182 | { |
| 183 | asm("strb %" __W "1, %0" : "=m"(*(u8 *)addr) : "r"(value)); |
| 184 | } |
| 185 | |
| 186 | void flash_write16(u16 value, void *addr) |
| 187 | { |
| 188 | asm("strh %" __W "1, %0" : "=m"(*(u16 *)addr) : "r"(value)); |
| 189 | } |
| 190 | |
| 191 | void flash_write32(u32 value, void *addr) |
| 192 | { |
| 193 | asm("str %" __W "1, %0" : "=m"(*(u32 *)addr) : "r"(value)); |
| 194 | } |