qemu/include/hw/s390x/pv.h
<<
>>
Prefs
   1/*
   2 * Protected Virtualization header
   3 *
   4 * Copyright IBM Corp. 2020
   5 * Author(s):
   6 *  Janosch Frank <frankja@linux.ibm.com>
   7 *
   8 * This work is licensed under the terms of the GNU GPL, version 2 or (at
   9 * your option) any later version. See the COPYING file in the top-level
  10 * directory.
  11 */
  12#ifndef HW_S390_PV_H
  13#define HW_S390_PV_H
  14
  15#include "qapi/error.h"
  16#include "sysemu/kvm.h"
  17
  18#ifdef CONFIG_KVM
  19#include "cpu.h"
  20#include "hw/s390x/s390-virtio-ccw.h"
  21
  22static inline bool s390_is_pv(void)
  23{
  24    static S390CcwMachineState *ccw;
  25    Object *obj;
  26
  27    if (ccw) {
  28        return ccw->pv;
  29    }
  30
  31    /* we have to bail out for the "none" machine */
  32    obj = object_dynamic_cast(qdev_get_machine(),
  33                              TYPE_S390_CCW_MACHINE);
  34    if (!obj) {
  35        return false;
  36    }
  37    ccw = S390_CCW_MACHINE(obj);
  38    return ccw->pv;
  39}
  40
  41int s390_pv_vm_enable(void);
  42void s390_pv_vm_disable(void);
  43int s390_pv_set_sec_parms(uint64_t origin, uint64_t length);
  44int s390_pv_unpack(uint64_t addr, uint64_t size, uint64_t tweak);
  45void s390_pv_prep_reset(void);
  46int s390_pv_verify(void);
  47void s390_pv_unshare(void);
  48void s390_pv_inject_reset_error(CPUState *cs);
  49#else /* CONFIG_KVM */
  50static inline bool s390_is_pv(void) { return false; }
  51static inline int s390_pv_vm_enable(void) { return 0; }
  52static inline void s390_pv_vm_disable(void) {}
  53static inline int s390_pv_set_sec_parms(uint64_t origin, uint64_t length) { return 0; }
  54static inline int s390_pv_unpack(uint64_t addr, uint64_t size, uint64_t tweak) { return 0; }
  55static inline void s390_pv_prep_reset(void) {}
  56static inline int s390_pv_verify(void) { return 0; }
  57static inline void s390_pv_unshare(void) {}
  58static inline void s390_pv_inject_reset_error(CPUState *cs) {};
  59#endif /* CONFIG_KVM */
  60
  61int s390_pv_kvm_init(ConfidentialGuestSupport *cgs, Error **errp);
  62static inline int s390_pv_init(ConfidentialGuestSupport *cgs, Error **errp)
  63{
  64    if (!cgs) {
  65        return 0;
  66    }
  67    if (kvm_enabled()) {
  68        return s390_pv_kvm_init(cgs, errp);
  69    }
  70
  71    error_setg(errp, "Protected Virtualization requires KVM");
  72    return -1;
  73}
  74
  75#endif /* HW_S390_PV_H */
  76