Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 282088
b: refs/heads/master
c: e9f0fec
h: refs/heads/master
v: v3
  • Loading branch information
Bastian Blank authored and Konrad Rzeszutek Wilk committed Dec 16, 2011
1 parent 01a132e commit c68f801
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 2fb3683e7b164ee2b324039f7c9d90fe5b1a259b
refs/heads/master: e9f0fec3f5d406c500861da779d16a779a110055
1 change: 1 addition & 0 deletions trunk/drivers/xen/xenbus/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ xenbus-objs += xenbus_probe.o
xenbus-be-objs-$(CONFIG_XEN_BACKEND) += xenbus_probe_backend.o
xenbus-objs += $(xenbus-be-objs-y)

obj-$(CONFIG_XEN_BACKEND) += xenbus_dev_backend.o
obj-$(CONFIG_XEN_XENBUS_FRONTEND) += xenbus_probe_frontend.o
89 changes: 89 additions & 0 deletions trunk/drivers/xen/xenbus/xenbus_dev_backend.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#include <linux/slab.h>
#include <linux/types.h>
#include <linux/mm.h>
#include <linux/fs.h>
#include <linux/miscdevice.h>
#include <linux/module.h>
#include <linux/capability.h>

#include <xen/page.h>
#include <xen/xenbus_dev.h>

#include "xenbus_comms.h"

MODULE_LICENSE("GPL");

static int xenbus_backend_open(struct inode *inode, struct file *filp)
{
if (!capable(CAP_SYS_ADMIN))
return -EPERM;

return nonseekable_open(inode, filp);
}

static long xenbus_backend_ioctl(struct file *file, unsigned int cmd, unsigned long data)
{
if (!capable(CAP_SYS_ADMIN))
return -EPERM;

switch (cmd) {
case IOCTL_XENBUS_BACKEND_EVTCHN:
if (xen_store_evtchn > 0)
return xen_store_evtchn;
return -ENODEV;

default:
return -ENOTTY;
}
}

static int xenbus_backend_mmap(struct file *file, struct vm_area_struct *vma)
{
size_t size = vma->vm_end - vma->vm_start;

if (!capable(CAP_SYS_ADMIN))
return -EPERM;

if ((size > PAGE_SIZE) || (vma->vm_pgoff != 0))
return -EINVAL;

if (remap_pfn_range(vma, vma->vm_start,
virt_to_pfn(xen_store_interface),
size, vma->vm_page_prot))
return -EAGAIN;

return 0;
}

const struct file_operations xenbus_backend_fops = {
.open = xenbus_backend_open,
.mmap = xenbus_backend_mmap,
.unlocked_ioctl = xenbus_backend_ioctl,
};

static struct miscdevice xenbus_backend_dev = {
.minor = MISC_DYNAMIC_MINOR,
.name = "xen/xenbus_backend",
.fops = &xenbus_backend_fops,
};

static int __init xenbus_backend_init(void)
{
int err;

if (!xen_initial_domain())
return -ENODEV;

err = misc_register(&xenbus_backend_dev);
if (err)
printk(KERN_ERR "Could not register xenbus backend device\n");
return err;
}

static void __exit xenbus_backend_exit(void)
{
misc_deregister(&xenbus_backend_dev);
}

module_init(xenbus_backend_init);
module_exit(xenbus_backend_exit);
41 changes: 41 additions & 0 deletions trunk/include/xen/xenbus_dev.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/******************************************************************************
* evtchn.h
*
* Interface to /dev/xen/xenbus_backend.
*
* Copyright (c) 2011 Bastian Blank <waldi@debian.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation; or, when distributed
* separately from the Linux kernel or incorporated into other
* software packages, subject to the following license:
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this source file (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy, modify,
* merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/

#ifndef __LINUX_XEN_XENBUS_DEV_H__
#define __LINUX_XEN_XENBUS_DEV_H__

#include <linux/ioctl.h>

#define IOCTL_XENBUS_BACKEND_EVTCHN \
_IOC(_IOC_NONE, 'B', 0, 0)

#endif /* __LINUX_XEN_XENBUS_DEV_H__ */

0 comments on commit c68f801

Please sign in to comment.