On Mon, Feb 23, 2026 at 9:27 PM Sergei Heifetz <[email protected]> wrote: > > PCSPK (PC Speaker) is an embedded audio device. We don't want it to use audio > when QEMU is configured with `--disable-audio`. This is achieved with minimal, > non-invasive changes to the code. > > In essence, the changes ensure that PCSPK does not have a corresponding > audio backend, while functioning the same way in non-audio aspects. > > Signed-off-by: Sergei Heifetz <[email protected]>
looks ok Reviewed-by: Marc-André Lureau <[email protected]> > --- > hw/audio/pcspk.c | 12 +++++++++++- > hw/i386/pc.c | 2 ++ > 2 files changed, 13 insertions(+), 1 deletion(-) > > diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c > index 6b826507ce..54e1882265 100644 > --- a/hw/audio/pcspk.c > +++ b/hw/audio/pcspk.c > @@ -48,17 +48,20 @@ struct PCSpkState { > > MemoryRegion ioport; > uint32_t iobase; > + PITCommonState *pit; > +#ifdef CONFIG_AUDIO > uint8_t sample_buf[PCSPK_BUF_LEN]; > AudioBackend *audio_be; > SWVoiceOut *voice; > - PITCommonState *pit; > unsigned int pit_count; > unsigned int samples; > unsigned int play_pos; > +#endif > uint8_t data_on; > uint8_t dummy_refresh_clock; > }; > > +#ifdef CONFIG_AUDIO > static const char *s_spk = "pcspk"; > > static inline void generate_samples(PCSpkState *s) > @@ -130,6 +133,7 @@ static int pcspk_audio_init(PCSpkState *s) > > return 0; > } > +#endif > > static uint64_t pcspk_io_read(void *opaque, hwaddr addr, > unsigned size) > @@ -160,11 +164,13 @@ static void pcspk_io_write(void *opaque, hwaddr addr, > uint64_t val, > > s->data_on = (val >> 1) & 1; > pit_set_gate(s->pit, 2, gate); > +#ifdef CONFIG_AUDIO > if (s->voice) { > if (gate) /* restart */ > s->play_pos = 0; > audio_be_set_active_out(s->audio_be, s->voice, gate & s->data_on); > } > +#endif > } > > static const MemoryRegionOps pcspk_io_ops = { > @@ -195,10 +201,12 @@ static void pcspk_realizefn(DeviceState *dev, Error > **errp) > > isa_register_ioport(isadev, &s->ioport, s->iobase); > > +#ifdef CONFIG_AUDIO > if (s->audio_be && audio_be_check(&s->audio_be, errp)) { > pcspk_audio_init(s); > return; > } > +#endif > } > > static const VMStateDescription vmstate_spk = { > @@ -213,7 +221,9 @@ static const VMStateDescription vmstate_spk = { > }; > > static const Property pcspk_properties[] = { > +#ifdef CONFIG_AUDIO > DEFINE_AUDIO_PROPERTIES(PCSpkState, audio_be), > +#endif we could make DEFINE_AUDIO_PROPERTIES compile down to nothing if !CONFIG_AUDIO, to avoid ifdefry > DEFINE_PROP_UINT32("iobase", PCSpkState, iobase, 0x61), > DEFINE_PROP_LINK("pit", PCSpkState, pit, TYPE_PIT_COMMON, PITCommonState > *), > }; > diff --git a/hw/i386/pc.c b/hw/i386/pc.c > index 0dd3fd01d9..3992553c2a 100644 > --- a/hw/i386/pc.c > +++ b/hw/i386/pc.c > @@ -1679,8 +1679,10 @@ static void pc_machine_initfn(Object *obj) > > pc_system_flash_create(pcms); > pcms->pcspk = isa_new(TYPE_PC_SPEAKER); > +#ifdef CONFIG_AUDIO > object_property_add_alias(OBJECT(pcms), "pcspk-audiodev", > OBJECT(pcms->pcspk), "audiodev"); > +#endif > if (pcmc->pci_enabled) { > cxl_machine_init(obj, &pcms->cxl_devices_state); > } > -- > 2.34.1 > > -- Marc-André Lureau
