Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Still more MediaTek updates #82993

Merged
merged 13 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions arch/xtensa/core/prep_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ extern FUNC_NORETURN void z_cstart(void);
/* defined by the SoC in case of CONFIG_SOC_HAS_RUNTIME_NUM_CPUS=y */
extern void soc_num_cpus_init(void);

/* Make sure the platform configuration matches what the toolchain
* thinks the hardware is doing.
*/
#ifdef CONFIG_DCACHE_LINE_SIZE
BUILD_ASSERT(CONFIG_DCACHE_LINE_SIZE == XCHAL_DCACHE_LINESIZE);
#endif

/**
*
* @brief Prepare to and run C code
Expand Down
6 changes: 3 additions & 3 deletions boards/mediatek/mt8186/mt8186_adsp.dts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
#interrupt-cells = <3>;
};

intc2: intc@10680010 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some spelling mistakes: becuase->because, "process on thsi device, the and the set"

intc2: intc@10680050 {
compatible = "mediatek,adsp_intc";
interrupt-controller;
#interrupt-cells = <3>;
reg = <0x10680010 4>;
status-reg = <0x10680050>;
reg = <0x10680050 4>;
status-reg = <0x10680010>;
interrupts = <2 0 0>;
mask = <0x3f>;
interrupt-parent = <&core_intc>;
Expand Down
6 changes: 3 additions & 3 deletions boards/mediatek/mt8188/mt8188_adsp.dts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@
#interrupt-cells = <3>;
};

intc2: intc@10b80010 {
intc2: intc@10b80050 {
compatible = "mediatek,adsp_intc";
interrupt-controller;
#interrupt-cells = <3>;
reg = <0x10b80010 4>;
status-reg = <0x10b80050>;
reg = <0x10b80050 4>;
status-reg = <0x10b80010>;
interrupts = <2 0 0>;
mask = <0x3f>;
interrupt-parent = <&core_intc>;
Expand Down
8 changes: 7 additions & 1 deletion boards/mediatek/mt8195/mt8195_adsp.dts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@
dram0: memory@60000000 {
device_type = "memory";
compatible = "mmio-sram";
reg = <0x60000000 DT_SIZE_M(17)>;
reg = <0x60000000 DT_SIZE_K(13824)>;
};

dram1: memory@60e80000 {
device_type = "memory";
compatible = "mmio-sram";
reg = <0x60e80000 DT_SIZE_K(2560)>;
};

soc {
Expand Down
12 changes: 6 additions & 6 deletions boards/mediatek/mt8196/mt8196_adsp.dts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
reg = <0x90000000 DT_SIZE_M(6)>;
};

dram1: memory@90700000 {
dram1: memory@90800000 {
device_type = "memory";
compatible = "mmio-sram";
reg = <0x90700000 DT_SIZE_M(1)>;
reg = <0x90800000 DT_SIZE_M(1)>;
};

soc {
Expand Down Expand Up @@ -88,16 +88,16 @@
interrupts = <8 0 0>;
};

mbox0: mbox@1a360100 {
mbox0: mbox@1a350100 {
compatible = "mediatek,mbox";
reg = <0x1a360100 16>;
reg = <0x1a350100 16>;
interrupt-parent = <&intc_g2>;
interrupts = <6 0 0>;
};

mbox1: mbox@1a370100 {
mbox1: mbox@1a360100 {
compatible = "mediatek,mbox";
reg = <0x1a370100 16>;
reg = <0x1a360100 16>;
interrupt-parent = <&intc_g2>;
interrupts = <7 0 0>;
};
Expand Down
4 changes: 4 additions & 0 deletions boards/qemu/xtensa/Kconfig.defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ config BUILD_OUTPUT_BIN
config IPM_CONSOLE_STACK_SIZE
default 2048 if IPM_CONSOLE_RECEIVER

# Must match XCHAL_DCACHE_LINESIZE form core-isa.h
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/form/from

config DCACHE_LINE_SIZE
default 32

endif # BOARD_QEMU_XTENSA
16 changes: 16 additions & 0 deletions drivers/console/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,20 @@ config WINSTREAM_CONSOLE

See the WINSTREAM Kconfig help for more information.

config WINSTREAM_CONSOLE_STATIC
bool "Use static/linkable memory for the winstream console"
default y if !SOC_FAMILY_INTEL_ADSP
help
The winstream console can be configured to use simple linker
memory which can help avoid manual memory management at the
platform layer. The memory should be pointed to by the
symbol "_winstream_console_buf" and have size set by
CONFIG_WINSTREAM_CONSOLE_SIZE.

config WINSTREAM_CONSOLE_STATIC_SIZE
int "Size of winstream console buffer"
default 32768
help
Size of winstream console buffer, in bytes

endif # CONSOLE
59 changes: 56 additions & 3 deletions drivers/console/winstream_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
#include <zephyr/devicetree.h>
#include <zephyr/cache.h>

#ifdef SOC_FAMILY_INTEL_ADSP
#include <adsp_memory.h>
#include <mem_window.h>
#endif

struct k_spinlock trace_lock;

Expand Down Expand Up @@ -58,19 +60,70 @@ static void winstream_console_hook_install(void)
#endif
}

/* This gets optionally defined by the platform layer as it needs (it
* might want to go in a special location to coordinate with linux
* userspace, etc...)
*/
extern char _winstream_console_buf[];

/* This descriptor with a 96-bit magic number gets linked into the
* binary when enabled so that external tooling can easily find it at
* runtime (e.g. by searching the binary image file, etc...)
*/
#define WINSTREAM_CONSOLE_MAGIC1 0xd06a5f74U
#define WINSTREAM_CONSOLE_MAGIC2 0x004fe279U
#define WINSTREAM_CONSOLE_MAGIC3 0xf9bdb8cdU

struct winstream_console_desc {
uint32_t magic1;
uint32_t magic2;
uint32_t magic3;
uint32_t buf_addr;
uint32_t size;
};

static const __used struct winstream_console_desc wsdesc = {
.magic1 = WINSTREAM_CONSOLE_MAGIC1,
.magic2 = WINSTREAM_CONSOLE_MAGIC2,
.magic3 = WINSTREAM_CONSOLE_MAGIC3,
.buf_addr = (uint32_t) &_winstream_console_buf,
.size = CONFIG_WINSTREAM_CONSOLE_STATIC_SIZE,
};

static int winstream_console_init(void)
{
void *buf = NULL;
size_t size = 0;

#ifdef SOC_FAMILY_INTEL_ADSP
/* These have a SOC-specific "mem_window" device. FIXME: The
* type handling is backwards here. We shouldn't be grabbing
* an arbitrary DTS alias and assuming it's a mem_window at
* runtime, that's not safe. The mem_window init code (which
* is typesafe by construction) should be detecting that it's
* supposed to be the console and starting the console hook
* registration process.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a thumbs up for this, needs follow up.

*/
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 =
sys_cache_uncached_ptr_get((__sparse_force void __sparse_cache *)config->mem_base);
buf = sys_cache_uncached_ptr_get((__sparse_force void __sparse_cache *)config->mem_base);
size = config->size;
#endif

#ifdef CONFIG_WINSTREAM_CONSOLE_STATIC
/* Dirty trick to prevent linker garbage collection */
_winstream_console_buf[0] = ((volatile char*) &wsdesc)[0];

buf = &_winstream_console_buf;
size = CONFIG_WINSTREAM_CONSOLE_STATIC_SIZE;
#endif

winstream = sys_winstream_init(buf, config->size);
__ASSERT_NO_MSG(buf != NULL && size != 0);
winstream = sys_winstream_init(buf, size);
winstream_console_hook_install();

return 0;
Expand Down
21 changes: 21 additions & 0 deletions soc/mediatek/mt8xxx/Kconfig.defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,32 @@ config IRQ_OFFLOAD_NESTED
default n if SOC_SERIES_MT818X
default y

config CPU_HAS_DCACHE
default y
config DCACHE
default y
config CACHE_MANAGEMENT
default y
config DCACHE_LINE_SIZE
default 128

config NOCACHE_MEMORY
default y

config MTK_ADSP_TIMER
default y
config XTENSA_TIMER
default n

config CONSOLE
default y
config WINSTREAM_CONSOLE
default y
config WINSTREAM
default y
config LOG_BACKEND_ADSP
default y if LOG

config XTENSA_CCOUNT_HZ
default 720000000 if SOC_MT8195
default 400000000 if SOC_MT8186
Expand Down
14 changes: 14 additions & 0 deletions soc/mediatek/mt8xxx/linker.ld
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ SECTIONS {
*(.gnu.linkonce.h.*)
} > dram

/* SOF extended manifest */
. = ALIGN(16);
_fw_metadata_start = .;
.fw_metadata : {
KEEP (*(.fw_metadata))
. = ALIGN(16);
} > dram
_fw_metadata_end = .;

#include <zephyr/linker/common-rom.ld>
#include <snippets-rom-sections.ld>

Expand Down Expand Up @@ -101,6 +110,11 @@ SECTIONS {
_end = .;
_mtk_adsp_dram_end = .;

.nocache (NOLOAD) : {
. = ALIGN(4096);
*(.nocache .nocache.*)
} > dram

/* Non-runtime-loaded sections below */

#include <zephyr/linker/debug-sections.ld>
Expand Down
18 changes: 14 additions & 4 deletions soc/mediatek/mt8xxx/mbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ struct mtk_mbox {

struct mbox_cfg {
volatile struct mtk_mbox *mbox;
uint32_t irq;
};

struct mbox_data {
Expand Down Expand Up @@ -85,7 +84,12 @@ void mtk_adsp_mbox_signal(const struct device *mbox, uint32_t chan)
}
}

static void mbox_isr(const void *arg)
#define DEF_DEVPTR(N) DEVICE_DT_INST_GET(N),
const struct device * const mbox_devs[] = {
DT_INST_FOREACH_STATUS_OKAY(DEF_DEVPTR)
};

static void mbox_handle(const void *arg)
{
const struct mbox_cfg *cfg = ((struct device *)arg)->config;
struct mbox_data *data = ((struct device *)arg)->data;
Expand All @@ -101,11 +105,17 @@ static void mbox_isr(const void *arg)
cfg->mbox->in_cmd_clr = cfg->mbox->in_cmd; /* ACK */
}

static void mbox_isr(const void *arg)
{
for (int i = 0; i < ARRAY_SIZE(mbox_devs); i++) {
mbox_handle(mbox_devs[i]);
}
}

#define DEF_IRQ(N) \
{ IRQ_CONNECT(DT_INST_IRQN(N), 0, mbox_isr, DEVICE_DT_INST_GET(N), 0); \
irq_enable(DT_INST_IRQN(N)); }


static int mbox_init(void)
{
DT_INST_FOREACH_STATUS_OKAY(DEF_IRQ);
Expand All @@ -117,7 +127,7 @@ SYS_INIT(mbox_init, POST_KERNEL, 0);
#define DEF_DEV(N) \
static struct mbox_data dev_data##N; \
static const struct mbox_cfg dev_cfg##N = \
{ .irq = DT_INST_IRQN(N), .mbox = (void *)DT_INST_REG_ADDR(N), }; \
{ .mbox = (void *)DT_INST_REG_ADDR(N), }; \
DEVICE_DT_INST_DEFINE(N, NULL, NULL, &dev_data##N, &dev_cfg##N, \
POST_KERNEL, 0, NULL);

Expand Down
Loading
Loading