MALI: rockchip: upgrade utgard DDK to r6p0-01rel0
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / mali400 / mali / linux / mali_ukk_profiling.c
index d77ca2517dd2b630fee757b2155f8e4ec19de4c3..e84544dee07d9c26fb25784cfd3c95b502adbd34 100755 (executable)
@@ -1,11 +1,11 @@
 /*
- * This confidential and proprietary software may be used only as
- * authorised by a licensing agreement from ARM Limited
- * (C) COPYRIGHT 2010-2013 ARM Limited
- * ALL RIGHTS RESERVED
- * The entire notice above must be reproduced on all authorised
- * copies and copies may only be made to the extent permitted
- * by a licensing agreement from ARM Limited.
+ * Copyright (C) 2010-2015 ARM Limited. All rights reserved.
+ * 
+ * This program is free software and is provided to you under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
+ * 
+ * A copy of the licence is included with the program, and can also be obtained from Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
 #include <linux/fs.h>       /* file system operations */
 #include <asm/uaccess.h>    /* user space access */
 #include "mali_session.h"
 #include "mali_ukk_wrappers.h"
 
-int profiling_start_wrapper(struct mali_session_data *session_data, _mali_uk_profiling_start_s __user *uargs)
+int profiling_add_event_wrapper(struct mali_session_data *session_data, _mali_uk_profiling_add_event_s __user *uargs)
 {
-       _mali_uk_profiling_start_s kargs;
+       _mali_uk_profiling_add_event_s kargs;
        _mali_osk_errcode_t err;
 
        MALI_CHECK_NON_NULL(uargs, -EINVAL);
 
-       if (0 != copy_from_user(&kargs, uargs, sizeof(_mali_uk_profiling_start_s))) {
+       if (0 != copy_from_user(&kargs, uargs, sizeof(_mali_uk_profiling_add_event_s))) {
                return -EFAULT;
        }
 
-       kargs.ctx = session_data;
-       err = _mali_ukk_profiling_start(&kargs);
+       kargs.ctx = (uintptr_t)session_data;
+       err = _mali_ukk_profiling_add_event(&kargs);
        if (_MALI_OSK_ERR_OK != err) {
                return map_errcode(err);
        }
 
-       if (0 != put_user(kargs.limit, &uargs->limit)) {
-               return -EFAULT;
-       }
-
        return 0;
 }
 
-int profiling_add_event_wrapper(struct mali_session_data *session_data, _mali_uk_profiling_add_event_s __user *uargs)
+int profiling_report_sw_counters_wrapper(struct mali_session_data *session_data, _mali_uk_sw_counters_report_s __user *uargs)
 {
-       _mali_uk_profiling_add_event_s kargs;
+       _mali_uk_sw_counters_report_s kargs;
        _mali_osk_errcode_t err;
+       u32 *counter_buffer;
+       u32 __user *counters;
 
        MALI_CHECK_NON_NULL(uargs, -EINVAL);
 
-       if (0 != copy_from_user(&kargs, uargs, sizeof(_mali_uk_profiling_add_event_s))) {
+       if (0 != copy_from_user(&kargs, uargs, sizeof(_mali_uk_sw_counters_report_s))) {
                return -EFAULT;
        }
 
-       kargs.ctx = session_data;
-       err = _mali_ukk_profiling_add_event(&kargs);
-       if (_MALI_OSK_ERR_OK != err) {
-               return map_errcode(err);
+       /* make sure that kargs.num_counters is [at least somewhat] sane */
+       if (kargs.num_counters > 10000) {
+               MALI_DEBUG_PRINT(1, ("User space attempted to allocate too many counters.\n"));
+               return -EINVAL;
        }
 
-       return 0;
-}
+       counter_buffer = (u32 *)kmalloc(sizeof(u32) * kargs.num_counters, GFP_KERNEL);
+       if (NULL == counter_buffer) {
+               return -ENOMEM;
+       }
 
-int profiling_stop_wrapper(struct mali_session_data *session_data, _mali_uk_profiling_stop_s __user *uargs)
-{
-       _mali_uk_profiling_stop_s kargs;
-       _mali_osk_errcode_t err;
+       counters = (u32 *)(uintptr_t)kargs.counters;
 
-       MALI_CHECK_NON_NULL(uargs, -EINVAL);
+       if (0 != copy_from_user(counter_buffer, counters, sizeof(u32) * kargs.num_counters)) {
+               kfree(counter_buffer);
+               return -EFAULT;
+       }
+
+       kargs.ctx = (uintptr_t)session_data;
+       kargs.counters = (uintptr_t)counter_buffer;
+
+       err = _mali_ukk_sw_counters_report(&kargs);
+
+       kfree(counter_buffer);
 
-       kargs.ctx = session_data;
-       err = _mali_ukk_profiling_stop(&kargs);
        if (_MALI_OSK_ERR_OK != err) {
                return map_errcode(err);
        }
 
-       if (0 != put_user(kargs.count, &uargs->count)) {
-               return -EFAULT;
-       }
-
        return 0;
 }
 
-int profiling_get_event_wrapper(struct mali_session_data *session_data, _mali_uk_profiling_get_event_s __user *uargs)
+int profiling_get_stream_fd_wrapper(struct mali_session_data *session_data, _mali_uk_profiling_stream_fd_get_s __user *uargs)
 {
-       _mali_uk_profiling_get_event_s kargs;
+       _mali_uk_profiling_stream_fd_get_s kargs;
        _mali_osk_errcode_t err;
 
        MALI_CHECK_NON_NULL(uargs, -EINVAL);
 
-       if (0 != get_user(kargs.index, &uargs->index)) {
+       if (0 != copy_from_user(&kargs, uargs, sizeof(_mali_uk_profiling_stream_fd_get_s))) {
                return -EFAULT;
        }
 
-       kargs.ctx = session_data;
-
-       err = _mali_ukk_profiling_get_event(&kargs);
+       kargs.ctx = (uintptr_t)session_data;
+       err = _mali_ukk_profiling_stream_fd_get(&kargs);
        if (_MALI_OSK_ERR_OK != err) {
                return map_errcode(err);
        }
 
-       kargs.ctx = NULL; /* prevent kernel address to be returned to user space */
-       if (0 != copy_to_user(uargs, &kargs, sizeof(_mali_uk_profiling_get_event_s))) {
+       if (0 != copy_to_user(uargs, &kargs, sizeof(_mali_uk_profiling_stream_fd_get_s))) {
                return -EFAULT;
        }
 
        return 0;
 }
 
-int profiling_clear_wrapper(struct mali_session_data *session_data, _mali_uk_profiling_clear_s __user *uargs)
+int profiling_control_set_wrapper(struct mali_session_data *session_data, _mali_uk_profiling_control_set_s __user *uargs)
 {
-       _mali_uk_profiling_clear_s kargs;
+       _mali_uk_profiling_control_set_s kargs;
        _mali_osk_errcode_t err;
+       u8 *kernel_control_data = NULL;
+       u8 *kernel_response_data = NULL;
 
        MALI_CHECK_NON_NULL(uargs, -EINVAL);
 
-       kargs.ctx = session_data;
-       err = _mali_ukk_profiling_clear(&kargs);
-       if (_MALI_OSK_ERR_OK != err) {
-               return map_errcode(err);
-       }
+       if (0 != get_user(kargs.control_packet_size, &uargs->control_packet_size)) return -EFAULT;
+       if (0 != get_user(kargs.response_packet_size, &uargs->response_packet_size)) return -EFAULT;
 
-       return 0;
-}
+       kargs.ctx = (uintptr_t)session_data;
 
-int profiling_report_sw_counters_wrapper(struct mali_session_data *session_data, _mali_uk_sw_counters_report_s __user *uargs)
-{
-       _mali_uk_sw_counters_report_s kargs;
-       _mali_osk_errcode_t err;
-       u32 *counter_buffer;
+       if (0 !=  kargs.control_packet_size) {
 
-       MALI_CHECK_NON_NULL(uargs, -EINVAL);
+               kernel_control_data = _mali_osk_calloc(1, kargs.control_packet_size);
+               if (NULL == kernel_control_data) {
+                       return -ENOMEM;
+               }
 
-       if (0 != copy_from_user(&kargs, uargs, sizeof(_mali_uk_sw_counters_report_s))) {
-               return -EFAULT;
-       }
+               MALI_DEBUG_ASSERT(0 != kargs.response_packet_size);
 
-       /* make sure that kargs.num_counters is [at least somewhat] sane */
-       if (kargs.num_counters > 10000) {
-               MALI_DEBUG_PRINT(1, ("User space attempted to allocate too many counters.\n"));
-               return -EINVAL;
-       }
+               kernel_response_data = _mali_osk_calloc(1, kargs.response_packet_size);
+               if (NULL == kernel_response_data) {
+                       _mali_osk_free(kernel_control_data);
+                       return -ENOMEM;
+               }
 
-       counter_buffer = (u32*)kmalloc(sizeof(u32) * kargs.num_counters, GFP_KERNEL);
-       if (NULL == counter_buffer) {
-               return -ENOMEM;
-       }
+               kargs.control_packet_data = (uintptr_t)kernel_control_data;
+               kargs.response_packet_data = (uintptr_t)kernel_response_data;
 
-       if (0 != copy_from_user(counter_buffer, kargs.counters, sizeof(u32) * kargs.num_counters)) {
-               kfree(counter_buffer);
-               return -EFAULT;
-       }
+               if (0 != copy_from_user((void *)(uintptr_t)kernel_control_data, (void *)(uintptr_t)uargs->control_packet_data, kargs.control_packet_size)) {
+                       _mali_osk_free(kernel_control_data);
+                       _mali_osk_free(kernel_response_data);
+                       return -EFAULT;
+               }
 
-       kargs.ctx = session_data;
-       kargs.counters = counter_buffer;
+               err = _mali_ukk_profiling_control_set(&kargs);
+               if (_MALI_OSK_ERR_OK != err) {
+                       _mali_osk_free(kernel_control_data);
+                       _mali_osk_free(kernel_response_data);
+                       return map_errcode(err);
+               }
 
-       err = _mali_ukk_sw_counters_report(&kargs);
+               if (0 != kargs.response_packet_size && 0 != copy_to_user(((void *)(uintptr_t)uargs->response_packet_data), ((void *)(uintptr_t)kargs.response_packet_data), kargs.response_packet_size)) {
+                       _mali_osk_free(kernel_control_data);
+                       _mali_osk_free(kernel_response_data);
+                       return -EFAULT;
+               }
 
-       kfree(counter_buffer);
+               if (0 != put_user(kargs.response_packet_size, &uargs->response_packet_size)) {
+                       _mali_osk_free(kernel_control_data);
+                       _mali_osk_free(kernel_response_data);
+                       return -EFAULT;
+               }
 
-       if (_MALI_OSK_ERR_OK != err) {
-               return map_errcode(err);
-       }
+               _mali_osk_free(kernel_control_data);
+               _mali_osk_free(kernel_response_data);
+       } else {
 
+               err = _mali_ukk_profiling_control_set(&kargs);
+               if (_MALI_OSK_ERR_OK != err) {
+                       return map_errcode(err);
+               }
+
+       }
        return 0;
 }
-
-