1 /* 2 * TOD (Time Of Day) clock - KVM implementation 3 * 4 * Copyright 2018 Red Hat, Inc. 5 * Author(s): David Hildenbrand <david@redhat.com> 6 * 7 * This work is licensed under the terms of the GNU GPL, version 2 or later. 8 * See the COPYING file in the top-level directory. 9 */ 10 11 #include "qemu/osdep.h" 12 #include "qapi/error.h" 13 #include "hw/s390x/tod.h" 14 #include "kvm_s390x.h" 15 16 static void kvm_s390_tod_get(const S390TODState *td, S390TOD *tod, Error **errp) 17 { 18 int r; 19 20 r = kvm_s390_get_clock_ext(&tod->high, &tod->low); 21 if (r == -ENXIO) { 22 r = kvm_s390_get_clock(&tod->high, &tod->low); 23 } 24 if (r) { 25 error_setg(errp, "Unable to get KVM guest TOD clock: %s", 26 strerror(-r)); 27 } 28 } 29 30 static void kvm_s390_tod_set(S390TODState *td, const S390TOD *tod, Error **errp) 31 { 32 int r; 33 34 r = kvm_s390_set_clock_ext(tod->high, tod->low); 35 if (r == -ENXIO) { 36 r = kvm_s390_set_clock(tod->high, tod->low); 37 } 38 if (r) { 39 error_setg(errp, "Unable to set KVM guest TOD clock: %s", 40 strerror(-r)); 41 } 42 } 43 44 static void kvm_s390_tod_class_init(ObjectClass *oc, void *data) 45 { 46 S390TODClass *tdc = S390_TOD_CLASS(oc); 47 48 tdc->get = kvm_s390_tod_get; 49 tdc->set = kvm_s390_tod_set; 50 } 51 52 static TypeInfo kvm_s390_tod_info = { 53 .name = TYPE_KVM_S390_TOD, 54 .parent = TYPE_S390_TOD, 55 .instance_size = sizeof(S390TODState), 56 .class_init = kvm_s390_tod_class_init, 57 .class_size = sizeof(S390TODClass), 58 }; 59 60 static void register_types(void) 61 { 62 type_register_static(&kvm_s390_tod_info); 63 } 64 type_init(register_types); 65