xref: /illumos-kvm/kvm_iodev.c (revision 2a9ff8dc)
1 /*
2  * GPL HEADER START
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16  *
17  * GPL HEADER END
18  *
19  * Copyright 2011 various Linux Kernel contributors.
20  * Copyright 2011 Joyent, Inc. All Rights Reserved.
21  */
22 
23 #include "kvm_iodev.h"
24 #include <sys/errno.h>
25 
26 void
kvm_iodevice_init(struct kvm_io_device * dev,const struct kvm_io_device_ops * ops)27 kvm_iodevice_init(struct kvm_io_device *dev,
28     const struct kvm_io_device_ops *ops)
29 {
30 	dev->ops = ops;
31 }
32 
33 int
kvm_iodevice_read(struct kvm_io_device * dev,gpa_t addr,int l,void * v)34 kvm_iodevice_read(struct kvm_io_device *dev,
35     gpa_t addr, int l, void *v)
36 {
37 	return (dev->ops->read ? dev->ops->read(dev, addr, l, v) : -EOPNOTSUPP);
38 }
39 
40 int
kvm_iodevice_write(struct kvm_io_device * dev,gpa_t addr,int l,const void * v)41 kvm_iodevice_write(struct kvm_io_device *dev,
42     gpa_t addr, int l, const void *v)
43 {
44 	return (dev->ops->write ? dev->ops->write(dev, addr, l, v) :
45 	    -EOPNOTSUPP);
46 }
47 
48 void
kvm_iodevice_destructor(struct kvm_io_device * dev)49 kvm_iodevice_destructor(struct kvm_io_device *dev)
50 {
51 	if (dev->ops->destructor)
52 		dev->ops->destructor(dev);
53 }
54