2012-07-12 15:28:17 +00:00
|
|
|
/*
|
|
|
|
* cpu_arm.c: CPU driver for arm CPUs
|
|
|
|
*
|
2020-05-13 10:48:30 +00:00
|
|
|
* Copyright (C) 2020 Huawei Technologies Co., Ltd.
|
maint: avoid 'const fooPtr' in cpu files
'const fooPtr' is the same as 'foo * const' (the pointer won't
change, but it's contents can). But in general, if an interface
is trying to be const-correct, it should be using 'const foo *'
(the pointer is to data that can't be changed).
Fix up offenders in src/cpu.
* src/cpu/cpu.h (cpuArchDecode, cpuArchEncode, cpuArchUpdate)
(cpuArchHasFeature, cpuDecode, cpuEncode, cpuUpdate)
(cpuHasFeature): Use intended type.
* src/conf/cpu_conf.h (virCPUDefCopyModel, virCPUDefCopy):
Likewise.
(virCPUDefParseXML): Drop const.
* src/cpu/cpu.c (cpuDecode, cpuEncode, cpuUpdate, cpuHasFeature):
Fix fallout.
* src/cpu/cpu_x86.c (x86ModelFromCPU, x86ModelSubtractCPU)
(x86DecodeCPUData, x86EncodePolicy, x86Encode, x86UpdateCustom)
(x86UpdateHostModel, x86Update, x86HasFeature): Likewise.
* src/cpu/cpu_s390.c (s390Decode): Likewise.
* src/cpu/cpu_arm.c (ArmDecode): Likewise.
* src/cpu/cpu_powerpc.c (ppcModelFromCPU, ppcCompute, ppcDecode)
(ppcUpdate): Likewise.
* src/conf/cpu_conf.c (virCPUDefCopyModel, virCPUDefCopy)
(virCPUDefParseXML): Likewise.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-10-05 20:01:02 +00:00
|
|
|
* Copyright (C) 2013 Red Hat, Inc.
|
2012-07-12 15:28:17 +00:00
|
|
|
* Copyright (C) Canonical Ltd. 2012
|
|
|
|
*
|
|
|
|
* 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
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2012-07-12 15:28:17 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
2020-05-13 10:48:34 +00:00
|
|
|
#if defined(__aarch64__)
|
2020-07-08 13:39:36 +00:00
|
|
|
# if defined(HAVE_ASM_HWCAP_H)
|
|
|
|
# include <asm/hwcap.h>
|
|
|
|
# endif
|
2020-05-13 10:48:34 +00:00
|
|
|
# include <sys/auxv.h>
|
|
|
|
#endif
|
2012-07-12 15:28:17 +00:00
|
|
|
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2012-07-12 15:28:17 +00:00
|
|
|
#include "cpu.h"
|
2020-05-13 10:48:30 +00:00
|
|
|
#include "cpu_arm.h"
|
2019-10-11 08:05:49 +00:00
|
|
|
#include "cpu_map.h"
|
2020-05-13 10:48:30 +00:00
|
|
|
#include "virlog.h"
|
2014-02-26 16:40:12 +00:00
|
|
|
#include "virstring.h"
|
2019-10-11 08:05:49 +00:00
|
|
|
#include "virxml.h"
|
2012-07-12 15:28:17 +00:00
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_CPU
|
2020-05-13 10:48:34 +00:00
|
|
|
#if defined(__aarch64__)
|
|
|
|
/* Shift bit mask for parsing cpu flags */
|
|
|
|
# define BIT_SHIFTS(n) (1UL << (n))
|
|
|
|
/* The current max number of cpu flags on ARM is 32 */
|
|
|
|
# define MAX_CPU_FLAGS 32
|
|
|
|
#endif
|
|
|
|
|
2012-07-12 15:28:17 +00:00
|
|
|
|
2020-05-13 10:48:30 +00:00
|
|
|
VIR_LOG_INIT("cpu.cpu_arm");
|
|
|
|
|
2016-06-24 16:21:50 +00:00
|
|
|
static const virArch archs[] = {
|
|
|
|
VIR_ARCH_ARMV6L,
|
|
|
|
VIR_ARCH_ARMV7B,
|
|
|
|
VIR_ARCH_ARMV7L,
|
|
|
|
VIR_ARCH_AARCH64,
|
|
|
|
};
|
2012-07-12 15:28:17 +00:00
|
|
|
|
2020-05-13 10:48:30 +00:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2019-10-11 08:05:49 +00:00
|
|
|
typedef struct _virCPUarmFeature virCPUarmFeature;
|
|
|
|
typedef virCPUarmFeature *virCPUarmFeaturePtr;
|
|
|
|
struct _virCPUarmFeature {
|
|
|
|
char *name;
|
|
|
|
};
|
|
|
|
|
|
|
|
static virCPUarmFeaturePtr
|
|
|
|
virCPUarmFeatureNew(void)
|
|
|
|
{
|
|
|
|
return g_new0(virCPUarmFeature, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
virCPUarmFeatureFree(virCPUarmFeaturePtr feature)
|
|
|
|
{
|
|
|
|
if (!feature)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_free(feature->name);
|
|
|
|
|
|
|
|
g_free(feature);
|
|
|
|
}
|
|
|
|
|
|
|
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virCPUarmFeature, virCPUarmFeatureFree);
|
|
|
|
|
|
|
|
typedef struct _virCPUarmMap virCPUarmMap;
|
|
|
|
typedef virCPUarmMap *virCPUarmMapPtr;
|
|
|
|
struct _virCPUarmMap {
|
2020-05-13 10:48:30 +00:00
|
|
|
size_t nvendors;
|
|
|
|
virCPUarmVendorPtr *vendors;
|
|
|
|
size_t nmodels;
|
|
|
|
virCPUarmModelPtr *models;
|
2019-10-11 08:05:49 +00:00
|
|
|
GPtrArray *features;
|
|
|
|
};
|
|
|
|
|
|
|
|
static virCPUarmMapPtr
|
|
|
|
virCPUarmMapNew(void)
|
|
|
|
{
|
|
|
|
virCPUarmMapPtr map;
|
|
|
|
|
|
|
|
map = g_new0(virCPUarmMap, 1);
|
|
|
|
|
|
|
|
map->features = g_ptr_array_new();
|
|
|
|
g_ptr_array_set_free_func(map->features,
|
|
|
|
(GDestroyNotify) virCPUarmFeatureFree);
|
|
|
|
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
2020-05-13 10:48:30 +00:00
|
|
|
static void
|
|
|
|
virCPUarmDataClear(virCPUarmData *data)
|
|
|
|
{
|
|
|
|
if (!data)
|
|
|
|
return;
|
|
|
|
|
2020-08-02 17:36:03 +00:00
|
|
|
g_strfreev(data->features);
|
2020-05-13 10:48:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2019-10-11 08:05:49 +00:00
|
|
|
static void
|
|
|
|
virCPUarmMapFree(virCPUarmMapPtr map)
|
|
|
|
{
|
2020-05-13 10:48:30 +00:00
|
|
|
size_t i;
|
|
|
|
|
2019-10-11 08:05:49 +00:00
|
|
|
if (!map)
|
|
|
|
return;
|
|
|
|
|
2020-05-13 10:48:30 +00:00
|
|
|
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);
|
|
|
|
|
2019-10-11 08:05:49 +00:00
|
|
|
g_ptr_array_free(map->features, TRUE);
|
|
|
|
|
|
|
|
g_free(map);
|
|
|
|
}
|
|
|
|
|
|
|
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virCPUarmMap, virCPUarmMapFree);
|
|
|
|
|
|
|
|
static virCPUarmFeaturePtr
|
|
|
|
virCPUarmMapFeatureFind(virCPUarmMapPtr map,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < map->features->len; i++) {
|
|
|
|
virCPUarmFeaturePtr feature = g_ptr_array_index(map->features, i);
|
|
|
|
|
|
|
|
if (STREQ(feature->name, name))
|
|
|
|
return feature;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
virCPUarmMapFeatureParse(xmlXPathContextPtr ctxt G_GNUC_UNUSED,
|
|
|
|
const char *name,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
g_autoptr(virCPUarmFeature) feature = NULL;
|
|
|
|
virCPUarmMapPtr map = data;
|
|
|
|
|
|
|
|
if (virCPUarmMapFeatureFind(map, name)) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("CPU feature %s already defined"), name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
feature = virCPUarmFeatureNew();
|
|
|
|
feature->name = g_strdup(name);
|
|
|
|
|
|
|
|
g_ptr_array_add(map->features, g_steal_pointer(&feature));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-13 10:48:32 +00:00
|
|
|
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;
|
|
|
|
g_autoptr(virCPUarmVendor) vendor = NULL;
|
|
|
|
|
|
|
|
vendor = g_new0(virCPUarmVendor, 1);
|
|
|
|
vendor->name = g_strdup(name);
|
|
|
|
|
|
|
|
if (virCPUarmVendorFindByName(map, vendor->name)) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("CPU vendor %s already defined"),
|
|
|
|
vendor->name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virXPathULongHex("string(@value)", ctxt, &vendor->value) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("Missing CPU vendor value"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virCPUarmVendorFindByID(map, vendor->value)) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("CPU vendor value 0x%2lx already defined"),
|
|
|
|
vendor->value);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (VIR_APPEND_ELEMENT(map->vendors, map->nvendors, vendor) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-05-13 10:48:34 +00:00
|
|
|
#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
|
|
|
|
|
2020-05-13 10:48:32 +00:00
|
|
|
static int
|
|
|
|
virCPUarmModelParse(xmlXPathContextPtr ctxt,
|
|
|
|
const char *name,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
virCPUarmMapPtr map = data;
|
|
|
|
g_autoptr(virCPUarmModel) model = NULL;
|
|
|
|
g_autofree char *vendor = NULL;
|
|
|
|
|
|
|
|
model = g_new0(virCPUarmModel, 1);
|
|
|
|
model->name = g_strdup(name);
|
|
|
|
|
|
|
|
if (virCPUarmModelFind(map, model->name)) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("CPU model %s already defined"),
|
|
|
|
model->name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(model->vendor = virCPUarmVendorFindByName(map, vendor))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Unknown vendor %s referenced by CPU model %s"),
|
|
|
|
vendor, model->name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!virXPathBoolean("boolean(./pvr)", ctxt)) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Missing PVR information for CPU model %s"),
|
|
|
|
model->name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (VIR_APPEND_ELEMENT(map->models, map->nmodels, model) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-10-11 08:05:49 +00:00
|
|
|
static virCPUarmMapPtr
|
|
|
|
virCPUarmLoadMap(void)
|
|
|
|
{
|
|
|
|
g_autoptr(virCPUarmMap) map = NULL;
|
|
|
|
|
|
|
|
map = virCPUarmMapNew();
|
|
|
|
|
2020-05-13 10:48:32 +00:00
|
|
|
if (cpuMapLoad("arm", virCPUarmVendorParse, virCPUarmMapFeatureParse,
|
|
|
|
virCPUarmModelParse, map) < 0)
|
2019-10-11 08:05:49 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return g_steal_pointer(&map);
|
|
|
|
}
|
|
|
|
|
|
|
|
static virCPUarmMapPtr cpuMap;
|
|
|
|
|
|
|
|
int virCPUarmDriverOnceInit(void);
|
|
|
|
VIR_ONCE_GLOBAL_INIT(virCPUarmDriver);
|
|
|
|
|
|
|
|
int
|
|
|
|
virCPUarmDriverOnceInit(void)
|
|
|
|
{
|
|
|
|
if (!(cpuMap = virCPUarmLoadMap()))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virCPUarmMapPtr
|
|
|
|
virCPUarmGetMap(void)
|
|
|
|
{
|
|
|
|
if (virCPUarmDriverInitialize() < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return cpuMap;
|
|
|
|
}
|
2016-06-23 13:27:07 +00:00
|
|
|
|
2014-02-26 16:40:12 +00:00
|
|
|
static int
|
2016-06-23 13:27:07 +00:00
|
|
|
virCPUarmUpdate(virCPUDefPtr guest,
|
|
|
|
const virCPUDef *host)
|
2014-02-26 16:40:12 +00:00
|
|
|
{
|
2020-05-22 19:56:17 +00:00
|
|
|
g_autoptr(virCPUDef) updated = NULL;
|
2016-06-23 13:27:07 +00:00
|
|
|
|
|
|
|
if (guest->mode != VIR_CPU_MODE_HOST_MODEL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!host) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
|
_("unknown host CPU model"));
|
2020-05-22 19:56:17 +00:00
|
|
|
return -1;
|
2016-06-23 13:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!(updated = virCPUDefCopyWithoutModel(guest)))
|
2020-05-22 19:56:17 +00:00
|
|
|
return -1;
|
2016-06-23 13:27:07 +00:00
|
|
|
|
|
|
|
updated->mode = VIR_CPU_MODE_CUSTOM;
|
|
|
|
if (virCPUDefCopyModel(updated, host, true) < 0)
|
2020-05-22 19:56:17 +00:00
|
|
|
return -1;
|
2016-06-23 13:27:07 +00:00
|
|
|
|
2016-11-10 09:26:03 +00:00
|
|
|
virCPUDefStealModel(guest, updated, false);
|
2016-06-23 13:27:07 +00:00
|
|
|
guest->mode = VIR_CPU_MODE_CUSTOM;
|
2014-02-26 16:40:12 +00:00
|
|
|
guest->match = VIR_CPU_MATCH_EXACT;
|
2016-06-23 13:27:07 +00:00
|
|
|
|
2020-05-22 19:56:17 +00:00
|
|
|
return 0;
|
2014-02-26 16:40:12 +00:00
|
|
|
}
|
|
|
|
|
2016-06-23 13:27:07 +00:00
|
|
|
|
2014-03-03 13:41:03 +00:00
|
|
|
static virCPUDefPtr
|
2018-05-15 08:50:32 +00:00
|
|
|
virCPUarmBaseline(virCPUDefPtr *cpus,
|
2019-10-14 12:45:33 +00:00
|
|
|
unsigned int ncpus G_GNUC_UNUSED,
|
|
|
|
virDomainCapsCPUModelsPtr models G_GNUC_UNUSED,
|
|
|
|
const char **features G_GNUC_UNUSED,
|
|
|
|
bool migratable G_GNUC_UNUSED)
|
2014-03-03 13:41:03 +00:00
|
|
|
{
|
|
|
|
virCPUDefPtr cpu = NULL;
|
|
|
|
|
2019-11-29 11:00:26 +00:00
|
|
|
cpu = virCPUDefNew();
|
2014-03-03 13:41:03 +00:00
|
|
|
|
2019-10-20 11:49:46 +00:00
|
|
|
cpu->model = g_strdup(cpus[0]->model);
|
|
|
|
|
2014-03-03 13:41:03 +00:00
|
|
|
cpu->type = VIR_CPU_TYPE_GUEST;
|
|
|
|
cpu->match = VIR_CPU_MATCH_EXACT;
|
|
|
|
|
|
|
|
return cpu;
|
|
|
|
}
|
|
|
|
|
2014-05-07 16:38:10 +00:00
|
|
|
static virCPUCompareResult
|
2019-10-14 12:45:33 +00:00
|
|
|
virCPUarmCompare(virCPUDefPtr host G_GNUC_UNUSED,
|
|
|
|
virCPUDefPtr cpu G_GNUC_UNUSED,
|
|
|
|
bool failMessages G_GNUC_UNUSED)
|
2014-05-07 16:38:10 +00:00
|
|
|
{
|
|
|
|
return VIR_CPU_COMPARE_IDENTICAL;
|
|
|
|
}
|
|
|
|
|
2019-10-11 08:05:49 +00:00
|
|
|
static int
|
|
|
|
virCPUarmValidateFeatures(virCPUDefPtr cpu)
|
|
|
|
{
|
|
|
|
virCPUarmMapPtr map;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
if (!(map = virCPUarmGetMap()))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
for (i = 0; i < cpu->nfeatures; i++) {
|
|
|
|
virCPUFeatureDefPtr feature = &cpu->features[i];
|
|
|
|
|
|
|
|
if (!virCPUarmMapFeatureFind(map, feature->name)) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("unknown CPU feature: %s"),
|
|
|
|
feature->name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-13 10:48:34 +00:00
|
|
|
#if defined(__aarch64__)
|
|
|
|
/* Generate human readable flag list according to the order of */
|
|
|
|
/* AT_HWCAP bit map */
|
|
|
|
const char *aarch64_cpu_flags[MAX_CPU_FLAGS] = {
|
|
|
|
"fp", "asimd", "evtstrm", "aes", "pmull", "sha1", "sha2",
|
|
|
|
"crc32", "atomics", "fphp", "asimdhp", "cpuid", "asimdrdm",
|
|
|
|
"jscvt", "fcma", "lrcpc", "dcpop", "sha3", "sm3", "sm4",
|
|
|
|
"asimddp", "sha512", "sve", "asimdfhm", "dit", "uscat",
|
|
|
|
"ilrcpc", "flagm", "ssbs", "sb", "paca", "pacg"};
|
|
|
|
/**
|
|
|
|
* virCPUarmCpuDataFromRegs:
|
|
|
|
*
|
|
|
|
* @data: 64-bit arm CPU specific data
|
|
|
|
*
|
|
|
|
* Fetches CPU vendor_id and part_id from MIDR_EL1 register, parse CPU
|
|
|
|
* flags from AT_HWCAP. There are currently 32 valid flags on ARM arch
|
|
|
|
* represented by each bit.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
virCPUarmCpuDataFromRegs(virCPUarmData *data)
|
|
|
|
{
|
|
|
|
unsigned long cpuid;
|
|
|
|
unsigned long hwcaps;
|
|
|
|
VIR_AUTOSTRINGLIST features = NULL;
|
|
|
|
int cpu_feature_index = 0;
|
|
|
|
size_t i;
|
|
|
|
|
2020-07-08 13:39:36 +00:00
|
|
|
# if defined(HAVE_GETAUXVAL)
|
2020-05-13 10:48:34 +00:00
|
|
|
if (!(getauxval(AT_HWCAP) & HWCAP_CPUID)) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("CPUID registers unavailable"));
|
|
|
|
return -1;
|
|
|
|
}
|
2020-07-08 13:39:36 +00:00
|
|
|
# endif
|
2020-05-13 10:48:34 +00:00
|
|
|
|
|
|
|
/* read the cpuid data from MIDR_EL1 register */
|
|
|
|
asm("mrs %0, MIDR_EL1" : "=r" (cpuid));
|
|
|
|
VIR_DEBUG("CPUID read from register: 0x%016lx", cpuid);
|
|
|
|
|
2020-07-09 04:42:21 +00:00
|
|
|
/* parse the corresponding part_id bits */
|
2020-05-13 10:48:34 +00:00
|
|
|
data->pvr = (cpuid >> 4) & 0xfff;
|
2020-07-09 04:42:21 +00:00
|
|
|
/* parse the corresponding vendor_id bits */
|
2020-05-13 10:48:34 +00:00
|
|
|
data->vendor_id = (cpuid >> 24) & 0xff;
|
|
|
|
|
2020-07-08 13:39:36 +00:00
|
|
|
# if defined(HAVE_GETAUXVAL)
|
2020-05-13 10:48:34 +00:00
|
|
|
hwcaps = getauxval(AT_HWCAP);
|
2020-07-08 13:39:36 +00:00
|
|
|
# elif defined(HAVE_ELF_AUX_INFO)
|
|
|
|
elf_aux_info(AT_HWCAP, &hwcaps, sizeof(u_long));
|
|
|
|
# else
|
|
|
|
# error No routines to retrieve a value from the auxiliary vector
|
|
|
|
# endif
|
2020-05-13 10:48:34 +00:00
|
|
|
VIR_DEBUG("CPU flags read from register: 0x%016lx", hwcaps);
|
|
|
|
|
|
|
|
features = g_new0(char *, MAX_CPU_FLAGS + 1);
|
|
|
|
|
|
|
|
/* shift bit map mask to parse for CPU flags */
|
|
|
|
for (i = 0; i < MAX_CPU_FLAGS; i++) {
|
|
|
|
if (hwcaps & BIT_SHIFTS(i)) {
|
|
|
|
features[cpu_feature_index] = g_strdup(aarch64_cpu_flags[i]);
|
|
|
|
cpu_feature_index++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cpu_feature_index > 0)
|
|
|
|
data->features = g_steal_pointer(&features);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
virCPUarmDecode(virCPUDefPtr cpu,
|
|
|
|
const virCPUarmData *cpuData,
|
|
|
|
virDomainCapsCPUModelsPtr models)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
virCPUarmMapPtr map;
|
|
|
|
virCPUarmModelPtr model;
|
|
|
|
virCPUarmVendorPtr vendor = NULL;
|
|
|
|
|
|
|
|
if (!cpuData || !(map = virCPUarmGetMap()))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (!(model = virCPUarmModelFindByPVR(map, cpuData->pvr))) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
|
|
|
_("Cannot find CPU model with PVR 0x%03lx"),
|
|
|
|
cpuData->pvr);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!virCPUModelIsAllowed(model->name, models)) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("CPU model %s is not supported by hypervisor"),
|
|
|
|
model->name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
cpu->model = g_strdup(model->name);
|
|
|
|
|
|
|
|
if (cpuData->vendor_id &&
|
|
|
|
!(vendor = virCPUarmVendorFindByID(map, cpuData->vendor_id))) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
|
|
|
_("Cannot find CPU vendor with vendor id 0x%02lx"),
|
|
|
|
cpuData->vendor_id);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vendor)
|
|
|
|
cpu->vendor = g_strdup(vendor->name);
|
|
|
|
|
|
|
|
if (cpuData->features) {
|
|
|
|
cpu->nfeatures = virStringListLength((const char **)cpuData->features);
|
|
|
|
cpu->features = g_new0(virCPUFeatureDef, cpu->nfeatures);
|
|
|
|
|
|
|
|
for (i = 0; i < cpu->nfeatures; i++) {
|
|
|
|
cpu->features[i].policy = VIR_CPU_FEATURE_REQUIRE;
|
|
|
|
cpu->features[i].name = g_strdup(cpuData->features[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
virCPUarmGetHost(virCPUDefPtr cpu,
|
|
|
|
virDomainCapsCPUModelsPtr models)
|
|
|
|
{
|
|
|
|
g_autoptr(virCPUData) cpuData = NULL;
|
|
|
|
|
|
|
|
if (virCPUarmDriverInitialize() < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (!(cpuData = virCPUDataNew(archs[0])))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (virCPUarmCpuDataFromRegs(&cpuData->data.arm) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return virCPUarmDecode(cpu, &cpuData->data.arm, models);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2012-07-12 15:28:17 +00:00
|
|
|
struct cpuArchDriver cpuDriverArm = {
|
|
|
|
.name = "arm",
|
|
|
|
.arch = archs,
|
2019-10-15 11:55:26 +00:00
|
|
|
.narch = G_N_ELEMENTS(archs),
|
2016-08-09 11:26:53 +00:00
|
|
|
.compare = virCPUarmCompare,
|
2020-05-13 10:48:34 +00:00
|
|
|
#if defined(__aarch64__)
|
|
|
|
.getHost = virCPUarmGetHost,
|
|
|
|
#endif
|
2016-06-21 14:02:07 +00:00
|
|
|
.decode = NULL,
|
2012-07-12 15:28:17 +00:00
|
|
|
.encode = NULL,
|
2020-05-13 10:48:30 +00:00
|
|
|
.dataFree = virCPUarmDataFree,
|
2018-05-15 08:50:32 +00:00
|
|
|
.baseline = virCPUarmBaseline,
|
2016-06-23 13:27:07 +00:00
|
|
|
.update = virCPUarmUpdate,
|
2019-10-11 08:05:49 +00:00
|
|
|
.validateFeatures = virCPUarmValidateFeatures,
|
2012-07-12 15:28:17 +00:00
|
|
|
};
|