From nobody Mon Feb 9 23:00:10 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) client-ip=216.205.24.74; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-74.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=foxmail.com ARC-Seal: i=1; a=rsa-sha256; t=1585304551; cv=none; d=zohomail.com; s=zohoarc; b=BmQbmwKJggBqIdngRR8yf1+vyn24wpbmmsutxEcqZwQExzI1Xh3tav2rSE31Z9LbIruL2cLLsQdt8tejKVbIxxL39e4RhbHgzs62UojLP+4urMYPjSvOPcGoarVbzZmiPyxyqgmggoPEeIY7Un5I+lbwCnWymvbTb0cq/5mKSZ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585304551; 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:References:Sender:Subject:To; bh=p1vzPHXg8q0PAKoCjwJJYAr9ixaRVYOgjVJU6NQbkzY=; b=DzmJ8BulKubbLH0juHvH4sqe4W4KdNv+EswMlvtX1KmtRXuK/MCfavoktMpCd8bB55Fe60I2c0sQmWnUTzaSro5fP7qEuVJdrSRa9uv2+kVvXNS4xLQe0Fo8uWisnblPcb/YeIj1T02BagDaOP4RwJ2IFm/DAarQu4AGts/W83w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [216.205.24.74]) by mx.zohomail.com with SMTPS id 1585304551686919.9006688845997; Fri, 27 Mar 2020 03:22:31 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-61-VJ1FC-bCPW-sLpYv_6x2tQ-1; Fri, 27 Mar 2020 06:22:28 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1B5DE107B7DE; Fri, 27 Mar 2020 10:22:23 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E5B9F5C545; Fri, 27 Mar 2020 10:22:22 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 94BF38A04F; Fri, 27 Mar 2020 10:22:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02R8wnwh030141 for ; Fri, 27 Mar 2020 04:58:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id CA8542166B2C; Fri, 27 Mar 2020 08:58:49 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C686C2166B2B for ; Fri, 27 Mar 2020 08:58:47 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E2E928F7835 for ; Fri, 27 Mar 2020 08:58:46 +0000 (UTC) Received: from qq.com (out203-205-221-157.mail.qq.com [203.205.221.157]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-347-TpRDHh80PsWltMF0_LmdxQ-1; Fri, 27 Mar 2020 04:58:43 -0400 Received: from localhost.localdomain ([111.21.171.11]) by newxmesmtplogicsvrsza3.qq.com (NewEsmtp) with SMTP id D1E3CE25; Fri, 27 Mar 2020 16:52:30 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585304550; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=p1vzPHXg8q0PAKoCjwJJYAr9ixaRVYOgjVJU6NQbkzY=; b=PIYH2GvHwiodOuMxG3i3jJQcm2+QyS61fzgX4WL6VkQ36wxKIz/mcD0wMsY2ATVj/M03d/ qACP6A3pnFVYkfSe0WvZxvvK9FuvjG2/S7DyLBSO6kmWz+3KCHSrPHI9cVwAwUaEjIoKQp E32OsvlladHJA0mWKAVJ48CHP5Wg/6I= X-MC-Unique: VJ1FC-bCPW-sLpYv_6x2tQ-1 X-MC-Unique: TpRDHh80PsWltMF0_LmdxQ-1 X-QQ-mid: xmsmtpt1585299239tvklkapqk X-QQ-XMAILINFO: OGylKZV5Pv8GgWhfqsM++TJbzmpxW56bu9MKSbiFDKIMs7r6Gwn/72/7zPB9xs 2dSmtpHD1qbO194U7rR43m5j1wsWXpLypqeGrEA4rAJKtoLss0g7Ht750VIfw3EcsjOBLoNuuY+Y 2mZXGmQ92+EeCmJqN5VnsIW9aA7mjGWVh9CJZ84hnw9nW1CdbmCxLICUdEQRMmp9kKsyZCbGaVlo OJDqFump4Bb7LHBLyVEl/vB2oW39lcyt3Mh8TsmWXG2rW5HBVB52WKeYBa0Aa0+DzF0lv5uTPvx7 eX2FmDHAT8G17dg7rLHIcMHptWklPWCIuTrf0Bnub0HltyCrScg0PDRKYzMJ6bg994mm9orNXU/p d4kAZXwD8gNsw1R2QFr8j+vXUlYpotXjdlIgukLPEEvMwpEL2n4ANK9n4imCbwxJPv9TmEbT5Wcw wgv/3yAd7YCwUDcgoJB4UYB7UTVvnEBEKvMYGokjHkNv4fp9UtriIuzQXLhNDeoTL12l/BYwCpLC szmuw1kAykpZ8dizKcQj+hN8WFCaJcT44iGfaNBZ2IK4xAV5imT1OUUSUu0/QGusr6WqFG18a3vo TzSpO4AD7YYGctBQAQTmqSCiY73bftadmkdN6YKcfw5kRfw2hZbX0r/8QnWmHM2S5p8qkw9cDmxt OR91xFq3DERTYg From: Zhenyu Zheng To: libvir-list@redhat.com Subject: [PATCH 4/5] cpu: Add helper functions to parse vendor and model for ARM Date: Fri, 27 Mar 2020 16:52:23 +0800 Message-Id: <20200327085220.1811-5-zheng.zhenyu@foxmail.com> In-Reply-To: <20200327085220.1811-1-zheng.zhenyu@foxmail.com> References: <20200327085220.1811-1-zheng.zhenyu@foxmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 02R8wnwh030141 X-loop: libvir-list@redhat.com X-Mailman-Approved-At: Fri, 27 Mar 2020 06:21:59 -0400 Cc: Zhenyu Zheng , Zhenyu Zheng X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Add helper functions to parse vendor and model for ARM and use them as callback when load maps. Signed-of-by: Zhenyu Zheng --- src/cpu/cpu_arm.c | 143 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 142 insertions(+), 1 deletion(-) diff --git a/src/cpu/cpu_arm.c b/src/cpu/cpu_arm.c index 2a05f43118..969025b5cf 100644 --- a/src/cpu/cpu_arm.c +++ b/src/cpu/cpu_arm.c @@ -181,6 +181,147 @@ virCPUarmMapFeatureFind(virCPUarmMapPtr map, return NULL; } =20 +static virCPUarmVendorPtr +armVendorFindByID(virCPUarmMapPtr map, + unsigned long vendor_id) +{ + size_t i; + + for (i =3D 0; i < map->nvendors; i++) { + if (map->vendors[i]->value =3D=3D vendor_id) + return map->vendors[i]; + } + + return NULL; +} + + +static virCPUarmVendorPtr +armVendorFindByName(virCPUarmMapPtr map, + const char *name) +{ + size_t i; + + for (i =3D 0; i < map->nvendors; i++) { + if (STREQ(map->vendors[i]->name, name)) + return map->vendors[i]; + } + + return NULL; +} + + +static int +armVendorParse(xmlXPathContextPtr ctxt, + const char *name, + void *data) +{ + virCPUarmMapPtr map =3D (virCPUarmMapPtr)data; + virCPUarmVendorPtr vendor =3D NULL; + int ret =3D -1; + + if (VIR_ALLOC(vendor) < 0) + return ret; + + vendor->name =3D g_strdup(name); + + if (armVendorFindByName(map, vendor->name)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("CPU vendor %s already defined"), vendor->name); + goto cleanup; + } + + if (virXPathULongHex("string(@value)", ctxt, &vendor->value) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("Missing CPU vendor value")); + goto cleanup; + } + + if (armVendorFindByID(map, vendor->value)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("CPU vendor value 0x%2lx already defined"), vendo= r->value); + goto cleanup; + } + + if (VIR_APPEND_ELEMENT(map->vendors, map->nvendors, vendor) < 0) + goto cleanup; + + ret =3D 0; + + cleanup: + armVendorFree(vendor); + return ret; + +} + +static virCPUarmModelPtr +armModelFind(virCPUarmMapPtr map, + const char *name) +{ + size_t i; + + for (i =3D 0; i < map->nmodels; i++) { + if (STREQ(map->models[i]->name, name)) + return map->models[i]; + } + + return NULL; +} + +static int +armModelParse(xmlXPathContextPtr ctxt, + const char *name, + void *data) +{ + virCPUarmMapPtr map =3D (virCPUarmMapPtr)data; + virCPUarmModel *model; + xmlNodePtr *nodes =3D NULL; + char *vendor =3D NULL; + int ret =3D -1; + + if (VIR_ALLOC(model) < 0) + goto error; + + model->name =3D g_strdup(name); + + if (armModelFind(map, model->name)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("CPU model %s already defined"), model->name); + goto error; + } + + if (virXPathBoolean("boolean(./vendor)", ctxt)) { + vendor =3D virXPathString("string(./vendor/@name)", ctxt); + if (!vendor) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Invalid vendor element in CPU model %s"), + model->name); + goto error; + } + + if (!(model->vendor =3D armVendorFindByName(map, vendor))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unknown vendor %s referenced by CPU model %s= "), + vendor, model->name); + goto error; + } + } + + if (VIR_APPEND_ELEMENT(map->models, map->nmodels, model) < 0) + goto error; + + ret =3D 0; + + cleanup: + VIR_FREE(vendor); + VIR_FREE(nodes); + return ret; + + error: + armModelFree(model); + goto cleanup; +} + static int virCPUarmMapFeatureParse(xmlXPathContextPtr ctxt G_GNUC_UNUSED, const char *name, @@ -210,7 +351,7 @@ virCPUarmLoadMap(void) =20 map =3D virCPUarmMapNew(); =20 - if (cpuMapLoad("arm", NULL, virCPUarmMapFeatureParse, NULL, map) < 0) + if (cpuMapLoad("arm", armVendorParse, virCPUarmMapFeatureParse, armMod= elParse, map) < 0) return NULL; =20 return g_steal_pointer(&map); --=20 2.26.0.windows.1