From nobody Thu Oct 2 17:02:10 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A4A4B2F549F; Mon, 15 Sep 2025 09:15:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757927723; cv=none; b=D1ctABXYOLH3vQcBynnc357DvtSw5mreju7UZGQvTkMr8lc8SmPRXPtYMG8Bg74J8LCG1gipsU8Cy8ufuU8edPHK6enKkH4ovpsiK06tfuk6iI0SSHqp/vD68F6MCXJc2/KWtHB3MDsTgxIi1LMaAWrk+XIq5052X67hKPCQqZ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757927723; c=relaxed/simple; bh=h/Xhf1+IdqyzVV9Qr0HMdfiRWshhu3XbN9mZnzNd18A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=NKNbw3VAJ/vJ/J7uyMB7iv5+3YBgkTI9/QBazbxFQRJgM6Z93PWdsc11F5xvlwI30mnDuYwDC1sh7SZAFj+I7TLWpjMxNSa4D1yGWXHyEpGFw4MzKXAsftHQHT0/M1QuaavjWkzzZKJsPy9n/OcraAZxhve1olmhMzRyHJwOmoo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=hY24+JRj; arc=none smtp.client-ip=198.175.65.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="hY24+JRj" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1757927722; x=1789463722; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=h/Xhf1+IdqyzVV9Qr0HMdfiRWshhu3XbN9mZnzNd18A=; b=hY24+JRj8PzwYhZ2T08Chu2k4pphGv64T6gTtq4dEAgZo4GCFtD6n6lg nnkgj+RBYYtGAkYS9S9BrwkfsEHzqxvbS1Fobs6v+cLUf+APmGPopLhwE kPCZ9DEIQpunzt4iPLa0Pm5HC1sPVboPA1Cv4EbSRJ+2L/F0Itbzmng/N 6RjS90ZxZz2jO5ZALzvqEvyLtBZLrzVZiToQpmWpKlai9Jpwnq/g+gflO d4OKDm6wPYdgh1pkmfgquw9BY7GgZEYRR5iJG6rJa4Izn81j2bc5PiZy/ XpwQkDR0SmnYIj++5L8F5hwpbtWCo+dX3FJw93Wph/LRGvqWi27GRQdma Q==; X-CSE-ConnectionGUID: nmpSumq8Tjeob9DJGJ+tJA== X-CSE-MsgGUID: YS/dER3oR/uTCAh8CfIN0w== X-IronPort-AV: E=McAfee;i="6800,10657,11553"; a="59870357" X-IronPort-AV: E=Sophos;i="6.18,265,1751266800"; d="scan'208";a="59870357" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Sep 2025 02:15:21 -0700 X-CSE-ConnectionGUID: G+ni6SSzSXmX6MDly/yb9g== X-CSE-MsgGUID: gyrD8VVoReCu83iTq4IYpQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.18,265,1751266800"; d="scan'208";a="178917829" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.245.39]) by fmviesa005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Sep 2025 02:15:13 -0700 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: linux-pci@vger.kernel.org, Bjorn Helgaas , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , =?UTF-8?q?Christian=20K=C3=B6nig?= , =?UTF-8?q?Micha=C5=82=20Winiarski?= , Alex Deucher , amd-gfx@lists.freedesktop.org, David Airlie , dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org, Jani Nikula , Joonas Lahtinen , Lucas De Marchi , Rodrigo Vivi , Simona Vetter , Tvrtko Ursulin , ?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , "Michael J . Ruhl" , linux-kernel@vger.kernel.org Cc: linux-doc@vger.kernel.org, =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH v2 05/11] PCI: Add pci_rebar_size_supported() helper Date: Mon, 15 Sep 2025 12:13:52 +0300 Message-Id: <20250915091358.9203-6-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250915091358.9203-1-ilpo.jarvinen@linux.intel.com> References: <20250915091358.9203-1-ilpo.jarvinen@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Many callers of pci_rebar_get_possible_sizes() are interested in finding out if a particular BAR Size (PCIe r6.2 sec. 7.8.6.3) is supported by the particular BAR. Add pci_rebar_size_supported() into PCI core to make it easy for the drivers to determine if the BAR Size is supported or not. Use the new function in pci_resize_resource() and in pci_iov_vf_bar_set_size(). Signed-off-by: Ilpo J=C3=A4rvinen Reviewed-by: Christian K=C3=B6nig Reviewed-by: Andi Shyti --- drivers/pci/iov.c | 7 +------ drivers/pci/rebar.c | 25 +++++++++++++++++++------ include/linux/pci.h | 1 + 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index ac4375954c94..51844a9176a0 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -1334,7 +1334,6 @@ EXPORT_SYMBOL_GPL(pci_sriov_configure_simple); */ int pci_iov_vf_bar_set_size(struct pci_dev *dev, int resno, int size) { - u32 sizes; int ret; =20 if (!pci_resource_is_iov(resno)) @@ -1343,11 +1342,7 @@ int pci_iov_vf_bar_set_size(struct pci_dev *dev, int= resno, int size) if (pci_iov_is_memory_decoding_enabled(dev)) return -EBUSY; =20 - sizes =3D pci_rebar_get_possible_sizes(dev, resno); - if (!sizes) - return -ENOTSUPP; - - if (!(sizes & BIT(size))) + if (!pci_rebar_size_supported(dev, resno, size)) return -EINVAL; =20 ret =3D pci_rebar_set_size(dev, resno, size); diff --git a/drivers/pci/rebar.c b/drivers/pci/rebar.c index b1bd24a72bcc..81e01cbadde7 100644 --- a/drivers/pci/rebar.c +++ b/drivers/pci/rebar.c @@ -3,6 +3,7 @@ * PCI Resizable BAR Extended Capability handling. */ =20 +#include #include #include #include @@ -124,6 +125,23 @@ u32 pci_rebar_get_possible_sizes(struct pci_dev *pdev,= int bar) } EXPORT_SYMBOL(pci_rebar_get_possible_sizes); =20 +/** + * pci_rebar_size_supported - check if size is supported for BAR + * @pdev: PCI device + * @bar: BAR to check + * @size: size as defined in the PCIe spec (0=3D1MB, 31=3D128TB) + * + * Return: %true if @bar is resizable and @size is a supported, otherwise + * %false. + */ +bool pci_rebar_size_supported(struct pci_dev *pdev, int bar, int size) +{ + u64 sizes =3D pci_rebar_get_possible_sizes(pdev, bar); + + return BIT(size) & sizes; +} +EXPORT_SYMBOL_GPL(pci_rebar_size_supported); + /** * pci_rebar_get_current_size - get the current size of a Resizable BAR * @pdev: PCI device @@ -231,7 +249,6 @@ int pci_resize_resource(struct pci_dev *dev, int resno,= int size) struct resource *res =3D pci_resource_n(dev, resno); struct pci_host_bridge *host; int old, ret; - u32 sizes; =20 /* Check if we must preserve the firmware's resource assignment */ host =3D pci_find_host_bridge(dev->bus); @@ -245,11 +262,7 @@ int pci_resize_resource(struct pci_dev *dev, int resno= , int size) if (pci_resize_is_memory_decoding_enabled(dev, resno)) return -EBUSY; =20 - sizes =3D pci_rebar_get_possible_sizes(dev, resno); - if (!sizes) - return -ENOTSUPP; - - if (!(sizes & BIT(size))) + if (!pci_rebar_size_supported(dev, resno, size)) return -EINVAL; =20 old =3D pci_rebar_get_current_size(dev, resno); diff --git a/include/linux/pci.h b/include/linux/pci.h index 6f0c31290675..917c3b897739 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1423,6 +1423,7 @@ void pci_release_resource(struct pci_dev *dev, int re= sno); int pci_rebar_bytes_to_size(u64 bytes); resource_size_t pci_rebar_size_to_bytes(int size); u32 pci_rebar_get_possible_sizes(struct pci_dev *pdev, int bar); +bool pci_rebar_size_supported(struct pci_dev *pdev, int bar, int size); int __must_check pci_resize_resource(struct pci_dev *dev, int i, int size); =20 int pci_select_bars(struct pci_dev *dev, unsigned long flags); --=20 2.39.5