Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4092322pxb; Mon, 1 Feb 2021 12:12:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJx7sU/w9Ghj/mSA9ILT8r/sm04L3wWiX2Ro5Ad9t7j3AyWhPIB2dVBNWyV0lOwSGfEkBu2X X-Received: by 2002:aa7:db4e:: with SMTP id n14mr20494190edt.101.1612210358267; Mon, 01 Feb 2021 12:12:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612210358; cv=none; d=google.com; s=arc-20160816; b=U/S6WjDKW9BWNEPj1Pq6wSrEs7DR7vuolrip/Z87guGXoFgdgbSlaghOc/jtmjSbPG ib8DRJAjbY7qcs2swL4ALq51AqdfvW6vA0+Vf8t/WZxylTltE6p7fAhMBZXCLHibQ0xv TrCtxaeEaRhc2B6KW96+uwVukOPX3+kam2ZOqlG8trUcVrdDB4lJbYZ+k9lZnkamJVk+ dN9jacMthYdjt56bCAaUFHlaUepZuHqGnAlL3ovJdWNqR1XUQ10re/PTGWaq9OGqBSIN B6hsVXHDk7AIxXFsY6l4CSRy0J2LXkvJ5l97hBjDX2XeL/ujCG+FQVUzAvQaBp1o0ySu trrA== 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=re6MIOXxybv+Yv493YnPwG3dJx5wl6L6fPllpFd+bzs=; b=uWIvkA6nLcRyeUxEnG7Z11PEifviNHr6AZzN4bfACev8OpkV1/T85lMtchJquKKqg/ rXawutiEk0EddaiBeM8f/tYKvS+Gw7Stc2E+VMml3yUsKkpa7ku1Fb6EF+Ezg1dL4rhM kbzlJOvZ7jmxhshiKT3omy+YMhhNvp3mBuNlQQVyOjJgjKJgRXjmn+LqAzQhQ05PvPiR kQ/8qKGi/zgSzscRe3jZ3tejM6kjz+oQU0jMsHv0C3RENSO5WHkmkplWGvgc1XHBXS/0 DeMEKu5lxS/v7+WmD4+HyvYOSjn5gKO9KBaEanGR5x+nanMdbigP/uSnOOMgNXdboiO5 pjOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=RvD4q44q; 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 y9si1021861edp.33.2021.02.01.12.12.13; Mon, 01 Feb 2021 12:12:38 -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=RvD4q44q; 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 S232658AbhBAT7r (ORCPT + 99 others); Mon, 1 Feb 2021 14:59:47 -0500 Received: from fllv0015.ext.ti.com ([198.47.19.141]:39416 "EHLO fllv0015.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232637AbhBAT7g (ORCPT ); Mon, 1 Feb 2021 14:59:36 -0500 Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 111JwR1H037066; Mon, 1 Feb 2021 13:58:27 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1612209507; bh=re6MIOXxybv+Yv493YnPwG3dJx5wl6L6fPllpFd+bzs=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=RvD4q44qy/aKbSMO/+ifHbOiFN6hPgWQswZ7cuEN0nli7lvFOtz3xWK60Fh060AaW HTg38glErZ9+jwcGwCrlWpiGDkJarzZnoxmTCxb83iWeYr4SOQI0he4suQnjQN8048 VS2bX8vEWb/LNXey350/OHGohxCZHXtsxNgOp80o= Received: from DLEE106.ent.ti.com (dlee106.ent.ti.com [157.170.170.36]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 111JwRkv036460 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 1 Feb 2021 13:58:27 -0600 Received: from DLEE113.ent.ti.com (157.170.170.24) 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.1979.3; Mon, 1 Feb 2021 13:58:27 -0600 Received: from fllv0039.itg.ti.com (10.64.41.19) by DLEE113.ent.ti.com (157.170.170.24) 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; Mon, 1 Feb 2021 13:58:27 -0600 Received: from a0393678-ssd.dal.design.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id 111JwAQZ085814; Mon, 1 Feb 2021 13:58:22 -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 v11 02/17] PCI: endpoint: Make *_get_first_free_bar() take into account 64 bit BAR Date: Tue, 2 Feb 2021 01:27:54 +0530 Message-ID: <20210201195809.7342-3-kishon@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210201195809.7342-1-kishon@ti.com> References: <20210201195809.7342-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 pci_epc_get_first_free_bar() uses only "reserved_bar" member in epc_features to get the first unreserved BAR. However if the reserved BAR is also a 64-bit BAR, then the next BAR shouldn't be returned (since 64-bit BAR uses two BARs). Make pci_epc_get_first_free_bar() take into account 64 bit BAR while returning the first free unreserved BAR. Signed-off-by: Kishon Vijay Abraham I --- drivers/pci/endpoint/pci-epc-core.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c index cadd3db0cbb0..25e57672e1a1 100644 --- a/drivers/pci/endpoint/pci-epc-core.c +++ b/drivers/pci/endpoint/pci-epc-core.c @@ -93,12 +93,20 @@ EXPORT_SYMBOL_GPL(pci_epc_get); unsigned int pci_epc_get_first_free_bar(const struct pci_epc_features *epc_features) { - int free_bar; + unsigned long free_bar; if (!epc_features) return 0; - free_bar = ffz(epc_features->reserved_bar); + /* Find if the reserved BAR is also a 64-bit BAR */ + free_bar = epc_features->reserved_bar & epc_features->bar_fixed_64bit; + + /* Set the adjacent bit if the reserved BAR is also a 64-bit BAR */ + free_bar <<= 1; + free_bar |= epc_features->reserved_bar; + + /* Now find the free BAR */ + free_bar = ffz(free_bar); if (free_bar > 5) return 0; -- 2.17.1