2 Copyright © 2017, The AROS Development Team. All rights reserved.
8 #include <kernel_base.h>
10 #ifdef KERNELIRQ_NEEDSCONTROLLERS
12 #include <aros/kernel.h>
13 #include <proto/exec.h>
19 #include <kernel_cpu.h>
20 #include <kernel_debug.h>
21 #include <kernel_interrupts.h>
22 #include <kernel_objects.h>
24 /* We use own implementation of bug(), so we don't need aros/debug.h */
27 /*****************************************************************************
29 Register an Interrupt Controller in Kernelbase. Assign an ID (in ln_Type)
30 returns -1 on failure.
32 *****************************************************************************/
34 icintrid_t
krnAddInterruptController(struct KernelBase
*KernelBase
, struct IntrController
*intController
)
36 struct IntrController
*regContr
;
39 ForeachNode(&KernelBase
->kb_ICList
, regContr
)
41 if (!strcmp(intController
->ic_Node
.ln_Name
, regContr
->ic_Node
.ln_Name
))
43 /* Already registered, return its ID */
46 D(bug("[Kernel] %s: controller id #%d, use count %d\n", __func__
, regContr
->ic_Node
.ln_Type
, regContr
->ic_Count
));
48 return (icintrid_t
)((regContr
->ic_Node
.ln_Type
<< 8) | regContr
->ic_Count
);
51 intController
->ic_Count
= 1; /* first user */
52 intController
->ic_Node
.ln_Type
= KernelBase
->kb_ICTypeBase
++;
54 if (intController
->ic_Register
)
55 icid
= intController
->ic_Register(KernelBase
);
57 icid
= intController
->ic_Node
.ln_Type
;
59 if (icid
== (icid_t
)-1)
60 return (icintrid_t
)-1;
62 Enqueue(&KernelBase
->kb_ICList
, &intController
->ic_Node
);
64 D(bug("[Kernel] %s: new controller id #%d = '%s'\n", __func__
, intController
->ic_Node
.ln_Type
, intController
->ic_Node
.ln_Name
));
66 return (icintrid_t
)((icid
<< 8) | intController
->ic_Count
);
69 /*****************************************************************************/
71 struct IntrController
*krnFindInterruptController(struct KernelBase
*KernelBase
, ULONG ICType
)
73 struct IntrController
*intContr
;
74 ForeachNode(&KernelBase
->kb_ICList
, intContr
)
76 if (intContr
->ic_Type
== ICType
)
84 /*****************************************************************************/
86 BOOL
krnInitInterrupt(struct KernelBase
*KernelBase
, icid_t irq
, icid_t icid
, icid_t icinstance
)
88 if (KERNELIRQ_LIST(irq
).lh_Type
== KBL_INTERNAL
)
90 KERNELIRQ_LIST(irq
).lh_Type
= icid
;
91 KERNELIRQ_LIST(irq
).l_pad
= icinstance
;
97 struct IntrMapping
*krnInterruptMapping(struct KernelBase
*KernelBase
, icid_t irq
)
99 struct IntrMapping
*intrMap
;
101 ForeachNode(&KernelBase
->kb_InterruptMappings
, intrMap
)
103 if (intrMap
->im_Node
.ln_Pri
== irq
)
111 struct IntrMapping
*krnInterruptMapped(struct KernelBase
*KernelBase
, icid_t irq
)
113 struct IntrMapping
*intrMap
;
115 ForeachNode(&KernelBase
->kb_InterruptMappings
, intrMap
)
117 if (intrMap
->im_IRQ
== irq
)
125 /*****************************************************************************
127 Initialize the registered Interrupt Controllers.
129 *****************************************************************************/
131 int krnInitInterruptControllers(struct KernelBase
*KernelBase
)
133 struct IntrController
*regContr
;
136 ForeachNode(&KernelBase
->kb_ICList
, regContr
)
138 if (regContr
->ic_Init
)
140 if (regContr
->ic_Init(KernelBase
, regContr
->ic_Count
))
142 regContr
->ic_Flags
|= ICF_READY
;
143 cnt
+= regContr
->ic_Count
;