diff options
| -rw-r--r-- | drivers/xen/xenbus/Makefile | 1 | ||||
| -rw-r--r-- | drivers/xen/xenbus/xenbus_dev_backend.c | 89 | ||||
| -rw-r--r-- | include/xen/xenbus_dev.h | 41 |
3 files changed, 131 insertions, 0 deletions
diff --git a/drivers/xen/xenbus/Makefile b/drivers/xen/xenbus/Makefile index a2ea363b9f34..31e2e9050c7a 100644 --- a/drivers/xen/xenbus/Makefile +++ b/drivers/xen/xenbus/Makefile | |||
| @@ -10,4 +10,5 @@ xenbus-objs += xenbus_probe.o | |||
| 10 | xenbus-be-objs-$(CONFIG_XEN_BACKEND) += xenbus_probe_backend.o | 10 | xenbus-be-objs-$(CONFIG_XEN_BACKEND) += xenbus_probe_backend.o |
| 11 | xenbus-objs += $(xenbus-be-objs-y) | 11 | xenbus-objs += $(xenbus-be-objs-y) |
| 12 | 12 | ||
| 13 | obj-$(CONFIG_XEN_BACKEND) += xenbus_dev_backend.o | ||
| 13 | obj-$(CONFIG_XEN_XENBUS_FRONTEND) += xenbus_probe_frontend.o | 14 | obj-$(CONFIG_XEN_XENBUS_FRONTEND) += xenbus_probe_frontend.o |
diff --git a/drivers/xen/xenbus/xenbus_dev_backend.c b/drivers/xen/xenbus/xenbus_dev_backend.c new file mode 100644 index 000000000000..a2092bd97693 --- /dev/null +++ b/drivers/xen/xenbus/xenbus_dev_backend.c | |||
| @@ -0,0 +1,89 @@ | |||
| 1 | #include <linux/slab.h> | ||
| 2 | #include <linux/types.h> | ||
| 3 | #include <linux/mm.h> | ||
| 4 | #include <linux/fs.h> | ||
| 5 | #include <linux/miscdevice.h> | ||
| 6 | #include <linux/module.h> | ||
| 7 | #include <linux/capability.h> | ||
| 8 | |||
| 9 | #include <xen/page.h> | ||
| 10 | #include <xen/xenbus_dev.h> | ||
| 11 | |||
| 12 | #include "xenbus_comms.h" | ||
| 13 | |||
| 14 | MODULE_LICENSE("GPL"); | ||
| 15 | |||
| 16 | static int xenbus_backend_open(struct inode *inode, struct file *filp) | ||
| 17 | { | ||
| 18 | if (!capable(CAP_SYS_ADMIN)) | ||
| 19 | return -EPERM; | ||
| 20 | |||
| 21 | return nonseekable_open(inode, filp); | ||
| 22 | } | ||
| 23 | |||
| 24 | static long xenbus_backend_ioctl(struct file *file, unsigned int cmd, unsigned long data) | ||
| 25 | { | ||
| 26 | if (!capable(CAP_SYS_ADMIN)) | ||
| 27 | return -EPERM; | ||
| 28 | |||
| 29 | switch (cmd) { | ||
| 30 | case IOCTL_XENBUS_BACKEND_EVTCHN: | ||
| 31 | if (xen_store_evtchn > 0) | ||
| 32 | return xen_store_evtchn; | ||
| 33 | return -ENODEV; | ||
| 34 | |||
| 35 | default: | ||
| 36 | return -ENOTTY; | ||
| 37 | } | ||
| 38 | } | ||
| 39 | |||
| 40 | static int xenbus_backend_mmap(struct file *file, struct vm_area_struct *vma) | ||
| 41 | { | ||
| 42 | size_t size = vma->vm_end - vma->vm_start; | ||
| 43 | |||
| 44 | if (!capable(CAP_SYS_ADMIN)) | ||
| 45 | return -EPERM; | ||
| 46 | |||
| 47 | if ((size > PAGE_SIZE) || (vma->vm_pgoff != 0)) | ||
| 48 | return -EINVAL; | ||
| 49 | |||
| 50 | if (remap_pfn_range(vma, vma->vm_start, | ||
| 51 | virt_to_pfn(xen_store_interface), | ||
| 52 | size, vma->vm_page_prot)) | ||
| 53 | return -EAGAIN; | ||
| 54 | |||
| 55 | return 0; | ||
| 56 | } | ||
| 57 | |||
| 58 | const struct file_operations xenbus_backend_fops = { | ||
| 59 | .open = xenbus_backend_open, | ||
| 60 | .mmap = xenbus_backend_mmap, | ||
| 61 | .unlocked_ioctl = xenbus_backend_ioctl, | ||
| 62 | }; | ||
| 63 | |||
| 64 | static struct miscdevice xenbus_backend_dev = { | ||
| 65 | .minor = MISC_DYNAMIC_MINOR, | ||
| 66 | .name = "xen/xenbus_backend", | ||
| 67 | .fops = &xenbus_backend_fops, | ||
| 68 | }; | ||
| 69 | |||
| 70 | static int __init xenbus_backend_init(void) | ||
| 71 | { | ||
| 72 | int err; | ||
| 73 | |||
| 74 | if (!xen_initial_domain()) | ||
| 75 | return -ENODEV; | ||
| 76 | |||
| 77 | err = misc_register(&xenbus_backend_dev); | ||
| 78 | if (err) | ||
| 79 | printk(KERN_ERR "Could not register xenbus backend device\n"); | ||
| 80 | return err; | ||
| 81 | } | ||
| 82 | |||
| 83 | static void __exit xenbus_backend_exit(void) | ||
| 84 | { | ||
| 85 | misc_deregister(&xenbus_backend_dev); | ||
| 86 | } | ||
| 87 | |||
| 88 | module_init(xenbus_backend_init); | ||
| 89 | module_exit(xenbus_backend_exit); | ||
diff --git a/include/xen/xenbus_dev.h b/include/xen/xenbus_dev.h new file mode 100644 index 000000000000..ac5f0fe47ed9 --- /dev/null +++ b/include/xen/xenbus_dev.h | |||
| @@ -0,0 +1,41 @@ | |||
| 1 | /****************************************************************************** | ||
| 2 | * evtchn.h | ||
| 3 | * | ||
| 4 | * Interface to /dev/xen/xenbus_backend. | ||
| 5 | * | ||
| 6 | * Copyright (c) 2011 Bastian Blank <waldi@debian.org> | ||
| 7 | * | ||
| 8 | * This program is free software; you can redistribute it and/or | ||
| 9 | * modify it under the terms of the GNU General Public License version 2 | ||
| 10 | * as published by the Free Software Foundation; or, when distributed | ||
| 11 | * separately from the Linux kernel or incorporated into other | ||
| 12 | * software packages, subject to the following license: | ||
| 13 | * | ||
| 14 | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| 15 | * of this source file (the "Software"), to deal in the Software without | ||
| 16 | * restriction, including without limitation the rights to use, copy, modify, | ||
| 17 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, | ||
| 18 | * and to permit persons to whom the Software is furnished to do so, subject to | ||
| 19 | * the following conditions: | ||
| 20 | * | ||
| 21 | * The above copyright notice and this permission notice shall be included in | ||
| 22 | * all copies or substantial portions of the Software. | ||
| 23 | * | ||
| 24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 25 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| 26 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| 27 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| 28 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
| 29 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
| 30 | * IN THE SOFTWARE. | ||
| 31 | */ | ||
| 32 | |||
| 33 | #ifndef __LINUX_XEN_XENBUS_DEV_H__ | ||
| 34 | #define __LINUX_XEN_XENBUS_DEV_H__ | ||
| 35 | |||
| 36 | #include <linux/ioctl.h> | ||
| 37 | |||
| 38 | #define IOCTL_XENBUS_BACKEND_EVTCHN \ | ||
| 39 | _IOC(_IOC_NONE, 'B', 0, 0) | ||
| 40 | |||
| 41 | #endif /* __LINUX_XEN_XENBUS_DEV_H__ */ | ||
