opl4_proc.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 <sound/info.h>
  22. #ifdef CONFIG_PROC_FS
  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. long size;
  52. char* buf;
  53. size = count;
  54. if (pos + size > entry->size)
  55. size = entry->size - pos;
  56. if (size > 0) {
  57. buf = vmalloc(size);
  58. if (!buf)
  59. return -ENOMEM;
  60. snd_opl4_read_memory(opl4, buf, pos, size);
  61. if (copy_to_user(_buf, buf, size)) {
  62. vfree(buf);
  63. return -EFAULT;
  64. }
  65. vfree(buf);
  66. return size;
  67. }
  68. return 0;
  69. }
  70. static ssize_t snd_opl4_mem_proc_write(struct snd_info_entry *entry,
  71. void *file_private_data,
  72. struct file *file,
  73. const char __user *_buf,
  74. size_t count, size_t pos)
  75. {
  76. struct snd_opl4 *opl4 = entry->private_data;
  77. long size;
  78. char *buf;
  79. size = count;
  80. if (pos + size > entry->size)
  81. size = entry->size - pos;
  82. if (size > 0) {
  83. buf = vmalloc(size);
  84. if (!buf)
  85. return -ENOMEM;
  86. if (copy_from_user(buf, _buf, size)) {
  87. vfree(buf);
  88. return -EFAULT;
  89. }
  90. snd_opl4_write_memory(opl4, buf, pos, size);
  91. vfree(buf);
  92. return size;
  93. }
  94. return 0;
  95. }
  96. static loff_t snd_opl4_mem_proc_llseek(struct snd_info_entry *entry,
  97. void *file_private_data,
  98. struct file *file,
  99. loff_t offset, int orig)
  100. {
  101. switch (orig) {
  102. case SEEK_SET:
  103. file->f_pos = offset;
  104. break;
  105. case SEEK_CUR:
  106. file->f_pos += offset;
  107. break;
  108. case SEEK_END: /* offset is negative */
  109. file->f_pos = entry->size + offset;
  110. break;
  111. default:
  112. return -EINVAL;
  113. }
  114. if (file->f_pos > entry->size)
  115. file->f_pos = entry->size;
  116. return file->f_pos;
  117. }
  118. static struct snd_info_entry_ops snd_opl4_mem_proc_ops = {
  119. .open = snd_opl4_mem_proc_open,
  120. .release = snd_opl4_mem_proc_release,
  121. .read = snd_opl4_mem_proc_read,
  122. .write = snd_opl4_mem_proc_write,
  123. .llseek = snd_opl4_mem_proc_llseek,
  124. };
  125. int snd_opl4_create_proc(struct snd_opl4 *opl4)
  126. {
  127. struct snd_info_entry *entry;
  128. entry = snd_info_create_card_entry(opl4->card, "opl4-mem", opl4->card->proc_root);
  129. if (entry) {
  130. if (opl4->hardware < OPL3_HW_OPL4_ML) {
  131. /* OPL4 can access 4 MB external ROM/SRAM */
  132. entry->mode |= S_IWUSR;
  133. entry->size = 4 * 1024 * 1024;
  134. } else {
  135. /* OPL4-ML has 1 MB internal ROM */
  136. entry->size = 1 * 1024 * 1024;
  137. }
  138. entry->content = SNDRV_INFO_CONTENT_DATA;
  139. entry->c.ops = &snd_opl4_mem_proc_ops;
  140. entry->module = THIS_MODULE;
  141. entry->private_data = opl4;
  142. if (snd_info_register(entry) < 0) {
  143. snd_info_free_entry(entry);
  144. entry = NULL;
  145. }
  146. }
  147. opl4->proc_entry = entry;
  148. return 0;
  149. }
  150. void snd_opl4_free_proc(struct snd_opl4 *opl4)
  151. {
  152. snd_info_free_entry(opl4->proc_entry);
  153. }
  154. #endif /* CONFIG_PROC_FS */