common.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * File: arch/blackfin/oprofile/common.c
  3. * Based on: arch/alpha/oprofile/common.c
  4. * Author: Anton Blanchard <anton@au.ibm.com>
  5. *
  6. * Created:
  7. * Description:
  8. *
  9. * Modified:
  10. * Copyright (C) 2004 Anton Blanchard <anton@au.ibm.com>, IBM
  11. * Copyright 2004-2006 Analog Devices Inc.
  12. *
  13. * Bugs: Enter bugs at http://blackfin.uclinux.org/
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 2 of the License, or
  18. * (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, see the file COPYING, or write
  27. * to the Free Software Foundation, Inc.,
  28. * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  29. */
  30. #include <linux/oprofile.h>
  31. #include <linux/init.h>
  32. #include <linux/smp.h>
  33. #include <linux/errno.h>
  34. #include <linux/mutex.h>
  35. #include <linux/ptrace.h>
  36. #include <linux/irq.h>
  37. #include <linux/io.h>
  38. #include <asm/system.h>
  39. #include <asm/blackfin.h>
  40. #include "op_blackfin.h"
  41. #define BFIN_533_ID 0xE5040003
  42. #define BFIN_537_ID 0xE5040002
  43. static int pfmon_enabled;
  44. static struct mutex pfmon_lock;
  45. struct op_bfin533_model *model;
  46. struct op_counter_config ctr[OP_MAX_COUNTER];
  47. static int op_bfin_setup(void)
  48. {
  49. int ret;
  50. /* Pre-compute the values to stuff in the hardware registers. */
  51. spin_lock(&oprofilefs_lock);
  52. ret = model->reg_setup(ctr);
  53. spin_unlock(&oprofilefs_lock);
  54. return ret;
  55. }
  56. static void op_bfin_shutdown(void)
  57. {
  58. #if 0
  59. /* what is the difference between shutdown and stop? */
  60. #endif
  61. }
  62. static int op_bfin_start(void)
  63. {
  64. int ret = -EBUSY;
  65. printk(KERN_INFO "KSDBG:in %s\n", __FUNCTION__);
  66. mutex_lock(&pfmon_lock);
  67. if (!pfmon_enabled) {
  68. ret = model->start(ctr);
  69. pfmon_enabled = !ret;
  70. }
  71. mutex_unlock(&pfmon_lock);
  72. return ret;
  73. }
  74. static void op_bfin_stop(void)
  75. {
  76. mutex_lock(&pfmon_lock);
  77. if (pfmon_enabled) {
  78. model->stop();
  79. pfmon_enabled = 0;
  80. }
  81. mutex_unlock(&pfmon_lock);
  82. }
  83. static int op_bfin_create_files(struct super_block *sb, struct dentry *root)
  84. {
  85. int i;
  86. for (i = 0; i < model->num_counters; ++i) {
  87. struct dentry *dir;
  88. char buf[3];
  89. printk(KERN_INFO "Oprofile: creating files... \n");
  90. snprintf(buf, sizeof buf, "%d", i);
  91. dir = oprofilefs_mkdir(sb, root, buf);
  92. oprofilefs_create_ulong(sb, dir, "enabled", &ctr[i].enabled);
  93. oprofilefs_create_ulong(sb, dir, "event", &ctr[i].event);
  94. oprofilefs_create_ulong(sb, dir, "count", &ctr[i].count);
  95. /*
  96. * We dont support per counter user/kernel selection, but
  97. * we leave the entries because userspace expects them
  98. */
  99. oprofilefs_create_ulong(sb, dir, "kernel", &ctr[i].kernel);
  100. oprofilefs_create_ulong(sb, dir, "user", &ctr[i].user);
  101. oprofilefs_create_ulong(sb, dir, "unit_mask",
  102. &ctr[i].unit_mask);
  103. }
  104. return 0;
  105. }
  106. int __init oprofile_arch_init(struct oprofile_operations *ops)
  107. {
  108. #ifdef CONFIG_HARDWARE_PM
  109. unsigned int dspid;
  110. mutex_init(&pfmon_lock);
  111. dspid = bfin_read_DSPID();
  112. printk(KERN_INFO "Oprofile got the cpu id is 0x%x. \n", dspid);
  113. switch (dspid) {
  114. case BFIN_533_ID:
  115. model = &op_model_bfin533;
  116. model->num_counters = 2;
  117. break;
  118. case BFIN_537_ID:
  119. model = &op_model_bfin533;
  120. model->num_counters = 2;
  121. break;
  122. default:
  123. return -ENODEV;
  124. }
  125. ops->cpu_type = model->name;
  126. ops->create_files = op_bfin_create_files;
  127. ops->setup = op_bfin_setup;
  128. ops->shutdown = op_bfin_shutdown;
  129. ops->start = op_bfin_start;
  130. ops->stop = op_bfin_stop;
  131. printk(KERN_INFO "oprofile: using %s performance monitoring.\n",
  132. ops->cpu_type);
  133. return 0;
  134. #else
  135. return -1;
  136. #endif
  137. }
  138. void oprofile_arch_exit(void)
  139. {
  140. }