]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/cpu_threads.h
xnu-1228.7.58.tar.gz
[apple/xnu.git] / osfmk / i386 / cpu_threads.h
1 /*
2 * Copyright (c) 2003-2007 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 #ifndef _I386_CPU_THREADS_H_
29 #define _I386_CPU_THREADS_H_
30
31 #include <i386/cpu_data.h>
32 #include <i386/mp.h>
33 #include <i386/cpu_topology.h>
34
35 /*
36 * These are defined here rather than in cpu_topology.h so as to keep
37 * cpu_topology.h from having a dependency on cpu_data.h.
38 */
39 #define CPU_THREAD_MASK 0x00000001
40 #define cpu_to_core_lapic(cpu) (cpu_to_lapic[cpu] & ~CPU_THREAD_MASK)
41 #define cpu_to_core_cpu(cpu) (lapic_to_cpu[cpu_to_core_lapic(cpu)])
42 #define cpu_to_logical_cpu(cpu) (cpu_to_lapic[cpu] & CPU_THREAD_MASK)
43 #define cpu_is_core_cpu(cpu) (cpu_to_logical_cpu(cpu) == 0)
44
45 #define _cpu_to_lcpu(cpu) (&cpu_datap(cpu)->lcpu)
46 #define _cpu_to_core(cpu) (_cpu_to_lcpu(cpu)->core)
47 #define _cpu_to_package(cpu) (_cpu_to_core(cpu)->package)
48
49 #define cpu_to_lcpu(cpu) ((cpu_datap(cpu) != NULL) ? _cpu_to_lcpu(cpu) : NULL)
50 #define cpu_to_core(cpu) ((cpu_to_lcpu(cpu) != NULL) ? _cpu_to_lcpu(cpu)->core : NULL)
51 #define cpu_to_package(cpu) ((cpu_to_core(cpu) != NULL) ? _cpu_to_core(cpu)->package : NULL)
52
53 /* Fast access: */
54 #define x86_lcpu() (&current_cpu_datap()->lcpu)
55 #define x86_core() (x86_lcpu()->core)
56 #define x86_package() (x86_core()->package)
57
58 #define cpu_is_same_core(cpu1,cpu2) (cpu_to_core(cpu1) == cpu_to_core(cpu2))
59 #define cpu_is_same_package(cpu1,cpu2) (cpu_to_package(cpu1) == cpu_to_package(cpu2))
60 #define cpus_share_cache(cpu1,cpu2,_cl) (cpu_to_lcpu(cpu1)->caches[_cl] == cpu_to_lcpu(cpu2)->caches[_cl])
61
62 extern decl_simple_lock_data(, x86_topo_lock);
63
64 extern void *cpu_thread_alloc(int);
65 extern void cpu_thread_init(void);
66 extern void cpu_thread_halt(void);
67
68 #endif /* _I386_CPU_THREADS_H_ */