mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 12:48:22 +00:00
kernel: DPC support
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include <arch/ps2.h>
|
||||
#include <kernel/keyboard.h>
|
||||
#include <kernel/console.h>
|
||||
#include <kernel/dpc.h>
|
||||
|
||||
static cpu_t bsp_cpu;
|
||||
|
||||
@@ -31,6 +32,7 @@ void kernel_entry() {
|
||||
arch_gdt_reload();
|
||||
arch_idt_setup();
|
||||
arch_idt_reload();
|
||||
dpc_init();
|
||||
pmm_init();
|
||||
term_init();
|
||||
logging_sethook(term_putchar);
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef _DPC_H
|
||||
#define _DPC_H
|
||||
|
||||
#include <arch/context.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef void * dpcarg_t;
|
||||
typedef void (*dpcfn_t)(context_t *, dpcarg_t);
|
||||
|
||||
typedef struct _dpc_t {
|
||||
struct _dpc_t *next;
|
||||
struct _dpc_t *prev;
|
||||
bool enqueued;
|
||||
dpcfn_t fn;
|
||||
dpcarg_t arg;
|
||||
} dpc_t;
|
||||
|
||||
void dpc_enqueue(dpc_t *dpc, dpcfn_t, dpcarg_t);
|
||||
void dpc_dequeue(dpc_t *dpc);
|
||||
void dpc_init();
|
||||
|
||||
#endif
|
||||
@@ -15,6 +15,7 @@
|
||||
#define IPL_MAX 0
|
||||
#define IPL_TIMER 1
|
||||
#define IPL_KEYBOARD 2
|
||||
#define IPL_DPC 900
|
||||
#define IPL_NORMAL 1000
|
||||
|
||||
struct _isr_t;
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <kernel/vmm.h>
|
||||
#include <kernel/timer.h>
|
||||
#include <kernel/scheduler.h>
|
||||
#include <kernel/dpc.h>
|
||||
|
||||
typedef struct cpu_t {
|
||||
thread_t *thread;
|
||||
@@ -26,6 +27,7 @@ typedef struct cpu_t {
|
||||
timerentry_t schedtimerentry;
|
||||
void *schedulerstack;
|
||||
isr_t *isrqueue;
|
||||
dpc_t *dpcqueue;
|
||||
} cpu_t;
|
||||
|
||||
#define CPU_HALT() asm volatile("hlt")
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
#include <kernel/dpc.h>
|
||||
#include <arch/cpu.h>
|
||||
#include <kernel/interrupt.h>
|
||||
#include <logging.h>
|
||||
|
||||
static isr_t *dpcisr;
|
||||
|
||||
static void remove(dpc_t *dpc) {
|
||||
if (dpc->prev)
|
||||
dpc->prev->next = dpc->next;
|
||||
else
|
||||
_cpu()->dpcqueue = dpc->next;
|
||||
|
||||
if (dpc->next)
|
||||
dpc->next->prev = dpc->prev;
|
||||
}
|
||||
|
||||
static void insert(dpc_t *dpc) {
|
||||
dpc->prev = NULL;
|
||||
dpc->next = _cpu()->dpcqueue;
|
||||
|
||||
if (dpc->next)
|
||||
dpc->next->prev = dpc;
|
||||
|
||||
_cpu()->dpcqueue = dpc;
|
||||
}
|
||||
|
||||
static void isrfn(isr_t *self, context_t *context) {
|
||||
while (_cpu()->dpcqueue) {
|
||||
dpc_t *dpc = _cpu()->dpcqueue;
|
||||
remove(dpc);
|
||||
|
||||
__assert(dpc->enqueued);
|
||||
dpc->enqueued = false;
|
||||
|
||||
interrupt_set(true);
|
||||
dpc->fn(context, dpc->arg);
|
||||
interrupt_set(false);
|
||||
}
|
||||
}
|
||||
|
||||
void dpc_enqueue(dpc_t *dpc, dpcfn_t fn, dpcarg_t arg) {
|
||||
bool entrystate = interrupt_set(false);
|
||||
|
||||
if (dpc->enqueued)
|
||||
goto cleanup;
|
||||
|
||||
dpc->fn = fn;
|
||||
dpc->arg = arg;
|
||||
dpc->enqueued = true;
|
||||
insert(dpc);
|
||||
interrupt_raise(dpcisr);
|
||||
|
||||
cleanup:
|
||||
interrupt_set(entrystate);
|
||||
}
|
||||
|
||||
void dpc_dequeue(dpc_t *dpc) {
|
||||
bool entrystate = interrupt_set(false);
|
||||
|
||||
if (dpc->enqueued == false)
|
||||
goto cleanup;
|
||||
|
||||
dpc->enqueued = false;
|
||||
remove(dpc);
|
||||
|
||||
cleanup:
|
||||
interrupt_set(entrystate);
|
||||
}
|
||||
|
||||
void dpc_init() {
|
||||
dpcisr = interrupt_allocate(isrfn, NULL, IPL_DPC);
|
||||
__assert(dpcisr);
|
||||
}
|
||||
Reference in New Issue
Block a user