add sdcard to raspi BE kernel
[AROS.git] / rom / kernel / addirqhandler.c
blobbcbe06e445e119bfeaa5cedc3528bd00b9a04e01
1 /*
2 Copyright © 1995-2017, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 */
8 #include <aros/kernel.h>
9 #include <aros/libcall.h>
10 #include <proto/exec.h>
12 #include <kernel_base.h>
13 #include <kernel_cpu.h>
14 #include <kernel_debug.h>
15 #include <kernel_interrupts.h>
16 #include <kernel_objects.h>
18 /* We use own implementation of bug(), so we don't need aros/debug.h */
19 #define D(x)
21 /*****************************************************************************
23 NAME */
24 #include <proto/kernel.h>
26 AROS_LH4(void *, KrnAddIRQHandler,
28 /* SYNOPSIS */
29 AROS_LHA(uint32_t, irq, D0),
30 AROS_LHA(irqhandler_t *, handler, A0),
31 AROS_LHA(void *, handlerData, A1),
32 AROS_LHA(void *, handlerData2, A2),
34 /* LOCATION */
35 struct KernelBase *, KernelBase, 7, Kernel)
37 /* FUNCTION
38 Add a raw hardware IRQ handler to the chain of handlers.
40 INPUTS
41 num - hardware-specific IRQ number
42 handler - Pointer to a handler function
43 handlerData,
44 handlerData2 - User-defined data which is passed to the
45 handler.
47 Handler function uses a C calling convention and must be
48 declared as follows:
50 void IRQHandler(void *handlerData, void *handlerData2)
52 handlerData and handlerData2 will be values passed to the
53 KrnAddExceptionHandler() function.
55 There is no return code for the IRQ handler.
57 RESULT
58 An opaque handle that can be used for handler removal or NULL in case
59 of failure (like unsupported exception number).
61 NOTES
63 EXAMPLE
65 BUGS
67 SEE ALSO
68 KrnRemIRQHandler()
70 INTERNALS
72 ******************************************************************************/
74 AROS_LIBFUNC_INIT
76 struct IntrNode *handle = NULL;
78 D(bug("[KRN] KrnAddIRQHandler(%02x, %012p, %012p, %012p):\n", irq, handler, handlerData, handlerData2));
80 if (irq < HW_IRQ_COUNT)
82 /* Go to supervisor mode */
83 (void)goSuper();
85 handle = krnAllocIntrNode();
86 D(bug("[KRN] handle=%012p\n", handle));
88 if (handle)
90 handle->in_Handler = handler;
91 handle->in_HandlerData = handlerData;
92 handle->in_HandlerData2 = handlerData2;
93 handle->in_type = it_interrupt;
94 handle->in_nr = irq;
96 Disable();
98 ADDHEAD(&KERNELIRQ_LIST(irq), &handle->in_Node);
100 ictl_enable_irq(irq, KernelBase);
102 Enable();
105 goUser();
108 return handle;
110 AROS_LIBFUNC_EXIT
113 /* Run IRQ handlers */
114 void krnRunIRQHandlers(struct KernelBase *KernelBase, uint8_t irq)
116 struct IntrNode *in, *in2;
118 ForeachNodeSafe(&KERNELIRQ_LIST(irq), in, in2)
120 irqhandler_t h = in->in_Handler;
122 h(in->in_HandlerData, in->in_HandlerData2);