summaryrefslogtreecommitdiff
path: root/lib/sbi_ipi.c
AgeCommit message (Collapse)AuthorFilesLines
2019-06-19lib: Move sbi core library to lib/sbiAtish Patra1-153/+0
Signed-off-by: Atish Patra <atish.patra@wdc.com> Acked-by: Anup Patel <anup.patel@wdc.com>
2019-05-24lib: Handle page/access fault caused by unpriv load/storeAnup Patel1-4/+7
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: Factor-out TLB management from IPI managementAnup Patel1-188/+15
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 Patel1-12/+54
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-3/+15
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-04-24all: run clang-format and update checked-in filesOlof Johansson1-33/+34
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-10lib: Optimize TLB flush IPIsAtish Patra1-0/+73
Simulatenous requests for tlbflush IPIs can have overlapping address ranges. Ignore if address range is same or within already existing fifo entries. Update the tlb flush info in fifo directly if the one of the existing entry lies within the new flush request. Delete all entries if flush all request is recieved for the vma. Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-04-03lib: More improvements to sbi_fifoAnup Patel1-2/+2
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 Patra1-15/+31
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-01include: Rename sbi_unpriv.h to riscv_unpriv.hAnup Patel1-1/+1
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-1/+1
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-14lib: Fix full tlb flush behaviorAtish Patra1-10/+15
Currently, global page mappings are not flushed if start and size arguments are zero. Flush entire TLB if both size and start argument is passed as zero. Fixes : 90cb491 (lib: Implement sfence.vma correctly) Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-03-12lib: Implement sfence.vma correctly.Atish Patra1-5/+66
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-3/+5
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-2/+2
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-02-18lib: Fix mask shift in sbi_ipi_send_many()Anup Patel1-1/+1
The mask shift in for-loop of sbi_ipi_send_many() is broken with commit 918c1354b75c74b62f67c4e929551d643f035443 ("lib: Improve delivery of SBI_IPI_EVENT_HALT") This patch fix it. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-02-18lib: Fix small typo on sbi_ipi.cNick Kossifidis1-1/+1
2019-02-18lib: Improve delivery of SBI_IPI_EVENT_HALTNick Kossifidis1-13/+34
When sbi_ipi_send_many gets called with the current hartid included on pmask (or when pmask is NULL), and we send a HALT event, since the for loop works sequentially over all hartids on the mask, we may send a HALT event to the current hart before the loop finishes. So we will halt the current hart before it can deliver a HALT IPI to the rest and some harts will remain active. Make sure we send an IPI to the current hart after we've finished with everybody else. Signed-off-by: Nick Kossifidis <mick@ics.forth.gr>
2019-02-14lib: Use CSR_<FOO> instead of <foo> for csr_*()Atish Patra1-4/+4
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-23include: Rename ipi_inject() to ipi_send() for sbi_platformAnup Patel1-1/+1
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-23lib: Remove source_hart and hartid parameter from IPI callbacksAnup patel1-8/+9
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-22lib: Allow sending IPI to self.Atish Patra1-1/+1
S-mode software may send IPI to self. For example, tlbflush may be executed for the same hart. Let the hart send IPI to itself. It's an overhead but doesn't break anything. However, if we don't allow it, it breaks if S-mode keep sending IPIs. Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-01-22lib: Fix ipi type updateAtish Patra1-16/+27
IPIs are updated in scratch space by source hart. However, different harts or same hart may want to send different IPIs before previous IPI was read by the target hart. Currently, previous IPI type is overwritten in that case. Use atomic bit set/clear operations to update IPIs. Signed-off-by: Atish Patra <atish.patra@wdc.com>
2018-12-27lib: Simplify sbi_platform ipi_init() hooksAnup Patel1-7/+3
Instead of having separate ipi_init() hooks for cold and warm boot, this patch updates struct sbi_platform to have just one ipi_init() hook. The type of boot (cold or warm) is now a boolean flag parameter for the updated ipi_init() hook. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2018-12-22Introduce hart disabled parameter in platform.Atish Patra1-1/+1
As of now, uboot doesn't have support for SMP. Moreover, unleashed board has a E51 hart which doesn't not support S mode. We should only boot only 1 non-zero hart. Signed-off-by: Atish Patra <atish.patra@wdc.com>
2018-12-11Initial commit.Anup Patel1-0/+82
Signed-off-by: Anup Patel <anup.patel@wdc.com>