| 1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
| 2 | /* |
| 3 | * Copyright (c) 2019 Western Digital Corporation or its affiliates. |
| 4 | * |
| 5 | * Based on include/sbi/{fw_dynamic.h,sbi_scratch.h} from the OpenSBI project. |
| 6 | */ |
| 7 | |
| 8 | #ifndef RISCV_BOOT_OPENSBI_H |
| 9 | #define RISCV_BOOT_OPENSBI_H |
| 10 | |
| 11 | #include "exec/cpu-defs.h" |
| 12 | |
| 13 | /** Expected value of info magic ('OSBI' ascii string in hex) */ |
| 14 | #define FW_DYNAMIC_INFO_MAGIC_VALUE 0x4942534f |
| 15 | |
| 16 | /** Maximum supported info version */ |
| 17 | #define FW_DYNAMIC_INFO_VERSION 0x2 |
| 18 | |
| 19 | /** Possible next mode values */ |
| 20 | #define FW_DYNAMIC_INFO_NEXT_MODE_U 0x0 |
| 21 | #define FW_DYNAMIC_INFO_NEXT_MODE_S 0x1 |
| 22 | #define FW_DYNAMIC_INFO_NEXT_MODE_M 0x3 |
| 23 | |
| 24 | enum sbi_scratch_options { |
| 25 | /** Disable prints during boot */ |
| 26 | SBI_SCRATCH_NO_BOOT_PRINTS = (1 << 0), |
| 27 | /** Enable runtime debug prints */ |
| 28 | SBI_SCRATCH_DEBUG_PRINTS = (1 << 1), |
| 29 | }; |
| 30 | |
| 31 | /** Representation dynamic info passed by previous booting stage */ |
| 32 | struct fw_dynamic_info64 { |
| 33 | /** Info magic */ |
| 34 | int64_t magic; |
| 35 | /** Info version */ |
| 36 | int64_t version; |
| 37 | /** Next booting stage address */ |
| 38 | int64_t next_addr; |
| 39 | /** Next booting stage mode */ |
| 40 | int64_t next_mode; |
| 41 | /** Options for OpenSBI library */ |
| 42 | int64_t options; |
| 43 | /** |
| 44 | * Preferred boot HART id |
| 45 | * |
| 46 | * It is possible that the previous booting stage uses same link |
| 47 | * address as the FW_DYNAMIC firmware. In this case, the relocation |
| 48 | * lottery mechanism can potentially overwrite the previous booting |
| 49 | * stage while other HARTs are still running in the previous booting |
| 50 | * stage leading to boot-time crash. To avoid this boot-time crash, |
| 51 | * the previous booting stage can specify last HART that will jump |
| 52 | * to the FW_DYNAMIC firmware as the preferred boot HART. |
| 53 | * |
| 54 | * To avoid specifying a preferred boot HART, the previous booting |
| 55 | * stage can set it to -1UL which will force the FW_DYNAMIC firmware |
| 56 | * to use the relocation lottery mechanism. |
| 57 | */ |
| 58 | int64_t boot_hart; |
| 59 | }; |
| 60 | |
| 61 | /** Representation dynamic info passed by previous booting stage */ |
| 62 | struct fw_dynamic_info32 { |
| 63 | /** Info magic */ |
| 64 | int32_t magic; |
| 65 | /** Info version */ |
| 66 | int32_t version; |
| 67 | /** Next booting stage address */ |
| 68 | int32_t next_addr; |
| 69 | /** Next booting stage mode */ |
| 70 | int32_t next_mode; |
| 71 | /** Options for OpenSBI library */ |
| 72 | int32_t options; |
| 73 | /** |
| 74 | * Preferred boot HART id |
| 75 | * |
| 76 | * It is possible that the previous booting stage uses same link |
| 77 | * address as the FW_DYNAMIC firmware. In this case, the relocation |
| 78 | * lottery mechanism can potentially overwrite the previous booting |
| 79 | * stage while other HARTs are still running in the previous booting |
| 80 | * stage leading to boot-time crash. To avoid this boot-time crash, |
| 81 | * the previous booting stage can specify last HART that will jump |
| 82 | * to the FW_DYNAMIC firmware as the preferred boot HART. |
| 83 | * |
| 84 | * To avoid specifying a preferred boot HART, the previous booting |
| 85 | * stage can set it to -1UL which will force the FW_DYNAMIC firmware |
| 86 | * to use the relocation lottery mechanism. |
| 87 | */ |
| 88 | int32_t boot_hart; |
| 89 | }; |
| 90 | #endif |