summaryrefslogtreecommitdiff
path: root/lib/sbi
AgeCommit message (Collapse)Author
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-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: 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]>
2023-07-13lib: sbi: Add functions to manipulate PMP entriesHimanshu Chauhan
- Add a function to disable a given PMP entry. - Add a function to check if a given entry is disabled. Signed-off-by: Himanshu Chauhan <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-07-12lib: sbi: Fix missing '\0' when buffer szie equal 1Xiang W
Fix special case: sbi_snprintf(out, out_len, ...) when out_len equal 1, The previous code will not fill the buffer with any char. Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-07-12lib: sbi: Fix timing of clearing tbufXiang W
A single scan of the format char may add multiple characters to the tbuf, causing a buffer overflow. You should check if tbuf is full in printc so that it does not cause a buffer overflow. Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-07-12lib: sbi: Fix printcXiang W
Because *out needs to reserve a byte to hold '\0', no more characters should be added to the buffer when *out has one byte left, and the buffer size *out_len should not be modified. this patch prevents the correction of *out_len when *out_len is 1. Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-07-12lib: sbi: Simplify printsXiang W
When doing width = width - strlen(string) in prints there is no need to consider the case that witdh may be less than 0. This is because the code to do filling needs to be executed under the condition that width > 0. Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-07-12lib: sbi: Fix printiXiang W
Fix two bug: > printf("%#08x", 0x123); /* print 0000x123 */ > printf("%#x", 0); /* print 0x0 */ Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-07-12lib: sbi: print add 'o' typeXiang W
Add o type for print to print octal numbers Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-07-12lib: sbi: implifying the parameters of printiXiang W
The information of sg/b/letbase can be obtained by the type character, simplifying the parameter by passing the type directly. Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-07-12lib: sbi: Add ' ' '\'' flags for printXiang W
The space flag is used to add a space before positive numbers, and apostrophe is used to print the thousand separator. Add code to ignore these two flags Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-07-12lib: sbi: Add '+' flags for printXiang W
Adds + flags for print, prefixing positive numbers with + when this flags is present Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-07-12lib: sbi: print not fill '0' when left-alignedXiang W
Left alignment and padding '0' should not exist at the same time, this patch skips padding. Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-07-12lib: sbi: Fix how print gets flagsXiang W
The flags for print should be able to appear in any order. The previous code required the order to be fixed. Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-07-09lib: sbi: Fix Priv spec version for [m|s]counteren and mcountinhibit CSRsLey Foon Tan
Fix Priv spec version typo in commit d4b563c881d6 ("lib: sbi: Remove MCOUNTEREN and SCOUNTEREN hart features"). At least Priv spec v1.11 is required for [m|s]counteren and mcountinhibit CSRs. Fixes: d4b563c881d6 ("lib: sbi: Remove MCOUNTEREN and SCOUNTEREN hart features") Signed-off-by: Ley Foon Tan <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-07-09lib: sbi: Rename hart_pmu_get_allowed_bits() functionAnup Patel
The hart_pmu_get_allowed_bits() function detects implemented bits of mhpm counters so let us rename this function accordingly. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Xiang W <[email protected]>
2023-07-09lib: sbi: Alphabetically sort HART ISA extensionsAnup Patel
Let us follow alphabetical order for HART ISA extension so that it is simpler to maintain. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Xiang W <[email protected]>
2023-07-09lib: sbi: Add Zihpm as a HART ISA extensionAnup Patel
Recently ratified Zihpm ISA extension covers all [m]hpm* CSRs so we add Zihpm as a HART ISA extension in OpenSBI. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Xiang W <[email protected]>
2023-07-09lib: sbi: Add Zicntr as a HART ISA extensionAnup Patel
Recently ratified Zicntr ISA extension covers cycle, time and instret CSRs so we replace the "time" ISA extension with "zicntr" ISA extension in OpenSBI. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Xiang W <[email protected]>
2023-07-05lib: sbi_pmu: Avoid out of bounds accessHeinrich Schuchardt
On a misconfigured system we could access phs->active_events[] out of bounds. Check that num_hw_ctrs is less or equal SBI_PMU_HW_CTR_MAX. Addresses-Coverity-ID: 1566113 ("Out-of-bounds read") Addresses-Coverity-ID: 1566114 ("Out-of-bounds write") Signed-off-by: Heinrich Schuchardt <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-07-05lib: sbi: fix comment indentGianluca Guida
Use tabs rather than spaces. Signed-off-by: Gianluca Guida <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-06-23lib: sbi: check A2 register in ecall_dbcn_handler.Gianluca Guida
Do not ignore register A2 (high bits of physical address) in the dbcn handler (RV64). Signed-off-by: Gianluca Guida <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-06-05lib: sbi: Use scratch space to save per-HART domain pointerAnup Patel
Instead of using a global array indexed by hartid, we should use scratch space to save per-HART domain pointer. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Andrew Jones <[email protected]>
2023-06-05lib: sbi: Use heap for root domain creationAnup Patel
Let's use heap allocation in root domain creation instead of using a fixed size global array. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Andrew Jones <[email protected]>
2023-06-05lib: sbi_pmu: Use heap for per-HART PMU stateAnup Patel
Instead of using a global array for per-HART PMU state, we should use heap to on-demand allocate per-HART PMU state when the HART is initialized in cold boot or warm boot path. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Andrew Jones <[email protected]>
2023-06-05lib: sbi: Print scratch size and usage at boot timeAnup Patel
The scratch space being a scarce resource so let us print it's size and usage at boot time. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Andrew Jones <[email protected]>
2023-06-05lib: sbi: Introduce simple heap allocatorAnup Patel
We provide simple heap allocator to manage the heap space provided by OpenSBI firmware and platform. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Andrew Jones <[email protected]>
2023-06-04lib: sbi: Align system suspend errors with specAndrew Jones
The spec says sbi_system_suspend() will return SBI_ERR_INVALID_PARAM when "sleep_type is reserved or is platform-specific and unimplemented" and SBI_ERR_NOT_SUPPORTED when sleep_type "is not reserved and is implemented, but the platform does not support it due to one or more missing dependencies." Ensure SBI_ERR_INVALID_PARAM is returned for reserved sleep types and that the system suspend driver can choose which of the two error types to return itself by returning an error from its check function rather than a boolean. Signed-off-by: Andrew Jones <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-05-26lib: sbi: Fix return of sbi_console_initXiang W
console is not a required peripheral. So it should return success when the console does not exist. Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-05-21lib: sbi: Remove 0/1 probe implementationsAndrew Jones
When a probe implementation just returns zero for not available and one for available then we don't need it, as the extension won't be registered at all if it would return zero and the Base extension probe function will already set out_val to 1 if not probe function is implemented. Currently all probe functions only return zero or one, so remove them all. Signed-off-by: Andrew Jones <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-05-21lib: sbi: Optimize probe of srst/suspXiang W
No need to do a fully comprehensive count, just find a supported reset or suspend type Signed-off-by: Xiang W <[email protected]> Signed-off-by: Andrew Jones <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-05-21lib: sbi: Only register available extensionsAndrew Jones
When an extension implements a probe function it means there's a chance that the extension is not available. Use this function in the register_extensions callback to determine if the extension should be registered at all. Where the probe implementation is simple, just open code the check. Signed-off-by: Andrew Jones <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-05-21lib: sbi: pmu: Remove unnecessary probe functionAndrew Jones
The absence of a probe implementation means that the extension is always available. Remove the implementation for the PMU extension, which does no checking, and indeed even has a comment saying it's always available. Signed-off-by: Andrew Jones <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-05-21lib: sbi: Narrow vendor extension rangeAndrew Jones
The vendor extension ID range is large, but at runtime at most a single ID will be available. Narrow the range in the register_extensions callback. After narrowing, we no longer need to check that the extension ID is correct in the other callbacks, as those callbacks will never be invoked with anything other than the single ID. Signed-off-by: Andrew Jones <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-05-21lib: sbi: Introduce register_extensions extension callbackAndrew Jones
Rather than registering all extensions on their behalf in sbi_ecall_init(), introduce another extension callback and invoke that instead. For now, implement each callback by simply registering the extension, which means this patch has no intended functional change. In later patches, extension callbacks will be modified to choose when to register and to possibly narrow the extension ID range prior to registering. When an extension range needs to remove IDs, leaving gaps, then multiple invocations of sbi_ecall_register_extension() may be used. In summary, later patches for current extensions and the introductions of future extensions will use the new callback to ensure that only valid extension IDs from the initial range, which are also available, will be registered. Signed-off-by: Andrew Jones <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-05-11lib: sbi: Simplify sbi_ipi_process remove gotoXiang W
Simplify sbi_ipi_process() by removing goto statement. Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-05-11lib: sbi: Remove unnecessary semicolonXiang W
We have redundant semicolon at quite a few places so let's remove it. Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-04-20lib: sbi: Add debug print when sbi_pmu_init failsTan En De
Since sbi_pmu_init is called after sbi_console_init, the sbi_printf can be called when sbi_pmu_init fails. Signed-off-by: Tan En De <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2023-04-17lib: sbi: Don't check SBI error range for legacy console getcharAnup Patel
The legacy console getchar SBI call returns character value in the sbiret.error field so the "SBI_SUCCESS < ret" check in sbi_ecall_handler() results in unwanted error prints for the legacy console getchar SBI call. Let's suppress these unwanted error prints. Fixes: 67b2a408924b ("lib: sbi: sbi_ecall: Check the range of SBI error") Signed-off-by: Anup Patel <[email protected]>
2023-04-17lib: sbi: Fix counter index calculation for SBI_PMU_CFG_FLAG_SKIP_MATCHAlexandre Ghiti
As per the SBI specification, we should "unconditionally select the first counter from the set of counters specified by the counter_idx_base and counter_idx_mask", so implement this behaviour. Suggested-by: Atish Patra <[email protected]> Signed-off-by: Alexandre Ghiti <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2023-04-17lib: sbi: Do not clear active_events for cycle/instret when stoppingAlexandre Ghiti
Those events are enabled by default and should not be reset afterwards since when using SBI_PMU_CFG_FLAG_SKIP_MATCH, it leads to unaccessible counters after the first use. Signed-off-by: Alexandre Ghiti <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2023-04-14lib: sbi: Optimize sbi_tlb queue waitingXiang W
When tlb_fifo is full, it will wait and affect the ipi update to other harts. This patch is optimized. Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]> Tested-by: Anup Patel <[email protected]>
2023-04-13sbi: tlb: Simplify to tlb_process_count/tlb_process functionXiang W
tlb_process_count is only used when count=1, so refactor to tlb_process_once and add the return value to be reused in tlb_process Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]> Tested-by: Anup Patel <[email protected]>
2023-04-13lib: sbi: Optimize sbi_ipiXiang W
The original sbi_ipi will be processed by hart by hart, after optimization, send ipi first and finally wait together. Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]> Tested-by: Anup Patel <[email protected]>
2023-04-13lib: sbi: Optimize sbi_tlbXiang W
Originally, the process and sync of sbi_tlb need to wait for each other. Evasion by atomic addition and subtraction. Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]> Tested-by: Anup Patel <[email protected]>