From nobody Mon Nov 23 04:18:05 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1793227756; cv=none; d=zohomail.com; s=zohoarc; b=lYlLtl5Atjoryn+Q33yxRSkc/ZHdydfEhRaqGas5HDiZEv24FiJhNbXQ0VJebodlarA3XS3JmzXt2Aa1lWFp/8mGLBAbUM/CfCM+tdJX2xs8ZCaa4c6tsDjpOCmbG7wvBF+DR7O3QLCf20MyRr6L4NVJD+NCjQGe9z3bTGg1t+E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793227756; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=5PwoP5eFK/VgNiqkCXL3FsO/x8WWjBSqellI8Ng4YYc=; b=Kxd5nqSz4wOw+JSs6maKEGCGFJFE2fTlCMn/6JOX0jGNvITjMp0sEQjZCFt2bmK6jWOQtanYowYaKLwO7xZwIAYKaLVnYEEBIxQeJo89ewWDVBvvxaVRwF4tosN1T4aDK0aKC5Air1kdqDlN9ACm4+hVlCEIYxEhw3ddQgW9jOw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793227756758635.0206445707411; Wed, 28 Oct 2026 15:49:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMCRX-0001uI-Ig; Wed, 28 Oct 2026 18:48:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMCRV-0001tk-Hf for qemu-devel@nongnu.org; Wed, 28 Oct 2026 18:48:25 -0400 Received: from tor.source.kernel.org ([172.105.4.254]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMCRS-0007cb-40 for qemu-devel@nongnu.org; Wed, 28 Oct 2026 18:48:25 -0400 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id CC38A600DA; Wed, 28 Oct 2026 22:48:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2CFC51F01825; Wed, 28 Oct 2026 22:48:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793227700; bh=5PwoP5eFK/VgNiqkCXL3FsO/x8WWjBSqellI8Ng4YYc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=WznaIcKi6exD7uIbK+RhwX1o9b3fFTGEvUs6YguazCP/rGvso5flHD4sKWPLcJlA5 Vl/U2NfKosTDbHA2zA98/6rBHRGtkuPof6Cv5q13O85q3VytyDpIXs2jrKoOzTtLf+ 2o41E5iBqL1OMbOaKQvFAsOvsLF04bHHFNwHLR/cALJiHfuQi9FNDjabrhz/gHitQ5 nvmewpLgOVTTEVu2Lrr3hu+6kyONnB+crLhkxfoh5NMmc7ZjmUsD650RPPFKtD8DNQ x+sqbvLH8JiAO+ZforsAbkURKEYlgCFflqUAE5tZbFtQSOv4OmayR9ZbOUbE5uLbCA tF7iEACXRAuIw== From: Helge Deller To: qemu-devel@nongnu.org Cc: Richard Henderson , Keith Monahan , Gerd Hoffmann , Helge Deller Subject: [PATCH 1/4] hw/audio: Add HP Harmony audio (LASI audio function, CS4215/AD1849 codec) Date: Wed, 28 Oct 2026 23:48:12 +0100 Message-ID: <20261028224815.32502-2-deller@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20261028224815.32502-1-deller@kernel.org> References: <20261028224815.32502-1-deller@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=172.105.4.254; envelope-from=deller@kernel.org; helo=tor.source.kernel.org X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1793227759964154100 Content-Type: text/plain; charset="utf-8" From: Keith Monahan Found in the HP 712, HP 715/64-100, HP 725 and B132L-B180L workstations. Register layout per the "712 I/O Subsystem ERS". Playback and record each have a pair of 4 KiB page registers (next/current). While the codec is out of reset a queued next page moves to current as soon as the current one is done, leaving the "next empty" status bit (PN/RN) set; DSTATUS.IE only gates that onto the interrupt line. A direction with no queued page idles. Both directions run off the codec's single sample clock. Signed-off-by: Keith Monahan --- hw/audio/harmony.c | 892 +++++++++++++++++++++++++++++++++++++ hw/audio/trace-events | 10 + include/hw/audio/harmony.h | 76 ++++ 3 files changed, 978 insertions(+) create mode 100644 hw/audio/harmony.c create mode 100644 include/hw/audio/harmony.h diff --git a/hw/audio/harmony.c b/hw/audio/harmony.c new file mode 100644 index 0000000000..f25d7197d5 --- /dev/null +++ b/hw/audio/harmony.c @@ -0,0 +1,892 @@ +/* + * HP Harmony audio (LASI audio function, CS4215/AD1849 codec) + * + * Found in the 712, 715/64-100, 725 and B132L-B180L. Register layout per + * the "712 I/O Subsystem ERS". Playback and record each have a pair of + * 4 KiB page registers (next/current). While the codec is out of reset a + * queued next page moves to current as soon as the current one is done, + * leaving the "next empty" status bit (PN/RN) set; DSTATUS.IE only gates + * that onto the interrupt line. A direction with no queued page idles. + * Both directions run off the codec's single sample clock. + * + * Copyright (c) 2026 Keith Monahan + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include +#include "qemu/bswap.h" +#include "qemu/log.h" +#include "qapi/error.h" +#include "hw/core/irq.h" +#include "hw/core/qdev-properties.h" +#include "hw/audio/harmony.h" +#include "migration/vmstate.h" +#include "system/address-spaces.h" +#include "system/dma.h" +#include "trace.h" + +#define HARMONY_ID 0x00 +#define HARMONY_RESET 0x04 +#define HARMONY_CNTL 0x08 +#define HARMONY_GAINCTL 0x0c +#define HARMONY_PNXTADD 0x10 +#define HARMONY_PCURADD 0x14 +#define HARMONY_RNXTADD 0x18 +#define HARMONY_RCURADD 0x1c +#define HARMONY_DSTATUS 0x20 +#define HARMONY_OV 0x24 +#define HARMONY_PIO 0x28 +#define HARMONY_DIAG 0x3c + +#define RESET_RST 0x00000001 + +#define CNTL_C 0x80000000 +#define CNTL_CODEC_REV_SHIFT 20 +#define CNTL_CODEC_REV_MASK 0x0ff00000 +#define CNTL_FORMAT_SHIFT 6 +#define CNTL_FORMAT_MASK 0x000000c0 +#define CNTL_STEREO 0x00000020 +#define CNTL_RATE_MASK 0x0000001f + +#define FMT_S16BE 0 +#define FMT_ULAW 1 +#define FMT_ALAW 2 +#define FMT_U8 3 + +#define GAINCTL_HE 0x08000000 +#define GAINCTL_LE 0x04000000 +#define GAINCTL_SE 0x02000000 +#define GAINCTL_IS 0x01000000 +#define GAINCTL_IN_R_SHIFT 16 +#define GAINCTL_IN_L_SHIFT 12 +#define GAINCTL_OUT_L_SHIFT 6 +#define GAINCTL_OUT_R_SHIFT 0 + +#define DSTATUS_IE 0x80000000 +#define DSTATUS_PN 0x00000200 +#define DSTATUS_PC 0x00000100 +#define DSTATUS_RN 0x00000002 +#define DSTATUS_RC 0x00000001 + +#define OV_OV 0x00000001 +#define PIO_PO 0x00000002 +#define DIAG_CO 0x00000001 + +/* audio ticks with nothing to transfer before the host voices are stopped= */ +#define HARMONY_IDLE_TICKS 5 + +/* CNTL rate field to sample rate; 0 =3D reserved encoding */ +static const int harmony_rates[32] =3D { + [0x08] =3D 8000, [0x09] =3D 16000, [0x0a] =3D 27429, [0x0b] =3D 32000, + [0x0e] =3D 48000, [0x0f] =3D 9600, [0x10] =3D 5513, [0x11] =3D 11025, + [0x12] =3D 18900, [0x13] =3D 22050, [0x14] =3D 37800, [0x15] =3D 44100, + [0x16] =3D 33075, [0x17] =3D 6615, +}; + +/* Q12 input gain, 1.5 dB steps */ +static int32_t harmony_in_gain[16]; + +static void harmony_init_tables(void) +{ + int i; + + for (i =3D 0; i < 16; i++) { + harmony_in_gain[i] =3D lrint(4096.0 * pow(10.0, 1.5 * i / 20.0)); + } +} + +/* G.711 */ +static int16_t ulaw_to_s16(uint8_t u) +{ + int t; + + u =3D ~u; + t =3D ((u & 0x0f) << 3) + 0x84; + t <<=3D (u & 0x70) >> 4; + return (u & 0x80) ? (0x84 - t) : (t - 0x84); +} + +static int16_t alaw_to_s16(uint8_t a) +{ + int t, seg; + + a ^=3D 0x55; + t =3D (a & 0x0f) << 4; + seg =3D (a & 0x70) >> 4; + if (seg =3D=3D 0) { + t +=3D 8; + } else { + t =3D (t + 0x108) << (seg - 1); + } + return (a & 0x80) ? t : -t; +} + +/* smallest segment whose end ((base << seg) - 1) is >=3D val */ +static int g711_segment(int val, int base) +{ + int seg; + + for (seg =3D 0; seg < 8; seg++) { + if (val < (base << seg)) { + break; + } + } + return seg; +} + +static uint8_t s16_to_ulaw(int16_t s) +{ + int val =3D s >> 2, mask, seg; + + if (val < 0) { + val =3D -val; + mask =3D 0x7f; + } else { + mask =3D 0xff; + } + val =3D MIN(val, 8159) + 33; + seg =3D g711_segment(val, 0x40); + if (seg >=3D 8) { + return 0x7f ^ mask; + } + return ((seg << 4) | ((val >> (seg + 1)) & 0x0f)) ^ mask; +} + +static uint8_t s16_to_alaw(int16_t s) +{ + int val =3D s >> 3, mask, seg; + uint8_t aval; + + if (val >=3D 0) { + mask =3D 0xd5; + } else { + mask =3D 0x55; + val =3D -val - 1; + } + seg =3D g711_segment(val, 0x20); + if (seg >=3D 8) { + return 0x7f ^ mask; + } + aval =3D seg << 4; + aval |=3D (val >> (seg < 2 ? 1 : seg)) & 0x0f; + return aval ^ mask; +} + +static int harmony_format(HarmonyState *s) +{ + return (s->cntl & CNTL_FORMAT_MASK) >> CNTL_FORMAT_SHIFT; +} + +static int harmony_channels(HarmonyState *s) +{ + return (s->cntl & CNTL_STEREO) ? 2 : 1; +} + +/* guest bytes per frame */ +static int harmony_bpf(HarmonyState *s) +{ + return (harmony_format(s) =3D=3D FMT_S16BE ? 2 : 1) * harmony_channels= (s); +} + +static int harmony_freq(HarmonyState *s) +{ + int freq =3D harmony_rates[s->cntl & CNTL_RATE_MASK]; + + return freq ? freq : 8000; +} + +/* + * DMA does not stop when IE is cleared: HP-UX stops a stream by leaving + * pages queued with IE clear, and on the next open expects to find both + * next registers drained (PN and RN set) again. + */ +static bool harmony_running(HarmonyState *s) +{ + return !(s->reset & RESET_RST); +} + +static void harmony_update_irq(HarmonyState *s) +{ + int level =3D (s->dstatus & DSTATUS_IE) && + (!s->pnxt_valid || !s->rnxt_valid); + + if (level !=3D s->irq_level) { + s->irq_level =3D level; + trace_harmony_irq(level); + qemu_set_irq(s->irq, level); + } +} + +static void harmony_set_voices(HarmonyState *s, bool out, bool in) +{ + if (out !=3D s->out_active) { + s->out_active =3D out; + s->starved =3D false; + if (s->voice_out) { + audio_be_set_active_out(s->audio_be, s->voice_out, out); + } + } + if (in !=3D s->in_active) { + s->in_active =3D in; + s->in_rd =3D s->in_wr; + if (s->voice_in) { + audio_be_set_active_in(s->audio_be, s->voice_in, in); + } + } +} + +static bool harmony_busy(HarmonyState *s) +{ + return harmony_running(s) && + (s->pcur_valid || s->pnxt_valid || s->rcur_valid || s->rnxt_val= id); +} + +/* + * Voices start as soon as there is a page to transfer. They are stopped + * only by harmony_out_cb after a sustained idle spell: drivers leave both + * directions empty for a moment at every page boundary, and restarting a + * host capture stream that often loses its input. + */ +static void harmony_update_active(HarmonyState *s) +{ + bool out; + + if (!harmony_running(s)) { + s->rec_seen =3D false; + harmony_set_voices(s, false, false); + return; + } + if (s->rcur_valid || s->rnxt_valid) { + s->rec_seen =3D true; + } + out =3D s->out_active || harmony_busy(s); + harmony_set_voices(s, out, out && s->rec_seen); +} + +/* Start the queued next page in any direction that has finished its last = */ +static void harmony_load(HarmonyState *s) +{ + if (!harmony_running(s)) { + return; + } + if (!s->pcur_valid && s->pnxt_valid) { + s->pcuradd =3D s->pnxtadd; + s->poff =3D 0; + s->pcur_valid =3D true; + s->pnxt_valid =3D false; + trace_harmony_page("play", s->pcuradd); + } + if (!s->rcur_valid && s->rnxt_valid) { + s->rcuradd =3D s->rnxtadd; + s->roff =3D 0; + s->rcur_valid =3D true; + s->rnxt_valid =3D false; + trace_harmony_page("rec", s->rcuradd); + } + harmony_update_irq(s); +} + +static int16_t harmony_get_sample(HarmonyState *s, const uint8_t *p) +{ + switch (harmony_format(s)) { + case FMT_S16BE: + return (int16_t)lduw_be_p(p); + case FMT_ULAW: + return ulaw_to_s16(*p); + case FMT_ALAW: + return alaw_to_s16(*p); + default: + return (int16_t)((*p - 0x80) << 8); + } +} + +static void harmony_put_sample(HarmonyState *s, uint8_t *p, int16_t v) +{ + switch (harmony_format(s)) { + case FMT_S16BE: + stw_be_p(p, v); + break; + case FMT_ULAW: + *p =3D s16_to_ulaw(v); + break; + case FMT_ALAW: + *p =3D s16_to_alaw(v); + break; + default: + *p =3D (v >> 8) + 0x80; + break; + } +} + +/* Fetch n playback frames from guest memory into out_buf as S16 stereo */ +static void harmony_play_fetch(HarmonyState *s, int n) +{ + int bpf =3D harmony_bpf(s); + int bps =3D harmony_format(s) =3D=3D FMT_S16BE ? 2 : 1; + bool stereo =3D harmony_channels(s) =3D=3D 2; + int32_t att_l =3D s->out_att[(s->gainctl >> GAINCTL_OUT_L_SHIFT) & 0x3= f]; + int32_t att_r =3D s->out_att[(s->gainctl >> GAINCTL_OUT_R_SHIFT) & 0x3= f]; + int i; + + /* + * HE/LE/SE are not used to mute the host output: HP-UX 10.20 sets all + * three while idle and clears all three for playback, the opposite of + * the "enable" reading in the Linux and BSD drivers. The host output + * stands for whichever jack is in use; attenuation still applies. + */ + if (!s->pcur_valid) { + memset(s->out_buf, 0, n * 4); + return; + } + + dma_memory_read(&address_space_memory, s->pcuradd + s->poff, + s->dma_buf, n * bpf, MEMTXATTRS_UNSPECIFIED); + for (i =3D 0; i < n; i++) { + const uint8_t *p =3D s->dma_buf + i * bpf; + int16_t l =3D harmony_get_sample(s, p); + int16_t r =3D stereo ? harmony_get_sample(s, p + bps) : l; + + s->out_buf[2 * i] =3D MIN(MAX((l * att_l) >> 15, INT16_MIN), INT16= _MAX); + s->out_buf[2 * i + 1] =3D MIN(MAX((r * att_r) >> 15, INT16_MIN), + INT16_MAX); + } +} + +/* Store n record frames (host input or silence) into guest memory */ +static void harmony_rec_store(HarmonyState *s, int n) +{ + int bpf =3D harmony_bpf(s); + int bps =3D harmony_format(s) =3D=3D FMT_S16BE ? 2 : 1; + bool stereo =3D harmony_channels(s) =3D=3D 2; + int32_t g_l =3D harmony_in_gain[(s->gainctl >> GAINCTL_IN_L_SHIFT) & 0= xf]; + int32_t g_r =3D harmony_in_gain[(s->gainctl >> GAINCTL_IN_R_SHIFT) & 0= xf]; + uint32_t got =3D MIN(s->in_wr - s->in_rd, (uint32_t)n); + uint32_t i; + + for (i =3D 0; i < got; i++) { + uint32_t j =3D (s->in_rd + i) & (HARMONY_IN_RING - 1); + + s->in_buf[2 * i] =3D s->in_ring[2 * j]; + s->in_buf[2 * i + 1] =3D s->in_ring[2 * j + 1]; + } + s->in_rd +=3D got; + trace_harmony_rec_read(n, got, s->in_wr - s->in_rd); + memset(s->in_buf + 2 * got, 0, (n - got) * 4); + + for (i =3D 0; i < n; i++) { + int32_t l =3D (s->in_buf[2 * i] * g_l) >> 12; + int32_t r =3D (s->in_buf[2 * i + 1] * g_r) >> 12; + uint8_t *p =3D s->dma_buf + i * bpf; + + if (l !=3D (int16_t)l || r !=3D (int16_t)r) { + s->ov |=3D OV_OV; + l =3D MIN(MAX(l, INT16_MIN), INT16_MAX); + r =3D MIN(MAX(r, INT16_MIN), INT16_MAX); + } + if (stereo) { + harmony_put_sample(s, p, l); + harmony_put_sample(s, p + bps, r); + } else { + harmony_put_sample(s, p, (l + r) / 2); + } + } + dma_memory_write(&address_space_memory, s->rcuradd + s->roff, + s->dma_buf, n * bpf, MEMTXATTRS_UNSPECIFIED); +} + +/* + * Retire finished pages and start queued ones. Returns true if a directi= on + * ran out with nothing queued: the transfer then waits for the driver to + * service the interrupt rather than consuming more of this audio tick. + */ +static bool harmony_page_end(HarmonyState *s) +{ + /* a format change mid-page can leave less than a frame; drop it */ + int bpf =3D harmony_bpf(s); + bool p_end =3D s->pcur_valid && s->poff + bpf > HARMONY_PAGE_SIZE; + bool r_end =3D s->rcur_valid && s->roff + bpf > HARMONY_PAGE_SIZE; + + if (p_end) { + s->pcur_valid =3D false; + } + if (r_end) { + s->rcur_valid =3D false; + } + harmony_load(s); + if ((p_end && !s->pcur_valid) || (r_end && !s->rcur_valid)) { + trace_harmony_starved(!s->pcur_valid, !s->rcur_valid); + return true; + } + return false; +} + +/* + * Transfer up to the given number of frames, as far as the output voice + * accepts them. Stops early, marking the stream starved, when a direction + * runs out with nothing queued. + */ +static void harmony_fill(HarmonyState *s, int frames) +{ + while (frames > 0) { + int bpf, n; + size_t written; + + if (harmony_page_end(s)) { + s->starved =3D true; + break; + } + if (!(s->pcur_valid || s->rcur_valid)) { + break; + } + s->starved =3D false; + + bpf =3D harmony_bpf(s); + n =3D MIN(frames, HARMONY_MIX_FRAMES); + if (s->pcur_valid) { + n =3D MIN(n, (HARMONY_PAGE_SIZE - s->poff) / bpf); + } + if (s->rcur_valid) { + n =3D MIN(n, (HARMONY_PAGE_SIZE - s->roff) / bpf); + } + + harmony_play_fetch(s, n); + written =3D audio_be_write(s->audio_be, s->voice_out, s->out_buf, = n * 4); + n =3D written / 4; + if (n =3D=3D 0) { + break; + } + if (s->pcur_valid) { + s->poff +=3D n * bpf; + } + if (s->rcur_valid) { + harmony_rec_store(s, n); + s->roff +=3D n * bpf; + } + frames -=3D n; + } +} + +/* + * A page queued while the stream is starved is picked up at once instead + * of at the next audio tick. Backends that call back rarely (PulseAudio + * after an underrun raises its latency) would otherwise hold the stream to + * one page per tick. The voice only accepts what it has room for, so this + * cannot run ahead of the host clock. While record is in use, wait for + * its page too so the two directions stay in step. + */ +static void harmony_resume(HarmonyState *s) +{ + if (!s->starved || !s->out_active || !s->voice_out) { + return; + } + if (s->rec_seen && !s->rcur_valid) { + return; + } + harmony_fill(s, INT_MAX / 4); +} + +static void harmony_out_cb(void *opaque, int avail) +{ + HarmonyState *s =3D opaque; + + harmony_fill(s, avail / 4); + + if (harmony_busy(s)) { + s->idle_ticks =3D 0; + } else if (++s->idle_ticks >=3D HARMONY_IDLE_TICKS) { + s->idle_ticks =3D 0; + s->rec_seen =3D false; + harmony_set_voices(s, false, false); + return; + } + harmony_update_active(s); +} + +/* + * Drain the input voice into the ring. Keep at most a quarter second of + * backlog so a host input running faster than the codec clock doesn't + * build up latency. + */ +static void harmony_in_cb(void *opaque, int avail) +{ + HarmonyState *s =3D opaque; + uint32_t max_backlog =3D MIN(harmony_freq(s) / 4, HARMONY_IN_RING - 1); + int frames =3D avail / 4; + + trace_harmony_in_cb(avail); + while (frames > 0) { + int n =3D MIN(frames, HARMONY_MIX_FRAMES); + size_t got =3D audio_be_read(s->audio_be, s->voice_in, s->in_buf, = n * 4); + int i; + + n =3D got / 4; + if (n =3D=3D 0) { + break; + } + for (i =3D 0; i < n; i++) { + uint32_t j =3D (s->in_wr + i) & (HARMONY_IN_RING - 1); + + s->in_ring[2 * j] =3D s->in_buf[2 * i]; + s->in_ring[2 * j + 1] =3D s->in_buf[2 * i + 1]; + } + s->in_wr +=3D n; + frames -=3D n; + } + if (s->in_wr - s->in_rd > max_backlog) { + s->in_rd =3D s->in_wr - max_backlog; + } +} + +static void harmony_open_voices(HarmonyState *s) +{ + struct audsettings as =3D { + .freq =3D harmony_freq(s), + .nchannels =3D 2, + .fmt =3D AUDIO_FORMAT_S16, + .big_endian =3D HOST_BIG_ENDIAN, + }; + + if (s->voice_out && as.freq =3D=3D s->freq) { + return; + } + s->freq =3D as.freq; + trace_harmony_config(as.freq, harmony_format(s), harmony_channels(s)); + + s->voice_out =3D audio_be_open_out(s->audio_be, s->voice_out, "harmony= .out", + s, harmony_out_cb, &as); + s->voice_in =3D audio_be_open_in(s->audio_be, s->voice_in, "harmony.in= ", + s, harmony_in_cb, &as); + + /* reopening leaves the voices inactive; restore their state */ + if (s->voice_out) { + audio_be_set_active_out(s->audio_be, s->voice_out, s->out_active); + } + if (s->voice_in) { + audio_be_set_active_in(s->audio_be, s->voice_in, s->in_active); + } + harmony_update_active(s); +} + +static const char *harmony_reg_name(hwaddr addr) +{ + switch (addr) { + case HARMONY_ID: return "ID"; + case HARMONY_RESET: return "RESET"; + case HARMONY_CNTL: return "CNTL"; + case HARMONY_GAINCTL: return "GAINCTL"; + case HARMONY_PNXTADD: return "PNXTADD"; + case HARMONY_PCURADD: return "PCURADD"; + case HARMONY_RNXTADD: return "RNXTADD"; + case HARMONY_RCURADD: return "RCURADD"; + case HARMONY_DSTATUS: return "DSTATUS"; + case HARMONY_OV: return "OV"; + case HARMONY_PIO: return "PIO"; + case HARMONY_DIAG: return "DIAG"; + default: return "?"; + } +} + +static uint64_t harmony_read(void *opaque, hwaddr addr, unsigned size) +{ + HarmonyState *s =3D opaque; + uint32_t val =3D 0; + + switch (addr) { + case HARMONY_ID: + val =3D s->id; + break; + case HARMONY_RESET: + val =3D s->reset; + break; + case HARMONY_CNTL: + /* control writes complete at once, so C never reads back set */ + val =3D (s->cntl & ~(CNTL_C | CNTL_CODEC_REV_MASK)) | + (s->codec_rev << CNTL_CODEC_REV_SHIFT); + break; + case HARMONY_GAINCTL: + val =3D s->gainctl; + break; + case HARMONY_PNXTADD: + val =3D s->pnxtadd; + break; + case HARMONY_PCURADD: + val =3D s->pcuradd + s->poff; + break; + case HARMONY_RNXTADD: + val =3D s->rnxtadd; + break; + case HARMONY_RCURADD: + val =3D s->rcuradd + s->roff; + break; + case HARMONY_DSTATUS: + val =3D s->dstatus & DSTATUS_IE; + val |=3D s->pnxt_valid ? 0 : DSTATUS_PN; + val |=3D s->rnxt_valid ? 0 : DSTATUS_RN; + if (harmony_running(s)) { + val |=3D s->pcur_valid ? DSTATUS_PC : 0; + val |=3D s->rcur_valid ? DSTATUS_RC : 0; + } + break; + case HARMONY_OV: + val =3D s->ov; + break; + case HARMONY_PIO: + val =3D s->pio & PIO_PO; + break; + case HARMONY_DIAG: + val =3D (s->reset & RESET_RST) ? 0 : DIAG_CO; + break; + default: + qemu_log_mask(LOG_UNIMP, "harmony: read from unknown register " + "0x%" HWADDR_PRIx "\n", addr); + break; + } + + trace_harmony_reg_read(addr, harmony_reg_name(addr), val); + return val; +} + +static void harmony_write(void *opaque, hwaddr addr, uint64_t val64, + unsigned size) +{ + HarmonyState *s =3D opaque; + uint32_t val =3D val64; + + trace_harmony_reg_write(addr, harmony_reg_name(addr), val); + + switch (addr) { + case HARMONY_RESET: + s->reset =3D val & RESET_RST; + harmony_load(s); + harmony_update_active(s); + break; + case HARMONY_CNTL: + s->cntl =3D val & ~CNTL_C; + harmony_open_voices(s); + break; + case HARMONY_GAINCTL: + s->gainctl =3D val; + break; + case HARMONY_PNXTADD: + s->pnxtadd =3D val; + s->pnxt_valid =3D true; + harmony_load(s); + harmony_update_active(s); + harmony_resume(s); + break; + case HARMONY_RNXTADD: + s->rnxtadd =3D val; + s->rnxt_valid =3D true; + harmony_load(s); + harmony_update_active(s); + harmony_resume(s); + break; + case HARMONY_DSTATUS: + s->dstatus =3D val & DSTATUS_IE; + harmony_load(s); + harmony_update_irq(s); + harmony_update_active(s); + break; + case HARMONY_OV: + s->ov =3D val & OV_OV; + break; + case HARMONY_PIO: + s->pio =3D val & PIO_PO; + break; + case HARMONY_ID: + case HARMONY_PCURADD: + case HARMONY_RCURADD: + case HARMONY_DIAG: + qemu_log_mask(LOG_GUEST_ERROR, "harmony: write to read-only regist= er " + "%s\n", harmony_reg_name(addr)); + break; + default: + qemu_log_mask(LOG_UNIMP, "harmony: write to unknown register " + "0x%" HWADDR_PRIx "\n", addr); + break; + } +} + +static const MemoryRegionOps harmony_ops =3D { + .read =3D harmony_read, + .write =3D harmony_write, + .endianness =3D DEVICE_BIG_ENDIAN, + .valid =3D { + .min_access_size =3D 1, + .max_access_size =3D 4, + }, + .impl =3D { + .min_access_size =3D 4, + .max_access_size =3D 4, + }, +}; + +static void harmony_reset_hold(Object *obj, ResetType type) +{ + HarmonyState *s =3D HARMONY(obj); + + s->reset =3D 0; + s->cntl =3D 0x08; /* 8 kHz, S16BE, mono */ + s->gainctl =3D 0; + s->pnxtadd =3D 0; + s->rnxtadd =3D 0; + s->dstatus =3D 0; + s->ov =3D 0; + s->pio =3D 0; + s->pcuradd =3D 0; + s->poff =3D 0; + s->rcuradd =3D 0; + s->roff =3D 0; + s->pcur_valid =3D false; + s->pnxt_valid =3D false; + s->rcur_valid =3D false; + s->rnxt_valid =3D false; + + harmony_update_irq(s); + harmony_open_voices(s); + harmony_set_voices(s, false, false); + s->rec_seen =3D false; + s->starved =3D false; + s->idle_ticks =3D 0; +} + +static int harmony_post_load(void *opaque, int version_id) +{ + HarmonyState *s =3D opaque; + + s->freq =3D 0; + harmony_open_voices(s); + if (s->voice_out) { + audio_be_set_active_out(s->audio_be, s->voice_out, false); + } + if (s->voice_in) { + audio_be_set_active_in(s->audio_be, s->voice_in, false); + } + s->out_active =3D false; + s->in_active =3D false; + s->rec_seen =3D false; + s->starved =3D false; + s->idle_ticks =3D 0; + harmony_update_active(s); + qemu_set_irq(s->irq, s->irq_level); + return 0; +} + +static const VMStateDescription vmstate_harmony =3D { + .name =3D "harmony", + .version_id =3D 1, + .minimum_version_id =3D 1, + .post_load =3D harmony_post_load, + .fields =3D (const VMStateField[]) { + VMSTATE_UINT32(reset, HarmonyState), + VMSTATE_UINT32(cntl, HarmonyState), + VMSTATE_UINT32(gainctl, HarmonyState), + VMSTATE_UINT32(pnxtadd, HarmonyState), + VMSTATE_UINT32(rnxtadd, HarmonyState), + VMSTATE_UINT32(dstatus, HarmonyState), + VMSTATE_UINT32(ov, HarmonyState), + VMSTATE_UINT32(pio, HarmonyState), + VMSTATE_UINT32(pcuradd, HarmonyState), + VMSTATE_UINT32(poff, HarmonyState), + VMSTATE_UINT32(rcuradd, HarmonyState), + VMSTATE_UINT32(roff, HarmonyState), + VMSTATE_BOOL(pcur_valid, HarmonyState), + VMSTATE_BOOL(pnxt_valid, HarmonyState), + VMSTATE_BOOL(rcur_valid, HarmonyState), + VMSTATE_BOOL(rnxt_valid, HarmonyState), + VMSTATE_INT32(irq_level, HarmonyState), + VMSTATE_END_OF_LIST() + } +}; + +static void harmony_realize(DeviceState *dev, Error **errp) +{ + HarmonyState *s =3D HARMONY(dev); + int i; + + /* + * Output attenuation is 1.5 dB per step. HP-UX puts its 0 dB play ga= in + * at attenuation 6 (range -84..+9 dB), so that step is unity here and + * the steps below it amplify, saturating at full scale. + */ + for (i =3D 0; i < 64; i++) { + s->out_att[i] =3D lrint(32768.0 * + pow(10.0, -1.5 * (i - s->out_unity_att) / 20= .0)); + } + + if (!audio_be_check(&s->audio_be, errp)) { + return; + } + + harmony_open_voices(s); + if (!s->voice_out) { + error_setg(errp, "harmony: initializing audio output failed"); + return; + } +} + +static void harmony_unrealize(DeviceState *dev) +{ + HarmonyState *s =3D HARMONY(dev); + + if (s->voice_in) { + audio_be_close_in(s->audio_be, s->voice_in); + s->voice_in =3D NULL; + } + if (s->voice_out) { + audio_be_close_out(s->audio_be, s->voice_out); + s->voice_out =3D NULL; + } +} + +static void harmony_init(Object *obj) +{ + HarmonyState *s =3D HARMONY(obj); + SysBusDevice *sbd =3D SYS_BUS_DEVICE(obj); + + memory_region_init_io(&s->mmio, obj, &harmony_ops, s, "harmony", + HARMONY_MMIO_SIZE); + sysbus_init_mmio(sbd, &s->mmio); + sysbus_init_irq(sbd, &s->irq); +} + +static const Property harmony_properties[] =3D { + DEFINE_AUDIO_PROPERTIES(HarmonyState, audio_be), + /* revision 0x14 =3D no teleshare, 0x15 =3D teleshare */ + DEFINE_PROP_UINT32("id", HarmonyState, id, 0x00140000), + DEFINE_PROP_UINT8("codec-rev", HarmonyState, codec_rev, 0x02), + DEFINE_PROP_UINT8("out-unity-att", HarmonyState, out_unity_att, 6), +}; + +static void harmony_class_init(ObjectClass *oc, const void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(oc); + ResettableClass *rc =3D RESETTABLE_CLASS(oc); + + harmony_init_tables(); + + dc->realize =3D harmony_realize; + dc->unrealize =3D harmony_unrealize; + dc->vmsd =3D &vmstate_harmony; + dc->desc =3D "HP Harmony audio"; + set_bit(DEVICE_CATEGORY_SOUND, dc->categories); + device_class_set_props(dc, harmony_properties); + rc->phases.hold =3D harmony_reset_hold; +} + +static const TypeInfo harmony_info =3D { + .name =3D TYPE_HARMONY, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(HarmonyState), + .instance_init =3D harmony_init, + .class_init =3D harmony_class_init, +}; + +static void harmony_register_types(void) +{ + type_register_static(&harmony_info); +} + +type_init(harmony_register_types) diff --git a/hw/audio/trace-events b/hw/audio/trace-events index 30f5921545..99d39075c2 100644 --- a/hw/audio/trace-events +++ b/hw/audio/trace-events @@ -61,3 +61,13 @@ virtio_snd_handle_event(void) "event queue callback call= ed" virtio_snd_pcm_stream_flush(uint32_t stream) "flushing stream %"PRIu32 virtio_snd_handle_tx_xfer(void) "tx queue callback called" virtio_snd_handle_rx_xfer(void) "rx queue callback called" + +# harmony.c +harmony_reg_read(uint64_t addr, const char *name, uint32_t val) "0x%02"PRI= x64" %s -> 0x%08x" +harmony_reg_write(uint64_t addr, const char *name, uint32_t val) "0x%02"PR= Ix64" %s <- 0x%08x" +harmony_irq(int level) "irq %d" +harmony_page(const char *dir, uint32_t addr) "%s page 0x%08x" +harmony_starved(int play, int rec) "no next page queued (play %d rec %d)" +harmony_rec_read(int want, int got, int backlog) "want %d got %d frames, b= acklog %d" +harmony_in_cb(int avail) "input voice has %d bytes" +harmony_config(int freq, int fmt, int channels) "%d Hz format %d channels = %d" diff --git a/include/hw/audio/harmony.h b/include/hw/audio/harmony.h new file mode 100644 index 0000000000..0a0f6c4dfa --- /dev/null +++ b/include/hw/audio/harmony.h @@ -0,0 +1,76 @@ +/* + * HP Harmony audio (LASI audio function, CS4215/AD1849 codec) + * + * Copyright (c) 2026 Keith Monahan + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef HW_AUDIO_HARMONY_H +#define HW_AUDIO_HARMONY_H + +#include "hw/core/sysbus.h" +#include "qemu/audio.h" +#include "qom/object.h" + +#define TYPE_HARMONY "harmony" +OBJECT_DECLARE_SIMPLE_TYPE(HarmonyState, HARMONY) + +#define HARMONY_MMIO_SIZE 0x1000 +#define HARMONY_PAGE_SIZE 4096 +#define HARMONY_MIX_FRAMES 1024 +#define HARMONY_IN_RING 8192 /* frames, power of 2 */ + +struct HarmonyState { + SysBusDevice parent_obj; + + MemoryRegion mmio; + qemu_irq irq; + AudioBackend *audio_be; + SWVoiceOut *voice_out; + SWVoiceIn *voice_in; + + /* properties */ + uint32_t id; + uint8_t codec_rev; + uint8_t out_unity_att; + + /* registers */ + uint32_t reset; + uint32_t cntl; + uint32_t gainctl; + uint32_t pnxtadd; + uint32_t rnxtadd; + uint32_t dstatus; /* IE only, PN/RN are below */ + uint32_t ov; + uint32_t pio; + + /* DMA engine, playback and record share the codec sample clock */ + uint32_t pcuradd; + uint32_t poff; + uint32_t rcuradd; + uint32_t roff; + bool pcur_valid; + bool pnxt_valid; /* PN =3D !pnxt_valid */ + bool rcur_valid; + bool rnxt_valid; /* RN =3D !rnxt_valid */ + + int irq_level; + int freq; + int32_t out_att[64]; /* Q15 per attenuation step */ + + int16_t out_buf[HARMONY_MIX_FRAMES * 2]; + int16_t in_buf[HARMONY_MIX_FRAMES * 2]; + /* host input captured by the input voice, consumed at the codec clock= */ + int16_t in_ring[HARMONY_IN_RING * 2]; + uint32_t in_rd; + uint32_t in_wr; + bool out_active; + bool in_active; + bool rec_seen; + bool starved; + int idle_ticks; + uint8_t dma_buf[HARMONY_MIX_FRAMES * 4]; +}; + +#endif --=20 2.54.0 From nobody Mon Nov 23 04:18:05 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1793227770; cv=none; d=zohomail.com; s=zohoarc; b=Is8J7zqxv6bozAnyx5Ge65DbfKDo7Ms/z5VBSSHMS7GKAZNjAG369XvNSplKRu34Y8nGGnR0irGC9HBxnTY5TZgQ45HRgiVQU+U9h6/a1nwcot9rt1QivwPFE8WbJlmXPEgXSFoiHaLWeW/4fBCNz0LiwUzE9ndjwSWB1V0JiGY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793227770; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=0yiUY2Z9qQHK+/rTlkffNQL8k1/sn9HIstSC9OkeCc0=; b=idI8EpAjRBiEyuaEJ2IPFNJIR+X3aNyiwCMDK9cFSUI7sWCvNRTPOx4XC0Ck+DFi1O9m9n9IZVmuw7v1q+ugrlWUlIjRyMQiV6jpR3IgocMfMYvllgcyDIVmRj/FXXwP1ZNggSifHNMOVvDG4ZmL9gT7nWIrjFXpaae4c/jfZNQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793227770551220.80437386991116; Wed, 28 Oct 2026 15:49:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMCRW-0001tv-AR; Wed, 28 Oct 2026 18:48:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMCRV-0001tP-2J for qemu-devel@nongnu.org; Wed, 28 Oct 2026 18:48:25 -0400 Received: from sea.source.kernel.org ([172.234.252.31]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMCRT-0007cn-LJ for qemu-devel@nongnu.org; Wed, 28 Oct 2026 18:48:24 -0400 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 3F57140C1F; Wed, 28 Oct 2026 22:48:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ECF531F01828; Wed, 28 Oct 2026 22:48:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793227702; bh=0yiUY2Z9qQHK+/rTlkffNQL8k1/sn9HIstSC9OkeCc0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ZaVmHYpFM5pgd3Q007lMKsHusEtsu+Xx/zqrv3/CBhlFEtDkzvsWN278xLCaykZF4 t65Zr9A0KOYY8REFnwZbLE3NYDSB2ajP7/ZuSDudeRp4hiA5b/Ctzwx6Y8jF7bg8a7 Y+qDm2I+kp7JGSBzwhNxtlAJfapbV2vB2IgTVODAkLhg5LQJN0B5VQYkQRcsEzQyk+ kdXmWykJL8InIcRjahjt1loOtwUl4iC3ydsTNldQlvMY7FvyBoR5RRivWq4n23akyS IEoSUfL8n9F1kENz70uB7cIdWcrfqQtUIg3ClzyVL8kU8rnrOjB/gzFo7S/1fY8lwr Ddg9JDZce9q4w== From: Helge Deller To: qemu-devel@nongnu.org Cc: Richard Henderson , Keith Monahan , Gerd Hoffmann , Helge Deller Subject: [PATCH 2/4] hw/audio: Wire up the harmony driver in meson and Kconfig Date: Wed, 28 Oct 2026 23:48:13 +0100 Message-ID: <20261028224815.32502-3-deller@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20261028224815.32502-1-deller@kernel.org> References: <20261028224815.32502-1-deller@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=172.234.252.31; envelope-from=deller@kernel.org; helo=sea.source.kernel.org X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1793227772075158500 Content-Type: text/plain; charset="utf-8" From: Keith Monahan Signed-off-by: Keith Monahan --- hw/audio/Kconfig | 3 +++ hw/audio/meson.build | 1 + 2 files changed, 4 insertions(+) diff --git a/hw/audio/Kconfig b/hw/audio/Kconfig index ed93fa2698..ba6f66342e 100644 --- a/hw/audio/Kconfig +++ b/hw/audio/Kconfig @@ -51,3 +51,6 @@ config VIRTIO_SND bool default y depends on VIRTIO + +config HARMONY + bool diff --git a/hw/audio/meson.build b/hw/audio/meson.build index 3312bcec10..f440324cdf 100644 --- a/hw/audio/meson.build +++ b/hw/audio/meson.build @@ -6,6 +6,7 @@ system_ss.add(when: 'CONFIG_CS4231', if_true: files('cs4231= .c')) system_ss.add(when: 'CONFIG_CS4231A', if_true: files('cs4231a.c')) system_ss.add(when: 'CONFIG_ES1370', if_true: files('es1370.c')) system_ss.add(when: 'CONFIG_GUS', if_true: files('gus.c', 'gusemu_hal.c', = 'gusemu_mixer.c')) +system_ss.add(when: 'CONFIG_HARMONY', if_true: files('harmony.c')) system_ss.add(when: 'CONFIG_HDA', if_true: files('intel-hda.c', 'hda-codec= .c')) system_ss.add(when: 'CONFIG_PCSPK', if_true: files('pcspk.c')) system_ss.add(when: 'CONFIG_PL041', if_true: files('pl041.c', 'lm4549.c')) --=20 2.54.0 From nobody Mon Nov 23 04:18:05 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1793227754; cv=none; d=zohomail.com; s=zohoarc; b=SFF5y0pBvxqIzZgmuLxqUfE0h2tc4kkx6ZC/Ci4eke/7jCQQGOKLHBaoPFPoDRKu7TkLB/RvXrgofIEXFHF+TeVIGVKqoRpUF8zo7aTf1qcLXOQNPcu1ZranJHDGntGGb9Lncu0EFMiLVkJz9LiAwqJ8ShyUMeEeDtQln6RU1cY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793227754; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=18S4xiqd0zh/+ecdsNiuR0/WNpS+taOR9QWxO/S66Jo=; b=BTlf2dGfAAx9dAfLxT+rxgCNTE33zLMNwVWecziKl78UdB/lbSNtAYnGBH1npMWRD8gfzZvN/IoUtkNrj60DgqwR7Bed6eu8ytRFH7InhWvQevpgjzbLYQPRkH+WC/0zmytrOjSwiTsZ80bNAbGKsjGJQ3f1aIN4FNPHH5yN3jY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 179322775471056.86596053424694; Wed, 28 Oct 2026 15:49:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMCRX-0001uH-CU; Wed, 28 Oct 2026 18:48:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMCRW-0001u8-Dq for qemu-devel@nongnu.org; Wed, 28 Oct 2026 18:48:26 -0400 Received: from sea.source.kernel.org ([172.234.252.31]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMCRU-0007cr-Pb for qemu-devel@nongnu.org; Wed, 28 Oct 2026 18:48:26 -0400 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id D513B42E9D; Wed, 28 Oct 2026 22:48:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8EBE11F01825; Wed, 28 Oct 2026 22:48:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793227703; bh=18S4xiqd0zh/+ecdsNiuR0/WNpS+taOR9QWxO/S66Jo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=W3UhUFIZdwhgBdrwZjLCHyWCuztDvetbV954De5X8+EEKJh1L9NMeQ+ZKhVwg6tv2 +T6uvdMWPgu1zl9OA+rvBkYgaLP2WgZGzUC/HYZB1u4SEWYfLYra5cilJ7aM/vOmhR qSks4b/0wbRJhXVavLkJz4QP546zdq2csMO5bE3+BJSYJ5hPVT4N6I0KoqHvcXJrDE qXG8vx/KhqfjPQH/xSMf49AXi1dggd/tStk2Jlc8hW2ZyXo243pO0OCZY0JNf3TU0r BbkW55ZXZbgtMFUlId906VEJkhxnG/IRzMwQuiOB+Ze5eYrs8UPfMIDPuzM8lAo5HR f36vgInpm2tOg== From: Helge Deller To: qemu-devel@nongnu.org Cc: Richard Henderson , Keith Monahan , Gerd Hoffmann , Helge Deller Subject: [PATCH 3/4] hw/hppa: Add harmony sound card to HP 715 and B160L machines Date: Wed, 28 Oct 2026 23:48:14 +0100 Message-ID: <20261028224815.32502-4-deller@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20261028224815.32502-1-deller@kernel.org> References: <20261028224815.32502-1-deller@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=172.234.252.31; envelope-from=deller@kernel.org; helo=sea.source.kernel.org X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1793227755870158500 Content-Type: text/plain; charset="utf-8" From: Keith Monahan Signed-off-by: Keith Monahan --- hw/hppa/Kconfig | 1 + hw/hppa/machine.c | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/hw/hppa/Kconfig b/hw/hppa/Kconfig index 9ede4d1140..d00d7ca040 100644 --- a/hw/hppa/Kconfig +++ b/hw/hppa/Kconfig @@ -19,3 +19,4 @@ config HPPA_B160L select LSI_SCSI_PCI select PARALLEL select ARTIST + select HARMONY diff --git a/hw/hppa/machine.c b/hw/hppa/machine.c index f23936fc5b..940bf2c72e 100644 --- a/hw/hppa/machine.c +++ b/hw/hppa/machine.c @@ -32,6 +32,7 @@ #include "hw/misc/lasi.h" #include "hw/scsi/ncr53c710.h" #include "hw/scsi/lasi_ncr710.h" +#include "hw/audio/harmony.h" #include "hppa_hardware.h" #include "qemu/units.h" #include "qapi/error.h" @@ -271,6 +272,21 @@ static LasiState *lasi_init(void) return LASI_CHIP(dev); } =20 +/* Harmony audio, inside the LASI register block at LASI + 0x4000 */ +static void harmony_create(MachineState *machine, hwaddr addr, qemu_irq ir= q) +{ + DeviceState *dev =3D qdev_new(TYPE_HARMONY); + + if (machine->audiodev) { + qdev_prop_set_string(dev, "audiodev", machine->audiodev); + } + sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); + sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, irq); + memory_region_add_subregion_overlap(get_system_memory(), addr, + sysbus_mmio_get_region( + SYS_BUS_DEVICE(dev), 0), 1); +} + static DinoState *dino_init(MemoryRegion *addr_space) { DeviceState *dev; @@ -699,6 +715,9 @@ static void machine_HP_715_init(MachineState *machine) sysbus_mmio_get_region(SYS_BUS_DEVICE(= dev), 0)); } =20 + harmony_create(machine, translate(NULL, LASI_HPA_715 + LASI_AUDIO), + qdev_get_gpio_in(lasi_dev, LASI_IRQ_AUDIO_HPA)); + /* Add NICs, graphics & load firmware */ machine_HP_common_init_tail(machine, NULL, translate, false); } @@ -778,6 +797,9 @@ static void machine_HP_B160L_init(MachineState *machine) lsi53c8xx_handle_legacy_cmdline(dev); } =20 + harmony_create(machine, translate(NULL, LASI_HPA + LASI_AUDIO), + qdev_get_gpio_in(lasi_dev, LASI_IRQ_AUDIO_HPA)); + /* Add NICs, graphics & load firmware */ machine_HP_common_init_tail(machine, pci_bus, translate, false); } @@ -985,6 +1007,7 @@ static void HP_B160L_machine_init_class_init(ObjectCla= ss *oc, const void *data) mc->init =3D machine_HP_B160L_init; mc->is_default =3D true; mc->default_ram_size =3D 512 * MiB; + machine_add_audiodev_property(mc); } =20 static void HP_C3700_machine_init_class_init(ObjectClass *oc, const void *= data) @@ -1036,6 +1059,7 @@ static void HP_715_machine_init_class_init(ObjectClas= s *oc, const void *data) mc->default_cpu_type =3D TYPE_HPPA_CPU_PA_7300LC; mc->valid_cpu_types =3D valid_cpu_types; mc->init =3D machine_HP_715_init; + machine_add_audiodev_property(mc); /* can only support up to max. 8 CPUs due inventory major numbers */ mc->max_cpus =3D MIN_CONST(HPPA_MAX_CPUS, 8); mc->default_ram_size =3D 256 * MiB; --=20 2.54.0 From nobody Mon Nov 23 04:18:05 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1793227753; cv=none; d=zohomail.com; s=zohoarc; b=Jdae2U1gjmuh2BhqxtbwHb01qxFXRNZH48WsneEqxsf2fH5UzbxcyExCp9gEdMnZ9/ztVVBrwLpDQoNX+BZ0Y0NZWTgdJY1ZjLE4AAabicw9BVdQ61tdF8PDNex0jlIJ9sh+UGCHlTAcbBI/8lVD5fRyjNyBdzWyda+Mzv3UxaE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793227753; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=zf5ppi2teIHh97kn4uw3WTJifd4Yq00Q4xRpdEtBweI=; b=mzjCdPS2x1PQNs9epqaakIBfRbzntrJB8a4WtI1PxsdyzlYOA8faiDK7JqHZX8JoTrnjb1/pRm7Y0L1CC9a3i5XfohSjELssEZx9htEy1l2VwLVQ/HjDJ/V9Y63CaMfmkrmylaC/NE0ebmiQifRAhmYRI7hWTADEBGp1x54Cif0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793227753600532.5094787388488; Wed, 28 Oct 2026 15:49:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMCRa-0001vC-Ht; Wed, 28 Oct 2026 18:48:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMCRX-0001uJ-TU for qemu-devel@nongnu.org; Wed, 28 Oct 2026 18:48:28 -0400 Received: from sea.source.kernel.org ([172.234.252.31]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMCRW-0007d6-C0 for qemu-devel@nongnu.org; Wed, 28 Oct 2026 18:48:27 -0400 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 745CA435D3; Wed, 28 Oct 2026 22:48:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F0151F01825; Wed, 28 Oct 2026 22:48:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793227705; bh=zf5ppi2teIHh97kn4uw3WTJifd4Yq00Q4xRpdEtBweI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=OKPf4J/tp2W4MD2O1WIlRIUh1pSjo8CiA08GA/0I1rJ42Wc+iupX6VSDDR7NVi3dc cgy9upnDyZW0XVwrbcuTfVLn/zdnOuqeoV6sBJKyw8UH5b2kmtgD3l4H5cjK/Mv9Q4 r0xs7/2cSiqrpDn+pEceQp3lbBa8KbNpsNrWO6R4J+6g4jLgp5yjuZcVfYkg/upAyL qruKLzqSB4nyLF9heBW1VHaRMHsM7VIWJq+YliPJ7Yl+K3BQM1K6FpZBa1oVo8Vzjh OaRCCtLIOKWvVP48vZL9c5Os4c+DVASvOSSheVxQ5cz95ZRo+j1ppclQSziA/l3dPS lB+tzdzF/qzlw== From: Helge Deller To: qemu-devel@nongnu.org Cc: Richard Henderson , Keith Monahan , Gerd Hoffmann , Helge Deller Subject: [PATCH 4/4] hw/misc: Harmony sound registers now handled by harmony driver Date: Wed, 28 Oct 2026 23:48:15 +0100 Message-ID: <20261028224815.32502-5-deller@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20261028224815.32502-1-deller@kernel.org> References: <20261028224815.32502-1-deller@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=172.234.252.31; envelope-from=deller@kernel.org; helo=sea.source.kernel.org X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1793227754190158500 Content-Type: text/plain; charset="utf-8" From: Helge Deller No need to handle the LASI AUDIO registers here. Signed-off-by: Helge Deller --- hw/misc/lasi.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/hw/misc/lasi.c b/hw/misc/lasi.c index 76029804e1..d4ef832af1 100644 --- a/hw/misc/lasi.c +++ b/hw/misc/lasi.c @@ -86,13 +86,7 @@ static MemTxResult lasi_chip_read_with_attrs(void *opaqu= e, hwaddr addr, val =3D s->iar; break; =20 - case LASI_AUDIO ... LASI_AUDIO + 0xFF: - /* - * Harmony audio not yet emulated. DIAG (0x3c) reports a running - * sample clock, which HP-UX 9 checks before using the beeper. - */ - val =3D (addr =3D=3D LASI_AUDIO + 0x3c); - break; + case LASI_AUDIO: /* handled by harmony audio driver */ case LASI_LPT: case LASI_UART: case LASI_LAN: @@ -164,8 +158,8 @@ static MemTxResult lasi_chip_write_with_attrs(void *opa= que, hwaddr addr, case LASI_LPT: /* XXX: reset parallel port */ break; - case LASI_AUDIO ... LASI_AUDIO + 0xFF: - /* XXX: Harmony audio is not emulated */ + case LASI_AUDIO: + /* handled by harmony audio driver */ break; case LASI_UART: /* XXX: reset serial port */ --=20 2.54.0