root/kernel/plic.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. plicinit
  2. plicinithart
  3. plic_claim
  4. plic_complete

   1 #include "types.h"
   2 #include "param.h"
   3 #include "memlayout.h"
   4 #include "riscv.h"
   5 #include "defs.h"
   6 
   7 //
   8 // the riscv Platform Level Interrupt Controller (PLIC).
   9 //
  10 
  11 void
  12 plicinit(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 }
  18 
  19 void
  20 plicinithart(void)
  21 {
  22   int hart = cpuid();
  23   
  24   // set enable bits for this hart's S-mode
  25   // for the uart and virtio disk.
  26   *(uint32*)PLIC_SENABLE(hart) = (1 << UART0_IRQ) | (1 << VIRTIO0_IRQ);
  27 
  28   // set this hart's S-mode priority threshold to 0.
  29   *(uint32*)PLIC_SPRIORITY(hart) = 0;
  30 }
  31 
  32 // ask the PLIC what interrupt we should serve.
  33 int
  34 plic_claim(void)
  35 {
  36   int hart = cpuid();
  37   int irq = *(uint32*)PLIC_SCLAIM(hart);
  38   return irq;
  39 }
  40 
  41 // tell the PLIC we've served this IRQ.
  42 void
  43 plic_complete(int irq)
  44 {
  45   int hart = cpuid();
  46   *(uint32*)PLIC_SCLAIM(hart) = irq;
  47 }

/* [<][>][^][v][top][bottom][index][help] */