opl4_proc.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Functions for the OPL4 proc file
  3. * Copyright (c) 2003 by Clemens Ladisch <clemens@ladisch.de>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #include "opl4_local.h"
  20. #include <linux/vmalloc.h>
  21. #include <linux/export.h>
  22. #include <sound/info.h>
  23. #ifdef CONFIG_PROC_FS
  24. static int snd_opl4_mem_proc_open(struct snd_info_entry *entry,
  25. unsigned short mode, void **file_private_data)
  26. {
  27. struct snd_opl4 *opl4 = entry->private_data;
  28. mutex_lock(&opl4->access_mutex);
  29. if (opl4->memory_access) {
  30. mutex_unlock(&opl4->access_mutex);
  31. return -EBUSY;
  32. }
  33. opl4->memory_access++;
  34. mutex_unlock(&opl4->access_mutex);
  35. return 0;
  36. }
  37. static int snd_opl4_mem_proc_release(struct snd_info_entry *entry,
  38. unsigned short mode, void *file_private_data)
  39. {
  40. struct snd_opl4 *opl4 = entry->private_data;
  41. mutex_lock(&opl4->access_mutex);
  42. opl4->memory_access--;
  43. mutex_unlock(&opl4->access_mutex);
  44. return 0;
  45. }
  46. static ssize_t snd_opl4_mem_proc_read(struct snd_info_entry *entry,
  47. void *file_private_data,
  48. struct file *file, char __user *_buf,
  49. size_t count, loff_t pos)
  50. {
  51. struct snd_opl4 *opl4 = entry->private_data;
  52. char* buf;
  53. buf = vmalloc(count);
  54. if (!buf)
  55. return -ENOMEM;
  56. snd_opl4_read_memory(opl4, buf, pos, count);
  57. if (copy_to_user(_buf, buf, count)) {
  58. vfree(buf);
  59. return -EFAULT;
  60. }
  61. vfree(buf);
  62. return count;
  63. }
  64. static ssize_t snd_opl4_mem_proc_write(struct snd_info_entry *entry,
  65. void *file_private_data,
  66. struct file *file,
  67. const char __user *_buf,
  68. size_t count, loff_t pos)
  69. {
  70. struct snd_opl4 *opl4 = entry->private_data;
  71. char *buf;
  72. buf = vmalloc(count);
  73. if (!buf)
  74. return -ENOMEM;
  75. if (copy_from_user(buf, _buf, count)) {
  76. vfree(buf);
  77. return -EFAULT;
  78. }
  79. snd_opl4_write_memory(opl4, buf, pos, count);
  80. vfree(buf);
  81. return count;
  82. }
  83. static struct snd_info_entry_ops snd_opl4_mem_proc_ops = {
  84. .open = snd_opl4_mem_proc_open,
  85. .release = snd_opl4_mem_proc_release,
  86. .read = snd_opl4_mem_proc_read,
  87. .write = snd_opl4_mem_proc_write,
  88. };
  89. int snd_opl4_create_proc(struct snd_opl4 *opl4)
  90. {
  91. struct snd_info_entry *entry;
  92. entry = snd_info_create_card_entry(opl4->card, "opl4-mem", opl4->card->proc_root);
  93. if (entry) {
  94. if (opl4->hardware < OPL3_HW_OPL4_ML) {
  95. /* OPL4 can access 4 MB external ROM/SRAM */
  96. entry->mode |= S_IWUSR;
  97. entry->size = 4 * 1024 * 1024;
  98. } else {
  99. /* OPL4-ML has 1 MB internal ROM */
  100. entry->size = 1 * 1024 * 1024;
  101. }
  102. entry->content = SNDRV_INFO_CONTENT_DATA;
  103. entry->c.ops = &snd_opl4_mem_proc_ops;
  104. entry->module = THIS_MODULE;
  105. entry->private_data = opl4;
  106. if (snd_info_register(entry) < 0) {
  107. snd_info_free_entry(entry);
  108. entry = NULL;
  109. }
  110. }
  111. opl4->proc_entry = entry;
  112. return 0;
  113. }
  114. void snd_opl4_free_proc(struct snd_opl4 *opl4)
  115. {
  116. snd_info_free_entry(opl4->proc_entry);
  117. }
  118. #endif /* CONFIG_PROC_FS */