From nobody Tue Feb 10 21:59:56 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1587539579; cv=none; d=zohomail.com; s=zohoarc; b=FXzexG53DAB8p6IMGZqxZsdhAWHzXlsQiggQ2XdYjkLmKEQKwnC0HNNFa0G2vQPW1lcXPq16JzBR050F3w9pMandT5mxQtmeJnjGqajehd4qhE5WjleeIr1qwmUcdfy6ivX+agMRv34O4QVzLh8EPlgaOqMbaoQswFCNZcmw/ds= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587539579; 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=pjmrkiB3tEZqJxOR97oVLXtkSzkjSvy9kSJyJuCgmxQ=; b=FvoxjHPqxxt6eogWxBtgESwlPGk9R2Y+C9oaXnTtqjU4mNAlan4A3vb/ecO/Jv/djd9/MrCIMCyY+qndZSKDenx1uymDwKNVk4qGeeQVwH0/dcEsRIjKY7N5fB9JulV4HGRzZcIeJfBxfRoEj9ccFO3QZSXazhXzcvZLUvqvryE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1587539579574286.66625788347324; Wed, 22 Apr 2020 00:12:59 -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-503-8fjo1YmbNmm17l82HSNJBQ-1; Wed, 22 Apr 2020 03:12:56 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 29B988018A5; Wed, 22 Apr 2020 07:12:51 +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 02EE876E69; Wed, 22 Apr 2020 07:12:51 +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 AED35941BC; Wed, 22 Apr 2020 07:12:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 03M7CnuY010562 for ; Wed, 22 Apr 2020 03:12:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8DBF0FFE6; Wed, 22 Apr 2020 07:12:49 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 89E71F77BD for ; Wed, 22 Apr 2020 07:12:46 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.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 A6CC0185A78E for ; Wed, 22 Apr 2020 07:12:46 +0000 (UTC) Received: from qq.com (out203-205-221-190.mail.qq.com [203.205.221.190]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-160-NSmxK42ePjagZ4S8PVgcUQ-1; Wed, 22 Apr 2020 03:12:43 -0400 Received: from localhost.localdomain ([111.21.171.11]) by newxmesmtplogicsvrsza5.qq.com (NewEsmtp) with SMTP id 2DD1AA27; Wed, 22 Apr 2020 15:11:29 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587539578; 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=pjmrkiB3tEZqJxOR97oVLXtkSzkjSvy9kSJyJuCgmxQ=; b=YWY8QTZRfH578G/u4oNFAMYHPZAN6r+ncN7N3kA3qn9g3rSeqQUxlwdhaSShOmMQXWRKcS pHIU1/4gQKIZVXcBJvTfn28QWIvKDiozcRk8D5q7n6X3elI1G6PUL7Vh0IbreyMTCz4gIi vbcM7rQr3aZ/bbQ3LlyI3uc6aiZo5a8= X-MC-Unique: 8fjo1YmbNmm17l82HSNJBQ-1 X-MC-Unique: NSmxK42ePjagZ4S8PVgcUQ-1 X-QQ-mid: xmsmtpt1587539544t5hrngpc1 X-QQ-XMAILINFO: NYYDu0KrGl4J1/xanj2W3X9SjfB7HZe6SDnwaxoZmrIo3tfhISji/OxFQGZD3q QGlSfOCyNmA9ri7vHmHHtsv6re2a7kfA1+tZeGy6AVKFfTwnx7UAXDZwN8F+xK/ikCGkX2B6bg82 REjnvsg4w69rHGM9ptcUwIPs5A2RXIxRicNjVlJk2BeegRrssvZ0L9TTHk66k0PBiGbS3x8L4dfu 9Q84e+H842M42PSBKWiWdYXzB1pszuNAB2vRdcTG3IAAJVVF0OcHklOIh9my4b00QrkX4++NxwNk jqw9z8ohat5bB3x/NfJOIk75AvxFVdw6MEpk/dDFdT0t1cq0wXZDWy4U+ngol1q/tQ4dVE4I/gEi hU2F4D8SKHIYFcTqZBPSAB7QLYYhWej5RZWy67sO59JIUCXeXY/MokjiAJaZrpLWjPKTKPUpWjti Cj8mRdBNZ/DleIaCT2TyCgEOQhghVtLh2UsykbQ3PY80jlZK86yAtg24RESOdNbgJlR+lGsHoW9/ YtywG925ja98XNxpZQppFVHGffxO8stUcBHMNybDoaS1xJTG6mC8o+g8rz/iha3NVr6Zbz6ubGmC eRrDGTKPnULZq7CgZmuUxY7NtaSO2FPVNELbVxXldEAWB+0ILAPQgMB1rKjXRNH1FzUSzhSADnez XaHQ== From: ZhengZhenyu To: libvir-list@redhat.com Subject: [PATCH V3 4/5] cpu: Add helper funtions to parse vendor and model Date: Wed, 22 Apr 2020 15:11:22 +0800 Message-Id: <20200422071119.2026-5-zheng.zhenyu@foxmail.com> In-Reply-To: <20200422071119.2026-1-zheng.zhenyu@foxmail.com> References: <20200422071119.2026-1-zheng.zhenyu@foxmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 03M7CnuY010562 X-loop: libvir-list@redhat.com Cc: Zhenyu Zheng , ZhengZhenyu 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.11 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 from xml for ARM arch, and use them as callbacks when load cpu maps. Signed-off-by: Zhenyu Zheng --- src/cpu/cpu_arm.c | 173 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 170 insertions(+), 3 deletions(-) diff --git a/src/cpu/cpu_arm.c b/src/cpu/cpu_arm.c index 2009904cc9..6e9ff9bf11 100644 --- a/src/cpu/cpu_arm.c +++ b/src/cpu/cpu_arm.c @@ -204,6 +204,174 @@ virCPUarmMapFeatureParse(xmlXPathContextPtr ctxt G_GN= UC_UNUSED, return 0; } =20 +static virCPUarmVendorPtr +virCPUarmVendorFindByID(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 +virCPUarmVendorFindByName(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 +virCPUarmVendorParse(xmlXPathContextPtr ctxt, + const char *name, + void *data) +{ + virCPUarmMapPtr map =3D data; + virCPUarmVendorPtr vendor =3D NULL; + int ret =3D -1; + + if (VIR_ALLOC(vendor) < 0) + return ret; + + vendor->name =3D g_strdup(name); + + if (virCPUarmVendorFindByName(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 (virCPUarmVendorFindByID(map, vendor->value)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("CPU vendor value 0x%2lx already defined"), + vendor->value); + goto cleanup; + } + + if (VIR_APPEND_ELEMENT(map->vendors, map->nvendors, vendor) < 0) + goto cleanup; + + ret =3D 0; + + cleanup: + virCPUarmVendorFree(vendor); + return ret; + +} + +static virCPUarmModelPtr +virCPUarmModelFind(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; +} + +#if defined(__aarch64__) +static virCPUarmModelPtr +virCPUarmModelFindByPVR(virCPUarmMapPtr map, + unsigned long pvr) +{ + size_t i; + + for (i =3D 0; i < map->nmodels; i++) { + if (map->models[i]->data.pvr =3D=3D pvr) + return map->models[i]; + } + + return NULL; +} +#endif + +static int +virCPUarmModelParse(xmlXPathContextPtr ctxt, + const char *name, + void *data) +{ + virCPUarmMapPtr map =3D data; + virCPUarmModel *model; + g_autofree xmlNodePtr *nodes =3D NULL; + g_autofree char *vendor =3D NULL; + + if (VIR_ALLOC(model) < 0) + goto error; + + model->name =3D g_strdup(name); + + if (virCPUarmModelFind(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 virCPUarmVendorFindByName(map, vendor))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unknown vendor %s referenced by CPU model %s= "), + vendor, model->name); + goto error; + } + } + + if (!virXPathBoolean("boolean(./pvr)", ctxt)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Missing PVR information for CPU model %s"), + model->name); + goto error; + } + + if (virXPathULongHex("string(./pvr/@value)", ctxt, &model->data.pvr) <= 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Missing or invalid PVR value in CPU model %s"), + model->name); + goto error; + } + + if (VIR_APPEND_ELEMENT(map->models, map->nmodels, model) < 0) + goto error; + + return 0; + + error: + virCPUarmModelFree(model); + return -1; +} + static virCPUarmMapPtr virCPUarmLoadMap(void) { @@ -211,8 +379,8 @@ virCPUarmLoadMap(void) =20 map =3D virCPUarmMapNew(); =20 - if (cpuMapLoad("arm", NULL, virCPUarmMapFeatureParse, NULL, map) < 0) - return NULL; + if (cpuMapLoad("arm", virCPUarmVendorParse, virCPUarmMapFeatureParse, + virCPUarmModelParse, map) < 0) =20 return g_steal_pointer(&map); } @@ -273,7 +441,6 @@ virCPUarmUpdate(virCPUDefPtr guest, return ret; } =20 - static virCPUDefPtr virCPUarmBaseline(virCPUDefPtr *cpus, unsigned int ncpus G_GNUC_UNUSED, --=20 2.26.0.windows.1