2 * Copyright (C) 2010-2015 ARM Limited. All rights reserved.
4 * This program is free software and is provided to you under the terms of the GNU General Public License version 2
5 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
7 * A copy of the licence is included with the program, and can also be obtained from Free Software
8 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
10 #include <linux/fs.h> /* file system operations */
11 #include <asm/uaccess.h> /* user space access */
12 #include <linux/slab.h>
16 #include "mali_kernel_common.h"
17 #include "mali_session.h"
18 #include "mali_ukk_wrappers.h"
20 int profiling_add_event_wrapper(struct mali_session_data *session_data, _mali_uk_profiling_add_event_s __user *uargs)
22 _mali_uk_profiling_add_event_s kargs;
23 _mali_osk_errcode_t err;
25 MALI_CHECK_NON_NULL(uargs, -EINVAL);
27 if (0 != copy_from_user(&kargs, uargs, sizeof(_mali_uk_profiling_add_event_s))) {
31 kargs.ctx = (uintptr_t)session_data;
32 err = _mali_ukk_profiling_add_event(&kargs);
33 if (_MALI_OSK_ERR_OK != err) {
34 return map_errcode(err);
40 int profiling_report_sw_counters_wrapper(struct mali_session_data *session_data, _mali_uk_sw_counters_report_s __user *uargs)
42 _mali_uk_sw_counters_report_s kargs;
43 _mali_osk_errcode_t err;
47 MALI_CHECK_NON_NULL(uargs, -EINVAL);
49 if (0 != copy_from_user(&kargs, uargs, sizeof(_mali_uk_sw_counters_report_s))) {
53 /* make sure that kargs.num_counters is [at least somewhat] sane */
54 if (kargs.num_counters > 10000) {
55 MALI_DEBUG_PRINT(1, ("User space attempted to allocate too many counters.\n"));
59 counter_buffer = (u32 *)kmalloc(sizeof(u32) * kargs.num_counters, GFP_KERNEL);
60 if (NULL == counter_buffer) {
64 counters = (u32 *)(uintptr_t)kargs.counters;
66 if (0 != copy_from_user(counter_buffer, counters, sizeof(u32) * kargs.num_counters)) {
67 kfree(counter_buffer);
71 kargs.ctx = (uintptr_t)session_data;
72 kargs.counters = (uintptr_t)counter_buffer;
74 err = _mali_ukk_sw_counters_report(&kargs);
76 kfree(counter_buffer);
78 if (_MALI_OSK_ERR_OK != err) {
79 return map_errcode(err);
85 int profiling_get_stream_fd_wrapper(struct mali_session_data *session_data, _mali_uk_profiling_stream_fd_get_s __user *uargs)
87 _mali_uk_profiling_stream_fd_get_s kargs;
88 _mali_osk_errcode_t err;
90 MALI_CHECK_NON_NULL(uargs, -EINVAL);
92 if (0 != copy_from_user(&kargs, uargs, sizeof(_mali_uk_profiling_stream_fd_get_s))) {
96 kargs.ctx = (uintptr_t)session_data;
97 err = _mali_ukk_profiling_stream_fd_get(&kargs);
98 if (_MALI_OSK_ERR_OK != err) {
99 return map_errcode(err);
102 if (0 != copy_to_user(uargs, &kargs, sizeof(_mali_uk_profiling_stream_fd_get_s))) {
109 int profiling_control_set_wrapper(struct mali_session_data *session_data, _mali_uk_profiling_control_set_s __user *uargs)
111 _mali_uk_profiling_control_set_s kargs;
112 _mali_osk_errcode_t err;
113 u8 *kernel_control_data = NULL;
114 u8 *kernel_response_data = NULL;
116 MALI_CHECK_NON_NULL(uargs, -EINVAL);
118 if (0 != get_user(kargs.control_packet_size, &uargs->control_packet_size)) return -EFAULT;
119 if (0 != get_user(kargs.response_packet_size, &uargs->response_packet_size)) return -EFAULT;
121 kargs.ctx = (uintptr_t)session_data;
123 if (0 != kargs.control_packet_size) {
125 kernel_control_data = _mali_osk_calloc(1, kargs.control_packet_size);
126 if (NULL == kernel_control_data) {
130 MALI_DEBUG_ASSERT(0 != kargs.response_packet_size);
132 kernel_response_data = _mali_osk_calloc(1, kargs.response_packet_size);
133 if (NULL == kernel_response_data) {
134 _mali_osk_free(kernel_control_data);
138 kargs.control_packet_data = (uintptr_t)kernel_control_data;
139 kargs.response_packet_data = (uintptr_t)kernel_response_data;
141 if (0 != copy_from_user((void *)(uintptr_t)kernel_control_data, (void *)(uintptr_t)uargs->control_packet_data, kargs.control_packet_size)) {
142 _mali_osk_free(kernel_control_data);
143 _mali_osk_free(kernel_response_data);
147 err = _mali_ukk_profiling_control_set(&kargs);
148 if (_MALI_OSK_ERR_OK != err) {
149 _mali_osk_free(kernel_control_data);
150 _mali_osk_free(kernel_response_data);
151 return map_errcode(err);
154 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)) {
155 _mali_osk_free(kernel_control_data);
156 _mali_osk_free(kernel_response_data);
160 if (0 != put_user(kargs.response_packet_size, &uargs->response_packet_size)) {
161 _mali_osk_free(kernel_control_data);
162 _mali_osk_free(kernel_response_data);
166 _mali_osk_free(kernel_control_data);
167 _mali_osk_free(kernel_response_data);
170 err = _mali_ukk_profiling_control_set(&kargs);
171 if (_MALI_OSK_ERR_OK != err) {
172 return map_errcode(err);