1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * pptt.c - parsing of Processor Properties Topology Table (PPTT)
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Copyright (C) 2018, ARM
6*4882a593Smuzhiyun *
7*4882a593Smuzhiyun * This file implements parsing of the Processor Properties Topology Table
8*4882a593Smuzhiyun * which is optionally used to describe the processor and cache topology.
9*4882a593Smuzhiyun * Due to the relative pointers used throughout the table, this doesn't
10*4882a593Smuzhiyun * leverage the existing subtable parsing in the kernel.
11*4882a593Smuzhiyun *
12*4882a593Smuzhiyun * The PPTT structure is an inverted tree, with each node potentially
13*4882a593Smuzhiyun * holding one or two inverted tree data structures describing
14*4882a593Smuzhiyun * the caches available at that level. Each cache structure optionally
15*4882a593Smuzhiyun * contains properties describing the cache at a given level which can be
16*4882a593Smuzhiyun * used to override hardware probed values.
17*4882a593Smuzhiyun */
18*4882a593Smuzhiyun #define pr_fmt(fmt) "ACPI PPTT: " fmt
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun #include <linux/acpi.h>
21*4882a593Smuzhiyun #include <linux/cacheinfo.h>
22*4882a593Smuzhiyun #include <acpi/processor.h>
23*4882a593Smuzhiyun
fetch_pptt_subtable(struct acpi_table_header * table_hdr,u32 pptt_ref)24*4882a593Smuzhiyun static struct acpi_subtable_header *fetch_pptt_subtable(struct acpi_table_header *table_hdr,
25*4882a593Smuzhiyun u32 pptt_ref)
26*4882a593Smuzhiyun {
27*4882a593Smuzhiyun struct acpi_subtable_header *entry;
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun /* there isn't a subtable at reference 0 */
30*4882a593Smuzhiyun if (pptt_ref < sizeof(struct acpi_subtable_header))
31*4882a593Smuzhiyun return NULL;
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun if (pptt_ref + sizeof(struct acpi_subtable_header) > table_hdr->length)
34*4882a593Smuzhiyun return NULL;
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun entry = ACPI_ADD_PTR(struct acpi_subtable_header, table_hdr, pptt_ref);
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun if (entry->length == 0)
39*4882a593Smuzhiyun return NULL;
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun if (pptt_ref + entry->length > table_hdr->length)
42*4882a593Smuzhiyun return NULL;
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun return entry;
45*4882a593Smuzhiyun }
46*4882a593Smuzhiyun
fetch_pptt_node(struct acpi_table_header * table_hdr,u32 pptt_ref)47*4882a593Smuzhiyun static struct acpi_pptt_processor *fetch_pptt_node(struct acpi_table_header *table_hdr,
48*4882a593Smuzhiyun u32 pptt_ref)
49*4882a593Smuzhiyun {
50*4882a593Smuzhiyun return (struct acpi_pptt_processor *)fetch_pptt_subtable(table_hdr, pptt_ref);
51*4882a593Smuzhiyun }
52*4882a593Smuzhiyun
fetch_pptt_cache(struct acpi_table_header * table_hdr,u32 pptt_ref)53*4882a593Smuzhiyun static struct acpi_pptt_cache *fetch_pptt_cache(struct acpi_table_header *table_hdr,
54*4882a593Smuzhiyun u32 pptt_ref)
55*4882a593Smuzhiyun {
56*4882a593Smuzhiyun return (struct acpi_pptt_cache *)fetch_pptt_subtable(table_hdr, pptt_ref);
57*4882a593Smuzhiyun }
58*4882a593Smuzhiyun
acpi_get_pptt_resource(struct acpi_table_header * table_hdr,struct acpi_pptt_processor * node,int resource)59*4882a593Smuzhiyun static struct acpi_subtable_header *acpi_get_pptt_resource(struct acpi_table_header *table_hdr,
60*4882a593Smuzhiyun struct acpi_pptt_processor *node,
61*4882a593Smuzhiyun int resource)
62*4882a593Smuzhiyun {
63*4882a593Smuzhiyun u32 *ref;
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun if (resource >= node->number_of_priv_resources)
66*4882a593Smuzhiyun return NULL;
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun ref = ACPI_ADD_PTR(u32, node, sizeof(struct acpi_pptt_processor));
69*4882a593Smuzhiyun ref += resource;
70*4882a593Smuzhiyun
71*4882a593Smuzhiyun return fetch_pptt_subtable(table_hdr, *ref);
72*4882a593Smuzhiyun }
73*4882a593Smuzhiyun
acpi_pptt_match_type(int table_type,int type)74*4882a593Smuzhiyun static inline bool acpi_pptt_match_type(int table_type, int type)
75*4882a593Smuzhiyun {
76*4882a593Smuzhiyun return ((table_type & ACPI_PPTT_MASK_CACHE_TYPE) == type ||
77*4882a593Smuzhiyun table_type & ACPI_PPTT_CACHE_TYPE_UNIFIED & type);
78*4882a593Smuzhiyun }
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun /**
81*4882a593Smuzhiyun * acpi_pptt_walk_cache() - Attempt to find the requested acpi_pptt_cache
82*4882a593Smuzhiyun * @table_hdr: Pointer to the head of the PPTT table
83*4882a593Smuzhiyun * @local_level: passed res reflects this cache level
84*4882a593Smuzhiyun * @res: cache resource in the PPTT we want to walk
85*4882a593Smuzhiyun * @found: returns a pointer to the requested level if found
86*4882a593Smuzhiyun * @level: the requested cache level
87*4882a593Smuzhiyun * @type: the requested cache type
88*4882a593Smuzhiyun *
89*4882a593Smuzhiyun * Attempt to find a given cache level, while counting the max number
90*4882a593Smuzhiyun * of cache levels for the cache node.
91*4882a593Smuzhiyun *
92*4882a593Smuzhiyun * Given a pptt resource, verify that it is a cache node, then walk
93*4882a593Smuzhiyun * down each level of caches, counting how many levels are found
94*4882a593Smuzhiyun * as well as checking the cache type (icache, dcache, unified). If a
95*4882a593Smuzhiyun * level & type match, then we set found, and continue the search.
96*4882a593Smuzhiyun * Once the entire cache branch has been walked return its max
97*4882a593Smuzhiyun * depth.
98*4882a593Smuzhiyun *
99*4882a593Smuzhiyun * Return: The cache structure and the level we terminated with.
100*4882a593Smuzhiyun */
acpi_pptt_walk_cache(struct acpi_table_header * table_hdr,unsigned int local_level,struct acpi_subtable_header * res,struct acpi_pptt_cache ** found,unsigned int level,int type)101*4882a593Smuzhiyun static unsigned int acpi_pptt_walk_cache(struct acpi_table_header *table_hdr,
102*4882a593Smuzhiyun unsigned int local_level,
103*4882a593Smuzhiyun struct acpi_subtable_header *res,
104*4882a593Smuzhiyun struct acpi_pptt_cache **found,
105*4882a593Smuzhiyun unsigned int level, int type)
106*4882a593Smuzhiyun {
107*4882a593Smuzhiyun struct acpi_pptt_cache *cache;
108*4882a593Smuzhiyun
109*4882a593Smuzhiyun if (res->type != ACPI_PPTT_TYPE_CACHE)
110*4882a593Smuzhiyun return 0;
111*4882a593Smuzhiyun
112*4882a593Smuzhiyun cache = (struct acpi_pptt_cache *) res;
113*4882a593Smuzhiyun while (cache) {
114*4882a593Smuzhiyun local_level++;
115*4882a593Smuzhiyun
116*4882a593Smuzhiyun if (local_level == level &&
117*4882a593Smuzhiyun cache->flags & ACPI_PPTT_CACHE_TYPE_VALID &&
118*4882a593Smuzhiyun acpi_pptt_match_type(cache->attributes, type)) {
119*4882a593Smuzhiyun if (*found != NULL && cache != *found)
120*4882a593Smuzhiyun pr_warn("Found duplicate cache level/type unable to determine uniqueness\n");
121*4882a593Smuzhiyun
122*4882a593Smuzhiyun pr_debug("Found cache @ level %u\n", level);
123*4882a593Smuzhiyun *found = cache;
124*4882a593Smuzhiyun /*
125*4882a593Smuzhiyun * continue looking at this node's resource list
126*4882a593Smuzhiyun * to verify that we don't find a duplicate
127*4882a593Smuzhiyun * cache node.
128*4882a593Smuzhiyun */
129*4882a593Smuzhiyun }
130*4882a593Smuzhiyun cache = fetch_pptt_cache(table_hdr, cache->next_level_of_cache);
131*4882a593Smuzhiyun }
132*4882a593Smuzhiyun return local_level;
133*4882a593Smuzhiyun }
134*4882a593Smuzhiyun
135*4882a593Smuzhiyun static struct acpi_pptt_cache *
acpi_find_cache_level(struct acpi_table_header * table_hdr,struct acpi_pptt_processor * cpu_node,unsigned int * starting_level,unsigned int level,int type)136*4882a593Smuzhiyun acpi_find_cache_level(struct acpi_table_header *table_hdr,
137*4882a593Smuzhiyun struct acpi_pptt_processor *cpu_node,
138*4882a593Smuzhiyun unsigned int *starting_level, unsigned int level,
139*4882a593Smuzhiyun int type)
140*4882a593Smuzhiyun {
141*4882a593Smuzhiyun struct acpi_subtable_header *res;
142*4882a593Smuzhiyun unsigned int number_of_levels = *starting_level;
143*4882a593Smuzhiyun int resource = 0;
144*4882a593Smuzhiyun struct acpi_pptt_cache *ret = NULL;
145*4882a593Smuzhiyun unsigned int local_level;
146*4882a593Smuzhiyun
147*4882a593Smuzhiyun /* walk down from processor node */
148*4882a593Smuzhiyun while ((res = acpi_get_pptt_resource(table_hdr, cpu_node, resource))) {
149*4882a593Smuzhiyun resource++;
150*4882a593Smuzhiyun
151*4882a593Smuzhiyun local_level = acpi_pptt_walk_cache(table_hdr, *starting_level,
152*4882a593Smuzhiyun res, &ret, level, type);
153*4882a593Smuzhiyun /*
154*4882a593Smuzhiyun * we are looking for the max depth. Since its potentially
155*4882a593Smuzhiyun * possible for a given node to have resources with differing
156*4882a593Smuzhiyun * depths verify that the depth we have found is the largest.
157*4882a593Smuzhiyun */
158*4882a593Smuzhiyun if (number_of_levels < local_level)
159*4882a593Smuzhiyun number_of_levels = local_level;
160*4882a593Smuzhiyun }
161*4882a593Smuzhiyun if (number_of_levels > *starting_level)
162*4882a593Smuzhiyun *starting_level = number_of_levels;
163*4882a593Smuzhiyun
164*4882a593Smuzhiyun return ret;
165*4882a593Smuzhiyun }
166*4882a593Smuzhiyun
167*4882a593Smuzhiyun /**
168*4882a593Smuzhiyun * acpi_count_levels() - Given a PPTT table, and a CPU node, count the caches
169*4882a593Smuzhiyun * @table_hdr: Pointer to the head of the PPTT table
170*4882a593Smuzhiyun * @cpu_node: processor node we wish to count caches for
171*4882a593Smuzhiyun *
172*4882a593Smuzhiyun * Given a processor node containing a processing unit, walk into it and count
173*4882a593Smuzhiyun * how many levels exist solely for it, and then walk up each level until we hit
174*4882a593Smuzhiyun * the root node (ignore the package level because it may be possible to have
175*4882a593Smuzhiyun * caches that exist across packages). Count the number of cache levels that
176*4882a593Smuzhiyun * exist at each level on the way up.
177*4882a593Smuzhiyun *
178*4882a593Smuzhiyun * Return: Total number of levels found.
179*4882a593Smuzhiyun */
acpi_count_levels(struct acpi_table_header * table_hdr,struct acpi_pptt_processor * cpu_node)180*4882a593Smuzhiyun static int acpi_count_levels(struct acpi_table_header *table_hdr,
181*4882a593Smuzhiyun struct acpi_pptt_processor *cpu_node)
182*4882a593Smuzhiyun {
183*4882a593Smuzhiyun int total_levels = 0;
184*4882a593Smuzhiyun
185*4882a593Smuzhiyun do {
186*4882a593Smuzhiyun acpi_find_cache_level(table_hdr, cpu_node, &total_levels, 0, 0);
187*4882a593Smuzhiyun cpu_node = fetch_pptt_node(table_hdr, cpu_node->parent);
188*4882a593Smuzhiyun } while (cpu_node);
189*4882a593Smuzhiyun
190*4882a593Smuzhiyun return total_levels;
191*4882a593Smuzhiyun }
192*4882a593Smuzhiyun
193*4882a593Smuzhiyun /**
194*4882a593Smuzhiyun * acpi_pptt_leaf_node() - Given a processor node, determine if its a leaf
195*4882a593Smuzhiyun * @table_hdr: Pointer to the head of the PPTT table
196*4882a593Smuzhiyun * @node: passed node is checked to see if its a leaf
197*4882a593Smuzhiyun *
198*4882a593Smuzhiyun * Determine if the *node parameter is a leaf node by iterating the
199*4882a593Smuzhiyun * PPTT table, looking for nodes which reference it.
200*4882a593Smuzhiyun *
201*4882a593Smuzhiyun * Return: 0 if we find a node referencing the passed node (or table error),
202*4882a593Smuzhiyun * or 1 if we don't.
203*4882a593Smuzhiyun */
acpi_pptt_leaf_node(struct acpi_table_header * table_hdr,struct acpi_pptt_processor * node)204*4882a593Smuzhiyun static int acpi_pptt_leaf_node(struct acpi_table_header *table_hdr,
205*4882a593Smuzhiyun struct acpi_pptt_processor *node)
206*4882a593Smuzhiyun {
207*4882a593Smuzhiyun struct acpi_subtable_header *entry;
208*4882a593Smuzhiyun unsigned long table_end;
209*4882a593Smuzhiyun u32 node_entry;
210*4882a593Smuzhiyun struct acpi_pptt_processor *cpu_node;
211*4882a593Smuzhiyun u32 proc_sz;
212*4882a593Smuzhiyun
213*4882a593Smuzhiyun if (table_hdr->revision > 1)
214*4882a593Smuzhiyun return (node->flags & ACPI_PPTT_ACPI_LEAF_NODE);
215*4882a593Smuzhiyun
216*4882a593Smuzhiyun table_end = (unsigned long)table_hdr + table_hdr->length;
217*4882a593Smuzhiyun node_entry = ACPI_PTR_DIFF(node, table_hdr);
218*4882a593Smuzhiyun entry = ACPI_ADD_PTR(struct acpi_subtable_header, table_hdr,
219*4882a593Smuzhiyun sizeof(struct acpi_table_pptt));
220*4882a593Smuzhiyun proc_sz = sizeof(struct acpi_pptt_processor *);
221*4882a593Smuzhiyun
222*4882a593Smuzhiyun while ((unsigned long)entry + proc_sz < table_end) {
223*4882a593Smuzhiyun cpu_node = (struct acpi_pptt_processor *)entry;
224*4882a593Smuzhiyun if (entry->type == ACPI_PPTT_TYPE_PROCESSOR &&
225*4882a593Smuzhiyun cpu_node->parent == node_entry)
226*4882a593Smuzhiyun return 0;
227*4882a593Smuzhiyun if (entry->length == 0)
228*4882a593Smuzhiyun return 0;
229*4882a593Smuzhiyun entry = ACPI_ADD_PTR(struct acpi_subtable_header, entry,
230*4882a593Smuzhiyun entry->length);
231*4882a593Smuzhiyun
232*4882a593Smuzhiyun }
233*4882a593Smuzhiyun return 1;
234*4882a593Smuzhiyun }
235*4882a593Smuzhiyun
236*4882a593Smuzhiyun /**
237*4882a593Smuzhiyun * acpi_find_processor_node() - Given a PPTT table find the requested processor
238*4882a593Smuzhiyun * @table_hdr: Pointer to the head of the PPTT table
239*4882a593Smuzhiyun * @acpi_cpu_id: CPU we are searching for
240*4882a593Smuzhiyun *
241*4882a593Smuzhiyun * Find the subtable entry describing the provided processor.
242*4882a593Smuzhiyun * This is done by iterating the PPTT table looking for processor nodes
243*4882a593Smuzhiyun * which have an acpi_processor_id that matches the acpi_cpu_id parameter
244*4882a593Smuzhiyun * passed into the function. If we find a node that matches this criteria
245*4882a593Smuzhiyun * we verify that its a leaf node in the topology rather than depending
246*4882a593Smuzhiyun * on the valid flag, which doesn't need to be set for leaf nodes.
247*4882a593Smuzhiyun *
248*4882a593Smuzhiyun * Return: NULL, or the processors acpi_pptt_processor*
249*4882a593Smuzhiyun */
acpi_find_processor_node(struct acpi_table_header * table_hdr,u32 acpi_cpu_id)250*4882a593Smuzhiyun static struct acpi_pptt_processor *acpi_find_processor_node(struct acpi_table_header *table_hdr,
251*4882a593Smuzhiyun u32 acpi_cpu_id)
252*4882a593Smuzhiyun {
253*4882a593Smuzhiyun struct acpi_subtable_header *entry;
254*4882a593Smuzhiyun unsigned long table_end;
255*4882a593Smuzhiyun struct acpi_pptt_processor *cpu_node;
256*4882a593Smuzhiyun u32 proc_sz;
257*4882a593Smuzhiyun
258*4882a593Smuzhiyun table_end = (unsigned long)table_hdr + table_hdr->length;
259*4882a593Smuzhiyun entry = ACPI_ADD_PTR(struct acpi_subtable_header, table_hdr,
260*4882a593Smuzhiyun sizeof(struct acpi_table_pptt));
261*4882a593Smuzhiyun proc_sz = sizeof(struct acpi_pptt_processor *);
262*4882a593Smuzhiyun
263*4882a593Smuzhiyun /* find the processor structure associated with this cpuid */
264*4882a593Smuzhiyun while ((unsigned long)entry + proc_sz < table_end) {
265*4882a593Smuzhiyun cpu_node = (struct acpi_pptt_processor *)entry;
266*4882a593Smuzhiyun
267*4882a593Smuzhiyun if (entry->length == 0) {
268*4882a593Smuzhiyun pr_warn("Invalid zero length subtable\n");
269*4882a593Smuzhiyun break;
270*4882a593Smuzhiyun }
271*4882a593Smuzhiyun if (entry->type == ACPI_PPTT_TYPE_PROCESSOR &&
272*4882a593Smuzhiyun acpi_cpu_id == cpu_node->acpi_processor_id &&
273*4882a593Smuzhiyun acpi_pptt_leaf_node(table_hdr, cpu_node)) {
274*4882a593Smuzhiyun return (struct acpi_pptt_processor *)entry;
275*4882a593Smuzhiyun }
276*4882a593Smuzhiyun
277*4882a593Smuzhiyun entry = ACPI_ADD_PTR(struct acpi_subtable_header, entry,
278*4882a593Smuzhiyun entry->length);
279*4882a593Smuzhiyun }
280*4882a593Smuzhiyun
281*4882a593Smuzhiyun return NULL;
282*4882a593Smuzhiyun }
283*4882a593Smuzhiyun
acpi_find_cache_levels(struct acpi_table_header * table_hdr,u32 acpi_cpu_id)284*4882a593Smuzhiyun static int acpi_find_cache_levels(struct acpi_table_header *table_hdr,
285*4882a593Smuzhiyun u32 acpi_cpu_id)
286*4882a593Smuzhiyun {
287*4882a593Smuzhiyun int number_of_levels = 0;
288*4882a593Smuzhiyun struct acpi_pptt_processor *cpu;
289*4882a593Smuzhiyun
290*4882a593Smuzhiyun cpu = acpi_find_processor_node(table_hdr, acpi_cpu_id);
291*4882a593Smuzhiyun if (cpu)
292*4882a593Smuzhiyun number_of_levels = acpi_count_levels(table_hdr, cpu);
293*4882a593Smuzhiyun
294*4882a593Smuzhiyun return number_of_levels;
295*4882a593Smuzhiyun }
296*4882a593Smuzhiyun
acpi_cache_type(enum cache_type type)297*4882a593Smuzhiyun static u8 acpi_cache_type(enum cache_type type)
298*4882a593Smuzhiyun {
299*4882a593Smuzhiyun switch (type) {
300*4882a593Smuzhiyun case CACHE_TYPE_DATA:
301*4882a593Smuzhiyun pr_debug("Looking for data cache\n");
302*4882a593Smuzhiyun return ACPI_PPTT_CACHE_TYPE_DATA;
303*4882a593Smuzhiyun case CACHE_TYPE_INST:
304*4882a593Smuzhiyun pr_debug("Looking for instruction cache\n");
305*4882a593Smuzhiyun return ACPI_PPTT_CACHE_TYPE_INSTR;
306*4882a593Smuzhiyun default:
307*4882a593Smuzhiyun case CACHE_TYPE_UNIFIED:
308*4882a593Smuzhiyun pr_debug("Looking for unified cache\n");
309*4882a593Smuzhiyun /*
310*4882a593Smuzhiyun * It is important that ACPI_PPTT_CACHE_TYPE_UNIFIED
311*4882a593Smuzhiyun * contains the bit pattern that will match both
312*4882a593Smuzhiyun * ACPI unified bit patterns because we use it later
313*4882a593Smuzhiyun * to match both cases.
314*4882a593Smuzhiyun */
315*4882a593Smuzhiyun return ACPI_PPTT_CACHE_TYPE_UNIFIED;
316*4882a593Smuzhiyun }
317*4882a593Smuzhiyun }
318*4882a593Smuzhiyun
acpi_find_cache_node(struct acpi_table_header * table_hdr,u32 acpi_cpu_id,enum cache_type type,unsigned int level,struct acpi_pptt_processor ** node)319*4882a593Smuzhiyun static struct acpi_pptt_cache *acpi_find_cache_node(struct acpi_table_header *table_hdr,
320*4882a593Smuzhiyun u32 acpi_cpu_id,
321*4882a593Smuzhiyun enum cache_type type,
322*4882a593Smuzhiyun unsigned int level,
323*4882a593Smuzhiyun struct acpi_pptt_processor **node)
324*4882a593Smuzhiyun {
325*4882a593Smuzhiyun unsigned int total_levels = 0;
326*4882a593Smuzhiyun struct acpi_pptt_cache *found = NULL;
327*4882a593Smuzhiyun struct acpi_pptt_processor *cpu_node;
328*4882a593Smuzhiyun u8 acpi_type = acpi_cache_type(type);
329*4882a593Smuzhiyun
330*4882a593Smuzhiyun pr_debug("Looking for CPU %d's level %u cache type %d\n",
331*4882a593Smuzhiyun acpi_cpu_id, level, acpi_type);
332*4882a593Smuzhiyun
333*4882a593Smuzhiyun cpu_node = acpi_find_processor_node(table_hdr, acpi_cpu_id);
334*4882a593Smuzhiyun
335*4882a593Smuzhiyun while (cpu_node && !found) {
336*4882a593Smuzhiyun found = acpi_find_cache_level(table_hdr, cpu_node,
337*4882a593Smuzhiyun &total_levels, level, acpi_type);
338*4882a593Smuzhiyun *node = cpu_node;
339*4882a593Smuzhiyun cpu_node = fetch_pptt_node(table_hdr, cpu_node->parent);
340*4882a593Smuzhiyun }
341*4882a593Smuzhiyun
342*4882a593Smuzhiyun return found;
343*4882a593Smuzhiyun }
344*4882a593Smuzhiyun
345*4882a593Smuzhiyun /**
346*4882a593Smuzhiyun * update_cache_properties() - Update cacheinfo for the given processor
347*4882a593Smuzhiyun * @this_leaf: Kernel cache info structure being updated
348*4882a593Smuzhiyun * @found_cache: The PPTT node describing this cache instance
349*4882a593Smuzhiyun * @cpu_node: A unique reference to describe this cache instance
350*4882a593Smuzhiyun *
351*4882a593Smuzhiyun * The ACPI spec implies that the fields in the cache structures are used to
352*4882a593Smuzhiyun * extend and correct the information probed from the hardware. Lets only
353*4882a593Smuzhiyun * set fields that we determine are VALID.
354*4882a593Smuzhiyun *
355*4882a593Smuzhiyun * Return: nothing. Side effect of updating the global cacheinfo
356*4882a593Smuzhiyun */
update_cache_properties(struct cacheinfo * this_leaf,struct acpi_pptt_cache * found_cache,struct acpi_pptt_processor * cpu_node)357*4882a593Smuzhiyun static void update_cache_properties(struct cacheinfo *this_leaf,
358*4882a593Smuzhiyun struct acpi_pptt_cache *found_cache,
359*4882a593Smuzhiyun struct acpi_pptt_processor *cpu_node)
360*4882a593Smuzhiyun {
361*4882a593Smuzhiyun this_leaf->fw_token = cpu_node;
362*4882a593Smuzhiyun if (found_cache->flags & ACPI_PPTT_SIZE_PROPERTY_VALID)
363*4882a593Smuzhiyun this_leaf->size = found_cache->size;
364*4882a593Smuzhiyun if (found_cache->flags & ACPI_PPTT_LINE_SIZE_VALID)
365*4882a593Smuzhiyun this_leaf->coherency_line_size = found_cache->line_size;
366*4882a593Smuzhiyun if (found_cache->flags & ACPI_PPTT_NUMBER_OF_SETS_VALID)
367*4882a593Smuzhiyun this_leaf->number_of_sets = found_cache->number_of_sets;
368*4882a593Smuzhiyun if (found_cache->flags & ACPI_PPTT_ASSOCIATIVITY_VALID)
369*4882a593Smuzhiyun this_leaf->ways_of_associativity = found_cache->associativity;
370*4882a593Smuzhiyun if (found_cache->flags & ACPI_PPTT_WRITE_POLICY_VALID) {
371*4882a593Smuzhiyun switch (found_cache->attributes & ACPI_PPTT_MASK_WRITE_POLICY) {
372*4882a593Smuzhiyun case ACPI_PPTT_CACHE_POLICY_WT:
373*4882a593Smuzhiyun this_leaf->attributes = CACHE_WRITE_THROUGH;
374*4882a593Smuzhiyun break;
375*4882a593Smuzhiyun case ACPI_PPTT_CACHE_POLICY_WB:
376*4882a593Smuzhiyun this_leaf->attributes = CACHE_WRITE_BACK;
377*4882a593Smuzhiyun break;
378*4882a593Smuzhiyun }
379*4882a593Smuzhiyun }
380*4882a593Smuzhiyun if (found_cache->flags & ACPI_PPTT_ALLOCATION_TYPE_VALID) {
381*4882a593Smuzhiyun switch (found_cache->attributes & ACPI_PPTT_MASK_ALLOCATION_TYPE) {
382*4882a593Smuzhiyun case ACPI_PPTT_CACHE_READ_ALLOCATE:
383*4882a593Smuzhiyun this_leaf->attributes |= CACHE_READ_ALLOCATE;
384*4882a593Smuzhiyun break;
385*4882a593Smuzhiyun case ACPI_PPTT_CACHE_WRITE_ALLOCATE:
386*4882a593Smuzhiyun this_leaf->attributes |= CACHE_WRITE_ALLOCATE;
387*4882a593Smuzhiyun break;
388*4882a593Smuzhiyun case ACPI_PPTT_CACHE_RW_ALLOCATE:
389*4882a593Smuzhiyun case ACPI_PPTT_CACHE_RW_ALLOCATE_ALT:
390*4882a593Smuzhiyun this_leaf->attributes |=
391*4882a593Smuzhiyun CACHE_READ_ALLOCATE | CACHE_WRITE_ALLOCATE;
392*4882a593Smuzhiyun break;
393*4882a593Smuzhiyun }
394*4882a593Smuzhiyun }
395*4882a593Smuzhiyun /*
396*4882a593Smuzhiyun * If cache type is NOCACHE, then the cache hasn't been specified
397*4882a593Smuzhiyun * via other mechanisms. Update the type if a cache type has been
398*4882a593Smuzhiyun * provided.
399*4882a593Smuzhiyun *
400*4882a593Smuzhiyun * Note, we assume such caches are unified based on conventional system
401*4882a593Smuzhiyun * design and known examples. Significant work is required elsewhere to
402*4882a593Smuzhiyun * fully support data/instruction only type caches which are only
403*4882a593Smuzhiyun * specified in PPTT.
404*4882a593Smuzhiyun */
405*4882a593Smuzhiyun if (this_leaf->type == CACHE_TYPE_NOCACHE &&
406*4882a593Smuzhiyun found_cache->flags & ACPI_PPTT_CACHE_TYPE_VALID)
407*4882a593Smuzhiyun this_leaf->type = CACHE_TYPE_UNIFIED;
408*4882a593Smuzhiyun }
409*4882a593Smuzhiyun
cache_setup_acpi_cpu(struct acpi_table_header * table,unsigned int cpu)410*4882a593Smuzhiyun static void cache_setup_acpi_cpu(struct acpi_table_header *table,
411*4882a593Smuzhiyun unsigned int cpu)
412*4882a593Smuzhiyun {
413*4882a593Smuzhiyun struct acpi_pptt_cache *found_cache;
414*4882a593Smuzhiyun struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
415*4882a593Smuzhiyun u32 acpi_cpu_id = get_acpi_id_for_cpu(cpu);
416*4882a593Smuzhiyun struct cacheinfo *this_leaf;
417*4882a593Smuzhiyun unsigned int index = 0;
418*4882a593Smuzhiyun struct acpi_pptt_processor *cpu_node = NULL;
419*4882a593Smuzhiyun
420*4882a593Smuzhiyun while (index < get_cpu_cacheinfo(cpu)->num_leaves) {
421*4882a593Smuzhiyun this_leaf = this_cpu_ci->info_list + index;
422*4882a593Smuzhiyun found_cache = acpi_find_cache_node(table, acpi_cpu_id,
423*4882a593Smuzhiyun this_leaf->type,
424*4882a593Smuzhiyun this_leaf->level,
425*4882a593Smuzhiyun &cpu_node);
426*4882a593Smuzhiyun pr_debug("found = %p %p\n", found_cache, cpu_node);
427*4882a593Smuzhiyun if (found_cache)
428*4882a593Smuzhiyun update_cache_properties(this_leaf,
429*4882a593Smuzhiyun found_cache,
430*4882a593Smuzhiyun cpu_node);
431*4882a593Smuzhiyun
432*4882a593Smuzhiyun index++;
433*4882a593Smuzhiyun }
434*4882a593Smuzhiyun }
435*4882a593Smuzhiyun
flag_identical(struct acpi_table_header * table_hdr,struct acpi_pptt_processor * cpu)436*4882a593Smuzhiyun static bool flag_identical(struct acpi_table_header *table_hdr,
437*4882a593Smuzhiyun struct acpi_pptt_processor *cpu)
438*4882a593Smuzhiyun {
439*4882a593Smuzhiyun struct acpi_pptt_processor *next;
440*4882a593Smuzhiyun
441*4882a593Smuzhiyun /* heterogeneous machines must use PPTT revision > 1 */
442*4882a593Smuzhiyun if (table_hdr->revision < 2)
443*4882a593Smuzhiyun return false;
444*4882a593Smuzhiyun
445*4882a593Smuzhiyun /* Locate the last node in the tree with IDENTICAL set */
446*4882a593Smuzhiyun if (cpu->flags & ACPI_PPTT_ACPI_IDENTICAL) {
447*4882a593Smuzhiyun next = fetch_pptt_node(table_hdr, cpu->parent);
448*4882a593Smuzhiyun if (!(next && next->flags & ACPI_PPTT_ACPI_IDENTICAL))
449*4882a593Smuzhiyun return true;
450*4882a593Smuzhiyun }
451*4882a593Smuzhiyun
452*4882a593Smuzhiyun return false;
453*4882a593Smuzhiyun }
454*4882a593Smuzhiyun
455*4882a593Smuzhiyun /* Passing level values greater than this will result in search termination */
456*4882a593Smuzhiyun #define PPTT_ABORT_PACKAGE 0xFF
457*4882a593Smuzhiyun
acpi_find_processor_tag(struct acpi_table_header * table_hdr,struct acpi_pptt_processor * cpu,int level,int flag)458*4882a593Smuzhiyun static struct acpi_pptt_processor *acpi_find_processor_tag(struct acpi_table_header *table_hdr,
459*4882a593Smuzhiyun struct acpi_pptt_processor *cpu,
460*4882a593Smuzhiyun int level, int flag)
461*4882a593Smuzhiyun {
462*4882a593Smuzhiyun struct acpi_pptt_processor *prev_node;
463*4882a593Smuzhiyun
464*4882a593Smuzhiyun while (cpu && level) {
465*4882a593Smuzhiyun /* special case the identical flag to find last identical */
466*4882a593Smuzhiyun if (flag == ACPI_PPTT_ACPI_IDENTICAL) {
467*4882a593Smuzhiyun if (flag_identical(table_hdr, cpu))
468*4882a593Smuzhiyun break;
469*4882a593Smuzhiyun } else if (cpu->flags & flag)
470*4882a593Smuzhiyun break;
471*4882a593Smuzhiyun pr_debug("level %d\n", level);
472*4882a593Smuzhiyun prev_node = fetch_pptt_node(table_hdr, cpu->parent);
473*4882a593Smuzhiyun if (prev_node == NULL)
474*4882a593Smuzhiyun break;
475*4882a593Smuzhiyun cpu = prev_node;
476*4882a593Smuzhiyun level--;
477*4882a593Smuzhiyun }
478*4882a593Smuzhiyun return cpu;
479*4882a593Smuzhiyun }
480*4882a593Smuzhiyun
acpi_pptt_warn_missing(void)481*4882a593Smuzhiyun static void acpi_pptt_warn_missing(void)
482*4882a593Smuzhiyun {
483*4882a593Smuzhiyun pr_warn_once("No PPTT table found, CPU and cache topology may be inaccurate\n");
484*4882a593Smuzhiyun }
485*4882a593Smuzhiyun
486*4882a593Smuzhiyun /**
487*4882a593Smuzhiyun * topology_get_acpi_cpu_tag() - Find a unique topology value for a feature
488*4882a593Smuzhiyun * @table: Pointer to the head of the PPTT table
489*4882a593Smuzhiyun * @cpu: Kernel logical CPU number
490*4882a593Smuzhiyun * @level: A level that terminates the search
491*4882a593Smuzhiyun * @flag: A flag which terminates the search
492*4882a593Smuzhiyun *
493*4882a593Smuzhiyun * Get a unique value given a CPU, and a topology level, that can be
494*4882a593Smuzhiyun * matched to determine which cpus share common topological features
495*4882a593Smuzhiyun * at that level.
496*4882a593Smuzhiyun *
497*4882a593Smuzhiyun * Return: Unique value, or -ENOENT if unable to locate CPU
498*4882a593Smuzhiyun */
topology_get_acpi_cpu_tag(struct acpi_table_header * table,unsigned int cpu,int level,int flag)499*4882a593Smuzhiyun static int topology_get_acpi_cpu_tag(struct acpi_table_header *table,
500*4882a593Smuzhiyun unsigned int cpu, int level, int flag)
501*4882a593Smuzhiyun {
502*4882a593Smuzhiyun struct acpi_pptt_processor *cpu_node;
503*4882a593Smuzhiyun u32 acpi_cpu_id = get_acpi_id_for_cpu(cpu);
504*4882a593Smuzhiyun
505*4882a593Smuzhiyun cpu_node = acpi_find_processor_node(table, acpi_cpu_id);
506*4882a593Smuzhiyun if (cpu_node) {
507*4882a593Smuzhiyun cpu_node = acpi_find_processor_tag(table, cpu_node,
508*4882a593Smuzhiyun level, flag);
509*4882a593Smuzhiyun /*
510*4882a593Smuzhiyun * As per specification if the processor structure represents
511*4882a593Smuzhiyun * an actual processor, then ACPI processor ID must be valid.
512*4882a593Smuzhiyun * For processor containers ACPI_PPTT_ACPI_PROCESSOR_ID_VALID
513*4882a593Smuzhiyun * should be set if the UID is valid
514*4882a593Smuzhiyun */
515*4882a593Smuzhiyun if (level == 0 ||
516*4882a593Smuzhiyun cpu_node->flags & ACPI_PPTT_ACPI_PROCESSOR_ID_VALID)
517*4882a593Smuzhiyun return cpu_node->acpi_processor_id;
518*4882a593Smuzhiyun return ACPI_PTR_DIFF(cpu_node, table);
519*4882a593Smuzhiyun }
520*4882a593Smuzhiyun pr_warn_once("PPTT table found, but unable to locate core %d (%d)\n",
521*4882a593Smuzhiyun cpu, acpi_cpu_id);
522*4882a593Smuzhiyun return -ENOENT;
523*4882a593Smuzhiyun }
524*4882a593Smuzhiyun
find_acpi_cpu_topology_tag(unsigned int cpu,int level,int flag)525*4882a593Smuzhiyun static int find_acpi_cpu_topology_tag(unsigned int cpu, int level, int flag)
526*4882a593Smuzhiyun {
527*4882a593Smuzhiyun struct acpi_table_header *table;
528*4882a593Smuzhiyun acpi_status status;
529*4882a593Smuzhiyun int retval;
530*4882a593Smuzhiyun
531*4882a593Smuzhiyun status = acpi_get_table(ACPI_SIG_PPTT, 0, &table);
532*4882a593Smuzhiyun if (ACPI_FAILURE(status)) {
533*4882a593Smuzhiyun acpi_pptt_warn_missing();
534*4882a593Smuzhiyun return -ENOENT;
535*4882a593Smuzhiyun }
536*4882a593Smuzhiyun retval = topology_get_acpi_cpu_tag(table, cpu, level, flag);
537*4882a593Smuzhiyun pr_debug("Topology Setup ACPI CPU %d, level %d ret = %d\n",
538*4882a593Smuzhiyun cpu, level, retval);
539*4882a593Smuzhiyun acpi_put_table(table);
540*4882a593Smuzhiyun
541*4882a593Smuzhiyun return retval;
542*4882a593Smuzhiyun }
543*4882a593Smuzhiyun
544*4882a593Smuzhiyun /**
545*4882a593Smuzhiyun * check_acpi_cpu_flag() - Determine if CPU node has a flag set
546*4882a593Smuzhiyun * @cpu: Kernel logical CPU number
547*4882a593Smuzhiyun * @rev: The minimum PPTT revision defining the flag
548*4882a593Smuzhiyun * @flag: The flag itself
549*4882a593Smuzhiyun *
550*4882a593Smuzhiyun * Check the node representing a CPU for a given flag.
551*4882a593Smuzhiyun *
552*4882a593Smuzhiyun * Return: -ENOENT if the PPTT doesn't exist, the CPU cannot be found or
553*4882a593Smuzhiyun * the table revision isn't new enough.
554*4882a593Smuzhiyun * 1, any passed flag set
555*4882a593Smuzhiyun * 0, flag unset
556*4882a593Smuzhiyun */
check_acpi_cpu_flag(unsigned int cpu,int rev,u32 flag)557*4882a593Smuzhiyun static int check_acpi_cpu_flag(unsigned int cpu, int rev, u32 flag)
558*4882a593Smuzhiyun {
559*4882a593Smuzhiyun struct acpi_table_header *table;
560*4882a593Smuzhiyun acpi_status status;
561*4882a593Smuzhiyun u32 acpi_cpu_id = get_acpi_id_for_cpu(cpu);
562*4882a593Smuzhiyun struct acpi_pptt_processor *cpu_node = NULL;
563*4882a593Smuzhiyun int ret = -ENOENT;
564*4882a593Smuzhiyun
565*4882a593Smuzhiyun status = acpi_get_table(ACPI_SIG_PPTT, 0, &table);
566*4882a593Smuzhiyun if (ACPI_FAILURE(status)) {
567*4882a593Smuzhiyun acpi_pptt_warn_missing();
568*4882a593Smuzhiyun return ret;
569*4882a593Smuzhiyun }
570*4882a593Smuzhiyun
571*4882a593Smuzhiyun if (table->revision >= rev)
572*4882a593Smuzhiyun cpu_node = acpi_find_processor_node(table, acpi_cpu_id);
573*4882a593Smuzhiyun
574*4882a593Smuzhiyun if (cpu_node)
575*4882a593Smuzhiyun ret = (cpu_node->flags & flag) != 0;
576*4882a593Smuzhiyun
577*4882a593Smuzhiyun acpi_put_table(table);
578*4882a593Smuzhiyun
579*4882a593Smuzhiyun return ret;
580*4882a593Smuzhiyun }
581*4882a593Smuzhiyun
582*4882a593Smuzhiyun /**
583*4882a593Smuzhiyun * acpi_find_last_cache_level() - Determines the number of cache levels for a PE
584*4882a593Smuzhiyun * @cpu: Kernel logical CPU number
585*4882a593Smuzhiyun *
586*4882a593Smuzhiyun * Given a logical CPU number, returns the number of levels of cache represented
587*4882a593Smuzhiyun * in the PPTT. Errors caused by lack of a PPTT table, or otherwise, return 0
588*4882a593Smuzhiyun * indicating we didn't find any cache levels.
589*4882a593Smuzhiyun *
590*4882a593Smuzhiyun * Return: Cache levels visible to this core.
591*4882a593Smuzhiyun */
acpi_find_last_cache_level(unsigned int cpu)592*4882a593Smuzhiyun int acpi_find_last_cache_level(unsigned int cpu)
593*4882a593Smuzhiyun {
594*4882a593Smuzhiyun u32 acpi_cpu_id;
595*4882a593Smuzhiyun struct acpi_table_header *table;
596*4882a593Smuzhiyun int number_of_levels = 0;
597*4882a593Smuzhiyun acpi_status status;
598*4882a593Smuzhiyun
599*4882a593Smuzhiyun pr_debug("Cache Setup find last level CPU=%d\n", cpu);
600*4882a593Smuzhiyun
601*4882a593Smuzhiyun acpi_cpu_id = get_acpi_id_for_cpu(cpu);
602*4882a593Smuzhiyun status = acpi_get_table(ACPI_SIG_PPTT, 0, &table);
603*4882a593Smuzhiyun if (ACPI_FAILURE(status)) {
604*4882a593Smuzhiyun acpi_pptt_warn_missing();
605*4882a593Smuzhiyun } else {
606*4882a593Smuzhiyun number_of_levels = acpi_find_cache_levels(table, acpi_cpu_id);
607*4882a593Smuzhiyun acpi_put_table(table);
608*4882a593Smuzhiyun }
609*4882a593Smuzhiyun pr_debug("Cache Setup find last level level=%d\n", number_of_levels);
610*4882a593Smuzhiyun
611*4882a593Smuzhiyun return number_of_levels;
612*4882a593Smuzhiyun }
613*4882a593Smuzhiyun
614*4882a593Smuzhiyun /**
615*4882a593Smuzhiyun * cache_setup_acpi() - Override CPU cache topology with data from the PPTT
616*4882a593Smuzhiyun * @cpu: Kernel logical CPU number
617*4882a593Smuzhiyun *
618*4882a593Smuzhiyun * Updates the global cache info provided by cpu_get_cacheinfo()
619*4882a593Smuzhiyun * when there are valid properties in the acpi_pptt_cache nodes. A
620*4882a593Smuzhiyun * successful parse may not result in any updates if none of the
621*4882a593Smuzhiyun * cache levels have any valid flags set. Further, a unique value is
622*4882a593Smuzhiyun * associated with each known CPU cache entry. This unique value
623*4882a593Smuzhiyun * can be used to determine whether caches are shared between CPUs.
624*4882a593Smuzhiyun *
625*4882a593Smuzhiyun * Return: -ENOENT on failure to find table, or 0 on success
626*4882a593Smuzhiyun */
cache_setup_acpi(unsigned int cpu)627*4882a593Smuzhiyun int cache_setup_acpi(unsigned int cpu)
628*4882a593Smuzhiyun {
629*4882a593Smuzhiyun struct acpi_table_header *table;
630*4882a593Smuzhiyun acpi_status status;
631*4882a593Smuzhiyun
632*4882a593Smuzhiyun pr_debug("Cache Setup ACPI CPU %d\n", cpu);
633*4882a593Smuzhiyun
634*4882a593Smuzhiyun status = acpi_get_table(ACPI_SIG_PPTT, 0, &table);
635*4882a593Smuzhiyun if (ACPI_FAILURE(status)) {
636*4882a593Smuzhiyun acpi_pptt_warn_missing();
637*4882a593Smuzhiyun return -ENOENT;
638*4882a593Smuzhiyun }
639*4882a593Smuzhiyun
640*4882a593Smuzhiyun cache_setup_acpi_cpu(table, cpu);
641*4882a593Smuzhiyun acpi_put_table(table);
642*4882a593Smuzhiyun
643*4882a593Smuzhiyun return status;
644*4882a593Smuzhiyun }
645*4882a593Smuzhiyun
646*4882a593Smuzhiyun /**
647*4882a593Smuzhiyun * acpi_pptt_cpu_is_thread() - Determine if CPU is a thread
648*4882a593Smuzhiyun * @cpu: Kernel logical CPU number
649*4882a593Smuzhiyun *
650*4882a593Smuzhiyun * Return: 1, a thread
651*4882a593Smuzhiyun * 0, not a thread
652*4882a593Smuzhiyun * -ENOENT ,if the PPTT doesn't exist, the CPU cannot be found or
653*4882a593Smuzhiyun * the table revision isn't new enough.
654*4882a593Smuzhiyun */
acpi_pptt_cpu_is_thread(unsigned int cpu)655*4882a593Smuzhiyun int acpi_pptt_cpu_is_thread(unsigned int cpu)
656*4882a593Smuzhiyun {
657*4882a593Smuzhiyun return check_acpi_cpu_flag(cpu, 2, ACPI_PPTT_ACPI_PROCESSOR_IS_THREAD);
658*4882a593Smuzhiyun }
659*4882a593Smuzhiyun
660*4882a593Smuzhiyun /**
661*4882a593Smuzhiyun * find_acpi_cpu_topology() - Determine a unique topology value for a given CPU
662*4882a593Smuzhiyun * @cpu: Kernel logical CPU number
663*4882a593Smuzhiyun * @level: The topological level for which we would like a unique ID
664*4882a593Smuzhiyun *
665*4882a593Smuzhiyun * Determine a topology unique ID for each thread/core/cluster/mc_grouping
666*4882a593Smuzhiyun * /socket/etc. This ID can then be used to group peers, which will have
667*4882a593Smuzhiyun * matching ids.
668*4882a593Smuzhiyun *
669*4882a593Smuzhiyun * The search terminates when either the requested level is found or
670*4882a593Smuzhiyun * we reach a root node. Levels beyond the termination point will return the
671*4882a593Smuzhiyun * same unique ID. The unique id for level 0 is the acpi processor id. All
672*4882a593Smuzhiyun * other levels beyond this use a generated value to uniquely identify
673*4882a593Smuzhiyun * a topological feature.
674*4882a593Smuzhiyun *
675*4882a593Smuzhiyun * Return: -ENOENT if the PPTT doesn't exist, or the CPU cannot be found.
676*4882a593Smuzhiyun * Otherwise returns a value which represents a unique topological feature.
677*4882a593Smuzhiyun */
find_acpi_cpu_topology(unsigned int cpu,int level)678*4882a593Smuzhiyun int find_acpi_cpu_topology(unsigned int cpu, int level)
679*4882a593Smuzhiyun {
680*4882a593Smuzhiyun return find_acpi_cpu_topology_tag(cpu, level, 0);
681*4882a593Smuzhiyun }
682*4882a593Smuzhiyun
683*4882a593Smuzhiyun /**
684*4882a593Smuzhiyun * find_acpi_cpu_cache_topology() - Determine a unique cache topology value
685*4882a593Smuzhiyun * @cpu: Kernel logical CPU number
686*4882a593Smuzhiyun * @level: The cache level for which we would like a unique ID
687*4882a593Smuzhiyun *
688*4882a593Smuzhiyun * Determine a unique ID for each unified cache in the system
689*4882a593Smuzhiyun *
690*4882a593Smuzhiyun * Return: -ENOENT if the PPTT doesn't exist, or the CPU cannot be found.
691*4882a593Smuzhiyun * Otherwise returns a value which represents a unique topological feature.
692*4882a593Smuzhiyun */
find_acpi_cpu_cache_topology(unsigned int cpu,int level)693*4882a593Smuzhiyun int find_acpi_cpu_cache_topology(unsigned int cpu, int level)
694*4882a593Smuzhiyun {
695*4882a593Smuzhiyun struct acpi_table_header *table;
696*4882a593Smuzhiyun struct acpi_pptt_cache *found_cache;
697*4882a593Smuzhiyun acpi_status status;
698*4882a593Smuzhiyun u32 acpi_cpu_id = get_acpi_id_for_cpu(cpu);
699*4882a593Smuzhiyun struct acpi_pptt_processor *cpu_node = NULL;
700*4882a593Smuzhiyun int ret = -1;
701*4882a593Smuzhiyun
702*4882a593Smuzhiyun status = acpi_get_table(ACPI_SIG_PPTT, 0, &table);
703*4882a593Smuzhiyun if (ACPI_FAILURE(status)) {
704*4882a593Smuzhiyun acpi_pptt_warn_missing();
705*4882a593Smuzhiyun return -ENOENT;
706*4882a593Smuzhiyun }
707*4882a593Smuzhiyun
708*4882a593Smuzhiyun found_cache = acpi_find_cache_node(table, acpi_cpu_id,
709*4882a593Smuzhiyun CACHE_TYPE_UNIFIED,
710*4882a593Smuzhiyun level,
711*4882a593Smuzhiyun &cpu_node);
712*4882a593Smuzhiyun if (found_cache)
713*4882a593Smuzhiyun ret = ACPI_PTR_DIFF(cpu_node, table);
714*4882a593Smuzhiyun
715*4882a593Smuzhiyun acpi_put_table(table);
716*4882a593Smuzhiyun
717*4882a593Smuzhiyun return ret;
718*4882a593Smuzhiyun }
719*4882a593Smuzhiyun
720*4882a593Smuzhiyun /**
721*4882a593Smuzhiyun * find_acpi_cpu_topology_package() - Determine a unique CPU package value
722*4882a593Smuzhiyun * @cpu: Kernel logical CPU number
723*4882a593Smuzhiyun *
724*4882a593Smuzhiyun * Determine a topology unique package ID for the given CPU.
725*4882a593Smuzhiyun * This ID can then be used to group peers, which will have matching ids.
726*4882a593Smuzhiyun *
727*4882a593Smuzhiyun * The search terminates when either a level is found with the PHYSICAL_PACKAGE
728*4882a593Smuzhiyun * flag set or we reach a root node.
729*4882a593Smuzhiyun *
730*4882a593Smuzhiyun * Return: -ENOENT if the PPTT doesn't exist, or the CPU cannot be found.
731*4882a593Smuzhiyun * Otherwise returns a value which represents the package for this CPU.
732*4882a593Smuzhiyun */
find_acpi_cpu_topology_package(unsigned int cpu)733*4882a593Smuzhiyun int find_acpi_cpu_topology_package(unsigned int cpu)
734*4882a593Smuzhiyun {
735*4882a593Smuzhiyun return find_acpi_cpu_topology_tag(cpu, PPTT_ABORT_PACKAGE,
736*4882a593Smuzhiyun ACPI_PPTT_PHYSICAL_PACKAGE);
737*4882a593Smuzhiyun }
738*4882a593Smuzhiyun
739*4882a593Smuzhiyun /**
740*4882a593Smuzhiyun * find_acpi_cpu_topology_hetero_id() - Get a core architecture tag
741*4882a593Smuzhiyun * @cpu: Kernel logical CPU number
742*4882a593Smuzhiyun *
743*4882a593Smuzhiyun * Determine a unique heterogeneous tag for the given CPU. CPUs with the same
744*4882a593Smuzhiyun * implementation should have matching tags.
745*4882a593Smuzhiyun *
746*4882a593Smuzhiyun * The returned tag can be used to group peers with identical implementation.
747*4882a593Smuzhiyun *
748*4882a593Smuzhiyun * The search terminates when a level is found with the identical implementation
749*4882a593Smuzhiyun * flag set or we reach a root node.
750*4882a593Smuzhiyun *
751*4882a593Smuzhiyun * Due to limitations in the PPTT data structure, there may be rare situations
752*4882a593Smuzhiyun * where two cores in a heterogeneous machine may be identical, but won't have
753*4882a593Smuzhiyun * the same tag.
754*4882a593Smuzhiyun *
755*4882a593Smuzhiyun * Return: -ENOENT if the PPTT doesn't exist, or the CPU cannot be found.
756*4882a593Smuzhiyun * Otherwise returns a value which represents a group of identical cores
757*4882a593Smuzhiyun * similar to this CPU.
758*4882a593Smuzhiyun */
find_acpi_cpu_topology_hetero_id(unsigned int cpu)759*4882a593Smuzhiyun int find_acpi_cpu_topology_hetero_id(unsigned int cpu)
760*4882a593Smuzhiyun {
761*4882a593Smuzhiyun return find_acpi_cpu_topology_tag(cpu, PPTT_ABORT_PACKAGE,
762*4882a593Smuzhiyun ACPI_PPTT_ACPI_IDENTICAL);
763*4882a593Smuzhiyun }
764