Paul Mundt | 60a51fb | 2008-12-16 09:33:53 +0900 | [diff] [blame^] | 1 | /* |
| 2 | * arch/sh/oprofile/init.c |
| 3 | * |
| 4 | * Copyright (C) 2003 - 2008 Paul Mundt |
| 5 | * |
| 6 | * Based on arch/mips/oprofile/common.c: |
| 7 | * |
| 8 | * Copyright (C) 2004, 2005 Ralf Baechle |
| 9 | * Copyright (C) 2005 MIPS Technologies, Inc. |
| 10 | * |
| 11 | * This file is subject to the terms and conditions of the GNU General Public |
| 12 | * License. See the file "COPYING" in the main directory of this archive |
| 13 | * for more details. |
| 14 | */ |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/oprofile.h> |
| 17 | #include <linux/init.h> |
| 18 | #include <linux/errno.h> |
| 19 | #include <linux/smp.h> |
| 20 | #include <asm/processor.h> |
| 21 | #include "op_impl.h" |
| 22 | |
| 23 | extern struct op_sh_model op_model_sh7750_ops __weak; |
| 24 | extern struct op_sh_model op_model_sh4a_ops __weak; |
| 25 | |
| 26 | static struct op_sh_model *model; |
| 27 | |
| 28 | static struct op_counter_config ctr[20]; |
| 29 | |
| 30 | static int op_sh_setup(void) |
| 31 | { |
| 32 | /* Pre-compute the values to stuff in the hardware registers. */ |
| 33 | model->reg_setup(ctr); |
| 34 | |
| 35 | /* Configure the registers on all cpus. */ |
| 36 | on_each_cpu(model->cpu_setup, NULL, 1); |
| 37 | |
| 38 | return 0; |
| 39 | } |
| 40 | |
| 41 | static int op_sh_create_files(struct super_block *sb, struct dentry *root) |
| 42 | { |
| 43 | int i, ret = 0; |
| 44 | |
| 45 | for (i = 0; i < model->num_counters; i++) { |
| 46 | struct dentry *dir; |
| 47 | char buf[4]; |
| 48 | |
| 49 | snprintf(buf, sizeof(buf), "%d", i); |
| 50 | dir = oprofilefs_mkdir(sb, root, buf); |
| 51 | |
| 52 | ret |= oprofilefs_create_ulong(sb, dir, "enabled", &ctr[i].enabled); |
| 53 | ret |= oprofilefs_create_ulong(sb, dir, "event", &ctr[i].event); |
| 54 | ret |= oprofilefs_create_ulong(sb, dir, "kernel", &ctr[i].kernel); |
| 55 | ret |= oprofilefs_create_ulong(sb, dir, "user", &ctr[i].user); |
| 56 | |
| 57 | if (model->create_files) |
| 58 | ret |= model->create_files(sb, dir); |
| 59 | else |
| 60 | ret |= oprofilefs_create_ulong(sb, dir, "count", &ctr[i].count); |
| 61 | |
| 62 | /* Dummy entries */ |
| 63 | ret |= oprofilefs_create_ulong(sb, dir, "unit_mask", &ctr[i].unit_mask); |
| 64 | } |
| 65 | |
| 66 | return ret; |
| 67 | } |
| 68 | |
| 69 | static int op_sh_start(void) |
| 70 | { |
| 71 | /* Enable performance monitoring for all counters. */ |
| 72 | on_each_cpu(model->cpu_start, NULL, 1); |
| 73 | |
| 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | static void op_sh_stop(void) |
| 78 | { |
| 79 | /* Disable performance monitoring for all counters. */ |
| 80 | on_each_cpu(model->cpu_stop, NULL, 1); |
| 81 | } |
| 82 | |
| 83 | int __init oprofile_arch_init(struct oprofile_operations *ops) |
| 84 | { |
| 85 | struct op_sh_model *lmodel = NULL; |
| 86 | int ret; |
| 87 | |
| 88 | switch (current_cpu_data.type) { |
| 89 | /* SH-4 types */ |
| 90 | case CPU_SH7750: |
| 91 | case CPU_SH7750S: |
| 92 | lmodel = &op_model_sh7750_ops; |
| 93 | break; |
| 94 | |
| 95 | /* SH-4A types */ |
| 96 | case CPU_SH7763: |
| 97 | case CPU_SH7770: |
| 98 | case CPU_SH7780: |
| 99 | case CPU_SH7781: |
| 100 | case CPU_SH7785: |
| 101 | case CPU_SH7723: |
| 102 | case CPU_SHX3: |
| 103 | lmodel = &op_model_sh4a_ops; |
| 104 | break; |
| 105 | |
| 106 | /* SH4AL-DSP types */ |
| 107 | case CPU_SH7343: |
| 108 | case CPU_SH7722: |
| 109 | case CPU_SH7366: |
| 110 | lmodel = &op_model_sh4a_ops; |
| 111 | break; |
| 112 | } |
| 113 | |
| 114 | if (!lmodel) |
| 115 | return -ENODEV; |
| 116 | if (!(current_cpu_data.flags & CPU_HAS_PERF_COUNTER)) |
| 117 | return -ENODEV; |
| 118 | |
| 119 | ret = lmodel->init(); |
| 120 | if (unlikely(ret != 0)) |
| 121 | return ret; |
| 122 | |
| 123 | model = lmodel; |
| 124 | |
| 125 | ops->setup = op_sh_setup; |
| 126 | ops->create_files = op_sh_create_files; |
| 127 | ops->start = op_sh_start; |
| 128 | ops->stop = op_sh_stop; |
| 129 | ops->cpu_type = lmodel->cpu_type; |
| 130 | |
| 131 | printk(KERN_INFO "oprofile: using %s performance monitoring.\n", |
| 132 | lmodel->cpu_type); |
| 133 | |
| 134 | return 0; |
| 135 | } |
| 136 | |
| 137 | void oprofile_arch_exit(void) |
| 138 | { |
| 139 | if (model && model->exit) |
| 140 | model->exit(); |
| 141 | } |