From patchwork Wed May 13 10:48:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhenyu Zheng X-Patchwork-Id: 186590 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp343577ilb; Wed, 13 May 2020 03:51:31 -0700 (PDT) X-Google-Smtp-Source: APiQypKj04Y+1RiRXg8HQexxCCmp8tzf2JF2o55NINCWYvld6qvh45SToS8A4hQk7kBqbRDzEQKL X-Received: by 2002:a17:906:27d1:: with SMTP id k17mr21028644ejc.134.1589367091080; Wed, 13 May 2020 03:51:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589367091; cv=none; d=google.com; s=arc-20160816; b=nVx81Pejd3nU15Ke05aY3GzdcOnjn0sc/HLDvXMX8vb8S9bywW0Xq7gG4gXjZpM/ct o2dlBS4bG9jgk+9VzRsuWNDcKT9DukRU5bVCmC5nhLNAk318fvjP+wNRQVO0A1JBWap9 5/g5sISpwCs5yuBZFopaHdmpU/c1f73cYENtM7T1yq63bSx3D65DaXkhx5D/FtBsat+Q Nbklsnj9i9oWmS8fqt8XPUp/mjgHi+grd6kMI8MaRXRCdx6Bmnxo6vvH+jwCwEGw9jDN WXEPWlXQaX3yAdFsalJhVqnEU7YIH6GvZIcGBPNjQOn1T4BX+0uojWd/9XNpATjbsf3q eX2g== 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=MippITJs+HY+Ie3gJJ7YcdJnaNHXJlaYH6cyU+PXUwk=; b=blxkIUTh8yrT1Z9GjFGdijFlgwX+MIfbjQTtiA25ibQkNG+MGbr2/xrQgveNHJ9WxJ /nmfp8NntUoJSXvgIYqgDyQmzb3fAuuVIXq6IxlptzqQ32v/tu7zuk+gSjRLbOJq7Q6r HYXBWMVxQonY1EAI4AvsRhpMrLekR8YPMzHjmIs8j2k/5NZg4DbY0J/SORj4ht2BGQ8G Xbsh5QmT3pt4qtPZbMrPfYwkFW1+o3m3S2+mUA3AiLxOyYhkoCCXye4GgDVgW9q8WsP1 b5afqIMuaS4AGFh+wPkxgr3lRue2aXzDN0SyYdTu/lC1yTZOEQva8mBmPlC9+aqLOv5S kaDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HGoA4lNF; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com. [207.211.31.81]) by mx.google.com with ESMTPS id ob20si7245952ejb.401.2020.05.13.03.51.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 May 2020 03:51:31 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HGoA4lNF; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589367089; 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=MippITJs+HY+Ie3gJJ7YcdJnaNHXJlaYH6cyU+PXUwk=; b=HGoA4lNFDUjgLUkjNEK/zpArp3yFbyJnUtjS61VXcL9SUBxTmbJnf75tt2yb4gIKY3rJKs SIQ/UA81MuxX8IXLOfqlPlTYPSywjUTILJbKGkoM/Y63sV5lXu0gqGBCo6YxR2nXpJXKUH P8tdnCuDKqyGixc7QiSHIm1gdLIN6lo= 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-247-neXGSqrPOxiQq04JgzrxxQ-1; Wed, 13 May 2020 06:51:27 -0400 X-MC-Unique: neXGSqrPOxiQq04JgzrxxQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 943D31005512; Wed, 13 May 2020 10:51:16 +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 6BF5E619AE; Wed, 13 May 2020 10:51:16 +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 3B3B04CAB0; Wed, 13 May 2020 10:51:16 +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 04DAnhmj010237 for ; Wed, 13 May 2020 06:49:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id E65AD2166B27; Wed, 13 May 2020 10:49:42 +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 E151D2166BA0 for ; Wed, 13 May 2020 10:49:40 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (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 283681859160 for ; Wed, 13 May 2020 10:49:40 +0000 (UTC) Received: from APC01-HK2-obe.outbound.protection.outlook.com (mail-oln040092255076.outbound.protection.outlook.com [40.92.255.76]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-310-I2UlP8GGMDWsBg0sGmvDWg-1; Wed, 13 May 2020 06:49:37 -0400 X-MC-Unique: I2UlP8GGMDWsBg0sGmvDWg-1 Received: from SG2APC01FT003.eop-APC01.prod.protection.outlook.com (2a01:111:e400:7ebd::46) by SG2APC01HT235.eop-APC01.prod.protection.outlook.com (2a01:111:e400:7ebd::399) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.27; Wed, 13 May 2020 10:49:33 +0000 Received: from TY2PR01MB3113.jpnprd01.prod.outlook.com (10.152.250.56) by SG2APC01FT003.mail.protection.outlook.com (10.152.250.130) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.19 via Frontend Transport; Wed, 13 May 2020 10:49:33 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:02A1F6205F72953C8763AAFDCE2F65F38ADF5A8D6688DC20EA19D2E955AA76B3; UpperCasedChecksum:90DCF3E36E79F99C848A2DF6E7CAB4CA6298153EC320F4FE199E6A688CE442B4; SizeAsReceived:7609; Count:50 Received: from TY2PR01MB3113.jpnprd01.prod.outlook.com ([fe80::b9e6:3960:1f6:7d81]) by TY2PR01MB3113.jpnprd01.prod.outlook.com ([fe80::b9e6:3960:1f6:7d81%7]) with mapi id 15.20.2979.033; Wed, 13 May 2020 10:49:33 +0000 From: Zhenyu Zheng To: libvir-list@redhat.com Subject: [PATCH V5 1/4] cpu: Introduce virCPUarmData and related struts Date: Wed, 13 May 2020 18:48:30 +0800 Message-ID: In-Reply-To: <20200513104832.7390-1-zheng.zhenyu@outlook.com> References: <20200513104832.7390-1-zheng.zhenyu@outlook.com> X-ClientProxiedBy: HK2PR0401CA0023.apcprd04.prod.outlook.com (2603:1096:202:2::33) To TY2PR01MB3113.jpnprd01.prod.outlook.com (2603:1096:404:78::22) X-Microsoft-Original-Message-ID: <20200513104832.7390-2-zheng.zhenyu@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (119.8.114.27) by HK2PR0401CA0023.apcprd04.prod.outlook.com (2603:1096:202:2::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.24 via Frontend Transport; Wed, 13 May 2020 10:49:32 +0000 X-Microsoft-Original-Message-ID: <20200513104832.7390-2-zheng.zhenyu@outlook.com> X-TMN: [WuZfvTvTSc3sginm/UEf7HonHSKiliar] X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 50 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: fbea1eef-48c0-498a-5caa-08d7f72b51fb X-MS-Exchange-SLBlob-MailProps: citmFLqyTFTDPpI75R1qiLOOWK0C9sbnZgMT4PWaMyRhF1ykdIyaegi0D9FkGIPe2g29EsM4TwGOzOd6Jx8A5z2o8WQ41vxX8Gvz4k6mFConPUWW66wWcN1szhrnPqPCILhzeIN/mDWJm6KPzi68FRXf3MfSMGxWPqHXHxvOCZ8QXi4EvfW5xHvvFNvhyIyUXxplZ4F/lDL8dftTrZbnm/zZcoxX0yYB4qWNQ02NRKzbcQEe40yo0VG+f2o8b6t0FBQDaAVibmCLQ8o8c7MRXXVsOWiYw/3YOzUAATkQeTyTLR1H8GETrEesgOj5GecobWXR0wmTTX4NmnY+QJ31DXpsge7b+BcbCBZOlw6ZbS3vKE/NbkTAjL0zfPaY8gBj8lBoWa5FvBT1sEBEA1Rxgk9Da7qJXmWgvPqlOH2WAIX7JHEqP2spgzWcXfRD5sA8Ha9PLje8l+a8o4dEZhsLxemddY+hj3KtQrcky/EdQLiGcp3URmS7YVXA3K17YFTa1J+llMIPQijYtlldNwUxwG1dcyJ6A6v+AxRtec0n4MOtSCJTwdDMmBwgbEdmEzqJRb9CZrcq0YEIC3ooQ+Yq5AohbI+9oG5jj06o+y08X5EfpQSJmdrybbZTUQzdDitlT6QESHnmhiQmlzlDERK3TStJaMSRrjemZl/LOz9aw8ZWwksMBVQPW4EfkmVL7sXWhxuRyPHQ1jEeAUlmkxLdxqZQMKGrgc27wzjd7XMZdI5ADXXZDC5s11fMWGGwmak0URby1Y9NTEu79XfQKC2s7Uj9Q8s/vWioyOwm7xIUKD0= X-MS-TrafficTypeDiagnostic: SG2APC01HT235: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: es4qYM7QbgTzvXbq3uKHXCU2vFDP1sFRMNdMzmtg9sb2CUn8qUCrQnymLBxHxLm6yg/XBHxYTlbieHsrkJmue/3+TnZMQlT2p8mgsDQ+saHTwWVICGV0JVl1lLVUOPg7M8sn0t8MClR2SsDWWWS/Dgh7WNRZiUWM6BUzyctebAJ4E5gjqtHE0pj+OCbi3/qBTUHkMTkAq865le0VmgLv+PwltthBoYOx2QN3ZHtAym+SIpFrFt1mQ7RR5ronzmKF X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:0; SRV:; IPV:NLI; SFV:NSPM; H:TY2PR01MB3113.jpnprd01.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:; DIR:OUT; SFP:1901; X-MS-Exchange-AntiSpam-MessageData: pVcmlQDJ0KTz8vIgPHJGoZ/gf5p/PQEg8K7wbGVSzjV/3oUcFdQyYm5D0Dvy1D61tPhB0AE/pnoWwnjh0jyKu0Ln13bGCN4QvqqusRGUKEbeIEsLypm09Dv01HcDKIBZWX0i/Fpaaqw3wu6zFPSGyQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: fbea1eef-48c0-498a-5caa-08d7f72b51fb X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 May 2020 10:49:33.3013 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SG2APC01HT235 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 04DAnhmj010237 X-loop: libvir-list@redhat.com X-Mailman-Approved-At: Wed, 13 May 2020 06:51:05 -0400 Cc: 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.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Introduce virCPUarmData to virCPUData and related structs to cpu_arm.c for ARM cpus. Signed-off-by: Zhenyu Zheng --- src/cpu/Makefile.inc.am | 1 + src/cpu/cpu.h | 2 ++ src/cpu/cpu_arm.c | 80 ++++++++++++++++++++++++++++++++++++++++- src/cpu/cpu_arm_data.h | 32 +++++++++++++++++ 4 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 src/cpu/cpu_arm_data.h -- 2.20.1 diff --git a/src/cpu/Makefile.inc.am b/src/cpu/Makefile.inc.am index 0abeee87b6..228112a3c6 100644 --- a/src/cpu/Makefile.inc.am +++ b/src/cpu/Makefile.inc.am @@ -9,6 +9,7 @@ CPU_SOURCES = \ cpu/cpu_s390.h \ cpu/cpu_s390.c \ cpu/cpu_arm.h \ + cpu/cpu_arm_data.h \ cpu/cpu_arm.c \ cpu/cpu_ppc64.h \ cpu/cpu_ppc64.c \ diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h index f779d2be17..ec22a183a1 100644 --- a/src/cpu/cpu.h +++ b/src/cpu/cpu.h @@ -27,6 +27,7 @@ #include "cpu_conf.h" #include "cpu_x86_data.h" #include "cpu_ppc64_data.h" +#include "cpu_arm_data.h" typedef struct _virCPUData virCPUData; @@ -36,6 +37,7 @@ struct _virCPUData { union { virCPUx86Data x86; virCPUppc64Data ppc64; + virCPUarmData arm; /* generic driver needs no data */ } data; }; diff --git a/src/cpu/cpu_arm.c b/src/cpu/cpu_arm.c index ee5802198f..1bb0afb762 100644 --- a/src/cpu/cpu_arm.c +++ b/src/cpu/cpu_arm.c @@ -1,6 +1,7 @@ /* * cpu_arm.c: CPU driver for arm CPUs * + * Copyright (C) 2020 Huawei Technologies Co., Ltd. * Copyright (C) 2013 Red Hat, Inc. * Copyright (C) Canonical Ltd. 2012 * @@ -23,12 +24,16 @@ #include "viralloc.h" #include "cpu.h" +#include "cpu_arm.h" #include "cpu_map.h" +#include "virlog.h" #include "virstring.h" #include "virxml.h" #define VIR_FROM_THIS VIR_FROM_CPU +VIR_LOG_INIT("cpu.cpu_arm"); + static const virArch archs[] = { VIR_ARCH_ARMV6L, VIR_ARCH_ARMV7B, @@ -36,6 +41,21 @@ static const virArch archs[] = { VIR_ARCH_AARCH64, }; +typedef struct _virCPUarmVendor virCPUarmVendor; +typedef virCPUarmVendor *virCPUarmVendorPtr; +struct _virCPUarmVendor { + char *name; + unsigned long value; +}; + +typedef struct _virCPUarmModel virCPUarmModel; +typedef virCPUarmModel *virCPUarmModelPtr; +struct _virCPUarmModel { + char *name; + virCPUarmVendorPtr vendor; + virCPUarmData data; +}; + typedef struct _virCPUarmFeature virCPUarmFeature; typedef virCPUarmFeature *virCPUarmFeaturePtr; struct _virCPUarmFeature { @@ -64,6 +84,10 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(virCPUarmFeature, virCPUarmFeatureFree); typedef struct _virCPUarmMap virCPUarmMap; typedef virCPUarmMap *virCPUarmMapPtr; struct _virCPUarmMap { + size_t nvendors; + virCPUarmVendorPtr *vendors; + size_t nmodels; + virCPUarmModelPtr *models; GPtrArray *features; }; @@ -81,12 +105,66 @@ virCPUarmMapNew(void) return map; } +static void +virCPUarmDataClear(virCPUarmData *data) +{ + if (!data) + return; + + virStringListFree(data->features); +} + +static void +virCPUarmDataFree(virCPUDataPtr cpuData) +{ + if (!cpuData) + return; + + virCPUarmDataClear(&cpuData->data.arm); + g_free(cpuData); +} + +static void +virCPUarmModelFree(virCPUarmModelPtr model) +{ + if (!model) + return; + + virCPUarmDataClear(&model->data); + g_free(model->name); + g_free(model); +} + +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virCPUarmModel, virCPUarmModelFree); + +static void +virCPUarmVendorFree(virCPUarmVendorPtr vendor) +{ + if (!vendor) + return; + + g_free(vendor->name); + g_free(vendor); +} + +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virCPUarmVendor, virCPUarmVendorFree); + static void virCPUarmMapFree(virCPUarmMapPtr map) { + size_t i; + if (!map) return; + for (i = 0; i < map->nmodels; i++) + virCPUarmModelFree(map->models[i]); + g_free(map->models); + + for (i = 0; i < map->nvendors; i++) + virCPUarmVendorFree(map->vendors[i]); + g_free(map->vendors); + g_ptr_array_free(map->features, TRUE); g_free(map); @@ -201,7 +279,6 @@ virCPUarmUpdate(virCPUDefPtr guest, return ret; } - static virCPUDefPtr virCPUarmBaseline(virCPUDefPtr *cpus, unsigned int ncpus G_GNUC_UNUSED, @@ -259,6 +336,7 @@ struct cpuArchDriver cpuDriverArm = { .compare = virCPUarmCompare, .decode = NULL, .encode = NULL, + .dataFree = virCPUarmDataFree, .baseline = virCPUarmBaseline, .update = virCPUarmUpdate, .validateFeatures = virCPUarmValidateFeatures, diff --git a/src/cpu/cpu_arm_data.h b/src/cpu/cpu_arm_data.h new file mode 100644 index 0000000000..9b931cb8aa --- /dev/null +++ b/src/cpu/cpu_arm_data.h @@ -0,0 +1,32 @@ +/* + * cpu_arm_data.h: 64-bit arm CPU specific data + * + * Copyright (C) 2020 Huawei Technologies Co., Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; If not, see + * . + * + */ + +#pragma once + +#define VIR_CPU_ARM_DATA_INIT { 0 } + +typedef struct _virCPUarmData virCPUarmData; +struct _virCPUarmData { + unsigned long vendor_id; + unsigned long pvr; + char **features; + size_t nfeatures; +};