2
0

soundhw.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * QEMU System Emulator
  3. *
  4. * Copyright (c) 2003-2008 Fabrice Bellard
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. */
  24. #include "qemu/osdep.h"
  25. #include "qemu/help_option.h"
  26. #include "qemu/error-report.h"
  27. #include "qom/object.h"
  28. #include "hw/isa/isa.h"
  29. #include "hw/pci/pci.h"
  30. #include "hw/audio/soundhw.h"
  31. struct soundhw {
  32. const char *name;
  33. const char *descr;
  34. int enabled;
  35. int isa;
  36. union {
  37. int (*init_isa) (ISABus *bus);
  38. int (*init_pci) (PCIBus *bus);
  39. } init;
  40. };
  41. static struct soundhw soundhw[9];
  42. static int soundhw_count;
  43. void isa_register_soundhw(const char *name, const char *descr,
  44. int (*init_isa)(ISABus *bus))
  45. {
  46. assert(soundhw_count < ARRAY_SIZE(soundhw) - 1);
  47. soundhw[soundhw_count].name = name;
  48. soundhw[soundhw_count].descr = descr;
  49. soundhw[soundhw_count].isa = 1;
  50. soundhw[soundhw_count].init.init_isa = init_isa;
  51. soundhw_count++;
  52. }
  53. void pci_register_soundhw(const char *name, const char *descr,
  54. int (*init_pci)(PCIBus *bus))
  55. {
  56. assert(soundhw_count < ARRAY_SIZE(soundhw) - 1);
  57. soundhw[soundhw_count].name = name;
  58. soundhw[soundhw_count].descr = descr;
  59. soundhw[soundhw_count].isa = 0;
  60. soundhw[soundhw_count].init.init_pci = init_pci;
  61. soundhw_count++;
  62. }
  63. void select_soundhw(const char *optarg)
  64. {
  65. struct soundhw *c;
  66. if (is_help_option(optarg)) {
  67. show_valid_cards:
  68. if (soundhw_count) {
  69. printf("Valid sound card names (comma separated):\n");
  70. for (c = soundhw; c->name; ++c) {
  71. printf ("%-11s %s\n", c->name, c->descr);
  72. }
  73. printf("\n-soundhw all will enable all of the above\n");
  74. } else {
  75. printf("Machine has no user-selectable audio hardware "
  76. "(it may or may not have always-present audio hardware).\n");
  77. }
  78. exit(!is_help_option(optarg));
  79. }
  80. else {
  81. size_t l;
  82. const char *p;
  83. char *e;
  84. int bad_card = 0;
  85. if (!strcmp(optarg, "all")) {
  86. for (c = soundhw; c->name; ++c) {
  87. c->enabled = 1;
  88. }
  89. return;
  90. }
  91. p = optarg;
  92. while (*p) {
  93. e = strchr(p, ',');
  94. l = !e ? strlen(p) : (size_t) (e - p);
  95. for (c = soundhw; c->name; ++c) {
  96. if (!strncmp(c->name, p, l) && !c->name[l]) {
  97. c->enabled = 1;
  98. break;
  99. }
  100. }
  101. if (!c->name) {
  102. if (l > 80) {
  103. error_report("Unknown sound card name (too big to show)");
  104. }
  105. else {
  106. error_report("Unknown sound card name `%.*s'",
  107. (int) l, p);
  108. }
  109. bad_card = 1;
  110. }
  111. p += l + (e != NULL);
  112. }
  113. if (bad_card) {
  114. goto show_valid_cards;
  115. }
  116. }
  117. }
  118. void soundhw_init(void)
  119. {
  120. struct soundhw *c;
  121. ISABus *isa_bus = (ISABus *) object_resolve_path_type("", TYPE_ISA_BUS, NULL);
  122. PCIBus *pci_bus = (PCIBus *) object_resolve_path_type("", TYPE_PCI_BUS, NULL);
  123. for (c = soundhw; c->name; ++c) {
  124. if (c->enabled) {
  125. if (c->isa) {
  126. if (!isa_bus) {
  127. error_report("ISA bus not available for %s", c->name);
  128. exit(1);
  129. }
  130. c->init.init_isa(isa_bus);
  131. } else {
  132. if (!pci_bus) {
  133. error_report("PCI bus not available for %s", c->name);
  134. exit(1);
  135. }
  136. c->init.init_pci(pci_bus);
  137. }
  138. }
  139. }
  140. }