Lines Matching +full:cache +full:- +full:level
1 // SPDX-License-Identifier: GPL-2.0
3 * pptt.c - parsing of Processor Properties Topology Table (PPTT)
8 * which is optionally used to describe the processor and cache topology.
14 * the caches available at that level. Each cache structure optionally
15 * contains properties describing the cache at a given level which can be
33 if (pptt_ref + sizeof(struct acpi_subtable_header) > table_hdr->length) in fetch_pptt_subtable()
38 if (entry->length == 0) in fetch_pptt_subtable()
41 if (pptt_ref + entry->length > table_hdr->length) in fetch_pptt_subtable()
65 if (resource >= node->number_of_priv_resources) in acpi_get_pptt_resource()
81 * acpi_pptt_walk_cache() - Attempt to find the requested acpi_pptt_cache
83 * @local_level: passed res reflects this cache level
84 * @res: cache resource in the PPTT we want to walk
85 * @found: returns a pointer to the requested level if found
86 * @level: the requested cache level
87 * @type: the requested cache type
89 * Attempt to find a given cache level, while counting the max number
90 * of cache levels for the cache node.
92 * Given a pptt resource, verify that it is a cache node, then walk
93 * down each level of caches, counting how many levels are found
94 * as well as checking the cache type (icache, dcache, unified). If a
95 * level & type match, then we set found, and continue the search.
96 * Once the entire cache branch has been walked return its max
99 * Return: The cache structure and the level we terminated with.
105 unsigned int level, int type) in acpi_pptt_walk_cache() argument
107 struct acpi_pptt_cache *cache; in acpi_pptt_walk_cache() local
109 if (res->type != ACPI_PPTT_TYPE_CACHE) in acpi_pptt_walk_cache()
112 cache = (struct acpi_pptt_cache *) res; in acpi_pptt_walk_cache()
113 while (cache) { in acpi_pptt_walk_cache()
116 if (local_level == level && in acpi_pptt_walk_cache()
117 cache->flags & ACPI_PPTT_CACHE_TYPE_VALID && in acpi_pptt_walk_cache()
118 acpi_pptt_match_type(cache->attributes, type)) { in acpi_pptt_walk_cache()
119 if (*found != NULL && cache != *found) in acpi_pptt_walk_cache()
120 pr_warn("Found duplicate cache level/type unable to determine uniqueness\n"); in acpi_pptt_walk_cache()
122 pr_debug("Found cache @ level %u\n", level); in acpi_pptt_walk_cache()
123 *found = cache; in acpi_pptt_walk_cache()
127 * cache node. in acpi_pptt_walk_cache()
130 cache = fetch_pptt_cache(table_hdr, cache->next_level_of_cache); in acpi_pptt_walk_cache()
138 unsigned int *starting_level, unsigned int level, in acpi_find_cache_level() argument
152 res, &ret, level, type); in acpi_find_cache_level()
168 * acpi_count_levels() - Given a PPTT table, and a CPU node, count the caches
173 * how many levels exist solely for it, and then walk up each level until we hit
174 * the root node (ignore the package level because it may be possible to have
175 * caches that exist across packages). Count the number of cache levels that
176 * exist at each level on the way up.
187 cpu_node = fetch_pptt_node(table_hdr, cpu_node->parent); in acpi_count_levels()
194 * acpi_pptt_leaf_node() - Given a processor node, determine if its a leaf
213 if (table_hdr->revision > 1) in acpi_pptt_leaf_node()
214 return (node->flags & ACPI_PPTT_ACPI_LEAF_NODE); in acpi_pptt_leaf_node()
216 table_end = (unsigned long)table_hdr + table_hdr->length; in acpi_pptt_leaf_node()
224 if (entry->type == ACPI_PPTT_TYPE_PROCESSOR && in acpi_pptt_leaf_node()
225 cpu_node->parent == node_entry) in acpi_pptt_leaf_node()
227 if (entry->length == 0) in acpi_pptt_leaf_node()
230 entry->length); in acpi_pptt_leaf_node()
237 * acpi_find_processor_node() - Given a PPTT table find the requested processor
258 table_end = (unsigned long)table_hdr + table_hdr->length; in acpi_find_processor_node()
267 if (entry->length == 0) { in acpi_find_processor_node()
271 if (entry->type == ACPI_PPTT_TYPE_PROCESSOR && in acpi_find_processor_node()
272 acpi_cpu_id == cpu_node->acpi_processor_id && in acpi_find_processor_node()
278 entry->length); in acpi_find_processor_node()
301 pr_debug("Looking for data cache\n"); in acpi_cache_type()
304 pr_debug("Looking for instruction cache\n"); in acpi_cache_type()
308 pr_debug("Looking for unified cache\n"); in acpi_cache_type()
322 unsigned int level, in acpi_find_cache_node() argument
330 pr_debug("Looking for CPU %d's level %u cache type %d\n", in acpi_find_cache_node()
331 acpi_cpu_id, level, acpi_type); in acpi_find_cache_node()
337 &total_levels, level, acpi_type); in acpi_find_cache_node()
339 cpu_node = fetch_pptt_node(table_hdr, cpu_node->parent); in acpi_find_cache_node()
346 * update_cache_properties() - Update cacheinfo for the given processor
347 * @this_leaf: Kernel cache info structure being updated
348 * @found_cache: The PPTT node describing this cache instance
349 * @cpu_node: A unique reference to describe this cache instance
352 * The ACPI spec implies that the fields in the cache structures are used to
365 this_leaf->fw_token = cpu_node; in update_cache_properties()
366 if (found_cache->flags & ACPI_PPTT_SIZE_PROPERTY_VALID) in update_cache_properties()
367 this_leaf->size = found_cache->size; in update_cache_properties()
368 if (found_cache->flags & ACPI_PPTT_LINE_SIZE_VALID) in update_cache_properties()
369 this_leaf->coherency_line_size = found_cache->line_size; in update_cache_properties()
370 if (found_cache->flags & ACPI_PPTT_NUMBER_OF_SETS_VALID) in update_cache_properties()
371 this_leaf->number_of_sets = found_cache->number_of_sets; in update_cache_properties()
372 if (found_cache->flags & ACPI_PPTT_ASSOCIATIVITY_VALID) in update_cache_properties()
373 this_leaf->ways_of_associativity = found_cache->associativity; in update_cache_properties()
374 if (found_cache->flags & ACPI_PPTT_WRITE_POLICY_VALID) { in update_cache_properties()
375 switch (found_cache->attributes & ACPI_PPTT_MASK_WRITE_POLICY) { in update_cache_properties()
377 this_leaf->attributes = CACHE_WRITE_THROUGH; in update_cache_properties()
380 this_leaf->attributes = CACHE_WRITE_BACK; in update_cache_properties()
384 if (found_cache->flags & ACPI_PPTT_ALLOCATION_TYPE_VALID) { in update_cache_properties()
385 switch (found_cache->attributes & ACPI_PPTT_MASK_ALLOCATION_TYPE) { in update_cache_properties()
387 this_leaf->attributes |= CACHE_READ_ALLOCATE; in update_cache_properties()
390 this_leaf->attributes |= CACHE_WRITE_ALLOCATE; in update_cache_properties()
394 this_leaf->attributes |= in update_cache_properties()
400 * If cache type is NOCACHE, then the cache hasn't been specified in update_cache_properties()
401 * via other mechanisms. Update the type if a cache type has been in update_cache_properties()
409 if (this_leaf->type == CACHE_TYPE_NOCACHE && in update_cache_properties()
410 found_cache->flags & ACPI_PPTT_CACHE_TYPE_VALID) in update_cache_properties()
411 this_leaf->type = CACHE_TYPE_UNIFIED; in update_cache_properties()
413 if (revision >= 3 && (found_cache->flags & ACPI_PPTT_CACHE_ID_VALID)) { in update_cache_properties()
416 this_leaf->id = found_cache_v1->cache_id; in update_cache_properties()
417 this_leaf->attributes |= CACHE_ID; in update_cache_properties()
431 while (index < get_cpu_cacheinfo(cpu)->num_leaves) { in cache_setup_acpi_cpu()
432 this_leaf = this_cpu_ci->info_list + index; in cache_setup_acpi_cpu()
434 this_leaf->type, in cache_setup_acpi_cpu()
435 this_leaf->level, in cache_setup_acpi_cpu()
441 table->revision); in cache_setup_acpi_cpu()
453 if (table_hdr->revision < 2) in flag_identical()
457 if (cpu->flags & ACPI_PPTT_ACPI_IDENTICAL) { in flag_identical()
458 next = fetch_pptt_node(table_hdr, cpu->parent); in flag_identical()
459 if (!(next && next->flags & ACPI_PPTT_ACPI_IDENTICAL)) in flag_identical()
466 /* Passing level values greater than this will result in search termination */
471 int level, int flag) in acpi_find_processor_tag() argument
475 while (cpu && level) { in acpi_find_processor_tag()
480 } else if (cpu->flags & flag) in acpi_find_processor_tag()
482 pr_debug("level %d\n", level); in acpi_find_processor_tag()
483 prev_node = fetch_pptt_node(table_hdr, cpu->parent); in acpi_find_processor_tag()
487 level--; in acpi_find_processor_tag()
494 pr_warn_once("No PPTT table found, CPU and cache topology may be inaccurate\n"); in acpi_pptt_warn_missing()
498 * topology_get_acpi_cpu_tag() - Find a unique topology value for a feature
501 * @level: A level that terminates the search
504 * Get a unique value given a CPU, and a topology level, that can be
506 * at that level.
508 * Return: Unique value, or -ENOENT if unable to locate CPU
511 unsigned int cpu, int level, int flag) in topology_get_acpi_cpu_tag() argument
519 level, flag); in topology_get_acpi_cpu_tag()
526 if (level == 0 || in topology_get_acpi_cpu_tag()
527 cpu_node->flags & ACPI_PPTT_ACPI_PROCESSOR_ID_VALID) in topology_get_acpi_cpu_tag()
528 return cpu_node->acpi_processor_id; in topology_get_acpi_cpu_tag()
533 return -ENOENT; in topology_get_acpi_cpu_tag()
555 static int find_acpi_cpu_topology_tag(unsigned int cpu, int level, int flag) in find_acpi_cpu_topology_tag() argument
562 return -ENOENT; in find_acpi_cpu_topology_tag()
564 retval = topology_get_acpi_cpu_tag(table, cpu, level, flag); in find_acpi_cpu_topology_tag()
565 pr_debug("Topology Setup ACPI CPU %d, level %d ret = %d\n", in find_acpi_cpu_topology_tag()
566 cpu, level, retval); in find_acpi_cpu_topology_tag()
572 * check_acpi_cpu_flag() - Determine if CPU node has a flag set
579 * Return: -ENOENT if the PPTT doesn't exist, the CPU cannot be found or
589 int ret = -ENOENT; in check_acpi_cpu_flag()
593 return -ENOENT; in check_acpi_cpu_flag()
595 if (table->revision >= rev) in check_acpi_cpu_flag()
599 ret = (cpu_node->flags & flag) != 0; in check_acpi_cpu_flag()
605 * acpi_find_last_cache_level() - Determines the number of cache levels for a PE
608 * Given a logical CPU number, returns the number of levels of cache represented
610 * indicating we didn't find any cache levels.
612 * Return: Cache levels visible to this core.
622 return -ENOENT; in acpi_find_last_cache_level()
624 pr_debug("Cache Setup find last level CPU=%d\n", cpu); in acpi_find_last_cache_level()
628 pr_debug("Cache Setup find last level level=%d\n", number_of_levels); in acpi_find_last_cache_level()
634 * cache_setup_acpi() - Override CPU cache topology with data from the PPTT
637 * Updates the global cache info provided by cpu_get_cacheinfo()
640 * cache levels have any valid flags set. Further, a unique value is
641 * associated with each known CPU cache entry. This unique value
644 * Return: -ENOENT on failure to find table, or 0 on success
652 return -ENOENT; in cache_setup_acpi()
654 pr_debug("Cache Setup ACPI CPU %d\n", cpu); in cache_setup_acpi()
662 * acpi_pptt_cpu_is_thread() - Determine if CPU is a thread
667 * -ENOENT ,if the PPTT doesn't exist, the CPU cannot be found or
676 * find_acpi_cpu_topology() - Determine a unique topology value for a given CPU
678 * @level: The topological level for which we would like a unique ID
684 * The search terminates when either the requested level is found or
686 * same unique ID. The unique id for level 0 is the acpi processor id. All
690 * Return: -ENOENT if the PPTT doesn't exist, or the CPU cannot be found.
693 int find_acpi_cpu_topology(unsigned int cpu, int level) in find_acpi_cpu_topology() argument
695 return find_acpi_cpu_topology_tag(cpu, level, 0); in find_acpi_cpu_topology()
699 * find_acpi_cpu_topology_package() - Determine a unique CPU package value
705 * The search terminates when either a level is found with the PHYSICAL_PACKAGE
708 * Return: -ENOENT if the PPTT doesn't exist, or the CPU cannot be found.
718 * find_acpi_cpu_topology_cluster() - Determine a unique CPU cluster value
724 * The cluster, if present is the level of topology above CPUs. In a
725 * multi-thread CPU, it will be the level above the CPU, not the thread.
726 * It may not exist in single CPU systems. In simple multi-CPU systems,
727 * it may be equal to the package topology level.
729 * Return: -ENOENT if the PPTT doesn't exist, the CPU cannot be found
730 * or there is no toplogy level above the CPU..
744 return -ENOENT; in find_acpi_cpu_topology_cluster()
748 if (!cpu_node || !cpu_node->parent) in find_acpi_cpu_topology_cluster()
749 return -ENOENT; in find_acpi_cpu_topology_cluster()
751 is_thread = cpu_node->flags & ACPI_PPTT_ACPI_PROCESSOR_IS_THREAD; in find_acpi_cpu_topology_cluster()
752 cluster_node = fetch_pptt_node(table, cpu_node->parent); in find_acpi_cpu_topology_cluster()
754 return -ENOENT; in find_acpi_cpu_topology_cluster()
757 if (!cluster_node->parent) in find_acpi_cpu_topology_cluster()
758 return -ENOENT; in find_acpi_cpu_topology_cluster()
760 cluster_node = fetch_pptt_node(table, cluster_node->parent); in find_acpi_cpu_topology_cluster()
762 return -ENOENT; in find_acpi_cpu_topology_cluster()
764 if (cluster_node->flags & ACPI_PPTT_ACPI_PROCESSOR_ID_VALID) in find_acpi_cpu_topology_cluster()
765 retval = cluster_node->acpi_processor_id; in find_acpi_cpu_topology_cluster()
773 * find_acpi_cpu_topology_hetero_id() - Get a core architecture tag
781 * The search terminates when a level is found with the identical implementation
788 * Return: -ENOENT if the PPTT doesn't exist, or the CPU cannot be found.