ARM: Build fix after Tegra14 K3.4 merge
[linux-3.10.git] / include / linux / nvmap.h
1 /*
2  * include/linux/nvmap.h
3  *
4  * structure declarations for nvmem and nvmap user-space ioctls
5  *
6  * Copyright (c) 2009-2012, NVIDIA CORPORATION. All rights reserved.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
16  * more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21  */
22
23 #include <linux/ioctl.h>
24 #include <linux/file.h>
25 #include <linux/rbtree.h>
26 #include <linux/dma-buf.h>
27
28 #if !defined(__KERNEL__)
29 #define __user
30 #endif
31
32 #ifndef _LINUX_NVMAP_H
33 #define _LINUX_NVMAP_H
34
35 #define NVMAP_HEAP_SYSMEM  (1ul<<31)
36 #define NVMAP_HEAP_IOVMM   (1ul<<30)
37
38 /* common carveout heaps */
39 #define NVMAP_HEAP_CARVEOUT_IRAM    (1ul<<29)
40 #define NVMAP_HEAP_CARVEOUT_VPR     (1ul<<28)
41 #define NVMAP_HEAP_CARVEOUT_TSEC    (1ul<<27)
42 #define NVMAP_HEAP_CARVEOUT_GENERIC (1ul<<0)
43
44 #define NVMAP_HEAP_CARVEOUT_MASK    (NVMAP_HEAP_IOVMM - 1)
45
46 /* allocation flags */
47 #define NVMAP_HANDLE_UNCACHEABLE     (0x0ul << 0)
48 #define NVMAP_HANDLE_WRITE_COMBINE   (0x1ul << 0)
49 #define NVMAP_HANDLE_INNER_CACHEABLE (0x2ul << 0)
50 #define NVMAP_HANDLE_CACHEABLE       (0x3ul << 0)
51 #define NVMAP_HANDLE_CACHE_FLAG      (0x3ul << 0)
52
53 #define NVMAP_HANDLE_SECURE          (0x1ul << 2)
54 #define NVMAP_HANDLE_ZEROED_PAGES    (0x1ul << 3)
55
56 #if defined(__KERNEL__)
57
58 #if defined(CONFIG_TEGRA_NVMAP)
59 struct nvmap_handle;
60 struct nvmap_client;
61 struct nvmap_device;
62
63 #define nvmap_ref_to_handle(_ref) (*(struct nvmap_handle **)(_ref))
64 /* Convert User space handle to Kernel. */
65 #define nvmap_convert_handle_u2k(h) (h)
66
67 /* handle_ref objects are client-local references to an nvmap_handle;
68  * they are distinct objects so that handles can be unpinned and
69  * unreferenced the correct number of times when a client abnormally
70  * terminates */
71 struct nvmap_handle_ref {
72         struct nvmap_handle *handle;
73         struct rb_node  node;
74         atomic_t        dupes;  /* number of times to free on file close */
75         atomic_t        pin;    /* number of times to unpin on free */
76 };
77
78 #elif defined(CONFIG_ION_TEGRA)
79 /* For Ion Mem Manager support through nvmap_* API's. */
80 #include "../../../../../drivers/gpu/ion/ion_priv.h"
81 #define nvmap_client ion_client
82 #define nvmap_device ion_device
83 #define nvmap_handle ion_handle
84 #define nvmap_handle_ref ion_handle
85 #define nvmap_ref_to_handle(_ref) (struct ion_handle *)_ref
86 /* Convert User space handle to Kernel. */
87 #define nvmap_convert_handle_u2k(h) ({ \
88         if ((u32)h >= TASK_SIZE) { \
89                 pr_err("Invalid user space handle."); \
90                 BUG(); \
91         } \
92         (*((u32 *)h)); })
93
94 #endif /* CONFIG_ION_TEGRA */
95
96 #define nvmap_id_to_handle(_id) ((struct nvmap_handle *)(_id))
97
98 struct nvmap_client *nvmap_create_client(struct nvmap_device *dev,
99                                          const char *name);
100
101 struct nvmap_handle_ref *nvmap_alloc(struct nvmap_client *client, size_t size,
102                                      size_t align, unsigned int flags,
103                                      unsigned int heap_mask);
104
105 phys_addr_t _nvmap_get_addr_from_id(u32 id);
106
107 void nvmap_free(struct nvmap_client *client, struct nvmap_handle_ref *r);
108
109 void _nvmap_free(struct nvmap_client *client, struct nvmap_handle_ref *r);
110
111 void *nvmap_mmap(struct nvmap_handle_ref *r);
112
113 void nvmap_munmap(struct nvmap_handle_ref *r, void *addr);
114
115 void *nvmap_kmap(struct nvmap_handle_ref *r, unsigned int pagenum);
116
117 void nvmap_kunmap(struct nvmap_handle_ref *r, unsigned int pagenum,
118                 void *addr);
119
120 struct nvmap_client *nvmap_client_get_file(int fd);
121
122 struct nvmap_client *nvmap_client_get(struct nvmap_client *client);
123
124 void nvmap_client_put(struct nvmap_client *c);
125
126 phys_addr_t nvmap_pin(struct nvmap_client *c, struct nvmap_handle_ref *r);
127 phys_addr_t _nvmap_pin(struct nvmap_client *c, struct nvmap_handle_ref *r);
128
129
130 phys_addr_t nvmap_handle_address(struct nvmap_client *c, unsigned long id);
131
132 void nvmap_unpin(struct nvmap_client *client, struct nvmap_handle_ref *r);
133
134 void nvmap_unpin_handles(struct nvmap_client *client,
135                          struct nvmap_handle **h, int nr);
136
137 struct nvmap_handle_ref *nvmap_duplicate_handle_id(struct nvmap_client *client,
138                                                    unsigned long id);
139 struct nvmap_handle_ref *_nvmap_duplicate_handle_id(struct nvmap_client *client,
140                                                    unsigned long id);
141
142 int nvmap_pin_array(struct nvmap_client *client,
143                 unsigned long    *ids,
144                 long unsigned id_type_mask,
145                 long unsigned id_type,
146                 int nr,
147                 struct nvmap_handle **unique_arr,
148                 struct nvmap_handle_ref **unique_arr_refs);
149
150
151 struct nvmap_handle_ref *nvmap_duplicate_handle_id(struct nvmap_client *client,
152                                                    unsigned long id);
153
154 struct nvmap_platform_carveout {
155         const char *name;
156         unsigned int usage_mask;
157         phys_addr_t base;
158         size_t size;
159         size_t buddy_size;
160 };
161
162 struct nvmap_platform_data {
163         const struct nvmap_platform_carveout *carveouts;
164         unsigned int nr_carveouts;
165 };
166
167 extern struct nvmap_device *nvmap_dev;
168
169 #ifdef CONFIG_DMA_SHARED_BUFFER
170 /* dma-buf exporter */
171 struct dma_buf *nvmap_share_dmabuf(struct nvmap_client *client, u32 id);
172 #else
173 static inline struct dma_buf *nvmap_share_dmabuf(struct nvmap_client *client,
174                                                  u32 id)
175 {
176         return NULL;
177 }
178 #endif  /* !CONFIG_DMA_SHARED_BUFFER */
179
180 #endif /* __KERNEL__ */
181
182 #endif /* _LINUX_NVMAP_H */