aboutsummaryrefslogtreecommitdiff
path: root/arch/blackfin/oprofile/common.c
blob: 0f6d303a88913f3a3d20b0f8aaea8f42f5004429 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
 * File:         arch/blackfin/oprofile/common.c
 * Based on:     arch/alpha/oprofile/common.c
 * Author:       Anton Blanchard <anton@au.ibm.com>
 *
 * Created:
 * Description:
 *
 * Modified:
 *               Copyright (C) 2004 Anton Blanchard <anton@au.ibm.com>, IBM
 *               Copyright 2004-2006 Analog Devices Inc.
 *
 * Bugs:         Enter bugs at http://blackfin.uclinux.org/
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see the file COPYING, or write
 * to the Free Software Foundation, Inc.,
 * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include <linux/oprofile.h>
#include <linux/init.h>
#include <linux/smp.h>
#include <linux/errno.h>
#include <linux/mutex.h>
#include <linux/ptrace.h>
#include <linux/irq.h>
#include <linux/io.h>

#include <asm/system.h>
#include <asm/blackfin.h>

#include "op_blackfin.h"

#define BFIN_533_ID  0xE5040003
#define BFIN_537_ID  0xE5040002

static int pfmon_enabled;
static struct mutex pfmon_lock;

struct op_bfin533_model *model;

struct op_counter_config ctr[OP_MAX_COUNTER];

static int op_bfin_setup(void)
{
	int ret;

	/* Pre-compute the values to stuff in the hardware registers.  */
	spin_lock(&oprofilefs_lock);
	ret = model->reg_setup(ctr);
	spin_unlock(&oprofilefs_lock);

	return ret;
}

static void op_bfin_shutdown(void)
{
#if 0
	/* what is the difference between shutdown and stop? */
#endif
}

static int op_bfin_start(void)
{
	int ret = -EBUSY;

	printk(KERN_INFO "KSDBG:in %s\n", __func__);
	mutex_lock(&pfmon_lock);
	if (!pfmon_enabled) {
		ret = model->start(ctr);
		pfmon_enabled = !ret;
	}
	mutex_unlock(&pfmon_lock);

	return ret;
}

static void op_bfin_stop(void)
{
	mutex_lock(&pfmon_lock);
	if (pfmon_enabled) {
		model->stop();
		pfmon_enabled = 0;
	}
	mutex_unlock(&pfmon_lock);
}

static int op_bfin_create_files(struct super_block *sb, struct dentry *root)
{
	int i;

	for (i = 0; i < model->num_counters; ++i) {
		struct dentry *dir;
		char buf[3];
		printk(KERN_INFO "Oprofile: creating files... \n");

		snprintf(buf, sizeof buf, "%d", i);
		dir = oprofilefs_mkdir(sb, root, buf);

		oprofilefs_create_ulong(sb, dir, "enabled", &ctr[i].enabled);
		oprofilefs_create_ulong(sb, dir, "event", &ctr[i].event);
		oprofilefs_create_ulong(sb, dir, "count", &ctr[i].count);
		/*
		 * We dont support per counter user/kernel selection, but
		 * we leave the entries because userspace expects them
		 */
		oprofilefs_create_ulong(sb, dir, "kernel", &ctr[i].kernel);
		oprofilefs_create_ulong(sb, dir, "user", &ctr[i].user);
		oprofilefs_create_ulong(sb, dir, "unit_mask",
					&ctr[i].unit_mask);
	}

	return 0;
}
int __init oprofile_arch_init(struct oprofile_operations *ops)
{
#ifdef CONFIG_HARDWARE_PM
	unsigned int dspid;

	mutex_init(&pfmon_lock);

	dspid = bfin_read_DSPID();

	printk(KERN_INFO "Oprofile got the cpu id is 0x%x. \n", dspid);

	switch (dspid) {
	case BFIN_533_ID:
		model = &op_model_bfin533;
		model->num_counters = 2;
		break;
	case BFIN_537_ID:
		model = &op_model_bfin533;
		model->num_counters = 2;
		break;
	default:
		return -ENODEV;
	}

	ops->cpu_type = model->name;
	ops->create_files = op_bfin_create_files;
	ops->setup = op_bfin_setup;
	ops->shutdown = op_bfin_shutdown;
	ops->start = op_bfin_start;
	ops->stop = op_bfin_stop;

	printk(KERN_INFO "oprofile: using %s performance monitoring.\n",
	       ops->cpu_type);

	return 0;
#else
	return -1;
#endif
}

void oprofile_arch_exit(void)
{
}