2 * Copyright (c) 2008-2010 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
32 #include <mach/mach_types.h>
33 #include <mach/kern_return.h>
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>
41 #include <i386/postcode.h>
42 #include <i386/cpu_threads.h>
43 #include <i386/machine_routines.h>
46 #include <sys/kdebug.h>
48 /* Base vector for local APIC interrupt sources */
49 int lapic_interrupt_base
= LAPIC_DEFAULT_INTERRUPT_BASE
;
51 int lapic_to_cpu
[MAX_LAPICIDS
];
52 int cpu_to_lapic
[MAX_CPUS
];
55 lapic_cpu_map_init(void)
59 for (i
= 0; i
< MAX_CPUS
; i
++) {
62 for (i
= 0; i
< MAX_LAPICIDS
; i
++) {
68 lapic_cpu_map(int apic_id
, int cpu
)
70 assert(apic_id
< MAX_LAPICIDS
);
71 assert(cpu
< MAX_CPUS
);
72 cpu_to_lapic
[cpu
] = apic_id
;
73 lapic_to_cpu
[apic_id
] = cpu
;
77 * Retrieve the local apic ID a cpu.
79 * Returns the local apic ID for the given processor.
80 * If the processor does not exist or apic not configured, returns -1.
84 ml_get_apicid(uint32_t cpu
)
86 if (cpu
>= (uint32_t)MAX_CPUS
) {
87 return 0xFFFFFFFF; /* Return -1 if cpu too big */
89 /* Return the apic ID (or -1 if not configured) */
90 return (uint32_t)cpu_to_lapic
[cpu
];
94 ml_get_cpuid(uint32_t lapic_index
)
96 if (lapic_index
>= (uint32_t)MAX_LAPICIDS
) {
97 return 0xFFFFFFFF; /* Return -1 if cpu too big */
99 /* Return the cpu ID (or -1 if not configured) */
100 return (uint32_t)lapic_to_cpu
[lapic_index
];