Jon Medhurst | aaf37a3 | 2013-06-11 12:10:56 +0100 | [diff] [blame^] | 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 | #define GATOR_LIVE 1 |
| 24 | |
| 25 | // cpu ids |
| 26 | #define ARM1136 0xb36 |
| 27 | #define ARM1156 0xb56 |
| 28 | #define ARM1176 0xb76 |
| 29 | #define ARM11MPCORE 0xb02 |
| 30 | #define CORTEX_A5 0xc05 |
| 31 | #define CORTEX_A7 0xc07 |
| 32 | #define CORTEX_A8 0xc08 |
| 33 | #define CORTEX_A9 0xc09 |
| 34 | #define CORTEX_A15 0xc0f |
| 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 | #define MAXSIZE_CORE_NAME 32 |
| 46 | |
| 47 | struct gator_cpu { |
| 48 | const int cpuid; |
| 49 | const char core_name[MAXSIZE_CORE_NAME]; |
| 50 | const char * const pmu_name; |
| 51 | const char * const pmnc_name; |
| 52 | const int pmnc_counters; |
| 53 | }; |
| 54 | |
| 55 | const struct gator_cpu *gator_find_cpu_by_cpuid(const u32 cpuid); |
| 56 | const struct gator_cpu *gator_find_cpu_by_pmu_name(const char *const name); |
| 57 | |
| 58 | /****************************************************************************** |
| 59 | * Filesystem |
| 60 | ******************************************************************************/ |
| 61 | int gatorfs_create_file_perm(struct super_block *sb, struct dentry *root, |
| 62 | char const *name, |
| 63 | const struct file_operations *fops, int perm); |
| 64 | |
| 65 | struct dentry *gatorfs_mkdir(struct super_block *sb, struct dentry *root, |
| 66 | char const *name); |
| 67 | |
| 68 | int gatorfs_create_ulong(struct super_block *sb, struct dentry *root, |
| 69 | char const *name, unsigned long *val); |
| 70 | |
| 71 | int gatorfs_create_ro_ulong(struct super_block *sb, struct dentry *root, |
| 72 | char const *name, unsigned long *val); |
| 73 | |
| 74 | void gator_op_create_files(struct super_block *sb, struct dentry *root); |
| 75 | |
| 76 | /****************************************************************************** |
| 77 | * Tracepoints |
| 78 | ******************************************************************************/ |
| 79 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 32) |
| 80 | # error Kernels prior to 2.6.32 not supported |
| 81 | #elif LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35) |
| 82 | # define GATOR_DEFINE_PROBE(probe_name, proto) \ |
| 83 | static void probe_##probe_name(PARAMS(proto)) |
| 84 | # define GATOR_REGISTER_TRACE(probe_name) \ |
| 85 | register_trace_##probe_name(probe_##probe_name) |
| 86 | # define GATOR_UNREGISTER_TRACE(probe_name) \ |
| 87 | unregister_trace_##probe_name(probe_##probe_name) |
| 88 | #else |
| 89 | # define GATOR_DEFINE_PROBE(probe_name, proto) \ |
| 90 | static void probe_##probe_name(void *data, PARAMS(proto)) |
| 91 | # define GATOR_REGISTER_TRACE(probe_name) \ |
| 92 | register_trace_##probe_name(probe_##probe_name, NULL) |
| 93 | # define GATOR_UNREGISTER_TRACE(probe_name) \ |
| 94 | unregister_trace_##probe_name(probe_##probe_name, NULL) |
| 95 | #endif |
| 96 | |
| 97 | /****************************************************************************** |
| 98 | * Events |
| 99 | ******************************************************************************/ |
| 100 | struct gator_interface { |
| 101 | void (*shutdown)(void); // Complementary function to init |
| 102 | int (*create_files)(struct super_block *sb, struct dentry *root); |
| 103 | int (*start)(void); |
| 104 | void (*stop)(void); // Complementary function to start |
| 105 | int (*online)(int **buffer, bool migrate); |
| 106 | int (*offline)(int **buffer, bool migrate); |
| 107 | void (*online_dispatch)(int cpu, bool migrate); // called in process context but may not be running on core 'cpu' |
| 108 | void (*offline_dispatch)(int cpu, bool migrate); // called in process context but may not be running on core 'cpu' |
| 109 | int (*read)(int **buffer); |
| 110 | int (*read64)(long long **buffer); |
| 111 | struct list_head list; |
| 112 | }; |
| 113 | |
| 114 | // gator_events_init is used as a search term in gator_events.sh |
| 115 | #define gator_events_init(initfn) \ |
| 116 | static inline int __gator_events_init_test(void) \ |
| 117 | { return initfn(); } |
| 118 | |
| 119 | int gator_events_install(struct gator_interface *interface); |
| 120 | int gator_events_get_key(void); |
| 121 | u32 gator_cpuid(void); |
| 122 | |
| 123 | void gator_backtrace_handler(struct pt_regs *const regs); |
| 124 | |
| 125 | #if !GATOR_IKS_SUPPORT |
| 126 | |
| 127 | #define get_physical_cpu() smp_processor_id() |
| 128 | #define lcpu_to_pcpu(lcpu) lcpu |
| 129 | #define pcpu_to_lcpu(pcpu) pcpu |
| 130 | |
| 131 | #else |
| 132 | |
| 133 | #define get_physical_cpu() lcpu_to_pcpu(get_logical_cpu()) |
| 134 | int lcpu_to_pcpu(const int lcpu); |
| 135 | int pcpu_to_lcpu(const int pcpu); |
| 136 | |
| 137 | #endif |
| 138 | |
| 139 | #define get_logical_cpu() smp_processor_id() |
| 140 | #define on_primary_core() (get_logical_cpu() == 0) |
| 141 | |
| 142 | #endif // GATOR_H_ |