2 * QEMU PowerPC pSeries Logical Partition capabilities handling
4 * Copyright (c) 2017 David Gibson, Red Hat Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 #include "qemu/osdep.h"
25 #include "qemu/error-report.h"
26 #include "qapi/error.h"
27 #include "qapi/visitor.h"
28 #include "sysemu/hw_accel.h"
29 #include "exec/ram_addr.h"
30 #include "target/ppc/cpu.h"
31 #include "target/ppc/mmu-hash64.h"
32 #include "cpu-models.h"
34 #include "sysemu/qtest.h"
36 #include "hw/ppc/spapr.h"
38 typedef struct SpaprCapPossible
{
39 int num
; /* size of vals array below */
40 const char *help
; /* help text for vals */
43 * - because of the way compatibility is determined vals MUST be ordered
44 * such that later options are a superset of all preceding options.
45 * - the order of vals must be preserved, that is their index is important,
46 * however vals may be added to the end of the list so long as the above
52 typedef struct SpaprCapabilityInfo
{
54 const char *description
;
57 /* Getter and Setter Function Pointers */
58 ObjectPropertyAccessor
*get
;
59 ObjectPropertyAccessor
*set
;
61 /* Possible values if this is a custom string type */
62 SpaprCapPossible
*possible
;
63 /* Make sure the virtual hardware can support this capability */
64 void (*apply
)(SpaprMachineState
*spapr
, uint8_t val
, Error
**errp
);
65 void (*cpu_apply
)(SpaprMachineState
*spapr
, PowerPCCPU
*cpu
,
66 uint8_t val
, Error
**errp
);
67 } SpaprCapabilityInfo
;
69 static void spapr_cap_get_bool(Object
*obj
, Visitor
*v
, const char *name
,
70 void *opaque
, Error
**errp
)
72 SpaprCapabilityInfo
*cap
= opaque
;
73 SpaprMachineState
*spapr
= SPAPR_MACHINE(obj
);
74 bool value
= spapr_get_cap(spapr
, cap
->index
) == SPAPR_CAP_ON
;
76 visit_type_bool(v
, name
, &value
, errp
);
79 static void spapr_cap_set_bool(Object
*obj
, Visitor
*v
, const char *name
,
80 void *opaque
, Error
**errp
)
82 SpaprCapabilityInfo
*cap
= opaque
;
83 SpaprMachineState
*spapr
= SPAPR_MACHINE(obj
);
85 Error
*local_err
= NULL
;
87 visit_type_bool(v
, name
, &value
, &local_err
);
89 error_propagate(errp
, local_err
);
93 spapr
->cmd_line_caps
[cap
->index
] = true;
94 spapr
->eff
.caps
[cap
->index
] = value
? SPAPR_CAP_ON
: SPAPR_CAP_OFF
;
98 static void spapr_cap_get_string(Object
*obj
, Visitor
*v
, const char *name
,
99 void *opaque
, Error
**errp
)
101 SpaprCapabilityInfo
*cap
= opaque
;
102 SpaprMachineState
*spapr
= SPAPR_MACHINE(obj
);
104 uint8_t value
= spapr_get_cap(spapr
, cap
->index
);
106 if (value
>= cap
->possible
->num
) {
107 error_setg(errp
, "Invalid value (%d) for cap-%s", value
, cap
->name
);
111 val
= g_strdup(cap
->possible
->vals
[value
]);
113 visit_type_str(v
, name
, &val
, errp
);
117 static void spapr_cap_set_string(Object
*obj
, Visitor
*v
, const char *name
,
118 void *opaque
, Error
**errp
)
120 SpaprCapabilityInfo
*cap
= opaque
;
121 SpaprMachineState
*spapr
= SPAPR_MACHINE(obj
);
122 Error
*local_err
= NULL
;
126 visit_type_str(v
, name
, &val
, &local_err
);
128 error_propagate(errp
, local_err
);
132 if (!strcmp(val
, "?")) {
133 error_setg(errp
, "%s", cap
->possible
->help
);
136 for (i
= 0; i
< cap
->possible
->num
; i
++) {
137 if (!strcasecmp(val
, cap
->possible
->vals
[i
])) {
138 spapr
->cmd_line_caps
[cap
->index
] = true;
139 spapr
->eff
.caps
[cap
->index
] = i
;
144 error_setg(errp
, "Invalid capability mode \"%s\" for cap-%s", val
,
150 static void spapr_cap_get_pagesize(Object
*obj
, Visitor
*v
, const char *name
,
151 void *opaque
, Error
**errp
)
153 SpaprCapabilityInfo
*cap
= opaque
;
154 SpaprMachineState
*spapr
= SPAPR_MACHINE(obj
);
155 uint8_t val
= spapr_get_cap(spapr
, cap
->index
);
156 uint64_t pagesize
= (1ULL << val
);
158 visit_type_size(v
, name
, &pagesize
, errp
);
161 static void spapr_cap_set_pagesize(Object
*obj
, Visitor
*v
, const char *name
,
162 void *opaque
, Error
**errp
)
164 SpaprCapabilityInfo
*cap
= opaque
;
165 SpaprMachineState
*spapr
= SPAPR_MACHINE(obj
);
168 Error
*local_err
= NULL
;
170 visit_type_size(v
, name
, &pagesize
, &local_err
);
172 error_propagate(errp
, local_err
);
176 if (!is_power_of_2(pagesize
)) {
177 error_setg(errp
, "cap-%s must be a power of 2", cap
->name
);
181 val
= ctz64(pagesize
);
182 spapr
->cmd_line_caps
[cap
->index
] = true;
183 spapr
->eff
.caps
[cap
->index
] = val
;
186 static void cap_htm_apply(SpaprMachineState
*spapr
, uint8_t val
, Error
**errp
)
189 /* TODO: We don't support disabling htm yet */
194 "No Transactional Memory support in TCG, try cap-htm=off");
195 } else if (kvm_enabled() && !kvmppc_has_cap_htm()) {
197 "KVM implementation does not support Transactional Memory, try cap-htm=off"
202 static void cap_vsx_apply(SpaprMachineState
*spapr
, uint8_t val
, Error
**errp
)
204 PowerPCCPU
*cpu
= POWERPC_CPU(first_cpu
);
205 CPUPPCState
*env
= &cpu
->env
;
208 /* TODO: We don't support disabling vsx yet */
211 /* Allowable CPUs in spapr_cpu_core.c should already have gotten
212 * rid of anything that doesn't do VMX */
213 g_assert(env
->insns_flags
& PPC_ALTIVEC
);
214 if (!(env
->insns_flags2
& PPC2_VSX
)) {
215 error_setg(errp
, "VSX support not available, try cap-vsx=off");
219 static void cap_dfp_apply(SpaprMachineState
*spapr
, uint8_t val
, Error
**errp
)
221 PowerPCCPU
*cpu
= POWERPC_CPU(first_cpu
);
222 CPUPPCState
*env
= &cpu
->env
;
225 /* TODO: We don't support disabling dfp yet */
228 if (!(env
->insns_flags2
& PPC2_DFP
)) {
229 error_setg(errp
, "DFP support not available, try cap-dfp=off");
233 SpaprCapPossible cap_cfpc_possible
= {
235 .vals
= {"broken", "workaround", "fixed"},
236 .help
= "broken - no protection, workaround - workaround available,"
237 " fixed - fixed in hardware",
240 static void cap_safe_cache_apply(SpaprMachineState
*spapr
, uint8_t val
,
243 Error
*local_err
= NULL
;
244 uint8_t kvm_val
= kvmppc_get_cap_safe_cache();
246 if (tcg_enabled() && val
) {
247 /* TCG only supports broken, allow other values and print a warning */
248 error_setg(&local_err
,
249 "TCG doesn't support requested feature, cap-cfpc=%s",
250 cap_cfpc_possible
.vals
[val
]);
251 } else if (kvm_enabled() && (val
> kvm_val
)) {
253 "Requested safe cache capability level not supported by kvm, try cap-cfpc=%s",
254 cap_cfpc_possible
.vals
[kvm_val
]);
257 if (local_err
!= NULL
)
258 warn_report_err(local_err
);
261 SpaprCapPossible cap_sbbc_possible
= {
263 .vals
= {"broken", "workaround", "fixed"},
264 .help
= "broken - no protection, workaround - workaround available,"
265 " fixed - fixed in hardware",
268 static void cap_safe_bounds_check_apply(SpaprMachineState
*spapr
, uint8_t val
,
271 Error
*local_err
= NULL
;
272 uint8_t kvm_val
= kvmppc_get_cap_safe_bounds_check();
274 if (tcg_enabled() && val
) {
275 /* TCG only supports broken, allow other values and print a warning */
276 error_setg(&local_err
,
277 "TCG doesn't support requested feature, cap-sbbc=%s",
278 cap_sbbc_possible
.vals
[val
]);
279 } else if (kvm_enabled() && (val
> kvm_val
)) {
281 "Requested safe bounds check capability level not supported by kvm, try cap-sbbc=%s",
282 cap_sbbc_possible
.vals
[kvm_val
]);
285 if (local_err
!= NULL
)
286 warn_report_err(local_err
);
289 SpaprCapPossible cap_ibs_possible
= {
291 /* Note workaround only maintained for compatibility */
292 .vals
= {"broken", "workaround", "fixed-ibs", "fixed-ccd", "fixed-na"},
293 .help
= "broken - no protection, workaround - count cache flush"
294 ", fixed-ibs - indirect branch serialisation,"
295 " fixed-ccd - cache count disabled,"
296 " fixed-na - fixed in hardware (no longer applicable)",
299 static void cap_safe_indirect_branch_apply(SpaprMachineState
*spapr
,
300 uint8_t val
, Error
**errp
)
302 Error
*local_err
= NULL
;
303 uint8_t kvm_val
= kvmppc_get_cap_safe_indirect_branch();
305 if (tcg_enabled() && val
) {
306 /* TCG only supports broken, allow other values and print a warning */
307 error_setg(&local_err
,
308 "TCG doesn't support requested feature, cap-ibs=%s",
309 cap_ibs_possible
.vals
[val
]);
310 } else if (kvm_enabled() && (val
> kvm_val
)) {
312 "Requested safe indirect branch capability level not supported by kvm, try cap-ibs=%s",
313 cap_ibs_possible
.vals
[kvm_val
]);
316 if (local_err
!= NULL
) {
317 warn_report_err(local_err
);
321 #define VALUE_DESC_TRISTATE " (broken, workaround, fixed)"
323 void spapr_check_pagesize(SpaprMachineState
*spapr
, hwaddr pagesize
,
326 hwaddr maxpagesize
= (1ULL << spapr
->eff
.caps
[SPAPR_CAP_HPT_MAXPAGESIZE
]);
328 if (!kvmppc_hpt_needs_host_contiguous_pages()) {
332 if (maxpagesize
> pagesize
) {
334 "Can't support %"HWADDR_PRIu
" kiB guest pages with %"
335 HWADDR_PRIu
" kiB host pages with this KVM implementation",
336 maxpagesize
>> 10, pagesize
>> 10);
340 static void cap_hpt_maxpagesize_apply(SpaprMachineState
*spapr
,
341 uint8_t val
, Error
**errp
)
344 error_setg(errp
, "Require at least 4kiB hpt-max-page-size");
346 } else if (val
< 16) {
347 warn_report("Many guests require at least 64kiB hpt-max-page-size");
350 spapr_check_pagesize(spapr
, qemu_getrampagesize(), errp
);
353 static bool spapr_pagesize_cb(void *opaque
, uint32_t seg_pshift
,
356 unsigned maxshift
= *((unsigned *)opaque
);
358 assert(pshift
>= seg_pshift
);
360 /* Don't allow the guest to use pages bigger than the configured
362 if (pshift
> maxshift
) {
366 /* For whatever reason, KVM doesn't allow multiple pagesizes
367 * within a segment, *except* for the case of 16M pages in a 4k or
368 * 64k segment. Always exclude other cases, so that TCG and KVM
369 * guests see a consistent environment */
370 if ((pshift
!= seg_pshift
) && (pshift
!= 24)) {
377 static void cap_hpt_maxpagesize_cpu_apply(SpaprMachineState
*spapr
,
379 uint8_t val
, Error
**errp
)
381 unsigned maxshift
= val
;
383 ppc_hash64_filter_pagesizes(cpu
, spapr_pagesize_cb
, &maxshift
);
386 static void cap_nested_kvm_hv_apply(SpaprMachineState
*spapr
,
387 uint8_t val
, Error
**errp
)
390 /* capability disabled by default */
396 "No Nested KVM-HV support in tcg, try cap-nested-hv=off");
397 } else if (kvm_enabled()) {
398 if (!kvmppc_has_cap_nested_kvm_hv()) {
400 "KVM implementation does not support Nested KVM-HV, try cap-nested-hv=off");
401 } else if (kvmppc_set_cap_nested_kvm_hv(val
) < 0) {
403 "Error enabling cap-nested-hv with KVM, try cap-nested-hv=off");
408 static void cap_large_decr_apply(SpaprMachineState
*spapr
,
409 uint8_t val
, Error
**errp
)
411 PowerPCCPU
*cpu
= POWERPC_CPU(first_cpu
);
412 PowerPCCPUClass
*pcc
= POWERPC_CPU_GET_CLASS(cpu
);
415 return; /* Disabled by default */
419 if (!ppc_check_compat(cpu
, CPU_POWERPC_LOGICAL_3_00
, 0,
420 spapr
->max_compat_pvr
)) {
422 "Large decrementer only supported on POWER9, try -cpu POWER9");
425 } else if (kvm_enabled()) {
426 int kvm_nr_bits
= kvmppc_get_cap_large_decr();
430 "No large decrementer support, try cap-large-decr=off");
431 } else if (pcc
->lrg_decr_bits
!= kvm_nr_bits
) {
433 "KVM large decrementer size (%d) differs to model (%d), try -cap-large-decr=off",
434 kvm_nr_bits
, pcc
->lrg_decr_bits
);
439 static void cap_large_decr_cpu_apply(SpaprMachineState
*spapr
,
441 uint8_t val
, Error
**errp
)
443 CPUPPCState
*env
= &cpu
->env
;
444 target_ulong lpcr
= env
->spr
[SPR_LPCR
];
447 if (kvmppc_enable_cap_large_decr(cpu
, val
)) {
449 "No large decrementer support, try cap-large-decr=off");
458 ppc_store_lpcr(cpu
, lpcr
);
461 static void cap_ccf_assist_apply(SpaprMachineState
*spapr
, uint8_t val
,
464 uint8_t kvm_val
= kvmppc_get_cap_count_cache_flush_assist();
466 if (tcg_enabled() && val
) {
467 /* TODO - for now only allow broken for TCG */
469 "Requested count cache flush assist capability level not supported by tcg, try cap-ccf-assist=off");
470 } else if (kvm_enabled() && (val
> kvm_val
)) {
472 "Requested count cache flush assist capability level not supported by kvm, try cap-ccf-assist=off");
476 SpaprCapabilityInfo capability_table
[SPAPR_CAP_NUM
] = {
479 .description
= "Allow Hardware Transactional Memory (HTM)",
480 .index
= SPAPR_CAP_HTM
,
481 .get
= spapr_cap_get_bool
,
482 .set
= spapr_cap_set_bool
,
484 .apply
= cap_htm_apply
,
488 .description
= "Allow Vector Scalar Extensions (VSX)",
489 .index
= SPAPR_CAP_VSX
,
490 .get
= spapr_cap_get_bool
,
491 .set
= spapr_cap_set_bool
,
493 .apply
= cap_vsx_apply
,
497 .description
= "Allow Decimal Floating Point (DFP)",
498 .index
= SPAPR_CAP_DFP
,
499 .get
= spapr_cap_get_bool
,
500 .set
= spapr_cap_set_bool
,
502 .apply
= cap_dfp_apply
,
506 .description
= "Cache Flush on Privilege Change" VALUE_DESC_TRISTATE
,
507 .index
= SPAPR_CAP_CFPC
,
508 .get
= spapr_cap_get_string
,
509 .set
= spapr_cap_set_string
,
511 .possible
= &cap_cfpc_possible
,
512 .apply
= cap_safe_cache_apply
,
516 .description
= "Speculation Barrier Bounds Checking" VALUE_DESC_TRISTATE
,
517 .index
= SPAPR_CAP_SBBC
,
518 .get
= spapr_cap_get_string
,
519 .set
= spapr_cap_set_string
,
521 .possible
= &cap_sbbc_possible
,
522 .apply
= cap_safe_bounds_check_apply
,
527 "Indirect Branch Speculation (broken, workaround, fixed-ibs,"
528 "fixed-ccd, fixed-na)",
529 .index
= SPAPR_CAP_IBS
,
530 .get
= spapr_cap_get_string
,
531 .set
= spapr_cap_set_string
,
533 .possible
= &cap_ibs_possible
,
534 .apply
= cap_safe_indirect_branch_apply
,
536 [SPAPR_CAP_HPT_MAXPAGESIZE
] = {
537 .name
= "hpt-max-page-size",
538 .description
= "Maximum page size for Hash Page Table guests",
539 .index
= SPAPR_CAP_HPT_MAXPAGESIZE
,
540 .get
= spapr_cap_get_pagesize
,
541 .set
= spapr_cap_set_pagesize
,
543 .apply
= cap_hpt_maxpagesize_apply
,
544 .cpu_apply
= cap_hpt_maxpagesize_cpu_apply
,
546 [SPAPR_CAP_NESTED_KVM_HV
] = {
548 .description
= "Allow Nested KVM-HV",
549 .index
= SPAPR_CAP_NESTED_KVM_HV
,
550 .get
= spapr_cap_get_bool
,
551 .set
= spapr_cap_set_bool
,
553 .apply
= cap_nested_kvm_hv_apply
,
555 [SPAPR_CAP_LARGE_DECREMENTER
] = {
556 .name
= "large-decr",
557 .description
= "Allow Large Decrementer",
558 .index
= SPAPR_CAP_LARGE_DECREMENTER
,
559 .get
= spapr_cap_get_bool
,
560 .set
= spapr_cap_set_bool
,
562 .apply
= cap_large_decr_apply
,
563 .cpu_apply
= cap_large_decr_cpu_apply
,
565 [SPAPR_CAP_CCF_ASSIST
] = {
566 .name
= "ccf-assist",
567 .description
= "Count Cache Flush Assist via HW Instruction",
568 .index
= SPAPR_CAP_CCF_ASSIST
,
569 .get
= spapr_cap_get_bool
,
570 .set
= spapr_cap_set_bool
,
572 .apply
= cap_ccf_assist_apply
,
576 static SpaprCapabilities
default_caps_with_cpu(SpaprMachineState
*spapr
,
579 SpaprMachineClass
*smc
= SPAPR_MACHINE_GET_CLASS(spapr
);
580 SpaprCapabilities caps
;
582 caps
= smc
->default_caps
;
584 if (!ppc_type_check_compat(cputype
, CPU_POWERPC_LOGICAL_3_00
,
585 0, spapr
->max_compat_pvr
)) {
586 caps
.caps
[SPAPR_CAP_LARGE_DECREMENTER
] = SPAPR_CAP_OFF
;
589 if (!ppc_type_check_compat(cputype
, CPU_POWERPC_LOGICAL_2_07
,
590 0, spapr
->max_compat_pvr
)) {
591 caps
.caps
[SPAPR_CAP_HTM
] = SPAPR_CAP_OFF
;
592 caps
.caps
[SPAPR_CAP_CFPC
] = SPAPR_CAP_BROKEN
;
595 if (!ppc_type_check_compat(cputype
, CPU_POWERPC_LOGICAL_2_06_PLUS
,
596 0, spapr
->max_compat_pvr
)) {
597 caps
.caps
[SPAPR_CAP_SBBC
] = SPAPR_CAP_BROKEN
;
600 if (!ppc_type_check_compat(cputype
, CPU_POWERPC_LOGICAL_2_06
,
601 0, spapr
->max_compat_pvr
)) {
602 caps
.caps
[SPAPR_CAP_VSX
] = SPAPR_CAP_OFF
;
603 caps
.caps
[SPAPR_CAP_DFP
] = SPAPR_CAP_OFF
;
604 caps
.caps
[SPAPR_CAP_IBS
] = SPAPR_CAP_BROKEN
;
607 /* This is for pseries-2.12 and older */
608 if (smc
->default_caps
.caps
[SPAPR_CAP_HPT_MAXPAGESIZE
] == 0) {
611 if (kvmppc_hpt_needs_host_contiguous_pages()) {
612 mps
= ctz64(qemu_getrampagesize());
614 mps
= 34; /* allow everything up to 16GiB, i.e. everything */
617 caps
.caps
[SPAPR_CAP_HPT_MAXPAGESIZE
] = mps
;
623 int spapr_caps_pre_load(void *opaque
)
625 SpaprMachineState
*spapr
= opaque
;
627 /* Set to default so we can tell if this came in with the migration */
628 spapr
->mig
= spapr
->def
;
632 int spapr_caps_pre_save(void *opaque
)
634 SpaprMachineState
*spapr
= opaque
;
636 spapr
->mig
= spapr
->eff
;
640 /* This has to be called from the top-level spapr post_load, not the
641 * caps specific one. Otherwise it wouldn't be called when the source
642 * caps are all defaults, which could still conflict with overridden
643 * caps on the destination */
644 int spapr_caps_post_migration(SpaprMachineState
*spapr
)
648 SpaprCapabilities dstcaps
= spapr
->eff
;
649 SpaprCapabilities srccaps
;
651 srccaps
= default_caps_with_cpu(spapr
, MACHINE(spapr
)->cpu_type
);
652 for (i
= 0; i
< SPAPR_CAP_NUM
; i
++) {
653 /* If not default value then assume came in with the migration */
654 if (spapr
->mig
.caps
[i
] != spapr
->def
.caps
[i
]) {
655 srccaps
.caps
[i
] = spapr
->mig
.caps
[i
];
659 for (i
= 0; i
< SPAPR_CAP_NUM
; i
++) {
660 SpaprCapabilityInfo
*info
= &capability_table
[i
];
662 if (srccaps
.caps
[i
] > dstcaps
.caps
[i
]) {
663 error_report("cap-%s higher level (%d) in incoming stream than on destination (%d)",
664 info
->name
, srccaps
.caps
[i
], dstcaps
.caps
[i
]);
668 if (srccaps
.caps
[i
] < dstcaps
.caps
[i
]) {
669 warn_report("cap-%s lower level (%d) in incoming stream than on destination (%d)",
670 info
->name
, srccaps
.caps
[i
], dstcaps
.caps
[i
]);
674 return ok
? 0 : -EINVAL
;
677 /* Used to generate the migration field and needed function for a spapr cap */
678 #define SPAPR_CAP_MIG_STATE(sname, cap) \
679 static bool spapr_cap_##sname##_needed(void *opaque) \
681 SpaprMachineState *spapr = opaque; \
683 return spapr->cmd_line_caps[cap] && \
684 (spapr->eff.caps[cap] != \
685 spapr->def.caps[cap]); \
688 const VMStateDescription vmstate_spapr_cap_##sname = { \
689 .name = "spapr/cap/" #sname, \
691 .minimum_version_id = 1, \
692 .needed = spapr_cap_##sname##_needed, \
693 .fields = (VMStateField[]) { \
694 VMSTATE_UINT8(mig.caps[cap], \
695 SpaprMachineState), \
696 VMSTATE_END_OF_LIST() \
700 SPAPR_CAP_MIG_STATE(htm
, SPAPR_CAP_HTM
);
701 SPAPR_CAP_MIG_STATE(vsx
, SPAPR_CAP_VSX
);
702 SPAPR_CAP_MIG_STATE(dfp
, SPAPR_CAP_DFP
);
703 SPAPR_CAP_MIG_STATE(cfpc
, SPAPR_CAP_CFPC
);
704 SPAPR_CAP_MIG_STATE(sbbc
, SPAPR_CAP_SBBC
);
705 SPAPR_CAP_MIG_STATE(ibs
, SPAPR_CAP_IBS
);
706 SPAPR_CAP_MIG_STATE(nested_kvm_hv
, SPAPR_CAP_NESTED_KVM_HV
);
707 SPAPR_CAP_MIG_STATE(large_decr
, SPAPR_CAP_LARGE_DECREMENTER
);
708 SPAPR_CAP_MIG_STATE(ccf_assist
, SPAPR_CAP_CCF_ASSIST
);
710 void spapr_caps_init(SpaprMachineState
*spapr
)
712 SpaprCapabilities default_caps
;
715 /* Compute the actual set of caps we should run with */
716 default_caps
= default_caps_with_cpu(spapr
, MACHINE(spapr
)->cpu_type
);
718 for (i
= 0; i
< SPAPR_CAP_NUM
; i
++) {
719 /* Store the defaults */
720 spapr
->def
.caps
[i
] = default_caps
.caps
[i
];
721 /* If not set on the command line then apply the default value */
722 if (!spapr
->cmd_line_caps
[i
]) {
723 spapr
->eff
.caps
[i
] = default_caps
.caps
[i
];
728 void spapr_caps_apply(SpaprMachineState
*spapr
)
732 for (i
= 0; i
< SPAPR_CAP_NUM
; i
++) {
733 SpaprCapabilityInfo
*info
= &capability_table
[i
];
736 * If the apply function can't set the desired level and thinks it's
737 * fatal, it should cause that.
739 info
->apply(spapr
, spapr
->eff
.caps
[i
], &error_fatal
);
743 void spapr_caps_cpu_apply(SpaprMachineState
*spapr
, PowerPCCPU
*cpu
)
747 for (i
= 0; i
< SPAPR_CAP_NUM
; i
++) {
748 SpaprCapabilityInfo
*info
= &capability_table
[i
];
751 * If the apply function can't set the desired level and thinks it's
752 * fatal, it should cause that.
754 if (info
->cpu_apply
) {
755 info
->cpu_apply(spapr
, cpu
, spapr
->eff
.caps
[i
], &error_fatal
);
760 void spapr_caps_add_properties(SpaprMachineClass
*smc
, Error
**errp
)
762 Error
*local_err
= NULL
;
763 ObjectClass
*klass
= OBJECT_CLASS(smc
);
766 for (i
= 0; i
< ARRAY_SIZE(capability_table
); i
++) {
767 SpaprCapabilityInfo
*cap
= &capability_table
[i
];
768 const char *name
= g_strdup_printf("cap-%s", cap
->name
);
771 object_class_property_add(klass
, name
, cap
->type
,
773 NULL
, cap
, &local_err
);
775 error_propagate(errp
, local_err
);
779 desc
= g_strdup_printf("%s", cap
->description
);
780 object_class_property_set_description(klass
, name
, desc
, &local_err
);
783 error_propagate(errp
, local_err
);