A bus driver is allowed to ignore the actual value of RemainingDevicePath
in Supported() and Start(), and to produce all child handles at once.

This in effect means the following invariants for QemuVideoDxe:
- (RemainingDevicePath == NULL), and
- (Private->GopDevicePath != NULL)

Simplify Supported() and Start() by substituting constant TRUE and FALSE
(as appropriate) in expressions that check RemainingDevicePath and/or
Private->GopDevicePath.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <ler...@redhat.com>
---
 OvmfPkg/QemuVideoDxe/Driver.c | 108 +++++++++---------------------------------
 1 file changed, 23 insertions(+), 85 deletions(-)

diff --git a/OvmfPkg/QemuVideoDxe/Driver.c b/OvmfPkg/QemuVideoDxe/Driver.c
index b1105f4..ab3afae 100644
--- a/OvmfPkg/QemuVideoDxe/Driver.c
+++ b/OvmfPkg/QemuVideoDxe/Driver.c
@@ -97,7 +97,6 @@ QemuVideoControllerDriverSupported (
   EFI_STATUS          Status;
   EFI_PCI_IO_PROTOCOL *PciIo;
   PCI_TYPE00          Pci;
-  EFI_DEV_PATH        *Node;
   QEMU_VIDEO_CARD     *Card;
 
   //
@@ -130,40 +129,10 @@ QemuVideoControllerDriverSupported (
   }
 
   Status = EFI_UNSUPPORTED;
-  //
-  // See if the I/O enable is on.  Most systems only allow one VGA device to 
be turned on
-  // at a time, so see if this is one that is turned on.
-  //
-  //  if (((Pci.Hdr.Command & 0x01) == 0x01)) {
-  //
-  // See if this is a Cirrus Logic PCI controller
-  //
   Card = QemuVideoDetect(Pci.Hdr.VendorId, Pci.Hdr.DeviceId);
   if (Card != NULL) {
     DEBUG ((EFI_D_INFO, "QemuVideo: %s detected\n", Card->Name));
     Status = EFI_SUCCESS;
-    //
-    // If this is an Intel 945 graphics controller,
-    // go further check RemainingDevicePath validation
-    //
-    if (RemainingDevicePath != NULL) {
-      Node = (EFI_DEV_PATH *) RemainingDevicePath;
-      //
-      // Check if RemainingDevicePath is the End of Device Path Node, 
-      // if yes, return EFI_SUCCESS
-      //
-      if (!IsDevicePathEnd (Node)) {
-        //
-        // If RemainingDevicePath isn't the End of Device Path Node,
-        // check its validation
-        //
-        if (Node->DevPath.Type != ACPI_DEVICE_PATH ||
-            Node->DevPath.SubType != ACPI_ADR_DP ||
-            DevicePathNodeLength(&Node->DevPath) != 
sizeof(ACPI_ADR_DEVICE_PATH)) {
-          Status = EFI_UNSUPPORTED;
-        }
-      }
-    }
   }
 
 Done:
@@ -204,6 +173,7 @@ QemuVideoControllerDriverStart (
   EFI_STATUS                        Status;
   QEMU_VIDEO_PRIVATE_DATA           *Private;
   EFI_DEVICE_PATH_PROTOCOL          *ParentDevicePath;
+  ACPI_ADR_DEVICE_PATH              AcpiDeviceNode;
   PCI_TYPE00                        Pci;
   QEMU_VIDEO_CARD                   *Card;
   EFI_PCI_IO_PROTOCOL               *ChildPciIo;
@@ -342,50 +312,32 @@ QemuVideoControllerDriverStart (
   //
   // Set Gop Device Path
   //
-  if (RemainingDevicePath == NULL) {
-    ACPI_ADR_DEVICE_PATH AcpiDeviceNode;
+  ZeroMem (&AcpiDeviceNode, sizeof (ACPI_ADR_DEVICE_PATH));
+  AcpiDeviceNode.Header.Type = ACPI_DEVICE_PATH;
+  AcpiDeviceNode.Header.SubType = ACPI_ADR_DP;
+  AcpiDeviceNode.ADR = ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, 
ACPI_ADR_DISPLAY_TYPE_VGA, 0, 0);
+  SetDevicePathNodeLength (&AcpiDeviceNode.Header, sizeof 
(ACPI_ADR_DEVICE_PATH));
 
-    ZeroMem (&AcpiDeviceNode, sizeof (ACPI_ADR_DEVICE_PATH));
-    AcpiDeviceNode.Header.Type = ACPI_DEVICE_PATH;
-    AcpiDeviceNode.Header.SubType = ACPI_ADR_DP;
-    AcpiDeviceNode.ADR = ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, 
ACPI_ADR_DISPLAY_TYPE_VGA, 0, 0);
-    SetDevicePathNodeLength (&AcpiDeviceNode.Header, sizeof 
(ACPI_ADR_DEVICE_PATH));
-
-    Private->GopDevicePath = AppendDevicePathNode (
-                                        ParentDevicePath,
-                                        (EFI_DEVICE_PATH_PROTOCOL *) 
&AcpiDeviceNode
-                                        );
-    if (Private->GopDevicePath == NULL) {
-      Status = EFI_OUT_OF_RESOURCES;
-      goto RestoreAttributes;
-    }
-  } else if (!IsDevicePathEnd (RemainingDevicePath)) {
-    //
-    // If RemainingDevicePath isn't the End of Device Path Node, 
-    // only scan the specified device by RemainingDevicePath
-    //
-    Private->GopDevicePath = AppendDevicePathNode (ParentDevicePath, 
RemainingDevicePath);
-    if (Private->GopDevicePath == NULL) {
-      Status = EFI_OUT_OF_RESOURCES;
-      goto RestoreAttributes;
-    }
+  Private->GopDevicePath = AppendDevicePathNode (
+                                      ParentDevicePath,
+                                      (EFI_DEVICE_PATH_PROTOCOL *) 
&AcpiDeviceNode
+                                      );
+  if (Private->GopDevicePath == NULL) {
+    Status = EFI_OUT_OF_RESOURCES;
+    goto RestoreAttributes;
   }
 
   //
-  // Create new child handle and install the device path protocol on it only if
-  // RemainingDevicePath equals NULL, or doesn't point to the End of Device
-  // Path Node.
+  // Create new child handle and install the device path protocol on it.
   //
-  if (Private->GopDevicePath != NULL) {
-    Status = gBS->InstallMultipleProtocolInterfaces (
-                    &Private->Handle,
-                    &gEfiDevicePathProtocolGuid,
-                    Private->GopDevicePath,
-                    NULL
-                    );
-    if (EFI_ERROR (Status)) {
-      goto FreeGopDevicePath;
-    }
+  Status = gBS->InstallMultipleProtocolInterfaces (
+                  &Private->Handle,
+                  &gEfiDevicePathProtocolGuid,
+                  Private->GopDevicePath,
+                  NULL
+                  );
+  if (EFI_ERROR (Status)) {
+    goto FreeGopDevicePath;
   }
 
   //
@@ -410,14 +362,6 @@ QemuVideoControllerDriverStart (
   }
 
   //
-  // If RemainingDevicePath points to the End of Device Path Node, then we
-  // haven't created a child handle, and we're done.
-  //
-  if (Private->GopDevicePath == NULL) {
-    return EFI_SUCCESS;
-  }
-
-  //
   // Start the GOP software stack.
   //
   Status = QemuVideoGraphicsOutputConstructor (Private);
@@ -473,17 +417,11 @@ FreeModeData:
   FreePool (Private->ModeData);
 
 UninstallGopDevicePath:
-  //
-  // Handles the case transparently when Private->Handle and
-  // Private->GopDevicePath are NULL.
-  //
   gBS->UninstallProtocolInterface (Private->Handle,
          &gEfiDevicePathProtocolGuid, Private->GopDevicePath);
 
 FreeGopDevicePath:
-  if (Private->GopDevicePath != NULL) {
-    FreePool (Private->GopDevicePath);
-  }
+  FreePool (Private->GopDevicePath);
 
 RestoreAttributes:
   Private->PciIo->Attributes (Private->PciIo, EfiPciIoAttributeOperationSet,
-- 
1.8.3.1



------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to