From patchwork Fri Jul 20 01:47:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 142398 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2392021ljj; Thu, 19 Jul 2018 18:47:56 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfALQnjpEgmKn1Su4wfwBL2eS7aLIU9oBt2QadhaQO45GN4Vhnb8hZX8Mge/PrzX8nXQ6GL X-Received: by 2002:a63:1546:: with SMTP id 6-v6mr78814pgv.271.1532051276132; Thu, 19 Jul 2018 18:47:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532051276; cv=none; d=google.com; s=arc-20160816; b=oiaO7+IiSX+76h86ji2PRMzf1YDW5gbLxZCI+lr72Xl604H1B7Fbs420+uelm/yYYH +1H5B/Ww8RNPrL4TB7OiE1eZ96ZYUqEKbO5kO4VudmkoPKzwbtir4sFhBbElg+WN2PFe +98r2oHE8ZV0CAlKVbdOtPMIevE62C6BwPgvC1tcjBCFIaCXdlrNVyURUoDk4anWN21/ P54d7Y0+7sYv//6WZS53KeiNV6KuhSHsYyVgq5lRGgbk2j2+o2j+d07E60ZYsfcjhd9P mSXXwpmLTW51WIQ1B1ZLIPvGHqHBfi9Of72w8Y/3+ASjxsqZ2Lx/AS6jW7gD3CZBGMBT +cnw== 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=b1HwyUAnJF2NFfT/pD4cNVn1pcnD0HmMCE+nI0tO3hM=; b=s3gDqPctMRIrZj3YwAW6C3krO7Z3yUactY+tYmIvNC/RQlOk1O9iDq8GTEvv8VBok0 W2JSXS7Pdti/RJVWCigfxJLeVgGEi+PPc75yc7uW9IUv7g4hrM6yjF8LU+E6N7Wuo1vc lq9wxUuB8WJQAnHomvjT/1h4NR0BWEDoW5qvsuHLEtkUsGxn7pUoahpuCc8y1hmtO97b 2+WNuyMy/j3IgBCMv0B/vvnaC7Deow7swopLdfS2uqAoaReOkC6CYLP6oSOswRtwcWBt 6bdDzf6oux2QFlYsbkR3Yuxc8FxaNBkbNfTgyNiUGelaa1DnitFGf5blVR3XPtXnqRzh g7aA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KetIWsL8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (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 t1-v6si603911plo.241.2018.07.19.18.47.55; Thu, 19 Jul 2018 18:47:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KetIWsL8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731140AbeGTCdn (ORCPT + 31 others); Thu, 19 Jul 2018 22:33:43 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:43738 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730266AbeGTCdm (ORCPT ); Thu, 19 Jul 2018 22:33:42 -0400 Received: by mail-pg1-f193.google.com with SMTP id v13-v6so5364533pgr.10 for ; Thu, 19 Jul 2018 18:47:52 -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=b1HwyUAnJF2NFfT/pD4cNVn1pcnD0HmMCE+nI0tO3hM=; b=KetIWsL8Xgtgvr4CU0JJOsTlhb0wTqV8abhmvPA5nzD1Tk4HfA8YQ6ZeTPtFiZpR3v CKp3dJA+Pw8Dry6lRGssaheA9D/r/w3P2qh7/HyawCFbHchMubVypTQBJTML3btVrXug XfOF0cjcLi0ScdTFFQL2b+EuWSnNRvDfIaxiM= 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=b1HwyUAnJF2NFfT/pD4cNVn1pcnD0HmMCE+nI0tO3hM=; b=Iwg5DUF1M/R/lcnQQ6SVjRPS6taXBVFwP6Gafpsu32FKJ3EMRzPV3ALFl3xT3F+8cF aCJzggkRPpVhdRSq2x9Mt94mR8OeMMypC9YROByATGzP/h/+JOO5PP+BYIp/P/YI+kwN Ybrl0CVCVmMFB4lJygIsewv5wE3x6AUNmXtgh37pCkM4NOhc+znYvjbCRqyO+ke5/+6s mppVYAxArYldYySvD8ekwwBtpnj8bulNZhsC+D1LqmODOJ9tf2KmOsQNBsowAa4GaRFb gxu8OMarX1mVorvv4yWSFGHU4rGeMZhxy/5PRCyx4so7Sf6g7a8hv4/9qI+/o0gvgsRO 3Vqg== X-Gm-Message-State: AOUpUlEm9rMlcHjO1YNHVVVeQzoc/4ryXuf9PS4O/A48Li1AyGV9v3uh JetNxE+TxV8Hg5WKzhd6drf1xw== X-Received: by 2002:a62:d98f:: with SMTP id b15-v6mr107430pfl.1.1532051272160; Thu, 19 Jul 2018 18:47:52 -0700 (PDT) Received: from localhost.localdomain (fs76eedbeb.tkyc508.ap.nuro.jp. [118.238.219.235]) by smtp.gmail.com with ESMTPSA id 203-v6sm475868pgb.14.2018.07.19.18.47.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jul 2018 18:47:51 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org, Andy Shevchenko , Hans de Goede , Lukas Wunner Subject: [PATCH 2/9] efi/x86: merge setup_efi_pci32 and setup_efi_pci64 routines Date: Fri, 20 Jul 2018 10:47:19 +0900 Message-Id: <20180720014726.24031-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180720014726.24031-1-ard.biesheuvel@linaro.org> References: <20180720014726.24031-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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. Tested-by: Hans de Goede Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/eboot.c | 123 ++++++++----------------------- 1 file changed, 32 insertions(+), 91 deletions(-) -- 2.17.1 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);