]>
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@ |
0a7de745 | 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. | |
0a7de745 | 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. | |
0a7de745 | 17 | * |
2d21ac55 A |
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. | |
0a7de745 | 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 | */ | |
0a7de745 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) | |
91447636 | 44 | |
0a7de745 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) | |
cf7d32b8 | 48 | |
0a7de745 A |
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) | |
91447636 A |
53 | |
54 | /* Fast access: */ | |
0a7de745 A |
55 | #define x86_lcpu() (¤t_cpu_datap()->lcpu) |
56 | #define x86_core() (x86_lcpu()->core) | |
57 | #define x86_die() (x86_lcpu()->die) | |
58 | #define x86_package() (x86_lcpu()->package) | |
91447636 | 59 | |
0a7de745 A |
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]) | |
2d21ac55 | 64 | |
5ba3f43e | 65 | /* always take the x86_topo_lock with mp_safe_spin_lock */ |
0a7de745 | 66 | boolean_t mp_safe_spin_lock(usimple_lock_t lock); |
2d21ac55 | 67 | extern decl_simple_lock_data(, x86_topo_lock); |
91447636 | 68 | |
0c530ab8 | 69 | extern void *cpu_thread_alloc(int); |
91447636 A |
70 | extern void cpu_thread_init(void); |
71 | extern void cpu_thread_halt(void); | |
72 | ||
39236c6e A |
73 | extern void x86_set_logical_topology(x86_lcpu_t *lcpu, int pnum, int lnum); |
74 | extern void x86_validate_topology(void); | |
593a1d5f | 75 | |
0a7de745 | 76 | extern x86_topology_parameters_t topoParms; |
593a1d5f | 77 | |
0a7de745 A |
78 | extern boolean_t topo_dbg; |
79 | #define TOPO_DBG(x...) \ | |
80 | do { \ | |
81 | if (topo_dbg) \ | |
82 | kprintf(x); \ | |
83 | } while (0) \ | |
7ddcb079 | 84 | |
91447636 | 85 | #endif /* _I386_CPU_THREADS_H_ */ |