5ad0254d86a9d7bb514fbbebafbc1de61ca475a0
[firefly-linux-kernel-4.4.55.git] / drivers / gator / gator.h
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 #ifndef GATOR_H_
10 #define GATOR_H_
11
12 #include <linux/version.h>
13 #include <linux/fs.h>
14 #include <linux/mm.h>
15 #include <linux/list.h>
16
17 #define GATOR_PERF_SUPPORT              LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0)
18 #define GATOR_PERF_PMU_SUPPORT  GATOR_PERF_SUPPORT && defined(CONFIG_PERF_EVENTS) && (!(defined(__arm__) || defined(__aarch64__)) || defined(CONFIG_HW_PERF_EVENTS))
19 #define GATOR_NO_PERF_SUPPORT   (!(GATOR_PERF_SUPPORT))
20 #define GATOR_CPU_FREQ_SUPPORT  (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38)) && defined(CONFIG_CPU_FREQ)
21 #define GATOR_IKS_SUPPORT       defined(CONFIG_BL_SWITCHER)
22
23 // cpu ids
24 #define ARM1136     0xb36
25 #define ARM1156     0xb56
26 #define ARM1176     0xb76
27 #define ARM11MPCORE 0xb02
28 #define CORTEX_A5   0xc05
29 #define CORTEX_A7   0xc07
30 #define CORTEX_A8   0xc08
31 #define CORTEX_A9   0xc09
32 #define CORTEX_A12  0xc0d
33 #define CORTEX_A15  0xc0f
34 #define CORTEX_A17  0xc0e
35 #define SCORPION    0x00f
36 #define SCORPIONMP  0x02d
37 #define KRAITSIM    0x049
38 #define KRAIT       0x04d
39 #define KRAIT_S4_PRO 0x06f
40 #define CORTEX_A53  0xd03
41 #define CORTEX_A57  0xd07
42 #define AARCH64     0xd0f
43 #define OTHER       0xfff
44
45 // gpu enums
46 #define MALI_4xx     1
47 #define MALI_T6xx    2
48
49 #define MAXSIZE_CORE_NAME 32
50
51 struct gator_cpu {
52         const int cpuid;
53         // Human readable name
54         const char core_name[MAXSIZE_CORE_NAME];
55         // gatorfs event and Perf PMU name
56         const char * const pmnc_name;
57         // compatible from Documentation/devicetree/bindings/arm/cpus.txt
58         const char * const dt_name;
59         const int pmnc_counters;
60 };
61
62 const struct gator_cpu *gator_find_cpu_by_cpuid(const u32 cpuid);
63 const struct gator_cpu *gator_find_cpu_by_pmu_name(const char *const name);
64
65 /******************************************************************************
66  * Filesystem
67  ******************************************************************************/
68 struct dentry *gatorfs_mkdir(struct super_block *sb, struct dentry *root,
69                              char const *name);
70
71 int gatorfs_create_ulong(struct super_block *sb, struct dentry *root,
72                          char const *name, unsigned long *val);
73
74 int gatorfs_create_ro_ulong(struct super_block *sb, struct dentry *root,
75                             char const *name, unsigned long *val);
76
77 /******************************************************************************
78  * Tracepoints
79  ******************************************************************************/
80 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 32)
81 #       error Kernels prior to 2.6.32 not supported
82 #elif LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35)
83 #       define GATOR_DEFINE_PROBE(probe_name, proto) \
84                 static void probe_##probe_name(PARAMS(proto))
85 #       define GATOR_REGISTER_TRACE(probe_name) \
86                 register_trace_##probe_name(probe_##probe_name)
87 #       define GATOR_UNREGISTER_TRACE(probe_name) \
88                 unregister_trace_##probe_name(probe_##probe_name)
89 #elif LINUX_VERSION_CODE < KERNEL_VERSION(3, 15, 0)
90 #       define GATOR_DEFINE_PROBE(probe_name, proto) \
91                 static void probe_##probe_name(void *data, PARAMS(proto))
92 #       define GATOR_REGISTER_TRACE(probe_name) \
93                 register_trace_##probe_name(probe_##probe_name, NULL)
94 #       define GATOR_UNREGISTER_TRACE(probe_name) \
95                 unregister_trace_##probe_name(probe_##probe_name, NULL)
96 #else
97 #       define GATOR_DEFINE_PROBE(probe_name, proto) \
98                 extern struct tracepoint *gator_tracepoint_##probe_name; \
99                 static void probe_##probe_name(void *data, PARAMS(proto))
100 #       define GATOR_REGISTER_TRACE(probe_name) \
101                 tracepoint_probe_register(gator_tracepoint_##probe_name, probe_##probe_name, NULL)
102 #       define GATOR_UNREGISTER_TRACE(probe_name) \
103                 tracepoint_probe_unregister(gator_tracepoint_##probe_name, probe_##probe_name, NULL)
104 #endif
105
106 /******************************************************************************
107  * Events
108  ******************************************************************************/
109 struct gator_interface {
110         void (*shutdown)(void); // Complementary function to init
111         int (*create_files)(struct super_block *sb, struct dentry *root);
112         int (*start)(void);
113         void (*stop)(void);             // Complementary function to start
114         int (*online)(int **buffer, bool migrate);
115         int (*offline)(int **buffer, bool migrate);
116         void (*online_dispatch)(int cpu, bool migrate); // called in process context but may not be running on core 'cpu'
117         void (*offline_dispatch)(int cpu, bool migrate);        // called in process context but may not be running on core 'cpu'
118         int (*read)(int **buffer);
119         int (*read64)(long long **buffer);
120         int (*read_proc)(long long **buffer, struct task_struct *);
121         struct list_head list;
122 };
123
124 int gator_events_install(struct gator_interface *interface);
125 int gator_events_get_key(void);
126 u32 gator_cpuid(void);
127
128 void gator_backtrace_handler(struct pt_regs *const regs);
129
130 void gator_marshal_activity_switch(int core, int key, int activity, int pid);
131
132 #if !GATOR_IKS_SUPPORT
133
134 #define get_physical_cpu() smp_processor_id()
135 #define lcpu_to_pcpu(lcpu) lcpu
136 #define pcpu_to_lcpu(pcpu) pcpu
137
138 #else
139
140 #define get_physical_cpu() lcpu_to_pcpu(get_logical_cpu())
141 int lcpu_to_pcpu(const int lcpu);
142 int pcpu_to_lcpu(const int pcpu);
143
144 #endif
145
146 #define get_logical_cpu() smp_processor_id()
147 #define on_primary_core() (get_logical_cpu() == 0)
148
149 #endif // GATOR_H_