lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250915-vntb_msi_doorbell-v2-1-ca71605e3444@nxp.com>
Date: Mon, 15 Sep 2025 18:22:44 -0400
From: Frank Li <Frank.Li@....com>
To: Manivannan Sadhasivam <mani@...nel.org>, 
 Krzysztof WilczyƄski <kwilczynski@...nel.org>, 
 Kishon Vijay Abraham I <kishon@...nel.org>, 
 Bjorn Helgaas <bhelgaas@...gle.com>, Jon Mason <jdmason@...zu.us>, 
 Dave Jiang <dave.jiang@...el.com>, Allen Hubbe <allenbh@...il.com>
Cc: linux-pci@...r.kernel.org, linux-kernel@...r.kernel.org, 
 ntb@...ts.linux.dev, imx@...ts.linux.dev, Frank Li <Frank.Li@....com>
Subject: [PATCH v2 1/3] PCI: endpoint: Add helper function
 pci_epf_get_bar_required_size()

Introduce pci_epf_get_bar_required_size() to retrieve the required BAR
size. Prepare for adding support to set an MMIO address to a specific BAR.

No functional changes.

Signed-off-by: Frank Li <Frank.Li@....com>
---
change in v2
- new patch
---
 drivers/pci/endpoint/pci-epf-core.c | 52 ++++++++++++++++++++++++-------------
 1 file changed, 34 insertions(+), 18 deletions(-)

diff --git a/drivers/pci/endpoint/pci-epf-core.c b/drivers/pci/endpoint/pci-epf-core.c
index d54e18872aefc07c655c94c104a347328ff7a432..4281067d4a62da6fbf6c2fb807b0f1b5afd1f45b 100644
--- a/drivers/pci/endpoint/pci-epf-core.c
+++ b/drivers/pci/endpoint/pci-epf-core.c
@@ -248,6 +248,36 @@ void pci_epf_free_space(struct pci_epf *epf, void *addr, enum pci_barno bar,
 }
 EXPORT_SYMBOL_GPL(pci_epf_free_space);
 
+static size_t
+pci_epf_get_bar_required_size(struct pci_epf *epf, size_t size,
+			      enum pci_barno bar,
+			      const struct pci_epc_features *epc_features,
+			      enum pci_epc_interface_type type)
+{
+	u64 bar_fixed_size = epc_features->bar[bar].fixed_size;
+
+	if (size < 128)
+		size = 128;
+
+	/* According to PCIe base spec, min size for a resizable BAR is 1 MB. */
+	if (epc_features->bar[bar].type == BAR_RESIZABLE && size < SZ_1M)
+		size = SZ_1M;
+
+	if (epc_features->bar[bar].type == BAR_FIXED && bar_fixed_size) {
+		if (size > bar_fixed_size) {
+			dev_err(&epf->dev,
+				"requested BAR size is larger than fixed size\n");
+			return 0;
+		}
+		size = bar_fixed_size;
+	} else {
+		/* BAR size must be power of two */
+		size = roundup_pow_of_two(size);
+	}
+
+	return size;
+}
+
 /**
  * pci_epf_alloc_space() - allocate memory for the PCI EPF register space
  * @epf: the EPF device to whom allocate the memory
@@ -264,7 +294,6 @@ void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar,
 			  const struct pci_epc_features *epc_features,
 			  enum pci_epc_interface_type type)
 {
-	u64 bar_fixed_size = epc_features->bar[bar].fixed_size;
 	size_t aligned_size, align = epc_features->align;
 	struct pci_epf_bar *epf_bar;
 	dma_addr_t phys_addr;
@@ -272,24 +301,11 @@ void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar,
 	struct device *dev;
 	void *space;
 
-	if (size < 128)
-		size = 128;
-
-	/* According to PCIe base spec, min size for a resizable BAR is 1 MB. */
-	if (epc_features->bar[bar].type == BAR_RESIZABLE && size < SZ_1M)
-		size = SZ_1M;
+	size = pci_epf_get_bar_required_size(epf, size, bar,
+					     epc_features, type);
 
-	if (epc_features->bar[bar].type == BAR_FIXED && bar_fixed_size) {
-		if (size > bar_fixed_size) {
-			dev_err(&epf->dev,
-				"requested BAR size is larger than fixed size\n");
-			return NULL;
-		}
-		size = bar_fixed_size;
-	} else {
-		/* BAR size must be power of two */
-		size = roundup_pow_of_two(size);
-	}
+	if (size == 0)
+		return NULL;
 
 	/*
 	 * Allocate enough memory to accommodate the iATU alignment

-- 
2.34.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ