configure: change "found" to "find"
[qemu] / hw / es1370.c
index 0d2d861..9071a48 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
@@ -263,8 +266,7 @@ struct chan {
 };
 
 typedef struct ES1370State {
-    PCIDevice *pci_dev;
-
+    PCIDevice dev;
     QEMUSoundCard card;
     struct chan chan[NB_CHANNELS];
     SWVoiceOut *dac_voice[2];
@@ -277,11 +279,6 @@ typedef struct ES1370State {
     uint32_t sctl;
 } ES1370State;
 
-typedef struct PCIES1370State {
-    PCIDevice dev;
-    ES1370State es1370;
-} PCIES1370State;
-
 struct chan_bits {
     uint32_t ctl_en;
     uint32_t stat_int;
@@ -324,7 +321,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->dev.irq[0], !!level);
 }
 
 static void es1370_reset (ES1370State *s)
@@ -350,7 +347,7 @@ static void es1370_reset (ES1370State *s)
             s->dac_voice[i] = NULL;
         }
     }
-    pci_set_irq (s->pci_dev, 0, 0);
+    qemu_irq_lower (s->dev.irq[0]);
 }
 
 static void es1370_maybe_lower_irq (ES1370State *s, uint32_t sctl)
@@ -418,7 +415,7 @@ 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;
+                struct audsettings as;
 
                 as.freq = new_freq;
                 as.nchannels = 1 << (new_fmt & 1);
@@ -912,8 +909,7 @@ static void es1370_adc_callback (void *opaque, int avail)
 static void es1370_map (PCIDevice *pci_dev, int region_num,
                         uint32_t addr, uint32_t size, int type)
 {
-    PCIES1370State *d = (PCIES1370State *) pci_dev;
-    ES1370State *s = &d->es1370;
+    ES1370State *s = DO_UPCAST (ES1370State, dev, pci_dev);
 
     (void) region_num;
     (void) size;
@@ -933,6 +929,7 @@ static void es1370_save (QEMUFile *f, void *opaque)
     ES1370State *s = opaque;
     size_t i;
 
+    pci_device_save (&s->dev, f);
     for (i = 0; i < NB_CHANNELS; ++i) {
         struct chan *d = &s->chan[i];
         qemu_put_be32s (f, &d->shift);
@@ -950,13 +947,18 @@ static void es1370_save (QEMUFile *f, void *opaque)
 
 static int es1370_load (QEMUFile *f, void *opaque, int version_id)
 {
+    int ret;
     uint32_t ctl, sctl;
     ES1370State *s = opaque;
     size_t i;
 
-    if (version_id != 1)
+    if (version_id != 2)
         return -EINVAL;
 
+    ret = pci_device_load (&s->dev, f);
+    if (ret)
+        return ret;
+
     for (i = 0; i < NB_CHANNELS; ++i) {
         struct chan *d = &s->chan[i];
         qemu_get_be32s (f, &d->shift);
@@ -996,39 +998,15 @@ static void es1370_on_reset (void *opaque)
     es1370_reset (s);
 }
 
-int es1370_init (PCIBus *bus, AudioState *audio)
+static int es1370_initfn (PCIDevice *dev)
 {
-    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) {
-        AUD_log (NULL, "Failed to register PCI device for ES1370\n");
-        return -1;
-    }
+    ES1370State *s = DO_UPCAST (ES1370State, dev, dev);
+    uint8_t *c = s->dev.config;
 
-    c = d->dev.config;
-    c[0x00] = 0x74;
-    c[0x01] = 0x12;
-    c[0x02] = 0x00;
-    c[0x03] = 0x50;
+    pci_config_set_vendor_id (c, PCI_VENDOR_ID_ENSONIQ);
+    pci_config_set_device_id (c, PCI_DEVICE_ID_ENSONIQ_ES1370);
     c[0x07] = 2 << 1;
-    c[0x0a] = 0x01;
-    c[0x0b] = 0x04;
+    pci_config_set_class (c, PCI_CLASS_MULTIMEDIA_AUDIO);
 
 #if 1
     c[0x2c] = 0x42;
@@ -1049,14 +1027,31 @@ int es1370_init (PCIBus *bus, AudioState *audio)
     c[0x3e] = 0x0c;
     c[0x3f] = 0x80;
 
-    s = &d->es1370;
-    s->pci_dev = &d->dev;
-
-    pci_register_io_region (&d->dev, 0, 256, PCI_ADDRESS_SPACE_IO, es1370_map);
-    register_savevm ("es1370", 0, 1, es1370_save, es1370_load, s);
+    pci_register_bar (&s->dev, 0, 256, PCI_ADDRESS_SPACE_IO, es1370_map);
+    register_savevm ("es1370", 0, 2, es1370_save, es1370_load, s);
     qemu_register_reset (es1370_on_reset, s);
 
-    AUD_register_card (audio, "es1370", &s->card);
+    AUD_register_card ("es1370", &s->card);
     es1370_reset (s);
     return 0;
 }
+
+int es1370_init (PCIBus *bus)
+{
+    pci_create_simple (bus, -1, "ES1370");
+    return 0;
+}
+
+static PCIDeviceInfo es1370_info = {
+    .qdev.name    = "ES1370",
+    .qdev.desc    = "ENSONIQ AudioPCI ES1370",
+    .qdev.size    = sizeof (ES1370State),
+    .init         = es1370_initfn,
+};
+
+static void es1370_register (void)
+{
+    pci_qdev_register (&es1370_info);
+}
+device_init (es1370_register);
+