To build cache information, An AcpiCacheInfo structure is defined to hold the type 1 cache structure according to ACPI spec v6.3 5.2.29.2. A helper function build_cache_hierarchy is also introduced to encode the cache information.
Signed-off-by: Ying Fang <fangyi...@huawei.com> --- hw/acpi/aml-build.c | 26 ++++++++++++++++++++++++++ include/hw/acpi/acpi-defs.h | 8 ++++++++ include/hw/acpi/aml-build.h | 3 +++ 3 files changed, 37 insertions(+) diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c index d1aa9fd716..1a38110149 100644 --- a/hw/acpi/aml-build.c +++ b/hw/acpi/aml-build.c @@ -1770,6 +1770,32 @@ void build_slit(GArray *table_data, BIOSLinker *linker, MachineState *ms) table_data->len - slit_start, 1, NULL, NULL); } +/* ACPI 6.3: 5.29.2 Cache type structure (Type 1) */ +static void build_cache_head(GArray *tbl, uint32_t next_level) +{ + build_append_byte(tbl, 1); + build_append_byte(tbl, 24); + build_append_int_noprefix(tbl, 0, 2); + build_append_int_noprefix(tbl, 0x7f, 4); + build_append_int_noprefix(tbl, next_level, 4); +} + +static void build_cache_tail(GArray *tbl, AcpiCacheInfo *cache_info) +{ + build_append_int_noprefix(tbl, cache_info->size, 4); + build_append_int_noprefix(tbl, cache_info->sets, 4); + build_append_byte(tbl, cache_info->associativity); + build_append_byte(tbl, cache_info->attributes); + build_append_int_noprefix(tbl, cache_info->line_size, 2); +} + +void build_cache_hierarchy(GArray *tbl, + uint32_t next_level, AcpiCacheInfo *cache_info) +{ + build_cache_head(tbl, next_level); + build_cache_tail(tbl, cache_info); +} + /* * ACPI 6.3: 5.2.29.1 Processor hierarchy node structure (Type 0) */ diff --git a/include/hw/acpi/acpi-defs.h b/include/hw/acpi/acpi-defs.h index 38a42f409a..3df38ab449 100644 --- a/include/hw/acpi/acpi-defs.h +++ b/include/hw/acpi/acpi-defs.h @@ -618,4 +618,12 @@ struct AcpiIortRC { } QEMU_PACKED; typedef struct AcpiIortRC AcpiIortRC; +typedef struct AcpiCacheInfo { + uint32_t size; + uint32_t sets; + uint8_t associativity; + uint8_t attributes; + uint16_t line_size; +} AcpiCacheInfo; + #endif diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h index 56474835a7..01078753a8 100644 --- a/include/hw/acpi/aml-build.h +++ b/include/hw/acpi/aml-build.h @@ -437,6 +437,9 @@ void build_srat_memory(AcpiSratMemoryAffinity *numamem, uint64_t base, void build_slit(GArray *table_data, BIOSLinker *linker, MachineState *ms); +void build_cache_hierarchy(GArray *tbl, + uint32_t next_level, AcpiCacheInfo *cache_info); + void build_socket_hierarchy(GArray *tbl, uint32_t parent, uint32_t id); void build_processor_hierarchy(GArray *tbl, uint32_t flags, -- 2.23.0