blob: dae37640bc5bb2e43341117335ca787e3676631b [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Tuomas Tynkkynen28cac522017-09-19 23:18:07 +03002/*
3 * Copyright (c) 2017 Tuomas Tynkkynen
Tuomas Tynkkynen28cac522017-09-19 23:18:07 +03004 */
Bin Menga94f6a02018-10-15 02:21:19 -07005
Tuomas Tynkkynen28cac522017-09-19 23:18:07 +03006#include <common.h>
Ard Biesheuvel58f0bb92020-07-07 12:07:09 +02007#include <cpu_func.h>
Bin Menga94f6a02018-10-15 02:21:19 -07008#include <dm.h>
Sughosh Ganuccb36462022-04-15 11:29:34 +05309#include <efi.h>
10#include <efi_loader.h>
Tuomas Tynkkynen28cac522017-09-19 23:18:07 +030011#include <fdtdec.h>
Simon Glass97589732020-05-10 11:40:02 -060012#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060013#include <log.h>
Bin Menga94f6a02018-10-15 02:21:19 -070014#include <virtio_types.h>
15#include <virtio.h>
Tuomas Tynkkynen28cac522017-09-19 23:18:07 +030016
Sughosh Ganuccb36462022-04-15 11:29:34 +053017#include <linux/kernel.h>
Simon Glassdeffa692023-01-28 15:00:28 -070018#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 Ganuccb36462022-04-15 11:29:34 +053028
Tuomas Tynkkynendfdd46d2018-01-11 16:11:23 +020029#ifdef CONFIG_ARM64
30#include <asm/armv8/mmu.h>
31
Sughosh Ganuccb36462022-04-15 11:29:34 +053032#if CONFIG_IS_ENABLED(EFI_HAVE_CAPSULE_SUPPORT)
33struct 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
49struct efi_capsule_update_info update_info = {
50 .images = fw_images,
51};
52
53u8 num_image_type_guids = ARRAY_SIZE(fw_images);
54#endif /* EFI_HAVE_CAPSULE_SUPPORT */
55
Tuomas Tynkkynendfdd46d2018-01-11 16:11:23 +020056static 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 Tynkkynene09ca642018-09-04 18:16:52 +030065 /* Lowmem peripherals */
Tuomas Tynkkynendfdd46d2018-01-11 16:11:23 +020066 .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 Tynkkynenac927392018-05-14 18:47:51 +030076 .size = 255UL * SZ_1G,
Tuomas Tynkkynendfdd46d2018-01-11 16:11:23 +020077 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
78 PTE_BLOCK_INNER_SHARE
79 }, {
Tuomas Tynkkynene09ca642018-09-04 18:16:52 +030080 /* 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 Tynkkynendfdd46d2018-01-11 16:11:23 +020096 /* List terminator */
97 0,
98 }
99};
100
101struct mm_region *mem_map = qemu_arm64_mem_map;
102#endif
103
Tuomas Tynkkynen28cac522017-09-19 23:18:07 +0300104int board_init(void)
105{
Sughosh Ganu1316a702020-12-30 19:27:00 +0530106 return 0;
107}
108
109int board_late_init(void)
110{
Bin Menga94f6a02018-10-15 02:21:19 -0700111 /*
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 Tynkkynen28cac522017-09-19 23:18:07 +0300117 return 0;
118}
119
120int dram_init(void)
121{
Siva Durga Prasad Paladugub3d55ea2018-07-16 15:56:11 +0530122 if (fdtdec_setup_mem_size_base() != 0)
Tuomas Tynkkynen28cac522017-09-19 23:18:07 +0300123 return -EINVAL;
124
125 return 0;
126}
127
128int dram_init_banksize(void)
129{
130 fdtdec_setup_memory_banksize();
131
132 return 0;
133}
134
Ilias Apalodimasab5348a2021-10-26 09:12:33 +0300135void *board_fdt_blob_setup(int *err)
Tuomas Tynkkynen28cac522017-09-19 23:18:07 +0300136{
Ilias Apalodimasab5348a2021-10-26 09:12:33 +0300137 *err = 0;
Tuomas Tynkkynen28cac522017-09-19 23:18:07 +0300138 /* QEMU loads a generated DTB for us at the start of RAM. */
Tom Rinibb4dd962022-11-16 13:10:37 -0500139 return (void *)CFG_SYS_SDRAM_BASE;
Tuomas Tynkkynen28cac522017-09-19 23:18:07 +0300140}
Sughosh Ganu7064a5d2019-12-29 00:01:05 +0530141
Ard Biesheuvel58f0bb92020-07-07 12:07:09 +0200142void enable_caches(void)
143{
144 icache_enable();
145 dcache_enable();
146}
147
Ard Biesheuvelcd360da2020-07-07 12:07:11 +0200148#ifdef CONFIG_ARM64
149#define __W "w"
150#else
151#define __W
152#endif
153
154u8 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
162u16 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
170u32 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
178void flash_write8(u8 value, void *addr)
179{
180 asm("strb %" __W "1, %0" : "=m"(*(u8 *)addr) : "r"(value));
181}
182
183void flash_write16(u16 value, void *addr)
184{
185 asm("strh %" __W "1, %0" : "=m"(*(u16 *)addr) : "r"(value));
186}
187
188void flash_write32(u32 value, void *addr)
189{
190 asm("str %" __W "1, %0" : "=m"(*(u32 *)addr) : "r"(value));
191}