/*1* This program is free software; you can redistribute it and/or modify2* it under the terms of the GNU General Public License as published by3* the Free Software Foundation; either version 2 of the License.4*5* This program is distributed in the hope that it will be useful,6* but WITHOUT ANY WARRANTY; without even the implied warranty of7* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the8* GNU General Public License for more details.9*10* You should have received a copy of the GNU General Public License11* along with this program; if not, write to the Free Software12* Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.13*/1415#ifndef __KVM_IODEV_H__16#define __KVM_IODEV_H__1718#include <linux/kvm_types.h>19#include <asm/errno.h>2021struct kvm_io_device;2223/**24* kvm_io_device_ops are called under kvm slots_lock.25* read and write handlers return 0 if the transaction has been handled,26* or non-zero to have it passed to the next device.27**/28struct kvm_io_device_ops {29int (*read)(struct kvm_io_device *this,30gpa_t addr,31int len,32void *val);33int (*write)(struct kvm_io_device *this,34gpa_t addr,35int len,36const void *val);37void (*destructor)(struct kvm_io_device *this);38};394041struct kvm_io_device {42const struct kvm_io_device_ops *ops;43};4445static inline void kvm_iodevice_init(struct kvm_io_device *dev,46const struct kvm_io_device_ops *ops)47{48dev->ops = ops;49}5051static inline int kvm_iodevice_read(struct kvm_io_device *dev,52gpa_t addr, int l, void *v)53{54return dev->ops->read ? dev->ops->read(dev, addr, l, v) : -EOPNOTSUPP;55}5657static inline int kvm_iodevice_write(struct kvm_io_device *dev,58gpa_t addr, int l, const void *v)59{60return dev->ops->write ? dev->ops->write(dev, addr, l, v) : -EOPNOTSUPP;61}6263static inline void kvm_iodevice_destructor(struct kvm_io_device *dev)64{65if (dev->ops->destructor)66dev->ops->destructor(dev);67}6869#endif /* __KVM_IODEV_H__ */707172