revert between 56095 -> 55830 in arch
[AROS.git] / arch / all-pc / kernel / ictl.c
blobf5bd0d02c0e053b51e0cbc794907b86681bbf3a3
1 /*
2 Copyright © 1995-2018, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <proto/arossupport.h>
8 #include <string.h>
10 #include "kernel_base.h"
11 #include "kernel_intern.h"
12 #include "kernel_interrupts.h"
13 #include "kernel_debug.h"
15 #include "apic.h"
16 #include "i8259a.h"
18 #define D(x)
20 void ictl_enable_irq(unsigned char irq, struct KernelBase *KernelBase)
22 struct IntrController *irqIC;
23 struct KernelInt *irqInt = &KernelBase->kb_Interrupts[irq];
25 D(bug("[Kernel] %s(%d)\n", __func__, irq));
27 if ((irqIC = krnGetInterruptController(KernelBase, irqInt->ki_List.lh_Type)) != NULL)
29 if ((irqIC->ic_IntrEnable) && (irqIC->ic_IntrEnable(irqIC->ic_Private, irqInt->ki_List.l_pad, irq)))
31 D(bug("[Kernel] %s: controller enabled\n", __func__));
32 irqInt->ki_Priv |= IRQINTF_ENABLED;
35 else
37 D(bug("[Kernel] %s: enabled\n", __func__));
38 irqInt->ki_Priv |= IRQINTF_ENABLED;
42 void ictl_disable_irq(unsigned char irq, struct KernelBase *KernelBase)
44 struct IntrController *irqIC;
45 struct KernelInt *irqInt = &KernelBase->kb_Interrupts[irq];
47 D(bug("[Kernel] %s(%d)\n", __func__, irq));
49 if ((irqIC = krnGetInterruptController(KernelBase, irqInt->ki_List.lh_Type)) != NULL)
51 if ((irqIC->ic_IntrDisable) && (irqIC->ic_IntrDisable(irqIC->ic_Private, irqInt->ki_List.l_pad, irq)))
53 D(bug("[Kernel] %s: controller disabled\n", __func__));
54 irqInt->ki_Priv &= ~IRQINTF_ENABLED;
57 else
59 D(bug("[Kernel] %s: disabled\n", __func__));
60 irqInt->ki_Priv &= ~IRQINTF_ENABLED;
64 BOOL ictl_is_irq_enabled(unsigned char irq, struct KernelBase *KernelBase)
66 struct KernelInt *irqInt = &KernelBase->kb_Interrupts[irq];
68 D(bug("[Kernel] %s(%d)\n", __func__, irq));
70 return (BOOL)(irqInt->ki_Priv & IRQINTF_ENABLED);
73 void ictl_Initialize(struct KernelBase *KernelBase)
75 struct PlatformData *pdata = KernelBase->kb_PlatformData;
76 int cnt;
77 struct TagItem *cmdTags;
79 D(bug("[Kernel] %s()\n", __func__));
81 if (!pdata->kb_APIC)
83 /* No APIC was discovered by ACPI/whatever else. Do the probe. */
84 cmdTags = LibFindTagItem(KRN_CmdLine, BootMsg);
85 if (cmdTags && strstr((const char *)cmdTags->ti_Data, "noapic"))
86 D(bug("[Kernel] %s: APIC support disabled\n", __func__));
87 else
89 D(bug("[Kernel] %s(): probing for APIC\n", __func__));
90 pdata->kb_APIC = core_APIC_Probe();
94 #if (__WORDSIZE==64)
95 if (!pdata->kb_APIC)
97 /* We are x86-64, so we should always have APIC. */
98 krnPanic(KernelBase, "Failed to allocate APIC descriptor.");
100 #endif
102 /* Check if the 8259A has already been registered, if not probe for it */
103 if (!krnFindInterruptController(KernelBase, ICTYPE_I8259A))
105 D(__unused icintrid_t xtpicICInstID;)
107 D(bug("[Kernel] %s(): probing for PIC\n", __func__));
108 if (i8259a_Probe())
110 D(xtpicICInstID =) krnAddInterruptController(KernelBase, &i8259a_IntrController);
114 if ((cnt = krnInitInterruptControllers(KernelBase)) > 0)
116 D(bug("[Kernel] %s: %d Interrupt Controllers Initialized\n", __func__, cnt));
117 return;
120 krnPanic(KernelBase, "Failed to detect any Interrupt Controllers.");