summaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
2020-12-24lib: sbi: Fix sign-extension in sbi_misaligned_load_handler()Anup Patel1-1/+1
The misaligned load emulation does not sign-extend values correctly due to missing sign typecast in value passed to the SET_RD() macro. A very easy way to reproduce this issue is to load 16-bit value 0xff1e from a byte aligned address using LH instruction on hardware lacking misaligned load/store. This patch fixes sbi_misaligned_load_handler() for above issue. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-12-16lib: sbi: Remove domain_get() platform callback functionAnup Patel2-93/+3
The domain_get() platform callback function is now redundant because fdt_domain_populate() register new domain explicitly using the sbi_domain_register() function. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-12-16lib: utils: Remove fdt_domain_get() functionAnup Patel3-59/+36
The fdt_domain_get() function is now redundant because the fdt_domains_populate() function can explicitly register new domains using the sbi_domain_register() function. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-12-16lib: sbi: Add function to register new domainAnup Patel2-0/+81
We add sbi_domain_register() function to help platform code register a new domain explicitly instead of depending on domain_get() platform callback. This function will eventually help us completely remove the domain_get() platform callback. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-12-16lib: utils: Allow FDT domain iteration functions to failAnup Patel2-54/+79
We extend fdt_iterate_each_domain() and fdt_iterate_each_memregion() functions to allow underlying iteration function to fail. This will help us catch more domain misconfiguration issues at boot time. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-12-13lib: utils/libfdt: Upgrade to v1.6.0 releaseDimitri John Ledkov11-154/+356
Sync with libfdt v1.6.0 release source codes. Signed-off-by: Dimitri John Ledkov <xnox@ubuntu.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-12-04platform: generic: Populate domains from FDTAnup Patel1-0/+9
The generic platform should populate domains from FDT using the domain FDT helper routines. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-12-04lib: utils: Add helper routines to populate domains from FDTAnup Patel3-0/+526
We add various helper routines to populate domains, iterate domains, iterate domain memregions, and parse HART to domain assignment from the FDT. These helper routines can be used by platform support code and FDT fixup code. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-12-04docs: Add domain device tree binding documentationAnup Patel1-0/+208
This patch adds domain device tree binding documentation in the OpenSBI domain support documentation. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-12-04include: sbi: Add domains_init() platform operationAnup Patel2-0/+24
We introduce domains_init() platform operation which can be used by platform support to initialize/populate domains in the coldboot path. The domains_init() is called late in the coldboot sequence from the sbi_domain_finalize() so sbi_printf() can be used by platform support to print errors/warnings at time of populating domains. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-12-04lib: sbi: Add error prints in sbi_domain_finalize()Anup Patel1-11/+52
We add error prints in sbi_domain_finalize() and sanitize_domain() to help debug domain configuration issues. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-12-04lib: sbi: Override domain boot HART when coldboot HART assigned to itAnup Patel1-0/+11
If coldboot HART is assigned to a domain then we should use coldboot HART as the boot HART of the domain. This allows coldboot HART to continue boot sequence even when it is assigned to some non-root domain. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-12-04include: sbi: Use lower bits for domain memory region permissionsAnup Patel1-2/+4
We should use lower bits for domain memory region access permissions and higher bits for other domain memory region attributes. This helps us use same bit assignment for parsing domain memory region access permissions from device tree. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-12-04lib: sbi: Auto start domain only if boot HART within limitsAnup Patel1-0/+4
The sbi_domain_finalize() should auto start a domain only if the boot HART is withing limits (i.e. less than SBI_HARTMASK_MAX_BITS). Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-12-04lib: sbi: Fix domain_count check in sbi_domain_finalize()Anup Patel1-1/+1
The domain_count check in sbi_domain_finalize() for newly discovered domain is incorrect and should be reversed. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-12-04lib: sbi: Fix typo in sbi_domain_finalize()Anup Patel1-2/+2
There has been typo in automatic domain boot hart startup for non-root domains so this patch fixes it. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-12-04lib: sbi: Fix sbi_hart_switch_mode() for u-modeAnup Patel1-3/+5
We should check and access N-extension CSRs in sbi_hart_switch_mode() when next_mode is u-mode because N-extension is optional. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-12-01firmware: fw_base: Optimize trap handler for RV32 systemsAnup Patel1-19/+68
On RV32 systems, we have two CSRs for M-mode status (MSTATUS and MSTATUSH) when H-extension is implemented. This means we have to save/restore MSTATUSH for RV32 systems only when H-extension is implemented. The current _trap_handler() has extra instructions (roughly 10) for conditional save/restore of MSTATUSH CSR. These extra instructions in RV32 _trap_handler() can be avoided if we create separate low-level trap handler for RV32 systems having H-extension. This patch optimizes low-level trap handler for RV32 systems accordingly. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
2020-12-01lib: sbi: Implement System Reset (SRST) SBI extensionAnup Patel3-0/+64
The SBI SRST extension has been accepted and merged in the latest SBI v0.3-draft specification. (Refer, https://github.com/riscv/riscv-sbi-doc) It allows to S-mode software to request system shutdown, cold reboot, and warm reboot. This patch implements SBI SRST extension as a replacement of the legacy sbi_shutdown() call of SBI v0.1 specification. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-12-01lib: sbi: Improve system reset platform operationsAnup Patel17-36/+137
To implement the SBI SRST extension, we need two platform operations for system reset: 1) system_reset_check() - This operation will check whether given reset type and reason are supported by the platform 2) system_reset() - This operation will do the actual platform system reset and it will not return if reset type and reason are supported by the platform This patch updates system reset related code everywhere as-per above. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-12-01platform: Remove dummy system reset functionsAnup Patel5-49/+0
Few platforms have dummy system reset functions so let's remove these dummy system reset functions to allow generic code deal with it in the right way. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-12-01include: sbi: Remove opensbi specific reset type definesAnup Patel5-10/+8
We can now use the standard SBI SRST extension reset types instead of the opensbi specific (SBI_PLATFORM_RESET_xyz) reset types hence remove related opensbi specific defines. The "platform_" prefix of the reset type parameter of sbi_system_reset() function should also be removed. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-12-01include: sbi: Add SBI SRST extension related definesAnup Patel1-0/+12
We extend the SBI ecall interface header for the SBI SRST extension recently accepted in SBI specification v0.3-draft. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-11-27docs: fix a typo errorYuan Li1-1/+1
fix a typo error in docs/platform/sifive_fu540.md Signed-off-by: Yuan Li <dskwelmcy@163.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-11-10lib: sbi: Improve boot prints in cold boot sequenceAnup Patel1-21/+69
Currently, we have all boot prints at the end of cold boot sequence which means if there is any failure in cold boot sequence before boot prints then we don't get any print. This patch improves boot prints in cold boot sequence as follows: 1. We divide the boot prints into multiple parts and print it from different locations after sbi_console_init() 2. We throw an error print if there is any failure in cold boot sequence after sbi_console_init() Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-11-02Makefile: Add option to use toolchain default ABI and ISA stringAnup Patel1-4/+14
When PLATFORM_RISCV_ABI and PLATFORM_RISCV_ISA are not specified, we force "-mabi=lp64 -march=rv64gc" for RV64 and force "-mabi=ilp32 -march=rv32gc" for RV32. This can prevent users from using the toolchain default "-mabi" and "-march" options. To allow using toolchain defaults, we add compile-time option PLATFORM_RISCV_TOOLCHAIN_DEFAULT which when enabled forces the top-level makefile to use toolchain default ABI and ISA string. To enable the option, pass "PLATFORM_RISCV_TOOLCHAIN_DEFAULT=1" to top-level make. Reported-by: Alistair Francis <alistair.francis@wdc.com> Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
2020-10-26lib: sbi: Improve boot time print with additional PMP informationAtish Patra1-14/+23
We know about pmp granularity and number of bits supported by PMP. Show those information in the boot time info print Signed-off-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-10-26lib: sbi: Detect PMP granularity and number of address bitsAtish Patra2-4/+60
As per RISC-V privilege specification, a platform may choose to implement a coarser granularity scheme for PMP addresses. In that case, we shouldn't allow any pmp region size smaller than the platform supports. A platform may not also implement all the bits for a PMP address specified in the priv specification. The pmp range granularity and address bits should be detected dynamically before detecing PMP regions. Any pmp modification request beyond these detected value must not succeed. Signed-off-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-10-23lib: utils: Implement "ranges" property parsingAtish Patra1-2/+48
The "reg" property in a device node may not be the correct address always. If a parent node defines a "ranges" property, the child address need to be translated with respect to parents address. If the ranges property is not present, it will just use 1:1 translation. Signed-off-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-10-21docs: Add initial documentation for domain supportAnup Patel3-0/+110
We add initial documentation for OpenSBI domain support to help RISC-V platform vendors achieve system-level partitioning. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-10-21lib: sbi: Display domain details in boot printsAnup Patel5-48/+127
We extend boot prints to display details of each domain. In the process, we remove sbi_hart_pmp_dump() because it shows redundant information which domain details already show. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-10-20lib: sbi: Configure PMP based on domain memory regionsAnup Patel1-15/+22
The PMP configuration on each HART should be only based on the memory regions of the assigned domain because each domain includes a memory region to protect the underlying firmware. This patch updates the sbi_hart_pmp_configure() function accordingly. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-10-20lib: sbi: Remove redundant sbi_hart_pmp_xyz() functionsAnup Patel2-48/+0
The sbi_hart_pmp_get() and sbi_hart_pmp_check_addr() functions are not used anymore hence this patch removes these functions. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-10-20lib: utils: Update fdt_cpu_fixup() to use current domainAnup Patel1-5/+3
The fdt_cpu_fixup() should disable a HART in DT if the HART is not assigned to the current HART domain. This patch updates fdt_cpu_fixup() accordingly. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-10-20lib: utils: Update fdt_reserved_memory_fixup() to use current domainAnup Patel1-25/+22
Now that each HART is mapped to a domain having a set of memory regions, we update fdt_reserved_memory_fixup() to use domain memory regions for adding reserved memory nodes in device tree. We also change reserved memory node name prefix from "mmode_pmp" to "mmode_resv" because domain memory regions can impact other hardware configurations (such as IOPMP, etc) along with PMP. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-10-20lib: sbi: Extend sbi_system_reset() for domainsAnup Patel1-3/+4
The sbi_system_reset() should issue platform system reset only if domain of current HART is allowed to do system reset. This patch extends sbi_system_reset() as-per above. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-10-20lib: sbi: Optimize sbi_hsm_hart_started_mask() implementationAnup Patel1-12/+22
Instead of calling sbi_hsm_hart_get_state() in a loop, we can simply call a new inline __sbi_hsm_hart_get_state() which only takes "hartid" and enforce domain checks using sbi_domain_assigned_hartmask(). This patch optimizes sbi_hsm_hart_started_mask() as-per above. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-10-20lib: sbi: Extend sbi_hsm_hart_start() for domainsAnup Patel4-15/+19
The sbi_hsm_hart_start() should consider the domain under which we are trying to start the HART. This will help ensure that HART A can start HART B only if both HARTs A and B belong to the same domain. We also have a special case when we bring-up boot HART of non-root domains in sbi_domain_finalize() where we should skip domain checks in sbi_hsm_hart_start(). To achieve this, sbi_hsm_hart_start() should do domain checks only when domain parameter is non-NULL. This patch extends sbi_hsm_hart_start() as-per above. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-10-20lib: sbi: Extend sbi_hsm_hart_started_mask() for domainsAnup Patel6-15/+27
The sbi_hsm_hart_started_mask() API should take one more parameter to allow caller specify domain under which started_mask is being generated. Further, the sbi_hsm_hart_started_mask() depends on sbi_hsm_hart_get_state() which also should return HART state under specified domain. This patch updates both sbi_hsm_hart_started_mask() and sbi_hsm_hart_get_state() as-per above. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
2020-10-20lib: sbi: Add initial domain supportAnup Patel5-0/+568
An OpenSBI domain is a logical entity representing a set of HARTs and a set of memory regions for these HARTs. The OpenSBI domains support will allow OpenSBI platforms and previous booting stage (i.e. U-Boot SPL, Coreboot, etc) to partition a system into multiple domains where each domain will run it's own software. For inter-domain isolation, OpenSBI will eventually use various HW features such as PMP, ePMP, IOPMP, SiFive shield, etc but initial implementation only use HW PMP support. This patch provides initial implementation of OpenSBI domains where we have a root/default domain and OpenSBI platforms can provide non-root/custom domains using domain_get() callback. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-10-20include: sbi: Make hartmask pointer const in sbi_hartmask_test_hart()Anup Patel1-1/+1
The sbi_hartmask_test_hart() does not modify hartmask so the hartmask pointer parameter should be declared const. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
2020-10-20lib: sbi: Remove redundant hartid parameter from sbi_hart_init()Anup Patel3-10/+10
The hartid parameter of sbi_hart_init() is not used anywhere in sbi_hart_init() implementation so let's remove it. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
2020-10-20lib: sbi: Configure PMP late in coldboot and warmboot pathAnup Patel3-2/+11
We factor-out PMP configuration from sbi_hart_init() as a separate sbi_hart_pmp_configure() function and do the PMP configuration very late in coldboot and warmboot path just before platform_final_init(). Eventually, this enable us to configure PMP totally based on OpenSBI domain where OpenSBI domains can be parsed from device-tree in any of the platform operations except platform_final_init(). Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
2020-10-20include: sbi: Remove pmp_region callbacks from sbi_platform_operationsAnup Patel2-63/+1
The pmp_region_xyz() callbacks are not required in sbi_platform_operations because we will be using OpenSBI domain memory regions to program the PMP CSRs. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
2020-10-20include: sbi: Remove redundant includes from sbi_platform.hAnup Patel2-2/+3
The sbi_ecall.h and sbi_trap.h are not required to be included in sbi_platform.h hence we remove it. This way sources requiring these headers will have to explicitly include it thereby reducing implicit includes. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
2020-10-18platform: kendryte/k210: Add some padding for FDT fixupsAnup Patel1-0/+1
The Kendryte K210 platform has built-in DTB and does not provides FW_PAYLOAD_FDT_ADDR. This means the FDT fixups will be done on the built-in DTB in absence of FW_PAYLOAD_FDT_ADDR. This patch adds some padding in built-in DTB for FDT fixups. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-10-18Makefile: Allow padding zeros when converting DTB to C sourceHeinrich Schuchardt2-3/+13
We extend d2c.sh to allow padding zeros in output C source when converting DTB to C source. Using this feature, platforms can create extra room for in-place FDT fixups on built-in DTBs. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-10-18firmware: Remove FW_PAYLOAD_FDT_PATH compile-time optionAnup Patel11-79/+12
The FW_PAYLOAD_FDT_PATH compile-time option is replaced by FW_FDT_PATH compile-time option which is more flexible and common across all OpenSBI firmwares. This patch removes FW_PAYLOAD_FDT_PATH and updates related documentation to use FW_FDT_PATH. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-10-18firmware: Add common FW_FDT_PATH compile-time optionAnup Patel4-5/+38
Currently, only FW_PAYLOAD has mechanism to embed external FDT using FW_PAYLOAD_FDT_PATH compile-time option. This patch adds a common FW_FDT_PATH compile-time option to embed external FDT for all OpenSBI firmwares (i.e FW_JUMP, FW_PAYLOAD, and FW_DYNAMIC). Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-10-18Makefile: Build ELF, BIN and LD script in platform build directoryAnup Patel1-9/+9
Currently, the make rules for ELF, BIN and LD script are little generic to allowing ELF, BIN and LD script to be anywhere in the build directory. For OpenSBI firmwares, the ELF, BIN, and LD script are always platform specific so we update make rules accordingly. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>