gus_mem_proc.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
  3. * GUS's memory access via proc filesystem
  4. *
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. */
  21. #include <linux/slab.h>
  22. #include <sound/core.h>
  23. #include <sound/gus.h>
  24. #include <sound/info.h>
  25. struct gus_proc_private {
  26. int rom; /* data are in ROM */
  27. unsigned int address;
  28. unsigned int size;
  29. struct snd_gus_card * gus;
  30. };
  31. static long snd_gf1_mem_proc_dump(struct snd_info_entry *entry, void *file_private_data,
  32. struct file *file, char __user *buf,
  33. unsigned long count, unsigned long pos)
  34. {
  35. long size;
  36. struct gus_proc_private *priv = entry->private_data;
  37. struct snd_gus_card *gus = priv->gus;
  38. int err;
  39. size = count;
  40. if (pos + size > priv->size)
  41. size = (long)priv->size - pos;
  42. if (size > 0) {
  43. if ((err = snd_gus_dram_read(gus, buf, pos, size, priv->rom)) < 0)
  44. return err;
  45. return size;
  46. }
  47. return 0;
  48. }
  49. static long long snd_gf1_mem_proc_llseek(struct snd_info_entry *entry,
  50. void *private_file_data,
  51. struct file *file,
  52. long long offset,
  53. int orig)
  54. {
  55. struct gus_proc_private *priv = entry->private_data;
  56. switch (orig) {
  57. case SEEK_SET:
  58. file->f_pos = offset;
  59. break;
  60. case SEEK_CUR:
  61. file->f_pos += offset;
  62. break;
  63. case SEEK_END: /* offset is negative */
  64. file->f_pos = priv->size + offset;
  65. break;
  66. default:
  67. return -EINVAL;
  68. }
  69. if (file->f_pos > priv->size)
  70. file->f_pos = priv->size;
  71. return file->f_pos;
  72. }
  73. static void snd_gf1_mem_proc_free(struct snd_info_entry *entry)
  74. {
  75. struct gus_proc_private *priv = entry->private_data;
  76. kfree(priv);
  77. }
  78. static struct snd_info_entry_ops snd_gf1_mem_proc_ops = {
  79. .read = snd_gf1_mem_proc_dump,
  80. .llseek = snd_gf1_mem_proc_llseek,
  81. };
  82. int snd_gf1_mem_proc_init(struct snd_gus_card * gus)
  83. {
  84. int idx;
  85. char name[16];
  86. struct gus_proc_private *priv;
  87. struct snd_info_entry *entry;
  88. for (idx = 0; idx < 4; idx++) {
  89. if (gus->gf1.mem_alloc.banks_8[idx].size > 0) {
  90. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  91. if (priv == NULL)
  92. return -ENOMEM;
  93. priv->gus = gus;
  94. sprintf(name, "gus-ram-%i", idx);
  95. if (! snd_card_proc_new(gus->card, name, &entry)) {
  96. entry->content = SNDRV_INFO_CONTENT_DATA;
  97. entry->private_data = priv;
  98. entry->private_free = snd_gf1_mem_proc_free;
  99. entry->c.ops = &snd_gf1_mem_proc_ops;
  100. priv->address = gus->gf1.mem_alloc.banks_8[idx].address;
  101. priv->size = entry->size = gus->gf1.mem_alloc.banks_8[idx].size;
  102. }
  103. }
  104. }
  105. for (idx = 0; idx < 4; idx++) {
  106. if (gus->gf1.rom_present & (1 << idx)) {
  107. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  108. if (priv == NULL)
  109. return -ENOMEM;
  110. priv->rom = 1;
  111. priv->gus = gus;
  112. sprintf(name, "gus-rom-%i", idx);
  113. if (! snd_card_proc_new(gus->card, name, &entry)) {
  114. entry->content = SNDRV_INFO_CONTENT_DATA;
  115. entry->private_data = priv;
  116. entry->private_free = snd_gf1_mem_proc_free;
  117. entry->c.ops = &snd_gf1_mem_proc_ops;
  118. priv->address = idx * 4096 * 1024;
  119. priv->size = entry->size = gus->gf1.rom_memory;
  120. }
  121. }
  122. }
  123. return 0;
  124. }