Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 
0003 #ifndef __KVM_IODEV_H__
0004 #define __KVM_IODEV_H__
0005 
0006 #include <linux/kvm_types.h>
0007 #include <linux/errno.h>
0008 
0009 struct kvm_io_device;
0010 struct kvm_vcpu;
0011 
0012 /**
0013  * kvm_io_device_ops are called under kvm slots_lock.
0014  * read and write handlers return 0 if the transaction has been handled,
0015  * or non-zero to have it passed to the next device.
0016  **/
0017 struct kvm_io_device_ops {
0018     int (*read)(struct kvm_vcpu *vcpu,
0019             struct kvm_io_device *this,
0020             gpa_t addr,
0021             int len,
0022             void *val);
0023     int (*write)(struct kvm_vcpu *vcpu,
0024              struct kvm_io_device *this,
0025              gpa_t addr,
0026              int len,
0027              const void *val);
0028     void (*destructor)(struct kvm_io_device *this);
0029 };
0030 
0031 
0032 struct kvm_io_device {
0033     const struct kvm_io_device_ops *ops;
0034 };
0035 
0036 static inline void kvm_iodevice_init(struct kvm_io_device *dev,
0037                      const struct kvm_io_device_ops *ops)
0038 {
0039     dev->ops = ops;
0040 }
0041 
0042 static inline int kvm_iodevice_read(struct kvm_vcpu *vcpu,
0043                     struct kvm_io_device *dev, gpa_t addr,
0044                     int l, void *v)
0045 {
0046     return dev->ops->read ? dev->ops->read(vcpu, dev, addr, l, v)
0047                 : -EOPNOTSUPP;
0048 }
0049 
0050 static inline int kvm_iodevice_write(struct kvm_vcpu *vcpu,
0051                      struct kvm_io_device *dev, gpa_t addr,
0052                      int l, const void *v)
0053 {
0054     return dev->ops->write ? dev->ops->write(vcpu, dev, addr, l, v)
0055                  : -EOPNOTSUPP;
0056 }
0057 
0058 static inline void kvm_iodevice_destructor(struct kvm_io_device *dev)
0059 {
0060     if (dev->ops->destructor)
0061         dev->ops->destructor(dev);
0062 }
0063 
0064 #endif /* __KVM_IODEV_H__ */