RISC-V ACLINT Support
cover RISC-V ACLINT Support
The RISC-V Advanced Core Local Interruptor (ACLINT) is an improvement over the SiFive CLINT but also maintains backward compatibility with the SiFive CLINT.
Latest RISC-V ACLINT specification (will be frozen in a month) can be found at:
https://github.com/riscv/riscv-aclint/blob/main/riscv-aclint.adoc
This series adds RISC-V ACLINT support to OpenSBI and can be found in the riscv_aclint_v1 branch at:
https://github.com/avpatel/qemu.git
To test series, we require QEMU and Linux with ACLINT support which can be found in riscv_aclint_v1 branch at:
https://github.com/avpatel/qemu.git
https://github.com/avpatel/linux.git
Anup Patel (6):
lib: utils/timer: Add ACLINT MTIMER library
lib: utils/ipi: Add ACLINT MSWI library
lib: utils: Add FDT parsing API common for both ACLINT and CLINT
lib: utils/ipi: Add FDT based ACLINT MSWI IPI driver
lib: utils/timer: Add FDT based ACLINT MTIMER driver
platform: Replace CLINT library usage with ACLINT library
include/sbi_utils/fdt/fdt_helper.h | 7 +- include/sbi_utils/ipi/aclint_mswi.h | 33 +++ include/sbi_utils/sys/clint.h | 41 ---- include/sbi_utils/timer/aclint_mtimer.h | 41 ++++ lib/utils/fdt/fdt_helper.c | 31 ++- lib/utils/ipi/aclint_mswi.c | 100 +++++++++ lib/utils/ipi/fdt_ipi.c | 4 +- lib/utils/ipi/fdt_ipi_clint.c | 48 ----- lib/utils/ipi/fdt_ipi_mswi.c | 67 +++++++ lib/utils/ipi/objects.mk | 3 +- lib/utils/sys/clint.c | 256 ------------------------ lib/utils/sys/objects.mk | 1 - lib/utils/timer/aclint_mtimer.c | 180 +++++++++++++++++ lib/utils/timer/fdt_timer.c | 4 +- lib/utils/timer/fdt_timer_clint.c | 50 ----- lib/utils/timer/fdt_timer_mtimer.c | 74 +++++++ lib/utils/timer/objects.mk | 3 +- platform/fpga/ariane/platform.c | 26 ++- platform/fpga/openpiton/platform.c | 32 ++- platform/kendryte/k210/platform.c | 23 ++- platform/kendryte/k210/platform.h | 3 + platform/nuclei/ux600/platform.c | 27 ++- platform/template/platform.c | 30 ++- 23 files changed, 623 insertions(+), 461 deletions(-) create mode 100644 include/sbi_utils/ipi/aclint_mswi.h delete mode 100644 include/sbi_utils/sys/clint.h create mode 100644 include/sbi_utils/timer/aclint_mtimer.h create mode 100644 lib/utils/ipi/aclint_mswi.c delete mode 100644 lib/utils/ipi/fdt_ipi_clint.c create mode 100644 lib/utils/ipi/fdt_ipi_mswi.c delete mode 100644 lib/utils/sys/clint.c create mode 100644 lib/utils/timer/aclint_mtimer.c delete mode 100644 lib/utils/timer/fdt_timer_clint.c create mode 100644 lib/utils/timer/fdt_timer_mtimer.c
Signature · 1 line
2.25.1
PATCH 1/6 lib: utils/timer: Add ACLINT MTIMER library
We add common ACLINT MTIMER library similar to the CLINT library so that OpenSBI platforms can use it.
--- include/sbi_utils/timer/aclint_mtimer.h | 41 ++++++ lib/utils/timer/aclint_mtimer.c | 180 ++++++++++++++++++++++++ lib/utils/timer/objects.mk | 1 + 3 files changed, 222 insertions(+) create mode 100644 include/sbi_utils/timer/aclint_mtimer.h create mode 100644 lib/utils/timer/aclint_mtimer.c
include/sbi_utils/timer/aclint_mtimer.h new file +41 -0
@@ -0,0 +1,41 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2021 Western Digital Corporation or its affiliates. +* +* Authors: +* Anup Patel <[email protected]> +*/ + +#ifndef __TIMER_ACLINT_MTIMER_H__ +#define __TIMER_ACLINT_MTIMER_H__ + +#include <sbi/sbi_types.h> + +#define ACLINT_MTIMER_ALIGN 0x1000 +#define ACLINT_MTIMER_SIZE 0x8000 +#define ACLINT_MTIMER_MAX_HARTS 4095 + +#define CLINT_MTIMER_OFFSET 0x4000 + +struct aclint_mtimer_data { +/* Public details */ +unsigned long addr; +unsigned long size; +u32 first_hartid; +u32 hart_count; +bool has_64bit_mmio; +/* Private details (initialized and used by ACLINT MTIMER library) */ +struct aclint_mtimer_data *time_delta_reference; +unsigned long time_delta_computed; +u64 time_delta; +u64 (*time_rd)(volatile u64 *addr); +void (*time_wr)(u64 value,volatile u64 *addr); +}; + +int aclint_mtimer_warm_init (void ); + +int aclint_mtimer_cold_init (struct aclint_mtimer_data *mt, +struct aclint_mtimer_data *reference); + +#endif
lib/utils/timer/aclint_mtimer.c new file +180 -0
180 lines not on this page · raw message
lib/utils/timer/objects.mk +1 -0
@@ -9,3 +9,4 @@ libsbiutils-objs-y += timer/fdt_timer.o libsbiutils-objs-y += timer/fdt_timer_clint.o +libsbiutils-objs-y += timer/aclint_mtimer.o
Signature · 1 line
2.25.1
PATCH 1/6 lib: utils/timer: Add ACLINT MTIMER library
Quoted 251 lines · Anup Patel
We add common ACLINT MTIMER library similar to the CLINT library so that OpenSBI platforms can use it.
Signed-off-by Anup Patel <[email protected]>--- include/sbi_utils/timer/aclint_mtimer.h | 41 ++++++ lib/utils/timer/aclint_mtimer.c | 180 ++++++++++++++++++++++++ lib/utils/timer/objects.mk | 1 + 3 files changed, 222 insertions(+) create mode 100644 include/sbi_utils/timer/aclint_mtimer.h create mode 100644 lib/utils/timer/aclint_mtimer.cinclude/sbi_utils/timer/aclint_mtimer.h new file +41
-0@@ -0,0 +1,41 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2021 Western Digital Corporation or its affiliates. +* +* Authors: +* Anup Patel <[email protected]> +*/ + +#ifndef __TIMER_ACLINT_MTIMER_H__ +#define __TIMER_ACLINT_MTIMER_H__ + +#include <sbi/sbi_types.h> + +#define ACLINT_MTIMER_ALIGN 0x1000 +#define ACLINT_MTIMER_SIZE 0x8000 +#define ACLINT_MTIMER_MAX_HARTS 4095 + +#define CLINT_MTIMER_OFFSET 0x4000 + +struct aclint_mtimer_data { +/* Public details */ +unsigned long addr; +unsigned long size; +u32 first_hartid; +u32 hart_count; +bool has_64bit_mmio; +/* Private details (initialized and used by ACLINT MTIMER library) */ +struct aclint_mtimer_data *time_delta_reference; +unsigned long time_delta_computed; +u64 time_delta; +u64 (*time_rd)(volatile u64 *addr); +void (*time_wr)(u64 value,volatile u64 *addr); +}; + +int aclint_mtimer_warm_init (void ); + +int aclint_mtimer_cold_init (struct aclint_mtimer_data *mt, +struct aclint_mtimer_data *reference); + +#endif lib/utils/timer/aclint_mtimer.c new file +180
-0@@ -0,0 +1,180 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2021 Western Digital Corporation or its affiliates. +* +* Authors: +* Anup Patel <[email protected]> +*/ + +#include <sbi/riscv_asm.h> +#include <sbi/riscv_atomic.h> +#include <sbi/riscv_io.h> +#include <sbi/sbi_domain.h> +#include <sbi/sbi_error.h> +#include <sbi/sbi_hartmask.h> +#include <sbi/sbi_ipi.h> +#include <sbi/sbi_timer.h> +#include <sbi_utils/timer/aclint_mtimer.h> + +#define MTIMER_CMP_OFF 0x0000 +#define MTIMER_VAL_OFF 0x7ff8 + +static struct aclint_mtimer_data *mtimer_hartid2data[SBI_HARTMASK_MAX_BITS ]; + +#if __riscv_xlen !=32 +static u64 mtimer_time_rd64 (volatile u64 *addr) +{ +return readq_relaxed (addr); +} + +static void mtimer_time_wr64 (u64 value,volatile u64 *addr) +{ +writeq_relaxed (value, addr); +} +#endif + +static u64 mtimer_time_rd32 (volatile u64 *addr) +{ +u32 lo, hi; + +do { + hi =readl_relaxed ((u32 *)addr +1 ); + lo =readl_relaxed ((u32 *)addr); + }while (hi !=readl_relaxed ((u32 *)addr +1 )); + +return ((u64 )hi <<32 ) | (u64 )lo; +} + +static void mtimer_time_wr32 (u64 value,volatile u64 *addr) +{ +u32 mask =-1U ; + +writel_relaxed (value & mask, (void *)(addr)); +writel_relaxed (value >>32 , (void *)(addr) +0x04 ); +} + +static u64 mtimer_value (void ) +{ +struct aclint_mtimer_data *mt = mtimer_hartid2data[current_hartid ()]; +u64 *time_val = ((void *)mt->addr) +MTIMER_VAL_OFF ; + +/* Read MTIMER Time Value */ +return mt->time_rd (time_val) + mt->time_delta; +} + +static void mtimer_event_stop (void ) +{ +u32 target_hart =current_hartid (); +struct aclint_mtimer_data *mt = mtimer_hartid2data[target_hart]; +u64 *time_cmp = (void *)mt->addr +MTIMER_CMP_OFF ; + +/* Clear MTIMER Time Compare */ + mt->time_wr (-1ULL , &time_cmp[target_hart - mt->first_hartid]); +} + +static void mtimer_event_start (u64 next_event) +{ +u32 target_hart =current_hartid (); +struct aclint_mtimer_data *mt = mtimer_hartid2data[target_hart]; +u64 *time_cmp = (void *)mt->addr +MTIMER_CMP_OFF ; + +/* Program MTIMER Time Compare */ + mt->time_wr (next_event - mt->time_delta, + &time_cmp[target_hart - mt->first_hartid]); +} + +static struct sbi_timer_device mtimer = { + .name ="aclint-mtimer" , + .timer_value = mtimer_value, + .timer_event_start = mtimer_event_start, + .timer_event_stop = mtimer_event_stop +}; + +int aclint_mtimer_warm_init (void ) +{ +u64 v1, v2, mv; +u32 target_hart =current_hartid (); +struct aclint_mtimer_data *reference; +u64 *mt_time_val, *mt_time_cmp, *ref_time_val; +struct aclint_mtimer_data *mt = mtimer_hartid2data[target_hart]; + +if (!mt) +return SBI_ENODEV ; + +/* +* Compute delta if reference available +* +* We deliberately compute time_delta in warm init so that time_delta +* is computed on a HART which is going to use given MTIMER. We use +* atomic flag timer_delta_computed to ensure that only one HART does +* time_delta computation. +*/ +if (mt->time_delta_reference) { + reference = mt->time_delta_reference; + mt_time_val = (void *)mt->addr +MTIMER_VAL_OFF ; + ref_time_val = (void *)reference->addr +MTIMER_VAL_OFF ; +if (!atomic_raw_xchg_ulong (&mt->time_delta_computed,1 )) { + v1 = mt->time_rd (mt_time_val); + mv = reference->time_rd (ref_time_val); + v2 = mt->time_rd (mt_time_val); + mt->time_delta = mv - ((v1 /2 ) + (v2 /2 )); + } + } + +/* Clear Time Compare */ + mt_time_cmp = (void *)mt->addr +MTIMER_CMP_OFF ; + mt->time_wr (-1ULL , &mt_time_cmp[target_hart - mt->first_hartid]); + +return 0 ; +} + +int aclint_mtimer_cold_init (struct aclint_mtimer_data *mt, +struct aclint_mtimer_data *reference) +{ +u32 i; +int rc; +unsigned long pos, region_size; +struct sbi_domain_memregion reg; + +/* Sanity checks */ +if (!mt || (mt->addr & (ACLINT_MTIMER_ALIGN -1 )) || + (mt->size <ACLINT_MTIMER_SIZE ) || + (mt->first_hartid >=SBI_HARTMASK_MAX_BITS ) || + (mt->hart_count >ACLINT_MTIMER_MAX_HARTS )) +return SBI_EINVAL ; + +/* Initialize private data */ + mt->time_delta_reference = reference; + mt->time_delta_computed =0 ; + mt->time_delta =0 ; + mt->time_rd = mtimer_time_rd32; + mt->time_wr = mtimer_time_wr32; + +/* Override read/write accessors for 64bit MMIO */ +#if __riscv_xlen !=32 +if (mt->has_64bit_mmio) { + mt->time_rd = mtimer_time_rd64; + mt->time_wr = mtimer_time_wr64; + } +#endif + +/* Update MTIMER hartid table */ +for (i =0 ; i < mt->hart_count; i++) + mtimer_hartid2data[mt->first_hartid + i] = mt; + +/* Add MTIMER regions to the root domain */ +for (pos =0 ; pos < mt->size; pos +=ACLINT_MTIMER_ALIGN ) { + region_size = ((mt->size - pos) <ACLINT_MTIMER_ALIGN ) ? + (mt->size - pos) :ACLINT_MTIMER_ALIGN ; +sbi_domain_memregion_init (mt->addr + pos, region_size, +SBI_DOMAIN_MEMREGION_MMIO , ®); + rc =sbi_domain_root_add_memregion (®); +if (rc) +return rc; + } + +sbi_timer_set_device (&mtimer); + +return 0 ; +}lib/utils/timer/objects.mk +0
-0
lib/utils/timer/objects.mk line 12
Quoted 4 lines
lib/utils/timer/objects.mk +1
-0@@ -9,3 +9,4 @@ libsbiutils-objs-y += timer/fdt_timer.o libsbiutils-objs-y += timer/fdt_timer_clint.o +libsbiutils-objs-y += timer/aclint_mtimer.o
nits: insert this by following the alphabetical order
Otherwise,
PATCH 1/6 lib: utils/timer: Add ACLINT MTIMER library
Quoted 254 lines · Bin Meng
Quoted 252 lines · Anup Patel
We add common ACLINT MTIMER library similar to the CLINT library so that OpenSBI platforms can use it.
Signed-off-by Anup Patel <[email protected]>--- include/sbi_utils/timer/aclint_mtimer.h | 41 ++++++ lib/utils/timer/aclint_mtimer.c | 180 ++++++++++++++++++++++++ lib/utils/timer/objects.mk | 1 + 3 files changed, 222 insertions(+) create mode 100644 include/sbi_utils/timer/aclint_mtimer.h create mode 100644 lib/utils/timer/aclint_mtimer.cinclude/sbi_utils/timer/aclint_mtimer.h new file +41
-0@@ -0,0 +1,41 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2021 Western Digital Corporation or its affiliates. +* +* Authors: +* Anup Patel <[email protected]> +*/ + +#ifndef __TIMER_ACLINT_MTIMER_H__ +#define __TIMER_ACLINT_MTIMER_H__ + +#include <sbi/sbi_types.h> + +#define ACLINT_MTIMER_ALIGN 0x1000 +#define ACLINT_MTIMER_SIZE 0x8000 +#define ACLINT_MTIMER_MAX_HARTS 4095 + +#define CLINT_MTIMER_OFFSET 0x4000 + +struct aclint_mtimer_data { +/* Public details */ +unsigned long addr; +unsigned long size; +u32 first_hartid; +u32 hart_count; +bool has_64bit_mmio; +/* Private details (initialized and used by ACLINT MTIMER library) */ +struct aclint_mtimer_data *time_delta_reference; +unsigned long time_delta_computed; +u64 time_delta; +u64 (*time_rd)(volatile u64 *addr); +void (*time_wr)(u64 value,volatile u64 *addr); +}; + +int aclint_mtimer_warm_init (void ); + +int aclint_mtimer_cold_init (struct aclint_mtimer_data *mt, +struct aclint_mtimer_data *reference); + +#endif lib/utils/timer/aclint_mtimer.c new file +180
-0@@ -0,0 +1,180 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2021 Western Digital Corporation or its affiliates. +* +* Authors: +* Anup Patel <[email protected]> +*/ + +#include <sbi/riscv_asm.h> +#include <sbi/riscv_atomic.h> +#include <sbi/riscv_io.h> +#include <sbi/sbi_domain.h> +#include <sbi/sbi_error.h> +#include <sbi/sbi_hartmask.h> +#include <sbi/sbi_ipi.h> +#include <sbi/sbi_timer.h> +#include <sbi_utils/timer/aclint_mtimer.h> + +#define MTIMER_CMP_OFF 0x0000 +#define MTIMER_VAL_OFF 0x7ff8 + +static struct aclint_mtimer_data *mtimer_hartid2data[SBI_HARTMASK_MAX_BITS ]; + +#if __riscv_xlen !=32 +static u64 mtimer_time_rd64 (volatile u64 *addr) +{ +return readq_relaxed (addr); +} + +static void mtimer_time_wr64 (u64 value,volatile u64 *addr) +{ +writeq_relaxed (value, addr); +} +#endif + +static u64 mtimer_time_rd32 (volatile u64 *addr) +{ +u32 lo, hi; + +do { + hi =readl_relaxed ((u32 *)addr +1 ); + lo =readl_relaxed ((u32 *)addr); + }while (hi !=readl_relaxed ((u32 *)addr +1 )); + +return ((u64 )hi <<32 ) | (u64 )lo; +} + +static void mtimer_time_wr32 (u64 value,volatile u64 *addr) +{ +u32 mask =-1U ; + +writel_relaxed (value & mask, (void *)(addr)); +writel_relaxed (value >>32 , (void *)(addr) +0x04 ); +} + +static u64 mtimer_value (void ) +{ +struct aclint_mtimer_data *mt = mtimer_hartid2data[current_hartid ()]; +u64 *time_val = ((void *)mt->addr) +MTIMER_VAL_OFF ; + +/* Read MTIMER Time Value */ +return mt->time_rd (time_val) + mt->time_delta; +} + +static void mtimer_event_stop (void ) +{ +u32 target_hart =current_hartid (); +struct aclint_mtimer_data *mt = mtimer_hartid2data[target_hart]; +u64 *time_cmp = (void *)mt->addr +MTIMER_CMP_OFF ; + +/* Clear MTIMER Time Compare */ + mt->time_wr (-1ULL , &time_cmp[target_hart - mt->first_hartid]); +} + +static void mtimer_event_start (u64 next_event) +{ +u32 target_hart =current_hartid (); +struct aclint_mtimer_data *mt = mtimer_hartid2data[target_hart]; +u64 *time_cmp = (void *)mt->addr +MTIMER_CMP_OFF ; + +/* Program MTIMER Time Compare */ + mt->time_wr (next_event - mt->time_delta, + &time_cmp[target_hart - mt->first_hartid]); +} + +static struct sbi_timer_device mtimer = { + .name ="aclint-mtimer" , + .timer_value = mtimer_value, + .timer_event_start = mtimer_event_start, + .timer_event_stop = mtimer_event_stop +}; + +int aclint_mtimer_warm_init (void ) +{ +u64 v1, v2, mv; +u32 target_hart =current_hartid (); +struct aclint_mtimer_data *reference; +u64 *mt_time_val, *mt_time_cmp, *ref_time_val; +struct aclint_mtimer_data *mt = mtimer_hartid2data[target_hart]; + +if (!mt) +return SBI_ENODEV ; + +/* +* Compute delta if reference available +* +* We deliberately compute time_delta in warm init so that time_delta +* is computed on a HART which is going to use given MTIMER. We use +* atomic flag timer_delta_computed to ensure that only one HART does +* time_delta computation. +*/ +if (mt->time_delta_reference) { + reference = mt->time_delta_reference; + mt_time_val = (void *)mt->addr +MTIMER_VAL_OFF ; + ref_time_val = (void *)reference->addr +MTIMER_VAL_OFF ; +if (!atomic_raw_xchg_ulong (&mt->time_delta_computed,1 )) { + v1 = mt->time_rd (mt_time_val); + mv = reference->time_rd (ref_time_val); + v2 = mt->time_rd (mt_time_val); + mt->time_delta = mv - ((v1 /2 ) + (v2 /2 )); + } + } + +/* Clear Time Compare */ + mt_time_cmp = (void *)mt->addr +MTIMER_CMP_OFF ; + mt->time_wr (-1ULL , &mt_time_cmp[target_hart - mt->first_hartid]); + +return 0 ; +} + +int aclint_mtimer_cold_init (struct aclint_mtimer_data *mt, +struct aclint_mtimer_data *reference) +{ +u32 i; +int rc; +unsigned long pos, region_size; +struct sbi_domain_memregion reg; + +/* Sanity checks */ +if (!mt || (mt->addr & (ACLINT_MTIMER_ALIGN -1 )) || + (mt->size <ACLINT_MTIMER_SIZE ) || + (mt->first_hartid >=SBI_HARTMASK_MAX_BITS ) || + (mt->hart_count >ACLINT_MTIMER_MAX_HARTS )) +return SBI_EINVAL ; + +/* Initialize private data */ + mt->time_delta_reference = reference; + mt->time_delta_computed =0 ; + mt->time_delta =0 ; + mt->time_rd = mtimer_time_rd32; + mt->time_wr = mtimer_time_wr32; + +/* Override read/write accessors for 64bit MMIO */ +#if __riscv_xlen !=32 +if (mt->has_64bit_mmio) { + mt->time_rd = mtimer_time_rd64; + mt->time_wr = mtimer_time_wr64; + } +#endif + +/* Update MTIMER hartid table */ +for (i =0 ; i < mt->hart_count; i++) + mtimer_hartid2data[mt->first_hartid + i] = mt; + +/* Add MTIMER regions to the root domain */ +for (pos =0 ; pos < mt->size; pos +=ACLINT_MTIMER_ALIGN ) { + region_size = ((mt->size - pos) <ACLINT_MTIMER_ALIGN ) ? + (mt->size - pos) :ACLINT_MTIMER_ALIGN ; +sbi_domain_memregion_init (mt->addr + pos, region_size, +SBI_DOMAIN_MEMREGION_MMIO , ®); + rc =sbi_domain_root_add_memregion (®); +if (rc) +return rc; + } + +sbi_timer_set_device (&mtimer); + +return 0 ; +}lib/utils/timer/objects.mk +0
-0@@ -9,3 +9,4 @@
Quoted 5 lines
lib/utils/timer/objects.mk line 12
Quoted 3 lines
lib/utils/timer/objects.mk +1
-0libsbiutils-objs-y += timer/fdt_timer.o libsbiutils-objs-y += timer/fdt_timer_clint.o +libsbiutils-objs-y += timer/aclint_mtimer.onits: insert this by following the alphabetical order
Okay, will update.
Quoted 3 lines
Otherwise,
Reviewed-by Bin Meng <[email protected]>
Regards,
Anup
PATCH 1/6 lib: utils/timer: Add ACLINT MTIMER library
In reply to Anup Patel? 2021-06-12???? 21:33 +0530?Anup Patel???
Quoted 114 lines
We add common ACLINT MTIMER library similar to the CLINT library so that OpenSBI platforms can use it.
Signed-off-by Anup Patel <[email protected]>---
?include/sbi_utils/timer/aclint_mtimer.h |? 41 ++++++ ?lib/utils/timer/aclint_mtimer.c???????? | 180
++++++++++++++++++++++++
?lib/utils/timer/objects.mk????????????? |?? 1 + ?3 files changed, 222 insertions(+)
?create mode 100644include/sbi_utils/timer/aclint_mtimer.h?create mode 100644lib/utils/timer/aclint_mtimer.cinclude/sbi_utils/timer/aclint_mtimer.h new file +28
-0@@ -0,0 +1,41 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2021 Western Digital Corporation or its affiliates. +* +* Authors: +*?? Anup Patel <[email protected]> +*/ + +#ifndef __TIMER_ACLINT_MTIMER_H__ +#define __TIMER_ACLINT_MTIMER_H__ + +#include <sbi/sbi_types.h> + +#define ACLINT_MTIMER_ALIGN????????????0x1000 +#define ACLINT_MTIMER_SIZE?????????????0x8000 +#define ACLINT_MTIMER_MAX_HARTS????????4095 + +#define CLINT_MTIMER_OFFSET????????????0x4000 + +struct aclint_mtimer_data { +???????/* Public details */ +???????unsigned long addr; +???????unsigned long size; +???????u32 first_hartid; +???????u32 hart_count; +???????bool has_64bit_mmio; +???????/* Private details (initialized and used by ACLINT MTIMERlibrary) */
+???????structaclint_mtimer_data*time_delta_reference; +???????unsigned longtime_delta_computed; +???????u64time_delta;
+???????u64 (*time_rd)(volatile u64 *addr); +???????void (*time_wr)(u64 value, volatile u64 *addr);include/sbi_utils/timer/aclint_mtimer.h new file +8
-0+}; + +int aclint_mtimer_warm_init (void ); + +int aclint_mtimer_cold_init (struct aclint_mtimer_data *mt, +?????????????????????????? struct aclint_mtimer_data *reference); + +#endif lib/utils/timer/aclint_mtimer.c new file +23
-0@@ -0,0 +1,180 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2021 Western Digital Corporation or its affiliates. +* +* Authors: +*?? Anup Patel <[email protected]> +*/ + +#include <sbi/riscv_asm.h> +#include <sbi/riscv_atomic.h> +#include <sbi/riscv_io.h> +#include <sbi/sbi_domain.h> +#include <sbi/sbi_error.h> +#include <sbi/sbi_hartmask.h> +#include <sbi/sbi_ipi.h> +#include <sbi/sbi_timer.h> +#include <sbi_utils/timer/aclint_mtimer.h> + +#define MTIMER_CMP_OFF ?????????0x0000 +#define MTIMER_VAL_OFF ?????????0x7ff8 + +static struct aclint_mtimer_data*mtimer_hartid2data[SBI_HARTMASK_MAX_BITS];
lib/utils/timer/aclint_mtimer.c new file +21
-0+ +#if __riscv_xlen !=32 +static u64 mtimer_time_rd64 (volatile u64 *addr) +{ +???????return readq_relaxed(addr); +} + +static void mtimer_time_wr64 (u64 value,volatile u64 *addr) +{ +???????writeq_relaxed(value, addr); +} +#endif + +static u64 mtimer_time_rd32 (volatile u64 *addr) +{ +???????u32 lo, hi; + +???????do { +???????????????hi = readl_relaxed((u32 *)addr + 1); +???????????????lo = readl_relaxed((u32 *)addr); +???????} while (hi != readl_relaxed((u32 *)addr + 1));
lib/utils/timer/aclint_mtimer.c
Quoted 10 lines
lib/utils/timer/aclint_mtimer.c new file +10
-0+ +???????return ((u64)hi << 32) | (u64)lo; +} + +static void mtimer_time_wr32 (u64 value,volatile u64 *addr) +{ +???????u32 mask = -1U; + +???????writel_relaxed(value & mask, (void *)(addr)); +???????writel_relaxed(value >> 32, (void *)(addr) + 0x04);
I recommend writing like this
writel_relaxed(0, (void *)(addr)); writel_relaxed(value >> 32, (void *)(addr) + 0x04); writel_relaxed(value & mask, (void *)(addr));
Quoted 153 lines
lib/utils/timer/aclint_mtimer.c new file +5
-0+} + +static u64 mtimer_value (void ) +{ +???????struct aclint_mtimer_data *mt =mtimer_hartid2data[current_hartid()];
+???????u64*time_val= ((void *)mt->addr) +MTIMER_VAL_OFF;lib/utils/timer/aclint_mtimer.c new file +9
-0+ +???????/* Read MTIMER Time Value */ +???????return mt->time_rd(time_val) + mt->time_delta; +} + +static void mtimer_event_stop (void ) +{ +???????u32 target_hart = current_hartid(); +???????struct aclint_mtimer_data *mt =mtimer_hartid2data[target_hart];
+???????u64*time_cmp= (void *)mt->addr +MTIMER_CMP_OFF; +
+???????/* Clear MTIMER Time Compare */ +???????mt->time_wr(-1ULL, &time_cmp[target_hart - mt-Quoted 1 line
first_hartid]);lib/utils/timer/aclint_mtimer.c new file +6
-0+} + +static void mtimer_event_start (u64 next_event) +{ +???????u32 target_hart = current_hartid(); +???????struct aclint_mtimer_data *mt =mtimer_hartid2data[target_hart];
+???????u64*time_cmp= (void *)mt->addr +MTIMER_CMP_OFF;lib/utils/timer/aclint_mtimer.c new file +20
-0+ +???????/* Program MTIMER Time Compare */ +???????mt->time_wr(next_event - mt->time_delta, +?????????????????? &time_cmp[target_hart - mt->first_hartid]); +} + +static struct sbi_timer_device mtimer = { +???????.name = "aclint-mtimer", +???????.timer_value = mtimer_value, +???????.timer_event_start = mtimer_event_start, +???????.timer_event_stop = mtimer_event_stop +}; + +int aclint_mtimer_warm_init (void ) +{ +???????u64 v1, v2, mv; +???????u32 target_hart = current_hartid(); +???????struct aclint_mtimer_data *reference; +???????u64 *mt_time_val, *mt_time_cmp, *ref_time_val; +???????struct aclint_mtimer_data *mt =mtimer_hartid2data[target_hart];
lib/utils/timer/aclint_mtimer.c new file +8
-0+ +???????if (!mt) +???????????????return SBI_ENODEV; + +???????/* +??????? * Compute delta if reference available +??????? * +??????? * We deliberately compute time_delta in warm init so that
time_delta
+??????? * is computed on a HART which is going to use given MTIMER. We use
+??????? * atomic flagtimer_delta_computedto ensure that only one HART does
+??????? *time_deltacomputation.
+??????? */
+???????if (mt->time_delta_reference) { +???????????????reference =mt->time_delta_reference; +???????????????mt_time_val = (void *)mt->addr +MTIMER_VAL_OFF; +???????????????ref_time_val = (void *)reference->addr +MTIMER_VAL_OFF;
+???????????????if (!atomic_raw_xchg_ulong(&mt->time_delta_computed, 1)) {
+???????????????????????v1 =mt->time_rd(mt_time_val); +???????????????????????mv =reference->time_rd(ref_time_val); +???????????????????????v2 =mt->time_rd(mt_time_val); +???????????????????????mt->time_delta = mv - ((v1 / 2) + (v2 / 2)); +???????????????}
+???????}
+
+???????/* Clear Time Compare */
+???????mt_time_cmp = (void *)mt->addr +MTIMER_CMP_OFF; +???????mt->time_wr(-1ULL, &mt_time_cmp[target_hart - mt-Quoted 1 line
first_hartid]);lib/utils/timer/aclint_mtimer.c new file +41
-0+ +???????return 0; +} + +int aclint_mtimer_cold_init (struct aclint_mtimer_data *mt, +?????????????????????????? struct aclint_mtimer_data *reference) +{ +???????u32 i; +???????int rc; +???????unsigned long pos, region_size; +???????struct sbi_domain_memregion reg; + +???????/* Sanity checks */ +???????if (!mt || (mt->addr & (ACLINT_MTIMER_ALIGN - 1)) || +?????????? (mt->size < ACLINT_MTIMER_SIZE) || +?????????? (mt->first_hartid >= SBI_HARTMASK_MAX_BITS) || +?????????? (mt->hart_count > ACLINT_MTIMER_MAX_HARTS)) +???????????????return SBI_EINVAL; + +???????/* Initialize private data */ +???????mt->time_delta_reference = reference; +???????mt->time_delta_computed = 0; +???????mt->time_delta = 0; +???????mt->time_rd = mtimer_time_rd32; +???????mt->time_wr = mtimer_time_wr32; + +???????/* Override read/write accessors for 64bit MMIO */ +#if __riscv_xlen !=32 +???????if (mt->has_64bit_mmio) { +???????????????mt->time_rd = mtimer_time_rd64; +???????????????mt->time_wr = mtimer_time_wr64; +???????} +#endif + +???????/* Update MTIMER hartid table */ +???????for (i = 0; i < mt->hart_count; i++) +???????????????mtimer_hartid2data[mt->first_hartid + i] = mt; + +???????/* Add MTIMER regions to the root domain */ +???????for (pos = 0; pos < mt->size; pos += ACLINT_MTIMER_ALIGN) { +???????????????region_size = ((mt->size - pos) <
ACLINT_MTIMER_ALIGN) ?
+???????????????????????????? (mt->size- pos) :ACLINT_MTIMER_ALIGN; +???????????????sbi_domain_memregion_init(mt->addr + pos,region_size,
+????????????????????????????????????????SBI_DOMAIN_MEMREGION_MMIO, ®);
+???????????????rc =sbi_domain_root_add_memregion(®); +???????????????if (rc)
+???????????????????????return rc;
+???????}lib/utils/timer/aclint_mtimer.c new file +5
-0+ +???????sbi_timer_set_device(&mtimer); + +???????return 0; +}lib/utils/timer/objects.mk +0
-0@@ -9,3 +9,4 @@?
?libsbiutils-objs-y +=timer/fdt_timer.o
?libsbiutils-objs-y +=timer/fdt_timer_clint.o
+libsbiutils-objs-y +=timer/aclint_mtimer.oSignature · 1 line
2.25.1
PATCH 1/6 lib: utils/timer: Add ACLINT MTIMER library
Quoted 127 lines · Xiang W
? 2021-06-12???? 21:33 +0530?Anup Patel???
Quoted 114 lines
We add common ACLINT MTIMER library similar to the CLINT library so that OpenSBI platforms can use it.
Signed-off-by Anup Patel <[email protected]>--- include/sbi_utils/timer/aclint_mtimer.h | 41 ++++++ lib/utils/timer/aclint_mtimer.c | 180 ++++++++++++++++++++++++ lib/utils/timer/objects.mk | 1 + 3 files changed, 222 insertions(+) create mode 100644 include/sbi_utils/timer/aclint_mtimer.h create mode 100644 lib/utils/timer/aclint_mtimer.cinclude/sbi_utils/timer/aclint_mtimer.h new file +28
-0@@ -0,0 +1,41 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2021 Western Digital Corporation or its affiliates. +* +* Authors: +* Anup Patel <[email protected]> +*/ + +#ifndef __TIMER_ACLINT_MTIMER_H__ +#define __TIMER_ACLINT_MTIMER_H__ + +#include <sbi/sbi_types.h> + +#define ACLINT_MTIMER_ALIGN 0x1000 +#define ACLINT_MTIMER_SIZE 0x8000 +#define ACLINT_MTIMER_MAX_HARTS 4095 + +#define CLINT_MTIMER_OFFSET 0x4000 + +struct aclint_mtimer_data { + /* Public details */ + unsigned long addr; + unsigned long size; + u32 first_hartid; + u32 hart_count; + bool has_64bit_mmio; + /* Private details (initialized and used by ACLINT MTIMERlibrary) */
include/sbi_utils/timer/aclint_mtimer.h new file +13
-0+struct aclint_mtimer_data *time_delta_reference; +unsigned long time_delta_computed; +u64 time_delta; +u64 (*time_rd)(volatile u64 *addr); + void (*time_wr)(u64 value, volatile u64 *addr); +}; + +int aclint_mtimer_warm_init (void ); + +int aclint_mtimer_cold_init (struct aclint_mtimer_data *mt, +struct aclint_mtimer_data *reference); + +#endif lib/utils/timer/aclint_mtimer.c new file +23
-0@@ -0,0 +1,180 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2021 Western Digital Corporation or its affiliates. +* +* Authors: +* Anup Patel <[email protected]> +*/ + +#include <sbi/riscv_asm.h> +#include <sbi/riscv_atomic.h> +#include <sbi/riscv_io.h> +#include <sbi/sbi_domain.h> +#include <sbi/sbi_error.h> +#include <sbi/sbi_hartmask.h> +#include <sbi/sbi_ipi.h> +#include <sbi/sbi_timer.h> +#include <sbi_utils/timer/aclint_mtimer.h> + +#define MTIMER_CMP_OFF 0x0000 +#define MTIMER_VAL_OFF 0x7ff8 + +static struct aclint_mtimer_data*mtimer_hartid2data[SBI_HARTMASK_MAX_BITS];
lib/utils/timer/aclint_mtimer.c new file +21
-0+ +#if __riscv_xlen !=32 +static u64 mtimer_time_rd64 (volatile u64 *addr) +{ +return readq_relaxed (addr); +} + +static void mtimer_time_wr64 (u64 value,volatile u64 *addr) +{ +writeq_relaxed (value, addr); +} +#endif + +static u64 mtimer_time_rd32 (volatile u64 *addr) +{ +u32 lo, hi; + +do { + hi =readl_relaxed ((u32 *)addr +1 ); + lo =readl_relaxed ((u32 *)addr); + }while (hi !=readl_relaxed ((u32 *)addr +1 ));lib/utils/timer/aclint_mtimer.c line 54
Quoted 10 lines
lib/utils/timer/aclint_mtimer.c new file +10
-0+ +return ((u64 )hi <<32 ) | (u64 )lo; +} + +static void mtimer_time_wr32 (u64 value,volatile u64 *addr) +{ +u32 mask =-1U ; + +writel_relaxed (value & mask, (void *)(addr)); +writel_relaxed (value >>32 , (void *)(addr) +0x04 );I recommend writing like this
Quoted 3 lines
writel_relaxed(0, (void *)(addr));
writel_relaxed(value >> 32, (void *)(addr) + 0x04);
writel_relaxed(value & mask, (void *)(addr));Yes, certainly this is more appropriate sequence but the RISC-V privilege spec says to write -1U instead of 0 in the first write.
Refer, "section 3.2.1 Machine Timer Registers (mtime and mtimecmp)" in the RISC-V privilege spec.
Quoted 2 lines
Reviewed-by Xiang W <[email protected]>
Regards,
Anup
Quoted 155 lines
Quoted 153 lines
lib/utils/timer/aclint_mtimer.c new file +5
-0+} + +static u64 mtimer_value (void ) +{ + struct aclint_mtimer_data *mt =mtimer_hartid2data[current_hartid()];
lib/utils/timer/aclint_mtimer.c new file +10
-0+u64 *time_val = ((void *)mt->addr) +MTIMER_VAL_OFF ; + +/* Read MTIMER Time Value */ +return mt->time_rd (time_val) + mt->time_delta; +} + +static void mtimer_event_stop (void ) +{ +u32 target_hart =current_hartid (); + struct aclint_mtimer_data *mt =mtimer_hartid2data[target_hart];
lib/utils/timer/aclint_mtimer.c new file +4
-0+u64 *time_cmp = (void *)mt->addr +MTIMER_CMP_OFF ; + +/* Clear MTIMER Time Compare */ + mt->time_wr(-1ULL, &time_cmp[target_hart - mt-Quoted 1 line
first_hartid]);lib/utils/timer/aclint_mtimer.c new file +6
-0+} + +static void mtimer_event_start (u64 next_event) +{ +u32 target_hart =current_hartid (); + struct aclint_mtimer_data *mt =mtimer_hartid2data[target_hart];
lib/utils/timer/aclint_mtimer.c new file +21
-0+u64 *time_cmp = (void *)mt->addr +MTIMER_CMP_OFF ; + +/* Program MTIMER Time Compare */ + mt->time_wr (next_event - mt->time_delta, + &time_cmp[target_hart - mt->first_hartid]); +} + +static struct sbi_timer_device mtimer = { + .name ="aclint-mtimer" , + .timer_value = mtimer_value, + .timer_event_start = mtimer_event_start, + .timer_event_stop = mtimer_event_stop +}; + +int aclint_mtimer_warm_init (void ) +{ +u64 v1, v2, mv; +u32 target_hart =current_hartid (); +struct aclint_mtimer_data *reference; +u64 *mt_time_val, *mt_time_cmp, *ref_time_val; + struct aclint_mtimer_data *mt =mtimer_hartid2data[target_hart];
lib/utils/timer/aclint_mtimer.c new file +8
-0+ +if (!mt) +return SBI_ENODEV ; + +/* +* Compute delta if reference available +* +* We deliberately compute time_delta in warm init so that
time_delta
+ * is computed on a HART which is going to use given MTIMER.
We use
+ * atomic flagtimer_delta_computedto ensure that only one
HART doeslib/utils/timer/aclint_mtimer.c new file +6
-0+* time_delta computation. +*/ +if (mt->time_delta_reference) { + reference = mt->time_delta_reference; + mt_time_val = (void *)mt->addr +MTIMER_VAL_OFF ; + ref_time_val = (void *)reference->addr +
MTIMER_VAL_OFF;
+ if (!atomic_raw_xchg_ulong(&mt->time_delta_computed,
1)) {lib/utils/timer/aclint_mtimer.c new file +10
-0+ v1 = mt->time_rd (mt_time_val); + mv = reference->time_rd (ref_time_val); + v2 = mt->time_rd (mt_time_val); + mt->time_delta = mv - ((v1 /2 ) + (v2 /2 )); + } + } + +/* Clear Time Compare */ + mt_time_cmp = (void *)mt->addr +MTIMER_CMP_OFF ; + mt->time_wr(-1ULL, &mt_time_cmp[target_hart - mt-Quoted 1 line
first_hartid]);lib/utils/timer/aclint_mtimer.c new file +41
-0+ +return 0 ; +} + +int aclint_mtimer_cold_init (struct aclint_mtimer_data *mt, +struct aclint_mtimer_data *reference) +{ +u32 i; +int rc; +unsigned long pos, region_size; +struct sbi_domain_memregion reg; + +/* Sanity checks */ +if (!mt || (mt->addr & (ACLINT_MTIMER_ALIGN -1 )) || + (mt->size <ACLINT_MTIMER_SIZE ) || + (mt->first_hartid >=SBI_HARTMASK_MAX_BITS ) || + (mt->hart_count >ACLINT_MTIMER_MAX_HARTS )) +return SBI_EINVAL ; + +/* Initialize private data */ + mt->time_delta_reference = reference; + mt->time_delta_computed =0 ; + mt->time_delta =0 ; + mt->time_rd = mtimer_time_rd32; + mt->time_wr = mtimer_time_wr32; + +/* Override read/write accessors for 64bit MMIO */ +#if __riscv_xlen !=32 +if (mt->has_64bit_mmio) { + mt->time_rd = mtimer_time_rd64; + mt->time_wr = mtimer_time_wr64; + } +#endif + +/* Update MTIMER hartid table */ +for (i =0 ; i < mt->hart_count; i++) + mtimer_hartid2data[mt->first_hartid + i] = mt; + +/* Add MTIMER regions to the root domain */ +for (pos =0 ; pos < mt->size; pos +=ACLINT_MTIMER_ALIGN ) { + region_size = ((mt->size - pos) <
ACLINT_MTIMER_ALIGN) ?lib/utils/timer/aclint_mtimer.c new file +2
-0+ (mt->size - pos) : ACLINT_MTIMER_ALIGN; + sbi_domain_memregion_init(mt->addr + pos,
region_size,
+SBI_DOMAIN_MEMREGION_MMIO,
®);lib/utils/timer/aclint_mtimer.c new file +9
-0+ rc =sbi_domain_root_add_memregion (®); +if (rc) +return rc; + } + +sbi_timer_set_device (&mtimer); + +return 0 ; +}lib/utils/timer/objects.mk +1
-1@@ -9,3 +9,4 @@ libsbiutils-objs-y += timer/fdt_timer.o libsbiutils-objs-y += timer/fdt_timer_clint.o +libsbiutils-objs-y += timer/aclint_mtimer.o --2.25.1
PATCH 1/6 lib: utils/timer: Add ACLINT MTIMER library
? 2021-06-23???? 10:35 +0530?Anup Patel???
Quoted 135 lines · Xiang W
Quoted 125 lines
? 2021-06-12???? 21:33 +0530?Anup Patel???
Quoted 123 lines
We add common ACLINT MTIMER library similar to the CLINT library so that OpenSBI platforms can use it.
Signed-off-by Anup Patel <[email protected]>---
?include/sbi_utils/timer/aclint_mtimer.h |? 41 ++++++ ?lib/utils/timer/aclint_mtimer.c???????? | 180
++++++++++++++++++++++++
?lib/utils/timer/objects.mk????????????? |?? 1 + ?3 files changed, 222 insertions(+)
?create mode 100644include/sbi_utils/timer/aclint_mtimer.h?create mode 100644lib/utils/timer/aclint_mtimer.cinclude/sbi_utils/timer/aclint_mtimer.h new file +4
-0@@ -0,0 +1,41 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2021 Western Digital Corporation or its affiliates.
+ *
+ * Authors:
+ *?? Anup Patel <[email protected]>
+ */include/sbi_utils/timer/aclint_mtimer.h new file +20
-0+ +#ifndef __TIMER_ACLINT_MTIMER_H__ +#define __TIMER_ACLINT_MTIMER_H__ + +#include <sbi/sbi_types.h> + +#define ACLINT_MTIMER_ALIGN??????????? 0x1000 +#define ACLINT_MTIMER_SIZE???????????? 0x8000 +#define ACLINT_MTIMER_MAX_HARTS??????? 4095 + +#define CLINT_MTIMER_OFFSET??????????? 0x4000 + +struct aclint_mtimer_data { +?????? /* Public details */ +?????? unsigned long addr; +?????? unsigned long size; +?????? u32 first_hartid; +?????? u32 hart_count; +?????? bool has_64bit_mmio; +?????? /* Private details (initialized and used by ACLINT MTIMERlibrary) */
+?????? structaclint_mtimer_data*time_delta_reference; +?????? unsigned longtime_delta_computed; +?????? u64time_delta;
+?????? u64 (*time_rd)(volatile u64 *addr); +?????? void (*time_wr)(u64 value, volatile u64 *addr);include/sbi_utils/timer/aclint_mtimer.h new file +6
-0+}; + +int aclint_mtimer_warm_init (void ); + +int aclint_mtimer_cold_init (struct aclint_mtimer_data *mt, +?????????????????????????? struct aclint_mtimer_data*reference);
include/sbi_utils/timer/aclint_mtimer.h new file +2
-0+ +#endif lib/utils/timer/aclint_mtimer.c new file +4
-0@@ -0,0 +1,180 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2021 Western Digital Corporation or its affiliates.
+ *
+ * Authors:
+ *?? Anup Patel <[email protected]>
+ */lib/utils/timer/aclint_mtimer.c new file +15
-0+ +#include <sbi/riscv_asm.h> +#include <sbi/riscv_atomic.h> +#include <sbi/riscv_io.h> +#include <sbi/sbi_domain.h> +#include <sbi/sbi_error.h> +#include <sbi/sbi_hartmask.h> +#include <sbi/sbi_ipi.h> +#include <sbi/sbi_timer.h> +#include <sbi_utils/timer/aclint_mtimer.h> + +#define MTIMER_CMP_OFF ???????? 0x0000 +#define MTIMER_VAL_OFF ???????? 0x7ff8 + +static struct aclint_mtimer_data*mtimer_hartid2data[SBI_HARTMASK_MAX_BITS];
lib/utils/timer/aclint_mtimer.c new file +27
-0+ +#if __riscv_xlen !=32 +static u64 mtimer_time_rd64 (volatile u64 *addr) +{ +?????? return readq_relaxed(addr); +} + +static void mtimer_time_wr64 (u64 value,volatile u64 *addr) +{ +?????? writeq_relaxed(value, addr); +} +#endif + +static u64 mtimer_time_rd32 (volatile u64 *addr) +{ +?????? u32 lo, hi; + +?????? do { +?????????????? hi = readl_relaxed((u32 *)addr + 1); +?????????????? lo = readl_relaxed((u32 *)addr); +?????? } while (hi != readl_relaxed((u32 *)addr + 1)); + +?????? return ((u64)hi << 32) | (u64)lo; +} + +static void mtimer_time_wr32 (u64 value,volatile u64 *addr) +{Quoted 8 lines
Quoted 4 lines
+?????? u32 mask = -1U;
+
+??????writel_relaxed(value & mask, (void *)(addr)); +??????writel_relaxed(value >> 32, (void *)(addr) + 0x04);I recommend writing like this
???????writel_relaxed(0, (void *)(addr));
???????writel_relaxed(value >> 32, (void *)(addr) + 0x04); ???????writel_relaxed(value & mask, (void *)(addr));
Quoted 7 lines
Yes, certainly this is more appropriate sequence but the RISC-V privilege spec says to write -1U instead of 0 in the first write.
Refer, "section 3.2.1 Machine Timer Registers (mtime and mtimecmp)" in the RISC-V privilege spec.
Low 32bit write 0 is to prevent low 32bit carry to high 32bit. Write -1 will make this situation easier
Regards,
Xiang W
Quoted 170 lines
Quoted 2 lines
Reviewed-by Xiang W <[email protected]>Regards,
AnupQuoted 164 lines
Quoted 162 lines
lib/utils/timer/aclint_mtimer.c new file +5
-0+} + +static u64 mtimer_value (void ) +{ +?????? struct aclint_mtimer_data *mt =mtimer_hartid2data[current_hartid()];
+?????? u64*time_val= ((void *)mt->addr) +MTIMER_VAL_OFF;lib/utils/timer/aclint_mtimer.c new file +9
-0+ +?????? /* Read MTIMER Time Value */ +?????? return mt->time_rd(time_val) + mt->time_delta; +} + +static void mtimer_event_stop (void ) +{ +?????? u32 target_hart = current_hartid(); +?????? struct aclint_mtimer_data *mt =mtimer_hartid2data[target_hart];
+?????? u64*time_cmp= (void *)mt->addr +MTIMER_CMP_OFF; +
+?????? /* Clear MTIMER Time Compare */
+?????? mt->time_wr(-1ULL, &time_cmp[target_hart - mt-Quoted 1 line
first_hartid]);lib/utils/timer/aclint_mtimer.c new file +6
-0+} + +static void mtimer_event_start (u64 next_event) +{ +?????? u32 target_hart = current_hartid(); +?????? struct aclint_mtimer_data *mt =mtimer_hartid2data[target_hart];
+?????? u64*time_cmp= (void *)mt->addr +MTIMER_CMP_OFF;lib/utils/timer/aclint_mtimer.c new file +20
-0+ +?????? /* Program MTIMER Time Compare */ +?????? mt->time_wr(next_event - mt->time_delta, +?????????????????? &time_cmp[target_hart - mt->first_hartid]); +} + +static struct sbi_timer_device mtimer = { +?????? .name = "aclint-mtimer", +?????? .timer_value = mtimer_value, +?????? .timer_event_start = mtimer_event_start, +?????? .timer_event_stop = mtimer_event_stop +}; + +int aclint_mtimer_warm_init (void ) +{ +?????? u64 v1, v2, mv; +?????? u32 target_hart = current_hartid(); +?????? struct aclint_mtimer_data *reference; +?????? u64 *mt_time_val, *mt_time_cmp, *ref_time_val; +?????? struct aclint_mtimer_data *mt =mtimer_hartid2data[target_hart];
lib/utils/timer/aclint_mtimer.c new file +8
-0+ +?????? if (!mt) +?????????????? return SBI_ENODEV; + +?????? /* +??????? * Compute delta if reference available +??????? * +??????? * We deliberately compute time_delta in warm init so that
time_delta
+??????? * is computed on a HART which is going to use given MTIMER.
We use
+??????? * atomic flagtimer_delta_computedto ensure that only one
HART does
+??????? *time_deltacomputation.
+??????? */
+?????? if (mt->time_delta_reference) { +?????????????? reference =mt->time_delta_reference; +??????????????mt_time_val= (void *)mt->addr +MTIMER_VAL_OFF; +??????????????ref_time_val= (void *)reference->addr +MTIMER_VAL_OFF;
+?????????????? if (!atomic_raw_xchg_ulong(&mt-Quoted 1 line
time_delta_computed,1)) {
+?????????????????????? v1 =mt->time_rd(mt_time_val); +?????????????????????? mv =reference->time_rd(ref_time_val); +?????????????????????? v2 =mt->time_rd(mt_time_val); +??????????????????????mt->time_delta= mv - ((v1 / 2) + (v2 / 2));
+?????????????? }
+?????? }
+
+?????? /* Clear Time Compare */
+??????mt_time_cmp= (void *)mt->addr +MTIMER_CMP_OFF; +?????? mt->time_wr(-1ULL, &mt_time_cmp[target_hart - mt-Quoted 1 line
first_hartid]);lib/utils/timer/aclint_mtimer.c new file +40
-0+ +?????? return 0; +} + +int aclint_mtimer_cold_init (struct aclint_mtimer_data *mt, +?????????????????????????? struct aclint_mtimer_data *reference) +{ +?????? u32 i; +?????? int rc; +?????? unsigned long pos, region_size; +?????? struct sbi_domain_memregion reg; + +?????? /* Sanity checks */ +?????? if (!mt || (mt->addr & (ACLINT_MTIMER_ALIGN - 1)) || +?????????? (mt->size < ACLINT_MTIMER_SIZE) || +?????????? (mt->first_hartid >= SBI_HARTMASK_MAX_BITS) || +?????????? (mt->hart_count > ACLINT_MTIMER_MAX_HARTS)) +?????????????? return SBI_EINVAL; + +?????? /* Initialize private data */ +?????? mt->time_delta_reference = reference; +?????? mt->time_delta_computed = 0; +?????? mt->time_delta = 0; +?????? mt->time_rd = mtimer_time_rd32; +?????? mt->time_wr = mtimer_time_wr32; + +?????? /* Override read/write accessors for 64bit MMIO */ +#if __riscv_xlen !=32 +?????? if (mt->has_64bit_mmio) { +?????????????? mt->time_rd = mtimer_time_rd64; +?????????????? mt->time_wr = mtimer_time_wr64; +?????? } +#endif + +?????? /* Update MTIMER hartid table */ +?????? for (i = 0; i < mt->hart_count; i++) +?????????????? mtimer_hartid2data[mt->first_hartid + i] = mt; + +?????? /* Add MTIMER regions to the root domain */ +?????? for (pos = 0; pos < mt->size; pos += ACLINT_MTIMER_ALIGN){
+??????????????region_size= ((mt->size- pos) <ACLINT_MTIMER_ALIGN) ? +???????????????????????????? (mt->size- pos) :ACLINT_MTIMER_ALIGN;
+?????????????? sbi_domain_memregion_init(mt->addr + pos,region_size, +????????????????????????????????????????SBI_DOMAIN_MEMREGION_MMIO,
®);
+?????????????? rc =sbi_domain_root_add_memregion(®); +?????????????? if (rc)
+?????????????????????? return rc;
+?????? }lib/utils/timer/aclint_mtimer.c new file +5
-0+ +?????? sbi_timer_set_device(&mtimer); + +?????? return 0; +}lib/utils/timer/objects.mk +0
-0@@ -9,3 +9,4 @@?libsbiutils-objs-y +=
timer/fdt_timer.o
?libsbiutils-objs-y +=timer/fdt_timer_clint.o
+libsbiutils-objs-y +=timer/aclint_mtimer.o
--
2.25.1
PATCH 1/6 lib: utils/timer: Add ACLINT MTIMER library
In reply to Anup Patel? 2021-06-23???? 10:35 +0530?Anup Patel???
Quoted 135 lines · Xiang W
Quoted 125 lines
? 2021-06-12???? 21:33 +0530?Anup Patel???
Quoted 123 lines
We add common ACLINT MTIMER library similar to the CLINT library so that OpenSBI platforms can use it.
Signed-off-by Anup Patel <[email protected]>---
?include/sbi_utils/timer/aclint_mtimer.h |? 41 ++++++ ?lib/utils/timer/aclint_mtimer.c???????? | 180
++++++++++++++++++++++++
?lib/utils/timer/objects.mk????????????? |?? 1 + ?3 files changed, 222 insertions(+)
?create mode 100644include/sbi_utils/timer/aclint_mtimer.h?create mode 100644lib/utils/timer/aclint_mtimer.cinclude/sbi_utils/timer/aclint_mtimer.h new file +4
-0@@ -0,0 +1,41 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2021 Western Digital Corporation or its affiliates.
+ *
+ * Authors:
+ *?? Anup Patel <[email protected]>
+ */include/sbi_utils/timer/aclint_mtimer.h new file +20
-0+ +#ifndef __TIMER_ACLINT_MTIMER_H__ +#define __TIMER_ACLINT_MTIMER_H__ + +#include <sbi/sbi_types.h> + +#define ACLINT_MTIMER_ALIGN??????????? 0x1000 +#define ACLINT_MTIMER_SIZE???????????? 0x8000 +#define ACLINT_MTIMER_MAX_HARTS??????? 4095 + +#define CLINT_MTIMER_OFFSET??????????? 0x4000 + +struct aclint_mtimer_data { +?????? /* Public details */ +?????? unsigned long addr; +?????? unsigned long size; +?????? u32 first_hartid; +?????? u32 hart_count; +?????? bool has_64bit_mmio; +?????? /* Private details (initialized and used by ACLINT MTIMERlibrary) */
+?????? structaclint_mtimer_data*time_delta_reference; +?????? unsigned longtime_delta_computed; +?????? u64time_delta;
+?????? u64 (*time_rd)(volatile u64 *addr); +?????? void (*time_wr)(u64 value, volatile u64 *addr);include/sbi_utils/timer/aclint_mtimer.h new file +6
-0+}; + +int aclint_mtimer_warm_init (void ); + +int aclint_mtimer_cold_init (struct aclint_mtimer_data *mt, +?????????????????????????? struct aclint_mtimer_data*reference);
include/sbi_utils/timer/aclint_mtimer.h new file +2
-0+ +#endif lib/utils/timer/aclint_mtimer.c new file +4
-0@@ -0,0 +1,180 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2021 Western Digital Corporation or its affiliates.
+ *
+ * Authors:
+ *?? Anup Patel <[email protected]>
+ */lib/utils/timer/aclint_mtimer.c new file +15
-0+ +#include <sbi/riscv_asm.h> +#include <sbi/riscv_atomic.h> +#include <sbi/riscv_io.h> +#include <sbi/sbi_domain.h> +#include <sbi/sbi_error.h> +#include <sbi/sbi_hartmask.h> +#include <sbi/sbi_ipi.h> +#include <sbi/sbi_timer.h> +#include <sbi_utils/timer/aclint_mtimer.h> + +#define MTIMER_CMP_OFF ???????? 0x0000 +#define MTIMER_VAL_OFF ???????? 0x7ff8 + +static struct aclint_mtimer_data*mtimer_hartid2data[SBI_HARTMASK_MAX_BITS];
lib/utils/timer/aclint_mtimer.c new file +27
-0+ +#if __riscv_xlen !=32 +static u64 mtimer_time_rd64 (volatile u64 *addr) +{ +?????? return readq_relaxed(addr); +} + +static void mtimer_time_wr64 (u64 value,volatile u64 *addr) +{ +?????? writeq_relaxed(value, addr); +} +#endif + +static u64 mtimer_time_rd32 (volatile u64 *addr) +{ +?????? u32 lo, hi; + +?????? do { +?????????????? hi = readl_relaxed((u32 *)addr + 1); +?????????????? lo = readl_relaxed((u32 *)addr); +?????? } while (hi != readl_relaxed((u32 *)addr + 1)); + +?????? return ((u64)hi << 32) | (u64)lo; +} + +static void mtimer_time_wr32 (u64 value,volatile u64 *addr) +{Quoted 8 lines
Quoted 4 lines
+?????? u32 mask = -1U;
+
+??????writel_relaxed(value & mask, (void *)(addr)); +??????writel_relaxed(value >> 32, (void *)(addr) + 0x04);I recommend writing like this
???????writel_relaxed(0, (void *)(addr));
???????writel_relaxed(value >> 32, (void *)(addr) + 0x04); ???????writel_relaxed(value & mask, (void *)(addr));
Quoted 7 lines
Yes, certainly this is more appropriate sequence but the RISC-V privilege spec says to write -1U instead of 0 in the first write.
Refer, "section 3.2.1 Machine Timer Registers (mtime and mtimecmp)" in the RISC-V privilege spec.
The example in the manual is to prevent MTIMECMP from less than the original value or less than the value to be written. And MTIMECMP is not a counter and does not change. My suggestion is to prevent changes during write, causing the value of the counter and expected inconsistency after writing completion.
Regards,
Xiang W
Quoted 170 lines
Quoted 2 lines
Reviewed-by Xiang W <[email protected]>Regards,
AnupQuoted 164 lines
Quoted 162 lines
lib/utils/timer/aclint_mtimer.c new file +5
-0+} + +static u64 mtimer_value (void ) +{ +?????? struct aclint_mtimer_data *mt =mtimer_hartid2data[current_hartid()];
+?????? u64*time_val= ((void *)mt->addr) +MTIMER_VAL_OFF;lib/utils/timer/aclint_mtimer.c new file +9
-0+ +?????? /* Read MTIMER Time Value */ +?????? return mt->time_rd(time_val) + mt->time_delta; +} + +static void mtimer_event_stop (void ) +{ +?????? u32 target_hart = current_hartid(); +?????? struct aclint_mtimer_data *mt =mtimer_hartid2data[target_hart];
+?????? u64*time_cmp= (void *)mt->addr +MTIMER_CMP_OFF; +
+?????? /* Clear MTIMER Time Compare */
+?????? mt->time_wr(-1ULL, &time_cmp[target_hart - mt-Quoted 1 line
first_hartid]);lib/utils/timer/aclint_mtimer.c new file +6
-0+} + +static void mtimer_event_start (u64 next_event) +{ +?????? u32 target_hart = current_hartid(); +?????? struct aclint_mtimer_data *mt =mtimer_hartid2data[target_hart];
+?????? u64*time_cmp= (void *)mt->addr +MTIMER_CMP_OFF;lib/utils/timer/aclint_mtimer.c new file +20
-0+ +?????? /* Program MTIMER Time Compare */ +?????? mt->time_wr(next_event - mt->time_delta, +?????????????????? &time_cmp[target_hart - mt->first_hartid]); +} + +static struct sbi_timer_device mtimer = { +?????? .name = "aclint-mtimer", +?????? .timer_value = mtimer_value, +?????? .timer_event_start = mtimer_event_start, +?????? .timer_event_stop = mtimer_event_stop +}; + +int aclint_mtimer_warm_init (void ) +{ +?????? u64 v1, v2, mv; +?????? u32 target_hart = current_hartid(); +?????? struct aclint_mtimer_data *reference; +?????? u64 *mt_time_val, *mt_time_cmp, *ref_time_val; +?????? struct aclint_mtimer_data *mt =mtimer_hartid2data[target_hart];
lib/utils/timer/aclint_mtimer.c new file +8
-0+ +?????? if (!mt) +?????????????? return SBI_ENODEV; + +?????? /* +??????? * Compute delta if reference available +??????? * +??????? * We deliberately compute time_delta in warm init so that
time_delta
+??????? * is computed on a HART which is going to use given MTIMER.
We use
+??????? * atomic flagtimer_delta_computedto ensure that only one
HART does
+??????? *time_deltacomputation.
+??????? */
+?????? if (mt->time_delta_reference) { +?????????????? reference =mt->time_delta_reference; +??????????????mt_time_val= (void *)mt->addr +MTIMER_VAL_OFF; +??????????????ref_time_val= (void *)reference->addr +MTIMER_VAL_OFF;
+?????????????? if (!atomic_raw_xchg_ulong(&mt-Quoted 1 line
time_delta_computed,1)) {
+?????????????????????? v1 =mt->time_rd(mt_time_val); +?????????????????????? mv =reference->time_rd(ref_time_val); +?????????????????????? v2 =mt->time_rd(mt_time_val); +??????????????????????mt->time_delta= mv - ((v1 / 2) + (v2 / 2));
+?????????????? }
+?????? }
+
+?????? /* Clear Time Compare */
+??????mt_time_cmp= (void *)mt->addr +MTIMER_CMP_OFF; +?????? mt->time_wr(-1ULL, &mt_time_cmp[target_hart - mt-Quoted 1 line
first_hartid]);lib/utils/timer/aclint_mtimer.c new file +40
-0+ +?????? return 0; +} + +int aclint_mtimer_cold_init (struct aclint_mtimer_data *mt, +?????????????????????????? struct aclint_mtimer_data *reference) +{ +?????? u32 i; +?????? int rc; +?????? unsigned long pos, region_size; +?????? struct sbi_domain_memregion reg; + +?????? /* Sanity checks */ +?????? if (!mt || (mt->addr & (ACLINT_MTIMER_ALIGN - 1)) || +?????????? (mt->size < ACLINT_MTIMER_SIZE) || +?????????? (mt->first_hartid >= SBI_HARTMASK_MAX_BITS) || +?????????? (mt->hart_count > ACLINT_MTIMER_MAX_HARTS)) +?????????????? return SBI_EINVAL; + +?????? /* Initialize private data */ +?????? mt->time_delta_reference = reference; +?????? mt->time_delta_computed = 0; +?????? mt->time_delta = 0; +?????? mt->time_rd = mtimer_time_rd32; +?????? mt->time_wr = mtimer_time_wr32; + +?????? /* Override read/write accessors for 64bit MMIO */ +#if __riscv_xlen !=32 +?????? if (mt->has_64bit_mmio) { +?????????????? mt->time_rd = mtimer_time_rd64; +?????????????? mt->time_wr = mtimer_time_wr64; +?????? } +#endif + +?????? /* Update MTIMER hartid table */ +?????? for (i = 0; i < mt->hart_count; i++) +?????????????? mtimer_hartid2data[mt->first_hartid + i] = mt; + +?????? /* Add MTIMER regions to the root domain */ +?????? for (pos = 0; pos < mt->size; pos += ACLINT_MTIMER_ALIGN){
+??????????????region_size= ((mt->size- pos) <ACLINT_MTIMER_ALIGN) ? +???????????????????????????? (mt->size- pos) :ACLINT_MTIMER_ALIGN;
+?????????????? sbi_domain_memregion_init(mt->addr + pos,region_size, +????????????????????????????????????????SBI_DOMAIN_MEMREGION_MMIO,
®);
+?????????????? rc =sbi_domain_root_add_memregion(®); +?????????????? if (rc)
+?????????????????????? return rc;
+?????? }lib/utils/timer/aclint_mtimer.c new file +5
-0+ +?????? sbi_timer_set_device(&mtimer); + +?????? return 0; +}lib/utils/timer/objects.mk +0
-0@@ -9,3 +9,4 @@?libsbiutils-objs-y +=
timer/fdt_timer.o
?libsbiutils-objs-y +=timer/fdt_timer_clint.o
+libsbiutils-objs-y +=timer/aclint_mtimer.o
--
2.25.1
PATCH 1/6 lib: utils/timer: Add ACLINT MTIMER library
Quoted 141 lines · Xiang W
? 2021-06-23???? 10:35 +0530?Anup Patel???
Quoted 139 lines · Xiang W
Quoted 130 lines
? 2021-06-12???? 21:33 +0530?Anup Patel???
Quoted 117 lines
We add common ACLINT MTIMER library similar to the CLINT library so that OpenSBI platforms can use it.
Signed-off-by Anup Patel <[email protected]>--- include/sbi_utils/timer/aclint_mtimer.h | 41 ++++++ lib/utils/timer/aclint_mtimer.c | 180 ++++++++++++++++++++++++ lib/utils/timer/objects.mk | 1 + 3 files changed, 222 insertions(+) create mode 100644 include/sbi_utils/timer/aclint_mtimer.h create mode 100644 lib/utils/timer/aclint_mtimer.cinclude/sbi_utils/timer/aclint_mtimer.h new file +4
-0@@ -0,0 +1,41 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2021 Western Digital Corporation or its affiliates.
+ *
+ * Authors:
+ * Anup Patel <[email protected]>
+ */include/sbi_utils/timer/aclint_mtimer.h new file +20
-0+ +#ifndef __TIMER_ACLINT_MTIMER_H__ +#define __TIMER_ACLINT_MTIMER_H__ + +#include <sbi/sbi_types.h> + +#define ACLINT_MTIMER_ALIGN 0x1000 +#define ACLINT_MTIMER_SIZE 0x8000 +#define ACLINT_MTIMER_MAX_HARTS 4095 + +#define CLINT_MTIMER_OFFSET 0x4000 + +struct aclint_mtimer_data { + /* Public details */ + unsigned long addr; + unsigned long size; + u32 first_hartid; + u32 hart_count; + bool has_64bit_mmio; + /* Private details (initialized and used by ACLINT MTIMERlibrary) */
include/sbi_utils/timer/aclint_mtimer.h new file +11
-0+struct aclint_mtimer_data *time_delta_reference; +unsigned long time_delta_computed; +u64 time_delta; +u64 (*time_rd)(volatile u64 *addr); +void (*time_wr)(u64 value,volatile u64 *addr); +}; + +int aclint_mtimer_warm_init (void ); + +int aclint_mtimer_cold_init (struct aclint_mtimer_data *mt, + struct aclint_mtimer_data*reference);
include/sbi_utils/timer/aclint_mtimer.h new file +2
-0+ +#endif lib/utils/timer/aclint_mtimer.c new file +4
-0@@ -0,0 +1,180 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2021 Western Digital Corporation or its affiliates.
+ *
+ * Authors:
+ * Anup Patel <[email protected]>
+ */lib/utils/timer/aclint_mtimer.c new file +15
-0+ +#include <sbi/riscv_asm.h> +#include <sbi/riscv_atomic.h> +#include <sbi/riscv_io.h> +#include <sbi/sbi_domain.h> +#include <sbi/sbi_error.h> +#include <sbi/sbi_hartmask.h> +#include <sbi/sbi_ipi.h> +#include <sbi/sbi_timer.h> +#include <sbi_utils/timer/aclint_mtimer.h> + +#define MTIMER_CMP_OFF 0x0000 +#define MTIMER_VAL_OFF 0x7ff8 + +static struct aclint_mtimer_data*mtimer_hartid2data[SBI_HARTMASK_MAX_BITS];
lib/utils/timer/aclint_mtimer.c new file +21
-0+ +#if __riscv_xlen !=32 +static u64 mtimer_time_rd64 (volatile u64 *addr) +{ +return readq_relaxed (addr); +} + +static void mtimer_time_wr64 (u64 value,volatile u64 *addr) +{ +writeq_relaxed (value, addr); +} +#endif + +static u64 mtimer_time_rd32 (volatile u64 *addr) +{ +u32 lo, hi; + +do { + hi =readl_relaxed ((u32 *)addr +1 ); + lo =readl_relaxed ((u32 *)addr); + }while (hi !=readl_relaxed ((u32 *)addr +1 ));lib/utils/timer/aclint_mtimer.c line 54
Quoted 10 lines
lib/utils/timer/aclint_mtimer.c new file +10
-0+ +return ((u64 )hi <<32 ) | (u64 )lo; +} + +static void mtimer_time_wr32 (u64 value,volatile u64 *addr) +{ +u32 mask =-1U ; + +writel_relaxed (value & mask, (void *)(addr)); +writel_relaxed (value >>32 , (void *)(addr) +0x04 );I recommend writing like this
Quoted 3 lines
writel_relaxed(0, (void *)(addr)); writel_relaxed(value >> 32, (void *)(addr) + 0x04); writel_relaxed(value & mask, (void *)(addr));Yes, certainly this is more appropriate sequence but the RISC-V privilege spec says to write -1U instead of 0 in the first write.
Quoted 8 lines
Quoted 3 lines
Refer, "section 3.2.1 Machine Timer Registers (mtime and mtimecmp)" in the RISC-V privilege spec.
The example in the manual is to prevent MTIMECMP from less than the original value or less than the value to be written. And MTIMECMP is not a counter and does not change. My suggestion is to prevent changes during write, causing the value of the counter and expected inconsistency after writing completion.
Yes, the RISC-V privilege spec sequence is for MTIMECMP and we need to do things differently for MTIME.
Regards,
Anup
Quoted 175 lines
Regards,
Xiang WQuoted 170 lines
Quoted 2 lines
Reviewed-by Xiang W <[email protected]>Regards,
AnupQuoted 164 lines
Quoted 162 lines
lib/utils/timer/aclint_mtimer.c new file +5
-0+} + +static u64 mtimer_value (void ) +{ + struct aclint_mtimer_data *mt =mtimer_hartid2data[current_hartid()];
lib/utils/timer/aclint_mtimer.c new file +10
-0+u64 *time_val = ((void *)mt->addr) +MTIMER_VAL_OFF ; + +/* Read MTIMER Time Value */ +return mt->time_rd (time_val) + mt->time_delta; +} + +static void mtimer_event_stop (void ) +{ +u32 target_hart =current_hartid (); + struct aclint_mtimer_data *mt =mtimer_hartid2data[target_hart];
lib/utils/timer/aclint_mtimer.c new file +4
-0+u64 *time_cmp = (void *)mt->addr +MTIMER_CMP_OFF ; + +/* Clear MTIMER Time Compare */ + mt->time_wr(-1ULL, &time_cmp[target_hart - mt-Quoted 1 line
first_hartid]);lib/utils/timer/aclint_mtimer.c new file +6
-0+} + +static void mtimer_event_start (u64 next_event) +{ +u32 target_hart =current_hartid (); + struct aclint_mtimer_data *mt =mtimer_hartid2data[target_hart];
lib/utils/timer/aclint_mtimer.c new file +21
-0+u64 *time_cmp = (void *)mt->addr +MTIMER_CMP_OFF ; + +/* Program MTIMER Time Compare */ + mt->time_wr (next_event - mt->time_delta, + &time_cmp[target_hart - mt->first_hartid]); +} + +static struct sbi_timer_device mtimer = { + .name ="aclint-mtimer" , + .timer_value = mtimer_value, + .timer_event_start = mtimer_event_start, + .timer_event_stop = mtimer_event_stop +}; + +int aclint_mtimer_warm_init (void ) +{ +u64 v1, v2, mv; +u32 target_hart =current_hartid (); +struct aclint_mtimer_data *reference; +u64 *mt_time_val, *mt_time_cmp, *ref_time_val; + struct aclint_mtimer_data *mt =mtimer_hartid2data[target_hart];
lib/utils/timer/aclint_mtimer.c new file +8
-0+ +if (!mt) +return SBI_ENODEV ; + +/* +* Compute delta if reference available +* +* We deliberately compute time_delta in warm init so that
time_delta
+ * is computed on a HART which is going to use given
MTIMER.
We use
+ * atomic flagtimer_delta_computedto ensure that only
one
HART doeslib/utils/timer/aclint_mtimer.c new file +6
-0+* time_delta computation. +*/ +if (mt->time_delta_reference) { + reference = mt->time_delta_reference; + mt_time_val = (void *)mt->addr +MTIMER_VAL_OFF ; + ref_time_val = (void *)reference->addr +
MTIMER_VAL_OFF;
+ if (!atomic_raw_xchg_ulong(&mt-Quoted 1 line
time_delta_computed,1)) {
lib/utils/timer/aclint_mtimer.c new file +4
-0+ v1 = mt->time_rd (mt_time_val); + mv = reference->time_rd (ref_time_val); + v2 = mt->time_rd (mt_time_val); + mt->time_delta = mv - ((v1 / 2) + (v2 /2));
lib/utils/timer/aclint_mtimer.c new file +6
-0+ } + } + +/* Clear Time Compare */ + mt_time_cmp = (void *)mt->addr +MTIMER_CMP_OFF ; + mt->time_wr(-1ULL, &mt_time_cmp[target_hart - mt-Quoted 1 line
first_hartid]);lib/utils/timer/aclint_mtimer.c new file +40
-0+ +return 0 ; +} + +int aclint_mtimer_cold_init (struct aclint_mtimer_data *mt, +struct aclint_mtimer_data *reference) +{ +u32 i; +int rc; +unsigned long pos, region_size; +struct sbi_domain_memregion reg; + +/* Sanity checks */ +if (!mt || (mt->addr & (ACLINT_MTIMER_ALIGN -1 )) || + (mt->size <ACLINT_MTIMER_SIZE ) || + (mt->first_hartid >=SBI_HARTMASK_MAX_BITS ) || + (mt->hart_count >ACLINT_MTIMER_MAX_HARTS )) +return SBI_EINVAL ; + +/* Initialize private data */ + mt->time_delta_reference = reference; + mt->time_delta_computed =0 ; + mt->time_delta =0 ; + mt->time_rd = mtimer_time_rd32; + mt->time_wr = mtimer_time_wr32; + +/* Override read/write accessors for 64bit MMIO */ +#if __riscv_xlen !=32 +if (mt->has_64bit_mmio) { + mt->time_rd = mtimer_time_rd64; + mt->time_wr = mtimer_time_wr64; + } +#endif + +/* Update MTIMER hartid table */ +for (i =0 ; i < mt->hart_count; i++) + mtimer_hartid2data[mt->first_hartid + i] = mt; + +/* Add MTIMER regions to the root domain */ +for (pos =0 ; pos < mt->size; pos +=ACLINT_MTIMER_ALIGN ){
+region_size= ((mt->size- pos) <ACLINT_MTIMER_ALIGN) ?
+ (mt->size- pos) :ACLINT_MTIMER_ALIGN;
+ sbi_domain_memregion_init(mt->addr + pos,region_size,
+SBI_DOMAIN_MEMREGION_MMIO,
®);lib/utils/timer/aclint_mtimer.c new file +9
-0+ rc =sbi_domain_root_add_memregion (®); +if (rc) +return rc; + } + +sbi_timer_set_device (&mtimer); + +return 0 ; +}lib/utils/timer/objects.mk +1
-1@@ -9,3 +9,4 @@ libsbiutils-objs-y += timer/fdt_timer.o libsbiutils-objs-y += timer/fdt_timer_clint.o +libsbiutils-objs-y += timer/aclint_mtimer.o --2.25.1
PATCH 2/6 lib: utils/ipi: Add ACLINT MSWI library
In reply to Anup PatelWe add common ACLINT MSWI library similar to the CLINT library so that OpenSBI platforms can use it.
--- include/sbi_utils/ipi/aclint_mswi.h | 33 +++++++++ lib/utils/ipi/aclint_mswi.c | 100 ++++++++++++++++++++++++++++ lib/utils/ipi/objects.mk | 1 + 3 files changed, 134 insertions(+) create mode 100644 include/sbi_utils/ipi/aclint_mswi.h create mode 100644 lib/utils/ipi/aclint_mswi.c
include/sbi_utils/ipi/aclint_mswi.h new file +33 -0
@@ -0,0 +1,33 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2021 Western Digital Corporation or its affiliates. +* +* Authors: +* Anup Patel <[email protected]> +*/ + +#ifndef __IPI_ACLINT_MSWI_H__ +#define __IPI_ACLINT_MSWI_H__ + +#include <sbi/sbi_types.h> + +#define ACLINT_MSWI_ALIGN 0x1000 +#define ACLINT_MSWI_SIZE 0x4000 +#define ACLINT_MSWI_MAX_HARTS 4095 + +#define CLINT_MSWI_OFFSET 0x0000 + +struct aclint_mswi_data { +/* Public details */ +unsigned long addr; +unsigned long size; +u32 first_hartid; +u32 hart_count; +}; + +int aclint_mswi_warm_init (void ); + +int aclint_mswi_cold_init (struct aclint_mswi_data *mswi); + +#endif
lib/utils/ipi/aclint_mswi.c new file +100 -0
100 lines not on this page · raw message
lib/utils/ipi/objects.mk +1 -0
@@ -9,3 +9,4 @@ libsbiutils-objs-y += ipi/fdt_ipi.o libsbiutils-objs-y += ipi/fdt_ipi_clint.o +libsbiutils-objs-y += ipi/aclint_mswi.o
Signature · 1 line
2.25.1
PATCH 2/6 lib: utils/ipi: Add ACLINT MSWI library
Quoted 81 lines · Anup Patel
We add common ACLINT MSWI library similar to the CLINT library so that OpenSBI platforms can use it.
Signed-off-by Anup Patel <[email protected]>--- include/sbi_utils/ipi/aclint_mswi.h | 33 +++++++++ lib/utils/ipi/aclint_mswi.c | 100 ++++++++++++++++++++++++++++ lib/utils/ipi/objects.mk | 1 + 3 files changed, 134 insertions(+) create mode 100644 include/sbi_utils/ipi/aclint_mswi.h create mode 100644 lib/utils/ipi/aclint_mswi.cinclude/sbi_utils/ipi/aclint_mswi.h new file +33
-0@@ -0,0 +1,33 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2021 Western Digital Corporation or its affiliates. +* +* Authors: +* Anup Patel <[email protected]> +*/ + +#ifndef __IPI_ACLINT_MSWI_H__ +#define __IPI_ACLINT_MSWI_H__ + +#include <sbi/sbi_types.h> + +#define ACLINT_MSWI_ALIGN 0x1000 +#define ACLINT_MSWI_SIZE 0x4000 +#define ACLINT_MSWI_MAX_HARTS 4095 + +#define CLINT_MSWI_OFFSET 0x0000 + +struct aclint_mswi_data { +/* Public details */ +unsigned long addr; +unsigned long size; +u32 first_hartid; +u32 hart_count; +}; + +int aclint_mswi_warm_init (void ); + +int aclint_mswi_cold_init (struct aclint_mswi_data *mswi); + +#endif lib/utils/ipi/aclint_mswi.c new file +23
-0@@ -0,0 +1,100 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2021 Western Digital Corporation or its affiliates. +* +* Authors: +* Anup Patel <[email protected]> +*/ + +#include <sbi/riscv_asm.h> +#include <sbi/riscv_atomic.h> +#include <sbi/riscv_io.h> +#include <sbi/sbi_domain.h> +#include <sbi/sbi_error.h> +#include <sbi/sbi_hartmask.h> +#include <sbi/sbi_ipi.h> +#include <sbi/sbi_timer.h> +#include <sbi_utils/ipi/aclint_mswi.h> + +static struct aclint_mswi_data *mswi_hartid2data[SBI_HARTMASK_MAX_BITS ]; + +static void mswi_ipi_send (u32 target_hart) +{
lib/utils/ipi/aclint_mswi.c line 33
Quoted 10 lines
lib/utils/ipi/aclint_mswi.c new file +10
-0+u32 *msip; +struct aclint_mswi_data *mswi; + +if (SBI_HARTMASK_MAX_BITS <= target_hart) +return ; + mswi = mswi_hartid2data[target_hart]; +if (!mswi) +return ; + +/* Set CLINT IPI */
nits: ACLINT
Quoted 6 lines
lib/utils/ipi/aclint_mswi.c new file +6
-0+ msip = (void *)mswi->addr; +writel (1 , &msip[target_hart - mswi->first_hartid]); +} + +static void mswi_ipi_clear (u32 target_hart) +{
lib/utils/ipi/aclint_mswi.c line 49
Quoted 10 lines
lib/utils/ipi/aclint_mswi.c new file +10
-0+u32 *msip; +struct aclint_mswi_data *mswi; + +if (SBI_HARTMASK_MAX_BITS <= target_hart) +return ; + mswi = mswi_hartid2data[target_hart]; +if (!mswi) +return ; + +/* Clear CLINT IPI */
nits: ACLINT
Quoted 56 lines
lib/utils/ipi/aclint_mswi.c new file +51
-0+ msip = (void *)mswi->addr; +writel (0 , &msip[target_hart - mswi->first_hartid]); +} + +static struct sbi_ipi_device aclint_mswi = { + .name ="aclint-mswi" , + .ipi_send = mswi_ipi_send, + .ipi_clear = mswi_ipi_clear +}; + +int aclint_mswi_warm_init (void ) +{ +/* Clear IPI for current HART */ +mswi_ipi_clear (current_hartid ()); + +return 0 ; +} + +int aclint_mswi_cold_init (struct aclint_mswi_data *mswi) +{ +u32 i; +int rc; +unsigned long pos, region_size; +struct sbi_domain_memregion reg; + +/* Sanity checks */ +if (!mswi || (mswi->addr & (ACLINT_MSWI_ALIGN -1 )) || + (mswi->size <ACLINT_MSWI_SIZE ) || + (mswi->first_hartid >=SBI_HARTMASK_MAX_BITS ) || + (mswi->hart_count >ACLINT_MSWI_MAX_HARTS )) +return SBI_EINVAL ; + +/* Update MSWI hartid table */ +for (i =0 ; i < mswi->hart_count; i++) + mswi_hartid2data[mswi->first_hartid + i] = mswi; + +/* Add MSWI regions to the root domain */ +for (pos =0 ; pos < mswi->size; pos +=ACLINT_MSWI_ALIGN ) { + region_size = ((mswi->size - pos) <ACLINT_MSWI_ALIGN ) ? + (mswi->size - pos) :ACLINT_MSWI_ALIGN ; +sbi_domain_memregion_init (mswi->addr + pos, region_size, +SBI_DOMAIN_MEMREGION_MMIO , ®); + rc =sbi_domain_root_add_memregion (®); +if (rc) +return rc; + } + +sbi_ipi_set_device (&aclint_mswi); + +return 0 ; +}lib/utils/ipi/objects.mk +0
-0
lib/utils/ipi/objects.mk line 12
Quoted 4 lines
lib/utils/ipi/objects.mk +1
-0@@ -9,3 +9,4 @@ libsbiutils-objs-y += ipi/fdt_ipi.o libsbiutils-objs-y += ipi/fdt_ipi_clint.o +libsbiutils-objs-y += ipi/aclint_mswi.o
nits: insert this by following the alphabetical order
Otherwise,
PATCH 2/6 lib: utils/ipi: Add ACLINT MSWI library
Quoted 87 lines · Bin Meng
Quoted 85 lines · Anup Patel
We add common ACLINT MSWI library similar to the CLINT library so that OpenSBI platforms can use it.
Signed-off-by Anup Patel <[email protected]>--- include/sbi_utils/ipi/aclint_mswi.h | 33 +++++++++ lib/utils/ipi/aclint_mswi.c | 100 ++++++++++++++++++++++++++++ lib/utils/ipi/objects.mk | 1 + 3 files changed, 134 insertions(+) create mode 100644 include/sbi_utils/ipi/aclint_mswi.h create mode 100644 lib/utils/ipi/aclint_mswi.cinclude/sbi_utils/ipi/aclint_mswi.h new file +33
-0@@ -0,0 +1,33 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2021 Western Digital Corporation or its affiliates. +* +* Authors: +* Anup Patel <[email protected]> +*/ + +#ifndef __IPI_ACLINT_MSWI_H__ +#define __IPI_ACLINT_MSWI_H__ + +#include <sbi/sbi_types.h> + +#define ACLINT_MSWI_ALIGN 0x1000 +#define ACLINT_MSWI_SIZE 0x4000 +#define ACLINT_MSWI_MAX_HARTS 4095 + +#define CLINT_MSWI_OFFSET 0x0000 + +struct aclint_mswi_data { +/* Public details */ +unsigned long addr; +unsigned long size; +u32 first_hartid; +u32 hart_count; +}; + +int aclint_mswi_warm_init (void ); + +int aclint_mswi_cold_init (struct aclint_mswi_data *mswi); + +#endif lib/utils/ipi/aclint_mswi.c new file +27
-0@@ -0,0 +1,100 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2021 Western Digital Corporation or its affiliates. +* +* Authors: +* Anup Patel <[email protected]> +*/ + +#include <sbi/riscv_asm.h> +#include <sbi/riscv_atomic.h> +#include <sbi/riscv_io.h> +#include <sbi/sbi_domain.h> +#include <sbi/sbi_error.h> +#include <sbi/sbi_hartmask.h> +#include <sbi/sbi_ipi.h> +#include <sbi/sbi_timer.h> +#include <sbi_utils/ipi/aclint_mswi.h> + +static struct aclint_mswi_data *mswi_hartid2data[SBI_HARTMASK_MAX_BITS ]; + +static void mswi_ipi_send (u32 target_hart) +{ +u32 *msip; +struct aclint_mswi_data *mswi; + +if (SBI_HARTMASK_MAX_BITS <= target_hart)
Quoted 8 lines
lib/utils/ipi/aclint_mswi.c line 33
Quoted 6 lines
lib/utils/ipi/aclint_mswi.c new file +6
-0+return ; + mswi = mswi_hartid2data[target_hart]; +if (!mswi) +return ; + +/* Set CLINT IPI */ nits: ACLINT
Okay, will update.
Quoted 11 lines
Quoted 11 lines
lib/utils/ipi/aclint_mswi.c new file +10
-0+ msip = (void *)mswi->addr; +writel (1 , &msip[target_hart - mswi->first_hartid]); +} + +static void mswi_ipi_clear (u32 target_hart) +{ +u32 *msip; +struct aclint_mswi_data *mswi; + +if (SBI_HARTMASK_MAX_BITS <= target_hart)
Quoted 8 lines
lib/utils/ipi/aclint_mswi.c line 49
Quoted 6 lines
lib/utils/ipi/aclint_mswi.c new file +6
-0+return ; + mswi = mswi_hartid2data[target_hart]; +if (!mswi) +return ; + +/* Clear CLINT IPI */ nits: ACLINT
Okay, will update.
Quoted 58 lines
Quoted 58 lines
lib/utils/ipi/aclint_mswi.c new file +51
-0+ msip = (void *)mswi->addr; +writel (0 , &msip[target_hart - mswi->first_hartid]); +} + +static struct sbi_ipi_device aclint_mswi = { + .name ="aclint-mswi" , + .ipi_send = mswi_ipi_send, + .ipi_clear = mswi_ipi_clear +}; + +int aclint_mswi_warm_init (void ) +{ +/* Clear IPI for current HART */ +mswi_ipi_clear (current_hartid ()); + +return 0 ; +} + +int aclint_mswi_cold_init (struct aclint_mswi_data *mswi) +{ +u32 i; +int rc; +unsigned long pos, region_size; +struct sbi_domain_memregion reg; + +/* Sanity checks */ +if (!mswi || (mswi->addr & (ACLINT_MSWI_ALIGN -1 )) || + (mswi->size <ACLINT_MSWI_SIZE ) || + (mswi->first_hartid >=SBI_HARTMASK_MAX_BITS ) || + (mswi->hart_count >ACLINT_MSWI_MAX_HARTS )) +return SBI_EINVAL ; + +/* Update MSWI hartid table */ +for (i =0 ; i < mswi->hart_count; i++) + mswi_hartid2data[mswi->first_hartid + i] = mswi; + +/* Add MSWI regions to the root domain */ +for (pos =0 ; pos < mswi->size; pos +=ACLINT_MSWI_ALIGN ) { + region_size = ((mswi->size - pos) <ACLINT_MSWI_ALIGN ) ? + (mswi->size - pos) :ACLINT_MSWI_ALIGN ; +sbi_domain_memregion_init (mswi->addr + pos, region_size, +SBI_DOMAIN_MEMREGION_MMIO , ®); + rc =sbi_domain_root_add_memregion (®); +if (rc) +return rc; + } + +sbi_ipi_set_device (&aclint_mswi); + +return 0 ; +}lib/utils/ipi/objects.mk +0
-0@@ -9,3 +9,4 @@
Quoted 5 lines
lib/utils/ipi/objects.mk line 12
Quoted 3 lines
lib/utils/ipi/objects.mk +1
-0libsbiutils-objs-y += ipi/fdt_ipi.o libsbiutils-objs-y += ipi/fdt_ipi_clint.o +libsbiutils-objs-y += ipi/aclint_mswi.onits: insert this by following the alphabetical order
Okay, will update.
Quoted 3 lines
Otherwise,
Reviewed-by Bin Meng <[email protected]>
Regards,
Anup
PATCH 2/6 lib: utils/ipi: Add ACLINT MSWI library
In reply to Anup Patel? 2021-06-12???? 21:33 +0530?Anup Patel???
Quoted 4 lines
We add common ACLINT MSWI library similar to the CLINT library so that OpenSBI platforms can use it.
Signed-off-by Anup Patel <[email protected]>
look good to me
Quoted 173 lines
---
?include/sbi_utils/ipi/aclint_mswi.h |? 33 +++++++++ ?lib/utils/ipi/aclint_mswi.c???????? | 100
++++++++++++++++++++++++++++
?lib/utils/ipi/objects.mk??????????? |?? 1 + ?3 files changed, 134 insertions(+)
?create mode 100644include/sbi_utils/ipi/aclint_mswi.h?create mode 100644lib/utils/ipi/aclint_mswi.cinclude/sbi_utils/ipi/aclint_mswi.h new file +33
-0@@ -0,0 +1,33 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2021 Western Digital Corporation or its affiliates. +* +* Authors: +*?? Anup Patel <[email protected]> +*/ + +#ifndef __IPI_ACLINT_MSWI_H__ +#define __IPI_ACLINT_MSWI_H__ + +#include <sbi/sbi_types.h> + +#define ACLINT_MSWI_ALIGN ??????????????0x1000 +#define ACLINT_MSWI_SIZE ???????????????0x4000 +#define ACLINT_MSWI_MAX_HARTS ??????????4095 + +#define CLINT_MSWI_OFFSET ??????????????0x0000 + +struct aclint_mswi_data { +???????/* Public details */ +???????unsigned long addr; +???????unsigned long size; +???????u32 first_hartid; +???????u32 hart_count; +}; + +int aclint_mswi_warm_init (void ); + +int aclint_mswi_cold_init (struct aclint_mswi_data *mswi); + +#endif lib/utils/ipi/aclint_mswi.c new file +20
-0@@ -0,0 +1,100 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2021 Western Digital Corporation or its affiliates. +* +* Authors: +*?? Anup Patel <[email protected]> +*/ + +#include <sbi/riscv_asm.h> +#include <sbi/riscv_atomic.h> +#include <sbi/riscv_io.h> +#include <sbi/sbi_domain.h> +#include <sbi/sbi_error.h> +#include <sbi/sbi_hartmask.h> +#include <sbi/sbi_ipi.h> +#include <sbi/sbi_timer.h> +#include <sbi_utils/ipi/aclint_mswi.h> + +static struct aclint_mswi_data*mswi_hartid2data[SBI_HARTMASK_MAX_BITS];
lib/utils/ipi/aclint_mswi.c new file +68
-0+ +static void mswi_ipi_send (u32 target_hart) +{ +???????u32 *msip; +???????struct aclint_mswi_data *mswi; + +???????if (SBI_HARTMASK_MAX_BITS <= target_hart) +???????????????return; +???????mswi = mswi_hartid2data[target_hart]; +???????if (!mswi) +???????????????return; + +???????/* Set CLINT IPI */ +???????msip = (void *)mswi->addr; +???????writel(1, &msip[target_hart - mswi->first_hartid]); +} + +static void mswi_ipi_clear (u32 target_hart) +{ +???????u32 *msip; +???????struct aclint_mswi_data *mswi; + +???????if (SBI_HARTMASK_MAX_BITS <= target_hart) +???????????????return; +???????mswi = mswi_hartid2data[target_hart]; +???????if (!mswi) +???????????????return; + +???????/* Clear CLINT IPI */ +???????msip = (void *)mswi->addr; +???????writel(0, &msip[target_hart - mswi->first_hartid]); +} + +static struct sbi_ipi_device aclint_mswi = { +???????.name = "aclint-mswi", +???????.ipi_send = mswi_ipi_send, +???????.ipi_clear = mswi_ipi_clear +}; + +int aclint_mswi_warm_init (void ) +{ +???????/* Clear IPI for current HART */ +???????mswi_ipi_clear(current_hartid()); + +???????return 0; +} + +int aclint_mswi_cold_init (struct aclint_mswi_data *mswi) +{ +???????u32 i; +???????int rc; +???????unsigned long pos, region_size; +???????struct sbi_domain_memregion reg; + +???????/* Sanity checks */ +???????if (!mswi || (mswi->addr & (ACLINT_MSWI_ALIGN - 1)) || +?????????? (mswi->size < ACLINT_MSWI_SIZE) || +?????????? (mswi->first_hartid >= SBI_HARTMASK_MAX_BITS) || +?????????? (mswi->hart_count > ACLINT_MSWI_MAX_HARTS)) +???????????????return SBI_EINVAL; + +???????/* Update MSWI hartid table */ +???????for (i = 0; i < mswi->hart_count; i++) +???????????????mswi_hartid2data[mswi->first_hartid + i] = mswi; + +???????/* Add MSWI regions to the root domain */ +???????for (pos = 0; pos < mswi->size; pos += ACLINT_MSWI_ALIGN) { +???????????????region_size = ((mswi->size - pos) <
ACLINT_MSWI_ALIGN) ?
+???????????????????????????? (mswi->size- pos) :ACLINT_MSWI_ALIGN; +???????????????sbi_domain_memregion_init(mswi->addr + pos,region_size,
+????????????????????????????????????????SBI_DOMAIN_MEMREGION_MMIO, ®);
+???????????????rc =sbi_domain_root_add_memregion(®); +???????????????if (rc)
+???????????????????????return rc;
+???????}lib/utils/ipi/aclint_mswi.c new file +5
-0+ +???????sbi_ipi_set_device(&aclint_mswi); + +???????return 0; +}lib/utils/ipi/objects.mk +0
-0@@ -9,3 +9,4 @@?
?libsbiutils-objs-y +=ipi/fdt_ipi.o
?libsbiutils-objs-y +=ipi/fdt_ipi_clint.o
+libsbiutils-objs-y +=ipi/aclint_mswi.oSignature · 1 line
2.25.1
PATCH 3/6 lib: utils: Add FDT parsing API common for both ACLINT and CLINT
In reply to Anup PatelWe add fdt_parse_aclint_node() which is can parse both ACLINT and CLINT DT nodes. This means fdt_parse_clint_node() is not required anymore so we remove it as well.
--- include/sbi_utils/fdt/fdt_helper.h | 7 +++---- lib/utils/fdt/fdt_helper.c | 31 +++++++++++++++--------------- lib/utils/ipi/fdt_ipi_clint.c | 5 ++++- lib/utils/timer/fdt_timer_clint.c | 9 ++++++++- 4 files changed, 30 insertions(+), 22 deletions(-)
include/sbi_utils/fdt/fdt_helper.h +3 -4
@@ -60,10 +60,9 @@ int fdt_parse_plic_node(void *fdt, int nodeoffset, struct plic_data *plic);int fdt_parse_plic (void *fdt,struct plic_data *plic,const char *compat); -struct clint_data ; - -int fdt_parse_clint_node (void *fdt,int nodeoffset,bool for_timer, -struct clint_data *clint); +int fdt_parse_aclint_node (void *fdt,int nodeoffset,bool for_timer, +unsigned long *out_addr,unsigned long *out_size, +u32 *out_first_hartid,u32 *out_hart_count);int fdt_parse_compat_addr (void *fdt,unsigned long *addr,const char *compatible);
lib/utils/fdt/fdt_helper.c +15 -16
@@ -14,7 +14,6 @@#include <sbi/sbi_scratch.h> #include <sbi_utils/fdt/fdt_helper.h> #include <sbi_utils/irqchip/plic.h> -#include <sbi_utils/sys/clint.h> #define DEFAULT_UART_FREQ 0#define DEFAULT_UART_BAUD 115200
@@ -421,8 +420,9 @@ int fdt_parse_plic(void *fdt, struct plic_data *plic, const char *compat)return fdt_parse_plic_node (fdt, nodeoffset, plic); } -int fdt_parse_clint_node (void *fdt,int nodeoffset,bool for_timer, -struct clint_data *clint) +int fdt_parse_aclint_node (void *fdt,int nodeoffset,bool for_timer, +unsigned long *out_addr,unsigned long *out_size, +u32 *out_first_hartid,u32 *out_hart_count) {const fdt32_t *val;unsigned long reg_addr, reg_size;
@@ -430,22 +430,25 @@ int fdt_parse_clint_node(void *fdt, int nodeoffset, bool for_timer,u32 phandle, hwirq, hartid, first_hartid, last_hartid;u32 match_hwirq = (for_timer) ?IRQ_M_TIMER :IRQ_M_SOFT ; -if (nodeoffset <0 || !clint || !fdt) -return SBI_ENODEV ; +if (nodeoffset <0 || !fdt || + !out_addr || !out_size || + !out_first_hartid || !out_hart_count) +return SBI_EINVAL ; rc =fdt_get_node_addr_size (fdt, nodeoffset, ®_addr, ®_size);if (rc <0 || !reg_addr || !reg_size)return SBI_ENODEV ; - clint->addr = reg_addr; + *out_addr = reg_addr; + *out_size = reg_size; val =fdt_getprop (fdt, nodeoffset,"interrupts-extended" , &count);if (!val || count <sizeof (fdt32_t)) -return SBI_EINVAL ; +return SBI_ENODEV ; count = count /sizeof (fdt32_t); first_hartid =-1U ; last_hartid =0 ; - clint->hart_count =0 ; + *out_hart_count =0 ;for (i =0 ; i < count; i +=2 ) { phandle =fdt32_to_cpu (val[i]); hwirq =fdt32_to_cpu (val[i +1 ]);
@@ -470,21 +473,17 @@ int fdt_parse_clint_node(void *fdt, int nodeoffset, bool for_timer, first_hartid = hartid;if (hartid > last_hartid) last_hartid = hartid; - clint->hart_count++; + (*out_hart_count)++; } }if ((last_hartid < first_hartid) || first_hartid ==-1U )return SBI_ENODEV ; - clint->first_hartid = first_hartid; + *out_first_hartid = first_hartid; count = last_hartid - first_hartid +1 ; -if (clint->hart_count < count) - clint->hart_count = count; - - clint->has_64bit_mmio = TRUE; -if (fdt_getprop (fdt, nodeoffset,"clint,has-no-64bit-mmio" , &count)) - clint->has_64bit_mmio = FALSE; +if (*out_hart_count < count) + *out_hart_count = count;return 0 ; }
lib/utils/ipi/fdt_ipi_clint.c +4 -1
@@ -21,15 +21,18 @@ static int ipi_clint_cold_init(void *fdt, int nodeoff, const struct fdt_match *match) {int rc; +unsigned long cisize;struct clint_data *ci;if (CLINT_IPI_MAX_NR <= clint_ipi_count)return SBI_ENOSPC ; ci = &clint_ipi[clint_ipi_count++]; - rc =fdt_parse_clint_node (fdt, nodeoff, FALSE, ci); + rc =fdt_parse_aclint_node (fdt, nodeoff, FALSE, &ci->addr, &cisize, + &ci->first_hartid, &ci->hart_count);if (rc)return rc; + ci->has_64bit_mmio = false;return clint_cold_ipi_init (ci); }
lib/utils/timer/fdt_timer_clint.c +8 -1
@@ -7,6 +7,7 @@* Anup Patel <[email protected]> */ +#include <libfdt.h> #include <sbi/sbi_error.h> #include <sbi_utils/fdt/fdt_helper.h> #include <sbi_utils/timer/fdt_timer.h>
@@ -21,6 +22,7 @@ static int timer_clint_cold_init(void *fdt, int nodeoff, const struct fdt_match *match) {int rc; +unsigned long ctsize;struct clint_data *ct, *ctmaster =NULL ;if (CLINT_TIMER_MAX_NR <= clint_timer_count)
@@ -29,10 +31,15 @@ static int timer_clint_cold_init(void *fdt, int nodeoff,if (1 < clint_timer_count) ctmaster = &clint_timer[0 ]; - rc =fdt_parse_clint_node (fdt, nodeoff, TRUE, ct); + rc =fdt_parse_aclint_node (fdt, nodeoff, TRUE, &ct->addr, &ctsize, + &ct->first_hartid, &ct->hart_count);if (rc)return rc; + ct->has_64bit_mmio = true; +if (fdt_getprop (fdt, nodeoff,"clint,has-no-64bit-mmio" , &rc)) + ct->has_64bit_mmio = FALSE; +return clint_cold_timer_init (ct, ctmaster); }
Signature · 1 line
2.25.1
PATCH 3/6 lib: utils: Add FDT parsing API common for both ACLINT and CLINT
Quoted 2 lines · Anup Patel
We add
fdt_parse_aclint_node()which is can parse both ACLINT and
which can
Quoted 117 lines
CLINT DT nodes. This means
fdt_parse_clint_node()is not required anymore so we remove it as well.Signed-off-by Anup Patel <[email protected]>--- include/sbi_utils/fdt/fdt_helper.h | 7 +++---- lib/utils/fdt/fdt_helper.c | 31 +++++++++++++++--------------- lib/utils/ipi/fdt_ipi_clint.c | 5 ++++- lib/utils/timer/fdt_timer_clint.c | 9 ++++++++- 4 files changed, 30 insertions(+), 22 deletions(-)include/sbi_utils/fdt/fdt_helper.h +3
-4@@ -60,10 +60,9 @@ int fdt_parse_plic_node(void *fdt, int nodeoffset, struct plic_data *plic);int fdt_parse_plic (void *fdt,struct plic_data *plic,const char *compat); -struct clint_data ; - -int fdt_parse_clint_node (void *fdt,int nodeoffset,bool for_timer, -struct clint_data *clint); +int fdt_parse_aclint_node (void *fdt,int nodeoffset,bool for_timer, +unsigned long *out_addr,unsigned long *out_size, +u32 *out_first_hartid,u32 *out_hart_count);int fdt_parse_compat_addr (void *fdt,unsigned long *addr,const char *compatible);lib/utils/fdt/fdt_helper.c +15
-16@@ -14,7 +14,6 @@#include <sbi/sbi_scratch.h> #include <sbi_utils/fdt/fdt_helper.h> #include <sbi_utils/irqchip/plic.h> -#include <sbi_utils/sys/clint.h> #define DEFAULT_UART_FREQ 0#define DEFAULT_UART_BAUD 115200@@ -421,8 +420,9 @@ int fdt_parse_plic(void *fdt, struct plic_data *plic, const char *compat)return fdt_parse_plic_node (fdt, nodeoffset, plic); } -int fdt_parse_clint_node (void *fdt,int nodeoffset,bool for_timer, -struct clint_data *clint) +int fdt_parse_aclint_node (void *fdt,int nodeoffset,bool for_timer, +unsigned long *out_addr,unsigned long *out_size, +u32 *out_first_hartid,u32 *out_hart_count) {const fdt32_t *val;unsigned long reg_addr, reg_size;@@ -430,22 +430,25 @@ int fdt_parse_clint_node(void *fdt, int nodeoffset, bool for_timer,u32 phandle, hwirq, hartid, first_hartid, last_hartid;u32 match_hwirq = (for_timer) ?IRQ_M_TIMER :IRQ_M_SOFT ; -if (nodeoffset <0 || !clint || !fdt) -return SBI_ENODEV ; +if (nodeoffset <0 || !fdt || + !out_addr || !out_size || + !out_first_hartid || !out_hart_count) +return SBI_EINVAL ; rc =fdt_get_node_addr_size (fdt, nodeoffset, ®_addr, ®_size);if (rc <0 || !reg_addr || !reg_size)return SBI_ENODEV ; - clint->addr = reg_addr; + *out_addr = reg_addr; + *out_size = reg_size; val =fdt_getprop (fdt, nodeoffset,"interrupts-extended" , &count);if (!val || count <sizeof (fdt32_t)) -return SBI_EINVAL ; +return SBI_ENODEV ; count = count /sizeof (fdt32_t); first_hartid =-1U ; last_hartid =0 ; - clint->hart_count =0 ; + *out_hart_count =0 ;for (i =0 ; i < count; i +=2 ) { phandle =fdt32_to_cpu (val[i]); hwirq =fdt32_to_cpu (val[i +1 ]);@@ -470,21 +473,17 @@ int fdt_parse_clint_node(void *fdt, int nodeoffset, bool for_timer, first_hartid = hartid;if (hartid > last_hartid) last_hartid = hartid; - clint->hart_count++; + (*out_hart_count)++; } }if ((last_hartid < first_hartid) || first_hartid ==-1U )return SBI_ENODEV ; - clint->first_hartid = first_hartid; + *out_first_hartid = first_hartid; count = last_hartid - first_hartid +1 ; -if (clint->hart_count < count) - clint->hart_count = count; - - clint->has_64bit_mmio = TRUE; -if (fdt_getprop (fdt, nodeoffset,"clint,has-no-64bit-mmio" , &count)) - clint->has_64bit_mmio = FALSE; +if (*out_hart_count < count) + *out_hart_count = count;return 0 ; }lib/utils/ipi/fdt_ipi_clint.c +0
-0@@ -21,15 +21,18 @@ static int ipi_clint_cold_init(void *fdt, int nodeoff, const struct fdt_match *match) {
lib/utils/ipi/fdt_ipi_clint.c static int ipi_clint_cold_init(void *fdt, int nodeoff, · line 31
Quoted 10 lines
lib/utils/ipi/fdt_ipi_clint.c +2
-1int rc; +unsigned long cisize;struct clint_data *ci;if (CLINT_IPI_MAX_NR <= clint_ipi_count)return SBI_ENOSPC ; ci = &clint_ipi[clint_ipi_count++]; - rc =fdt_parse_clint_node (fdt, nodeoff, FALSE, ci); + rc = fdt_parse_aclint_node(fdt, nodeoff, FALSE, &ci->addr, &cisize,
nits: use false
Quoted 28 lines
lib/utils/ipi/fdt_ipi_clint.c +2
-0+ &ci->first_hartid, &ci->hart_count);if (rc)return rc; + ci->has_64bit_mmio = false;return clint_cold_ipi_init (ci); }lib/utils/timer/fdt_timer_clint.c +2
-0@@ -7,6 +7,7 @@* Anup Patel <[email protected]> */ +#include <libfdt.h> #include <sbi/sbi_error.h> #include <sbi_utils/fdt/fdt_helper.h> #include <sbi_utils/timer/fdt_timer.h> @@ -21,6 +22,7 @@ static int timer_clint_cold_init(void *fdt, int nodeoff, const struct fdt_match *match) {int rc; +unsigned long ctsize;struct clint_data *ct, *ctmaster =NULL ;if (CLINT_TIMER_MAX_NR <= clint_timer_count)
lib/utils/timer/fdt_timer_clint.c static int timer_clint_cold_init(void *fdt, int nodeoff, · line 34
Quoted 5 lines
lib/utils/timer/fdt_timer_clint.c +1
-1@@ -29,10 +31,15 @@ static int timer_clint_cold_init(void *fdt, int nodeoff,if (1 < clint_timer_count) ctmaster = &clint_timer[0 ]; - rc =fdt_parse_clint_node (fdt, nodeoff, TRUE, ct); + rc = fdt_parse_aclint_node(fdt, nodeoff, TRUE, &ct->addr, &ctsize,
nits: use true
lib/utils/timer/fdt_timer_clint.c static int timer_clint_cold_init(void *fdt, int nodeoff, · line 41
Quoted 7 lines
lib/utils/timer/fdt_timer_clint.c +4
-0+ &ct->first_hartid, &ct->hart_count);if (rc)return rc; + ct->has_64bit_mmio = true; +if (fdt_getprop (fdt, nodeoff,"clint,has-no-64bit-mmio" , &rc)) + ct->has_64bit_mmio = FALSE;
nits: use false
lib/utils/timer/fdt_timer_clint.c static int timer_clint_cold_init(void *fdt, int nodeoff, · line 45
Quoted 4 lines
lib/utils/timer/fdt_timer_clint.c +1
-0+return clint_cold_timer_init (ct, ctmaster); }
Otherwise,
PATCH 3/6 lib: utils: Add FDT parsing API common for both ACLINT and CLINT
Quoted 6 lines · Bin Meng
Quoted 2 lines · Anup Patel
We add
fdt_parse_aclint_node()which is can parse both ACLINT andwhich can
Okay, will update.
Quoted 122 lines
Quoted 122 lines
CLINT DT nodes. This means
fdt_parse_clint_node()is not required anymore so we remove it as well.Signed-off-by Anup Patel <[email protected]>--- include/sbi_utils/fdt/fdt_helper.h | 7 +++---- lib/utils/fdt/fdt_helper.c | 31 +++++++++++++++--------------- lib/utils/ipi/fdt_ipi_clint.c | 5 ++++- lib/utils/timer/fdt_timer_clint.c | 9 ++++++++- 4 files changed, 30 insertions(+), 22 deletions(-)include/sbi_utils/fdt/fdt_helper.h +3
-4@@ -60,10 +60,9 @@ int fdt_parse_plic_node(void *fdt, int nodeoffset, struct plic_data *plic);int fdt_parse_plic (void *fdt,struct plic_data *plic,const char *compat); -struct clint_data ; - -int fdt_parse_clint_node (void *fdt,int nodeoffset,bool for_timer, -struct clint_data *clint); +int fdt_parse_aclint_node (void *fdt,int nodeoffset,bool for_timer, +unsigned long *out_addr,unsigned long *out_size, +u32 *out_first_hartid,u32 *out_hart_count);int fdt_parse_compat_addr (void *fdt,unsigned long *addr,const char *compatible);lib/utils/fdt/fdt_helper.c +15
-16@@ -14,7 +14,6 @@#include <sbi/sbi_scratch.h> #include <sbi_utils/fdt/fdt_helper.h> #include <sbi_utils/irqchip/plic.h> -#include <sbi_utils/sys/clint.h> #define DEFAULT_UART_FREQ 0#define DEFAULT_UART_BAUD 115200@@ -421,8 +420,9 @@ int fdt_parse_plic(void *fdt, struct plic_data *plic, const char *compat)return fdt_parse_plic_node (fdt, nodeoffset, plic); } -int fdt_parse_clint_node (void *fdt,int nodeoffset,bool for_timer, -struct clint_data *clint) +int fdt_parse_aclint_node (void *fdt,int nodeoffset,bool for_timer, +unsigned long *out_addr,unsigned long *out_size, +u32 *out_first_hartid,u32 *out_hart_count) {const fdt32_t *val;unsigned long reg_addr, reg_size;@@ -430,22 +430,25 @@ int fdt_parse_clint_node(void *fdt, int nodeoffset, bool for_timer,u32 phandle, hwirq, hartid, first_hartid, last_hartid;u32 match_hwirq = (for_timer) ?IRQ_M_TIMER :IRQ_M_SOFT ; -if (nodeoffset <0 || !clint || !fdt) -return SBI_ENODEV ; +if (nodeoffset <0 || !fdt || + !out_addr || !out_size || + !out_first_hartid || !out_hart_count) +return SBI_EINVAL ; rc =fdt_get_node_addr_size (fdt, nodeoffset, ®_addr, ®_size);if (rc <0 || !reg_addr || !reg_size)return SBI_ENODEV ; - clint->addr = reg_addr; + *out_addr = reg_addr; + *out_size = reg_size; val =fdt_getprop (fdt, nodeoffset,"interrupts-extended" , &count);if (!val || count <sizeof (fdt32_t)) -return SBI_EINVAL ; +return SBI_ENODEV ; count = count /sizeof (fdt32_t); first_hartid =-1U ; last_hartid =0 ; - clint->hart_count =0 ; + *out_hart_count =0 ;for (i =0 ; i < count; i +=2 ) { phandle =fdt32_to_cpu (val[i]); hwirq =fdt32_to_cpu (val[i +1 ]);@@ -470,21 +473,17 @@ int fdt_parse_clint_node(void *fdt, int nodeoffset, bool for_timer, first_hartid = hartid;if (hartid > last_hartid) last_hartid = hartid; - clint->hart_count++; + (*out_hart_count)++; } }if ((last_hartid < first_hartid) || first_hartid ==-1U )return SBI_ENODEV ; - clint->first_hartid = first_hartid; + *out_first_hartid = first_hartid; count = last_hartid - first_hartid +1 ; -if (clint->hart_count < count) - clint->hart_count = count; - - clint->has_64bit_mmio = TRUE; -if (fdt_getprop (fdt, nodeoffset,"clint,has-no-64bit-mmio" , &count)) - clint->has_64bit_mmio = FALSE; +if (*out_hart_count < count) + *out_hart_count = count;return 0 ; }lib/utils/ipi/fdt_ipi_clint.c +1
-0@@ -21,15 +21,18 @@ static int ipi_clint_cold_init(void *fdt, int nodeoff, const struct fdt_match *match) {int rc; +unsigned long cisize;struct clint_data *ci;
Quoted 8 lines
lib/utils/ipi/fdt_ipi_clint.c static int ipi_clint_cold_init(void *fdt, int nodeoff, · line 31
Quoted 6 lines
lib/utils/ipi/fdt_ipi_clint.c +1
-1if (CLINT_IPI_MAX_NR <= clint_ipi_count)return SBI_ENOSPC ; ci = &clint_ipi[clint_ipi_count++]; - rc =fdt_parse_clint_node (fdt, nodeoff, FALSE, ci); + rc = fdt_parse_aclint_node(fdt, nodeoff, FALSE, &ci->addr, &cisize,nits: use false
Okay, will update this and others mentioned below.
Quoted 47 lines
Quoted 29 lines
lib/utils/ipi/fdt_ipi_clint.c +2
-0+ &ci->first_hartid, &ci->hart_count);if (rc)return rc; + ci->has_64bit_mmio = false;return clint_cold_ipi_init (ci); }lib/utils/timer/fdt_timer_clint.c +2
-0@@ -7,6 +7,7 @@* Anup Patel <[email protected]> */ +#include <libfdt.h> #include <sbi/sbi_error.h> #include <sbi_utils/fdt/fdt_helper.h> #include <sbi_utils/timer/fdt_timer.h> @@ -21,6 +22,7 @@ static int timer_clint_cold_init(void *fdt, int nodeoff, const struct fdt_match *match) {int rc; +unsigned long ctsize;struct clint_data *ct, *ctmaster =NULL ;if (CLINT_TIMER_MAX_NR <= clint_timer_count)lib/utils/timer/fdt_timer_clint.c static int timer_clint_cold_init(void *fdt, int nodeoff, · line 34
Quoted 5 lines
lib/utils/timer/fdt_timer_clint.c +1
-1@@ -29,10 +31,15 @@ static int timer_clint_cold_init(void *fdt, int nodeoff,if (1 < clint_timer_count) ctmaster = &clint_timer[0 ]; - rc =fdt_parse_clint_node (fdt, nodeoff, TRUE, ct); + rc = fdt_parse_aclint_node(fdt, nodeoff, TRUE, &ct->addr, &ctsize,nits: use true
lib/utils/timer/fdt_timer_clint.c static int timer_clint_cold_init(void *fdt, int nodeoff, · line 41
Quoted 7 lines
lib/utils/timer/fdt_timer_clint.c +4
-0+ &ct->first_hartid, &ct->hart_count);if (rc)return rc; + ct->has_64bit_mmio = true; +if (fdt_getprop (fdt, nodeoff,"clint,has-no-64bit-mmio" , &rc)) + ct->has_64bit_mmio = FALSE;nits: use false
Quoted 7 lines
lib/utils/timer/fdt_timer_clint.c static int timer_clint_cold_init(void *fdt, int nodeoff, · line 45
Quoted 4 lines
lib/utils/timer/fdt_timer_clint.c +1
-0+return clint_cold_timer_init (ct, ctmaster); }Otherwise,
Reviewed-by Bin Meng <[email protected]>
Regards,
Anup
PATCH 3/6 lib: utils: Add FDT parsing API common for both ACLINT and CLINT
In reply to Anup Patel? 2021-06-12???? 21:33 +0530?Anup Patel???
Quoted 5 lines
We add
fdt_parse_aclint_node()which is can parse both ACLINT and CLINT DT nodes. This meansfdt_parse_clint_node()is not required anymore so we remove it as well.Signed-off-by Anup Patel <[email protected]>
look good to me
Quoted 194 lines
---
?include/sbi_utils/fdt/fdt_helper.h |? 7 +++---- ?lib/utils/fdt/fdt_helper.c???????? | 31 +++++++++++++++------------- --
?lib/utils/ipi/fdt_ipi_clint.c????? |? 5 ++++- ?lib/utils/timer/fdt_timer_clint.c? |? 9 ++++++++-
?4 files changed, 30 insertions(+), 22 deletions(-)include/sbi_utils/fdt/fdt_helper.h +0
-0@@ -60,10 +60,9 @@ int fdt_parse_plic_node(void *fdt, int nodeoffset, struct plic_data *plic);?
?intfdt_parse_plic(void *fdt, struct plic_data *plic, const char *compat);
?include/sbi_utils/fdt/fdt_helper.h +2
-4-struct clint_data ; - -int fdt_parse_clint_node (void *fdt,int nodeoffset,bool for_timer, -??????????????????????? struct clint_data *clint); +int fdt_parse_aclint_node (void *fdt,int nodeoffset,bool for_timer, +???????????????????????? unsigned long *out_addr, unsigned long
*out_size,
+???????????????????????? u32*out_first_hartid, u32*out_hart_count);
?
?intfdt_parse_compat_addr(void *fdt, unsigned long *addr, ????????????????????????? const char *compatible);lib/utils/fdt/fdt_helper.c +0
-0@@ -14,7 +14,6 @@?#include <
sbi/sbi_scratch.h>
?#include <sbi_utils/fdt/fdt_helper.h>
?#include <sbi_utils/irqchip/plic.h>
-#include <sbi_utils/sys/clint.h>
?
?#define DEFAULT_UART_FREQ??????????????0
?#define DEFAULT_UART_BAUD??????????????115200lib/utils/fdt/fdt_helper.c +0
-0@@ -421,8 +420,9 @@ int fdt_parse_plic(void *fdt, struct plic_data *plic, const char *compat) ????????return fdt_parse_plic_node(fdt, nodeoffset, plic); ?}?
lib/utils/fdt/fdt_helper.c +2
-2-int fdt_parse_clint_node (void *fdt,int nodeoffset,bool for_timer, -??????????????????????? struct clint_data *clint) +int fdt_parse_aclint_node (void *fdt,int nodeoffset,bool for_timer, +???????????????????????? unsigned long *out_addr, unsigned long
*out_size,
+???????????????????????? u32*out_first_hartid, u32*out_hart_count) ?{
????????constfdt32_t*val;
????????unsigned longreg_addr,reg_size;lib/utils/fdt/fdt_helper.c +0
-0@@ -430,22 +430,25 @@ int fdt_parse_clint_node(void *fdt, int nodeoffset, bool for_timer, ????????u32 phandle, hwirq, hartid, first_hartid, last_hartid; ????????u32 match_hwirq = (for_timer) ? IRQ_M_TIMER : IRQ_M_SOFT;?
-???????if (nodeoffset < 0 || !clint || !fdt)
-???????????????returnSBI_ENODEV;+???????if (nodeoffset < 0 || !fdt || +?????????? !out_addr || !out_size ||+?????????? !out_first_hartid || !out_hart_count) +???????????????return
SBI_EINVAL;
?
????????rc =fdt_get_node_addr_size(fdt, nodeoffset, ®_addr, ®_size);
????????if (rc < 0 || !reg_addr || !reg_size) ????????????????returnSBI_ENODEV;
-???????clint->addr =reg_addr;
+???????*out_addr =reg_addr;
+???????*out_size =reg_size;
?
????????val =fdt_getprop(fdt, nodeoffset, "interrupts-extended", &count);
????????if (!val || count <sizeof(fdt32_t)) -???????????????returnSBI_EINVAL; +???????????????returnSBI_ENODEV;
????????count = count /sizeof(fdt32_t);
?
????????first_hartid = -1U;
????????last_hartid = 0;
-???????clint->hart_count = 0;
+???????*out_hart_count = 0;
????????for (i = 0; i < count; i += 2) { ????????????????phandle =fdt32_to_cpu(val[i]); ????????????????hwirq =fdt32_to_cpu(val[i + 1]);lib/utils/fdt/fdt_helper.c +1
-1@@ -470,21 +473,17 @@ int fdt_parse_clint_node(void *fdt, int nodeoffset, bool for_timer, ????????????????????????????????first_hartid = hartid; ????????????????????????if (hartid > last_hartid) ????????????????????????????????last_hartid = hartid; -???????????????????????clint->hart_count++; +???????????????????????(*out_hart_count)++; ????????????????} ????????}?
????????if ((last_hartid<first_hartid) ||first_hartid== -1U) ????????????????returnSBI_ENODEV;
?
-???????clint->first_hartid =first_hartid; +???????*out_first_hartid =first_hartid;
????????count =last_hartid-first_hartid+ 1; -???????if (clint->hart_count< count) -???????????????clint->hart_count = count;
-
-???????clint->has_64bit_mmio = TRUE;
-???????if (fdt_getprop(fdt, nodeoffset, "clint,has-no-64bit-mmio", &count))
-???????????????clint->has_64bit_mmio = FALSE; +???????if (*out_hart_count< count) +???????????????*out_hart_count = count;
?
????????return 0;
?}lib/utils/ipi/fdt_ipi_clint.c +1
-0@@ -21,15 +21,18 @@ static int ipi_clint_cold_init(void *fdt, int nodeoff, ?????????????????????????????? const struct fdt_match *match) ?{ ????????int rc; +???????unsigned long cisize; ????????struct clint_data *ci;?
????????if (CLINT_IPI_MAX_NR<=clint_ipi_count) ????????????????returnSBI_ENOSPC;
????????ci = &clint_ipi[clint_ipi_count++];
?
-???????rc =fdt_parse_clint_node(fdt, nodeoff, FALSE, ci); +???????rc = fdt_parse_aclint_node(fdt, nodeoff, FALSE,&ci->addr, &cisize,
+?????????????????????????????????&ci->first_hartid, &ci-Quoted 1 line
hart_count);????????if (rc)
????????????????return rc;
+???????ci->has_64bit_mmio = false;
?
????????returnclint_cold_ipi_init(ci);
?}lib/utils/timer/fdt_timer_clint.c +0
-0@@ -7,6 +7,7 @@? *?? Anup Patel <[email protected]>
? */
?
+#include <libfdt.h>
?#include <sbi/sbi_error.h>
?#include <sbi_utils/fdt/fdt_helper.h>
?#include <sbi_utils/timer/fdt_timer.h>lib/utils/timer/fdt_timer_clint.c +1
-0@@ -21,6 +22,7 @@ static int timer_clint_cold_init(void *fdt, int nodeoff, ????????????????????????????????? const struct fdt_match *match) ?{ ????????int rc; +???????unsigned long ctsize; ????????struct clint_data *ct, *ctmaster = NULL;?
????????if (CLINT_TIMER_MAX_NR<=clint_timer_count)lib/utils/timer/fdt_timer_clint.c +0
-0@@ -29,10 +31,15 @@ static int timer_clint_cold_init(void *fdt, int nodeoff, ????????if (1 < clint_timer_count) ????????????????ctmaster = &clint_timer[0];?
-???????rc =fdt_parse_clint_node(fdt, nodeoff, TRUE, ct); +???????rc = fdt_parse_aclint_node(fdt, nodeoff, TRUE,&ct->addr, &ctsize,
+?????????????????????????????????&ct->first_hartid, &ct-Quoted 1 line
hart_count);????????if (rc)
????????????????return rc;
?
+???????ct->has_64bit_mmio = true;
+???????if (fdt_getprop(fdt, nodeoff, "clint,has-no-64bit-mmio", &rc))
+???????????????ct->has_64bit_mmio = FALSE;
+
????????returnclint_cold_timer_init(ct, ctmaster);
?}
?Signature · 1 line
2.25.1
PATCH 4/6 lib: utils/ipi: Add FDT based ACLINT MSWI IPI driver
In reply to Anup PatelWe add a new FDT based ACLINT MSWI IPI driver which works for both CLINT device and standalone ACLINT MSWI device.
--- lib/utils/ipi/fdt_ipi.c | 4 +-- lib/utils/ipi/fdt_ipi_clint.c | 51 -------------------------- lib/utils/ipi/fdt_ipi_mswi.c | 67 +++++++++++++++++++++++++++++++++++ lib/utils/ipi/objects.mk | 2 +- 4 files changed, 70 insertions(+), 54 deletions(-) delete mode 100644 lib/utils/ipi/fdt_ipi_clint.c create mode 100644 lib/utils/ipi/fdt_ipi_mswi.c
lib/utils/ipi/fdt_ipi.c +2 -2
@@ -12,10 +12,10 @@#include <sbi_utils/fdt/fdt_helper.h> #include <sbi_utils/ipi/fdt_ipi.h> -extern struct fdt_ipi fdt_ipi_clint; +extern struct fdt_ipi fdt_ipi_mswi;static struct fdt_ipi *ipi_drivers[] = { - &fdt_ipi_clint + &fdt_ipi_mswi };static struct fdt_ipi dummy = {
lib/utils/ipi/fdt_ipi_clint.c deleted +0 -51
51 lines not on this page · raw message
lib/utils/ipi/fdt_ipi_mswi.c new file +67 -0
67 lines not on this page · raw message
lib/utils/ipi/objects.mk +1 -1
@@ -8,5 +8,5 @@ # libsbiutils-objs-y += ipi/fdt_ipi.o -libsbiutils-objs-y += ipi/fdt_ipi_clint.o +libsbiutils-objs-y += ipi/fdt_ipi_mswi.o libsbiutils-objs-y += ipi/aclint_mswi.o
Signature · 1 line
2.25.1
PATCH 4/6 lib: utils/ipi: Add FDT based ACLINT MSWI IPI driver
Quoted 5 lines · Anup Patel
We add a new FDT based ACLINT MSWI IPI driver which works for both CLINT device and standalone ACLINT MSWI device.
Signed-off-by Anup Patel <[email protected]>
Quoted 9 lines
--- lib/utils/ipi/fdt_ipi.c | 4 +-- lib/utils/ipi/fdt_ipi_clint.c | 51 -------------------------- lib/utils/ipi/fdt_ipi_mswi.c | 67 +++++++++++++++++++++++++++++++++++ lib/utils/ipi/objects.mk | 2 +- 4 files changed, 70 insertions(+), 54 deletions(-) delete mode 100644 lib/utils/ipi/fdt_ipi_clint.c create mode 100644 lib/utils/ipi/fdt_ipi_mswi.c
PATCH 4/6 lib: utils/ipi: Add FDT based ACLINT MSWI IPI driver
In reply to Anup Patel? 2021-06-12???? 21:33 +0530?Anup Patel???
Quoted 4 lines
We add a new FDT based ACLINT MSWI IPI driver which works for both CLINT device and standalone ACLINT MSWI device.
Signed-off-by Anup Patel <[email protected]>
look good to me
Quoted 178 lines
---
?lib/utils/ipi/fdt_ipi.c?????? |? 4 +-- ?lib/utils/ipi/fdt_ipi_clint.c | 51 -------------------------- ?lib/utils/ipi/fdt_ipi_mswi.c? | 67+++++++++++++++++++++++++++++++++++
?lib/utils/ipi/objects.mk????? |? 2 +-
?4 files changed, 70 insertions(+), 54 deletions(-) ?delete mode 100644lib/utils/ipi/fdt_ipi_clint.c?create mode 100644lib/utils/ipi/fdt_ipi_mswi.clib/utils/ipi/fdt_ipi.c +0
-0@@ -12,10 +12,10 @@?#include <
sbi_utils/fdt/fdt_helper.h>
?#include <sbi_utils/ipi/fdt_ipi.h>
?lib/utils/ipi/fdt_ipi.c +1
-1-extern struct fdt_ipi fdt_ipi_clint; +extern struct fdt_ipi fdt_ipi_mswi;?
?static structfdt_ipi*ipi_drivers[] = {
-???????&fdt_ipi_clint
+???????&fdt_ipi_mswi
?};
?
?static structfdt_ipidummy = {lib/utils/ipi/fdt_ipi_clint.c deleted +0
-31@@ -1,51 +0,0 @@ -/* -* SPDX-License-Identifier: BSD-2-Clause -* -* Copyright (c) 2020 Western Digital Corporation or its affiliates. -* -* Authors: -*?? Anup Patel <[email protected]> -*/ - -#include <sbi/sbi_error.h> -#include <sbi_utils/fdt/fdt_helper.h> -#include <sbi_utils/ipi/fdt_ipi.h> -#include <sbi_utils/sys/clint.h> - -#define CLINT_IPI_MAX_NR ???????????????????????16 - -static unsigned long clint_ipi_count =0 ; -static struct clint_data clint_ipi[CLINT_IPI_MAX_NR ]; - -static int ipi_clint_cold_init (void *fdt,int nodeoff, -????????????????????????????? const struct fdt_match *match) -{ -???????int rc; -???????unsigned long cisize; -???????struct clint_data *ci; - -???????if (CLINT_IPI_MAX_NR <= clint_ipi_count) -???????????????return SBI_ENOSPC; -???????ci = &clint_ipi[clint_ipi_count++]; - -???????rc = fdt_parse_aclint_node(fdt, nodeoff, FALSE, &ci->addr,&cisize,
-?????????????????????????????????&ci->first_hartid, &ci-Quoted 1 line
hart_count);-???????if (rc)
-???????????????return rc;
-???????ci->has_64bit_mmio = false;lib/utils/ipi/fdt_ipi_clint.c deleted +0
-16- -???????return clint_cold_ipi_init(ci); -} - -static const struct fdt_match ipi_clint_match[] = { -???????{ .compatible = "riscv,clint0" }, -???????{ .compatible = "sifive,clint0" }, -???????{ }, -}; - -struct fdt_ipi fdt_ipi_clint = { -???????.match_table = ipi_clint_match, -???????.cold_init = ipi_clint_cold_init, -???????.warm_init = clint_warm_ipi_init, -???????.exit = NULL, -};lib/utils/ipi/fdt_ipi_mswi.c new file +31
-0@@ -0,0 +1,67 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2021 Western Digital Corporation or its affiliates. +* +* Authors: +*?? Anup Patel <[email protected]> +*/ + +#include <sbi/sbi_error.h> +#include <sbi_utils/fdt/fdt_helper.h> +#include <sbi_utils/ipi/fdt_ipi.h> +#include <sbi_utils/ipi/aclint_mswi.h> + +#define MSWI_MAX_NR ????????????????????16 + +static unsigned long mswi_count =0 ; +static struct aclint_mswi_data mswi[MSWI_MAX_NR ]; + +static int ipi_mswi_cold_init (void *fdt,int nodeoff, +???????????????????????????? const struct fdt_match *match) +{ +???????int rc; +???????unsigned long offset; +???????struct aclint_mswi_data *ms; + +???????if (MSWI_MAX_NR <= mswi_count) +???????????????return SBI_ENOSPC; +???????ms = &mswi[mswi_count]; + +???????rc = fdt_parse_aclint_node(fdt, nodeoff, FALSE, &ms->addr,
&ms->size,
+?????????????????????????????????&ms->first_hartid, &ms-Quoted 1 line
hart_count);+???????if (rc)
+???????????????return rc;lib/utils/ipi/fdt_ipi_mswi.c new file +33
-0+ +???????if (match->data) { +???????????????/* Adjust MSWI address and size for CLINT device */ +???????????????offset = *((unsigned long *)match->data); +???????????????ms->addr += offset; +???????????????if ((ms->size - offset) < ACLINT_MSWI_SIZE) +???????????????????????return SBI_EINVAL; +???????????????ms->size = ACLINT_MSWI_SIZE; +???????} + +???????rc = aclint_mswi_cold_init(ms); +???????if (rc) +???????????????return rc; + +???????mswi_count++; +???????return 0; +} + +static unsigned long clint_offset =CLINT_MSWI_OFFSET ; + +static const struct fdt_match ipi_mswi_match[] = { +???????{ .compatible = "riscv,clint0", .data = &clint_offset }, +???????{ .compatible = "sifive,clint0", .data = &clint_offset }, +???????{ .compatible = "riscv,aclint-mswi" }, +???????{ }, +}; + +struct fdt_ipi fdt_ipi_mswi = { +???????.match_table = ipi_mswi_match, +???????.cold_init = ipi_mswi_cold_init, +???????.warm_init = aclint_mswi_warm_init, +???????.exit = NULL, +};lib/utils/ipi/objects.mk +0
-0@@ -8,5 +8,5 @@?#
?
?libsbiutils-objs-y +=ipi/fdt_ipi.olib/utils/ipi/objects.mk +1
-1-libsbiutils-objs-y += ipi/fdt_ipi_clint.o +libsbiutils-objs-y += ipi/fdt_ipi_mswi.o?libsbiutils-objs-y +=
ipi/aclint_mswi.oSignature · 1 line
2.25.1
PATCH 5/6 lib: utils/timer: Add FDT based ACLINT MTIMER driver
In reply to Anup PatelWe add a new FDT based ACLINT MTIMER driver which works for both CLINT device and standalone ACLINT MTIMER device.
--- lib/utils/timer/fdt_timer.c | 4 +- lib/utils/timer/fdt_timer_clint.c | 57 ----------------------- lib/utils/timer/fdt_timer_mtimer.c | 74 ++++++++++++++++++++++++++++++ lib/utils/timer/objects.mk | 2 +- 4 files changed, 77 insertions(+), 60 deletions(-) delete mode 100644 lib/utils/timer/fdt_timer_clint.c create mode 100644 lib/utils/timer/fdt_timer_mtimer.c
lib/utils/timer/fdt_timer.c +2 -2
@@ -12,10 +12,10 @@#include <sbi_utils/fdt/fdt_helper.h> #include <sbi_utils/timer/fdt_timer.h> -extern struct fdt_timer fdt_timer_clint; +extern struct fdt_timer fdt_timer_mtimer;static struct fdt_timer *timer_drivers[] = { - &fdt_timer_clint + &fdt_timer_mtimer };static struct fdt_timer dummy = {
lib/utils/timer/fdt_timer_clint.c deleted +0 -57
57 lines not on this page · raw message
lib/utils/timer/fdt_timer_mtimer.c new file +74 -0
74 lines not on this page · raw message
lib/utils/timer/objects.mk +1 -1
@@ -8,5 +8,5 @@ # libsbiutils-objs-y += timer/fdt_timer.o -libsbiutils-objs-y += timer/fdt_timer_clint.o +libsbiutils-objs-y += timer/fdt_timer_mtimer.o libsbiutils-objs-y += timer/aclint_mtimer.o
Signature · 1 line
2.25.1
PATCH 5/6 lib: utils/timer: Add FDT based ACLINT MTIMER driver
Quoted 5 lines · Anup Patel
We add a new FDT based ACLINT MTIMER driver which works for both CLINT device and standalone ACLINT MTIMER device.
Signed-off-by Anup Patel <[email protected]>
Quoted 9 lines
--- lib/utils/timer/fdt_timer.c | 4 +- lib/utils/timer/fdt_timer_clint.c | 57 ----------------------- lib/utils/timer/fdt_timer_mtimer.c | 74 ++++++++++++++++++++++++++++++ lib/utils/timer/objects.mk | 2 +- 4 files changed, 77 insertions(+), 60 deletions(-) delete mode 100644 lib/utils/timer/fdt_timer_clint.c create mode 100644 lib/utils/timer/fdt_timer_mtimer.c
PATCH 5/6 lib: utils/timer: Add FDT based ACLINT MTIMER driver
In reply to Anup Patel? 2021-06-12???? 21:33 +0530?Anup Patel???
Quoted 4 lines
We add a new FDT based ACLINT MTIMER driver which works for both CLINT device and standalone ACLINT MTIMER device.
Signed-off-by Anup Patel <[email protected]>
look good to me
Quoted 194 lines
---
?lib/utils/timer/fdt_timer.c??????? |? 4 +- ?lib/utils/timer/fdt_timer_clint.c? | 57 ----------------------- ?lib/utils/timer/fdt_timer_mtimer.c | 74++++++++++++++++++++++++++++++
?lib/utils/timer/objects.mk???????? |? 2 +- ?4 files changed, 77 insertions(+), 60 deletions(-) ?delete mode 100644lib/utils/timer/fdt_timer_clint.c?create mode 100644lib/utils/timer/fdt_timer_mtimer.clib/utils/timer/fdt_timer.c +0
-0@@ -12,10 +12,10 @@?#include <
sbi_utils/fdt/fdt_helper.h>
?#include <sbi_utils/timer/fdt_timer.h>
?lib/utils/timer/fdt_timer.c +1
-1-extern struct fdt_timer fdt_timer_clint; +extern struct fdt_timer fdt_timer_mtimer;?
?static structfdt_timer*timer_drivers[] = {
-???????&fdt_timer_clint
+???????&fdt_timer_mtimer
?};
?
?static structfdt_timerdummy = {lib/utils/timer/fdt_timer_clint.c deleted +0
-34@@ -1,57 +0,0 @@ -/* -* SPDX-License-Identifier: BSD-2-Clause -* -* Copyright (c) 2020 Western Digital Corporation or its affiliates. -* -* Authors: -*?? Anup Patel <[email protected]> -*/ - -#include <libfdt.h> -#include <sbi/sbi_error.h> -#include <sbi_utils/fdt/fdt_helper.h> -#include <sbi_utils/timer/fdt_timer.h> -#include <sbi_utils/sys/clint.h> - -#define CLINT_TIMER_MAX_NR ?????????????????????16 - -static unsigned long clint_timer_count =0 ; -static struct clint_data clint_timer[CLINT_TIMER_MAX_NR ]; - -static int timer_clint_cold_init (void *fdt,int nodeoff, -???????????????????????????????? const struct fdt_match *match) -{ -???????int rc; -???????unsigned long ctsize; -???????struct clint_data *ct, *ctmaster = NULL; - -???????if (CLINT_TIMER_MAX_NR <= clint_timer_count) -???????????????return SBI_ENOSPC; -???????ct = &clint_timer[clint_timer_count++]; -???????if (1 < clint_timer_count) -???????????????ctmaster = &clint_timer[0]; - -???????rc = fdt_parse_aclint_node(fdt, nodeoff, TRUE, &ct->addr,&ctsize,
-?????????????????????????????????&ct->first_hartid, &ct-Quoted 1 line
hart_count);-???????if (rc)
-???????????????return rc;
-
-???????ct->has_64bit_mmio = true;
-???????if (fdt_getprop(fdt, nodeoff, "clint,has-no-64bit-mmio", &rc))
-???????????????ct->has_64bit_mmio = FALSE;lib/utils/timer/fdt_timer_clint.c deleted +0
-16- -???????return clint_cold_timer_init(ct, ctmaster); -} - -static const struct fdt_match timer_clint_match[] = { -???????{ .compatible = "riscv,clint0" }, -???????{ .compatible = "sifive,clint0" }, -???????{ }, -}; - -struct fdt_timer fdt_timer_clint = { -???????.match_table = timer_clint_match, -???????.cold_init = timer_clint_cold_init, -???????.warm_init = clint_warm_timer_init, -???????.exit = NULL, -};lib/utils/timer/fdt_timer_mtimer.c new file +34
-0@@ -0,0 +1,74 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2020 Western Digital Corporation or its affiliates. +* +* Authors: +*?? Anup Patel <[email protected]> +*/ + +#include <libfdt.h> +#include <sbi/sbi_error.h> +#include <sbi_utils/fdt/fdt_helper.h> +#include <sbi_utils/timer/fdt_timer.h> +#include <sbi_utils/timer/aclint_mtimer.h> + +#define MTIMER_MAX_NR ??????????????????16 + +static unsigned long mtimer_count =0 ; +static struct aclint_mtimer_data mtimer[MTIMER_MAX_NR ]; + +static int timer_mtimer_cold_init (void *fdt,int nodeoff, +???????????????????????????????? const struct fdt_match *match) +{ +???????int rc; +???????unsigned long offset; +???????struct aclint_mtimer_data *mt, *mtmaster = NULL; + +???????if (MTIMER_MAX_NR <= mtimer_count) +???????????????return SBI_ENOSPC; +???????mt = &mtimer[mtimer_count]; +???????if (0 < mtimer_count) +???????????????mtmaster = &mtimer[0]; + +???????rc = fdt_parse_aclint_node(fdt, nodeoff, TRUE, &mt->addr,
&mt->size,
+?????????????????????????????????&mt->first_hartid, &mt-Quoted 1 line
hart_count);+???????if (rc)
+???????????????return rc;
+???????mt->has_64bit_mmio = true;
+
+???????if (match->data) {
+???????????????/* Adjust MTIMER address and size for CLINT device */ +???????????????offset = *((unsigned long *)match->data); +???????????????mt->addr += offset;
+???????????????if ((mt->size- offset) <ACLINT_MTIMER_SIZE) +???????????????????????returnSBI_EINVAL; +???????????????mt->size -= offset;
+???????????????/* Parse additional CLINT properties */ +???????????????if (fdt_getprop(fdt, nodeoff, "clint,has-no-64bit- mmio", &rc))
+???????????????????????mt->has_64bit_mmio = false; +???????}lib/utils/timer/fdt_timer_mtimer.c new file +24
-0+ +???????rc = aclint_mtimer_cold_init(mt, mtmaster); +???????if (rc) +???????????????return rc; + +???????mtimer_count++; +???????return 0; +} + +static unsigned long clint_offset =CLINT_MTIMER_OFFSET ; + +static const struct fdt_match timer_mtimer_match[] = { +???????{ .compatible = "riscv,clint0", .data = &clint_offset }, +???????{ .compatible = "sifive,clint0", .data = &clint_offset }, +???????{ .compatible = "riscv,aclint-mtimer" }, +???????{ }, +}; + +struct fdt_timer fdt_timer_mtimer = { +???????.match_table = timer_mtimer_match, +???????.cold_init = timer_mtimer_cold_init, +???????.warm_init = aclint_mtimer_warm_init, +???????.exit = NULL, +};lib/utils/timer/objects.mk +0
-0@@ -8,5 +8,5 @@?#
?
?libsbiutils-objs-y +=timer/fdt_timer.olib/utils/timer/objects.mk +1
-1-libsbiutils-objs-y += timer/fdt_timer_clint.o +libsbiutils-objs-y += timer/fdt_timer_mtimer.o?libsbiutils-objs-y +=
timer/aclint_mtimer.oSignature · 1 line
2.25.1
PATCH 6/6 platform: Replace CLINT library usage with ACLINT library
In reply to Anup PatelThe ACLINT devices are backward compatible with SiFive CLINT so we replace all CLINT library usage in various platforms with ACLINT library. As a result of this replacement, the CLINT library is not used by any part of OpenSBI hence we remove it.
--- include/sbi_utils/sys/clint.h | 41 ----- lib/utils/sys/clint.c | 256 ----------------------------- lib/utils/sys/objects.mk | 1 - platform/fpga/ariane/platform.c | 26 ++- platform/fpga/openpiton/platform.c | 32 +++- platform/kendryte/k210/platform.c | 23 ++- platform/kendryte/k210/platform.h | 3 + platform/nuclei/ux600/platform.c | 27 ++- platform/template/platform.c | 30 +++- 9 files changed, 102 insertions(+), 337 deletions(-) delete mode 100644 include/sbi_utils/sys/clint.h delete mode 100644 lib/utils/sys/clint.c
include/sbi_utils/sys/clint.h deleted +0 -41
@@ -1,41 +0,0 @@ -/* -* SPDX-License-Identifier: BSD-2-Clause -* -* Copyright (c) 2019 Western Digital Corporation or its affiliates. -* -* Authors: -* Anup Patel <[email protected]> -*/ - -#ifndef __SYS_CLINT_H__ -#define __SYS_CLINT_H__ - -#include <sbi/sbi_types.h> - -struct clint_data { -/* Public details */ -unsigned long addr; -u32 first_hartid; -u32 hart_count; -bool has_64bit_mmio; -/* Private details (initialized and used by CLINT library)*/ -u32 *ipi; -struct clint_data *time_delta_reference; -unsigned long time_delta_computed; -u64 time_delta; -u64 *time_val; -u64 *time_cmp; -u64 (*time_rd)(volatile u64 *addr); -void (*time_wr)(u64 value,volatile u64 *addr); -}; - -int clint_warm_ipi_init (void ); - -int clint_cold_ipi_init (struct clint_data *clint); - -int clint_warm_timer_init (void ); - -int clint_cold_timer_init (struct clint_data *clint, -struct clint_data *reference); - -#endif
lib/utils/sys/clint.c deleted +0 -256
256 lines not on this page · raw message
lib/utils/sys/objects.mk +0 -1
@@ -7,6 +7,5 @@ # Anup Patel <[email protected]> # -libsbiutils-objs-y += sys/clint.o libsbiutils-objs-y += sys/htif.o libsbiutils-objs-y += sys/sifive_test.o
platform/fpga/ariane/platform.c +19 -7
@@ -12,9 +12,10 @@#include <sbi/sbi_hart.h> #include <sbi/sbi_platform.h> #include <sbi_utils/fdt/fdt_fixup.h> +#include <sbi_utils/ipi/aclint_mswi.h> #include <sbi_utils/irqchip/plic.h> #include <sbi_utils/serial/uart8250.h> -#include <sbi_utils/sys/clint.h> +#include <sbi_utils/timer/aclint_mtimer.h> #define ARIANE_UART_ADDR 0x10000000#define ARIANE_UART_FREQ 50000000
@@ -25,14 +26,25 @@#define ARIANE_PLIC_NUM_SOURCES 3#define ARIANE_HART_COUNT 1#define ARIANE_CLINT_ADDR 0x2000000 +#define ARIANE_ACLINT_MSWI_ADDR ARIANE_CLINT_ADDR +#define ARIANE_ACLINT_MTIMER_ADDR (ARIANE_CLINT_ADDR + \ + CLINT_MTIMER_OFFSET)static struct plic_data plic = { .addr =ARIANE_PLIC_ADDR , .num_src =ARIANE_PLIC_NUM_SOURCES , }; -static struct clint_data clint = { - .addr =ARIANE_CLINT_ADDR , +static struct aclint_mswi_data mswi = { + .addr =ARIANE_ACLINT_MSWI_ADDR , + .size =ACLINT_MSWI_SIZE , + .first_hartid =0 , + .hart_count =ARIANE_HART_COUNT , +}; + +static struct aclint_mtimer_data mtimer = { + .addr =ARIANE_ACLINT_MTIMER_ADDR , + .size =ACLINT_MTIMER_SIZE , .first_hartid =0 , .hart_count =ARIANE_HART_COUNT , .has_64bit_mmio = TRUE,
@@ -123,12 +135,12 @@ static int ariane_ipi_init(bool cold_boot)int ret;if (cold_boot) { - ret =clint_cold_ipi_init (&clint); + ret =aclint_mswi_cold_init (&mswi);if (ret)return ret; } -return clint_warm_ipi_init (); +return aclint_mswi_warm_init (); }/*
@@ -139,12 +151,12 @@ static int ariane_timer_init(bool cold_boot)int ret;if (cold_boot) { - ret =clint_cold_timer_init (&clint,NULL ); + ret =aclint_mtimer_cold_init (&mtimer,NULL );if (ret)return ret; } -return clint_warm_timer_init (); +return aclint_mtimer_warm_init (); }/*
platform/fpga/openpiton/platform.c +23 -9
@@ -12,9 +12,10 @@#include <sbi/sbi_platform.h> #include <sbi_utils/fdt/fdt_helper.h> #include <sbi_utils/fdt/fdt_fixup.h> +#include <sbi_utils/ipi/aclint_mswi.h> #include <sbi_utils/irqchip/plic.h> #include <sbi_utils/serial/uart8250.h> -#include <sbi_utils/sys/clint.h> +#include <sbi_utils/timer/aclint_mtimer.h> #define OPENPITON_DEFAULT_UART_ADDR 0xfff0c2c000#define OPENPITON_DEFAULT_UART_FREQ 60000000
@@ -25,6 +26,9 @@#define OPENPITON_DEFAULT_PLIC_NUM_SOURCES 2#define OPENPITON_DEFAULT_HART_COUNT 3#define OPENPITON_DEFAULT_CLINT_ADDR 0xfff1020000 +#define OPENPITON_DEFAULT_ACLINT_MSWI_ADDR OPENPITON_DEFAULT_CLINT_ADDR +#define OPENPITON_DEFAULT_ACLINT_MTIMER_ADDR \ + (OPENPITON_DEFAULT_CLINT_ADDR + CLINT_MTIMER_OFFSET)static struct platform_uart_data uart = {OPENPITON_DEFAULT_UART_ADDR ,
@@ -36,8 +40,16 @@ static struct plic_data plic = { .num_src = OPENPITON_DEFAULT_PLIC_NUM_SOURCES, }; -static struct clint_data clint = { - .addr =OPENPITON_DEFAULT_CLINT_ADDR , +static struct aclint_mswi_data mswi = { + .addr =OPENPITON_DEFAULT_ACLINT_MSWI_ADDR , + .size =ACLINT_MSWI_SIZE , + .first_hartid =0 , + .hart_count =OPENPITON_DEFAULT_HART_COUNT , +}; + +static struct aclint_mtimer_data mtimer = { + .addr =OPENPITON_DEFAULT_ACLINT_MTIMER_ADDR , + .size =ACLINT_MTIMER_SIZE , .first_hartid =0 , .hart_count =OPENPITON_DEFAULT_HART_COUNT , .has_64bit_mmio = TRUE,
@@ -67,8 +79,10 @@ static int openpiton_early_init(bool cold_boot) plic = plic_data; rc =fdt_parse_compat_addr (fdt, &clint_addr,"riscv,clint0" ); -if (!rc) - clint.addr = clint_addr; +if (!rc) { + mswi.addr = clint_addr; + mtimer.addr = clint_addr +CLINT_MTIMER_OFFSET ; + }return 0 ; }
@@ -149,12 +163,12 @@ static int openpiton_ipi_init(bool cold_boot)int ret;if (cold_boot) { - ret =clint_cold_ipi_init (&clint); + ret =aclint_mswi_cold_init (&mswi);if (ret)return ret; } -return clint_warm_ipi_init (); +return aclint_mswi_warm_init (); }/*
@@ -165,12 +179,12 @@ static int openpiton_timer_init(bool cold_boot)int ret;if (cold_boot) { - ret =clint_cold_timer_init (&clint,NULL ); + ret =aclint_mtimer_cold_init (&mtimer,NULL );if (ret)return ret; } -return clint_warm_timer_init (); +return aclint_mtimer_warm_init (); }/*
platform/kendryte/k210/platform.c +16 -7
@@ -14,9 +14,10 @@#include <sbi/sbi_platform.h> #include <sbi/sbi_system.h> #include <sbi_utils/fdt/fdt_fixup.h> +#include <sbi_utils/ipi/aclint_mswi.h> #include <sbi_utils/irqchip/plic.h> #include <sbi_utils/serial/sifive-uart.h> -#include <sbi_utils/sys/clint.h> +#include <sbi_utils/timer/aclint_mtimer.h> #include "platform.h" extern const char dt_k210_start[];
@@ -33,8 +34,16 @@ static struct plic_data plic = { .num_src = K210_PLIC_NUM_SOURCES, }; -static struct clint_data clint = { - .addr =K210_CLINT_BASE_ADDR , +static struct aclint_mswi_data mswi = { + .addr =K210_ACLINT_MSWI_ADDR , + .size =ACLINT_MSWI_SIZE , + .first_hartid =0 , + .hart_count =K210_HART_COUNT , +}; + +static struct aclint_mtimer_data mtimer = { + .addr =K210_ACLINT_MTIMER_ADDR , + .size =ACLINT_MTIMER_SIZE , .first_hartid =0 , .hart_count =K210_HART_COUNT , .has_64bit_mmio = TRUE,
@@ -139,12 +148,12 @@ static int k210_ipi_init(bool cold_boot)int rc;if (cold_boot) { - rc =clint_cold_ipi_init (&clint); + rc =aclint_mswi_cold_init (&mswi);if (rc)return rc; } -return clint_warm_ipi_init (); +return aclint_mswi_warm_init (); }static int k210_timer_init (bool cold_boot)
@@ -152,12 +161,12 @@ static int k210_timer_init(bool cold_boot)int rc;if (cold_boot) { - rc =clint_cold_timer_init (&clint,NULL ); + rc =aclint_mtimer_cold_init (&mtimer,NULL );if (rc)return rc; } -return clint_warm_timer_init (); +return aclint_mtimer_warm_init (); }const struct sbi_platform_operations platform_ops = {
platform/kendryte/k210/platform.h +3 -0
@@ -22,6 +22,9 @@#define K210_SYSCTL_BASE_ADDR 0x50440000ULL#define K210_UART_BASE_ADDR 0x38000000ULL#define K210_CLINT_BASE_ADDR 0x02000000ULL +#define K210_ACLINT_MSWI_ADDR K210_CLINT_BASE_ADDR +#define K210_ACLINT_MTIMER_ADDR \ + (K210_CLINT_BASE_ADDR + CLINT_MTIMER_OFFSET)#define K210_PLIC_BASE_ADDR 0x0C000000ULL/* Registers */
platform/nuclei/ux600/platform.c +20 -7
@@ -17,9 +17,10 @@#include <sbi/sbi_platform.h> #include <sbi/sbi_system.h> #include <sbi_utils/fdt/fdt_fixup.h> +#include <sbi_utils/ipi/aclint_mswi.h> #include <sbi_utils/irqchip/plic.h> #include <sbi_utils/serial/sifive-uart.h> -#include <sbi_utils/sys/clint.h> +#include <sbi_utils/timer/aclint_mtimer.h> /* clang-format off */
@@ -32,6 +33,9 @@#define UX600_NUCLEI_TIMER_MSFTRST_KEY 0x80000A5F/* The clint compatiable timer offset is 0x1000 against nuclei timer */ #define UX600_CLINT_TIMER_ADDR (UX600_NUCLEI_TIMER_ADDR + 0x1000) +#define UX600_ACLINT_MSWI_ADDR UX600_CLINT_TIMER_ADDR +#define UX600_ACLINT_MTIMER_ADDR (UX600_CLINT_TIMER_ADDR + \ + CLINT_MTIMER_OFFSET)#define UX600_PLIC_ADDR 0x8000000#define UX600_PLIC_NUM_SOURCES 0x35
@@ -61,12 +65,21 @@ static struct plic_data plic = { .num_src = UX600_PLIC_NUM_SOURCES, }; -static struct clint_data clint = { - .addr =UX600_CLINT_TIMER_ADDR , +static struct aclint_mswi_data mswi = { + .addr =UX600_ACLINT_MSWI_ADDR , + .size =ACLINT_MSWI_SIZE , + .first_hartid =0 , + .hart_count =UX600_HART_COUNT , +}; + +static struct aclint_mtimer_data mtimer = { + .addr =UX600_ACLINT_MTIMER_ADDR , + .size =ACLINT_MTIMER_SIZE , .first_hartid =0 , .hart_count =UX600_HART_COUNT , .has_64bit_mmio = TRUE, }; +static u32 measure_cpu_freq (u32 n) {u32 start_mtime, delta_mtime;
@@ -188,12 +201,12 @@ static int ux600_ipi_init(bool cold_boot)int rc;if (cold_boot) { - rc =clint_cold_ipi_init (&clint); + rc =aclint_mswi_cold_init (&mswi);if (rc)return rc; } -return clint_warm_ipi_init (); +return aclint_mswi_warm_init (); }static int ux600_timer_init (bool cold_boot)
@@ -201,12 +214,12 @@ static int ux600_timer_init(bool cold_boot)int rc;if (cold_boot) { - rc =clint_cold_timer_init (&clint,NULL ); + rc =aclint_mtimer_cold_init (&mtimer,NULL );if (rc)return rc; } -return clint_warm_timer_init (); +return aclint_mtimer_warm_init (); }const struct sbi_platform_operations platform_ops = {
platform/template/platform.c +21 -9
@@ -13,14 +13,18 @@* Include these files as needed. * See config.mk PLATFORM_xxx configuration parameters. */ +#include <sbi_utils/ipi/aclint_mswi.h> #include <sbi_utils/irqchip/plic.h> #include <sbi_utils/serial/uart8250.h> -#include <sbi_utils/sys/clint.h> +#include <sbi_utils/timer/aclint_mtimer.h> #define PLATFORM_PLIC_ADDR 0xc000000#define PLATFORM_PLIC_NUM_SOURCES 128#define PLATFORM_HART_COUNT 4#define PLATFORM_CLINT_ADDR 0x2000000 +#define PLATFORM_ACLINT_MSWI_ADDR PLATFORM_CLINT_ADDR +#define PLATFORM_ACLINT_MTIMER_ADDR (PLATFORM_CLINT_ADDR + \ + CLINT_MTIMER_OFFSET)#define PLATFORM_UART_ADDR 0x09000000#define PLATFORM_UART_INPUT_FREQ 10000000#define PLATFORM_UART_BAUDRATE 115200
@@ -30,8 +34,16 @@ static struct plic_data plic = { .num_src = PLATFORM_PLIC_NUM_SOURCES, }; -static struct clint_data clint = { - .addr =PLATFORM_CLINT_ADDR , +static struct aclint_mswi_data mswi = { + .addr =PLATFORM_ACLINT_MSWI_ADDR , + .size =ACLINT_MSWI_SIZE , + .first_hartid =0 , + .hart_count =PLATFORM_HART_COUNT , +}; + +static struct aclint_mtimer_data mtimer = { + .addr =PLATFORM_ACLINT_MTIMER_ADDR , + .size =ACLINT_MTIMER_SIZE , .first_hartid =0 , .hart_count =PLATFORM_HART_COUNT , .has_64bit_mmio = TRUE,
@@ -88,14 +100,14 @@ static int platform_ipi_init(bool cold_boot) {int ret; -/* Example if the generic CLINT driver is used */ +/* Example if the generic ACLINT driver is used */ if (cold_boot) { - ret =clint_cold_ipi_init (&clint); + ret =aclint_mswi_cold_init (&mswi);if (ret)return ret; } -return clint_warm_ipi_init (); +return aclint_mswi_warm_init (); }/*
@@ -105,14 +117,14 @@ static int platform_timer_init(bool cold_boot) {int ret; -/* Example if the generic CLINT driver is used */ +/* Example if the generic ACLINT driver is used */ if (cold_boot) { - ret =clint_cold_timer_init (&clint,NULL ); + ret =aclint_mtimer_cold_init (&mtimer,NULL );if (ret)return ret; } -return clint_warm_timer_init (); +return aclint_mtimer_warm_init (); }/*
Signature · 1 line
2.25.1
PATCH 6/6 platform: Replace CLINT library usage with ACLINT library
Quoted 359 lines · Anup Patel
The ACLINT devices are backward compatible with SiFive CLINT so we replace all CLINT library usage in various platforms with ACLINT library. As a result of this replacement, the CLINT library is not used by any part of OpenSBI hence we remove it.
Signed-off-by Anup Patel <[email protected]>--- include/sbi_utils/sys/clint.h | 41 ----- lib/utils/sys/clint.c | 256 ----------------------------- lib/utils/sys/objects.mk | 1 - platform/fpga/ariane/platform.c | 26 ++- platform/fpga/openpiton/platform.c | 32 +++- platform/kendryte/k210/platform.c | 23 ++- platform/kendryte/k210/platform.h | 3 + platform/nuclei/ux600/platform.c | 27 ++- platform/template/platform.c | 30 +++- 9 files changed, 102 insertions(+), 337 deletions(-) delete mode 100644 include/sbi_utils/sys/clint.h delete mode 100644 lib/utils/sys/clint.cinclude/sbi_utils/sys/clint.h deleted +0
-41@@ -1,41 +0,0 @@ -/* -* SPDX-License-Identifier: BSD-2-Clause -* -* Copyright (c) 2019 Western Digital Corporation or its affiliates. -* -* Authors: -* Anup Patel <[email protected]> -*/ - -#ifndef __SYS_CLINT_H__ -#define __SYS_CLINT_H__ - -#include <sbi/sbi_types.h> - -struct clint_data { -/* Public details */ -unsigned long addr; -u32 first_hartid; -u32 hart_count; -bool has_64bit_mmio; -/* Private details (initialized and used by CLINT library)*/ -u32 *ipi; -struct clint_data *time_delta_reference; -unsigned long time_delta_computed; -u64 time_delta; -u64 *time_val; -u64 *time_cmp; -u64 (*time_rd)(volatile u64 *addr); -void (*time_wr)(u64 value,volatile u64 *addr); -}; - -int clint_warm_ipi_init (void ); - -int clint_cold_ipi_init (struct clint_data *clint); - -int clint_warm_timer_init (void ); - -int clint_cold_timer_init (struct clint_data *clint, -struct clint_data *reference); - -#endif lib/utils/sys/clint.c deleted +0
-256@@ -1,256 +0,0 @@ -/* -* SPDX-License-Identifier: BSD-2-Clause -* -* Copyright (c) 2019 Western Digital Corporation or its affiliates. -* -* Authors: -* Anup Patel <[email protected]> -*/ - -#include <sbi/riscv_asm.h> -#include <sbi/riscv_atomic.h> -#include <sbi/riscv_io.h> -#include <sbi/sbi_domain.h> -#include <sbi/sbi_error.h> -#include <sbi/sbi_hartmask.h> -#include <sbi/sbi_ipi.h> -#include <sbi/sbi_timer.h> -#include <sbi_utils/sys/clint.h> - -#define CLINT_IPI_OFF 0 -#define CLINT_IPI_SIZE 0x4000 - -#define CLINT_TIME_CMP_OFF 0x4000 -#define CLINT_TIME_CMP_SIZE 0x4000 - -#define CLINT_TIME_VAL_OFF 0xbff8 -#define CLINT_TIME_VAL_SIZE 0x4000 - -static struct clint_data *clint_ipi_hartid2data[SBI_HARTMASK_MAX_BITS ]; - -static void clint_ipi_send (u32 target_hart) -{ -struct clint_data *clint; - -if (SBI_HARTMASK_MAX_BITS <= target_hart) -return ; - clint = clint_ipi_hartid2data[target_hart]; -if (!clint) -return ; - -/* Set CLINT IPI */ -writel (1 , &clint->ipi[target_hart - clint->first_hartid]); -} - -static void clint_ipi_clear (u32 target_hart) -{ -struct clint_data *clint; - -if (SBI_HARTMASK_MAX_BITS <= target_hart) -return ; - clint = clint_ipi_hartid2data[target_hart]; -if (!clint) -return ; - -/* Clear CLINT IPI */ -writel (0 , &clint->ipi[target_hart - clint->first_hartid]); -} - -static struct sbi_ipi_device clint_ipi = { - .name ="clint" , - .ipi_send = clint_ipi_send, - .ipi_clear = clint_ipi_clear -}; - -int clint_warm_ipi_init (void ) -{ -/* Clear CLINT IPI for current HART */ -clint_ipi_clear (current_hartid ()); - -return 0 ; -} - -int clint_cold_ipi_init (struct clint_data *clint) -{ -u32 i; -int rc; -struct sbi_domain_memregion reg; - -if (!clint) -return SBI_EINVAL ; - -/* Initialize private data */ - clint->ipi = (void *)clint->addr; - -/* Update IPI hartid table */ -for (i =0 ; i < clint->hart_count; i++) - clint_ipi_hartid2data[clint->first_hartid + i] = clint; - -/* Add CLINT ipi region to the root domain */ -sbi_domain_memregion_init (clint->addr +CLINT_IPI_OFF , -CLINT_IPI_SIZE , -SBI_DOMAIN_MEMREGION_MMIO , ®); - rc =sbi_domain_root_add_memregion (®); -if (rc) -return rc; - -sbi_ipi_set_device (&clint_ipi); - -return 0 ; -} - -static struct clint_data *clint_timer_hartid2data[SBI_HARTMASK_MAX_BITS ]; - -#if __riscv_xlen !=32 -static u64 clint_time_rd64 (volatile u64 *addr) -{ -return readq_relaxed (addr); -} - -static void clint_time_wr64 (u64 value,volatile u64 *addr) -{ -writeq_relaxed (value, addr); -} -#endif - -static u64 clint_time_rd32 (volatile u64 *addr) -{ -u32 lo, hi; - -do { - hi =readl_relaxed ((u32 *)addr +1 ); - lo =readl_relaxed ((u32 *)addr); - }while (hi !=readl_relaxed ((u32 *)addr +1 )); - -return ((u64 )hi <<32 ) | (u64 )lo; -} - -static void clint_time_wr32 (u64 value,volatile u64 *addr) -{ -u32 mask =-1U ; - -writel_relaxed (value & mask, (void *)(addr)); -writel_relaxed (value >>32 , (void *)(addr) +0x04 ); -} - -static u64 clint_timer_value (void ) -{ -struct clint_data *clint = clint_timer_hartid2data[current_hartid ()]; - -/* Read CLINT Time Value */ -return clint->time_rd (clint->time_val) + clint->time_delta; -} - -static void clint_timer_event_stop (void ) -{ -u32 target_hart =current_hartid (); -struct clint_data *clint = clint_timer_hartid2data[target_hart]; - -/* Clear CLINT Time Compare */ - clint->time_wr (-1ULL , - &clint->time_cmp[target_hart - clint->first_hartid]); -} - -static void clint_timer_event_start (u64 next_event) -{ -u32 target_hart =current_hartid (); -struct clint_data *clint = clint_timer_hartid2data[target_hart]; - -/* Program CLINT Time Compare */ - clint->time_wr (next_event - clint->time_delta, - &clint->time_cmp[target_hart - clint->first_hartid]); -} - -static struct sbi_timer_device clint_timer = { - .name ="clint" , - .timer_value = clint_timer_value, - .timer_event_start = clint_timer_event_start, - .timer_event_stop = clint_timer_event_stop -}; - -int clint_warm_timer_init (void ) -{ -u64 v1, v2, mv; -u32 target_hart =current_hartid (); -struct clint_data *reference; -struct clint_data *clint = clint_timer_hartid2data[target_hart]; - -if (!clint) -return SBI_ENODEV ; - -/* -* Compute delta if reference available -* -* We deliberately compute time_delta in warm init so that time_delta -* is computed on a HART which is going to use given CLINT. We use -* atomic flag timer_delta_computed to ensure that only one HART does -* time_delta computation. -*/ -if (clint->time_delta_reference) { - reference = clint->time_delta_reference; -if (!atomic_raw_xchg_ulong (&clint->time_delta_computed,1 )) { - v1 = clint->time_rd (clint->time_val); - mv = reference->time_rd (reference->time_val); - v2 = clint->time_rd (clint->time_val); - clint->time_delta = mv - ((v1 /2 ) + (v2 /2 )); - } - } - -/* Clear CLINT Time Compare */ - clint->time_wr (-1ULL , - &clint->time_cmp[target_hart - clint->first_hartid]); - -return 0 ; -} - -int clint_cold_timer_init (struct clint_data *clint, -struct clint_data *reference) -{ -u32 i; -int rc; -struct sbi_domain_memregion reg; - -if (!clint) -return SBI_EINVAL ; - -/* Initialize private data */ - clint->time_delta_reference = reference; - clint->time_delta_computed =0 ; - clint->time_delta =0 ; - clint->time_val = (u64 *)((void *)clint->addr +CLINT_TIME_VAL_OFF ); - clint->time_cmp = (u64 *)((void *)clint->addr +CLINT_TIME_CMP_OFF ); - clint->time_rd = clint_time_rd32; - clint->time_wr = clint_time_wr32; - -/* Override read/write accessors for 64bit MMIO */ -#if __riscv_xlen !=32 -if (clint->has_64bit_mmio) { - clint->time_rd = clint_time_rd64; - clint->time_wr = clint_time_wr64; - } -#endif - -/* Update timer hartid table */ -for (i =0 ; i < clint->hart_count; i++) - clint_timer_hartid2data[clint->first_hartid + i] = clint; - -/* Add CLINT mtime region to the root domain */ -sbi_domain_memregion_init (clint->addr +CLINT_TIME_VAL_OFF , -CLINT_TIME_VAL_SIZE , -SBI_DOMAIN_MEMREGION_MMIO , ®); - rc =sbi_domain_root_add_memregion (®); -if (rc) -return rc; - -/* Add CLINT timecmp region to the root domain */ -sbi_domain_memregion_init (clint->addr +CLINT_TIME_CMP_OFF , -CLINT_TIME_CMP_SIZE , -SBI_DOMAIN_MEMREGION_MMIO , ®); - rc =sbi_domain_root_add_memregion (®); -if (rc) -return rc; - -sbi_timer_set_device (&clint_timer); - -return 0 ; -}lib/utils/sys/objects.mk +0
-1@@ -7,6 +7,5 @@ # Anup Patel <[email protected]> # -libsbiutils-objs-y += sys/clint.o libsbiutils-objs-y += sys/htif.o libsbiutils-objs-y += sys/sifive_test.oplatform/fpga/ariane/platform.c +2
-1@@ -12,9 +12,10 @@#include <sbi/sbi_hart.h> #include <sbi/sbi_platform.h> #include <sbi_utils/fdt/fdt_fixup.h> +#include <sbi_utils/ipi/aclint_mswi.h> +#include <sbi_utils/irqchip/plic.h> #include <sbi_utils/serial/uart8250.h> -#include <sbi_utils/sys/clint.h> +#include <sbi_utils/timer/aclint_mtimer.h> #define ARIANE_UART_ADDR 0x10000000#define ARIANE_UART_FREQ 50000000
platform/fpga/ariane/platform.c line 29
Quoted 4 lines
platform/fpga/ariane/platform.c +1
-0@@ -25,14 +26,25 @@#define ARIANE_PLIC_NUM_SOURCES 3#define ARIANE_HART_COUNT 1#define ARIANE_CLINT_ADDR 0x2000000 +#define ARIANE_ACLINT_MSWI_ADDR ARIANE_CLINT_ADDR
nits: for consistency please make this equal to:
(ARIANE_CLINT_ADDR + CLINT_MSWI_OFFSET)
Please do this globally in this patch.
Quoted 42 lines
platform/fpga/ariane/platform.c +14
-4+#define ARIANE_ACLINT_MTIMER_ADDR (ARIANE_CLINT_ADDR + \ + CLINT_MTIMER_OFFSET)static struct plic_data plic = { .addr =ARIANE_PLIC_ADDR , .num_src =ARIANE_PLIC_NUM_SOURCES , }; -static struct clint_data clint = { - .addr =ARIANE_CLINT_ADDR , +static struct aclint_mswi_data mswi = { + .addr =ARIANE_ACLINT_MSWI_ADDR , + .size =ACLINT_MSWI_SIZE , + .first_hartid =0 , + .hart_count =ARIANE_HART_COUNT , +}; + +static struct aclint_mtimer_data mtimer = { + .addr =ARIANE_ACLINT_MTIMER_ADDR , + .size =ACLINT_MTIMER_SIZE , .first_hartid =0 , .hart_count =ARIANE_HART_COUNT , .has_64bit_mmio = TRUE,@@ -123,12 +135,12 @@ static int ariane_ipi_init(bool cold_boot)int ret;if (cold_boot) { - ret =clint_cold_ipi_init (&clint); + ret =aclint_mswi_cold_init (&mswi);if (ret)return ret; } -return clint_warm_ipi_init (); +return aclint_mswi_warm_init (); }/* @@ -139,12 +151,12 @@ static int ariane_timer_init(bool cold_boot)int ret;if (cold_boot) {
platform/fpga/ariane/platform.c static int ariane_timer_init(bool cold_boot) · line 161
Quoted 10 lines
platform/fpga/ariane/platform.c +2
-2- ret =clint_cold_timer_init (&clint,NULL ); + ret =aclint_mtimer_cold_init (&mtimer,NULL );if (ret)return ret; } -return clint_warm_timer_init (); +return aclint_mtimer_warm_init (); }
[snip]
Otherwise,
PATCH 6/6 platform: Replace CLINT library usage with ACLINT library
Quoted 368 lines · Bin Meng
Quoted 359 lines · Anup Patel
The ACLINT devices are backward compatible with SiFive CLINT so we replace all CLINT library usage in various platforms with ACLINT library. As a result of this replacement, the CLINT library is not used by any part of OpenSBI hence we remove it.
Signed-off-by Anup Patel <[email protected]>--- include/sbi_utils/sys/clint.h | 41 ----- lib/utils/sys/clint.c | 256 ----------------------------- lib/utils/sys/objects.mk | 1 - platform/fpga/ariane/platform.c | 26 ++- platform/fpga/openpiton/platform.c | 32 +++- platform/kendryte/k210/platform.c | 23 ++- platform/kendryte/k210/platform.h | 3 + platform/nuclei/ux600/platform.c | 27 ++- platform/template/platform.c | 30 +++- 9 files changed, 102 insertions(+), 337 deletions(-) delete mode 100644 include/sbi_utils/sys/clint.h delete mode 100644 lib/utils/sys/clint.cinclude/sbi_utils/sys/clint.h deleted +0
-41@@ -1,41 +0,0 @@ -/* -* SPDX-License-Identifier: BSD-2-Clause -* -* Copyright (c) 2019 Western Digital Corporation or its affiliates. -* -* Authors: -* Anup Patel <[email protected]> -*/ - -#ifndef __SYS_CLINT_H__ -#define __SYS_CLINT_H__ - -#include <sbi/sbi_types.h> - -struct clint_data { -/* Public details */ -unsigned long addr; -u32 first_hartid; -u32 hart_count; -bool has_64bit_mmio; -/* Private details (initialized and used by CLINT library)*/ -u32 *ipi; -struct clint_data *time_delta_reference; -unsigned long time_delta_computed; -u64 time_delta; -u64 *time_val; -u64 *time_cmp; -u64 (*time_rd)(volatile u64 *addr); -void (*time_wr)(u64 value,volatile u64 *addr); -}; - -int clint_warm_ipi_init (void ); - -int clint_cold_ipi_init (struct clint_data *clint); - -int clint_warm_timer_init (void ); - -int clint_cold_timer_init (struct clint_data *clint, -struct clint_data *reference); - -#endif lib/utils/sys/clint.c deleted +0
-256@@ -1,256 +0,0 @@ -/* -* SPDX-License-Identifier: BSD-2-Clause -* -* Copyright (c) 2019 Western Digital Corporation or its affiliates. -* -* Authors: -* Anup Patel <[email protected]> -*/ - -#include <sbi/riscv_asm.h> -#include <sbi/riscv_atomic.h> -#include <sbi/riscv_io.h> -#include <sbi/sbi_domain.h> -#include <sbi/sbi_error.h> -#include <sbi/sbi_hartmask.h> -#include <sbi/sbi_ipi.h> -#include <sbi/sbi_timer.h> -#include <sbi_utils/sys/clint.h> - -#define CLINT_IPI_OFF 0 -#define CLINT_IPI_SIZE 0x4000 - -#define CLINT_TIME_CMP_OFF 0x4000 -#define CLINT_TIME_CMP_SIZE 0x4000 - -#define CLINT_TIME_VAL_OFF 0xbff8 -#define CLINT_TIME_VAL_SIZE 0x4000 - -static struct clint_data *clint_ipi_hartid2data[SBI_HARTMASK_MAX_BITS ]; - -static void clint_ipi_send (u32 target_hart) -{ -struct clint_data *clint; - -if (SBI_HARTMASK_MAX_BITS <= target_hart) -return ; - clint = clint_ipi_hartid2data[target_hart]; -if (!clint) -return ; - -/* Set CLINT IPI */ -writel (1 , &clint->ipi[target_hart - clint->first_hartid]); -} - -static void clint_ipi_clear (u32 target_hart) -{ -struct clint_data *clint; - -if (SBI_HARTMASK_MAX_BITS <= target_hart) -return ; - clint = clint_ipi_hartid2data[target_hart]; -if (!clint) -return ; - -/* Clear CLINT IPI */ -writel (0 , &clint->ipi[target_hart - clint->first_hartid]); -} - -static struct sbi_ipi_device clint_ipi = { - .name ="clint" , - .ipi_send = clint_ipi_send, - .ipi_clear = clint_ipi_clear -}; - -int clint_warm_ipi_init (void ) -{ -/* Clear CLINT IPI for current HART */ -clint_ipi_clear (current_hartid ()); - -return 0 ; -} - -int clint_cold_ipi_init (struct clint_data *clint) -{ -u32 i; -int rc; -struct sbi_domain_memregion reg; - -if (!clint) -return SBI_EINVAL ; - -/* Initialize private data */ - clint->ipi = (void *)clint->addr; - -/* Update IPI hartid table */ -for (i =0 ; i < clint->hart_count; i++) - clint_ipi_hartid2data[clint->first_hartid + i] = clint; - -/* Add CLINT ipi region to the root domain */ -sbi_domain_memregion_init (clint->addr +CLINT_IPI_OFF , -CLINT_IPI_SIZE , -SBI_DOMAIN_MEMREGION_MMIO , ®); - rc =sbi_domain_root_add_memregion (®); -if (rc) -return rc; - -sbi_ipi_set_device (&clint_ipi); - -return 0 ; -} - -static struct clint_data *clint_timer_hartid2data[SBI_HARTMASK_MAX_BITS ]; - -#if __riscv_xlen !=32 -static u64 clint_time_rd64 (volatile u64 *addr) -{ -return readq_relaxed (addr); -} - -static void clint_time_wr64 (u64 value,volatile u64 *addr) -{ -writeq_relaxed (value, addr); -} -#endif - -static u64 clint_time_rd32 (volatile u64 *addr) -{ -u32 lo, hi; - -do { - hi =readl_relaxed ((u32 *)addr +1 ); - lo =readl_relaxed ((u32 *)addr); - }while (hi !=readl_relaxed ((u32 *)addr +1 )); - -return ((u64 )hi <<32 ) | (u64 )lo; -} - -static void clint_time_wr32 (u64 value,volatile u64 *addr) -{ -u32 mask =-1U ; - -writel_relaxed (value & mask, (void *)(addr)); -writel_relaxed (value >>32 , (void *)(addr) +0x04 ); -} - -static u64 clint_timer_value (void ) -{ -struct clint_data *clint = clint_timer_hartid2data[current_hartid ()]; - -/* Read CLINT Time Value */ -return clint->time_rd (clint->time_val) + clint->time_delta; -} - -static void clint_timer_event_stop (void ) -{ -u32 target_hart =current_hartid (); -struct clint_data *clint = clint_timer_hartid2data[target_hart]; - -/* Clear CLINT Time Compare */ - clint->time_wr (-1ULL , - &clint->time_cmp[target_hart - clint->first_hartid]); -} - -static void clint_timer_event_start (u64 next_event) -{ -u32 target_hart =current_hartid (); -struct clint_data *clint = clint_timer_hartid2data[target_hart]; - -/* Program CLINT Time Compare */ - clint->time_wr (next_event - clint->time_delta, - &clint->time_cmp[target_hart - clint->first_hartid]); -} - -static struct sbi_timer_device clint_timer = { - .name ="clint" , - .timer_value = clint_timer_value, - .timer_event_start = clint_timer_event_start, - .timer_event_stop = clint_timer_event_stop -}; - -int clint_warm_timer_init (void ) -{ -u64 v1, v2, mv; -u32 target_hart =current_hartid (); -struct clint_data *reference; -struct clint_data *clint = clint_timer_hartid2data[target_hart]; - -if (!clint) -return SBI_ENODEV ; - -/* -* Compute delta if reference available -* -* We deliberately compute time_delta in warm init so that time_delta -* is computed on a HART which is going to use given CLINT. We use -* atomic flag timer_delta_computed to ensure that only one HART does -* time_delta computation. -*/ -if (clint->time_delta_reference) { - reference = clint->time_delta_reference; -if (!atomic_raw_xchg_ulong (&clint->time_delta_computed,1 )) { - v1 = clint->time_rd (clint->time_val); - mv = reference->time_rd (reference->time_val); - v2 = clint->time_rd (clint->time_val); - clint->time_delta = mv - ((v1 /2 ) + (v2 /2 )); - } - } - -/* Clear CLINT Time Compare */ - clint->time_wr (-1ULL , - &clint->time_cmp[target_hart - clint->first_hartid]); - -return 0 ; -} - -int clint_cold_timer_init (struct clint_data *clint, -struct clint_data *reference) -{ -u32 i; -int rc; -struct sbi_domain_memregion reg; - -if (!clint) -return SBI_EINVAL ; - -/* Initialize private data */ - clint->time_delta_reference = reference; - clint->time_delta_computed =0 ; - clint->time_delta =0 ; - clint->time_val = (u64 *)((void *)clint->addr +CLINT_TIME_VAL_OFF ); - clint->time_cmp = (u64 *)((void *)clint->addr +CLINT_TIME_CMP_OFF ); - clint->time_rd = clint_time_rd32; - clint->time_wr = clint_time_wr32; - -/* Override read/write accessors for 64bit MMIO */ -#if __riscv_xlen !=32 -if (clint->has_64bit_mmio) { - clint->time_rd = clint_time_rd64; - clint->time_wr = clint_time_wr64; - } -#endif - -/* Update timer hartid table */ -for (i =0 ; i < clint->hart_count; i++) - clint_timer_hartid2data[clint->first_hartid + i] = clint; - -/* Add CLINT mtime region to the root domain */ -sbi_domain_memregion_init (clint->addr +CLINT_TIME_VAL_OFF , -CLINT_TIME_VAL_SIZE , -SBI_DOMAIN_MEMREGION_MMIO , ®); - rc =sbi_domain_root_add_memregion (®); -if (rc) -return rc; - -/* Add CLINT timecmp region to the root domain */ -sbi_domain_memregion_init (clint->addr +CLINT_TIME_CMP_OFF , -CLINT_TIME_CMP_SIZE , -SBI_DOMAIN_MEMREGION_MMIO , ®); - rc =sbi_domain_root_add_memregion (®); -if (rc) -return rc; - -sbi_timer_set_device (&clint_timer); - -return 0 ; -}lib/utils/sys/objects.mk +0
-1@@ -7,6 +7,5 @@ # Anup Patel <[email protected]> # -libsbiutils-objs-y += sys/clint.o libsbiutils-objs-y += sys/htif.o libsbiutils-objs-y += sys/sifive_test.oplatform/fpga/ariane/platform.c +2
-1@@ -12,9 +12,10 @@#include <sbi/sbi_hart.h> #include <sbi/sbi_platform.h> #include <sbi_utils/fdt/fdt_fixup.h> +#include <sbi_utils/ipi/aclint_mswi.h> +#include <sbi_utils/irqchip/plic.h> #include <sbi_utils/serial/uart8250.h> -#include <sbi_utils/sys/clint.h> +#include <sbi_utils/timer/aclint_mtimer.h> #define ARIANE_UART_ADDR 0x10000000#define ARIANE_UART_FREQ 50000000platform/fpga/ariane/platform.c line 29
Quoted 4 lines
platform/fpga/ariane/platform.c +1
-0@@ -25,14 +26,25 @@#define ARIANE_PLIC_NUM_SOURCES 3#define ARIANE_HART_COUNT 1#define ARIANE_CLINT_ADDR 0x2000000 +#define ARIANE_ACLINT_MSWI_ADDR ARIANE_CLINT_ADDRnits: for consistency please make this equal to:
Quoted 3 lines
(
ARIANE_CLINT_ADDR+CLINT_MSWI_OFFSET)Please do this globally in this patch.
Okay, will update.
Quoted 56 lines
Quoted 53 lines
platform/fpga/ariane/platform.c +16
-6+#define ARIANE_ACLINT_MTIMER_ADDR (ARIANE_CLINT_ADDR + \ + CLINT_MTIMER_OFFSET)static struct plic_data plic = { .addr =ARIANE_PLIC_ADDR , .num_src =ARIANE_PLIC_NUM_SOURCES , }; -static struct clint_data clint = { - .addr =ARIANE_CLINT_ADDR , +static struct aclint_mswi_data mswi = { + .addr =ARIANE_ACLINT_MSWI_ADDR , + .size =ACLINT_MSWI_SIZE , + .first_hartid =0 , + .hart_count =ARIANE_HART_COUNT , +}; + +static struct aclint_mtimer_data mtimer = { + .addr =ARIANE_ACLINT_MTIMER_ADDR , + .size =ACLINT_MTIMER_SIZE , .first_hartid =0 , .hart_count =ARIANE_HART_COUNT , .has_64bit_mmio = TRUE,@@ -123,12 +135,12 @@ static int ariane_ipi_init(bool cold_boot)int ret;if (cold_boot) { - ret =clint_cold_ipi_init (&clint); + ret =aclint_mswi_cold_init (&mswi);if (ret)return ret; } -return clint_warm_ipi_init (); +return aclint_mswi_warm_init (); }/* @@ -139,12 +151,12 @@ static int ariane_timer_init(bool cold_boot)int ret;if (cold_boot) { - ret =clint_cold_timer_init (&clint,NULL ); + ret =aclint_mtimer_cold_init (&mtimer,NULL );if (ret)return ret; } -return clint_warm_timer_init (); +return aclint_mtimer_warm_init (); }[snip]
Quoted 2 lines
Otherwise,
Reviewed-by Bin Meng <[email protected]>
Regards,
Anup
PATCH 6/6 platform: Replace CLINT library usage with ACLINT library
In reply to Anup Patel? 2021-06-12???? 21:33 +0530?Anup Patel???
Quoted 7 lines
The ACLINT devices are backward compatible with SiFive CLINT so we replace all CLINT library usage in various platforms with ACLINT library. As a result of this replacement, the CLINT library is not used by any part of OpenSBI hence we remove it.
Signed-off-by Anup Patel <[email protected]>
look good to me
Quoted 770 lines
---
?include/sbi_utils/sys/clint.h????? |? 41 ----- ?lib/utils/sys/clint.c????????????? | 256 --------------------------- --?lib/utils/sys/objects.mk?????????? |?? 1 - ?platform/fpga/ariane/platform.c??? |? 26 ++- ?platform/fpga/openpiton/platform.c |? 32 +++- ?platform/kendryte/k210/platform.c? |? 23 ++- ?platform/kendryte/k210/platform.h? |?? 3 + ?platform/nuclei/ux600/platform.c?? |? 27 ++- ?platform/template/platform.c?????? |? 30 +++-?9 files changed, 102 insertions(+), 337 deletions(-) ?delete mode 100644
include/sbi_utils/sys/clint.h?delete mode 100644lib/utils/sys/clint.cinclude/sbi_utils/sys/clint.h deleted +0
-41@@ -1,41 +0,0 @@ -/* -* SPDX-License-Identifier: BSD-2-Clause -* -* Copyright (c) 2019 Western Digital Corporation or its affiliates. -* -* Authors: -*?? Anup Patel <[email protected]> -*/ - -#ifndef __SYS_CLINT_H__ -#define __SYS_CLINT_H__ - -#include <sbi/sbi_types.h> - -struct clint_data { -???????/* Public details */ -???????unsigned long addr; -???????u32 first_hartid; -???????u32 hart_count; -???????bool has_64bit_mmio; -???????/* Private details (initialized and used by CLINT library)*/ -???????u32 *ipi; -???????struct clint_data *time_delta_reference; -???????unsigned long time_delta_computed; -???????u64 time_delta; -???????u64 *time_val; -???????u64 *time_cmp; -???????u64 (*time_rd)(volatile u64 *addr); -???????void (*time_wr)(u64 value, volatile u64 *addr); -}; - -int clint_warm_ipi_init (void ); - -int clint_cold_ipi_init (struct clint_data *clint); - -int clint_warm_timer_init (void ); - -int clint_cold_timer_init (struct clint_data *clint, -???????????????????????? struct clint_data *reference); - -#endif lib/utils/sys/clint.c deleted +0
-29@@ -1,256 +0,0 @@ -/* -* SPDX-License-Identifier: BSD-2-Clause -* -* Copyright (c) 2019 Western Digital Corporation or its affiliates. -* -* Authors: -*?? Anup Patel <[email protected]> -*/ - -#include <sbi/riscv_asm.h> -#include <sbi/riscv_atomic.h> -#include <sbi/riscv_io.h> -#include <sbi/sbi_domain.h> -#include <sbi/sbi_error.h> -#include <sbi/sbi_hartmask.h> -#include <sbi/sbi_ipi.h> -#include <sbi/sbi_timer.h> -#include <sbi_utils/sys/clint.h> - -#define CLINT_IPI_OFF ??????????0 -#define CLINT_IPI_SIZE ?????????0x4000 - -#define CLINT_TIME_CMP_OFF ?????0x4000 -#define CLINT_TIME_CMP_SIZE ????0x4000 - -#define CLINT_TIME_VAL_OFF ?????0xbff8 -#define CLINT_TIME_VAL_SIZE ????0x4000 - -static struct clint_data*clint_ipi_hartid2data[SBI_HARTMASK_MAX_BITS];
lib/utils/sys/clint.c deleted +0
-58- -static void clint_ipi_send (u32 target_hart) -{ -???????struct clint_data *clint; - -???????if (SBI_HARTMASK_MAX_BITS <= target_hart) -???????????????return; -???????clint = clint_ipi_hartid2data[target_hart]; -???????if (!clint) -???????????????return; - -???????/* Set CLINT IPI */ -???????writel(1, &clint->ipi[target_hart - clint->first_hartid]); -} - -static void clint_ipi_clear (u32 target_hart) -{ -???????struct clint_data *clint; - -???????if (SBI_HARTMASK_MAX_BITS <= target_hart) -???????????????return; -???????clint = clint_ipi_hartid2data[target_hart]; -???????if (!clint) -???????????????return; - -???????/* Clear CLINT IPI */ -???????writel(0, &clint->ipi[target_hart - clint->first_hartid]); -} - -static struct sbi_ipi_device clint_ipi = { -???????.name = "clint", -???????.ipi_send = clint_ipi_send, -???????.ipi_clear = clint_ipi_clear -}; - -int clint_warm_ipi_init (void ) -{ -???????/* Clear CLINT IPI for current HART */ -???????clint_ipi_clear(current_hartid()); - -???????return 0; -} - -int clint_cold_ipi_init (struct clint_data *clint) -{ -???????u32 i; -???????int rc; -???????struct sbi_domain_memregion reg; - -???????if (!clint) -???????????????return SBI_EINVAL; - -???????/* Initialize private data */ -???????clint->ipi = (void *)clint->addr; - -???????/* Update IPI hartid table */ -???????for (i = 0; i < clint->hart_count; i++) -???????????????clint_ipi_hartid2data[clint->first_hartid + i] =clint;
lib/utils/sys/clint.c deleted +0
-15- -???????/* Add CLINT ipi region to the root domain */ -???????sbi_domain_memregion_init(clint->addr + CLINT_IPI_OFF, -???????????????????????????????? CLINT_IPI_SIZE, -???????????????????????????????? SBI_DOMAIN_MEMREGION_MMIO, ®); -???????rc = sbi_domain_root_add_memregion(®); -???????if (rc) -???????????????return rc; - -???????sbi_ipi_set_device(&clint_ipi); - -???????return 0; -} - -static struct clint_data*clint_timer_hartid2data[SBI_HARTMASK_MAX_BITS];
lib/utils/sys/clint.c deleted +0
-36- -#if __riscv_xlen !=32 -static u64 clint_time_rd64 (volatile u64 *addr) -{ -???????return readq_relaxed(addr); -} - -static void clint_time_wr64 (u64 value,volatile u64 *addr) -{ -???????writeq_relaxed(value, addr); -} -#endif - -static u64 clint_time_rd32 (volatile u64 *addr) -{ -???????u32 lo, hi; - -???????do { -???????????????hi = readl_relaxed((u32 *)addr + 1); -???????????????lo = readl_relaxed((u32 *)addr); -???????} while (hi != readl_relaxed((u32 *)addr + 1)); - -???????return ((u64)hi << 32) | (u64)lo; -} - -static void clint_time_wr32 (u64 value,volatile u64 *addr) -{ -???????u32 mask = -1U; - -???????writel_relaxed(value & mask, (void *)(addr)); -???????writel_relaxed(value >> 32, (void *)(addr) + 0x04); -} - -static u64 clint_timer_value (void ) -{ -???????struct clint_data *clint =clint_timer_hartid2data[current_hartid()];
lib/utils/sys/clint.c deleted +0
-9- -???????/* Read CLINT Time Value */ -???????return clint->time_rd(clint->time_val) + clint->time_delta; -} - -static void clint_timer_event_stop (void ) -{ -???????u32 target_hart = current_hartid(); -???????struct clint_data *clint =clint_timer_hartid2data[target_hart];
-
-???????/* Clear CLINT Time Compare */ -???????clint->time_wr(-1ULL, -???????????????????????&clint->time_cmp[target_hart - clint-Quoted 1 line
first_hartid]);lib/utils/sys/clint.c deleted +0
-6-} - -static void clint_timer_event_start (u64 next_event) -{ -???????u32 target_hart = current_hartid(); -???????struct clint_data *clint =clint_timer_hartid2data[target_hart];
-
-???????/* Program CLINT Time Compare */ -???????clint->time_wr(next_event -clint->time_delta, -????????????????????? &clint->time_cmp[target_hart - clint-Quoted 1 line
first_hartid]);lib/utils/sys/clint.c deleted +0
-15-} - -static struct sbi_timer_device clint_timer = { -???????.name = "clint", -???????.timer_value = clint_timer_value, -???????.timer_event_start = clint_timer_event_start, -???????.timer_event_stop = clint_timer_event_stop -}; - -int clint_warm_timer_init (void ) -{ -???????u64 v1, v2, mv; -???????u32 target_hart = current_hartid(); -???????struct clint_data *reference; -???????struct clint_data *clint =clint_timer_hartid2data[target_hart];
lib/utils/sys/clint.c deleted +0
-8- -???????if (!clint) -???????????????return SBI_ENODEV; - -???????/* -??????? * Compute delta if reference available -??????? * -??????? * We deliberately compute time_delta in warm init so that
time_delta
-??????? * is computed on a HART which is going to use given CLINT. We use
-??????? * atomic flagtimer_delta_computedto ensure that only one HART does
-??????? *time_deltacomputation.
-??????? */
-???????if (clint->time_delta_reference) { -???????????????reference =clint->time_delta_reference; -???????????????if (!atomic_raw_xchg_ulong(&clint-Quoted 1 line
time_delta_computed, 1)) {-???????????????????????v1 =
clint->time_rd(clint->time_val); -???????????????????????mv =reference->time_rd(reference->time_val); -???????????????????????v2 =clint->time_rd(clint->time_val); -???????????????????????clint->time_delta = mv - ((v1 / 2) + (v2 / 2));
-???????????????}
-???????}
-
-???????/* Clear CLINT Time Compare */ -???????clint->time_wr(-1ULL,
-????????????????????? &clint->time_cmp[target_hart - clint-Quoted 1 line
first_hartid]);lib/utils/sys/clint.c deleted +0
-19- -???????return 0; -} - -int clint_cold_timer_init (struct clint_data *clint, -???????????????????????? struct clint_data *reference) -{ -???????u32 i; -???????int rc; -???????struct sbi_domain_memregion reg; - -???????if (!clint) -???????????????return SBI_EINVAL; - -???????/* Initialize private data */ -???????clint->time_delta_reference = reference; -???????clint->time_delta_computed = 0; -???????clint->time_delta = 0; -???????clint->time_val = (u64 *)((void *)clint->addr +
CLINT_TIME_VAL_OFF);
-???????clint->time_cmp = (u64 *)((void *)clint->addr +CLINT_TIME_CMP_OFF);
-???????clint->time_rd =clint_time_rd32; -???????clint->time_wr =clint_time_wr32;lib/utils/sys/clint.c deleted +0
-12- -???????/* Override read/write accessors for 64bit MMIO */ -#if __riscv_xlen !=32 -???????if (clint->has_64bit_mmio) { -???????????????clint->time_rd = clint_time_rd64; -???????????????clint->time_wr = clint_time_wr64; -???????} -#endif - -???????/* Update timer hartid table */ -???????for (i = 0; i < clint->hart_count; i++) -???????????????clint_timer_hartid2data[clint->first_hartid + i] =clint;
lib/utils/sys/clint.c deleted +0
-21- -???????/* Add CLINT mtime region to the root domain */ -???????sbi_domain_memregion_init(clint->addr + CLINT_TIME_VAL_OFF, -???????????????????????????????? CLINT_TIME_VAL_SIZE, -???????????????????????????????? SBI_DOMAIN_MEMREGION_MMIO, ®); -???????rc = sbi_domain_root_add_memregion(®); -???????if (rc) -???????????????return rc; - -???????/* Add CLINT timecmp region to the root domain */ -???????sbi_domain_memregion_init(clint->addr + CLINT_TIME_CMP_OFF, -???????????????????????????????? CLINT_TIME_CMP_SIZE, -???????????????????????????????? SBI_DOMAIN_MEMREGION_MMIO, ®); -???????rc = sbi_domain_root_add_memregion(®); -???????if (rc) -???????????????return rc; - -???????sbi_timer_set_device(&clint_timer); - -???????return 0; -}lib/utils/sys/objects.mk +0
-0@@ -7,6 +7,5 @@?#?? Anup Patel <[email protected]>
?#
?
-libsbiutils-objs-y +=sys/clint.o
?libsbiutils-objs-y +=sys/htif.o
?libsbiutils-objs-y +=sys/sifive_test.oplatform/fpga/ariane/platform.c +0
-0@@ -12,9 +12,10 @@?#include <
sbi/sbi_hart.h>
?#include <sbi/sbi_platform.h>
?#include <sbi_utils/fdt/fdt_fixup.h>
+#include <sbi_utils/ipi/aclint_mswi.h>
?#include <sbi_utils/irqchip/plic.h>
?#include <sbi_utils/serial/uart8250.h>platform/fpga/ariane/platform.c +1
-1-#include <sbi_utils/sys/clint.h> +#include <sbi_utils/timer/aclint_mtimer.h> ?
?#define ARIANE_UART_ADDR???????????????????????0x10000000 ?#define ARIANE_UART_FREQ???????????????????????50000000platform/fpga/ariane/platform.c +0
-0@@ -25,14 +26,25 @@?#define ARIANE_PLIC_NUM_SOURCES????????????????????????3 ?#define ARIANE_HART_COUNT??????????????????????1
?#define ARIANE_CLINT_ADDR??????????????????????0x2000000 +#define ARIANE_ACLINT_MSWI_ADDR????????????????????????ARIANE_CLINT_ADDR +#define ARIANE_ACLINT_MTIMER_ADDR??????????????(ARIANE_CLINT_ADDR + \
+???????????????????????????????????????????????CLINT_MTIMER_OFFSET) ?
?static structplic_dataplic = {
????????.addr =ARIANE_PLIC_ADDR,
????????.num_src =ARIANE_PLIC_NUM_SOURCES,
?};
?platform/fpga/ariane/platform.c +10
-2-static struct clint_data clint = { -???????.addr = ARIANE_CLINT_ADDR, +static struct aclint_mswi_data mswi = { +???????.addr = ARIANE_ACLINT_MSWI_ADDR, +???????.size = ACLINT_MSWI_SIZE, +???????.first_hartid = 0, +???????.hart_count = ARIANE_HART_COUNT, +}; + +static struct aclint_mtimer_data mtimer = { +???????.addr = ARIANE_ACLINT_MTIMER_ADDR, +???????.size = ACLINT_MTIMER_SIZE,????????.first_hartid = 0,
????????.hart_count =ARIANE_HART_COUNT,
????????.has_64bit_mmio = TRUE,platform/fpga/ariane/platform.c +0
-0@@ -123,12 +135,12 @@ static int ariane_ipi_init(bool cold_boot) ????????int ret;?
????????if (cold_boot) { -???????????????ret =clint_cold_ipi_init(&clint); +???????????????ret =aclint_mswi_cold_init(&mswi); ????????????????if (ret) ????????????????????????return ret; ????????}
?
-???????returnclint_warm_ipi_init(); +???????returnaclint_mswi_warm_init();
?}
?
?/*platform/fpga/ariane/platform.c +0
-0@@ -139,12 +151,12 @@ static int ariane_timer_init(bool cold_boot) ????????int ret;?
????????if (cold_boot) {
-???????????????ret =clint_cold_timer_init(&clint, NULL); +???????????????ret =aclint_mtimer_cold_init(&mtimer, NULL); ????????????????if (ret) ????????????????????????return ret;
????????}
?
-???????returnclint_warm_timer_init(); +???????returnaclint_mtimer_warm_init();
?}
?
?/*platform/fpga/openpiton/platform.c +0
-0@@ -12,9 +12,10 @@?#include <
sbi/sbi_platform.h>
?#include <sbi_utils/fdt/fdt_helper.h>
?#include <sbi_utils/fdt/fdt_fixup.h>
+#include <sbi_utils/ipi/aclint_mswi.h>
?#include <sbi_utils/irqchip/plic.h>
?#include <sbi_utils/serial/uart8250.h>platform/fpga/openpiton/platform.c +1
-1-#include <sbi_utils/sys/clint.h> +#include <sbi_utils/timer/aclint_mtimer.h> ?
?#define OPENPITON_DEFAULT_UART_ADDR????????????0xfff0c2c000 ?#define OPENPITON_DEFAULT_UART_FREQ????????????60000000platform/fpga/openpiton/platform.c +0
-0@@ -25,6 +26,9 @@?#define OPENPITON_DEFAULT_PLIC_NUM_SOURCES?????2 ?#define OPENPITON_DEFAULT_HART_COUNT???????????3 ?#define OPENPITON_DEFAULT_CLINT_ADDR???????????0xfff1020000 +#define OPENPITON_DEFAULT_ACLINT_MSWI_ADDR?????OPENPITON_DEFAULT_CLINT_ADDR +#define OPENPITON_DEFAULT_ACLINT_MTIMER_ADDR???\
+???????????????(OPENPITON_DEFAULT_CLINT_ADDR +CLINT_MTIMER_OFFSET) ?
?static structplatform_uart_datauart = { ????????OPENPITON_DEFAULT_UART_ADDR,platform/fpga/openpiton/platform.c +0
-0@@ -36,8 +40,16 @@ static struct plic_data plic = { ????????.num_src = OPENPITON_DEFAULT_PLIC_NUM_SOURCES, ?};?
platform/fpga/openpiton/platform.c +10
-2-static struct clint_data clint = { -???????.addr = OPENPITON_DEFAULT_CLINT_ADDR, +static struct aclint_mswi_data mswi = { +???????.addr = OPENPITON_DEFAULT_ACLINT_MSWI_ADDR, +???????.size = ACLINT_MSWI_SIZE, +???????.first_hartid = 0, +???????.hart_count = OPENPITON_DEFAULT_HART_COUNT, +}; + +static struct aclint_mtimer_data mtimer = { +???????.addr = OPENPITON_DEFAULT_ACLINT_MTIMER_ADDR, +???????.size = ACLINT_MTIMER_SIZE,????????.first_hartid = 0, ????????.hart_count =
OPENPITON_DEFAULT_HART_COUNT, ????????.has_64bit_mmio = TRUE,platform/fpga/openpiton/platform.c +0
-0@@ -67,8 +79,10 @@ static int openpiton_early_init(bool cold_boot) ????????????????plic = plic_data;?
????????rc =fdt_parse_compat_addr(fdt, &clint_addr, "riscv,clint0"); -???????if (!rc)
-???????????????clint.addr =clint_addr;
+???????if (!rc) {
+???????????????mswi.addr =clint_addr; +???????????????mtimer.addr =clint_addr+CLINT_MTIMER_OFFSET; +???????}
?
????????return 0;
?}platform/fpga/openpiton/platform.c +0
-0@@ -149,12 +163,12 @@ static int openpiton_ipi_init(bool cold_boot) ????????int ret;?
????????if (cold_boot) { -???????????????ret =clint_cold_ipi_init(&clint); +???????????????ret =aclint_mswi_cold_init(&mswi); ????????????????if (ret) ????????????????????????return ret; ????????}
?
-???????returnclint_warm_ipi_init(); +???????returnaclint_mswi_warm_init();
?}
?
?/*platform/fpga/openpiton/platform.c +0
-0@@ -165,12 +179,12 @@ static int openpiton_timer_init(bool cold_boot) ????????int ret;?
????????if (cold_boot) {
-???????????????ret =clint_cold_timer_init(&clint, NULL); +???????????????ret =aclint_mtimer_cold_init(&mtimer, NULL); ????????????????if (ret) ????????????????????????return ret;
????????}
?
-???????returnclint_warm_timer_init(); +???????returnaclint_mtimer_warm_init();
?}
?
?/*platform/kendryte/k210/platform.c +0
-0@@ -14,9 +14,10 @@?#include <
sbi/sbi_platform.h>
?#include <sbi/sbi_system.h>
?#include <sbi_utils/fdt/fdt_fixup.h>
+#include <sbi_utils/ipi/aclint_mswi.h>
?#include <sbi_utils/irqchip/plic.h>
?#include <sbi_utils/serial/sifive-uart.h>platform/kendryte/k210/platform.c +1
-1-#include <sbi_utils/sys/clint.h> +#include <sbi_utils/timer/aclint_mtimer.h> ?#include "
platform.h"
?
?extern const char dt_k210_start[];platform/kendryte/k210/platform.c +0
-0@@ -33,8 +34,16 @@ static struct plic_data plic = { ????????.num_src = K210_PLIC_NUM_SOURCES, ?};?
platform/kendryte/k210/platform.c +10
-2-static struct clint_data clint = { -???????.addr = K210_CLINT_BASE_ADDR, +static struct aclint_mswi_data mswi = { +???????.addr = K210_ACLINT_MSWI_ADDR, +???????.size = ACLINT_MSWI_SIZE, +???????.first_hartid = 0, +???????.hart_count = K210_HART_COUNT, +}; + +static struct aclint_mtimer_data mtimer = { +???????.addr = K210_ACLINT_MTIMER_ADDR, +???????.size = ACLINT_MTIMER_SIZE,????????.first_hartid = 0,
????????.hart_count =K210_HART_COUNT,
????????.has_64bit_mmio = TRUE,platform/kendryte/k210/platform.c +0
-0@@ -139,12 +148,12 @@ static int k210_ipi_init(bool cold_boot) ????????int rc;?
????????if (cold_boot) { -???????????????rc =clint_cold_ipi_init(&clint); +???????????????rc =aclint_mswi_cold_init(&mswi); ????????????????if (rc) ????????????????????????return rc; ????????}
?
-???????returnclint_warm_ipi_init(); +???????returnaclint_mswi_warm_init();
?}
?
?static intk210_timer_init(bool cold_boot)platform/kendryte/k210/platform.c +0
-0@@ -152,12 +161,12 @@ static int k210_timer_init(bool cold_boot) ????????int rc;?
????????if (cold_boot) {
-???????????????rc =clint_cold_timer_init(&clint, NULL); +???????????????rc =aclint_mtimer_cold_init(&mtimer, NULL); ????????????????if (rc) ????????????????????????return rc;
????????}
?
-???????returnclint_warm_timer_init(); +???????returnaclint_mtimer_warm_init();
?}
?
?const structsbi_platform_operationsplatform_ops= {platform/kendryte/k210/platform.h +0
-0@@ -22,6 +22,9 @@?#define K210_SYSCTL_BASE_ADDR??0x50440000ULL
?#define K210_UART_BASE_ADDR????0x38000000ULL
?#define K210_CLINT_BASE_ADDR???0x02000000ULLplatform/kendryte/k210/platform.h +3
-0+#define K210_ACLINT_MSWI_ADDR ??K210_CLINT_BASE_ADDR +#define K210_ACLINT_MTIMER_ADDR \ +???????????????(K210_CLINT_BASE_ADDR + CLINT_MTIMER_OFFSET)?#define K210_PLIC_BASE_ADDR????0x0C000000ULL
?
?/* Registers */platform/nuclei/ux600/platform.c +0
-0@@ -17,9 +17,10 @@?#include <
sbi/sbi_platform.h>
?#include <sbi/sbi_system.h>
?#include <sbi_utils/fdt/fdt_fixup.h>
+#include <sbi_utils/ipi/aclint_mswi.h>
?#include <sbi_utils/irqchip/plic.h>
?#include <sbi_utils/serial/sifive-uart.h>platform/nuclei/ux600/platform.c +1
-1-#include <sbi_utils/sys/clint.h> +#include <sbi_utils/timer/aclint_mtimer.h> ?
?/* clang-format off */
?platform/nuclei/ux600/platform.c +0
-0@@ -32,6 +33,9 @@?#define UX600_NUCLEI_TIMER_MSFTRST_KEY?0x80000A5F
?/* The clint compatiable timer offset is0x1000against nuclei timer */
?#define UX600_CLINT_TIMER_ADDR?????????(UX600_NUCLEI_TIMER_ADDR +0x1000)platform/nuclei/ux600/platform.c +2
-0+#define UX600_ACLINT_MSWI_ADDR ?????????UX600_CLINT_TIMER_ADDR +#defineUX600_ACLINT_MTIMER_ADDR???????????????(UX600_CLINT_TIMER_ADDR + \
+???????????????????????????????????????????????CLINT_MTIMER_OFFSET) ?
?#define UX600_PLIC_ADDR????????????????????????0x8000000 ?#define UX600_PLIC_NUM_SOURCES?????????0x35platform/nuclei/ux600/platform.c +0
-0@@ -61,12 +65,21 @@ static struct plic_data plic = { ????????.num_src = UX600_PLIC_NUM_SOURCES, ?};?
platform/nuclei/ux600/platform.c +10
-2-static struct clint_data clint = { -???????.addr = UX600_CLINT_TIMER_ADDR, +static struct aclint_mswi_data mswi = { +???????.addr = UX600_ACLINT_MSWI_ADDR, +???????.size = ACLINT_MSWI_SIZE, +???????.first_hartid = 0, +???????.hart_count = UX600_HART_COUNT, +}; + +static struct aclint_mtimer_data mtimer = { +???????.addr = UX600_ACLINT_MTIMER_ADDR, +???????.size = ACLINT_MTIMER_SIZE,????????.first_hartid = 0,
????????.hart_count =UX600_HART_COUNT,
????????.has_64bit_mmio = TRUE,
?};
+
?static u32measure_cpu_freq(u32 n)
?{
????????u32start_mtime,delta_mtime;platform/nuclei/ux600/platform.c +0
-0@@ -188,12 +201,12 @@ static int ux600_ipi_init(bool cold_boot) ????????int rc;?
????????if (cold_boot) { -???????????????rc =clint_cold_ipi_init(&clint); +???????????????rc =aclint_mswi_cold_init(&mswi); ????????????????if (rc) ????????????????????????return rc; ????????}
?
-???????returnclint_warm_ipi_init(); +???????returnaclint_mswi_warm_init();
?}
?
?static intux600_timer_init(bool cold_boot)platform/nuclei/ux600/platform.c +0
-0@@ -201,12 +214,12 @@ static int ux600_timer_init(bool cold_boot) ????????int rc;?
????????if (cold_boot) {
-???????????????rc =clint_cold_timer_init(&clint, NULL); +???????????????rc =aclint_mtimer_cold_init(&mtimer, NULL); ????????????????if (rc) ????????????????????????return rc;
????????}
?
-???????returnclint_warm_timer_init(); +???????returnaclint_mtimer_warm_init();
?}
?
?const structsbi_platform_operationsplatform_ops= {platform/template/platform.c +0
-0@@ -13,14 +13,18 @@? * Include these files as needed.
? * See config.mkPLATFORM_xxxconfiguration parameters. ? */
+#include <sbi_utils/ipi/aclint_mswi.h> ?#include <sbi_utils/irqchip/plic.h>
?#include <sbi_utils/serial/uart8250.h>platform/template/platform.c +1
-1-#include <sbi_utils/sys/clint.h> +#include <sbi_utils/timer/aclint_mtimer.h> ?
?#define PLATFORM_PLIC_ADDR?????????????0xc000000 ?#define PLATFORM_PLIC_NUM_SOURCES??????128 ?#define PLATFORM_HART_COUNT????????????4
?#define PLATFORM_CLINT_ADDR????????????0x2000000platform/template/platform.c +3
-0+#define PLATFORM_ACLINT_MSWI_ADDR ??????PLATFORM_CLINT_ADDR +#define PLATFORM_ACLINT_MTIMER_ADDR ????(PLATFORM_CLINT_ADDR + \ +??????????????????????????????????????? CLINT_MTIMER_OFFSET)?#define PLATFORM_UART_ADDR?????????????0x09000000 ?#define PLATFORM_UART_INPUT_FREQ???????10000000 ?#define PLATFORM_UART_BAUDRATE?????????115200
platform/template/platform.c +0
-0@@ -30,8 +34,16 @@ static struct plic_data plic = { ????????.num_src = PLATFORM_PLIC_NUM_SOURCES, ?};?
platform/template/platform.c +10
-2-static struct clint_data clint = { -???????.addr = PLATFORM_CLINT_ADDR, +static struct aclint_mswi_data mswi = { +???????.addr = PLATFORM_ACLINT_MSWI_ADDR, +???????.size = ACLINT_MSWI_SIZE, +???????.first_hartid = 0, +???????.hart_count = PLATFORM_HART_COUNT, +}; + +static struct aclint_mtimer_data mtimer = { +???????.addr = PLATFORM_ACLINT_MTIMER_ADDR, +???????.size = ACLINT_MTIMER_SIZE,????????.first_hartid = 0,
????????.hart_count =PLATFORM_HART_COUNT,
????????.has_64bit_mmio = TRUE,platform/template/platform.c +0
-0@@ -88,14 +100,14 @@ static int platform_ipi_init(bool cold_boot) ?{ ????????int ret;?
-???????/* Example if the generic CLINT driver is used */ +???????/* Example if the generic ACLINT driver is used */ ????????if (cold_boot) {
-???????????????ret =clint_cold_ipi_init(&clint); +???????????????ret =aclint_mswi_cold_init(&mswi); ????????????????if (ret) ????????????????????????return ret;
????????}
?
-???????returnclint_warm_ipi_init(); +???????returnaclint_mswi_warm_init();
?}
?
?/*platform/template/platform.c +0
-0@@ -105,14 +117,14 @@ static int platform_timer_init(bool cold_boot) ?{ ????????int ret;?
-???????/* Example if the generic CLINT driver is used */ +???????/* Example if the generic ACLINT driver is used */ ????????if (cold_boot) {
-???????????????ret =clint_cold_timer_init(&clint, NULL); +???????????????ret =aclint_mtimer_cold_init(&mtimer, NULL); ????????????????if (ret) ????????????????????????return ret;
????????}
?
-???????returnclint_warm_timer_init(); +???????returnaclint_mtimer_warm_init();
?}
?
?/*Signature · 1 line
2.25.1