From 2915635a0a4d03fe442399a679a42a92b33c8b99 Mon Sep 17 00:00:00 2001 From: Mateusz Krawczuk Date: Fri, 12 Jun 2015 20:09:25 +0200 Subject: v4l2-mfc-example: Add and refactor gem functions Gem function related moved to gem.c and gem.h It should make code more clean and obviously. Signed-off-by: Mateusz Krawczuk --- v4l2-mfc-example/Makefile | 2 +- v4l2-mfc-example/gem.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++ v4l2-mfc-example/gem.h | 40 ++++++++++++++++++++++ 3 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 v4l2-mfc-example/gem.c create mode 100644 v4l2-mfc-example/gem.h (limited to 'v4l2-mfc-example') diff --git a/v4l2-mfc-example/Makefile b/v4l2-mfc-example/Makefile index 7056683..64294a8 100644 --- a/v4l2-mfc-example/Makefile +++ b/v4l2-mfc-example/Makefile @@ -48,7 +48,7 @@ INCLUDES = $(KERNELHEADERS) $(DRMHEADERS) #-I$(TARGETROOT)/usr/include/linux -SOURCES = main.c fileops.c args.c parser.c fb.c fimc.c mfc.c queue.c drm.c +SOURCES = main.c fileops.c args.c parser.c fb.c fimc.c mfc.c queue.c drm.c gem.c OBJECTS := $(SOURCES:.c=.o) EXEC = v4l2_decode CFLAGS = -Wall -g -DS5PC1XX_FIMC -lm diff --git a/v4l2-mfc-example/gem.c b/v4l2-mfc-example/gem.c new file mode 100644 index 0000000..a6d6516 --- /dev/null +++ b/v4l2-mfc-example/gem.c @@ -0,0 +1,85 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "common.h" +#include "fimc.h" +#include + +#include +#include +#include "gem.h" + +int exynos_gem_create(int fd, struct drm_exynos_gem_create *gem) +{ + int ret; + if (!gem) { + fprintf(stderr,"%s: %d - GEM object is null\n",__func__,__LINE__); + return -EINVAL; + } + + ret = ioctl(fd, DRM_IOCTL_EXYNOS_GEM_CREATE, gem) ; + if(ret){ + fprintf(stderr,"%s: %d - Failed to create GEM buffer\n %d %s",__func__,__LINE__,ret,strerror(errno)); + return -EINVAL; + + } + return 0; +} + +int exynos_gem_map_offset(int fd, struct drm_mode_map_dumb *map_off) +{ + + if (ioctl(fd, DRM_IOCTL_MODE_MAP_DUMB, map_off) < 0) { + fprintf(stderr,"%s: %d - Failed to get buffer offset\n",__func__,__LINE__); + return -EINVAL; + } + return 0; +} +int exynos_gem_mmap(int fd, struct exynos_gem_mmap_data *in_mmap) +{ + int ret; + void *map; + struct drm_mode_map_dumb arg; + + memset(&arg, 0, sizeof(arg)); + arg.handle = in_mmap->handle; + + ret = ioctl(fd, DRM_IOCTL_MODE_MAP_DUMB, &arg); + if (ret) { + fprintf(stderr, "%s: %d - failed to map dumb buffer: %s\n", + __func__, __LINE__, strerror(errno)); + return ret; + } + + in_mmap->offset = arg.offset; + + map = mmap(NULL, (size_t)in_mmap->size, PROT_READ | PROT_WRITE, + MAP_SHARED, fd, (off_t)arg.offset); + if (map == MAP_FAILED) { + fprintf(stderr, "%s: %d - failed to mmap buffer: %s\n", + __func__, __LINE__, strerror(errno)); + return -EFAULT; + } + + in_mmap->addr = map; + + return 0; +} + +int exynos_gem_close(int fd, struct drm_gem_close *gem_close) +{ + int ret = 0; + + ret = ioctl(fd, DRM_IOCTL_GEM_CLOSE, gem_close); + if (ret < 0) + fprintf(stderr, "%s: %d - failed to close: %s\n", __func__, __LINE__, strerror(-ret)); + return ret; +} \ No newline at end of file diff --git a/v4l2-mfc-example/gem.h b/v4l2-mfc-example/gem.h new file mode 100644 index 0000000..8b92b48 --- /dev/null +++ b/v4l2-mfc-example/gem.h @@ -0,0 +1,40 @@ +/* + * V4L2 Codec decoding example application + * Kamil Debski + * Mateusz Krawczuk + * + * GEM operations header file + * + * Copyright 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#ifndef INCLUDE_GEM_H +#define INCLUDE_GEM_H + +#include "common.h" +#include + +struct exynos_gem_mmap_data { + uint32_t handle; + uint64_t size; + uint64_t offset; + void *addr; +}; + +int exynos_gem_create(int fd, struct drm_exynos_gem_create *gem); +int exynos_gem_map_offset(int fd, struct drm_mode_map_dumb *map_off); +int exynos_gem_mmap(int fd, struct exynos_gem_mmap_data *in_mmap); +int exynos_gem_close(int fd, struct drm_gem_close *gem_close); +#endif /* INCLUDE_IPP_H */ -- cgit v1.2.3