162306a36Sopenharmony_ci/******************************************************************************
262306a36Sopenharmony_ci * gntalloc.h
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Interface to /dev/xen/gntalloc.
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci * Author: Daniel De Graaf <dgdegra@tycho.nsa.gov>
762306a36Sopenharmony_ci *
862306a36Sopenharmony_ci * This file is in the public domain.
962306a36Sopenharmony_ci */
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#ifndef __LINUX_PUBLIC_GNTALLOC_H__
1262306a36Sopenharmony_ci#define __LINUX_PUBLIC_GNTALLOC_H__
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci#include <linux/types.h>
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci/*
1762306a36Sopenharmony_ci * Allocates a new page and creates a new grant reference.
1862306a36Sopenharmony_ci */
1962306a36Sopenharmony_ci#define IOCTL_GNTALLOC_ALLOC_GREF \
2062306a36Sopenharmony_ci_IOC(_IOC_NONE, 'G', 5, sizeof(struct ioctl_gntalloc_alloc_gref))
2162306a36Sopenharmony_cistruct ioctl_gntalloc_alloc_gref {
2262306a36Sopenharmony_ci	/* IN parameters */
2362306a36Sopenharmony_ci	/* The ID of the domain to be given access to the grants. */
2462306a36Sopenharmony_ci	__u16 domid;
2562306a36Sopenharmony_ci	/* Flags for this mapping */
2662306a36Sopenharmony_ci	__u16 flags;
2762306a36Sopenharmony_ci	/* Number of pages to map */
2862306a36Sopenharmony_ci	__u32 count;
2962306a36Sopenharmony_ci	/* OUT parameters */
3062306a36Sopenharmony_ci	/* The offset to be used on a subsequent call to mmap(). */
3162306a36Sopenharmony_ci	__u64 index;
3262306a36Sopenharmony_ci	/* The grant references of the newly created grant, one per page */
3362306a36Sopenharmony_ci	/* Variable size, depending on count */
3462306a36Sopenharmony_ci	__u32 gref_ids[1];
3562306a36Sopenharmony_ci};
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_ci#define GNTALLOC_FLAG_WRITABLE 1
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ci/*
4062306a36Sopenharmony_ci * Deallocates the grant reference, allowing the associated page to be freed if
4162306a36Sopenharmony_ci * no other domains are using it.
4262306a36Sopenharmony_ci */
4362306a36Sopenharmony_ci#define IOCTL_GNTALLOC_DEALLOC_GREF \
4462306a36Sopenharmony_ci_IOC(_IOC_NONE, 'G', 6, sizeof(struct ioctl_gntalloc_dealloc_gref))
4562306a36Sopenharmony_cistruct ioctl_gntalloc_dealloc_gref {
4662306a36Sopenharmony_ci	/* IN parameters */
4762306a36Sopenharmony_ci	/* The offset returned in the map operation */
4862306a36Sopenharmony_ci	__u64 index;
4962306a36Sopenharmony_ci	/* Number of references to unmap */
5062306a36Sopenharmony_ci	__u32 count;
5162306a36Sopenharmony_ci};
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_ci/*
5462306a36Sopenharmony_ci * Sets up an unmap notification within the page, so that the other side can do
5562306a36Sopenharmony_ci * cleanup if this side crashes. Required to implement cross-domain robust
5662306a36Sopenharmony_ci * mutexes or close notification on communication channels.
5762306a36Sopenharmony_ci *
5862306a36Sopenharmony_ci * Each mapped page only supports one notification; multiple calls referring to
5962306a36Sopenharmony_ci * the same page overwrite the previous notification. You must clear the
6062306a36Sopenharmony_ci * notification prior to the IOCTL_GNTALLOC_DEALLOC_GREF if you do not want it
6162306a36Sopenharmony_ci * to occur.
6262306a36Sopenharmony_ci */
6362306a36Sopenharmony_ci#define IOCTL_GNTALLOC_SET_UNMAP_NOTIFY \
6462306a36Sopenharmony_ci_IOC(_IOC_NONE, 'G', 7, sizeof(struct ioctl_gntalloc_unmap_notify))
6562306a36Sopenharmony_cistruct ioctl_gntalloc_unmap_notify {
6662306a36Sopenharmony_ci	/* IN parameters */
6762306a36Sopenharmony_ci	/* Offset in the file descriptor for a byte within the page (same as
6862306a36Sopenharmony_ci	 * used in mmap). If using UNMAP_NOTIFY_CLEAR_BYTE, this is the byte to
6962306a36Sopenharmony_ci	 * be cleared. Otherwise, it can be any byte in the page whose
7062306a36Sopenharmony_ci	 * notification we are adjusting.
7162306a36Sopenharmony_ci	 */
7262306a36Sopenharmony_ci	__u64 index;
7362306a36Sopenharmony_ci	/* Action(s) to take on unmap */
7462306a36Sopenharmony_ci	__u32 action;
7562306a36Sopenharmony_ci	/* Event channel to notify */
7662306a36Sopenharmony_ci	__u32 event_channel_port;
7762306a36Sopenharmony_ci};
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_ci/* Clear (set to zero) the byte specified by index */
8062306a36Sopenharmony_ci#define UNMAP_NOTIFY_CLEAR_BYTE 0x1
8162306a36Sopenharmony_ci/* Send an interrupt on the indicated event channel */
8262306a36Sopenharmony_ci#define UNMAP_NOTIFY_SEND_EVENT 0x2
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ci#endif /* __LINUX_PUBLIC_GNTALLOC_H__ */
85