From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:4864:20::441; helo=mail-wr1-x441.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) (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 AA91921959CB2 for ; Wed, 12 Sep 2018 06:22:45 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id 20-v6so2009040wrb.12 for ; Wed, 12 Sep 2018 06:22:45 -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=1mPsRwICitXpw5IpjTEB5Cg9062CZQWh0lcwt+o5jhY=; b=WnP/BJkjTmlv6w0Yq2VGUzvF5LWN2562YtC+4B94FXroEFBmb+caIG0ah+BqKaN+M2 mIxLFpxv2q1MGGk0g5iQaD2wbeboKCek5R26czchKPsBBU6NuBqeYHImQWBTofcdhL1J d+bwWNXdIlKeEhygSER/B25KZ0lCdpnWcCwfE= 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=1mPsRwICitXpw5IpjTEB5Cg9062CZQWh0lcwt+o5jhY=; b=h7TKM3XN0lTFjFIdlR7i4+0Am5HxLqeSCVxFNMnbdCJehZs8zrShgUWlndqriKzTzT jIMvbe1kha6Usvnq03T4LPm+oQ9BvyifmddI6VmPGBhWhvwlYj+buWqFi6GcA6MsAHMj jeKhREqYzoDcEZ+JUwd5ScZbbWF2xWdXjrQW5m2YBcYlgumByNkN9Mq7xHMNnqkwbiok XxPvOUBn1jGbF4kd1w+pLVj508a4PJv59ORRaLi0fxco6NeM6icykOzeHUezWeW9hn0E 6HLXSGDVk1VR1RGBKAmg0CgHkuafaKdrU/TN35HXpf/trU3fk3s14fkD1EzLNXJFjavG y+DQ== X-Gm-Message-State: APzg51CqvMzoidbkgmjbZZvLi3u0Q6sHU4lUrSUzaS9cqivjwEliob8z fBYciK3z1CN62xmv3WJEZR17DB/VDakIPg== X-Google-Smtp-Source: ANB0VdZbeDAGcR9Z5oeepZmrigJZofQ9Y2NlF8Q9tbYB6X0kCM/epFgvE3AtYsuXc5s9Q+5EhFFOkA== X-Received: by 2002:a5d:69d1:: with SMTP id s17-v6mr1593915wrw.77.1536758563792; Wed, 12 Sep 2018 06:22:43 -0700 (PDT) Received: from mba13.kuq.prv ([2001:a62:605:90f4:1f3:d690:1764:36ca]) by smtp.gmail.com with ESMTPSA id e133-v6sm1985129wma.33.2018.09.12.06.22.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Sep 2018 06:22:43 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org Cc: agraf@suse.de, Ard Biesheuvel , Zimmer Vincent , Brian Richardson , Michael D Kinney , Andrew Fish , Laszlo Ersek , Leif Lindholm , Star Zeng , Eric Dong , Ruiyu Ni Date: Wed, 12 Sep 2018 15:21:50 +0200 Message-Id: <20180912132151.4258-4-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180912132151.4258-1-ard.biesheuvel@linaro.org> References: <20180912132151.4258-1-ard.biesheuvel@linaro.org> Subject: [PATCH 3/4] 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: Wed, 12 Sep 2018 13:22:46 -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.0 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 | 16 +++++++++++++++- 3 files changed, 17 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..3d99ea0c1047 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf @@ -97,6 +97,7 @@ gEfiLoadFile2ProtocolGuid ## SOMETIMES_PRODUCES gEdkiiIoMmuProtocolGuid ## SOMETIMES_CONSUMES gEfiLoadedImageDevicePathProtocolGuid ## CONSUMES + gEdkiiPeCoffImageEmulatorProtocolGuid ## SOMETIMES_CONSUMES [FeaturePcd] gEfiMdeModulePkgTokenSpaceGuid.PcdPciBusHotplugDeviceSupport ## CONSUMES diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c index c2be85a906af..07236afd327d 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c @@ -678,6 +678,7 @@ ProcessOpRomImage ( MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH EfiOpRomImageNode; VOID *Buffer; UINTN BufferSize; + EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *PeCoffEmulator; Indicator = 0; @@ -693,6 +694,7 @@ ProcessOpRomImage ( } ASSERT (((EFI_PCI_EXPANSION_ROM_HEADER *) RomBarOffset)->Signature == PCI_EXPANSION_ROM_HEADER_SIGNATURE); + PeCoffEmulator = NULL; do { EfiRomHeader = (EFI_PCI_EXPANSION_ROM_HEADER *) RomBarOffset; if (EfiRomHeader->Signature != PCI_EXPANSION_ROM_HEADER_SIGNATURE) { @@ -716,7 +718,19 @@ ProcessOpRomImage ( // Skip the EFI PCI Option ROM image if its machine type is not supported // if (!EFI_IMAGE_MACHINE_TYPE_SUPPORTED (EfiRomHeader->EfiMachineType)) { - goto NextImage; + // + // Check whether we have a PE/COFF emulator that supports this image + // + if (PeCoffEmulator == NULL) { + gBS->LocateProtocol (&gEdkiiPeCoffImageEmulatorProtocolGuid, NULL, + (VOID **)&PeCoffEmulator); + } + if (PeCoffEmulator == NULL || + !PeCoffEmulator->IsImageSupported (PeCoffEmulator, + EfiRomHeader->EfiMachineType, + EfiRomHeader->EfiSubsystem)) { + goto NextImage; + } } // -- 2.17.1