blob: aa68bef469a66ac1e738c1ce0145287ae1681a3b [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>
Tuomas Tynkkynen28cac522017-09-19 23:18:07 +03009#include <fdtdec.h>
Simon Glass97589732020-05-10 11:40:02 -060010#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060011#include <log.h>
Bin Menga94f6a02018-10-15 02:21:19 -070012#include <virtio_types.h>
13#include <virtio.h>
Tuomas Tynkkynen28cac522017-09-19 23:18:07 +030014
Tuomas Tynkkynendfdd46d2018-01-11 16:11:23 +020015#ifdef CONFIG_ARM64
16#include <asm/armv8/mmu.h>
17
18static 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 Tynkkynene09ca642018-09-04 18:16:52 +030027 /* Lowmem peripherals */
Tuomas Tynkkynendfdd46d2018-01-11 16:11:23 +020028 .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 Tynkkynenac927392018-05-14 18:47:51 +030038 .size = 255UL * SZ_1G,
Tuomas Tynkkynendfdd46d2018-01-11 16:11:23 +020039 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
40 PTE_BLOCK_INNER_SHARE
41 }, {
Tuomas Tynkkynene09ca642018-09-04 18:16:52 +030042 /* 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 Tynkkynendfdd46d2018-01-11 16:11:23 +020058 /* List terminator */
59 0,
60 }
61};
62
63struct mm_region *mem_map = qemu_arm64_mem_map;
64#endif
65
Tuomas Tynkkynen28cac522017-09-19 23:18:07 +030066int board_init(void)
67{
Sughosh Ganu1316a702020-12-30 19:27:00 +053068 return 0;
69}
70
71int board_late_init(void)
72{
Bin Menga94f6a02018-10-15 02:21:19 -070073 /*
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 Tynkkynen28cac522017-09-19 23:18:07 +030079 return 0;
80}
81
82int dram_init(void)
83{
Siva Durga Prasad Paladugub3d55ea2018-07-16 15:56:11 +053084 if (fdtdec_setup_mem_size_base() != 0)
Tuomas Tynkkynen28cac522017-09-19 23:18:07 +030085 return -EINVAL;
86
87 return 0;
88}
89
90int dram_init_banksize(void)
91{
92 fdtdec_setup_memory_banksize();
93
94 return 0;
95}
96
97void *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 Ganu7064a5d2019-12-29 00:01:05 +0530102
Ard Biesheuvel58f0bb92020-07-07 12:07:09 +0200103void enable_caches(void)
104{
105 icache_enable();
106 dcache_enable();
107}
108
Sughosh Ganu7064a5d2019-12-29 00:01:05 +0530109#if defined(CONFIG_EFI_RNG_PROTOCOL)
110#include <efi_loader.h>
111#include <efi_rng.h>
112
113#include <dm/device-internal.h>
114
115efi_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 Biesheuvelcd360da2020-07-07 12:07:11 +0200150
151#ifdef CONFIG_ARM64
152#define __W "w"
153#else
154#define __W
155#endif
156
157u8 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
165u16 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
173u32 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
181void flash_write8(u8 value, void *addr)
182{
183 asm("strb %" __W "1, %0" : "=m"(*(u8 *)addr) : "r"(value));
184}
185
186void flash_write16(u16 value, void *addr)
187{
188 asm("strh %" __W "1, %0" : "=m"(*(u16 *)addr) : "r"(value));
189}
190
191void flash_write32(u32 value, void *addr)
192{
193 asm("str %" __W "1, %0" : "=m"(*(u32 *)addr) : "r"(value));
194}