From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=66.187.233.73; helo=mx1.redhat.com; envelope-from=kraxel@redhat.com; receiver=edk2-devel@lists.01.org Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 5646A226612B8 for ; Wed, 25 Apr 2018 05:13:24 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 929CC4022414 for ; Wed, 25 Apr 2018 12:13:23 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-113.ams2.redhat.com [10.36.116.113]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6CE98215CDCB; Wed, 25 Apr 2018 12:13:22 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id C03181752E; Wed, 25 Apr 2018 14:13:21 +0200 (CEST) From: Gerd Hoffmann To: edk2-devel@lists.01.org Date: Wed, 25 Apr 2018 14:13:12 +0200 Message-Id: <20180425121312.26424-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 25 Apr 2018 12:13:23 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 25 Apr 2018 12:13:23 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kraxel@redhat.com' RCPT:'' Subject: [PATCH] Add QemuIGDHelperDxe X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Apr 2018 12:13:24 -0000 Little driver to setup the OpRegion for Intel vgpu devices. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Gerd Hoffmann --- OvmfPkg/QemuIGDHelperDxe/QemuIGDHelper.c | 262 ++++++++++++++++++++++++++ OvmfPkg/OvmfPkgIa32.dsc | 1 + OvmfPkg/OvmfPkgIa32.fdf | 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 1 + OvmfPkg/OvmfPkgIa32X64.fdf | 1 + OvmfPkg/OvmfPkgX64.dsc | 1 + OvmfPkg/OvmfPkgX64.fdf | 1 + OvmfPkg/QemuIGDHelperDxe/QemuIGDHelperDxe.inf | 32 ++++ 8 files changed, 300 insertions(+) create mode 100644 OvmfPkg/QemuIGDHelperDxe/QemuIGDHelper.c create mode 100644 OvmfPkg/QemuIGDHelperDxe/QemuIGDHelperDxe.inf diff --git a/OvmfPkg/QemuIGDHelperDxe/QemuIGDHelper.c b/OvmfPkg/QemuIGDHelperDxe/QemuIGDHelper.c new file mode 100644 index 0000000000..f314049bb4 --- /dev/null +++ b/OvmfPkg/QemuIGDHelperDxe/QemuIGDHelper.c @@ -0,0 +1,262 @@ +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +VOID *QemuIGDHelperOpRegion; + +EFI_STATUS +EFIAPI +QemuIGDHelperControllerDriverSupported ( + IN EFI_DRIVER_BINDING_PROTOCOL *This, + IN EFI_HANDLE Controller, + IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath + ) +{ + EFI_STATUS Status; + EFI_PCI_IO_PROTOCOL *PciIo; + PCI_TYPE00 Pci; + UINT32 OpRegion; + + Status = gBS->OpenProtocol ( + Controller, + &gEfiPciIoProtocolGuid, + (VOID **) &PciIo, + This->DriverBindingHandle, + Controller, + EFI_OPEN_PROTOCOL_BY_DRIVER + ); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = PciIo->Pci.Read ( + PciIo, + EfiPciIoWidthUint32, + 0, + sizeof (Pci) / sizeof (UINT32), + &Pci + ); + if (EFI_ERROR (Status)) { + goto Done; + } + + Status = EFI_UNSUPPORTED; + if (!IS_PCI_VGA (&Pci)) { + goto Done; + } + if (Pci.Hdr.VendorId != 0x8086 /* Intel */) { + goto Done; + } + + DEBUG ((EFI_D_INFO, "IGDHelper: intel gfx %x:%x found\n", + Pci.Hdr.VendorId, Pci.Hdr.DeviceId)); + OpRegion = (UINTN)QemuIGDHelperOpRegion; + Status = PciIo->Pci.Write ( + PciIo, + EfiPciIoWidthUint32, + 0xFC, + 1, + &OpRegion + ); + if (EFI_ERROR (Status)) { + DEBUG ((EFI_D_INFO, "IGDHelper: write error: %d\n", Status)); + } else { + DEBUG ((EFI_D_INFO, "IGDHelper: opregion setup OK\n")); + } + +Done: + gBS->CloseProtocol ( + Controller, + &gEfiPciIoProtocolGuid, + This->DriverBindingHandle, + Controller + ); + + return Status; +} + +EFI_STATUS +EFIAPI +QemuIGDHelperControllerDriverStart ( + IN EFI_DRIVER_BINDING_PROTOCOL *This, + IN EFI_HANDLE Controller, + IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath + ) +{ + DEBUG ((EFI_D_INFO, "QemuIGDHelperControllerDriverStart\n")); + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +QemuIGDHelperControllerDriverStop ( + IN EFI_DRIVER_BINDING_PROTOCOL *This, + IN EFI_HANDLE Controller, + IN UINTN NumberOfChildren, + IN EFI_HANDLE *ChildHandleBuffer + ) +{ + DEBUG ((EFI_D_INFO, "QemuIGDHelperControllerDriverStop\n")); + return EFI_SUCCESS; +} + +EFI_DRIVER_BINDING_PROTOCOL gQemuIGDHelperDriverBinding = { + QemuIGDHelperControllerDriverSupported, + QemuIGDHelperControllerDriverStart, + QemuIGDHelperControllerDriverStop, + 0x10, + NULL, + NULL +}; + +EFI_STATUS +EFIAPI +QemuIGDHelperComponentNameGetDriverName ( + IN EFI_COMPONENT_NAME_PROTOCOL *This, + IN CHAR8 *Language, + OUT CHAR16 **DriverName + ); + +EFI_STATUS +EFIAPI +QemuIGDHelperComponentNameGetControllerName ( + IN EFI_COMPONENT_NAME_PROTOCOL *This, + IN EFI_HANDLE ControllerHandle, + IN EFI_HANDLE ChildHandle OPTIONAL, + IN CHAR8 *Language, + OUT CHAR16 **ControllerName + ); + +EFI_UNICODE_STRING_TABLE mQemuIGDHelperDriverNameTable[] = { + { "eng;en", L"QEMU IGD Helper" }, + { NULL , NULL } +}; + +EFI_UNICODE_STRING_TABLE mQemuIGDHelperControllerNameTable[] = { + { "eng;en", L"IGD" }, + { NULL , NULL } +}; + +EFI_COMPONENT_NAME_PROTOCOL gQemuIGDHelperComponentName = { + QemuIGDHelperComponentNameGetDriverName, + QemuIGDHelperComponentNameGetControllerName, + "eng" +}; + +EFI_COMPONENT_NAME2_PROTOCOL gQemuIGDHelperComponentName2 = { + (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) QemuIGDHelperComponentNameGetDriverName, + (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) QemuIGDHelperComponentNameGetControllerName, + "en" +}; + +EFI_STATUS +EFIAPI +QemuIGDHelperComponentNameGetDriverName ( + IN EFI_COMPONENT_NAME_PROTOCOL *This, + IN CHAR8 *Language, + OUT CHAR16 **DriverName + ) +{ + return LookupUnicodeString2 ( + Language, + This->SupportedLanguages, + mQemuIGDHelperDriverNameTable, + DriverName, + (BOOLEAN)(This == &gQemuIGDHelperComponentName) + ); +} + +EFI_STATUS +EFIAPI +QemuIGDHelperComponentNameGetControllerName ( + IN EFI_COMPONENT_NAME_PROTOCOL *This, + IN EFI_HANDLE ControllerHandle, + IN EFI_HANDLE ChildHandle OPTIONAL, + IN CHAR8 *Language, + OUT CHAR16 **ControllerName + ) +{ + EFI_STATUS Status; + + if (ChildHandle != NULL) { + return EFI_UNSUPPORTED; + } + + Status = EfiTestManagedDevice ( + ControllerHandle, + gQemuIGDHelperDriverBinding.DriverBindingHandle, + &gEfiPciIoProtocolGuid + ); + if (EFI_ERROR (Status)) { + return Status; + } + + return LookupUnicodeString2 ( + Language, + This->SupportedLanguages, + mQemuIGDHelperControllerNameTable, + ControllerName, + (BOOLEAN)(This == &gQemuIGDHelperComponentName) + ); +} + +EFI_STATUS +EFIAPI +InitializeQemuIGDHelper ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + RETURN_STATUS Ret; + FIRMWARE_CONFIG_ITEM Item; + UINTN Size,Pages; + + DEBUG ((EFI_D_INFO, "InitializeQemuIGDHelper\n")); + + if (!QemuFwCfgIsAvailable()) { + DEBUG ((EFI_D_INFO, "IGDHelper: no FwCfg\n")); + return EFI_NOT_FOUND; + } + + Ret = QemuFwCfgFindFile("etc/igd-opregion", &Item, &Size); + if (Ret != RETURN_SUCCESS) { + DEBUG ((EFI_D_INFO, "IGDHelper: no etc/igd-opregion in FwCfg\n")); + return EFI_NOT_FOUND; + } + + Pages = (Size + EFI_PAGE_SIZE - 1) / EFI_PAGE_SIZE; + DEBUG ((EFI_D_INFO, "IGDHelper: opregion: fwcfg entry %d, size %d (%d pages)\n", + Item, Size, Pages)); + + QemuIGDHelperOpRegion = AllocateRuntimePages(Pages); + QemuFwCfgSelectItem(Item); + QemuFwCfgReadBytes(Size, QemuIGDHelperOpRegion); + DEBUG ((EFI_D_INFO, "IGDHelper: opregion: allocated at %p\n", + QemuIGDHelperOpRegion)); + + Status = EfiLibInstallDriverBindingComponentName2 ( + ImageHandle, + SystemTable, + &gQemuIGDHelperDriverBinding, + ImageHandle, + &gQemuIGDHelperComponentName, + &gQemuIGDHelperComponentName2 + ); + ASSERT_EFI_ERROR (Status); + + return Status; +} diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index 2d6c4c4615..16adbf2cff 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -740,6 +740,7 @@ MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.inf OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf + OvmfPkg/QemuIGDHelperDxe/QemuIGDHelperDxe.inf OvmfPkg/VirtioGpuDxe/VirtioGpu.inf # diff --git a/OvmfPkg/OvmfPkgIa32.fdf b/OvmfPkg/OvmfPkgIa32.fdf index 0427ded492..7df5fd47d3 100644 --- a/OvmfPkg/OvmfPkgIa32.fdf +++ b/OvmfPkg/OvmfPkgIa32.fdf @@ -351,6 +351,7 @@ INF RuleOverride=CSM OvmfPkg/Csm/Csm16/Csm16.inf !endif INF OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf +INF OvmfPkg/QemuIGDHelperDxe/QemuIGDHelperDxe.inf INF OvmfPkg/VirtioGpuDxe/VirtioGpu.inf INF OvmfPkg/PlatformDxe/Platform.inf INF OvmfPkg/IoMmuDxe/IoMmuDxe.inf diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index 43158c5f06..dfa25ad056 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -749,6 +749,7 @@ MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.inf OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf + OvmfPkg/QemuIGDHelperDxe/QemuIGDHelperDxe.inf OvmfPkg/VirtioGpuDxe/VirtioGpu.inf # diff --git a/OvmfPkg/OvmfPkgIa32X64.fdf b/OvmfPkg/OvmfPkgIa32X64.fdf index 6df47f48cd..c5e77f4298 100644 --- a/OvmfPkg/OvmfPkgIa32X64.fdf +++ b/OvmfPkg/OvmfPkgIa32X64.fdf @@ -357,6 +357,7 @@ INF RuleOverride=CSM OvmfPkg/Csm/Csm16/Csm16.inf !endif INF OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf +INF OvmfPkg/QemuIGDHelperDxe/QemuIGDHelperDxe.inf INF OvmfPkg/VirtioGpuDxe/VirtioGpu.inf INF OvmfPkg/PlatformDxe/Platform.inf INF OvmfPkg/AmdSevDxe/AmdSevDxe.inf diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index d1fdf7c307..72fac3429a 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -747,6 +747,7 @@ MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.inf OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf + OvmfPkg/QemuIGDHelperDxe/QemuIGDHelperDxe.inf OvmfPkg/VirtioGpuDxe/VirtioGpu.inf # diff --git a/OvmfPkg/OvmfPkgX64.fdf b/OvmfPkg/OvmfPkgX64.fdf index 2e2a1749b5..5e3ce00f8e 100644 --- a/OvmfPkg/OvmfPkgX64.fdf +++ b/OvmfPkg/OvmfPkgX64.fdf @@ -357,6 +357,7 @@ INF RuleOverride=CSM OvmfPkg/Csm/Csm16/Csm16.inf !endif INF OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf +INF OvmfPkg/QemuIGDHelperDxe/QemuIGDHelperDxe.inf INF OvmfPkg/VirtioGpuDxe/VirtioGpu.inf INF OvmfPkg/PlatformDxe/Platform.inf INF OvmfPkg/AmdSevDxe/AmdSevDxe.inf diff --git a/OvmfPkg/QemuIGDHelperDxe/QemuIGDHelperDxe.inf b/OvmfPkg/QemuIGDHelperDxe/QemuIGDHelperDxe.inf new file mode 100644 index 0000000000..9d6c8200ce --- /dev/null +++ b/OvmfPkg/QemuIGDHelperDxe/QemuIGDHelperDxe.inf @@ -0,0 +1,32 @@ +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = QemuIGDHelperDxe + FILE_GUID = 26a95470-bc51-4f40-9dc6-f33af3321b25 + MODULE_TYPE = UEFI_DRIVER + VERSION_STRING = 1.0 + + ENTRY_POINT = InitializeQemuIGDHelper + +[Sources.common] + QemuIGDHelper.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + OvmfPkg/OvmfPkg.dec + +[LibraryClasses] + BaseMemoryLib + DebugLib + DevicePathLib + MemoryAllocationLib + PcdLib + PciLib + UefiBootManagerLib + UefiBootServicesTableLib + UefiDriverEntryPoint + UefiLib + QemuFwCfgLib + +[Protocols] + gEfiPciIoProtocolGuid # PROTOCOL TO_START -- 2.9.3