Skip to content

Commit accb9db

Browse files
damien-lemoalpaul-walmsley-sifive
authored andcommitted
riscv: read the hart ID from mhartid on boot
When in M-Mode, we can use the mhartid CSR to get the ID of the running HART. Doing so, direct M-Mode boot without firmware is possible. Signed-off-by: Damien Le Moal <[email protected]> Reviewed-by: Anup Patel <[email protected]> Reviewed-by: Atish Patra <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]> Signed-off-by: Paul Walmsley <[email protected]>
1 parent fcdc653 commit accb9db

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

arch/riscv/include/asm/csr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
#define CSR_MCAUSE 0x342
100100
#define CSR_MTVAL 0x343
101101
#define CSR_MIP 0x344
102+
#define CSR_MHARTID 0xf14
102103

103104
#ifdef CONFIG_RISCV_M_MODE
104105
# define CSR_STATUS CSR_MSTATUS

arch/riscv/kernel/head.S

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ _start_kernel:
5050
csrw CSR_IE, zero
5151
csrw CSR_IP, zero
5252

53+
#ifdef CONFIG_RISCV_M_MODE
54+
/*
55+
* The hartid in a0 is expected later on, and we have no firmware
56+
* to hand it to us.
57+
*/
58+
csrr a0, CSR_MHARTID
59+
#endif
60+
5361
/* Load the global pointer */
5462
.option push
5563
.option norelax

0 commit comments

Comments
 (0)