qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Li Zhi Hui <zhihuili@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, zhihuili@linux.vnet.ibm.com,
	pingfank@linux.vnet.ibm.com, stefanha@linux.vnet.ibm.com
Subject: [Qemu-devel] [PATCH] Replace bdrv_* to bdrv_aio_* functions in pio mode in fdc.c.
Date: Fri, 23 Mar 2012 15:07:20 +0800	[thread overview]
Message-ID: <1332486440-12512-1-git-send-email-zhihuili@linux.vnet.ibm.com> (raw)

Replace bdrv_* to bdrv_aio_* functions in pio mode in fdc.c.

Signed-off-by: Li Zhi Hui <zhihuili@linux.vnet.ibm.com>
---
 hw/fdc.c |  117 +++++++++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 90 insertions(+), 27 deletions(-)

diff --git a/hw/fdc.c b/hw/fdc.c
index a0236b7..5e855fd 100644
--- a/hw/fdc.c
+++ b/hw/fdc.c
@@ -1301,12 +1301,42 @@ static int fdctrl_transfer_handler (void *opaque, int nchan,
     return len;
 }
 
+enum {
+    FD_DATA_IDLE,
+    FD_DATA_WORKING,
+    FD_DATA_FIN,
+};
+
+int data_status[MAX_FD];
+
+static void fdctrl_read_pio_cb(void *opaque, int ret)
+{
+    FDCtrl *fdctrl = opaque;
+    FDrive *cur_drv;
+
+    if (ret < 0) {
+        cur_drv = get_cur_drv(fdctrl);
+        FLOPPY_DPRINTF("error getting sector %d\n",
+                       fd_sector(cur_drv));
+        /* Sure, image size is too small... */
+        memset(fdctrl->fifo, 0, FD_SECTOR_LEN);
+        data_status[fdctrl->cur_drv] = FD_DATA_IDLE;
+        goto end;
+    }
+    data_status[fdctrl->cur_drv] = FD_DATA_FIN;
+
+end:
+    return;
+}
+
 /* Data register : 0x05 */
 static uint32_t fdctrl_read_data(FDCtrl *fdctrl)
 {
     FDrive *cur_drv;
     uint32_t retval = 0;
     int pos;
+    QEMUIOVector qiov;
+    struct iovec iov;
 
     cur_drv = get_cur_drv(fdctrl);
     fdctrl->dsr &= ~FD_DSR_PWRDOWN;
@@ -1318,17 +1348,30 @@ static uint32_t fdctrl_read_data(FDCtrl *fdctrl)
     if (fdctrl->msr & FD_MSR_NONDMA) {
         pos %= FD_SECTOR_LEN;
         if (pos == 0) {
-            if (fdctrl->data_pos != 0)
-                if (!fdctrl_seek_to_next_sect(fdctrl, cur_drv)) {
-                    FLOPPY_DPRINTF("error seeking to next sector %d\n",
-                                   fd_sector(cur_drv));
-                    return 0;
+            switch (data_status[fdctrl->cur_drv]) {
+            case FD_DATA_IDLE:
+                if (fdctrl->data_pos != 0) {
+                    if (!fdctrl_seek_to_next_sect(fdctrl, cur_drv)) {
+                        FLOPPY_DPRINTF("error seeking to next sector %d\n",
+                                         fd_sector(cur_drv));
+                        goto end;
+                    }
                 }
-            if (bdrv_read(cur_drv->bs, fd_sector(cur_drv), fdctrl->fifo, 1) < 0) {
-                FLOPPY_DPRINTF("error getting sector %d\n",
-                               fd_sector(cur_drv));
-                /* Sure, image size is too small... */
-                memset(fdctrl->fifo, 0, FD_SECTOR_LEN);
+                iov.iov_base = fdctrl->fifo;
+                iov.iov_len  = FD_SECTOR_LEN;
+                qemu_iovec_init_external(&qiov, &iov, 1);
+                bdrv_aio_readv(cur_drv->bs, fd_sector(cur_drv),
+                    &qiov, 1, fdctrl_read_pio_cb, fdctrl);
+                data_status[fdctrl->cur_drv] = FD_DATA_WORKING;
+                goto end;
+            case FD_DATA_WORKING:
+                goto end;
+            case FD_DATA_FIN:
+                data_status[fdctrl->cur_drv] = FD_DATA_IDLE;
+                break;
+            default:
+                data_status[fdctrl->cur_drv] = FD_DATA_IDLE;
+                goto end;
             }
         }
     }
@@ -1347,6 +1390,7 @@ static uint32_t fdctrl_read_data(FDCtrl *fdctrl)
     }
     FLOPPY_DPRINTF("data register: 0x%02x\n", retval);
 
+end:
     return retval;
 }
 
@@ -1759,10 +1803,38 @@ static const struct {
 /* Associate command to an index in the 'handlers' array */
 static uint8_t command_to_handler[256];
 
+static void fdctrl_write_pio_cb(void *opaque, int ret)
+{
+    FDCtrl *fdctrl = opaque;
+    FDrive *cur_drv;
+
+    cur_drv = get_cur_drv(fdctrl);
+    if (ret < 0) {
+        FLOPPY_ERROR("writing sector %d\n", fd_sector(cur_drv));
+        goto end;
+    }
+    if (!fdctrl_seek_to_next_sect(fdctrl, cur_drv)) {
+        FLOPPY_DPRINTF("error seeking to next sector %d\n",
+                       fd_sector(cur_drv));
+        goto end;
+    }
+    /* Switch from transfer mode to status mode
+     * then from status mode to command mode
+     */
+    if (fdctrl->data_pos == fdctrl->data_len) {
+        fdctrl_stop_transfer(fdctrl, FD_SR0_SEEK, 0x00, 0x00);
+    }
+
+end:
+    return;
+}
+
 static void fdctrl_write_data(FDCtrl *fdctrl, uint32_t value)
 {
     FDrive *cur_drv;
     int pos;
+    QEMUIOVector qiov;
+    struct iovec iov;
 
     /* Reset mode */
     if (!(fdctrl->dor & FD_DOR_nRESET)) {
@@ -1780,25 +1852,16 @@ static void fdctrl_write_data(FDCtrl *fdctrl, uint32_t value)
         pos = fdctrl->data_pos++;
         pos %= FD_SECTOR_LEN;
         fdctrl->fifo[pos] = value;
-        if (pos == FD_SECTOR_LEN - 1 ||
-            fdctrl->data_pos == fdctrl->data_len) {
+        if ((pos == FD_SECTOR_LEN - 1) ||
+            (fdctrl->data_pos == fdctrl->data_len)) {
             cur_drv = get_cur_drv(fdctrl);
-            if (bdrv_write(cur_drv->bs, fd_sector(cur_drv), fdctrl->fifo, 1) < 0) {
-                FLOPPY_ERROR("writing sector %d\n", fd_sector(cur_drv));
-                return;
-            }
-            if (!fdctrl_seek_to_next_sect(fdctrl, cur_drv)) {
-                FLOPPY_DPRINTF("error seeking to next sector %d\n",
-                               fd_sector(cur_drv));
-                return;
-            }
+            iov.iov_base = fdctrl->fifo;
+            iov.iov_len  = FD_SECTOR_LEN;
+            qemu_iovec_init_external(&qiov, &iov, 1);
+            bdrv_aio_writev(cur_drv->bs, fd_sector(cur_drv),
+                &qiov, 1, fdctrl_write_pio_cb, fdctrl);
+            return;
         }
-        /* Switch from transfer mode to status mode
-         * then from status mode to command mode
-         */
-        if (fdctrl->data_pos == fdctrl->data_len)
-            fdctrl_stop_transfer(fdctrl, FD_SR0_SEEK, 0x00, 0x00);
-        return;
     }
     if (fdctrl->data_pos == 0) {
         /* Command */
-- 
1.7.4.1

             reply	other threads:[~2012-03-23  7:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-23  7:07 Li Zhi Hui [this message]
2012-03-23  8:47 ` [Qemu-devel] [PATCH] Replace bdrv_* to bdrv_aio_* functions in pio mode in fdc.c Stefan Hajnoczi

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=1332486440-12512-1-git-send-email-zhihuili@linux.vnet.ibm.com \
    --to=zhihuili@linux.vnet.ibm.com \
    --cc=kwolf@redhat.com \
    --cc=pingfank@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@linux.vnet.ibm.com \
    /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).