2 * Copyright (C) 2011-2012 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_start_wrapper(struct mali_session_data *session_data, _mali_uk_profiling_start_s __user *uargs)
22 _mali_uk_profiling_start_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_start_s)))
32 kargs.ctx = session_data;
33 err = _mali_ukk_profiling_start(&kargs);
34 if (_MALI_OSK_ERR_OK != err)
36 return map_errcode(err);
39 if (0 != put_user(kargs.limit, &uargs->limit))
47 int profiling_add_event_wrapper(struct mali_session_data *session_data, _mali_uk_profiling_add_event_s __user *uargs)
49 _mali_uk_profiling_add_event_s kargs;
50 _mali_osk_errcode_t err;
52 MALI_CHECK_NON_NULL(uargs, -EINVAL);
54 if (0 != copy_from_user(&kargs, uargs, sizeof(_mali_uk_profiling_add_event_s)))
59 kargs.ctx = session_data;
60 err = _mali_ukk_profiling_add_event(&kargs);
61 if (_MALI_OSK_ERR_OK != err)
63 return map_errcode(err);
69 int profiling_stop_wrapper(struct mali_session_data *session_data, _mali_uk_profiling_stop_s __user *uargs)
71 _mali_uk_profiling_stop_s kargs;
72 _mali_osk_errcode_t err;
74 MALI_CHECK_NON_NULL(uargs, -EINVAL);
76 kargs.ctx = session_data;
77 err = _mali_ukk_profiling_stop(&kargs);
78 if (_MALI_OSK_ERR_OK != err)
80 return map_errcode(err);
83 if (0 != put_user(kargs.count, &uargs->count))
91 int profiling_get_event_wrapper(struct mali_session_data *session_data, _mali_uk_profiling_get_event_s __user *uargs)
93 _mali_uk_profiling_get_event_s kargs;
94 _mali_osk_errcode_t err;
96 MALI_CHECK_NON_NULL(uargs, -EINVAL);
98 if (0 != get_user(kargs.index, &uargs->index))
103 kargs.ctx = session_data;
105 err = _mali_ukk_profiling_get_event(&kargs);
106 if (_MALI_OSK_ERR_OK != err)
108 return map_errcode(err);
111 kargs.ctx = NULL; /* prevent kernel address to be returned to user space */
112 if (0 != copy_to_user(uargs, &kargs, sizeof(_mali_uk_profiling_get_event_s)))
120 int profiling_clear_wrapper(struct mali_session_data *session_data, _mali_uk_profiling_clear_s __user *uargs)
122 _mali_uk_profiling_clear_s kargs;
123 _mali_osk_errcode_t err;
125 MALI_CHECK_NON_NULL(uargs, -EINVAL);
127 kargs.ctx = session_data;
128 err = _mali_ukk_profiling_clear(&kargs);
129 if (_MALI_OSK_ERR_OK != err)
131 return map_errcode(err);
137 int profiling_report_sw_counters_wrapper(struct mali_session_data *session_data, _mali_uk_sw_counters_report_s __user *uargs)
139 _mali_uk_sw_counters_report_s kargs;
140 _mali_osk_errcode_t err;
143 MALI_CHECK_NON_NULL(uargs, -EINVAL);
145 if (0 != copy_from_user(&kargs, uargs, sizeof(_mali_uk_sw_counters_report_s)))
150 /* make sure that kargs.num_counters is [at least somewhat] sane */
151 if (kargs.num_counters > 10000) {
152 MALI_DEBUG_PRINT(1, ("User space attempted to allocate too many counters.\n"));
156 counter_buffer = (u32*)kmalloc(sizeof(u32) * kargs.num_counters, GFP_KERNEL);
157 if (NULL == counter_buffer)
162 if (0 != copy_from_user(counter_buffer, kargs.counters, sizeof(u32) * kargs.num_counters))
164 kfree(counter_buffer);
168 kargs.ctx = session_data;
169 kargs.counters = counter_buffer;
171 err = _mali_ukk_sw_counters_report(&kargs);
173 kfree(counter_buffer);
175 if (_MALI_OSK_ERR_OK != err)
177 return map_errcode(err);