opl4_proc.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Functions for the OPL4 proc file
  4. * Copyright (c) 2003 by Clemens Ladisch <clemens@ladisch.de>
  5. */
  6. #include "opl4_local.h"
  7. #include <linux/vmalloc.h>
  8. #include <linux/export.h>
  9. #include <sound/info.h>
  10. static int snd_opl4_mem_proc_open(struct snd_info_entry *entry,
  11. unsigned short mode, void **file_private_data)
  12. {
  13. struct snd_opl4 *opl4 = entry->private_data;
  14. mutex_lock(&opl4->access_mutex);
  15. if (opl4->memory_access) {
  16. mutex_unlock(&opl4->access_mutex);
  17. return -EBUSY;
  18. }
  19. opl4->memory_access++;
  20. mutex_unlock(&opl4->access_mutex);
  21. return 0;
  22. }
  23. static int snd_opl4_mem_proc_release(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. opl4->memory_access--;
  29. mutex_unlock(&opl4->access_mutex);
  30. return 0;
  31. }
  32. static ssize_t snd_opl4_mem_proc_read(struct snd_info_entry *entry,
  33. void *file_private_data,
  34. struct file *file, char __user *_buf,
  35. size_t count, loff_t pos)
  36. {
  37. struct snd_opl4 *opl4 = entry->private_data;
  38. char* buf;
  39. buf = vmalloc(count);
  40. if (!buf)
  41. return -ENOMEM;
  42. snd_opl4_read_memory(opl4, buf, pos, count);
  43. if (copy_to_user(_buf, buf, count)) {
  44. vfree(buf);
  45. return -EFAULT;
  46. }
  47. vfree(buf);
  48. return count;
  49. }
  50. static ssize_t snd_opl4_mem_proc_write(struct snd_info_entry *entry,
  51. void *file_private_data,
  52. struct file *file,
  53. const char __user *_buf,
  54. size_t count, loff_t pos)
  55. {
  56. struct snd_opl4 *opl4 = entry->private_data;
  57. char *buf;
  58. buf = vmalloc(count);
  59. if (!buf)
  60. return -ENOMEM;
  61. if (copy_from_user(buf, _buf, count)) {
  62. vfree(buf);
  63. return -EFAULT;
  64. }
  65. snd_opl4_write_memory(opl4, buf, pos, count);
  66. vfree(buf);
  67. return count;
  68. }
  69. static const struct snd_info_entry_ops snd_opl4_mem_proc_ops = {
  70. .open = snd_opl4_mem_proc_open,
  71. .release = snd_opl4_mem_proc_release,
  72. .read = snd_opl4_mem_proc_read,
  73. .write = snd_opl4_mem_proc_write,
  74. };
  75. int snd_opl4_create_proc(struct snd_opl4 *opl4)
  76. {
  77. struct snd_info_entry *entry;
  78. entry = snd_info_create_card_entry(opl4->card, "opl4-mem", opl4->card->proc_root);
  79. if (entry) {
  80. if (opl4->hardware < OPL3_HW_OPL4_ML) {
  81. /* OPL4 can access 4 MB external ROM/SRAM */
  82. entry->mode |= 0200;
  83. entry->size = 4 * 1024 * 1024;
  84. } else {
  85. /* OPL4-ML has 1 MB internal ROM */
  86. entry->size = 1 * 1024 * 1024;
  87. }
  88. entry->content = SNDRV_INFO_CONTENT_DATA;
  89. entry->c.ops = &snd_opl4_mem_proc_ops;
  90. entry->module = THIS_MODULE;
  91. entry->private_data = opl4;
  92. }
  93. opl4->proc_entry = entry;
  94. return 0;
  95. }
  96. void snd_opl4_free_proc(struct snd_opl4 *opl4)
  97. {
  98. snd_info_free_entry(opl4->proc_entry);
  99. }