dtsi: rk3368: add uart & jtag pcl func for sdmmc mux
[firefly-linux-kernel-4.4.55.git] / drivers / gator / gator_events_irq.c
1 /**
2  * Copyright (C) ARM Limited 2010-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
10 #include "gator.h"
11 #include <trace/events/irq.h>
12
13 #define HARDIRQ         0
14 #define SOFTIRQ         1
15 #define TOTALIRQ        (SOFTIRQ+1)
16
17 static ulong hardirq_enabled;
18 static ulong softirq_enabled;
19 static ulong hardirq_key;
20 static ulong softirq_key;
21 static DEFINE_PER_CPU(atomic_t[TOTALIRQ], irqCnt);
22 static DEFINE_PER_CPU(int[TOTALIRQ * 2], irqGet);
23
24 GATOR_DEFINE_PROBE(irq_handler_exit,
25                    TP_PROTO(int irq, struct irqaction *action, int ret))
26 {
27         atomic_inc(&per_cpu(irqCnt, get_physical_cpu())[HARDIRQ]);
28 }
29
30 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 37)
31 GATOR_DEFINE_PROBE(softirq_exit, TP_PROTO(struct softirq_action *h, struct softirq_action *vec))
32 #else
33 GATOR_DEFINE_PROBE(softirq_exit, TP_PROTO(unsigned int vec_nr))
34 #endif
35 {
36         atomic_inc(&per_cpu(irqCnt, get_physical_cpu())[SOFTIRQ]);
37 }
38
39 static int gator_events_irq_create_files(struct super_block *sb, struct dentry *root)
40 {
41         struct dentry *dir;
42
43         /* irq */
44         dir = gatorfs_mkdir(sb, root, "Linux_irq_irq");
45         if (!dir)
46                 return -1;
47         gatorfs_create_ulong(sb, dir, "enabled", &hardirq_enabled);
48         gatorfs_create_ro_ulong(sb, dir, "key", &hardirq_key);
49
50         /* soft irq */
51         dir = gatorfs_mkdir(sb, root, "Linux_irq_softirq");
52         if (!dir)
53                 return -1;
54         gatorfs_create_ulong(sb, dir, "enabled", &softirq_enabled);
55         gatorfs_create_ro_ulong(sb, dir, "key", &softirq_key);
56
57         return 0;
58 }
59
60 static int gator_events_irq_online(int **buffer, bool migrate)
61 {
62         int len = 0, cpu = get_physical_cpu();
63
64         /* synchronization with the irq_exit functions is not necessary as the values are being reset */
65         if (hardirq_enabled) {
66                 atomic_set(&per_cpu(irqCnt, cpu)[HARDIRQ], 0);
67                 per_cpu(irqGet, cpu)[len++] = hardirq_key;
68                 per_cpu(irqGet, cpu)[len++] = 0;
69         }
70
71         if (softirq_enabled) {
72                 atomic_set(&per_cpu(irqCnt, cpu)[SOFTIRQ], 0);
73                 per_cpu(irqGet, cpu)[len++] = softirq_key;
74                 per_cpu(irqGet, cpu)[len++] = 0;
75         }
76
77         if (buffer)
78                 *buffer = per_cpu(irqGet, cpu);
79
80         return len;
81 }
82
83 static int gator_events_irq_start(void)
84 {
85         /* register tracepoints */
86         if (hardirq_enabled)
87                 if (GATOR_REGISTER_TRACE(irq_handler_exit))
88                         goto fail_hardirq_exit;
89         if (softirq_enabled)
90                 if (GATOR_REGISTER_TRACE(softirq_exit))
91                         goto fail_softirq_exit;
92         pr_debug("gator: registered irq tracepoints\n");
93
94         return 0;
95
96         /* unregister tracepoints on error */
97 fail_softirq_exit:
98         if (hardirq_enabled)
99                 GATOR_UNREGISTER_TRACE(irq_handler_exit);
100 fail_hardirq_exit:
101         pr_err("gator: irq tracepoints failed to activate, please verify that tracepoints are enabled in the linux kernel\n");
102
103         return -1;
104 }
105
106 static void gator_events_irq_stop(void)
107 {
108         if (hardirq_enabled)
109                 GATOR_UNREGISTER_TRACE(irq_handler_exit);
110         if (softirq_enabled)
111                 GATOR_UNREGISTER_TRACE(softirq_exit);
112         pr_debug("gator: unregistered irq tracepoints\n");
113
114         hardirq_enabled = 0;
115         softirq_enabled = 0;
116 }
117
118 static int gator_events_irq_read(int **buffer, bool sched_switch)
119 {
120         int len, value;
121         int cpu = get_physical_cpu();
122
123         len = 0;
124         if (hardirq_enabled) {
125                 value = atomic_read(&per_cpu(irqCnt, cpu)[HARDIRQ]);
126                 atomic_sub(value, &per_cpu(irqCnt, cpu)[HARDIRQ]);
127
128                 per_cpu(irqGet, cpu)[len++] = hardirq_key;
129                 per_cpu(irqGet, cpu)[len++] = value;
130         }
131
132         if (softirq_enabled) {
133                 value = atomic_read(&per_cpu(irqCnt, cpu)[SOFTIRQ]);
134                 atomic_sub(value, &per_cpu(irqCnt, cpu)[SOFTIRQ]);
135
136                 per_cpu(irqGet, cpu)[len++] = softirq_key;
137                 per_cpu(irqGet, cpu)[len++] = value;
138         }
139
140         if (buffer)
141                 *buffer = per_cpu(irqGet, cpu);
142
143         return len;
144 }
145
146 static struct gator_interface gator_events_irq_interface = {
147         .create_files = gator_events_irq_create_files,
148         .online = gator_events_irq_online,
149         .start = gator_events_irq_start,
150         .stop = gator_events_irq_stop,
151         .read = gator_events_irq_read,
152 };
153
154 int gator_events_irq_init(void)
155 {
156         hardirq_key = gator_events_get_key();
157         softirq_key = gator_events_get_key();
158
159         hardirq_enabled = 0;
160         softirq_enabled = 0;
161
162         return gator_events_install(&gator_events_irq_interface);
163 }