opl4_proc.c 4.1 KB

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