2 * This confidential and proprietary software may be used only as
3 * authorised by a licensing agreement from ARM Limited
4 * (C) COPYRIGHT 2010-2013 ARM Limited
6 * The entire notice above must be reproduced on all authorised
7 * copies and copies may only be made to the extent permitted
8 * by a licensing agreement from ARM Limited.
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))) {
31 kargs.ctx = session_data;
32 err = _mali_ukk_profiling_start(&kargs);
33 if (_MALI_OSK_ERR_OK != err) {
34 return map_errcode(err);
37 if (0 != put_user(kargs.limit, &uargs->limit)) {
44 int profiling_add_event_wrapper(struct mali_session_data *session_data, _mali_uk_profiling_add_event_s __user *uargs)
46 _mali_uk_profiling_add_event_s kargs;
47 _mali_osk_errcode_t err;
49 MALI_CHECK_NON_NULL(uargs, -EINVAL);
51 if (0 != copy_from_user(&kargs, uargs, sizeof(_mali_uk_profiling_add_event_s))) {
55 kargs.ctx = session_data;
56 err = _mali_ukk_profiling_add_event(&kargs);
57 if (_MALI_OSK_ERR_OK != err) {
58 return map_errcode(err);
64 int profiling_stop_wrapper(struct mali_session_data *session_data, _mali_uk_profiling_stop_s __user *uargs)
66 _mali_uk_profiling_stop_s kargs;
67 _mali_osk_errcode_t err;
69 MALI_CHECK_NON_NULL(uargs, -EINVAL);
71 kargs.ctx = session_data;
72 err = _mali_ukk_profiling_stop(&kargs);
73 if (_MALI_OSK_ERR_OK != err) {
74 return map_errcode(err);
77 if (0 != put_user(kargs.count, &uargs->count)) {
84 int profiling_get_event_wrapper(struct mali_session_data *session_data, _mali_uk_profiling_get_event_s __user *uargs)
86 _mali_uk_profiling_get_event_s kargs;
87 _mali_osk_errcode_t err;
89 MALI_CHECK_NON_NULL(uargs, -EINVAL);
91 if (0 != get_user(kargs.index, &uargs->index)) {
95 kargs.ctx = session_data;
97 err = _mali_ukk_profiling_get_event(&kargs);
98 if (_MALI_OSK_ERR_OK != err) {
99 return map_errcode(err);
102 kargs.ctx = NULL; /* prevent kernel address to be returned to user space */
103 if (0 != copy_to_user(uargs, &kargs, sizeof(_mali_uk_profiling_get_event_s))) {
110 int profiling_clear_wrapper(struct mali_session_data *session_data, _mali_uk_profiling_clear_s __user *uargs)
112 _mali_uk_profiling_clear_s kargs;
113 _mali_osk_errcode_t err;
115 MALI_CHECK_NON_NULL(uargs, -EINVAL);
117 kargs.ctx = session_data;
118 err = _mali_ukk_profiling_clear(&kargs);
119 if (_MALI_OSK_ERR_OK != err) {
120 return map_errcode(err);
126 int profiling_report_sw_counters_wrapper(struct mali_session_data *session_data, _mali_uk_sw_counters_report_s __user *uargs)
128 _mali_uk_sw_counters_report_s kargs;
129 _mali_osk_errcode_t err;
132 MALI_CHECK_NON_NULL(uargs, -EINVAL);
134 if (0 != copy_from_user(&kargs, uargs, sizeof(_mali_uk_sw_counters_report_s))) {
138 /* make sure that kargs.num_counters is [at least somewhat] sane */
139 if (kargs.num_counters > 10000) {
140 MALI_DEBUG_PRINT(1, ("User space attempted to allocate too many counters.\n"));
144 counter_buffer = (u32*)kmalloc(sizeof(u32) * kargs.num_counters, GFP_KERNEL);
145 if (NULL == counter_buffer) {
149 if (0 != copy_from_user(counter_buffer, kargs.counters, sizeof(u32) * kargs.num_counters)) {
150 kfree(counter_buffer);
154 kargs.ctx = session_data;
155 kargs.counters = counter_buffer;
157 err = _mali_ukk_sw_counters_report(&kargs);
159 kfree(counter_buffer);
161 if (_MALI_OSK_ERR_OK != err) {
162 return map_errcode(err);