2e122da767d83e7c05d40103809f266e974f638d
[firefly-linux-kernel-4.4.55.git] / drivers / gator / gator.h
1 /**
2  * Copyright (C) ARM Limited 2010-2013. 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 SCORPION    0x00f
35 #define SCORPIONMP  0x02d
36 #define KRAITSIM    0x049
37 #define KRAIT       0x04d
38 #define KRAIT_S4_PRO 0x06f
39 #define CORTEX_A53  0xd03
40 #define CORTEX_A57  0xd07
41 #define AARCH64     0xd0f
42 #define OTHER       0xfff
43
44 #define MAXSIZE_CORE_NAME 32
45
46 struct gator_cpu {
47         const int cpuid;
48         // Human readable name
49         const char core_name[MAXSIZE_CORE_NAME];
50         // Perf PMU name
51         const char * const pmu_name;
52         // gatorfs event name
53         const char * const pmnc_name;
54         // compatible from Documentation/devicetree/bindings/arm/cpus.txt
55         const char * const dt_name;
56         const int pmnc_counters;
57 };
58
59 const struct gator_cpu *gator_find_cpu_by_cpuid(const u32 cpuid);
60 const struct gator_cpu *gator_find_cpu_by_pmu_name(const char *const name);
61
62 /******************************************************************************
63  * Filesystem
64  ******************************************************************************/
65 int gatorfs_create_file_perm(struct super_block *sb, struct dentry *root,
66                              char const *name,
67                              const struct file_operations *fops, int perm);
68
69 struct dentry *gatorfs_mkdir(struct super_block *sb, struct dentry *root,
70                              char const *name);
71
72 int gatorfs_create_ulong(struct super_block *sb, struct dentry *root,
73                          char const *name, unsigned long *val);
74
75 int gatorfs_create_ro_ulong(struct super_block *sb, struct dentry *root,
76                             char const *name, unsigned long *val);
77
78 void gator_op_create_files(struct super_block *sb, struct dentry *root);
79
80 /******************************************************************************
81  * Tracepoints
82  ******************************************************************************/
83 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 32)
84 #       error Kernels prior to 2.6.32 not supported
85 #elif LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35)
86 #       define GATOR_DEFINE_PROBE(probe_name, proto) \
87                 static void probe_##probe_name(PARAMS(proto))
88 #       define GATOR_REGISTER_TRACE(probe_name) \
89                 register_trace_##probe_name(probe_##probe_name)
90 #       define GATOR_UNREGISTER_TRACE(probe_name) \
91                 unregister_trace_##probe_name(probe_##probe_name)
92 #else
93 #       define GATOR_DEFINE_PROBE(probe_name, proto) \
94                 static void probe_##probe_name(void *data, PARAMS(proto))
95 #       define GATOR_REGISTER_TRACE(probe_name) \
96                 register_trace_##probe_name(probe_##probe_name, NULL)
97 #       define GATOR_UNREGISTER_TRACE(probe_name) \
98                 unregister_trace_##probe_name(probe_##probe_name, NULL)
99 #endif
100
101 /******************************************************************************
102  * Events
103  ******************************************************************************/
104 struct gator_interface {
105         void (*shutdown)(void); // Complementary function to init
106         int (*create_files)(struct super_block *sb, struct dentry *root);
107         int (*start)(void);
108         void (*stop)(void);             // Complementary function to start
109         int (*online)(int **buffer, bool migrate);
110         int (*offline)(int **buffer, bool migrate);
111         void (*online_dispatch)(int cpu, bool migrate); // called in process context but may not be running on core 'cpu'
112         void (*offline_dispatch)(int cpu, bool migrate);        // called in process context but may not be running on core 'cpu'
113         int (*read)(int **buffer);
114         int (*read64)(long long **buffer);
115         struct list_head list;
116 };
117
118 // gator_events_init is used as a search term in gator_events.sh
119 #define gator_events_init(initfn) \
120         static inline int __gator_events_init_test(void) \
121         { return initfn(); }
122
123 int gator_events_install(struct gator_interface *interface);
124 int gator_events_get_key(void);
125 u32 gator_cpuid(void);
126
127 void gator_backtrace_handler(struct pt_regs *const regs);
128
129 #if !GATOR_IKS_SUPPORT
130
131 #define get_physical_cpu() smp_processor_id()
132 #define lcpu_to_pcpu(lcpu) lcpu
133 #define pcpu_to_lcpu(pcpu) pcpu
134
135 #else
136
137 #define get_physical_cpu() lcpu_to_pcpu(get_logical_cpu())
138 int lcpu_to_pcpu(const int lcpu);
139 int pcpu_to_lcpu(const int pcpu);
140
141 #endif
142
143 #define get_logical_cpu() smp_processor_id()
144 #define on_primary_core() (get_logical_cpu() == 0)
145
146 #endif // GATOR_H_