1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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/qdev-properties.h"
31#include "hw/isa/isa.h"
32#include "hw/pci/pci.h"
33#include "hw/audio/soundhw.h"
34
35struct soundhw {
36 const char *name;
37 const char *descr;
38 const char *typename;
39 int isa;
40 int (*init_pci) (PCIBus *bus, const char *audiodev);
41};
42
43static struct soundhw soundhw[9];
44static int soundhw_count;
45
46void pci_register_soundhw(const char *name, const char *descr,
47 int (*init_pci)(PCIBus *bus, const char *audiodev))
48{
49 assert(soundhw_count < ARRAY_SIZE(soundhw) - 1);
50 soundhw[soundhw_count].name = name;
51 soundhw[soundhw_count].descr = descr;
52 soundhw[soundhw_count].isa = 0;
53 soundhw[soundhw_count].init_pci = init_pci;
54 soundhw_count++;
55}
56
57void deprecated_register_soundhw(const char *name, const char *descr,
58 int isa, const char *typename)
59{
60 assert(soundhw_count < ARRAY_SIZE(soundhw) - 1);
61 soundhw[soundhw_count].name = name;
62 soundhw[soundhw_count].descr = descr;
63 soundhw[soundhw_count].isa = isa;
64 soundhw[soundhw_count].typename = typename;
65 soundhw_count++;
66}
67
68void show_valid_soundhw(void)
69{
70 struct soundhw *c;
71
72 if (soundhw_count) {
73 printf("Valid sound card names (comma separated):\n");
74 for (c = soundhw; c->name; ++c) {
75 printf ("%-11s %s\n", c->name, c->descr);
76 }
77 } else {
78 printf("Machine has no user-selectable audio hardware "
79 "(it may or may not have always-present audio hardware).\n");
80 }
81}
82
83static struct soundhw *selected = NULL;
84static const char *audiodev_id;
85
86void select_soundhw(const char *optarg, const char *audiodev)
87{
88 struct soundhw *c;
89
90 if (selected) {
91 error_setg(&error_fatal, "only one -soundhw option is allowed");
92 }
93
94 for (c = soundhw; c->name; ++c) {
95 if (g_str_equal(c->name, optarg)) {
96 selected = c;
97 audiodev_id = audiodev;
98 break;
99 }
100 }
101
102 if (!c->name) {
103 error_report("Unknown sound card name `%s'", optarg);
104 show_valid_soundhw();
105 exit(1);
106 }
107}
108
109void soundhw_init(void)
110{
111 struct soundhw *c = selected;
112 ISABus *isa_bus = (ISABus *) object_resolve_path_type("", TYPE_ISA_BUS, NULL);
113 PCIBus *pci_bus = (PCIBus *) object_resolve_path_type("", TYPE_PCI_BUS, NULL);
114 BusState *bus;
115
116 if (!c) {
117 return;
118 }
119 if (c->isa) {
120 if (!isa_bus) {
121 error_report("ISA bus not available for %s", c->name);
122 exit(1);
123 }
124 bus = BUS(isa_bus);
125 } else {
126 if (!pci_bus) {
127 error_report("PCI bus not available for %s", c->name);
128 exit(1);
129 }
130 bus = BUS(pci_bus);
131 }
132
133 if (c->typename) {
134 DeviceState *dev = qdev_new(c->typename);
135 qdev_prop_set_string(dev, "audiodev", audiodev_id);
136 qdev_realize_and_unref(dev, bus, &error_fatal);
137 } else {
138 assert(!c->isa);
139 c->init_pci(pci_bus, audiodev_id);
140 }
141}
142
143