From patchwork Fri Apr 10 07:33:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ZhengZhenyu X-Patchwork-Id: 185346 Delivered-To: patch@linaro.org Received: by 2002:a92:de47:0:0:0:0:0 with SMTP id e7csp462459ilr; Fri, 10 Apr 2020 00:34:53 -0700 (PDT) X-Google-Smtp-Source: APiQypKamhe4vHI7mNG6EoM97zDxhC/ii8Ak9tds1Rt276ZwTKVIgXPYMco8e8RMx0J5YYhX5GEX X-Received: by 2002:a25:3b08:: with SMTP id i8mr5700215yba.402.1586504093004; Fri, 10 Apr 2020 00:34:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586504093; cv=none; d=google.com; s=arc-20160816; b=eC7sgq87zSmBDjbAEJiz5FlnXIaLiaRkss+XSe3w5xnJOBFq6sLq5xysFg3hCF98Qc bl5Ja3GPROw8dqrFaHPHB+9vOckVlCa5C56TcXAbVHtjEcx6zr32Fd4O4LdghfzQnwP2 vyWX/WAEaXnaZGYyoUkQQsh+DnraZ9U2SZGH1VHITdsaSLgf00d/KKxeC/XvdP681GNE F5KCyvPnHGvJ4mr7Tqfh58QXpCQ6KHlCLICUOJHVMZhsIvHBXQGTiAb/xw9OiHlOnV6h o1IPB9l5eh+PkUTLeiI+b5nEBqc06xOaDRaNc+jmNsSe613SAPHpUotwLiK/Onlh7s5I i9nA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:errors-to:sender:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:cc :mime-version:references:in-reply-to:message-id:date:subject:to:from :delivered-to:dkim-signature; bh=ZSFB2VtBiv2RNJzi8+3nLgmEbPeJVPv26OPyJri9mVo=; b=uwzmNHWRcoaLtQhMN5ZFAInFkZnKD2ttN/XwiZWelVSq/h3BVQirJ8iJNE3W/sPhNQ FF4M+cIoAD1dKTkJuaVoyr/e8kNhD4fB45TMTw/kescs4zf1njLa5P6kClD5O799XSJZ rwIyKaRTfwKrrl/G9LXLedPBb/oWMBK7N9aX5LLmTVugj8IfuZWlDncVWkbmqhmXtYJF zD7jIC0+syNNa2txKruafVxXnaTJNobcwlrPhz4255W+NSsg8lEfLeOUSQ2QE1ZsHbuv 2LbUHiqnwMRlmUJemh8ijWvh8XMOChqXpWST8nokA+S8D8mgMEBAwc29XExW5PmKiTxf seUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=eGv+C5Of; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com. [205.139.110.120]) by mx.google.com with ESMTPS id i8si1364452ybi.237.2020.04.10.00.34.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Apr 2020 00:34:52 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=eGv+C5Of; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=foxmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586504092; 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=ZSFB2VtBiv2RNJzi8+3nLgmEbPeJVPv26OPyJri9mVo=; b=eGv+C5Oflmq+qbBeJIB5TIko4Rhn58Pdm40oNGAwXDYIa/M8b3BZV3mUIL/MQyUamjPMnT LI9UXHHiIRp8tDxt3ndCmoirLu4aEvdPL9KrPM0dWrI76euM/VFT+0Rs1h4tM4C0BMLwqv eJ1gFSJbJOjpwQ6vIVZQei2krXBR0Z8= 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-330-xRn1apOFO8CCJQ-MPQ0Nxg-1; Fri, 10 Apr 2020 03:34:49 -0400 X-MC-Unique: xRn1apOFO8CCJQ-MPQ0Nxg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D2EC0DB61; Fri, 10 Apr 2020 07:34:43 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 639E496B9B; Fri, 10 Apr 2020 07:34:42 +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 3E28018089CD; Fri, 10 Apr 2020 07:34:38 +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 03A7YaVm031172 for ; Fri, 10 Apr 2020 03:34:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id 25B4612253F; Fri, 10 Apr 2020 07:34:36 +0000 (UTC) Delivered-To: libvir-list@redhat.com 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 21A6C12254B for ; Fri, 10 Apr 2020 07:34:33 +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 DB076185A78E for ; Fri, 10 Apr 2020 07:34:33 +0000 (UTC) Received: from qq.com (out203-205-221-205.mail.qq.com [203.205.221.205]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-480-9Zl9VlzoNy2mIA_5pvspQg-1; Fri, 10 Apr 2020 03:34:30 -0400 X-MC-Unique: 9Zl9VlzoNy2mIA_5pvspQg-1 Received: from localhost.localdomain ([111.21.171.11]) by newxmesmtplogicsvrsza7.qq.com (NewEsmtp) with SMTP id 89629C7D; Fri, 10 Apr 2020 15:34:22 +0800 X-QQ-mid: xmsmtpt1586504062t3c4a9cix X-QQ-XMAILINFO: OHMgCzXrKqNtlskXjs9Lf+EyuAxBbFIUekf7a5uAGJclzUXwwl9lGAIaDUS49x yVqx5jK6AoVYP/REUZKH4vDMGysmrEoAlsR2Pwvj2x8bFLI31aW8+DKmHfx9BjHyChqu4hz3qdIW BqyBzm+BPaELhbtgrvl2I+3ND6VvQ6dTaANl1KMtJI6d217f/psFGepKVsnptmnJJpQtjWvn6qN6 ukrOoJ26KqzYAkK5ijkMg9XUxEGMuEaTNExhZKWhl41CH8nH36n7GAaq6wwpqw03pUZ6i/H115WO iSarbOf8Xh0BK8FUX864x8MW6ZFJU4IrguSh8ajtWEg89B8Ng7VLuaFIJwA6MOCaRFr6CPn+hJc8 cR/FvnWO7GJ1ybaOZAaw5ZgZaxPlK3EbOiXwFT8/hAPK/qj5v9F0nR68lelki5ZEXy3tsPinx0pm koESgWrmfmmr9SAxeu+Z/ba41G+v3BaXuhQYea9dSdq3ZmCdNyY8v3QtslLVE= From: ZhengZhenyu To: libvir-list@redhat.com Subject: Date: Fri, 10 Apr 2020 15:33:55 +0800 Message-Id: <20200410073410.3303-1-zheng.zhenyu@foxmail.com> In-Reply-To: <20200402090354.2193-5-zheng.zhenyu@foxmail.com> References: <20200402090354.2193-5-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 03A7YaVm031172 X-loop: libvir-list@redhat.com Cc: ZhengZhenyu , 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.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com From: ZhengZhenyu 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 | 171 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 170 insertions(+), 1 deletion(-) -- 2.26.0.windows.1 diff --git a/src/cpu/cpu_arm.c b/src/cpu/cpu_arm.c index d8f571cae3..24404eac2c 100644 --- a/src/cpu/cpu_arm.c +++ b/src/cpu/cpu_arm.c @@ -206,6 +206,174 @@ virCPUarmMapFeatureParse(xmlXPathContextPtr ctxt G_GNUC_UNUSED, return 0; } +static virCPUarmVendorPtr +virCPUarmVendorFindByID(virCPUarmMapPtr map, + unsigned long vendor_id) +{ + size_t i; + + for (i = 0; i < map->nvendors; i++) { + if (map->vendors[i]->value == vendor_id) + return map->vendors[i]; + } + + return NULL; +} + + +static virCPUarmVendorPtr +virCPUarmVendorFindByName(virCPUarmMapPtr map, + const char *name) +{ + size_t i; + + for (i = 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 = data; + virCPUarmVendorPtr vendor = NULL; + int ret = -1; + + if (VIR_ALLOC(vendor) < 0) + return ret; + + vendor->name = 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 = 0; + + cleanup: + virCPUarmVendorFree(vendor); + return ret; + +} + +static virCPUarmModelPtr +virCPUarmModelFind(virCPUarmMapPtr map, + const char *name) +{ + size_t i; + + for (i = 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 = 0; i < map->nmodels; i++) { + if (map->models[i]->data.pvr == pvr) + return map->models[i]; + } + + return NULL; +} +#endif + +static int +virCPUarmModelParse(xmlXPathContextPtr ctxt, + const char *name, + void *data) +{ + virCPUarmMapPtr map = data; + virCPUarmModel *model; + g_autofree xmlNodePtr *nodes = NULL; + g_autofree char *vendor = NULL; + + if (VIR_ALLOC(model) < 0) + goto error; + + model->name = 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 = 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 = 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) { @@ -213,7 +381,8 @@ virCPUarmLoadMap(void) map = virCPUarmMapNew(); - if (cpuMapLoad("arm", NULL, virCPUarmMapFeatureParse, NULL, map) < 0) + if (cpuMapLoad("arm", virCPUarmVendorParse, virCPUarmMapFeatureParse, + virCPUarmModelParse, map) < 0) return NULL; return g_steal_pointer(&map);