From patchwork Thu Jul 12 12:21:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 141822 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp1445792ljj; Thu, 12 Jul 2018 05:22:04 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe5KMH4KdFojPdsyfUe3NAk1iq+7M3yvrjsuYxG+CxKSw6om0Ujci5urmeDJ+EGFMVcn0BU X-Received: by 2002:a17:902:9b98:: with SMTP id y24-v6mr1962367plp.177.1531398124437; Thu, 12 Jul 2018 05:22:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531398124; cv=none; d=google.com; s=arc-20160816; b=joq1Pj1Ll9MdD1n8wzCwfIHh50hQwbrQOrE5HQmeNuVgHg+2hr/LPzIsqdWxbLaqSG +VxIpPh7tmBW7mjjflPEYA832bVv7xa1N0enLSVglAmNNZQQp+L21woJ5NcN/bV6t71J bhEUU7a/bo11Rdbvg/+1UPBXmV4Wy7iQ9KtjqAbI1F7QJHJcF2clfD6Cm/gVmLjK0+iW u22lSGK3ngh/l1rOMkXk4D09ghwhaEBN+aMmZxTBp4t1pmLNNtv7PY25LWslUnbrW1l7 dgfbnT6pQQGeEkwbtBaAEmglggpTwbyQlXEc7d3apP0EHw/G4U+//JGt31rhoBb17/tE lBbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=NqoWVwjs0IbWWkpdr1chW4dwGJvYj1cdlKjgIf8FBj8=; b=a5h9svBTe90HrWgXbUFTAl15+wQM8Y4JagWHYHpYOhHNK39cGyRU+8YRsQVmHeSfi1 O2/X1aGCnUOvbpCQJw34DNYo6bnCAQrtDKSdx1u8pp8XYZplQWfU4eX5xhn4FLOE4gS2 Wvt+7F+YEv6MyJgDOsblmRbHtgV8cHfzqDaHVwkQuK9Q7WFIjNqbZBLv5lyP3ht4lEgi HEECSV28iOj6L3HQQXEjeRDuzdajNYG7sKFREGo4f/OxXwmG6jzXfvcKslcOLt5epaVk FnfM0CYN+NHVTWPCE8BjeNYcOP8r8p+VYkDbK6wPL+arqBadclisgDswmUzn+0/ONTZM +V1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=idQA+CXG; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v8-v6si7016131pff.248.2018.07.12.05.22.04; Thu, 12 Jul 2018 05:22:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=idQA+CXG; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726888AbeGLMbX (ORCPT + 3 others); Thu, 12 Jul 2018 08:31:23 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:39839 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726810AbeGLMbW (ORCPT ); Thu, 12 Jul 2018 08:31:22 -0400 Received: by mail-wr1-f66.google.com with SMTP id h10-v6so21489846wre.6 for ; Thu, 12 Jul 2018 05:22:02 -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=Xa1oCOxGi3VGiwj5bciKhIoLsDEFyyT+8HAJdmSrulo=; b=idQA+CXGEeUU7C5in6fpLahqDhdvdTza1+G8iGsi/i0mz6kBPc93RcqJCc5ygeHGNY arWEEyUTqR5EG4fXqVO8LEBc+SCdJxCFF8ho661PrtDMxexjaud4G+auSBp8E4T/MaxO kALP1mOyknc6rUQ0zmdgYFgCw5pmrLdtHkJmw= 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=Xa1oCOxGi3VGiwj5bciKhIoLsDEFyyT+8HAJdmSrulo=; b=pNkyhtRk5l0L3hIaO3HDBOvADWiiRtk1ps4e4l5d3VjSwZZYgMiDFio0SuYtFQ8HTb JkiOG7f7pBMAuxIyMUN4QwMWW2hARUfUJGv6FjU9Y1YIBBr71LfEIjx/aSK/7gmojFhK Mmp/Ar57XQvICLjJQkbwCfFw9zQWJKmiUJN2hAzVcWWc3A0i4qlSyYLvuKZFNeMiJxM+ YJ43IlY+x3x4D5H2lRqnlZj1YTE3yDEKY8eVRH3qKQSGuQPIOc8256DLJEz9gKsG+8Lu kiNrCGJGNSdg5+O/ydgp9o6NlffD0Go50B+nNBRg0nNHHS9EQUbVBCifVNmy2NWAWEgH zLMg== X-Gm-Message-State: AOUpUlEDYonA4PQ+vgL1PJATMz7i3JNUrgkl6AnFkEXd0KIjBfSMhw6/ 35JLnZdiQwwklm/hxm2EdvHNbrEFT48= X-Received: by 2002:a5d:48cd:: with SMTP id p13-v6mr1762616wrs.0.1531398121102; Thu, 12 Jul 2018 05:22:01 -0700 (PDT) Received: from localhost.localdomain (33.153.69.91.rev.sfr.net. [91.69.153.33]) by smtp.gmail.com with ESMTPSA id y3-v6sm3551246wmd.24.2018.07.12.05.21.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Jul 2018 05:22:00 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: sai.praneeth.prakhya@intel.com, mingo@kernel.org, hdegoede@redhat.com, lukas@wunner.de, Ard Biesheuvel Subject: [PATCH 2/6] efi/x86: merge setup_efi_pci32 and setup_efi_pci64 routines Date: Thu, 12 Jul 2018 14:21:50 +0200 Message-Id: <20180712122154.13819-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180712122154.13819-1-ard.biesheuvel@linaro.org> References: <20180712122154.13819-1-ard.biesheuvel@linaro.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org After merging the 32-bit and 64-bit versions of the code that invokes the PCI I/O protocol methods to preserve PCI ROM images in commit 2c3625cb9fa2 ("efi/x86: Fold __setup_efi_pci32() and __setup_efi_pci64() ...") there are still separate code paths for 32-bit and 64-bit, where the only difference is the size of a EFI_HANDLE. So let's parameterize a single implementation for that difference only, and get rid of the two copies of the code. While at it, rename __setup_efi_pci() to preserve_pci_rom_image() to better reflect its purpose. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/eboot.c | 123 +++++--------------- 1 file changed, 32 insertions(+), 91 deletions(-) -- 2.17.1 -- To unsubscribe from this list: send the line "unsubscribe linux-efi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c index 9f6813493945..c72550783c16 100644 --- a/arch/x86/boot/compressed/eboot.c +++ b/arch/x86/boot/compressed/eboot.c @@ -111,7 +111,7 @@ void efi_char16_printk(efi_system_table_t *table, efi_char16_t *str) } static efi_status_t -__setup_efi_pci(efi_pci_io_protocol_t *pci, struct pci_setup_rom **__rom) +preserve_pci_rom_image(efi_pci_io_protocol_t *pci, struct pci_setup_rom **__rom) { struct pci_setup_rom *rom = NULL; efi_status_t status; @@ -181,92 +181,6 @@ __setup_efi_pci(efi_pci_io_protocol_t *pci, struct pci_setup_rom **__rom) return status; } -static void -setup_efi_pci32(struct boot_params *params, void **pci_handle, unsigned long size) -{ - efi_pci_io_protocol_t *pci = NULL; - efi_guid_t pci_proto = EFI_PCI_IO_PROTOCOL_GUID; - u32 *handles = (u32 *)(unsigned long)pci_handle; - efi_status_t status; - unsigned long nr_pci; - struct setup_data *data; - int i; - - data = (struct setup_data *)(unsigned long)params->hdr.setup_data; - - while (data && data->next) - data = (struct setup_data *)(unsigned long)data->next; - - nr_pci = size / sizeof(u32); - for (i = 0; i < nr_pci; i++) { - struct pci_setup_rom *rom = NULL; - u32 h = handles[i]; - - status = efi_call_early(handle_protocol, h, - &pci_proto, (void **)&pci); - - if (status != EFI_SUCCESS) - continue; - - if (!pci) - continue; - - status = __setup_efi_pci(pci, &rom); - if (status != EFI_SUCCESS) - continue; - - if (data) - data->next = (unsigned long)rom; - else - params->hdr.setup_data = (unsigned long)rom; - - data = (struct setup_data *)rom; - } -} - -static void -setup_efi_pci64(struct boot_params *params, void **pci_handle, unsigned long size) -{ - efi_pci_io_protocol_t *pci = NULL; - efi_guid_t pci_proto = EFI_PCI_IO_PROTOCOL_GUID; - u64 *handles = (u64 *)(unsigned long)pci_handle; - efi_status_t status; - unsigned long nr_pci; - struct setup_data *data; - int i; - - data = (struct setup_data *)(unsigned long)params->hdr.setup_data; - - while (data && data->next) - data = (struct setup_data *)(unsigned long)data->next; - - nr_pci = size / sizeof(u64); - for (i = 0; i < nr_pci; i++) { - struct pci_setup_rom *rom = NULL; - u64 h = handles[i]; - - status = efi_call_early(handle_protocol, h, - &pci_proto, (void **)&pci); - - if (status != EFI_SUCCESS) - continue; - - if (!pci) - continue; - - status = __setup_efi_pci(pci, &rom); - if (status != EFI_SUCCESS) - continue; - - if (data) - data->next = (unsigned long)rom; - else - params->hdr.setup_data = (unsigned long)rom; - - data = (struct setup_data *)rom; - } -} - /* * There's no way to return an informative status from this function, * because any analysis (and printing of error messages) needs to be @@ -282,6 +196,9 @@ static void setup_efi_pci(struct boot_params *params) void **pci_handle = NULL; efi_guid_t pci_proto = EFI_PCI_IO_PROTOCOL_GUID; unsigned long size = 0; + unsigned long nr_pci; + struct setup_data *data; + int i; status = efi_call_early(locate_handle, EFI_LOCATE_BY_PROTOCOL, @@ -305,10 +222,34 @@ static void setup_efi_pci(struct boot_params *params) if (status != EFI_SUCCESS) goto free_handle; - if (efi_early->is64) - setup_efi_pci64(params, pci_handle, size); - else - setup_efi_pci32(params, pci_handle, size); + data = (struct setup_data *)(unsigned long)params->hdr.setup_data; + + while (data && data->next) + data = (struct setup_data *)(unsigned long)data->next; + + nr_pci = size / (efi_is_64bit() ? sizeof(u64) : sizeof(u32)); + for (i = 0; i < nr_pci; i++) { + efi_pci_io_protocol_t *pci = NULL; + struct pci_setup_rom *rom; + + status = efi_call_early(handle_protocol, + efi_is_64bit() ? ((u64 *)pci_handle)[i] + : ((u32 *)pci_handle)[i], + &pci_proto, (void **)&pci); + if (status != EFI_SUCCESS || !pci) + continue; + + status = preserve_pci_rom_image(pci, &rom); + if (status != EFI_SUCCESS) + continue; + + if (data) + data->next = (unsigned long)rom; + else + params->hdr.setup_data = (unsigned long)rom; + + data = (struct setup_data *)rom; + } free_handle: efi_call_early(free_pool, pci_handle);