]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OvmfPkg/QemuVideoDxe/Driver.c
ArmPlatformPkg: fix undefined reference to memcpy
[mirror_edk2.git] / OvmfPkg / QemuVideoDxe / Driver.c
index 1dd8899fcf8c0b10a32b61f629bcc8b7dd5be74c..17bd4cc2ccc3af88311a2f261f39967fab8a13ce 100644 (file)
@@ -97,7 +97,6 @@ QemuVideoControllerDriverSupported (
   EFI_STATUS          Status;\r
   EFI_PCI_IO_PROTOCOL *PciIo;\r
   PCI_TYPE00          Pci;\r
-  EFI_DEV_PATH        *Node;\r
   QEMU_VIDEO_CARD     *Card;\r
 \r
   //\r
@@ -130,40 +129,10 @@ QemuVideoControllerDriverSupported (
   }\r
 \r
   Status = EFI_UNSUPPORTED;\r
-  //\r
-  // See if the I/O enable is on.  Most systems only allow one VGA device to be turned on\r
-  // at a time, so see if this is one that is turned on.\r
-  //\r
-  //  if (((Pci.Hdr.Command & 0x01) == 0x01)) {\r
-  //\r
-  // See if this is a Cirrus Logic PCI controller\r
-  //\r
   Card = QemuVideoDetect(Pci.Hdr.VendorId, Pci.Hdr.DeviceId);\r
   if (Card != NULL) {\r
     DEBUG ((EFI_D_INFO, "QemuVideo: %s detected\n", Card->Name));\r
     Status = EFI_SUCCESS;\r
-    //\r
-    // If this is an Intel 945 graphics controller,\r
-    // go further check RemainingDevicePath validation\r
-    //\r
-    if (RemainingDevicePath != NULL) {\r
-      Node = (EFI_DEV_PATH *) RemainingDevicePath;\r
-      //\r
-      // Check if RemainingDevicePath is the End of Device Path Node, \r
-      // if yes, return EFI_SUCCESS\r
-      //\r
-      if (!IsDevicePathEnd (Node)) {\r
-        //\r
-        // If RemainingDevicePath isn't the End of Device Path Node,\r
-        // check its validation\r
-        //\r
-        if (Node->DevPath.Type != ACPI_DEVICE_PATH ||\r
-            Node->DevPath.SubType != ACPI_ADR_DP ||\r
-            DevicePathNodeLength(&Node->DevPath) != sizeof(ACPI_ADR_DEVICE_PATH)) {\r
-          Status = EFI_UNSUPPORTED;\r
-        }\r
-      }\r
-    }\r
   }\r
 \r
 Done:\r
@@ -201,30 +170,31 @@ QemuVideoControllerDriverStart (
   IN EFI_DEVICE_PATH_PROTOCOL       *RemainingDevicePath\r
   )\r
 {\r
+  EFI_TPL                           OldTpl;\r
   EFI_STATUS                        Status;\r
   QEMU_VIDEO_PRIVATE_DATA           *Private;\r
-  BOOLEAN                           PciAttributesSaved;\r
+  BOOLEAN                           IsQxl;\r
   EFI_DEVICE_PATH_PROTOCOL          *ParentDevicePath;\r
   ACPI_ADR_DEVICE_PATH              AcpiDeviceNode;\r
   PCI_TYPE00                        Pci;\r
   QEMU_VIDEO_CARD                   *Card;\r
-  EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *MmioDesc;\r
+  EFI_PCI_IO_PROTOCOL               *ChildPciIo;\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
 \r
-  PciAttributesSaved = FALSE;\r
   //\r
   // Allocate Private context data for GOP inteface.\r
   //\r
   Private = AllocateZeroPool (sizeof (QEMU_VIDEO_PRIVATE_DATA));\r
   if (Private == NULL) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
-    goto Error;\r
+    goto RestoreTpl;\r
   }\r
 \r
   //\r
   // Set up context record\r
   //\r
   Private->Signature  = QEMU_VIDEO_PRIVATE_DATA_SIGNATURE;\r
-  Private->Handle     = NULL;\r
 \r
   //\r
   // Open PCI I/O Protocol\r
@@ -238,7 +208,7 @@ QemuVideoControllerDriverStart (
                   EFI_OPEN_PROTOCOL_BY_DRIVER\r
                   );\r
   if (EFI_ERROR (Status)) {\r
-    goto Error;\r
+    goto FreePrivate;\r
   }\r
 \r
   //\r
@@ -252,16 +222,25 @@ QemuVideoControllerDriverStart (
                         &Pci\r
                         );\r
   if (EFI_ERROR (Status)) {\r
-    goto Error;\r
+    goto ClosePciIo;\r
   }\r
 \r
+  //\r
+  // Determine card variant.\r
+  //\r
   Card = QemuVideoDetect(Pci.Hdr.VendorId, Pci.Hdr.DeviceId);\r
   if (Card == NULL) {\r
     Status = EFI_DEVICE_ERROR;\r
-    goto Error;\r
+    goto ClosePciIo;\r
   }\r
   Private->Variant = Card->Variant;\r
 \r
+  //\r
+  // IsQxl is based on the detected Card->Variant, which at a later point might\r
+  // not match Private->Variant.\r
+  //\r
+  IsQxl = (BOOLEAN)(Card->Variant == QEMU_VIDEO_BOCHS);\r
+\r
   //\r
   // Save original PCI attributes\r
   //\r
@@ -273,10 +252,12 @@ QemuVideoControllerDriverStart (
                     );\r
 \r
   if (EFI_ERROR (Status)) {\r
-    goto Error;\r
+    goto ClosePciIo;\r
   }\r
-  PciAttributesSaved = TRUE;\r
 \r
+  //\r
+  // Set new PCI attributes\r
+  //\r
   Status = Private->PciIo->Attributes (\r
                             Private->PciIo,\r
                             EfiPciIoAttributeOperationEnable,\r
@@ -284,13 +265,15 @@ QemuVideoControllerDriverStart (
                             NULL\r
                             );\r
   if (EFI_ERROR (Status)) {\r
-    goto Error;\r
+    goto ClosePciIo;\r
   }\r
 \r
   //\r
   // Check whenever the qemu stdvga mmio bar is present (qemu 1.3+).\r
   //\r
   if (Private->Variant == QEMU_VIDEO_BOCHS_MMIO) {\r
+    EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *MmioDesc;\r
+\r
     Status = Private->PciIo->GetBarAttributes (\r
                         Private->PciIo,\r
                         PCI_BAR_IDX2,\r
@@ -305,6 +288,10 @@ QemuVideoControllerDriverStart (
       DEBUG ((EFI_D_INFO, "QemuVideo: Using mmio bar @ 0x%lx\n",\r
               MmioDesc->AddrRangeMin));\r
     }\r
+\r
+    if (!EFI_ERROR (Status)) {\r
+      FreePool (MmioDesc);\r
+    }\r
   }\r
 \r
   //\r
@@ -317,7 +304,7 @@ QemuVideoControllerDriverStart (
     if ((BochsId & 0xFFF0) != VBE_DISPI_ID0) {\r
       DEBUG ((EFI_D_INFO, "QemuVideo: BochsID mismatch (got 0x%x)\n", BochsId));\r
       Status = EFI_DEVICE_ERROR;\r
-      goto Error;\r
+      goto RestoreAttributes;\r
     }\r
   }\r
 \r
@@ -330,48 +317,38 @@ QemuVideoControllerDriverStart (
                   (VOID **) &ParentDevicePath\r
                   );\r
   if (EFI_ERROR (Status)) {\r
-    goto Error;\r
+    goto RestoreAttributes;\r
   }\r
 \r
   //\r
   // Set Gop Device Path\r
   //\r
-  if (RemainingDevicePath == NULL) {\r
-    ZeroMem (&AcpiDeviceNode, sizeof (ACPI_ADR_DEVICE_PATH));\r
-    AcpiDeviceNode.Header.Type = ACPI_DEVICE_PATH;\r
-    AcpiDeviceNode.Header.SubType = ACPI_ADR_DP;\r
-    AcpiDeviceNode.ADR = ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_VGA, 0, 0);\r
-    SetDevicePathNodeLength (&AcpiDeviceNode.Header, sizeof (ACPI_ADR_DEVICE_PATH));\r
-\r
-    Private->GopDevicePath = AppendDevicePathNode (\r
-                                        ParentDevicePath,\r
-                                        (EFI_DEVICE_PATH_PROTOCOL *) &AcpiDeviceNode\r
-                                        );\r
-  } else if (!IsDevicePathEnd (RemainingDevicePath)) {\r
-    //\r
-    // If RemainingDevicePath isn't the End of Device Path Node, \r
-    // only scan the specified device by RemainingDevicePath\r
-    //\r
-    Private->GopDevicePath = AppendDevicePathNode (ParentDevicePath, RemainingDevicePath);\r
-  } else {\r
-    //\r
-    // If RemainingDevicePath is the End of Device Path Node, \r
-    // don't create child device and return EFI_SUCCESS\r
-    //\r
-    Private->GopDevicePath = NULL;\r
+  ZeroMem (&AcpiDeviceNode, sizeof (ACPI_ADR_DEVICE_PATH));\r
+  AcpiDeviceNode.Header.Type = ACPI_DEVICE_PATH;\r
+  AcpiDeviceNode.Header.SubType = ACPI_ADR_DP;\r
+  AcpiDeviceNode.ADR = ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_VGA, 0, 0);\r
+  SetDevicePathNodeLength (&AcpiDeviceNode.Header, sizeof (ACPI_ADR_DEVICE_PATH));\r
+\r
+  Private->GopDevicePath = AppendDevicePathNode (\r
+                                      ParentDevicePath,\r
+                                      (EFI_DEVICE_PATH_PROTOCOL *) &AcpiDeviceNode\r
+                                      );\r
+  if (Private->GopDevicePath == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto RestoreAttributes;\r
   }\r
-    \r
-  if (Private->GopDevicePath != NULL) {\r
-    //\r
-    // Creat child handle and device path protocol firstly\r
-    //\r
-    Private->Handle = NULL;\r
-    Status = gBS->InstallMultipleProtocolInterfaces (\r
-                    &Private->Handle,\r
-                    &gEfiDevicePathProtocolGuid,\r
-                    Private->GopDevicePath,\r
-                    NULL\r
-                    );\r
+\r
+  //\r
+  // Create new child handle and install the device path protocol on it.\r
+  //\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &Private->Handle,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  Private->GopDevicePath,\r
+                  NULL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    goto FreeGopDevicePath;\r
   }\r
 \r
   //\r
@@ -384,7 +361,7 @@ QemuVideoControllerDriverStart (
     break;\r
   case QEMU_VIDEO_BOCHS_MMIO:\r
   case QEMU_VIDEO_BOCHS:\r
-    Status = QemuVideoBochsModeSetup (Private);\r
+    Status = QemuVideoBochsModeSetup (Private, IsQxl);\r
     break;\r
   default:\r
     ASSERT (FALSE);\r
@@ -392,61 +369,81 @@ QemuVideoControllerDriverStart (
     break;\r
   }\r
   if (EFI_ERROR (Status)) {\r
-    goto Error;\r
+    goto UninstallGopDevicePath;\r
   }\r
 \r
-  if (Private->GopDevicePath == NULL) {\r
-    //\r
-    // If RemainingDevicePath is the End of Device Path Node, \r
-    // don't create child device and return EFI_SUCCESS\r
-    //\r
-    Status = EFI_SUCCESS;\r
-  } else {\r
-\r
-    //\r
-    // Start the GOP software stack.\r
-    //\r
-    Status = QemuVideoGraphicsOutputConstructor (Private);\r
-    ASSERT_EFI_ERROR (Status);\r
+  //\r
+  // Start the GOP software stack.\r
+  //\r
+  Status = QemuVideoGraphicsOutputConstructor (Private);\r
+  if (EFI_ERROR (Status)) {\r
+    goto FreeModeData;\r
+  }\r
 \r
-    Status = gBS->InstallMultipleProtocolInterfaces (\r
-                    &Private->Handle,\r
-                    &gEfiGraphicsOutputProtocolGuid,\r
-                    &Private->GraphicsOutput,\r
-                    NULL\r
-                    );\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &Private->Handle,\r
+                  &gEfiGraphicsOutputProtocolGuid,\r
+                  &Private->GraphicsOutput,\r
+                  NULL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    goto DestructQemuVideoGraphics;\r
   }\r
 \r
-Error:\r
+  //\r
+  // Reference parent handle from child handle.\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                Controller,\r
+                &gEfiPciIoProtocolGuid,\r
+                (VOID **) &ChildPciIo,\r
+                This->DriverBindingHandle,\r
+                Private->Handle,\r
+                EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
+                );\r
   if (EFI_ERROR (Status)) {\r
-    if (Private) {\r
-      if (Private->PciIo) {\r
-        if (PciAttributesSaved == TRUE) {\r
-          //\r
-          // Restore original PCI attributes\r
-          //\r
-          Private->PciIo->Attributes (\r
-                          Private->PciIo,\r
-                          EfiPciIoAttributeOperationSet,\r
-                          Private->OriginalPciAttributes,\r
-                          NULL\r
-                          );\r
-        }\r
-        //\r
-        // Close the PCI I/O Protocol\r
-        //\r
-        gBS->CloseProtocol (\r
-              Private->Handle,\r
-              &gEfiPciIoProtocolGuid,\r
-              This->DriverBindingHandle,\r
-              Private->Handle\r
-              );\r
-      }\r
+    goto UninstallGop;\r
+  }\r
 \r
-      gBS->FreePool (Private);\r
-    }\r
+  if (Private->Variant == QEMU_VIDEO_BOCHS_MMIO ||\r
+      Private->Variant == QEMU_VIDEO_BOCHS) {\r
+    InstallVbeShim (Card->Name, Private->GraphicsOutput.Mode->FrameBufferBase);\r
   }\r
 \r
+  gBS->RestoreTPL (OldTpl);\r
+  return EFI_SUCCESS;\r
+\r
+UninstallGop:\r
+  gBS->UninstallProtocolInterface (Private->Handle,\r
+         &gEfiGraphicsOutputProtocolGuid, &Private->GraphicsOutput);\r
+\r
+DestructQemuVideoGraphics:\r
+  QemuVideoGraphicsOutputDestructor (Private);\r
+\r
+FreeModeData:\r
+  FreePool (Private->ModeData);\r
+\r
+UninstallGopDevicePath:\r
+  gBS->UninstallProtocolInterface (Private->Handle,\r
+         &gEfiDevicePathProtocolGuid, Private->GopDevicePath);\r
+\r
+FreeGopDevicePath:\r
+  FreePool (Private->GopDevicePath);\r
+\r
+RestoreAttributes:\r
+  Private->PciIo->Attributes (Private->PciIo, EfiPciIoAttributeOperationSet,\r
+                    Private->OriginalPciAttributes, NULL);\r
+\r
+ClosePciIo:\r
+  gBS->CloseProtocol (Controller, &gEfiPciIoProtocolGuid,\r
+         This->DriverBindingHandle, Controller);\r
+\r
+FreePrivate:\r
+  FreePool (Private);\r
+\r
+RestoreTpl:\r
+  gBS->RestoreTPL (OldTpl);\r
+\r
   return Status;\r
 }\r
 \r
@@ -477,8 +474,26 @@ QemuVideoControllerDriverStop (
   EFI_STATUS                      Status;\r
   QEMU_VIDEO_PRIVATE_DATA  *Private;\r
 \r
+  if (NumberOfChildren == 0) {\r
+    //\r
+    // Close the PCI I/O Protocol\r
+    //\r
+    gBS->CloseProtocol (\r
+          Controller,\r
+          &gEfiPciIoProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          Controller\r
+          );\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  //\r
+  // free all resources for whose access we need the child handle, because the\r
+  // child handle is going away\r
+  //\r
+  ASSERT (NumberOfChildren == 1);\r
   Status = gBS->OpenProtocol (\r
-                  Controller,\r
+                  ChildHandleBuffer[0],\r
                   &gEfiGraphicsOutputProtocolGuid,\r
                   (VOID **) &GraphicsOutput,\r
                   This->DriverBindingHandle,\r
@@ -493,6 +508,7 @@ QemuVideoControllerDriverStop (
   // Get our private context information\r
   //\r
   Private = QEMU_VIDEO_PRIVATE_DATA_FROM_GRAPHICS_OUTPUT_THIS (GraphicsOutput);\r
+  ASSERT (Private->Handle == ChildHandleBuffer[0]);\r
 \r
   QemuVideoGraphicsOutputDestructor (Private);\r
   //\r
@@ -519,16 +535,18 @@ QemuVideoControllerDriverStop (
                   NULL\r
                   );\r
 \r
-  //\r
-  // Close the PCI I/O Protocol\r
-  //\r
   gBS->CloseProtocol (\r
         Controller,\r
         &gEfiPciIoProtocolGuid,\r
         This->DriverBindingHandle,\r
-        Controller\r
+        Private->Handle\r
         );\r
 \r
+  FreePool (Private->ModeData);\r
+  gBS->UninstallProtocolInterface (Private->Handle,\r
+         &gEfiDevicePathProtocolGuid, Private->GopDevicePath);\r
+  FreePool (Private->GopDevicePath);\r
+\r
   //\r
   // Free our instance data\r
   //\r