]> rtime.felk.cvut.cz Git - sojka/nv-tegra/linux-3.10.git/blob - include/linux/nvhost_as_ioctl.h
gpu: nvgpu: implement mapping for sparse allocation
[sojka/nv-tegra/linux-3.10.git] / include / linux / nvhost_as_ioctl.h
1 /*
2  * include/linux/nvhost_as_ioctl.h
3  *
4  * Tegra Host Address Space Driver
5  *
6  * Copyright (c) 2011-2014, NVIDIA CORPORATION.  All rights reserved.
7  *
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms and conditions of the GNU General Public License,
10  * version 2, as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15  * more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #ifndef __LINUX_NVHOST_AS_IOCTL_H
23 #define __LINUX_NVHOST_AS_IOCTL_H
24
25 #include <linux/ioctl.h>
26 #include <linux/types.h>
27
28 #if !defined(__KERNEL__)
29 #define __user
30 #endif
31
32 #define NVHOST_AS_IOCTL_MAGIC 'A'
33
34 /*
35  * /dev/nvhost-as-* devices
36  *
37  * Opening a '/dev/nvhost-as-<module_name>' device node creates a new address
38  * space.  nvhost channels (for the same module) can then be bound to such an
39  * address space to define the addresses it has access to.
40  *
41  * Once a nvhost channel has been bound to an address space it cannot be
42  * unbound.  There is no support for allowing an nvhost channel to change from
43  * one address space to another (or from one to none).
44  *
45  * As long as there is an open device file to the address space, or any bound
46  * nvhost channels it will be valid.  Once all references to the address space
47  * are removed the address space is deleted.
48  *
49  */
50
51
52 /*
53  * Allocating an address space range:
54  *
55  * Address ranges created with this ioctl are reserved for later use with
56  * fixed-address buffer mappings.
57  *
58  * If _FLAGS_FIXED_OFFSET is specified then the new range starts at the 'offset'
59  * given.  Otherwise the address returned is chosen to be a multiple of 'align.'
60  *
61  */
62 struct nvhost32_as_alloc_space_args {
63         __u32 pages;     /* in, pages */
64         __u32 page_size; /* in, bytes */
65         __u32 flags;     /* in */
66 #define NVHOST_AS_ALLOC_SPACE_FLAGS_FIXED_OFFSET 0x1
67 #define NVHOST_AS_ALLOC_SPACE_FLAGS_SPARSE 0x2
68         union {
69                 __u64 offset; /* inout, byte address valid iff _FIXED_OFFSET */
70                 __u64 align;  /* in, alignment multiple (0:={1 or n/a}) */
71         } o_a;
72 };
73
74 struct nvhost_as_alloc_space_args {
75         __u32 pages;     /* in, pages */
76         __u32 page_size; /* in, bytes */
77         __u32 flags;     /* in */
78         __u32 padding;     /* in */
79         union {
80                 __u64 offset; /* inout, byte address valid iff _FIXED_OFFSET */
81                 __u64 align;  /* in, alignment multiple (0:={1 or n/a}) */
82         } o_a;
83 };
84
85 /*
86  * Releasing an address space range:
87  *
88  * The previously allocated region starting at 'offset' is freed.  If there are
89  * any buffers currently mapped inside the region the ioctl will fail.
90  */
91 struct nvhost_as_free_space_args {
92         __u64 offset; /* in, byte address */
93         __u32 pages;     /* in, pages */
94         __u32 page_size; /* in, bytes */
95 };
96
97 /*
98  * Binding a nvhost channel to an address space:
99  *
100  * A channel must be bound to an address space before allocating a gpfifo
101  * in nvhost.  The 'channel_fd' given here is the fd used to allocate the
102  * channel.  Once a channel has been bound to an address space it cannot
103  * be unbound (except for when the channel is destroyed).
104  */
105 struct nvhost_as_bind_channel_args {
106         __u32 channel_fd; /* in */
107 } __packed;
108
109 /*
110  * Mapping nvmap buffers into an address space:
111  *
112  * The start address is the 'offset' given if _FIXED_OFFSET is specified.
113  * Otherwise the address returned is a multiple of 'align.'
114  *
115  * If 'page_size' is set to 0 the nvmap buffer's allocation alignment/sizing
116  * will be used to determine the page size (largest possible).  The page size
117  * chosen will be returned back to the caller in the 'page_size' parameter in
118  * that case.
119  */
120 struct nvhost_as_map_buffer_args {
121         __u32 flags;          /* in/out */
122 #define NVHOST_AS_MAP_BUFFER_FLAGS_FIXED_OFFSET     BIT(0)
123 #define NVHOST_AS_MAP_BUFFER_FLAGS_CACHEABLE        BIT(2)
124         __u32 nvmap_fd;       /* in */
125         __u32 nvmap_handle;   /* in */
126         __u32 page_size;      /* inout, 0:= best fit to buffer */
127         union {
128                 __u64 offset; /* inout, byte address valid iff _FIXED_OFFSET */
129                 __u64 align;  /* in, alignment multiple (0:={1 or n/a})   */
130         } o_a;
131 };
132
133  /*
134  * Mapping dmabuf fds into an address space:
135  *
136  * The caller requests a mapping to a particular page 'kind'.
137  *
138  * If 'page_size' is set to 0 the dmabuf's alignment/sizing will be used to
139  * determine the page size (largest possible).  The page size chosen will be
140  * returned back to the caller in the 'page_size' parameter in that case.
141  */
142 struct nvhost_as_map_buffer_ex_args {
143         __u32 flags;            /* in/out */
144 #define NV_KIND_DEFAULT -1
145         __s32 kind;             /* in (-1 represents default) */
146         __u32 dmabuf_fd;        /* in */
147         __u32 page_size;        /* inout, 0:= best fit to buffer */
148
149         __u64 buffer_offset;    /* in, offset of mapped buffer region */
150         __u64 mapping_size;     /* in, size of mapped buffer region */
151
152         __u64 as_offset;        /* in/out, we use this address if flag
153                                  * FIXED_OFFSET is set. This will fail
154                                  * if space is not properly allocated. The
155                                  * actual virtual address to which we mapped
156                                  * the buffer is returned in this field. */
157 };
158
159 /*
160  * Unmapping a buffer:
161  *
162  * To unmap a previously mapped buffer set 'offset' to the offset returned in
163  * the mapping call.  This includes where a buffer has been mapped into a fixed
164  * offset of a previously allocated address space range.
165  */
166 struct nvhost_as_unmap_buffer_args {
167         __u64 offset; /* in, byte address */
168 };
169
170 #define NVHOST_AS_IOCTL_BIND_CHANNEL \
171         _IOWR(NVHOST_AS_IOCTL_MAGIC, 1, struct nvhost_as_bind_channel_args)
172 #define NVHOST32_AS_IOCTL_ALLOC_SPACE \
173         _IOWR(NVHOST_AS_IOCTL_MAGIC, 2, struct nvhost32_as_alloc_space_args)
174 #define NVHOST_AS_IOCTL_FREE_SPACE \
175         _IOWR(NVHOST_AS_IOCTL_MAGIC, 3, struct nvhost_as_free_space_args)
176 #define NVHOST_AS_IOCTL_MAP_BUFFER \
177         _IOWR(NVHOST_AS_IOCTL_MAGIC, 4, struct nvhost_as_map_buffer_args)
178 #define NVHOST_AS_IOCTL_UNMAP_BUFFER \
179         _IOWR(NVHOST_AS_IOCTL_MAGIC, 5, struct nvhost_as_unmap_buffer_args)
180 #define NVHOST_AS_IOCTL_ALLOC_SPACE \
181         _IOWR(NVHOST_AS_IOCTL_MAGIC, 6, struct nvhost_as_alloc_space_args)
182 #define NVHOST_AS_IOCTL_MAP_BUFFER_EX \
183         _IOWR(NVHOST_AS_IOCTL_MAGIC, 7, struct nvhost_as_map_buffer_ex_args)
184
185 #define NVHOST_AS_IOCTL_LAST            \
186         _IOC_NR(NVHOST_AS_IOCTL_MAP_BUFFER_EX)
187 #define NVHOST_AS_IOCTL_MAX_ARG_SIZE    \
188         sizeof(struct nvhost_as_map_buffer_ex_args)
189
190
191 #endif