public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Laszlo Ersek" <lersek@redhat.com>
To: David Woodhouse <dwmw2@infradead.org>, devel@edk2.groups.io
Cc: Ray Ni <ray.ni@intel.com>
Subject: Re: [PATCH v2 6/7] MdeModulePkg/UefiBootManagerLib: describe VirtIO devices correctly
Date: Tue, 25 Jun 2019 15:44:56 +0200	[thread overview]
Message-ID: <4936db7b-242a-b125-46fa-cde763306008@redhat.com> (raw)
In-Reply-To: <20190625114859.795331-6-dwmw2@infradead.org>

On 06/25/19 13:48, David Woodhouse wrote:
> I know, I said it was Someone Else's Problem. But it annoyed me.
> 
> My initial thought was to look for VIRTIO_DEVICE_PROTOCOL on the same
> handle but I don't think I can do that if I can't rely on VirtIO being
> present in the build. This will do.
> 
> Signed-off-by: David Woodhouse <dwmw2@infradead.org>
> ---
>  .../UefiBootManagerLib/BmBootDescription.c    | 34 +++++++++++++++++--
>  1 file changed, 32 insertions(+), 2 deletions(-)
> 
> diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmBootDescription.c b/MdeModulePkg/Library/UefiBootManagerLib/BmBootDescription.c
> index 06edba8b4d..95adb9a7d3 100644
> --- a/MdeModulePkg/Library/UefiBootManagerLib/BmBootDescription.c
> +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmBootDescription.c
> @@ -661,6 +661,8 @@ BmGetMiscDescription (
>    CHAR16                          *Description;
>    EFI_BLOCK_IO_PROTOCOL           *BlockIo;
>    EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Fs;
> +  EFI_PCI_IO_PROTOCOL             *PciIo;
> +  PCI_TYPE00                      Pci;
>  
>    switch (BmDevicePathType (DevicePathFromHandle (Handle))) {
>    case BmAcpiFloppyBoot:
> @@ -698,9 +700,37 @@ BmGetMiscDescription (
>      Status = gBS->HandleProtocol (Handle, &gEfiSimpleFileSystemProtocolGuid, (VOID **) &Fs);
>      if (!EFI_ERROR (Status)) {
>        Description = L"Non-Block Boot Device";
> -    } else {
> -      Description = L"Misc Device";
> +      break;
> +    }
> +    Status = gBS->HandleProtocol (Handle, &gEfiPciIoProtocolGuid, (VOID **) &PciIo);
> +    if (!EFI_ERROR (Status)) {
> +      Status = PciIo->Pci.Read (
> +                            PciIo,                        // (protocol, device)
> +                                                          // handle
> +                            EfiPciIoWidthUint32,          // access width & copy
> +                                                          // mode
> +                            0,                            // Offset
> +                            sizeof Pci / sizeof (UINT32), // Count
> +                            &Pci                          // target buffer
> +                            );
> +      //
> +      // If the same node is a Qumranet/Red Hat PCI device, it's VirtIO.
> +      //
> +      if (!EFI_ERROR (Status) && (Pci.Hdr.VendorId == 0x1AF4))
> +        //
> +        // Separate checks for legacy/transitional VirtIO vs. Virtio 1.0+
> +        //
> +        if (((Pci.Hdr.DeviceId >= 0x1000) && (Pci.Hdr.DeviceId <= 0x103F) &&
> +             (Pci.Hdr.RevisionID == 0x00)) ||
> +            (Pci.Hdr.DeviceId >= 0x1040 && Pci.Hdr.DeviceId <= 0x107F &&
> +             Pci.Hdr.RevisionID >= 0x01 && Pci.Device.SubsystemID >= 0x40 &&
> +             (Pci.Hdr.Status & EFI_PCI_STATUS_CAPABILITY) != 0)) {
> +        Description = L"VirtIO Device";
> +        break;
> +      }

This code is functionally correct, but there are two syntactical issues
with it.

(1) The last three lines -- the assignment to Description, the break
statement, and the closing brace -- should be indented one level more
deeply.

(2) Which in turn shows that the "if" statement that checks "Status" and
"VendorId" lacks an opening brace. The brace is required by the edk2
coding style.

>      }
> +
> +    Description = L"Misc Device";
>      break;
>    }
>  
> 

With those fixed:

Reviewed-by: Laszlo Ersek <lersek@redhat.com>

Thanks
Laszlo

  reply	other threads:[~2019-06-25 13:45 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-25 11:48 [PATCH v2 1/7] OvmfPkg/LegacyBios: set NumberBbsEntries to the size of BbsTable David Woodhouse
2019-06-25 11:48 ` [PATCH v2 2/7] OvmfPkg/LegacyBbs: Add boot entries for VirtIO and NVME devices David Woodhouse
2019-06-25 11:48 ` [PATCH v2 3/7] OvmfPkg: Don't build in QemuVideoDxe when we have CSM David Woodhouse
2019-06-25 11:48 ` [PATCH v2 4/7] MdeModulePkg/UefiBootManagerLib: export EfiBootManagerGetBootDescription() David Woodhouse
2019-06-27  2:12   ` [edk2-devel] " Ni, Ray
2019-06-25 11:48 ` [PATCH v2 5/7] OvmfPkg/LegacyBiosDxe: Use EfiBootManagerGetBootDescription() David Woodhouse
2019-06-25 13:29   ` Laszlo Ersek
2019-06-25 14:10     ` [edk2-devel] " David Woodhouse
2019-06-25 19:16       ` Laszlo Ersek
2019-06-25 11:48 ` [PATCH v2 6/7] MdeModulePkg/UefiBootManagerLib: describe VirtIO devices correctly David Woodhouse
2019-06-25 13:44   ` Laszlo Ersek [this message]
2019-06-25 11:48 ` [PATCH v2 7/7] OvmfPkg: don't assign PCI BARs above 4GiB when CSM enabled David Woodhouse
2019-06-25 13:47   ` Laszlo Ersek

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=4936db7b-242a-b125-46fa-cde763306008@redhat.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