1 /*
2 * Copyright (C) 2010-2014, 2016-2017 ARM Limited. All rights reserved.
3 *
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.
6 *
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.
9 */
10
11 /**
12 * @file mali_osk_misc.c
13 * Implementation of the OS abstraction layer for the kernel device driver
14 */
15 #include <linux/kernel.h>
16 #include <linux/uaccess.h>
17 #include <asm/cacheflush.h>
18 #include <linux/sched.h>
19 #include <linux/seq_file.h>
20 #include <linux/module.h>
21 #include "mali_osk.h"
22
23 #if !defined(CONFIG_MALI_QUIET)
_mali_osk_dbgmsg(const char * fmt,...)24 void _mali_osk_dbgmsg(const char *fmt, ...)
25 {
26 va_list args;
27 va_start(args, fmt);
28 vprintk(fmt, args);
29 va_end(args);
30 }
31 #endif /* !defined(CONFIG_MALI_QUIET) */
32
_mali_osk_snprintf(char * buf,u32 size,const char * fmt,...)33 u32 _mali_osk_snprintf(char *buf, u32 size, const char *fmt, ...)
34 {
35 int res;
36 va_list args;
37 va_start(args, fmt);
38
39 res = vscnprintf(buf, (size_t)size, fmt, args);
40
41 va_end(args);
42 return res;
43 }
44
_mali_osk_abort(void)45 void _mali_osk_abort(void)
46 {
47 /* make a simple fault by dereferencing a NULL pointer */
48 dump_stack();
49 *(volatile int *)0 = 0;
50 }
51
_mali_osk_break(void)52 void _mali_osk_break(void)
53 {
54 _mali_osk_abort();
55 }
56
_mali_osk_get_pid(void)57 u32 _mali_osk_get_pid(void)
58 {
59 /* Thread group ID is the process ID on Linux */
60 return (u32)current->tgid;
61 }
62
_mali_osk_get_comm(void)63 char *_mali_osk_get_comm(void)
64 {
65 return (char *)current->comm;
66 }
67
68
_mali_osk_get_tid(void)69 u32 _mali_osk_get_tid(void)
70 {
71 /* pid is actually identifying the thread on Linux */
72 u32 tid = current->pid;
73
74 /* If the pid is 0 the core was idle. Instead of returning 0 we return a special number
75 * identifying which core we are on. */
76 if (0 == tid) {
77 tid = -(1 + raw_smp_processor_id());
78 }
79
80 return tid;
81 }
82