From patchwork Thu Sep 20 23:01:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 147170 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp100020ljw; Thu, 20 Sep 2018 16:02:00 -0700 (PDT) X-Google-Smtp-Source: ANB0Vda4E9KjSV63bH5WrbYBvlZp1p/3lyt2nmmy/N4fnuMnTjejxlBYXC2MHdbGHdk9TUul7nr4 X-Received: by 2002:a63:1363:: with SMTP id 35-v6mr38755570pgt.202.1537484520747; Thu, 20 Sep 2018 16:02:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537484520; cv=none; d=google.com; s=arc-20160816; b=EJtcq8N0dHq0dfNs9nQOR5XVF7+s/IkSEoITgMtsfDe+1eUeqXDqczXY3CdMy3prx4 WkWUvGqXIqwi8IXDRAO7O7TDJP3apS8psxau9EnqFQw/vc9kk8Pb3E9J6/adPKBBUCCN Wys3N6JOrUaPctutvHVovJm5WhqwH9zzJOIn1k3/HDnm3aw4zTMrPfp/6Ilc5hzcm0R8 TPxcDvmcvCtNVBpg8l9giCwN1CPziZEld3m/DewBBQ+hPlZdodczgBWMI7oCtbj0za+b Go46BQ7BV4bYQhS3GMK77qIUaHK9LzVEQy4K/wofoAit/in5wYpdC7IlBox5Oad/idB8 EMwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to; bh=iq+Hxe7lbm3PDva2peZGCyJKhxn8CseURCeFgoSb+Jk=; b=ltYsPAWtACOd5bmziDE951RctdJ0jPoscEHJ0mXoFlEzNMQVkorlrFPrAxThNTzjoC B0n9bDAytV0fsrb4u3BsnQu8dCXQF5ZYX2wT82cjKi1KJKOl5aq/U5GQdf6gapluDDjk Wk6qXuotKxUFPX1980yDvH/X8WkjWkmlbhN9EmHMXpEgdM0LghrRDAtrom6Javvt6+r+ OJHmEDyxT/sKidCCAi/UJxUKS08wHldMb41xS7nk6GGwb1a8RqlLiFOMV3n5zlzgydHp zd30544NMLEU8X99XBBE0rDJMArJZkO/rMbupsaLu5G8iSgg7j504TKJ1KQOVZlaVHQO up1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=hw3KEiIQ; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id r34-v6si25307043pgb.656.2018.09.20.16.02.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Sep 2018 16:02:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=hw3KEiIQ; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id A6E312114A6AF; Thu, 20 Sep 2018 16:01:56 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org 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-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 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: [edk2] [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: , Cc: Ruiyu Ni , Vincent Zimmer , Eric Dong , Andrew Fish , Jaben Carsey , Brian Richardson , Liming Gao , Michael D Kinney , Star Zeng MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" 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(-) -- 2.17.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel 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; }