qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
Subject: [Qemu-devel] [PULL 38/69] hw/isa/superio: Factor out the floppy disc controller code from pc87312.c
Date: Tue, 13 Mar 2018 23:46:48 +0100	[thread overview]
Message-ID: <20180313224719.4954-39-pbonzini@redhat.com> (raw)
In-Reply-To: <20180313224719.4954-1-pbonzini@redhat.com>

From: Philippe Mathieu-Daudé <f4bug@amsat.org>

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-Id: <20180308223946.26784-13-f4bug@amsat.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/isa/isa-superio.c     | 36 ++++++++++++++++++++++++++++++++++++
 hw/isa/pc87312.c         | 46 +++++++++++++++++++---------------------------
 hw/isa/trace-events      |  2 +-
 include/hw/isa/pc87312.h |  4 ----
 include/hw/isa/superio.h |  2 ++
 5 files changed, 58 insertions(+), 32 deletions(-)

diff --git a/hw/isa/isa-superio.c b/hw/isa/isa-superio.c
index 6962421aad..4b5e280b38 100644
--- a/hw/isa/isa-superio.c
+++ b/hw/isa/isa-superio.c
@@ -11,7 +11,10 @@
  */
 #include "qemu/osdep.h"
 #include "qemu/error-report.h"
+#include "qapi/error.h"
 #include "sysemu/sysemu.h"
+#include "sysemu/block-backend.h"
+#include "sysemu/blockdev.h"
 #include "chardev/char.h"
 #include "hw/isa/superio.h"
 #include "hw/char/serial.h"
@@ -25,6 +28,7 @@ static void isa_superio_realize(DeviceState *dev, Error **errp)
     ISADevice *isa;
     DeviceState *d;
     Chardev *chr;
+    DriveInfo *drive;
     char *name;
     int i;
 
@@ -107,6 +111,38 @@ static void isa_superio_realize(DeviceState *dev, Error **errp)
             g_free(name);
         }
     }
+
+    /* Floppy disc */
+    if (!k->floppy.is_enabled || k->floppy.is_enabled(sio, 0)) {
+        isa = isa_create(bus, "isa-fdc");
+        d = DEVICE(isa);
+        if (k->floppy.get_iobase) {
+            qdev_prop_set_uint32(d, "iobase", k->floppy.get_iobase(sio, 0));
+        }
+        if (k->floppy.get_irq) {
+            qdev_prop_set_uint32(d, "irq", k->floppy.get_irq(sio, 0));
+        }
+        /* FIXME use a qdev drive property instead of drive_get() */
+        drive = drive_get(IF_FLOPPY, 0, 0);
+        if (drive != NULL) {
+            qdev_prop_set_drive(d, "driveA", blk_by_legacy_dinfo(drive),
+                                &error_fatal);
+        }
+        /* FIXME use a qdev drive property instead of drive_get() */
+        drive = drive_get(IF_FLOPPY, 0, 1);
+        if (drive != NULL) {
+            qdev_prop_set_drive(d, "driveB", blk_by_legacy_dinfo(drive),
+                                &error_fatal);
+        }
+        qdev_init_nofail(d);
+        sio->floppy = isa;
+        trace_superio_create_floppy(0,
+                                    k->floppy.get_iobase ?
+                                    k->floppy.get_iobase(sio, 0) : -1,
+                                    k->floppy.get_irq ?
+                                    k->floppy.get_irq(sio, 0) : -1);
+    }
+
 }
 
 static void isa_superio_class_init(ObjectClass *oc, void *data)
diff --git a/hw/isa/pc87312.c b/hw/isa/pc87312.c
index c2837bca43..a1845a91c3 100644
--- a/hw/isa/pc87312.c
+++ b/hw/isa/pc87312.c
@@ -27,8 +27,6 @@
 #include "hw/isa/pc87312.h"
 #include "qapi/error.h"
 #include "qemu/error-report.h"
-#include "sysemu/block-backend.h"
-#include "sysemu/blockdev.h"
 #include "trace.h"
 
 
@@ -129,16 +127,26 @@ static bool is_uart_enabled(ISASuperIODevice *sio, uint8_t i)
 
 /* Floppy controller */
 
-static inline bool is_fdc_enabled(PC87312State *s)
+static bool is_fdc_enabled(ISASuperIODevice *sio, uint8_t index)
 {
+    PC87312State *s = PC87312(sio);
+    assert(!index);
     return s->regs[REG_FER] & FER_FDC_EN;
 }
 
-static inline uint16_t get_fdc_iobase(PC87312State *s)
+static uint16_t get_fdc_iobase(ISASuperIODevice *sio, uint8_t index)
 {
+    PC87312State *s = PC87312(sio);
+    assert(!index);
     return (s->regs[REG_FER] & FER_FDC_ADDR) ? 0x370 : 0x3f0;
 }
 
+static unsigned int get_fdc_irq(ISASuperIODevice *sio, uint8_t index)
+{
+    assert(!index);
+    return 6;
+}
+
 
 /* IDE controller */
 
@@ -272,7 +280,6 @@ static void pc87312_realize(DeviceState *dev, Error **errp)
     DeviceState *d;
     ISADevice *isa;
     ISABus *bus;
-    DriveInfo *drive;
     Error *local_err = NULL;
 
     s = PC87312(dev);
@@ -287,28 +294,6 @@ static void pc87312_realize(DeviceState *dev, Error **errp)
         return;
     }
 
-    if (is_fdc_enabled(s)) {
-        isa = isa_create(bus, "isa-fdc");
-        d = DEVICE(isa);
-        qdev_prop_set_uint32(d, "iobase", get_fdc_iobase(s));
-        qdev_prop_set_uint32(d, "irq", 6);
-        /* FIXME use a qdev drive property instead of drive_get() */
-        drive = drive_get(IF_FLOPPY, 0, 0);
-        if (drive != NULL) {
-            qdev_prop_set_drive(d, "driveA", blk_by_legacy_dinfo(drive),
-                                &error_fatal);
-        }
-        /* FIXME use a qdev drive property instead of drive_get() */
-        drive = drive_get(IF_FLOPPY, 0, 1);
-        if (drive != NULL) {
-            qdev_prop_set_drive(d, "driveB", blk_by_legacy_dinfo(drive),
-                                &error_fatal);
-        }
-        qdev_init_nofail(d);
-        s->fdc.dev = isa;
-        trace_pc87312_info_floppy(get_fdc_iobase(s));
-    }
-
     if (is_ide_enabled(s)) {
         isa = isa_create(bus, "isa-ide");
         d = DEVICE(isa);
@@ -370,6 +355,12 @@ static void pc87312_class_init(ObjectClass *klass, void *data)
         .get_iobase = get_uart_iobase,
         .get_irq    = get_uart_irq,
     };
+    sc->floppy = (ISASuperIOFuncs){
+        .count = 1,
+        .is_enabled = is_fdc_enabled,
+        .get_iobase = get_fdc_iobase,
+        .get_irq    = get_fdc_irq,
+    };
 }
 
 static const TypeInfo pc87312_type_info = {
@@ -378,6 +369,7 @@ static const TypeInfo pc87312_type_info = {
     .instance_size = sizeof(PC87312State),
     .instance_init = pc87312_initfn,
     .class_init    = pc87312_class_init,
+    /* FIXME use a qdev drive property instead of drive_get() */
 };
 
 static void pc87312_register_types(void)
diff --git a/hw/isa/trace-events b/hw/isa/trace-events
index c78dd6c353..8d9900882f 100644
--- a/hw/isa/trace-events
+++ b/hw/isa/trace-events
@@ -3,9 +3,9 @@
 # hw/isa/isa-superio.c
 superio_create_parallel(int id, uint16_t base, unsigned int irq) "id=%d, base 0x%03x, irq %u"
 superio_create_serial(int id, uint16_t base, unsigned int irq) "id=%d, base 0x%03x, irq %u"
+superio_create_floppy(int id, uint16_t base, unsigned int irq) "id=%d, base 0x%03x, irq %u"
 
 # hw/isa/pc87312.c
 pc87312_io_read(uint32_t addr, uint32_t val) "read addr=0x%x val=0x%x"
 pc87312_io_write(uint32_t addr, uint32_t val) "write addr=0x%x val=0x%x"
-pc87312_info_floppy(uint32_t base) "base 0x%x"
 pc87312_info_ide(uint32_t base) "base 0x%x"
diff --git a/include/hw/isa/pc87312.h b/include/hw/isa/pc87312.h
index 1480615a2c..e16263d4b1 100644
--- a/include/hw/isa/pc87312.h
+++ b/include/hw/isa/pc87312.h
@@ -39,10 +39,6 @@ typedef struct PC87312State {
     uint16_t iobase;
     uint8_t config; /* initial configuration */
 
-    struct {
-        ISADevice *dev;
-    } fdc;
-
     struct {
         ISADevice *dev;
     } ide;
diff --git a/include/hw/isa/superio.h b/include/hw/isa/superio.h
index 0b516721c3..e8007b9eee 100644
--- a/include/hw/isa/superio.h
+++ b/include/hw/isa/superio.h
@@ -29,6 +29,7 @@ typedef struct ISASuperIODevice {
 
     ISADevice *parallel[MAX_PARALLEL_PORTS];
     ISADevice *serial[MAX_SERIAL_PORTS];
+    ISADevice *floppy;
 } ISASuperIODevice;
 
 typedef struct ISASuperIOFuncs {
@@ -47,6 +48,7 @@ typedef struct ISASuperIOClass {
 
     ISASuperIOFuncs parallel;
     ISASuperIOFuncs serial;
+    ISASuperIOFuncs floppy;
 } ISASuperIOClass;
 
 #endif /* HW_ISA_SUPERIO_H */
-- 
2.14.3

  parent reply	other threads:[~2018-03-13 22:48 UTC|newest]

Thread overview: 83+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-13 22:46 [Qemu-devel] [PULL 00/69] Misc patches for QEMU soft freeze Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 01/69] qom: introduce object_class_get_list_sorted Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 02/69] net: allow using any PCI NICs in -net or -nic Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 03/69] q35: change default NIC to e1000e Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 04/69] scsi-disk.c: consider bl->max_transfer in INQUIRY emulation Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 05/69] qemu-doc: update deprecation section to use -nic and -netdev hubport Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 06/69] qemu-doc: Add the paragraph about the -no-frame deprecation again Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 07/69] build-sys: make help could have 'modules' target Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 08/69] hw: Do not include "sysemu/block-backend.h" if it is not necessary Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 09/69] checkpatch: Exempt long URLs Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 10/69] vl: export machine_init_done Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 11/69] chardev: fix handling of EAGAIN for TCP chardev Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 12/69] chardev: update net listener gcontext Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 13/69] chardev: allow telnet gsource to switch gcontext Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 14/69] chardev: introduce chr_machine_done hook Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 15/69] chardev: use chardev's gcontext for async connect Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 16/69] chardev: tcp: postpone async connection setup Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 17/69] chardev: tcp: let TLS run on chardev context Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 18/69] scsi: support NDOB (no data-out buffer) for WRITE SAME commands Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 19/69] hw/i386: make IOMMUs configurable via default-configs/ Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 20/69] Polish the version strings containing the package version Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 21/69] hw/mips/jazz: Fix implicit creation of "-drive if=scsi" devices Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 22/69] rcutorture: remove synchronize_rcu from readers Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 23/69] docs: document atomic_load_acquire and atomic_store_release Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 24/69] rcu: make memory barriers more explicit Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 25/69] membarrier: introduce qemu/sys_membarrier.h Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 26/69] membarrier: add --enable-membarrier Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 27/69] hw/isa: Move parallel_hds_isa_init() to hw/char/parallel-isa.c Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 28/69] hw/dma/i8257: Rename DMA_init() to i8257_dma_init() Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 29/69] hw/input/i8042: Extract declarations from i386/pc.h into input/i8042.h Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 30/69] MAINTAINERS: Fix the PC87312 include path Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 31/69] hw/isa/pc87312: Rename the device type as TYPE_PC87312_SUPERIO Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 32/69] hw/isa/pc87312: Use uint16_t for the ISA I/O base address Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 33/69] hw/isa/pc87312: Use 'unsigned int' for the irq value Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 34/69] hw/isa/superio: Add a Super I/O template based on the PC87312 device Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 35/69] hw/isa/pc87312: Inherit from the abstract TYPE_ISA_SUPERIO Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 36/69] hw/isa/superio: Factor out the parallel code from pc87312.c Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 37/69] hw/isa/superio: Factor out the serial " Paolo Bonzini
2018-03-13 22:46 ` Paolo Bonzini [this message]
2018-03-13 22:46 ` [Qemu-devel] [PULL 39/69] hw/isa/superio: Add a keyboard/mouse controller (8042) Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 40/69] hw/isa/superio: Factor out the IDE code from pc87312.c Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 41/69] hw/mips/malta: Code movement Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 42/69] hw/isa/superio: Factor out the FDC37M817 Super I/O from mips_malta.c Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 43/69] hw/mips/mips_fulong2e: Factor out vt82c686b_southbridge_init() Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 44/69] hw/isa/vt82c686: Rename vt82c686b_init() -> vt82c686b_isa_init() Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 45/69] hw/isa/vt82c686: Add the TYPE_VT82C686B_SUPERIO Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 46/69] MAINTAINERS: Add entries for the VT82C686B Super I/O Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 47/69] MAINTAINERS: Split the Alpha TCG/machine section Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 48/69] hw/isa/superio: Add the SMC FDC37C669 Super I/O Paolo Bonzini
2018-03-13 22:46 ` [Qemu-devel] [PULL 49/69] hw/alpha/dp264: Add the ISA DMA controller Paolo Bonzini
2018-03-13 22:47 ` [Qemu-devel] [PULL 50/69] hw/alpha/dp264: Use the TYPE_SMC37C669_SUPERIO Paolo Bonzini
2018-06-01 18:51   ` Emilio G. Cota
2018-06-01 19:49     ` Richard Henderson
2018-06-13 16:21     ` Paolo Bonzini
2018-06-13 16:35       ` Philippe Mathieu-Daudé
2018-06-13 17:17         ` Philippe Mathieu-Daudé
2018-06-14 12:21           ` Philippe Mathieu-Daudé
2018-03-13 22:47 ` [Qemu-devel] [PULL 51/69] hw/i386/pc: Factor out the superio code Paolo Bonzini
2018-03-13 22:47 ` [Qemu-devel] [PULL 52/69] cpu-exec: fix exception_index handling Paolo Bonzini
2018-03-13 22:47 ` [Qemu-devel] [PULL 53/69] replay: fix processing async events Paolo Bonzini
2018-03-13 22:47 ` [Qemu-devel] [PULL 54/69] replay: fixed replay_enable_events Paolo Bonzini
2018-03-13 22:47 ` [Qemu-devel] [PULL 55/69] replay: fix save/load vm for non-empty queue Paolo Bonzini
2018-03-13 22:47 ` [Qemu-devel] [PULL 56/69] replay: added replay log format description Paolo Bonzini
2018-03-13 22:47 ` [Qemu-devel] [PULL 57/69] replay: save prior value of the host clock Paolo Bonzini
2018-03-13 22:47 ` [Qemu-devel] [PULL 58/69] replay/replay.c: bump REPLAY_VERSION again Paolo Bonzini
2018-03-13 22:47 ` [Qemu-devel] [PULL 59/69] replay/replay-internal.c: track holding of replay_lock Paolo Bonzini
2018-03-13 22:47 ` [Qemu-devel] [PULL 60/69] replay: make locking visible outside replay code Paolo Bonzini
2018-03-13 22:47 ` [Qemu-devel] [PULL 61/69] replay: don't destroy mutex at exit Paolo Bonzini
2018-03-13 22:47 ` [Qemu-devel] [PULL 62/69] replay: push replay_mutex_lock up the call tree Paolo Bonzini
2018-03-13 22:47 ` [Qemu-devel] [PULL 63/69] replay: check return values of fwrite Paolo Bonzini
2018-03-13 22:47 ` [Qemu-devel] [PULL 64/69] replay: avoid recursive call of checkpoints Paolo Bonzini
2018-03-13 22:47 ` [Qemu-devel] [PULL 65/69] scripts/replay-dump.py: replay log dumper Paolo Bonzini
2018-03-13 22:47 ` [Qemu-devel] [PULL 66/69] replay: don't process async events when warping the clock Paolo Bonzini
2018-03-13 22:47 ` [Qemu-devel] [PULL 67/69] replay: save vmstate of the asynchronous events Paolo Bonzini
2018-03-13 22:47 ` [Qemu-devel] [PULL 68/69] replay: update documentation Paolo Bonzini
2018-03-13 22:47 ` [Qemu-devel] [PULL 69/69] tcg: fix cpu_io_recompile Paolo Bonzini
2018-03-14  0:15 ` [Qemu-devel] [PULL 00/69] Misc patches for QEMU soft freeze no-reply
2018-03-14  3:35   ` Peter Xu
2018-03-14 10:12     ` Paolo Bonzini
2018-03-14 11:30       ` Eric Blake
2018-03-14 11:36         ` Peter Xu
2018-03-14 11:53         ` Paolo Bonzini
2018-03-16 12:58 ` Peter Maydell

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=20180313224719.4954-39-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=f4bug@amsat.org \
    --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).