From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: linux-pci@vger.kernel.org, "Bjorn Helgaas" <bhelgaas@google.com>,
"Krzysztof Wilczyński" <kw@linux.com>,
"Christian König" <christian.koenig@amd.com>,
"Michał Winiarski" <michal.winiarski@intel.com>,
"Alex Deucher" <alexander.deucher@amd.com>,
amd-gfx@lists.freedesktop.org, "David Airlie" <airlied@gmail.com>,
dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org,
intel-xe@lists.freedesktop.org,
"Jani Nikula" <jani.nikula@linux.intel.com>,
"Joonas Lahtinen" <joonas.lahtinen@linux.intel.com>,
"Lucas De Marchi" <lucas.demarchi@intel.com>,
"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Tvrtko Ursulin" <tursulin@ursulin.net>,
?UTF-8?q?Thomas=20Hellstr=C3=B6m?=
<thomas.hellstrom@linux.intel.com>,
linux-kernel@vger.kernel.org
Cc: linux-doc@vger.kernel.org,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Subject: [PATCH 02/11] PCI: Cleanup pci_rebar_bytes_to_size() and move into rebar.c
Date: Thu, 11 Sep 2025 10:55:56 +0300 [thread overview]
Message-ID: <20250911075605.5277-3-ilpo.jarvinen@linux.intel.com> (raw)
In-Reply-To: <20250911075605.5277-1-ilpo.jarvinen@linux.intel.com>
Move pci_rebar_bytes_to_size() from include/linux/pci.h into rebar.c as
it does not look very trivial and is not expected to be performance
critical.
Convert literals to use a newly added PCI_REBAR_MIN_SIZE define.
Also add kernel doc for the function as the function is exported.
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
drivers/pci/rebar.c | 23 +++++++++++++++++++++++
include/linux/pci.h | 10 +++-------
2 files changed, 26 insertions(+), 7 deletions(-)
diff --git a/drivers/pci/rebar.c b/drivers/pci/rebar.c
index b87cfa6fb3ef..961bd43be02b 100644
--- a/drivers/pci/rebar.c
+++ b/drivers/pci/rebar.c
@@ -7,11 +7,34 @@
#include <linux/errno.h>
#include <linux/export.h>
#include <linux/ioport.h>
+#include <linux/log2.h>
#include <linux/pci.h>
+#include <linux/sizes.h>
#include <linux/types.h>
#include "pci.h"
+#define PCI_REBAR_MIN_SIZE ((resource_size_t)SZ_1M)
+
+/**
+ * pci_rebar_bytes_to_size - Convert size in bytes to PCI BAR Size
+ * @bytes: size in bytes
+ *
+ * Convert bytes to BAR Size in Resizable BAR Capability (PCIe r6.2,
+ * sec. 7.8.6.3).
+ *
+ * Return: BAR Size as defined in the PCIe spec (0=1MB, bit 31=128TB).
+ */
+int pci_rebar_bytes_to_size(u64 bytes)
+{
+ int rebar_minsize = ilog2(PCI_REBAR_MIN_SIZE);
+
+ bytes = roundup_pow_of_two(bytes);
+
+ return max(ilog2(bytes), rebar_minsize) - rebar_minsize;
+}
+EXPORT_SYMBOL_GPL(pci_rebar_bytes_to_size);
+
void pci_rebar_init(struct pci_dev *pdev)
{
pdev->rebar_cap = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_REBAR);
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 59876de13860..894e9020b07d 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1418,16 +1418,12 @@ void pcibios_reset_secondary_bus(struct pci_dev *dev);
void pci_update_resource(struct pci_dev *dev, int resno);
int __must_check pci_assign_resource(struct pci_dev *dev, int i);
void pci_release_resource(struct pci_dev *dev, int resno);
-static inline int pci_rebar_bytes_to_size(u64 bytes)
-{
- bytes = roundup_pow_of_two(bytes);
-
- /* Return BAR size as defined in the resizable BAR specification */
- return max(ilog2(bytes), 20) - 20;
-}
+/* Resizable BAR related routines */
+int pci_rebar_bytes_to_size(u64 bytes);
u32 pci_rebar_get_possible_sizes(struct pci_dev *pdev, int bar);
int __must_check pci_resize_resource(struct pci_dev *dev, int i, int size);
+
int pci_select_bars(struct pci_dev *dev, unsigned long flags);
bool pci_device_is_present(struct pci_dev *pdev);
void pci_ignore_hotplug(struct pci_dev *dev);
--
2.39.5
next prev parent reply other threads:[~2025-09-11 7:56 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-11 7:55 [PATCH 00/11] PCI: Resizable BAR improvements Ilpo Järvinen
2025-09-11 7:55 ` [PATCH 01/11] PCI: Move Resizable BAR code into rebar.c Ilpo Järvinen
2025-09-11 7:55 ` Ilpo Järvinen [this message]
2025-09-11 17:25 ` [PATCH 02/11] PCI: Cleanup pci_rebar_bytes_to_size() and move " Ruhl, Michael J
2025-09-11 7:55 ` [PATCH 03/11] PCI: Move pci_rebar_size_to_bytes() and export it Ilpo Järvinen
2025-09-11 7:55 ` [PATCH 04/11] PCI: Improve Resizable BAR functions kernel doc Ilpo Järvinen
2025-09-11 8:24 ` Christian König
2025-09-11 8:59 ` Ilpo Järvinen
2025-09-11 9:08 ` Christian König
2025-09-11 20:58 ` Randy Dunlap
2025-09-11 7:55 ` [PATCH 05/11] PCI: Add pci_rebar_size_supported() helper Ilpo Järvinen
2025-09-11 8:27 ` Christian König
2025-09-11 7:56 ` [PATCH 06/11] drm/i915/gt: Use pci_rebar_size_supported() Ilpo Järvinen
2025-09-11 7:56 ` [PATCH 07/11] drm/xe/vram: Use PCI rebar helpers in resize_vram_bar() Ilpo Järvinen
2025-09-11 7:56 ` [PATCH 08/11] PCI: Add pci_rebar_get_max_size() Ilpo Järvinen
2025-09-11 7:56 ` [PATCH 09/11] drm/xe/vram: Use pci_rebar_get_max_size() Ilpo Järvinen
2025-09-11 7:56 ` [PATCH 10/11] drm/amdgpu: " Ilpo Järvinen
2025-09-11 7:56 ` [PATCH 11/11] PCI: Convert BAR sizes bitmasks to u64 Ilpo Järvinen
2025-09-11 8:35 ` [PATCH 00/11] PCI: Resizable BAR improvements Christian König
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250911075605.5277-3-ilpo.jarvinen@linux.intel.com \
--to=ilpo.jarvinen@linux.intel.com \
--cc=airlied@gmail.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=bhelgaas@google.com \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=jani.nikula@linux.intel.com \
--cc=joonas.lahtinen@linux.intel.com \
--cc=kw@linux.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lucas.demarchi@intel.com \
--cc=michal.winiarski@intel.com \
--cc=rodrigo.vivi@intel.com \
--cc=simona@ffwll.ch \
--cc=thomas.hellstrom@linux.intel.com \
--cc=tursulin@ursulin.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox