From nobody Sat Apr 20 10:05:18 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 1637916629181521.1473614702157; Fri, 26 Nov 2021 00:50:29 -0800 (PST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id 9832D16E3DA8; Fri, 26 Nov 2021 08:50:25 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id 4159816E3CF6 for ; Fri, 26 Nov 2021 08:50:12 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Nov 2021 00:50:10 -0800 Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by orsmga003.jf.intel.com with ESMTP; 26 Nov 2021 00:50:08 -0800 X-IronPort-AV: E=McAfee;i="6200,9189,10179"; a="299037740" X-IronPort-AV: E=Sophos;i="5.87,265,1631602800"; d="scan'208";a="299037740" X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,265,1631602800"; d="scan'208";a="457604122" From: Andy Pei To: seabios@seabios.org Date: Fri, 26 Nov 2021 16:06:23 +0800 Message-Id: <1637913983-113758-1-git-send-email-andy.pei@intel.com> Message-ID-Hash: XLD6NKLV6KC2MNZ6JRKPFD6NS3ZS55PA X-Message-ID-Hash: XLD6NKLV6KC2MNZ6JRKPFD6NS3ZS55PA 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 v2] src/hw/virtio-blk: add feature VIRTIO_BLK_F_SIZE_MAX and VIRTIO_BLK_F_SEG_MAX 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: 1637916629967100001 Content-Type: text/plain; charset="utf-8" according to virtio spec, add feature VIRTIO_BLK_F_SIZE_MAX and VIRTIO_BLK_F_SEG_MAX parse to virtio blk driver. Signed-off-by: Ding Limin Signed-off-by: Andy Pei --- src/block.h | 2 ++ src/hw/virtio-blk.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++= ++-- src/hw/virtio-blk.h | 3 +++ 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/src/block.h b/src/block.h index c1b8d73..3af2d71 100644 --- a/src/block.h +++ b/src/block.h @@ -57,6 +57,8 @@ struct drive_s { u8 translation; // type of translation u16 blksize; // block size struct chs_s pchs; // Physical CHS + u32 max_segment_size; //max_segment_size + u32 max_segments; //max_segments }; =20 #define DISK_SECTOR_SIZE 512 diff --git a/src/hw/virtio-blk.c b/src/hw/virtio-blk.c index 3b19896..7935f0f 100644 --- a/src/hw/virtio-blk.c +++ b/src/hw/virtio-blk.c @@ -121,12 +121,16 @@ init_virtio_blk(void *data) u64 version1 =3D 1ull << VIRTIO_F_VERSION_1; u64 iommu_platform =3D 1ull << VIRTIO_F_IOMMU_PLATFORM; u64 blk_size =3D 1ull << VIRTIO_BLK_F_BLK_SIZE; + u64 max_segments =3D 1ull << VIRTIO_BLK_F_SEG_MAX; + u64 max_segment_size =3D 1ull << VIRTIO_BLK_F_SIZE_MAX; + if (!(features & version1)) { dprintf(1, "modern device without virtio_1 feature bit: %pP\n"= , pci); goto fail; } =20 - features =3D features & (version1 | iommu_platform | blk_size); + features =3D features & (version1 | iommu_platform | blk_size + | max_segments | max_segment_size); vp_set_features(vp, features); status |=3D VIRTIO_CONFIG_S_FEATURES_OK; vp_set_status(vp, status); @@ -135,6 +139,22 @@ init_virtio_blk(void *data) goto fail; } =20 + if (features & max_segment_size) + vdrive->drive.max_segment_size =3D + vp_read(&vp->device, struct virtio_blk_config, size_max); + else + vdrive->drive.max_segment_size =3D 0; + dprintf(3, "virtio-blk %pP size_max=3D%u.\n", pci, + vdrive->drive.max_segment_size); + + if (features & max_segments) + vdrive->drive.max_segments =3D + vp_read(&vp->device, struct virtio_blk_config, seg_max); + else + vdrive->drive.max_segments =3D 0; + dprintf(3, "virtio-blk %pP seg_max=3D%u.\n", pci, + vdrive->drive.max_segments); + vdrive->drive.sectors =3D vp_read(&vp->device, struct virtio_blk_config, capacity); if (features & blk_size) { @@ -177,6 +197,21 @@ init_virtio_blk(void *data) vdrive->drive.pchs.cylinder =3D cfg.cylinders; vdrive->drive.pchs.head =3D cfg.heads; vdrive->drive.pchs.sector =3D cfg.sectors; + + if (f & (1 << VIRTIO_BLK_F_SIZE_MAX)) + vdrive->drive.max_segment_size =3D cfg.size_max; + else + vdrive->drive.max_segment_size =3D 0; + dprintf(3, "virtio-blk %pP size_max=3D%u.\n", pci, + vdrive->drive.max_segment_size); + + if (f & (1 << VIRTIO_BLK_F_SEG_MAX)) + vdrive->drive.max_segments =3D cfg.seg_max; + else + vdrive->drive.max_segments =3D 0; + dprintf(3, "virtio-blk %pP seg_max=3D%u.\n", pci, + vdrive->drive.max_segments); + } =20 char *desc =3D znprintf(MAXDESCSIZE, "Virtio disk PCI:%pP", pci); @@ -218,8 +253,11 @@ init_virtio_blk_mmio(void *mmio) u64 features =3D vp_get_features(vp); u64 version1 =3D 1ull << VIRTIO_F_VERSION_1; u64 blk_size =3D 1ull << VIRTIO_BLK_F_BLK_SIZE; + u64 max_segments =3D 1ull << VIRTIO_BLK_F_SEG_MAX; + u64 max_segment_size =3D 1ull << VIRTIO_BLK_F_SIZE_MAX; =20 - features =3D features & (version1 | blk_size); + features =3D features & (version1 | blk_size + | max_segments | max_segment_size); vp_set_features(vp, features); status |=3D VIRTIO_CONFIG_S_FEATURES_OK; vp_set_status(vp, status); @@ -228,6 +266,20 @@ init_virtio_blk_mmio(void *mmio) goto fail; } =20 + if (features & max_segment_size) + vdrive->drive.max_segment_size =3D + vp_read(&vp->device, struct virtio_blk_config, size_max); + else + vdrive->drive.max_segment_size =3D 0; + dprintf(3, "virtio-blk size_max=3D%u.\n", vdrive->drive.max_segment_si= ze); + + if (features & max_segments) + vdrive->drive.max_segments =3D + vp_read(&vp->device, struct virtio_blk_config, seg_max); + else + vdrive->drive.max_segments =3D 0; + dprintf(3, "virtio-blk seg_max=3D%u.\n", vdrive->drive.max_segments); + vdrive->drive.sectors =3D vp_read(&vp->device, struct virtio_blk_config, capacity); if (features & blk_size) { diff --git a/src/hw/virtio-blk.h b/src/hw/virtio-blk.h index d20461a..0294291 100644 --- a/src/hw/virtio-blk.h +++ b/src/hw/virtio-blk.h @@ -16,6 +16,9 @@ struct virtio_blk_config u32 opt_io_size; } __attribute__((packed)); =20 +/* Feature bits */ +#define VIRTIO_BLK_F_SIZE_MAX 1 /* Maximum size of any single segment */ +#define VIRTIO_BLK_F_SEG_MAX 2 /* Maximum number of segments in a reques= t */ #define VIRTIO_BLK_F_BLK_SIZE 6 =20 /* These two define direction. */ --=20 1.8.3.1 _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org