Commit af8f3f514d193eb353f9b6cea503c55d074e6153

Authored by Hanjun Guo
Committed by Rafael J. Wysocki
1 parent b7392d2247

ACPI / processor: Convert apic_id to phys_id to make it arch agnostic

apic_id in MADT table is the CPU hardware id which identify
it self in the system for x86 and ia64, OSPM will use it for
SMP init to map APIC ID to logical cpu number in the early
boot, when the DSDT/SSDT (ACPI namespace) is scanned later, the
ACPI processor driver is probed and the driver will use acpi_id
in DSDT to get the apic_id, then map to the logical cpu number
which is needed by the processor driver.

Before ACPI 5.0, only x86 and ia64 were supported in ACPI spec,
so apic_id is used both in arch code and ACPI core which is
pretty fine. Since ACPI 5.0, ARM is supported by ACPI and
APIC is not available on ARM, this will confuse people when
apic_id is both used by x86 and ARM in one function.

So convert apic_id to phys_id (which is the original meaning)
in ACPI processor dirver to make it arch agnostic, but leave the
arch dependent code unchanged, no functional change.

Signed-off-by: Hanjun Guo <hanjun.guo@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Showing 3 changed files with 44 additions and 41 deletions Side-by-side Diff

drivers/acpi/acpi_processor.c
... ... @@ -170,7 +170,7 @@
170 170 acpi_status status;
171 171 int ret;
172 172  
173   - if (pr->apic_id == -1)
  173 + if (pr->phys_id == -1)
174 174 return -ENODEV;
175 175  
176 176 status = acpi_evaluate_integer(pr->handle, "_STA", NULL, &sta);
... ... @@ -180,7 +180,7 @@
180 180 cpu_maps_update_begin();
181 181 cpu_hotplug_begin();
182 182  
183   - ret = acpi_map_lsapic(pr->handle, pr->apic_id, &pr->id);
  183 + ret = acpi_map_lsapic(pr->handle, pr->phys_id, &pr->id);
184 184 if (ret)
185 185 goto out;
186 186  
... ... @@ -215,7 +215,7 @@
215 215 union acpi_object object = { 0 };
216 216 struct acpi_buffer buffer = { sizeof(union acpi_object), &object };
217 217 struct acpi_processor *pr = acpi_driver_data(device);
218   - int apic_id, cpu_index, device_declaration = 0;
  218 + int phys_id, cpu_index, device_declaration = 0;
219 219 acpi_status status = AE_OK;
220 220 static int cpu0_initialized;
221 221 unsigned long long value;
222 222  
223 223  
... ... @@ -262,15 +262,18 @@
262 262 pr->acpi_id = value;
263 263 }
264 264  
265   - apic_id = acpi_get_apicid(pr->handle, device_declaration, pr->acpi_id);
266   - if (apic_id < 0)
267   - acpi_handle_debug(pr->handle, "failed to get CPU APIC ID.\n");
268   - pr->apic_id = apic_id;
  265 + phys_id = acpi_get_phys_id(pr->handle, device_declaration, pr->acpi_id);
  266 + if (phys_id < 0)
  267 + acpi_handle_debug(pr->handle, "failed to get CPU physical ID.\n");
  268 + pr->phys_id = phys_id;
269 269  
270   - cpu_index = acpi_map_cpuid(pr->apic_id, pr->acpi_id);
  270 + cpu_index = acpi_map_cpuid(pr->phys_id, pr->acpi_id);
271 271 if (!cpu0_initialized && !acpi_has_cpu_in_madt()) {
272 272 cpu0_initialized = 1;
273   - /* Handle UP system running SMP kernel, with no LAPIC in MADT */
  273 + /*
  274 + * Handle UP system running SMP kernel, with no CPU
  275 + * entry in MADT
  276 + */
274 277 if ((cpu_index == -1) && (num_online_cpus() == 1))
275 278 cpu_index = 0;
276 279 }
drivers/acpi/processor_core.c
... ... @@ -69,7 +69,7 @@
69 69 unsigned long madt_end, entry;
70 70 static struct acpi_table_madt *madt;
71 71 static int read_madt;
72   - int apic_id = -1;
  72 + int phys_id = -1; /* CPU hardware ID */
73 73  
74 74 if (!read_madt) {
75 75 if (ACPI_FAILURE(acpi_get_table(ACPI_SIG_MADT, 0,
... ... @@ -79,7 +79,7 @@
79 79 }
80 80  
81 81 if (!madt)
82   - return apic_id;
  82 + return phys_id;
83 83  
84 84 entry = (unsigned long)madt;
85 85 madt_end = entry + madt->header.length;
86 86  
87 87  
88 88  
... ... @@ -91,18 +91,18 @@
91 91 struct acpi_subtable_header *header =
92 92 (struct acpi_subtable_header *)entry;
93 93 if (header->type == ACPI_MADT_TYPE_LOCAL_APIC) {
94   - if (!map_lapic_id(header, acpi_id, &apic_id))
  94 + if (!map_lapic_id(header, acpi_id, &phys_id))
95 95 break;
96 96 } else if (header->type == ACPI_MADT_TYPE_LOCAL_X2APIC) {
97   - if (!map_x2apic_id(header, type, acpi_id, &apic_id))
  97 + if (!map_x2apic_id(header, type, acpi_id, &phys_id))
98 98 break;
99 99 } else if (header->type == ACPI_MADT_TYPE_LOCAL_SAPIC) {
100   - if (!map_lsapic_id(header, type, acpi_id, &apic_id))
  100 + if (!map_lsapic_id(header, type, acpi_id, &phys_id))
101 101 break;
102 102 }
103 103 entry += header->length;
104 104 }
105   - return apic_id;
  105 + return phys_id;
106 106 }
107 107  
108 108 static int map_mat_entry(acpi_handle handle, int type, u32 acpi_id)
... ... @@ -110,7 +110,7 @@
110 110 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
111 111 union acpi_object *obj;
112 112 struct acpi_subtable_header *header;
113   - int apic_id = -1;
  113 + int phys_id = -1;
114 114  
115 115 if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer)))
116 116 goto exit;
117 117  
118 118  
119 119  
120 120  
121 121  
122 122  
123 123  
124 124  
125 125  
126 126  
... ... @@ -126,38 +126,38 @@
126 126  
127 127 header = (struct acpi_subtable_header *)obj->buffer.pointer;
128 128 if (header->type == ACPI_MADT_TYPE_LOCAL_APIC)
129   - map_lapic_id(header, acpi_id, &apic_id);
  129 + map_lapic_id(header, acpi_id, &phys_id);
130 130 else if (header->type == ACPI_MADT_TYPE_LOCAL_SAPIC)
131   - map_lsapic_id(header, type, acpi_id, &apic_id);
  131 + map_lsapic_id(header, type, acpi_id, &phys_id);
132 132 else if (header->type == ACPI_MADT_TYPE_LOCAL_X2APIC)
133   - map_x2apic_id(header, type, acpi_id, &apic_id);
  133 + map_x2apic_id(header, type, acpi_id, &phys_id);
134 134  
135 135 exit:
136 136 kfree(buffer.pointer);
137   - return apic_id;
  137 + return phys_id;
138 138 }
139 139  
140   -int acpi_get_apicid(acpi_handle handle, int type, u32 acpi_id)
  140 +int acpi_get_phys_id(acpi_handle handle, int type, u32 acpi_id)
141 141 {
142   - int apic_id;
  142 + int phys_id;
143 143  
144   - apic_id = map_mat_entry(handle, type, acpi_id);
145   - if (apic_id == -1)
146   - apic_id = map_madt_entry(type, acpi_id);
  144 + phys_id = map_mat_entry(handle, type, acpi_id);
  145 + if (phys_id == -1)
  146 + phys_id = map_madt_entry(type, acpi_id);
147 147  
148   - return apic_id;
  148 + return phys_id;
149 149 }
150 150  
151   -int acpi_map_cpuid(int apic_id, u32 acpi_id)
  151 +int acpi_map_cpuid(int phys_id, u32 acpi_id)
152 152 {
153 153 #ifdef CONFIG_SMP
154 154 int i;
155 155 #endif
156 156  
157   - if (apic_id == -1) {
  157 + if (phys_id == -1) {
158 158 /*
159 159 * On UP processor, there is no _MAT or MADT table.
160   - * So above apic_id is always set to -1.
  160 + * So above phys_id is always set to -1.
161 161 *
162 162 * BIOS may define multiple CPU handles even for UP processor.
163 163 * For example,
... ... @@ -170,7 +170,7 @@
170 170 * Processor (CPU3, 0x03, 0x00000410, 0x06) {}
171 171 * }
172 172 *
173   - * Ignores apic_id and always returns 0 for the processor
  173 + * Ignores phys_id and always returns 0 for the processor
174 174 * handle with acpi id 0 if nr_cpu_ids is 1.
175 175 * This should be the case if SMP tables are not found.
176 176 * Return -1 for other CPU's handle.
177 177  
178 178  
179 179  
180 180  
181 181  
... ... @@ -178,29 +178,29 @@
178 178 if (nr_cpu_ids <= 1 && acpi_id == 0)
179 179 return acpi_id;
180 180 else
181   - return apic_id;
  181 + return phys_id;
182 182 }
183 183  
184 184 #ifdef CONFIG_SMP
185 185 for_each_possible_cpu(i) {
186   - if (cpu_physical_id(i) == apic_id)
  186 + if (cpu_physical_id(i) == phys_id)
187 187 return i;
188 188 }
189 189 #else
190 190 /* In UP kernel, only processor 0 is valid */
191   - if (apic_id == 0)
192   - return apic_id;
  191 + if (phys_id == 0)
  192 + return phys_id;
193 193 #endif
194 194 return -1;
195 195 }
196 196  
197 197 int acpi_get_cpuid(acpi_handle handle, int type, u32 acpi_id)
198 198 {
199   - int apic_id;
  199 + int phys_id;
200 200  
201   - apic_id = acpi_get_apicid(handle, type, acpi_id);
  201 + phys_id = acpi_get_phys_id(handle, type, acpi_id);
202 202  
203   - return acpi_map_cpuid(apic_id, acpi_id);
  203 + return acpi_map_cpuid(phys_id, acpi_id);
204 204 }
205 205 EXPORT_SYMBOL_GPL(acpi_get_cpuid);
include/acpi/processor.h
... ... @@ -196,8 +196,8 @@
196 196 struct acpi_processor {
197 197 acpi_handle handle;
198 198 u32 acpi_id;
199   - u32 apic_id;
200   - u32 id;
  199 + u32 phys_id; /* CPU hardware ID such as APIC ID for x86 */
  200 + u32 id; /* CPU logical ID allocated by OS */
201 201 u32 pblk;
202 202 int performance_platform_limit;
203 203 int throttling_platform_limit;
... ... @@ -310,8 +310,8 @@
310 310 #endif /* CONFIG_CPU_FREQ */
311 311  
312 312 /* in processor_core.c */
313   -int acpi_get_apicid(acpi_handle, int type, u32 acpi_id);
314   -int acpi_map_cpuid(int apic_id, u32 acpi_id);
  313 +int acpi_get_phys_id(acpi_handle, int type, u32 acpi_id);
  314 +int acpi_map_cpuid(int phys_id, u32 acpi_id);
315 315 int acpi_get_cpuid(acpi_handle, int type, u32 acpi_id);
316 316  
317 317 /* in processor_pdc.c */