spi-topcliff-pch: add recovery processing in case wait-event timeout
[zen-stable.git] / drivers / xen / xenbus / xenbus_dev_backend.c
blob3d3be78c1093788f1591426157fdd4db9f3d5459
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>
9 #include <xen/xen.h>
10 #include <xen/page.h>
11 #include <xen/xenbus_dev.h>
13 #include "xenbus_comms.h"
15 MODULE_LICENSE("GPL");
17 static int xenbus_backend_open(struct inode *inode, struct file *filp)
19 if (!capable(CAP_SYS_ADMIN))
20 return -EPERM;
22 return nonseekable_open(inode, filp);
25 static long xenbus_backend_ioctl(struct file *file, unsigned int cmd, unsigned long data)
27 if (!capable(CAP_SYS_ADMIN))
28 return -EPERM;
30 switch (cmd) {
31 case IOCTL_XENBUS_BACKEND_EVTCHN:
32 if (xen_store_evtchn > 0)
33 return xen_store_evtchn;
34 return -ENODEV;
36 default:
37 return -ENOTTY;
41 static int xenbus_backend_mmap(struct file *file, struct vm_area_struct *vma)
43 size_t size = vma->vm_end - vma->vm_start;
45 if (!capable(CAP_SYS_ADMIN))
46 return -EPERM;
48 if ((size > PAGE_SIZE) || (vma->vm_pgoff != 0))
49 return -EINVAL;
51 if (remap_pfn_range(vma, vma->vm_start,
52 virt_to_pfn(xen_store_interface),
53 size, vma->vm_page_prot))
54 return -EAGAIN;
56 return 0;
59 const struct file_operations xenbus_backend_fops = {
60 .open = xenbus_backend_open,
61 .mmap = xenbus_backend_mmap,
62 .unlocked_ioctl = xenbus_backend_ioctl,
65 static struct miscdevice xenbus_backend_dev = {
66 .minor = MISC_DYNAMIC_MINOR,
67 .name = "xen/xenbus_backend",
68 .fops = &xenbus_backend_fops,
71 static int __init xenbus_backend_init(void)
73 int err;
75 if (!xen_initial_domain())
76 return -ENODEV;
78 err = misc_register(&xenbus_backend_dev);
79 if (err)
80 printk(KERN_ERR "Could not register xenbus backend device\n");
81 return err;
84 static void __exit xenbus_backend_exit(void)
86 misc_deregister(&xenbus_backend_dev);
89 module_init(xenbus_backend_init);
90 module_exit(xenbus_backend_exit);