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

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

1.1       init        1: /*
1.3     ! nbrk        2:  * $Id: kern_irq.c,v 1.2 2007/11/04 23:18:46 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:         */
1.3     ! nbrk       24:        struct intr_vector *ivp, *previvp;
1.1       init       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 */
1.3     ! nbrk       46:                while(ivp->iv_next != NULL) {
1.1       init       47:                        if (ivp->iv_intrno == intrno)
                     48:                                panic("failed to establish interrupt (intrno %d already set by other device)\n", intrno);
                     49:
                     50:                        ivp = ivp->iv_next;
1.3     ! nbrk       51:                }
        !            52:                /* found last entry */
        !            53:                previvp = ivp;
        !            54:                ivp = ivp->iv_next;
1.1       init       55:
                     56:                /* allocate space */
                     57:                ivp = kmalloc(sizeof(struct intr_vector));
                     58:
                     59:                if (ivp == NULL)
                     60:                        panic("failed to allocate space for interrupt vector\n");
                     61:
                     62:                ivp->iv_intrno = intrno;
                     63:                ivp->iv_device = device;
                     64:                ivp->iv_intrfunc = intrfunc;
                     65:                ivp->iv_next = NULL;
1.3     ! nbrk       66:
        !            67:                /* link previous entry */
        !            68:                previvp->iv_next = ivp;
1.1       init       69:        }
                     70:
                     71: }
                     72:
                     73:
                     74: void
                     75: intr_disestablish(uint8_t intrno)
                     76: {
                     77:        /*
                     78:         * Delete interrupt vector from vectors irqtable.
                     79:         */
                     80:        /* TODO when kfree() will be implemented */
                     81: }
                     82:
                     83:
                     84: void
                     85: intr_execute(uint8_t intrno)
                     86: {
                     87:        /*
                     88:         * Find intrno in irqtable and call interrupt handler of driver associated with this line.
                     89:         * Pass struct device * into that handler to disguise between driver instances.
                     90:         */
                     91:        struct intr_vector *ivp;
                     92:
                     93:        ivp = irqtable;
                     94:
                     95:        if (ivp == NULL)
                     96:                /* none vectors are configured yet */
                     97:                panic("failed to execute intr handler (irqtable is not configured yet)\n");
                     98:
                     99:        /* look for our handler */
                    100:        while(ivp != NULL) {
                    101:                if (ivp->iv_intrno == intrno) {
                    102:                        /* jump off */
                    103:                        ivp->iv_intrfunc(ivp->iv_device);
                    104:                        return;
                    105:                }
                    106:
                    107:                ivp = ivp->iv_next;
                    108:        }
                    109:        /*
                    110:         * Search stopped on NULL.
                    111:         */
                    112:        /* XXX really panic here? */
                    113:        panic("failed to execute intr handler for intr %d (irqtable record not found)\n", intrno);
                    114:
                    115: }
                    116:

CVSweb