From nobody Wed Nov 27 04:37:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701354906; cv=none; d=zohomail.com; s=zohoarc; b=mtkCqolHo9OUiKOiqKWOVib4V0sBRsyC2W9nUEg9lzKU9MZp5GGVosKwvnQYjRDxid+NKrBYoGzjZ6MGLNeWZT3kMlabXSAPUw5V2uRzDBgnrbkaQNiQ5isbfAbxUm6QaFxnBDe/vyym0SLBjn8fAIJ1CLMKjC9ck3OfrE6aG+o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701354906; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=cb8f+4ERS2LFmgEeqVriYNcoskNwV0iZz/vm+/T+QCU=; b=ZUzS9n7bXOn3qcx1wszf2cUx0LVHo+EQ8lrKaLu7IlFHfCoKPWcOYr+G5rRCQFLPJjRhWNDqzQZqVJWY7Oyd4XXDMxAFaQeyP2XKN1Rpef1y/xankVODkl7LR5TdwrrHib9g1ir0R7KWdTAHvvF7/zQ7uByl996JWm/UGaeqKkM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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 1701354906369395.1270972327891; Thu, 30 Nov 2023 06:35:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8i6G-0003wQ-PV; Thu, 30 Nov 2023 09:33:08 -0500 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 1r8i6E-0003s2-Ve; Thu, 30 Nov 2023 09:33:07 -0500 Received: from mgamail.intel.com ([192.55.52.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8i6C-0001Gr-16; Thu, 30 Nov 2023 09:33:06 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:32:46 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:32:36 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701354784; x=1732890784; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ISMaXqLtdhEuyYCRvB604LjEvb5pWdCfmnGTYVK8V4c=; b=ak11wZfzILl/gXjJYsuWOWKk5002A5CWfd+K9lASJZpcuOhANhyr71Dr oUwgOyPhXMS76DJ7f4SeznqoesvrsOq2nZ172ya0z94IAHgx1pP0jPg8O bzod8489bRaDtXz2eALg/H9GP7srVYEJsavXCU7om0FE2lgSD0qpgol+3 fFOLmbzL+aZWmiMo02wv9sMBGgOxOdOvZq9fGjbg+kf1e3oWue7GHTg7T ohKY2s7aotaR0FFHb5pm4OAaKuCyXwaTmvzMiWLO72hJVxDsXxh6/vWpQ SKSakEcAKpVAnpi1aeS4x25zzqEDTnp5s+NxLog3ESRR49pHSidkeTWeP Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479531735" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479531735" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942729902" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942729902" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 14/41] PPC/ppc-core: Offload core-id to PPC specific core abstarction Date: Thu, 30 Nov 2023 22:41:36 +0800 Message-Id: <20231130144203.2307629-15-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: none client-ip=192.55.52.43; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701354907058000006 Content-Type: text/plain; charset="utf-8" From: Zhao Liu PPC (spapr) supports hotplugs at the core granularity (spapr core) and treats core-id as the global id for all cores. But other architectures that support hotplugging at CPU granularity, use core-id as the local id to indicate the core within the parent topology container instand of the global index. To remove potential ambiguity and make the core abstraction available to other architectures, introduce the ppc core abstraction and define the "global" core-id over the ppc specific core. Signed-off-by: Zhao Liu --- MAINTAINERS | 2 + hw/cpu/core.c | 29 ------------ hw/ppc/meson.build | 1 + hw/ppc/pnv.c | 6 +-- hw/ppc/pnv_core.c | 5 ++- hw/ppc/ppc_core.c | 79 +++++++++++++++++++++++++++++++++ hw/ppc/spapr.c | 28 +++++++----- hw/ppc/spapr_cpu_core.c | 6 +-- include/hw/cpu/core.h | 6 --- include/hw/ppc/pnv_core.h | 8 ++-- include/hw/ppc/ppc_core.h | 57 ++++++++++++++++++++++++ include/hw/ppc/spapr_cpu_core.h | 9 ++-- 12 files changed, 175 insertions(+), 61 deletions(-) create mode 100644 hw/ppc/ppc_core.c create mode 100644 include/hw/ppc/ppc_core.h diff --git a/MAINTAINERS b/MAINTAINERS index 564cb776ae80..89e350866d6a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1501,6 +1501,8 @@ F: include/hw/ppc/fdt.h F: hw/ppc/fdt.c F: include/hw/ppc/pef.h F: hw/ppc/pef.c +F: include/hw/ppc/ppc_core.h +F: hw/ppc/ppc_core.c F: pc-bios/slof.bin F: docs/system/ppc/pseries.rst F: docs/specs/ppc-spapr-* diff --git a/hw/cpu/core.c b/hw/cpu/core.c index 495a5c30ffe1..7e274d6aebb7 100644 --- a/hw/cpu/core.c +++ b/hw/cpu/core.c @@ -14,33 +14,6 @@ #include "qapi/error.h" #include "qapi/visitor.h" =20 -static void core_prop_get_core_id(Object *obj, Visitor *v, const char *nam= e, - void *opaque, Error **errp) -{ - CPUCore *core =3D CPU_CORE(obj); - int64_t value =3D core->core_id; - - visit_type_int(v, name, &value, errp); -} - -static void core_prop_set_core_id(Object *obj, Visitor *v, const char *nam= e, - void *opaque, Error **errp) -{ - CPUCore *core =3D CPU_CORE(obj); - int64_t value; - - if (!visit_type_int(v, name, &value, errp)) { - return; - } - - if (value < 0) { - error_setg(errp, "Invalid core id %"PRId64, value); - return; - } - - core->core_id =3D value; -} - static void core_prop_get_nr_threads(Object *obj, Visitor *v, const char *= name, void *opaque, Error **errp) { @@ -82,8 +55,6 @@ static void cpu_core_class_init(ObjectClass *oc, void *da= ta) DeviceClass *dc =3D DEVICE_CLASS(oc); =20 set_bit(DEVICE_CATEGORY_CPU, dc->categories); - object_class_property_add(oc, "core-id", "int", core_prop_get_core_id, - core_prop_set_core_id, NULL, NULL); object_class_property_add(oc, "nr-threads", "int", core_prop_get_nr_th= reads, core_prop_set_nr_threads, NULL, NULL); } diff --git a/hw/ppc/meson.build b/hw/ppc/meson.build index ea44856d43b0..2b40a91a4661 100644 --- a/hw/ppc/meson.build +++ b/hw/ppc/meson.build @@ -2,6 +2,7 @@ ppc_ss =3D ss.source_set() ppc_ss.add(files( 'ppc.c', 'ppc_booke.c', + 'ppc_core.c', )) ppc_ss.add(when: 'CONFIG_FDT_PPC', if_true: [files( 'fdt.c', diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c index 0297871bdd5d..6e92ff8b4f64 100644 --- a/hw/ppc/pnv.c +++ b/hw/ppc/pnv.c @@ -1224,7 +1224,7 @@ static void pnv_chip_icp_realize(Pnv8Chip *chip8, Err= or **errp) /* Map the ICP registers for each thread */ for (i =3D 0; i < chip->nr_cores; i++) { PnvCore *pnv_core =3D chip->cores[i]; - int core_hwid =3D CPU_CORE(pnv_core)->core_id; + int core_hwid =3D POWERPC_CORE(pnv_core)->core_id; =20 for (j =3D 0; j < CPU_CORE(pnv_core)->nr_threads; j++) { uint32_t pir =3D pcc->core_pir(chip, core_hwid) + j; @@ -1443,7 +1443,7 @@ static void pnv_chip_quad_realize_one(PnvChip *chip, = PnvQuad *eq, const char *type) { char eq_name[32]; - int core_id =3D CPU_CORE(pnv_core)->core_id; + int core_id =3D POWERPC_CORE(pnv_core)->core_id; =20 snprintf(eq_name, sizeof(eq_name), "eq[%d]", core_id); object_initialize_child_with_props(OBJECT(chip), eq_name, eq, @@ -1983,7 +1983,7 @@ static void pnv_chip_core_realize(PnvChip *chip, Erro= r **errp) chip->cores[i] =3D pnv_core; object_property_set_int(OBJECT(pnv_core), "nr-threads", chip->nr_threads, &error_fatal); - object_property_set_int(OBJECT(pnv_core), CPU_CORE_PROP_CORE_ID, + object_property_set_int(OBJECT(pnv_core), POWERPC_CORE_PROP_CORE_I= D, core_hwid, &error_fatal); object_property_set_int(OBJECT(pnv_core), "pir", pcc->core_pir(chip, core_hwid), &error_fat= al); diff --git a/hw/ppc/pnv_core.c b/hw/ppc/pnv_core.c index 8c7afe037f00..a90d1ec92bd8 100644 --- a/hw/ppc/pnv_core.c +++ b/hw/ppc/pnv_core.c @@ -267,6 +267,7 @@ static void pnv_core_realize(DeviceState *dev, Error **= errp) PnvCore *pc =3D PNV_CORE(OBJECT(dev)); PnvCoreClass *pcc =3D PNV_CORE_GET_CLASS(pc); CPUCore *cc =3D CPU_CORE(OBJECT(dev)); + PowerPCCore *ppc =3D POWERPC_CORE(cc); const char *typename =3D pnv_core_cpu_typename(pc); Error *local_err =3D NULL; void *obj; @@ -299,7 +300,7 @@ static void pnv_core_realize(DeviceState *dev, Error **= errp) } } =20 - snprintf(name, sizeof(name), "xscom-core.%d", cc->core_id); + snprintf(name, sizeof(name), "xscom-core.%d", ppc->core_id); pnv_xscom_region_init(&pc->xscom_regs, OBJECT(dev), pcc->xscom_ops, pc, name, pcc->xscom_size); =20 @@ -392,7 +393,7 @@ static void pnv_core_class_init(ObjectClass *oc, void *= data) static const TypeInfo pnv_core_infos[] =3D { { .name =3D TYPE_PNV_CORE, - .parent =3D TYPE_CPU_CORE, + .parent =3D TYPE_POWERPC_CORE, .instance_size =3D sizeof(PnvCore), .class_size =3D sizeof(PnvCoreClass), .class_init =3D pnv_core_class_init, diff --git a/hw/ppc/ppc_core.c b/hw/ppc/ppc_core.c new file mode 100644 index 000000000000..4433b54af506 --- /dev/null +++ b/hw/ppc/ppc_core.c @@ -0,0 +1,79 @@ +/* + * Common PPC CPU core abstraction + * + * Copyright (c) 2023 Intel Corporation + * Author: Zhao Liu + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, + * or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "qemu/osdep.h" + +#include "hw/ppc/ppc_core.h" +#include "qapi/error.h" +#include "qapi/visitor.h" + +static void powerpc_core_prop_get_core_id(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + PowerPCCore *core =3D POWERPC_CORE(obj); + int64_t value =3D core->core_id; + + visit_type_int(v, name, &value, errp); +} + +static void powerpc_core_prop_set_core_id(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + PowerPCCore *core =3D POWERPC_CORE(obj); + int64_t value; + + if (!visit_type_int(v, name, &value, errp)) { + return; + } + + if (value < 0) { + error_setg(errp, "Invalid core id %"PRId64, value); + return; + } + + core->core_id =3D value; +} + +static void powerpc_core_class_init(ObjectClass *oc, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(oc); + + object_class_property_add(oc, "core-id", "int", + powerpc_core_prop_get_core_id, + powerpc_core_prop_set_core_id, + NULL, NULL); +} + +static const TypeInfo powerpc_core_type_info =3D { + .name =3D TYPE_POWERPC_CORE, + .parent =3D TYPE_CPU_CORE, + .abstract =3D true, + .class_init =3D powerpc_core_class_init, + .instance_size =3D sizeof(PowerPCCore), +}; + +static void powerpc_core_register_types(void) +{ + type_register_static(&powerpc_core_type_info); +} + +type_init(powerpc_core_register_types) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index df09aa9d6a00..72e9f49da110 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -2713,7 +2713,7 @@ static void spapr_init_cpus(SpaprMachineState *spapr) =20 object_property_set_int(core, "nr-threads", nr_threads, &error_fatal); - object_property_set_int(core, CPU_CORE_PROP_CORE_ID, core_id, + object_property_set_int(core, POWERPC_CORE_PROP_CORE_ID, core_= id, &error_fatal); qdev_realize(DEVICE(core), NULL, &error_fatal); =20 @@ -3889,7 +3889,8 @@ static void spapr_core_unplug(HotplugHandler *hotplug= _dev, DeviceState *dev) MachineState *ms =3D MACHINE(hotplug_dev); SpaprMachineClass *smc =3D SPAPR_MACHINE_GET_CLASS(ms); CPUCore *cc =3D CPU_CORE(dev); - CPUArchId *core_slot =3D spapr_find_cpu_slot(ms, cc->core_id, NULL); + PowerPCCore *ppc =3D POWERPC_CORE(cc); + CPUArchId *core_slot =3D spapr_find_cpu_slot(ms, ppc->core_id, NULL); =20 if (smc->pre_2_10_has_unused_icps) { SpaprCpuCore *sc =3D SPAPR_CPU_CORE(OBJECT(dev)); @@ -3915,10 +3916,11 @@ void spapr_core_unplug_request(HotplugHandler *hotp= lug_dev, DeviceState *dev, int index; SpaprDrc *drc; CPUCore *cc =3D CPU_CORE(dev); + PowerPCCore *ppc =3D POWERPC_CORE(cc); =20 - if (!spapr_find_cpu_slot(MACHINE(hotplug_dev), cc->core_id, &index)) { + if (!spapr_find_cpu_slot(MACHINE(hotplug_dev), ppc->core_id, &index)) { error_setg(errp, "Unable to find CPU core with core-id: %d", - cc->core_id); + ppc->core_id); return; } if (index =3D=3D 0) { @@ -3927,7 +3929,7 @@ void spapr_core_unplug_request(HotplugHandler *hotplu= g_dev, DeviceState *dev, } =20 drc =3D spapr_drc_by_id(TYPE_SPAPR_DRC_CPU, - spapr_vcpu_id(spapr, cc->core_id)); + spapr_vcpu_id(spapr, ppc->core_id)); g_assert(drc); =20 if (!spapr_drc_unplug_requested(drc)) { @@ -3985,6 +3987,7 @@ static void spapr_core_plug(HotplugHandler *hotplug_d= ev, DeviceState *dev) SpaprMachineClass *smc =3D SPAPR_MACHINE_CLASS(mc); SpaprCpuCore *core =3D SPAPR_CPU_CORE(OBJECT(dev)); CPUCore *cc =3D CPU_CORE(dev); + PowerPCCore *ppc =3D POWERPC_CORE(cc); CPUState *cs; SpaprDrc *drc; CPUArchId *core_slot; @@ -3992,11 +3995,11 @@ static void spapr_core_plug(HotplugHandler *hotplug= _dev, DeviceState *dev) bool hotplugged =3D spapr_drc_hotplugged(dev); int i; =20 - core_slot =3D spapr_find_cpu_slot(MACHINE(hotplug_dev), cc->core_id, &= index); + core_slot =3D spapr_find_cpu_slot(MACHINE(hotplug_dev), ppc->core_id, = &index); g_assert(core_slot); /* Already checked in spapr_core_pre_plug() */ =20 drc =3D spapr_drc_by_id(TYPE_SPAPR_DRC_CPU, - spapr_vcpu_id(spapr, cc->core_id)); + spapr_vcpu_id(spapr, ppc->core_id)); =20 g_assert(drc || !mc->has_hotpluggable_cpus); =20 @@ -4047,6 +4050,7 @@ static void spapr_core_pre_plug(HotplugHandler *hotpl= ug_dev, DeviceState *dev, MachineState *machine =3D MACHINE(OBJECT(hotplug_dev)); MachineClass *mc =3D MACHINE_GET_CLASS(hotplug_dev); CPUCore *cc =3D CPU_CORE(dev); + PowerPCCore *ppc =3D POWERPC_CORE(cc); const char *base_core_type =3D spapr_get_cpu_core_type(machine->cpu_ty= pe); const char *type =3D object_get_typename(OBJECT(dev)); CPUArchId *core_slot; @@ -4063,8 +4067,8 @@ static void spapr_core_pre_plug(HotplugHandler *hotpl= ug_dev, DeviceState *dev, return; } =20 - if (cc->core_id % smp_threads) { - error_setg(errp, "invalid core id %d", cc->core_id); + if (ppc->core_id % smp_threads) { + error_setg(errp, "invalid core id %d", ppc->core_id); return; } =20 @@ -4080,14 +4084,14 @@ static void spapr_core_pre_plug(HotplugHandler *hot= plug_dev, DeviceState *dev, return; } =20 - core_slot =3D spapr_find_cpu_slot(MACHINE(hotplug_dev), cc->core_id, &= index); + core_slot =3D spapr_find_cpu_slot(MACHINE(hotplug_dev), ppc->core_id, = &index); if (!core_slot) { - error_setg(errp, "core id %d out of range", cc->core_id); + error_setg(errp, "core id %d out of range", ppc->core_id); return; } =20 if (core_slot->cpu) { - error_setg(errp, "core %d already populated", cc->core_id); + error_setg(errp, "core %d already populated", ppc->core_id); return; } =20 diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index 91fae56573ee..7c2ea1424747 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -292,7 +292,7 @@ static bool spapr_realize_vcpu(PowerPCCPU *cpu, SpaprMa= chineState *spapr, static PowerPCCPU *spapr_create_vcpu(SpaprCpuCore *sc, int i, Error **errp) { SpaprCpuCoreClass *scc =3D SPAPR_CPU_CORE_GET_CLASS(sc); - CPUCore *cc =3D CPU_CORE(sc); + PowerPCCore *ppc =3D POWERPC_CORE(sc); g_autoptr(Object) obj =3D NULL; g_autofree char *id =3D NULL; CPUState *cs; @@ -307,7 +307,7 @@ static PowerPCCPU *spapr_create_vcpu(SpaprCpuCore *sc, = int i, Error **errp) * and the rest are explicitly started up by the guest using an RTAS c= all. */ cs->start_powered_off =3D true; - cs->cpu_index =3D cc->core_id + i; + cs->cpu_index =3D ppc->core_id + i; if (!spapr_set_vcpu_id(cpu, cs->cpu_index, errp)) { return NULL; } @@ -381,7 +381,7 @@ static void spapr_cpu_core_class_init(ObjectClass *oc, = void *data) static const TypeInfo spapr_cpu_core_type_infos[] =3D { { .name =3D TYPE_SPAPR_CPU_CORE, - .parent =3D TYPE_CPU_CORE, + .parent =3D TYPE_POWERPC_CORE, .abstract =3D true, .instance_size =3D sizeof(SpaprCpuCore), .class_size =3D sizeof(SpaprCpuCoreClass), diff --git a/include/hw/cpu/core.h b/include/hw/cpu/core.h index 98ab91647eb2..17f117bd5225 100644 --- a/include/hw/cpu/core.h +++ b/include/hw/cpu/core.h @@ -21,13 +21,7 @@ struct CPUCore { DeviceState parent_obj; =20 /*< public >*/ - int core_id; int nr_threads; }; =20 -/* Note: topology field names need to be kept in sync with - * 'CpuInstanceProperties' */ - -#define CPU_CORE_PROP_CORE_ID "core-id" - #endif diff --git a/include/hw/ppc/pnv_core.h b/include/hw/ppc/pnv_core.h index 4db21229a68b..56c3f6b51f2f 100644 --- a/include/hw/ppc/pnv_core.h +++ b/include/hw/ppc/pnv_core.h @@ -20,9 +20,9 @@ #ifndef PPC_PNV_CORE_H #define PPC_PNV_CORE_H =20 -#include "hw/cpu/core.h" #include "target/ppc/cpu.h" #include "hw/ppc/pnv.h" +#include "hw/ppc/ppc_core.h" #include "qom/object.h" =20 #define TYPE_PNV_CORE "powernv-cpu-core" @@ -31,7 +31,7 @@ OBJECT_DECLARE_TYPE(PnvCore, PnvCoreClass, =20 struct PnvCore { /*< private >*/ - CPUCore parent_obj; + PowerPCCore parent_obj; =20 /*< public >*/ PowerPCCPU **threads; @@ -43,8 +43,10 @@ struct PnvCore { }; =20 struct PnvCoreClass { - DeviceClass parent_class; + /*< private >*/ + PowerPCCoreClass parent_class; =20 + /*< public >*/ const MemoryRegionOps *xscom_ops; uint64_t xscom_size; }; diff --git a/include/hw/ppc/ppc_core.h b/include/hw/ppc/ppc_core.h new file mode 100644 index 000000000000..bcc83e426e3f --- /dev/null +++ b/include/hw/ppc/ppc_core.h @@ -0,0 +1,57 @@ +/* + * Common PPC CPU core abstraction header + * + * Copyright (c) 2023 Intel Corporation + * Author: Zhao Liu + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, + * or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef HW_PPC_CORE_H +#define HW_PPC_CORE_H + +#include "hw/cpu/core.h" +#include "hw/qdev-core.h" +#include "qom/object.h" + +#define TYPE_POWERPC_CORE "powerpc-core" + +OBJECT_DECLARE_TYPE(PowerPCCore, PowerPCCoreClass, POWERPC_CORE) + +struct PowerPCCoreClass { + /*< private >*/ + CPUCoreClass parent_class; + + /*< public >*/ +}; + +struct PowerPCCore { + /*< private >*/ + CPUCore parent_obj; + + /*< public >*/ + /* + * The system-wide id for core, not the sub core-id within the + * parent container (which is above the core level). + */ + int core_id; +}; + +/* + * Note: topology field names need to be kept in sync with + * 'CpuInstanceProperties' + */ +#define POWERPC_CORE_PROP_CORE_ID "core-id" + +#endif /* HW_PPC_CORE_H */ diff --git a/include/hw/ppc/spapr_cpu_core.h b/include/hw/ppc/spapr_cpu_cor= e.h index 69a52e39b850..db3e515051ca 100644 --- a/include/hw/ppc/spapr_cpu_core.h +++ b/include/hw/ppc/spapr_cpu_core.h @@ -9,7 +9,7 @@ #ifndef HW_SPAPR_CPU_CORE_H #define HW_SPAPR_CPU_CORE_H =20 -#include "hw/cpu/core.h" +#include "hw/ppc/ppc_core.h" #include "hw/qdev-core.h" #include "target/ppc/cpu-qom.h" #include "target/ppc/cpu.h" @@ -23,7 +23,7 @@ OBJECT_DECLARE_TYPE(SpaprCpuCore, SpaprCpuCoreClass, =20 struct SpaprCpuCore { /*< private >*/ - CPUCore parent_obj; + PowerPCCore parent_obj; =20 /*< public >*/ PowerPCCPU **threads; @@ -32,7 +32,10 @@ struct SpaprCpuCore { }; =20 struct SpaprCpuCoreClass { - DeviceClass parent_class; + /*< private >*/ + PowerPCCoreClass parent_class; + + /*< public >*/ const char *cpu_type; }; =20 --=20 2.34.1