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> |
Sughosh Ganu | ccb3646 | 2022-04-15 11:29:34 +0530 | [diff] [blame] | 9 | #include <efi.h> |
| 10 | #include <efi_loader.h> |
Tuomas Tynkkynen | 28cac52 | 2017-09-19 23:18:07 +0300 | [diff] [blame] | 11 | #include <fdtdec.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 12 | #include <init.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 13 | #include <log.h> |
Bin Meng | a94f6a0 | 2018-10-15 02:21:19 -0700 | [diff] [blame] | 14 | #include <virtio_types.h> |
| 15 | #include <virtio.h> |
Tuomas Tynkkynen | 28cac52 | 2017-09-19 23:18:07 +0300 | [diff] [blame] | 16 | |
Sughosh Ganu | ccb3646 | 2022-04-15 11:29:34 +0530 | [diff] [blame] | 17 | #include <linux/kernel.h> |
Simon Glass | deffa69 | 2023-01-28 15:00:28 -0700 | [diff] [blame] | 18 | #include <linux/sizes.h> |
| 19 | |
| 20 | /* GUIDs for capsule updatable firmware images */ |
| 21 | #define QEMU_ARM_UBOOT_IMAGE_GUID \ |
| 22 | EFI_GUID(0xf885b085, 0x99f8, 0x45af, 0x84, 0x7d, \ |
| 23 | 0xd5, 0x14, 0x10, 0x7a, 0x4a, 0x2c) |
| 24 | |
| 25 | #define QEMU_ARM64_UBOOT_IMAGE_GUID \ |
| 26 | EFI_GUID(0x058b7d83, 0x50d5, 0x4c47, 0xa1, 0x95, \ |
| 27 | 0x60, 0xd8, 0x6a, 0xd3, 0x41, 0xc4) |
Sughosh Ganu | ccb3646 | 2022-04-15 11:29:34 +0530 | [diff] [blame] | 28 | |
Tuomas Tynkkynen | dfdd46d | 2018-01-11 16:11:23 +0200 | [diff] [blame] | 29 | #ifdef CONFIG_ARM64 |
| 30 | #include <asm/armv8/mmu.h> |
| 31 | |
Simon Glass | b819621 | 2023-02-05 15:39:42 -0700 | [diff] [blame] | 32 | #if IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) |
Sughosh Ganu | ccb3646 | 2022-04-15 11:29:34 +0530 | [diff] [blame] | 33 | struct efi_fw_image fw_images[] = { |
| 34 | #if defined(CONFIG_TARGET_QEMU_ARM_32BIT) |
| 35 | { |
| 36 | .image_type_id = QEMU_ARM_UBOOT_IMAGE_GUID, |
| 37 | .fw_name = u"Qemu-Arm-UBOOT", |
| 38 | .image_index = 1, |
| 39 | }, |
| 40 | #elif defined(CONFIG_TARGET_QEMU_ARM_64BIT) |
| 41 | { |
| 42 | .image_type_id = QEMU_ARM64_UBOOT_IMAGE_GUID, |
| 43 | .fw_name = u"Qemu-Arm-UBOOT", |
| 44 | .image_index = 1, |
| 45 | }, |
| 46 | #endif |
| 47 | }; |
| 48 | |
| 49 | struct efi_capsule_update_info update_info = { |
Masahisa Kojima | 5d2438b | 2023-06-07 14:41:51 +0900 | [diff] [blame] | 50 | .num_images = ARRAY_SIZE(fw_images) |
Sughosh Ganu | ccb3646 | 2022-04-15 11:29:34 +0530 | [diff] [blame] | 51 | .images = fw_images, |
| 52 | }; |
| 53 | |
Sughosh Ganu | ccb3646 | 2022-04-15 11:29:34 +0530 | [diff] [blame] | 54 | #endif /* EFI_HAVE_CAPSULE_SUPPORT */ |
| 55 | |
Tuomas Tynkkynen | dfdd46d | 2018-01-11 16:11:23 +0200 | [diff] [blame] | 56 | static struct mm_region qemu_arm64_mem_map[] = { |
| 57 | { |
| 58 | /* Flash */ |
| 59 | .virt = 0x00000000UL, |
| 60 | .phys = 0x00000000UL, |
| 61 | .size = 0x08000000UL, |
| 62 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 63 | PTE_BLOCK_INNER_SHARE |
| 64 | }, { |
Tuomas Tynkkynen | e09ca64 | 2018-09-04 18:16:52 +0300 | [diff] [blame] | 65 | /* Lowmem peripherals */ |
Tuomas Tynkkynen | dfdd46d | 2018-01-11 16:11:23 +0200 | [diff] [blame] | 66 | .virt = 0x08000000UL, |
| 67 | .phys = 0x08000000UL, |
| 68 | .size = 0x38000000, |
| 69 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 70 | PTE_BLOCK_NON_SHARE | |
| 71 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 72 | }, { |
| 73 | /* RAM */ |
| 74 | .virt = 0x40000000UL, |
| 75 | .phys = 0x40000000UL, |
Tuomas Tynkkynen | ac92739 | 2018-05-14 18:47:51 +0300 | [diff] [blame] | 76 | .size = 255UL * SZ_1G, |
Tuomas Tynkkynen | dfdd46d | 2018-01-11 16:11:23 +0200 | [diff] [blame] | 77 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 78 | PTE_BLOCK_INNER_SHARE |
| 79 | }, { |
Tuomas Tynkkynen | e09ca64 | 2018-09-04 18:16:52 +0300 | [diff] [blame] | 80 | /* Highmem PCI-E ECAM memory area */ |
| 81 | .virt = 0x4010000000ULL, |
| 82 | .phys = 0x4010000000ULL, |
| 83 | .size = 0x10000000, |
| 84 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 85 | PTE_BLOCK_NON_SHARE | |
| 86 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 87 | }, { |
| 88 | /* Highmem PCI-E MMIO memory area */ |
| 89 | .virt = 0x8000000000ULL, |
| 90 | .phys = 0x8000000000ULL, |
| 91 | .size = 0x8000000000ULL, |
| 92 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 93 | PTE_BLOCK_NON_SHARE | |
| 94 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 95 | }, { |
Tuomas Tynkkynen | dfdd46d | 2018-01-11 16:11:23 +0200 | [diff] [blame] | 96 | /* List terminator */ |
| 97 | 0, |
| 98 | } |
| 99 | }; |
| 100 | |
| 101 | struct mm_region *mem_map = qemu_arm64_mem_map; |
| 102 | #endif |
| 103 | |
Tuomas Tynkkynen | 28cac52 | 2017-09-19 23:18:07 +0300 | [diff] [blame] | 104 | int board_init(void) |
| 105 | { |
Sughosh Ganu | 1316a70 | 2020-12-30 19:27:00 +0530 | [diff] [blame] | 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | int board_late_init(void) |
| 110 | { |
Bin Meng | a94f6a0 | 2018-10-15 02:21:19 -0700 | [diff] [blame] | 111 | /* |
| 112 | * Make sure virtio bus is enumerated so that peripherals |
| 113 | * on the virtio bus can be discovered by their drivers |
| 114 | */ |
| 115 | virtio_init(); |
| 116 | |
Tuomas Tynkkynen | 28cac52 | 2017-09-19 23:18:07 +0300 | [diff] [blame] | 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | int dram_init(void) |
| 121 | { |
Siva Durga Prasad Paladugu | b3d55ea | 2018-07-16 15:56:11 +0530 | [diff] [blame] | 122 | if (fdtdec_setup_mem_size_base() != 0) |
Tuomas Tynkkynen | 28cac52 | 2017-09-19 23:18:07 +0300 | [diff] [blame] | 123 | return -EINVAL; |
| 124 | |
| 125 | return 0; |
| 126 | } |
| 127 | |
| 128 | int dram_init_banksize(void) |
| 129 | { |
| 130 | fdtdec_setup_memory_banksize(); |
| 131 | |
| 132 | return 0; |
| 133 | } |
| 134 | |
Ilias Apalodimas | ab5348a | 2021-10-26 09:12:33 +0300 | [diff] [blame] | 135 | void *board_fdt_blob_setup(int *err) |
Tuomas Tynkkynen | 28cac52 | 2017-09-19 23:18:07 +0300 | [diff] [blame] | 136 | { |
Ilias Apalodimas | ab5348a | 2021-10-26 09:12:33 +0300 | [diff] [blame] | 137 | *err = 0; |
Tuomas Tynkkynen | 28cac52 | 2017-09-19 23:18:07 +0300 | [diff] [blame] | 138 | /* QEMU loads a generated DTB for us at the start of RAM. */ |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 139 | return (void *)CFG_SYS_SDRAM_BASE; |
Tuomas Tynkkynen | 28cac52 | 2017-09-19 23:18:07 +0300 | [diff] [blame] | 140 | } |
Sughosh Ganu | 7064a5d | 2019-12-29 00:01:05 +0530 | [diff] [blame] | 141 | |
Ard Biesheuvel | 58f0bb9 | 2020-07-07 12:07:09 +0200 | [diff] [blame] | 142 | void enable_caches(void) |
| 143 | { |
| 144 | icache_enable(); |
| 145 | dcache_enable(); |
| 146 | } |
| 147 | |
Ard Biesheuvel | cd360da | 2020-07-07 12:07:11 +0200 | [diff] [blame] | 148 | #ifdef CONFIG_ARM64 |
| 149 | #define __W "w" |
| 150 | #else |
| 151 | #define __W |
| 152 | #endif |
| 153 | |
| 154 | u8 flash_read8(void *addr) |
| 155 | { |
| 156 | u8 ret; |
| 157 | |
| 158 | asm("ldrb %" __W "0, %1" : "=r"(ret) : "m"(*(u8 *)addr)); |
| 159 | return ret; |
| 160 | } |
| 161 | |
| 162 | u16 flash_read16(void *addr) |
| 163 | { |
| 164 | u16 ret; |
| 165 | |
| 166 | asm("ldrh %" __W "0, %1" : "=r"(ret) : "m"(*(u16 *)addr)); |
| 167 | return ret; |
| 168 | } |
| 169 | |
| 170 | u32 flash_read32(void *addr) |
| 171 | { |
| 172 | u32 ret; |
| 173 | |
| 174 | asm("ldr %" __W "0, %1" : "=r"(ret) : "m"(*(u32 *)addr)); |
| 175 | return ret; |
| 176 | } |
| 177 | |
| 178 | void flash_write8(u8 value, void *addr) |
| 179 | { |
| 180 | asm("strb %" __W "1, %0" : "=m"(*(u8 *)addr) : "r"(value)); |
| 181 | } |
| 182 | |
| 183 | void flash_write16(u16 value, void *addr) |
| 184 | { |
| 185 | asm("strh %" __W "1, %0" : "=m"(*(u16 *)addr) : "r"(value)); |
| 186 | } |
| 187 | |
| 188 | void flash_write32(u32 value, void *addr) |
| 189 | { |
| 190 | asm("str %" __W "1, %0" : "=m"(*(u32 *)addr) : "r"(value)); |
| 191 | } |