Files
LithosAnanake/include/starkernel/plic.h
T
Robert Allan JamesandClaude Sonnet 5 9b6de5d6c7
Build / build-amd64-iso (push) Waiting to run
Build / build-aarch64-iso (push) Waiting to run
Build / build-riscv64-img (push) Waiting to run
riscv64: PLIC base address DTB-discovered, QEMU-virt constant as fallback (§V.3 item 3)
plic_init() now takes boot_info->dtb (threaded through apic_init()) and
tries fdt_find_node_by_compatible(dtb, "sifive,plic-1.0.0") ->
fdt_find_prop_in_node(..., "reg", ...) before falling back to the
QEMU-virt-specific constant it previously hardcoded unconditionally.
Reuses the node-scoped DTB lookup primitive built for the aarch64 GIC
base fix unchanged. s_plic_base is now a runtime uintptr_t, same shape
as apic.c's s_gicd_base/s_gicc_base.

This system's QEMU/UEFI riscv64 firmware does not forward a DTB to the
guest (timer.c's own timebase-frequency read falls back too, confirmed
in this boot's own log), so only the no-DTB fallback branch is exercised
here -- the success branch (a real DTB with a matching PLIC node) stays
unverified until real Milk-V Mars hardware. FABRIC-3.md's first-drafted
claim that the success branch would run (based on a stale comment in
plic.c's own pre-fix header) was checked against the actual log and
corrected before this commit.

3-arch acceptance: amd64/aarch64 don't compile these files, so their
runs are non-regression on untouched files only. riscv64's own boot log
confirms the fallback path prints exactly as designed and boot reaches
zuse)ok> unchanged.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019YcT3H2PQeyujrzjqS3Var
2026-09-05 00:56:25 -04:00

64 lines
2.5 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
StarForth — Steady-State Virtual Machine Runtime
Copyright (c) 20232025 Robert A. James. All rights reserved.
Licensed under the StarForth License, Version 1.0.
*/
/**
* plic.h - Platform-Level Interrupt Controller interface (riscv64 only)
*
* Item 4.3.5a (FABRIC-0.md §27.5): Phase 0 (0.2/0.3) only ever enabled the
* S-mode *timer* interrupt (sie.STIE). External interrupts (sie.SEIE) were
* never touched, and the PLIC -- the only external-interrupt path on
* RISC-V, there is no legacy PIC or I/O APIC equivalent -- had no driver
* at all before this item. Pure substrate: this item wires the mechanism
* (claim/dispatch/complete) with no permanent source enabled by default;
* a real consumer (4.3.5b, virtio-keyboard) enables its own source later.
*
* @c plic_init() takes the boot DTB as of FABRIC-3.md §V.3 item 3's fix,
* 2026-09-05: the base address was previously a QEMU-virt-specific
* hardcoded constant, unconditionally wrong on the Milk-V Mars's real
* JH7110 PLIC. See @c plic.c's file header for the discovery mechanism.
*/
#ifndef STARKERNEL_PLIC_H
#define STARKERNEL_PLIC_H
#include <stdint.h>
/**
* Map the PLIC and set the S-mode hart-0 context's priority threshold to 0
* (maximally permissive -- safe because nothing is enabled at any source
* by default; enabling a source is what actually lets it reach claim()).
* Also sets sie.SEIE. Does not touch sstatus.SIE -- arch_enable_interrupts()
* still owns that, same as the timer.
*
* @param dtb Candidate devicetree blob (@c BootInfo->dtb); NULL-safe. When
* a real @c "sifive,plic-1.0.0" node is found, the PLIC base
* address is read from its @c reg property; otherwise falls
* back to the QEMU-virt-machine constant, unchanged from this
* function's previous unconditional behaviour.
* @return 0 on success.
*/
int plic_init(const void *dtb);
/** Set a source's interrupt priority (1-7; 0 means "never interrupt"). */
void plic_set_priority(uint32_t irq, uint32_t priority);
/** Enable a source for the S-mode hart-0 context. */
void plic_enable(uint32_t irq);
/** Disable a source for the S-mode hart-0 context. */
void plic_disable(uint32_t irq);
/**
* Claim the highest-priority pending interrupt for the S-mode hart-0
* context. Returns the source ID, or 0 if none is pending.
*/
uint32_t plic_claim(void);
/** Signal completion of the source previously returned by plic_claim(). */
void plic_complete(uint32_t irq);
#endif /* STARKERNEL_PLIC_H */