From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:4001:c0b::244; helo=mail-it0-x244.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-it0-x244.google.com (mail-it0-x244.google.com [IPv6:2607:f8b0:4001:c0b::244]) (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 A61B52112E02A for ; Thu, 13 Sep 2018 03:47:00 -0700 (PDT) Received: by mail-it0-x244.google.com with SMTP id h23-v6so7121357ita.5 for ; Thu, 13 Sep 2018 03:47:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=CJxkVlBHiggjjpIGZiMnGm5yASC2cCcKLIO+olrq4EQ=; b=hMQl2beBQEGmn1kVPcczRab9K80cIpsCtM69FdbRsTHk88O8vk+jIiAulXjCAL1PMA Cm8NAgdG+j3E3eEDpzLxZVYVIZZepTSO8fb5tTLC3qV3KqFmmYaswMkzi0Bjl7WCSdCH yvctaaTuKGcEO9NkwhCQXd2xrEBCBbx0efEns= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=CJxkVlBHiggjjpIGZiMnGm5yASC2cCcKLIO+olrq4EQ=; b=CbT+nHUk+nIn6zNbxZssz9RF1oc9nj5x96FhwNXs2Jq+ev2VQSZ0uRq8whAHUk74Ni WvbK+GDfWsGhg8jsXRwj7XEnMXMylu1erez6UVxLRCgdJF9P+TiLMj4px6WNbAWb1VLE YsqIwHv7j8SBxKzabc/d8rnhWahD9uXUSauyD2M3hohPZU7nsGEQU2D3PCAJHHdo5/TW MxjCFnElJoxV8RE46oGGJOVlZvLPKPzrVIAy40PP4k01pY/Udbh/6PrB/GSGCNbTVKs6 G6hcm5YHMiL7QA1MlMktoeuq1DgScTEErvrHCowXmlYN6glwkrmWdNdm4nf3SxDHwK6A SFQg== X-Gm-Message-State: APzg51DqpbwLRs1MSD5V6tdl56guKZX7b2VMIggws5DFpKEIMqB/Foyb 1Y+TEAaaZFK0+iX6ZH8qMam1a6wtSEwtnxt4KfiyPQ== X-Google-Smtp-Source: ANB0VdZWTLZg5taEt7SVrQSG/GF0r+GzJqUwYqkZXB/X+7vBvMJrrwWOmRdfVbGjHbEe+07wnO7sSBoERKLKIJ/tkfQ= X-Received: by 2002:a02:59cc:: with SMTP id v73-v6mr5992687jad.5.1536835619672; Thu, 13 Sep 2018 03:46:59 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a6b:2848:0:0:0:0:0 with HTTP; Thu, 13 Sep 2018 03:46:59 -0700 (PDT) In-Reply-To: References: <20180912132151.4258-1-ard.biesheuvel@linaro.org> <20180912132151.4258-4-ard.biesheuvel@linaro.org> From: Ard Biesheuvel Date: Thu, 13 Sep 2018 12:46:59 +0200 Message-ID: To: "Zeng, Star" Cc: "edk2-devel@lists.01.org" , Ruiyu Ni , Zimmer Vincent , Eric Dong , Andrew Fish , Alexander Graf , Brian Richardson , Michael D Kinney , Laszlo Ersek Subject: Re: [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: Thu, 13 Sep 2018 10:47:00 -0000 Content-Type: text/plain; charset="UTF-8" On 13 September 2018 at 12:24, Zeng, Star wrote: > On 2018/9/12 21:21, Ard Biesheuvel wrote: >> >> 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; >> + } > > > Hi Ard, > > Could these be abstracted to a separate function like the PATCH 4/4 did? > Yes.