From patchwork Sun Apr 29 11:06:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 134664 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp2663746lji; Sun, 29 Apr 2018 04:06:51 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrWw0na+S2GkP1wn09WMcQj+zpTRxKJ95oY31H7b7FT51pngk1xHJYg1n+3zEGUCLtylxTP X-Received: by 2002:a17:902:7406:: with SMTP id g6-v6mr8551457pll.237.1525000011301; Sun, 29 Apr 2018 04:06:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525000011; cv=none; d=google.com; s=arc-20160816; b=IGN2kBkCpISp/nfP9gAways7jhdy7lIhQtwfb6bFQ804cZQPl1fXehmIgY5mpOCU4U LCKqRwWuW9HdUJPXI89oYt3bX7Ymjr5XhHaq+EwPT3+ylZIme2zn9+UjYIFsSuT4J5xq 0bL/tbGb4DU7L3YRDoRoT1U0/Dfp/787P7YFRCgbKKbDIMihSl6A3t5e+mklr7HTk1pj NHnX0ZF7UgH6lHLuQBPruyo6vFC2ibAFt0raat3rRjyPonc9b7dZwpfV6NuuVnV8C1y7 V2JiZm2p0CBd53ov8kaEKXn/o/hYrt0dM/HgiVLeay1JaNjqSvtUJDmEjQTiRBUHlRw0 6zDA== 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=567TfHnOExbPoGZrk9JB2pkPMODTTMSn/LaY+V8Y7dQ=; b=whLQMZPW16jbVSdNuJJr5wSsnsCb0hByydNEXcLzm/b7Sn9r1su4BD/cl++1Bbvirf hiXg2iKADhEPg+m8liUPmvOal5d+t2J6wDvveK3H/oERkrWGPLPLaFYSwboXTU9y5Ha0 ireointFAuA8js5KxeMSS07Eaz6hXo3iR5wrbUg85H4kFcJm9E2tmUsTBv7HJsJw7gKS rLMe1Za/L/rEaC2yuvGB184GnA3xBO2nYORyZIy2/yNBQ04GTbRJCss3RNegaycY8tCo EwcWVa0w3sn2yjkeZC8sjrdV4tMntyaFtHeSAFBfRDIWrsirRDSmAnwrmA/64LKIs9p+ ofbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=aPMT2i0V; 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 z1-v6si5369654plo.263.2018.04.29.04.06.51; Sun, 29 Apr 2018 04:06:51 -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=aPMT2i0V; 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 S1753054AbeD2LGu (ORCPT + 2 others); Sun, 29 Apr 2018 07:06:50 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:55960 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752977AbeD2LGt (ORCPT ); Sun, 29 Apr 2018 07:06:49 -0400 Received: by mail-wm0-f65.google.com with SMTP id a8so8867371wmg.5 for ; Sun, 29 Apr 2018 04:06:49 -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=fSbijCkk8hhRmdOnMzF9VUCG5wX+TYjZk9Gmdpbn0nw=; b=aPMT2i0VYHpxPkAsprNYpVPf7GkyH/ALNxCt/7oOknZcTMw480vctuQih7jW0qC7AQ pAl2yWmVkAYxhBBgc+OEQvfbz1gmBniVCtW6Wo41h7t5vUmKRXmmya37yzrytHWVtWZG rsAbyfQPK4H8bIpWpN9/JlEtA1I7kyIXBDGQg= 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=fSbijCkk8hhRmdOnMzF9VUCG5wX+TYjZk9Gmdpbn0nw=; b=byBoIKNG27S7k5WSe3FV+4uPxwRnCykBXt53m56cpm24tc44iOb7oDhahMonUzra1s FfCBROBOrQviz5xRB2eojSxy5iV+LyaEkJj4Pf34Yqsi3NfyAxcPZfNVF5FZJxwyH8r0 T4H3YVUaPZ+0qZzZF40HHSvzs2aD/UAU0s6wyMHQSEGJrUMiQvR18YJoRZHFozQCYxak q7ycF1q9nc9MGAkGypbIq7S26JIX80M6HygBma0TOPmYl5YW5j+LHLf/KsHx+2g+rizG Jpqx1eI+xt2zT7DKxypzViyh5jZbJmewYt0OvrusbHpgGTPcNm7QLzgRRCtLWarkCien rY6A== X-Gm-Message-State: ALQs6tDxVBEklg7Te5YHQgjOH6LVjrR2kuONxZL/cPu9zhCCzbJrxFKp TA1YLbJDl4UAqsaR5WT2ldG4tA== X-Received: by 10.28.138.69 with SMTP id m66mr5754570wmd.117.1525000008599; Sun, 29 Apr 2018 04:06:48 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:3995:5470:200:1aff:fe1b:b328]) by smtp.gmail.com with ESMTPSA id a13-v6sm4783275wrc.19.2018.04.29.04.06.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 29 Apr 2018 04:06:47 -0700 (PDT) From: Ard Biesheuvel To: mingo@kernel.org, hdegoede@redhat.com, linux-efi@vger.kernel.org Cc: lukas@wunner.de, Ard Biesheuvel Subject: [PATCH v4 3/4] efi/x86: fold __setup_efi_pci32 and __setup_efi_pci64 into one Date: Sun, 29 Apr 2018 13:06:22 +0200 Message-Id: <20180429110623.13949-4-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180429110623.13949-1-ard.biesheuvel@linaro.org> References: <20180429110623.13949-1-ard.biesheuvel@linaro.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@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 Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/eboot.c | 107 +++++--------------- 1 file changed, 25 insertions(+), 82 deletions(-) -- 2.17.0 -- 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 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;