[BACK]Return to kern_irq.c CVS log [TXT][DIR] Up to [local] / funnyos / kern

Annotation of funnyos/kern/kern_irq.c, Revision 1.2

1.1       init        1: /*
1.2     ! init        2:  * $Id: kern_irq.c,v 1.1 2007/11/02 11:40:02 init Exp $
1.1       init        3:  */
                      4: #include <sys/types.h>
                      5: #include <sys/device.h>
                      6: #include <sys/mem.h>
                      7:
                      8: #include <sys/kern_irq.h>
                      9: #include <libkern/printf.h>
                     10:
                     11: /*
                     12:  * System interrupt vectors to be used by (some) interrupt controller unit.
                     13:  */
                     14:
                     15: struct intr_vector *irqtable = NULL;
                     16:
                     17:
                     18: void
                     19: intr_establish(uint8_t intrno, struct device *device, void (*intrfunc)(struct device *))
                     20: {
                     21:        /*
                     22:         * Add interrupt vector to irqtable.
                     23:         */
                     24:        struct intr_vector *ivp;
                     25:
                     26:        ivp = irqtable;
                     27:
                     28:        if (ivp == NULL) {
                     29:                /* first element in list */
                     30:
                     31:                /* allocate space for this (first) vector */
                     32:                ivp = kmalloc(sizeof(struct intr_vector));
                     33:
                     34:                if (ivp == NULL)
                     35:                        panic("failed to allocate initial space for interrupt table\n");
                     36:
                     37:                ivp->iv_intrno = intrno;
                     38:                ivp->iv_device = device;
                     39:                ivp->iv_intrfunc = intrfunc;
                     40:                ivp->iv_next = NULL;
1.2     ! init       41:
        !            42:                irqtable = ivp;
1.1       init       43:        }
                     44:        else {
                     45:                /* walk through the list */
                     46:                do {
                     47:                        /* check if this interrupt line already binded */
                     48:                        if (ivp->iv_intrno == intrno)
                     49:                                panic("failed to establish interrupt (intrno %d already set by other device)\n", intrno);
                     50:
                     51:                        /* become next element */
                     52:                        ivp = ivp->iv_next;
                     53:                } while(ivp != NULL);
                     54:
                     55:                /* allocate space */
                     56:                ivp = kmalloc(sizeof(struct intr_vector));
                     57:
                     58:                if (ivp == NULL)
                     59:                        panic("failed to allocate space for interrupt vector\n");
                     60:
                     61:                ivp->iv_intrno = intrno;
                     62:                ivp->iv_device = device;
                     63:                ivp->iv_intrfunc = intrfunc;
                     64:                ivp->iv_next = NULL;
                     65:        }
                     66:
                     67: }
                     68:
                     69:
                     70: void
                     71: intr_disestablish(uint8_t intrno)
                     72: {
                     73:        /*
                     74:         * Delete interrupt vector from vectors irqtable.
                     75:         */
                     76:        /* TODO when kfree() will be implemented */
                     77: }
                     78:
                     79:
                     80: void
                     81: intr_execute(uint8_t intrno)
                     82: {
                     83:        /*
                     84:         * Find intrno in irqtable and call interrupt handler of driver associated with this line.
                     85:         * Pass struct device * into that handler to disguise between driver instances.
                     86:         */
                     87:        struct intr_vector *ivp;
                     88:
                     89:        ivp = irqtable;
                     90:
                     91:        if (ivp == NULL)
                     92:                /* none vectors are configured yet */
                     93:                panic("failed to execute intr handler (irqtable is not configured yet)\n");
                     94:
                     95:        /* look for our handler */
                     96:        while(ivp != NULL) {
                     97:                if (ivp->iv_intrno == intrno) {
                     98:                        /* jump off */
                     99:                        ivp->iv_intrfunc(ivp->iv_device);
                    100:                        return;
                    101:                }
                    102:
                    103:                ivp = ivp->iv_next;
                    104:        }
                    105:        /*
                    106:         * Search stopped on NULL.
                    107:         */
                    108:        /* XXX really panic here? */
                    109:        panic("failed to execute intr handler for intr %d (irqtable record not found)\n", intrno);
                    110:
                    111: }
                    112:

CVSweb