1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2017 Tuomas Tynkkynen
10 #include <efi_loader.h>
15 #include <virtio_types.h>
18 #include <linux/kernel.h>
19 #include <linux/sizes.h>
21 /* GUIDs for capsule updatable firmware images */
22 #define QEMU_ARM_UBOOT_IMAGE_GUID \
23 EFI_GUID(0xf885b085, 0x99f8, 0x45af, 0x84, 0x7d, \
24 0xd5, 0x14, 0x10, 0x7a, 0x4a, 0x2c)
26 #define QEMU_ARM64_UBOOT_IMAGE_GUID \
27 EFI_GUID(0x058b7d83, 0x50d5, 0x4c47, 0xa1, 0x95, \
28 0x60, 0xd8, 0x6a, 0xd3, 0x41, 0xc4)
31 #include <asm/armv8/mmu.h>
33 #if IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT)
34 struct efi_fw_image fw_images[] = {
35 #if defined(CONFIG_TARGET_QEMU_ARM_32BIT)
37 .image_type_id = QEMU_ARM_UBOOT_IMAGE_GUID,
38 .fw_name = u"Qemu-Arm-UBOOT",
41 #elif defined(CONFIG_TARGET_QEMU_ARM_64BIT)
43 .image_type_id = QEMU_ARM64_UBOOT_IMAGE_GUID,
44 .fw_name = u"Qemu-Arm-UBOOT",
50 struct efi_capsule_update_info update_info = {
51 .num_images = ARRAY_SIZE(fw_images),
55 #endif /* EFI_HAVE_CAPSULE_SUPPORT */
57 static struct mm_region qemu_arm64_mem_map[] = {
63 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
66 /* Lowmem peripherals */
70 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
72 PTE_BLOCK_PXN | PTE_BLOCK_UXN
77 .size = 255UL * SZ_1G,
78 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
81 /* Highmem PCI-E ECAM memory area */
82 .virt = 0x4010000000ULL,
83 .phys = 0x4010000000ULL,
85 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
87 PTE_BLOCK_PXN | PTE_BLOCK_UXN
89 /* Highmem PCI-E MMIO memory area */
90 .virt = 0x8000000000ULL,
91 .phys = 0x8000000000ULL,
92 .size = 0x8000000000ULL,
93 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
95 PTE_BLOCK_PXN | PTE_BLOCK_UXN
102 struct mm_region *mem_map = qemu_arm64_mem_map;
110 int board_late_init(void)
113 * Make sure virtio bus is enumerated so that peripherals
114 * on the virtio bus can be discovered by their drivers
118 /* start usb so that usb keyboard can be used as input device */
119 if (CONFIG_IS_ENABLED(USB_KEYBOARD))
127 if (fdtdec_setup_mem_size_base() != 0)
131 * When LPAE is enabled (ARMv7),
132 * 1:1 mapping is created using 2 MB blocks.
134 * In case amount of memory provided to QEMU
135 * is not multiple of 2 MB, round down the amount
136 * of available memory to avoid hang during MMU
139 if (CONFIG_IS_ENABLED(ARMV7_LPAE))
140 gd->ram_size -= (gd->ram_size % 0x200000);
145 int dram_init_banksize(void)
147 fdtdec_setup_memory_banksize();
152 int board_fdt_blob_setup(void **fdtp)
154 /* QEMU loads a generated DTB for us at the start of RAM. */
155 *fdtp = (void *)CFG_SYS_SDRAM_BASE;
160 void enable_caches(void)
172 u8 flash_read8(void *addr)
176 asm("ldrb %" __W "0, %1" : "=r"(ret) : "m"(*(u8 *)addr));
180 u16 flash_read16(void *addr)
184 asm("ldrh %" __W "0, %1" : "=r"(ret) : "m"(*(u16 *)addr));
188 u32 flash_read32(void *addr)
192 asm("ldr %" __W "0, %1" : "=r"(ret) : "m"(*(u32 *)addr));
196 void flash_write8(u8 value, void *addr)
198 asm("strb %" __W "1, %0" : "=m"(*(u8 *)addr) : "r"(value));
201 void flash_write16(u16 value, void *addr)
203 asm("strh %" __W "1, %0" : "=m"(*(u16 *)addr) : "r"(value));
206 void flash_write32(u32 value, void *addr)
208 asm("str %" __W "1, %0" : "=m"(*(u32 *)addr) : "r"(value));