Merge remote-tracking branch 'lsk/v3.10/topic/arm64-misc' into linux-linaro-lsk
[firefly-linux-kernel-4.4.55.git] / drivers / gator / gator_events_mali_common.c
1 /**
2  * Copyright (C) ARM Limited 2012-2014. All rights reserved.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  */
9 #include "gator_events_mali_common.h"
10
11 extern int gator_mali_create_file_system(const char *mali_name, const char *event_name, struct super_block *sb, struct dentry *root, struct mali_counter *counter, unsigned long *event)
12 {
13         int err;
14         char buf[255];
15         struct dentry *dir;
16
17         /* If the counter name is empty ignore it */
18         if (strlen(event_name) != 0) {
19                 /* Set up the filesystem entry for this event. */
20                 if (mali_name == NULL)
21                         snprintf(buf, sizeof(buf), "ARM_Mali-%s", event_name);
22                 else
23                         snprintf(buf, sizeof(buf), "ARM_Mali-%s_%s", mali_name, event_name);
24
25                 dir = gatorfs_mkdir(sb, root, buf);
26
27                 if (dir == NULL) {
28                         pr_debug("gator: %s: error creating file system for: %s (%s)\n", mali_name, event_name, buf);
29                         return -1;
30                 }
31
32                 err = gatorfs_create_ulong(sb, dir, "enabled", &counter->enabled);
33                 if (err != 0) {
34                         pr_debug("gator: %s: error calling gatorfs_create_ulong for: %s (%s)\n", mali_name, event_name, buf);
35                         return -1;
36                 }
37                 err = gatorfs_create_ro_ulong(sb, dir, "key", &counter->key);
38                 if (err != 0) {
39                         pr_debug("gator: %s: error calling gatorfs_create_ro_ulong for: %s (%s)\n", mali_name, event_name, buf);
40                         return -1;
41                 }
42                 if (counter->cores != -1) {
43                         err = gatorfs_create_ro_ulong(sb, dir, "cores", &counter->cores);
44                         if (err != 0) {
45                                 pr_debug("gator: %s: error calling gatorfs_create_ro_ulong for: %s (%s)\n", mali_name, event_name, buf);
46                                 return -1;
47                         }
48                 }
49                 if (event != NULL) {
50                         err = gatorfs_create_ulong(sb, dir, "event", event);
51                         if (err != 0) {
52                                 pr_debug("gator: %s: error calling gatorfs_create_ro_ulong for: %s (%s)\n", mali_name, event_name, buf);
53                                 return -1;
54                         }
55                 }
56         }
57
58         return 0;
59 }
60
61 extern void gator_mali_initialise_counters(struct mali_counter counters[], unsigned int n_counters)
62 {
63         unsigned int cnt;
64
65         for (cnt = 0; cnt < n_counters; cnt++) {
66                 struct mali_counter *counter = &counters[cnt];
67
68                 counter->key = gator_events_get_key();
69                 counter->enabled = 0;
70                 counter->cores = -1;
71         }
72 }