xref: /openbmc/qemu/include/hw/riscv/boot_opensbi.h (revision 4921d0a7)
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_info {
33     /** Info magic */
34     target_long magic;
35     /** Info version */
36     target_long version;
37     /** Next booting stage address */
38     target_long next_addr;
39     /** Next booting stage mode */
40     target_long next_mode;
41     /** Options for OpenSBI library */
42     target_long 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     target_long boot_hart;
59 };
60 
61 #endif
62