From: "Yao, Jiewen" <jiewen.yao@intel.com>
To: "devel@edk2.groups.io" <devel@edk2.groups.io>,
"Yao, Jiewen" <jiewen.yao@intel.com>,
"kraxel@redhat.com" <kraxel@redhat.com>
Cc: Philippe Mathieu-Daude <philmd@redhat.com>
Subject: Re: [edk2-devel] [PATCH v2 2/4] OvmfPkg/VirtioMmioDeviceLib: Add virtio 1.0 support.
Date: Mon, 16 Aug 2021 13:37:43 +0000 [thread overview]
Message-ID: <PH0PR11MB4885C536145E21992FC7FF348CFD9@PH0PR11MB4885.namprd11.prod.outlook.com> (raw)
In-Reply-To: <169BCCE38BFCC61F.3513@groups.io>
HI Gerd
I apologize for the mistake on name.
I should call you Gerd, not Greg.
Thank you
Yao Jiewen
> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Yao, Jiewen
> Sent: Monday, August 16, 2021 9:36 PM
> To: devel@edk2.groups.io; kraxel@redhat.com
> Cc: Philippe Mathieu-Daude <philmd@redhat.com>
> Subject: Re: [edk2-devel] [PATCH v2 2/4] OvmfPkg/VirtioMmioDeviceLib: Add
> virtio 1.0 support.
>
> Hi Greg
> Can we define MACRO to replace 1 or 2? That is very confusing.
>
> For example,
> #define VIRT_IO_DEVICE_VERSION_0_95 1
> #define VIRT_IO_DEVICE_VERSION_1_00 2
>
> Thank you
> Yao Jiewen
>
>
> > -----Original Message-----
> > From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Gerd
> > Hoffmann
> > Sent: Monday, August 16, 2021 3:11 PM
> > To: devel@edk2.groups.io
> > Cc: Gerd Hoffmann <kraxel@redhat.com>; Philippe Mathieu-Daude
> > <philmd@redhat.com>
> > Subject: [edk2-devel] [PATCH v2 2/4] OvmfPkg/VirtioMmioDeviceLib: Add
> virtio
> > 1.0 support.
> >
> > Add support for virtio 1.0 to the mmio transport. virtio 0.9.5 uses
> > page size, page frame number and a fixed layout for the ring. virtio
> > 1.0 uses the physical addresses for base address, used bits and
> > available bits instead.
> >
> > The ring layout is not changed, so a 0.9.5 compatible layout is used in
> > both 0.9.5 and 1.0 mode to to keep the code differences as small as
> > possible.
> >
> > Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> > Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com>
> > ---
> > .../VirtioMmioDeviceLib/VirtioMmioDevice.h | 1 +
> > .../VirtioMmioDeviceLib/VirtioMmioDevice.c | 17 +++++++---
> > .../VirtioMmioDeviceFunctions.c | 31 +++++++++++++++++--
> > 3 files changed, 42 insertions(+), 7 deletions(-)
> >
> > diff --git a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h
> > b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h
> > index ab53b90d51c9..8b19996b716f 100644
> > --- a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h
> > +++ b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h
> > @@ -26,6 +26,7 @@
> >
> > typedef struct {
> > UINT32 Signature;
> > + UINT32 Version;
> > VIRTIO_DEVICE_PROTOCOL VirtioDevice;
> > PHYSICAL_ADDRESS BaseAddress;
> > } VIRTIO_MMIO_DEVICE;
> > diff --git a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.c
> > b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.c
> > index 6dbbba008c75..a8f78a50861b 100644
> > --- a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.c
> > +++ b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.c
> > @@ -58,7 +58,6 @@ VirtioMmioInit (
> > )
> > {
> > UINT32 MagicValue;
> > - UINT32 Version;
> >
> > //
> > // Initialize VirtIo Mmio Device
> > @@ -66,7 +65,6 @@ VirtioMmioInit (
> > CopyMem (&Device->VirtioDevice, &mMmioDeviceProtocolTemplate,
> > sizeof (VIRTIO_DEVICE_PROTOCOL));
> > Device->BaseAddress = BaseAddress;
> > - Device->VirtioDevice.Revision = VIRTIO_SPEC_REVISION (0, 9, 5);
> > Device->VirtioDevice.SubSystemDeviceId =
> > MmioRead32 (BaseAddress + VIRTIO_MMIO_OFFSET_DEVICE_ID);
> >
> > @@ -78,8 +76,19 @@ VirtioMmioInit (
> > return EFI_UNSUPPORTED;
> > }
> >
> > - Version = VIRTIO_CFG_READ (Device, VIRTIO_MMIO_OFFSET_VERSION);
> > - if (Version != 1) {
> > + Device->Version = VIRTIO_CFG_READ (Device,
> > VIRTIO_MMIO_OFFSET_VERSION);
> > + switch (Device->Version) {
> > + case 1:
> > + DEBUG ((DEBUG_INFO, "%a virtio 0.9.5, id %d\n", __FUNCTION__,
> > + Device->VirtioDevice.SubSystemDeviceId));
> > + Device->VirtioDevice.Revision = VIRTIO_SPEC_REVISION (0, 9, 5);
> > + break;
> > + case 2:
> > + DEBUG ((DEBUG_INFO, "%a virtio 1.0, id %d\n", __FUNCTION__,
> > + Device->VirtioDevice.SubSystemDeviceId));
> > + Device->VirtioDevice.Revision = VIRTIO_SPEC_REVISION (1, 0, 0);
> > + break;
> > + default:
> > return EFI_UNSUPPORTED;
> > }
> >
> > diff --git
> a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c
> > b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c
> > index b0d75fb1dd24..bf8523a6fb3b 100644
> > --- a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c
> > +++ b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c
> > @@ -151,7 +151,9 @@ VirtioMmioSetPageSize (
> >
> > Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
> >
> > - VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_GUEST_PAGE_SIZE,
> > PageSize);
> > + if (Device->Version == 1) {
> > + VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_GUEST_PAGE_SIZE,
> > PageSize);
> > + }
> >
> > return EFI_SUCCESS;
> > }
> > @@ -181,13 +183,36 @@ VirtioMmioSetQueueAddress (
> > )
> > {
> > VIRTIO_MMIO_DEVICE *Device;
> > + UINT64 Address;
> >
> > ASSERT (RingBaseShift == 0);
> >
> > Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This);
> >
> > - VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_PFN,
> > - (UINT32)((UINTN)Ring->Base >> EFI_PAGE_SHIFT));
> > + if (Device->Version == 1) {
> > + VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_PFN,
> > + (UINT32)((UINTN)Ring->Base >> EFI_PAGE_SHIFT));
> > + } else {
> > + Address = (UINT64)Ring->Base;
> > + VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_DESC_LO,
> > + (UINT32)Address);
> > + VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_DESC_HI,
> > + (UINT32)RShiftU64(Address, 32));
> > +
> > + Address = (UINT64)Ring->Avail.Flags;
> > + VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_AVAIL_LO,
> > + (UINT32)Address);
> > + VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_AVAIL_HI,
> > + (UINT32)RShiftU64(Address, 32));
> > +
> > + Address = (UINT64)Ring->Used.Flags;
> > + VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_USED_LO,
> > + (UINT32)Address);
> > + VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_USED_HI,
> > + (UINT32)RShiftU64(Address, 32));
> > +
> > + VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_READY, 1);
> > + }
> >
> > return EFI_SUCCESS;
> > }
> > --
> > 2.31.1
> >
> >
> >
> >
> >
>
>
>
>
>
next prev parent reply other threads:[~2021-08-16 13:37 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-16 7:11 [PATCH v2 0/4] add support for virtio-mmio 1.0 Gerd Hoffmann
2021-08-16 7:11 ` [PATCH v2 1/4] OvmfPkg/Virtio10: Add virtio-mmio 1.0 defines Gerd Hoffmann
2021-08-16 7:11 ` [PATCH v2 2/4] OvmfPkg/VirtioMmioDeviceLib: Add virtio 1.0 support Gerd Hoffmann
2021-08-16 13:35 ` [edk2-devel] " Yao, Jiewen
2021-08-16 16:04 ` Philippe Mathieu-Daudé
[not found] ` <169BCCE38BFCC61F.3513@groups.io>
2021-08-16 13:37 ` Yao, Jiewen [this message]
2021-08-16 7:11 ` [PATCH v2 3/4] OvmfPkg/VirtioMmioDeviceLib: Add default QueueNum for virtio 1.0 Gerd Hoffmann
2021-08-16 7:11 ` [PATCH v2 4/4] OvmfPkg/VirtioMmioDeviceLib: Add virtio 1.0 feature bit handling Gerd Hoffmann
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-list 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=PH0PR11MB4885C536145E21992FC7FF348CFD9@PH0PR11MB4885.namprd11.prod.outlook.com \
--to=devel@edk2.groups.io \
/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