2017-05-08 20:57:33 +00:00
|
|
|
/*
|
|
|
|
* QEMU System Emulator
|
|
|
|
*
|
|
|
|
* Copyright (c) 2003-2008 Fabrice Bellard
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
#include "qemu/osdep.h"
|
2020-07-02 13:25:08 +00:00
|
|
|
#include "qemu/option.h"
|
2017-05-08 20:57:33 +00:00
|
|
|
#include "qemu/help_option.h"
|
|
|
|
#include "qemu/error-report.h"
|
2022-04-27 10:04:47 +00:00
|
|
|
#include "qapi/error.h"
|
2017-05-08 20:57:33 +00:00
|
|
|
#include "qom/object.h"
|
2022-04-27 10:27:46 +00:00
|
|
|
#include "hw/qdev-properties.h"
|
2017-05-08 20:57:33 +00:00
|
|
|
#include "hw/isa/isa.h"
|
|
|
|
#include "hw/pci/pci.h"
|
2017-05-08 20:57:35 +00:00
|
|
|
#include "hw/audio/soundhw.h"
|
2017-05-08 20:57:33 +00:00
|
|
|
|
|
|
|
struct soundhw {
|
|
|
|
const char *name;
|
|
|
|
const char *descr;
|
2020-07-02 13:25:08 +00:00
|
|
|
const char *typename;
|
2017-05-08 20:57:33 +00:00
|
|
|
int isa;
|
2022-04-27 10:27:46 +00:00
|
|
|
int (*init_pci) (PCIBus *bus, const char *audiodev);
|
2017-05-08 20:57:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct soundhw soundhw[9];
|
|
|
|
static int soundhw_count;
|
|
|
|
|
|
|
|
void pci_register_soundhw(const char *name, const char *descr,
|
2022-04-27 10:27:46 +00:00
|
|
|
int (*init_pci)(PCIBus *bus, const char *audiodev))
|
2017-05-08 20:57:33 +00:00
|
|
|
{
|
|
|
|
assert(soundhw_count < ARRAY_SIZE(soundhw) - 1);
|
|
|
|
soundhw[soundhw_count].name = name;
|
|
|
|
soundhw[soundhw_count].descr = descr;
|
|
|
|
soundhw[soundhw_count].isa = 0;
|
2022-04-27 10:01:48 +00:00
|
|
|
soundhw[soundhw_count].init_pci = init_pci;
|
2017-05-08 20:57:33 +00:00
|
|
|
soundhw_count++;
|
|
|
|
}
|
|
|
|
|
2020-07-02 13:25:08 +00:00
|
|
|
void deprecated_register_soundhw(const char *name, const char *descr,
|
|
|
|
int isa, const char *typename)
|
|
|
|
{
|
|
|
|
assert(soundhw_count < ARRAY_SIZE(soundhw) - 1);
|
|
|
|
soundhw[soundhw_count].name = name;
|
|
|
|
soundhw[soundhw_count].descr = descr;
|
|
|
|
soundhw[soundhw_count].isa = isa;
|
|
|
|
soundhw[soundhw_count].typename = typename;
|
|
|
|
soundhw_count++;
|
|
|
|
}
|
|
|
|
|
2022-04-27 10:26:48 +00:00
|
|
|
void show_valid_soundhw(void)
|
|
|
|
{
|
|
|
|
struct soundhw *c;
|
|
|
|
|
|
|
|
if (soundhw_count) {
|
|
|
|
printf("Valid sound card names (comma separated):\n");
|
|
|
|
for (c = soundhw; c->name; ++c) {
|
|
|
|
printf ("%-11s %s\n", c->name, c->descr);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
printf("Machine has no user-selectable audio hardware "
|
|
|
|
"(it may or may not have always-present audio hardware).\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-27 10:04:47 +00:00
|
|
|
static struct soundhw *selected = NULL;
|
2022-04-27 10:27:46 +00:00
|
|
|
static const char *audiodev_id;
|
2022-04-27 10:04:47 +00:00
|
|
|
|
2022-04-27 10:27:46 +00:00
|
|
|
void select_soundhw(const char *optarg, const char *audiodev)
|
2017-05-08 20:57:33 +00:00
|
|
|
{
|
|
|
|
struct soundhw *c;
|
|
|
|
|
2022-04-27 10:04:47 +00:00
|
|
|
if (selected) {
|
|
|
|
error_setg(&error_fatal, "only one -soundhw option is allowed");
|
|
|
|
}
|
|
|
|
|
2022-04-27 11:15:23 +00:00
|
|
|
for (c = soundhw; c->name; ++c) {
|
|
|
|
if (g_str_equal(c->name, optarg)) {
|
|
|
|
selected = c;
|
2022-04-27 10:27:46 +00:00
|
|
|
audiodev_id = audiodev;
|
2022-04-27 11:15:23 +00:00
|
|
|
break;
|
2017-05-08 20:57:33 +00:00
|
|
|
}
|
2022-04-27 11:15:23 +00:00
|
|
|
}
|
2017-05-08 20:57:33 +00:00
|
|
|
|
2022-04-27 11:15:23 +00:00
|
|
|
if (!c->name) {
|
|
|
|
error_report("Unknown sound card name `%s'", optarg);
|
|
|
|
show_valid_soundhw();
|
|
|
|
exit(1);
|
2017-05-08 20:57:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-08 20:57:34 +00:00
|
|
|
void soundhw_init(void)
|
2017-05-08 20:57:33 +00:00
|
|
|
{
|
2022-04-27 10:04:47 +00:00
|
|
|
struct soundhw *c = selected;
|
2017-05-08 20:57:33 +00:00
|
|
|
ISABus *isa_bus = (ISABus *) object_resolve_path_type("", TYPE_ISA_BUS, NULL);
|
|
|
|
PCIBus *pci_bus = (PCIBus *) object_resolve_path_type("", TYPE_PCI_BUS, NULL);
|
2022-04-27 10:06:59 +00:00
|
|
|
BusState *bus;
|
2017-05-08 20:57:33 +00:00
|
|
|
|
2022-04-27 10:04:47 +00:00
|
|
|
if (!c) {
|
|
|
|
return;
|
|
|
|
}
|
2022-04-27 10:06:59 +00:00
|
|
|
if (c->isa) {
|
|
|
|
if (!isa_bus) {
|
|
|
|
error_report("ISA bus not available for %s", c->name);
|
|
|
|
exit(1);
|
2022-04-27 10:04:47 +00:00
|
|
|
}
|
2022-04-27 10:06:59 +00:00
|
|
|
bus = BUS(isa_bus);
|
2022-04-27 10:04:47 +00:00
|
|
|
} else {
|
|
|
|
if (!pci_bus) {
|
|
|
|
error_report("PCI bus not available for %s", c->name);
|
|
|
|
exit(1);
|
2017-05-08 20:57:33 +00:00
|
|
|
}
|
2022-04-27 10:06:59 +00:00
|
|
|
bus = BUS(pci_bus);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c->typename) {
|
|
|
|
DeviceState *dev = qdev_new(c->typename);
|
2022-04-27 10:27:46 +00:00
|
|
|
qdev_prop_set_string(dev, "audiodev", audiodev_id);
|
2022-04-27 10:06:59 +00:00
|
|
|
qdev_realize_and_unref(dev, bus, &error_fatal);
|
|
|
|
} else {
|
|
|
|
assert(!c->isa);
|
2022-04-27 10:27:46 +00:00
|
|
|
c->init_pci(pci_bus, audiodev_id);
|
2017-05-08 20:57:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|