2 * PPC 32 oprofile support
3 * Based on PPC64 oprofile support
4 * Copyright (C) 2004 Anton Blanchard <anton@au.ibm.com>, IBM
6 * Copyright (C) Freescale Semiconductor, Inc 2004
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
16 #include <linux/oprofile.h>
17 #include <linux/slab.h>
18 #include <linux/init.h>
19 #include <linux/smp.h>
20 #include <linux/errno.h>
21 #include <asm/ptrace.h>
22 #include <asm/system.h>
23 #include <asm/perfmon.h>
24 #include <asm/cputable.h>
28 static struct op_ppc32_model
*model
;
30 static struct op_counter_config ctr
[OP_MAX_COUNTER
];
31 static struct op_system_config sys
;
33 static void op_handle_interrupt(struct pt_regs
*regs
)
35 model
->handle_interrupt(regs
, ctr
);
38 static int op_ppc32_setup(void)
40 /* Install our interrupt handler into the existing hook. */
41 if(request_perfmon_irq(&op_handle_interrupt
))
46 /* Pre-compute the values to stuff in the hardware registers. */
47 model
->reg_setup(ctr
, &sys
, model
->num_counters
);
50 /* FIXME: Make multi-cpu work */
51 /* Configure the registers on all cpus. */
52 on_each_cpu(model
->reg_setup
, NULL
, 0, 1);
58 static void op_ppc32_shutdown(void)
62 /* Remove our interrupt handler. We may be removing this module. */
66 static void op_ppc32_cpu_start(void *dummy
)
71 static int op_ppc32_start(void)
73 on_each_cpu(op_ppc32_cpu_start
, NULL
, 0, 1);
77 static inline void op_ppc32_cpu_stop(void *dummy
)
82 static void op_ppc32_stop(void)
84 on_each_cpu(op_ppc32_cpu_stop
, NULL
, 0, 1);
87 static int op_ppc32_create_files(struct super_block
*sb
, struct dentry
*root
)
91 for (i
= 0; i
< model
->num_counters
; ++i
) {
95 snprintf(buf
, sizeof buf
, "%d", i
);
96 dir
= oprofilefs_mkdir(sb
, root
, buf
);
98 oprofilefs_create_ulong(sb
, dir
, "enabled", &ctr
[i
].enabled
);
99 oprofilefs_create_ulong(sb
, dir
, "event", &ctr
[i
].event
);
100 oprofilefs_create_ulong(sb
, dir
, "count", &ctr
[i
].count
);
101 oprofilefs_create_ulong(sb
, dir
, "kernel", &ctr
[i
].kernel
);
102 oprofilefs_create_ulong(sb
, dir
, "user", &ctr
[i
].user
);
104 /* FIXME: Not sure if this is used */
105 oprofilefs_create_ulong(sb
, dir
, "unit_mask", &ctr
[i
].unit_mask
);
108 oprofilefs_create_ulong(sb
, root
, "enable_kernel", &sys
.enable_kernel
);
109 oprofilefs_create_ulong(sb
, root
, "enable_user", &sys
.enable_user
);
111 /* Default to tracing both kernel and user */
112 sys
.enable_kernel
= 1;
118 static struct oprofile_operations oprof_ppc32_ops
= {
119 .create_files
= op_ppc32_create_files
,
120 .setup
= op_ppc32_setup
,
121 .shutdown
= op_ppc32_shutdown
,
122 .start
= op_ppc32_start
,
123 .stop
= op_ppc32_stop
,
124 .cpu_type
= NULL
/* To be filled in below. */
127 int __init
oprofile_arch_init(struct oprofile_operations
*ops
)
130 int cpu_id
= smp_processor_id();
132 #ifdef CONFIG_FSL_BOOKE
133 model
= &op_model_fsl_booke
;
138 name
= kmalloc(32, GFP_KERNEL
);
143 sprintf(name
, "ppc/%s", cur_cpu_spec
[cpu_id
]->cpu_name
);
145 oprof_ppc32_ops
.cpu_type
= name
;
147 model
->num_counters
= cur_cpu_spec
[cpu_id
]->num_pmcs
;
149 *ops
= oprof_ppc32_ops
;
151 printk(KERN_INFO
"oprofile: using %s performance monitoring.\n",
152 oprof_ppc32_ops
.cpu_type
);
157 void oprofile_arch_exit(void)
159 kfree(oprof_ppc32_ops
.cpu_type
);
160 oprof_ppc32_ops
.cpu_type
= NULL
;