summaryrefslogtreecommitdiff
path: root/include
AgeCommit message (Collapse)AuthorFilesLines
2019-05-24lib: Handle page/access fault caused by unpriv load/storeAnup Patel3-6/+20
The unpriv load/store instruction from M-mode can cause page/access fault to M-mode if S-mode page table did not have mappings OR it did not have PMP access permission. To tackle this, we redirect trap back to S-mode if unpriv load/store instruction traps in M-mode. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2019-05-24lib: Add per-HART trap info pointerAnup Patel1-1/+5
This patch adds per-HART trap info pointer which can be used to communicate trap information to sbi_trap_handler(). Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2019-05-24include: Make unprivilege load/store functions as non-inline functionsAnup Patel1-102/+20
Currently, the unprivilege load/store functions are inline functions. We will be extending these functions to track whether a page/access fault occurs when we execute unprivilege load/store instruction. To make things simpler and debugable, we reduce number of places which can potentially generate a page/access fault by making all unprivilege load/store functions as regular (non-inline) functions. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2019-05-24lib: Factor-out TLB management from IPI managementAnup Patel3-19/+48
This patch factor-out TLB management from IPI management to separate sources sbi_tlb.c and sbi_tlb.h. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2019-05-24lib: Add a simple brain-dead allocator to manage extra scratch spaceAnup Patel2-17/+17
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-05-21lib: Flush everything when remote TLB flush range is too largeAnup Patel1-1/+3
On latest Linux kernel (i.e. 5.2-rc1), we get large TLB flush request for user space addresses (typically, start=x and end=-1). This is caused by Linux kernel commit a21344dfc6 ("riscv: fix sbi_remote_sfence_vma{,_asid}"). It's not practical to execute large number of sfence instructions for a large TLB flush range because it takes too much time and eventually causes CPU stall in Linux kernel. This patch addresses above issue by upgrading TLB flush range to TLB flush all whenever TLB flush range is greater than 1GB. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2019-05-10firmware: Add fw_dynamic firmwareAnup Patel1-0/+61
This patch provides first-cut implementation of fw_dynamic firmware. As compared to fw_jump and fw_payload, the fw_dynamic obtains next address, next mode and OpenSBI options from struct fw_dynamic_info. The previous booting stage can create struct fw_dynamic_info in memory and pass address of struct fw_dynamic_info in 'a2' register. Also, the struct fw_dynamic_info has versioning as well so changes to the struct fw_dynamic_info can be done in a backward compatible manner. 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 Johansson21-277/+297
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 Johansson11-0/+44
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-10lib: Provide a lock enabled iteration of fifo.Atish Patra1-0/+10
Implement a lock enabled iteration for fifo so that caller can determine if next entry can be skipped or any existing entries in fifo can be updated before enqueue. Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-04-06lib: Fix the ecall macro definitionsAlistair Francis1-2/+2
Fix the ECALL definitions to matc the latest information in the privlidge spec table 5.5. Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2019-04-03lib: Pack struct sbi_fifoAnup Patel1-8/+5
This patch reduces memory consumed by struct sbi_fifo by droping redundant "head" member and using u16 in-place of "unsigned long". Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-04-03lib: More improvements to sbi_fifoAnup Patel2-7/+12
This patch does following improvements to sbi_fifo: 1. Use valid SBI_Exxxx error codes instead of -1 2. The sbi_fifo_is_full() and sbi_fifo_is_empty() did not acquire qlock before accessing head and tail hence fixed it 3. Added avail member for ease in debugging and simplifying head/tail updates. Due to above changes size of sbi_fifo changes from 48 bytes to 56 bytes. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-04-03lib: Use a fifo to keep track of sfence related IPIs.Atish Patra2-4/+13
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-04-03lib: Introduce a tlb info type.Atish Patra1-0/+7
Add a tlb info to distinguish between different type of tlb flush request pending. Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-04-03lib: Add a fifo implementation.Atish Patra1-0/+32
Implement a fifo to accomodate outstanding IPIs for a specific hart at the same time. Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-04-01include: Make mstatus parameter optional for get_insn()Anup Patel1-3/+4
The mstatus parameter of get_insn() is used to return MSTATUS CSR value which get_insn() saw. Most of the get_insn() callers don't use the value returned in mstatus so this patch makes mstatus parameter optional for get_insn(). Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-04-01include: Rename sbi_unpriv.h to riscv_unpriv.hAnup Patel1-2/+2
The sbi_unpriv.h has quite a few load_xyz() and store_xyz() helper routines based on RISC-V inline assembly for unpriviledged accesses from M-mode. These helper routines are similar to helper routines present in riscv_locks.h, riscv_io.h, and riscv_atomic.h so let's rename sbi_unpriv.h to riscv_unpriv.h. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-04-01lib: Remove unused mepc arg from load_xyz() and store_xyz() functionsAnup Patel1-17/+15
This patch removes unused mepc arg from load_xyz() and store_xyz() unpriviledge access functions. Signed-off-by: Anup Patel <anup.patel@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 Patra3-6/+24
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-03-06platform: Make the `platform` read-onlyXiang Wang1-25/+27
platform should be a read-only variable, if it is placed in the data segment, it may be exploited. Signed-off-by: Xiang Wang <wxjstz@126.com>
2019-03-05lib:platform: Fix sbi_getc return type.Atish Patra2-4/+4
As per the current SBI specification, sbi_getc should return an int instead of char. In case of FIFO is empty, return -1 as per the specification. Reported-by: Sergi Granell <xerpi.g.12@gmail.com> Suggested-by:Thadeu Lima de Souza Cascardo <cascardo@cascardo.eti.br> Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-02-26include: Bump-up version to 0.3Anup Patel1-1/+1
This patch updates OpenSBI version to 0.3 as part of release preparation. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-02-22include: Bump-up version to 0.2Anup Patel1-1/+1
This patch increases OpenSBI version to 0.2. Signed-off-by: Anup Patel <anup.patel@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-20include: Add PRILX define to help print unsigned longAnup Patel1-0/+2
The unsigned long is always machine word size. This means it is 4 bytes on 32bit system and 8 bytes on 64bit system. This patch adds PRILX define for sbi_printf() which will help us print unsigned long without worrying whether it is 32bit or 64bit system. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-02-14lib: Use CSR_<FOO> instead of <foo> for csr_*()Atish Patra4-15/+23
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-02-08firmware: Use lw instead of lwu for 32-bit architecturesAlistair Francis1-0/+8
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2019-02-05riscv_asm.h: Use CSR_<FOO> instead of <foo> for csr_read()Olof Johansson1-3/+5
Some toolchains might not have all the CSRs available (as seen with GCC 7.2). So, instead use the defined CSR_ values. Signed-off-by: Olof Johansson <olof@lixom.net>
2019-01-25include: Add separate header for OpenSBI versionAnup Patel1-0/+16
Currently, the OpenSBI version is in top-level Makefile so firmware linking to OpenSBI static library have no-way to know OpenSBI version. This patch moves OpenSBI version from top-level Makefile to sbi/sbi_version.h header which provides OPENSBI_VERSION_MAJOR and OPENSBI_VERSION_MINOR defines. NOTE: the SBI spec (or SBI ecall interface) version is different. The SBI spec version is provided by functions sbi_ecall_version_major() and sbi_ecall_version_minor(). Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-01-24all: Update copyright header in all filesAnup patel27-80/+80
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-23include: Use TRUE/FALSE as return values in sbi_platform_hart_disabled()Anup Patel1-2/+2
The sbi_platform_hart_disabled() returns bool hence explicitly return TRUE or FALSE instead of 1 or 0. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-01-23include: Rename ipi_inject() to ipi_send() for sbi_platformAnup Patel1-7/+7
For better naming, we rename ipi_inject() to ipi_send() in struct sbi_platform. We also replace term "inject" with "send" in all related places. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-01-23include: Drop MMIO from SBI_PLATFORM_HAS_MMIO_TIMER_VALUEAnup Patel1-6/+6
It is not necessary that platform has MMIO-based timer value register. It can also have some custom (implementation specific) CSR for timer value. This patch renames SBI_PLATFORM_HAS_MMIO_TIMER_VALUE to SBI_PLATFORM_HAS_TIMER_VALUE to imply "platform timer value" instead of "mmio timer value". Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-01-23include: Update documentation of sbi_platform after callback cleanupAnup Patel1-16/+16
The prototypes of sbi_platform callbacks have changed hence we update related documentation. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-01-23lib: Remove target_hart and hartid parameter from TIMER callbacksAnup Patel2-19/+12
The target_hart and hartid paramter of TIMER callbacks is not required because it always current hartid which can be obtained using sbi_current_hartid() API. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-01-23lib: Remove hartid parameter from IRQCHIP callbacksAnup Patel1-4/+3
The hartid parameter in IRQCHIP callbacks of sbi_platform is not required because current hartid can be determined using sbi_current_hartid() API. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-01-23lib: Remove source_hart and hartid parameter from IPI callbacksAnup patel2-15/+13
The source_hart and hartid parameter is really not required in IPI callbacks of sbi_platform because current hartid can always be obtained by calling sbi_current_hartid() API. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-01-23lib: Remove hartid paramter from early_init() and final_init() callbacksAnup Patel2-15/+11
We simplify early_init() and final_init() callbacks of sbi_platform by removing "hartid" parameter. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-01-22lib: Add doxygen style documentation for sbi_platformAnup Patel1-9/+234
This patch adds doxygen style documenation for struct sbi_platform and related functions/macros/defines. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-01-22lib: Add atomic bit set/clear operations.Atish Patra4-0/+130
Add addtional functionlities for set/clear bits atomically. Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-01-21sbi: Add ecall helpersDamien Le Moal1-1/+10
Define sbi_ecall_console_puts() using sbi_ecall_console_putchar() renamed as sbi_ecall_console_putc() and remove the hardcoded version of the same funtion in the test payload code. Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
2019-01-18platform: Add libfdt support.Atish Patra1-1/+0
Some of the platform (i.e. SiFive FU540) requires Device Tree modification before it is passed to higher stages. Add libfdt support now to help this process. Libfdt should only be included per platform basis. Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-01-16include: Add documentation for sbi_trap_regs and friendsAnup Patel2-2/+74
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 __packed define for packed structuresAnup Patel1-0/+1
This patch adds __packed define for specifying packed attribute of structures. 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>