hw/pcie: Introduce a base class for PCI Express Root Ports
[qemu/kevin.git] / hw / s390x / s390-skeys-kvm.c
blob131da56bbe3f083794a38e78a6288123c79849a0
1 /*
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
9 * directory.
12 #include "qemu/osdep.h"
13 #include "hw/s390x/storage-keys.h"
14 #include "sysemu/kvm.h"
15 #include "qemu/error-report.h"
17 static int kvm_s390_skeys_enabled(S390SKeysState *ss)
19 S390SKeysClass *skeyclass = S390_SKEYS_GET_CLASS(ss);
20 uint8_t single_key;
21 int r;
23 r = skeyclass->get_skeys(ss, 0, 1, &single_key);
24 if (r != 0 && r != KVM_S390_GET_SKEYS_NONE) {
25 error_report("S390_GET_KEYS error %d", r);
27 return (r == 0);
30 static int kvm_s390_skeys_get(S390SKeysState *ss, uint64_t start_gfn,
31 uint64_t count, uint8_t *keys)
33 struct kvm_s390_skeys args = {
34 .start_gfn = start_gfn,
35 .count = count,
36 .skeydata_addr = (__u64)keys
39 return kvm_vm_ioctl(kvm_state, KVM_S390_GET_SKEYS, &args);
42 static int kvm_s390_skeys_set(S390SKeysState *ss, uint64_t start_gfn,
43 uint64_t count, uint8_t *keys)
45 struct kvm_s390_skeys args = {
46 .start_gfn = start_gfn,
47 .count = count,
48 .skeydata_addr = (__u64)keys
51 return kvm_vm_ioctl(kvm_state, KVM_S390_SET_SKEYS, &args);
54 static void kvm_s390_skeys_class_init(ObjectClass *oc, void *data)
56 S390SKeysClass *skeyclass = S390_SKEYS_CLASS(oc);
58 skeyclass->skeys_enabled = kvm_s390_skeys_enabled;
59 skeyclass->get_skeys = kvm_s390_skeys_get;
60 skeyclass->set_skeys = kvm_s390_skeys_set;
63 static const TypeInfo kvm_s390_skeys_info = {
64 .name = TYPE_KVM_S390_SKEYS,
65 .parent = TYPE_S390_SKEYS,
66 .instance_size = sizeof(S390SKeysState),
67 .class_init = kvm_s390_skeys_class_init,
68 .class_size = sizeof(S390SKeysClass),
71 static void kvm_s390_skeys_register_types(void)
73 type_register_static(&kvm_s390_skeys_info);
76 type_init(kvm_s390_skeys_register_types)