revert between 56095 -> 55830 in arch
[AROS.git] / arch / all-pc / kernel / apic_msi.c
blob905f7f093dd145f9d5467eebc49f38fabf9c8a25
1 /*
2 Copyright © 2017, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <aros/kernel.h>
7 #include <aros/libcall.h>
9 #define __KERNEL_NOLIBBASE__
10 #include <proto/kernel.h>
11 #include <proto/exec.h>
13 #include <kernel_base.h>
14 #include <kernel_cpu.h>
15 #include <kernel_debug.h>
16 #include <kernel_interrupts.h>
17 #include <kernel_objects.h>
19 #define D(x)
21 ULONG core_APIC_AllocMSI(ULONG count)
23 struct PlatformData *kernPlatD = (struct PlatformData *)KernelBase->kb_PlatformData;
24 struct APICData *apicPrivate = kernPlatD->kb_APIC;
25 apicid_t cpuNo = KrnGetCPUNumber();
26 apicidt_t *IGATES = (apicidt_t *)apicPrivate->cores[cpuNo].cpu_IDT;
27 ULONG msiID = APIC_MSI_BASE;
28 int startIRQ = -1, cpuIRQ = -1, irq;
30 D(bug("[APIC:MSI] %s()\n"));
32 for (irq = (APIC_IRQ_BASE - X86_CPU_EXCEPT_COUNT); irq < ((APIC_IRQ_BASE - X86_CPU_EXCEPT_COUNT) + APIC_IRQ_COUNT); irq++)
34 if (KERNELIRQ_LIST(irq).lh_Type == APICInt_IntrController.ic_Node.ln_Type)
36 if (startIRQ == -1)
37 startIRQ = HW_IRQ_BASE + irq;
38 else if ((HW_IRQ_BASE + irq) == (startIRQ + count))
40 cpuIRQ = startIRQ;
41 break;
44 else
45 cpuIRQ = -1;
47 if (cpuIRQ != -1)
49 msiID += ((cpuNo << 8) | (cpuIRQ));
51 for (irq = cpuIRQ; irq < (cpuIRQ + count); irq++)
52 IGATES[irq].p = 1;
54 D(bug("[APIC:MSI] %s: New MSI IRQ ID Base = %d, for %d IRQs\n", __func__, (int)msiID, count));
56 else
57 msiID = (ULONG)-1;
59 return msiID;
62 void core_APIC_RegisterMSI(void *handle)
64 struct IntrNode *msihandle = (struct IntrNode *)handle;
66 D(bug("[APIC:MSI] %s: MSI Handler @ 0x%p\n", msihandle));
67 if ((msihandle->in_nr >= APIC_MSI_BASE) && (msihandle->in_nr < (ULONG)-1))
69 ULONG tmp = msihandle->in_nr - APIC_MSI_BASE;
70 int msiCPUIRQ = (tmp & 0xFF);
71 apicid_t msiCPUNo = (tmp >> 8) & 0xFF;
73 bug("[APIC:MSI] %s: Registering MSI %d (%03u:%02X)\n", (int)msihandle->in_nr, msiCPUNo, msiCPUIRQ);