As of now, everything except the code imported from FreeBSD is proprietary. Of course, it won't be like this for long, only until we have decided which license we like to use. The rationale is that releasing everything under a copyleft license later is always easier than doing so immediately and then changing it afterwards. Naturally, any changes made before this commit are still subject to the terms of the CNPL.
69 lines
1.4 KiB
C
69 lines
1.4 KiB
C
/* Copyright (C) 2021 fef <owo@fef.moe>. All rights reserved. */
|
|
|
|
#include <arch/irq.h>
|
|
|
|
#include <gay/config.h>
|
|
#include <gay/errno.h>
|
|
#include <gay/irq.h>
|
|
#include <gay/kprintf.h>
|
|
|
|
void (*irq_table[NUM_IRQ])(void);
|
|
|
|
#if CFG_DEBUG_IRQ
|
|
/*
|
|
* If CFG_DEBUG_IRQ is set, the IRQ entry points pass the IRQ number
|
|
* as an argument to the IRQ handler (see arch/<arch>/sys/irq.S).
|
|
*/
|
|
static void do_unknown_irq(unsigned int number)
|
|
{
|
|
kprintf("Unknown IRQ %d encountered!\n", number);
|
|
}
|
|
# define UNKNOWN_IRQ_HANDLER ((void (*)(void))do_unknown_irq)
|
|
#else
|
|
static void do_unknown_irq(void)
|
|
{
|
|
kprintf("Unknown IRQ encountered!\n");
|
|
}
|
|
# define UNKNOWN_IRQ_HANDLER (do_unknown_irq)
|
|
#endif
|
|
|
|
void irq_init(void)
|
|
{
|
|
for (unsigned int i = 0; i < NUM_IRQ; i++)
|
|
irq_table[i] = UNKNOWN_IRQ_HANDLER;
|
|
arch_irq_init();
|
|
}
|
|
|
|
int irq_enable(unsigned int number)
|
|
{
|
|
if (number >= NUM_IRQ)
|
|
return -ERANGE;
|
|
if (irq_table[number] == UNKNOWN_IRQ_HANDLER)
|
|
return -ENOENT;
|
|
|
|
arch_irq_enable(number);
|
|
return 0;
|
|
}
|
|
|
|
void irq_disable(unsigned int number)
|
|
{
|
|
if (number < NUM_IRQ)
|
|
arch_irq_disable(number);
|
|
}
|
|
|
|
int irq_attach(unsigned int number, void (*handler)(void))
|
|
{
|
|
if (number >= NUM_IRQ)
|
|
return -ERANGE;
|
|
if (irq_table[number] != UNKNOWN_IRQ_HANDLER)
|
|
return -EEXIST;
|
|
|
|
irq_table[number] = handler;
|
|
return 0;
|
|
}
|
|
|
|
void irq_detach(unsigned int number)
|
|
{
|
|
if (number < NUM_IRQ)
|
|
irq_table[number] = UNKNOWN_IRQ_HANDLER;
|
|
}
|