hw/arm/boot: Factor out "direct kernel boot" code into its own function
[qemu/ar7.git] / hw / s390x / s390-skeys-kvm.c
blobdc54ed8b11e7749d19815fcc2954245811820595
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);
57 DeviceClass *dc = DEVICE_CLASS(oc);
59 skeyclass->skeys_enabled = kvm_s390_skeys_enabled;
60 skeyclass->get_skeys = kvm_s390_skeys_get;
61 skeyclass->set_skeys = kvm_s390_skeys_set;
63 /* Reason: Internal device (only one skeys device for the whole memory) */
64 dc->user_creatable = false;
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),
75 static void kvm_s390_skeys_register_types(void)
77 type_register_static(&kvm_s390_skeys_info);
80 type_init(kvm_s390_skeys_register_types)