Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp411939pxj; Tue, 18 May 2021 06:16:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKvlWdotX63OS7ni0LMlft9plopIU99BLHL9jVgf6cWFYtMmlQbZoXdti4X+IYcmVvq0ZQ X-Received: by 2002:a5d:64c6:: with SMTP id f6mr7126048wri.18.1621343768188; Tue, 18 May 2021 06:16:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621343768; cv=none; d=google.com; s=arc-20160816; b=kSYohAXuAX1v4j6uFnJ3Vbu0P/mzkamSgmM266Vuo86teOHkHUcXnvPaifeCw1DZo+ Uf7rPlbXmdlcT4VgutNCkRxnan5ARKdg2M2xEPgzTzIWhvAN/lpiU+ve8N0HevBvOucY wtlD9KLGXO+JcFRoF4cv6rhXVOy27852q1w0X71ozp51itBHc2flHIETwNJhPOd1L0ef RRvg+whbSht50XyoWvY8gjIMC5BPoxt6FBrHmbsocT3Sq+Bc+GggQbsOX/9iIH11pCDe nkVTI6YhitgSmYML1tMADwF2YIq/p1ttc8z3UtHTWgvPzDsMK7hHNTYFSGgiClkKUmCZ pJ6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=H+1eUi1wZw3rxF7C7Rk+BQu01i8BIuuH+/47C4Bio1c=; b=k3C/Wc99Q10SPNtH8E1OtJ6aoEGgO5hfdOsKhf1eExpl4+cA1Ev3oEJGQ3w3T2TBO+ r3fAEuZSqy/A+zoUhs7Nmuq+AmwvnkHkN7lISQIMll1+wUeizd7hGFfjs2nqYJ0nW8qu wIJUOgnAo223osKaFEoS3ZEY4JBIJ8EKKXzQPhU7IFW9Dd2wo07pTK6ypco1dDmjlJ7f +09rTNRkZSVoe8Xeq59kOyKkTTSSZrKkQknFT+yp+IJhGPOp+NS54GnSQFc5eMBOZQt4 VmJjHLLbhI5fg75gZ8v2w9dQ4PgATKGJNuXX6Kq/KBOtS4Vkl68VZys+GqvhApjUJije 8GGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2ojTj14s; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id op24si16036607ejb.278.2021.05.18.06.15.44; Tue, 18 May 2021 06:16:08 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=2ojTj14s; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243900AbhEQPgL (ORCPT + 99 others); Mon, 17 May 2021 11:36:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:57662 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244550AbhEQPVT (ORCPT ); Mon, 17 May 2021 11:21:19 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id BA95161C86; Mon, 17 May 2021 14:34:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621262072; bh=u/xNXHQeeuK5IA8QPMCNpd+Hs2XXTZxB9m4f+qzaEQY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2ojTj14stzycAEB2jRouiyBgjDd36moANPVw6iqnfjo3TNOml9FpLLY9Col8FknNH uyFSxT5HZu+rxIETG49wtXjsdoaSJar9xiUg23xBpRLx1zdgqUCnyCOOp4d9gnCr65 hpGXdquiy/e/wZz4zKhQlkv2z4A0EAMOHzHIYXD8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kishon Vijay Abraham I , Lorenzo Pieralisi , Bjorn Helgaas , Sasha Levin Subject: [PATCH 5.10 107/289] PCI: endpoint: Make *_get_first_free_bar() take into account 64 bit BAR Date: Mon, 17 May 2021 16:00:32 +0200 Message-Id: <20210517140308.776324066@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140305.140529752@linuxfoundation.org> References: <20210517140305.140529752@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kishon Vijay Abraham I [ Upstream commit 959a48d0eac0321948c9f3d1707ba22c100e92d5 ] 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. Link: https://lore.kernel.org/r/20210201195809.7342-3-kishon@ti.com Signed-off-by: Kishon Vijay Abraham I Signed-off-by: Lorenzo Pieralisi Signed-off-by: Bjorn Helgaas Signed-off-by: Sasha Levin --- 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.30.2