opl4_proc.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. static int snd_opl4_mem_proc_open(struct snd_info_entry *entry,
  24. unsigned short mode, void **file_private_data)
  25. {
  26. struct snd_opl4 *opl4 = entry->private_data;
  27. mutex_lock(&opl4->access_mutex);
  28. if (opl4->memory_access) {
  29. mutex_unlock(&opl4->access_mutex);
  30. return -EBUSY;
  31. }
  32. opl4->memory_access++;
  33. mutex_unlock(&opl4->access_mutex);
  34. return 0;
  35. }
  36. static int snd_opl4_mem_proc_release(struct snd_info_entry *entry,
  37. unsigned short mode, void *file_private_data)
  38. {
  39. struct snd_opl4 *opl4 = entry->private_data;
  40. mutex_lock(&opl4->access_mutex);
  41. opl4->memory_access--;
  42. mutex_unlock(&opl4->access_mutex);
  43. return 0;
  44. }
  45. static ssize_t snd_opl4_mem_proc_read(struct snd_info_entry *entry,
  46. void *file_private_data,
  47. struct file *file, char __user *_buf,
  48. size_t count, loff_t pos)
  49. {
  50. struct snd_opl4 *opl4 = entry->private_data;
  51. char* buf;
  52. buf = vmalloc(count);
  53. if (!buf)
  54. return -ENOMEM;
  55. snd_opl4_read_memory(opl4, buf, pos, count);
  56. if (copy_to_user(_buf, buf, count)) {
  57. vfree(buf);
  58. return -EFAULT;
  59. }
  60. vfree(buf);
  61. return count;
  62. }
  63. static ssize_t snd_opl4_mem_proc_write(struct snd_info_entry *entry,
  64. void *file_private_data,
  65. struct file *file,
  66. const char __user *_buf,
  67. size_t count, loff_t pos)
  68. {
  69. struct snd_opl4 *opl4 = entry->private_data;
  70. char *buf;
  71. buf = vmalloc(count);
  72. if (!buf)
  73. return -ENOMEM;
  74. if (copy_from_user(buf, _buf, count)) {
  75. vfree(buf);
  76. return -EFAULT;
  77. }
  78. snd_opl4_write_memory(opl4, buf, pos, count);
  79. vfree(buf);
  80. return count;
  81. }
  82. static struct snd_info_entry_ops snd_opl4_mem_proc_ops = {
  83. .open = snd_opl4_mem_proc_open,
  84. .release = snd_opl4_mem_proc_release,
  85. .read = snd_opl4_mem_proc_read,
  86. .write = snd_opl4_mem_proc_write,
  87. };
  88. int snd_opl4_create_proc(struct snd_opl4 *opl4)
  89. {
  90. struct snd_info_entry *entry;
  91. entry = snd_info_create_card_entry(opl4->card, "opl4-mem", opl4->card->proc_root);
  92. if (entry) {
  93. if (opl4->hardware < OPL3_HW_OPL4_ML) {
  94. /* OPL4 can access 4 MB external ROM/SRAM */
  95. entry->mode |= S_IWUSR;
  96. entry->size = 4 * 1024 * 1024;
  97. } else {
  98. /* OPL4-ML has 1 MB internal ROM */
  99. entry->size = 1 * 1024 * 1024;
  100. }
  101. entry->content = SNDRV_INFO_CONTENT_DATA;
  102. entry->c.ops = &snd_opl4_mem_proc_ops;
  103. entry->module = THIS_MODULE;
  104. entry->private_data = opl4;
  105. if (snd_info_register(entry) < 0) {
  106. snd_info_free_entry(entry);
  107. entry = NULL;
  108. }
  109. }
  110. opl4->proc_entry = entry;
  111. return 0;
  112. }
  113. void snd_opl4_free_proc(struct snd_opl4 *opl4)
  114. {
  115. snd_info_free_entry(opl4->proc_entry);
  116. }