kernel/plic.c

47 lines
1#include "types.h"2#include "param.h"3#include "memlayout.h"4#include "riscv.h"5#include "defs.h"67//8// the riscv Platform Level Interrupt Controller (PLIC).9//1011void12plicinit(void)13{14  // set desired IRQ priorities non-zero (otherwise disabled).15  *(uint32*)(PLIC + UART0_IRQ*4) = 1;16  *(uint32*)(PLIC + VIRTIO0_IRQ*4) = 1;17}1819void20plicinithart(void)21{22  int hart = cpuid();23  24  // set enable bits for this hart's S-mode25  // for the uart and virtio disk.26  *(uint32*)PLIC_SENABLE(hart) = (1 << UART0_IRQ) | (1 << VIRTIO0_IRQ);2728  // set this hart's S-mode priority threshold to 0.29  *(uint32*)PLIC_SPRIORITY(hart) = 0;30}3132// ask the PLIC what interrupt we should serve.33int34plic_claim(void)35{36  int hart = cpuid();37  int irq = *(uint32*)PLIC_SCLAIM(hart);38  return irq;39}4041// tell the PLIC we've served this IRQ.42void43plic_complete(int irq)44{45  int hart = cpuid();46  *(uint32*)PLIC_SCLAIM(hart) = irq;47}48