bhyve: implement sound device support

bhyve supports intel hda sound devices that could be specified
on the command like using "-1:0,hda,play=$play_dev,rec=$rec_dev",
where "1:0" is a PCI address, and "$play_dev" and "$rec_dev"
point to the playback and recording device on the host respectively.
Currently, schema of the 'sound' element doesn't allow specifying
neither playback nor recording devices, so for now hardcode
/dev/dsp0, which is the first audio device on the host.

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Roman Bogorodskiy 2020-07-14 18:44:13 +04:00
parent 9499521718
commit 5d3137bbfb
10 changed files with 136 additions and 1 deletions

View File

@ -323,6 +323,17 @@ bhyveProbeCapsXHCIController(unsigned int *caps, char *binary)
}
static int
bhyveProbeCapsSoundHda(unsigned int *caps, char *binary)
{
return bhyveProbeCapsDeviceHelper(caps, binary,
"-s",
"0,hda",
"pci slot 0:0: unknown device \"hda\"",
BHYVE_CAP_SOUND_HDA);
}
int
virBhyveProbeCaps(unsigned int *caps)
{
@ -351,6 +362,9 @@ virBhyveProbeCaps(unsigned int *caps)
if ((ret = bhyveProbeCapsXHCIController(caps, binary)))
goto out;
if ((ret = bhyveProbeCapsSoundHda(caps, binary)))
goto out;
out:
VIR_FREE(binary);
return ret;

View File

@ -49,6 +49,7 @@ typedef enum {
BHYVE_CAP_FBUF = 1 << 4,
BHYVE_CAP_XHCI = 1 << 5,
BHYVE_CAP_CPUTOPOLOGY = 1 << 6,
BHYVE_CAP_SOUND_HDA = 1 << 7,
} virBhyveCapsFlags;
int virBhyveProbeGrubCaps(virBhyveGrubCapsFlags *caps);

View File

@ -475,6 +475,34 @@ bhyveBuildGraphicsArgStr(const virDomainDef *def,
}
static int
bhyveBuildSoundArgStr(const virDomainDef *def G_GNUC_UNUSED,
virDomainSoundDefPtr sound,
bhyveConnPtr driver,
virCommandPtr cmd)
{
if (!(bhyveDriverGetBhyveCaps(driver) & BHYVE_CAP_SOUND_HDA)) {
/* Currently, bhyve only supports "hda" sound devices, so
if it's not supported, sound devices are not supported at all */
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Sound devices emulation is not supported "
"by given bhyve binary"));
return -1;
}
if (sound->model != VIR_DOMAIN_SOUND_MODEL_ICH7) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Sound device model is not supported"));
return -1;
}
virCommandAddArg(cmd, "-s");
virCommandAddArgFormat(cmd, "%d:%d,hda,play=/dev/dsp0",
sound->info.addr.pci.slot,
sound->info.addr.pci.function);
return 0;
}
virCommandPtr
virBhyveProcessBuildBhyveCmd(bhyveConnPtr driver, virDomainDefPtr def,
bool dryRun)
@ -619,6 +647,11 @@ virBhyveProcessBuildBhyveCmd(bhyveConnPtr driver, virDomainDefPtr def,
}
}
for (i = 0; i < def->nsounds; i++) {
if (bhyveBuildSoundArgStr(def, def->sounds[i], driver, cmd) < 0)
goto error;
}
if (bhyveDomainDefNeedsISAController(def))
bhyveBuildLPCArgStr(def, cmd);

View File

@ -154,6 +154,15 @@ bhyveAssignDevicePCISlots(virDomainDefPtr def,
return -1;
}
for (i = 0; i < def->nsounds; i++) {
if (!virDeviceInfoPCIAddressIsWanted(&def->sounds[i]->info))
continue;
if (virDomainPCIAddressReserveNextAddr(addrs,
&def->sounds[i]->info,
VIR_PCI_CONNECT_TYPE_PCI_DEVICE,
-1) < 0)
return -1;
}
return 0;
}

View File

@ -0,0 +1,10 @@
/usr/sbin/bhyve \
-c 1 \
-m 214 \
-u \
-H \
-P \
-s 0:0,hostbridge \
-s 2:0,ahci,hd:/tmp/freebsd.img \
-s 3:0,virtio-net,faketapdev,mac=52:54:00:b9:94:02 \
-s 4:0,hda,play=/dev/dsp0 bhyve

View File

@ -0,0 +1,3 @@
/usr/sbin/bhyveload \
-m 214 \
-d /tmp/freebsd.img bhyve

View File

@ -0,0 +1,24 @@
<domain type='bhyve'>
<name>bhyve</name>
<uuid>df3be7e7-a104-11e3-aeb0-50e5492bd3dc</uuid>
<memory>219136</memory>
<vcpu>1</vcpu>
<os>
<type>hvm</type>
</os>
<devices>
<disk type='file'>
<driver name='file' type='raw'/>
<source file='/tmp/freebsd.img'/>
<target dev='hda' bus='sata'/>
<address type='drive' controller='0' bus='0' target='2' unit='0'/>
</disk>
<interface type='bridge'>
<mac address='52:54:00:b9:94:02'/>
<model type='virtio'/>
<source bridge="virbr0"/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
<sound model='ich7'/>
</devices>
</domain>

View File

@ -166,7 +166,7 @@ mymain(void)
driver.bhyvecaps = BHYVE_CAP_RTC_UTC | BHYVE_CAP_AHCI32SLOT | \
BHYVE_CAP_NET_E1000 | BHYVE_CAP_LPC_BOOTROM | \
BHYVE_CAP_FBUF | BHYVE_CAP_XHCI | \
BHYVE_CAP_CPUTOPOLOGY;
BHYVE_CAP_CPUTOPOLOGY | BHYVE_CAP_SOUND_HDA;
DO_TEST("base");
DO_TEST("wired");
@ -201,6 +201,7 @@ mymain(void)
DO_TEST_FAILURE("cputopology-nvcpu-mismatch");
DO_TEST("commandline");
DO_TEST("msrs");
DO_TEST("sound");
/* Address allocation tests */
DO_TEST("addr-single-sata-disk");
@ -240,6 +241,9 @@ mymain(void)
driver.bhyvecaps &= ~BHYVE_CAP_CPUTOPOLOGY;
DO_TEST_FAILURE("cputopology");
driver.bhyvecaps &= ~BHYVE_CAP_SOUND_HDA;
DO_TEST_FAILURE("sound");
virObjectUnref(driver.caps);
virObjectUnref(driver.xmlopt);
virPortAllocatorRangeFree(driver.remotePorts);

View File

@ -0,0 +1,36 @@
<domain type='bhyve'>
<name>bhyve</name>
<uuid>df3be7e7-a104-11e3-aeb0-50e5492bd3dc</uuid>
<memory unit='KiB'>219136</memory>
<currentMemory unit='KiB'>219136</currentMemory>
<vcpu placement='static'>1</vcpu>
<os>
<type arch='x86_64'>hvm</type>
<boot dev='hd'/>
</os>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<disk type='file' device='disk'>
<driver name='file' type='raw'/>
<source file='/tmp/freebsd.img'/>
<target dev='hda' bus='sata'/>
<address type='drive' controller='0' bus='0' target='2' unit='0'/>
</disk>
<controller type='pci' index='0' model='pci-root'/>
<controller type='sata' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</controller>
<interface type='bridge'>
<mac address='52:54:00:b9:94:02'/>
<source bridge='virbr0'/>
<model type='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
<sound model='ich7'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</sound>
</devices>
</domain>

View File

@ -108,6 +108,7 @@ mymain(void)
DO_TEST_DIFFERENT("vnc-autoport");
DO_TEST_DIFFERENT("commandline");
DO_TEST_DIFFERENT("msrs");
DO_TEST_DIFFERENT("sound");
/* Address allocation tests */
DO_TEST_DIFFERENT("addr-single-sata-disk");