GNU Linux-libre 5.4.274-gnu1
[releases.git] / arch / arm64 / kernel / topology.c
1 /*
2  * arch/arm64/kernel/topology.c
3  *
4  * Copyright (C) 2011,2013,2014 Linaro Limited.
5  *
6  * Based on the arm32 version written by Vincent Guittot in turn based on
7  * arch/sh/kernel/topology.c
8  *
9  * This file is subject to the terms and conditions of the GNU General Public
10  * License.  See the file "COPYING" in the main directory of this archive
11  * for more details.
12  */
13
14 #include <linux/acpi.h>
15 #include <linux/arch_topology.h>
16 #include <linux/cacheinfo.h>
17 #include <linux/init.h>
18 #include <linux/percpu.h>
19
20 #include <asm/cpu.h>
21 #include <asm/cputype.h>
22 #include <asm/topology.h>
23
24 #ifdef CONFIG_ACPI
25 static bool __init acpi_cpu_is_threaded(int cpu)
26 {
27         int is_threaded = acpi_pptt_cpu_is_thread(cpu);
28
29         /*
30          * if the PPTT doesn't have thread information, assume a homogeneous
31          * machine and return the current CPU's thread state.
32          */
33         if (is_threaded < 0)
34                 is_threaded = read_cpuid_mpidr() & MPIDR_MT_BITMASK;
35
36         return !!is_threaded;
37 }
38
39 /*
40  * Propagate the topology information of the processor_topology_node tree to the
41  * cpu_topology array.
42  */
43 int __init parse_acpi_topology(void)
44 {
45         int cpu, topology_id;
46
47         if (acpi_disabled)
48                 return 0;
49
50         for_each_possible_cpu(cpu) {
51                 int i, cache_id;
52
53                 topology_id = find_acpi_cpu_topology(cpu, 0);
54                 if (topology_id < 0)
55                         return topology_id;
56
57                 if (acpi_cpu_is_threaded(cpu)) {
58                         cpu_topology[cpu].thread_id = topology_id;
59                         topology_id = find_acpi_cpu_topology(cpu, 1);
60                         cpu_topology[cpu].core_id   = topology_id;
61                 } else {
62                         cpu_topology[cpu].thread_id  = -1;
63                         cpu_topology[cpu].core_id    = topology_id;
64                 }
65                 topology_id = find_acpi_cpu_topology_package(cpu);
66                 cpu_topology[cpu].package_id = topology_id;
67
68                 i = acpi_find_last_cache_level(cpu);
69
70                 if (i > 0) {
71                         /*
72                          * this is the only part of cpu_topology that has
73                          * a direct relationship with the cache topology
74                          */
75                         cache_id = find_acpi_cpu_cache_topology(cpu, i);
76                         if (cache_id > 0)
77                                 cpu_topology[cpu].llc_id = cache_id;
78                 }
79         }
80
81         return 0;
82 }
83 #endif
84
85