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