cpu.h 6.2 KB
Newer Older
J
Jiri Denemark 已提交
1 2 3
/*
 * cpu.h: internal functions for CPU manipulation
 *
4
 * Copyright (C) 2009-2010, 2013 Red Hat, Inc.
J
Jiri Denemark 已提交
5 6 7 8 9 10 11 12 13 14 15 16
 *
 * 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
17
 * License along with this library.  If not, see
O
Osier Yang 已提交
18
 * <http://www.gnu.org/licenses/>.
J
Jiri Denemark 已提交
19 20 21 22 23 24
 *
 * Authors:
 *      Jiri Denemark <jdenemar@redhat.com>
 */

#ifndef __VIR_CPU_H__
25
# define __VIR_CPU_H__
J
Jiri Denemark 已提交
26

27
# include "virerror.h"
28
# include "datatypes.h"
29
# include "virarch.h"
30 31
# include "conf/cpu_conf.h"
# include "cpu_x86_data.h"
32
# include "cpu_ppc64_data.h"
J
Jiri Denemark 已提交
33 34


J
Jiri Denemark 已提交
35
typedef struct _virCPUData virCPUData;
36
typedef virCPUData *virCPUDataPtr;
J
Jiri Denemark 已提交
37 38 39
struct _virCPUData {
    virArch arch;
    union {
40
        virCPUx86Data x86;
41
        virCPUppc64Data ppc64;
J
Jiri Denemark 已提交
42 43
        /* generic driver needs no data */
    } data;
J
Jiri Denemark 已提交
44 45 46 47
};


typedef virCPUCompareResult
J
Jiri Denemark 已提交
48
(*virCPUArchCompare)(virCPUDefPtr host,
49 50
                     virCPUDefPtr cpu,
                     bool failIncompatible);
J
Jiri Denemark 已提交
51 52 53

typedef int
(*cpuArchDecode)    (virCPUDefPtr cpu,
54
                     const virCPUData *data,
55
                     const char **models,
56
                     unsigned int nmodels,
57 58
                     const char *preferred,
                     unsigned int flags);
J
Jiri Denemark 已提交
59 60

typedef int
J
Jiri Denemark 已提交
61
(*cpuArchEncode)    (virArch arch,
62
                     const virCPUDef *cpu,
63 64 65 66 67 68
                     virCPUDataPtr *forced,
                     virCPUDataPtr *required,
                     virCPUDataPtr *optional,
                     virCPUDataPtr *disabled,
                     virCPUDataPtr *forbidden,
                     virCPUDataPtr *vendor);
J
Jiri Denemark 已提交
69 70

typedef void
71
(*cpuArchDataFree)  (virCPUDataPtr data);
J
Jiri Denemark 已提交
72

73
typedef virCPUDataPtr
74
(*cpuArchNodeData)  (virArch arch);
J
Jiri Denemark 已提交
75

76 77 78 79
typedef virCPUDefPtr
(*cpuArchBaseline)  (virCPUDefPtr *cpus,
                     unsigned int ncpus,
                     const char **models,
80 81
                     unsigned int nmodels,
                     unsigned int flags);
82

83
typedef int
J
Jiri Denemark 已提交
84 85
(*virCPUArchUpdate)(virCPUDefPtr guest,
                    const virCPUDef *host);
86

87 88 89 90
typedef int
(*virCPUArchCheckFeature)(const virCPUDef *cpu,
                          const char *feature);

D
Daniel P. Berrange 已提交
91
typedef int
92 93
(*virCPUArchDataCheckFeature)(const virCPUData *data,
                              const char *feature);
D
Daniel P. Berrange 已提交
94

95
typedef char *
J
Jiri Denemark 已提交
96
(*virCPUArchDataFormat)(const virCPUData *data);
97 98

typedef virCPUDataPtr
J
Jiri Denemark 已提交
99
(*virCPUArchDataParse)(xmlXPathContextPtr ctxt);
J
Jiri Denemark 已提交
100

101
typedef int
J
Jiri Denemark 已提交
102
(*virCPUArchGetModels)(char ***models);
103

J
Jiri Denemark 已提交
104 105 106 107 108
typedef int
(*virCPUArchTranslate)(virCPUDefPtr cpu,
                       const char **models,
                       unsigned int nmodels);

109 110 111
typedef int
(*virCPUArchConvertLegacy)(virCPUDefPtr cpu);

J
Jiri Denemark 已提交
112 113
struct cpuArchDriver {
    const char *name;
114
    const virArch *arch;
J
Jiri Denemark 已提交
115
    unsigned int narch;
J
Jiri Denemark 已提交
116
    virCPUArchCompare   compare;
J
Jiri Denemark 已提交
117 118 119 120
    cpuArchDecode       decode;
    cpuArchEncode       encode;
    cpuArchDataFree     free;
    cpuArchNodeData     nodeData;
121
    cpuArchBaseline     baseline;
J
Jiri Denemark 已提交
122
    virCPUArchUpdate    update;
123
    virCPUArchCheckFeature checkFeature;
124
    virCPUArchDataCheckFeature dataCheckFeature;
J
Jiri Denemark 已提交
125
    virCPUArchDataFormat dataFormat;
J
Jiri Denemark 已提交
126
    virCPUArchDataParse dataParse;
J
Jiri Denemark 已提交
127
    virCPUArchGetModels getModels;
J
Jiri Denemark 已提交
128
    virCPUArchTranslate translate;
129
    virCPUArchConvertLegacy convertLegacy;
J
Jiri Denemark 已提交
130 131 132
};


133
virCPUCompareResult
J
Jiri Denemark 已提交
134 135 136 137
virCPUCompareXML(virArch arch,
                 virCPUDefPtr host,
                 const char *xml,
                 bool failIncompatible);
J
Jiri Denemark 已提交
138

139
virCPUCompareResult
J
Jiri Denemark 已提交
140 141 142 143 144
virCPUCompare(virArch arch,
              virCPUDefPtr host,
              virCPUDefPtr cpu,
              bool failIncompatible)
    ATTRIBUTE_NONNULL(3);
J
Jiri Denemark 已提交
145

146
int
147
cpuDecode   (virCPUDefPtr cpu,
148
             const virCPUData *data,
149
             const char **models,
150
             unsigned int nmodels,
151 152
             const char *preferred)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
J
Jiri Denemark 已提交
153

154
int
155
cpuEncode   (virArch arch,
156
             const virCPUDef *cpu,
157 158 159 160 161
             virCPUDataPtr *forced,
             virCPUDataPtr *required,
             virCPUDataPtr *optional,
             virCPUDataPtr *disabled,
             virCPUDataPtr *forbidden,
162 163
             virCPUDataPtr *vendor)
    ATTRIBUTE_NONNULL(2);
J
Jiri Denemark 已提交
164

J
Jiri Denemark 已提交
165 166 167
virCPUDataPtr
virCPUDataNew(virArch arch);

168
void
J
Jiri Denemark 已提交
169
cpuDataFree (virCPUDataPtr data);
J
Jiri Denemark 已提交
170

171
virCPUDataPtr
172
cpuNodeData (virArch arch);
J
Jiri Denemark 已提交
173

174
char *
175 176 177
cpuBaselineXML(const char **xmlCPUs,
               unsigned int ncpus,
               const char **models,
178 179
               unsigned int nmodels,
               unsigned int flags);
180

181
virCPUDefPtr
182 183 184
cpuBaseline (virCPUDefPtr *cpus,
             unsigned int ncpus,
             const char **models,
185
             unsigned int nmodels,
186 187
             unsigned int flags)
    ATTRIBUTE_NONNULL(1);
188

189
int
J
Jiri Denemark 已提交
190 191
virCPUUpdate(virArch arch,
             virCPUDefPtr guest,
192
             const virCPUDef *host)
J
Jiri Denemark 已提交
193
    ATTRIBUTE_NONNULL(2);
194

195 196 197 198 199 200 201 202

int
virCPUCheckFeature(virArch arch,
                   const virCPUDef *cpu,
                   const char *feature)
    ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);


203
int
204 205
virCPUDataCheckFeature(const virCPUData *data,
                       const char *feature)
206
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
D
Daniel P. Berrange 已提交
207 208


209
bool
210 211 212
virCPUModelIsAllowed(const char *model,
                     const char **models,
                     unsigned int nmodels)
213
    ATTRIBUTE_NONNULL(1);
214

215
int
J
Jiri Denemark 已提交
216
virCPUGetModels(virArch arch, char ***models);
217

J
Jiri Denemark 已提交
218 219 220
int
virCPUTranslate(virArch arch,
                virCPUDefPtr cpu,
221
                const char **models,
J
Jiri Denemark 已提交
222 223 224
                unsigned int nmodels)
    ATTRIBUTE_NONNULL(2);

225 226 227 228
int
virCPUConvertLegacy(virArch arch,
                    virCPUDefPtr cpu)
    ATTRIBUTE_NONNULL(2);
J
Jiri Denemark 已提交
229

J
Jiri Denemark 已提交
230
/* virCPUDataFormat and virCPUDataParse are implemented for unit tests only and
231 232
 * have no real-life usage
 */
J
Jiri Denemark 已提交
233
char *virCPUDataFormat(const virCPUData *data)
234
    ATTRIBUTE_NONNULL(1);
J
Jiri Denemark 已提交
235
virCPUDataPtr virCPUDataParse(const char *xmlStr)
236
    ATTRIBUTE_NONNULL(1);
237

J
Jiri Denemark 已提交
238
#endif /* __VIR_CPU_H__ */