0a619e3fc27e24b0d03b71aa581fa9386c0e38a4
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / mali400 / mali / linux / mali_osk_misc.c
1 /*
2  * Copyright (C) 2010-2015 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 <asm/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)
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
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
45 void _mali_osk_ctxprintf(_mali_osk_print_ctx *print_ctx, const char *fmt, ...)
46 {
47         va_list args;
48         char buf[512];
49
50         va_start(args, fmt);
51         vscnprintf(buf, 512, fmt, args);
52         seq_printf(print_ctx, buf);
53         va_end(args);
54 }
55
56 void _mali_osk_abort(void)
57 {
58         /* make a simple fault by dereferencing a NULL pointer */
59         dump_stack();
60         *(int *)0 = 0;
61 }
62
63 void _mali_osk_break(void)
64 {
65         _mali_osk_abort();
66 }
67
68 u32 _mali_osk_get_pid(void)
69 {
70         /* Thread group ID is the process ID on Linux */
71         return (u32)current->tgid;
72 }
73
74 char *_mali_osk_get_comm(void)
75 {
76         return (char *)current->comm;
77 }
78
79
80 u32 _mali_osk_get_tid(void)
81 {
82         /* pid is actually identifying the thread on Linux */
83         u32 tid = current->pid;
84
85         /* If the pid is 0 the core was idle.  Instead of returning 0 we return a special number
86          * identifying which core we are on. */
87         if (0 == tid) {
88                 tid = -(1 + raw_smp_processor_id());
89         }
90
91         return tid;
92 }