]> git.saurik.com Git - apple/xnu.git/blame - osfmk/i386/lapic.c
xnu-1699.26.8.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
51#define MAX_LAPICIDS (LAPIC_ID_MAX+1)
52int lapic_to_cpu[MAX_LAPICIDS];
53int cpu_to_lapic[MAX_CPUS];
54
6d2010ae 55void
593a1d5f
A
56lapic_cpu_map_init(void)
57{
58 int i;
59
b7266188 60 for (i = 0; i < MAX_CPUS; i++)
593a1d5f 61 cpu_to_lapic[i] = -1;
b7266188
A
62 for (i = 0; i < MAX_LAPICIDS; i++)
63 lapic_to_cpu[i] = -1;
593a1d5f
A
64}
65
66void
67lapic_cpu_map(int apic_id, int cpu)
68{
b7266188
A
69 assert(apic_id < MAX_LAPICIDS);
70 assert(cpu < MAX_CPUS);
593a1d5f
A
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
82uint32_t
83ml_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
b0d623f7
A
93uint32_t
94ml_get_cpuid(uint32_t lapic_index)
95{
b7266188 96 if(lapic_index >= (uint32_t)MAX_LAPICIDS)
b0d623f7
A
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}