diff options
author | Daniel Levin <dendy@ti.com> | 2012-10-04 15:58:53 +0300 |
---|---|---|
committer | Daniel Levin <dendy@ti.com> | 2012-11-19 21:51:55 +0200 |
commit | c7a625e6dbe9011d583e0322ce8d061c541b1604 (patch) | |
tree | 82713195d3756cab3e54d2b585d84d754286bab2 | |
parent | ebf043f0d02d6394066b142158c2928a37a4540f (diff) | |
download | hardware_ti_omap4-c7a625e6dbe9011d583e0322ce8d061c541b1604.zip hardware_ti_omap4-c7a625e6dbe9011d583e0322ce8d061c541b1604.tar.gz hardware_ti_omap4-c7a625e6dbe9011d583e0322ce8d061c541b1604.tar.bz2 |
ION: Moved ion to libion_ti
Since Google approach is to have own ion library in parallel with TI
ion library, latter has been renamed to ion_ti in JB MR1 and moved into
hardware/ti/omap4xxx together with kernel headers.
This patch updates Google ion_ti to recent version from TI JB MR0
release and moves sources to libion_ti to avoid accidental picking up
of system/core/include/ion/ion.h instead of TI ion.h header.
Change-Id: Icbaddbe65298a99fa7d7d5c53e9736774dc75ead
Signed-off-by: Daniel Levin <dendy@ti.com>
-rw-r--r-- | camera/MemoryManager.cpp | 2 | ||||
-rw-r--r-- | include/ion_ti/ion.h | 1 | ||||
-rw-r--r-- | ion/Android.mk | 13 | ||||
-rw-r--r-- | libion_ti/Android.mk | 27 | ||||
-rw-r--r-- | libion_ti/ion.c (renamed from ion/ion.c) | 49 | ||||
-rw-r--r-- | libion_ti/ion.h (renamed from ion/ion.h) | 14 | ||||
-rw-r--r-- | libion_ti/ion_test.c | 319 | ||||
-rw-r--r-- | libion_ti/ion_test_2.c | 479 | ||||
-rw-r--r-- | libion_ti/linux_ion.h (renamed from ion/linux_ion.h) | 18 | ||||
-rw-r--r-- | libion_ti/omap_ion.h (renamed from ion/omap_ion.h) | 14 |
10 files changed, 910 insertions, 26 deletions
diff --git a/camera/MemoryManager.cpp b/camera/MemoryManager.cpp index 8631bbd..e3b642c 100644 --- a/camera/MemoryManager.cpp +++ b/camera/MemoryManager.cpp @@ -24,7 +24,7 @@ extern "C" { -#include <ion.h> +#include <ion_ti/ion.h> //#include <timm_osal_interfaces.h> //#include <timm_osal_trace.h> diff --git a/include/ion_ti/ion.h b/include/ion_ti/ion.h new file mode 100644 index 0000000..b0b1973 --- /dev/null +++ b/include/ion_ti/ion.h @@ -0,0 +1 @@ +#include "../../libion_ti/ion.h" diff --git a/ion/Android.mk b/ion/Android.mk deleted file mode 100644 index 58fc9f9..0000000 --- a/ion/Android.mk +++ /dev/null @@ -1,13 +0,0 @@ -# only include if running on an omap4 platform -ifeq ($(TARGET_BOARD_PLATFORM),omap4) - -LOCAL_PATH:= $(call my-dir) - -include $(CLEAR_VARS) -LOCAL_SRC_FILES := ion.c -LOCAL_MODULE := libion_ti -LOCAL_MODULE_TAGS := optional -LOCAL_SHARED_LIBRARIES := liblog -include $(BUILD_HEAPTRACKED_SHARED_LIBRARY) - -endif diff --git a/libion_ti/Android.mk b/libion_ti/Android.mk new file mode 100644 index 0000000..ada33f7 --- /dev/null +++ b/libion_ti/Android.mk @@ -0,0 +1,27 @@ +# only include if running on an omap4 platform +ifeq ($(TARGET_BOARD_PLATFORM),omap4) + +LOCAL_PATH:= $(call my-dir) + +include $(CLEAR_VARS) +LOCAL_SRC_FILES := ion.c +LOCAL_MODULE := libion_ti +LOCAL_MODULE_TAGS := optional +LOCAL_SHARED_LIBRARIES := liblog +include $(BUILD_SHARED_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_SRC_FILES := ion.c ion_test.c +LOCAL_MODULE := ion_ti_test +LOCAL_MODULE_TAGS := optional tests +LOCAL_SHARED_LIBRARIES := liblog +include $(BUILD_EXECUTABLE) + +include $(CLEAR_VARS) +LOCAL_SRC_FILES := ion.c ion_test_2.c +LOCAL_MODULE := ion_ti_test2 +LOCAL_MODULE_TAGS := optional tests +LOCAL_SHARED_LIBRARIES := liblog +include $(BUILD_EXECUTABLE) + +endif diff --git a/ion/ion.c b/libion_ti/ion.c index 54579db..01459ab 100644 --- a/ion/ion.c +++ b/libion_ti/ion.c @@ -27,8 +27,6 @@ #define LOG_TAG "ion" #include <cutils/log.h> -#include "linux_ion.h" -#include "omap_ion.h" #include "ion.h" int ion_open() @@ -81,6 +79,8 @@ int ion_alloc_tiler(int fd, size_t w, size_t h, int fmt, unsigned int flags, .h = h, .fmt = fmt, .flags = flags, + .out_align = PAGE_SIZE, + .token = 0, }; struct ion_custom_data custom_data = { @@ -154,3 +154,48 @@ int ion_import(int fd, int share_fd, struct ion_handle **handle) *handle = data.handle; return ret; } + +int ion_map_cacheable(int fd, struct ion_handle *handle, size_t length, int prot, + int flags, off_t offset, unsigned char **ptr, int *map_fd) +{ + struct ion_fd_data data = { + .handle = handle, + .cacheable = 1, + }; + int ret = ion_ioctl(fd, ION_IOC_MAP, &data); + if (ret < 0) + return ret; + *map_fd = data.fd; + if (*map_fd < 0) { + ALOGE("map ioctl returned negative fd\n"); + return -EINVAL; + } + *ptr = mmap(NULL, length, prot, flags, *map_fd, offset); + if (*ptr == MAP_FAILED) { + ALOGE("mmap failed: %s\n", strerror(errno)); + return -errno; + } + return ret; +} + +int ion_flush_cached(int fd, struct ion_handle *handle, size_t length, + unsigned char *ptr) +{ + struct ion_cached_user_buf_data data = { + .handle = handle, + .vaddr = (unsigned long)ptr, + .size = length, + }; + return ion_ioctl(fd, ION_IOC_FLUSH_CACHED, &data); +} + +int ion_inval_cached(int fd, struct ion_handle *handle, size_t length, + unsigned char *ptr) +{ + struct ion_cached_user_buf_data data = { + .handle = handle, + .vaddr = (unsigned long)ptr, + .size = length, + }; + return ion_ioctl(fd, ION_IOC_INVAL_CACHED, &data); +} diff --git a/ion/ion.h b/libion_ti/ion.h index c0d9476..05fe1ec 100644 --- a/ion/ion.h +++ b/libion_ti/ion.h @@ -18,9 +18,14 @@ * limitations under the License. */ +#ifndef __TI_ION_H +#define __TI_ION_H + #include "linux_ion.h" #include "omap_ion.h" +__BEGIN_DECLS + int ion_open(); int ion_close(int fd); int ion_alloc(int fd, size_t len, size_t align, unsigned int flags, @@ -32,4 +37,13 @@ int ion_map(int fd, struct ion_handle *handle, size_t length, int prot, int flags, off_t offset, unsigned char **ptr, int *map_fd); int ion_share(int fd, struct ion_handle *handle, int *share_fd); int ion_import(int fd, int share_fd, struct ion_handle **handle); +int ion_map_cacheable(int fd, struct ion_handle *handle, size_t length, + int prot, int flags, off_t offset, unsigned char **ptr, int *map_fd); +int ion_flush_cached(int fd, struct ion_handle *handle, size_t length, + unsigned char *ptr); +int ion_inval_cached(int fd, struct ion_handle *handle, size_t length, + unsigned char *ptr); + +__END_DECLS +#endif /* __TI_ION_H */ diff --git a/libion_ti/ion_test.c b/libion_ti/ion_test.c new file mode 100644 index 0000000..ae7dead --- /dev/null +++ b/libion_ti/ion_test.c @@ -0,0 +1,319 @@ +#include <errno.h> +#include <fcntl.h> +#include <getopt.h> +#include <string.h> +#include <stdlib.h> +#include <stdio.h> +#include <sys/mman.h> +#include <sys/ioctl.h> +#include <sys/socket.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <unistd.h> + +#include "ion.h" + +size_t len = 1024*1024, align = 0; +int prot = PROT_READ | PROT_WRITE; +int map_flags = MAP_SHARED; +int alloc_flags = 0; +int test = -1; +size_t width = 1024*1024, height = 1024*1024; +int fmt = TILER_PIXEL_FMT_32BIT; +int tiler_test = 0; +size_t stride; + +int _ion_alloc_test(int *fd, struct ion_handle **handle) +{ + int ret; + + *fd = ion_open(); + if (*fd < 0) + return *fd; + + if (tiler_test) + ret = ion_alloc_tiler(*fd, width, height, fmt, alloc_flags, + handle, &stride); + else + ret = ion_alloc(*fd, len, align, alloc_flags, handle); + + if (ret) + printf("%s failed: %s\n", __func__, strerror(ret)); + return ret; +} + +void ion_alloc_test() +{ + int fd, ret; + struct ion_handle *handle; + + if(_ion_alloc_test(&fd, &handle)) + return; + + ret = ion_free(fd, handle); + if (ret) { + printf("%s failed: %s %p\n", __func__, strerror(ret), handle); + return; + } + ion_close(fd); + printf("ion alloc test: passed\n"); +} + +void _ion_tiler_map_test(unsigned char *ptr) +{ + size_t row, col; + + for (row = 0; row < height; row++) + for (col = 0; col < width; col++) { + int i = (row * stride) + col; + ptr[i] = (unsigned char)i; + } + for (row = 0; row < height; row++) + for (col = 0; col < width; col++) { + int i = (row * stride) + col; + if (ptr[i] != (unsigned char)i) + printf("%s failed wrote %d read %d from mapped " + "memory\n", __func__, i, ptr[i]); + } +} + + +void ion_map_test() +{ + int fd, map_fd, ret; + size_t i; + struct ion_handle *handle; + unsigned char *ptr; + + if(_ion_alloc_test(&fd, &handle)) + return; + + if (tiler_test) + len = height * stride; + ret = ion_map(fd, handle, len, prot, map_flags, 0, &ptr, &map_fd); + if (ret) + return; + + if (tiler_test) + _ion_tiler_map_test(ptr); + else { + for (i = 0; i < len; i++) { + ptr[i] = (unsigned char)i; + } + for (i = 0; i < len; i++) + if (ptr[i] != (unsigned char)i) + printf("%s failed wrote %d read %d from mapped " + "memory\n", __func__, i, ptr[i]); + } + /* clean up properly */ + ret = ion_free(fd, handle); + ion_close(fd); + munmap(ptr, len); + close(map_fd); + + _ion_alloc_test(&fd, &handle); + close(fd); + +#if 0 + munmap(ptr, len); + close(map_fd); + ion_close(fd); + + _ion_alloc_test(len, align, flags, &fd, &handle); + close(map_fd); + ret = ion_map(fd, handle, len, prot, flags, 0, &ptr, &map_fd); + /* don't clean up */ +#endif +} + +void ion_share_test() + +{ + struct ion_handle *handle; + int sd[2]; + int num_fd = 1; + struct iovec count_vec = { + .iov_base = &num_fd, + .iov_len = sizeof num_fd, + }; + char buf[CMSG_SPACE(sizeof(int))]; + socketpair(AF_UNIX, SOCK_STREAM, 0, sd); + if (fork()) { + struct msghdr msg = { + .msg_control = buf, + .msg_controllen = sizeof buf, + .msg_iov = &count_vec, + .msg_iovlen = 1, + }; + + struct cmsghdr *cmsg; + int fd, share_fd, ret; + char *ptr; + /* parent */ + if(_ion_alloc_test(&fd, &handle)) + return; + ret = ion_share(fd, handle, &share_fd); + if (ret) + printf("share failed %s\n", strerror(errno)); + ptr = mmap(NULL, len, prot, map_flags, share_fd, 0); + if (ptr == MAP_FAILED) { + return; + } + strcpy(ptr, "master"); + cmsg = CMSG_FIRSTHDR(&msg); + cmsg->cmsg_level = SOL_SOCKET; + cmsg->cmsg_type = SCM_RIGHTS; + cmsg->cmsg_len = CMSG_LEN(sizeof(int)); + *(int *)CMSG_DATA(cmsg) = share_fd; + /* send the fd */ + printf("master? [%10s] should be [master]\n", ptr); + printf("master sending msg 1\n"); + sendmsg(sd[0], &msg, 0); + if (recvmsg(sd[0], &msg, 0) < 0) + perror("master recv msg 2"); + printf("master? [%10s] should be [child]\n", ptr); + + /* send ping */ + sendmsg(sd[0], &msg, 0); + printf("master->master? [%10s]\n", ptr); + if (recvmsg(sd[0], &msg, 0) < 0) + perror("master recv 1"); + } else { + struct msghdr msg; + struct cmsghdr *cmsg; + char* ptr; + int fd, recv_fd; + char* child_buf[100]; + /* child */ + struct iovec count_vec = { + .iov_base = child_buf, + .iov_len = sizeof child_buf, + }; + + struct msghdr child_msg = { + .msg_control = buf, + .msg_controllen = sizeof buf, + .msg_iov = &count_vec, + .msg_iovlen = 1, + }; + + if (recvmsg(sd[1], &child_msg, 0) < 0) + perror("child recv msg 1"); + cmsg = CMSG_FIRSTHDR(&child_msg); + if (cmsg == NULL) { + printf("no cmsg rcvd in child"); + return; + } + recv_fd = *(int*)CMSG_DATA(cmsg); + if (recv_fd < 0) { + printf("could not get recv_fd from socket"); + return; + } + printf("child %d\n", recv_fd); + fd = ion_open(); + ptr = mmap(NULL, len, prot, map_flags, recv_fd, 0); + if (ptr == MAP_FAILED) { + return; + } + printf("child? [%10s] should be [master]\n", ptr); + strcpy(ptr, "child"); + printf("child sending msg 2\n"); + sendmsg(sd[1], &child_msg, 0); + } +} + +int main(int argc, char* argv[]) { + int c; + enum tests { + ALLOC_TEST = 0, MAP_TEST, SHARE_TEST, + }; + + while (1) { + static struct option opts[] = { + {"alloc", no_argument, 0, 'a'}, + {"alloc_flags", required_argument, 0, 'f'}, + {"map", no_argument, 0, 'm'}, + {"share", no_argument, 0, 's'}, + {"len", required_argument, 0, 'l'}, + {"align", required_argument, 0, 'g'}, + {"map_flags", required_argument, 0, 'z'}, + {"prot", required_argument, 0, 'p'}, + {"alloc_tiler", no_argument, 0, 't'}, + {"width", required_argument, 0, 'w'}, + {"height", required_argument, 0, 'h'}, + {"fmt", required_argument, 0, 'r'}, + }; + int i = 0; + c = getopt_long(argc, argv, "af:h:l:mr:stw:", opts, &i); + if (c == -1) + break; + + switch (c) { + case 'l': + len = atol(optarg); + break; + case 'g': + align = atol(optarg); + break; + case 'z': + map_flags = 0; + map_flags |= strstr(optarg, "PROT_EXEC") ? + PROT_EXEC : 0; + map_flags |= strstr(optarg, "PROT_READ") ? + PROT_READ: 0; + map_flags |= strstr(optarg, "PROT_WRITE") ? + PROT_WRITE: 0; + map_flags |= strstr(optarg, "PROT_NONE") ? + PROT_NONE: 0; + break; + case 'p': + prot = 0; + prot |= strstr(optarg, "MAP_PRIVATE") ? + MAP_PRIVATE : 0; + prot |= strstr(optarg, "MAP_SHARED") ? + MAP_PRIVATE : 0; + break; + case 'f': + alloc_flags = atol(optarg); + break; + case 'a': + test = ALLOC_TEST; + break; + case 'm': + test = MAP_TEST; + break; + case 'r': + fmt = atol(optarg); + break; + case 's': + test = SHARE_TEST; + break; + case 'w': + width = atol(optarg); + break; + case 'h': + height = atol(optarg); + break; + case 't': + tiler_test = 1; + break; + } + } + printf("test %d, len %u, width %u, height %u fmt %u align %u, " + "map_flags %d, prot %d, alloc_flags %d\n", test, len, width, + height, fmt, align, map_flags, prot, alloc_flags); + switch (test) { + case ALLOC_TEST: + ion_alloc_test(); + break; + case MAP_TEST: + ion_map_test(); + break; + case SHARE_TEST: + ion_share_test(); + break; + default: + printf("must specify a test (alloc, map, share)\n"); + } + return 0; +} diff --git a/libion_ti/ion_test_2.c b/libion_ti/ion_test_2.c new file mode 100644 index 0000000..5c19102 --- /dev/null +++ b/libion_ti/ion_test_2.c @@ -0,0 +1,479 @@ +/* + * Copyright (C) Texas Instruments - http://www.ti.com/ + * + * 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. + */ + +/* + * Test case to test ION Memory Allocator module + */ + +#include <errno.h> +#include <fcntl.h> +#include <getopt.h> +#include <string.h> +#include <stdlib.h> +#include <stdio.h> +#include <sys/mman.h> +#include <sys/ioctl.h> +#include <sys/socket.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <unistd.h> + +#include "ion.h" + +size_t len = 1024*1024, align = 0; +int prot = PROT_READ | PROT_WRITE; +int map_flags = MAP_SHARED; +int alloc_flags = 0; +int test = -1; +size_t width = 1024*1024, height = 1024*1024; +int fmt = TILER_PIXEL_FMT_32BIT; +int tiler_test = 0; +size_t stride; + +int _ion_alloc_test(int fd, struct ion_handle **handle) +{ + int ret; + + if (tiler_test) + ret = ion_alloc_tiler(fd, width, height, fmt, alloc_flags, + handle, &stride); + else + ret = ion_alloc(fd, len, align, alloc_flags, handle); + + if (ret) + printf("%s() failed: %s\n", __func__, strerror(ret)); + return ret; +} + +int ion_alloc_test(int count) +{ + int fd, ret = 0, i, count_alloc; + struct ion_handle **handle; + + fd = ion_open(); + if (fd < 0) { + printf("%s(): FAILED to open ion device\n", __func__); + return -1; + } + + handle = (struct ion_handle **)malloc(count * sizeof(struct ion_handle *)); + if(handle == NULL) { + printf("%s() : FAILED to allocate memory for ion_handles\n", __func__); + return -ENOMEM; + } + + /* Allocate ion_handles */ + count_alloc = count; + for(i = 0; i < count; i++) { + ret = _ion_alloc_test(fd, &(handle[i])); + printf("%s(): Alloc handle[%d]=%p\n", __func__, i, handle[i]); + if(ret || ((int)handle[i] == -ENOMEM)) { + printf("%s(): Alloc handle[%d]=%p FAILED, err:%s\n", + __func__, i, handle[i], strerror(ret)); + count_alloc = i; + goto err_alloc; + } + } + + err_alloc: + /* Free ion_handles */ + for (i = 0; i < count_alloc; i++) { + printf("%s(): Free handle[%d]=%p\n", __func__, i, handle[i]); + ret = ion_free(fd, handle[i]); + if (ret) { + printf("%s(): Free handle[%d]=%p FAILED, err:%s\n", + __func__, i, handle[i], strerror(ret)); + } + } + + ion_close(fd); + free(handle); + handle = NULL; + + if(ret || (count_alloc != count)) { + printf("\nion alloc test: FAILED\n\n"); + if(count_alloc != count) + ret = -ENOMEM; + } + else + printf("\nion alloc test: PASSED\n\n"); + + return ret; +} + +void _ion_tiler_map_test(unsigned char *ptr) +{ + size_t row, col; + + for (row = 0; row < height; row++) + for (col = 0; col < width; col++) { + int i = (row * stride) + col; + ptr[i] = (unsigned char)i; + } + for (row = 0; row < height; row++) + for (col = 0; col < width; col++) { + int i = (row * stride) + col; + if (ptr[i] != (unsigned char)i) + printf("%s(): FAILED, wrote %d read %d from mapped " + "memory\n", __func__, i, ptr[i]); + } +} + +void _ion_map_test(unsigned char *ptr) +{ + size_t i; + + for (i = 0; i < len; i++) { + ptr[i] = (unsigned char)i; + } + for (i = 0; i < len; i++) { + if (ptr[i] != (unsigned char)i) + printf("%s(): failed wrote %d read %d from mapped " + "memory\n", __func__, i, ptr[i]); + } +} + +int ion_map_test(int count) +{ + int fd, ret = 0, i, count_alloc, count_map; + struct ion_handle **handle; + unsigned char **ptr; + int *map_fd; + + fd = ion_open(); + if (fd < 0) { + printf("%s(): FAILED to open ion device\n", __func__); + return -1; + } + + handle = (struct ion_handle **)malloc(count * sizeof(struct ion_handle *)); + if(handle == NULL) { + printf("%s(): FAILED to allocate memory for ion_handles\n", __func__); + return -ENOMEM; + } + + count_alloc = count; + count_map = count; + + /* Allocate ion_handles */ + for(i = 0; i < count; i++) { + ret = _ion_alloc_test(fd, &(handle[i])); + printf("%s(): Alloc handle[%d]=%p\n", __func__, i, handle[i]); + if(ret || ((int)handle[i] == -ENOMEM)) { + printf("%s(): Alloc handle[%d]=%p FAILED, err:%s\n", + __func__, i, handle[i], strerror(ret)); + count_alloc = i; + goto err_alloc; + } + } + + /* Map ion_handles and validate */ + if (tiler_test) + len = height * stride; + + ptr = (unsigned char **)malloc(count * sizeof(unsigned char **)); + map_fd = (int *)malloc(count * sizeof(int *)); + + for(i = 0; i < count; i++) { + /* Map ion_handle on userside */ + ret = ion_map(fd, handle[i], len, prot, map_flags, 0, &(ptr[i]), &(map_fd[i])); + printf("%s(): Map handle[%d]=%p, map_fd=%d, ptr=%p\n", + __func__, i, handle[i], map_fd[i], ptr[i]); + if(ret) { + printf("%s Map handle[%d]=%p FAILED, err:%s\n", + __func__, i, handle[i], strerror(ret)); + count_map = i; + goto err_map; + } + + /* Validate mapping by writing the data and reading it back */ + if (tiler_test) + _ion_tiler_map_test(ptr[i]); + else + _ion_map_test(ptr[i]); + } + + /* clean up properly */ + err_map: + for(i = 0; i < count_map; i++) { + /* Unmap ion_handles */ + ret = munmap(ptr[i], len); + printf("%s(): Unmap handle[%d]=%p, map_fd=%d, ptr=%p\n", + __func__, i, handle[i], map_fd[i], ptr[i]); + if(ret) { + printf("%s(): Unmap handle[%d]=%p FAILED, err:%s\n", + __func__, i, handle[i], strerror(ret)); + goto err_map; + } + /* Close fds */ + close(map_fd[i]); + } + free(map_fd); + free(ptr); + + err_alloc: + /* Free ion_handles */ + for (i = 0; i < count_alloc; i++) { + printf("%s(): Free handle[%d]=%p\n", __func__, i, handle[i]); + ret = ion_free(fd, handle[i]); + if (ret) { + printf("%s(): Free handle[%d]=%p FAILED, err:%s\n", + __func__, i, handle[i], strerror(ret)); + } + } + + ion_close(fd); + free(handle); + handle = NULL; + + if(ret || (count_alloc != count) || (count_map != count)) + { + printf("\nion map test: FAILED\n\n"); + if((count_alloc != count) || (count_map != count)) + ret = -ENOMEM; + } else + printf("\nion map test: PASSED\n"); + + return ret; +} + +/** + * Go on allocating buffers of specified size & type, untill the allocation fails. + * Then free 10 buffers and allocate 10 buffers again. + */ +int ion_alloc_fail_alloc_test() +{ + int fd, ret = 0, i; + struct ion_handle **handle; + const int COUNT_ALLOC_MAX = 200; + const int COUNT_REALLOC_MAX = 10; + int count_alloc = COUNT_ALLOC_MAX, count_realloc = COUNT_ALLOC_MAX; + + fd = ion_open(); + if (fd < 0) { + printf("%s(): FAILED to open ion device\n", __func__); + return -1; + } + + handle = (struct ion_handle **)malloc(COUNT_ALLOC_MAX * sizeof(struct ion_handle *)); + if(handle == NULL) { + printf("%s(): FAILED to allocate memory for ion_handles\n", __func__); + return -ENOMEM; + } + + /* Allocate ion_handles as much as possible */ + for(i = 0; i < COUNT_ALLOC_MAX; i++) { + ret = _ion_alloc_test(fd, &(handle[i])); + printf("%s(): Alloc handle[%d]=%p\n", __func__, i, handle[i]); + if(ret || ((int)handle[i] == -ENOMEM)) { + printf("%s(): Alloc handle[%d]=%p FAILED, err:%s\n\n", + __func__, i, handle[i], strerror(ret)); + count_alloc = i; + break; + } + } + + /* Free COUNT_REALLOC_MAX ion_handles */ + for (i = count_alloc-1; i > (count_alloc-1 - COUNT_REALLOC_MAX); i--) { + printf("%s(): Free handle[%d]=%p\n", __func__, i, handle[i]); + ret = ion_free(fd, handle[i]); + if (ret) { + printf("%s(): Free handle[%d]=%p FAILED, err:%s\n\n", + __func__, i, handle[i], strerror(ret)); + } + } + + /* Again allocate COUNT_REALLOC_MAX ion_handles to test + that we are still able to allocate */ + for(i = (count_alloc - COUNT_REALLOC_MAX); i < count_alloc; i++) { + ret = _ion_alloc_test(fd, &(handle[i])); + printf("%s(): Alloc handle[%d]=%p\n", __func__, i, handle[i]); + if(ret || ((int)handle[i] == -ENOMEM)) { + printf("%s(): Alloc handle[%d]=%p FAILED, err:%s\n\n", + __func__, i, handle[i], strerror(ret)); + count_realloc = i; + goto err_alloc; + } + } + count_realloc = i; + + err_alloc: + /* Free all ion_handles */ + for (i = 0; i < count_alloc; i++) { + printf("%s(): Free handle[%d]=%p\n", __func__, i, handle[i]); + ret = ion_free(fd, handle[i]); + if (ret) { + printf("%s(): Free handle[%d]=%p FAILED, err:%s\n", + __func__, i, handle[i], strerror(ret)); + } + } + + ion_close(fd); + free(handle); + handle = NULL; + + printf("\ncount_alloc=%d, count_realloc=%d\n",count_alloc, count_realloc); + + if(ret || (count_alloc != count_realloc)) { + printf("\nion alloc->fail->alloc test: FAILED\n\n"); + if(count_alloc != COUNT_ALLOC_MAX) + ret = -ENOMEM; + } + else + printf("\nion alloc->fail->alloc test: PASSED\n\n"); + + return ret; +} + +int custom_test(int test_number) +{ + switch(test_number) { + case 1 : + return ion_alloc_fail_alloc_test(); + default : + printf("%s(): Invalid custom_test_number=%d\n", __func__, test_number); + return -EINVAL; + } +} + +int main(int argc, char* argv[]) { + int c, ret; + unsigned int count = 1, iteration = 1, j, custom_test_num = 1; + enum tests { + ALLOC_TEST = 0, MAP_TEST, CUSTOM_TEST, + }; + + while (1) { + static struct option opts[] = { + {"alloc", no_argument, 0, 'a'}, + {"alloc_flags", required_argument, 0, 'f'}, + {"map", no_argument, 0, 'm'}, + {"custom", required_argument, 0, 'c'}, + {"len", required_argument, 0, 'l'}, + {"align", required_argument, 0, 'g'}, + {"map_flags", required_argument, 0, 'z'}, + {"prot", required_argument, 0, 'p'}, + {"alloc_tiler", no_argument, 0, 't'}, + {"width", required_argument, 0, 'w'}, + {"height", required_argument, 0, 'h'}, + {"fmt", required_argument, 0, 'r'}, + {"count", required_argument, 0, 'n'}, + {"iteration", required_argument, 0, 'i'}, + }; + int i = 0; + c = getopt_long(argc, argv, "af:h:l:mr:stw:c:n:i:", opts, &i); + if (c == -1) + break; + + switch (c) { + case 'l': + len = atol(optarg); + break; + case 'g': + align = atol(optarg); + break; + case 'z': + map_flags = 0; + map_flags |= strstr(optarg, "PROT_EXEC") ? + PROT_EXEC : 0; + map_flags |= strstr(optarg, "PROT_READ") ? + PROT_READ: 0; + map_flags |= strstr(optarg, "PROT_WRITE") ? + PROT_WRITE: 0; + map_flags |= strstr(optarg, "PROT_NONE") ? + PROT_NONE: 0; + break; + case 'p': + prot = 0; + prot |= strstr(optarg, "MAP_PRIVATE") ? + MAP_PRIVATE : 0; + prot |= strstr(optarg, "MAP_SHARED") ? + MAP_PRIVATE : 0; + break; + case 'f': + alloc_flags = atol(optarg); + break; + case 'a': + test = ALLOC_TEST; + break; + case 'm': + test = MAP_TEST; + break; + case 'c': + test = CUSTOM_TEST; + printf("KALP : Case 'c'\n"); + custom_test_num = atol(optarg); + break; + case 'r': + fmt = atol(optarg); + break; + case 'w': + width = atol(optarg); + break; + case 'h': + height = atol(optarg); + break; + case 't': + tiler_test = 1; + break; + case 'n': + printf("KALP : Case 'n'\n"); + count = atol(optarg); + break; + case 'i': + printf("KALP : Case 'i'\n"); + iteration = atol(optarg); + break; + } + } + printf("test %d, len %u, width %u, height %u, fmt %u, align %u, count %d, " + "iteration %d, map_flags %d, prot %d, alloc_flags %d\n", test, len, width, + height, fmt, align, count, iteration, map_flags, prot, alloc_flags); + + switch (test) { + case ALLOC_TEST: + for(j = 0; j < iteration; j++) { + ret = ion_alloc_test(count); + if(ret) { + printf("\nion alloc test: FAILED at iteration-%d\n", j+1); + break; + } + } + break; + + case MAP_TEST: + for(j = 0; j < iteration; j++) { + ret = ion_map_test(count); + if(ret) { + printf("\nion map test: FAILED at iteration-%d\n", j+1); + break; + } + } + break; + + case CUSTOM_TEST: + ret = custom_test(custom_test_num); + if(ret) { + printf("\nion custom test #%d: FAILED\n", custom_test_num); + } + break; + + default: + printf("must specify a test (alloc, map, custom)\n"); + } + + return 0; +} diff --git a/ion/linux_ion.h b/libion_ti/linux_ion.h index b8715a3..300853a 100644 --- a/ion/linux_ion.h +++ b/libion_ti/linux_ion.h @@ -44,23 +44,33 @@ struct ion_allocation_data { struct ion_fd_data { struct ion_handle *handle; int fd; -}; + unsigned char cacheable; /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +}; struct ion_handle_data { struct ion_handle *handle; }; -struct ion_custom_data { /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +struct ion_custom_data { unsigned int cmd; unsigned long arg; }; -#define ION_IOC_MAGIC 'I' /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +struct ion_cached_user_buf_data { + struct ion_handle *handle; + unsigned long vaddr; + size_t size; +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +}; +#define ION_IOC_MAGIC 'I' #define ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, struct ion_allocation_data) #define ION_IOC_FREE _IOWR(ION_IOC_MAGIC, 1, struct ion_handle_data) +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ #define ION_IOC_MAP _IOWR(ION_IOC_MAGIC, 2, struct ion_fd_data) #define ION_IOC_SHARE _IOWR(ION_IOC_MAGIC, 4, struct ion_fd_data) -/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ #define ION_IOC_IMPORT _IOWR(ION_IOC_MAGIC, 5, int) #define ION_IOC_CUSTOM _IOWR(ION_IOC_MAGIC, 6, struct ion_custom_data) +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ +#define ION_IOC_FLUSH_CACHED _IOWR(ION_IOC_MAGIC, 7, struct ion_cached_user_buf_data) +#define ION_IOC_INVAL_CACHED _IOWR(ION_IOC_MAGIC, 8, struct ion_cached_user_buf_data) #endif diff --git a/ion/omap_ion.h b/libion_ti/omap_ion.h index 65af914..b8a6228 100644 --- a/ion/omap_ion.h +++ b/libion_ti/omap_ion.h @@ -29,31 +29,33 @@ struct omap_ion_tiler_alloc_data { struct ion_handle *handle; size_t stride; size_t offset; -}; + unsigned int out_align; /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ + unsigned int token; +}; enum { OMAP_ION_HEAP_TYPE_TILER = ION_HEAP_TYPE_CUSTOM + 1, +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ }; #define OMAP_ION_HEAP_TILER_MASK (1 << OMAP_ION_HEAP_TYPE_TILER) -/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ enum { OMAP_ION_TILER_ALLOC, +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ }; enum { -/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ TILER_PIXEL_FMT_MIN = 0, TILER_PIXEL_FMT_8BIT = 0, +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ TILER_PIXEL_FMT_16BIT = 1, TILER_PIXEL_FMT_32BIT = 2, -/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ TILER_PIXEL_FMT_PAGE = 3, TILER_PIXEL_FMT_MAX = 3 +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ }; enum { -/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ OMAP_ION_HEAP_LARGE_SURFACES, OMAP_ION_HEAP_TILER, +/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ OMAP_ION_HEAP_SECURE_INPUT, }; -/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ #endif |