summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2023-10-06firmware: Remove ALIGN in .rela.dyn in linker scriptVivian Wang
The .rela.dyn section should be exactly the size of the relocations, without padding. On RV64, .rela* sections are already aligned and there's no need for padding. On RV32, this adds padding up to 4 bytes, which, if present, confuses the relocation loop into processing an extra entry past the end of .rela*, and it crashes with an invalid memory access. Fixes: 0f20e8adcf42 ("firmware: Support position independent execution") Signed-off-by: Vivian Wang <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-10-04platform: generic: thead: fix stale TLB entries for th1520/sg2042Inochi Amaoto
The TLB entries remain functional all the time once added in T-HEAD th1520 and Sophgo sg2042 (even if the MMU is then disabled afterwards). If there are some stale TLB entries that contains the address of SBI, it will cause unexpected memory access and issue a illegal instruction error. To avoid this, a TLB flush is needed to drop these TLB entries before any memory access in the trap handler. To handle this workaroud, add a custom trap handler with executing TLB flush first in the T-HEAD platform to fix affected socs. Signed-off-by: Inochi Amaoto <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-09-24lib: utils/regmap: Mark syscon region as shared read-writeAnup Patel
The syscon region used by OpenSBI should be marked as a shared read-write region between M-mode and SU-mode. Signed-off-by: Anup Patel <[email protected]> Signed-off-by: Mayuresh Chitale <[email protected]>
2023-09-24lib: utils/serial: Add shared regions for serial driversMayuresh Chitale
The serial driver regions used by OpenSBI should be marked as a shared read-write regions between M-mode and SU-mode as those are accessed by earlycon and the corresponding tty serial drivers running in 'S' mode. When the smepmp extension is enabled, PMP entries for these shared regions will get programmed. Signed-off-by: Mayuresh Chitale <[email protected]> Signed-off-by: Anup Patel <[email protected]>
2023-09-24lib: sbi: Populate M-only Smepmp entries before setting mseccfg.MMLAnup Patel
Based on sections 4.c and 4.d in Ch.2 of the Smepmp spec the PMP entries must be programmed as below: 1. Program M-only entries 2. Enable mseccfg.MML 3. Program shared-region entries 4. Program SU-only entries Co-developed-by: Mayuresh Chitale <[email protected]> Signed-off-by: Mayuresh Chitale <[email protected]> Signed-off-by: Anup Patel <[email protected]>
2023-09-24lib: sbi: Fix pmp_flags for Smepmp read-only shared regionAnup Patel
The Smepmp read-only shared region must have pmpcfg.L, pmpcfg.R, pmpcfg.W, and pmpcfg.X bits set so sbi_hart_get_smepmp_flags() must return pmp_flags accordingly. Signed-off-by: Anup Patel <[email protected]> Signed-off-by: Mayuresh Chitale <[email protected]>
2023-09-24lib: sbi: Don't clear mseccfg.MML bit in sbi_hart_smepmp_configure()Anup Patel
The mseccfg.MML bit is a sticky bit which remains unchanged once set so no need to clear it in sbi_hart_smepmp_configure(). Signed-off-by: Anup Patel <[email protected]> Signed-off-by: Mayuresh Chitale <[email protected]>
2023-09-24lib: sbi: Factor-out Smepmp configuration as separate functionAnup Patel
Let us factor-out Smepmp configuaration as separate function so that code is more readable. Signed-off-by: Anup Patel <[email protected]> Signed-off-by: Mayuresh Chitale <[email protected]>
2023-09-24include: sbi_domain: Fix permission test macrosMayuresh Chitale
The macros to test permissions must perform an exact match of all the bits in the input with the desired permission bits. Otherwise, the check returns false positives in those cases where only some of the desired permissions are set in the input. Fixes: 6c202c5 ("include: sbi: Add Smepmp specific access flags for PMP entries") Signed-off-by: Mayuresh Chitale <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-09-24include: sbi: Remove sbi_hartmask_for_each_hart() macroAnup Patel
The sbi_hartmask_for_each_hart() macro is slow and has only one user so let us completely remove the sbi_hartmask_for_each_hart() macro. Signed-off-by: Anup Patel <[email protected]>
2023-09-24lib: sbi: Maximize the use of HART index in sbi_domainAnup Patel
Let us maximize the use of HART index in sbi_domain because hartindex based hartmask access and sbi_scratch lookup is faster. Signed-off-by: Anup Patel <[email protected]>
2023-09-24lib: sbi: Remove sbi_scratch_last_hartid() macroAnup Patel
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 <[email protected]>
2023-09-24lib: sbi: Prefer hartindex over hartid in IPI frameworkAnup Patel
Let us prefer hartindex over hartid in IPI framework which in-turn forces IPI users to also prefer hartindex. Signed-off-by: Anup Patel <[email protected]>
2023-09-24lib: sbi: Use sbi_scratch_last_hartindex() in remote TLB managmentAnup Patel
The sbi_hartid_to_scratch() involves translating hartid to hartindex which is expensive so let's use sbi_hartindex_to_scratch() instead. Signed-off-by: Anup Patel <[email protected]>
2023-09-24lib: sbi: Extend sbi_hartmask to support both hartid and hartindexXiang W
Currently, the sbi_hartmask is indexed by hartid which puts a limit on hartid to be less than SBI_HARTMASK_MAX_BITS. We extend the sbi_hartmask implementation to use hartindex and support updating sbi_hartmask using hartid. This removes the limit on hartid and existing code works largely unmodified. Signed-off-by: Xiang W <[email protected]> Signed-off-by: Anup Patel <[email protected]>
2023-09-24lib: sbi: Remove sbi_platform_hart_index/invalid() functionsAnup Patel
The hartid to hartindex mapping is now tracked in sbi_scratch so we don't need sbi_platform_hart_index() and sbi_platform_hart_invalid() functions hence let us remove them. Signed-off-by: Anup Patel <[email protected]>
2023-09-24lib: sbi: Introduce HART index in sbi_scratchAnup Patel
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 <[email protected]>
2023-09-22lib: sbi: Implement SET_FS_DIRTY() to make sure the mstatus FS dirty is setGreentime Hu
We found the mstatus.FS status is not set correctly after the SET_F64_REG() and SET_F32_REG(). We should set mstatus.FS dirty after we emulate the FPU instructions. Co-developed-by: Roy Lin <[email protected]> Signed-off-by: Roy Lin <[email protected]> Signed-off-by: Greentime Hu <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-09-10lib: sbi: alloc tlb fifo by sbi_mallocXiang W
If the system is defined from tlb_fifo_num_entries, the scratch may be too small to hold the fifo, so it is alloc through the heap. Signed-off-by: Xiang W <[email protected]> Signed-off-by: Xing Xiaoguang <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-09-10platform: Allow platforms to specify the size of tlb fifoXiang W
For some platforms with a particularly high number of harts, if the tlb fifo is too small, it case harts to wait. Platforms should be allowed to specify the size of the tlb fifo. Signed-off-by: Xiang W <[email protected]> Signed-off-by: Xing Xiaoguang <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-09-10lib: sbi_pmu: keep overflow interrupt of stopped hpm counter disabledInochi Amaoto
After the hardware hpm counter is stopped, it should not raise any new interrupt as it is already stopped. So add the hw_counter_disable_irq callback to allow the custom pmu device to control this behavior. Signed-off-by: Inochi Amaoto <[email protected]> Reviewed-by: Guo Ren <[email protected]> Reviewed-by: Anup Patel <[email protected]> Tested-by: Samuel Holland <[email protected]>
2023-09-10platform: generic: allwinner: fix OF process for T-HEAD c9xx pmuInochi Amaoto
T-HEAD c9xx pmu needs to clear OV bits of MCOUNTEROF in any condition to avoid unnecessary OF interrupts. In addition, the S-mode SCOUNTEROF only have OF bit set when the related bits of MCOUNTERWEN is set, so also configure MCOUNTERWEN to allow kernel to access valid SCOUNTEROF. Signed-off-by: Haijiao Liu <[email protected]> Co-authored-by: Inochi Amaoto <[email protected]> Signed-off-by: Inochi Amaoto <[email protected]> Reviewed-by: Anup Patel <[email protected]> Tested-by: Samuel Holland <[email protected]>
2023-09-10lib: sbi_pmu: ensure update hpm counter before starting countingInochi Amaoto
When detecting features of PMU, the hpm counter may be written to some value, this will cause some unexpected behavior in some cases. So ensure the hpm counter is updated before starting the counter and the related interrupt. Signed-off-by: Haijiao Liu <[email protected]> Co-authored-by: Inochi Amaoto <[email protected]> Signed-off-by: Inochi Amaoto <[email protected]> Reviewed-by: Anup Patel <[email protected]> Tested-by: Samuel Holland <[email protected]>
2023-09-06lib: sbi: improve the definition of SBI_IPI_EVENT_MAXXiang W
The previous definition had the assumption that the machine word length is equal to the word length of LONG. Remove this assumption and add a static check to prevent errors in subsequent modifications. Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-09-06firmware: payload: test: Change to SBI v2.0 DBCN ecallsInochi Amaoto
As the the "Console Putchar" extension is already legacy and may be removed in the furture. So replace it with the SBI v2.0 "DBCN" extension. Signed-off-by: Inochi Amaoto <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-08-22lib: sbi_pmu: remove mhpm_count field in hart featureInochi Amaoto
After supporting noncontigous hpm event and counters in opensbi, the number of hpm counters can be calculated by the mhpm_mask. So this field is unnecessary and can be removed to save some space. Signed-off-by: Inochi Amaoto <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-08-22platform: generic: allwinner: correct mhpmevent countInochi Amaoto
Only the CSR mhpmevent 3-9,13-17 of D1 have valid function, so change the mhpm_mask to a valid value to avoid invalid usage. Due to the openc906 pmu code https://github.com/T-head-Semi/openc906/blob/main/C906_RTL_FACTORY/gen_rtl/pmu/rtl/aq_hpcp_top.v Signed-off-by: Inochi Amaoto <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-08-22Makefile: Fix grep warningAndrew Jones
grep (at least my version, grep-3.8-3.fc38.x86_64) warns with "grep: warning: stray \ before -". Fix the warning by making the command line input to grep less ambiguous. Signed-off-by: Andrew Jones <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-08-18lib: sbi: Add support for smcntrpmfKaiwen Xue
This adds the support for ISA extension smcntrpmf. When some inhibit flags are set by a lower privilege mode for new CSRs added by smcntrpmf, OpenSBI sets the appropriate values correspondingly. Signed-off-by: Kaiwen Xue <[email protected]> Signed-off-by: Kaiwen Xue <[email protected]> Reviewed-by: Anup Patel <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2023-08-06fw_base.S: Fix assembler error with clang 16+Mitchell Horne
Attempting to build OpenSBI with clang 16 and the following command: $ make LLVM=1 PLATFORM=generic Results in the following error: AS platform/generic/firmware/fw_dynamic.o /tmp/fw_dynamic-d000a6.s:429:9: error: symbol '_fw_start' can not be undefined in a subtraction expression .dword _fw_rw_start - _fw_start Work around this issue by eliminating the __fw_rw_offset variable and performing the offset calculation at run-time instead. This takes advantage of the fact that the a4 register contains the value of _fw_start. Signed-off-by: Mitchell Horne <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-08-06lib: sbi: Fix typo for finding fixed event counterKaiwen Xue
Cycle and instructions are hardware events instead of firmware ones. Fix the typo in the name of this function. Signed-off-by: Kaiwen Xue <[email protected]> Signed-off-by: Kaiwen Xue <[email protected]> Reviewed-by: Anup patel <[email protected]>
2023-08-06lib: utils/fdt: Fix fdt_parse_isa_extensions() implementationAnup Patel
Currently, the fdt_parse_isa_extensions() tries to parse the ISA string once for each HART. This ISA string parsing can fail for secondary HARTs if the FDT memory is already overwritten by the supervisor OS. To tackle this issue, we improve the fdt_parse_isa_extensions() implementation to pre-parse ISA string for all HARTs during cold boot. Fixes: d72f5f17478d ("lib: utils: Add detection of Smepmp from ISA string in FDT") Signed-off-by: Anup Patel <[email protected]> Tested-By: Mayuresh Chitale<[email protected]>
2023-08-06lib: sbi_pmu: Enable noncontigous hpm event and countersMayuresh Chitale
Platforms may implement hpm events/counters non contiguously but the current implementation assumes them to be always contigous. Add a bitmap that captures the hpm events/counters as implemented in the hardware and use it to set the max limit of hardware counters visible to the OS. Counters not implemented in the hardware can't be used by the OS because those wont be described in the DT. Signed-off-by: Mayuresh Chitale <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-08-06gitignore: allow gitignore to ignore most dot fileInochi Amaoto
Nowadays, most of the editor use files or directories begin with dot to store some settings. So let git ignore these files and directories to reduce potential mistakes. Add dot match to ignore any editor file and there are two exceptions: - .gitignore - .clang-format Signed-off-by: Inochi Amaoto <[email protected]> Reviewed-by: Bin Meng <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-07-31lib: utils/reset: Remove SiFive Test reset driverAnup Patel
The functionality of SiFive Test reset driver is easily available through Syscon reset driver so let us remove the SiFive Test driver. Signed-off-by: Anup Patel <[email protected]>
2023-07-31lib: utils/reset: Add syscon based reboot and poweroffAnup Patel
Let us have common FDT based reset driver for syscon reboot and poweroff. The device tree bindings for syscon reboot and poweroff are already available in the Linux kernel sources. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Xiang W <[email protected]>
2023-07-31lib: utils/regmap: Add simple FDT based syscon regmap driverAnup Patel
Let us add a simple FDT based system regmap driver which follows the device tree bindings already defined in the Linux kernel. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Xiang W <[email protected]>
2023-07-31lib: utils/regmap: Add simple FDT based regmap frameworkAnup Patel
We add a simple FDT based regmap framework which is built on top of generic regmap library. The phandle of FDT regmap DT node is treated as unique regmap ID. The FDT based regmap drivers will be probed on-demand from fdt_regmap_get_by_phandle() and fdt_regmap_get() called by the regmap client drivers. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Xiang W <[email protected]>
2023-07-31lib: utils/regmap: Add generic regmap access libraryAnup Patel
We add generic regmap access library which is independent of hardware description format (FDT or ACPI). The OpenSBI platform support or regmap drivers can register regmap instances which can be discovered by different regmap clients based on the unique ID of regmap instances. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Xiang W <[email protected]>
2023-07-31include: sbi_utils: Remove driver pointer from struct i2c_adapterAnup Patel
The "driver" pointer in struct i2c_adapter is not used anywhere so let us remove it. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Xiang W <[email protected]>
2023-07-31include: sbi: fix CSR define of mseccfgXiang W
Because the CSR names in the spec are mseccfg and mseccfgh. Remove CSR_MSECCFG_LOWER and CSR_MSECCFG_UPPER and directly define CSR_MSECCFG and CSR_MSECCFGH. Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-07-31lib: sbi: Update system suspend to specAndrew Jones
commit 68e66106120f ("SUSP: Add SBI_ERR_DENIED") of the SBI spec adds a new error code, SBI_ERR_DENIED, which is returned when entry criteria has not be meant. Update the system suspend implementation to return this error when it has detected that not all harts are in the STOPPED state. Signed-off-by: Andrew Jones <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-07-31libfdt: fix SPDX license identifiersHeinrich Schuchardt
License identifiers should be machine readable. According to the SPDX v2.3.0 specification annex E parentheses are not used in the SPDX identifier field when specifying multiple licenses [1]. [1] https://spdx.github.io/spdx-spec/v2.3/using-SPDX-short-identifiers-in-source-files/ Signed-off-by: Heinrich Schuchardt <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-07-13lib: sbi: Map/Unmap debug console shared memory buffersHimanshu Chauhan
With Smepmp enabled, it is necessary for shared memory from S/U mode to be mapped/unmapped before and after read/write of the memory region. This patch maps the debug console shared memory before accessing it. Signed-off-by: Himanshu Chauhan <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-07-13lib: sbi: Add functions to map/unmap shared memoryHimanshu Chauhan
When Smepmp is enabled, M-mode will need to map/unmap the shared memory before it can read/write to it. This patch adds functions to create dynamic short-lived mappings. Signed-off-by: Himanshu Chauhan <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-07-13lib: sbi: Add support for SmepmpHimanshu Chauhan
- If Smepmp is enabled, the access flags of an entry are determined based on truth table defined in Smepmp. - First PMP entry (index 0) is reserved. - Existing boot PMP entries start from index 1. - Since enabling Smepmp revokes the access privileges of the M-mode software on S/U-mode region, first PMP entry is used to map/unmap the shared memory between M and S/U-mode. This allows a temporary access window for the M-mode software to read/write to S/U-mode memory region. Signed-off-by: Himanshu Chauhan <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-07-13lib: sbi: Change the order of PMP initializationHimanshu Chauhan
Configure PMP at last when all other initializations have been done. Because if SMEPMP is detected, M-mode access to the S/U space will be rescinded. Signed-off-by: Himanshu Chauhan <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-07-13lib: sbi: Grant SU R/W/X permissions to whole memoryHimanshu Chauhan
Since pmp entries have implicit priority on index, previous entries will deny access to SU on M-mode region. Also, M-mode will not have access to SU region while previous entries will allow access to M-mode regions. Signed-off-by: Himanshu Chauhan <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-07-13lib: utils: Add detection of Smepmp from ISA string in FDTHimanshu Chauhan
- Add function to parse ISA string in FDT. - Set Smepmp feature bit in extensions if "smepmp" string is found in ISA string. Signed-off-by: Himanshu Chauhan <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-07-13lib: sbi: Add smepmp in hart extensionsHimanshu Chauhan
- Add Smepmp as extension in sbi_hart_extensions enum - Return "smepmp" string for Smepmp extension from sbi_hart_extension_id2string Signed-off-by: Himanshu Chauhan <[email protected]> Reviewed-by: Anup Patel <[email protected]>