Skip to content

Commit 77fbed5

Browse files
GuEe-GUIRbb666
authored andcommitted
[libcpu][aarch64] Update for DM
1. PSCI port to system power. 2. Support builtin fdt. 3. Update system aspace size. 4. Support DMA memory probe. 5. Fixup not backtrace in Serror for device bus fault. Signed-off-by: GuEe-GUI <[email protected]>
1 parent d09135f commit 77fbed5

File tree

4 files changed

+133
-21
lines changed

4 files changed

+133
-21
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (c) 2006-2022, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2022-08-24 GuEe-GUI first version
9+
*/
10+
11+
#include <rtconfig.h>
12+
13+
.data
14+
15+
.align 8
16+
.globl rt_hw_builtin_fdt
17+
rt_hw_builtin_fdt:
18+
#ifdef RT_BUILTIN_FDT_PATH
19+
.incbin RT_BUILTIN_FDT_PATH
20+
#endif

libcpu/aarch64/common/psci.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <drivers/ofw.h>
2323
#include <drivers/platform.h>
2424
#include <drivers/core/dm.h>
25+
#include <drivers/core/power.h>
2526

2627
struct psci_ops
2728
{
@@ -98,16 +99,9 @@ static rt_uint32_t psci_get_features(rt_uint32_t psci_func_id)
9899
/* PSCI CPU_ON */
99100
static rt_uint32_t psci_cpu_on(rt_uint32_t func_id, int cpuid, rt_ubase_t entry_point)
100101
{
101-
rt_uint32_t ret = -PSCI_RET_INVALID_PARAMETERS;
102-
103-
if (cpuid < RT_CPUS_NR)
104-
{
105-
rt_ubase_t mpid = rt_cpu_mpidr_table[cpuid] & MPIDR_MASK;
106-
107-
ret = (rt_uint32_t)psci_call(func_id, mpid, entry_point, 0);
108-
}
102+
rt_ubase_t mpid = rt_cpu_mpidr_table[cpuid] & MPIDR_MASK;
109103

110-
return ret;
104+
return (rt_uint32_t)psci_call(func_id, mpid, entry_point, 0);
111105
}
112106

113107
static rt_uint32_t psci_0_1_cpu_on(int cpuid, rt_ubase_t entry_point)
@@ -211,7 +205,6 @@ void psci_system_reboot(void)
211205
{
212206
psci_call(PSCI_0_2_FN_SYSTEM_RESET, 0, 0, 0);
213207
}
214-
215208
}
216209

217210
#define PSCI_CALL_FN_RET(fn, ...) \
@@ -316,6 +309,16 @@ static rt_err_t psci_0_2_init(struct rt_ofw_node *np)
316309
_psci_ops.migrate = psci_0_2_migrate;
317310
_psci_ops.get_affinity_info = psci_affinity_info;
318311
_psci_ops.migrate_info_type = psci_migrate_info_type;
312+
313+
if (!rt_dm_machine_shutdown)
314+
{
315+
rt_dm_machine_shutdown = psci_system_off;
316+
}
317+
318+
if (!rt_dm_machine_reset)
319+
{
320+
rt_dm_machine_reset = psci_system_reboot;
321+
}
319322
}
320323
else
321324
{

libcpu/aarch64/common/setup.c

Lines changed: 97 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,16 @@
2626
#include <gic.h>
2727
#include <gicv3.h>
2828
#include <mm_memblock.h>
29-
30-
#define SIZE_KB 1024
31-
#define SIZE_MB (1024 * SIZE_KB)
32-
#define SIZE_GB (1024 * SIZE_MB)
29+
#include <dt-bindings/size.h>
3330

3431
extern rt_ubase_t _start, _end;
3532
extern void _secondary_cpu_entry(void);
33+
extern void rt_hw_builtin_fdt();
3634
extern size_t MMUTable[];
3735
extern void *system_vectors;
3836

3937
static void *fdt_ptr = RT_NULL;
4038
static rt_size_t fdt_size = 0;
41-
static rt_uint64_t initrd_ranges[3] = { };
4239

4340
#ifdef RT_USING_SMP
4441
extern struct cpu_ops_t cpu_psci_ops;
@@ -64,11 +61,15 @@ static struct rt_ofw_node *cpu_np[RT_CPUS_NR] = { };
6461

6562
void rt_hw_fdt_install_early(void *fdt)
6663
{
64+
#ifndef RT_USING_BUILTIN_FDT
6765
if (fdt != RT_NULL && !fdt_check_header(fdt))
6866
{
6967
fdt_ptr = fdt;
7068
fdt_size = fdt_totalsize(fdt);
7169
}
70+
#else
71+
(void)fdt;
72+
#endif
7273
}
7374

7475
#ifdef RT_USING_HWTIMER
@@ -169,8 +170,6 @@ rt_inline void cpu_info_init(void)
169170
cpu_np[i] = np;
170171
rt_cpu_mpidr_table[i] = hwid;
171172

172-
rt_ofw_data(np) = (void *)hwid;
173-
174173
for (int idx = 0; idx < RT_ARRAY_SIZE(cpu_ops); ++idx)
175174
{
176175
struct cpu_ops_t *ops = cpu_ops[idx];
@@ -199,8 +198,44 @@ rt_inline void cpu_info_init(void)
199198
#endif /* RT_USING_HWTIMER */
200199
}
201200

201+
rt_inline rt_size_t string_to_size(const char *string, const char *who)
202+
{
203+
char unit;
204+
rt_size_t size;
205+
const char *cp = string;
206+
207+
size = atoi(cp);
208+
209+
while (*cp >= '0' && *cp <= '9')
210+
{
211+
++cp;
212+
}
213+
214+
unit = *cp & '_';
215+
216+
if (unit == 'M')
217+
{
218+
size *= SIZE_MB;
219+
}
220+
else if (unit == 'K')
221+
{
222+
size *= SIZE_KB;
223+
}
224+
else if (unit == 'G')
225+
{
226+
size *= SIZE_GB;
227+
}
228+
else
229+
{
230+
LOG_W("Unknown unit of '%c' in `%s`", unit, who);
231+
}
232+
233+
return size;
234+
}
235+
202236
void rt_hw_common_setup(void)
203237
{
238+
rt_uint64_t initrd_ranges[3];
204239
rt_size_t kernel_start, kernel_end;
205240
rt_size_t heap_start, heap_end;
206241
rt_size_t init_page_start, init_page_end;
@@ -213,9 +248,9 @@ void rt_hw_common_setup(void)
213248
system_vectors_init();
214249

215250
#ifdef RT_USING_SMART
216-
rt_hw_mmu_map_init(&rt_kernel_space, (void*)0xfffffffff0000000, 0x10000000, MMUTable, pv_off);
251+
rt_hw_mmu_map_init(&rt_kernel_space, (void*)0xffffffff00000000, 0x20000000, MMUTable, pv_off);
217252
#else
218-
rt_hw_mmu_map_init(&rt_kernel_space, (void*)0xffffd0000000, 0x10000000, MMUTable, 0);
253+
rt_hw_mmu_map_init(&rt_kernel_space, (void*)0xffffd0000000, 0x20000000, MMUTable, 0);
219254
#endif
220255

221256
kernel_start = RT_ALIGN_DOWN((rt_size_t)rt_kmem_v2p((void *)&_start) - 64, ARCH_PAGE_SIZE);
@@ -228,25 +263,36 @@ void rt_hw_common_setup(void)
228263
fdt_end = RT_ALIGN(fdt_start + fdt_size, ARCH_PAGE_SIZE);
229264

230265
platform_mem_region.start = kernel_start;
266+
#ifndef RT_USING_BUILTIN_FDT
231267
platform_mem_region.end = fdt_end;
268+
#else
269+
platform_mem_region.end = init_page_end;
270+
(void)fdt_start;
271+
(void)fdt_end;
272+
#endif
232273

233274
rt_memblock_reserve_memory("kernel", kernel_start, kernel_end, MEMBLOCK_NONE);
234275
rt_memblock_reserve_memory("memheap", heap_start, heap_end, MEMBLOCK_NONE);
235276
rt_memblock_reserve_memory("init-page", init_page_start, init_page_end, MEMBLOCK_NONE);
277+
#ifndef RT_USING_BUILTIN_FDT
236278
rt_memblock_reserve_memory("fdt", fdt_start, fdt_end, MEMBLOCK_NONE);
237279

238280
/* To virtual address */
239281
fdt_ptr = (void *)(fdt_ptr - pv_off);
240282
#ifdef KERNEL_VADDR_START
241-
if ((rt_ubase_t)fdt_ptr + fdt_size - KERNEL_VADDR_START > SIZE_GB)
283+
if ((rt_ubase_t)fdt_ptr + fdt_size - KERNEL_VADDR_START > ARCH_EARLY_MAP_SIZE)
242284
{
243285
fdt_ptr = rt_ioremap_early(fdt_ptr + pv_off, fdt_size);
244286

245287
RT_ASSERT(fdt_ptr != RT_NULL);
246288
}
247-
#endif
289+
#endif /* KERNEL_VADDR_START */
248290
rt_memmove((void *)(fdt_start - pv_off), fdt_ptr, fdt_size);
249291
fdt_ptr = (void *)fdt_start - pv_off;
292+
#else
293+
fdt_ptr = &rt_hw_builtin_fdt;
294+
fdt_size = fdt_totalsize(fdt_ptr);
295+
#endif /* RT_USING_BUILTIN_FDT */
250296

251297
rt_system_heap_init((void *)(heap_start - pv_off), (void *)(heap_end - pv_off));
252298

@@ -277,6 +323,46 @@ void rt_hw_common_setup(void)
277323

278324
rt_fdt_scan_memory();
279325

326+
#ifdef RT_USING_DMA
327+
do {
328+
const char *bootargs;
329+
rt_ubase_t dma_pool_base;
330+
rt_size_t cma_size = 0, coherent_pool_size = 0;
331+
332+
if (!rt_fdt_bootargs_select("cma=", 0, &bootargs))
333+
{
334+
cma_size = string_to_size(bootargs, "cma");
335+
}
336+
337+
if (!rt_fdt_bootargs_select("coherent_pool=", 0, &bootargs))
338+
{
339+
coherent_pool_size = string_to_size(bootargs, "coherent-pool");
340+
}
341+
342+
if (cma_size <= coherent_pool_size)
343+
{
344+
if (cma_size || coherent_pool_size)
345+
{
346+
LOG_W("DMA pool %s=%u > %s=%u",
347+
"CMA", cma_size, "coherent-pool", coherent_pool_size);
348+
}
349+
350+
cma_size = 8 * SIZE_MB;
351+
coherent_pool_size = 2 * SIZE_MB;
352+
}
353+
354+
dma_pool_base = platform_mem_region.end;
355+
rt_memblock_reserve_memory("dma-pool",
356+
dma_pool_base, dma_pool_base + cma_size + coherent_pool_size, MEMBLOCK_NONE);
357+
358+
if (rt_dma_pool_extract(cma_size, coherent_pool_size))
359+
{
360+
LOG_E("Alloc DMA pool %s=%u, %s=%u fail",
361+
"CMA", cma_size, "coherent-pool", coherent_pool_size);
362+
}
363+
} while (0);
364+
#endif /* RT_USING_DMA */
365+
280366
rt_memblock_setup_memory_environment();
281367

282368
rt_fdt_earlycon_kick(FDT_EARLYCON_KICK_UPDATE);

libcpu/aarch64/common/trap.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,5 +394,8 @@ void rt_hw_trap_serror(struct rt_hw_exp_stack *regs)
394394
#ifdef RT_USING_FINSH
395395
list_thread();
396396
#endif
397+
398+
struct rt_hw_backtrace_frame frame = {.fp = regs->x29, .pc = regs->pc};
399+
rt_backtrace_frame(rt_thread_self(), &frame);
397400
rt_hw_cpu_shutdown();
398401
}

0 commit comments

Comments
 (0)