From cbbfb7411ec72962eb15ee19ee8bd2289d7dd9bf Mon Sep 17 00:00:00 2001 From: Matt Rossouw Date: Thu, 14 Nov 2024 15:03:51 +1100 Subject: [PATCH] Add support for Cheshire (CVA6), refactored Ariane to share CVA6 Added support for Cheshire (CVA6). Refactored Ariane and Cheshire to use a shared mach definition since they both implement the CVA6 core and have common code. Signed-off-by: Matt Rossouw --- libplatsupport/CMakeLists.txt | 2 + .../cheshire/platsupport/plat/apb_timer.h | 53 +++++++++++++++++++ .../cheshire/platsupport/plat/serial.h | 19 +++++++ libplatsupport/src/mach/cva6/chardev.c | 16 ++++++ libplatsupport/src/mach/cva6/serial.c | 17 ++++++ 5 files changed, 107 insertions(+) create mode 100644 libplatsupport/plat_include/cheshire/platsupport/plat/apb_timer.h create mode 100644 libplatsupport/plat_include/cheshire/platsupport/plat/serial.h create mode 100644 libplatsupport/src/mach/cva6/chardev.c create mode 100644 libplatsupport/src/mach/cva6/serial.c diff --git a/libplatsupport/CMakeLists.txt b/libplatsupport/CMakeLists.txt index 0bae33f2c..f3aa41f76 100644 --- a/libplatsupport/CMakeLists.txt +++ b/libplatsupport/CMakeLists.txt @@ -38,6 +38,8 @@ config_choice( set(LibPlatSupportMach "") if(KernelPlatformRpi3 OR KernelPlatformRpi4) set(LibPlatSupportMach "bcm") +elseif(KernelPlatformCheshire OR KernelPlatformAriane) + set(LibPlatSupportMach "cva6") elseif(NOT ${KernelArmMach} STREQUAL "") # falling back to kernel settings is done to keep legacy compatibility set(LibPlatSupportMach "${KernelArmMach}") diff --git a/libplatsupport/plat_include/cheshire/platsupport/plat/apb_timer.h b/libplatsupport/plat_include/cheshire/platsupport/plat/apb_timer.h new file mode 100644 index 000000000..26382aecc --- /dev/null +++ b/libplatsupport/plat_include/cheshire/platsupport/plat/apb_timer.h @@ -0,0 +1,53 @@ +/* + * Copyright 2019, Data61, CSIRO (ABN 41 687 119 230) + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +#include +#include +#include + +/* The input frequence is the CPU frequency which is 50MHz by default */ +#define APB_TIMER_INPUT_FREQ (50*1000*1000) +#define APB_TIMER_PADDR 0x18000000 + +/* Multiple timers */ +#define APB_TIMER_DIST 0x10 +#define APB_TIMER_NUM 2 +#define APB_TIMER_BASE(n) APB_TIMER_DIST * n + +#define CMP_WIDTH 32 +#define APB_TIMER_CTRL_ENABLE BIT(0); +#define CMP_MASK MASK(CMP_WIDTH) + +/* Timer IRQs */ +#define APB_TIMER_PLIC_BASE 4 +#define APB_TIMER_IRQ_OVF(n) APB_TIMER_PLIC_BASE + 2*n + 0x0 +#define APB_TIMER_IRQ_CMP(n) APB_TIMER_PLIC_BASE + 2*n + 0x1 + +typedef struct { + /* vaddr apb_timer is mapped to */ + void *vaddr; +} apb_timer_config_t; + +typedef struct apb_timer { + volatile struct apb_timer_map *apb_timer_map; + uint64_t time_h; +} apb_timer_t; + +struct apb_timer_map { + uint32_t time; + uint32_t ctrl; + uint32_t cmp; +}; + +int apb_timer_start(apb_timer_t *apb_timer); +int apb_timer_stop(apb_timer_t *apb_timer); +uint64_t apb_timer_get_time(apb_timer_t *apb_timer); +int apb_timer_set_timeout(apb_timer_t *apb_timer, uint64_t ns); +int apb_timer_init(apb_timer_t *apb_timer, apb_timer_config_t config); diff --git a/libplatsupport/plat_include/cheshire/platsupport/plat/serial.h b/libplatsupport/plat_include/cheshire/platsupport/plat/serial.h new file mode 100644 index 000000000..6656a5f3a --- /dev/null +++ b/libplatsupport/plat_include/cheshire/platsupport/plat/serial.h @@ -0,0 +1,19 @@ +/* + * Copyright 2019, Data61, CSIRO (ABN 41 687 119 230) + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once +#include + +enum chardev_id { + PS_SERIAL0, + /* defaults */ + PS_SERIAL_DEFAULT = PS_SERIAL0 +}; + +#define PS_SERIAL_DEFAULT 0 + +#define DEFAULT_SERIAL_PADDR NULL +#define DEFAULT_SERIAL_INTERRUPT 0 diff --git a/libplatsupport/src/mach/cva6/chardev.c b/libplatsupport/src/mach/cva6/chardev.c new file mode 100644 index 000000000..0ad021ddc --- /dev/null +++ b/libplatsupport/src/mach/cva6/chardev.c @@ -0,0 +1,16 @@ +/* + * Copyright 2019, Data61, CSIRO (ABN 41 687 119 230) + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "../../chardev.h" +#include "../../common.h" +#include + +struct ps_chardevice * +ps_cdev_init(enum chardev_id id, const ps_io_ops_t *o, struct ps_chardevice *d) +{ + return NULL; +} + diff --git a/libplatsupport/src/mach/cva6/serial.c b/libplatsupport/src/mach/cva6/serial.c new file mode 100644 index 000000000..921b15139 --- /dev/null +++ b/libplatsupport/src/mach/cva6/serial.c @@ -0,0 +1,17 @@ +/* + * Copyright 2019, Data61, CSIRO (ABN 41 687 119 230) + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include +#include + +int uart_init(const struct dev_defn *defn, + const ps_io_ops_t *ops, + ps_chardevice_t *dev) +{ + return 0; +}