Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp1936392ybn; Thu, 26 Sep 2019 04:35:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqxFGMMOi9RN/GaCeKpZL6oMYMZccqWuGjB5slU6bDfE/ssX02jp/SiLCR4Wk2pyAHClXW80 X-Received: by 2002:a17:906:7687:: with SMTP id o7mr2609130ejm.213.1569497746627; Thu, 26 Sep 2019 04:35:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569497746; cv=none; d=google.com; s=arc-20160816; b=nyz9FCTUb/GhbhdEpCRHrYJY9+HQJbDb4vJhY+3zzWE6ec1rU0qunCMb6DwxLNE0J9 Ejc3mQw40hvd8TYiaY/PChkDAhvBYf4N8TIM61t3mZPWHk+JFCTg9Grx30F0NZR77a8w I2CCX2LQ4sqRSBc7LXdzUsQ1Hc0xykO5FU3A8K5u8rI1T3/+VBITS8e5kvzI2CBEYpPl 9d2zcwL2Ps3+YB0/AYacjDoblfFKxuYRDF0PXG5t6smKJ7ClTA+YEBAJClKs+68XFHzN BeTwdULbgUr8+2WYQ9D/x12RpKErOuitYj5D0o1IbbPoCDcgZwuvYcrcjSiIHApr2N0m NecQ== 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=WN6zQz22SKDDpOt20zGyRCD7tAdq3OZmA5JGj+CItiA=; b=RefHRm9+TRSKoGfU2X8RkiE4+S1+YAji7Bn2Bw9qvQzxUrw48XuvJF9Ega8jwOlzmS TVcLIR1rKiFTCNIPz1R3PvEZza4I0TjlMtc3xin4gFEntT74svF0DcJOPgMfOnN7AkIY AUBzOkaxjUYlddMargJSEq9Wqm9P4tHenuP2HSxE2cJk37foPAo6JedZrFAtKt6OB1n7 0f5xYM02LCcXKgThLjYlWER8/O/Y4rbsK/66g30zCEBC8U9T+0O48p3M7Xz3p3t4TGN1 urBDFTOXI7DhPrxmsgouMfP9FLOJIVp7muO32c7soOUVJGcn9HAzr3sm0f4nJCkLBKPl wcig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=RQUZDPwN; 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 ns21si845840ejb.167.2019.09.26.04.35.23; Thu, 26 Sep 2019 04:35:46 -0700 (PDT) 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=RQUZDPwN; 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 S1726527AbfIZLbV (ORCPT + 99 others); Thu, 26 Sep 2019 07:31:21 -0400 Received: from fllv0015.ext.ti.com ([198.47.19.141]:51010 "EHLO fllv0015.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726505AbfIZLbT (ORCPT ); Thu, 26 Sep 2019 07:31:19 -0400 Received: from lelv0265.itg.ti.com ([10.180.67.224]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id x8QBVC81042477; Thu, 26 Sep 2019 06:31:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1569497472; bh=WN6zQz22SKDDpOt20zGyRCD7tAdq3OZmA5JGj+CItiA=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=RQUZDPwN4ZiuygapbnHMM6deZpVpQm99D4Pe71h5eiPTyPWTKyOj6dBefH4bIrmA7 paBCgP16GiCPx8F+/1FYb0OoGYT9dRgYPdvF3L3Gs/j+1PPKsMGyOK7pmvt2nrWKzE p7SLqKsbrvoCAFhaj86YyiwJc7FhUgxoUpSR0t+g= Received: from DLEE106.ent.ti.com (dlee106.ent.ti.com [157.170.170.36]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x8QBVC84050400 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 26 Sep 2019 06:31:12 -0500 Received: from DLEE111.ent.ti.com (157.170.170.22) by DLEE106.ent.ti.com (157.170.170.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Thu, 26 Sep 2019 06:31:11 -0500 Received: from lelv0327.itg.ti.com (10.180.67.183) by DLEE111.ent.ti.com (157.170.170.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5 via Frontend Transport; Thu, 26 Sep 2019 06:31:04 -0500 Received: from a0393678ub.india.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0327.itg.ti.com (8.15.2/8.15.2) with ESMTP id x8QBUTk2069017; Thu, 26 Sep 2019 06:31:07 -0500 From: Kishon Vijay Abraham I To: Bjorn Helgaas , Jonathan Corbet , Rob Herring , Jon Mason , Dave Jiang , Allen Hubbe , Lorenzo Pieralisi CC: Mark Rutland , , , , , , Subject: [RFC PATCH 09/21] PCI: endpoint: Add helper API to get the 'next' unreserved BAR Date: Thu, 26 Sep 2019 16:59:21 +0530 Message-ID: <20190926112933.8922-10-kishon@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190926112933.8922-1-kishon@ti.com> References: <20190926112933.8922-1-kishon@ti.com> MIME-Version: 1.0 Content-Type: text/plain 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 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 7eae7dcaebf9..49bdff217777 100644 --- a/drivers/pci/endpoint/pci-epc-core.c +++ b/drivers/pci/endpoint/pci-epc-core.c @@ -147,17 +147,36 @@ EXPORT_SYMBOL_GPL(of_pci_epc_get_by_name); * 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; @@ -165,14 +184,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 ef6531af6ed2..993b1a55a239 100644 --- a/include/linux/pci-epc.h +++ b/include/linux/pci-epc.h @@ -200,6 +200,8 @@ const struct pci_epc_features *pci_epc_get_features(struct pci_epc *epc, u8 func_no, u8 vfunc_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); struct pci_epc *of_pci_epc_get(struct device_node *node, int index); -- 2.17.1