From nobody Sat Apr 20 02:28:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) client-ip=78.46.105.101; envelope-from=seabios-bounces@seabios.org; helo=coreboot.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from coreboot.org (coreboot.org [78.46.105.101]) by mx.zohomail.com with SMTPS id 1638843442014827.4833933035852; Mon, 6 Dec 2021 18:17:22 -0800 (PST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id 1440916E3D9B; Tue, 7 Dec 2021 02:17:14 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id 44E9116E3D70 for ; Tue, 7 Dec 2021 02:16:24 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Dec 2021 18:16:22 -0800 Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by orsmga001.jf.intel.com with ESMTP; 06 Dec 2021 18:16:21 -0800 X-IronPort-AV: E=McAfee;i="6200,9189,10190"; a="236205197" X-IronPort-AV: E=Sophos;i="5.87,293,1631602800"; d="scan'208";a="236205197" X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,293,1631602800"; d="scan'208";a="542632711" From: Andy Pei To: seabios@seabios.org Date: Tue, 7 Dec 2021 09:31:07 +0800 Message-Id: <1638840668-165774-3-git-send-email-andy.pei@intel.com> In-Reply-To: <1638840668-165774-1-git-send-email-andy.pei@intel.com> References: <1638840668-165774-1-git-send-email-andy.pei@intel.com> Message-ID-Hash: 3BMZB6XVFBGUXKSFBTSRRGQRPEXQO7JW X-Message-ID-Hash: 3BMZB6XVFBGUXKSFBTSRRGQRPEXQO7JW X-MailFrom: andy.pei@intel.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-seabios.seabios.org-0; header-match-seabios.seabios.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: kraxel@redhat.com, andy.pei@intel.com, Ding Limin X-Mailman-Version: 3.3.5rc1 Precedence: list Subject: [SeaBIOS] [PATCH v4 2/3] virtio-blk: abstract a function named virtio_blk_op_one_segment to handle r/w request List-Id: SeaBIOS mailing list Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: coreboot.org; auth=pass smtp.auth=mailman@coreboot.org smtp.mailfrom=seabios-bounces@seabios.org X-Spamd-Bar: --- X-ZM-MESSAGEID: 1638843443880100001 Content-Type: text/plain; charset="utf-8" abstract virtio-blk queue operation to form a function named virtio_blk_op_= one_segment Signed-off-by: Andy Pei Signed-off-by: Ding Limin Reviewed-by: Gerd Hoffmann --- src/hw/virtio-blk.c | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/src/hw/virtio-blk.c b/src/hw/virtio-blk.c index 2653dad..82b1d2a 100644 --- a/src/hw/virtio-blk.c +++ b/src/hw/virtio-blk.c @@ -30,12 +30,38 @@ struct virtiodrive_s { struct vp_device vp; }; =20 +void +virtio_blk_op_one_segment(struct virtiodrive_s *vdrive, + int write, struct vring_list sg[]) +{ + struct vring_virtqueue *vq =3D vdrive->vq; + + /* Add to virtqueue and kick host */ + if (write) + vring_add_buf(vq, sg, 2, 1, 0, 0); + else + vring_add_buf(vq, sg, 1, 2, 0, 0); + vring_kick(&vdrive->vp, vq, 1); + + /* Wait for reply */ + while (!vring_more_used(vq)) + usleep(5); + + /* Reclaim virtqueue element */ + vring_get_buf(vq, NULL); + + /** + ** Clear interrupt status register. Avoid leaving interrupts stuck + ** if VRING_AVAIL_F_NO_INTERRUPT was ignored and interrupts were raise= d. + **/ + vp_get_isr(&vdrive->vp); +} + static int virtio_blk_op(struct disk_op_s *op, int write) { struct virtiodrive_s *vdrive =3D container_of(op->drive_fl, struct virtiodrive_s, drive); - struct vring_virtqueue *vq =3D vdrive->vq; struct virtio_blk_outhdr hdr =3D { .type =3D write ? VIRTIO_BLK_T_OUT : VIRTIO_BLK_T_IN, .ioprio =3D 0, @@ -57,25 +83,7 @@ virtio_blk_op(struct disk_op_s *op, int write) }, }; =20 - /* Add to virtqueue and kick host */ - if (write) - vring_add_buf(vq, sg, 2, 1, 0, 0); - else - vring_add_buf(vq, sg, 1, 2, 0, 0); - vring_kick(&vdrive->vp, vq, 1); - - /* Wait for reply */ - while (!vring_more_used(vq)) - usleep(5); - - /* Reclaim virtqueue element */ - vring_get_buf(vq, NULL); - - /* Clear interrupt status register. Avoid leaving interrupts stuck if - * VRING_AVAIL_F_NO_INTERRUPT was ignored and interrupts were raised. - */ - vp_get_isr(&vdrive->vp); - + virtio_blk_op_one_segment(vdrive, write, sg); return status =3D=3D VIRTIO_BLK_S_OK ? DISK_RET_SUCCESS : DISK_RET_EBA= DTRACK; } =20 --=20 1.8.3.1 _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org