From nobody Thu Nov 28 12:54:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1691495888; cv=none; d=zohomail.com; s=zohoarc; b=SbCYN4g6FQfxlG/M+84YKGwriaOIyiMiKPeWw6dlHU+I1wHwNRAZZR4Gxuth+7sfSRqrxWujhsZCF0k4hKS2gJVaBw6cklt5ASscrZVqRf+c8FAV7NShmZPn5TPRN0A6NifdjMLvZwRD1e9+ty6fJq+2iqCxquD14T8MKA5IQDU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691495888; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=KSmZtiHoXj0fPGC7TVY1TyJIu6083yk5gIVLleSH8jM=; b=UVg0/z4P45zr1ZzNG8cewwYodKJoYEFGgHTeRAqhOG7vOJ+TPXJzz2l//C+jK7kfRQhzWVza1WnybPpBejCwdOwwRJF1PFfrNQDLjGYn+0Ld8wwsz234j99A2IFcu5lHiWo07APLN92lnRZ6kbF/C9tsi3J6/W9bOm3WytI2s6A= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691495888931211.2514255475346; Tue, 8 Aug 2023 04:58:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qTLLc-0001r0-7U; Tue, 08 Aug 2023 07:58:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qTLLR-0001j6-BL for qemu-devel@nongnu.org; Tue, 08 Aug 2023 07:57:50 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qTLLN-0001S0-7k for qemu-devel@nongnu.org; Tue, 08 Aug 2023 07:57:48 -0400 Received: from lhrpeml500005.china.huawei.com (unknown [172.18.147.207]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4RKs6B4l5Vz67mnJ; Tue, 8 Aug 2023 19:53:54 +0800 (CST) Received: from SecurePC-101-06.china.huawei.com (10.122.247.231) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 8 Aug 2023 12:57:42 +0100 To: CC: Gavin Shan , , James Morse , "peter . maydell @ linaro . org" , , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Shameerali Kolothum Thodi , Yicong Yang Subject: [RFC PATCH 1/5] hw/acpi: Add PPTT cache descriptions Date: Tue, 8 Aug 2023 12:57:09 +0100 Message-ID: <20230808115713.2613-2-Jonathan.Cameron@huawei.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230808115713.2613-1-Jonathan.Cameron@huawei.com> References: <20230808115713.2613-1-Jonathan.Cameron@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.122.247.231] X-ClientProxiedBy: lhrpeml500001.china.huawei.com (7.191.163.213) To lhrpeml500005.china.huawei.com (7.191.163.240) X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=185.176.79.56; envelope-from=jonathan.cameron@huawei.com; helo=frasgout.his.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Jonathan Cameron From: Jonathan Cameron via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1691495890929100003 Content-Type: text/plain; charset="utf-8" Current PPTT tables generated by QEMU only provide information on CPU topology and neglect the description of Caches. This patch adds flexible definition of those caches and updates the table version to 3 to allow for the per CPU cache instance IDs needed for cross references from the MPAM table. If MPAM is not being used, then a unified description can be used, greatly reducing the resulting table size. New machine parameters are used to control the cache toplogy. cache-cluster-start-level: Which caches are associated with the cluster level of the topology. e.g cache-cluster-start-level=3D2 results in shared l2 cache across a cluster. cache-numa-start-level: Which caches are associate with the NUMA (in qemu this is currently the physical package level). For example cache-cluster-start-level=3D2,cache-numa-start-level=3D3 gives private l1, cluster shared l2 and package shared L3. FIXME: Test updates. Signed-off-by: Jonathan Cameron --- qapi/machine.json | 8 +- include/hw/acpi/aml-build.h | 19 +++- include/hw/boards.h | 4 + hw/acpi/aml-build.c | 189 ++++++++++++++++++++++++++++++++++-- hw/arm/virt-acpi-build.c | 130 ++++++++++++++++++++++++- hw/core/machine-smp.c | 8 ++ hw/loongarch/acpi-build.c | 2 +- 7 files changed, 350 insertions(+), 10 deletions(-) diff --git a/qapi/machine.json b/qapi/machine.json index a08b6576ca..cc86784641 100644 --- a/qapi/machine.json +++ b/qapi/machine.json @@ -1494,6 +1494,10 @@ # @maxcpus: maximum number of hotpluggable virtual CPUs in the virtual # machine # +# @cache-cluster-start-level: Level of first cache attached to cluster +# +# @cache-node-start-level: Level of first cache attached to cluster +# # Since: 6.1 ## { 'struct': 'SMPConfiguration', 'data': { @@ -1503,7 +1507,9 @@ '*clusters': 'int', '*cores': 'int', '*threads': 'int', - '*maxcpus': 'int' } } + '*maxcpus': 'int', + '*cache-cluster-start-level': 'int', + '*cache-node-start-level': 'int'} } =20 ## # @x-query-irq: diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h index d1fb08514b..055b74820d 100644 --- a/include/hw/acpi/aml-build.h +++ b/include/hw/acpi/aml-build.h @@ -489,8 +489,25 @@ void build_srat_memory(GArray *table_data, uint64_t ba= se, void build_slit(GArray *table_data, BIOSLinker *linker, MachineState *ms, const char *oem_id, const char *oem_table_id); =20 +typedef enum ACPIPPTTCacheType { + DATA, + INSTRUCTION, + UNIFIED, +} ACPIPPTTCacheType; + +typedef struct ACPIPPTTCache { + ACPIPPTTCacheType type; + int sets; + int size; + int associativity; + int linesize; + unsigned int pptt_id; + int level; +} ACPIPPTTCache; + void build_pptt(GArray *table_data, BIOSLinker *linker, MachineState *ms, - const char *oem_id, const char *oem_table_id); + const char *oem_id, const char *oem_table_id, + int num_caches, ACPIPPTTCache *caches); =20 void build_fadt(GArray *tbl, BIOSLinker *linker, const AcpiFadtData *f, const char *oem_id, const char *oem_table_id); diff --git a/include/hw/boards.h b/include/hw/boards.h index ed83360198..6e8ab92684 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -316,6 +316,8 @@ typedef struct DeviceMemoryState { * @cores: the number of cores in one cluster * @threads: the number of threads in one core * @max_cpus: the maximum number of logical processors on the machine + * @cache_cluster_start_level: First cache level attached to cluster + * @cache_node_start_level: First cache level attached to node */ typedef struct CpuTopology { unsigned int cpus; @@ -325,6 +327,8 @@ typedef struct CpuTopology { unsigned int cores; unsigned int threads; unsigned int max_cpus; + unsigned int cache_cluster_start_level; + unsigned int cache_node_start_level; } CpuTopology; =20 /** diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c index ea331a20d1..e103cd638f 100644 --- a/hw/acpi/aml-build.c +++ b/hw/acpi/aml-build.c @@ -1994,32 +1994,175 @@ static void build_processor_hierarchy_node(GArray = *tbl, uint32_t flags, } } =20 +static void build_cache_nodes(GArray *tbl, ACPIPPTTCache *cache, + uint32_t next_offset, + bool has_id, unsigned int id) +{ + int val; + + /* Type 1 - cache */ + build_append_byte(tbl, 1); + /* Length */ + build_append_byte(tbl, 28); + /* Reserved */ + build_append_int_noprefix(tbl, 0, 2); + /* Flags - everything except possibly the ID */ + build_append_int_noprefix(tbl, has_id ? 0xff : 0x7f, 4); + /* Offset of next cache up */ + build_append_int_noprefix(tbl, next_offset, 4); + build_append_int_noprefix(tbl, cache->size, 4); + build_append_int_noprefix(tbl, cache->sets, 4); + build_append_byte(tbl, cache->associativity); + /* Read and Write allocate amd WB */ + val =3D 0x3 | (1 << 4); + switch (cache->type) { + case INSTRUCTION: + val |=3D (1 << 2); + break; + case DATA: + val |=3D (0 << 2); /* Data */ + break; + case UNIFIED: + val |=3D (3 << 2); /* Unified */ + break; + } + build_append_byte(tbl, val); + build_append_int_noprefix(tbl, cache->linesize, 2); + build_append_int_noprefix(tbl, + has_id ? + (cache->type << 24) | (cache->level << 16) |= id : + 0, 4); +} + +static void build_caches_subset(GArray *table_data, uint32_t pptt_start, + int num_caches, ACPIPPTTCache *caches, + bool assign_ids, int base_id, + uint8_t level_high, uint8_t level_low, + uint32_t *data_offset, uint32_t *instr_off= set) +{ + uint32_t next_level_offset_data =3D 0, next_level_offset_instruction = =3D 0; + uint32_t this_offset, next_offset =3D 0; + int c, l; + + /* Walk caches from top to bottom */ + + for (l =3D level_high; l >=3D level_low; l--) { /* Walk down levels */ + for (c =3D 0; c < num_caches; c++) { + if (caches[c].level !=3D l) { + continue; + } + + /* Assume only unified above l1 for now */ + this_offset =3D table_data->len - pptt_start; + switch (caches[c].type) { + case INSTRUCTION: + next_offset =3D next_level_offset_instruction; + break; + case DATA: + next_offset =3D next_level_offset_data; + break; + case UNIFIED: + /* Either is fine here - hopefully */ + next_offset =3D next_level_offset_instruction; + break; + } + build_cache_nodes(table_data, &caches[c], next_offset, + assign_ids, base_id); + switch (caches[c].type) { + case INSTRUCTION: + next_level_offset_instruction =3D this_offset; + break; + case DATA: + next_level_offset_data =3D this_offset; + break; + case UNIFIED: + next_level_offset_instruction =3D this_offset; + next_level_offset_data =3D this_offset; + break; + } + *data_offset =3D next_level_offset_data; + *instr_offset =3D next_level_offset_instruction; + } + } +} + /* * ACPI spec, Revision 6.3 * 5.2.29 Processor Properties Topology Table (PPTT) */ void build_pptt(GArray *table_data, BIOSLinker *linker, MachineState *ms, - const char *oem_id, const char *oem_table_id) + const char *oem_id, const char *oem_table_id, + int num_caches, ACPIPPTTCache *caches) { + bool share_structs =3D false; MachineClass *mc =3D MACHINE_GET_CLASS(ms); CPUArchIdList *cpus =3D ms->possible_cpus; int64_t socket_id =3D -1, cluster_id =3D -1, core_id =3D -1; uint32_t socket_offset =3D 0, cluster_offset =3D 0, core_offset =3D 0; uint32_t pptt_start =3D table_data->len; int n; - AcpiTable table =3D { .sig =3D "PPTT", .rev =3D 2, + AcpiTable table =3D { .sig =3D "PPTT", .rev =3D 3, .oem_id =3D oem_id, .oem_table_id =3D oem_table_id= }; + uint32_t l1_data_offset =3D 0; + uint32_t l1_instr_offset =3D 0; + uint32_t cluster_data_offset =3D 0; + uint32_t cluster_instr_offset =3D 0; + uint32_t node_data_offset =3D 0; + uint32_t node_instr_offset =3D 0; + int top_node =3D 7; + int top_cluster =3D 7; + int top_core =3D 7; =20 acpi_table_begin(&table, table_data); =20 + /* Let us have a unified cache description for now */ + + if (share_structs && num_caches >=3D 1) { + if (ms->smp.cache_node_start_level) { + build_caches_subset(table_data, pptt_start, num_caches, caches, + false, 0, + top_node, ms->smp.cache_node_start_level, + &node_data_offset, &node_instr_offset); + top_cluster =3D ms->smp.cache_node_start_level - 1; + } + /* Assumption that some caches below this */ + if (ms->smp.cache_cluster_start_level) { + build_caches_subset(table_data, pptt_start, num_caches, caches, + false, 0, + top_cluster, ms->smp.cache_cluster_start_= level, + &cluster_data_offset, &cluster_instr_offse= t); + top_core =3D ms->smp.cache_cluster_start_level - 1; + } + build_caches_subset(table_data, pptt_start, num_caches, caches, + false, 0, + top_core , 0, + &l1_data_offset, &l1_instr_offset); + } + /* * This works with the assumption that cpus[n].props.*_id has been * sorted from top to down levels in mc->possible_cpu_arch_ids(). * Otherwise, the unexpected and duplicated containers will be * created. */ + for (n =3D 0; n < cpus->len; n++) { if (cpus->cpus[n].props.socket_id !=3D socket_id) { + uint32_t priv_rsrc[2]; + int num_priv =3D 0; + + if (!share_structs && ms->smp.cache_node_start_level) { + build_caches_subset(table_data, pptt_start, num_caches, ca= ches, + true, n, + top_node, ms->smp.cache_node_start_lev= el, + &node_data_offset, &node_instr_offset); + top_cluster =3D ms->smp.cache_node_start_level - 1; + } + priv_rsrc[0] =3D node_instr_offset; + priv_rsrc[1] =3D node_data_offset; + if (node_instr_offset || node_data_offset) { + num_priv =3D node_instr_offset =3D=3D node_data_offset ? 1= : 2; + } assert(cpus->cpus[n].props.socket_id > socket_id); socket_id =3D cpus->cpus[n].props.socket_id; cluster_id =3D -1; @@ -2027,36 +2170,70 @@ void build_pptt(GArray *table_data, BIOSLinker *lin= ker, MachineState *ms, socket_offset =3D table_data->len - pptt_start; build_processor_hierarchy_node(table_data, (1 << 0), /* Physical package */ - 0, socket_id, NULL, 0); + 0, socket_id, priv_rsrc, num_priv); } =20 + if (mc->smp_props.clusters_supported && mc->smp_props.has_clusters= ) { if (cpus->cpus[n].props.cluster_id !=3D cluster_id) { + uint32_t priv_rsrc[2]; + int num_priv =3D 0; + + if (!share_structs && ms->smp.cache_cluster_start_level) { + build_caches_subset(table_data, pptt_start, num_caches, + caches, true, n, + top_cluster, + ms->smp.cache_cluster_start_level, + &cluster_data_offset, + &cluster_instr_offset); + top_core =3D ms->smp.cache_cluster_start_level - 1; + } + priv_rsrc[0] =3D cluster_instr_offset; + priv_rsrc[1] =3D cluster_data_offset; + assert(cpus->cpus[n].props.cluster_id > cluster_id); cluster_id =3D cpus->cpus[n].props.cluster_id; core_id =3D -1; cluster_offset =3D table_data->len - pptt_start; + + if (cluster_instr_offset || cluster_data_offset) { + num_priv =3D cluster_instr_offset =3D=3D cluster_data_= offset ? + 1 : 2; + } build_processor_hierarchy_node(table_data, (0 << 0), /* Not a physical package */ - socket_offset, cluster_id, NULL, 0); + socket_offset, cluster_id, priv_rsrc, num_priv); } } else { cluster_offset =3D socket_offset; } =20 + if (!share_structs && + cpus->cpus[n].props.core_id !=3D core_id) { + build_caches_subset(table_data, pptt_start, num_caches, caches, + true, n, + top_core , 0, + &l1_data_offset, &l1_instr_offset); + } if (ms->smp.threads =3D=3D 1) { + uint32_t priv_rsrc[2] =3D { l1_instr_offset, l1_data_offset }; + build_processor_hierarchy_node(table_data, (1 << 1) | /* ACPI Processor ID valid */ (1 << 3), /* Node is a Leaf */ - cluster_offset, n, NULL, 0); + cluster_offset, n, priv_rsrc, + l1_instr_offset =3D=3D l1_data_offset ? 1 : 2); } else { if (cpus->cpus[n].props.core_id !=3D core_id) { + uint32_t priv_rsrc[2] =3D { l1_instr_offset, l1_data_offse= t }; + assert(cpus->cpus[n].props.core_id > core_id); core_id =3D cpus->cpus[n].props.core_id; core_offset =3D table_data->len - pptt_start; build_processor_hierarchy_node(table_data, (0 << 0), /* Not a physical package */ - cluster_offset, core_id, NULL, 0); + cluster_offset, core_id, priv_rsrc, + l1_instr_offset =3D=3D l1_data_offset ? 1 : 2); } =20 build_processor_hierarchy_node(table_data, diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c index 6b674231c2..ec8fdcefff 100644 --- a/hw/arm/virt-acpi-build.c +++ b/hw/arm/virt-acpi-build.c @@ -922,6 +922,129 @@ static void acpi_align_size(GArray *blob, unsigned al= ign) g_array_set_size(blob, ROUND_UP(acpi_data_len(blob), align)); } =20 +static unsigned int virt_get_caches(VirtMachineState *vms, + ACPIPPTTCache *caches) +{ + ARMCPU *armcpu =3D ARM_CPU(qemu_get_cpu(0)); + bool ccidx =3D cpu_isar_feature(any_ccidx, armcpu); + unsigned int num_cache, i; + int level_instr =3D 1, level_data =3D 1; + + for (i =3D 0, num_cache =3D 0; i < 7; i++, num_cache++) { + int type =3D (armcpu->clidr >> (3 * i)) & 7; + int bank_index; + int level =3D 0; + ACPIPPTTCacheType cache_type =3D INSTRUCTION; + + if (type =3D=3D 0) { + break; + } + + switch (type) { + case 1: + cache_type =3D INSTRUCTION; + level =3D level_instr; + break; + case 2: + cache_type =3D DATA; + level =3D level_data; + break; + case 4: + cache_type =3D UNIFIED; + level =3D level_instr > level_data ? level_instr : level_data; + break; + case 3: /* Split - Do data first */ + cache_type =3D DATA; + level =3D level_data; + break; + } + /* + * ccsidr is indexed using both the level and whether it is + * an instruction cache. Unified caches use the same storage + * as data caches. + */ + bank_index =3D (i * 2) | ((type =3D=3D 1) ? 1 : 0); + if (ccidx) { + caches[num_cache] =3D (ACPIPPTTCache) { + .type =3D cache_type, + .level =3D level, + .linesize =3D 1 << (FIELD_EX64(armcpu->ccsidr[bank_index], + CCSIDR_EL1, + CCIDX_LINESIZE) + 4), + .associativity =3D FIELD_EX64(armcpu->ccsidr[bank_index], + CCSIDR_EL1, + CCIDX_ASSOCIATIVITY) + 1, + .sets =3D FIELD_EX64(armcpu->ccsidr[bank_index], CCSIDR_EL= 1, + CCIDX_NUMSETS) + 1, + }; + } else { + caches[num_cache] =3D (ACPIPPTTCache) { + .type =3D cache_type, + .level =3D level, + .linesize =3D 1 << (FIELD_EX64(armcpu->ccsidr[bank_index], + CCSIDR_EL1, LINESIZE) + 4), + .associativity =3D FIELD_EX64(armcpu->ccsidr[bank_index], + CCSIDR_EL1, + ASSOCIATIVITY) + 1, + .sets =3D FIELD_EX64(armcpu->ccsidr[bank_index], CCSIDR_EL= 1, + NUMSETS) + 1, + }; + } + caches[num_cache].size =3D caches[num_cache].associativity * + caches[num_cache].sets * caches[num_cache].linesize; + + /* Break one 'split' entry up into two records */ + if (type =3D=3D 3) { + num_cache++; + bank_index =3D (i * 2) | 1; + if (ccidx) { + /* Instruction cache: bottom bit set when reading banked r= eg */ + caches[num_cache] =3D (ACPIPPTTCache) { + .type =3D INSTRUCTION, + .level =3D level_instr, + .linesize =3D 1 << (FIELD_EX64(armcpu->ccsidr[bank_ind= ex], + CCSIDR_EL1, + CCIDX_LINESIZE) + 4), + .associativity =3D FIELD_EX64(armcpu->ccsidr[bank_inde= x], + CCSIDR_EL1, + CCIDX_ASSOCIATIVITY) + 1, + .sets =3D FIELD_EX64(armcpu->ccsidr[bank_index], CCSID= R_EL1, + CCIDX_NUMSETS) + 1, + }; + } else { + caches[num_cache] =3D (ACPIPPTTCache) { + .type =3D INSTRUCTION, + .level =3D level_instr, + .linesize =3D 1 << (FIELD_EX64(armcpu->ccsidr[bank_ind= ex], + CCSIDR_EL1, LINESIZE) + 4= ), + .associativity =3D FIELD_EX64(armcpu->ccsidr[bank_inde= x], + CCSIDR_EL1, + ASSOCIATIVITY) + 1, + .sets =3D FIELD_EX64(armcpu->ccsidr[bank_index], CCSID= R_EL1, + NUMSETS) + 1, + }; + } + caches[num_cache].size =3D caches[num_cache].associativity * + caches[num_cache].sets * caches[num_cache].linesize; + } + switch (type) { + case 1: + level_instr++; + break; + case 2: + level_data++; + break; + case 3: + case 4: + level_instr++; + level_data++; + break; + } + } + + return num_cache; +} + static void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables) { @@ -930,6 +1053,8 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildT= ables *tables) unsigned dsdt, xsdt; GArray *tables_blob =3D tables->table_data; MachineState *ms =3D MACHINE(vms); + ACPIPPTTCache caches[16]; /* Can select up to 16 */ + unsigned int num_cache; =20 table_offsets =3D g_array_new(false, true /* clear */, sizeof(uint32_t)); @@ -949,10 +1074,13 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuil= dTables *tables) acpi_add_table(table_offsets, tables_blob); build_madt(tables_blob, tables->linker, vms); =20 + num_cache =3D virt_get_caches(vms, caches); + if (!vmc->no_cpu_topology) { acpi_add_table(table_offsets, tables_blob); build_pptt(tables_blob, tables->linker, ms, - vms->oem_id, vms->oem_table_id); + vms->oem_id, vms->oem_table_id, + num_cache, caches); } =20 acpi_add_table(table_offsets, tables_blob); diff --git a/hw/core/machine-smp.c b/hw/core/machine-smp.c index 0f4d9b6f7a..cbb0bf1bc7 100644 --- a/hw/core/machine-smp.c +++ b/hw/core/machine-smp.c @@ -81,6 +81,10 @@ void machine_parse_smp_config(MachineState *ms, unsigned cores =3D config->has_cores ? config->cores : 0; unsigned threads =3D config->has_threads ? config->threads : 0; unsigned maxcpus =3D config->has_maxcpus ? config->maxcpus : 0; + unsigned cache_cl_start =3D config->has_cache_cluster_start_level ? + config->cache_cluster_start_level : 0; + unsigned cache_nd_start =3D config->has_cache_node_start_level ? + config->cache_node_start_level : 0; =20 /* * Specified CPU topology parameters must be greater than zero, @@ -161,6 +165,10 @@ void machine_parse_smp_config(MachineState *ms, ms->smp.max_cpus =3D maxcpus; =20 mc->smp_props.has_clusters =3D config->has_clusters; + if (mc->smp_props.has_clusters) { + ms->smp.cache_cluster_start_level =3D cache_cl_start; + ms->smp.cache_node_start_level =3D cache_nd_start; + } =20 /* sanity-check of the computed topology */ if (sockets * dies * clusters * cores * threads !=3D maxcpus) { diff --git a/hw/loongarch/acpi-build.c b/hw/loongarch/acpi-build.c index 0b62c3a2f7..51d4ed9a19 100644 --- a/hw/loongarch/acpi-build.c +++ b/hw/loongarch/acpi-build.c @@ -439,7 +439,7 @@ static void acpi_build(AcpiBuildTables *tables, Machine= State *machine) =20 acpi_add_table(table_offsets, tables_blob); build_pptt(tables_blob, tables->linker, machine, - lams->oem_id, lams->oem_table_id); + lams->oem_id, lams->oem_table_id, 0, NULL); =20 acpi_add_table(table_offsets, tables_blob); build_srat(tables_blob, tables->linker, machine); --=20 2.39.2 From nobody Thu Nov 28 12:54:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1691495914; cv=none; d=zohomail.com; s=zohoarc; b=kApggt69Zd4xOIelX4wIl8VRi2USMBzyGyxTWTVMzx03ATOZkrY3C4vSuE7bSpY1maB93jEKp/cTZnIApr6NHqBadgnnvYcavxv+K21haueaZ1YriO95/FrGaSUxasChqgcGiJRfRzYJ1wkhjBZPV0sXfdNJHBPsqQ47Li+RrIE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691495914; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=6gTZNNsVw+Urfz/iMybsZ6/L8+yRH17hs8uhDdeJpag=; b=SUIaGnTW/ruA+80bI8mS3NFj0wzvPko6++V79c88RgpNEZPZ98mNx0t2I3/QwVRPOPGMULuTXzTDcDITQ+vo7u2t9QRFrG37du54c/08BbzxSk/1Five/Vy2vmKtBkeVLqrJpuip0eEtJNqRcCi9epJmJVVJqB/aBZM5aDLByy0= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691495914775731.5964960093378; Tue, 8 Aug 2023 04:58:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qTLLu-0002iO-Uv; Tue, 08 Aug 2023 07:58:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qTLLt-0002cd-Q7 for qemu-devel@nongnu.org; Tue, 08 Aug 2023 07:58:17 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qTLLr-0001XR-VI for qemu-devel@nongnu.org; Tue, 08 Aug 2023 07:58:17 -0400 Received: from lhrpeml500005.china.huawei.com (unknown [172.18.147.207]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4RKs6p024nz67bhy; Tue, 8 Aug 2023 19:54:25 +0800 (CST) Received: from SecurePC-101-06.china.huawei.com (10.122.247.231) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 8 Aug 2023 12:58:13 +0100 To: CC: Gavin Shan , , James Morse , "peter . maydell @ linaro . org" , , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Shameerali Kolothum Thodi , Yicong Yang Subject: [RFC PATCH 2/5] HACK: target/arm/tcg: Add some more caches to cpu=max Date: Tue, 8 Aug 2023 12:57:10 +0100 Message-ID: <20230808115713.2613-3-Jonathan.Cameron@huawei.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230808115713.2613-1-Jonathan.Cameron@huawei.com> References: <20230808115713.2613-1-Jonathan.Cameron@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.122.247.231] X-ClientProxiedBy: lhrpeml500001.china.huawei.com (7.191.163.213) To lhrpeml500005.china.huawei.com (7.191.163.240) X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=185.176.79.56; envelope-from=jonathan.cameron@huawei.com; helo=frasgout.his.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Jonathan Cameron From: Jonathan Cameron via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1691495916782100001 Content-Type: text/plain; charset="utf-8" Used to drive the MPAM cache intialization and to exercise more of the PPTT cache entry generation code. Perhaps a default L3 cache is acceptable for max? Signed-off-by: Jonathan Cameron --- target/arm/tcg/cpu64.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/target/arm/tcg/cpu64.c b/target/arm/tcg/cpu64.c index 8019f00bc3..2af67739f6 100644 --- a/target/arm/tcg/cpu64.c +++ b/target/arm/tcg/cpu64.c @@ -711,6 +711,17 @@ void aarch64_max_tcg_initfn(Object *obj) uint64_t t; uint32_t u; =20 + /* + * Expanded cache set + */ + cpu->clidr =3D 0x8204923; /* 4 4 4 4 3 in 3 bit fields */ + cpu->ccsidr[0] =3D 0x000000ff0000001aull; /* 64KB L1 dcache */ + cpu->ccsidr[1] =3D 0x000000ff0000001aull; /* 64KB L1 icache */ + cpu->ccsidr[2] =3D 0x000007ff0000003aull; /* 1MB L2 unified cache */ + cpu->ccsidr[4] =3D 0x000007ff0000007cull; /* 2MB L3 cache 128B line */ + cpu->ccsidr[6] =3D 0x00007fff0000007cull; /* 16MB L4 cache 128B line */ + cpu->ccsidr[8] =3D 0x0007ffff0000007cull; /* 2048MB L5 cache 128B line= */ + /* * Reset MIDR so the guest doesn't mistake our 'max' CPU type for a re= al * one and try to apply errata workarounds or use impdef features we @@ -828,6 +839,7 @@ void aarch64_max_tcg_initfn(Object *obj) t =3D FIELD_DP64(t, ID_AA64MMFR2, BBM, 2); /* FEAT_BBM at level 2= */ t =3D FIELD_DP64(t, ID_AA64MMFR2, EVT, 2); /* FEAT_EVT */ t =3D FIELD_DP64(t, ID_AA64MMFR2, E0PD, 1); /* FEAT_E0PD */ + t =3D FIELD_DP64(t, ID_AA64MMFR2, CCIDX, 1); /* FEAT_TTCNP */ cpu->isar.id_aa64mmfr2 =3D t; =20 t =3D cpu->isar.id_aa64zfr0; --=20 2.39.2 From nobody Thu Nov 28 12:54:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1691495949; cv=none; d=zohomail.com; s=zohoarc; b=DSDFSdxe/+gX7fRuL8l1hqQLWBL5BWEtLOCvYSOuA2hnWwymNmhkDmg1PC92LoegNhx5pM/Kc9jMU8ZjPJFDkc+ASMDLktUh9CqHaO2Jwhh1cVbpA3G2G6qgerkCuQQx6ewxUIuYlH6XqE9Mde0VTaaTmHiMPpj3yLZje3i7njM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691495949; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=aXNM7Bbpy584Guza8Z0OO15OY7gYPWKGQtcOBUAfHkM=; b=Dy8K9beFr4CmSzTVCyrPgIdPTuNuqrz91mM3RBVQgjUTzLLbxcZl+WsWiaF2kQiJbddUdwhBDFYbQBCuxjdQDnraI5E9LdwNhjPhw2Ul0Ds3ltfhMxEjmmJUjmmim3qfj5pqr82eQr4X/7Tj8eAZR12FgHlQfYFq8AODnpTXK2A= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691495949164635.8312992459133; Tue, 8 Aug 2023 04:59:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qTLMR-0003ql-FO; Tue, 08 Aug 2023 07:58:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qTLMO-0003q0-MY for qemu-devel@nongnu.org; Tue, 08 Aug 2023 07:58:48 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qTLMM-0001bh-Ex for qemu-devel@nongnu.org; Tue, 08 Aug 2023 07:58:48 -0400 Received: from lhrpeml500005.china.huawei.com (unknown [172.18.147.206]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4RKs7Z4sKFz6J6mV; Tue, 8 Aug 2023 19:55:06 +0800 (CST) Received: from SecurePC-101-06.china.huawei.com (10.122.247.231) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 8 Aug 2023 12:58:44 +0100 To: CC: Gavin Shan , , James Morse , "peter . maydell @ linaro . org" , , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Shameerali Kolothum Thodi , Yicong Yang Subject: [RFC PATCH 3/5] target/arm: Add support for MPAM CPU registers Date: Tue, 8 Aug 2023 12:57:11 +0100 Message-ID: <20230808115713.2613-4-Jonathan.Cameron@huawei.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230808115713.2613-1-Jonathan.Cameron@huawei.com> References: <20230808115713.2613-1-Jonathan.Cameron@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.122.247.231] X-ClientProxiedBy: lhrpeml500001.china.huawei.com (7.191.163.213) To lhrpeml500005.china.huawei.com (7.191.163.240) X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=185.176.79.56; envelope-from=jonathan.cameron@huawei.com; helo=frasgout.his.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Jonathan Cameron From: Jonathan Cameron via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1691495950993100003 Content-Type: text/plain; charset="utf-8" It is common to support MPAM on CPU cores, but not in the rest of the system, so there is little disadvantage in always enabling these. Signed-off-by: Jonathan Cameron --- target/arm/cpu.h | 15 +++++++++++++++ target/arm/cpu.c | 10 +++++++++- target/arm/helper.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 88e5accda6..8d28e22291 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -735,6 +735,10 @@ typedef struct CPUArchState { * to keep the offsets into the rest of the structure smaller. */ ARMVectorReg zarray[ARM_MAX_VQ * 16]; + + uint64_t mpam0_el1; + uint64_t mpam1_el1; + #endif =20 struct CPUBreakpoint *cpu_breakpoint[16]; @@ -1043,6 +1047,7 @@ struct ArchCPU { uint64_t id_aa64zfr0; uint64_t id_aa64smfr0; uint64_t reset_pmcr_el0; + uint64_t mpamidr_el1; } isar; uint64_t midr; uint32_t revidr; @@ -2327,6 +2332,16 @@ FIELD(DBGDEVID, DOUBLELOCK, 20, 4) FIELD(DBGDEVID, AUXREGS, 24, 4) FIELD(DBGDEVID, CIDMASK, 28, 4) =20 +FIELD(MPAMIDR, PARTID_MAX, 0, 16) +FIELD(MPAMIDR, HAS_HCR, 17, 1) +FIELD(MPAMIDR, VMR_MAX, 18, 3) +FIELD(MPAMIDR, PMG_MAX, 32, 8) +FIELD(MPAMIDR, HAS_ALTSP, 57, 1) +FIELD(MPAMIDR, HAS_TIDR, 58, 1) +FIELD(MPAMIDR, SP4, 59, 1) +FIELD(MPAMIDR, HAS_FORCE_NS, 60, 1) +FIELD(MPAMIDR, HAS_SDEFLT, 61, 1) + FIELD(MVFR0, SIMDREG, 0, 4) FIELD(MVFR0, FPSP, 4, 4) FIELD(MVFR0, FPDP, 8, 4) diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 93c28d50e5..d85a3ec8a2 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -305,6 +305,9 @@ static void arm_cpu_reset_hold(Object *obj) env->cp15.rvbar =3D cpu->rvbar_prop; env->pc =3D env->cp15.rvbar; #endif + + env->mpam1_el1 =3D 1ULL << 63; + } else { #if defined(CONFIG_USER_ONLY) /* Userspace expects access to cp10 and cp11 for FP/Neon */ @@ -2097,7 +2100,12 @@ static void arm_cpu_realizefn(DeviceState *dev, Erro= r **errp) FIELD_DP32(cpu->isar.id_pfr0, ID_PFR0, AMU, 0); /* FEAT_MPAM (Memory Partitioning and Monitoring Extension) */ cpu->isar.id_aa64pfr0 =3D - FIELD_DP64(cpu->isar.id_aa64pfr0, ID_AA64PFR0, MPAM, 0); + FIELD_DP64(cpu->isar.id_aa64pfr0, ID_AA64PFR0, MPAM, 1); + cpu->isar.mpamidr_el1 =3D + FIELD_DP64(cpu->isar.mpamidr_el1, MPAMIDR, PARTID_MAX, 63); + cpu->isar.mpamidr_el1 =3D + FIELD_DP64(cpu->isar.mpamidr_el1, MPAMIDR, PMG_MAX, 3); + /* FEAT_NV (Nested Virtualization) */ cpu->isar.id_aa64mmfr2 =3D FIELD_DP64(cpu->isar.id_aa64mmfr2, ID_AA64MMFR2, NV, 0); diff --git a/target/arm/helper.c b/target/arm/helper.c index 50f61e42ca..dbeb8d9fa6 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -8072,7 +8072,17 @@ static const ARMCPRegInfo actlr2_hactlr2_reginfo[] = =3D { .access =3D PL2_RW, .type =3D ARM_CP_CONST, .resetvalue =3D 0 }, }; +/* +static uint64_t mpam_el1_read(CPUARMState *env, const ARMCPRegInfo *ri) +{ + return 0; +} =20 +static void mpam_el1_write(CPUARMState *env, const ARMCPRegInfo *ri, uint6= 4_t val) +{ + return; +} +*/ void register_cp_regs_for_features(ARMCPU *cpu) { /* Register all the coprocessor registers based on feature bits */ @@ -8404,6 +8414,26 @@ void register_cp_regs_for_features(ARMCPU *cpu) .access =3D PL1_R, .type =3D ARM_CP_CONST, .accessfn =3D access_aa64_tid3, .resetvalue =3D 0 }, + + /* Should be separate feature */ + { .name =3D "MPAMIDR_EL1", .state =3D ARM_CP_STATE_AA64, + .opc0 =3D 3, .opc1 =3D 0, .crn =3D 0xa, .crm =3D 4, .opc2 = =3D 4, + .access =3D PL1_R, .type =3D ARM_CP_CONST, + .accessfn =3D access_aa64_tid3, + .resetvalue =3D cpu->isar.mpamidr_el1 }, + /* TODO: check the accessfn and whether we need a reset value = for these */ + { .name =3D "MPAM0_EL1", .state =3D ARM_CP_STATE_AA64, + .opc0 =3D 3, .opc1 =3D 0, .crn =3D 0xa, .crm =3D 5, .opc2 = =3D 1, + .access =3D PL1_RW, .type =3D ARM_CP_ALIAS, + .accessfn =3D access_aa64_tid3, + .fieldoffset =3D offsetof(CPUARMState, mpam0_el1), + }, + { .name =3D "MPAM1_EL1", .state =3D ARM_CP_STATE_AA64, + .opc0 =3D 3, .opc1 =3D 0, .crn =3D 0xa, .crm =3D 5, .opc2 = =3D 0, + .access =3D PL1_RW, .type =3D ARM_CP_ALIAS, + .accessfn =3D access_aa64_tid3, + .fieldoffset =3D offsetof(CPUARMState, mpam1_el1), + }, { .name =3D "MVFR0_EL1", .state =3D ARM_CP_STATE_AA64, .opc0 =3D 3, .opc1 =3D 0, .crn =3D 0, .crm =3D 3, .opc2 =3D = 0, .access =3D PL1_R, .type =3D ARM_CP_CONST, --=20 2.39.2 From nobody Thu Nov 28 12:54:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1691495984; cv=none; d=zohomail.com; s=zohoarc; b=DAt/Un/TyM+dLUF6r0n277NerflICW4lPPyJEzvpFPzp4Av+HLTO2uHnHC2HBxZbTa1NqnojarnQHgpNZO/zMtges1ruh/UMXyo6apTnUSezpR5UyNVDieg6wLY6hAMCsL3ZS88WOxAA+brV1RH6vxeqsQV8erkxOb9h5sjHJSw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691495984; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=jWqUJ3UrlCt4Xk5eq4xOp+0+NtrQyzpXcz7qzFBqKBE=; b=kVGkyVg5m/pjctFebzOaSUylZtrDUIZtbBPJGOkjGl0ss+wlF1CyVpBsO+OLerey1E5s9j/7fD8F4jJTdhGGyYr2bS1kVfVWzrxrk2xrT/x1I7IJ/CUbXiiEiasF1Yk/muLhxa3C0nMsnz85ujnTACtjk3yBi8rMh998+QmDEII= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691495984933385.08923141366904; Tue, 8 Aug 2023 04:59:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qTLMy-0004WA-VA; Tue, 08 Aug 2023 07:59:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qTLMx-0004VZ-7w for qemu-devel@nongnu.org; Tue, 08 Aug 2023 07:59:23 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qTLMs-0001et-FW for qemu-devel@nongnu.org; Tue, 08 Aug 2023 07:59:23 -0400 Received: from lhrpeml500005.china.huawei.com (unknown [172.18.147.226]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4RKs8B65jKz6J73r; Tue, 8 Aug 2023 19:55:38 +0800 (CST) Received: from SecurePC-101-06.china.huawei.com (10.122.247.231) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 8 Aug 2023 12:59:14 +0100 To: CC: Gavin Shan , , James Morse , "peter . maydell @ linaro . org" , , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Shameerali Kolothum Thodi , Yicong Yang Subject: [RFC PATCH 4/5] hw/arm: Add MPAM emulation. Date: Tue, 8 Aug 2023 12:57:12 +0100 Message-ID: <20230808115713.2613-5-Jonathan.Cameron@huawei.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230808115713.2613-1-Jonathan.Cameron@huawei.com> References: <20230808115713.2613-1-Jonathan.Cameron@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.122.247.231] X-ClientProxiedBy: lhrpeml500004.china.huawei.com (7.191.163.9) To lhrpeml500005.china.huawei.com (7.191.163.240) X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=185.176.79.56; envelope-from=jonathan.cameron@huawei.com; helo=frasgout.his.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Jonathan Cameron From: Jonathan Cameron via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1691495985299100001 Content-Type: text/plain; charset="utf-8" Note this doesn't 'do' anything other than provide an introspection interface. The intent here is to support work on the Linux kernel support and for that a functional emulation of the interface is useful. Signed-off-by: Jonathan Cameron --- qapi/mpam.json | 78 ++++ qapi/qapi-schema.json | 1 + include/hw/arm/mpam.h | 12 + include/hw/arm/virt.h | 2 + hw/arm/mpam-qapi-stubs.c | 9 + hw/arm/mpam-qapi.c | 58 +++ hw/arm/mpam.c | 886 +++++++++++++++++++++++++++++++++++++++ hw/arm/Kconfig | 4 + hw/arm/meson.build | 4 + qapi/meson.build | 1 + 10 files changed, 1055 insertions(+) diff --git a/qapi/mpam.json b/qapi/mpam.json new file mode 100644 index 0000000000..f4990ef96b --- /dev/null +++ b/qapi/mpam.json @@ -0,0 +1,78 @@ +# -*- Mode: Python -*- +# vim: filetype=3Dpython + +## +# =3D ARM MPAM State Introspection +## + +## +# @MpamBm: +## +{ 'struct': 'MpamBm', + 'data' : { 'words' : [ 'int' ] + } +} + +## +# @MpamRegs: +# +# Per RIS Register State +# +## +{ 'struct' : 'MpamRegs', + 'data' : { 'idr' : 'int', + 'iidr' : 'int', + 'aidr' : 'int', + 'cpor-idr': 'int', + 'ccap-idr': 'int', + 'mbw-idr': 'int', + 'pri-idr': 'int', + 'partid-nrw-idr': 'int', + 'msmon-idr': 'int', + 'csumon-idr': 'int', + 'mbwumon-idr': 'int', + 'ecr': 'int', + 'esr': 'int', + 'cfg-part-sel': 'int', + 'cfg-cpbm': ['MpamBm']#lazy + } +} + +## +# @MpamCacheInfo: +# +# Information about MPAM Cache MSCs +# +# @cpu: First CPU of the set associated with the cache +# +# @level: Level of cache +# +# @type: type of cache - make an enum +# +# Since: 9.0 +## + +{ 'struct': 'MpamCacheInfo', + 'data' : { 'cpu' : 'int', + 'level' : 'int', + 'type' : 'int', + 'regs' : ['MpamRegs'] + } +} + +## +# @query-mpam-cache: +# +# Get a list of MpamInfo for all Cache Related MSC +# +# @level: Provide a cache level to filter against +# +# Returns: a list of @MpamCacheInfo describing all +# the MPAM cache MSC instances +# +# Since: 9.0 +## +{ 'command': 'query-mpam-cache', + 'data': { '*level': 'int' }, + 'returns' : ['MpamCacheInfo'], + 'allow-preconfig': true } diff --git a/qapi/qapi-schema.json b/qapi/qapi-schema.json index 6594afba31..ea3ee75841 100644 --- a/qapi/qapi-schema.json +++ b/qapi/qapi-schema.json @@ -79,3 +79,4 @@ { 'include': 'virtio.json' } { 'include': 'cryptodev.json' } { 'include': 'cxl.json' } +{ 'include': 'mpam.json' } diff --git a/include/hw/arm/mpam.h b/include/hw/arm/mpam.h new file mode 100644 index 0000000000..7bd88d57bc --- /dev/null +++ b/include/hw/arm/mpam.h @@ -0,0 +1,12 @@ +#ifndef _MPAM_H_ +#define _MPAM_H_ + +#include "qom/object.h" +#include "qapi/qapi-commands-mpam.h" + +#define TYPE_MPAM_MSC_MEM "mpam-msc-mem" +#define TYPE_MPAM_MSC_CACHE "mpam-msc-cache" + +void mpam_cache_fill_info(Object *obj, MpamCacheInfo *info); + +#endif /* _MPAM_H_ */ diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h index e1ddbea96b..ac015a391a 100644 --- a/include/hw/arm/virt.h +++ b/include/hw/arm/virt.h @@ -71,6 +71,7 @@ enum { VIRT_SMMU, VIRT_UART, VIRT_MMIO, + VIRT_MPAM_MSC, VIRT_RTC, VIRT_FW_CFG, VIRT_PCIE, @@ -160,6 +161,7 @@ struct VirtMachineState { bool ras; bool mte; bool dtb_randomness; + bool mpam, mpam_min_msc; OnOffAuto acpi; VirtGICType gic_version; VirtIOMMUType iommu; diff --git a/hw/arm/mpam-qapi-stubs.c b/hw/arm/mpam-qapi-stubs.c new file mode 100644 index 0000000000..40ccb7de9a --- /dev/null +++ b/hw/arm/mpam-qapi-stubs.c @@ -0,0 +1,9 @@ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qapi/qapi-commands-mpam.h" + +MpamCacheInfoList *qmp_query_mpam_cache(bool has_level, int64_t level, Err= or **errp) +{ + return NULL; +} diff --git a/hw/arm/mpam-qapi.c b/hw/arm/mpam-qapi.c new file mode 100644 index 0000000000..cf027e0da9 --- /dev/null +++ b/hw/arm/mpam-qapi.c @@ -0,0 +1,58 @@ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "hw/arm/mpam.h" +#include "qom/object.h" +#include "qapi/qapi-commands-mpam.h" + +typedef struct MPAMQueryState { + Error **errp; + MpamCacheInfoList **head; + bool level_filter_on; + int level; +} MPAMQueryState; + +static int mpam_query_cache(Object *obj, void *opaque) +{ + MPAMQueryState *state =3D opaque; + MpamCacheInfoList *infolist; + MpamCacheInfo *info; + + if (!object_dynamic_cast(obj, TYPE_MPAM_MSC_CACHE)) { + return 0; + } + if (state->level_filter_on && + object_property_get_uint(obj, "cache-level", state->errp) !=3D + state->level) { + return 0; + } + + infolist =3D g_malloc0(sizeof(*infolist)); + info =3D g_malloc0(sizeof(*info)); + + mpam_cache_fill_info(obj, info); + + infolist->value =3D info; + + *state->head =3D infolist; + state->head =3D &infolist->next; + + return 0; +} + +MpamCacheInfoList *qmp_query_mpam_cache(bool has_level, int64_t level, + Error **errp) +{ + + MpamCacheInfoList *head =3D NULL; + MPAMQueryState state =3D { + .errp =3D errp, + .head =3D &head, + .level_filter_on =3D has_level, + .level =3D level, + }; + + object_child_foreach_recursive(object_get_root(), mpam_query_cache, &s= tate); + + return head; +} diff --git a/hw/arm/mpam.c b/hw/arm/mpam.c new file mode 100644 index 0000000000..4b645efc2e --- /dev/null +++ b/hw/arm/mpam.c @@ -0,0 +1,886 @@ +/* + * ARM MPAM emulation + * + * Copyright (c) 2023 Huawei + */ +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu/log.h" +#include "hw/irq.h" +#include "hw/qdev-properties.h" +#include "hw/registerfields.h" +#include "hw/sysbus.h" +#include "qom/object.h" +#include "hw/arm/mpam.h" + +REG64(MPAMF_IDR, 0) + FIELD(MPAMF_IDR, PART_ID_MAX, 0, 16) + FIELD(MPAMF_IDR, PMG_MAX, 16, 8) + FIELD(MPAMF_IDR, HAS_CCAP_PART, 24, 1) + FIELD(MPAMF_IDR, HAS_CPOR_PART, 25, 1) + FIELD(MPAMF_IDR, HAS_MBW_PART, 26, 1) + FIELD(MPAMF_IDR, HAS_PRI_PART, 27, 1) + FIELD(MPAMF_IDR, EXT, 28, 1) + FIELD(MPAMF_IDR, HAS_IMPL_IDR, 29, 1) + FIELD(MPAMF_IDR, HAS_MSMON, 30, 1) + FIELD(MPAMF_IDR, HAS_PARTID_NRW, 31, 1) + FIELD(MPAMF_IDR, HAS_RIS, 32, 1) + FIELD(MPAMF_IDR, NO_IMPL_PART, 36, 1) + FIELD(MPAMF_IDR, NO_IMPL_MSMON, 37, 1) + FIELD(MPAMF_IDR, HAS_EXTD_ESR, 38, 1) + FIELD(MPAMF_IDR, HAS_ESR, 39, 1) + FIELD(MPAMF_IDR, HAS_ERR_MS, 40, 1) + FIELD(MPAMF_IDR, SP4, 41, 1) + FIELD(MPAMF_IDR, HAS_ENDIS, 42, 1) + FIELD(MPAMF_IDR, HAS_NFU, 43, 1) + FIELD(MPAMF_IDR, RIS_MAX, 56, 4) + +REG32(MPAMF_IIDR, 0x0018) + FIELD(MPAMF_IIDR, IMPLEMENTER, 0, 12) + FIELD(MPAMF_IIDR, REVISION, 12, 4) + FIELD(MPAMF_IIDR, VARIANT, 16, 4) + FIELD(MPAMF_IIDR, PRODUCT_ID, 20, 12) + +REG32(MPAMF_AIDR, 0x0020) + FIELD(MPAMF_AIDR, ARCH_MINOR_REV, 0, 4) + FIELD(MPAMF_AIDR, ARCH_MAJOR_REV, 4, 4) + +REG32(MPAMF_IMPL_IDR, 0x0028) +REG32(MPAMF_CPOR_IDR, 0x0030) + FIELD(MPAMF_CPOR_IDR, CPBM_WD, 0, 16) + +REG32(MPAMF_CCAP_IDR, 0x0038) + FIELD(MPAMF_CCAP_IDR, CMAX_WD, 0, 6) + FIELD(MPAMF_CCAP_IDR, CASSOC_WD, 8, 5) + FIELD(MPAMF_CCAP_IDR, HAS_CASSOC, 28, 1) + FIELD(MPAMF_CCAP_IDR, HAS_CMIN, 29, 1) + FIELD(MPAMF_CCAP_IDR, NO_CMAX, 30, 1) + FIELD(MPAMF_CCAP_IDR, HAS_CMAX_SOFTLIM, 31, 1) + +REG32(MPAMF_MBW_IDR, 0x0040) + FIELD(MPAMF_MBW_IDR, BWA_WD, 0, 6) + FIELD(MPAMF_MBW_IDR, HAS_MIN, 10, 1) + FIELD(MPAMF_MBW_IDR, HAS_MAX, 11, 1) + FIELD(MPAMF_MBW_IDR, HAS_PBM, 12, 1) + FIELD(MPAMF_MBW_IDR, HAS_PROP, 13, 1) + FIELD(MPAMF_MBW_IDR, WINDWR, 14, 1) + FIELD(MPAMF_MBW_IDR, BWPBM_WD, 16, 13) + +REG32(MPAMF_PRI_IDR, 0x0048) + FIELD(MPAMF_PRI_IDR, HAS_INTPRI, 0, 1) + FIELD(MPAMF_PRI_IDR, INTPRI_0_IS_LOW, 1, 1) + FIELD(MPAMF_PRI_IDR, INTPRI_WD, 4, 6) + FIELD(MPAMF_PRI_IDR, HAS_DSPRI, 16, 1) + FIELD(MPAMF_PRI_IDR, DSPRI_0_IS_LOW, 17, 1) + FIELD(MPAMF_PRI_IDR, DSPRI_WD, 20, 6) + +REG32(MPAMF_PARTID_NRW_IDR, 0x0050) + FIELD(MPAMF_PARTID_NRW_IDR, INTPARTID_MAX, 0, 16) + +REG32(MPAMF_MSMON_IDR, 0x080) + FIELD(MPAMF_MSMON_IDR, MSMON_CSU, 16, 1) + FIELD(MPAMF_MSMON_IDR, MSMON_MBWU, 17, 1) + FIELD(MPAMF_MSMON_IDR, HAS_OFLOW_SR, 28, 1) + FIELD(MPAMF_MSMON_IDR, HAS_OFLW_MS, 29, 1) + FIELD(MPAMF_MSMON_IDR, NO_OFLW_INTR, 30, 1) + FIELD(MPAMF_MSMON_IDR, HAS_LOCAL_CAPT_EVNT, 31, 1) + +REG32(MPAMF_CSUMON_IDR, 0x0088) + FIELD(MPAMF_CSUMON_IDR, NUM_MON, 0, 16) + FIELD(MPAMF_CSUMON_IDR, HAS_OFLOW_CAPT, 24, 1) + FIELD(MPAMF_CSUMON_IDR, HAS_CEVNT_OFLW, 25, 1) + FIELD(MPAMF_CSUMON_IDR, HAS_OFSR, 26, 1) + FIELD(MPAMF_CSUMON_IDR, HAS_OFLOW_LNKG, 27, 1) + FIELD(MPAMF_CSUMON_IDR, HAS_XCL, 29, 1) + FIELD(MPAMF_CSUMON_IDR, CSU_RO, 30, 1) + FIELD(MPAMF_CSUMON_IDR, HAS_CAPTURE, 31, 1) + +REG32(MPAMF_MBWUMON_IDR, 0x0090) + FIELD(MPAMF_MBWUMON_IDR, NUM_MON, 0, 16) + FIELD(MPAMF_MBWUMON_IDR, SCALE, 16, 5) + FIELD(MPAMF_MBWUMON_IDR, HAS_OFLOW_CAPT, 24, 1) + FIELD(MPAMF_MBWUMON_IDR, HAS_CEVNT_OFLW, 25, 1) + FIELD(MPAMF_MBWUMON_IDR, HAS_OFSR, 26, 1) + FIELD(MPAMF_MBWUMON_IDR, HAS_OFLOW_LNKG, 27, 1) + FIELD(MPAMF_MBWUMON_IDR, HAS_RWBW, 28, 1) + FIELD(MPAMF_MBWUMON_IDR, LWD, 29, 1) + FIELD(MPAMF_MBWUMON_IDR, HAS_LONG, 30, 1) + FIELD(MPAMF_MBWUMON_IDR, HAS_CAPTURE, 31, 1) + +REG32(MPAMF_ERR_MSI_MPAM, 0x00dc) +REG32(MPAMF_ERR_MSI_ADDR_L, 0x00e0) +REG32(MPAMF_ERR_MSI_ADDR_H, 0x00e4) +REG32(MPAMF_ERR_MSI_DATA, 0x00e8) +REG32(MPAMF_ERR_MSI_ATTR, 0x00ec) + +REG32(MPAMF_ECR, 0x00f0) + FIELD(MPAMF_ECR, INTEN, 0, 1) +#define MPAMF_ECR_WRITE_MASK ( \ + R_MPAMF_ECR_INTEN_MASK) + +REG64(MPAMF_ESR, 0x00f8) + FIELD(MPAMF_ESR, PARID_MON, 0, 16) + FIELD(MPAMF_ESR, PMG, 16, 8) + FIELD(MPAMF_ESR, ERR_CODE, 24, 4) + FIELD(MPAMF_ESR, OVRWR, 31, 1) + FIELD(MPAMF_ESR, RIS, 32, 4) + +REG32(MPAMF_CFG_PART_SEL, 0x0100) + FIELD(MPAMF_CFG_PART_SEL, PARTID_SEL, 0, 16) + FIELD(MPAMF_CFG_PART_SEL, INTERNAL, 16, 1) + FIELD(MPAMF_CFG_PART_SEL, RIS, 24, 4) +#define MPAMF_CFG_PART_SEL_WRITE_MASK ( \ + R_MPAMF_CFG_PART_SEL_PARTID_SEL_MASK | \ + R_MPAMF_CFG_PART_SEL_INTERNAL_MASK | \ + R_MPAMF_CFG_PART_SEL_RIS_MASK) + +REG32(MPAMF_MPAMCFG_CMAX, 0x0108) + FIELD(MPAMF_MPAMCFG_CMAX, CMAX, 0, 16) + FIELD(MPAMF_MPAMCFG_CMAX, SOFTLIM, 31, 1) +#define MPAMF_MPAMCFG_CMAX_WRITE_MASK ( \ + R_MPAMF_MPAMCFG_CMAX_CMAX_MASK | \ + R_MPAMF_MPAMCFG_CMAX_SOFTLIM_MASK) + +REG32(MPAMF_MPAMCFG_CMIN, 0x0110) + FIELD(MPAMF_MPAMCFG_CMIN, CMIN, 0, 16) +#define MPAMF_MPAMCFG_CMIN_WRITE_MASK ( \ + R_MPAMF_MPAMCFG_CMIN_CMIN_MASK) + +REG32(MPAMF_MPAMCFG_CASSOC, 0x0118) + FIELD(MPAMF_MPAMCFG_CASSOC, CASSOC, 0, 16) +#define MPAMF_MPAMCFG_CASSOC_WRITE_MASK ( \ + R_MPAMF_MPAMCCG_CASSOC_CASSOC_MASK) + +REG32(MPAMF_MPAMCFG_MBW_MIN, 0x0200) + FIELD(MPAMF_MPAMCFG_MBW_MIN, MIN, 0, 16) +#define MPAMF_MPAMCFG_MBW_MIN_WRITE_MASK ( \ + R_MPAMF_MPAMCFG_MBW_MIN_MASK) + +REG32(MPAMF_MPAMCFG_MBW_MAX, 0x0208) + FIELD(MPAMF_MPAMCFG_MBW_MAX, MAX, 0, 16) + FIELD(MPAMF_MPAMCFG_MBW_MAX, HARDLIM, 31, 1) +#define MPAMF_MPAMCFG_MBW_MAX_WRITE_MASK ( \ + R_MPAMF_MPAMCFG_MBW_MAX_MAX_MASK | \ + R_MPAMF_MPAMCFG_MBW_MAX_HARDLIM_MASK) + +REG32(MPAMF_MPAMCFG_WINWD, 0x0220) + FIELD(MPAMF_MPAMCFG_WINWD, US_FRAC, 0, 8) + FIELD(MPAMF_MPAMCFG_WINWD, US_INT, 8, 16) +#define MPAMF_MPAMCFG_WINWD_WRITE_MASK ( \ + R_MPAMF_MPAMCFG_WINWD_US_FRAC | \ + R_MPAMF_MPAMCFG_WINWD_US_INT) + +REG32(MPAMF_MPAMCFG_EN, 0x0300) + FIELD(MPAMF_MPAMCFG_EN, PARTID, 0, 16) +#define MPAMF_MPAMCFG_EN_WRITE_MASK ( \ + R_MPAMF_MPAMCFG_EN_PARTID_MASK) + +REG32(MPAMF_MPAMCFG_DIS, 0x0310) /* WHat is this for? */ + FIELD(MPAMF_MPAMCFG_DIS, PARTID, 0, 16) + FIELD(MPAMF_MPAMCFG_DIS, NFU, 31, 1) +#define MPAMF_MPAMCFG_DIS_WRITE_MASK ( \ + R_MPAMF_MPAMCFG_DIS_PARTID_MASK | \ + R_MPAMF_MPAMCFG_DIS_NFU) + +REG32(MPAMF_MPAMCFG_EN_FLAGS, 0x320) + +REG32(MPAMF_MPAMCFG_PRI, 0x400) + FIELD(MPAMF_MPAMCFG_PRI, INTPRI, 0, 16) + FIELD(MPAMF_MPAMCFG_PRI, DSPRI, 16, 16) +#define MPAMF_MPAMCFG_PRI_WRITE_MASK ( \ + R_MPAMF_MPAMCFG_PRI_INTPRI_MASK | \ + R_MPAMF_MPAMCFG_PRI_DSPRI_MASK) + +REG32(MPAMF_MPAMCFG_MBW_PROP, 0x500) + FIELD(MPAMF_MPAMCFG_MBW_PROP, STRIDEM1, 0, 16) + FIELD(MPAMF_MPAMCFG_MBW_PROP, EN, 31, 1) +#define MPAMF_MPAMCFG_MBW_PROP_WRITE_MASK ( \ + R_MPAMF_MPAMCFG_MBW_PROP_STRIDEM1_MASK | \ + R_MPAMF_MPAMCFG_MBW_PROP_EN_MASK) + +REG32(MPAMF_MPAMCFG_INTPARTID, 0x600) + FIELD(MPAMF_MPAMCFG_INTPARTID, INTPARTID, 0, 16) + FIELD(MPAMF_MPAMCFG_INTPARTID, INTERNAL, 16, 1) +#define MPAMF_MPAMCFG_INTPARTID_WRITE_MASK ( \ + R_MPAMF_MPAMCFG_INTPARTID_INTPARTID_MASK | \ + R_MPAMF_MPAMCFG_INTPARTID_INTERNAL_MASK) + +REG32(MPAMF_MPAMCFG_CPBM0, 0x1000) + +REG32(MPAMF_MPAMCFG_MBW_PBM0, 0x2000) + +#define TYPE_MPAM_MSC "mpam-msc" +#define MPAM_MBW_PART 4 +#define MPAM_CACHE_PART 32 + +typedef struct MpamfPerNrwId { + uint32_t cfg_cpbm[(MPAM_CACHE_PART + 31) / 32]; + uint32_t cfg_mbw_pbm[(MPAM_MBW_PART + 31) / 32]; + uint32_t cfg_pri; + uint32_t cfg_cmax; + uint32_t cfg_mbw_min; + uint32_t cfg_mbw_max; + uint32_t cfg_mbw_prop; +} MpamfPerNrwId; + +typedef struct Mpamf { + uint64_t idr; + uint32_t iidr; + uint32_t aidr; + uint32_t impl_idr; + uint32_t cpor_idr; + uint32_t ccap_idr; + uint32_t mbw_idr; + uint32_t pri_idr; + uint32_t partid_nrw_idr; + uint32_t msmon_idr; + uint32_t csumon_idr; + uint32_t mbwumon_idr; + uint32_t err_msi_mpam; + uint32_t err_msi_addr_l; + uint32_t err_msi_addr_h; + uint32_t err_msi_data; + uint32_t err_msi_attr; + uint32_t ecr; + uint32_t esr; + uint32_t cfg_part_sel; + uint32_t *cfg_intpartid; + + MpamfPerNrwId *per_nrw_id; + +} Mpamf; + +typedef struct MPAMMSCState { + SysBusDevice parent_obj; + + Mpamf *mpamf; + + uint8_t ris; + uint16_t part_sel; /* Technically per ris, but in same reg */ + bool internal_part_sel; + struct MemoryRegion mr; + uint32_t num_partid; + uint32_t num_int_partid; + uint8_t num_ris; + +} MPAMMSCState; + +/* + * ID narrowing may be in effect. If it is there is an indirection + * table per RIS mapping from part_sel to the internal ID. To make things + * more complex, the Partition selection register can directly address + * internal IDs. That works for everything other than the ID map itself. + * This function pulls the right internal ID out of this complexity + * for use in accessing the per_nrw_id structures. + */ +static uint32_t mpam_get_nrw_id(MPAMMSCState *s) +{ + Mpamf *mpamf =3D &s->mpamf[s->ris]; + + if (!FIELD_EX32(mpamf->idr, MPAMF_IDR, HAS_PARTID_NRW)) { + return s->part_sel; + } + if (s->internal_part_sel) { + return s->part_sel; + } + return mpamf->cfg_intpartid[s->part_sel]; +} + +typedef struct MPAMMSCMemState { + MPAMMSCState parent; +} MPAMMSCMemState; + +typedef struct MPAMMSCCacheState { + MPAMMSCState parent; + uint8_t cache_level; + uint8_t cache_type; + uint16_t cpu; + +} MPAMMSCCacheState; + +DECLARE_INSTANCE_CHECKER(MPAMMSCState, MPAM_MSC_DEVICE, TYPE_MPAM_MSC); + +DECLARE_INSTANCE_CHECKER(MPAMMSCMemState, MPAM_MSC_MEM_DEVICE, + TYPE_MPAM_MSC_MEM); + +DECLARE_INSTANCE_CHECKER(MPAMMSCCacheState, MPAM_MSC_CACHE_DEVICE, + TYPE_MPAM_MSC_CACHE); + +void mpam_cache_fill_info(Object *obj, MpamCacheInfo *info) +{ + MPAMMSCCacheState *cs =3D MPAM_MSC_CACHE_DEVICE(obj); + MPAMMSCState *s =3D MPAM_MSC_DEVICE(obj); + MpamRegsList *reg_list =3D NULL, **r_next =3D ®_list; + int i, p, b; + + info->cpu =3D cs->cpu; + info->level =3D cs->cache_level; + info->type =3D cs->cache_level; + for (i =3D 0; i < s->num_ris; i++) { + MpamRegsList *regs; + MpamRegs *r; + MpamBmList *bm_list =3D NULL, **bm_next =3D &bm_list; + + Mpamf *mpamf =3D &s->mpamf[i]; + + r =3D g_malloc0(sizeof(*r)); + regs =3D g_malloc0(sizeof(*regs)); + regs->value =3D r; + + *r =3D (MpamRegs) { + .idr =3D mpamf->idr, + .iidr =3D mpamf->iidr, + .aidr =3D mpamf->aidr, + .cpor_idr =3D mpamf->cpor_idr, + .ccap_idr =3D mpamf->ccap_idr, + .mbw_idr =3D mpamf->mbw_idr, + .pri_idr =3D mpamf->pri_idr, + .partid_nrw_idr =3D mpamf->partid_nrw_idr, + .msmon_idr =3D mpamf->msmon_idr, + .csumon_idr =3D mpamf->csumon_idr, + .mbwumon_idr =3D mpamf->mbwumon_idr, + .ecr =3D mpamf->ecr, + .esr =3D mpamf->esr, + .cfg_part_sel =3D mpamf->cfg_part_sel, /* Garbage */ + }; + + /* This is annoyingly complex */ + for (p =3D 0; p < s->num_int_partid; p++) { + intList *w_list =3D NULL, **w_next =3D &w_list; + MpamBm *bm =3D g_malloc0(sizeof(*bm)); + MpamBmList *bml =3D g_malloc0(sizeof(*bml)); + + bml->value =3D bm; + + for (b =3D 0; b < (MPAM_CACHE_PART + 31) / 32; b++) { + intList *il =3D g_malloc0(sizeof(*il)); + + il->value =3D mpamf->per_nrw_id[p].cfg_cpbm[b]; + *w_next =3D il; + w_next =3D &il->next; + + } + *bm_next =3D bml; + bm_next =3D &bml->next; + bm->words =3D w_list; + } + r->cfg_cpbm =3D bm_list; + *r_next =3D regs; + r_next =3D ®s->next; + } + info->regs =3D reg_list; + +} + +static uint64_t mpam_msc_read_reg(void *opaque, hwaddr offset, + unsigned size) +{ + MPAMMSCState *s =3D MPAM_MSC_DEVICE(opaque); + Mpamf *mpamf =3D &s->mpamf[s->ris]; + uint32_t nrw_part_sel =3D mpam_get_nrw_id(s); + + switch (offset) { + case A_MPAMF_IDR: + switch (size) { + case 4: + return mpamf->idr & 0xffffffff; + case 8: + return mpamf->idr; + default: + qemu_log_mask(LOG_UNIMP, "MPAM: Unexpected read size\n"); + return 0; + } + case A_MPAMF_IDR + 0x04: + if (!FIELD_EX32(mpamf->idr, MPAMF_IDR, EXT)) { + qemu_log_mask(LOG_UNIMP, "MPAM: Unexpected read of top of IDR\= n"); + return 0; + } + switch (size) { + case 4: + return mpamf->idr >> 32; + default: + qemu_log_mask(LOG_UNIMP, "MPAM: Unexpected read size\n"); + return 0; + } + case A_MPAMF_IIDR: + return mpamf->iidr; + case A_MPAMF_AIDR: + return mpamf->aidr; + case A_MPAMF_IMPL_IDR: + if (!FIELD_EX32(mpamf->idr, MPAMF_IDR, HAS_IMPL_IDR)) { + qemu_log_mask(LOG_UNIMP, + "MPAM: Accessing IMPL_IDR which isn't suported\n"); + return 0; + } + return mpamf->impl_idr; + case A_MPAMF_CPOR_IDR: + if (!FIELD_EX32(mpamf->idr, MPAMF_IDR, HAS_CPOR_PART)) { + qemu_log_mask(LOG_UNIMP, + "MPAM: Unexpected read of CPOR_IDR with no CPOR support\n"= ); + return 0; + } + return mpamf->cpor_idr; + case A_MPAMF_CCAP_IDR: + if (!FIELD_EX32(mpamf->idr, MPAMF_IDR, HAS_CCAP_PART)) { + qemu_log_mask(LOG_UNIMP, + "MPAM: Unexpected read of CCAP_IDR with no CCAP support\n"= ); + return 0; + } + return mpamf->ccap_idr; + case A_MPAMF_MBW_IDR: + return mpamf->mbw_idr; + case A_MPAMF_PRI_IDR: + if (!FIELD_EX32(mpamf->idr, MPAMF_IDR, HAS_PRI_PART)) { + qemu_log_mask(LOG_UNIMP, + "MPAM: Unexpected read of PRI_IDR with no PRI PART support= \n"); + return 0; + } + return mpamf->pri_idr; + case A_MPAMF_PARTID_NRW_IDR: { + return mpamf->partid_nrw_idr; + } + case A_MPAMF_MSMON_IDR: + return mpamf->msmon_idr; + case A_MPAMF_CSUMON_IDR: + return mpamf->csumon_idr; + case A_MPAMF_MBWUMON_IDR: + return mpamf->mbwumon_idr; + case A_MPAMF_ERR_MSI_MPAM: + return mpamf->err_msi_mpam; + case A_MPAMF_ERR_MSI_ADDR_L: + return mpamf->err_msi_addr_l; + case A_MPAMF_ERR_MSI_ADDR_H: + return mpamf->err_msi_addr_h; + case A_MPAMF_ERR_MSI_DATA: + return mpamf->err_msi_data; + case A_MPAMF_ERR_MSI_ATTR: + return mpamf->err_msi_attr; + case A_MPAMF_ECR: + return mpamf->ecr; + case A_MPAMF_ESR: + return mpamf->esr; + case A_MPAMF_CFG_PART_SEL: + return mpamf->cfg_part_sel; + case A_MPAMF_MPAMCFG_CMAX: + if (!FIELD_EX32(mpamf->idr, MPAMF_IDR, HAS_CCAP_PART)) { + qemu_log_mask(LOG_UNIMP, + "MPAM: Unexpected read of CMAX with no CCAP support\n"); + return 0; + } + return mpamf->per_nrw_id[nrw_part_sel].cfg_cmax; + case A_MPAMF_MPAMCFG_MBW_MIN: + return mpamf->per_nrw_id[nrw_part_sel].cfg_mbw_min; + case A_MPAMF_MPAMCFG_MBW_MAX: + return mpamf->per_nrw_id[nrw_part_sel].cfg_mbw_max; + case A_MPAMF_MPAMCFG_PRI: + return mpamf->per_nrw_id[nrw_part_sel].cfg_pri; + case A_MPAMF_MPAMCFG_MBW_PROP: + return mpamf->per_nrw_id[nrw_part_sel].cfg_mbw_prop; + case A_MPAMF_MPAMCFG_CPBM0... + (A_MPAMF_MPAMCFG_CPBM0 + ((MPAM_CACHE_PART + 31) / 32 - 1) * 4): + { + uint32_t array_offset; + + if (!FIELD_EX32(mpamf->idr, MPAMF_IDR, HAS_CPOR_PART)) { + qemu_log_mask(LOG_UNIMP, + "MPAM: Unexpected read of CPBM with no CPOR support\n"); + return 0; + } + array_offset =3D (offset - A_MPAMF_MPAMCFG_CPBM0) / sizeof(uint32_= t); + return mpamf->per_nrw_id[nrw_part_sel].cfg_cpbm[array_offset]; + } + case A_MPAMF_MPAMCFG_MBW_PBM0... + (A_MPAMF_MPAMCFG_MBW_PBM0 + ((MPAM_MBW_PART + 31) / 32 - 1) * = 4): + { + uint32_t array_offset; + + if (!FIELD_EX32(mpamf->idr, MPAMF_IDR, HAS_MBW_PART)) { + qemu_log_mask(LOG_UNIMP, + "MPAM: Unexpected read of MBW_PBM with no MBW_PART support= \n"); + return 0; + } + array_offset =3D (offset - A_MPAMF_MPAMCFG_MBW_PBM0) / sizeof(uint= 32_t); + return mpamf->per_nrw_id[nrw_part_sel].cfg_mbw_pbm[array_offset]; + } + default: + qemu_log_mask(LOG_UNIMP, + "MPAM: Unexpected read of %lx\n", offset); + return 0x0; + } +} + +static void mpam_msc_write_reg(void *opaque, hwaddr offset, uint64_t value, + unsigned size) +{ + MPAMMSCState *s =3D MPAM_MSC_DEVICE(opaque); + /* Update in the ris setting path */ + Mpamf *mpamf =3D &s->mpamf[s->ris]; + /* Update if cfg_intpartid being touched */ + uint32_t nrw_part_sel =3D mpam_get_nrw_id(s); + + switch (offset) { + case A_MPAMF_CFG_PART_SEL: + if (value & ~MPAMF_CFG_PART_SEL_WRITE_MASK) { + qemu_log_mask(LOG_UNIMP, + "MPAM: Unexpected write to CFG_PART_SEL Mask=3D%= x Value=3D%lx\n", + MPAMF_CFG_PART_SEL_WRITE_MASK, value); + } + /* Field matches for all RIS */ + if (!FIELD_EX64(mpamf->idr, MPAMF_IDR, HAS_RIS) && + FIELD_EX32(value, MPAMF_CFG_PART_SEL, RIS) !=3D 0) { + qemu_log_mask(LOG_UNIMP, + "MPAM: Unexpected write of non 0 RIS on MSC with= !HAS_RIS\n"); + return; + } + s->ris =3D FIELD_EX32(value, MPAMF_CFG_PART_SEL, RIS); + s->part_sel =3D FIELD_EX32(value, MPAMF_CFG_PART_SEL, PARTID_SEL); + s->internal_part_sel =3D FIELD_EX32(value, MPAMF_CFG_PART_SEL, INT= ERNAL); + mpamf =3D &s->mpamf[s->ris]; + mpamf->cfg_part_sel =3D value; + return; + case A_MPAMF_MPAMCFG_CMAX: + if (value & ~MPAMF_MPAMCFG_CMAX_WRITE_MASK) { + qemu_log_mask(LOG_UNIMP, + "MPAM: Unexpected write to CMAX Mask=3D%x Value= =3D%lx\n", + MPAMF_MPAMCFG_CMAX_WRITE_MASK, value); + } + mpamf->per_nrw_id[nrw_part_sel].cfg_cmax =3D value; + return; + case A_MPAMF_MPAMCFG_MBW_MIN: + if (value & ~MPAMF_MPAMCFG_CMIN_WRITE_MASK) { + qemu_log_mask(LOG_UNIMP, + "MPAM: Unexpected write to CMAX Mask=3D%x Value= =3D%lx\n", + MPAMF_MPAMCFG_CMIN_WRITE_MASK, value); + } + mpamf->per_nrw_id[nrw_part_sel].cfg_mbw_min =3D value; + return; + case A_MPAMF_MPAMCFG_MBW_MAX: + if (value & ~MPAMF_MPAMCFG_MBW_MAX_WRITE_MASK) { + qemu_log_mask(LOG_UNIMP, + "MPAM: Unexpected write to MBW_MAX Mask=3D%x Val= ue=3D%lx\n", + MPAMF_MPAMCFG_MBW_MAX_WRITE_MASK, value); + } + mpamf->per_nrw_id[nrw_part_sel].cfg_mbw_max =3D value; + return; + case A_MPAMF_MPAMCFG_PRI: + if (!FIELD_EX32(mpamf->idr, MPAMF_IDR, HAS_PRI_PART)) { + qemu_log_mask(LOG_UNIMP, + "MPAM: Unexpected write to CFG_PRI when !HAS_PRI= _PART\n"); + } else { + if (!FIELD_EX32(mpamf->pri_idr, MPAMF_PRI_IDR, HAS_DSPRI) && + FIELD_EX32(value, MPAMF_MPAMCFG_PRI, DSPRI)) { + qemu_log_mask(LOG_UNIMP, + "MPAM: Unexpected write to CFGP_PRI DSPRI wh= en !HAS_DSPRI\n"); + } + if (!FIELD_EX32(mpamf->pri_idr, MPAMF_PRI_IDR, HAS_INTPRI) && + FIELD_EX32(value, MPAMF_MPAMCFG_PRI, INTPRI)) { + qemu_log_mask(LOG_UNIMP, + "MPAM: Unexpected write to CFGP_PRI INTPRI w= hen !HAS_INTPRI\n"); + } + } + mpamf->per_nrw_id[nrw_part_sel].cfg_pri =3D value; + return; + case A_MPAMF_MPAMCFG_MBW_PROP: + if (value & ~MPAMF_MPAMCFG_MBW_PROP_WRITE_MASK) { + qemu_log_mask(LOG_UNIMP, + "MPAM: Unexpected write to MBW_PROP Mask=3D%x Va= lue=3D%lx\n", + MPAMF_MPAMCFG_MBW_MAX_WRITE_MASK, value); + } + mpamf->per_nrw_id[nrw_part_sel].cfg_mbw_prop =3D value; + return; + case A_MPAMF_MPAMCFG_CPBM0... + (A_MPAMF_MPAMCFG_CPBM0 + ((MPAM_CACHE_PART + 31) / 32 - 1) * 4): + { + uint32_t array_offset; + + /* TODO: Figure out write mask to check this stays in write bits */ + if (!FIELD_EX32(mpamf->idr, MPAMF_IDR, HAS_CPOR_PART)) { + qemu_log_mask(LOG_UNIMP, + "MPAM: Unexpected write to CPMB when !HAS_CPORT_= PART\n"); + return; + } + array_offset =3D (offset - A_MPAMF_MPAMCFG_CPBM0) / sizeof(uint32_= t); + mpamf->per_nrw_id[nrw_part_sel].cfg_cpbm[array_offset] =3D value; + return; + } + case A_MPAMF_MPAMCFG_MBW_PBM0... + (A_MPAMF_MPAMCFG_MBW_PBM0 + ((MPAM_MBW_PART + 31) / 32 - 1) * 4): + { + uint32_t array_offset; + + if (!FIELD_EX32(mpamf->idr, MPAMF_IDR, HAS_MBW_PART)) { + qemu_log_mask(LOG_UNIMP, + "MPAM: Unexpected write to MBW_PBM when !HAS_MBW= _PART\n"); + return; + } + /* TODO: Figure out write mask to check this stays in write bits */ + array_offset =3D (offset - A_MPAMF_MPAMCFG_MBW_PBM0) / sizeof(uint= 32_t); + + mpamf->per_nrw_id[nrw_part_sel].cfg_mbw_pbm[array_offset] =3D valu= e; + return; + } + case A_MPAMF_ECR: + if (value & ~MPAMF_ECR_WRITE_MASK) { + qemu_log_mask(LOG_UNIMP, + "MPAM: Unexpected write to ECR Mask=3D%x Value= =3D%lx\n", + MPAMF_ECR_WRITE_MASK, value); + } + mpamf->ecr =3D value; + return; + default: + qemu_log_mask(LOG_UNIMP, + "MPAM: Write to unexpected register Addr %lx Value= =3D%lx\n", + offset, value); + } +} + +static const MemoryRegionOps mpam_msc_ops =3D { + .read =3D mpam_msc_read_reg, + .write =3D mpam_msc_write_reg, + .endianness =3D DEVICE_LITTLE_ENDIAN, + .valid =3D { + .min_access_size =3D 1, + .max_access_size =3D 8, + .unaligned =3D false, + }, + .impl =3D { + .min_access_size =3D 1, + .max_access_size =3D 8, + }, +}; + + +static void mpam_msc_realize(DeviceState *dev, Error **errp) +{ + MPAMMSCState *s =3D MPAM_MSC_DEVICE(dev); + int i; + + if (s->num_ris > 16) { + error_setg(errp, "num-ris must be <=3D 16"); + return; + } + if (s->num_partid =3D=3D 0) { + error_setg(errp, "num-ris must be <=3D 16"); + return; + } + if (s->num_int_partid =3D=3D 0) { + s->num_int_partid =3D s->num_partid; + } + + s->mpamf =3D g_new0(Mpamf, s->num_ris); + for (i =3D 0; i < s->num_ris; i++) { + s->mpamf[i].per_nrw_id =3D g_new0(MpamfPerNrwId, s->num_int_partid= ); + s->mpamf[i].cfg_intpartid =3D g_new0(uint32_t, s->num_partid); + } + + memory_region_init_io(&s->mr, OBJECT(s), &mpam_msc_ops, s, "mpam_msc", + 0x4000); + sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->mr); +} + +static void mpam_msc_mem_realize(DeviceState *dev, Error **errp) +{ + + MPAMMSCState *s =3D MPAM_MSC_DEVICE(dev); + int i; + + mpam_msc_realize(dev, errp); + + for (i =3D 0; i < s->num_ris; i++) { + Mpamf *mpamf =3D &s->mpamf[i]; + + mpamf->idr =3D FIELD_DP64(mpamf->idr, MPAMF_IDR, PART_ID_MAX, + s->num_partid - 1); + /* No PCMG for now */ + mpamf->idr =3D FIELD_DP64(mpamf->idr, MPAMF_IDR, PMG_MAX, 0); + mpamf->idr =3D FIELD_DP64(mpamf->idr, MPAMF_IDR, EXT, 1); + mpamf->idr =3D FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_RIS, s->num_r= is > 1); + mpamf->idr =3D FIELD_DP64(mpamf->idr, MPAMF_IDR, RIS_MAX, + s->num_ris > 1 ? s->num_ris - 1 : 0); + /* Optional - test with and without */ + mpamf->idr =3D FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_ESR, 1); + mpamf->idr =3D FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_EXTD_ESR, 1); + mpamf->idr =3D FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_PARTID_NRW, + s->num_int_partid < s->num_partid); + + /* We won't implement any implementation specific stuff */ + mpamf->idr =3D FIELD_DP64(mpamf->idr, MPAMF_IDR, NO_IMPL_PART, 1); + mpamf->idr =3D FIELD_DP64(mpamf->idr, MPAMF_IDR, NO_IMPL_MSMON, 1); + /* Memory specific bit */ + mpamf->idr =3D FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_MBW_PART, 1); + + mpamf->iidr =3D FIELD_DP64(mpamf->iidr, MPAMF_IIDR, IMPLEMENTER, 0= x736); + mpamf->iidr =3D FIELD_DP64(mpamf->iidr, MPAMF_IIDR, REVISION, 0); + mpamf->iidr =3D FIELD_DP64(mpamf->iidr, MPAMF_IIDR, VARIANT, 0); + /* FIXME get allocation for this emulation */ + mpamf->iidr =3D FIELD_DP64(mpamf->iidr, MPAMF_IIDR, PRODUCT_ID, 42= ); + + mpamf->aidr =3D FIELD_DP64(mpamf->aidr, MPAMF_AIDR, ARCH_MINOR_REV= , 1); + mpamf->aidr =3D FIELD_DP64(mpamf->aidr, MPAMF_AIDR, ARCH_MAJOR_REV= , 1); + + mpamf->mbw_idr =3D FIELD_DP32(mpamf->mbw_idr, MPAMF_MBW_IDR, BWA_W= D, 16); + mpamf->mbw_idr =3D FIELD_DP32(mpamf->mbw_idr, MPAMF_MBW_IDR, HAS_M= IN, 1); + mpamf->mbw_idr =3D FIELD_DP32(mpamf->mbw_idr, MPAMF_MBW_IDR, HAS_M= AX, 1); + mpamf->mbw_idr =3D FIELD_DP32(mpamf->mbw_idr, MPAMF_MBW_IDR, HAS_P= BM, 1); + mpamf->mbw_idr =3D FIELD_DP32(mpamf->mbw_idr, MPAMF_MBW_IDR, HAS_P= ROP, 1); + + mpamf->mbw_idr =3D FIELD_DP32(mpamf->mbw_idr, MPAMF_MBW_IDR, WINDW= R, 0); + mpamf->mbw_idr =3D FIELD_DP32(mpamf->mbw_idr, MPAMF_MBW_IDR, + BWPBM_WD, MPAM_MBW_PART); + + if (s->num_int_partid < s->num_partid) { + mpamf->partid_nrw_idr =3D FIELD_DP32(mpamf->partid_nrw_idr, + MPAMF_PARTID_NRW_IDR, + INTPARTID_MAX, + s->num_int_partid - 1); + } + } +} + +static void mpam_msc_cache_realize(DeviceState *dev, Error **errp) +{ + MPAMMSCState *s =3D MPAM_MSC_DEVICE(dev); + int i; + + mpam_msc_realize(dev, errp); + + for (i =3D 0; i < s->num_ris; i++) { + Mpamf *mpamf =3D &s->mpamf[i]; + + mpamf->idr =3D FIELD_DP64(mpamf->idr, MPAMF_IDR, PART_ID_MAX, + s->num_partid - 1); + /* No PCMG for now */ + mpamf->idr =3D FIELD_DP64(mpamf->idr, MPAMF_IDR, PMG_MAX, 0); + mpamf->idr =3D FIELD_DP64(mpamf->idr, MPAMF_IDR, EXT, 1); + mpamf->idr =3D FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_RIS, s->num_r= is > 1); + mpamf->idr =3D FIELD_DP64(mpamf->idr, MPAMF_IDR, RIS_MAX, + s->num_ris > 1 ? s->num_ris - 1 : 0); + + /* Optional - test with and without */ + mpamf->idr =3D FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_ESR, 1); + mpamf->idr =3D FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_EXTD_ESR, + s->num_ris > 1); + + /* We won't implement any implementation specific stuff */ + mpamf->idr =3D FIELD_DP64(mpamf->idr, MPAMF_IDR, NO_IMPL_PART, 1); + mpamf->idr =3D FIELD_DP64(mpamf->idr, MPAMF_IDR, NO_IMPL_MSMON, 1); + + /* Need to implement for RME */ + mpamf->idr =3D FIELD_DP64(mpamf->idr, MPAMF_IDR, SP4, 0); + + /* Cache specific bit */ + mpamf->idr =3D FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_CPOR_PART, 1); + mpamf->idr =3D FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_CCAP_PART, 1); + mpamf->idr =3D FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_PRI_PART, 1); + mpamf->idr =3D FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_PARTID_NRW, + s->num_int_partid < s->num_partid); + + mpamf->iidr =3D FIELD_DP32(mpamf->iidr, MPAMF_IIDR, IMPLEMENTER, 0= x736); + mpamf->iidr =3D FIELD_DP32(mpamf->iidr, MPAMF_IIDR, REVISION, 0); + mpamf->iidr =3D FIELD_DP32(mpamf->iidr, MPAMF_IIDR, VARIANT, 0); + /* FIXME get allocation for this emulation */ + mpamf->iidr =3D FIELD_DP32(mpamf->iidr, MPAMF_IIDR, PRODUCT_ID, 42= ); + + mpamf->aidr =3D FIELD_DP32(mpamf->aidr, MPAMF_AIDR, ARCH_MINOR_REV= , 1); + mpamf->aidr =3D FIELD_DP32(mpamf->aidr, MPAMF_AIDR, ARCH_MAJOR_REV= , 1); + + /* Portion */ + mpamf->cpor_idr =3D FIELD_DP32(mpamf->cpor_idr, MPAMF_CPOR_IDR, CP= BM_WD, + MPAM_CACHE_PART); + + /* Priority */ + mpamf->pri_idr =3D FIELD_DP32(mpamf->pri_idr, MPAMF_PRI_IDR, + HAS_INTPRI, 1); + mpamf->pri_idr =3D FIELD_DP32(mpamf->pri_idr, MPAMF_PRI_IDR, + INTPRI_0_IS_LOW, 1); + mpamf->pri_idr =3D FIELD_DP32(mpamf->pri_idr, MPAMF_PRI_IDR, + INTPRI_WD, 2); + + /* Capacity Partitioning */ + mpamf->ccap_idr =3D FIELD_DP32(mpamf->ccap_idr, MPAMF_CCAP_IDR, + HAS_CMAX_SOFTLIM, 1); + mpamf->ccap_idr =3D FIELD_DP32(mpamf->ccap_idr, MPAMF_CCAP_IDR, + NO_CMAX, 0); + mpamf->ccap_idr =3D FIELD_DP32(mpamf->ccap_idr, MPAMF_CCAP_IDR, + HAS_CMIN, 1); + mpamf->ccap_idr =3D FIELD_DP32(mpamf->ccap_idr, MPAMF_CCAP_IDR, + HAS_CASSOC, 1); + mpamf->ccap_idr =3D FIELD_DP32(mpamf->ccap_idr, MPAMF_CCAP_IDR, + CASSOC_WD, 4); /* Not much flex on th= is */ + mpamf->ccap_idr =3D FIELD_DP32(mpamf->ccap_idr, MPAMF_CCAP_IDR, + CMAX_WD, 4); + + if (s->num_int_partid < s->num_partid) { + mpamf->partid_nrw_idr =3D FIELD_DP32(mpamf->partid_nrw_idr, + MPAMF_PARTID_NRW_IDR, + INTPARTID_MAX, + s->num_int_partid - 1); + } + /* TODO: Initialize all on as if firmware had done it for us */ + } +} + +static Property mpam_msc_props[] =3D { + DEFINE_PROP_UINT8("num-ris", MPAMMSCState, num_ris, 1), + DEFINE_PROP_UINT32("num-partid", MPAMMSCState, num_partid, 1), + DEFINE_PROP_UINT32("num-int-partid", MPAMMSCState, num_int_partid, 0), + DEFINE_PROP_END_OF_LIST() +}; + +static Property mpam_msc_cache_props[] =3D { + DEFINE_PROP_UINT8("cache-level", MPAMMSCCacheState, cache_level, 1), + DEFINE_PROP_UINT8("cache-type", MPAMMSCCacheState, cache_type, 1), + DEFINE_PROP_UINT16("cpu", MPAMMSCCacheState, cpu, 2), + DEFINE_PROP_END_OF_LIST() +}; + +static void mpam_msc_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + device_class_set_props(dc, mpam_msc_props); +} + +static void mpam_msc_mem_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + dc->realize =3D mpam_msc_mem_realize; +} + +static void mpam_msc_cache_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + dc->realize =3D mpam_msc_cache_realize; + device_class_set_props(dc, mpam_msc_cache_props); +} + +static const TypeInfo mpam_msc_info =3D { + .name =3D TYPE_MPAM_MSC, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(MPAMMSCState), + .class_init =3D mpam_msc_init +}; + +static const TypeInfo mpam_msc_mem_info =3D { + .name =3D TYPE_MPAM_MSC_MEM, + .parent =3D TYPE_MPAM_MSC, + .instance_size =3D sizeof(MPAMMSCMemState), + .class_init =3D mpam_msc_mem_init +}; + +static const TypeInfo mpam_msc_cache_info =3D { + .name =3D TYPE_MPAM_MSC_CACHE, + .parent =3D TYPE_MPAM_MSC, + .instance_size =3D sizeof(MPAMMSCCacheState), + .class_init =3D mpam_msc_cache_init +}; + +static void mpam_register_types(void) +{ + type_register_static(&mpam_msc_info); + type_register_static(&mpam_msc_mem_info); + type_register_static(&mpam_msc_cache_info); +} +type_init(mpam_register_types); diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig index 7e68348440..e44259910c 100644 --- a/hw/arm/Kconfig +++ b/hw/arm/Kconfig @@ -32,6 +32,7 @@ config ARM_VIRT select VIRTIO_MEM_SUPPORTED select ACPI_CXL select ACPI_HMAT + select MPAM =20 config CHEETAH bool @@ -593,6 +594,9 @@ config FSL_IMX7 config ARM_SMMUV3 bool =20 +config MPAM + bool + config FSL_IMX6UL bool default y diff --git a/hw/arm/meson.build b/hw/arm/meson.build index 11eb9112f8..08f72befa1 100644 --- a/hw/arm/meson.build +++ b/hw/arm/meson.build @@ -67,6 +67,10 @@ arm_ss.add(when: 'CONFIG_XEN', if_true: files('xen_arm.c= ')) arm_ss.add_all(xen_ss) =20 system_ss.add(when: 'CONFIG_ARM_SMMUV3', if_true: files('smmu-common.c')) +system_ss.add(when: 'CONFIG_MPAM', if_true: files('mpam.c', 'mpam-qapi.c')) +system_ss.add(when: 'CONFIG_MPAM', if_false: files('mpam-qapi-stubs.c')) +system_ss.add(when: 'CONFIG_ALL', if_true: files('mpam-qapi-stubs.c')) + system_ss.add(when: 'CONFIG_EXYNOS4', if_true: files('exynos4_boards.c')) system_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2835_peripherals.c'= )) system_ss.add(when: 'CONFIG_TOSA', if_true: files('tosa.c')) diff --git a/qapi/meson.build b/qapi/meson.build index 60a668b343..8e9a45330b 100644 --- a/qapi/meson.build +++ b/qapi/meson.build @@ -41,6 +41,7 @@ qapi_all_modules =3D [ 'migration', 'misc', 'misc-target', + 'mpam', 'net', 'pragma', 'qom', --=20 2.39.2 From nobody Thu Nov 28 12:54:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1691496002; cv=none; d=zohomail.com; s=zohoarc; b=MpepX29vwgFROrS1ePBMUuwmWX/FuBrMGiu36ShiY+NhrVhtoQIghQUTztdFm/9y5Z+kgX5G/lLweiYkJK7pf3Y2uaSGNT2vBSutoqX0R6ZED3F8EbrRarGyWHnUAZCS6Wj18meA9HO2fR6O2kFuNm4y5J/w83j2bl14xjaAV5c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691496002; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=LmBqsEqIok4VsfIE/oyCcKF50Tp36EuyfTUXBkuWtiY=; b=m1520cZkLAuJMTgX4R+BCJdm5qJpL9rGiRmgdMaNcfa10KqSa+jWK9R40zLR/bxRtUDybLluRlqP+hRrrzd30n/NPIhEhJNFZgWlM8ylcKp6WOC9LYK7ASqBWit0Z2afE7+59J7qOdnb9ho7+dogSlRMgarn3DXvDGwlYeCWIxs= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691496002717971.2069219036634; Tue, 8 Aug 2023 05:00:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qTLNP-00054G-JV; Tue, 08 Aug 2023 07:59:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qTLNO-0004wZ-4d for qemu-devel@nongnu.org; Tue, 08 Aug 2023 07:59:50 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qTLNL-0001k3-OK for qemu-devel@nongnu.org; Tue, 08 Aug 2023 07:59:49 -0400 Received: from lhrpeml500005.china.huawei.com (unknown [172.18.147.206]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4RKs8m0cXFz6J6jD; Tue, 8 Aug 2023 19:56:08 +0800 (CST) Received: from SecurePC-101-06.china.huawei.com (10.122.247.231) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 8 Aug 2023 12:59:45 +0100 To: CC: Gavin Shan , , James Morse , "peter . maydell @ linaro . org" , , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Shameerali Kolothum Thodi , Yicong Yang Subject: [RFC PATCH 5/5] hw/arm/virt: Add MPAM MSCs for memory controllers and caches. Date: Tue, 8 Aug 2023 12:57:13 +0100 Message-ID: <20230808115713.2613-6-Jonathan.Cameron@huawei.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230808115713.2613-1-Jonathan.Cameron@huawei.com> References: <20230808115713.2613-1-Jonathan.Cameron@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.122.247.231] X-ClientProxiedBy: lhrpeml500004.china.huawei.com (7.191.163.9) To lhrpeml500005.china.huawei.com (7.191.163.240) X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=185.176.79.56; envelope-from=jonathan.cameron@huawei.com; helo=frasgout.his.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Jonathan Cameron From: Jonathan Cameron via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1691496003279100001 Content-Type: text/plain; charset="utf-8" Allow sharing of MSC instances (using RIS) for memory controllers. Currently cached controllers are not using RIS (tend to be more in a system so more clever logic needed to auto allocate them). No DT support yet. The kernel bindings are considered unstable so premature to add too much on that front. Note that for now MPAM MSC creation is dependent on having SRAT and hence you need some numa nodes defined. Signed-off-by: Jonathan Cameron --- include/hw/arm/mpam.h | 1 + hw/arm/virt-acpi-build.c | 197 +++++++++++++++++++++++++++++++++++++++ hw/arm/virt.c | 134 ++++++++++++++++++++++++++ 3 files changed, 332 insertions(+) diff --git a/include/hw/arm/mpam.h b/include/hw/arm/mpam.h index 7bd88d57bc..8f47c8806f 100644 --- a/include/hw/arm/mpam.h +++ b/include/hw/arm/mpam.h @@ -7,6 +7,7 @@ #define TYPE_MPAM_MSC_MEM "mpam-msc-mem" #define TYPE_MPAM_MSC_CACHE "mpam-msc-cache" =20 +#define MPAM_SIZE 0x4000 /* Big enough for anyone ;) */ void mpam_cache_fill_info(Object *obj, MpamCacheInfo *info); =20 #endif /* _MPAM_H_ */ diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c index ec8fdcefff..b14dce3722 100644 --- a/hw/arm/virt-acpi-build.c +++ b/hw/arm/virt-acpi-build.c @@ -49,6 +49,7 @@ #include "hw/pci/pci_bus.h" #include "hw/pci-host/gpex.h" #include "hw/arm/virt.h" +#include "hw/arm/mpam.h" #include "hw/intc/arm_gicv3_its_common.h" #include "hw/mem/nvdimm.h" #include "hw/platform-bus.h" @@ -515,6 +516,198 @@ build_spcr(GArray *table_data, BIOSLinker *linker, Vi= rtMachineState *vms) acpi_table_end(linker, &table); } =20 +static void build_msc_memory_controller(GArray *table_data, int identifier, + hwaddr base_addr, uint32_t mpam_id, + int num_ris, uint64_t *nodes) +{ + int length =3D 72 + 24 * num_ris; + int i; + + build_append_int_noprefix(table_data, length, 2); + /* Interface Type */ + build_append_int_noprefix(table_data, 0 /* MMIO */, 1); + /* Reserved */ + build_append_int_noprefix(table_data, 0, 1); + build_append_int_noprefix(table_data, identifier, 4); + build_append_int_noprefix(table_data, base_addr, 8); + build_append_int_noprefix(table_data, MPAM_SIZE, 4); + /* Overflow interrupt - HACK */ + build_append_int_noprefix(table_data, 0x2C, 4); + /* Edge - SPI */ + build_append_int_noprefix(table_data, 1, 4); + /* Reserved */ + build_append_int_noprefix(table_data, 0, 4); + /* Overflow Int Affinity - HACK */ + build_append_int_noprefix(table_data, 0, 4); + /* Error interrupt - HACK */ + build_append_int_noprefix(table_data, 0x2D, 4); + /* Edge - SPI */ + build_append_int_noprefix(table_data, 1, 4); + /* More reserved */ + build_append_int_noprefix(table_data, 0, 4); + /* Error Int Affinity */ + build_append_int_noprefix(table_data, 0, 4); + /* MAX_NRDY_USEC */ + build_append_int_noprefix(table_data, 100, 4); + /* Linked Device - none for now */ + build_append_int_noprefix(table_data, 0, 8); + /* _UID of linked device */ + build_append_int_noprefix(table_data, 0, 4); + build_append_int_noprefix(table_data, num_ris, 4); + /* Build a memory controller resouce */ + for (i =3D 0; i < num_ris; i++) { + build_append_int_noprefix(table_data, mpam_id, 4); + build_append_int_noprefix(table_data, i, 1); + /* Reserved1 */ + build_append_int_noprefix(table_data, 0, 2); + /* Locator type - 1 =3D Memory */ + build_append_int_noprefix(table_data, 1, 1); + /* Locator part 1 Node */ + build_append_int_noprefix(table_data, nodes[i], 8); + /* Locator part 2 reserved */ + build_append_int_noprefix(table_data, 0, 4); + /* Num functional dependencies */ + build_append_int_noprefix(table_data, 0, 4); + } +} + +static void build_msc_cache_controller(GArray *table_data, int identifier, + hwaddr base_addr, uint32_t mpam_id, + int num_ris, uint64_t *cache_id) +{ + int length =3D 72 + 24 * num_ris; + int i; + + build_append_int_noprefix(table_data, length, 2); + /* Interface Type */ + build_append_int_noprefix(table_data, 0 /* MMIO */, 1); + /* Reserved */ + build_append_int_noprefix(table_data, 0, 1); + build_append_int_noprefix(table_data, identifier, 4); + build_append_int_noprefix(table_data, base_addr, 8); + build_append_int_noprefix(table_data, MPAM_SIZE, 4); + /* Overflow interrupt - HACK */ + build_append_int_noprefix(table_data, 0x2C, 4); + /* Edge - SPI */ + build_append_int_noprefix(table_data, 1, 4); + /* Reserved */ + build_append_int_noprefix(table_data, 0, 4); + /* Overflow Int Affinity */ + build_append_int_noprefix(table_data, 0, 4); + /* Error interrupt - HACK */ + build_append_int_noprefix(table_data, 0x2D, 4); + /* Edge - SPI */ + build_append_int_noprefix(table_data, 1, 4); + /* More reserved */ + build_append_int_noprefix(table_data, 0, 4); + /* Error Int Affinity */ + build_append_int_noprefix(table_data, 0, 4); + /* MAX_NRDY_USEC */ + build_append_int_noprefix(table_data, 100, 4); + /* Linked Device - none for now */ + build_append_int_noprefix(table_data, 0, 8); + /* _UID of linked device */ + build_append_int_noprefix(table_data, 0, 4); + /* Num resource nodes */ + build_append_int_noprefix(table_data, num_ris, 4); + /* Build a memory controller resouce */ + for (i =3D 0; i < num_ris; i++) { + /* Identifier */ + build_append_int_noprefix(table_data, mpam_id, 4); + /* RIS index */ + build_append_int_noprefix(table_data, i, 1); + /* Reserved1 */ + build_append_int_noprefix(table_data, 0, 2); + /* Locator type - 0 =3D Cache */ + build_append_int_noprefix(table_data, 0, 1); + /* Locator part 1 PPTT ID */ + build_append_int_noprefix(table_data, cache_id[i], 8); + /* Locator part 2 reserved */ + build_append_int_noprefix(table_data, 0, 4); + /* Num functional dependencies */ + build_append_int_noprefix(table_data, 0, 4); + } +} + +struct mpam_stat { + MachineState *ms; + GArray *table_data; + hwaddr base_addr; + int count; + int cpu_count; + uint32_t mpam_id; /* Just needs to be unique */ +}; + +static int mpam_add_msc(Object *obj, void *opaque) +{ + if (object_dynamic_cast(obj, TYPE_MPAM_MSC_MEM)) { + struct mpam_stat *mpam_s =3D opaque; + SysBusDevice *s =3D SYS_BUS_DEVICE(obj); + int num_ris =3D object_property_get_uint(obj, "num-ris", &error_fa= tal); + uint64_t *ids =3D g_new0(uint64_t, num_ris); + int j =3D 0; + int i; + + /* Fill them in based on which nodes have memory */ + for (i =3D 0; i < mpam_s->ms->numa_state->num_nodes; i++) { + if (mpam_s->ms->numa_state->nodes[i].node_mem) { + ids[j++] =3D i; + } + } + + build_msc_memory_controller(mpam_s->table_data, mpam_s->count, + s->mmio[0].addr, mpam_s->mpam_id++, + num_ris, ids); + mpam_s->count++; + g_free(ids); + } + + if (object_dynamic_cast(obj, TYPE_MPAM_MSC_CACHE)) { + struct mpam_stat *mpam_s =3D opaque; + SysBusDevice *s =3D SYS_BUS_DEVICE(obj); + int num_ris =3D 1; + uint64_t *ids =3D g_new0(uint64_t, num_ris); + uint8_t cache_level =3D object_property_get_uint(obj, "cache-level= ", + &error_fatal); + uint8_t cache_type =3D object_property_get_uint(obj, "cache-type", + &error_fatal); + uint16_t cpu =3D object_property_get_uint(obj, "cpu", &error_fatal= ); + + ids[0] =3D cpu | (cache_level << 16) | (cache_type << 24); + printf("MPAM has a cache with ID %lx\n", ids[0]); + build_msc_cache_controller(mpam_s->table_data, mpam_s->count, + s->mmio[0].addr, mpam_s->mpam_id++, + num_ris, ids); + mpam_s->count++; + g_free(ids); + } + + return 0; +} + +static void +build_mpam(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) +{ + AcpiTable table =3D { + .sig =3D "MPAM", + .rev =3D 1, + .oem_id =3D vms->oem_id, + .oem_table_id =3D vms->oem_table_id, + }; + struct mpam_stat mpam_s =3D { + .ms =3D MACHINE(vms), + .count =3D 0, + .base_addr =3D vms->memmap[VIRT_MPAM_MSC].base, + .table_data =3D table_data, + }; + + acpi_table_begin(&table, table_data); + + object_child_foreach_recursive(object_get_root(), mpam_add_msc, &mpam_= s); + + acpi_table_end(linker, &table); +} + /* * ACPI spec, Revision 5.1 * 5.2.16 System Resource Affinity Table (SRAT) @@ -1124,6 +1317,10 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuil= dTables *tables) vms->oem_id, vms->oem_table_id); } } + if (vms->mpam) { + acpi_add_table(table_offsets, tables_blob); + build_mpam(tables_blob, tables->linker, vms); + } =20 if (ms->nvdimms_state->is_enabled) { nvdimm_build_acpi(table_offsets, tables_blob, tables->linker, diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 7d9dbc2663..1ded7737f0 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -79,6 +79,7 @@ #include "hw/virtio/virtio-md-pci.h" #include "hw/virtio/virtio-iommu.h" #include "hw/char/pl011.h" +#include "hw/arm/mpam.h" #include "qemu/guest-random.h" =20 #define DEFINE_VIRT_MACHINE_LATEST(major, minor, latest) \ @@ -156,6 +157,7 @@ static const MemMapEntry base_memmap[] =3D { [VIRT_PVTIME] =3D { 0x090a0000, 0x00010000 }, [VIRT_SECURE_GPIO] =3D { 0x090b0000, 0x00001000 }, [VIRT_MMIO] =3D { 0x0a000000, 0x00000200 }, + [VIRT_MPAM_MSC] =3D { 0x0b006000, 0x00004000 * 256 }, /* ...repeating for a total of NUM_VIRTIO_TRANSPORTS, each of that siz= e */ [VIRT_PLATFORM_BUS] =3D { 0x0c000000, 0x02000000 }, [VIRT_SECURE_MEM] =3D { 0x0e000000, 0x01000000 }, @@ -1406,6 +1408,98 @@ static void create_virtio_iommu_dt_bindings(VirtMach= ineState *vms) bdf + 1, vms->iommu_phandle, bdf + 1, 0xffff - = bdf); } =20 +static void create_mpam_msc_cache(VirtMachineState *vms, int level, + hwaddr *base) +{ + VirtMachineClass *vmc =3D VIRT_MACHINE_GET_CLASS(vms); + MachineClass *mc =3D MACHINE_CLASS(vmc); + MachineState *ms =3D MACHINE(vms); + const CPUArchIdList *cpu_list =3D mc->possible_cpu_arch_ids(ms); + DeviceState *dev; + int step, i; + + /* First check if L2 is at socket level */ + if (ms->smp.cache_node_start_level && + ms->smp.cache_node_start_level <=3D level) { + step =3D cpu_list->len / ms->smp.sockets; + /* If not check cluster level */ + } else if (ms->smp.cache_cluster_start_level <=3D level) { + step =3D cpu_list->len / ms->smp.clusters; + /* Must be private then (or non existent?) */ + } else { + step =3D ms->smp.threads; + } + + for (i =3D 0; i < cpu_list->len; i +=3D step) { + dev =3D qdev_new(TYPE_MPAM_MSC_CACHE); + object_property_set_uint(OBJECT(dev), "num-ris", 1, &error_fatal); + object_property_set_uint(OBJECT(dev), "num-partid", 256, &error_fa= tal); + object_property_set_uint(OBJECT(dev), "num-int-partid", 32, + &error_fatal); + object_property_set_uint(OBJECT(dev), "cache-level", level, + &error_fatal); + object_property_set_uint(OBJECT(dev), "cache-type", UNIFIED, + &error_fatal); + object_property_set_uint(OBJECT(dev), "cpu", i, &error_fatal); + sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); + sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, *base); + *base +=3D MPAM_SIZE; + } +} + +static void create_mpam_msc(VirtMachineState *vms, Error **errp) +{ + MachineState *ms =3D MACHINE(vms); + DeviceState *dev; + int i, count =3D 0; + hwaddr base =3D vms->memmap[VIRT_MPAM_MSC].base; + + if (ms->numa_state->num_nodes =3D=3D 0) { + error_setg(errp, + "MPAM support requires NUMA nodes to be specified"); + return; + } + if (!vms->mpam_min_msc) { + for (i =3D 0; i < ms->numa_state->num_nodes; i++) { + if (ms->numa_state->nodes[i].node_mem > 0 && count < 16) { + dev =3D qdev_new(TYPE_MPAM_MSC_MEM); + + object_property_set_uint(OBJECT(dev), "num-ris", 1, + &error_fatal); + object_property_set_uint(OBJECT(dev), "num-partid", 256, + &error_fatal); + object_property_set_uint(OBJECT(dev), "num-int-partid", 32, + &error_fatal); + sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal= ); + sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base); + base +=3D MPAM_SIZE; + } + } + } else { + /* One MSC for all numa nodes with memory */ + int count_with_mem =3D 0; + + for (i =3D 0; i < ms->numa_state->num_nodes; i++) { + if (ms->numa_state->nodes[i].node_mem) { + count_with_mem++; + } + } + dev =3D qdev_new(TYPE_MPAM_MSC_MEM); + object_property_set_uint(OBJECT(dev), "num-ris", count_with_mem, + &error_fatal); + object_property_set_uint(OBJECT(dev), "num-partid", 256, &error_fa= tal); + object_property_set_uint(OBJECT(dev), "num-int-partid", 2, + &error_fatal); + + sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); + sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base); + base +=3D MPAM_SIZE; + } + + create_mpam_msc_cache(vms, 3, &base); + create_mpam_msc_cache(vms, 2, &base); +} + static void create_pcie(VirtMachineState *vms) { hwaddr base_mmio =3D vms->memmap[VIRT_PCIE_MMIO].base; @@ -2280,6 +2374,10 @@ static void machvirt_init(MachineState *machine) =20 create_pcie(vms); =20 + if (vms->mpam) { + create_mpam_msc(vms, &error_fatal); + } + if (has_ged && aarch64 && firmware_loaded && virt_is_acpi_enabled(vms)= ) { vms->acpi_dev =3D create_acpi_ged(vms); } else { @@ -2457,6 +2555,34 @@ static void virt_set_dtb_randomness(Object *obj, boo= l value, Error **errp) vms->dtb_randomness =3D value; } =20 +static bool virt_get_mpam(Object *obj, Error **errp) +{ + VirtMachineState *vms =3D VIRT_MACHINE(obj); + + return vms->mpam; +} + +static void virt_set_mpam(Object *obj, bool value, Error **errp) +{ + VirtMachineState *vms =3D VIRT_MACHINE(obj); + + vms->mpam =3D value; +} + +static bool virt_get_mpam_min_msc(Object *obj, Error **errp) +{ + VirtMachineState *vms =3D VIRT_MACHINE(obj); + + return vms->mpam_min_msc; +} + +static void virt_set_mpam_min_msc(Object *obj, bool value, Error **errp) +{ + VirtMachineState *vms =3D VIRT_MACHINE(obj); + + vms->mpam_min_msc =3D value; +} + static char *virt_get_oem_id(Object *obj, Error **errp) { VirtMachineState *vms =3D VIRT_MACHINE(obj); @@ -3053,6 +3179,14 @@ static void virt_machine_class_init(ObjectClass *oc,= void *data) "guest CPU which implements the = ARM " "Memory Tagging Extension"); =20 + object_class_property_add_bool(oc, "mpam", virt_get_mpam, virt_set_mpa= m); + object_class_property_set_description(oc, "mpam", "Enable MPAM"); + + object_class_property_add_bool(oc, "mpam-min-msc", virt_get_mpam_min_m= sc, + virt_set_mpam_min_msc); + object_class_property_set_description(oc, "mpam-min-msc", + "Use RIS to reduce MSCs exposed.= "); + object_class_property_add_bool(oc, "its", virt_get_its, virt_set_its); object_class_property_set_description(oc, "its", --=20 2.39.2