mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
cpu: Align ppc64 CPU data with x86
Use a typedef instead of the plain struct and heap allocation. This will make it easier to extend the ppc64 specific CPU data later on.
This commit is contained in:
parent
04f5a60d4b
commit
adb865df85
@ -38,7 +38,7 @@ struct _virCPUData {
|
|||||||
virArch arch;
|
virArch arch;
|
||||||
union {
|
union {
|
||||||
virCPUx86Data *x86;
|
virCPUx86Data *x86;
|
||||||
struct cpuPPC64Data ppc64;
|
virCPUppc64Data *ppc64;
|
||||||
/* generic driver needs no data */
|
/* generic driver needs no data */
|
||||||
} data;
|
} data;
|
||||||
};
|
};
|
||||||
|
@ -48,7 +48,7 @@ struct ppc64_vendor {
|
|||||||
struct ppc64_model {
|
struct ppc64_model {
|
||||||
char *name;
|
char *name;
|
||||||
const struct ppc64_vendor *vendor;
|
const struct ppc64_vendor *vendor;
|
||||||
struct cpuPPC64Data data;
|
virCPUppc64Data *data;
|
||||||
struct ppc64_model *next;
|
struct ppc64_model *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -57,6 +57,25 @@ struct ppc64_map {
|
|||||||
struct ppc64_model *models;
|
struct ppc64_model *models;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void
|
||||||
|
ppc64DataFree(virCPUppc64Data *data)
|
||||||
|
{
|
||||||
|
VIR_FREE(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
static virCPUppc64Data *
|
||||||
|
ppc64DataCopy(const virCPUppc64Data *data)
|
||||||
|
{
|
||||||
|
virCPUppc64Data *copy;
|
||||||
|
|
||||||
|
if (VIR_ALLOC(copy) < 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
copy->pvr = data->pvr;
|
||||||
|
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ppc64VendorFree(struct ppc64_vendor *vendor)
|
ppc64VendorFree(struct ppc64_vendor *vendor)
|
||||||
{
|
{
|
||||||
@ -90,6 +109,7 @@ ppc64ModelFree(struct ppc64_model *model)
|
|||||||
if (!model)
|
if (!model)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
ppc64DataFree(model->data);
|
||||||
VIR_FREE(model->name);
|
VIR_FREE(model->name);
|
||||||
VIR_FREE(model);
|
VIR_FREE(model);
|
||||||
}
|
}
|
||||||
@ -99,16 +119,22 @@ ppc64ModelCopy(const struct ppc64_model *model)
|
|||||||
{
|
{
|
||||||
struct ppc64_model *copy;
|
struct ppc64_model *copy;
|
||||||
|
|
||||||
if (VIR_ALLOC(copy) < 0 ||
|
if (VIR_ALLOC(copy) < 0)
|
||||||
VIR_STRDUP(copy->name, model->name) < 0) {
|
goto error;
|
||||||
ppc64ModelFree(copy);
|
|
||||||
return NULL;
|
if (VIR_STRDUP(copy->name, model->name) < 0)
|
||||||
}
|
goto error;
|
||||||
|
|
||||||
|
if (!(copy->data = ppc64DataCopy(model->data)))
|
||||||
|
goto error;
|
||||||
|
|
||||||
copy->data.pvr = model->data.pvr;
|
|
||||||
copy->vendor = model->vendor;
|
copy->vendor = model->vendor;
|
||||||
|
|
||||||
return copy;
|
return copy;
|
||||||
|
|
||||||
|
error:
|
||||||
|
ppc64ModelFree(copy);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct ppc64_model *
|
static struct ppc64_model *
|
||||||
@ -136,7 +162,7 @@ ppc64ModelFindPVR(const struct ppc64_map *map,
|
|||||||
|
|
||||||
model = map->models;
|
model = map->models;
|
||||||
while (model) {
|
while (model) {
|
||||||
if (model->data.pvr == pvr)
|
if (model->data->pvr == pvr)
|
||||||
return model;
|
return model;
|
||||||
|
|
||||||
model = model->next;
|
model = model->next;
|
||||||
@ -237,6 +263,11 @@ ppc64ModelLoad(xmlXPathContextPtr ctxt,
|
|||||||
if (VIR_ALLOC(model) < 0)
|
if (VIR_ALLOC(model) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
if (VIR_ALLOC(model->data) < 0) {
|
||||||
|
ppc64ModelFree(model);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
model->name = virXPathString("string(@name)", ctxt);
|
model->name = virXPathString("string(@name)", ctxt);
|
||||||
if (!model->name) {
|
if (!model->name) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
@ -274,7 +305,7 @@ ppc64ModelLoad(xmlXPathContextPtr ctxt,
|
|||||||
model->name);
|
model->name);
|
||||||
goto ignore;
|
goto ignore;
|
||||||
}
|
}
|
||||||
model->data.pvr = pvr;
|
model->data->pvr = pvr;
|
||||||
|
|
||||||
if (!map->models) {
|
if (!map->models) {
|
||||||
map->models = model;
|
map->models = model;
|
||||||
@ -318,7 +349,7 @@ ppc64LoadMap(void)
|
|||||||
struct ppc64_map *map;
|
struct ppc64_map *map;
|
||||||
|
|
||||||
if (VIR_ALLOC(map) < 0)
|
if (VIR_ALLOC(map) < 0)
|
||||||
return NULL;
|
goto error;
|
||||||
|
|
||||||
if (cpuMapLoad("ppc64", ppc64MapLoadCallback, map) < 0)
|
if (cpuMapLoad("ppc64", ppc64MapLoadCallback, map) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
@ -332,7 +363,7 @@ ppc64LoadMap(void)
|
|||||||
|
|
||||||
static virCPUDataPtr
|
static virCPUDataPtr
|
||||||
ppc64MakeCPUData(virArch arch,
|
ppc64MakeCPUData(virArch arch,
|
||||||
struct cpuPPC64Data *data)
|
virCPUppc64Data *data)
|
||||||
{
|
{
|
||||||
virCPUDataPtr cpuData;
|
virCPUDataPtr cpuData;
|
||||||
|
|
||||||
@ -340,7 +371,9 @@ ppc64MakeCPUData(virArch arch,
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
cpuData->arch = arch;
|
cpuData->arch = arch;
|
||||||
cpuData->data.ppc64 = *data;
|
|
||||||
|
if (!(cpuData->data.ppc64 = ppc64DataCopy(data)))
|
||||||
|
VIR_FREE(cpuData);
|
||||||
|
|
||||||
return cpuData;
|
return cpuData;
|
||||||
}
|
}
|
||||||
@ -421,7 +454,7 @@ ppc64Compute(virCPUDefPtr host,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (guestData)
|
if (guestData)
|
||||||
if (!(*guestData = ppc64MakeCPUData(arch, &guest_model->data)))
|
if (!(*guestData = ppc64MakeCPUData(arch, guest_model->data)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
ret = VIR_CPU_COMPARE_IDENTICAL;
|
ret = VIR_CPU_COMPARE_IDENTICAL;
|
||||||
@ -473,10 +506,10 @@ ppc64DriverDecode(virCPUDefPtr cpu,
|
|||||||
if (!data || !(map = ppc64LoadMap()))
|
if (!data || !(map = ppc64LoadMap()))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (!(model = ppc64ModelFindPVR(map, data->data.ppc64.pvr))) {
|
if (!(model = ppc64ModelFindPVR(map, data->data.ppc64->pvr))) {
|
||||||
virReportError(VIR_ERR_OPERATION_FAILED,
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
||||||
_("Cannot find CPU model with PVR 0x%08x"),
|
_("Cannot find CPU model with PVR 0x%08x"),
|
||||||
data->data.ppc64.pvr);
|
data->data.ppc64->pvr);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -506,25 +539,36 @@ ppc64DriverFree(virCPUDataPtr data)
|
|||||||
if (!data)
|
if (!data)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
ppc64DataFree(data->data.ppc64);
|
||||||
VIR_FREE(data);
|
VIR_FREE(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static virCPUDataPtr
|
static virCPUDataPtr
|
||||||
ppc64DriverNodeData(virArch arch)
|
ppc64DriverNodeData(virArch arch)
|
||||||
{
|
{
|
||||||
virCPUDataPtr cpuData;
|
virCPUDataPtr nodeData;
|
||||||
|
virCPUppc64Data *data;
|
||||||
|
|
||||||
if (VIR_ALLOC(cpuData) < 0)
|
if (VIR_ALLOC(nodeData) < 0)
|
||||||
return NULL;
|
goto error;
|
||||||
|
|
||||||
cpuData->arch = arch;
|
if (VIR_ALLOC(data) < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
data = nodeData->data.ppc64;
|
||||||
|
|
||||||
#if defined(__powerpc__) || defined(__powerpc64__)
|
#if defined(__powerpc__) || defined(__powerpc64__)
|
||||||
asm("mfpvr %0"
|
asm("mfpvr %0"
|
||||||
: "=r" (cpuData->data.ppc64.pvr));
|
: "=r" (data->pvr));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return cpuData;
|
nodeData->arch = arch;
|
||||||
|
|
||||||
|
return nodeData;
|
||||||
|
|
||||||
|
error:
|
||||||
|
ppc64DriverFree(nodeData);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static virCPUCompareResult
|
static virCPUCompareResult
|
||||||
|
@ -26,7 +26,8 @@
|
|||||||
|
|
||||||
# include <stdint.h>
|
# include <stdint.h>
|
||||||
|
|
||||||
struct cpuPPC64Data {
|
typedef struct _virCPUppc64Data virCPUppc64Data;
|
||||||
|
struct _virCPUppc64Data {
|
||||||
uint32_t pvr;
|
uint32_t pvr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user