Skip to content

Commit

Permalink
riscv: read the hart ID from mhartid on boot
Browse files Browse the repository at this point in the history
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 <damien.lemoal@wdc.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Paul Walmsley <paul.walmsley@sifive.com>
  • Loading branch information
Damien Le Moal authored and Paul Walmsley committed Nov 17, 2019
1 parent fcdc653 commit accb9db
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions arch/riscv/include/asm/csr.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
#define CSR_MCAUSE 0x342
#define CSR_MTVAL 0x343
#define CSR_MIP 0x344
#define CSR_MHARTID 0xf14

#ifdef CONFIG_RISCV_M_MODE
# define CSR_STATUS CSR_MSTATUS
Expand Down
8 changes: 8 additions & 0 deletions arch/riscv/kernel/head.S
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ _start_kernel:
csrw CSR_IE, zero
csrw CSR_IP, zero

#ifdef CONFIG_RISCV_M_MODE
/*
* The hartid in a0 is expected later on, and we have no firmware
* to hand it to us.
*/
csrr a0, CSR_MHARTID
#endif

/* Load the global pointer */
.option push
.option norelax
Expand Down

0 comments on commit accb9db

Please sign in to comment.