当前位置: 移动技术网 > 移动技术>移动开发>Android > 关于Android中ION的libion

关于Android中ION的libion

2018年12月08日  | 移动技术网移动技术  | 我要评论

在高通的opencl sdk中,其android.mk文件中,有判断当前kernel的版本,如果大于4.12,那么就使用libion.so,否则则使用ion kernle uapi

# tries to determine whether to use libion or ion kernel uapi
kernel_version = $(shell ls kernel | sed -n 's/msm-\([0-9]\+\)\.\([0-9]\+\)/-v x0=\1 -v x1=\2/p')
use_libion = $(shell awk $(kernel_version) -v y0="4" -v y1="12" 'begin {printf (x0>=y0 && x1>=y1?"true":"false") "\n"}')
ifeq ($(use_libion), true)
    $(info opencl sdk: using libion)

    opencl_sdk_cppflags := -wno-missing-braces -duses_libion

    opencl_sdk_shared_libs := libion libopencl

    opencl_sdk_common_includes := \
        $(local_path)/src \
        kernel/msm-4.14/ \
        $(target_out_intermediates)/include/adreno

else
    $(info opencl sdk: using ion uapi)

    opencl_sdk_cppflags := -wno-missing-braces

    opencl_sdk_shared_libs := libopencl

    opencl_sdk_common_includes := \
        $(local_path)/src \
        $(target_out_intermediates)/kernel_obj/usr/include \
        $(target_out_intermediates)/include/adreno

endif

从andriod p开始,kernel 4.14已推到aosp, libion在android p上已支持新的kernel ion接口,强烈建议 使用libion,而非直接使用ion ioctl调用.


在网上也找到关于如何使用ion的回答:

you can use libion.
you can find it in system /
core /libion

根据这个答案链接,编译libion的如下:

local_path:= $(call my-dir)

include $(clear_vars)
local_src_files := ion.c
local_module := libion
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 := iontest
local_module_tags := optional tests
local_shared_libraries := liblog
include $(build_executable)

这个mk文件使用,编译出来libion shared library ,以及使用,和编一个出来一个executable。ion_test.c里面有一个main()函数,主要是用来test alloc,map和share功能,也可以说是提供了使用demo;而ion.c则是libion的实现,其实也是对ion toctl的几个功能的封装而已。其实我们如果把这个ion.c和ion.h文件拿出来,那么我们也能编译出libion库了。头文件如下:

#ifndef __sys_core_ion_h
#define __sys_core_ion_h

#include <linux/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 heap_mask,
          unsigned int flags, struct ion_handle **handle);
int ion_alloc_fd(int fd, size_t len, size_t align, unsigned int heap_mask,
         unsigned int flags, int *handle_fd);
int ion_sync_fd(int fd, int handle_fd);
int ion_free(int fd, struct ion_handle *handle);
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);

__end_decls

#endif /* __sys_core_ion_h */

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网