coroutine: Revert to constant batch size
[qemu/ar7.git] / hw / audio / soundhw.c
blobf7d94d7dfa19eb1bf24289ce1e7b38d9cd110997
1 /*
2 * QEMU System Emulator
4 * Copyright (c) 2003-2008 Fabrice Bellard
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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.
24 #include "qemu/osdep.h"
25 #include "qemu/option.h"
26 #include "qemu/help_option.h"
27 #include "qemu/error-report.h"
28 #include "qom/object.h"
29 #include "hw/isa/isa.h"
30 #include "hw/pci/pci.h"
31 #include "hw/audio/soundhw.h"
33 struct soundhw {
34 const char *name;
35 const char *descr;
36 const char *typename;
37 int enabled;
38 int isa;
39 int (*init_pci) (PCIBus *bus);
42 static struct soundhw soundhw[9];
43 static int soundhw_count;
45 void pci_register_soundhw(const char *name, const char *descr,
46 int (*init_pci)(PCIBus *bus))
48 assert(soundhw_count < ARRAY_SIZE(soundhw) - 1);
49 soundhw[soundhw_count].name = name;
50 soundhw[soundhw_count].descr = descr;
51 soundhw[soundhw_count].isa = 0;
52 soundhw[soundhw_count].init_pci = init_pci;
53 soundhw_count++;
56 void deprecated_register_soundhw(const char *name, const char *descr,
57 int isa, const char *typename)
59 assert(soundhw_count < ARRAY_SIZE(soundhw) - 1);
60 soundhw[soundhw_count].name = name;
61 soundhw[soundhw_count].descr = descr;
62 soundhw[soundhw_count].isa = isa;
63 soundhw[soundhw_count].typename = typename;
64 soundhw_count++;
67 void select_soundhw(const char *optarg)
69 struct soundhw *c;
71 if (is_help_option(optarg)) {
72 show_valid_cards:
74 if (soundhw_count) {
75 printf("Valid sound card names (comma separated):\n");
76 for (c = soundhw; c->name; ++c) {
77 printf ("%-11s %s\n", c->name, c->descr);
79 printf("\n-soundhw all will enable all of the above\n");
80 } else {
81 printf("Machine has no user-selectable audio hardware "
82 "(it may or may not have always-present audio hardware).\n");
84 exit(!is_help_option(optarg));
86 else {
87 size_t l;
88 const char *p;
89 char *e;
90 int bad_card = 0;
92 if (!strcmp(optarg, "all")) {
93 for (c = soundhw; c->name; ++c) {
94 c->enabled = 1;
96 return;
99 p = optarg;
100 while (*p) {
101 e = strchr(p, ',');
102 l = !e ? strlen(p) : (size_t) (e - p);
104 for (c = soundhw; c->name; ++c) {
105 if (!strncmp(c->name, p, l) && !c->name[l]) {
106 c->enabled = 1;
107 break;
111 if (!c->name) {
112 if (l > 80) {
113 error_report("Unknown sound card name (too big to show)");
115 else {
116 error_report("Unknown sound card name `%.*s'",
117 (int) l, p);
119 bad_card = 1;
121 p += l + (e != NULL);
124 if (bad_card) {
125 goto show_valid_cards;
130 void soundhw_init(void)
132 struct soundhw *c;
133 ISABus *isa_bus = (ISABus *) object_resolve_path_type("", TYPE_ISA_BUS, NULL);
134 PCIBus *pci_bus = (PCIBus *) object_resolve_path_type("", TYPE_PCI_BUS, NULL);
136 for (c = soundhw; c->name; ++c) {
137 if (c->enabled) {
138 if (c->typename) {
139 warn_report("'-soundhw %s' is deprecated, "
140 "please use '-device %s' instead",
141 c->name, c->typename);
142 if (c->isa) {
143 isa_create_simple(isa_bus, c->typename);
144 } else {
145 pci_create_simple(pci_bus, -1, c->typename);
147 } else {
148 assert(!c->isa);
149 if (!pci_bus) {
150 error_report("PCI bus not available for %s", c->name);
151 exit(1);
153 c->init_pci(pci_bus);