summaryrefslogtreecommitdiff
path: root/lib
AgeCommit message (Collapse)Author
2024-09-26lib: sbi: Update sbi_domain_is_assigned_hart() to take a hart indexSamuel Holland
This removes redundant hartid to hartindex conversions from four call sites and provides a net reduction in code size. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-09-26lib: sbi: Use sbi_hartmask in sbi_hsm_hart_interruptible_mask()Samuel Holland
This removes several hartid/hartindex conversions, as well as two loops through the mask for broadcast IPIs. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-09-26lib: sbi: Update __sbi_hsm_hart_get_state() to take a hart indexSamuel Holland
This removes some hartindex conversions in sbi_system_suspend(), but is mostly intended to support refactoring sbi_hsm_hart_interruptible_mask() to work exclusively with struct sbi_hartmask. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-09-26lib: sbi: Simplify halt broadcast logicSamuel Holland
Use the IPI .update callback to exclude the local hart. This allows reusing the normal logic for broadcasting an IPI to all active harts. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-09-26lib: sbi_ecall_legacy: Use SBI v0.2 encoding for "all harts"Samuel Holland
This simplifies the logic so that sbi_hsm_hart_interruptible_mask() is only called from one place (sbi_ipi_send_many()). A minor functional change is that the legacy functions can now affect more than XLEN harts when targeting all harts. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-09-25lib: utils/irqchip: Look up IMSIC data by hart indexSamuel Holland
This avoids needing to map a hartid to a hart index. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-09-25lib: sbi_sse: Cache the event's target hart indexSamuel Holland
This avoids needing to map the target hartid to a hart index when enabling or disabling an event, and provides a net code size reduction. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-09-25lib: sbi: Use current_hartindex() where possibleSamuel Holland
This avoids calls to the expensive sbi_hartid_to_hartindex() function and also makes the firmware smaller. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-09-25lib: sbi_init: Remove obsolete hartid checkSamuel Holland
This check has been obsolete since commit c51f02cf143b ("include: sbi_platform: Introduce HART index to HART id table"). It originally filtered out harts that were disabled in the FDT, but those harts are omitted from the hart_index2id table, so they will hang in fw_base.S after the "Find HART index" loop and never enter sbi_init(). Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-09-23lib: sbi: fwft: implement landing pad and shadow stack fwft interfaceDeepak Gupta
Supervisor software can enable control flow integrity features for itself using fwft feature `SBI_FWFT_LANDING_PAD` and `SBI_FWFT_SHADOW_STACK`. This patch implements the mechanism to enable both these fwft. Signed-off-by: Deepak Gupta <[email protected]> Reviewed-by: Atish Patra <[email protected]> Reviewed-by: Clément Léger <[email protected]>
2024-09-23lib: sbi: sw check exception delegationDeepak Gupta
zicfiss and zicfilp introduces new exception (cause=18). Delegate this exception to S mode because cfi violations in U / S will be reported via this exception. Signed-off-by: Deepak Gupta <[email protected]> Reviewed-by: Samuel Holland <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2024-09-23lib: sbi: add zicfilp/zicfiss and elp cfi state reflect back in statusDeepak Gupta
This patch adds support to check for zicfilp / zicfiss extension. zicfilp record status of hart's ELP state in *status csr. Missing landing pad sets MPELP in mstatus. When SBI is redirecting back to S/VS/HS, SPELP is set in sstatus/vsstatus. Signed-off-by: Deepak Gupta <[email protected]> Reviewed-by: Atish Patra <[email protected]> Reviewed-by: Samuel Holland <[email protected]>
2024-09-23lib: sbi_domain_context: Fix file permissionsSamuel Holland
These C source files should not be marked as executable. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-09-23lib: sbi: Respect scounteren when emulating the time CSRSamuel Holland
This optimization creates a correctness issue, as it prevents supervisor software from restricting VS-mode or U-mode access to the time CSR for its own purposes. Closes: https://github.com/riscv-software-src/opensbi/issues/370 Fixes: ebc8ebc0f846 ("lib: sbi: Improve HPM CSR read/write emulation") Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-09-23lib: sbi: fwft: add support for SBI_FWFT_POINTER_MASKING_PMLENSamuel Holland
Add support for controlling the pointer masking mode on harts which support the Smnpm extension. This extension can only exist on harts where XLEN >= 64 bits. This implementation selects the mode with the smallest PMLEN that satisfies the caller's requested lower bound. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-09-20lib: sbi: Fix writes to emulated 32-bit htimedelta CSRSamuel Holland
Writes to the low half CSR should not affect the high half of the value. Make this separation explicit by writing to the delta in memory as two adjacent XLEN-sized values. Fixes: 1e9f88889f8b ("lib: Emulate HTIMEDELTA CSR for platforms not having TIME CSR") Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-09-20lib: sbi: Use a linked list to track domainsSamuel Holland
This removes the compile-time limit on the number of domains. It also reduces firmware size by about 200 bytes by removing the lookup table. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-08-24lib: Delete redundant `ulong`Zhang RunMin
In `csr_read_allowed` and `csr_write_allowed` macros, has already converted second param to `ulong`. So delete redundant `ulong` where uses csr_read/write_allowed macros. Signed-off-by: Zhang RunMin <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-08-24lib: utils: fdt_domain: Make opensbi-domain optional in CPU nodeGregor Haas
The domain_support.md documentation states that "the HART to domain instance assignment can be parsed from the device tree using *optional* DT property opensbi-domain in each CPU DT node". However, the current implementation does not treat this parameter as optional when determining which HARTs to assign to a freshly discovered domain from the device tree, causing an effect where every HART in the system must be explicitly assigned to a domain only if a domain is specified in the device tree. Instead, this patch simply ignores CPUs that do not specify a domain, and does not attempt to assign them into the recently discovered domain. Signed-off-by: Gregor Haas <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-08-24lib: sse: remove unused sse_inject_out() parameterClément Léger
This parameters was a remnant of a previous version, remove it now that it is unused. Signed-off-by: Clément Léger <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-08-24util: atcsmu.c: modify sbi_printf() formattingYu Chien Peter Lin
Beautify multi-line printing. Signed-off-by: Leo Yu-Chi Liang <[email protected]> Reviewed-by: Yu Chien Peter Lin <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-08-24util: atcsmu.c: fix typo "%s/hard/hart/"Leo Yu-Chi Liang
%s/hard/hart Signed-off-by: Leo Yu-Chi Liang <[email protected]> Reviewed-by: Yu Chien Peter Lin <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-08-24lib: utils/serial: Pass the FDT to fdt_serial_init()Samuel Holland
Indicate that this function does not modify the FDT blob, and deduplicate the call to fdt_get_address(). Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-08-24lib: utils/reset: Pass the FDT to fdt_reset_init()Samuel Holland
Indicate that this function does not modify the FDT blob, and deduplicate the call to fdt_get_address(). Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-08-24lib: utils/timer: Constify FDT pointers in parsing functionsSamuel Holland
Indicate that none of these functions modify the devicetree by constifying the parameter type. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-08-24lib: utils/serial: Constify FDT pointers in parsing functionsSamuel Holland
Indicate that none of these functions modify the devicetree by constifying the parameter type. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-08-24lib: utils/reset: Constify FDT pointers in parsing functionsSamuel Holland
Indicate that none of these functions modify the devicetree by constifying the parameter type. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-08-24lib: utils/regmap: Constify FDT pointers in parsing functionsSamuel Holland
Indicate that none of these functions modify the devicetree by constifying the parameter type. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-08-24lib: utils/irqchip: Constify FDT pointers in parsing functionsSamuel Holland
Indicate that none of these functions modify the devicetree by constifying the parameter type. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-08-24lib: utils/ipi: Constify FDT pointers in parsing functionsSamuel Holland
Indicate that none of these functions modify the devicetree by constifying the parameter type. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-08-24lib: utils/i2c: Constify FDT pointers in parsing functionsSamuel Holland
Indicate that none of these functions modify the devicetree by constifying the parameter type. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-08-24lib: utils/gpio: Constify FDT pointers in parsing functionsSamuel Holland
Indicate that none of these functions modify the devicetree by constifying the parameter type. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-08-24lib: utils/fdt: Constify FDT parsing functionsSamuel Holland
Distinguish between functions which modify the devicetree and those which only extract information from it. Other than the iterators in fdt_domain.c, this is a mechanical conversion. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-08-23lib: utils: fdt_domain: Use consistent device-tree address when next-arg1 is ↵Yu Chien Peter Lin
missing The diagram shown below illustrates the boot-flow involving OP-TEE OS initialization. (1)-----------+ | U-Boot SPL | +------------+ | v (2)-------------------------------------------------------------+ | OpenSBI (fw_dynamic) | | (4)------------------------+ | | | optee dispatcher driver | | +-----------------+-------^---------|-------+------------------+ M-mode | | | ---------+--[trusted domain]---+----.----+--[untrusted domain]------- S-mode | (coldboot domain) | | | v | | v (3)---------------------------+ |(5)----------------------------+ | OP-TEE OS | | | U-Boot | +----------------------------+ | +-----------------------------+ | | | v |(6)----------------------------+ | | Linux | | +-----------------------------+ As OP-TEE OS has device-tree node fixups that need to be passed through to the next boot stages, e.g. the reserved memory node: reserved-memory { #address-cells = <2>; #size-cells = <2>; ranges; optee_core@f1000000 { no-map; reg = <0x0 0xf1000000 // OP-TEE OS base address 0x0 0x01000000>; }; <...> }; Instead of using 0x0 as the default value, allow identical next-arg1 to be used by non-coldboot domain (i.e., untrusted domain) when the property is not provided. Also, update the description of next-arg1 property in the document. Signed-off-by: Yu Chien Peter Lin <[email protected]> Reviewed-by: Alvin Chang <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-08-23lib: sbi: Enhance CSR Handling in system_opcode_insnDongdong Zhang
- Completed TODO in `system_opcode_insn` to ensure CSR read/write instruction handling. - Refactored to use new macros `GET_RS1_NUM` and `GET_CSR_NUM`. - Updated `GET_RM` macro and replaced hardcoded funct3 values with constants (`CSRRW`, `CSRRS`, `CSRRC`, etc.). - Removed redundant `GET_RM` from `riscv_fp.h`. - Improved validation and error handling for CSR instructions. This patch enhances the clarity and correctness of CSR handling in `system_opcode_insn`. Signed-off-by: Dongdong Zhang <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-08-09lib: sbi: Implement aligned memory allocatorsGregor Haas
This change adds a simple implementation of sbi_aligned_alloc(), for future use in allocating aligned memory for SMMTT tables. Signed-off-by: Gregor Haas <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-08-09lib: sbi: Allocate from beginning of heap blocksGregor Haas
In the next commit, we'll add a new sbi_memalign() function. In order to allocate aligned memory, we'll sometimes need to allocate from the middle of a heap block, effectively splitting it in two. Allocating from the beginning of a heap block in the nonaligned case more closely matches this behavior, reducing the complexity of understanding the heap implementation. Signed-off-by: Gregor Haas <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-08-09lib: sbi: Support multiple heapsGregor Haas
The upcoming SMMTT implementation will require some larger contiguous memory regions for the memory tracking tables. We plan to specify the memory region for these tables as a reserved-memory node in the device tree, and then dynamically allocate individual tables out of this region. These changes to the SBI heap allocator will allow us to explicitly create and allocate from a dedicated heap tied to the table memory region. Signed-off-by: Gregor Haas <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-08-02lib: sbi: check result of pmp_get() in is_pmp_entry_mapped()Carlos López
pmp_get() may return an error if the given entry, given by the caller of is_pmp_entry_mapped(), is invalid. This results in the output parameters for pmp_get() being uninitialized. To avoid using garbage values, check the result and return early if necessary. This issue is not being hit because at the moment is_pmp_entry_mapped() is only being called from a single site with a valid hardcoded value. Signed-off-by: Carlos López <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-08-02lib: sbi: fwft: fix incorrect size passed to sbi_zalloc()Carlos López
The fwt_hart_state struct inciludes a flexible array member, so its allocation size will be that of the struct itself, plus that of each of the members in the array. When calculating this size, instead of taking the size of the struct, the size of a pointer to it was taken, which is incorrect. Luckily, this happenned to not produce memory corruption because the size of the non-flexible members of the struct is the same as the size of a pointer. Signed-off-by: Carlos López <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-08-02lib: sbi: dbtr: fix potential NULL pointer dereferencesCarlos López
In several dbtr functions, we first check that the dbtr trigger is not NULL and that its state is what we expect. However, it only makes sense to perform the second check if the dbtr trigger is not NULL. Othwerwise we will dereference a NULL pointer. Thus, change the condition so that it shortcuts to the first check if necessary. Signed-off-by: Carlos López <[email protected]> Reviewed-By: Anup Patel <[email protected]>
2024-07-24lib: sbi: Introduce an early console buffer for caching early printsAnup Patel
The console device is registered by platform only in early_init() callback so any prints before this point will be lost. Introduce an early console buffer for caching prints before platform early_init(). For crashes before platform early_init(), users can simply dump the contents of the console_early_buffer[] string using a debugger. The relative address of the console_early_buffer[] string can be found using following two commands: CONSOLE_EARLY_FIFO_ADDR=`${CROSS_COMPILE}objdump -D \ build/platform/generic/firmware/fw_dynamic.elf | \ grep "<console_early_fifo>:" | awk '{print $1}'` ${CROSS_COMPILE}objdump -R build/platform/generic/firmware/fw_dynamic.elf | \ grep $CONSOLE_EARLY_FIFO_ADDR | awk '{print $3}' Signed-off-by: Anup Patel <[email protected]> Reviewed-By: Himanshu Chauhan <[email protected]>
2024-07-24lib: sbi: Allow forceful queueing of data in sbi_fifo_enqueue()Anup Patel
Extend sbi_fifo_enqueue() to allow forceful queueing by droping data from the tail. Signed-off-by: Anup Patel <[email protected]> Reviewed-By: Himanshu Chauhan <[email protected]>
2024-07-24lib: sbi: Optimize fifo enqueue/dequeue for basic data typesAnup Patel
Don't use sbi_memcpy() for basic data types in fifo enqueue/dequeue instead use direct type-cast and assignment. Signed-off-by: Anup Patel <[email protected]> Reviewed-By: Himanshu Chauhan <[email protected]>
2024-07-24lib: sbi: Remove sbi_console_init() and console_init() platform callbackAnup Patel
Now that all platforms have been updated to initialize serial console device in early_init(), the sbi_console_init() and console_init() platform callback are redundant hence remove them. Signed-off-by: Anup Patel <[email protected]> Reviewed-By: Himanshu Chauhan <[email protected]>
2024-07-24lib: sbi_hsm: Save/restore menvcfg only when it existsSamuel Holland
Attempting to access the menvcfg CSR raises an illegal instruction exception on hardware which implements Sm1p11 or older. Fixes: e9ee9678ba50 ("lib: sbi: fwft: add support for SBI_FWFT_PTE_AD_HW_UPDATING") Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-07-23lib: utils/fdt: Add support for parsing riscv,isa-extensionsConor Dooley
A new property has been added, with an extensive rationale at [1], that can be used in place of "riscv,isa" to indicate what extensions are supported by a given platform that is a list of strings rather than a single string. There are some differences between the new property, "riscv,isa-extensions" and the incumbent "riscv,isa" - chief among them for the sake of parsing being the list of strings, as opposed to a string. Another advantage is strictly defined meanings for each string in a dt-binding, rather than deriving meaning from RVI standards. This may likely to some divergence over time, but, at least for now, there's no relevant differences between the two for an M-Mode program. Add support for the new property in OpenSBI, prioritising it, before falling back to the, now deprecated, "riscv,isa" property if it is not present. Link: https://lore.kernel.org/all/20230702-eats-scorebook-c951f170d29f@spud/ [1] Signed-off-by: Conor Dooley <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-07-23lib: tests: add math test suiteDongdong Zhang
This patch introduces a new math test suite to the SBI unit tests. The changes include: * Updating lib/sbi/tests/objects.mk to include math_test_suite and sbi_math_test.o. * Adding a new file lib/sbi/tests/sbi_math_test.c which contains tests for log2roundup function using various cases. The addition of this test suite ensures that mathematical functions are verified and work as expected. Signed-off-by: Dongdong Zhang <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-07-23lib: tests: enhance test output with colored pass/fail messagesDongdong Zhang
This patch improves the readability of the SBI unit test output by adding color-coded status messages. Adding ANSI color codes for green (pass) and red (fail) in sbi_unit_test.c. Now, the test results will be displayed in green for passed tests and red for failed tests, making it easier to quickly distinguish between them. Signed-off-by: Dongdong Zhang <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-07-04Makefile: change to using .carray.c for carray filesBen Dooks
We would like to clean any files generated by the carray scripts by just searching for the filename as the current make system turns f.carray into f.o. Change to make the make system turn f.carray into f.carray.o note, command to go through .mk files changing the .o in the .mk files is: find . -type f -name "*.carray" | xargs -t -I fname /bin/bash -x -c ' fn=`basename -s .carray fname`; echo "$fn"; sed -i `dirname fname `/objects.mk -e s/"$fn".o/"$fn".carray.o/g' Link: https://patchwork.ozlabs.org/project/opensbi/patch/[email protected]/ Reported-by: Ivan Orlov <[email protected]> Suggested-by: Andrew Jones <[email protected]> Signed-off-by: Ben Dooks <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Reviewed-by: Anup Patel <[email protected]>