From patchwork Fri May 4 06:00:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 134946 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp437222lji; Thu, 3 May 2018 23:01:39 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrLr8HkwXYNt1q/NT2oUD8bHl6wL35r4yowX/WV9Cnx3lraF9gdUc9PTSnfsCEX+NljaiVg X-Received: by 2002:a17:902:784c:: with SMTP id e12-v6mr14825913pln.60.1525413699074; Thu, 03 May 2018 23:01:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525413699; cv=none; d=google.com; s=arc-20160816; b=pBenqdG5VXS48CjbYBQF+jrUXiOtR16gA3xwHDR/kYltXv3uSmG/QcQm4a4MmyVfh5 sEnikZ+JfEEuLtc+knpQBX8njaw8IyjDoCwpwVZLpmxudVRRYhKb0DvZisU7+nR2DpAO hLDLVMENI4BCH8nS3SJulfI6yrKniKR5s0FC6jjnKl4iM6CvRnpjbF5/cWnDuLUU5Kq1 fxe5TaUZMOA1Nr/c+NXBa7JP0sETGDpdlYpVemBmX2PpD2/7czyqvDje5MBNUYzkfc7F /BuTz/slGmQnbjn3dZjycZcI4ejTkuXbg6Fbi+G4npGveIO1/sZTs0JjoGS8YyZNZ9pA mfmQ== 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=3VOyyaPz5dqEYq5DBPkF4AI2EW707wdSPFitILkebtE=; b=UWSo0aWpnwLNItgjZ/2Dx3OMPfv1wx89vzwpI/4KyLIXTobiVAv+wCbdBaOQ10eIut qvnzkv6KTKHcbM3sMu7MhpURdP06R6fge1kMqBIwardOgH0GoUKvfsH9wZRx6ekjdD/s wColscZR19R5EK6Jjt9BH16+1mxOms94x8MZN0BwA+ovXtmwTG82pMtYEGWjth26yKgs GJNmI9Nih9gQyPN/pucmSxb9ubrlp6WSY2Ktd126jJmbkL6KFZjOdz7zGEcovwvxs2EK aqchhG0f2zkyuq6jS0ZOEaalYNxUgKcMV90ajOmuSTNMz84zq2uivGZvfZcKup2G8fwc G9BA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bZriFtyh; 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 h8si2812110pfh.278.2018.05.03.23.01.38; Thu, 03 May 2018 23:01:39 -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=bZriFtyh; 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 S1751799AbeEDGBe (ORCPT + 29 others); Fri, 4 May 2018 02:01:34 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:44465 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751689AbeEDGB3 (ORCPT ); Fri, 4 May 2018 02:01:29 -0400 Received: by mail-wr0-f193.google.com with SMTP id y15-v6so8040031wrg.11 for ; Thu, 03 May 2018 23:01:29 -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=3VOyyaPz5dqEYq5DBPkF4AI2EW707wdSPFitILkebtE=; b=bZriFtyhSR325nyXvIsSZVIqlvA93hpLE1NNYdT2SzDqvlX8dhB9QgcQGJye/u7zAk IAzT0iOd8BBSr+jAXGQgKN8AstGYjKMC1qpwckV5EMsdxoCfW1MykvSqD52TImGQuCK3 bIlfnazaX9gXqDjbzLKLawU4tTSmd9aTicFek= 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=3VOyyaPz5dqEYq5DBPkF4AI2EW707wdSPFitILkebtE=; b=OC4tb4mVj17+YNbntx6oYVNG78SIfhMq4fAYl+tHd1BNEQHLNqRgKzEEmekWNpSBfu FK0mMBB2N4G4us/SjGZAOr4PfPXx+bCS+1u/Kh5bZ3er058AToX2WY4sucs2Mnu4EzBR kjJKcCWguiME+w/J+nf5jPNfmsBGEY8oq57hUxtTj/l+oWRgDh//VtwDoStlBn7PwN/N UZrBx9Q3fqonJ9Rf12OtqRN+k8krGJNCoydsvUoXahh6iXI2IAVTCNaVphMzj3kdU/Dg 4Nkx+d6DPDpu5NATFf+Q6/1otNS/vHi0rBrBDiR7phnXZD8irHKtVfuw+Cbqq1XLmggt 8Vkg== X-Gm-Message-State: ALQs6tDVjlbcdI+6SL6VzGubzIZ4Jt++mPL3JzQ0yNJFn1ErA6TKJi3h JxXaHjI+kXAPa8iLXRmORoQqqw== X-Received: by 2002:adf:e791:: with SMTP id n17-v6mr20490109wrm.225.1525413688514; Thu, 03 May 2018 23:01:28 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:3995:5470:200:1aff:fe1b:b328]) by smtp.gmail.com with ESMTPSA id i30-v6sm32411863wra.38.2018.05.03.23.01.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 May 2018 23:01:27 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org Subject: [PATCH 14/17] efi/x86: fold __setup_efi_pci32 and __setup_efi_pci64 into one Date: Fri, 4 May 2018 08:00:00 +0200 Message-Id: <20180504060003.19618-15-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180504060003.19618-1-ard.biesheuvel@linaro.org> References: <20180504060003.19618-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As suggested by Lukas, use his efi_call_proto() and efi_table_attr() macros to merge __setup_efi_pci32() and __setup_efi_pci64() into a single function, removing the need to duplicate changes made in subsequent patches across both. Cc: Lukas Wunner Tested-by: Hans de Goede Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/eboot.c | 107 ++++++++----------------------- 1 file changed, 25 insertions(+), 82 deletions(-) -- 2.17.0 diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c index 3994f48c4043..dadf32312082 100644 --- a/arch/x86/boot/compressed/eboot.c +++ b/arch/x86/boot/compressed/eboot.c @@ -109,23 +109,27 @@ void efi_char16_printk(efi_system_table_t *table, efi_char16_t *str) } static efi_status_t -__setup_efi_pci32(efi_pci_io_protocol_32_t *pci, struct pci_setup_rom **__rom) +__setup_efi_pci(efi_pci_io_protocol_t *pci, struct pci_setup_rom **__rom) { struct pci_setup_rom *rom = NULL; efi_status_t status; unsigned long size; - uint64_t attributes; + uint64_t attributes, romsize; + void *romimage; - status = efi_early->call(pci->attributes, pci, - EfiPciIoAttributeOperationGet, 0, 0, - &attributes); + status = efi_call_proto(efi_pci_io_protocol, attributes, pci, + EfiPciIoAttributeOperationGet, 0, 0, + &attributes); if (status != EFI_SUCCESS) return status; - if (!pci->romimage || !pci->romsize) + romimage = (void *)(unsigned long)efi_table_attr(efi_pci_io_protocol, + romimage, pci); + romsize = efi_table_attr(efi_pci_io_protocol, romsize, pci); + if (!romimage || !romsize) return EFI_INVALID_PARAMETER; - size = pci->romsize + sizeof(*rom); + size = romsize + sizeof(*rom); status = efi_call_early(allocate_pool, EFI_LOADER_DATA, size, &rom); if (status != EFI_SUCCESS) { @@ -141,30 +145,32 @@ __setup_efi_pci32(efi_pci_io_protocol_32_t *pci, struct pci_setup_rom **__rom) rom->pcilen = pci->romsize; *__rom = rom; - status = efi_early->call(pci->pci.read, pci, EfiPciIoWidthUint16, - PCI_VENDOR_ID, 1, &(rom->vendor)); + status = efi_call_proto(efi_pci_io_protocol, pci.read, pci, + EfiPciIoWidthUint16, PCI_VENDOR_ID, 1, + &rom->vendor); if (status != EFI_SUCCESS) { efi_printk(sys_table, "Failed to read rom->vendor\n"); goto free_struct; } - status = efi_early->call(pci->pci.read, pci, EfiPciIoWidthUint16, - PCI_DEVICE_ID, 1, &(rom->devid)); + status = efi_call_proto(efi_pci_io_protocol, pci.read, pci, + EfiPciIoWidthUint16, PCI_DEVICE_ID, 1, + &rom->devid); if (status != EFI_SUCCESS) { efi_printk(sys_table, "Failed to read rom->devid\n"); goto free_struct; } - status = efi_early->call(pci->get_location, pci, &(rom->segment), - &(rom->bus), &(rom->device), &(rom->function)); + status = efi_call_proto(efi_pci_io_protocol, get_location, pci, + &rom->segment, &rom->bus, &rom->device, + &rom->function); if (status != EFI_SUCCESS) goto free_struct; - memcpy(rom->romdata, (void *)(unsigned long)pci->romimage, - pci->romsize); + memcpy(rom->romdata, romimage, romsize); return status; free_struct: @@ -176,7 +182,7 @@ static void setup_efi_pci32(struct boot_params *params, void **pci_handle, unsigned long size) { - efi_pci_io_protocol_32_t *pci = NULL; + 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; @@ -203,7 +209,7 @@ setup_efi_pci32(struct boot_params *params, void **pci_handle, if (!pci) continue; - status = __setup_efi_pci32(pci, &rom); + status = __setup_efi_pci(pci, &rom); if (status != EFI_SUCCESS) continue; @@ -217,74 +223,11 @@ setup_efi_pci32(struct boot_params *params, void **pci_handle, } } -static efi_status_t -__setup_efi_pci64(efi_pci_io_protocol_64_t *pci, struct pci_setup_rom **__rom) -{ - struct pci_setup_rom *rom; - efi_status_t status; - unsigned long size; - uint64_t attributes; - - status = efi_early->call(pci->attributes, pci, - EfiPciIoAttributeOperationGet, 0, - &attributes); - if (status != EFI_SUCCESS) - return status; - - if (!pci->romimage || !pci->romsize) - return EFI_INVALID_PARAMETER; - - size = pci->romsize + sizeof(*rom); - - status = efi_call_early(allocate_pool, EFI_LOADER_DATA, size, &rom); - if (status != EFI_SUCCESS) { - efi_printk(sys_table, "Failed to alloc mem for rom\n"); - return status; - } - - rom->data.type = SETUP_PCI; - rom->data.len = size - sizeof(struct setup_data); - rom->data.next = 0; - rom->pcilen = pci->romsize; - *__rom = rom; - - status = efi_early->call(pci->pci.read, pci, EfiPciIoWidthUint16, - PCI_VENDOR_ID, 1, &(rom->vendor)); - - if (status != EFI_SUCCESS) { - efi_printk(sys_table, "Failed to read rom->vendor\n"); - goto free_struct; - } - - status = efi_early->call(pci->pci.read, pci, EfiPciIoWidthUint16, - PCI_DEVICE_ID, 1, &(rom->devid)); - - if (status != EFI_SUCCESS) { - efi_printk(sys_table, "Failed to read rom->devid\n"); - goto free_struct; - } - - status = efi_early->call(pci->get_location, pci, &(rom->segment), - &(rom->bus), &(rom->device), &(rom->function)); - - if (status != EFI_SUCCESS) - goto free_struct; - - memcpy(rom->romdata, (void *)(unsigned long)pci->romimage, - pci->romsize); - return status; - -free_struct: - efi_call_early(free_pool, rom); - return status; - -} - static void setup_efi_pci64(struct boot_params *params, void **pci_handle, unsigned long size) { - efi_pci_io_protocol_64_t *pci = NULL; + 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; @@ -311,7 +254,7 @@ setup_efi_pci64(struct boot_params *params, void **pci_handle, if (!pci) continue; - status = __setup_efi_pci64(pci, &rom); + status = __setup_efi_pci(pci, &rom); if (status != EFI_SUCCESS) continue;