]>
Commit | Line | Data |
---|---|---|
0efe406c JH |
1 | /* |
2 | * s390 storage key device | |
3 | * | |
4 | * Copyright 2015 IBM Corp. | |
5 | * Author(s): Jason J. Herne <[email protected]> | |
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 | ||
9615495a | 12 | #include "qemu/osdep.h" |
0efe406c JH |
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) { | |
9af9e0fe | 25 | error_report("S390_GET_KEYS error %d", r); |
0efe406c JH |
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); | |
574ee06d | 57 | DeviceClass *dc = DEVICE_CLASS(oc); |
0efe406c JH |
58 | |
59 | skeyclass->skeys_enabled = kvm_s390_skeys_enabled; | |
60 | skeyclass->get_skeys = kvm_s390_skeys_get; | |
61 | skeyclass->set_skeys = kvm_s390_skeys_set; | |
574ee06d TH |
62 | |
63 | /* Reason: Internal device (only one skeys device for the whole memory) */ | |
64 | dc->user_creatable = false; | |
0efe406c JH |
65 | } |
66 | ||
67 | static const TypeInfo kvm_s390_skeys_info = { | |
68 | .name = TYPE_KVM_S390_SKEYS, | |
69 | .parent = TYPE_S390_SKEYS, | |
70 | .instance_size = sizeof(S390SKeysState), | |
71 | .class_init = kvm_s390_skeys_class_init, | |
72 | .class_size = sizeof(S390SKeysClass), | |
73 | }; | |
74 | ||
75 | static void kvm_s390_skeys_register_types(void) | |
76 | { | |
77 | type_register_static(&kvm_s390_skeys_info); | |
78 | } | |
79 | ||
80 | type_init(kvm_s390_skeys_register_types) |