Fixed the messed up indentation (8 spaces instead of tabs)
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@309 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+96
-86
@@ -17,132 +17,142 @@
|
|||||||
#define NUM_IO_VECTORS 256
|
#define NUM_IO_VECTORS 256
|
||||||
|
|
||||||
struct io_handler {
|
struct io_handler {
|
||||||
struct io_handler *next;
|
struct io_handler *next;
|
||||||
int (*func)(void*);
|
int (*func)(void*);
|
||||||
void* data;
|
void* data;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct io_vector {
|
struct io_vector {
|
||||||
struct io_handler *handler_list;
|
struct io_handler *handler_list;
|
||||||
spinlock_t vector_lock;
|
spinlock_t vector_lock;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct io_vector *io_vectors = NULL;
|
static struct io_vector *io_vectors = NULL;
|
||||||
|
|
||||||
int int_init(kernel_args *ka)
|
|
||||||
{
|
|
||||||
dprintf("init_int_handlers: entry\n");
|
|
||||||
|
|
||||||
return arch_int_init(ka);
|
int
|
||||||
|
int_init(kernel_args *ka)
|
||||||
|
{
|
||||||
|
dprintf("init_int_handlers: entry\n");
|
||||||
|
|
||||||
|
return arch_int_init(ka);
|
||||||
}
|
}
|
||||||
|
|
||||||
int int_init2(kernel_args *ka)
|
|
||||||
|
int
|
||||||
|
int_init2(kernel_args *ka)
|
||||||
{
|
{
|
||||||
io_vectors = (struct io_vector *)kmalloc(sizeof(struct io_vectors *) * NUM_IO_VECTORS);
|
io_vectors = (struct io_vector *)kmalloc(sizeof(struct io_vectors *) * NUM_IO_VECTORS);
|
||||||
if(io_vectors == NULL)
|
if (io_vectors == NULL)
|
||||||
panic("int_init2: could not create io vector table!\n");
|
panic("int_init2: could not create io vector table!\n");
|
||||||
|
|
||||||
memset(io_vectors, 0, sizeof(struct io_vector *) * NUM_IO_VECTORS);
|
memset(io_vectors, 0, sizeof(struct io_vector *) * NUM_IO_VECTORS);
|
||||||
|
|
||||||
return arch_int_init2(ka);
|
return arch_int_init2(ka);
|
||||||
}
|
}
|
||||||
|
|
||||||
int int_set_io_interrupt_handler(int vector, int (*func)(void*), void* data)
|
|
||||||
|
int
|
||||||
|
int_set_io_interrupt_handler(int vector, int (*func)(void*), void* data)
|
||||||
{
|
{
|
||||||
struct io_handler *io;
|
struct io_handler *io;
|
||||||
int state;
|
int state;
|
||||||
|
|
||||||
// insert this io handler in the chain of interrupt
|
// insert this io handler in the chain of interrupt
|
||||||
// handlers registered for this io interrupt
|
// handlers registered for this io interrupt
|
||||||
|
|
||||||
io = (struct io_handler *)kmalloc(sizeof(struct io_handler));
|
io = (struct io_handler *)kmalloc(sizeof(struct io_handler));
|
||||||
if(io == NULL)
|
if (io == NULL)
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
io->func = func;
|
io->func = func;
|
||||||
io->data = data;
|
io->data = data;
|
||||||
|
|
||||||
state = int_disable_interrupts();
|
state = int_disable_interrupts();
|
||||||
acquire_spinlock(&io_vectors[vector].vector_lock);
|
acquire_spinlock(&io_vectors[vector].vector_lock);
|
||||||
io->next = io_vectors[vector].handler_list;
|
io->next = io_vectors[vector].handler_list;
|
||||||
io_vectors[vector].handler_list = io;
|
io_vectors[vector].handler_list = io;
|
||||||
release_spinlock(&io_vectors[vector].vector_lock);
|
release_spinlock(&io_vectors[vector].vector_lock);
|
||||||
int_restore_interrupts(state);
|
int_restore_interrupts(state);
|
||||||
|
|
||||||
arch_int_enable_io_interrupt(vector);
|
arch_int_enable_io_interrupt(vector);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int int_remove_io_interrupt_handler(int vector, int (*func)(void*), void* data)
|
|
||||||
|
int
|
||||||
|
int_remove_io_interrupt_handler(int vector, int (*func)(void*), void* data)
|
||||||
{
|
{
|
||||||
struct io_handler *io, *prev = NULL;
|
struct io_handler *io, *prev = NULL;
|
||||||
int state;
|
int state;
|
||||||
|
|
||||||
// lock the structures down so it is not modified while we search
|
// lock the structures down so it is not modified while we search
|
||||||
state = int_disable_interrupts();
|
state = int_disable_interrupts();
|
||||||
acquire_spinlock(&io_vectors[vector].vector_lock);
|
acquire_spinlock(&io_vectors[vector].vector_lock);
|
||||||
|
|
||||||
// start at the beginning
|
// start at the beginning
|
||||||
io = io_vectors[vector].handler_list;
|
io = io_vectors[vector].handler_list;
|
||||||
|
|
||||||
// while not at end
|
// while not at end
|
||||||
while(io != NULL) {
|
while (io != NULL) {
|
||||||
// see if we match both the function & data
|
// see if we match both the function & data
|
||||||
if (io->func == func && io->data == data)
|
if (io->func == func && io->data == data)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Store our backlink and move to next
|
// Store our backlink and move to next
|
||||||
prev = io;
|
prev = io;
|
||||||
io = io->next;
|
io = io->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we found it
|
// If we found it
|
||||||
if (io != NULL) {
|
if (io != NULL) {
|
||||||
// unlink it, taking care of the change it was the first in line
|
// unlink it, taking care of the change it was the first in line
|
||||||
if (prev != NULL)
|
if (prev != NULL)
|
||||||
prev->next = io->next;
|
prev->next = io->next;
|
||||||
else
|
else
|
||||||
io_vectors[vector].handler_list = io->next;
|
io_vectors[vector].handler_list = io->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
// release our lock as we're done with the vector
|
// release our lock as we're done with the vector
|
||||||
release_spinlock(&io_vectors[vector].vector_lock);
|
release_spinlock(&io_vectors[vector].vector_lock);
|
||||||
int_restore_interrupts(state);
|
int_restore_interrupts(state);
|
||||||
|
|
||||||
// and disable the IRQ if nothing left
|
// and disable the IRQ if nothing left
|
||||||
if (io != NULL) {
|
if (io != NULL) {
|
||||||
if (prev == NULL && io->next == NULL)
|
if (prev == NULL && io->next == NULL)
|
||||||
arch_int_disable_io_interrupt(vector);
|
arch_int_disable_io_interrupt(vector);
|
||||||
|
|
||||||
kfree(io);
|
kfree(io);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (io != NULL) ? 0 : EINVAL;
|
return (io != NULL) ? 0 : EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int int_io_interrupt_handler(int vector)
|
|
||||||
|
int
|
||||||
|
int_io_interrupt_handler(int vector)
|
||||||
{
|
{
|
||||||
int ret = INT_NO_RESCHEDULE;
|
int ret = INT_NO_RESCHEDULE;
|
||||||
|
|
||||||
acquire_spinlock(&io_vectors[vector].vector_lock);
|
acquire_spinlock(&io_vectors[vector].vector_lock);
|
||||||
|
|
||||||
if(io_vectors[vector].handler_list == NULL) {
|
if (io_vectors[vector].handler_list == NULL) {
|
||||||
dprintf("unhandled io interrupt %d\n", vector);
|
dprintf("unhandled io interrupt %d\n", vector);
|
||||||
} else {
|
} else {
|
||||||
struct io_handler *io;
|
struct io_handler *io;
|
||||||
int temp_ret;
|
int temp_ret;
|
||||||
|
|
||||||
io = io_vectors[vector].handler_list;
|
io = io_vectors[vector].handler_list;
|
||||||
while(io != NULL) {
|
while (io != NULL) {
|
||||||
temp_ret = io->func(io->data);
|
temp_ret = io->func(io->data);
|
||||||
if(temp_ret == INT_RESCHEDULE)
|
if (temp_ret == INT_RESCHEDULE)
|
||||||
ret = INT_RESCHEDULE;
|
ret = INT_RESCHEDULE;
|
||||||
io = io->next;
|
io = io->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
release_spinlock(&io_vectors[vector].vector_lock);
|
release_spinlock(&io_vectors[vector].vector_lock);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user