]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/lapic.c
xnu-2050.24.15.tar.gz
[apple/xnu.git] / osfmk / i386 / lapic.c
1 /*
2 * Copyright (c) 2008-2010 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /*
29 * @OSF_COPYRIGHT@
30 */
31
32 #include <mach/mach_types.h>
33 #include <mach/kern_return.h>
34
35 #include <i386/lapic.h>
36 #include <i386/cpuid.h>
37 #include <i386/proc_reg.h>
38 #include <i386/machine_cpu.h>
39 #include <i386/misc_protos.h>
40 #include <i386/mp.h>
41 #include <i386/postcode.h>
42 #include <i386/cpu_threads.h>
43 #include <i386/machine_routines.h>
44 #include <i386/tsc.h>
45
46 #include <sys/kdebug.h>
47
48 /* Base vector for local APIC interrupt sources */
49 int lapic_interrupt_base = LAPIC_DEFAULT_INTERRUPT_BASE;
50
51 #define MAX_LAPICIDS (LAPIC_ID_MAX+1)
52 int lapic_to_cpu[MAX_LAPICIDS];
53 int cpu_to_lapic[MAX_CPUS];
54
55 void
56 lapic_cpu_map_init(void)
57 {
58 int i;
59
60 for (i = 0; i < MAX_CPUS; i++)
61 cpu_to_lapic[i] = -1;
62 for (i = 0; i < MAX_LAPICIDS; i++)
63 lapic_to_cpu[i] = -1;
64 }
65
66 void
67 lapic_cpu_map(int apic_id, int cpu)
68 {
69 assert(apic_id < MAX_LAPICIDS);
70 assert(cpu < MAX_CPUS);
71 cpu_to_lapic[cpu] = apic_id;
72 lapic_to_cpu[apic_id] = cpu;
73 }
74
75 /*
76 * Retrieve the local apic ID a cpu.
77 *
78 * Returns the local apic ID for the given processor.
79 * If the processor does not exist or apic not configured, returns -1.
80 */
81
82 uint32_t
83 ml_get_apicid(uint32_t cpu)
84 {
85 if(cpu >= (uint32_t)MAX_CPUS)
86 return 0xFFFFFFFF; /* Return -1 if cpu too big */
87
88 /* Return the apic ID (or -1 if not configured) */
89 return (uint32_t)cpu_to_lapic[cpu];
90
91 }
92
93 uint32_t
94 ml_get_cpuid(uint32_t lapic_index)
95 {
96 if(lapic_index >= (uint32_t)MAX_LAPICIDS)
97 return 0xFFFFFFFF; /* Return -1 if cpu too big */
98
99 /* Return the cpu ID (or -1 if not configured) */
100 return (uint32_t)lapic_to_cpu[lapic_index];
101
102 }