add the common pc IRQTYPE definitions, and copy them for both the 32bit and 64bit...
[AROS.git] / arch / all-pc / kernel / addirqhandler.c
blobe8b6bf350e2d9e277813b121431f8abf8493ed7f
1 /*
2 Copyright © 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 #define D(x)
20 /*****************************************************************************
22 NAME */
23 #include <proto/kernel.h>
25 AROS_LH4(void *, KrnAddIRQHandler,
27 /* SYNOPSIS */
28 AROS_LHA(uint32_t, irq, D0),
29 AROS_LHA(irqhandler_t *, handler, A0),
30 AROS_LHA(void *, handlerData, A1),
31 AROS_LHA(void *, handlerData2, A2),
33 /* LOCATION */
34 struct KernelBase *, KernelBase, 7, Kernel)
36 /* FUNCTION
37 Add a raw hardware IRQ handler to the chain of handlers.
39 INPUTS
40 num - hardware-specific IRQ number
41 handler - Pointer to a handler function
42 handlerData,
43 handlerData2 - User-defined data which is passed to the
44 handler.
46 Handler function uses a C calling convention and must be
47 declared as follows:
49 void IRQHandler(void *handlerData, void *handlerData2)
51 handlerData and handlerData2 will be values passed to the
52 KrnAddExceptionHandler() function.
54 There is no return code for the IRQ handler.
56 RESULT
57 An opaque handle that can be used for handler removal or NULL in case
58 of failure (like unsupported exception number).
60 NOTES
62 EXAMPLE
64 BUGS
66 SEE ALSO
67 KrnRemIRQHandler()
69 INTERNALS
71 ******************************************************************************/
73 AROS_LIBFUNC_INIT
75 struct PlatformData *pdata = KernelBase->kb_PlatformData;
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) || (pdata->kb_PDFlags & PLATFORMF_HAVEMSI))
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 if (irq < HW_IRQ_COUNT)
100 ADDHEAD(&KERNELIRQ_LIST(irq), &handle->in_Node);
102 ictl_enable_irq(irq, KernelBase);
104 else
106 core_APIC_RegisterMSI(handle);
108 Enable();
111 goUser();
114 return handle;
116 AROS_LIBFUNC_EXIT
119 /* Run IRQ handlers */
120 void krnRunIRQHandlers(struct KernelBase *KernelBase, uint8_t irq)
122 struct IntrNode *in, *in2;
124 ForeachNodeSafe(&KERNELIRQ_LIST(irq), in, in2)
126 irqhandler_t h = in->in_Handler;
128 h(in->in_HandlerData, in->in_HandlerData2);