soundhw: extract soundhw help to a separate function
[qemu.git] / hw / audio / soundhw.c
blob0fb64bdc8ffc20db0c2c9159b0ee5ebced744258
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 "qapi/error.h"
29 #include "qom/object.h"
30 #include "hw/isa/isa.h"
31 #include "hw/pci/pci.h"
32 #include "hw/audio/soundhw.h"
34 struct soundhw {
35 const char *name;
36 const char *descr;
37 const char *typename;
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 show_valid_soundhw(void)
69 struct soundhw *c;
71 if (soundhw_count) {
72 printf("Valid sound card names (comma separated):\n");
73 for (c = soundhw; c->name; ++c) {
74 printf ("%-11s %s\n", c->name, c->descr);
76 } else {
77 printf("Machine has no user-selectable audio hardware "
78 "(it may or may not have always-present audio hardware).\n");
82 static struct soundhw *selected = NULL;
84 void select_soundhw(const char *optarg)
86 struct soundhw *c;
88 if (selected) {
89 error_setg(&error_fatal, "only one -soundhw option is allowed");
92 if (is_help_option(optarg)) {
93 show_valid_soundhw();
94 exit(0);
96 else {
97 for (c = soundhw; c->name; ++c) {
98 if (g_str_equal(c->name, optarg)) {
99 selected = c;
100 break;
104 if (!c->name) {
105 error_report("Unknown sound card name `%s'", optarg);
106 show_valid_soundhw();
107 exit(1);
112 void soundhw_init(void)
114 struct soundhw *c = selected;
115 ISABus *isa_bus = (ISABus *) object_resolve_path_type("", TYPE_ISA_BUS, NULL);
116 PCIBus *pci_bus = (PCIBus *) object_resolve_path_type("", TYPE_PCI_BUS, NULL);
118 if (!c) {
119 return;
121 if (c->typename) {
122 warn_report("'-soundhw %s' is deprecated, "
123 "please use '-device %s' instead",
124 c->name, c->typename);
125 if (c->isa) {
126 isa_create_simple(isa_bus, c->typename);
127 } else {
128 pci_create_simple(pci_bus, -1, c->typename);
130 } else {
131 assert(!c->isa);
132 if (!pci_bus) {
133 error_report("PCI bus not available for %s", c->name);
134 exit(1);
136 c->init_pci(pci_bus);