From patchwork Sat Sep 15 13:28:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 146771 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1805057ljw; Sat, 15 Sep 2018 06:29:15 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZ1GwbhHExIMe16zF0o+eTvCYK61DlhjY12GD/GfjS+wxqYEsc/C+R8j5AfbZu7ngWWcq5O X-Received: by 2002:a63:1c1b:: with SMTP id c27-v6mr16658307pgc.48.1537018154970; Sat, 15 Sep 2018 06:29:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537018154; cv=none; d=google.com; s=arc-20160816; b=Rk5K7ybdAv+GufLL9AC/w7nUmUADGj+CB5tHVZ3ZrBalb6ur3p7teGsdskzlyg44n9 BGV9xhXw3d8ZewmwXm+QtxztD5QGlKRDkFyOymw9NlzWXDaMnJ2yAPnZre4LFas2tSzM zHxbXJGvIFge/JTCpHHXS1dXrIOF0WOPFEWEcMwaVQfQhzR/YMGlOmRmPkL30bOmiPQp jjSWtBdkZUIeh7pmvdC5XkpgmEOvCrzuB+sNNEw77TXNOk1BtyQEuvSrDuF9PYk/aAaW P8mQwYUc8WKfytV1ajlg8aJ/eQHnQ8NZk3jOjDAtZV4adjJkiXGTlEuXOmGyiVXs+s2f 714w== 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=63uV4eyg3d/6R2ClxptfMwIYYhLOFNUWkhVXij8TOnY=; b=0R14h99qNVHFGhvdYJm2Q6/ictlYDTE8gtiaCpD+VNcj92+5TAfz8bkE2Qu6MuSkh9 CnQFXA1Ch3FwqNmkAl9+bpq7cdPVlq1KRsma80uqcPbd5iBR3TDFCXbOQpf9Od25LTa6 EH861qxn6bX8vhupocZXWI8zFFCYniTFcv70S+jJOzDzJqzfMgFQwfOYq/CZZk29+ixR YWCrWN12hOqQLwLAuPhArEZ2uSU+F+RmV3NtpEI8js46lcBTFj9qAB6FCGBMQ3qeXTIb pPnXbssVMKsre5FXRYf4SYvLpMPENBRqwuPtJnC9j0roiDB8unCUAYTrZWh0AIcO3aUe JUWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=BmHcGu7u; 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 d11-v6si9625426plo.91.2018.09.15.06.29.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 15 Sep 2018 06:29:14 -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=BmHcGu7u; 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 5CD3A211350EF; Sat, 15 Sep 2018 06:29:13 -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=2a00:1450:4864:20::52c; helo=mail-ed1-x52c.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) (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 5C1B5211350E3 for ; Sat, 15 Sep 2018 06:29:11 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id h4-v6so9492391edi.6 for ; Sat, 15 Sep 2018 06:29:11 -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=/8cs24/TIOOKeYusJolRaqh2SEZTJHbEt0J+wg7JK8I=; b=BmHcGu7uDJ8/FvMuLd+/mxugjB/cC0hbFI+jenMmd15p3Xgg8Lh533rbe71he/71YB N2Njh6CUhPtyZ0Ab5kX1i5laFEBh5QQmfkoubT6Nkg9oiZQ72JudSv8P+wBhLtKGkJ5J 1pPKGC2f2TWgR6/W8VpUhN347iRiFt4DDqt7E= 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=/8cs24/TIOOKeYusJolRaqh2SEZTJHbEt0J+wg7JK8I=; b=mgzXolk8yh5JRtn3OsJIJ11VMkgMRRhOaFvhLOxWM7JXiiw7Zgld8k4lZ/axe13dlA K4tu6RRoyPf/EL8/Shw+aT+UimuPLSETYs4vuCkdmg/rZ79IGQ8AaUbV2VETt9zOyQ7a PYIoR36N0nB5zlbRKxDn+0pWxCMZlwzG2CF7EhjMeObNzeZ/gnJl68sVgmXoBtk4B1xJ ADS1sBf7ZRuGFqaq3voyiIdsuAQKP44G5o1eLtG2QC6OlLNIFkJH4bXlunYSmzVXsvvw VhM7+mU1MCFVANNeyE9LbtYzJtIDIaDjVwJCz7HHeHhlbni5JWrV0a4x83Z2nJ4jOS6U N62A== X-Gm-Message-State: APzg51D/rLFLRNyHjpXvhPKj56UhZE4CW10zQVvCGGz5+T+zHVJ7OYjI 3/761H6L3r5mzRB9xDBjPyyR+378NJhzLQ== X-Received: by 2002:a50:c2d1:: with SMTP id u17-v6mr29446469edf.119.1537018149433; Sat, 15 Sep 2018 06:29:09 -0700 (PDT) Received: from mba13.kuq.prv ([194.138.39.100]) by smtp.gmail.com with ESMTPSA id j23-v6sm4449262edh.29.2018.09.15.06.29.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 15 Sep 2018 06:29:08 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Sat, 15 Sep 2018 15:28:55 +0200 Message-Id: <20180915132859.25727-4-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180915132859.25727-1-ard.biesheuvel@linaro.org> References: <20180915132859.25727-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH v2 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.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 | 51 +++++++++++++++++++- 3 files changed, 52 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..ac3a9fcaf1d0 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c @@ -651,6 +651,54 @@ RomDecode ( } } +STATIC +BOOLEAN +IsImageTypeSupported ( + IN UINT16 MachineType, + IN UINT16 SubSystem + ) +{ + 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)) { + ReturnValue = TRUE; + break; + } + } + + FreePool (HandleBuffer); + return ReturnValue; +} + /** Load and start the Option Rom image. @@ -715,7 +763,8 @@ 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)) { goto NextImage; }