]>
Commit | Line | Data |
---|---|---|
91447636 | 1 | /* |
593a1d5f | 2 | * Copyright (c) 2003-2008 Apple Inc. All rights reserved. |
91447636 | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
91447636 | 5 | * |
2d21ac55 A |
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. | |
8f6c56a5 | 14 | * |
2d21ac55 A |
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 | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
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. | |
8f6c56a5 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
91447636 A |
27 | */ |
28 | #ifndef _I386_CPU_THREADS_H_ | |
29 | #define _I386_CPU_THREADS_H_ | |
30 | ||
91447636 | 31 | #include <i386/cpu_data.h> |
2d21ac55 | 32 | #include <i386/cpu_topology.h> |
b0d623f7 | 33 | #include <i386/mp.h> |
91447636 | 34 | |
2d21ac55 A |
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 | */ | |
91447636 A |
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 | ||
cf7d32b8 A |
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) | |
593a1d5f A |
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) | |
91447636 A |
53 | |
54 | /* Fast access: */ | |
2d21ac55 A |
55 | #define x86_lcpu() (¤t_cpu_datap()->lcpu) |
56 | #define x86_core() (x86_lcpu()->core) | |
593a1d5f A |
57 | #define x86_die() (x86_lcpu()->die) |
58 | #define x86_package() (x86_lcpu()->package) | |
91447636 A |
59 | |
60 | #define cpu_is_same_core(cpu1,cpu2) (cpu_to_core(cpu1) == cpu_to_core(cpu2)) | |
593a1d5f | 61 | #define cpu_is_same_die(cpu1,cpu2) (cpu_to_die(cpu1) == cpu_to_die(cpu2)) |
2d21ac55 A |
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); | |
91447636 | 66 | |
0c530ab8 | 67 | extern void *cpu_thread_alloc(int); |
91447636 A |
68 | extern void cpu_thread_init(void); |
69 | extern void cpu_thread_halt(void); | |
70 | ||
593a1d5f A |
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 | ||
7ddcb079 A |
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 | ||
91447636 | 87 | #endif /* _I386_CPU_THREADS_H_ */ |