Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp448394pxb; Wed, 11 Nov 2020 07:39:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJxpPkc2pwLGevoq92y15+2lW6rXnyvu8HijAL6rdlwVWUy+wFKpyNNv07IFB8Q4FWSeYbNN X-Received: by 2002:aa7:d98b:: with SMTP id u11mr5879566eds.107.1605109139864; Wed, 11 Nov 2020 07:38:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605109139; cv=none; d=google.com; s=arc-20160816; b=UNm64Rt8RLtC06NpPONtU66iRhnSCJ7jcW9YlAfzxefJo3RXxl9/YBiwh2td3VDEWp KB5exTmRLZVb0gfZxah7czpmBalO5Vp83/RNIZ6sRtqO2lTUiMcNg9SgqfHeaLWZH0EW GK0hGVKNvWC11I2Ohz9S2v+spmRlf2JpKIdNQmyMpisCxxabP9ay9nbYD63DzZ48Iqge o9l0sc2KFz9ULCpTnTob4lxBOOjzUA8O3IZFXLt6PbV1rn9JcOdsaFz3QYvZCwAyuolv 1TrQRKei57VnXwB3asvMl2U5ymE8erxjWS6Dfi/tkeYIGi9lwXjzWZb3QDWsHXEeAH1x 8YEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=7qF2OVbWDyaTlnP441W+A6WtQychKbyb9MpcDopQVLo=; b=MFOs+uJF2DuDzZ+gbG4cuxBydSbtbON1BSEiHVnvjmIJxqxvLYw7Jp51LFwis/bbcG ECjhjqmfDad7bX9TbSl9A23F0So56ZurlG/R7El/5vYmQrznQ2EtRF22lhM352zJGQKI a4CKtmlG/QI11t+9R+zyyFoked1l4HG8enRMbGrdJFvU49KwB60Bg95CcKGtLNdhGHWD aitb0Ak7u2vWS1yXusEh+yLGVwDxX3WmzGOpJdqafmlOGfKoDwfkS/ikiOJC6y1Eu4Xg 0ka0Zo0KJm9KsCeLk5YXHBDB3Mlni7MFG9AH84gC+lt5l/fvFvYcKjYGS3YzCZ63eud/ 4gWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=afE+ZzSv; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l7si1571323eja.665.2020.11.11.07.38.35; Wed, 11 Nov 2020 07:38:59 -0800 (PST) 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=@ti.com header.s=ti-com-17Q1 header.b=afE+ZzSv; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727422AbgKKPgl (ORCPT + 99 others); Wed, 11 Nov 2020 10:36:41 -0500 Received: from fllv0015.ext.ti.com ([198.47.19.141]:58904 "EHLO fllv0015.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727412AbgKKPgk (ORCPT ); Wed, 11 Nov 2020 10:36:40 -0500 Received: from lelv0265.itg.ti.com ([10.180.67.224]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 0ABFaQTI124753; Wed, 11 Nov 2020 09:36:26 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1605108986; bh=7qF2OVbWDyaTlnP441W+A6WtQychKbyb9MpcDopQVLo=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=afE+ZzSvg/C4AopvndWoHGixQV6QXpvKJmJVGO4k82U71Rxiek0CAJi+OycU6j256 YyI8QEqS4gETmtT5ckVVdte1VnLQRW743jXd2b2p0//bfElXj2f9kg2HOSqQIy9gHn Tw0bK9aWbosMbX6aWCFtAhmwv5eHwqDnFkoMXKYA= Received: from DLEE103.ent.ti.com (dlee103.ent.ti.com [157.170.170.33]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 0ABFaQeB111777 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 11 Nov 2020 09:36:26 -0600 Received: from DLEE100.ent.ti.com (157.170.170.30) by DLEE103.ent.ti.com (157.170.170.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3; Wed, 11 Nov 2020 09:36:26 -0600 Received: from lelv0326.itg.ti.com (10.180.67.84) by DLEE100.ent.ti.com (157.170.170.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3 via Frontend Transport; Wed, 11 Nov 2020 09:36:25 -0600 Received: from a0393678-ssd.dal.design.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0326.itg.ti.com (8.15.2/8.15.2) with ESMTP id 0ABFa03s042109; Wed, 11 Nov 2020 09:36:18 -0600 From: Kishon Vijay Abraham I To: Bjorn Helgaas , Jonathan Corbet , Kishon Vijay Abraham I , Lorenzo Pieralisi , Arnd Bergmann , Jon Mason , Dave Jiang , Allen Hubbe , Tom Joseph , Rob Herring CC: Greg Kroah-Hartman , , , , Subject: [PATCH v8 03/18] PCI: endpoint: Add helper API to get the 'next' unreserved BAR Date: Wed, 11 Nov 2020 21:05:44 +0530 Message-ID: <20201111153559.19050-4-kishon@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201111153559.19050-1-kishon@ti.com> References: <20201111153559.19050-1-kishon@ti.com> MIME-Version: 1.0 Content-Type: text/plain X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add an API to get the next unreserved BAR starting from a given BAR number that can be used by the endpoint function. Signed-off-by: Kishon Vijay Abraham I --- 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.17.1