refactored some code. compiles now without suppresing any warning with gcc-6.3.0.
[AROS.git] / rom / kernel / kernel_interruptcontroller.c
bloba034b1aad5c286439f64d43c9123163039bee28a
1 /*
2 Copyright © 2017, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 */
8 #include <kernel_base.h>
10 #ifdef KERNELIRQ_NEEDSCONTROLLERS
12 #include <aros/kernel.h>
13 #include <proto/exec.h>
15 #include <inttypes.h>
16 #include <string.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 */
25 #define D(x)
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;
37 icid_t icid = 0;
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 */
44 regContr->ic_Count++;
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);
56 else
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)
78 return intContr;
81 return NULL;
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;
92 return TRUE;
94 return FALSE;
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)
105 return intrMap;
108 return NULL;
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)
119 return intrMap;
122 return NULL;
125 /*****************************************************************************
127 Initialize the registered Interrupt Controllers.
129 *****************************************************************************/
131 int krnInitInterruptControllers(struct KernelBase *KernelBase)
133 struct IntrController *regContr;
134 int cnt = 0;
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;
147 return cnt;
150 #endif