summaryrefslogtreecommitdiff
path: root/linux-core/mmfs.h
blob: bdc148b9c638efc62e96fa26838e46c11842cb73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
 * Copyright © 2008 Intel Corporation
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (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 (including the next
 * paragraph) 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.
 *
 * Authors:
 *    Eric Anholt <eric@anholt.net>
 *
 */

/** @file mmfs.h
 * This file provides ioctl and ioctl argument definitions for using the
 * mmfs device.
 */
#ifdef __KERNEL__
#include <linux/spinlock.h>
#include <linux/idr.h>

/** @file mmfs_priv.h
 * This file provides internal structure definitions for mmfs..
 */

/**
 * This structure defines the mmfs memory object, which will be used by the
 * DRM for its buffer objects.
 */
struct mmfs_object {
	/** File representing the shmem storage */
	struct file *filp;

	spinlock_t lock;

	size_t size;
	/** Reference count of this object, protected by object_lock */
	int refcount;
};

/**
 * This structure defines the process (actually per-fd) mapping of object
 * handles to mmfs objects.
 */
struct mmfs_file {
	/** Mapping of object handles to object pointers. */
	struct idr object_idr;
	/**
	 * Lock for synchronization of access to object->refcount and
	 * object_idr.  See note in mmfs_unreference_ioctl.
	 */
	spinlock_t delete_lock;
};

void mmfs_object_reference(struct mmfs_object *obj);
void mmfs_object_unreference(struct mmfs_object *obj);

#endif /* __KERNEL__ */

#define MMFS_DEVICE_PATH		"/dev/mmfs"
/* XXX: Choose non-experimental major */
#define MMFS_DEVICE_MAJOR		246

struct mmfs_alloc_args {
	/**
	 * Requested size for the object.
	 *
	 * The (page-aligned) allocated size for the object will be returned.
	 */
	uint32_t size;
	/** Returned handle for the object. */
	uint32_t handle;
};

struct mmfs_unreference_args {
	/** Handle of the object to be unreferenced. */
	uint32_t handle;
};

struct mmfs_link_args {
	/** Handle for the object being given a name. */
	uint32_t handle;
	/** Requested file name to export the object under. */
	char *name;
	/** Requested file mode to export the object under. */
	mode_t mode;
};

struct mmfs_pread_args {
	/** Handle for the object being read. */
	uint32_t handle;
	/** Offset into the object to read from */
	off_t offset;
	/** Length of data to read */
	size_t size;
	/** Pointer to write the data into. */
	void *data;
};

struct mmfs_pwrite_args {
	/** Handle for the object being written to. */
	uint32_t handle;
	/** Offset into the object to write to */
	off_t offset;
	/** Length of data to write */
	size_t size;
	/** Pointer to read the data from. */
	void *data;
};

struct mmfs_mmap_args {
	/** Handle for the object being mapped. */
	uint32_t handle;
	/** Offset in the object to map. */
	off_t offset;
	/**
	 * Length of data to map.
	 *
	 * The value will be page-aligned.
	 */
	size_t size;
	/** Returned pointer the data was mapped at */
	void *addr;
};

/**
 * \name Ioctls Definitions
 */
/* @{ */

#define MMFS_IOCTL_BASE			'm'
#define MMFS_IO(nr)			_IO(MMFS_IOCTL_BASE, nr)
#define MMFS_IOR(nr,type)		_IOR(MMFS_IOCTL_BASE, nr, type)
#define MMFS_IOW(nr,type)		_IOW(MMFS_IOCTL_BASE, nr, type)
#define MMFS_IOWR(nr,type)		_IOWR(MMFS_IOCTL_BASE, nr, type)

/** This ioctl allocates an object and returns a handle referencing it. */
#define MMFS_IOCTL_ALLOC		MMFS_IOWR(0x00, struct mmfs_alloc_args)

/**
 * This ioctl releases the reference on the handle returned from
 * MMFS_IOCTL_ALLOC.
 */
#define MMFS_IOCTL_UNREFERENCE		MMFS_IOR(0x01, struct mmfs_unreference_args)

/**
 * This ioctl creates a file in the mmfs filesystem representing an object.
 *
 * XXX: Need a way to get handle from fd or name.
 */
#define MMFS_IOCTL_LINK			MMFS_IOWR(0x02, struct mmfs_link_args)

/** This ioctl copies data from an object into a user address. */
#define MMFS_IOCTL_PREAD		MMFS_IOWR(0x03, struct mmfs_pread_args)

/** This ioctl copies data from a user address into an object. */
#define MMFS_IOCTL_PWRITE		MMFS_IOWR(0x04, struct mmfs_pwrite_args)

/** This ioctl maps data from the object into the user address space. */
#define MMFS_IOCTL_MMAP			MMFS_IOWR(0x05, struct mmfs_mmap_args)

/* }@ */