1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * Copyright (C) 2024 Loongson Technology Corporation Limited 4 */ 5 6 #include <asm/kvm_eiointc.h> 7 #include <asm/kvm_pch_pic.h> 8 #include <asm/kvm_vcpu.h> 9 #include <linux/count_zeros.h> 10 11 static int kvm_pch_pic_read(struct kvm_vcpu *vcpu, 12 struct kvm_io_device *dev, 13 gpa_t addr, int len, void *val) 14 { 15 return 0; 16 } 17 18 static int kvm_pch_pic_write(struct kvm_vcpu *vcpu, 19 struct kvm_io_device *dev, 20 gpa_t addr, int len, const void *val) 21 { 22 return 0; 23 } 24 25 static const struct kvm_io_device_ops kvm_pch_pic_ops = { 26 .read = kvm_pch_pic_read, 27 .write = kvm_pch_pic_write, 28 }; 29 30 static int kvm_pch_pic_get_attr(struct kvm_device *dev, 31 struct kvm_device_attr *attr) 32 { 33 return 0; 34 } 35 36 static int kvm_pch_pic_set_attr(struct kvm_device *dev, 37 struct kvm_device_attr *attr) 38 { 39 return 0; 40 } 41 42 static int kvm_pch_pic_create(struct kvm_device *dev, u32 type) 43 { 44 struct kvm *kvm = dev->kvm; 45 struct loongarch_pch_pic *s; 46 47 /* pch pic should not has been created */ 48 if (kvm->arch.pch_pic) 49 return -EINVAL; 50 51 s = kzalloc(sizeof(struct loongarch_pch_pic), GFP_KERNEL); 52 if (!s) 53 return -ENOMEM; 54 55 spin_lock_init(&s->lock); 56 s->kvm = kvm; 57 kvm->arch.pch_pic = s; 58 59 return 0; 60 } 61 62 static void kvm_pch_pic_destroy(struct kvm_device *dev) 63 { 64 struct kvm *kvm; 65 struct loongarch_pch_pic *s; 66 67 if (!dev || !dev->kvm || !dev->kvm->arch.pch_pic) 68 return; 69 70 kvm = dev->kvm; 71 s = kvm->arch.pch_pic; 72 /* unregister pch pic device and free it's memory */ 73 kvm_io_bus_unregister_dev(kvm, KVM_MMIO_BUS, &s->device); 74 kfree(s); 75 } 76 77 static struct kvm_device_ops kvm_pch_pic_dev_ops = { 78 .name = "kvm-loongarch-pch-pic", 79 .create = kvm_pch_pic_create, 80 .destroy = kvm_pch_pic_destroy, 81 .set_attr = kvm_pch_pic_set_attr, 82 .get_attr = kvm_pch_pic_get_attr, 83 }; 84 85 int kvm_loongarch_register_pch_pic_device(void) 86 { 87 return kvm_register_device_ops(&kvm_pch_pic_dev_ops, KVM_DEV_TYPE_LOONGARCH_PCHPIC); 88 } 89