1 /*
2 * dmabuf_container.c
3 *
4 * Copyright 2018 Samsung Electronics Co., Ltd.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 #define LOG_TAG "dmabuf-container"
20
21 #include <string.h>
22 #include <errno.h>
23 #include <sys/ioctl.h>
24
25 #include <string.h>
26
27 #include <sys/ioctl.h>
28
29 #include <log/log.h>
30
31 #include <hardware/exynos/ion.h>
32 #include <hardware/exynos/dmabuf_container.h>
33
34 struct dma_buf_merge {
35 int *dma_bufs;
36 int32_t count;
37 int32_t dmabuf_container;
38 uint32_t reserved[2];
39 };
40 #define DMA_BUF_BASE 'b'
41 #define DMA_BUF_IOCTL_MERGE _IOWR(DMA_BUF_BASE, 13, struct dma_buf_merge)
42 #define DMA_BUF_IOCTL_CONTAINER_SET_MASK _IOW(DMA_BUF_BASE, 14, __u32)
43 #define DMA_BUF_IOCTL_CONTAINER_GET_MASK _IOR(DMA_BUF_BASE, 14, __u32)
44
dma_buf_merge(int base_fd,int src_fds[],int src_count)45 int dma_buf_merge(int base_fd, int src_fds[], int src_count)
46 {
47 struct dma_buf_merge data = {
48 .dma_bufs = src_fds,
49 .count = src_count,
50 };
51
52 if (src_count > MAX_BUFCON_SRC_BUFS) {
53 ALOGE("too many source buffers");
54 return -1;
55 }
56
57 if (ioctl(base_fd, DMA_BUF_IOCTL_MERGE, &data) < 0) {
58 ALOGE("failed to merge %d dma-bufs: %s", src_count, strerror(errno));
59 return -1;
60 }
61
62 return data.dmabuf_container;
63 }
64
dmabuf_container_set_mask(int dmabuf,uint32_t mask)65 int dmabuf_container_set_mask(int dmabuf, uint32_t mask)
66 {
67 if (ioctl(dmabuf, DMA_BUF_IOCTL_CONTAINER_SET_MASK, &mask) < 0) {
68 ALOGE("Failed to configure dma-buf container mask %#x: %s", mask, strerror(errno));
69 return -1;
70 }
71
72 return 0;
73 }
74
dmabuf_container_get_mask(int dmabuf,uint32_t * mask)75 int dmabuf_container_get_mask(int dmabuf, uint32_t *mask)
76 {
77 if (ioctl(dmabuf, DMA_BUF_IOCTL_CONTAINER_GET_MASK, mask) < 0) {
78 ALOGE("Failed to retrieve dma-buf container mask: %s", strerror(errno));
79 return -1;
80 }
81
82 return 0;
83 }
84