blob: 202eb41c485b03c5d348c2cfe21de0ab00238311 [file] [log] [blame]
Jon Medhurstaaf37a32013-06-11 12:10:56 +01001/**
Jon Medhurstb1d07442015-05-08 12:04:18 +01002 * Copyright (C) ARM Limited 2010-2015. All rights reserved.
Jon Medhurstaaf37a32013-06-11 12:10:56 +01003 *
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
Jon Medhurst96b56152014-10-30 18:01:15 +000017#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)))
Jon Medhurstaaf37a32013-06-11 12:10:56 +010019#define GATOR_NO_PERF_SUPPORT (!(GATOR_PERF_SUPPORT))
Jon Medhurst96b56152014-10-30 18:01:15 +000020#define GATOR_CPU_FREQ_SUPPORT ((LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38)) && defined(CONFIG_CPU_FREQ))
Jon Medhurstaaf37a32013-06-11 12:10:56 +010021#define GATOR_IKS_SUPPORT defined(CONFIG_BL_SWITCHER)
22
Jon Medhurst96b56152014-10-30 18:01:15 +000023/* cpu ids */
Jon Medhurstb1d07442015-05-08 12:04:18 +010024#define ARM1136 0x41b36
25#define ARM1156 0x41b56
26#define ARM1176 0x41b76
27#define ARM11MPCORE 0x41b02
28#define CORTEX_A5 0x41c05
29#define CORTEX_A7 0x41c07
30#define CORTEX_A8 0x41c08
31#define CORTEX_A9 0x41c09
32#define CORTEX_A15 0x41c0f
33#define CORTEX_A12 0x41c0d
34#define CORTEX_A17 0x41c0e
35#define SCORPION 0x5100f
36#define SCORPIONMP 0x5102d
37#define KRAITSIM 0x51049
38#define KRAIT 0x5104d
39#define KRAIT_S4_PRO 0x5106f
40#define CORTEX_A53 0x41d03
41#define CORTEX_A57 0x41d07
42#define CORTEX_A72 0x41d08
43#define OTHER 0xfffff
Jon Medhurstaaf37a32013-06-11 12:10:56 +010044
Jon Medhurst96b56152014-10-30 18:01:15 +000045/* gpu enums */
Jon Medhurste31266f2014-08-04 15:47:44 +010046#define MALI_4xx 1
Jon Medhurst96b56152014-10-30 18:01:15 +000047#define MALI_MIDGARD 2
Jon Medhurste31266f2014-08-04 15:47:44 +010048
Jon Medhurstaaf37a32013-06-11 12:10:56 +010049#define MAXSIZE_CORE_NAME 32
50
51struct gator_cpu {
52 const int cpuid;
Jon Medhurst96b56152014-10-30 18:01:15 +000053 /* Human readable name */
Jon Medhurstaaf37a32013-06-11 12:10:56 +010054 const char core_name[MAXSIZE_CORE_NAME];
Jon Medhurst96b56152014-10-30 18:01:15 +000055 /* 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;
Jon Medhurstaaf37a32013-06-11 12:10:56 +010059 const int pmnc_counters;
60};
61
62const struct gator_cpu *gator_find_cpu_by_cpuid(const u32 cpuid);
63const struct gator_cpu *gator_find_cpu_by_pmu_name(const char *const name);
64
65/******************************************************************************
66 * Filesystem
67 ******************************************************************************/
Jon Medhurstaaf37a32013-06-11 12:10:56 +010068struct dentry *gatorfs_mkdir(struct super_block *sb, struct dentry *root,
69 char const *name);
70
71int gatorfs_create_ulong(struct super_block *sb, struct dentry *root,
72 char const *name, unsigned long *val);
73
74int gatorfs_create_ro_ulong(struct super_block *sb, struct dentry *root,
75 char const *name, unsigned long *val);
76
Jon Medhurstaaf37a32013-06-11 12:10:56 +010077/******************************************************************************
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)
Jon Medhurste31266f2014-08-04 15:47:44 +010089#elif LINUX_VERSION_CODE < KERNEL_VERSION(3, 15, 0)
Jon Medhurstaaf37a32013-06-11 12:10:56 +010090# 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)
Jon Medhurste31266f2014-08-04 15:47:44 +010096#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) \
Jon Medhurst96b56152014-10-30 18:01:15 +0000101 ((gator_tracepoint_##probe_name == NULL) || tracepoint_probe_register(gator_tracepoint_##probe_name, probe_##probe_name, NULL))
Jon Medhurste31266f2014-08-04 15:47:44 +0100102# define GATOR_UNREGISTER_TRACE(probe_name) \
103 tracepoint_probe_unregister(gator_tracepoint_##probe_name, probe_##probe_name, NULL)
Jon Medhurstaaf37a32013-06-11 12:10:56 +0100104#endif
105
106/******************************************************************************
107 * Events
108 ******************************************************************************/
109struct gator_interface {
Jon Medhurst96b56152014-10-30 18:01:15 +0000110 /* Complementary function to init */
111 void (*shutdown)(void);
Jon Medhurstaaf37a32013-06-11 12:10:56 +0100112 int (*create_files)(struct super_block *sb, struct dentry *root);
113 int (*start)(void);
Jon Medhurst96b56152014-10-30 18:01:15 +0000114 /* Complementary function to start */
115 void (*stop)(void);
Jon Medhurstaaf37a32013-06-11 12:10:56 +0100116 int (*online)(int **buffer, bool migrate);
117 int (*offline)(int **buffer, bool migrate);
Jon Medhurst96b56152014-10-30 18:01:15 +0000118 /* called in process context but may not be running on core 'cpu' */
119 void (*online_dispatch)(int cpu, bool migrate);
120 /* called in process context but may not be running on core 'cpu' */
121 void (*offline_dispatch)(int cpu, bool migrate);
122 int (*read)(int **buffer, bool sched_switch);
Jon Medhurstaaf37a32013-06-11 12:10:56 +0100123 int (*read64)(long long **buffer);
Jon Medhurst34d97692013-12-19 09:23:06 +0000124 int (*read_proc)(long long **buffer, struct task_struct *);
Jon Medhurstaaf37a32013-06-11 12:10:56 +0100125 struct list_head list;
126};
127
Jon Medhurstaaf37a32013-06-11 12:10:56 +0100128int gator_events_install(struct gator_interface *interface);
129int gator_events_get_key(void);
130u32 gator_cpuid(void);
131
132void gator_backtrace_handler(struct pt_regs *const regs);
133
Jon Medhurste31266f2014-08-04 15:47:44 +0100134void gator_marshal_activity_switch(int core, int key, int activity, int pid);
135
Jon Medhurstaaf37a32013-06-11 12:10:56 +0100136#if !GATOR_IKS_SUPPORT
137
138#define get_physical_cpu() smp_processor_id()
139#define lcpu_to_pcpu(lcpu) lcpu
140#define pcpu_to_lcpu(pcpu) pcpu
141
142#else
143
144#define get_physical_cpu() lcpu_to_pcpu(get_logical_cpu())
145int lcpu_to_pcpu(const int lcpu);
146int pcpu_to_lcpu(const int pcpu);
147
148#endif
149
150#define get_logical_cpu() smp_processor_id()
151#define on_primary_core() (get_logical_cpu() == 0)
152
Jon Medhurst96b56152014-10-30 18:01:15 +0000153#endif /* GATOR_H_ */