diff options
author | Atish Patra <atish.patra@wdc.com> | 2020-05-10 02:47:25 +0300 |
---|---|---|
committer | Anup Patel <anup@brainfault.org> | 2020-05-10 07:29:24 +0300 |
commit | 13ca20d8df3b402d12e5701c651a53409db167d8 (patch) | |
tree | c7afbf73b0047ab7534379f64f465c86ea1fcea6 | |
parent | aef9a60d521a7810557d1caf826311bc349691ac (diff) | |
download | opensbi-13ca20d8df3b402d12e5701c651a53409db167d8.tar.xz |
lib: Create a separate math helper function file
There may be few common mathematics helper functions which can be used
anywhere in OpenSBI project.
Add a separate math helper function file to add these functions.
Signed-off-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
-rw-r--r-- | include/sbi/sbi_math.h | 15 | ||||
-rw-r--r-- | lib/sbi/objects.mk | 1 | ||||
-rw-r--r-- | lib/sbi/sbi_hart.c | 14 | ||||
-rw-r--r-- | lib/sbi/sbi_math.c | 23 |
4 files changed, 40 insertions, 13 deletions
diff --git a/include/sbi/sbi_math.h b/include/sbi/sbi_math.h new file mode 100644 index 0000000..564fd58 --- /dev/null +++ b/include/sbi/sbi_math.h @@ -0,0 +1,15 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2020 Western Digital Corporation or its affiliates. + * + * Authors: + * Atish Patra <atish.patra@wdc.com> + */ + +#ifndef __SBI_MATH_H__ +#define __SBI_MATH_H__ + +unsigned long log2roundup(unsigned long x); + +#endif diff --git a/lib/sbi/objects.mk b/lib/sbi/objects.mk index 190ee12..31aaad5 100644 --- a/lib/sbi/objects.mk +++ b/lib/sbi/objects.mk @@ -24,6 +24,7 @@ libsbi-objs-y += sbi_ecall_vendor.o libsbi-objs-y += sbi_emulate_csr.o libsbi-objs-y += sbi_fifo.o libsbi-objs-y += sbi_hart.o +libsbi-objs-y += sbi_math.o libsbi-objs-y += sbi_hfence.o libsbi-objs-y += sbi_hsm.o libsbi-objs-y += sbi_illegal_insn.o diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index 00e593f..b789900 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -15,6 +15,7 @@ #include <sbi/sbi_console.h> #include <sbi/sbi_error.h> #include <sbi/sbi_hart.h> +#include <sbi/sbi_math.h> #include <sbi/sbi_platform.h> extern void __sbi_expected_trap(void); @@ -121,19 +122,6 @@ void sbi_hart_delegation_dump(struct sbi_scratch *scratch) #endif } -unsigned long log2roundup(unsigned long x) -{ - unsigned long ret = 0; - - while (ret < __riscv_xlen) { - if (x <= (1UL << ret)) - break; - ret++; - } - - return ret; -} - void sbi_hart_pmp_dump(struct sbi_scratch *scratch) { const struct sbi_platform *plat = sbi_platform_ptr(scratch); diff --git a/lib/sbi/sbi_math.c b/lib/sbi/sbi_math.c new file mode 100644 index 0000000..8ba0831 --- /dev/null +++ b/lib/sbi/sbi_math.c @@ -0,0 +1,23 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2020 Western Digital Corporation or its affiliates. + * + * Common helper functions used across OpenSBI project. + * + * Authors: + * Atish Patra <atish.patra@wdc.com> + */ + +unsigned long log2roundup(unsigned long x) +{ + unsigned long ret = 0; + + while (ret < __riscv_xlen) { + if (x <= (1UL << ret)) + break; + ret++; + } + + return ret; +} |