blob: 16d5a97167a6a8e5f26f6d6cda30ffe76a5ff2f3 [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
Ilias Apalodimasab5348a2021-10-26 09:12:33 +030097void *board_fdt_blob_setup(int *err)
Tuomas Tynkkynen28cac522017-09-19 23:18:07 +030098{
Ilias Apalodimasab5348a2021-10-26 09:12:33 +030099 *err = 0;
Tuomas Tynkkynen28cac522017-09-19 23:18:07 +0300100 /* QEMU loads a generated DTB for us at the start of RAM. */
101 return (void *)CONFIG_SYS_SDRAM_BASE;
102}
Sughosh Ganu7064a5d2019-12-29 00:01:05 +0530103
Ard Biesheuvel58f0bb92020-07-07 12:07:09 +0200104void enable_caches(void)
105{
106 icache_enable();
107 dcache_enable();
108}
109
Sughosh Ganu7064a5d2019-12-29 00:01:05 +0530110#if defined(CONFIG_EFI_RNG_PROTOCOL)
111#include <efi_loader.h>
112#include <efi_rng.h>
113
114#include <dm/device-internal.h>
115
116efi_status_t platform_get_rng_device(struct udevice **dev)
117{
118 int ret;
119 efi_status_t status = EFI_DEVICE_ERROR;
120 struct udevice *bus, *devp;
121
122 for (uclass_first_device(UCLASS_VIRTIO, &bus); bus;
123 uclass_next_device(&bus)) {
124 for (device_find_first_child(bus, &devp); devp;
125 device_find_next_child(&devp)) {
126 if (device_get_uclass_id(devp) == UCLASS_RNG) {
127 *dev = devp;
128 status = EFI_SUCCESS;
129 break;
130 }
131 }
132 }
133
134 if (status != EFI_SUCCESS) {
135 debug("No rng device found\n");
136 return EFI_DEVICE_ERROR;
137 }
138
139 if (*dev) {
140 ret = device_probe(*dev);
141 if (ret)
142 return EFI_DEVICE_ERROR;
143 } else {
144 debug("Couldn't get child device\n");
145 return EFI_DEVICE_ERROR;
146 }
147
148 return EFI_SUCCESS;
149}
150#endif /* CONFIG_EFI_RNG_PROTOCOL */
Ard Biesheuvelcd360da2020-07-07 12:07:11 +0200151
152#ifdef CONFIG_ARM64
153#define __W "w"
154#else
155#define __W
156#endif
157
158u8 flash_read8(void *addr)
159{
160 u8 ret;
161
162 asm("ldrb %" __W "0, %1" : "=r"(ret) : "m"(*(u8 *)addr));
163 return ret;
164}
165
166u16 flash_read16(void *addr)
167{
168 u16 ret;
169
170 asm("ldrh %" __W "0, %1" : "=r"(ret) : "m"(*(u16 *)addr));
171 return ret;
172}
173
174u32 flash_read32(void *addr)
175{
176 u32 ret;
177
178 asm("ldr %" __W "0, %1" : "=r"(ret) : "m"(*(u32 *)addr));
179 return ret;
180}
181
182void flash_write8(u8 value, void *addr)
183{
184 asm("strb %" __W "1, %0" : "=m"(*(u8 *)addr) : "r"(value));
185}
186
187void flash_write16(u16 value, void *addr)
188{
189 asm("strh %" __W "1, %0" : "=m"(*(u16 *)addr) : "r"(value));
190}
191
192void flash_write32(u32 value, void *addr)
193{
194 asm("str %" __W "1, %0" : "=m"(*(u32 *)addr) : "r"(value));
195}