gus_mem_proc.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 ssize_t snd_gf1_mem_proc_dump(struct snd_info_entry *entry,
  32. void *file_private_data,
  33. struct file *file, char __user *buf,
  34. size_t count, loff_t pos)
  35. {
  36. struct gus_proc_private *priv = entry->private_data;
  37. struct snd_gus_card *gus = priv->gus;
  38. int err;
  39. err = snd_gus_dram_read(gus, buf, pos, count, priv->rom);
  40. if (err < 0)
  41. return err;
  42. return count;
  43. }
  44. static void snd_gf1_mem_proc_free(struct snd_info_entry *entry)
  45. {
  46. struct gus_proc_private *priv = entry->private_data;
  47. kfree(priv);
  48. }
  49. static struct snd_info_entry_ops snd_gf1_mem_proc_ops = {
  50. .read = snd_gf1_mem_proc_dump,
  51. };
  52. int snd_gf1_mem_proc_init(struct snd_gus_card * gus)
  53. {
  54. int idx;
  55. char name[16];
  56. struct gus_proc_private *priv;
  57. struct snd_info_entry *entry;
  58. for (idx = 0; idx < 4; idx++) {
  59. if (gus->gf1.mem_alloc.banks_8[idx].size > 0) {
  60. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  61. if (priv == NULL)
  62. return -ENOMEM;
  63. priv->gus = gus;
  64. sprintf(name, "gus-ram-%i", idx);
  65. if (! snd_card_proc_new(gus->card, name, &entry)) {
  66. entry->content = SNDRV_INFO_CONTENT_DATA;
  67. entry->private_data = priv;
  68. entry->private_free = snd_gf1_mem_proc_free;
  69. entry->c.ops = &snd_gf1_mem_proc_ops;
  70. priv->address = gus->gf1.mem_alloc.banks_8[idx].address;
  71. priv->size = entry->size = gus->gf1.mem_alloc.banks_8[idx].size;
  72. }
  73. }
  74. }
  75. for (idx = 0; idx < 4; idx++) {
  76. if (gus->gf1.rom_present & (1 << idx)) {
  77. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  78. if (priv == NULL)
  79. return -ENOMEM;
  80. priv->rom = 1;
  81. priv->gus = gus;
  82. sprintf(name, "gus-rom-%i", idx);
  83. if (! snd_card_proc_new(gus->card, name, &entry)) {
  84. entry->content = SNDRV_INFO_CONTENT_DATA;
  85. entry->private_data = priv;
  86. entry->private_free = snd_gf1_mem_proc_free;
  87. entry->c.ops = &snd_gf1_mem_proc_ops;
  88. priv->address = idx * 4096 * 1024;
  89. priv->size = entry->size = gus->gf1.rom_memory;
  90. }
  91. }
  92. }
  93. return 0;
  94. }