zephyr/drivers/console/winstream_console.c
Gerard Marull-Paretas e42f58ec94 init: s/ARCH/EARLY, call it just before arch kernel init
The `ARCH` init level was added to solve a specific problem, call init
code (SYS_INIT/devices) before `z_cstart` in the `intel_adsp` platform.
The documentation claims it runs before `z_cstart`, but this is only
true if the SoC/arch takes care of calling:

```c
z_sys_init_run_level(_SYS_INIT_LEVEL_ARCH);
```

Which is only true for `intel_adsp` nowadays. So in practice, we now
have a platform specific init level. This patch proposes to do things in
a slightly different way. First, level name is renamed to `EARLY`, to
emphasize it runs in the early stage of the boot process. Then, it is
handled by the Kernel (inside `z_cstart()` before calling
`arch_kernel_init()`). This means that any platform can now use this
level. For `intel_adsp`, there should be no changes, other than
`gcov_static_init()` will be called before (I assume this will allow to
obtain coverage for code called in EARLY?).

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-10-12 17:16:27 +09:00

65 lines
1.4 KiB
C

/*
* Copyright (c) 2022 Intel Corporation
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/device.h>
#include <zephyr/init.h>
#include <zephyr/kernel.h>
#include <zephyr/sys/winstream.h>
#include <zephyr/devicetree.h>
#include <adsp_memory.h>
#include <mem_window.h>
#include <soc.h>
struct k_spinlock trace_lock;
static struct sys_winstream *winstream;
void winstream_console_trace_out(int8_t *str, size_t len)
{
if (len == 0) {
return;
}
#ifdef CONFIG_ADSP_TRACE_SIMCALL
register int a2 __asm__("a2") = 4; /* SYS_write */
register int a3 __asm__("a3") = 1; /* fd 1 == stdout */
register int a4 __asm__("a4") = (int)str;
register int a5 __asm__("a5") = len;
__asm__ volatile("simcall" : "+r"(a2), "+r"(a3) : "r"(a4), "r"(a5) : "memory");
#endif
k_spinlock_key_t key = k_spin_lock(&trace_lock);
sys_winstream_write(winstream, str, len);
k_spin_unlock(&trace_lock, key);
}
int arch_printk_char_out(int c)
{
int8_t s = c;
winstream_console_trace_out(&s, 1);
return 0;
}
static int winstream_console_init(const struct device *d)
{
ARG_UNUSED(d);
const struct device *dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));
if (!device_is_ready(dev)) {
return -ENODEV;
}
const struct mem_win_config *config = dev->config;
void *buf = arch_xtensa_uncached_ptr((void *)config->mem_base);
winstream = sys_winstream_init(buf, config->size);
return 0;
}
SYS_INIT(winstream_console_init, EARLY, CONFIG_CONSOLE_INIT_PRIORITY);