diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-05-24 13:24:27 +0300 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-05-24 18:13:43 +0300 |
| commit | bc600ecc3bdf0f189861dfb840f70c2339a7a853 (patch) | |
| tree | d9840b1dc1b865442a028c03ad7109ac67894f6e /src/irq.c | |
| parent | 6a7073e5f262db9a4578ff00b5b28e34335564ce (diff) | |
| download | kmi-bc600ecc3bdf0f189861dfb840f70c2339a7a853.tar.gz kmi-bc600ecc3bdf0f189861dfb840f70c2339a7a853.zip | |
rename common to src
+ I keep starting to type src and wondering why autocomplete won't work,
I guess src is just uncounciously a better name
Diffstat (limited to 'src/irq.c')
| -rw-r--r-- | src/irq.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/irq.c b/src/irq.c new file mode 100644 index 0000000..db90d34 --- /dev/null +++ b/src/irq.c @@ -0,0 +1,67 @@ +/* SPDX-License-Identifier: copyleft-next-0.3.1 */ +/* Copyright 2023, Kim Kuparinen < kimi.h.kuparinen@gmail.com > */ + +/** + * @file irq.c + * Common IRQ handling stuff implementations. + */ + +#include <kmi/irq.h> +#include <kmi/pmem.h> +#include <kmi/debug.h> +#include <kmi/assert.h> +#include <kmi/string.h> +#include <arch/irq.h> + +/** Hold maximum IRQ id supported by system. */ +static size_t max_irq; + +/** Hold map of IRD ID -> thread id. @todo process id? */ +static id_t *irq_map; + +void init_irq(void *fdt) +{ + /** @todo check arch max irq and adjust accordingly */ + irq_map = (id_t *)alloc_page(MM_O0); + memset(irq_map, 0, order_size(MM_O0)); + max_irq = order_size(MM_O0) / sizeof(irq_map[0]); + + setup_irq(fdt); +} + +stat_t register_irq(struct tcb *t, irq_t id) +{ + if (id >= max_irq) + return ERR_INVAL; + + if (irq_map[id]) + return ERR_EXT; + + irq_map[id] = t->tid; + return activate_irq(id); +} + +stat_t unregister_irq(struct tcb *t, irq_t id) +{ + id_t tid = irq_map[id]; + if (tid != t->tid) + return ERR_PERM; + + irq_map[id] = 0; + return deactivate_irq(id); +} + +void handle_irq() +{ + irq_t id = get_irq(); + hard_assert(id < max_irq, RETURN_VOID); + + id_t tid = irq_map[id]; + + if (!tid) { + bug("unregistered irq: %llu\n", (unsigned long long)id); + return; + } + + /** @todo switch to thread */ +} |
