qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: "Andreas Färber" <afaerber@suse.de>
Cc: av1474@comtv.ru, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [RFC PATCH 1/6] adlib: qdev-ify
Date: Wed, 10 Apr 2013 16:13:17 +0200	[thread overview]
Message-ID: <5165737D.7040301@redhat.com> (raw)
In-Reply-To: <51644FAB.1090908@suse.de>

[-- Attachment #1: Type: text/plain, Size: 3579 bytes --]

Il 09/04/2013 19:28, Andreas Färber ha scritto:
>> -int Adlib_init (ISABus *bus)
>> +static int Adlib_initfn (ISADevice *dev)
> 
> Hm, obviously that conflicts with my series converting ISADevices to QOM
> realize that I was hoping to still get into 1.5...

Just put this patch in front of your series (I attach an updated
version).  The patch will just disappear at the next rebase for whoever
submits last.

Paolo

>>  {
>> -    AdlibState *s = &glob_adlib;
>> +    AdlibState *s;
>>      struct audsettings as;
>>  
>> +    if (glob_adlib) {
>> +        dolog ("Cannot create more than 1 adlib device\n");
>> +        return -1;
>> +    }
>> +    s = DO_UPCAST (AdlibState, dev, dev);
> 
> No new DO_UPCAST() for QOM objects please!
> 
>> +    glob_adlib = s;
>> +
>>  #ifdef HAS_YMF262
>> -    if (YMF262Init (1, 14318180, conf.freq)) {
>> -        dolog ("YMF262Init %d failed\n", conf.freq);
>> +    if (YMF262Init (1, 14318180, s->freq)) {
>> +        dolog ("YMF262Init %d failed\n", s->freq);
>>          return -1;
>>      }
>>      else {
>> @@ -290,9 +301,9 @@ int Adlib_init (ISABus *bus)
>>          s->enabled = 1;
>>      }
>>  #else
>> -    s->opl = OPLCreate (OPL_TYPE_YM3812, 3579545, conf.freq);
>> +    s->opl = OPLCreate (OPL_TYPE_YM3812, 3579545, s->freq);
>>      if (!s->opl) {
>> -        dolog ("OPLCreate %d failed\n", conf.freq);
>> +        dolog ("OPLCreate %d failed\n", s->freq);
>>          return -1;
>>      }
>>      else {
>> @@ -301,7 +312,7 @@ int Adlib_init (ISABus *bus)
>>      }
>>  #endif
>>  
>> -    as.freq = conf.freq;
>> +    as.freq = s->freq;
>>      as.nchannels = SHIFT;
>>      as.fmt = AUD_FMT_S16;
>>      as.endianness = AUDIO_HOST_ENDIANNESS;
>> @@ -327,11 +338,46 @@ int Adlib_init (ISABus *bus)
>>      register_ioport_read (0x388, 4, 1, adlib_read, s);
>>      register_ioport_write (0x388, 4, 1, adlib_write, s);
>>  
>> -    register_ioport_read (conf.port, 4, 1, adlib_read, s);
>> -    register_ioport_write (conf.port, 4, 1, adlib_write, s);
>> +    register_ioport_read (s->port, 4, 1, adlib_read, s);
>> +    register_ioport_write (s->port, 4, 1, adlib_write, s);
>>  
>> -    register_ioport_read (conf.port + 8, 2, 1, adlib_read, s);
>> -    register_ioport_write (conf.port + 8, 2, 1, adlib_write, s);
>> +    register_ioport_read (s->port + 8, 2, 1, adlib_read, s);
>> +    register_ioport_write (s->port + 8, 2, 1, adlib_write, s);
>>  
>>      return 0;
>>  }
>> +
>> +static Property adlib_properties[] = {
>> +    DEFINE_PROP_HEX32  ("iobase",  AdlibState, port, 0x220),
>> +    DEFINE_PROP_UINT32 ("freq",    AdlibState, freq,  44100),
>> +    DEFINE_PROP_END_OF_LIST (),
>> +};
>> +
>> +static void adlib_class_initfn (ObjectClass *klass, void *data)
>> +{
>> +    DeviceClass *dc = DEVICE_CLASS (klass);
>> +    ISADeviceClass *ic = ISA_DEVICE_CLASS (klass);
>> +    ic->init = Adlib_initfn;
>> +    dc->desc = ADLIB_DESC;
>> +    dc->props = adlib_properties;
>> +}
>> +
>> +static TypeInfo adlib_info = {
> 
> static const please.
> 
>> +    .name          = "adlib",
>> +    .parent        = TYPE_ISA_DEVICE,
>> +    .instance_size = sizeof (AdlibState),
>> +    .class_init    = adlib_class_initfn,
>> +};
>> +
>> +int Adlib_init (ISABus *bus)
>> +{
>> +    isa_create_simple (bus, "adlib");
>> +    return 0;
>> +}
>> +
>> +static void adlib_register_types (void)
>> +{
>> +    type_register_static (&adlib_info);
>> +}
>> +
>> +type_init (adlib_register_types)
> 
> Andreas
> 


[-- Attachment #2: 0001-adlib-qdev-ify.patch --]
[-- Type: text/x-patch, Size: 4500 bytes --]

>From 2e03021695ed22fb02906eca8fc98c29a6ad50e6 Mon Sep 17 00:00:00 2001
From: Paolo Bonzini <pbonzini@redhat.com>
Date: Tue, 2 Apr 2013 15:14:55 +0200
Subject: [PATCH] adlib: qdev-ify

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/audio/adlib.c | 83 ++++++++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 66 insertions(+), 17 deletions(-)

diff --git a/hw/audio/adlib.c b/hw/audio/adlib.c
index 4a58e6e..fb41f9d 100644
--- a/hw/audio/adlib.c
+++ b/hw/audio/adlib.c
@@ -31,6 +31,12 @@
 
 #define ADLIB_KILL_TIMERS 1
 
+#ifdef HAS_YMF262
+#define ADLIB_DESC "Yamaha YMF262 (OPL3)"
+#else
+#define ADLIB_DESC "Yamaha YM3812 (OPL2)"
+#endif
+
 #ifdef DEBUG
 #include "qemu/timer.h"
 #endif
@@ -56,13 +62,15 @@ void YMF262UpdateOneQEMU (int which, INT16 *dst, int length);
 #define IO_WRITE_PROTO(name) \
     void name (void *opaque, uint32_t nport, uint32_t val)
 
-static struct {
-    int port;
-    int freq;
-} conf = {0x220, 44100};
+#define TYPE_ADLIB "adlib"
+#define ADLIB(obj) OBJECT_CHECK(AdlibState, (obj), TYPE_ADLIB)
 
 typedef struct {
+    ISADevice parent_obj;
+
     QEMUSoundCard card;
+    uint32_t freq;
+    uint32_t port;
     int ticking[2];
     int enabled;
     int active;
@@ -80,7 +88,7 @@ typedef struct {
 #endif
 } AdlibState;
 
-static AdlibState glob_adlib;
+static AdlibState *glob_adlib;
 
 static void adlib_stop_opl_timer (AdlibState *s, size_t n)
 {
@@ -150,7 +158,7 @@ static IO_READ_PROTO (adlib_read)
 
 static void timer_handler (int c, double interval_Sec)
 {
-    AdlibState *s = &glob_adlib;
+    AdlibState *s = glob_adlib;
     unsigned n = c & 1;
 #ifdef DEBUG
     double interval;
@@ -275,14 +283,20 @@ static void Adlib_fini (AdlibState *s)
     AUD_remove_card (&s->card);
 }
 
-int Adlib_init (ISABus *bus)
+static int Adlib_initfn (ISADevice *dev)
 {
-    AdlibState *s = &glob_adlib;
+    AdlibState *s = ADLIB(dev);
     struct audsettings as;
 
+    if (glob_adlib) {
+        dolog ("Cannot create more than 1 adlib device\n");
+        return -1;
+    }
+    glob_adlib = s;
+
 #ifdef HAS_YMF262
-    if (YMF262Init (1, 14318180, conf.freq)) {
-        dolog ("YMF262Init %d failed\n", conf.freq);
+    if (YMF262Init (1, 14318180, s->freq)) {
+        dolog ("YMF262Init %d failed\n", s->freq);
         return -1;
     }
     else {
@@ -290,9 +304,9 @@ int Adlib_init (ISABus *bus)
         s->enabled = 1;
     }
 #else
-    s->opl = OPLCreate (OPL_TYPE_YM3812, 3579545, conf.freq);
+    s->opl = OPLCreate (OPL_TYPE_YM3812, 3579545, s->freq);
     if (!s->opl) {
-        dolog ("OPLCreate %d failed\n", conf.freq);
+        dolog ("OPLCreate %d failed\n", s->freq);
         return -1;
     }
     else {
@@ -301,7 +315,7 @@ int Adlib_init (ISABus *bus)
     }
 #endif
 
-    as.freq = conf.freq;
+    as.freq = s->freq;
     as.nchannels = SHIFT;
     as.fmt = AUD_FMT_S16;
     as.endianness = AUDIO_HOST_ENDIANNESS;
@@ -327,11 +341,46 @@ int Adlib_init (ISABus *bus)
     register_ioport_read (0x388, 4, 1, adlib_read, s);
     register_ioport_write (0x388, 4, 1, adlib_write, s);
 
-    register_ioport_read (conf.port, 4, 1, adlib_read, s);
-    register_ioport_write (conf.port, 4, 1, adlib_write, s);
+    register_ioport_read (s->port, 4, 1, adlib_read, s);
+    register_ioport_write (s->port, 4, 1, adlib_write, s);
 
-    register_ioport_read (conf.port + 8, 2, 1, adlib_read, s);
-    register_ioport_write (conf.port + 8, 2, 1, adlib_write, s);
+    register_ioport_read (s->port + 8, 2, 1, adlib_read, s);
+    register_ioport_write (s->port + 8, 2, 1, adlib_write, s);
 
     return 0;
 }
+
+static Property adlib_properties[] = {
+    DEFINE_PROP_HEX32  ("iobase",  AdlibState, port, 0x220),
+    DEFINE_PROP_UINT32 ("freq",    AdlibState, freq,  44100),
+    DEFINE_PROP_END_OF_LIST (),
+};
+
+static void adlib_class_initfn (ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS (klass);
+    ISADeviceClass *ic = ISA_DEVICE_CLASS (klass);
+    ic->init = Adlib_initfn;
+    dc->desc = ADLIB_DESC;
+    dc->props = adlib_properties;
+}
+
+static const TypeInfo adlib_info = {
+    .name          = TYPE_ADLIB,
+    .parent        = TYPE_ISA_DEVICE,
+    .instance_size = sizeof (AdlibState),
+    .class_init    = adlib_class_initfn,
+};
+
+int Adlib_init (ISABus *bus)
+{
+    isa_create_simple (bus, TYPE_ADLIB);
+    return 0;
+}
+
+static void adlib_register_types (void)
+{
+    type_register_static (&adlib_info);
+}
+
+type_init (adlib_register_types)
-- 
1.8.1.4


  parent reply	other threads:[~2013-04-10 14:13 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-02 14:50 [Qemu-devel] [RFC PATCH 0/6] audio: simplify -soundhw machinery, use default-configs Paolo Bonzini
2013-04-02 14:50 ` [Qemu-devel] [RFC PATCH 1/6] adlib: qdev-ify Paolo Bonzini
2013-04-09 17:28   ` Andreas Färber
2013-04-10  8:03     ` Paolo Bonzini
2013-04-10 14:13     ` Paolo Bonzini [this message]
2013-04-02 14:50 ` [Qemu-devel] [RFC PATCH 2/6] audio: remove the need for audio card CONFIG_* symbols Paolo Bonzini
2013-04-02 14:50 ` [Qemu-devel] [RFC PATCH 3/6] audio: remove HAS_AUDIO Paolo Bonzini
2013-04-02 14:50 ` [Qemu-devel] [RFC PATCH 4/6] audio: remove CONFIG_* symbols Paolo Bonzini
2013-04-10 17:45   ` Andreas Färber
2013-04-11  6:30     ` Paolo Bonzini
2013-04-02 14:51 ` [Qemu-devel] [RFC PATCH 5/6] audio: replace audio card configuration with default-configs Paolo Bonzini
2013-04-02 14:51 ` [Qemu-devel] [RFC PATCH 6/6] audio: move PCI audio cards to pci.mak Paolo Bonzini
2013-04-09 17:06 ` [Qemu-devel] [RFC PATCH 0/6] audio: simplify -soundhw machinery, use default-configs Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5165737D.7040301@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=afaerber@suse.de \
    --cc=av1474@comtv.ru \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).