Break up vl.h.
[qemu] / hw / es1370.c
index 0191f5f..754f621 100644 (file)
 /* #define VERBOSE_ES1370 */
 #define SILENT_ES1370
 
-#include "vl.h"
+#include "hw.h"
+#include "audiodev.h"
+#include "audio/audio.h"
+#include "pci.h"
 
 /* Missing stuff:
    SCTRL_P[12](END|ST)INC
@@ -249,7 +252,7 @@ static void print_sctl (uint32_t val)
 #endif
 
 #ifndef SILENT_ES1370
-#define lwarn(...) AUD_log ("es1370: warning:", __VA_ARGS__)
+#define lwarn(...) AUD_log ("es1370: warning", __VA_ARGS__)
 #else
 #define lwarn(...)
 #endif
@@ -265,6 +268,7 @@ struct chan {
 typedef struct ES1370State {
     PCIDevice *pci_dev;
 
+    QEMUSoundCard card;
     struct chan chan[NB_CHANNELS];
     SWVoiceOut *dac_voice[2];
     SWVoiceIn *adc_voice;
@@ -323,7 +327,7 @@ static void es1370_update_status (ES1370State *s, uint32_t new_status)
     else {
         s->status = new_status & ~STAT_INTR;
     }
-    pci_set_irq (s->pci_dev, 0, !!level);
+    qemu_set_irq(s->pci_dev->irq[0], !!level);
 }
 
 static void es1370_reset (ES1370State *s)
@@ -341,15 +345,15 @@ static void es1370_reset (ES1370State *s)
         d->scount = 0;
         d->leftover = 0;
         if (i == ADC_CHANNEL) {
-            AUD_close_in (s->adc_voice);
+            AUD_close_in (&s->card, s->adc_voice);
             s->adc_voice = NULL;
         }
         else {
-            AUD_close_out (s->dac_voice[i]);
+            AUD_close_out (&s->card, s->dac_voice[i]);
             s->dac_voice[i] = NULL;
         }
     }
-    pci_set_irq (s->pci_dev, 0, 0);
+    qemu_irq_lower(s->pci_dev->irq[0]);
 }
 
 static void es1370_maybe_lower_irq (ES1370State *s, uint32_t sctl)
@@ -417,28 +421,33 @@ static void es1370_update_voices (ES1370State *s, uint32_t ctl, uint32_t sctl)
                     (new_fmt & 2) ? AUD_FMT_S16 : AUD_FMT_U8,
                     d->shift);
             if (new_freq) {
+                audsettings_t as;
+
+                as.freq = new_freq;
+                as.nchannels = 1 << (new_fmt & 1);
+                as.fmt = (new_fmt & 2) ? AUD_FMT_S16 : AUD_FMT_U8;
+                as.endianness = 0;
+
                 if (i == ADC_CHANNEL) {
                     s->adc_voice =
                         AUD_open_in (
+                            &s->card,
                             s->adc_voice,
                             "es1370.adc",
                             s,
                             es1370_adc_callback,
-                            new_freq,
-                            1 << (new_fmt & 1),
-                            (new_fmt & 2) ? AUD_FMT_S16 : AUD_FMT_U8
+                            &as
                             );
                 }
                 else {
                     s->dac_voice[i] =
                         AUD_open_out (
+                            &s->card,
                             s->dac_voice[i],
                             i ? "es1370.dac2" : "es1370.dac1",
                             s,
                             i ? es1370_dac2_callback : es1370_dac1_callback,
-                            new_freq,
-                            1 << (new_fmt & 1),
-                            (new_fmt & 2) ? AUD_FMT_S16 : AUD_FMT_U8
+                            &as
                             );
                 }
             }
@@ -472,9 +481,10 @@ static inline uint32_t es1370_fixup (ES1370State *s, uint32_t addr)
 IO_WRITE_PROTO (es1370_writeb)
 {
     ES1370State *s = opaque;
-    addr = es1370_fixup (s, addr);
     uint32_t shift, mask;
 
+    addr = es1370_fixup (s, addr);
+
     switch (addr) {
     case ES1370_REG_CONTROL:
     case ES1370_REG_CONTROL + 1:
@@ -585,6 +595,13 @@ IO_WRITE_PROTO (es1370_writel)
         ldebug ("chan %d frame address %#x\n", d - &s->chan[0], val);
         break;
 
+    case ES1370_REG_PHANTOM_FRAMECNT:
+        lwarn ("writing to phantom frame count %#x\n", val);
+        break;
+    case ES1370_REG_PHANTOM_FRAMEADR:
+        lwarn ("writing to phantom frame address %#x\n", val);
+        break;
+
     case ES1370_REG_ADC_FRAMECNT:
         d++;
     case ES1370_REG_DAC2_FRAMECNT:
@@ -654,6 +671,22 @@ IO_READ_PROTO (es1370_readw)
         val = d->scount >> 16;
         break;
 
+    case ES1370_REG_ADC_FRAMECNT:
+        d++;
+    case ES1370_REG_DAC2_FRAMECNT:
+        d++;
+    case ES1370_REG_DAC1_FRAMECNT:
+        val = d->frame_cnt & 0xffff;
+        break;
+
+    case ES1370_REG_ADC_FRAMECNT + 2:
+        d++;
+    case ES1370_REG_DAC2_FRAMECNT + 2:
+        d++;
+    case ES1370_REG_DAC1_FRAMECNT + 2:
+        val = d->frame_cnt >> 16;
+        break;
+
     default:
         val = ~0;
         lwarn ("readw %#x -> %#x\n", addr, val);
@@ -731,6 +764,15 @@ IO_READ_PROTO (es1370_readl)
         val = d->frame_addr;
         break;
 
+    case ES1370_REG_PHANTOM_FRAMECNT:
+        val = ~0U;
+        lwarn ("reading from phantom frame count\n");
+        break;
+    case ES1370_REG_PHANTOM_FRAMEADR:
+        val = ~0U;
+        lwarn ("reading from phantom frame address\n");
+        break;
+
     default:
         val = ~0U;
         lwarn ("readl %#x -> %#x\n", addr, val);
@@ -761,7 +803,7 @@ static void es1370_transfer_audio (ES1370State *s, struct chan *d, int loop_sel,
         while (temp) {
             int acquired, to_copy;
 
-            to_copy = audio_MIN (temp, sizeof (tmpbuf));
+            to_copy = audio_MIN ((size_t) temp, sizeof (tmpbuf));
             acquired = AUD_read (s->adc_voice, tmpbuf, to_copy);
             if (!acquired)
                 break;
@@ -779,7 +821,7 @@ static void es1370_transfer_audio (ES1370State *s, struct chan *d, int loop_sel,
         while (temp) {
             int copied, to_copy;
 
-            to_copy = audio_MIN (temp, sizeof (tmpbuf));
+            to_copy = audio_MIN ((size_t) temp, sizeof (tmpbuf));
             cpu_physical_memory_read (addr, tmpbuf, to_copy);
             copied = AUD_write (voice, tmpbuf, to_copy);
             if (!copied)
@@ -807,12 +849,12 @@ static void es1370_transfer_audio (ES1370State *s, struct chan *d, int loop_sel,
     if (s->sctl & loop_sel) {
         /* Bah, how stupid is that having a 0 represent true value?
            i just spent few hours on this shit */
-        lwarn ("whoops non looping mode\n");
+        AUD_log ("es1370: warning", "non looping mode\n");
     }
     else {
         d->frame_cnt = size;
 
-        if (cnt <= d->frame_cnt)
+        if ((uint32_t) cnt <= d->frame_cnt)
             d->frame_cnt |= cnt << 16;
     }
 
@@ -876,6 +918,10 @@ static void es1370_map (PCIDevice *pci_dev, int region_num,
     PCIES1370State *d = (PCIES1370State *) pci_dev;
     ES1370State *s = &d->es1370;
 
+    (void) region_num;
+    (void) size;
+    (void) type;
+
     register_ioport_write (addr, 0x40 * 4, 1, es1370_writeb, s);
     register_ioport_write (addr, 0x40 * 2, 2, es1370_writew, s);
     register_ioport_write (addr, 0x40, 4, es1370_writel, s);
@@ -923,13 +969,13 @@ static int es1370_load (QEMUFile *f, void *opaque, int version_id)
         qemu_get_be32s (f, &d->frame_cnt);
         if (i == ADC_CHANNEL) {
             if (s->adc_voice) {
-                AUD_close_in (s->adc_voice);
+                AUD_close_in (&s->card, s->adc_voice);
                 s->adc_voice = NULL;
             }
         }
         else {
             if (s->dac_voice[i]) {
-                AUD_close_out (s->dac_voice[i]);
+                AUD_close_out (&s->card, s->dac_voice[i]);
                 s->dac_voice[i] = NULL;
             }
         }
@@ -953,18 +999,28 @@ static void es1370_on_reset (void *opaque)
     es1370_reset (s);
 }
 
-int es1370_init (PCIBus *bus)
+int es1370_init (PCIBus *bus, AudioState *audio)
 {
     PCIES1370State *d;
     ES1370State *s;
     uint8_t *c;
 
+    if (!bus) {
+        dolog ("No PCI bus\n");
+        return -1;
+    }
+
+    if (!audio) {
+        dolog ("No audio state\n");
+        return -1;
+    }
+
     d = (PCIES1370State *) pci_register_device (bus, "ES1370",
                                                 sizeof (PCIES1370State),
                                                 -1, NULL, NULL);
 
     if (!d) {
-        fprintf (stderr, "Failed to register PCI device for ES1370\n");
+        AUD_log (NULL, "Failed to register PCI device for ES1370\n");
         return -1;
     }
 
@@ -1002,6 +1058,8 @@ int es1370_init (PCIBus *bus)
     pci_register_io_region (&d->dev, 0, 256, PCI_ADDRESS_SPACE_IO, es1370_map);
     register_savevm ("es1370", 0, 1, es1370_save, es1370_load, s);
     qemu_register_reset (es1370_on_reset, s);
+
+    AUD_register_card (audio, "es1370", &s->card);
     es1370_reset (s);
     return 0;
 }