HelenOS sources
This source file includes following definitions.
- pic_enable_irq
- i8259_connection
- i8259_add
- i8259_remove
- i8259_gone
#include <ipc/irc.h>
#include <loc.h>
#include <sysinfo.h>
#include <as.h>
#include <ddf/log.h>
#include <ddi.h>
#include <align.h>
#include <stdbool.h>
#include <errno.h>
#include <str_error.h>
#include <async.h>
#include <stdio.h>
#include "i8259.h"
#define NAME "i8259"
#define IO_RANGE0_SIZE 2
#define IO_RANGE1_SIZE 2
#define PIC_PIC0PORT1 0
#define PIC_PIC0PORT2 1
#define PIC_PIC1PORT1 0
#define PIC_PIC1PORT2 1
#define PIC_MAX_IRQ 15
static errno_t pic_enable_irq(i8259_t *i8259, sysarg_t irq)
{
if (irq > PIC_MAX_IRQ)
return ENOENT;
uint16_t irqmask = 1 << irq;
uint8_t val;
if (irqmask & 0xff) {
val = pio_read_8(i8259->regs0 + PIC_PIC0PORT2);
pio_write_8(i8259->regs0 + PIC_PIC0PORT2,
(uint8_t) (val & (~(irqmask & 0xff))));
}
if (irqmask >> 8) {
val = pio_read_8(i8259->regs1 + PIC_PIC1PORT2);
pio_write_8(i8259->regs1 + PIC_PIC1PORT2,
(uint8_t) (val & (~(irqmask >> 8))));
}
return EOK;
}
static void i8259_connection(ipc_call_t *icall, void *arg)
{
ipc_call_t call;
i8259_t *i8259 = NULL ;
async_accept_0(icall);
i8259 = (i8259_t *) ddf_dev_data_get(ddf_fun_get_dev((ddf_fun_t *) arg));
while (true) {
async_get_call(&call);
if (!ipc_get_imethod(&call)) {
async_answer_0(&call, EOK);
return;
}
switch (ipc_get_imethod(&call)) {
case IRC_ENABLE_INTERRUPT:
async_answer_0(&call, pic_enable_irq(i8259,
ipc_get_arg1(&call)));
break;
case IRC_DISABLE_INTERRUPT:
async_answer_0(&call, EOK);
break;
case IRC_CLEAR_INTERRUPT:
async_answer_0(&call, EOK);
break;
default:
async_answer_0(&call, EINVAL);
break;
}
}
}
errno_t i8259_add(i8259_t *i8259, i8259_res_t *res)
{
sysarg_t have_i8259;
ioport8_t *regs0;
ioport8_t *regs1;
ddf_fun_t *fun_a = NULL;
errno_t rc;
bool bound = false;
if ((sysinfo_get_value("i8259", &have_i8259) != EOK) || (!have_i8259)) {
printf("%s: No i8259 found\n", NAME);
return ENOTSUP;
}
if ((pio_enable((void *) res->base0, IO_RANGE0_SIZE,
(void **) ®s0) != EOK) ||
(pio_enable((void *) res->base1, IO_RANGE1_SIZE,
(void **) ®s1) != EOK)) {
printf("%s: i8259 not accessible\n", NAME);
return EIO;
}
i8259->regs0 = regs0;
i8259->regs1 = regs1;
fun_a = ddf_fun_create(i8259->dev, fun_exposed, "a");
if (fun_a == NULL) {
ddf_msg(LVL_ERROR, "Failed creating function 'a'.");
rc = ENOMEM;
goto error;
}
ddf_fun_set_conn_handler(fun_a, i8259_connection);
rc = ddf_fun_bind(fun_a);
if (rc != EOK) {
ddf_msg(LVL_ERROR, "Failed binding function 'a': %s", str_error(rc));
goto error;
}
bound = true;
rc = ddf_fun_add_to_category(fun_a, "irc");
if (rc != EOK)
goto error;
return EOK;
error:
if (bound)
ddf_fun_unbind(fun_a);
if (fun_a != NULL)
ddf_fun_destroy(fun_a);
return rc;
}
errno_t i8259_remove(i8259_t *i8259)
{
return ENOTSUP;
}
errno_t i8259_gone(i8259_t *i8259)
{
return ENOTSUP;
}
HelenOS homepage, sources at GitHub