summaryrefslogtreecommitdiff
path: root/firmware
AgeCommit message (Collapse)AuthorFilesLines
2020-03-28lib: sbi_trap: Simplify sbi_trap_handler() APIAnup Patel1-1/+0
This patch simplify sbi_trap_handler() API as follows: 1. Remove current hartid local variable because sbi_trap_handler() itself does not need it. 2. Remove scratch parameter because none of the functions directly called by sbi_trap_handler() require it. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-19include: sbi_platform: Introduce HART index to HART id tableAnup Patel1-4/+23
A platform can have discontinuous and/or sparse HART ids so we cannot always assume a set of HARTs with continuous HART ids. This patch adds support for discontinuous and sparse HART ids by introducing HART index to HART id table. This table has platform hart_count entries and it maps HART index to HART id. The HART index to HART id table has only two restrictions: 1. HART index < sbi_platform hart_count 2. HART id < SBI_HARTMASK_MAX_BITS Example1: Let's say we have a platform with 2 HART ids 11 and 22, for such a a platform: hart_count = 2 hart_index2id[0] = 11 hart_index2id[1] = 22 Example2: Let's say we have a platform with 5 HARTs ids 0, 1, 2, 3, and 4 but out of these HART with id 0 is not usable so for such a platform: hart_count = 5 hart_index2id[0] = -1U hart_index2id[1] = 1 hart_index2id[2] = 2 hart_index2id[3] = 3 hart_index2id[4] = 4 OR hart_count = 4 hart_index2id[0] = 1 hart_index2id[1] = 2 hart_index2id[2] = 3 hart_index2id[3] = 4 With HART index to HART id table in place, the hart_disabled() callback is now redundant so we remove it as well. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-13firmware: fw_base: Optimize _hartid_to_scratch() implementationAnup Patel1-23/+14
This patch optimizes _hartid_to_scratch() in following ways: 1. Use caller saved registers instead of callee saved registers so that we don't need to save/restore registers on stack 2. Remove second redundant mul instruction by re-arranging instructions Overall, we reduce 9 instructions in _hartid_to_scratch() implementation. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
2020-01-10firmware: Fix placement of .align directivesAndreas Schwab5-44/+34
Move the .align directives after switching the section. We want to align the start of the current section, not the end of the previous section. This also obsoletes the misguided workaround of disabling relaxation. Signed-off-by: Andreas Schwab <schwab@suse.de> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2019-12-27firmware: Improve comments for fw_prev_arg1() and fw_next_arg1()Anup Patel3-0/+12
The state of a0, a1, and a2 registers in fw_prev_arg1() and fw_next_arg1() is same as passed by previous booting stage so we add this info in comments for both these functions. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-12-27firmware: Return real DTB address when FW_xyz_FDT_ADDR is not definedLiu Yibin2-2/+2
Function fw_next_arg1 in firmware/fw_jump.S:59 and firmware/fw_payload.S:63 should return real dtb address(if specified in a1) in a0, in case we don't want to specify FW_xyz_FDT_ADDR when compiling. Signed-off-by: Liu Yibin <yibin_liu@c-sky.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2019-11-15firmware: Add preferred boot HART field in struct fw_dynamic_infoAnup Patel4-0/+78
It has been reported that link address range of previous booting stage (such as U-Boot SPL) can overlap the link address rage of FW_DYNAMIC. This means self-relocation in FW_DYNAMIC can potentially corrupt previous booting stage if any of the secondary HART enter FW_DYNAMIC before primary HART. To tackle this, we add preferred boot HART field (i.e boot_hart) in struct fw_dyanmic_info. We use this field to force secondary HARTs into relocation wait loop till preferred/primary boot HART enters FW_DYNAMIC completes self-relocation. If preferred boot HART is not available then we fall back to relocation lottery approach. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2019-11-05firmware: Introduce relocation lotteryAnup Patel1-6/+11
Instead of forcing HART0 to do the relocation and scratch init work, we should have an atomic lottery to decide which HART does the relocation and scratch init. This way any HART can be boot/main HART. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2019-10-28firmware: Fix compile error for FW_PAYLOAD with latest GCC binutilsAnup Patel1-0/+10
We get following compile error for FW_PAYLOAD with latest GCC binutils: fw_payload.o(.text+0x1961): 15 bytes required for alignment to 16-byte boundary, but only 14 present Further investigating, it turn-out to be a known issue with RISC-V GCC binutils. (Refer, https://github.com/riscv/riscv-gnu-toolchain/issues/298) As a work-around, we disable relaxation when including DTB and PAYLOAD binary in fw_payload.S. Reported-by: David Abdurachmanov <david.abdurachmanov@sifive.com> Signed-off-by: Anup Patel <anup.patel@wdc.com> Tested-by: David Abdurachmanov <david.abdurachmanov@sifive.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2019-10-03lib: Rename existing SBI implementation as 0.1.Atish Patra1-1/+1
Current SBI implementation is now considered as version 0.1 and will be removed/replaced with newer extension/functions in future. Rename the existing implementations accordingly to be in sync with the specification. Signed-off-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Zong Li <zong.li@sifive.com>
2019-10-03Test: Move test payload related code out of interface headerAtish Patra1-0/+25
Test payload uses an SBI call and uses the macros defined in interface header which is not the correct place to have these definitions. The interface header file should be used to keep SBI specification related macros. Keep all the test payload related code in test itself. Signed-off-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2019-09-30lib: Extend sbi_trap_redirect() for hypervisor extensionAnup Patel1-0/+19
When hypervisor extension is available, we can get traps from VS/VU modes. We should be able to force redirect some of these traps to HS-mode. In other words, we should be able forward traps from VS/VU mode to HS-mode using sbi_trap_redirect() hence this patch. Signed-off-by: Atish Patra <atish.patra@wdc.com> Signed-off-by: Anup Patel <anup.patel@wdc.com> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2019-08-13firmware: do not use relocated _boot_status before it is validLukas Auer1-3/+10
When OpenSBI is started from an address not equal to the link address, it is first relocated to the link address. Hart 0 performs the relocation and notifies the other harts of its completion with the _boot_status variable. It uses the copy of the variable relative to the link address. This copy contains valid data only after relocation has finished. The waiting harts will therefore read invalid data until relocation has finished. This can cause them to continue execution too early. Fix this by using the _boot_status variable relative to the load address while OpenSBI has not finished relocation. Signed-off-by: Lukas Auer <lukas.auer@aisec.fraunhofer.de> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2019-08-09firmware: Use macro instead of magic number for boot statusBin Meng1-4/+7
The boot status is currently hard-coded. Define some macros for it. Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2019-08-07firmware: Fix the loop condition of _wait_relocate_copy_done sectionNylon Chen1-1/+1
If core-0 have finished _fdt_reloc_done but any of other cores has not yet left the loop in _wait_relocate_copy_done, they could never leave the loop because _boot_status is not equal to 1.
2019-07-01firmware: For no relocation skip two stage wait for secondary HARTsAnup Patel1-0/+1
When relocation is not required (i.e. _load_start == _link_start), we can skip two stage wait for secondary HARTs. This means secondary HARTs can skip the _wait_relocate_copy_done() loop and directly jump to the _wait_for_boot_hart() loop when no relocation not required. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-06-24firmware: Handle overlapping load and link addresses in relocationXiang W1-21/+39
The old code may corrupt the code of the waiting hart hence this patch keeps waiting HART within relocation code range at time of relocation. Signed-off-by: Xiang W <wxjstz@126.com> Acked-by: Anup Patel <anup.patel@wdc.com>
2019-06-17firmware: Handle overlapping load and link addresses in relocationXiang W1-2/+42
This patch extends relocation to handle overlapping load and link addresses. The updated relocation will work fine in most cases except when the relocate copy loop itself falls in overlapping load and link addresses. Signed-off-by: Xiang W <wxjstz@126.com> Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-06-12firmware: Relocate when load address is not equal to link addressAnup Patel4-6/+53
This patch extends fw_base to relocate to link address whenever firmware load address is not equal to link address. The relocation will not work when load start to load end overlap link start to link end. Signed-off-by: Anup Patel <anup.patel@wdc.com> Tested-by: Lukas Auer <lukas.auer@aisec.fraunhofer.de>
2019-06-12firmware: add missing linker sections to fw_base.ldSLukas Auer1-0/+4
The linker sections .sdata and .sbss are missing from the linker script fw_base.ldS. Add them to the .data and .bss sections. On current builds, most variables are in the .sbss section. They are not correctly initialized to zero, because they are not within the boundaries indicated by _bss_start and _bss_end. Currently, this does not cause any issues, however with relocation support lock-ups may occur due to incorrectly initialized lock variables. Signed-off-by: Lukas Auer <lukas.auer@aisec.fraunhofer.de> Acked-by: Anup Patel <anup.patel@wdc.com>
2019-05-10firmware: Add fw_dynamic firmwareAnup Patel3-0/+136
This patch provides first-cut implementation of fw_dynamic firmware. As compared to fw_jump and fw_payload, the fw_dynamic obtains next address, next mode and OpenSBI options from struct fw_dynamic_info. The previous booting stage can create struct fw_dynamic_info in memory and pass address of struct fw_dynamic_info in 'a2' register. Also, the struct fw_dynamic_info has versioning as well so changes to the struct fw_dynamic_info can be done in a backward compatible manner. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2019-05-10firmware: Allow firmwares to provide next mode and optionsAnup Patel3-25/+148
This patch extends existing firmwares (i.e. fw_jump and fw_payload) to explicitly provide next mode and options to fw_base. We also introduce fw_save_info() which is called by fw_base very early on boot HART. This function can be used by existing firmwares (i.e. fw_jump and fw_payload) to save information passed by previous booting stage. Overall, this is a preparatory patch for implementing fw_dynamic. 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>
2019-04-24all: run clang-format and update checked-in filesOlof Johansson1-4/+4
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-09TOP: Allow building platform out-of-treeAnup Patel2-4/+4
This patch extends our current build-system for building platform sources which are not part of OpenSBI sources. For example: Let's say we have out-of-tree ABC platform sources. We place these sources under <XYZ>/ABC directory along with its config.mk and objects.mk. To build out-of-tree ABC platform from OpenSBI directory: $ make PLATFORM_DIR=<XYZ>/ABC OR $ make PLATFORM_DIR=<XYZ> PLATFORM=ABC To build out-of-tree ABC platform from <XYZ>/ABC directory: $ make PLATFORM_DIR=<XYZ>/ABC -C <path_to_opensbi> OR $ make PLATFORM_DIR=<XYZ> PLATFORM=ABC -C <path_to_opensbi> Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
2019-04-04firmware: Fix source fdt alignmentXiang Wang1-1/+1
When I tried to start opensbi with coreboot, I found that aligning to a 16-byte boundary would make a copy error. Corrected to align to an machine word length boundary. Signed-off-by: Xiang Wang <wxjstz@126.com>
2019-03-29firmware: Introduce "options" in "struct sbi_scratch"Bin Meng2-0/+10
Introduce "options" in "struct sbi_scratch" and firmware can update it based on optional compile time flags before calling sbi_init(). Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
2019-03-14firmware: Move scratch setup to _start instead of _start_warmAtish Patra1-31/+60
Scratch space setup needs to be done once for reboot for each hart. _start_warm may be called several times if hart hotplug is implemented. Move scratch space setup to the beginning so that it is done only once. Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-03-10lib: Create a sbi_ipi_data structureAlistair Francis1-1/+0
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-07firmware: Reset all registers and flush icacheAtish Patra1-0/+4
A warm reset using reset button may put icache and registers in non-coherent state. Flush the icache and reset all registers for every hart. Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-03-07firmware: Add nop to reduce bus traffic.Atish Patra1-0/+4
All the non-boot harts run in a tight loop which may cause a heavy load on the memory bus. This may delay the boot hart to complete the cold boot process. Introduce few nop that will ease up the traffic. Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-03-07Revert "firmware: Add a barrier instruction for wait for boot hart"Atish Patra1-1/+0
This reverts commit 05602e2bf4812533adcb7acb1a67e43726c0e7bb. Introducing a fence causes warm reset issue to reappear. Revert it for the time being.
2019-03-06firmware: Reset all the general purpose registers to zero.Atish Patra1-0/+41
A warm reset by pressing the reset button may not initialize all the registers to zero. Do it for every hart during warm boot. Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-03-06firmware: Ensure the mtvec is updated.Atish Patra1-0/+5
Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-03-06firmware: Fix a typoAtish Patra1-1/+1
Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-03-05firmware: Add a barrier instruction for wait for boot hartXiang Wang1-0/+1
Multi-core communication via memory requires the addition of a barrier instructions to ensure cache coherency. Signed-off-by: Xiang Wang <wxjstz@126.com>
2019-03-05firmware: Move _boot_hart_done to the data sectionXiang Wang1-6/+5
Writable code section can cause some security problems, so move _boot_hart_done to the data section Signed-off-by: Xiang Wang <wxjstz@126.com>
2019-02-20firmware: Improve low-level trap handler for M-mode to M-mode trapsAnup Patel1-39/+53
This patch extends our low-level trap handler in fw_base.S for handling M-mode to M-mode traps without overwritting stack. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-02-15firmware: Ensure the payloads are 4 bit allignedAlistair Francis1-4/+5
We expect the payloads to be 4 bit alligned as we later AND them with ~0xf. As most of the addresses are manually specified we don't really need this, but better to be over cautious. Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2019-02-14firmware: Use CSR_<FOO> instead of <foo> for csr*Atish Patra2-19/+20
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. Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-02-08firmware: Use lw instead of lwu for 32-bit architecturesAlistair Francis1-0/+14
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2019-02-06firwmare: don't expand macros in FW_PAYLOAD_PATHAndreas Schwab2-7/+4
Signed-off-by: Andreas Schwab <schwab@suse.de>
2019-01-24all: Update copyright header in all filesAnup patel12-36/+36
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-22lib: Move software interrupt enablement from firmware to libAtish Patra1-4/+0
The secondary hart waits for an IPI signal from the boot hart to executing boot code (hot boot). As a result, software generated interrupts have to be enabled for secondary harts before waiting for the boot hart boot completion IPI signal. Enabling software generated interrupts (IPI) can be done independently of the firmware code and moved to libsbi code so that the different firmware do not have to implement this. Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-01-21sbi: Add ecall helpersDamien Le Moal1-9/+1
Define sbi_ecall_console_puts() using sbi_ecall_console_putchar() renamed as sbi_ecall_console_putc() and remove the hardcoded version of the same funtion in the test payload code. Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
2019-01-21payload: rename dummy payload to test payloadDamien Le Moal5-9/+9
Use a more neutral term more representative of this payload intent. Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
2019-01-21Makefile: Add support for device tree compilationDamien Le Moal2-0/+6
Add rules to compile dts files into dtb files using the device tree compiler (dtc). A platform can specify the DTS file to compile using the platform-dtb-y variable. The flattened device tree binary file to be used for building the final polatform firmware can be specified using the new FW_PAYLOAD_FDT firmware configuration option to point to the automatically compiled FDT file. Using the existing FW_PAYLOAD_FDT_PATH configuration option is still possible and will take precedence over the FW_PAYLOAD_FDT definition. Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
2019-01-21build: Introduce FW_PAYLOAD_ALIGNDamien Le Moal3-0/+12
The firmware payload offset defined by FW_PAYLOAD_OFFSET must specify a value large enough so the the payload does not overlap with the base firmware data, bss and text. For platforms without any strong requirement on the payload address, introduce the FW_PAYLOAD_ALIGN build parameter to automatically place the payload right after the base firmware at an address aligned with the defined value. Either FW_PAYLOAD_OFFSET or FW_PAYLOAD_ALIGN should be defined by a platform configuration. If both FW_PAYLOAD_OFFSET and FW_PAYLOAD_ALIGN are defined by a platform, FW_PAYLOAD_OFFSET has precedence and is used for building the final firmawre image. Using FW_PAYLOAD_ALIGN=4096 with the Kendryte platform rather than the abitrary FW_PAYLOAD_OFFSET=0x10000 value reduces the final firmware image size by about 20KB. Add a description of the FW_PAYLOAD_ALIGN configuration parameter in the fw_payload documentation file as well. And while at it, also fix various grammar and style issues in that file.. Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
2019-01-04Makefile: Use generic flags for the firmwareAlistair Francis1-7/+8
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2019-01-03include: Remove redundant tmp0 from struct sbi_scratchAnup Patel1-1/+0
The tmp0 member was added in struct sbi_scratch to assist register save/restore at time of trap handling. This tmp0 is not unsed any more hence removing it. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-01-02include: Move RISCV_TRAP_REGS_xyz defines to sbi_trap.hAnup Patel1-69/+70
The struct sbi_trap_regs related defines RISCV_TRAP_REGS_xyz should be in sbi_trap.h so that we can keep these defines in-sync with changes in struct sbi_trap_regs. Signed-off-by: Anup Patel <anup.patel@wdc.com>