ACPI: tables: PPTT: Populate cache-id if provided by firmware
authorJames Morse <james.morse@arm.com>
Tue, 1 Jun 2021 12:17:35 +0000 (13:17 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 7 Jun 2021 13:55:02 +0000 (15:55 +0200)
ACPI 6.4 adds a 'cache id' to the PPTT Cache Type Structure.

Copy this property across into the cacheinfo leaf when it was
provided by firmware.

This value gets exposed to userspace as:
/sys/devices/system/cpu/cpu*/cache/index*/id.

See the "Cache IDs" section of Documentation/x86/resctrl.rst.

Co-authored-by: Joey Gouly <joey.gouly@arm.com>
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Joey Gouly <joey.gouly@arm.com>
[ rjw: Subject and changelog edits ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/acpi/pptt.c

index 4ae9335..fe69dc5 100644 (file)
@@ -347,6 +347,7 @@ static struct acpi_pptt_cache *acpi_find_cache_node(struct acpi_table_header *ta
  * @this_leaf: Kernel cache info structure being updated
  * @found_cache: The PPTT node describing this cache instance
  * @cpu_node: A unique reference to describe this cache instance
+ * @revision: The revision of the PPTT table
  *
  * The ACPI spec implies that the fields in the cache structures are used to
  * extend and correct the information probed from the hardware. Lets only
@@ -356,8 +357,11 @@ static struct acpi_pptt_cache *acpi_find_cache_node(struct acpi_table_header *ta
  */
 static void update_cache_properties(struct cacheinfo *this_leaf,
                                    struct acpi_pptt_cache *found_cache,
-                                   struct acpi_pptt_processor *cpu_node)
+                                   struct acpi_pptt_processor *cpu_node,
+                                   u8 revision)
 {
+       struct acpi_pptt_cache_v1* found_cache_v1;
+
        this_leaf->fw_token = cpu_node;
        if (found_cache->flags & ACPI_PPTT_SIZE_PROPERTY_VALID)
                this_leaf->size = found_cache->size;
@@ -405,6 +409,13 @@ static void update_cache_properties(struct cacheinfo *this_leaf,
        if (this_leaf->type == CACHE_TYPE_NOCACHE &&
            found_cache->flags & ACPI_PPTT_CACHE_TYPE_VALID)
                this_leaf->type = CACHE_TYPE_UNIFIED;
+
+       if (revision >= 3 && (found_cache->flags & ACPI_PPTT_CACHE_ID_VALID)) {
+               found_cache_v1 = ACPI_ADD_PTR(struct acpi_pptt_cache_v1,
+                                             found_cache, sizeof(struct acpi_pptt_cache));
+               this_leaf->id = found_cache_v1->cache_id;
+               this_leaf->attributes |= CACHE_ID;
+       }
 }
 
 static void cache_setup_acpi_cpu(struct acpi_table_header *table,
@@ -425,9 +436,8 @@ static void cache_setup_acpi_cpu(struct acpi_table_header *table,
                                                   &cpu_node);
                pr_debug("found = %p %p\n", found_cache, cpu_node);
                if (found_cache)
-                       update_cache_properties(this_leaf,
-                                               found_cache,
-                                               cpu_node);
+                       update_cache_properties(this_leaf, found_cache,
+                                               cpu_node, table->revision);
 
                index++;
        }