]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/cpu_threads.h
xnu-2050.18.24.tar.gz
[apple/xnu.git] / osfmk / i386 / cpu_threads.h
1 /*
2 * Copyright (c) 2003-2008 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/cpu_topology.h>
33 #include <i386/mp.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_die(cpu) ((cpu_to_lcpu(cpu) != NULL) ? _cpu_to_lcpu(cpu)->die : NULL)
52 #define cpu_to_package(cpu) ((cpu_to_lcpu(cpu) != NULL) ? _cpu_to_lcpu(cpu)->package : NULL)
53
54 /* Fast access: */
55 #define x86_lcpu() (&current_cpu_datap()->lcpu)
56 #define x86_core() (x86_lcpu()->core)
57 #define x86_die() (x86_lcpu()->die)
58 #define x86_package() (x86_lcpu()->package)
59
60 #define cpu_is_same_core(cpu1,cpu2) (cpu_to_core(cpu1) == cpu_to_core(cpu2))
61 #define cpu_is_same_die(cpu1,cpu2) (cpu_to_die(cpu1) == cpu_to_die(cpu2))
62 #define cpu_is_same_package(cpu1,cpu2) (cpu_to_package(cpu1) == cpu_to_package(cpu2))
63 #define cpus_share_cache(cpu1,cpu2,_cl) (cpu_to_lcpu(cpu1)->caches[_cl] == cpu_to_lcpu(cpu2)->caches[_cl])
64
65 extern decl_simple_lock_data(, x86_topo_lock);
66
67 extern void *cpu_thread_alloc(int);
68 extern void cpu_thread_init(void);
69 extern void cpu_thread_halt(void);
70
71 extern void x86_set_lcpu_numbers(x86_lcpu_t *lcpu);
72 extern void x86_set_core_numbers(x86_core_t *core, x86_lcpu_t *lcpu);
73 extern void x86_set_die_numbers(x86_die_t *die, x86_lcpu_t *lcpu);
74 extern void x86_set_pkg_numbers(x86_pkg_t *pkg, x86_lcpu_t *lcpu);
75
76 extern x86_topology_parameters_t topoParms;
77
78 extern boolean_t topo_dbg;
79 #define TOPO_DBG(x...) \
80 do { \
81 if (topo_dbg) \
82 kprintf(x); \
83 } while (0) \
84
85 extern void validate_topology(void);
86
87 #endif /* _I386_CPU_THREADS_H_ */