From patchwork Thu Sep 26 11:29:21 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: 174467 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp1920389ill; Thu, 26 Sep 2019 04:31:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqzwtLZTAh+Lo/ybLsQMYwj14MSA04Jtk0JzlqGBJkMc25bW04k1dYYRCeCgkR443zG8kogS X-Received: by 2002:a17:906:9703:: with SMTP id k3mr2515173ejx.159.1569497483463; Thu, 26 Sep 2019 04:31:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569497483; cv=none; d=google.com; s=arc-20160816; b=nJDRYZoRixA6LilkvQXKWyop1vlsn3C57BqNliQr15AU+0Nry0B9lwcX6H5nqu6m3A UaRJ3Fc/YGjlroApzu/2IsWjb19gzcfIaBDPNgqRcN7HHJ4x2mn2Uyxpj20bNU+QymJt PNTtJIxz1pZ4bTdEBnody4dNpttf7ZLVw3afvKSFDQOmoiA0tSf7mkoUysv3G6cvMv2O bzgBW/nx7AlLNCQ56xT+ytiO3e8Kcco/SNXhZYYbjlA0Cn8FjAPYVXNzjgGdc0y7GNpD nEUzrjdWpRSn7vPx06Jr9++aLx4saXKdnxXlqJUAr+j7U5txVlgICy93hgEO/RbzKTLI teFQ== 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=UYksCV0D7qfdaCmxHa2KanDKAyhdBu55FlMew1p3wwk9CDqM8Iza1ULXi2iJkfSVky 24cMyxrcQM0KlJGh1iuehzRpaQAUS0SMeXKBl4ljOK4C/U5QP3We0U5WvT9hgxGDVqpJ qXS+C8JjCV33WE7kK/j/QG2mVsyP9McYkHskFg0kdBDu33358dwJcOrIAVQKQQsGP8X8 8o/EaHsf0n7AowgyneF18kDnUrNhNObICmfxiFjeUqM2eC0OdBP/0SnFLrfhlBlCQisz JLQenBOVkkBTOelFO+RZkJkqkz8pSVFQ8oeJATwIfZDoojUE4Ypw+RIk/r1hisJSKMcA PRTQ== 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 devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-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 s21si855087eja.226.2019.09.26.04.31.23; Thu, 26 Sep 2019 04:31:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of devicetree-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 devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-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 S1726519AbfIZLbT (ORCPT + 8 others); Thu, 26 Sep 2019 07:31:19 -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 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@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(-) -- 2.17.1 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);