info_oss.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Information interface for ALSA driver
  4. * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
  5. */
  6. #include <linux/slab.h>
  7. #include <linux/time.h>
  8. #include <linux/string.h>
  9. #include <linux/export.h>
  10. #include <sound/core.h>
  11. #include <sound/minors.h>
  12. #include <sound/info.h>
  13. #include <linux/utsname.h>
  14. #include <linux/mutex.h>
  15. /*
  16. * OSS compatible part
  17. */
  18. static DEFINE_MUTEX(strings);
  19. static char *snd_sndstat_strings[SNDRV_CARDS][SNDRV_OSS_INFO_DEV_COUNT];
  20. int snd_oss_info_register(int dev, int num, char *string)
  21. {
  22. char *x;
  23. if (snd_BUG_ON(dev < 0 || dev >= SNDRV_OSS_INFO_DEV_COUNT))
  24. return -ENXIO;
  25. if (snd_BUG_ON(num < 0 || num >= SNDRV_CARDS))
  26. return -ENXIO;
  27. guard(mutex)(&strings);
  28. if (string == NULL) {
  29. x = snd_sndstat_strings[num][dev];
  30. kfree(x);
  31. x = NULL;
  32. } else {
  33. x = kstrdup(string, GFP_KERNEL);
  34. if (x == NULL)
  35. return -ENOMEM;
  36. }
  37. snd_sndstat_strings[num][dev] = x;
  38. return 0;
  39. }
  40. EXPORT_SYMBOL(snd_oss_info_register);
  41. static int snd_sndstat_show_strings(struct snd_info_buffer *buf, char *id, int dev)
  42. {
  43. int idx, ok = -1;
  44. char *str;
  45. snd_iprintf(buf, "\n%s:", id);
  46. guard(mutex)(&strings);
  47. for (idx = 0; idx < SNDRV_CARDS; idx++) {
  48. str = snd_sndstat_strings[idx][dev];
  49. if (str) {
  50. if (ok < 0) {
  51. snd_iprintf(buf, "\n");
  52. ok++;
  53. }
  54. snd_iprintf(buf, "%i: %s\n", idx, str);
  55. }
  56. }
  57. if (ok < 0)
  58. snd_iprintf(buf, " NOT ENABLED IN CONFIG\n");
  59. return ok;
  60. }
  61. static void snd_sndstat_proc_read(struct snd_info_entry *entry,
  62. struct snd_info_buffer *buffer)
  63. {
  64. snd_iprintf(buffer, "Sound Driver:3.8.1a-980706 (ALSA emulation code)\n");
  65. snd_iprintf(buffer, "Kernel: %s %s %s %s %s\n",
  66. init_utsname()->sysname,
  67. init_utsname()->nodename,
  68. init_utsname()->release,
  69. init_utsname()->version,
  70. init_utsname()->machine);
  71. snd_iprintf(buffer, "Config options: 0\n");
  72. snd_iprintf(buffer, "\nInstalled drivers: \n");
  73. snd_iprintf(buffer, "Type 10: ALSA emulation\n");
  74. snd_iprintf(buffer, "\nCard config: \n");
  75. snd_card_info_read_oss(buffer);
  76. snd_sndstat_show_strings(buffer, "Audio devices", SNDRV_OSS_INFO_DEV_AUDIO);
  77. snd_sndstat_show_strings(buffer, "Synth devices", SNDRV_OSS_INFO_DEV_SYNTH);
  78. snd_sndstat_show_strings(buffer, "Midi devices", SNDRV_OSS_INFO_DEV_MIDI);
  79. snd_sndstat_show_strings(buffer, "Timers", SNDRV_OSS_INFO_DEV_TIMERS);
  80. snd_sndstat_show_strings(buffer, "Mixers", SNDRV_OSS_INFO_DEV_MIXERS);
  81. }
  82. int __init snd_info_minor_register(void)
  83. {
  84. struct snd_info_entry *entry;
  85. memset(snd_sndstat_strings, 0, sizeof(snd_sndstat_strings));
  86. entry = snd_info_create_module_entry(THIS_MODULE, "sndstat",
  87. snd_oss_root);
  88. if (!entry)
  89. return -ENOMEM;
  90. entry->c.text.read = snd_sndstat_proc_read;
  91. return snd_info_register(entry); /* freed in error path */
  92. }