2008-01-14 07:27:55 +03:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2006 InnoTek Systemberatung GmbH
|
|
|
|
*
|
|
|
|
* This file is part of VirtualBox Open Source Edition (OSE), as
|
|
|
|
* available from http://www.virtualbox.org. This file is free software;
|
|
|
|
* you can redistribute it and/or modify it under the terms of the GNU
|
|
|
|
* General Public License as published by the Free Software Foundation,
|
|
|
|
* in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
|
|
|
* distribution. VirtualBox OSE is distributed in the hope that it will
|
|
|
|
* be useful, but WITHOUT ANY WARRANTY of any kind.
|
|
|
|
*
|
|
|
|
* If you received this file as part of a commercial VirtualBox
|
|
|
|
* distribution, then only the terms of your commercial VirtualBox
|
|
|
|
* license agreement apply instead of the previous paragraph.
|
2012-01-13 20:44:23 +04:00
|
|
|
*
|
|
|
|
* Contributions after 2012-01-13 are licensed under the terms of the
|
|
|
|
* GNU GPL, version 2 or (at your option) any later version.
|
2008-01-14 07:27:55 +03:00
|
|
|
*/
|
|
|
|
|
2016-01-18 20:33:52 +03:00
|
|
|
#include "qemu/osdep.h"
|
2017-05-08 23:57:35 +03:00
|
|
|
#include "hw/audio/soundhw.h"
|
2008-01-14 07:27:55 +03:00
|
|
|
#include "audio/audio.h"
|
2022-12-22 13:03:28 +03:00
|
|
|
#include "hw/pci/pci_device.h"
|
2019-08-12 08:23:51 +03:00
|
|
|
#include "hw/qdev-properties.h"
|
2019-08-12 08:23:45 +03:00
|
|
|
#include "migration/vmstate.h"
|
2019-05-23 17:35:07 +03:00
|
|
|
#include "qemu/module.h"
|
2012-12-17 21:20:04 +04:00
|
|
|
#include "sysemu/dma.h"
|
2020-09-03 23:43:22 +03:00
|
|
|
#include "qom/object.h"
|
2022-01-25 22:48:36 +03:00
|
|
|
#include "ac97.h"
|
2008-01-14 07:27:55 +03:00
|
|
|
|
|
|
|
#define SOFT_VOLUME
|
|
|
|
#define SR_FIFOE 16 /* rwc */
|
|
|
|
#define SR_BCIS 8 /* rwc */
|
|
|
|
#define SR_LVBCI 4 /* rwc */
|
|
|
|
#define SR_CELV 2 /* ro */
|
|
|
|
#define SR_DCH 1 /* ro */
|
|
|
|
#define SR_VALID_MASK ((1 << 5) - 1)
|
|
|
|
#define SR_WCLEAR_MASK (SR_FIFOE | SR_BCIS | SR_LVBCI)
|
|
|
|
#define SR_RO_MASK (SR_DCH | SR_CELV)
|
|
|
|
#define SR_INT_MASK (SR_FIFOE | SR_BCIS | SR_LVBCI)
|
|
|
|
|
|
|
|
#define CR_IOCE 16 /* rw */
|
|
|
|
#define CR_FEIE 8 /* rw */
|
|
|
|
#define CR_LVBIE 4 /* rw */
|
|
|
|
#define CR_RR 2 /* rw */
|
|
|
|
#define CR_RPBM 1 /* rw */
|
|
|
|
#define CR_VALID_MASK ((1 << 5) - 1)
|
|
|
|
#define CR_DONT_CLEAR_MASK (CR_IOCE | CR_FEIE | CR_LVBIE)
|
|
|
|
|
|
|
|
#define GC_WR 4 /* rw */
|
|
|
|
#define GC_CR 2 /* rw */
|
|
|
|
#define GC_VALID_MASK ((1 << 6) - 1)
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
#define GS_MD3 (1 << 17) /* rw */
|
|
|
|
#define GS_AD3 (1 << 16) /* rw */
|
|
|
|
#define GS_RCS (1 << 15) /* rwc */
|
|
|
|
#define GS_B3S12 (1 << 14) /* ro */
|
|
|
|
#define GS_B2S12 (1 << 13) /* ro */
|
|
|
|
#define GS_B1S12 (1 << 12) /* ro */
|
|
|
|
#define GS_S1R1 (1 << 11) /* rwc */
|
|
|
|
#define GS_S0R1 (1 << 10) /* rwc */
|
|
|
|
#define GS_S1CR (1 << 9) /* ro */
|
|
|
|
#define GS_S0CR (1 << 8) /* ro */
|
|
|
|
#define GS_MINT (1 << 7) /* ro */
|
|
|
|
#define GS_POINT (1 << 6) /* ro */
|
|
|
|
#define GS_PIINT (1 << 5) /* ro */
|
|
|
|
#define GS_RSRVD ((1 << 4) | (1 << 3))
|
|
|
|
#define GS_MOINT (1 << 2) /* ro */
|
|
|
|
#define GS_MIINT (1 << 1) /* ro */
|
2008-01-14 07:27:55 +03:00
|
|
|
#define GS_GSCI 1 /* rwc */
|
2022-04-23 12:36:57 +03:00
|
|
|
#define GS_RO_MASK (GS_B3S12 | \
|
|
|
|
GS_B2S12 | \
|
|
|
|
GS_B1S12 | \
|
|
|
|
GS_S1CR | \
|
|
|
|
GS_S0CR | \
|
|
|
|
GS_MINT | \
|
|
|
|
GS_POINT | \
|
|
|
|
GS_PIINT | \
|
|
|
|
GS_RSRVD | \
|
|
|
|
GS_MOINT | \
|
2008-01-14 07:27:55 +03:00
|
|
|
GS_MIINT)
|
|
|
|
#define GS_VALID_MASK ((1 << 18) - 1)
|
2022-04-23 12:36:57 +03:00
|
|
|
#define GS_WCLEAR_MASK (GS_RCS | GS_S1R1 | GS_S0R1 | GS_GSCI)
|
2008-01-14 07:27:55 +03:00
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
#define BD_IOC (1 << 31)
|
|
|
|
#define BD_BUP (1 << 30)
|
2008-01-14 07:27:55 +03:00
|
|
|
|
2018-10-13 09:08:09 +03:00
|
|
|
#define TYPE_AC97 "AC97"
|
2020-09-16 21:25:19 +03:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(AC97LinkState, AC97)
|
2018-10-13 09:08:09 +03:00
|
|
|
|
2008-01-14 07:27:55 +03:00
|
|
|
#define REC_MASK 7
|
|
|
|
enum {
|
|
|
|
REC_MIC = 0,
|
|
|
|
REC_CD,
|
|
|
|
REC_VIDEO,
|
|
|
|
REC_AUX,
|
|
|
|
REC_LINE_IN,
|
|
|
|
REC_STEREO_MIX,
|
|
|
|
REC_MONO_MIX,
|
|
|
|
REC_PHONE
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct BD {
|
|
|
|
uint32_t addr;
|
|
|
|
uint32_t ctl_len;
|
|
|
|
} BD;
|
|
|
|
|
|
|
|
typedef struct AC97BusMasterRegs {
|
|
|
|
uint32_t bdbar; /* rw 0 */
|
|
|
|
uint8_t civ; /* ro 0 */
|
|
|
|
uint8_t lvi; /* rw 0 */
|
|
|
|
uint16_t sr; /* rw 1 */
|
|
|
|
uint16_t picb; /* ro 0 */
|
|
|
|
uint8_t piv; /* ro 0 */
|
|
|
|
uint8_t cr; /* rw 0 */
|
|
|
|
unsigned int bd_valid;
|
|
|
|
BD bd;
|
|
|
|
} AC97BusMasterRegs;
|
|
|
|
|
2020-09-03 23:43:22 +03:00
|
|
|
struct AC97LinkState {
|
2009-08-21 15:56:09 +04:00
|
|
|
PCIDevice dev;
|
2008-01-14 07:27:55 +03:00
|
|
|
QEMUSoundCard card;
|
|
|
|
uint32_t glob_cnt;
|
|
|
|
uint32_t glob_sta;
|
|
|
|
uint32_t cas;
|
|
|
|
uint32_t last_samp;
|
|
|
|
AC97BusMasterRegs bm_regs[3];
|
|
|
|
uint8_t mixer_data[256];
|
|
|
|
SWVoiceIn *voice_pi;
|
|
|
|
SWVoiceOut *voice_po;
|
|
|
|
SWVoiceIn *voice_mc;
|
2008-06-08 05:07:48 +04:00
|
|
|
int invalid_freq[3];
|
2008-01-14 07:27:55 +03:00
|
|
|
uint8_t silence[128];
|
|
|
|
int bup_flag;
|
2011-08-08 17:09:07 +04:00
|
|
|
MemoryRegion io_nam;
|
|
|
|
MemoryRegion io_nabm;
|
2020-09-03 23:43:22 +03:00
|
|
|
};
|
2008-01-14 07:27:55 +03:00
|
|
|
|
|
|
|
enum {
|
|
|
|
BUP_SET = 1,
|
|
|
|
BUP_LAST = 2
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef DEBUG_AC97
|
2022-04-23 12:36:57 +03:00
|
|
|
#define dolog(...) AUD_log("ac97", __VA_ARGS__)
|
2008-01-14 07:27:55 +03:00
|
|
|
#else
|
|
|
|
#define dolog(...)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define MKREGS(prefix, start) \
|
|
|
|
enum { \
|
|
|
|
prefix ## _BDBAR = start, \
|
|
|
|
prefix ## _CIV = start + 4, \
|
|
|
|
prefix ## _LVI = start + 5, \
|
|
|
|
prefix ## _SR = start + 6, \
|
|
|
|
prefix ## _PICB = start + 8, \
|
|
|
|
prefix ## _PIV = start + 10, \
|
|
|
|
prefix ## _CR = start + 11 \
|
|
|
|
}
|
|
|
|
|
|
|
|
enum {
|
|
|
|
PI_INDEX = 0,
|
|
|
|
PO_INDEX,
|
|
|
|
MC_INDEX,
|
|
|
|
LAST_INDEX
|
|
|
|
};
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
MKREGS(PI, PI_INDEX * 16);
|
|
|
|
MKREGS(PO, PO_INDEX * 16);
|
|
|
|
MKREGS(MC, MC_INDEX * 16);
|
2008-01-14 07:27:55 +03:00
|
|
|
|
|
|
|
enum {
|
|
|
|
GLOB_CNT = 0x2c,
|
|
|
|
GLOB_STA = 0x30,
|
|
|
|
CAS = 0x34
|
|
|
|
};
|
|
|
|
|
|
|
|
#define GET_BM(index) (((index) >> 4) & 3)
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
static void po_callback(void *opaque, int free);
|
|
|
|
static void pi_callback(void *opaque, int avail);
|
|
|
|
static void mc_callback(void *opaque, int avail);
|
2008-01-14 07:27:55 +03:00
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
static void fetch_bd(AC97LinkState *s, AC97BusMasterRegs *r)
|
2008-01-14 07:27:55 +03:00
|
|
|
{
|
|
|
|
uint8_t b[8];
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
pci_dma_read(&s->dev, r->bdbar + r->civ * 8, b, 8);
|
2008-01-14 07:27:55 +03:00
|
|
|
r->bd_valid = 1;
|
2022-04-23 12:36:57 +03:00
|
|
|
r->bd.addr = le32_to_cpu(*(uint32_t *) &b[0]) & ~3;
|
|
|
|
r->bd.ctl_len = le32_to_cpu(*(uint32_t *) &b[4]);
|
2008-01-14 07:27:55 +03:00
|
|
|
r->picb = r->bd.ctl_len & 0xffff;
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("bd %2d addr=0x%x ctl=0x%06x len=0x%x(%d bytes)\n",
|
|
|
|
r->civ, r->bd.addr, r->bd.ctl_len >> 16,
|
|
|
|
r->bd.ctl_len & 0xffff, (r->bd.ctl_len & 0xffff) << 1);
|
2008-01-14 07:27:55 +03:00
|
|
|
}
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
static void update_sr(AC97LinkState *s, AC97BusMasterRegs *r, uint32_t new_sr)
|
2008-01-14 07:27:55 +03:00
|
|
|
{
|
|
|
|
int event = 0;
|
|
|
|
int level = 0;
|
|
|
|
uint32_t new_mask = new_sr & SR_INT_MASK;
|
|
|
|
uint32_t old_mask = r->sr & SR_INT_MASK;
|
|
|
|
uint32_t masks[] = {GS_PIINT, GS_POINT, GS_MINT};
|
|
|
|
|
|
|
|
if (new_mask ^ old_mask) {
|
|
|
|
/** @todo is IRQ deasserted when only one of status bits is cleared? */
|
|
|
|
if (!new_mask) {
|
|
|
|
event = 1;
|
|
|
|
level = 0;
|
2022-04-23 12:36:57 +03:00
|
|
|
} else {
|
2008-01-14 07:27:55 +03:00
|
|
|
if ((new_mask & SR_LVBCI) && (r->cr & CR_LVBIE)) {
|
|
|
|
event = 1;
|
|
|
|
level = 1;
|
|
|
|
}
|
|
|
|
if ((new_mask & SR_BCIS) && (r->cr & CR_IOCE)) {
|
|
|
|
event = 1;
|
|
|
|
level = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
r->sr = new_sr;
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("IOC%d LVB%d sr=0x%x event=%d level=%d\n",
|
|
|
|
r->sr & SR_BCIS, r->sr & SR_LVBCI, r->sr, event, level);
|
2008-01-14 07:27:55 +03:00
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
if (!event) {
|
2008-01-14 07:27:55 +03:00
|
|
|
return;
|
2022-04-23 12:36:57 +03:00
|
|
|
}
|
2008-01-14 07:27:55 +03:00
|
|
|
|
|
|
|
if (level) {
|
|
|
|
s->glob_sta |= masks[r - s->bm_regs];
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("set irq level=1\n");
|
2013-10-07 11:36:39 +04:00
|
|
|
pci_irq_assert(&s->dev);
|
2022-04-23 12:36:57 +03:00
|
|
|
} else {
|
2008-01-14 07:27:55 +03:00
|
|
|
s->glob_sta &= ~masks[r - s->bm_regs];
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("set irq level=0\n");
|
2013-10-07 11:36:39 +04:00
|
|
|
pci_irq_deassert(&s->dev);
|
2008-01-14 07:27:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
static void voice_set_active(AC97LinkState *s, int bm_index, int on)
|
2008-01-14 07:27:55 +03:00
|
|
|
{
|
|
|
|
switch (bm_index) {
|
|
|
|
case PI_INDEX:
|
2022-04-23 12:36:57 +03:00
|
|
|
AUD_set_active_in(s->voice_pi, on);
|
2008-01-14 07:27:55 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PO_INDEX:
|
2022-04-23 12:36:57 +03:00
|
|
|
AUD_set_active_out(s->voice_po, on);
|
2008-01-14 07:27:55 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MC_INDEX:
|
2022-04-23 12:36:57 +03:00
|
|
|
AUD_set_active_in(s->voice_mc, on);
|
2008-01-14 07:27:55 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2022-04-23 12:36:57 +03:00
|
|
|
AUD_log("ac97", "invalid bm_index(%d) in voice_set_active", bm_index);
|
2008-01-14 07:27:55 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
static void reset_bm_regs(AC97LinkState *s, AC97BusMasterRegs *r)
|
2008-01-14 07:27:55 +03:00
|
|
|
{
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("reset_bm_regs\n");
|
2008-01-14 07:27:55 +03:00
|
|
|
r->bdbar = 0;
|
|
|
|
r->civ = 0;
|
|
|
|
r->lvi = 0;
|
|
|
|
/** todo do we need to do that? */
|
2022-04-23 12:36:57 +03:00
|
|
|
update_sr(s, r, SR_DCH);
|
2008-01-14 07:27:55 +03:00
|
|
|
r->picb = 0;
|
|
|
|
r->piv = 0;
|
|
|
|
r->cr = r->cr & CR_DONT_CLEAR_MASK;
|
|
|
|
r->bd_valid = 0;
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
voice_set_active(s, r - s->bm_regs, 0);
|
|
|
|
memset(s->silence, 0, sizeof(s->silence));
|
2008-01-14 07:27:55 +03:00
|
|
|
}
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
static void mixer_store(AC97LinkState *s, uint32_t i, uint16_t v)
|
2008-01-14 07:27:55 +03:00
|
|
|
{
|
2022-04-23 12:36:57 +03:00
|
|
|
if (i + 2 > sizeof(s->mixer_data)) {
|
|
|
|
dolog("mixer_store: index %d out of bounds %zd\n",
|
|
|
|
i, sizeof(s->mixer_data));
|
2008-01-14 07:27:55 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
s->mixer_data[i + 0] = v & 0xff;
|
|
|
|
s->mixer_data[i + 1] = v >> 8;
|
|
|
|
}
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
static uint16_t mixer_load(AC97LinkState *s, uint32_t i)
|
2008-01-14 07:27:55 +03:00
|
|
|
{
|
|
|
|
uint16_t val = 0xffff;
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
if (i + 2 > sizeof(s->mixer_data)) {
|
|
|
|
dolog("mixer_load: index %d out of bounds %zd\n",
|
|
|
|
i, sizeof(s->mixer_data));
|
|
|
|
} else {
|
2008-01-14 07:27:55 +03:00
|
|
|
val = s->mixer_data[i + 0] | (s->mixer_data[i + 1] << 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
static void open_voice(AC97LinkState *s, int index, int freq)
|
2008-01-14 07:27:55 +03:00
|
|
|
{
|
2008-12-04 01:48:44 +03:00
|
|
|
struct audsettings as;
|
2008-01-14 07:27:55 +03:00
|
|
|
|
|
|
|
as.freq = freq;
|
|
|
|
as.nchannels = 2;
|
2019-03-09 01:34:13 +03:00
|
|
|
as.fmt = AUDIO_FORMAT_S16;
|
2008-01-14 07:27:55 +03:00
|
|
|
as.endianness = 0;
|
|
|
|
|
2008-06-08 05:07:48 +04:00
|
|
|
if (freq > 0) {
|
|
|
|
s->invalid_freq[index] = 0;
|
|
|
|
switch (index) {
|
|
|
|
case PI_INDEX:
|
2022-04-23 12:36:57 +03:00
|
|
|
s->voice_pi = AUD_open_in(
|
2008-06-08 05:07:48 +04:00
|
|
|
&s->card,
|
|
|
|
s->voice_pi,
|
|
|
|
"ac97.pi",
|
|
|
|
s,
|
|
|
|
pi_callback,
|
|
|
|
&as
|
|
|
|
);
|
|
|
|
break;
|
2008-01-14 07:27:55 +03:00
|
|
|
|
2008-06-08 05:07:48 +04:00
|
|
|
case PO_INDEX:
|
2022-04-23 12:36:57 +03:00
|
|
|
s->voice_po = AUD_open_out(
|
2008-06-08 05:07:48 +04:00
|
|
|
&s->card,
|
|
|
|
s->voice_po,
|
|
|
|
"ac97.po",
|
|
|
|
s,
|
|
|
|
po_callback,
|
|
|
|
&as
|
|
|
|
);
|
|
|
|
break;
|
2008-01-14 07:27:55 +03:00
|
|
|
|
2008-06-08 05:07:48 +04:00
|
|
|
case MC_INDEX:
|
2022-04-23 12:36:57 +03:00
|
|
|
s->voice_mc = AUD_open_in(
|
2008-06-08 05:07:48 +04:00
|
|
|
&s->card,
|
|
|
|
s->voice_mc,
|
|
|
|
"ac97.mc",
|
|
|
|
s,
|
|
|
|
mc_callback,
|
|
|
|
&as
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
2022-04-23 12:36:57 +03:00
|
|
|
} else {
|
2008-06-08 05:07:48 +04:00
|
|
|
s->invalid_freq[index] = freq;
|
|
|
|
switch (index) {
|
|
|
|
case PI_INDEX:
|
2022-04-23 12:36:57 +03:00
|
|
|
AUD_close_in(&s->card, s->voice_pi);
|
2008-06-08 05:07:48 +04:00
|
|
|
s->voice_pi = NULL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PO_INDEX:
|
2022-04-23 12:36:57 +03:00
|
|
|
AUD_close_out(&s->card, s->voice_po);
|
2008-06-08 05:07:48 +04:00
|
|
|
s->voice_po = NULL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MC_INDEX:
|
2022-04-23 12:36:57 +03:00
|
|
|
AUD_close_in(&s->card, s->voice_mc);
|
2008-06-08 05:07:48 +04:00
|
|
|
s->voice_mc = NULL;
|
|
|
|
break;
|
|
|
|
}
|
2008-01-14 07:27:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
static void reset_voices(AC97LinkState *s, uint8_t active[LAST_INDEX])
|
2008-01-14 07:27:55 +03:00
|
|
|
{
|
|
|
|
uint16_t freq;
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
freq = mixer_load(s, AC97_PCM_LR_ADC_Rate);
|
|
|
|
open_voice(s, PI_INDEX, freq);
|
|
|
|
AUD_set_active_in(s->voice_pi, active[PI_INDEX]);
|
2008-01-14 07:27:55 +03:00
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
freq = mixer_load(s, AC97_PCM_Front_DAC_Rate);
|
|
|
|
open_voice(s, PO_INDEX, freq);
|
|
|
|
AUD_set_active_out(s->voice_po, active[PO_INDEX]);
|
2008-01-14 07:27:55 +03:00
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
freq = mixer_load(s, AC97_MIC_ADC_Rate);
|
|
|
|
open_voice(s, MC_INDEX, freq);
|
|
|
|
AUD_set_active_in(s->voice_mc, active[MC_INDEX]);
|
2008-01-14 07:27:55 +03:00
|
|
|
}
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
static void get_volume(uint16_t vol, uint16_t mask, int inverse,
|
|
|
|
int *mute, uint8_t *lvol, uint8_t *rvol)
|
2012-04-17 16:32:39 +04:00
|
|
|
{
|
|
|
|
*mute = (vol >> MUTE_SHIFT) & 1;
|
|
|
|
*rvol = (255 * (vol & mask)) / mask;
|
|
|
|
*lvol = (255 * ((vol >> 8) & mask)) / mask;
|
|
|
|
|
|
|
|
if (inverse) {
|
|
|
|
*rvol = 255 - *rvol;
|
|
|
|
*lvol = 255 - *lvol;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
static void update_combined_volume_out(AC97LinkState *s)
|
2012-04-17 16:32:39 +04:00
|
|
|
{
|
|
|
|
uint8_t lvol, rvol, plvol, prvol;
|
|
|
|
int mute, pmute;
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
get_volume(mixer_load(s, AC97_Master_Volume_Mute), 0x3f, 1,
|
|
|
|
&mute, &lvol, &rvol);
|
|
|
|
get_volume(mixer_load(s, AC97_PCM_Out_Volume_Mute), 0x1f, 1,
|
|
|
|
&pmute, &plvol, &prvol);
|
2012-04-17 16:32:39 +04:00
|
|
|
|
|
|
|
mute = mute | pmute;
|
|
|
|
lvol = (lvol * plvol) / 255;
|
|
|
|
rvol = (rvol * prvol) / 255;
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
AUD_set_volume_out(s->voice_po, mute, lvol, rvol);
|
2012-04-17 16:32:39 +04:00
|
|
|
}
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
static void update_volume_in(AC97LinkState *s)
|
2012-04-17 16:32:39 +04:00
|
|
|
{
|
|
|
|
uint8_t lvol, rvol;
|
|
|
|
int mute;
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
get_volume(mixer_load(s, AC97_Record_Gain_Mute), 0x0f, 0,
|
|
|
|
&mute, &lvol, &rvol);
|
2012-04-17 16:32:39 +04:00
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
AUD_set_volume_in(s->voice_pi, mute, lvol, rvol);
|
2012-04-17 16:32:39 +04:00
|
|
|
}
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
static void set_volume(AC97LinkState *s, int index, uint32_t val)
|
2012-04-17 16:32:39 +04:00
|
|
|
{
|
2012-05-07 11:24:37 +04:00
|
|
|
switch (index) {
|
|
|
|
case AC97_Master_Volume_Mute:
|
|
|
|
val &= 0xbf3f;
|
2022-04-23 12:36:57 +03:00
|
|
|
mixer_store(s, index, val);
|
|
|
|
update_combined_volume_out(s);
|
2012-05-07 11:24:37 +04:00
|
|
|
break;
|
|
|
|
case AC97_PCM_Out_Volume_Mute:
|
|
|
|
val &= 0x9f1f;
|
2022-04-23 12:36:57 +03:00
|
|
|
mixer_store(s, index, val);
|
|
|
|
update_combined_volume_out(s);
|
2012-05-07 11:24:37 +04:00
|
|
|
break;
|
|
|
|
case AC97_Record_Gain_Mute:
|
|
|
|
val &= 0x8f0f;
|
2022-04-23 12:36:57 +03:00
|
|
|
mixer_store(s, index, val);
|
|
|
|
update_volume_in(s);
|
2012-05-07 11:24:37 +04:00
|
|
|
break;
|
2012-04-17 16:32:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
static void record_select(AC97LinkState *s, uint32_t val)
|
2012-04-17 16:32:39 +04:00
|
|
|
{
|
|
|
|
uint8_t rs = val & REC_MASK;
|
|
|
|
uint8_t ls = (val >> 8) & REC_MASK;
|
2022-04-23 12:36:57 +03:00
|
|
|
mixer_store(s, AC97_Record_Select, rs | (ls << 8));
|
2012-04-17 16:32:39 +04:00
|
|
|
}
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
static void mixer_reset(AC97LinkState *s)
|
2008-01-14 07:27:55 +03:00
|
|
|
{
|
|
|
|
uint8_t active[LAST_INDEX];
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("mixer_reset\n");
|
|
|
|
memset(s->mixer_data, 0, sizeof(s->mixer_data));
|
|
|
|
memset(active, 0, sizeof(active));
|
|
|
|
mixer_store(s, AC97_Reset, 0x0000); /* 6940 */
|
|
|
|
mixer_store(s, AC97_Headphone_Volume_Mute, 0x0000);
|
|
|
|
mixer_store(s, AC97_Master_Volume_Mono_Mute, 0x0000);
|
|
|
|
mixer_store(s, AC97_Master_Tone_RL, 0x0000);
|
|
|
|
mixer_store(s, AC97_PC_BEEP_Volume_Mute, 0x0000);
|
|
|
|
mixer_store(s, AC97_Phone_Volume_Mute, 0x0000);
|
|
|
|
mixer_store(s, AC97_Mic_Volume_Mute, 0x0000);
|
|
|
|
mixer_store(s, AC97_Line_In_Volume_Mute, 0x0000);
|
|
|
|
mixer_store(s, AC97_CD_Volume_Mute, 0x0000);
|
|
|
|
mixer_store(s, AC97_Video_Volume_Mute, 0x0000);
|
|
|
|
mixer_store(s, AC97_Aux_Volume_Mute, 0x0000);
|
|
|
|
mixer_store(s, AC97_Record_Gain_Mic_Mute, 0x0000);
|
|
|
|
mixer_store(s, AC97_General_Purpose, 0x0000);
|
|
|
|
mixer_store(s, AC97_3D_Control, 0x0000);
|
|
|
|
mixer_store(s, AC97_Powerdown_Ctrl_Stat, 0x000f);
|
2008-01-14 07:27:55 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Sigmatel 9700 (STAC9700)
|
|
|
|
*/
|
2022-04-23 12:36:57 +03:00
|
|
|
mixer_store(s, AC97_Vendor_ID1, 0x8384);
|
|
|
|
mixer_store(s, AC97_Vendor_ID2, 0x7600); /* 7608 */
|
|
|
|
|
|
|
|
mixer_store(s, AC97_Extended_Audio_ID, 0x0809);
|
|
|
|
mixer_store(s, AC97_Extended_Audio_Ctrl_Stat, 0x0009);
|
|
|
|
mixer_store(s, AC97_PCM_Front_DAC_Rate, 0xbb80);
|
|
|
|
mixer_store(s, AC97_PCM_Surround_DAC_Rate, 0xbb80);
|
|
|
|
mixer_store(s, AC97_PCM_LFE_DAC_Rate, 0xbb80);
|
|
|
|
mixer_store(s, AC97_PCM_LR_ADC_Rate, 0xbb80);
|
|
|
|
mixer_store(s, AC97_MIC_ADC_Rate, 0xbb80);
|
|
|
|
|
|
|
|
record_select(s, 0);
|
|
|
|
set_volume(s, AC97_Master_Volume_Mute, 0x8000);
|
|
|
|
set_volume(s, AC97_PCM_Out_Volume_Mute, 0x8808);
|
|
|
|
set_volume(s, AC97_Record_Gain_Mute, 0x8808);
|
|
|
|
|
|
|
|
reset_voices(s, active);
|
2008-01-14 07:27:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Native audio mixer
|
|
|
|
* I/O Reads
|
|
|
|
*/
|
2022-04-23 12:36:57 +03:00
|
|
|
static uint32_t nam_readb(void *opaque, uint32_t addr)
|
2008-01-14 07:27:55 +03:00
|
|
|
{
|
2009-08-21 15:56:09 +04:00
|
|
|
AC97LinkState *s = opaque;
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("U nam readb 0x%x\n", addr);
|
2008-01-14 07:27:55 +03:00
|
|
|
s->cas = 0;
|
|
|
|
return ~0U;
|
|
|
|
}
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
static uint32_t nam_readw(void *opaque, uint32_t addr)
|
2008-01-14 07:27:55 +03:00
|
|
|
{
|
2009-08-21 15:56:09 +04:00
|
|
|
AC97LinkState *s = opaque;
|
2008-01-14 07:27:55 +03:00
|
|
|
s->cas = 0;
|
2022-04-23 12:36:57 +03:00
|
|
|
return mixer_load(s, addr);
|
2008-01-14 07:27:55 +03:00
|
|
|
}
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
static uint32_t nam_readl(void *opaque, uint32_t addr)
|
2008-01-14 07:27:55 +03:00
|
|
|
{
|
2009-08-21 15:56:09 +04:00
|
|
|
AC97LinkState *s = opaque;
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("U nam readl 0x%x\n", addr);
|
2008-01-14 07:27:55 +03:00
|
|
|
s->cas = 0;
|
|
|
|
return ~0U;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Native audio mixer
|
|
|
|
* I/O Writes
|
|
|
|
*/
|
2022-04-23 12:36:57 +03:00
|
|
|
static void nam_writeb(void *opaque, uint32_t addr, uint32_t val)
|
2008-01-14 07:27:55 +03:00
|
|
|
{
|
2009-08-21 15:56:09 +04:00
|
|
|
AC97LinkState *s = opaque;
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("U nam writeb 0x%x <- 0x%x\n", addr, val);
|
2008-01-14 07:27:55 +03:00
|
|
|
s->cas = 0;
|
|
|
|
}
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
static void nam_writew(void *opaque, uint32_t addr, uint32_t val)
|
2008-01-14 07:27:55 +03:00
|
|
|
{
|
2009-08-21 15:56:09 +04:00
|
|
|
AC97LinkState *s = opaque;
|
2022-04-23 12:36:57 +03:00
|
|
|
|
2008-01-14 07:27:55 +03:00
|
|
|
s->cas = 0;
|
2022-04-23 12:36:57 +03:00
|
|
|
switch (addr) {
|
2008-01-14 07:27:55 +03:00
|
|
|
case AC97_Reset:
|
2022-04-23 12:36:57 +03:00
|
|
|
mixer_reset(s);
|
2008-01-14 07:27:55 +03:00
|
|
|
break;
|
|
|
|
case AC97_Powerdown_Ctrl_Stat:
|
2012-05-07 11:24:38 +04:00
|
|
|
val &= ~0x800f;
|
2022-04-23 12:36:57 +03:00
|
|
|
val |= mixer_load(s, addr) & 0xf;
|
|
|
|
mixer_store(s, addr, val);
|
2008-01-14 07:27:55 +03:00
|
|
|
break;
|
2012-04-17 16:32:39 +04:00
|
|
|
case AC97_PCM_Out_Volume_Mute:
|
|
|
|
case AC97_Master_Volume_Mute:
|
|
|
|
case AC97_Record_Gain_Mute:
|
2022-04-23 12:36:57 +03:00
|
|
|
set_volume(s, addr, val);
|
2012-04-17 16:32:39 +04:00
|
|
|
break;
|
|
|
|
case AC97_Record_Select:
|
2022-04-23 12:36:57 +03:00
|
|
|
record_select(s, val);
|
2012-04-17 16:32:39 +04:00
|
|
|
break;
|
2008-01-14 07:27:55 +03:00
|
|
|
case AC97_Vendor_ID1:
|
|
|
|
case AC97_Vendor_ID2:
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("Attempt to write vendor ID to 0x%x\n", val);
|
2008-01-14 07:27:55 +03:00
|
|
|
break;
|
|
|
|
case AC97_Extended_Audio_ID:
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("Attempt to write extended audio ID to 0x%x\n", val);
|
2008-01-14 07:27:55 +03:00
|
|
|
break;
|
|
|
|
case AC97_Extended_Audio_Ctrl_Stat:
|
|
|
|
if (!(val & EACS_VRA)) {
|
2022-04-23 12:36:57 +03:00
|
|
|
mixer_store(s, AC97_PCM_Front_DAC_Rate, 0xbb80);
|
|
|
|
mixer_store(s, AC97_PCM_LR_ADC_Rate, 0xbb80);
|
|
|
|
open_voice(s, PI_INDEX, 48000);
|
|
|
|
open_voice(s, PO_INDEX, 48000);
|
2008-01-14 07:27:55 +03:00
|
|
|
}
|
|
|
|
if (!(val & EACS_VRM)) {
|
2022-04-23 12:36:57 +03:00
|
|
|
mixer_store(s, AC97_MIC_ADC_Rate, 0xbb80);
|
|
|
|
open_voice(s, MC_INDEX, 48000);
|
2008-01-14 07:27:55 +03:00
|
|
|
}
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("Setting extended audio control to 0x%x\n", val);
|
|
|
|
mixer_store(s, AC97_Extended_Audio_Ctrl_Stat, val);
|
2008-01-14 07:27:55 +03:00
|
|
|
break;
|
|
|
|
case AC97_PCM_Front_DAC_Rate:
|
2022-04-23 12:36:57 +03:00
|
|
|
if (mixer_load(s, AC97_Extended_Audio_Ctrl_Stat) & EACS_VRA) {
|
2022-04-23 12:36:57 +03:00
|
|
|
mixer_store(s, addr, val);
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("Set front DAC rate to %d\n", val);
|
|
|
|
open_voice(s, PO_INDEX, val);
|
|
|
|
} else {
|
|
|
|
dolog("Attempt to set front DAC rate to %d, but VRA is not set\n",
|
|
|
|
val);
|
2008-01-14 07:27:55 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case AC97_MIC_ADC_Rate:
|
2022-04-23 12:36:57 +03:00
|
|
|
if (mixer_load(s, AC97_Extended_Audio_Ctrl_Stat) & EACS_VRM) {
|
2022-04-23 12:36:57 +03:00
|
|
|
mixer_store(s, addr, val);
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("Set MIC ADC rate to %d\n", val);
|
|
|
|
open_voice(s, MC_INDEX, val);
|
|
|
|
} else {
|
|
|
|
dolog("Attempt to set MIC ADC rate to %d, but VRM is not set\n",
|
|
|
|
val);
|
2008-01-14 07:27:55 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case AC97_PCM_LR_ADC_Rate:
|
2022-04-23 12:36:57 +03:00
|
|
|
if (mixer_load(s, AC97_Extended_Audio_Ctrl_Stat) & EACS_VRA) {
|
2022-04-23 12:36:57 +03:00
|
|
|
mixer_store(s, addr, val);
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("Set front LR ADC rate to %d\n", val);
|
|
|
|
open_voice(s, PI_INDEX, val);
|
|
|
|
} else {
|
|
|
|
dolog("Attempt to set LR ADC rate to %d, but VRA is not set\n",
|
|
|
|
val);
|
2008-01-14 07:27:55 +03:00
|
|
|
}
|
|
|
|
break;
|
2012-05-07 11:24:35 +04:00
|
|
|
case AC97_Headphone_Volume_Mute:
|
|
|
|
case AC97_Master_Volume_Mono_Mute:
|
|
|
|
case AC97_Master_Tone_RL:
|
|
|
|
case AC97_PC_BEEP_Volume_Mute:
|
|
|
|
case AC97_Phone_Volume_Mute:
|
|
|
|
case AC97_Mic_Volume_Mute:
|
2012-05-07 11:24:36 +04:00
|
|
|
case AC97_Line_In_Volume_Mute:
|
2012-05-07 11:24:35 +04:00
|
|
|
case AC97_CD_Volume_Mute:
|
|
|
|
case AC97_Video_Volume_Mute:
|
|
|
|
case AC97_Aux_Volume_Mute:
|
|
|
|
case AC97_Record_Gain_Mic_Mute:
|
|
|
|
case AC97_General_Purpose:
|
|
|
|
case AC97_3D_Control:
|
|
|
|
case AC97_Sigmatel_Analog:
|
|
|
|
case AC97_Sigmatel_Dac2Invert:
|
|
|
|
/* None of the features in these regs are emulated, so they are RO */
|
|
|
|
break;
|
2008-01-14 07:27:55 +03:00
|
|
|
default:
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("U nam writew 0x%x <- 0x%x\n", addr, val);
|
2022-04-23 12:36:57 +03:00
|
|
|
mixer_store(s, addr, val);
|
2008-01-14 07:27:55 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
static void nam_writel(void *opaque, uint32_t addr, uint32_t val)
|
2008-01-14 07:27:55 +03:00
|
|
|
{
|
2009-08-21 15:56:09 +04:00
|
|
|
AC97LinkState *s = opaque;
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("U nam writel 0x%x <- 0x%x\n", addr, val);
|
2008-01-14 07:27:55 +03:00
|
|
|
s->cas = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Native audio bus master
|
|
|
|
* I/O Reads
|
|
|
|
*/
|
2022-04-23 12:36:57 +03:00
|
|
|
static uint32_t nabm_readb(void *opaque, uint32_t addr)
|
2008-01-14 07:27:55 +03:00
|
|
|
{
|
2009-08-21 15:56:09 +04:00
|
|
|
AC97LinkState *s = opaque;
|
2008-01-14 07:27:55 +03:00
|
|
|
AC97BusMasterRegs *r = NULL;
|
|
|
|
uint32_t val = ~0U;
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
switch (addr) {
|
2008-01-14 07:27:55 +03:00
|
|
|
case CAS:
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("CAS %d\n", s->cas);
|
2008-01-14 07:27:55 +03:00
|
|
|
val = s->cas;
|
|
|
|
s->cas = 1;
|
|
|
|
break;
|
|
|
|
case PI_CIV:
|
|
|
|
case PO_CIV:
|
|
|
|
case MC_CIV:
|
2022-04-23 12:36:57 +03:00
|
|
|
r = &s->bm_regs[GET_BM(addr)];
|
2008-01-14 07:27:55 +03:00
|
|
|
val = r->civ;
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("CIV[%d] -> 0x%x\n", GET_BM(addr), val);
|
2008-01-14 07:27:55 +03:00
|
|
|
break;
|
|
|
|
case PI_LVI:
|
|
|
|
case PO_LVI:
|
|
|
|
case MC_LVI:
|
2022-04-23 12:36:57 +03:00
|
|
|
r = &s->bm_regs[GET_BM(addr)];
|
2008-01-14 07:27:55 +03:00
|
|
|
val = r->lvi;
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("LVI[%d] -> 0x%x\n", GET_BM(addr), val);
|
2008-01-14 07:27:55 +03:00
|
|
|
break;
|
|
|
|
case PI_PIV:
|
|
|
|
case PO_PIV:
|
|
|
|
case MC_PIV:
|
2022-04-23 12:36:57 +03:00
|
|
|
r = &s->bm_regs[GET_BM(addr)];
|
2008-01-14 07:27:55 +03:00
|
|
|
val = r->piv;
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("PIV[%d] -> 0x%x\n", GET_BM(addr), val);
|
2008-01-14 07:27:55 +03:00
|
|
|
break;
|
|
|
|
case PI_CR:
|
|
|
|
case PO_CR:
|
|
|
|
case MC_CR:
|
2022-04-23 12:36:57 +03:00
|
|
|
r = &s->bm_regs[GET_BM(addr)];
|
2008-01-14 07:27:55 +03:00
|
|
|
val = r->cr;
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("CR[%d] -> 0x%x\n", GET_BM(addr), val);
|
2008-01-14 07:27:55 +03:00
|
|
|
break;
|
|
|
|
case PI_SR:
|
|
|
|
case PO_SR:
|
|
|
|
case MC_SR:
|
2022-04-23 12:36:57 +03:00
|
|
|
r = &s->bm_regs[GET_BM(addr)];
|
2008-01-14 07:27:55 +03:00
|
|
|
val = r->sr & 0xff;
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("SRb[%d] -> 0x%x\n", GET_BM(addr), val);
|
2008-01-14 07:27:55 +03:00
|
|
|
break;
|
|
|
|
default:
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("U nabm readb 0x%x -> 0x%x\n", addr, val);
|
2008-01-14 07:27:55 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
static uint32_t nabm_readw(void *opaque, uint32_t addr)
|
2008-01-14 07:27:55 +03:00
|
|
|
{
|
2009-08-21 15:56:09 +04:00
|
|
|
AC97LinkState *s = opaque;
|
2008-01-14 07:27:55 +03:00
|
|
|
AC97BusMasterRegs *r = NULL;
|
|
|
|
uint32_t val = ~0U;
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
switch (addr) {
|
2008-01-14 07:27:55 +03:00
|
|
|
case PI_SR:
|
|
|
|
case PO_SR:
|
|
|
|
case MC_SR:
|
2022-04-23 12:36:57 +03:00
|
|
|
r = &s->bm_regs[GET_BM(addr)];
|
2008-01-14 07:27:55 +03:00
|
|
|
val = r->sr;
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("SR[%d] -> 0x%x\n", GET_BM(addr), val);
|
2008-01-14 07:27:55 +03:00
|
|
|
break;
|
|
|
|
case PI_PICB:
|
|
|
|
case PO_PICB:
|
|
|
|
case MC_PICB:
|
2022-04-23 12:36:57 +03:00
|
|
|
r = &s->bm_regs[GET_BM(addr)];
|
2008-01-14 07:27:55 +03:00
|
|
|
val = r->picb;
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("PICB[%d] -> 0x%x\n", GET_BM(addr), val);
|
2008-01-14 07:27:55 +03:00
|
|
|
break;
|
|
|
|
default:
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("U nabm readw 0x%x -> 0x%x\n", addr, val);
|
2008-01-14 07:27:55 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
static uint32_t nabm_readl(void *opaque, uint32_t addr)
|
2008-01-14 07:27:55 +03:00
|
|
|
{
|
2009-08-21 15:56:09 +04:00
|
|
|
AC97LinkState *s = opaque;
|
2008-01-14 07:27:55 +03:00
|
|
|
AC97BusMasterRegs *r = NULL;
|
|
|
|
uint32_t val = ~0U;
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
switch (addr) {
|
2008-01-14 07:27:55 +03:00
|
|
|
case PI_BDBAR:
|
|
|
|
case PO_BDBAR:
|
|
|
|
case MC_BDBAR:
|
2022-04-23 12:36:57 +03:00
|
|
|
r = &s->bm_regs[GET_BM(addr)];
|
2008-01-14 07:27:55 +03:00
|
|
|
val = r->bdbar;
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("BMADDR[%d] -> 0x%x\n", GET_BM(addr), val);
|
2008-01-14 07:27:55 +03:00
|
|
|
break;
|
|
|
|
case PI_CIV:
|
|
|
|
case PO_CIV:
|
|
|
|
case MC_CIV:
|
2022-04-23 12:36:57 +03:00
|
|
|
r = &s->bm_regs[GET_BM(addr)];
|
2008-01-14 07:27:55 +03:00
|
|
|
val = r->civ | (r->lvi << 8) | (r->sr << 16);
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("CIV LVI SR[%d] -> 0x%x, 0x%x, 0x%x\n", GET_BM(addr),
|
2008-01-14 07:27:55 +03:00
|
|
|
r->civ, r->lvi, r->sr);
|
|
|
|
break;
|
|
|
|
case PI_PICB:
|
|
|
|
case PO_PICB:
|
|
|
|
case MC_PICB:
|
2022-04-23 12:36:57 +03:00
|
|
|
r = &s->bm_regs[GET_BM(addr)];
|
2008-01-14 07:27:55 +03:00
|
|
|
val = r->picb | (r->piv << 16) | (r->cr << 24);
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("PICB PIV CR[%d] -> 0x%x 0x%x 0x%x 0x%x\n", GET_BM(addr),
|
2008-01-14 07:27:55 +03:00
|
|
|
val, r->picb, r->piv, r->cr);
|
|
|
|
break;
|
|
|
|
case GLOB_CNT:
|
|
|
|
val = s->glob_cnt;
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("glob_cnt -> 0x%x\n", val);
|
2008-01-14 07:27:55 +03:00
|
|
|
break;
|
|
|
|
case GLOB_STA:
|
|
|
|
val = s->glob_sta | GS_S0CR;
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("glob_sta -> 0x%x\n", val);
|
2008-01-14 07:27:55 +03:00
|
|
|
break;
|
|
|
|
default:
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("U nabm readl 0x%x -> 0x%x\n", addr, val);
|
2008-01-14 07:27:55 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Native audio bus master
|
|
|
|
* I/O Writes
|
|
|
|
*/
|
2022-04-23 12:36:57 +03:00
|
|
|
static void nabm_writeb(void *opaque, uint32_t addr, uint32_t val)
|
2008-01-14 07:27:55 +03:00
|
|
|
{
|
2009-08-21 15:56:09 +04:00
|
|
|
AC97LinkState *s = opaque;
|
2008-01-14 07:27:55 +03:00
|
|
|
AC97BusMasterRegs *r = NULL;
|
2022-04-23 12:36:57 +03:00
|
|
|
|
|
|
|
switch (addr) {
|
2008-01-14 07:27:55 +03:00
|
|
|
case PI_LVI:
|
|
|
|
case PO_LVI:
|
|
|
|
case MC_LVI:
|
2022-04-23 12:36:57 +03:00
|
|
|
r = &s->bm_regs[GET_BM(addr)];
|
2008-01-14 07:27:55 +03:00
|
|
|
if ((r->cr & CR_RPBM) && (r->sr & SR_DCH)) {
|
|
|
|
r->sr &= ~(SR_DCH | SR_CELV);
|
|
|
|
r->civ = r->piv;
|
|
|
|
r->piv = (r->piv + 1) % 32;
|
2022-04-23 12:36:57 +03:00
|
|
|
fetch_bd(s, r);
|
2008-01-14 07:27:55 +03:00
|
|
|
}
|
|
|
|
r->lvi = val % 32;
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("LVI[%d] <- 0x%x\n", GET_BM(addr), val);
|
2008-01-14 07:27:55 +03:00
|
|
|
break;
|
|
|
|
case PI_CR:
|
|
|
|
case PO_CR:
|
|
|
|
case MC_CR:
|
2022-04-23 12:36:57 +03:00
|
|
|
r = &s->bm_regs[GET_BM(addr)];
|
2008-01-14 07:27:55 +03:00
|
|
|
if (val & CR_RR) {
|
2022-04-23 12:36:57 +03:00
|
|
|
reset_bm_regs(s, r);
|
|
|
|
} else {
|
2008-01-14 07:27:55 +03:00
|
|
|
r->cr = val & CR_VALID_MASK;
|
|
|
|
if (!(r->cr & CR_RPBM)) {
|
2022-04-23 12:36:57 +03:00
|
|
|
voice_set_active(s, r - s->bm_regs, 0);
|
2008-01-14 07:27:55 +03:00
|
|
|
r->sr |= SR_DCH;
|
2022-04-23 12:36:57 +03:00
|
|
|
} else {
|
2008-01-14 07:27:55 +03:00
|
|
|
r->civ = r->piv;
|
|
|
|
r->piv = (r->piv + 1) % 32;
|
2022-04-23 12:36:57 +03:00
|
|
|
fetch_bd(s, r);
|
2008-01-14 07:27:55 +03:00
|
|
|
r->sr &= ~SR_DCH;
|
2022-04-23 12:36:57 +03:00
|
|
|
voice_set_active(s, r - s->bm_regs, 1);
|
2008-01-14 07:27:55 +03:00
|
|
|
}
|
|
|
|
}
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("CR[%d] <- 0x%x (cr 0x%x)\n", GET_BM(addr), val, r->cr);
|
2008-01-14 07:27:55 +03:00
|
|
|
break;
|
|
|
|
case PI_SR:
|
|
|
|
case PO_SR:
|
|
|
|
case MC_SR:
|
2022-04-23 12:36:57 +03:00
|
|
|
r = &s->bm_regs[GET_BM(addr)];
|
2008-01-14 07:27:55 +03:00
|
|
|
r->sr |= val & ~(SR_RO_MASK | SR_WCLEAR_MASK);
|
2022-04-23 12:36:57 +03:00
|
|
|
update_sr(s, r, r->sr & ~(val & SR_WCLEAR_MASK));
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("SR[%d] <- 0x%x (sr 0x%x)\n", GET_BM(addr), val, r->sr);
|
2008-01-14 07:27:55 +03:00
|
|
|
break;
|
|
|
|
default:
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("U nabm writeb 0x%x <- 0x%x\n", addr, val);
|
2008-01-14 07:27:55 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
static void nabm_writew(void *opaque, uint32_t addr, uint32_t val)
|
2008-01-14 07:27:55 +03:00
|
|
|
{
|
2009-08-21 15:56:09 +04:00
|
|
|
AC97LinkState *s = opaque;
|
2008-01-14 07:27:55 +03:00
|
|
|
AC97BusMasterRegs *r = NULL;
|
2022-04-23 12:36:57 +03:00
|
|
|
|
|
|
|
switch (addr) {
|
2008-01-14 07:27:55 +03:00
|
|
|
case PI_SR:
|
|
|
|
case PO_SR:
|
|
|
|
case MC_SR:
|
2022-04-23 12:36:57 +03:00
|
|
|
r = &s->bm_regs[GET_BM(addr)];
|
2008-01-14 07:27:55 +03:00
|
|
|
r->sr |= val & ~(SR_RO_MASK | SR_WCLEAR_MASK);
|
2022-04-23 12:36:57 +03:00
|
|
|
update_sr(s, r, r->sr & ~(val & SR_WCLEAR_MASK));
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("SR[%d] <- 0x%x (sr 0x%x)\n", GET_BM(addr), val, r->sr);
|
2008-01-14 07:27:55 +03:00
|
|
|
break;
|
|
|
|
default:
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("U nabm writew 0x%x <- 0x%x\n", addr, val);
|
2008-01-14 07:27:55 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
static void nabm_writel(void *opaque, uint32_t addr, uint32_t val)
|
2008-01-14 07:27:55 +03:00
|
|
|
{
|
2009-08-21 15:56:09 +04:00
|
|
|
AC97LinkState *s = opaque;
|
2008-01-14 07:27:55 +03:00
|
|
|
AC97BusMasterRegs *r = NULL;
|
2022-04-23 12:36:57 +03:00
|
|
|
|
|
|
|
switch (addr) {
|
2008-01-14 07:27:55 +03:00
|
|
|
case PI_BDBAR:
|
|
|
|
case PO_BDBAR:
|
|
|
|
case MC_BDBAR:
|
2022-04-23 12:36:57 +03:00
|
|
|
r = &s->bm_regs[GET_BM(addr)];
|
2008-01-14 07:27:55 +03:00
|
|
|
r->bdbar = val & ~3;
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("BDBAR[%d] <- 0x%x (bdbar 0x%x)\n", GET_BM(addr), val, r->bdbar);
|
2008-01-14 07:27:55 +03:00
|
|
|
break;
|
|
|
|
case GLOB_CNT:
|
2022-04-23 12:36:57 +03:00
|
|
|
/* TODO: Handle WR or CR being set (warm/cold reset requests) */
|
2022-04-23 12:36:57 +03:00
|
|
|
if (!(val & (GC_WR | GC_CR))) {
|
2008-01-14 07:27:55 +03:00
|
|
|
s->glob_cnt = val & GC_VALID_MASK;
|
2022-04-23 12:36:57 +03:00
|
|
|
}
|
|
|
|
dolog("glob_cnt <- 0x%x (glob_cnt 0x%x)\n", val, s->glob_cnt);
|
2008-01-14 07:27:55 +03:00
|
|
|
break;
|
|
|
|
case GLOB_STA:
|
|
|
|
s->glob_sta &= ~(val & GS_WCLEAR_MASK);
|
|
|
|
s->glob_sta |= (val & ~(GS_WCLEAR_MASK | GS_RO_MASK)) & GS_VALID_MASK;
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("glob_sta <- 0x%x (glob_sta 0x%x)\n", val, s->glob_sta);
|
2008-01-14 07:27:55 +03:00
|
|
|
break;
|
|
|
|
default:
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("U nabm writel 0x%x <- 0x%x\n", addr, val);
|
2008-01-14 07:27:55 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
static int write_audio(AC97LinkState *s, AC97BusMasterRegs *r,
|
|
|
|
int max, int *stop)
|
2008-01-14 07:27:55 +03:00
|
|
|
{
|
|
|
|
uint8_t tmpbuf[4096];
|
|
|
|
uint32_t addr = r->bd.addr;
|
|
|
|
uint32_t temp = r->picb << 1;
|
|
|
|
uint32_t written = 0;
|
|
|
|
int to_copy = 0;
|
2022-04-23 12:36:57 +03:00
|
|
|
temp = MIN(temp, max);
|
2008-01-14 07:27:55 +03:00
|
|
|
|
|
|
|
if (!temp) {
|
|
|
|
*stop = 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (temp) {
|
|
|
|
int copied;
|
2022-04-23 12:36:57 +03:00
|
|
|
to_copy = MIN(temp, sizeof(tmpbuf));
|
|
|
|
pci_dma_read(&s->dev, addr, tmpbuf, to_copy);
|
|
|
|
copied = AUD_write(s->voice_po, tmpbuf, to_copy);
|
|
|
|
dolog("write_audio max=%x to_copy=%x copied=%x\n",
|
|
|
|
max, to_copy, copied);
|
2008-01-14 07:27:55 +03:00
|
|
|
if (!copied) {
|
|
|
|
*stop = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
temp -= copied;
|
|
|
|
addr += copied;
|
|
|
|
written += copied;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!temp) {
|
|
|
|
if (to_copy < 4) {
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("whoops\n");
|
2008-01-14 07:27:55 +03:00
|
|
|
s->last_samp = 0;
|
2022-04-23 12:36:57 +03:00
|
|
|
} else {
|
|
|
|
s->last_samp = *(uint32_t *)&tmpbuf[to_copy - 4];
|
2008-01-14 07:27:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
r->bd.addr = addr;
|
|
|
|
return written;
|
|
|
|
}
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
static void write_bup(AC97LinkState *s, int elapsed)
|
2008-01-14 07:27:55 +03:00
|
|
|
{
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("write_bup\n");
|
2008-01-14 07:27:55 +03:00
|
|
|
if (!(s->bup_flag & BUP_SET)) {
|
|
|
|
if (s->bup_flag & BUP_LAST) {
|
|
|
|
int i;
|
|
|
|
uint8_t *p = s->silence;
|
2022-04-23 12:36:57 +03:00
|
|
|
for (i = 0; i < sizeof(s->silence) / 4; i++, p += 4) {
|
2008-01-14 07:27:55 +03:00
|
|
|
*(uint32_t *) p = s->last_samp;
|
|
|
|
}
|
2022-04-23 12:36:57 +03:00
|
|
|
} else {
|
|
|
|
memset(s->silence, 0, sizeof(s->silence));
|
2008-01-14 07:27:55 +03:00
|
|
|
}
|
|
|
|
s->bup_flag |= BUP_SET;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (elapsed) {
|
2022-04-23 12:36:57 +03:00
|
|
|
int temp = MIN(elapsed, sizeof(s->silence));
|
2008-01-14 07:27:55 +03:00
|
|
|
while (temp) {
|
2022-04-23 12:36:57 +03:00
|
|
|
int copied = AUD_write(s->voice_po, s->silence, temp);
|
|
|
|
if (!copied) {
|
2008-01-14 07:27:55 +03:00
|
|
|
return;
|
2022-04-23 12:36:57 +03:00
|
|
|
}
|
2008-01-14 07:27:55 +03:00
|
|
|
temp -= copied;
|
|
|
|
elapsed -= copied;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
static int read_audio(AC97LinkState *s, AC97BusMasterRegs *r,
|
|
|
|
int max, int *stop)
|
2008-01-14 07:27:55 +03:00
|
|
|
{
|
|
|
|
uint8_t tmpbuf[4096];
|
|
|
|
uint32_t addr = r->bd.addr;
|
|
|
|
uint32_t temp = r->picb << 1;
|
|
|
|
uint32_t nread = 0;
|
|
|
|
int to_copy = 0;
|
|
|
|
SWVoiceIn *voice = (r - s->bm_regs) == MC_INDEX ? s->voice_mc : s->voice_pi;
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
temp = MIN(temp, max);
|
2008-01-14 07:27:55 +03:00
|
|
|
|
|
|
|
if (!temp) {
|
|
|
|
*stop = 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (temp) {
|
|
|
|
int acquired;
|
2022-04-23 12:36:57 +03:00
|
|
|
to_copy = MIN(temp, sizeof(tmpbuf));
|
|
|
|
acquired = AUD_read(voice, tmpbuf, to_copy);
|
2008-01-14 07:27:55 +03:00
|
|
|
if (!acquired) {
|
|
|
|
*stop = 1;
|
|
|
|
break;
|
|
|
|
}
|
2022-04-23 12:36:57 +03:00
|
|
|
pci_dma_write(&s->dev, addr, tmpbuf, acquired);
|
2008-01-14 07:27:55 +03:00
|
|
|
temp -= acquired;
|
|
|
|
addr += acquired;
|
|
|
|
nread += acquired;
|
|
|
|
}
|
|
|
|
|
|
|
|
r->bd.addr = addr;
|
|
|
|
return nread;
|
|
|
|
}
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
static void transfer_audio(AC97LinkState *s, int index, int elapsed)
|
2008-01-14 07:27:55 +03:00
|
|
|
{
|
|
|
|
AC97BusMasterRegs *r = &s->bm_regs[index];
|
2011-05-08 10:58:11 +04:00
|
|
|
int stop = 0;
|
2008-01-14 07:27:55 +03:00
|
|
|
|
2008-06-08 05:07:48 +04:00
|
|
|
if (s->invalid_freq[index]) {
|
2022-04-23 12:36:57 +03:00
|
|
|
AUD_log("ac97", "attempt to use voice %d with invalid frequency %d\n",
|
|
|
|
index, s->invalid_freq[index]);
|
2008-06-08 05:07:48 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-01-14 07:27:55 +03:00
|
|
|
if (r->sr & SR_DCH) {
|
|
|
|
if (r->cr & CR_RPBM) {
|
|
|
|
switch (index) {
|
|
|
|
case PO_INDEX:
|
2022-04-23 12:36:57 +03:00
|
|
|
write_bup(s, elapsed);
|
2008-01-14 07:27:55 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while ((elapsed >> 1) && !stop) {
|
|
|
|
int temp;
|
|
|
|
|
|
|
|
if (!r->bd_valid) {
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("invalid bd\n");
|
|
|
|
fetch_bd(s, r);
|
2008-01-14 07:27:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!r->picb) {
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("fresh bd %d is empty 0x%x 0x%x\n",
|
|
|
|
r->civ, r->bd.addr, r->bd.ctl_len);
|
2008-01-14 07:27:55 +03:00
|
|
|
if (r->civ == r->lvi) {
|
|
|
|
r->sr |= SR_DCH; /* CELV? */
|
|
|
|
s->bup_flag = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
r->sr &= ~SR_CELV;
|
|
|
|
r->civ = r->piv;
|
|
|
|
r->piv = (r->piv + 1) % 32;
|
2022-04-23 12:36:57 +03:00
|
|
|
fetch_bd(s, r);
|
2008-01-14 07:27:55 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (index) {
|
|
|
|
case PO_INDEX:
|
2022-04-23 12:36:57 +03:00
|
|
|
temp = write_audio(s, r, elapsed, &stop);
|
2008-01-14 07:27:55 +03:00
|
|
|
elapsed -= temp;
|
|
|
|
r->picb -= (temp >> 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PI_INDEX:
|
|
|
|
case MC_INDEX:
|
2022-04-23 12:36:57 +03:00
|
|
|
temp = read_audio(s, r, elapsed, &stop);
|
2008-01-14 07:27:55 +03:00
|
|
|
elapsed -= temp;
|
|
|
|
r->picb -= (temp >> 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!r->picb) {
|
|
|
|
uint32_t new_sr = r->sr & ~SR_CELV;
|
|
|
|
|
|
|
|
if (r->bd.ctl_len & BD_IOC) {
|
|
|
|
new_sr |= SR_BCIS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r->civ == r->lvi) {
|
2022-04-23 12:36:57 +03:00
|
|
|
dolog("Underrun civ (%d) == lvi (%d)\n", r->civ, r->lvi);
|
2008-01-14 07:27:55 +03:00
|
|
|
|
|
|
|
new_sr |= SR_LVBCI | SR_DCH | SR_CELV;
|
|
|
|
stop = 1;
|
|
|
|
s->bup_flag = (r->bd.ctl_len & BD_BUP) ? BUP_LAST : 0;
|
2022-04-23 12:36:57 +03:00
|
|
|
} else {
|
2008-01-14 07:27:55 +03:00
|
|
|
r->civ = r->piv;
|
|
|
|
r->piv = (r->piv + 1) % 32;
|
2022-04-23 12:36:57 +03:00
|
|
|
fetch_bd(s, r);
|
2008-01-14 07:27:55 +03:00
|
|
|
}
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
update_sr(s, r, new_sr);
|
2008-01-14 07:27:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
static void pi_callback(void *opaque, int avail)
|
2008-01-14 07:27:55 +03:00
|
|
|
{
|
2022-04-23 12:36:57 +03:00
|
|
|
transfer_audio(opaque, PI_INDEX, avail);
|
2008-01-14 07:27:55 +03:00
|
|
|
}
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
static void mc_callback(void *opaque, int avail)
|
2008-01-14 07:27:55 +03:00
|
|
|
{
|
2022-04-23 12:36:57 +03:00
|
|
|
transfer_audio(opaque, MC_INDEX, avail);
|
2008-01-14 07:27:55 +03:00
|
|
|
}
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
static void po_callback(void *opaque, int free)
|
2008-01-14 07:27:55 +03:00
|
|
|
{
|
2022-04-23 12:36:57 +03:00
|
|
|
transfer_audio(opaque, PO_INDEX, free);
|
2008-01-14 07:27:55 +03:00
|
|
|
}
|
|
|
|
|
2009-12-02 13:49:42 +03:00
|
|
|
static const VMStateDescription vmstate_ac97_bm_regs = {
|
|
|
|
.name = "ac97_bm_regs",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
2014-04-16 17:32:32 +04:00
|
|
|
.fields = (VMStateField[]) {
|
2022-04-23 12:36:57 +03:00
|
|
|
VMSTATE_UINT32(bdbar, AC97BusMasterRegs),
|
|
|
|
VMSTATE_UINT8(civ, AC97BusMasterRegs),
|
|
|
|
VMSTATE_UINT8(lvi, AC97BusMasterRegs),
|
|
|
|
VMSTATE_UINT16(sr, AC97BusMasterRegs),
|
|
|
|
VMSTATE_UINT16(picb, AC97BusMasterRegs),
|
|
|
|
VMSTATE_UINT8(piv, AC97BusMasterRegs),
|
|
|
|
VMSTATE_UINT8(cr, AC97BusMasterRegs),
|
|
|
|
VMSTATE_UINT32(bd_valid, AC97BusMasterRegs),
|
|
|
|
VMSTATE_UINT32(bd.addr, AC97BusMasterRegs),
|
|
|
|
VMSTATE_UINT32(bd.ctl_len, AC97BusMasterRegs),
|
|
|
|
VMSTATE_END_OF_LIST()
|
2008-01-14 07:27:55 +03:00
|
|
|
}
|
2009-12-02 13:49:42 +03:00
|
|
|
};
|
2008-01-14 07:27:55 +03:00
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
static int ac97_post_load(void *opaque, int version_id)
|
2008-01-14 07:27:55 +03:00
|
|
|
{
|
|
|
|
uint8_t active[LAST_INDEX];
|
|
|
|
AC97LinkState *s = opaque;
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
record_select(s, mixer_load(s, AC97_Record_Select));
|
|
|
|
set_volume(s, AC97_Master_Volume_Mute,
|
|
|
|
mixer_load(s, AC97_Master_Volume_Mute));
|
|
|
|
set_volume(s, AC97_PCM_Out_Volume_Mute,
|
|
|
|
mixer_load(s, AC97_PCM_Out_Volume_Mute));
|
|
|
|
set_volume(s, AC97_Record_Gain_Mute,
|
|
|
|
mixer_load(s, AC97_Record_Gain_Mute));
|
2012-04-17 16:32:39 +04:00
|
|
|
|
2009-12-02 13:49:40 +03:00
|
|
|
active[PI_INDEX] = !!(s->bm_regs[PI_INDEX].cr & CR_RPBM);
|
|
|
|
active[PO_INDEX] = !!(s->bm_regs[PO_INDEX].cr & CR_RPBM);
|
|
|
|
active[MC_INDEX] = !!(s->bm_regs[MC_INDEX].cr & CR_RPBM);
|
2022-04-23 12:36:57 +03:00
|
|
|
reset_voices(s, active);
|
2008-01-14 07:27:55 +03:00
|
|
|
|
|
|
|
s->bup_flag = 0;
|
|
|
|
s->last_samp = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
static bool is_version_2(void *opaque, int version_id)
|
2009-12-02 13:49:42 +03:00
|
|
|
{
|
|
|
|
return version_id == 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_ac97 = {
|
|
|
|
.name = "ac97",
|
|
|
|
.version_id = 3,
|
|
|
|
.minimum_version_id = 2,
|
|
|
|
.post_load = ac97_post_load,
|
2014-04-16 17:32:32 +04:00
|
|
|
.fields = (VMStateField[]) {
|
2022-04-23 12:36:57 +03:00
|
|
|
VMSTATE_PCI_DEVICE(dev, AC97LinkState),
|
|
|
|
VMSTATE_UINT32(glob_cnt, AC97LinkState),
|
|
|
|
VMSTATE_UINT32(glob_sta, AC97LinkState),
|
|
|
|
VMSTATE_UINT32(cas, AC97LinkState),
|
|
|
|
VMSTATE_STRUCT_ARRAY(bm_regs, AC97LinkState, 3, 1,
|
|
|
|
vmstate_ac97_bm_regs, AC97BusMasterRegs),
|
|
|
|
VMSTATE_BUFFER(mixer_data, AC97LinkState),
|
|
|
|
VMSTATE_UNUSED_TEST(is_version_2, 3),
|
|
|
|
VMSTATE_END_OF_LIST()
|
2009-12-02 13:49:42 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-10-08 15:02:20 +04:00
|
|
|
static uint64_t nam_read(void *opaque, hwaddr addr, unsigned size)
|
|
|
|
{
|
|
|
|
if ((addr / size) > 256) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (size) {
|
|
|
|
case 1:
|
|
|
|
return nam_readb(opaque, addr);
|
|
|
|
case 2:
|
|
|
|
return nam_readw(opaque, addr);
|
|
|
|
case 4:
|
|
|
|
return nam_readl(opaque, addr);
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void nam_write(void *opaque, hwaddr addr, uint64_t val,
|
|
|
|
unsigned size)
|
|
|
|
{
|
|
|
|
if ((addr / size) > 256) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (size) {
|
|
|
|
case 1:
|
|
|
|
nam_writeb(opaque, addr, val);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
nam_writew(opaque, addr, val);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
nam_writel(opaque, addr, val);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-08-08 17:09:07 +04:00
|
|
|
|
|
|
|
static const MemoryRegionOps ac97_io_nam_ops = {
|
2012-10-08 15:02:20 +04:00
|
|
|
.read = nam_read,
|
|
|
|
.write = nam_write,
|
|
|
|
.impl = {
|
|
|
|
.min_access_size = 1,
|
|
|
|
.max_access_size = 4,
|
|
|
|
},
|
|
|
|
.endianness = DEVICE_LITTLE_ENDIAN,
|
2011-08-08 17:09:07 +04:00
|
|
|
};
|
|
|
|
|
2012-10-08 15:02:20 +04:00
|
|
|
static uint64_t nabm_read(void *opaque, hwaddr addr, unsigned size)
|
|
|
|
{
|
|
|
|
if ((addr / size) > 64) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (size) {
|
|
|
|
case 1:
|
|
|
|
return nabm_readb(opaque, addr);
|
|
|
|
case 2:
|
|
|
|
return nabm_readw(opaque, addr);
|
|
|
|
case 4:
|
|
|
|
return nabm_readl(opaque, addr);
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void nabm_write(void *opaque, hwaddr addr, uint64_t val,
|
2022-04-23 12:36:57 +03:00
|
|
|
unsigned size)
|
2012-10-08 15:02:20 +04:00
|
|
|
{
|
|
|
|
if ((addr / size) > 64) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (size) {
|
|
|
|
case 1:
|
|
|
|
nabm_writeb(opaque, addr, val);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
nabm_writew(opaque, addr, val);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
nabm_writel(opaque, addr, val);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-08 17:09:07 +04:00
|
|
|
|
|
|
|
static const MemoryRegionOps ac97_io_nabm_ops = {
|
2012-10-08 15:02:20 +04:00
|
|
|
.read = nabm_read,
|
|
|
|
.write = nabm_write,
|
|
|
|
.impl = {
|
|
|
|
.min_access_size = 1,
|
|
|
|
.max_access_size = 4,
|
|
|
|
},
|
|
|
|
.endianness = DEVICE_LITTLE_ENDIAN,
|
2011-08-08 17:09:07 +04:00
|
|
|
};
|
2008-01-14 07:27:55 +03:00
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
static void ac97_on_reset(DeviceState *dev)
|
2008-01-14 07:27:55 +03:00
|
|
|
{
|
2023-02-20 13:47:14 +03:00
|
|
|
AC97LinkState *s = AC97(dev);
|
2008-01-14 07:27:55 +03:00
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
reset_bm_regs(s, &s->bm_regs[0]);
|
|
|
|
reset_bm_regs(s, &s->bm_regs[1]);
|
|
|
|
reset_bm_regs(s, &s->bm_regs[2]);
|
2008-01-14 07:27:55 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset the mixer too. The Windows XP driver seems to rely on
|
|
|
|
* this. At least it wants to read the vendor id before it resets
|
|
|
|
* the codec manually.
|
|
|
|
*/
|
2022-04-23 12:36:57 +03:00
|
|
|
mixer_reset(s);
|
2008-01-14 07:27:55 +03:00
|
|
|
}
|
|
|
|
|
2015-01-19 17:52:30 +03:00
|
|
|
static void ac97_realize(PCIDevice *dev, Error **errp)
|
2008-01-14 07:27:55 +03:00
|
|
|
{
|
2018-10-13 09:08:09 +03:00
|
|
|
AC97LinkState *s = AC97(dev);
|
2009-08-21 15:56:09 +04:00
|
|
|
uint8_t *c = s->dev.config;
|
2008-01-14 07:27:55 +03:00
|
|
|
|
2009-12-10 20:21:55 +03:00
|
|
|
/* TODO: no need to override */
|
|
|
|
c[PCI_COMMAND] = 0x00; /* pcicmd pci command rw, ro */
|
|
|
|
c[PCI_COMMAND + 1] = 0x00;
|
2008-01-14 07:27:55 +03:00
|
|
|
|
2009-12-10 20:21:55 +03:00
|
|
|
/* TODO: */
|
|
|
|
c[PCI_STATUS] = PCI_STATUS_FAST_BACK; /* pcists pci status rwc, ro */
|
|
|
|
c[PCI_STATUS + 1] = PCI_STATUS_DEVSEL_MEDIUM >> 8;
|
2008-01-14 07:27:55 +03:00
|
|
|
|
2009-12-10 20:21:55 +03:00
|
|
|
c[PCI_CLASS_PROG] = 0x00; /* pi programming interface ro */
|
2008-01-14 07:27:55 +03:00
|
|
|
|
2009-12-10 20:21:55 +03:00
|
|
|
/* TODO set when bar is registered. no need to override. */
|
|
|
|
/* nabmar native audio mixer base address rw */
|
|
|
|
c[PCI_BASE_ADDRESS_0] = PCI_BASE_ADDRESS_SPACE_IO;
|
|
|
|
c[PCI_BASE_ADDRESS_0 + 1] = 0x00;
|
|
|
|
c[PCI_BASE_ADDRESS_0 + 2] = 0x00;
|
|
|
|
c[PCI_BASE_ADDRESS_0 + 3] = 0x00;
|
|
|
|
|
|
|
|
/* TODO set when bar is registered. no need to override. */
|
|
|
|
/* nabmbar native audio bus mastering base address rw */
|
|
|
|
c[PCI_BASE_ADDRESS_0 + 4] = PCI_BASE_ADDRESS_SPACE_IO;
|
|
|
|
c[PCI_BASE_ADDRESS_0 + 5] = 0x00;
|
|
|
|
c[PCI_BASE_ADDRESS_0 + 6] = 0x00;
|
|
|
|
c[PCI_BASE_ADDRESS_0 + 7] = 0x00;
|
|
|
|
|
|
|
|
c[PCI_INTERRUPT_LINE] = 0x00; /* intr_ln interrupt line rw */
|
|
|
|
c[PCI_INTERRUPT_PIN] = 0x01; /* intr_pn interrupt pin ro */
|
2008-01-14 07:27:55 +03:00
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
memory_region_init_io(&s->io_nam, OBJECT(s), &ac97_io_nam_ops, s,
|
|
|
|
"ac97-nam", 1024);
|
|
|
|
memory_region_init_io(&s->io_nabm, OBJECT(s), &ac97_io_nabm_ops, s,
|
|
|
|
"ac97-nabm", 256);
|
|
|
|
pci_register_bar(&s->dev, 0, PCI_BASE_ADDRESS_SPACE_IO, &s->io_nam);
|
|
|
|
pci_register_bar(&s->dev, 1, PCI_BASE_ADDRESS_SPACE_IO, &s->io_nabm);
|
|
|
|
AUD_register_card("ac97", &s->card);
|
2019-05-28 19:40:16 +03:00
|
|
|
ac97_on_reset(DEVICE(s));
|
2009-06-30 16:12:13 +04:00
|
|
|
}
|
|
|
|
|
2016-12-15 05:30:21 +03:00
|
|
|
static void ac97_exit(PCIDevice *dev)
|
|
|
|
{
|
2018-10-13 09:08:09 +03:00
|
|
|
AC97LinkState *s = AC97(dev);
|
2016-12-15 05:30:21 +03:00
|
|
|
|
|
|
|
AUD_close_in(&s->card, s->voice_pi);
|
|
|
|
AUD_close_out(&s->card, s->voice_po);
|
|
|
|
AUD_close_in(&s->card, s->voice_mc);
|
|
|
|
AUD_remove_card(&s->card);
|
|
|
|
}
|
|
|
|
|
2011-12-04 22:22:06 +04:00
|
|
|
static Property ac97_properties[] = {
|
2019-08-19 02:06:49 +03:00
|
|
|
DEFINE_AUDIO_PROPERTIES(AC97LinkState, card),
|
2022-04-23 12:36:57 +03:00
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
2011-12-04 22:22:06 +04:00
|
|
|
};
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
static void ac97_class_init(ObjectClass *klass, void *data)
|
2011-12-04 22:22:06 +04:00
|
|
|
{
|
2022-04-23 12:36:57 +03:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
|
|
|
PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
|
2011-12-04 22:22:06 +04:00
|
|
|
|
2015-01-19 17:52:30 +03:00
|
|
|
k->realize = ac97_realize;
|
2016-12-15 05:30:21 +03:00
|
|
|
k->exit = ac97_exit;
|
2011-12-04 22:22:06 +04:00
|
|
|
k->vendor_id = PCI_VENDOR_ID_INTEL;
|
|
|
|
k->device_id = PCI_DEVICE_ID_INTEL_82801AA_5;
|
|
|
|
k->revision = 0x01;
|
|
|
|
k->class_id = PCI_CLASS_MULTIMEDIA_AUDIO;
|
2013-07-29 18:17:45 +04:00
|
|
|
set_bit(DEVICE_CATEGORY_SOUND, dc->categories);
|
2011-12-08 07:34:16 +04:00
|
|
|
dc->desc = "Intel 82801AA AC97 Audio";
|
|
|
|
dc->vmsd = &vmstate_ac97;
|
2020-01-10 18:30:32 +03:00
|
|
|
device_class_set_props(dc, ac97_properties);
|
2014-09-16 09:59:55 +04:00
|
|
|
dc->reset = ac97_on_reset;
|
2011-12-04 22:22:06 +04:00
|
|
|
}
|
|
|
|
|
2013-01-10 19:19:07 +04:00
|
|
|
static const TypeInfo ac97_info = {
|
2018-10-13 09:08:09 +03:00
|
|
|
.name = TYPE_AC97,
|
2011-12-08 07:34:16 +04:00
|
|
|
.parent = TYPE_PCI_DEVICE,
|
2022-04-23 12:36:57 +03:00
|
|
|
.instance_size = sizeof(AC97LinkState),
|
2011-12-08 07:34:16 +04:00
|
|
|
.class_init = ac97_class_init,
|
2017-09-27 22:56:34 +03:00
|
|
|
.interfaces = (InterfaceInfo[]) {
|
|
|
|
{ INTERFACE_CONVENTIONAL_PCI_DEVICE },
|
|
|
|
{ },
|
|
|
|
},
|
2009-06-30 16:12:13 +04:00
|
|
|
};
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
static void ac97_register_types(void)
|
2009-06-30 16:12:13 +04:00
|
|
|
{
|
2022-04-23 12:36:57 +03:00
|
|
|
type_register_static(&ac97_info);
|
2020-07-02 16:25:09 +03:00
|
|
|
deprecated_register_soundhw("ac97", "Intel 82801AA AC97 Audio",
|
|
|
|
0, TYPE_AC97);
|
2009-06-30 16:12:13 +04:00
|
|
|
}
|
|
|
|
|
2022-04-23 12:36:57 +03:00
|
|
|
type_init(ac97_register_types)
|