]> git.saurik.com Git - apple/xnu.git/blame - osfmk/i386/lapic.c
xnu-2422.1.72.tar.gz
[apple/xnu.git] / osfmk / i386 / lapic.c
CommitLineData
593a1d5f 1/*
060df5ea 2 * Copyright (c) 2008-2010 Apple Inc. All rights reserved.
593a1d5f
A
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
593a1d5f
A
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>
593a1d5f
A
41#include <i386/postcode.h>
42#include <i386/cpu_threads.h>
593a1d5f 43#include <i386/machine_routines.h>
060df5ea 44#include <i386/tsc.h>
593a1d5f
A
45
46#include <sys/kdebug.h>
47
060df5ea
A
48/* Base vector for local APIC interrupt sources */
49int lapic_interrupt_base = LAPIC_DEFAULT_INTERRUPT_BASE;
50
060df5ea
A
51int lapic_to_cpu[MAX_LAPICIDS];
52int cpu_to_lapic[MAX_CPUS];
53
6d2010ae 54void
593a1d5f
A
55lapic_cpu_map_init(void)
56{
57 int i;
58
b7266188 59 for (i = 0; i < MAX_CPUS; i++)
593a1d5f 60 cpu_to_lapic[i] = -1;
b7266188
A
61 for (i = 0; i < MAX_LAPICIDS; i++)
62 lapic_to_cpu[i] = -1;
593a1d5f
A
63}
64
65void
66lapic_cpu_map(int apic_id, int cpu)
67{
b7266188
A
68 assert(apic_id < MAX_LAPICIDS);
69 assert(cpu < MAX_CPUS);
593a1d5f
A
70 cpu_to_lapic[cpu] = apic_id;
71 lapic_to_cpu[apic_id] = cpu;
72}
73
74/*
75 * Retrieve the local apic ID a cpu.
76 *
77 * Returns the local apic ID for the given processor.
78 * If the processor does not exist or apic not configured, returns -1.
79 */
80
81uint32_t
82ml_get_apicid(uint32_t cpu)
83{
84 if(cpu >= (uint32_t)MAX_CPUS)
85 return 0xFFFFFFFF; /* Return -1 if cpu too big */
86
87 /* Return the apic ID (or -1 if not configured) */
88 return (uint32_t)cpu_to_lapic[cpu];
89
90}
91
b0d623f7
A
92uint32_t
93ml_get_cpuid(uint32_t lapic_index)
94{
b7266188 95 if(lapic_index >= (uint32_t)MAX_LAPICIDS)
b0d623f7
A
96 return 0xFFFFFFFF; /* Return -1 if cpu too big */
97
98 /* Return the cpu ID (or -1 if not configured) */
99 return (uint32_t)lapic_to_cpu[lapic_index];
100
101}