summaryrefslogtreecommitdiff
path: root/include/sbi/sbi_scratch.h
AgeCommit message (Collapse)AuthorFilesLines
2024-11-11include: sbi: Fix typo errorZhang RunMin1-1/+1
Fix typo in comments describing SBI_SCRATCH_FW_HEAP_SIZE_OFFSET. Signed-off-by: Zhang RunMin <runmin.zhang@ingenic.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-10-28include: sbi: Optimize reads of mhartid and mscratchSamuel Holland1-1/+1
csr_read() is marked as volatile and clobbering memory, which is generally the safe thing to do. However, these two CSRs do not have any side effects, and the values returned do not change between calls. The compiler can generate better code if we allow it to reorder calls to these functions and cache the return value. Introduce csr_read_relaxed() for this use case. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-09-25include: sbi: Store the hart index in struct sbi_scratchSamuel Holland1-1/+9
This is a more efficient way to get the index of the current hart than calling a function to loop through the hartindex -> hartid lookup table. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-03-19include: sbi: Add trap_context pointer in struct sbi_scratchAnup Patel1-3/+12
To track nested traps, the struct sbi_scratch needs a pointer the current trap context so add trap_context pointer in struct sbi_context. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Samuel Holland <samuel.holland@sifive.com> Tested-by: Samuel Holland <samuel.holland@sifive.com>
2024-03-19lib: sbi: Remove sbi_trap_exit() and related codeAnup Patel1-12/+3
Over the years, no uses of sbi_trap_exit() have been found so remove it and also remove related code from fw_base.S and sbi_scratch.h. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Samuel Holland <samuel.holland@sifive.com> Tested-by: Samuel Holland <samuel.holland@sifive.com>
2023-09-24lib: sbi: Remove sbi_scratch_last_hartid() macroAnup Patel1-6/+0
The sbi_scratch_last_hartid() macro is not of much use on platforms with really sparse hartids so let us replace use of this macro with other approaches. Signed-off-by: Anup Patel <apatel@ventanamicro.com>
2023-09-24lib: sbi: Introduce HART index in sbi_scratchAnup Patel1-3/+42
We introduce HART index and related helper functions in sbi_scratch where HART index is contiguous and each HART index maps to a physical HART id such that 0 <= HART index and HART index < SBI_HARTMASK_MAX_BITS. The HART index to HART id mapping follows the index2id mapping provided by the platform. If the platform does not provide index2id mapping then identity mapping is assumed. Signed-off-by: Anup Patel <apatel@ventanamicro.com>
2023-06-05lib: sbi: Print scratch size and usage at boot timeAnup Patel1-0/+3
The scratch space being a scarce resource so let us print it's size and usage at boot time. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
2023-06-05platform: Allow platforms to specify heap sizeAnup Patel1-10/+18
We extend struct sbi_platform and struct sbi_scratch to allow platforms specify the heap size to the OpenSBI firmwares. The OpenSBI firmwares will use this information to determine the location of heap and provide heap base address in per-HART scratch space. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
2023-06-05include: sbi_scratch: Add helper macros to access data typeAnup Patel1-0/+17
Reading and writing a data type in scratch space is a very common use-case so let us add related helper macros in sbi_scratch.h. Signed-off-by: Anup Patel <apatel@ventanamicro.com>
2023-01-23firmware: Add RW section offset in scratchHimanshu Chauhan1-10/+14
Add the RW section offset, provided by _fw_rw_offset symbol, to the scratch structure. This will be used to program separate pmp entry for RW section. Signed-off-by: Himanshu Chauhan <hchauhan@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-10-23include: sbi: Fix typo in commentYu Chien Peter Lin1-1/+1
%s/Priviledge/Privilege Signed-off-by: Yu Chien Peter Lin <peterlin@andestech.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-03-27include: Use static asserts for SBI_SCRATCH_xxx_OFFSET definesXiang W1-0/+60
Add static detection to prevent the modification of struct sbi_scratch from forgetting the modification of SBI_SCRATCH_xxx_OFFSET Signed-off-by: Xiang W <wxjstz@126.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-01-21lib: fix pointer of type 'void *' used in arithmeticJukka Laitinen1-2/+2
Using "void *" in arithmetic causes errors with strict compiler settings: "error: pointer of type 'void *' used in arithmetic [-Werror=pointer-arith]" Avoid these by calculating on "char *" where 1-byte data size is assumed. Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae> Reviewed-by: Dong Du <Dd_nirvana@sjtu.edu.cn> Reviewed-by: Xiang W <wxjstz@126.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2021-06-02lib: sbi_scratch: remove owner from sbi_scratch_alloc_offsetHeinrich Schuchardt1-1/+1
The parameter owner of function sbi_scratch_alloc_offset() is never used. The scratch memory is small. We should not use it for debug information in future. Hence eliminate the parameter. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Xiang W <wxjstz@126.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2021-03-22include: headers: Replace __ASSEMBLY__ with __ASSEMBLER__Marouene Boubakri1-1/+1
GCC has already a predefined macro __ASSEMBLER__ therefore, it can be used without the need to define a new flag with -D__ASSEMBLY__. This is useful when adding the library to projects having a build system such one can build without the need to make changes. THe build system does not use the Makefile in the sources tree. Signed-off-by: Marouene Boubakri <marouene.boubakri@nxp.com> Signed-off-by: Anup Patel <anup.patel@wdc.com>
2021-01-15include: sbi: No need to pack struct sbi_scratchAnup Patel1-1/+1
All members in struct sbi_scrach are of machine word size so no need to pack this structure. This also allows GCC to generate more optimized instruction sequence when accessing members of struct sbi_scratch. Reported-by: Paul Campbell <taniwha@gmail.com> Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2021-01-07lib: sbi: Introduce sbi_trap_exit() APIAnup Patel1-3/+7
We introduce sbi_trap_exit() API which can help non-firmware (i.e. generic or platform) code to force exit trap/interrupt handling and resume execution at context pointed by parameter "const struct sbi_trap_regs *regs". This new sbi_trap_exit() API will help Keystone Enclave project to resume execution of enclave from custom SBI call handler. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-10-02lib: sbi_scratch: typo scatchHeinrich Schuchardt1-1/+1
%s/scatch/scratch Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-03-28lib: sbi_scratch: Introduce sbi_scratch_last_hartid() APIAnup Patel1-0/+6
The patch adds sbi_scratch_last_hartid() API which returns last HART id having a scratch space. We can use this new API to optimize places where we iterate over HART id from 0 to SBI_HARTMASK_MAX_BITS. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-19include: Simplify HART id to scratch macroAnup Patel1-1/+1
This patch simplify HART id to scratch macro as follows: 1. Remove current "scratch" pointer argument because now we use HART id to scratch table 2. Rename sbi_hart_id_to_scratch() to sbi_hartid_to_scratch() to have macro name consistent with the name of callback in struct sbi_scratch Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-19lib: sbi_scratch: Introduce HART id to scratch tableAnup Patel1-2/+6
Instead of calling hartid_to_scratch() callback every time when we want sbi_scratch pointer from HART id, we create a table of sbi_scratch pointers and use that to get sbi_scratch pointer. As a result of HART id to scratch table, the conversion of HART id to sbi_scratch pointer is just 2-3 instructions which was 9 instructions previously. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-13include: Make sbi_hart_id_to_scratch() as macroAnup Patel1-0/+6
The sbi_hart_id_to_scratch() just forwards call to firmware specific hartid_to_scratch() callback so we make sbi_hart_id_to_scratch() as macro in sbi_scratch.h instead of regular function in sbi_hart.c. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
2020-03-10lib: sbi: Fix coding style issuesBin Meng1-1/+2
This fixes various coding style issues found in the SBI codes. No functional changes. Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-03-08include: sbi_scratch: Set per-HART scratch size to 4KBAnup Patel1-2/+2
Currently, the per-HART scratch size is 256 bytes on RV32 and 512 bytes on RV64. This patch set per-HART scratch size to 4KB (4096 bytes) for both RV32 and RV64 so that we don't run-out of scratch space anytime soon. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-01-22lib: Introduce sbi_tlb_fifo_request() APIAnup Patel1-1/+0
Instead of directly calling sbi_ipi_send_many(), we introduce sbi_tlb_fifo_request() for halting a set of HARTs. This way in future we can assign any IPI event number for remote FENCE within sbi_tlb.c only. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-01-22include: Typo fix in comment for SBI_SCRATCH_SIZE defineAnup Patel1-1/+1
This patch fixes a minor typo in comment for SBI_SCRATCH_SIZE define. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2019-08-09lib: Introduce sbi_dprintf() APIAnup Patel1-0/+2
This patch introduces new sbi_dprintf() API for runtime debug prints. The sbi_dprintf() will print to console for a given HART only when SBI_SCRATCH_DEBUG_PRINTS option in enabled in sbi_scratch for this HART. We can now add debug prints using sbi_dprintf() at important places in OpenSBI sources. These debug prints will only show up when previous booting stage or compile time parameter sets the SBI_SCRATCH_DEBUG_PRINTS option in scratch space. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
2019-05-24lib: Add a simple brain-dead allocator to manage extra scratch spaceAnup Patel1-17/+16
We have extra space above scratch space (sbi_scratch) which we are currently using to manage per-HART IPI data and TLB request management. In future, more parts of OpenSBI will use the extra scratch space so it will become difficult to manage extra scratch space using just defines and macros. This patch adds a simple brain-dead allocator to manage extra scratch space. This allocator never expects anything to be free-ed hence it keeps incrementing to next allocation offset until it runs-out of space. In future, we can have more sophisticated allocator which will allow us to re-claim free-ed space and also allows us to track owner of allocated space. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2019-04-24all: run clang-format and update checked-in filesOlof Johansson1-11/+11
Noisy commit, no functional changes. Generated with an current upstream clang-format and: clang-format -i $(find . -name \*.[ch]) Signed-off-by: Olof Johansson <olof@lixom.net>
2019-04-24all: Annotate some tables to have clang-format leave them aloneOlof Johansson1-0/+4
One of the shortcomings of clang-format is that it doesn't allow for aligned define tables, which is used for a number of constants. Add annotation to disable the automatic formatting where needed. Signed-off-by: Olof Johansson <olof@lixom.net>
2019-04-03lib: Use a fifo to keep track of sfence related IPIs.Atish Patra1-4/+10
Currently, there is no provision for tracking multiple IPIs sent to a single hart at the same time by different harts. Use a fifo manage the outstanding requests. While dequeueing, read all the entries once, because we have only 1 bit to track the type of IPI. Once the queue is full, busy wait until the there is space available in queue. This is not the most elegant approach. It should be changed in favor of a wakeup event once available in opensbi. Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-04-03lib: Increase the scratch space to 512 bytes.Atish Patra1-1/+1
Currently scratch space per hart is 256 bytes. Increase it to 512 bytes to accomodate ipi queue. Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-03-29lib: Disable the boot prints if SBI_SCRATCH_NO_BOOT_PRINTS is setBin Meng1-0/+6
Use the newly introduced "options" in "struct sbi_scratch" to conditionally disable the boot prints. Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
2019-03-29firmware: Introduce "options" in "struct sbi_scratch"Bin Meng1-0/+4
Introduce "options" in "struct sbi_scratch" and firmware can update it based on optional compile time flags before calling sbi_init(). Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
2019-03-12lib: Implement sfence.vma correctly.Atish Patra1-4/+6
Currently, OpenSBI doesn't distinguish between sfence.vma and sfence.vm asid calls. Moreover, it ignores the page ranges and just flush entire TLB everytime. Fix the sfence implementation by keeping all the tlb flush info in scratch area. The relevant Linux kernel code was added by https://patchwork.kernel.org/project/linux-riscv/list/?series=89695 However, this patch is backward compatible with older version kernel that doesn't have the above patches as well. Fixes #87 Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-03-10lib: Create a sbi_ipi_data structureAlistair Francis1-7/+16
Create a sbi_ipi_data structure that holds unpacked IPI information. At the same time remove ipi_type from the sbi_scratch struct and use a fixed offset to access it. This structure fits in behind the sbi_scratch structure. This fixes https://github.com/riscv/opensbi/issues/81 Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2019-02-20firmware: Improve low-level trap handler for M-mode to M-mode trapsAnup Patel1-0/+4
This patch extends our low-level trap handler in fw_base.S for handling M-mode to M-mode traps without overwritting stack. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-02-14lib: Use CSR_<FOO> instead of <foo> for csr_*()Atish Patra1-1/+1
Some older toolchains may not have all the csr's defined. Update all the csr functions to use the CSR_ #define values instead of the toolchain defined values. Suggested-by: Olof Johansson <olof@lixom.net> Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-01-24all: Update copyright header in all filesAnup patel1-3/+3
This patch updates copyright header in all files as follows: 1. Makes "SPDX-License-Identifier: BSD-2-Clause" as first line 2. Change copyright year to 2019 for Western Digital Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-01-16include: Add documentation for sbi_trap_regs and friendsAnup Patel1-1/+1
This patch adds doxygen style documentation for struct sbi_trap_regs and related macros/defines/functions. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-01-16include: Add documentation for sbi_scratch and friendsAnup Patel1-0/+22
This patch adds doxygen style documentation for struct sbi_scratch and related helper macros/defines. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-01-03include: Remove redundant tmp0 from struct sbi_scratchAnup Patel1-11/+9
The tmp0 member was added in struct sbi_scratch to assist register save/restore at time of trap handling. This tmp0 is not unsed any more hence removing it. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-01-02include: Move RISCV_SCRATCH_xyz defines to sbi_scratch.hAnup Patel1-0/+17
The struct sbi_scratch related defines RISCV_SCRATCH_xyz should be in sbi_scratch.h so that we can keep these defines in-sync with changes in struct sbi_scratch. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2018-12-11Initial commit.Anup Patel1-0/+35
Signed-off-by: Anup Patel <anup.patel@wdc.com>