From patchwork Mon Jan 7 06:41:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kishon Vijay Abraham I X-Patchwork-Id: 154866 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3171874ljp; Sun, 6 Jan 2019 22:44:50 -0800 (PST) X-Google-Smtp-Source: ALg8bN4rU19WRZX3j5Wua1DyWB5gQPLWJ2MS4naNWiVsVUYU2ilg+kdkGCBrFpMBoO0NDCujv7AY X-Received: by 2002:a62:31c1:: with SMTP id x184mr63519892pfx.204.1546843489987; Sun, 06 Jan 2019 22:44:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546843489; cv=none; d=google.com; s=arc-20160816; b=n/aotQj8NpI17G4wbjquF7CbREmU1tmXQgBXHrfB39QEO5W0xxeqjAbIcdgnDBPg9a bjIPuWkX34qcwilfy+VTFUwJnv2DcDmh1AbJZu1Z33l9DvhHwc1VkcNDgL0G/GmplCLj G5fCBZ/4pZDl12ekMf9bwdWYwp9cC2bB4Z/wB2JtLE7nWKCH0dIO0+r0zvLyLsRnAbYZ IKskofPs4gElKb7Gb5PGfkfb9M3v3NTkvdKnGNjeBdGhbglmD5SfDAcO2d6kKo9+YTZC bcz5/RBThirFDCCU4CvDPcX2pLlZOTd/Opq1AmOSbwKmCeYQarq1edh4oe+1CfQRhIl8 EXoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=wJzish8jKdOVXhvaJ7MTD1mt6K3UYjBXhrK5Hbnol9E=; b=WBoYQQi034X7ip5myGFDkC46eZkmTfxgWEkCawH7iDiEzEEC/2RjebSzAap3ktE/d4 Rs1+Uu7PEZfeWY93FD6ATZ0fSfggUJXVsKSwRaiCof+bvEyVuFIH8ppXRdYs476cGgfw yiY/xwL/2FbwBnNA7ZrHCXCaSrlri4QTnsg1gIjFvfL6TKfTdVI8xoMM7yv+gi7kVGBw nEv3e+M47TmqQehULJgo3gt9xMIS9OI/dS5stFpnpj04CcorV7i1JQ7hM8/83amEv69C 8entdUlaKcPl7e25xiaBb/wciayh2LZ3SHV+evq/AACNiEA1/ZQNCEU0RXGkt8444GXK AWbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b="W8zH/Zjh"; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y189si65253978pfg.75.2019.01.06.22.44.49; Sun, 06 Jan 2019 22:44:49 -0800 (PST) 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=@ti.com header.s=ti-com-17Q1 header.b="W8zH/Zjh"; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726754AbfAGGos (ORCPT + 31 others); Mon, 7 Jan 2019 01:44:48 -0500 Received: from fllv0016.ext.ti.com ([198.47.19.142]:36896 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726446AbfAGGor (ORCPT ); Mon, 7 Jan 2019 01:44:47 -0500 Received: from lelv0265.itg.ti.com ([10.180.67.224]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id x076hI62021681; Mon, 7 Jan 2019 00:43:18 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1546843398; bh=wJzish8jKdOVXhvaJ7MTD1mt6K3UYjBXhrK5Hbnol9E=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=W8zH/Zjhszg3u1sMPVtKto0NvGJTmMf2q8FabmjBspWvtjOuZEawEp7qr8Is7V051 iR6iWyfnmPSyXHJn77KzkxoeZJcMUbWEEiy3GhD2H8kjeBMbp3PzICw/OUfXtQmAjk 4f2Z/MQM7roIY3iOkoZyJMEsdMcoApmw/0tIzftA= Received: from DFLE101.ent.ti.com (dfle101.ent.ti.com [10.64.6.22]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x076hHit048943 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 7 Jan 2019 00:43:17 -0600 Received: from DFLE105.ent.ti.com (10.64.6.26) by DFLE101.ent.ti.com (10.64.6.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10; Mon, 7 Jan 2019 00:43:17 -0600 Received: from dflp32.itg.ti.com (10.64.6.15) by DFLE105.ent.ti.com (10.64.6.26) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1591.10 via Frontend Transport; Mon, 7 Jan 2019 00:43:17 -0600 Received: from a0393678ub.india.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id x076gfo4002672; Mon, 7 Jan 2019 00:43:14 -0600 From: Kishon Vijay Abraham I To: Lorenzo Pieralisi , Bjorn Helgaas , Gustavo Pimentel , Alan Douglas , Shawn Lin CC: Jingoo Han , Heiko Stuebner , Cyrille Pitchen , Jia-Ju Bai , , , , , , Subject: [PATCH 07/15] PCI: endpoint: Add helper to get first unreserved BAR Date: Mon, 7 Jan 2019 12:11:40 +0530 Message-ID: <20190107064148.10152-8-kishon@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190107064148.10152-1-kishon@ti.com> References: <20190107064148.10152-1-kishon@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a helper function pci_epc_get_first_free_bar(), to get the first unreserved BAR that can be used for endpoint function. Signed-off-by: Kishon Vijay Abraham I --- drivers/pci/endpoint/pci-epc-core.c | 22 ++++++++++++++++++++++ include/linux/pci-epc.h | 1 + 2 files changed, 23 insertions(+) -- 2.17.1 diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c index 5a099479d9ab..b1632f91e33e 100644 --- a/drivers/pci/endpoint/pci-epc-core.c +++ b/drivers/pci/endpoint/pci-epc-core.c @@ -83,6 +83,28 @@ struct pci_epc *pci_epc_get(const char *epc_name) } 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 + * function. + */ +int pci_epc_get_first_free_bar(const struct pci_epc_features *epc_features) +{ + int free_bar; + + if (!epc_features) + return 0; + + free_bar = ffz(epc_features->reserved_bar); + if (free_bar <= 0 || free_bar > 6) + return -EINVAL; + + return free_bar; +} +EXPORT_SYMBOL_GPL(pci_epc_get_first_free_bar); + /** * pci_epc_get_features() - get the features supported by EPC * @epc: the features supported by *this* EPC device will be returned diff --git a/include/linux/pci-epc.h b/include/linux/pci-epc.h index 79fbcf94e14d..dc3513a2f88a 100644 --- a/include/linux/pci-epc.h +++ b/include/linux/pci-epc.h @@ -180,6 +180,7 @@ int pci_epc_start(struct pci_epc *epc); void pci_epc_stop(struct pci_epc *epc); const struct pci_epc_features *pci_epc_get_features(struct pci_epc *epc, u8 func_no); +int pci_epc_get_first_free_bar(const struct pci_epc_features *epc_features); struct pci_epc *pci_epc_get(const char *epc_name); void pci_epc_put(struct pci_epc *epc);