Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp416115pxj; Tue, 18 May 2021 06:20:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw1Gmy6ZTJ5HexGuA1CYiS8K0ccDkZtxgnhD5hdzU71eJ8CwBWufPT0GE5uI70tsXEG73tI X-Received: by 2002:a05:6638:3bc:: with SMTP id z28mr5369942jap.133.1621344048837; Tue, 18 May 2021 06:20:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621344048; cv=none; d=google.com; s=arc-20160816; b=w0RAHX7sps0IzBoDaiNffGTh1kRgPSGoMGJUKiT6ZjU3U0csgEsAzf8Cpr8cmxJ9jp i7HkbABuTftfesmOmp6jAVTidnsG60NbfXv/fipocw/OIoUDZJC0MVoLZzIRKArF8Szk 8lzXeCW4od8+yPRoRjn0Ez4l4daU0R2D9o3fm9+LqXv4mB8v/gF7Yidqx0iWqTQRGAww ObvhJMAetk+dxDf8ds97muoYEqwVFa8iR/DJluvR5H3hCYnn+pwif/kXNPlGRrcQkCpc BT9pBgtrZf6KN5SjOevrm4etmumesY9sybSJo9ucaIaslYNMxDnUxE6nGNNvRw/MWXUk avgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=QKMCtWpXAgHL8azuVSoTiSWTmObDXYLRTKGloiIfMKk=; b=HN/GeDnGmSPwPH9R+IsNG1Y7wD7M0otHyrxSnvpRqRcxM1CL1i5VTOIR49JPtjyPdS TOsMVlEHcWlORpCQuGDC/R7U+VpKUc0Cq5ISC9SYhURq9ee9RhkChmNiYplY4jxspWWA i5qoFEzcIHltyPsS8CJZdKdBHwegBffsiwSnVAeVa63aa4y3eeCU6AgavQnqeWA0vj32 1H0Dnbft+o5WhZCvYJBXuABB/5SGyfeQ1Wi+QJRpPjARi6DYLZ0rr1QfVJuT4nWhrjIe nD1gfjwL8nAtbRbMZPxwVVDwrJVYnJNj81rSe3JbO/ZehKCgRpPnqqbaAYq/kvkxoVxW TsDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ZHsl+IIq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t2si20081866ilq.112.2021.05.18.06.20.36; Tue, 18 May 2021 06:20:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ZHsl+IIq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244607AbhEQPhF (ORCPT + 99 others); Mon, 17 May 2021 11:37:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:39294 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244663AbhEQPVd (ORCPT ); Mon, 17 May 2021 11:21:33 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 58AFA61C85; Mon, 17 May 2021 14:34:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621262078; bh=8cOlcoMsdMiJoZFh719ykItWET96pM5IcG2M/aFbXJs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZHsl+IIq1qxRv8Wse3bjZa9jGNlQo8LY123nKBICcJ3ReAyY8NdS6tTLfvCowaGPd EJvxh+2svCx4zxMA9uGwvFtxX+ql6QV0yBmx8bpOPbQPIP5xpCmKqJWDTIHPwEp3UK Gqf44/SxvdeWZwg9LQF5yGeLgAKiAXgFTEJUXIFo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kishon Vijay Abraham I , Lorenzo Pieralisi , Bjorn Helgaas , Sasha Levin Subject: [PATCH 5.10 108/289] PCI: endpoint: Add helper API to get the next unreserved BAR Date: Mon, 17 May 2021 16:00:33 +0200 Message-Id: <20210517140308.807469605@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140305.140529752@linuxfoundation.org> References: <20210517140305.140529752@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kishon Vijay Abraham I [ Upstream commit fa8fef0e104a23efe568b835d9e7e188d1d97610 ] Add an API to get the next unreserved BAR starting from a given BAR number that can be used by the endpoint function. Link: https://lore.kernel.org/r/20210201195809.7342-4-kishon@ti.com Signed-off-by: Kishon Vijay Abraham I Signed-off-by: Lorenzo Pieralisi Signed-off-by: Bjorn Helgaas Signed-off-by: Sasha Levin --- drivers/pci/endpoint/pci-epc-core.c | 26 ++++++++++++++++++++++---- include/linux/pci-epc.h | 2 ++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c index 25e57672e1a1..1afe5d9afb0d 100644 --- a/drivers/pci/endpoint/pci-epc-core.c +++ b/drivers/pci/endpoint/pci-epc-core.c @@ -87,17 +87,36 @@ EXPORT_SYMBOL_GPL(pci_epc_get); * pci_epc_get_first_free_bar() - helper to get first unreserved BAR * @epc_features: pci_epc_features structure that holds the reserved bar bitmap * - * Invoke to get the first unreserved BAR that can be used for endpoint + * Invoke to get the first unreserved BAR that can be used by the endpoint * function. For any incorrect value in reserved_bar return '0'. */ unsigned int pci_epc_get_first_free_bar(const struct pci_epc_features *epc_features) +{ + return pci_epc_get_next_free_bar(epc_features, BAR_0); +} +EXPORT_SYMBOL_GPL(pci_epc_get_first_free_bar); + +/** + * pci_epc_get_next_free_bar() - helper to get unreserved BAR starting from @bar + * @epc_features: pci_epc_features structure that holds the reserved bar bitmap + * @bar: the starting BAR number from where unreserved BAR should be searched + * + * Invoke to get the next unreserved BAR starting from @bar that can be used + * for endpoint function. For any incorrect value in reserved_bar return '0'. + */ +unsigned int pci_epc_get_next_free_bar(const struct pci_epc_features + *epc_features, enum pci_barno bar) { unsigned long free_bar; if (!epc_features) return 0; + /* If 'bar - 1' is a 64-bit BAR, move to the next BAR */ + if ((epc_features->bar_fixed_64bit << 1) & 1 << bar) + bar++; + /* Find if the reserved BAR is also a 64-bit BAR */ free_bar = epc_features->reserved_bar & epc_features->bar_fixed_64bit; @@ -105,14 +124,13 @@ unsigned int pci_epc_get_first_free_bar(const struct pci_epc_features free_bar <<= 1; free_bar |= epc_features->reserved_bar; - /* Now find the free BAR */ - free_bar = ffz(free_bar); + free_bar = find_next_zero_bit(&free_bar, 6, bar); if (free_bar > 5) return 0; return free_bar; } -EXPORT_SYMBOL_GPL(pci_epc_get_first_free_bar); +EXPORT_SYMBOL_GPL(pci_epc_get_next_free_bar); /** * pci_epc_get_features() - get the features supported by EPC diff --git a/include/linux/pci-epc.h b/include/linux/pci-epc.h index cc66bec8be90..cfe9b427e6b7 100644 --- a/include/linux/pci-epc.h +++ b/include/linux/pci-epc.h @@ -203,6 +203,8 @@ const struct pci_epc_features *pci_epc_get_features(struct pci_epc *epc, u8 func_no); unsigned int pci_epc_get_first_free_bar(const struct pci_epc_features *epc_features); +unsigned int pci_epc_get_next_free_bar(const struct pci_epc_features + *epc_features, enum pci_barno bar); struct pci_epc *pci_epc_get(const char *epc_name); void pci_epc_put(struct pci_epc *epc); -- 2.30.2