2 * s390 storage key device
4 * Copyright 2015 IBM Corp.
5 * Author(s): Jason J. Herne <jjherne@linux.vnet.ibm.com>
7 * This work is licensed under the terms of the GNU GPL, version 2 or (at
8 * your option) any later version. See the COPYING file in the top-level
12 #include "qemu/osdep.h"
13 #include "hw/s390x/storage-keys.h"
14 #include "sysemu/kvm.h"
15 #include "qemu/error-report.h"
16 #include "qemu/module.h"
18 static bool kvm_s390_skeys_are_enabled(S390SKeysState
*ss
)
20 S390SKeysClass
*skeyclass
= S390_SKEYS_GET_CLASS(ss
);
24 r
= skeyclass
->get_skeys(ss
, 0, 1, &single_key
);
25 if (r
!= 0 && r
!= KVM_S390_GET_SKEYS_NONE
) {
26 error_report("S390_GET_KEYS error %d", r
);
31 static int kvm_s390_skeys_get(S390SKeysState
*ss
, uint64_t start_gfn
,
32 uint64_t count
, uint8_t *keys
)
34 struct kvm_s390_skeys args
= {
35 .start_gfn
= start_gfn
,
37 .skeydata_addr
= (__u64
)keys
40 return kvm_vm_ioctl(kvm_state
, KVM_S390_GET_SKEYS
, &args
);
43 static int kvm_s390_skeys_set(S390SKeysState
*ss
, uint64_t start_gfn
,
44 uint64_t count
, uint8_t *keys
)
46 struct kvm_s390_skeys args
= {
47 .start_gfn
= start_gfn
,
49 .skeydata_addr
= (__u64
)keys
52 return kvm_vm_ioctl(kvm_state
, KVM_S390_SET_SKEYS
, &args
);
55 static void kvm_s390_skeys_class_init(ObjectClass
*oc
, void *data
)
57 S390SKeysClass
*skeyclass
= S390_SKEYS_CLASS(oc
);
58 DeviceClass
*dc
= DEVICE_CLASS(oc
);
60 skeyclass
->skeys_are_enabled
= kvm_s390_skeys_are_enabled
;
61 skeyclass
->get_skeys
= kvm_s390_skeys_get
;
62 skeyclass
->set_skeys
= kvm_s390_skeys_set
;
64 /* Reason: Internal device (only one skeys device for the whole memory) */
65 dc
->user_creatable
= false;
68 static const TypeInfo kvm_s390_skeys_info
= {
69 .name
= TYPE_KVM_S390_SKEYS
,
70 .parent
= TYPE_S390_SKEYS
,
71 .instance_size
= sizeof(S390SKeysState
),
72 .class_init
= kvm_s390_skeys_class_init
,
73 .class_size
= sizeof(S390SKeysClass
),
76 static void kvm_s390_skeys_register_types(void)
78 type_register_static(&kvm_s390_skeys_info
);
81 type_init(kvm_s390_skeys_register_types
)