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
24 #include "qemu/osdep.h"
25 #include "qemu-common.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"
39 int (*init_isa
) (ISABus
*bus
);
40 int (*init_pci
) (PCIBus
*bus
);
44 static struct soundhw soundhw
[9];
45 static int soundhw_count
;
47 void isa_register_soundhw(const char *name
, const char *descr
,
48 int (*init_isa
)(ISABus
*bus
))
50 assert(soundhw_count
< ARRAY_SIZE(soundhw
) - 1);
51 soundhw
[soundhw_count
].name
= name
;
52 soundhw
[soundhw_count
].descr
= descr
;
53 soundhw
[soundhw_count
].isa
= 1;
54 soundhw
[soundhw_count
].init
.init_isa
= init_isa
;
58 void pci_register_soundhw(const char *name
, const char *descr
,
59 int (*init_pci
)(PCIBus
*bus
))
61 assert(soundhw_count
< ARRAY_SIZE(soundhw
) - 1);
62 soundhw
[soundhw_count
].name
= name
;
63 soundhw
[soundhw_count
].descr
= descr
;
64 soundhw
[soundhw_count
].isa
= 0;
65 soundhw
[soundhw_count
].init
.init_pci
= init_pci
;
69 void select_soundhw(const char *optarg
)
73 if (is_help_option(optarg
)) {
77 printf("Valid sound card names (comma separated):\n");
78 for (c
= soundhw
; c
->name
; ++c
) {
79 printf ("%-11s %s\n", c
->name
, c
->descr
);
81 printf("\n-soundhw all will enable all of the above\n");
83 printf("Machine has no user-selectable audio hardware "
84 "(it may or may not have always-present audio hardware).\n");
86 exit(!is_help_option(optarg
));
94 if (!strcmp(optarg
, "all")) {
95 for (c
= soundhw
; c
->name
; ++c
) {
104 l
= !e
? strlen(p
) : (size_t) (e
- p
);
106 for (c
= soundhw
; c
->name
; ++c
) {
107 if (!strncmp(c
->name
, p
, l
) && !c
->name
[l
]) {
115 error_report("Unknown sound card name (too big to show)");
118 error_report("Unknown sound card name `%.*s'",
123 p
+= l
+ (e
!= NULL
);
127 goto show_valid_cards
;
132 void soundhw_init(void)
135 ISABus
*isa_bus
= (ISABus
*) object_resolve_path_type("", TYPE_ISA_BUS
, NULL
);
136 PCIBus
*pci_bus
= (PCIBus
*) object_resolve_path_type("", TYPE_PCI_BUS
, NULL
);
138 for (c
= soundhw
; c
->name
; ++c
) {
142 error_report("ISA bus not available for %s", c
->name
);
145 c
->init
.init_isa(isa_bus
);
148 error_report("PCI bus not available for %s", c
->name
);
151 c
->init
.init_pci(pci_bus
);