arch-riscv,dev: Update the PLIC implementation (#886)

Update the PLIC based on the
[riscv-plic-spec](https://github.com/riscv/riscv-plic-spec) in the PR:
- Support customized PLIC hardID and privilege mode configuration
- Backward compatable with the n_contexts parameter, will generate the
config like {0,M}, {0,S}, {1,M} ...

Change-Id: Ibff736827edb7c97921e01fa27f503574a27a562
This commit is contained in:
Yu-Cheng Chang
2024-02-27 02:32:53 +08:00
committed by GitHub
parent 521a7c1de0
commit bcf455755e
7 changed files with 155 additions and 66 deletions

View File

@@ -185,7 +185,7 @@ class LupvBoard(AbstractSystemBoard, KernelDiskWorkload):
# point for our bbl to use upon startup, and will
# remain unused during the simulation
self.pic.n_src = 0
self.pic.n_contexts = 0
self.pic.hart_config = ""
self.lupio_pic.n_src = max(pic_srcs) + 1
self.lupio_pic.num_threads = self.processor.get_num_cores()
@@ -403,10 +403,19 @@ class LupvBoard(AbstractSystemBoard, KernelDiskWorkload):
plic_node.append(FdtPropertyWords("riscv,ndev", 0))
int_extended = list()
for i, core in enumerate(self.get_processor().get_cores()):
phandle = state.phandle(f"cpu@{i}.int_state")
int_extended.append(phandle)
int_extended.append(self._excep_code["INT_EXT_MACHINE"])
cpu_id = 0
phandle = int_state.phandle(f"cpu@{cpu_id}.int_state")
for c in plic.hart_config:
if c == ",":
cpu_id += 1
assert cpu_id < self.get_processor().get_num_cores()
phandle = int_state.phandle(f"cpu@{cpu_id}.int_state")
elif c == "S":
int_extended.append(phandle)
int_extended.append(self._excep_code["INT_SOFT_SUPER"])
elif c == "M":
int_extended.append(phandle)
int_extended.append(self._excep_code["INT_EXT_MACHINE"])
plic_node.append(FdtPropertyWords("interrupts-extended", int_extended))
plic_node.append(FdtProperty("interrupt-controller"))

View File

@@ -102,7 +102,9 @@ class RiscvBoard(AbstractSystemBoard, KernelDiskWorkload):
# Contains a CLINT, PLIC, UART, and some functions for the dtb, etc.
self.platform = HiFive()
# Note: This only works with single threaded cores.
self.platform.plic.n_contexts = self.processor.get_num_cores() * 2
self.platform.plic.hart_config = ",".join(
["MS" for _ in range(self.processor.get_num_cores())]
)
self.platform.attachPlic()
self.platform.clint.num_threads = self.processor.get_num_cores()
@@ -353,12 +355,19 @@ class RiscvBoard(AbstractSystemBoard, KernelDiskWorkload):
plic_node.append(FdtPropertyWords("riscv,ndev", [plic.n_src - 1]))
int_extended = list()
for i, core in enumerate(self.get_processor().get_cores()):
phandle = state.phandle(f"cpu@{i}.int_state")
int_extended.append(phandle)
int_extended.append(0xB)
int_extended.append(phandle)
int_extended.append(0x9)
cpu_id = 0
phandle = int_state.phandle(f"cpu@{cpu_id}.int_state")
for c in plic.hart_config:
if c == ",":
cpu_id += 1
assert cpu_id < self.get_processor().get_num_cores()
phandle = int_state.phandle(f"cpu@{cpu_id}.int_state")
elif c == "S":
int_extended.append(phandle)
int_extended.append(0x9)
elif c == "M":
int_extended.append(phandle)
int_extended.append(0xB)
plic_node.append(FdtPropertyWords("interrupts-extended", int_extended))
plic_node.append(FdtProperty("interrupt-controller"))

View File

@@ -149,7 +149,9 @@ class RISCVMatchedBoard(
# Contains a CLINT, PLIC, UART, and some functions for the dtb, etc.
self.platform = HiFive()
# Note: This only works with single threaded cores.
self.platform.plic.n_contexts = self.processor.get_num_cores() * 2
self.platform.plic.hart_config = ",".join(
["MS" for _ in range(self.processor.get_num_cores())]
)
self.platform.attachPlic()
self.platform.clint.num_threads = self.processor.get_num_cores()
@@ -433,12 +435,19 @@ class RISCVMatchedBoard(
plic_node.append(FdtPropertyWords("riscv,ndev", [plic.n_src - 1]))
int_extended = list()
for i, core in enumerate(self.get_processor().get_cores()):
phandle = state.phandle(f"cpu@{i}.int_state")
int_extended.append(phandle)
int_extended.append(0xB)
int_extended.append(phandle)
int_extended.append(0x9)
cpu_id = 0
phandle = int_state.phandle(f"cpu@{cpu_id}.int_state")
for c in plic.hart_config:
if c == ",":
cpu_id += 1
assert cpu_id < self.get_processor().get_num_cores()
phandle = int_state.phandle(f"cpu@{cpu_id}.int_state")
elif c == "S":
int_extended.append(phandle)
int_extended.append(0x9)
elif c == "M":
int_extended.append(phandle)
int_extended.append(0xB)
plic_node.append(FdtPropertyWords("interrupts-extended", int_extended))
plic_node.append(FdtProperty("interrupt-controller"))