Skip to content

Commit e37be5d

Browse files
spandruvadaij-intel
authored andcommitted
platform/x86/intel: power-domains: Add interface to get Linux die ID
The die ID in the Linux topology sysfs is a logical identifier that differs from the one presented in CPUID leaf 0x1F or via MSR 0x54. Introduce an interface that returns the Linux CPU die ID based on a given package ID and power domain ID. This mapping is stored during the CPU online callback in an array. Signed-off-by: Srinivas Pandruvada <[email protected]> Reviewed-by: Ilpo Järvinen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ilpo Järvinen <[email protected]>
1 parent bfbe772 commit e37be5d

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

drivers/platform/x86/intel/tpmi_power_domains.c

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ static enum cpuhp_state tpmi_hp_state __read_mostly;
7474

7575
static cpumask_t *tpmi_power_domain_mask;
7676

77+
static u16 *domain_die_map;
78+
7779
/* Lock to protect tpmi_power_domain_mask and tpmi_cpu_hash */
7880
static DEFINE_MUTEX(tpmi_lock);
7981

@@ -152,6 +154,15 @@ cpumask_t *tpmi_get_power_domain_mask(int cpu_no)
152154
}
153155
EXPORT_SYMBOL_NS_GPL(tpmi_get_power_domain_mask, "INTEL_TPMI_POWER_DOMAIN");
154156

157+
int tpmi_get_linux_die_id(int pkg_id, int domain_id)
158+
{
159+
if (pkg_id >= topology_max_packages() || domain_id >= MAX_POWER_DOMAINS)
160+
return -EINVAL;
161+
162+
return domain_die_map[pkg_id * MAX_POWER_DOMAINS + domain_id];
163+
}
164+
EXPORT_SYMBOL_NS_GPL(tpmi_get_linux_die_id, "INTEL_TPMI_POWER_DOMAIN");
165+
155166
static int tpmi_get_logical_id(unsigned int cpu, struct tpmi_cpu_info *info)
156167
{
157168
u64 data;
@@ -189,6 +200,9 @@ static int tpmi_cpu_online(unsigned int cpu)
189200
cpumask_set_cpu(cpu, &tpmi_power_domain_mask[index]);
190201
hash_add(tpmi_cpu_hash, &info->hnode, info->punit_core_id);
191202

203+
domain_die_map[info->pkg_id * MAX_POWER_DOMAINS + info->punit_domain_id] =
204+
topology_die_id(cpu);
205+
192206
return 0;
193207
}
194208

@@ -212,24 +226,36 @@ static int __init tpmi_init(void)
212226
if (!tpmi_power_domain_mask)
213227
return -ENOMEM;
214228

229+
domain_die_map = kcalloc(size_mul(topology_max_packages(), MAX_POWER_DOMAINS),
230+
sizeof(*domain_die_map), GFP_KERNEL);
231+
if (!domain_die_map)
232+
goto free_domain_mask;
233+
215234
ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN,
216235
"platform/x86/tpmi_power_domains:online",
217236
tpmi_cpu_online, NULL);
218-
if (ret < 0) {
219-
kfree(tpmi_power_domain_mask);
220-
return ret;
221-
}
237+
if (ret < 0)
238+
goto free_domain_map;
222239

223240
tpmi_hp_state = ret;
224241

225242
return 0;
243+
244+
free_domain_map:
245+
kfree(domain_die_map);
246+
247+
free_domain_mask:
248+
kfree(tpmi_power_domain_mask);
249+
250+
return ret;
226251
}
227252
module_init(tpmi_init)
228253

229254
static void __exit tpmi_exit(void)
230255
{
231256
cpuhp_remove_state(tpmi_hp_state);
232257
kfree(tpmi_power_domain_mask);
258+
kfree(domain_die_map);
233259
}
234260
module_exit(tpmi_exit)
235261

drivers/platform/x86/intel/tpmi_power_domains.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ int tpmi_get_linux_cpu_number(int package_id, int die_id, int punit_core_id);
1414
int tpmi_get_punit_core_number(int cpu_no);
1515
int tpmi_get_power_domain_id(int cpu_no);
1616
cpumask_t *tpmi_get_power_domain_mask(int cpu_no);
17+
int tpmi_get_linux_die_id(int pkg_id, int domain_id);
1718

1819
#endif

0 commit comments

Comments
 (0)