From patchwork Mon Jan 14 11:15:05 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: 155442 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3536650jaa; Mon, 14 Jan 2019 03:16:37 -0800 (PST) X-Google-Smtp-Source: ALg8bN7M2EK99nsAeciXUWUK3jVPv1L+AN9F74T0FhS8lw48/VP1gilUejKNxMUPKDbyFExCgubY X-Received: by 2002:a63:6c48:: with SMTP id h69mr21405047pgc.139.1547464597824; Mon, 14 Jan 2019 03:16:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547464597; cv=none; d=google.com; s=arc-20160816; b=P6SYI8vXo83Sr492slP1zkEvp5Ei+RBpFqrxmT271nC0T1eEZW9nPWJX7qxorMp4l2 TPmDXnSpZF5W41JyvsA6EXCJvfwNdT3+HmsEItCa0aUYLq4fFs/vfXeeaavOxKllWaZa lfICmBofNZYdT/v222EFeyBxrXyqAqDdOBzTeeSwxX1ggoVwMeAcA3I8S3ozsLuEL3cH XXOqgcoZBP8pdiFWhlbgf/emN9RM9/pfOce23ulKgKaQAz0wnwc0X2dn2EKwKpisW5+o K61GfzoN/zbrxEFIuxanMI7Nsp0+2mszxF5SS1zWCFjGBCl2Uvlp1yUXOM3YXTVlLxoV vbnw== 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=em3nniSoZzdBLeQmpghEPOG4OiEKNFjH6jr71UxEv8A=; b=roT1W1sDXq5nkhRSHXbjkMTUh0XWx5S/6J2qV3/jNbWM7L4CUZT9YHDrdDI0X1yMTt dx4ophhDYcGeHaD0MABzLdgetV4Fr62sGXBbZMz6U7qtwO7CrvO+D5eb8GdwYdzH4aO1 /FJ9D1X7nUFWZTc7TRd2jXAaKqwg17uOOj7E7QPTyPjodvqVPav2vqgjdFFPKyee2Zag f+v51sSrBkN+vEL55brekYnKjn4o31frgm7P1G/K14lQQf1wFngie8NEHMteBA4MIuRH POJahuNMx5J33Y6sw6k+hm2m1WbDkBZeBwAWvAhlCsyQ0s2W6CPb/3xngF1/cKzRuMpk uhEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b="XC/wStIe"; 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 87si144516pfs.7.2019.01.14.03.16.37; Mon, 14 Jan 2019 03:16:37 -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="XC/wStIe"; 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 S1726809AbfANLQg (ORCPT + 31 others); Mon, 14 Jan 2019 06:16:36 -0500 Received: from lelv0143.ext.ti.com ([198.47.23.248]:45416 "EHLO lelv0143.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726779AbfANLQd (ORCPT ); Mon, 14 Jan 2019 06:16:33 -0500 Received: from lelv0266.itg.ti.com ([10.180.67.225]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id x0EBGA2j112722; Mon, 14 Jan 2019 05:16:10 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1547464570; bh=em3nniSoZzdBLeQmpghEPOG4OiEKNFjH6jr71UxEv8A=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=XC/wStIeqY/aZOLxjVCCHhzcxgJmCYr7rNxHZ4r1v2r+KUP4nUPg8q9RSdjTXq+FQ DOtgyp4sImkH1gyp0anajHNyO8CVuB3qIHWGUUknwDOpWJhzlGfPqE3mCrczzrb/84 Er3TaP098NTS5pAFzuqaIQ65RFRMAuzjCShTFsIk= Received: from DFLE105.ent.ti.com (dfle105.ent.ti.com [10.64.6.26]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x0EBGAqp023949 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 14 Jan 2019 05:16:10 -0600 Received: from DFLE110.ent.ti.com (10.64.6.31) by DFLE105.ent.ti.com (10.64.6.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10; Mon, 14 Jan 2019 05:16:10 -0600 Received: from dflp32.itg.ti.com (10.64.6.15) by DFLE110.ent.ti.com (10.64.6.31) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1591.10 via Frontend Transport; Mon, 14 Jan 2019 05:16:10 -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 x0EBFd1Z011560; Mon, 14 Jan 2019 05:16:07 -0600 From: Kishon Vijay Abraham I To: Kishon Vijay Abraham I , Lorenzo Pieralisi , Gustavo Pimentel , Alan Douglas , Shawn Lin , Heiko Stuebner CC: Bjorn Helgaas , Jingoo Han , , , , , Subject: [PATCH v2 07/15] PCI: endpoint: Add helper to get first unreserved BAR Date: Mon, 14 Jan 2019 16:45:05 +0530 Message-ID: <20190114111513.21618-8-kishon@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190114111513.21618-1-kishon@ti.com> References: <20190114111513.21618-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 | 23 +++++++++++++++++++++++ include/linux/pci-epc.h | 2 ++ 2 files changed, 25 insertions(+) -- 2.17.1 diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c index 5a099479d9ab..e4712a0f249c 100644 --- a/drivers/pci/endpoint/pci-epc-core.c +++ b/drivers/pci/endpoint/pci-epc-core.c @@ -83,6 +83,29 @@ 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. For any incorrect value in reserved_bar return '0'. + */ +unsigned 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 > 5) + return 0; + + 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..94e1ecff98ce 100644 --- a/include/linux/pci-epc.h +++ b/include/linux/pci-epc.h @@ -180,6 +180,8 @@ 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); +unsigned 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);