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>
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
))
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
))
31 case IOCTL_XENBUS_BACKEND_EVTCHN
:
32 if (xen_store_evtchn
> 0)
33 return xen_store_evtchn
;
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
))
48 if ((size
> PAGE_SIZE
) || (vma
->vm_pgoff
!= 0))
51 if (remap_pfn_range(vma
, vma
->vm_start
,
52 virt_to_pfn(xen_store_interface
),
53 size
, vma
->vm_page_prot
))
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)
75 if (!xen_initial_domain())
78 err
= misc_register(&xenbus_backend_dev
);
80 printk(KERN_ERR
"Could not register xenbus backend device\n");
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
);