From: Frank Li <Frank.Li@nxp.com>
To: "Manivannan Sadhasivam" <manivannan.sadhasivam@linaro.org>,
"Krzysztof Wilczyński" <kw@linux.com>,
"Kishon Vijay Abraham I" <kishon@kernel.org>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Arnd Bergmann" <arnd@arndb.de>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
"Thomas Gleixner" <tglx@linutronix.de>,
"Anup Patel" <apatel@ventanamicro.com>,
"Marc Zyngier" <maz@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org,
imx@lists.linux.dev, Niklas Cassel <cassel@kernel.org>,
dlemoal@kernel.org, jdmason@kudzu.us,
linux-arm-kernel@lists.infradead.org,
Frank Li <Frank.Li@nxp.com>
Subject: [PATCH v10 4/7] PCI: endpoint: Add pci_epf_align_inbound_addr() helper for address alignment
Date: Wed, 04 Dec 2024 18:25:54 -0500 [thread overview]
Message-ID: <20241204-ep-msi-v10-4-87c378dbcd6d@nxp.com> (raw)
In-Reply-To: <20241204-ep-msi-v10-0-87c378dbcd6d@nxp.com>
Introduce the helper function pci_epf_align_inbound_addr() to adjust
addresses according to PCI BAR alignment requirements, converting addresses
into base and offset values.
Signed-off-by: Frank Li <Frank.Li@nxp.com>
---
Change form v9 to v10
- none
change from v8 to v9
- pci_epf_align_inbound_addr(), base and off must be not NULL
- rm pci_epf_align_inbound_addr_lo_hi()
change from v7 to v8
- change name to pci_epf_align_inbound_addr()
- update comment said only need for memory, which not allocated by
pci_epf_alloc_space().
change from v6 to v7
- new patch
---
drivers/pci/endpoint/pci-epf-core.c | 44 +++++++++++++++++++++++++++++++++++++
include/linux/pci-epf.h | 3 +++
2 files changed, 47 insertions(+)
diff --git a/drivers/pci/endpoint/pci-epf-core.c b/drivers/pci/endpoint/pci-epf-core.c
index 8fa2797d4169a..d7a80f9c1e661 100644
--- a/drivers/pci/endpoint/pci-epf-core.c
+++ b/drivers/pci/endpoint/pci-epf-core.c
@@ -464,6 +464,50 @@ struct pci_epf *pci_epf_create(const char *name)
}
EXPORT_SYMBOL_GPL(pci_epf_create);
+/**
+ * pci_epf_align_inbound_addr() - Get base address and offset that match BAR's
+ * alignment requirement
+ * @epf: the EPF device
+ * @addr: the address of the memory
+ * @bar: the BAR number corresponding to map addr
+ * @base: return base address, which match BAR's alignment requirement.
+ * @off: return offset.
+ *
+ * Helper function to convert input 'addr' to base and offset, which match
+ * BAR's alignment requirement.
+ *
+ * The pci_epf_alloc_space() function already accounts for alignment. This is
+ * primarily intended for use with other memory regions not allocated by
+ * pci_epf_alloc_space(), such as peripheral register spaces or the trigger
+ * address for a platform MSI controller.
+ */
+int pci_epf_align_inbound_addr(struct pci_epf *epf, enum pci_barno bar,
+ u64 addr, u64 *base, size_t *off)
+{
+ const struct pci_epc_features *epc_features;
+ u64 align;
+
+ if (!base || !off)
+ return -EINVAL;
+
+ epc_features = pci_epc_get_features(epf->epc, epf->func_no, epf->vfunc_no);
+ if (!epc_features) {
+ dev_err(&epf->dev, "epc_features not implemented\n");
+ return -EOPNOTSUPP;
+ }
+
+ align = epc_features->align;
+ align = align ? align : 128;
+ if (epc_features->bar[bar].type == BAR_FIXED)
+ align = max(epc_features->bar[bar].fixed_size, align);
+
+ *base = round_down(addr, align);
+ *off = addr & (align - 1);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(pci_epf_align_inbound_addr);
+
static void pci_epf_dev_release(struct device *dev)
{
struct pci_epf *epf = to_pci_epf(dev);
diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h
index 5374e6515ffa0..2847d195433bf 100644
--- a/include/linux/pci-epf.h
+++ b/include/linux/pci-epf.h
@@ -238,6 +238,9 @@ void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar,
enum pci_epc_interface_type type);
void pci_epf_free_space(struct pci_epf *epf, void *addr, enum pci_barno bar,
enum pci_epc_interface_type type);
+
+int pci_epf_align_inbound_addr(struct pci_epf *epf, enum pci_barno bar,
+ u64 addr, u64 *base, size_t *off);
int pci_epf_bind(struct pci_epf *epf);
void pci_epf_unbind(struct pci_epf *epf);
int pci_epf_add_vepf(struct pci_epf *epf_pf, struct pci_epf *epf_vf);
--
2.34.1
next prev parent reply other threads:[~2024-12-04 23:33 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-04 23:25 [PATCH v10 0/7] PCI: EP: Add RC-to-EP doorbell with platform MSI controller Frank Li
2024-12-04 23:25 ` [PATCH v10 1/7] irqchip/gic-v3-its: Avoid overwriting msi_prepare callback if provided by msi_domain_info Frank Li
2024-12-04 23:25 ` [PATCH v10 2/7] PCI: endpoint: Add RC-to-EP doorbell support using platform MSI controller Frank Li
2024-12-04 23:25 ` [PATCH v10 3/7] PCI: endpoint: pci-ep-msi: Add MSI address/data pair mutable check Frank Li
2024-12-05 13:10 ` Thomas Gleixner
2024-12-05 14:56 ` Frank Li
2024-12-05 18:05 ` Thomas Gleixner
2024-12-04 23:25 ` Frank Li [this message]
2024-12-04 23:25 ` [PATCH v10 5/7] PCI: endpoint: pci-epf-test: Add doorbell test support Frank Li
2024-12-04 23:25 ` [PATCH v10 6/7] misc: pci_endpoint_test: Add doorbell test case Frank Li
2024-12-04 23:25 ` [PATCH v10 7/7] tools: PCI: Add 'B' option for test doorbell Frank Li
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=20241204-ep-msi-v10-4-87c378dbcd6d@nxp.com \
--to=frank.li@nxp.com \
--cc=apatel@ventanamicro.com \
--cc=arnd@arndb.de \
--cc=bhelgaas@google.com \
--cc=cassel@kernel.org \
--cc=dlemoal@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=imx@lists.linux.dev \
--cc=jdmason@kudzu.us \
--cc=kishon@kernel.org \
--cc=kw@linux.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=manivannan.sadhasivam@linaro.org \
--cc=maz@kernel.org \
--cc=rafael@kernel.org \
--cc=tglx@linutronix.de \
/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