gus_mem_proc.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Copyright (c) by Jaroslav Kysela <perex@suse.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 <sound/driver.h>
  22. #include <linux/slab.h>
  23. #include <sound/core.h>
  24. #include <sound/gus.h>
  25. #include <sound/info.h>
  26. struct gus_proc_private {
  27. int rom; /* data are in ROM */
  28. unsigned int address;
  29. unsigned int size;
  30. struct snd_gus_card * gus;
  31. };
  32. static long snd_gf1_mem_proc_dump(struct snd_info_entry *entry, void *file_private_data,
  33. struct file *file, char __user *buf,
  34. unsigned long count, unsigned long pos)
  35. {
  36. long size;
  37. struct gus_proc_private *priv = entry->private_data;
  38. struct snd_gus_card *gus = priv->gus;
  39. int err;
  40. size = count;
  41. if (pos + size > priv->size)
  42. size = (long)priv->size - pos;
  43. if (size > 0) {
  44. if ((err = snd_gus_dram_read(gus, buf, pos, size, priv->rom)) < 0)
  45. return err;
  46. return size;
  47. }
  48. return 0;
  49. }
  50. static long long snd_gf1_mem_proc_llseek(struct snd_info_entry *entry,
  51. void *private_file_data,
  52. struct file *file,
  53. long long offset,
  54. int orig)
  55. {
  56. struct gus_proc_private *priv = entry->private_data;
  57. switch (orig) {
  58. case 0: /* SEEK_SET */
  59. file->f_pos = offset;
  60. break;
  61. case 1: /* SEEK_CUR */
  62. file->f_pos += offset;
  63. break;
  64. case 2: /* SEEK_END, offset is negative */
  65. file->f_pos = priv->size + offset;
  66. break;
  67. default:
  68. return -EINVAL;
  69. }
  70. if (file->f_pos > priv->size)
  71. file->f_pos = priv->size;
  72. return file->f_pos;
  73. }
  74. static void snd_gf1_mem_proc_free(struct snd_info_entry *entry)
  75. {
  76. struct gus_proc_private *priv = entry->private_data;
  77. kfree(priv);
  78. }
  79. static struct snd_info_entry_ops snd_gf1_mem_proc_ops = {
  80. .read = snd_gf1_mem_proc_dump,
  81. .llseek = snd_gf1_mem_proc_llseek,
  82. };
  83. int snd_gf1_mem_proc_init(struct snd_gus_card * gus)
  84. {
  85. int idx;
  86. char name[16];
  87. struct gus_proc_private *priv;
  88. struct snd_info_entry *entry;
  89. for (idx = 0; idx < 4; idx++) {
  90. if (gus->gf1.mem_alloc.banks_8[idx].size > 0) {
  91. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  92. if (priv == NULL)
  93. return -ENOMEM;
  94. priv->gus = gus;
  95. sprintf(name, "gus-ram-%i", idx);
  96. if (! snd_card_proc_new(gus->card, name, &entry)) {
  97. entry->content = SNDRV_INFO_CONTENT_DATA;
  98. entry->private_data = priv;
  99. entry->private_free = snd_gf1_mem_proc_free;
  100. entry->c.ops = &snd_gf1_mem_proc_ops;
  101. priv->address = gus->gf1.mem_alloc.banks_8[idx].address;
  102. priv->size = entry->size = gus->gf1.mem_alloc.banks_8[idx].size;
  103. }
  104. }
  105. }
  106. for (idx = 0; idx < 4; idx++) {
  107. if (gus->gf1.rom_present & (1 << idx)) {
  108. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  109. if (priv == NULL)
  110. return -ENOMEM;
  111. priv->rom = 1;
  112. priv->gus = gus;
  113. sprintf(name, "gus-rom-%i", idx);
  114. if (! snd_card_proc_new(gus->card, name, &entry)) {
  115. entry->content = SNDRV_INFO_CONTENT_DATA;
  116. entry->private_data = priv;
  117. entry->private_free = snd_gf1_mem_proc_free;
  118. entry->c.ops = &snd_gf1_mem_proc_ops;
  119. priv->address = idx * 4096 * 1024;
  120. priv->size = entry->size = gus->gf1.rom_memory;
  121. }
  122. }
  123. }
  124. return 0;
  125. }