2011-10-03 12:56:20 +00:00
|
|
|
/*
|
2012-10-15 09:07:51 +00:00
|
|
|
* cpu_powerpc.c: CPU driver for PowerPC CPUs
|
2011-10-03 12:56:20 +00:00
|
|
|
*
|
2012-10-15 09:07:51 +00:00
|
|
|
* Copyright (C) IBM Corporation, 2010
|
2011-10-03 12:56:20 +00:00
|
|
|
*
|
|
|
|
* 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/>.
|
2011-10-03 12:56:20 +00:00
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Anton Blanchard <anton@au.ibm.com>
|
|
|
|
* Prerna Saxena <prerna@linux.vnet.ibm.com>
|
2012-10-15 09:07:50 +00:00
|
|
|
* Li Zhang <zhlcindy@linux.vnet.ibm.com>
|
2011-10-03 12:56:20 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
2012-10-15 09:07:50 +00:00
|
|
|
#include <stdint.h>
|
2011-10-03 12:56:20 +00:00
|
|
|
|
2012-12-12 17:59:27 +00:00
|
|
|
#include "virlog.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2012-12-13 17:44:57 +00:00
|
|
|
#include "virutil.h"
|
2011-10-03 12:56:20 +00:00
|
|
|
#include "cpu.h"
|
|
|
|
|
2012-10-15 09:07:50 +00:00
|
|
|
#include "cpu_map.h"
|
2012-12-04 12:04:07 +00:00
|
|
|
#include "virbuffer.h"
|
2011-10-03 12:56:20 +00:00
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_CPU
|
|
|
|
|
2012-12-11 12:58:54 +00:00
|
|
|
static const virArch archs[] = { VIR_ARCH_PPC64 };
|
2011-10-03 12:56:20 +00:00
|
|
|
|
2012-10-15 09:07:50 +00:00
|
|
|
struct cpuPowerPC {
|
|
|
|
const char *name;
|
|
|
|
const char *vendor;
|
|
|
|
uint32_t pvr;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct cpuPowerPC cpu_defs[] = {
|
|
|
|
{"POWER7", "IBM", 0x003f0200},
|
|
|
|
{"POWER7_v2.1", "IBM", 0x003f0201},
|
|
|
|
{"POWER7_v2.3", "IBM", 0x003f0203},
|
|
|
|
{NULL, NULL, 0xffffffff}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct ppc_vendor {
|
|
|
|
char *name;
|
|
|
|
struct ppc_vendor *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ppc_model {
|
|
|
|
char *name;
|
|
|
|
const struct ppc_vendor *vendor;
|
|
|
|
union cpuData *data;
|
|
|
|
struct ppc_model *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ppc_map {
|
|
|
|
struct ppc_vendor *vendors;
|
|
|
|
struct ppc_model *models;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
ConvertModelVendorFromPVR(char ***model,
|
|
|
|
char ***vendor,
|
|
|
|
uint32_t pvr)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; cpu_defs[i].name; i++) {
|
|
|
|
if (cpu_defs[i].pvr == pvr) {
|
|
|
|
**model = strdup(cpu_defs[i].name);
|
|
|
|
**vendor = strdup(cpu_defs[i].vendor);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("Missing the definition of this model"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ConvertPVRFromModel(const char *model,
|
|
|
|
uint32_t *pvr)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; cpu_defs[i].name; i++) {
|
|
|
|
if (STREQ(cpu_defs[i].name, model)) {
|
|
|
|
*pvr = cpu_defs[i].pvr;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("Missing the definition of this model"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
cpuMatch(const union cpuData *data,
|
|
|
|
char **cpu_model,
|
|
|
|
char **cpu_vendor,
|
|
|
|
const struct ppc_model *model)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
ret = ConvertModelVendorFromPVR(&cpu_model, &cpu_vendor, data->ppc.pvr);
|
|
|
|
|
|
|
|
if (STREQ(model->name, *cpu_model) &&
|
|
|
|
STREQ(model->vendor->name, *cpu_vendor))
|
|
|
|
ret = 1;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static struct ppc_model *
|
|
|
|
ppcModelNew(void)
|
|
|
|
{
|
|
|
|
struct ppc_model *model;
|
|
|
|
|
|
|
|
if (VIR_ALLOC(model) < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (VIR_ALLOC(model->data) < 0) {
|
|
|
|
VIR_FREE(model);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return model;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ppcModelFree(struct ppc_model *model)
|
|
|
|
{
|
|
|
|
if (model == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
VIR_FREE(model->name);
|
|
|
|
|
|
|
|
VIR_FREE(model->data);
|
|
|
|
|
|
|
|
VIR_FREE(model);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ppc_model *
|
|
|
|
ppcModelFind(const struct ppc_map *map,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
struct ppc_model *model;
|
|
|
|
|
|
|
|
model = map->models;
|
|
|
|
while (model != NULL) {
|
|
|
|
if (STREQ(model->name, name))
|
|
|
|
return model;
|
|
|
|
|
|
|
|
model = model->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ppc_vendor *
|
|
|
|
ppcVendorFind(const struct ppc_map *map,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
struct ppc_vendor *vendor;
|
|
|
|
|
|
|
|
vendor = map->vendors;
|
|
|
|
while (vendor) {
|
|
|
|
if (STREQ(vendor->name, name))
|
|
|
|
return vendor;
|
|
|
|
|
|
|
|
vendor = vendor->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ppcVendorFree(struct ppc_vendor *vendor)
|
|
|
|
{
|
|
|
|
if (!vendor)
|
|
|
|
return;
|
|
|
|
|
|
|
|
VIR_FREE(vendor->name);
|
|
|
|
VIR_FREE(vendor);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ppcVendorLoad(xmlXPathContextPtr ctxt,
|
|
|
|
struct ppc_map *map)
|
|
|
|
{
|
|
|
|
struct ppc_vendor *vendor = NULL;
|
|
|
|
|
2012-12-18 23:06:45 +00:00
|
|
|
if (VIR_ALLOC(vendor) < 0) {
|
|
|
|
virReportOOMError();
|
|
|
|
return -1;
|
|
|
|
}
|
2012-10-15 09:07:50 +00:00
|
|
|
|
|
|
|
vendor->name = virXPathString("string(@name)", ctxt);
|
|
|
|
if (!vendor->name) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("Missing CPU vendor name"));
|
|
|
|
goto ignore;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ppcVendorFind(map, vendor->name)) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("CPU vendor %s already defined"), vendor->name);
|
|
|
|
goto ignore;
|
|
|
|
}
|
|
|
|
|
2012-12-18 23:06:45 +00:00
|
|
|
if (!map->vendors) {
|
2012-10-15 09:07:50 +00:00
|
|
|
map->vendors = vendor;
|
2012-12-18 23:06:45 +00:00
|
|
|
} else {
|
2012-10-15 09:07:50 +00:00
|
|
|
vendor->next = map->vendors;
|
|
|
|
map->vendors = vendor;
|
|
|
|
}
|
|
|
|
|
2012-12-18 23:06:45 +00:00
|
|
|
cleanup:
|
|
|
|
return 0;
|
2012-10-15 09:07:50 +00:00
|
|
|
|
|
|
|
ignore:
|
|
|
|
ppcVendorFree(vendor);
|
2012-12-18 23:06:45 +00:00
|
|
|
goto cleanup;
|
2012-10-15 09:07:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ppcModelLoad(xmlXPathContextPtr ctxt,
|
|
|
|
struct ppc_map *map)
|
|
|
|
{
|
|
|
|
xmlNodePtr *nodes = NULL;
|
|
|
|
struct ppc_model *model;
|
|
|
|
char *vendor = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
if (!(model = ppcModelNew()))
|
|
|
|
goto no_memory;
|
|
|
|
|
|
|
|
model->name = virXPathString("string(@name)", ctxt);
|
|
|
|
if (model->name == NULL) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("Missing CPU model name"));
|
|
|
|
goto ignore;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = ConvertPVRFromModel(model->name, &model->data->ppc.pvr);
|
|
|
|
if (ret < 0)
|
|
|
|
goto ignore;
|
|
|
|
|
|
|
|
|
|
|
|
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 ignore;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(model->vendor = ppcVendorFind(map, vendor))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Unknown vendor %s referenced by CPU model %s"),
|
|
|
|
vendor, model->name);
|
|
|
|
goto ignore;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (map->models == NULL)
|
|
|
|
map->models = model;
|
|
|
|
else {
|
|
|
|
model->next = map->models;
|
|
|
|
map->models = model;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
out:
|
|
|
|
VIR_FREE(vendor);
|
|
|
|
VIR_FREE(nodes);
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
no_memory:
|
|
|
|
virReportOOMError();
|
|
|
|
|
|
|
|
ignore:
|
|
|
|
ppcModelFree(model);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ppcMapLoadCallback(enum cpuMapElement element,
|
|
|
|
xmlXPathContextPtr ctxt,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
struct ppc_map *map = data;
|
|
|
|
|
|
|
|
switch (element) {
|
|
|
|
case CPU_MAP_ELEMENT_VENDOR:
|
|
|
|
return ppcVendorLoad(ctxt, map);
|
|
|
|
case CPU_MAP_ELEMENT_MODEL:
|
|
|
|
return ppcModelLoad(ctxt, map);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ppcMapFree(struct ppc_map *map)
|
|
|
|
{
|
|
|
|
if (map == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
while (map->models != NULL) {
|
|
|
|
struct ppc_model *model = map->models;
|
|
|
|
map->models = model->next;
|
|
|
|
ppcModelFree(model);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (map->vendors != NULL) {
|
|
|
|
struct ppc_vendor *vendor = map->vendors;
|
|
|
|
map->vendors = vendor->next;
|
|
|
|
ppcVendorFree(vendor);
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_FREE(map);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ppc_map *
|
|
|
|
ppcLoadMap(void)
|
|
|
|
{
|
|
|
|
struct ppc_map *map;
|
|
|
|
|
|
|
|
if (VIR_ALLOC(map) < 0) {
|
|
|
|
virReportOOMError();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cpuMapLoad("ppc64", ppcMapLoadCallback, map) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
return map;
|
|
|
|
|
|
|
|
error:
|
|
|
|
ppcMapFree(map);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virCPUCompareResult
|
2012-12-18 22:32:01 +00:00
|
|
|
ppcCompare(virCPUDefPtr host,
|
2012-10-15 09:07:50 +00:00
|
|
|
virCPUDefPtr cpu)
|
|
|
|
{
|
2012-12-18 22:32:01 +00:00
|
|
|
if ((cpu->arch == VIR_ARCH_NONE || host->arch == cpu->arch) &&
|
|
|
|
STREQ(host->model, cpu->model))
|
|
|
|
return VIR_CPU_COMPARE_IDENTICAL;
|
2012-10-15 09:07:50 +00:00
|
|
|
|
2012-12-18 22:32:01 +00:00
|
|
|
return VIR_CPU_COMPARE_INCOMPATIBLE;
|
2012-10-15 09:07:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
PowerPCDecode(virCPUDefPtr cpu,
|
|
|
|
const union cpuData *data,
|
|
|
|
const char **models,
|
|
|
|
unsigned int nmodels,
|
|
|
|
const char *preferred)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
struct ppc_map *map;
|
|
|
|
const struct ppc_model *candidate;
|
|
|
|
virCPUDefPtr cpuCandidate;
|
|
|
|
virCPUDefPtr cpuModel = NULL;
|
|
|
|
char *cpu_vendor = NULL;
|
|
|
|
char *cpu_model = NULL;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
if (data == NULL || (map = ppcLoadMap()) == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
candidate = map->models;
|
|
|
|
|
|
|
|
while (candidate != NULL) {
|
|
|
|
bool allowed = (models == NULL);
|
|
|
|
|
|
|
|
for (i = 0; i < nmodels; i++) {
|
|
|
|
if (models && models[i] && STREQ(models[i], candidate->name)) {
|
|
|
|
allowed = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!allowed) {
|
|
|
|
if (preferred && STREQ(candidate->name, preferred)) {
|
|
|
|
if (cpu->fallback != VIR_CPU_FALLBACK_ALLOW) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("CPU model %s is not supported by hypervisor"),
|
|
|
|
preferred);
|
|
|
|
goto out;
|
|
|
|
} else {
|
|
|
|
VIR_WARN("Preferred CPU model %s not allowed by"
|
|
|
|
" hypervisor; closest supported model will be"
|
|
|
|
" used", preferred);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
VIR_DEBUG("CPU model %s not allowed by hypervisor; ignoring",
|
|
|
|
candidate->name);
|
|
|
|
}
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (VIR_ALLOC(cpuCandidate) < 0) {
|
|
|
|
virReportOOMError();
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
cpuCandidate->model = strdup(candidate->name);
|
|
|
|
cpuCandidate->vendor = strdup(candidate->vendor->name);
|
|
|
|
|
|
|
|
if (preferred && STREQ(cpuCandidate->model, preferred)) {
|
|
|
|
virCPUDefFree(cpuModel);
|
|
|
|
cpuModel = cpuCandidate;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = cpuMatch(data, &cpu_model, &cpu_vendor, candidate);
|
|
|
|
if (ret < 0) {
|
|
|
|
VIR_FREE(cpuCandidate);
|
|
|
|
goto out;
|
2012-10-17 09:23:12 +00:00
|
|
|
} else if (ret == 1) {
|
2012-10-15 09:07:50 +00:00
|
|
|
cpuCandidate->model = cpu_model;
|
|
|
|
cpuCandidate->vendor = cpu_vendor;
|
|
|
|
virCPUDefFree(cpuModel);
|
|
|
|
cpuModel = cpuCandidate;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
virCPUDefFree(cpuCandidate);
|
|
|
|
|
|
|
|
next:
|
|
|
|
candidate = candidate->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cpuModel == NULL) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("Cannot find suitable CPU model for given data"));
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
cpu->model = cpuModel->model;
|
|
|
|
cpu->vendor = cpuModel->vendor;
|
|
|
|
VIR_FREE(cpuModel);
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
out:
|
|
|
|
ppcMapFree(map);
|
|
|
|
virCPUDefFree(cpuModel);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
PowerPCDataFree(union cpuData *data)
|
|
|
|
{
|
|
|
|
if (data == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
VIR_FREE(data);
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:42:34 +00:00
|
|
|
#if defined(__powerpc__) || defined(__powerpc64__)
|
2011-10-03 12:56:20 +00:00
|
|
|
static union cpuData *
|
2012-12-18 22:42:34 +00:00
|
|
|
ppcNodeData(void)
|
2011-10-03 12:56:20 +00:00
|
|
|
{
|
|
|
|
union cpuData *data;
|
|
|
|
|
|
|
|
if (VIR_ALLOC(data) < 0) {
|
|
|
|
virReportOOMError();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:42:34 +00:00
|
|
|
asm("mfpvr %0"
|
|
|
|
: "=r" (data->ppc.pvr));
|
2012-10-15 09:07:50 +00:00
|
|
|
|
2011-10-03 12:56:20 +00:00
|
|
|
return data;
|
|
|
|
}
|
2012-12-18 22:42:34 +00:00
|
|
|
#endif
|
2011-10-03 12:56:20 +00:00
|
|
|
|
|
|
|
static int
|
2012-10-15 09:07:50 +00:00
|
|
|
PowerPCUpdate(virCPUDefPtr guest ATTRIBUTE_UNUSED,
|
|
|
|
const virCPUDefPtr host ATTRIBUTE_UNUSED)
|
2011-10-03 12:56:20 +00:00
|
|
|
{
|
2012-10-15 09:07:50 +00:00
|
|
|
return 0;
|
2011-10-03 12:56:20 +00:00
|
|
|
}
|
2012-10-15 09:07:50 +00:00
|
|
|
static virCPUDefPtr
|
2012-12-19 00:33:01 +00:00
|
|
|
ppcBaseline(virCPUDefPtr *cpus,
|
|
|
|
unsigned int ncpus,
|
|
|
|
const char **models,
|
|
|
|
unsigned int nmodels)
|
2011-10-03 12:56:20 +00:00
|
|
|
{
|
2012-10-15 09:07:50 +00:00
|
|
|
struct ppc_map *map = NULL;
|
2012-12-19 00:33:01 +00:00
|
|
|
const struct ppc_model *model;
|
|
|
|
const struct ppc_vendor *vendor = NULL;
|
2012-10-15 09:07:50 +00:00
|
|
|
virCPUDefPtr cpu = NULL;
|
2012-12-19 00:33:01 +00:00
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
if (!(map = ppcLoadMap()))
|
|
|
|
goto error;
|
2012-10-15 09:07:50 +00:00
|
|
|
|
2012-12-19 00:33:01 +00:00
|
|
|
if (!(model = ppcModelFind(map, cpus[0]->model))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Unknown CPU model %s"), cpus[0]->model);
|
2012-10-15 09:07:50 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2012-12-19 00:33:01 +00:00
|
|
|
if (!cpuModelIsAllowed(model->name, models, nmodels)) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("CPU model %s is not supported by hypervisor"),
|
|
|
|
model->name);
|
2012-10-15 09:07:50 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2012-12-19 00:33:01 +00:00
|
|
|
for (i = 0; i < ncpus; i++) {
|
|
|
|
const struct ppc_vendor *vnd;
|
2012-12-11 12:58:54 +00:00
|
|
|
|
2012-12-19 00:33:01 +00:00
|
|
|
if (STRNEQ(cpus[i]->model, model->name)) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
|
|
|
_("CPUs are incompatible"));
|
|
|
|
goto error;
|
|
|
|
}
|
2012-10-15 09:07:50 +00:00
|
|
|
|
2012-12-19 00:33:01 +00:00
|
|
|
if (!cpus[i]->vendor)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!(vnd = ppcVendorFind(map, cpus[i]->vendor))) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
|
|
|
_("Unknown CPU vendor %s"), cpus[i]->vendor);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (model->vendor) {
|
|
|
|
if (model->vendor != vnd) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
|
|
|
_("CPU vendor %s of model %s differs from "
|
|
|
|
"vendor %s"),
|
|
|
|
model->vendor->name, model->name,
|
|
|
|
vnd->name);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
} else if (vendor) {
|
|
|
|
if (vendor != vnd) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
|
|
|
_("CPU vendors do not match"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
vendor = vnd;
|
|
|
|
}
|
2012-10-15 09:07:50 +00:00
|
|
|
}
|
|
|
|
|
2012-12-19 00:33:01 +00:00
|
|
|
if (VIR_ALLOC(cpu) < 0 ||
|
|
|
|
!(cpu->model = strdup(model->name)))
|
|
|
|
goto no_memory;
|
2012-10-15 09:07:50 +00:00
|
|
|
|
2012-12-19 00:33:01 +00:00
|
|
|
if (vendor && !(cpu->vendor = strdup(vendor->name)))
|
|
|
|
goto no_memory;
|
|
|
|
|
|
|
|
cpu->type = VIR_CPU_TYPE_GUEST;
|
|
|
|
cpu->match = VIR_CPU_MATCH_EXACT;
|
2012-10-15 09:07:50 +00:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
ppcMapFree(map);
|
2011-10-03 12:56:20 +00:00
|
|
|
|
2012-10-15 09:07:50 +00:00
|
|
|
return cpu;
|
2012-12-19 00:33:01 +00:00
|
|
|
|
2012-10-15 09:07:50 +00:00
|
|
|
no_memory:
|
|
|
|
virReportOOMError();
|
|
|
|
error:
|
|
|
|
virCPUDefFree(cpu);
|
|
|
|
cpu = NULL;
|
|
|
|
goto cleanup;
|
2011-10-03 12:56:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct cpuArchDriver cpuDriverPowerPC = {
|
|
|
|
.name = "ppc64",
|
|
|
|
.arch = archs,
|
|
|
|
.narch = ARRAY_CARDINALITY(archs),
|
2012-12-18 22:32:01 +00:00
|
|
|
.compare = ppcCompare,
|
2011-10-03 12:56:20 +00:00
|
|
|
.decode = PowerPCDecode,
|
|
|
|
.encode = NULL,
|
|
|
|
.free = PowerPCDataFree,
|
2012-12-18 22:42:34 +00:00
|
|
|
#if defined(__powerpc__) || defined(__powerpc64__)
|
|
|
|
.nodeData = ppcNodeData,
|
|
|
|
#else
|
|
|
|
.nodeData = NULL,
|
|
|
|
#endif
|
2011-10-03 12:56:20 +00:00
|
|
|
.guestData = NULL,
|
2012-12-19 00:33:01 +00:00
|
|
|
.baseline = ppcBaseline,
|
2012-10-15 09:07:50 +00:00
|
|
|
.update = PowerPCUpdate,
|
2011-10-03 12:56:20 +00:00
|
|
|
.hasFeature = NULL,
|
|
|
|
};
|