提交 00852313 编写于 作者: Z Zhenyu Zheng 提交者: Jiri Denemark

cpu: Introduce virCPUarmData and related struts

Introduce virCPUarmData to virCPUData and related
structs to cpu_arm.c for ARM cpus.
Signed-off-by: NZhenyu Zheng <zheng.zhenyu@outlook.com>
Message-Id: <TY2PR01MB31130D12A95144FF88C1E32499BF0@TY2PR01MB3113.jpnprd01.prod.outlook.com>
Reviewed-by: NJiri Denemark <jdenemar@redhat.com>
上级 8e3b77a0
......@@ -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 \
......
......@@ -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;
};
......
/*
* 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);
......@@ -259,6 +337,7 @@ struct cpuArchDriver cpuDriverArm = {
.compare = virCPUarmCompare,
.decode = NULL,
.encode = NULL,
.dataFree = virCPUarmDataFree,
.baseline = virCPUarmBaseline,
.update = virCPUarmUpdate,
.validateFeatures = virCPUarmValidateFeatures,
......
/*
* 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
* <http://www.gnu.org/licenses/>.
*
*/
#pragma once
#define VIR_CPU_ARM_DATA_INIT { 0 }
typedef struct _virCPUarmData virCPUarmData;
struct _virCPUarmData {
unsigned long vendor_id;
unsigned long pvr;
char **features;
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册