MOS Source Code
Loading...
Searching...
No Matches
plic.c
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2
4
5#include "mos/mm/mm.h"
6
7#include <mos/types.h>
8
9// qemu puts platform-level interrupt controller (PLIC) here.
10#define PLIC pa_va(0x0c000000L)
11#define PLIC_PRIORITY (PLIC + 0x0)
12#define PLIC_PENDING (PLIC + 0x1000)
13#define PLIC_MENABLE(hart) (PLIC + 0x2000 + (hart) * 0x100)
14#define PLIC_SENABLE(hart) (PLIC + 0x2080 + (hart) * 0x100)
15#define PLIC_MPRIORITY(hart) (PLIC + 0x200000 + (hart) * 0x2000)
16#define PLIC_SPRIORITY(hart) (PLIC + 0x201000 + (hart) * 0x2000)
17#define PLIC_MCLAIM(hart) (PLIC + 0x200004 + (hart) * 0x2000)
18#define PLIC_SCLAIM(hart) (PLIC + 0x201004 + (hart) * 0x2000)
19
20#define PLIC_IRQPRIO(irq) (PLIC + irq * 4)
21
23{
24 return *(u32 *) PLIC_SCLAIM(0);
25}
26
28{
29 *(u32 *) PLIC_SCLAIM(0) = irq;
30}
31
33{
34 *(u32 *) PLIC_IRQPRIO(irq) = 1; // set priority to a non-zero value
35 *(u32 *) PLIC_SENABLE(0) = 1 << irq; // enable the irq
36 *(u32 *) PLIC_SPRIORITY(0) = 0;
37}
u32 plic_claim_irq()
Definition plic.c:22
#define PLIC_IRQPRIO(irq)
Definition plic.c:20
#define PLIC_SENABLE(hart)
Definition plic.c:14
void plic_complete(u32 irq)
Definition plic.c:27
void plic_enable_irq(u32 irq)
Definition plic.c:32
#define PLIC_SPRIORITY(hart)
Definition plic.c:16
#define PLIC_SCLAIM(hart)
Definition plic.c:18
unsigned int u32
Definition types.h:21