52 #include <linux/module.h>
54 #include <linux/kernel.h>
56 #include <linux/slab.h>
58 #include <linux/device.h>
61 #include <linux/types.h>
62 #include <linux/list.h>
69 #include <xen/events.h>
71 static int limit = 1024;
74 "the gntalloc device");
110 static void do_cleanup(
void)
129 for (i = 0; i < op->
count; i++) {
153 list_splice_tail(&queue_gref, &gref_list);
154 list_splice_tail(&queue_file, &priv->
list);
161 gref_size -= (op->
count -
i);
174 if (
unlikely(!list_empty(&queue_gref)))
175 list_splice_tail(&queue_gref, &gref_list);
184 tmp[gref->
notify.pgoff] = 0;
188 notify_remote_via_evtchn(gref->
notify.event);
219 if (gref->file_index == index && !rv)
222 if (gref->file_index != index)
245 INIT_LIST_HEAD(&priv->
list);
249 pr_debug(
"%s: priv %p\n", __func__, priv);
257 static int gntalloc_release(
struct inode *inode,
struct file *filp)
262 pr_debug(
"%s: priv %p\n", __func__, priv);
265 while (!list_empty(&priv->
list)) {
270 if (gref->
users == 0)
286 pr_debug(
"%s: priv %p\n", __func__, priv);
310 gref_size += op.
count;
315 rc = add_grefs(&op, gref_ids, priv);
331 sizeof(gref_ids[0]) * op.
count)) {
349 pr_debug(
"%s: priv %p\n", __func__, priv);
353 goto dealloc_grant_out;
363 for (i = 0; i < op.
count; i++) {
393 index = op.
index & ~(PAGE_SIZE - 1);
394 pgoff = op.
index & (PAGE_SIZE - 1);
398 gref = find_grefs(priv, index, 1);
426 gref->
notify.flags = op.action;
427 gref->
notify.pgoff = pgoff;
428 gref->
notify.event = op.event_channel_port;
436 static long gntalloc_ioctl(
struct file *filp,
unsigned int cmd,
443 return gntalloc_ioctl_alloc(priv, (
void __user *)arg);
446 return gntalloc_ioctl_dealloc(priv, (
void __user *)arg);
449 return gntalloc_ioctl_unmap_notify(priv, (
void __user *)arg);
481 if (priv->
users == 0) {
483 for (i = 0; i < priv->
count; i++) {
487 if (gref->
users == 0)
496 static struct vm_operations_struct gntalloc_vmops = {
497 .open = gntalloc_vma_open,
498 .close = gntalloc_vma_close,
520 pr_debug(
"%s: priv %p,%p, page %lu+%d\n", __func__,
521 priv, vm_priv, vma->
vm_pgoff, count);
526 pr_debug(
"%s: Could not find grant reference",
532 vm_priv->
gref = gref;
538 vma->
vm_flags |= VM_DONTEXPAND | VM_DONTDUMP;
540 vma->
vm_ops = &gntalloc_vmops;
542 for (i = 0; i <
count; i++) {
561 .open = gntalloc_open,
562 .release = gntalloc_release,
563 .unlocked_ioctl = gntalloc_ioctl,
564 .mmap = gntalloc_mmap
574 .name =
"xen/gntalloc",
575 .fops = &gntalloc_fops,
578 static int __init gntalloc_init(
void)
591 pr_debug(
"Created grant allocation device at %d,%d\n",
597 static void __exit gntalloc_exit(
void)