These changes are the raw update to qemu-2.6.
[kvmfornfv.git] / qemu / hw / s390x / s390-skeys-kvm.c
1 /*
2  * s390 storage key device
3  *
4  * Copyright 2015 IBM Corp.
5  * Author(s): Jason J. Herne <jjherne@linux.vnet.ibm.com>
6  *
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.
10  */
11
12 #include "qemu/osdep.h"
13 #include "hw/s390x/storage-keys.h"
14 #include "sysemu/kvm.h"
15 #include "qemu/error-report.h"
16
17 static int kvm_s390_skeys_enabled(S390SKeysState *ss)
18 {
19     S390SKeysClass *skeyclass = S390_SKEYS_GET_CLASS(ss);
20     uint8_t single_key;
21     int r;
22
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);
26     }
27     return (r == 0);
28 }
29
30 static int kvm_s390_skeys_get(S390SKeysState *ss, uint64_t start_gfn,
31                               uint64_t count, uint8_t *keys)
32 {
33     struct kvm_s390_skeys args = {
34         .start_gfn = start_gfn,
35         .count = count,
36         .skeydata_addr = (__u64)keys
37     };
38
39     return kvm_vm_ioctl(kvm_state, KVM_S390_GET_SKEYS, &args);
40 }
41
42 static int kvm_s390_skeys_set(S390SKeysState *ss, uint64_t start_gfn,
43                               uint64_t count, uint8_t *keys)
44 {
45     struct kvm_s390_skeys args = {
46         .start_gfn = start_gfn,
47         .count = count,
48         .skeydata_addr = (__u64)keys
49     };
50
51     return kvm_vm_ioctl(kvm_state, KVM_S390_SET_SKEYS, &args);
52 }
53
54 static void kvm_s390_skeys_class_init(ObjectClass *oc, void *data)
55 {
56     S390SKeysClass *skeyclass = S390_SKEYS_CLASS(oc);
57
58     skeyclass->skeys_enabled = kvm_s390_skeys_enabled;
59     skeyclass->get_skeys = kvm_s390_skeys_get;
60     skeyclass->set_skeys = kvm_s390_skeys_set;
61 }
62
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),
69 };
70
71 static void kvm_s390_skeys_register_types(void)
72 {
73     type_register_static(&kvm_s390_skeys_info);
74 }
75
76 type_init(kvm_s390_skeys_register_types)