1 #include <linux/slab.h>
2 #include <linux/types.h>
5 #include <linux/miscdevice.h>
6 #include <linux/module.h>
7 #include <linux/capability.h>
10 #ifdef CONFIG_PARAVIRT_XEN
13 #include <xen/xenbus_dev.h>
15 #include "xenbus_comms.h"
17 MODULE_LICENSE("GPL");
19 static int xenbus_backend_open(struct inode *inode, struct file *filp)
21 if (!capable(CAP_SYS_ADMIN))
24 return nonseekable_open(inode, filp);
27 static long xenbus_backend_ioctl(struct file *file, unsigned int cmd, unsigned long data)
29 if (!capable(CAP_SYS_ADMIN))
33 case IOCTL_XENBUS_BACKEND_EVTCHN:
34 if (xen_store_evtchn > 0)
35 return xen_store_evtchn;
43 static int xenbus_backend_mmap(struct file *file, struct vm_area_struct *vma)
45 size_t size = vma->vm_end - vma->vm_start;
47 if (!capable(CAP_SYS_ADMIN))
50 if ((size > PAGE_SIZE) || (vma->vm_pgoff != 0))
53 if (remap_pfn_range(vma, vma->vm_start,
54 PFN_DOWN(__pa(xen_store_interface)),
55 size, vma->vm_page_prot))
61 const struct file_operations xenbus_backend_fops = {
62 .open = xenbus_backend_open,
63 .mmap = xenbus_backend_mmap,
64 .unlocked_ioctl = xenbus_backend_ioctl,
67 static struct miscdevice xenbus_backend_dev = {
68 .minor = MISC_DYNAMIC_MINOR,
69 .name = "xen/xenbus_backend",
70 .fops = &xenbus_backend_fops,
73 static int __init xenbus_backend_init(void)
77 if (!xen_initial_domain())
80 err = misc_register(&xenbus_backend_dev);
82 printk(KERN_ERR "Could not register xenbus backend device\n");
86 static void __exit xenbus_backend_exit(void)
88 misc_deregister(&xenbus_backend_dev);
91 module_init(xenbus_backend_init);
92 module_exit(xenbus_backend_exit);