xref: /xnu-11215.61.5/osfmk/arm/cpu_topology.h (revision 4f1223e81cd707a65cc109d0b8ad6653699da3c4)
1 /*
2  * Copyright (c) 2024 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 /**
29  * Data structures that reveal the CPU topology of the system. This header is
30  * used to contain the API which is kernel private for now, since things are
31  * constantly evolving and kexts that depend on it could break unexpectedly.
32  * It should not be included directly but instead is included from
33  * machine_routines.h
34  */
35 
36 #ifndef _ARM_CPU_TOPOLOGY_H_
37 #define _ARM_CPU_TOPOLOGY_H_
38 
39 __BEGIN_DECLS
40 
41 /*!
42  * @typedef ml_topology_cpu_t
43  * @brief Describes one CPU core in the topology.
44  *
45  * @field cpu_id            Logical CPU ID: 0, 1, 2, 3, 4, ...
46  *                          Dynamically assigned by XNU so it might not match EDT.  No holes.
47  * @field phys_id           Physical CPU ID (EDT: reg).  Same as MPIDR[15:0], i.e.
48  *                          (cluster_id << 8) | core_number_within_cluster
49  * @field cluster_id        Logical Cluster ID: 0, 1, 2, 3, 4, ...
50  *                          Dynamically assigned by XNU so it might not match EDT.  No holes.
51  * @field die_id            Die ID (EDT: die-id)
52  * @field cluster_type      The type of CPUs found in this cluster.
53  * @field l2_access_penalty Indicates that the scheduler should try to de-prioritize a core because
54  *                          L2 accesses are slower than on the boot processor.
55  * @field l2_cache_size     Size of the L2 cache, in bytes.  0 if unknown or not present.
56  * @field l2_cache_id       l2-cache-id property read from EDT.
57  * @field l3_cache_size     Size of the L3 cache, in bytes.  0 if unknown or not present.
58  * @field l3_cache_id       l3-cache-id property read from EDT.
59  * @field cpu_IMPL_regs     IO-mapped virtual address of cpuX_IMPL (implementation-defined) register block.
60  * @field cpu_IMPL_pa       Physical address of cpuX_IMPL register block.
61  * @field cpu_IMPL_len      Length of cpuX_IMPL register block.
62  * @field cpu_UTTDBG_regs   IO-mapped virtual address of cpuX_UTTDBG register block.
63  * @field cpu_UTTDBG_pa     Physical address of cpuX_UTTDBG register block, if set in DT, else zero
64  * @field cpu_UTTDBG_len    Length of cpuX_UTTDBG register block, if set in DT, else zero
65  * @field coresight_regs    IO-mapped virtual address of CoreSight debug register block.
66  * @field coresight_pa      Physical address of CoreSight register block.
67  * @field coresight_len     Length of CoreSight register block.
68  * @field die_cluster_id    Physical cluster ID within the local die (EDT: die-cluster-id)
69  * @field cluster_core_id   Physical core ID within the local cluster (EDT: cluster-core-id)
70  */
71 typedef struct ml_topology_cpu {
72 	unsigned int                    cpu_id;
73 	uint32_t                        phys_id;
74 	unsigned int                    cluster_id;
75 	unsigned int                    die_id;
76 	cluster_type_t                  cluster_type;
77 	uint32_t                        l2_access_penalty;
78 	uint32_t                        l2_cache_size;
79 	uint32_t                        l2_cache_id;
80 	uint32_t                        l3_cache_size;
81 	uint32_t                        l3_cache_id;
82 	vm_offset_t                     cpu_IMPL_regs;
83 	uint64_t                        cpu_IMPL_pa;
84 	uint64_t                        cpu_IMPL_len;
85 	vm_offset_t                     cpu_UTTDBG_regs;
86 	uint64_t                        cpu_UTTDBG_pa;
87 	uint64_t                        cpu_UTTDBG_len;
88 	vm_offset_t                     coresight_regs;
89 	uint64_t                        coresight_pa;
90 	uint64_t                        coresight_len;
91 	unsigned int                    die_cluster_id;
92 	unsigned int                    cluster_core_id;
93 } ml_topology_cpu_t;
94 
95 /*!
96  * @typedef ml_topology_cluster_t
97  * @brief Describes one cluster in the topology.
98  *
99  * @field cluster_id        Cluster ID (EDT: cluster-id)
100  * @field cluster_type      The type of CPUs found in this cluster.
101  * @field num_cpus          Total number of usable CPU cores in this cluster.
102  * @field first_cpu_id      The cpu_id of the first CPU in the cluster.
103  * @field cpu_mask          A bitmask representing the cpu_id's that belong to the cluster.  Example:
104  *                          If the cluster contains CPU4 and CPU5, cpu_mask will be 0x30.
105  * @field die_id            Die ID.
106  * @field die_cluster_id    Physical cluster ID within the local die (EDT: die-cluster-id)
107  * @field acc_IMPL_regs     IO-mapped virtual address of acc_IMPL (implementation-defined) register block.
108  * @field acc_IMPL_pa       Physical address of acc_IMPL register block.
109  * @field acc_IMPL_len      Length of acc_IMPL register block.
110  * @field cpm_IMPL_regs     IO-mapped virtual address of cpm_IMPL (implementation-defined) register block.
111  * @field cpm_IMPL_pa       Physical address of cpm_IMPL register block.
112  * @field cpm_IMPL_len      Length of cpm_IMPL register block.
113  */
114 typedef struct ml_topology_cluster {
115 	unsigned int                    cluster_id;
116 	cluster_type_t                  cluster_type;
117 	unsigned int                    num_cpus;
118 	unsigned int                    first_cpu_id;
119 	uint64_t                        cpu_mask;
120 	unsigned int                    die_id;
121 	unsigned int                    die_cluster_id;
122 	vm_offset_t                     acc_IMPL_regs;
123 	uint64_t                        acc_IMPL_pa;
124 	uint64_t                        acc_IMPL_len;
125 	vm_offset_t                     cpm_IMPL_regs;
126 	uint64_t                        cpm_IMPL_pa;
127 	uint64_t                        cpm_IMPL_len;
128 } ml_topology_cluster_t;
129 
130 // Bump this version number any time any ml_topology_* struct changes in a
131 // way that is likely to break kexts, so that users can check whether their
132 // headers are compatible with the running kernel
133 #define CPU_TOPOLOGY_VERSION 1
134 
135 /*!
136  * @typedef ml_topology_info_t
137  * @brief Describes the CPU topology for all APs in the system.  Populated from EDT and read-only at runtime.
138  * @discussion This struct only lists CPU cores that are considered usable by both iBoot and XNU.  Some
139  *             physically present CPU cores may be considered unusable due to configuration options like
140  *             the "cpus=" boot-arg.  Cores that are disabled in hardware will not show up in EDT at all, so
141  *             they also will not be present in this struct.
142  *
143  * @field version            Version of the struct (set to CPU_TOPOLOGY_VERSION).
144  * @field num_cpus           Total number of usable CPU cores.
145  * @field max_cpu_id         The highest usable logical CPU ID.
146  * @field num_clusters       Total number of AP CPU clusters on the system (usable or not).
147  * @field max_cluster_id     The highest cluster ID found in EDT.
148  * @field cpus               List of |num_cpus| entries.
149  * @field clusters           List of |num_clusters| entries.
150  * @field boot_cpu           Points to the |cpus| entry for the boot CPU.
151  * @field boot_cluster       Points to the |clusters| entry which contains the boot CPU.
152  * @field chip_revision      Silicon revision reported by iBoot, which comes from the
153  *                           SoC-specific fuse bits.  See CPU_VERSION_xx macros for definitions.
154  * @field cluster_power_down Set to 1 if there exists at least one cluster on the system that can be
155  *                           power-gated at runtime.
156  */
157 typedef struct ml_topology_info {
158 	unsigned int                    version;
159 	unsigned int                    num_cpus;
160 	unsigned int                    max_cpu_id;
161 	unsigned int                    num_clusters;
162 	unsigned int                    max_cluster_id;
163 	unsigned int                    max_die_id;
164 	ml_topology_cpu_t               *cpus;
165 	ml_topology_cluster_t           *clusters;
166 	ml_topology_cpu_t               *boot_cpu;
167 	ml_topology_cluster_t           *boot_cluster;
168 	unsigned int                    chip_revision;
169 	unsigned int                    cluster_types;
170 	unsigned int                    cluster_type_num_cpus[MAX_CPU_TYPES];
171 	unsigned int                    cluster_type_num_clusters[MAX_CPU_TYPES];
172 	unsigned int                    cluster_power_down;
173 } ml_topology_info_t;
174 
175 /*!
176  * @function ml_get_topology_info
177  * @result A pointer to the read-only topology struct.  Does not need to be freed.  Returns NULL
178  *         if the struct hasn't been initialized or the feature is unsupported.
179  */
180 const ml_topology_info_t *ml_get_topology_info(void);
181 
182 __END_DECLS
183 
184 #endif /* _ARM_CPU_TOPOLOGY_H_ */
185