Forgotten commit. Added automount.
[AROS.git] / arch / all-pc / kernel / apic.c
blob4e2a2128662b4992ea520bc39f2f50efc2f01665
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <exec/memory.h>
7 #include <proto/exec.h>
9 #include "kernel_base.h"
10 #include "kernel_debug.h"
11 #include "kernel_intern.h"
12 #include "apic.h"
14 #define D(x)
16 /* Initialize APIC by probing */
17 struct APICData *core_APIC_Probe(void)
19 struct APICData *data;
20 #ifdef __i386__
21 /* Only i386 needs detection. On x86-64 APIC is always present. */
22 ULONG arg = 1;
23 ULONG res;
25 asm volatile("cpuid":"+a"(arg),"=d"(res)::"%ebx", "%ecx");
27 if (!(res & (1 << 9)))
28 return NULL;
30 D(bug("[APIC] Detected by CPUID instruction\n"));
31 #endif
33 /* Assuming uniprocessor IBM PC compatible */
34 data = AllocMem(sizeof(struct APICData) + sizeof(struct CPUData), MEMF_CLEAR);
35 if (!data)
36 return NULL;
38 data->lapicBase = core_APIC_GetBase();
39 data->count = 1;
40 data->flags = APF_8259;
41 data->cores[0].lapicID = core_APIC_GetID(data->lapicBase);
43 /* Just initialize to default state */
44 core_APIC_Init(data, 0);
45 return data;
48 UBYTE core_APIC_GetNumber(struct APICData *data)
50 UBYTE __APICLogicalID;
51 UBYTE __APICNo;
53 if (!data)
55 /* No APIC data -> uniprocessor system */
56 return 0;
59 __APICLogicalID = core_APIC_GetID(data->lapicBase);
61 for (__APICNo = 0; __APICNo < data->count; __APICNo++)
63 if (data->cores[__APICNo].lapicID == __APICLogicalID)
64 return __APICNo;
67 return -1;