From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:4864:20::62d; helo=mail-pl1-x62d.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id E507C21148ED9 for ; Thu, 20 Sep 2018 16:01:54 -0700 (PDT) Received: by mail-pl1-x62d.google.com with SMTP id q5-v6so1552240pli.4 for ; Thu, 20 Sep 2018 16:01:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=NeNO2yxxJHj3+5x/STZPGsImoQ1uwGw7nU4vxibZh1E=; b=hw3KEiIQAtwAUw6COAW9iMWCMhxt1au+eseDQHZUXK1lQjC1u72zavK0KUn8I9SLtq uRI99faJcgbx6Pdv4CWKe5MgNpBkaktNlVxZ4ircVtxP/sxpPdR4mYnQPW8pppLWvt9x KL3u0EtrXZoBz4z5y9pXa85fJI5ccEv9jtJUA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=NeNO2yxxJHj3+5x/STZPGsImoQ1uwGw7nU4vxibZh1E=; b=YMkrPChmFxdS5zpGW7CfYzaUnu3mWl/UKWsWcic6lZ3KCkZs8xcpl7v53+6HYFrOm3 4cvo5T/zaOY/XmEH8MyEEZt5M9GrJflZizrWapObicvpL7GxKsAFp8W5tNudY+WsbPob 3QH9Z5uyPKzOVJoyH5mXUoi+CtVHQe50vzfPErVy1GOltE1T53Sf/Vp9mLyDwyUtbUGo C0eopo9DJ3X/BbEiU1CqIfORP2puI9dmu+reWercJpgnI0n2ENE/IYIJRreLhmdak3SX rZdosqy3WnhY20WN/9Kdny8YS+y6/TF8FsdQWdwHdFVd7h+kI8d57vtVUUxg/KyWv19x GBZw== X-Gm-Message-State: APzg51Dqrozrtdr7BJ8eo6dBaptCqtRZe9AYdLG9yg2hs+mmsHogiQ2v T314k9yGSEJ9zQYhjEBVZ/Uy50quNR8= X-Google-Smtp-Source: ANB0VdY93gkY0B72yCq9SAPyvJdcdLwe0FpkxyWm21ywG0EQMt3Fsfx184pqSHDFXiTB7VwLQwgi5Q== X-Received: by 2002:a17:902:4e:: with SMTP id 72-v6mr41191567pla.318.1537484514241; Thu, 20 Sep 2018 16:01:54 -0700 (PDT) Received: from localhost.localdomain ([209.121.128.187]) by smtp.gmail.com with ESMTPSA id p4-v6sm37507823pfd.65.2018.09.20.16.01.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Sep 2018 16:01:53 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org Cc: Ard Biesheuvel , Vincent Zimmer , Brian Richardson , Michael D Kinney , Andrew Fish , Leif Lindholm , Star Zeng , Eric Dong , Ruiyu Ni , Liming Gao , Jaben Carsey , Steven Shi Date: Thu, 20 Sep 2018 16:01:41 -0700 Message-Id: <20180920230145.7565-4-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180920230145.7565-1-ard.biesheuvel@linaro.org> References: <20180920230145.7565-1-ard.biesheuvel@linaro.org> Subject: [PATCH v3 3/7] MdeModulePkg/PciBusDxe: invoke PE/COFF emulator for foreign option ROMs X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Sep 2018 23:01:55 -0000 When enumerating option ROM images, take into account whether an emulator exists that would allow dispatch of PE/COFF images built for foreign architectures. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h | 1 + MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf | 1 + MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c | 53 +++++++++++++++++++- 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h b/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h index 55eb3a5a8070..dc57d4876c0f 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h @@ -33,6 +33,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include +#include #include #include diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf b/MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf index a21dd2b5edf4..c8b861093292 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf @@ -96,6 +96,7 @@ gEfiIncompatiblePciDeviceSupportProtocolGuid ## SOMETIMES_CONSUMES gEfiLoadFile2ProtocolGuid ## SOMETIMES_PRODUCES gEdkiiIoMmuProtocolGuid ## SOMETIMES_CONSUMES + gEdkiiPeCoffImageEmulatorProtocolGuid ## SOMETIMES_CONSUMES gEfiLoadedImageDevicePathProtocolGuid ## CONSUMES [FeaturePcd] diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c index c2be85a906af..085bd5d571bd 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c @@ -651,6 +651,55 @@ RomDecode ( } } +STATIC +BOOLEAN +IsImageTypeSupported ( + IN UINT16 MachineType, + IN UINT16 SubSystem, + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath + ) +{ + EFI_STATUS Status; + EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *Emu; + UINTN HandleCount; + EFI_HANDLE *HandleBuffer; + BOOLEAN ReturnValue; + UINTN Index; + + if (EFI_IMAGE_MACHINE_TYPE_SUPPORTED (MachineType)) { + return TRUE; + } + + Status = gBS->LocateHandleBuffer ( + ByProtocol, + &gEdkiiPeCoffImageEmulatorProtocolGuid, + NULL, + &HandleCount, + &HandleBuffer + ); + if (EFI_ERROR (Status)) { + return FALSE; + } + + ReturnValue = FALSE; + for (Index = 0; Index < HandleCount; Index++) { + Status = gBS->HandleProtocol ( + HandleBuffer[Index], + &gEdkiiPeCoffImageEmulatorProtocolGuid, + (VOID **)&Emu + ); + ASSERT_EFI_ERROR (Status); + + if (Emu->IsImageSupported (Emu, MachineType, SubSystem, DevicePath)) { + ReturnValue = TRUE; + break; + } + } + + FreePool (HandleBuffer); + return ReturnValue; +} + /** Load and start the Option Rom image. @@ -715,7 +764,9 @@ ProcessOpRomImage ( // // Skip the EFI PCI Option ROM image if its machine type is not supported // - if (!EFI_IMAGE_MACHINE_TYPE_SUPPORTED (EfiRomHeader->EfiMachineType)) { + if (!IsImageTypeSupported(EfiRomHeader->EfiMachineType, + EfiRomHeader->EfiSubsystem, + PciDevice->DevicePath)) { goto NextImage; } -- 2.17.1