summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorTerje Bergstrom <tbergstrom@nvidia.com>2012-09-23 02:36:48 -0400
committerDan Willemsen <dwillemsen@nvidia.com>2015-03-18 15:03:11 -0400
commit8162d4dee04b29fedcf7a070dbb573d24d49aa63 (patch)
treea9957109d3825dcccea29084d76fd0bc9da5e7fa /drivers
parent53a29d85f7eba5bacaf8ced36386830b333ccc28 (diff)
video: tegra: host: Add dmabuf support
Change-Id: I316fc5b8cc748b29e4f9776e27610d7468682311 Signed-off-by: Terje Bergstrom <tbergstrom@nvidia.com> Reviewed-on: http://git-master/r/139302 Reviewed-by: Juha Tukkinen <jtukkinen@nvidia.com> Tested-by: Juha Tukkinen <jtukkinen@nvidia.com> Rebase-Id: Rfe7ff7cabace52a9d9c75bcd7f5f768017367ff8
Diffstat (limited to 'drivers')
-rw-r--r--drivers/video/tegra/host/Makefile1
-rw-r--r--drivers/video/tegra/host/dmabuf.c87
-rw-r--r--drivers/video/tegra/host/dmabuf.h42
-rw-r--r--drivers/video/tegra/host/nvhost_memmgr.c53
-rw-r--r--drivers/video/tegra/host/nvhost_memmgr.h1
5 files changed, 184 insertions, 0 deletions
diff --git a/drivers/video/tegra/host/Makefile b/drivers/video/tegra/host/Makefile
index 17e919d68..8aaf2365f 100644
--- a/drivers/video/tegra/host/Makefile
+++ b/drivers/video/tegra/host/Makefile
@@ -28,3 +28,4 @@ obj-$(CONFIG_TEGRA_GRHOST) += tsec/
28obj-$(CONFIG_TEGRA_GRHOST) += nvhost.o 28obj-$(CONFIG_TEGRA_GRHOST) += nvhost.o
29 29
30obj-$(CONFIG_TEGRA_GRHOST_USE_NVMAP) += nvmap.o 30obj-$(CONFIG_TEGRA_GRHOST_USE_NVMAP) += nvmap.o
31obj-$(CONFIG_TEGRA_GRHOST_USE_DMABUF) += dmabuf.o
diff --git a/drivers/video/tegra/host/dmabuf.c b/drivers/video/tegra/host/dmabuf.c
new file mode 100644
index 000000000..68554b0df
--- /dev/null
+++ b/drivers/video/tegra/host/dmabuf.c
@@ -0,0 +1,87 @@
1/*
2 * drivers/video/tegra/host/dmabuf.c
3 *
4 * Tegra Graphics Host DMA-BUF support
5 *
6 * Copyright (c) 2012, NVIDIA Corporation.
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
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include <linux/dma-buf.h>
22#include <linux/nvhost.h>
23#include "chip_support.h"
24#include "nvhost_memmgr.h"
25
26static inline struct dma_buf_attachment *to_dmabuf_att(struct mem_handle *h)
27{
28 return (struct dma_buf_attachment *)(((u32)h) & ~0x3);
29}
30
31static inline struct dma_buf *to_dmabuf(struct mem_handle *h)
32{
33 return to_dmabuf_att(h)->dmabuf;
34}
35
36static inline int to_dmabuf_fd(u32 id)
37{
38 return nvhost_memmgr_id(id) >> 2;
39}
40struct mem_handle *nvhost_dmabuf_alloc(size_t size, size_t align, int flags)
41{
42 /* TODO: Add allocation via DMA Mapping API */
43 return NULL;
44}
45
46void nvhost_dmabuf_put(struct mem_handle *handle)
47{
48 dma_buf_put(to_dmabuf(handle));
49}
50
51struct sg_table *nvhost_dmabuf_pin(struct mem_handle *handle)
52{
53 return dma_buf_map_attachment(to_dmabuf_att(handle),
54 DMA_BIDIRECTIONAL);
55}
56
57void nvhost_dmabuf_unpin(struct mem_handle *handle, struct sg_table *sgt)
58{
59 dma_buf_unmap_attachment(to_dmabuf_att(handle), sgt, DMA_BIDIRECTIONAL);
60}
61
62void *nvhost_dmabuf_mmap(struct mem_handle *handle)
63{
64 return dma_buf_vmap(to_dmabuf(handle));
65}
66
67void nvhost_dmabuf_munmap(struct mem_handle *handle, void *addr)
68{
69 dma_buf_vunmap(to_dmabuf(handle), addr);
70}
71
72struct mem_handle *nvhost_dmabuf_get(u32 id, struct nvhost_device *dev)
73{
74 struct mem_handle *h;
75 struct dma_buf *buf;
76
77 buf = dma_buf_get(to_dmabuf_fd(id));
78 if (IS_ERR_OR_NULL(buf))
79 return (struct mem_handle *)buf;
80 else {
81 h = (struct mem_handle *)dma_buf_attach(buf, &dev->dev);
82 if (IS_ERR_OR_NULL(h))
83 dma_buf_put(buf);
84 }
85
86 return (struct mem_handle *) ((u32)h | mem_mgr_type_dmabuf);
87}
diff --git a/drivers/video/tegra/host/dmabuf.h b/drivers/video/tegra/host/dmabuf.h
new file mode 100644
index 000000000..0beb1d6b1
--- /dev/null
+++ b/drivers/video/tegra/host/dmabuf.h
@@ -0,0 +1,42 @@
1/*
2 * drivers/video/tegra/host/dmabuf.h
3 *
4 * Tegra Graphics Host dmabuf memory manager
5 *
6 * Copyright (c) 2012, NVIDIA Corporation.
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
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef __NVHOST_DMABUF_H
22#define __NVHOST_DMABUF_H
23
24#include "nvhost_memmgr.h"
25
26struct nvhost_chip_support;
27struct nvhost_device;
28
29struct mem_mgr *nvhost_dmabuf_alloc_mgr(void);
30void nvhost_dmabuf_put_mgr(struct mem_mgr *mgr);
31struct mem_mgr *nvhost_dmabuf_get_mgr(struct mem_mgr *mgr);
32struct mem_mgr *nvhost_dmabuf_get_mgr_file(int fd);
33struct mem_handle *nvhost_dmabuf_alloc(struct mem_mgr *mgr,
34 size_t size, size_t align, int flags);
35void nvhost_dmabuf_put(struct mem_handle *handle);
36struct sg_table *nvhost_dmabuf_pin(struct mem_handle *handle);
37void nvhost_dmabuf_unpin(struct mem_handle *handle, struct sg_table *sgt);
38void *nvhost_dmabuf_mmap(struct mem_handle *handle);
39void nvhost_dmabuf_munmap(struct mem_handle *handle, void *addr);
40int nvhost_dmabuf_get(u32 id, struct nvhost_device *dev);
41
42#endif
diff --git a/drivers/video/tegra/host/nvhost_memmgr.c b/drivers/video/tegra/host/nvhost_memmgr.c
index 8358f0c69..861cd8cdd 100644
--- a/drivers/video/tegra/host/nvhost_memmgr.c
+++ b/drivers/video/tegra/host/nvhost_memmgr.c
@@ -25,6 +25,9 @@
25#ifdef CONFIG_TEGRA_GRHOST_USE_NVMAP 25#ifdef CONFIG_TEGRA_GRHOST_USE_NVMAP
26#include "nvmap.h" 26#include "nvmap.h"
27#endif 27#endif
28#ifdef CONFIG_TEGRA_GRHOST_USE_DMABUF
29#include "dmabuf.h"
30#endif
28#include "chip_support.h" 31#include "chip_support.h"
29 32
30struct mem_mgr *nvhost_memmgr_alloc_mgr(void) 33struct mem_mgr *nvhost_memmgr_alloc_mgr(void)
@@ -32,6 +35,10 @@ struct mem_mgr *nvhost_memmgr_alloc_mgr(void)
32 struct mem_mgr *mgr = NULL; 35 struct mem_mgr *mgr = NULL;
33#ifdef CONFIG_TEGRA_GRHOST_USE_NVMAP 36#ifdef CONFIG_TEGRA_GRHOST_USE_NVMAP
34 mgr = nvhost_nvmap_alloc_mgr(); 37 mgr = nvhost_nvmap_alloc_mgr();
38#else
39#ifdef CONFIG_TEGRA_GRHOST_USE_DMABUF
40 mgr = (struct mem_mgr)1;
41#endif
35#endif 42#endif
36 43
37 return mgr; 44 return mgr;
@@ -41,6 +48,10 @@ void nvhost_memmgr_put_mgr(struct mem_mgr *mgr)
41{ 48{
42#ifdef CONFIG_TEGRA_GRHOST_USE_NVMAP 49#ifdef CONFIG_TEGRA_GRHOST_USE_NVMAP
43 nvhost_nvmap_put_mgr(mgr); 50 nvhost_nvmap_put_mgr(mgr);
51#else
52#ifdef CONFIG_TEGRA_GRHOST_USE_DMABUF
53 mgr = (struct mem_mgr)1;
54#endif
44#endif 55#endif
45} 56}
46 57
@@ -49,6 +60,10 @@ struct mem_mgr *nvhost_memmgr_get_mgr(struct mem_mgr *_mgr)
49 struct mem_mgr *mgr = NULL; 60 struct mem_mgr *mgr = NULL;
50#ifdef CONFIG_TEGRA_GRHOST_USE_NVMAP 61#ifdef CONFIG_TEGRA_GRHOST_USE_NVMAP
51 mgr = nvhost_nvmap_get_mgr(_mgr); 62 mgr = nvhost_nvmap_get_mgr(_mgr);
63#else
64#ifdef CONFIG_TEGRA_GRHOST_USE_DMABUF
65 mgr = (struct mem_mgr)1;
66#endif
52#endif 67#endif
53 68
54 return mgr; 69 return mgr;
@@ -59,6 +74,10 @@ struct mem_mgr *nvhost_memmgr_get_mgr_file(int fd)
59 struct mem_mgr *mgr = NULL; 74 struct mem_mgr *mgr = NULL;
60#ifdef CONFIG_TEGRA_GRHOST_USE_NVMAP 75#ifdef CONFIG_TEGRA_GRHOST_USE_NVMAP
61 mgr = nvhost_nvmap_get_mgr_file(fd); 76 mgr = nvhost_nvmap_get_mgr_file(fd);
77#else
78#ifdef CONFIG_TEGRA_GRHOST_USE_DMABUF
79 mgr = (struct mem_mgr)1;
80#endif
62#endif 81#endif
63 82
64 return mgr; 83 return mgr;
@@ -70,6 +89,10 @@ struct mem_handle *nvhost_memmgr_alloc(struct mem_mgr *mgr,
70 struct mem_handle *h = NULL; 89 struct mem_handle *h = NULL;
71#ifdef CONFIG_TEGRA_GRHOST_USE_NVMAP 90#ifdef CONFIG_TEGRA_GRHOST_USE_NVMAP
72 h = nvhost_nvmap_alloc(mgr, size, align, flags); 91 h = nvhost_nvmap_alloc(mgr, size, align, flags);
92#else
93#ifdef CONFIG_TEGRA_GRHOST_USE_DMABUF
94 h = nvhost_dmabuf_alloc(mgr, size, align, flags);
95#endif
73#endif 96#endif
74 97
75 return h; 98 return h;
@@ -86,6 +109,11 @@ struct mem_handle *nvhost_memmgr_get(struct mem_mgr *mgr,
86 h = (struct mem_handle *) nvhost_nvmap_get(mgr, id, dev); 109 h = (struct mem_handle *) nvhost_nvmap_get(mgr, id, dev);
87 break; 110 break;
88#endif 111#endif
112#ifdef CONFIG_TEGRA_GRHOST_USE_DMABUF
113 case mem_mgr_type_dmabuf:
114 h = (struct mem_handle *) nvhost_dmabuf_get(id, dev);
115 break;
116#endif
89 default: 117 default:
90 break; 118 break;
91 } 119 }
@@ -101,6 +129,11 @@ void nvhost_memmgr_put(struct mem_mgr *mgr, struct mem_handle *handle)
101 nvhost_nvmap_put(mgr, handle); 129 nvhost_nvmap_put(mgr, handle);
102 break; 130 break;
103#endif 131#endif
132#ifdef CONFIG_TEGRA_GRHOST_USE_DMABUF
133 case mem_mgr_type_dmabuf:
134 nvhost_dmabuf_put(handle);
135 break;
136#endif
104 default: 137 default:
105 break; 138 break;
106 } 139 }
@@ -115,6 +148,11 @@ struct sg_table *nvhost_memmgr_pin(struct mem_mgr *mgr,
115 return nvhost_nvmap_pin(mgr, handle); 148 return nvhost_nvmap_pin(mgr, handle);
116 break; 149 break;
117#endif 150#endif
151#ifdef CONFIG_TEGRA_GRHOST_USE_DMABUF
152 case mem_mgr_type_dmabuf:
153 return nvhost_dmabuf_pin(handle);
154 break;
155#endif
118 default: 156 default:
119 return 0; 157 return 0;
120 break; 158 break;
@@ -130,6 +168,11 @@ void nvhost_memmgr_unpin(struct mem_mgr *mgr,
130 nvhost_nvmap_unpin(mgr, handle, sgt); 168 nvhost_nvmap_unpin(mgr, handle, sgt);
131 break; 169 break;
132#endif 170#endif
171#ifdef CONFIG_TEGRA_GRHOST_USE_DMABUF
172 case mem_mgr_type_dmabuf:
173 nvhost_dmabuf_unpin(handle, sgt);
174 break;
175#endif
133 default: 176 default:
134 break; 177 break;
135 } 178 }
@@ -143,6 +186,11 @@ void *nvhost_memmgr_mmap(struct mem_handle *handle)
143 return nvhost_nvmap_mmap(handle); 186 return nvhost_nvmap_mmap(handle);
144 break; 187 break;
145#endif 188#endif
189#ifdef CONFIG_TEGRA_GRHOST_USE_DMABUF
190 case mem_mgr_type_dmabuf:
191 return nvhost_dmabuf_mmap(handle);
192 break;
193#endif
146 default: 194 default:
147 return 0; 195 return 0;
148 break; 196 break;
@@ -157,6 +205,11 @@ void nvhost_memmgr_munmap(struct mem_handle *handle, void *addr)
157 nvhost_nvmap_munmap(handle, addr); 205 nvhost_nvmap_munmap(handle, addr);
158 break; 206 break;
159#endif 207#endif
208#ifdef CONFIG_TEGRA_GRHOST_USE_DMABUF
209 case mem_mgr_type_dmabuf:
210 nvhost_dmabuf_munmap(handle, addr);
211 break;
212#endif
160 default: 213 default:
161 break; 214 break;
162 } 215 }
diff --git a/drivers/video/tegra/host/nvhost_memmgr.h b/drivers/video/tegra/host/nvhost_memmgr.h
index cfdde6db5..407a085e6 100644
--- a/drivers/video/tegra/host/nvhost_memmgr.h
+++ b/drivers/video/tegra/host/nvhost_memmgr.h
@@ -33,6 +33,7 @@ enum mem_mgr_flag {
33 33
34enum mem_mgr_type { 34enum mem_mgr_type {
35 mem_mgr_type_nvmap = 0, 35 mem_mgr_type_nvmap = 0,
36 mem_mgr_type_dmabuf = 1,
36}; 37};
37 38
38int nvhost_memmgr_init(struct nvhost_chip_support *chip); 39int nvhost_memmgr_init(struct nvhost_chip_support *chip);