gus_mem_proc.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (c) by Jaroslav Kysela <[email protected]>
  4. * GUS's memory access via proc filesystem
  5. */
  6. #include <linux/slab.h>
  7. #include <sound/core.h>
  8. #include <sound/gus.h>
  9. #include <sound/info.h>
  10. struct gus_proc_private {
  11. int rom; /* data are in ROM */
  12. unsigned int address;
  13. unsigned int size;
  14. struct snd_gus_card * gus;
  15. };
  16. static ssize_t snd_gf1_mem_proc_dump(struct snd_info_entry *entry,
  17. void *file_private_data,
  18. struct file *file, char __user *buf,
  19. size_t count, loff_t pos)
  20. {
  21. struct gus_proc_private *priv = entry->private_data;
  22. struct snd_gus_card *gus = priv->gus;
  23. int err;
  24. err = snd_gus_dram_read(gus, buf, pos, count, priv->rom);
  25. if (err < 0)
  26. return err;
  27. return count;
  28. }
  29. static void snd_gf1_mem_proc_free(struct snd_info_entry *entry)
  30. {
  31. struct gus_proc_private *priv = entry->private_data;
  32. kfree(priv);
  33. }
  34. static const struct snd_info_entry_ops snd_gf1_mem_proc_ops = {
  35. .read = snd_gf1_mem_proc_dump,
  36. };
  37. int snd_gf1_mem_proc_init(struct snd_gus_card * gus)
  38. {
  39. int idx;
  40. char name[16];
  41. struct gus_proc_private *priv;
  42. struct snd_info_entry *entry;
  43. for (idx = 0; idx < 4; idx++) {
  44. if (gus->gf1.mem_alloc.banks_8[idx].size > 0) {
  45. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  46. if (priv == NULL)
  47. return -ENOMEM;
  48. priv->gus = gus;
  49. sprintf(name, "gus-ram-%i", idx);
  50. if (! snd_card_proc_new(gus->card, name, &entry)) {
  51. entry->content = SNDRV_INFO_CONTENT_DATA;
  52. entry->private_data = priv;
  53. entry->private_free = snd_gf1_mem_proc_free;
  54. entry->c.ops = &snd_gf1_mem_proc_ops;
  55. priv->address = gus->gf1.mem_alloc.banks_8[idx].address;
  56. priv->size = entry->size = gus->gf1.mem_alloc.banks_8[idx].size;
  57. }
  58. }
  59. }
  60. for (idx = 0; idx < 4; idx++) {
  61. if (gus->gf1.rom_present & (1 << idx)) {
  62. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  63. if (priv == NULL)
  64. return -ENOMEM;
  65. priv->rom = 1;
  66. priv->gus = gus;
  67. sprintf(name, "gus-rom-%i", idx);
  68. if (! snd_card_proc_new(gus->card, name, &entry)) {
  69. entry->content = SNDRV_INFO_CONTENT_DATA;
  70. entry->private_data = priv;
  71. entry->private_free = snd_gf1_mem_proc_free;
  72. entry->c.ops = &snd_gf1_mem_proc_ops;
  73. priv->address = idx * 4096 * 1024;
  74. priv->size = entry->size = gus->gf1.rom_memory;
  75. }
  76. }
  77. }
  78. return 0;
  79. }