2 * include/linux/nvhost_as_ioctl.h
4 * Tegra Host Address Space Driver
6 * Copyright (c) 2011-2014, NVIDIA CORPORATION. All rights reserved.
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.
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
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.
22 #ifndef __LINUX_NVHOST_AS_IOCTL_H
23 #define __LINUX_NVHOST_AS_IOCTL_H
25 #include <linux/ioctl.h>
26 #include <linux/types.h>
28 #if !defined(__KERNEL__)
32 #define NVHOST_AS_IOCTL_MAGIC 'A'
35 * /dev/nvhost-as-* devices
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.
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).
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.
53 * Allocating an address space range:
55 * Address ranges created with this ioctl are reserved for later use with
56 * fixed-address buffer mappings.
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.'
62 struct nvhost32_as_alloc_space_args {
63 __u32 pages; /* in, pages */
64 __u32 page_size; /* in, bytes */
66 #define NVHOST_AS_ALLOC_SPACE_FLAGS_FIXED_OFFSET 0x1
67 #define NVHOST_AS_ALLOC_SPACE_FLAGS_SPARSE 0x2
69 __u64 offset; /* inout, byte address valid iff _FIXED_OFFSET */
70 __u64 align; /* in, alignment multiple (0:={1 or n/a}) */
74 struct nvhost_as_alloc_space_args {
75 __u32 pages; /* in, pages */
76 __u32 page_size; /* in, bytes */
78 __u32 padding; /* in */
80 __u64 offset; /* inout, byte address valid iff _FIXED_OFFSET */
81 __u64 align; /* in, alignment multiple (0:={1 or n/a}) */
86 * Releasing an address space range:
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.
91 struct nvhost_as_free_space_args {
92 __u64 offset; /* in, byte address */
93 __u32 pages; /* in, pages */
94 __u32 page_size; /* in, bytes */
98 * Binding a nvhost channel to an address space:
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).
105 struct nvhost_as_bind_channel_args {
106 __u32 channel_fd; /* in */
110 * Mapping nvmap buffers into an address space:
112 * The start address is the 'offset' given if _FIXED_OFFSET is specified.
113 * Otherwise the address returned is a multiple of 'align.'
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
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 */
128 __u64 offset; /* inout, byte address valid iff _FIXED_OFFSET */
129 __u64 align; /* in, alignment multiple (0:={1 or n/a}) */
134 * Mapping dmabuf fds into an address space:
136 * The caller requests a mapping to a particular page 'kind'.
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.
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 */
149 __u64 buffer_offset; /* in, offset of mapped buffer region */
150 __u64 mapping_size; /* in, size of mapped buffer region */
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. */
160 * Unmapping a buffer:
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.
166 struct nvhost_as_unmap_buffer_args {
167 __u64 offset; /* in, byte address */
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)
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)