2012-06-22 11:50:11 +00:00
|
|
|
/*
|
|
|
|
* cpu_s390.c: CPU driver for s390(x) CPUs
|
|
|
|
*
|
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-06-22 11:50:11 +00:00
|
|
|
* Copyright IBM Corp. 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-06-22 11:50:11 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2014-12-19 14:49:35 +00:00
|
|
|
#include "virstring.h"
|
2012-06-22 11:50:11 +00:00
|
|
|
#include "cpu.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_CPU
|
|
|
|
|
2012-12-11 12:58:54 +00:00
|
|
|
static const virArch archs[] = { VIR_ARCH_S390, VIR_ARCH_S390X };
|
2012-06-22 11:50:11 +00:00
|
|
|
|
2016-12-18 19:22:21 +00:00
|
|
|
static virCPUCompareResult
|
|
|
|
virCPUs390Compare(virCPUDefPtr host ATTRIBUTE_UNUSED,
|
|
|
|
virCPUDefPtr cpu ATTRIBUTE_UNUSED,
|
|
|
|
bool failMessages ATTRIBUTE_UNUSED)
|
|
|
|
{
|
2017-03-07 17:09:58 +00:00
|
|
|
/* s390 relies on QEMU to perform all runability checking. Return
|
2016-12-18 19:22:21 +00:00
|
|
|
* VIR_CPU_COMPARE_IDENTICAL to bypass Libvirt checking.
|
|
|
|
*/
|
|
|
|
return VIR_CPU_COMPARE_IDENTICAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
virCPUs390Update(virCPUDefPtr guest,
|
|
|
|
const virCPUDef *host)
|
|
|
|
{
|
2018-09-13 08:55:20 +00:00
|
|
|
virCPUDefPtr updated = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
if (guest->match == VIR_CPU_MATCH_MINIMUM) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("match mode %s not supported"),
|
|
|
|
virCPUMatchTypeToString(guest->match));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (guest->mode != VIR_CPU_MODE_HOST_MODEL) {
|
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!host) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
|
_("unknown host CPU model"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(updated = virCPUDefCopyWithoutModel(guest)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
updated->mode = VIR_CPU_MODE_CUSTOM;
|
|
|
|
if (virCPUDefCopyModel(updated, host, true) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
for (i = 0; i < guest->nfeatures; i++) {
|
|
|
|
if (virCPUDefUpdateFeature(updated,
|
|
|
|
guest->features[i].name,
|
|
|
|
guest->features[i].policy) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
virCPUDefStealModel(guest, updated, false);
|
|
|
|
guest->mode = VIR_CPU_MODE_CUSTOM;
|
|
|
|
guest->match = VIR_CPU_MATCH_EXACT;
|
|
|
|
ret = 0;
|
2016-12-18 19:22:21 +00:00
|
|
|
|
|
|
|
cleanup:
|
2018-09-13 08:55:20 +00:00
|
|
|
virCPUDefFree(updated);
|
|
|
|
return ret;
|
2016-12-18 19:22:21 +00:00
|
|
|
}
|
|
|
|
|
2017-09-14 14:09:35 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
virCPUs390ValidateFeatures(virCPUDefPtr cpu)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < cpu->nfeatures; i++) {
|
|
|
|
if (cpu->features[i].policy == VIR_CPU_FEATURE_OPTIONAL) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("only cpu feature policies 'require' and "
|
|
|
|
"'disable' are supported for %s"),
|
|
|
|
cpu->features[i].name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-22 11:50:11 +00:00
|
|
|
struct cpuArchDriver cpuDriverS390 = {
|
|
|
|
.name = "s390",
|
|
|
|
.arch = archs,
|
|
|
|
.narch = ARRAY_CARDINALITY(archs),
|
2016-12-18 19:22:21 +00:00
|
|
|
.compare = virCPUs390Compare,
|
2016-12-18 19:22:22 +00:00
|
|
|
.decode = NULL,
|
2012-06-22 11:50:11 +00:00
|
|
|
.encode = NULL,
|
|
|
|
.baseline = NULL,
|
2016-12-18 19:22:21 +00:00
|
|
|
.update = virCPUs390Update,
|
2017-09-14 14:09:35 +00:00
|
|
|
.validateFeatures = virCPUs390ValidateFeatures,
|
2012-06-22 11:50:11 +00:00
|
|
|
};
|