opl4_proc.c 2.6 KB

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