blob: ce72feb239af6a865f73487972d08c0c3999464d [file] [log] [blame]
From cb5fc70e9fa02e8dc4851c095eeee4a2c9e27be8 Mon Sep 17 00:00:00 2001
From: Yong Wu <yong.wu@mediatek.com>
Date: Tue, 9 Jan 2018 12:18:21 +0800
Subject: [PATCH 2/2] libion: Add MediaTek ION special heap and command
Add Mediatek ion heap and command.
ION_HEAP_TYPE_MULTIMEDIA: mm heap which hook the iommu drivers.
Also, we add a custom ioctl to get iova for the userspace buffer.
Example code about how to use this custom ioctl:
====================
struct ion_custom_data custom_data;
struct ion_sys_data sys_data = {0};
int ret;
sys_data.sys_cmd = ION_SYS_GET_PHYS;
sys_data.get_phys_param.handle = ion_handle;
/* ion handle in userspace */
custom_data.cmd = ION_CMD_SYSTEM;
custom_data.arg = (unsigned long) &sys_data;
ret = ioctl(fd, ION_IOC_CUSTOM, &custom_data);
if (ret < 0) {
printf("ion_custom_ioctl %x failed with code %d: %s\n",
ION_IOC_CUSTOM, ret, strerror(errno));
return -errno;
}
/* Then you could get the iova in sys_data.get_phys_param.phy_addr */
/* In order to avoid change the original libion interface, we don't
enclose this to a new interface.*/
====================
And, Don't forget to "close" the shared fd.
Signed-off-by: Yong Wu <yong.wu@mediatek.com>
---
libion/kernel-headers/linux/ion_mtk.h | 211 ++++++++++++++++++++++++++++++++++
1 file changed, 211 insertions(+)
create mode 100644 libion/kernel-headers/linux/ion_mtk.h
diff --git a/libion/kernel-headers/linux/ion_mtk.h b/libion/kernel-headers/linux/ion_mtk.h
new file mode 100644
index 0000000..e22c5ca
--- /dev/null
+++ b/libion/kernel-headers/linux/ion_mtk.h
@@ -0,0 +1,211 @@
+/*
+* Copyright (C) 2017 MediaTek.
+*
+* 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 _MTK_MM_ION_H
+#define _MTK_MM_ION_H
+
+enum mtk_ion_heap_type {
+ ION_HEAP_TYPE_DMA_MTK = 9,
+ ION_HEAP_TYPE_MULTIMEDIA = 10,
+ ION_HEAP_TYPE_FB = 11,
+ ION_HEAP_TYPE_MULTIMEDIA_FOR_CAMERA = 12,
+ ION_HEAP_TYPE_MULTIMEDIA_SEC = 13,
+ ION_HEAP_TYPE_MULTIMEDIA_MAP_MVA = 14,
+};
+
+#define ION_HEAP_DMA_MTK_MASK (1 << ION_HEAP_TYPE_DMA_MTK)
+#define ION_HEAP_MULTIMEDIA_MASK (1 << ION_HEAP_TYPE_MULTIMEDIA)
+#define ION_HEAP_FB_MASK (1 << ION_HEAP_TYPE_FB)
+#define ION_HEAP_CAMERA_MASK (1 << ION_HEAP_TYPE_MULTIMEDIA_FOR_CAMERA)
+#define ION_HEAP_MULTIMEDIA_SEC_MASK BIT (1 << ION_HEAP_TYPE_MULTIMEDIA_SEC)
+#define ION_HEAP_MULTIMEDIA_MAP_MVA_MASK (1 << ION_HEAP_TYPE_MULTIMEDIA_MAP_MVA)
+
+
+enum ION_CMDS {
+ ION_CMD_SYSTEM,
+ ION_CMD_MULTIMEDIA,
+ ION_CMD_MULTIMEDIA_SEC
+};
+
+enum ION_MM_CMDS {
+ ION_MM_CONFIG_BUFFER,
+ ION_MM_SET_DEBUG_INFO,
+ ION_MM_GET_DEBUG_INFO,
+ ION_MM_SET_SF_BUF_INFO,
+ ION_MM_GET_SF_BUF_INFO,
+ ION_MM_CONFIG_BUFFER_EXT
+};
+
+enum ION_SYS_CMDS {
+ ION_SYS_CACHE_SYNC,
+ ION_SYS_GET_PHYS,
+ ION_SYS_GET_CLIENT,
+ ION_SYS_SET_HANDLE_BACKTRACE,
+ ION_SYS_SET_CLIENT_NAME,
+ ION_SYS_DMA_OP,
+};
+
+enum ION_CACHE_SYNC_TYPE {
+ ION_CACHE_CLEAN_BY_RANGE,
+ ION_CACHE_INVALID_BY_RANGE,
+ ION_CACHE_FLUSH_BY_RANGE,
+ ION_CACHE_CLEAN_BY_RANGE_USE_VA,
+ ION_CACHE_INVALID_BY_RANGE_USE_VA,
+ ION_CACHE_FLUSH_BY_RANGE_USE_VA,
+ ION_CACHE_CLEAN_ALL,
+ ION_CACHE_INVALID_ALL,
+ ION_CACHE_FLUSH_ALL
+};
+
+enum ION_ERRORE {
+ ION_ERROR_CONFIG_LOCKED = 0x10000
+};
+
+/* mm or mm_sec heap flag which is do not conflist with ION_HEAP_FLAG_DEFER_FREE */
+#define ION_FLAG_MM_HEAP_INIT_ZERO (1 << 16)
+#define ION_FLAG_MM_HEAP_SEC_PA (1 << 18)
+
+#define ION_FLAG_GET_FIXED_PHYS 0x103
+
+struct ion_sys_cache_sync_param {
+ union {
+ ion_user_handle_t handle;
+ void *kernel_handle;
+ };
+ void *va;
+ unsigned int size;
+ enum ION_CACHE_SYNC_TYPE sync_type;
+};
+
+enum ION_DMA_TYPE {
+ ION_DMA_MAP_AREA,
+ ION_DMA_UNMAP_AREA,
+ ION_DMA_MAP_AREA_VA,
+ ION_DMA_UNMAP_AREA_VA,
+ ION_DMA_FLUSH_BY_RANGE,
+ ION_DMA_FLUSH_BY_RANGE_USE_VA,
+ ION_DMA_CACHE_FLUSH_ALL
+};
+
+enum ION_DMA_DIR {
+ ION_DMA_FROM_DEVICE,
+ ION_DMA_TO_DEVICE,
+ ION_DMA_BIDIRECTIONAL,
+};
+
+struct ion_dma_param {
+ union {
+ ion_user_handle_t handle;
+ void *kernel_handle;
+ };
+ void *va;
+ unsigned int size;
+ enum ION_DMA_TYPE dma_type;
+ enum ION_DMA_DIR dma_dir;
+};
+
+struct ion_sys_get_phys_param {
+ union {
+ ion_user_handle_t handle;
+ void *kernel_handle;
+ };
+ unsigned int phy_addr;
+ unsigned long len;
+};
+
+#define ION_MM_DBG_NAME_LEN 16
+#define ION_MM_SF_BUF_INFO_LEN 16
+
+struct ion_sys_client_name {
+ char name[ION_MM_DBG_NAME_LEN];
+};
+
+struct ion_sys_get_client_param {
+ unsigned int client;
+};
+
+#define BACKTRACE_SIZE 10
+
+struct ion_sys_record_param {
+ pid_t group_id;
+ pid_t pid;
+ unsigned int action;
+ unsigned int address_type;
+ unsigned int address;
+ unsigned int length;
+ unsigned int backtrace[BACKTRACE_SIZE];
+ unsigned int backtrace_num;
+ struct ion_handle *handle;
+ struct ion_client *client;
+ struct ion_buffer *buffer;
+ struct file *file;
+ int fd;
+};
+
+struct ion_sys_data {
+ enum ION_SYS_CMDS sys_cmd;
+ union {
+ struct ion_sys_cache_sync_param cache_sync_param;
+ struct ion_sys_get_phys_param get_phys_param;
+ struct ion_sys_get_client_param get_client_param;
+ struct ion_sys_client_name client_name_param;
+ struct ion_sys_record_param record_param;
+ struct ion_dma_param dma_param;
+ };
+};
+
+struct ion_mm_config_buffer_param {
+ union {
+ ion_user_handle_t handle;
+ void *kernel_handle;
+ };
+ int module_id;
+ unsigned int security;
+ unsigned int coherent;
+ unsigned int reserve_iova_start;
+ unsigned int reserve_iova_end;
+};
+
+struct ion_mm_buf_debug_info {
+ union {
+ ion_user_handle_t handle;
+ void *kernel_handle;
+ };
+ char dbg_name[ION_MM_DBG_NAME_LEN];
+ unsigned int value1;
+ unsigned int value2;
+ unsigned int value3;
+ unsigned int value4;
+};
+
+struct ion_mm_sf_buf_info {
+ union {
+ ion_user_handle_t handle;
+ void *kernel_handle;
+ };
+ unsigned int info[ION_MM_SF_BUF_INFO_LEN];
+};
+
+struct ion_mm_data {
+ enum ION_MM_CMDS mm_cmd;
+ union {
+ struct ion_mm_config_buffer_param config_buffer_param;
+ struct ion_mm_buf_debug_info buf_debug_info_param;
+ struct ion_mm_sf_buf_info sf_buf_info_param;
+ };
+};
+
+#endif
--
1.9.1