info_oss.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. mutex_lock(&strings);
  28. if (string == NULL) {
  29. if ((x = snd_sndstat_strings[num][dev]) != NULL) {
  30. kfree(x);
  31. x = NULL;
  32. }
  33. } else {
  34. x = kstrdup(string, GFP_KERNEL);
  35. if (x == NULL) {
  36. mutex_unlock(&strings);
  37. return -ENOMEM;
  38. }
  39. }
  40. snd_sndstat_strings[num][dev] = x;
  41. mutex_unlock(&strings);
  42. return 0;
  43. }
  44. EXPORT_SYMBOL(snd_oss_info_register);
  45. static int snd_sndstat_show_strings(struct snd_info_buffer *buf, char *id, int dev)
  46. {
  47. int idx, ok = -1;
  48. char *str;
  49. snd_iprintf(buf, "\n%s:", id);
  50. mutex_lock(&strings);
  51. for (idx = 0; idx < SNDRV_CARDS; idx++) {
  52. str = snd_sndstat_strings[idx][dev];
  53. if (str) {
  54. if (ok < 0) {
  55. snd_iprintf(buf, "\n");
  56. ok++;
  57. }
  58. snd_iprintf(buf, "%i: %s\n", idx, str);
  59. }
  60. }
  61. mutex_unlock(&strings);
  62. if (ok < 0)
  63. snd_iprintf(buf, " NOT ENABLED IN CONFIG\n");
  64. return ok;
  65. }
  66. static void snd_sndstat_proc_read(struct snd_info_entry *entry,
  67. struct snd_info_buffer *buffer)
  68. {
  69. snd_iprintf(buffer, "Sound Driver:3.8.1a-980706 (ALSA emulation code)\n");
  70. snd_iprintf(buffer, "Kernel: %s %s %s %s %s\n",
  71. init_utsname()->sysname,
  72. init_utsname()->nodename,
  73. init_utsname()->release,
  74. init_utsname()->version,
  75. init_utsname()->machine);
  76. snd_iprintf(buffer, "Config options: 0\n");
  77. snd_iprintf(buffer, "\nInstalled drivers: \n");
  78. snd_iprintf(buffer, "Type 10: ALSA emulation\n");
  79. snd_iprintf(buffer, "\nCard config: \n");
  80. snd_card_info_read_oss(buffer);
  81. snd_sndstat_show_strings(buffer, "Audio devices", SNDRV_OSS_INFO_DEV_AUDIO);
  82. snd_sndstat_show_strings(buffer, "Synth devices", SNDRV_OSS_INFO_DEV_SYNTH);
  83. snd_sndstat_show_strings(buffer, "Midi devices", SNDRV_OSS_INFO_DEV_MIDI);
  84. snd_sndstat_show_strings(buffer, "Timers", SNDRV_OSS_INFO_DEV_TIMERS);
  85. snd_sndstat_show_strings(buffer, "Mixers", SNDRV_OSS_INFO_DEV_MIXERS);
  86. }
  87. int __init snd_info_minor_register(void)
  88. {
  89. struct snd_info_entry *entry;
  90. memset(snd_sndstat_strings, 0, sizeof(snd_sndstat_strings));
  91. entry = snd_info_create_module_entry(THIS_MODULE, "sndstat",
  92. snd_oss_root);
  93. if (!entry)
  94. return -ENOMEM;
  95. entry->c.text.read = snd_sndstat_proc_read;
  96. return snd_info_register(entry); /* freed in error path */
  97. }