cpu.h 6.9 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
# include "domain_capabilities.h"
31
# include "cpu_conf.h"
32
# include "cpu_x86_data.h"
33
# include "cpu_ppc64_data.h"
J
Jiri Denemark 已提交
34 35


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


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

typedef int
(*cpuArchDecode)    (virCPUDefPtr cpu,
55
                     const virCPUData *data,
56
                     virDomainCapsCPUModelsPtr models);
J
Jiri Denemark 已提交
57 58

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

typedef void
69
(*cpuArchDataFree)  (virCPUDataPtr data);
J
Jiri Denemark 已提交
70

71
typedef int
72
(*virCPUArchGetHost)(virCPUDefPtr cpu,
73
                     virDomainCapsCPUModelsPtr models);
J
Jiri Denemark 已提交
74

75
typedef virCPUDefPtr
76 77 78 79
(*virCPUArchBaseline)(virCPUDefPtr *cpus,
                      unsigned int ncpus,
                      virDomainCapsCPUModelsPtr models,
                      bool migratable);
80

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

85 86 87 88 89
typedef int
(*virCPUArchUpdateLive)(virCPUDefPtr cpu,
                        virCPUDataPtr dataEnabled,
                        virCPUDataPtr dataDisabled);

90 91 92 93
typedef int
(*virCPUArchCheckFeature)(const virCPUDef *cpu,
                          const char *feature);

D
Daniel P. Berrange 已提交
94
typedef int
95 96
(*virCPUArchDataCheckFeature)(const virCPUData *data,
                              const char *feature);
D
Daniel P. Berrange 已提交
97

98
typedef char *
J
Jiri Denemark 已提交
99
(*virCPUArchDataFormat)(const virCPUData *data);
100 101

typedef virCPUDataPtr
J
Jiri Denemark 已提交
102
(*virCPUArchDataParse)(xmlXPathContextPtr ctxt);
J
Jiri Denemark 已提交
103

104
typedef int
J
Jiri Denemark 已提交
105
(*virCPUArchGetModels)(char ***models);
106

J
Jiri Denemark 已提交
107 108
typedef int
(*virCPUArchTranslate)(virCPUDefPtr cpu,
109
                       virDomainCapsCPUModelsPtr models);
J
Jiri Denemark 已提交
110

111 112 113
typedef int
(*virCPUArchConvertLegacy)(virCPUDefPtr cpu);

114 115 116
typedef int
(*virCPUArchExpandFeatures)(virCPUDefPtr cpu);

117 118 119
typedef virCPUDefPtr
(*virCPUArchCopyMigratable)(virCPUDefPtr cpu);

120 121 122
typedef int
(*virCPUArchValidateFeatures)(virCPUDefPtr cpu);

J
Jiri Denemark 已提交
123 124
struct cpuArchDriver {
    const char *name;
125
    const virArch *arch;
J
Jiri Denemark 已提交
126
    unsigned int narch;
J
Jiri Denemark 已提交
127
    virCPUArchCompare   compare;
J
Jiri Denemark 已提交
128 129
    cpuArchDecode       decode;
    cpuArchEncode       encode;
J
Jiri Denemark 已提交
130
    cpuArchDataFree     dataFree;
131
    virCPUArchGetHost   getHost;
132
    virCPUArchBaseline baseline;
J
Jiri Denemark 已提交
133
    virCPUArchUpdate    update;
134
    virCPUArchUpdateLive updateLive;
135
    virCPUArchCheckFeature checkFeature;
136
    virCPUArchDataCheckFeature dataCheckFeature;
J
Jiri Denemark 已提交
137
    virCPUArchDataFormat dataFormat;
J
Jiri Denemark 已提交
138
    virCPUArchDataParse dataParse;
J
Jiri Denemark 已提交
139
    virCPUArchGetModels getModels;
J
Jiri Denemark 已提交
140
    virCPUArchTranslate translate;
141
    virCPUArchConvertLegacy convertLegacy;
142
    virCPUArchExpandFeatures expandFeatures;
143
    virCPUArchCopyMigratable copyMigratable;
144
    virCPUArchValidateFeatures validateFeatures;
J
Jiri Denemark 已提交
145 146 147
};


148
virCPUCompareResult
J
Jiri Denemark 已提交
149 150 151 152
virCPUCompareXML(virArch arch,
                 virCPUDefPtr host,
                 const char *xml,
                 bool failIncompatible);
J
Jiri Denemark 已提交
153

154
virCPUCompareResult
J
Jiri Denemark 已提交
155 156 157 158 159
virCPUCompare(virArch arch,
              virCPUDefPtr host,
              virCPUDefPtr cpu,
              bool failIncompatible)
    ATTRIBUTE_NONNULL(3);
J
Jiri Denemark 已提交
160

161
int
162
cpuDecode   (virCPUDefPtr cpu,
163
             const virCPUData *data,
164
             virDomainCapsCPUModelsPtr models)
165
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
J
Jiri Denemark 已提交
166

167
int
168
cpuEncode   (virArch arch,
169
             const virCPUDef *cpu,
170 171 172 173 174
             virCPUDataPtr *forced,
             virCPUDataPtr *required,
             virCPUDataPtr *optional,
             virCPUDataPtr *disabled,
             virCPUDataPtr *forbidden,
175 176
             virCPUDataPtr *vendor)
    ATTRIBUTE_NONNULL(2);
J
Jiri Denemark 已提交
177

J
Jiri Denemark 已提交
178 179 180
virCPUDataPtr
virCPUDataNew(virArch arch);

181
void
J
Jiri Denemark 已提交
182
virCPUDataFree(virCPUDataPtr data);
J
Jiri Denemark 已提交
183

184 185 186
bool
virCPUGetHostIsSupported(virArch arch);

187 188
virCPUDefPtr
virCPUGetHost(virArch arch,
189
              virCPUType type,
190
              virNodeInfoPtr nodeInfo,
191
              virDomainCapsCPUModelsPtr models);
J
Jiri Denemark 已提交
192

M
Martin Kletzander 已提交
193 194 195
virCPUDefPtr
virCPUProbeHost(virArch arch);

196
virCPUDefPtr
197 198 199 200
virCPUBaseline(virCPUDefPtr *cpus,
               unsigned int ncpus,
               virDomainCapsCPUModelsPtr models,
               bool migratable);
201

202
int
J
Jiri Denemark 已提交
203 204
virCPUUpdate(virArch arch,
             virCPUDefPtr guest,
205
             const virCPUDef *host)
J
Jiri Denemark 已提交
206
    ATTRIBUTE_NONNULL(2);
207

208 209 210 211 212 213
int
virCPUUpdateLive(virArch arch,
                 virCPUDefPtr cpu,
                 virCPUDataPtr dataEnabled,
                 virCPUDataPtr dataDisabled)
    ATTRIBUTE_NONNULL(2);
214 215 216 217 218 219 220 221

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


222
int
223 224
virCPUDataCheckFeature(const virCPUData *data,
                       const char *feature)
225
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
D
Daniel P. Berrange 已提交
226 227


228
bool
229
virCPUModelIsAllowed(const char *model,
230
                     virDomainCapsCPUModelsPtr models)
231
    ATTRIBUTE_NONNULL(1);
232

233
int
J
Jiri Denemark 已提交
234
virCPUGetModels(virArch arch, char ***models);
235

J
Jiri Denemark 已提交
236 237 238
int
virCPUTranslate(virArch arch,
                virCPUDefPtr cpu,
239
                virDomainCapsCPUModelsPtr models)
J
Jiri Denemark 已提交
240 241
    ATTRIBUTE_NONNULL(2);

242 243 244 245
int
virCPUConvertLegacy(virArch arch,
                    virCPUDefPtr cpu)
    ATTRIBUTE_NONNULL(2);
J
Jiri Denemark 已提交
246

247 248 249 250
int
virCPUExpandFeatures(virArch arch,
                     virCPUDefPtr cpu);

251 252 253 254
virCPUDefPtr
virCPUCopyMigratable(virArch arch,
                     virCPUDefPtr cpu);

255 256 257 258 259
int
virCPUValidateFeatures(virArch arch,
                       virCPUDefPtr cpu)
    ATTRIBUTE_NONNULL(2);

J
Jiri Denemark 已提交
260
/* virCPUDataFormat and virCPUDataParse are implemented for unit tests only and
261 262
 * have no real-life usage
 */
J
Jiri Denemark 已提交
263
char *virCPUDataFormat(const virCPUData *data)
264
    ATTRIBUTE_NONNULL(1);
J
Jiri Denemark 已提交
265
virCPUDataPtr virCPUDataParse(const char *xmlStr)
266
    ATTRIBUTE_NONNULL(1);
267

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