From: Shunsuke Mie <mie@igel.co.jp>
To: Jingoo Han <jingoohan1@gmail.com>
Cc: "Gustavo Pimentel" <gustavo.pimentel@synopsys.com>,
"Lorenzo Pieralisi" <lpieralisi@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Wilczyński" <kw@linux.com>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Manivannan Sadhasivam" <mani@kernel.org>,
"Kishon Vijay Abraham I" <kishon@kernel.org>,
"Shunsuke Mie" <mie@igel.co.jp>,
"Kunihiko Hayashi" <hayashi.kunihiko@socionext.com>,
"Hou Zhiqiang" <Zhiqiang.Hou@nxp.com>,
"Frank Li" <Frank.Li@nxp.com>, "Li Chen" <lchen@ambarella.com>,
linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [RFC PATCH 1/3] PCI: endpoint: support an alignment aware map/unmaping
Date: Fri, 13 Jan 2023 18:03:48 +0900 [thread overview]
Message-ID: <20230113090350.1103494-2-mie@igel.co.jp> (raw)
In-Reply-To: <20230113090350.1103494-1-mie@igel.co.jp>
Add an align_mem operation to the EPC ops, which function is used to
pci_epc_map/unmap_addr(). These change to enable mapping for any alignment
restriction of EPC. The map function maps an aligned memory to include a
requested memory region.
Signed-off-by: Shunsuke Mie <mie@igel.co.jp>
---
drivers/pci/endpoint/pci-epc-core.c | 57 ++++++++++++++++++++++++-----
include/linux/pci-epc.h | 10 +++--
2 files changed, 53 insertions(+), 14 deletions(-)
diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c
index 2542196e8c3d..60d586e05e7d 100644
--- a/drivers/pci/endpoint/pci-epc-core.c
+++ b/drivers/pci/endpoint/pci-epc-core.c
@@ -430,8 +430,12 @@ EXPORT_SYMBOL_GPL(pci_epc_set_msix);
* Invoke to unmap the CPU address from PCI address.
*/
void pci_epc_unmap_addr(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
- phys_addr_t phys_addr)
+ phys_addr_t phys_addr, void __iomem *virt_addr, size_t size)
{
+ u64 aligned_phys;
+ void __iomem *aligned_virt;
+ size_t offset;
+
if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions)
return;
@@ -441,9 +445,22 @@ void pci_epc_unmap_addr(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
if (!epc->ops->unmap_addr)
return;
+ if (epc->ops->align_mem) {
+ mutex_lock(&epc->lock);
+ aligned_phys = epc->ops->align_mem(epc, phys_addr, &size);
+ mutex_unlock(&epc->lock);
+ } else {
+ aligned_phys = phys_addr;
+ }
+
+ offset = phys_addr - aligned_phys;
+ aligned_virt = virt_addr - offset;
+
mutex_lock(&epc->lock);
- epc->ops->unmap_addr(epc, func_no, vfunc_no, phys_addr);
+ epc->ops->unmap_addr(epc, func_no, vfunc_no, aligned_phys);
mutex_unlock(&epc->lock);
+
+ pci_epc_mem_free_addr(epc, aligned_phys, aligned_virt, size);
}
EXPORT_SYMBOL_GPL(pci_epc_unmap_addr);
@@ -458,26 +475,46 @@ EXPORT_SYMBOL_GPL(pci_epc_unmap_addr);
*
* Invoke to map CPU address with PCI address.
*/
-int pci_epc_map_addr(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
- phys_addr_t phys_addr, u64 pci_addr, size_t size)
+void __iomem *pci_epc_map_addr(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
+ u64 pci_addr, phys_addr_t *phys_addr, size_t size)
{
int ret;
+ u64 aligned_addr;
+ size_t offset;
+ void __iomem *virt_addr;
if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions)
- return -EINVAL;
+ return ERR_PTR(-EINVAL);
if (vfunc_no > 0 && (!epc->max_vfs || vfunc_no > epc->max_vfs[func_no]))
- return -EINVAL;
+ return ERR_PTR(-EINVAL);
if (!epc->ops->map_addr)
- return 0;
+ return ERR_PTR(-ENOPTSUPP);
+
+ if (epc->ops->align_mem) {
+ mutex_lock(&epc->lock);
+ aligned_addr = epc->ops->align_mem(epc, pci_addr, &size);
+ mutex_unlock(&epc->lock);
+ } else {
+ aligned_addr = pci_addr;
+ }
+
+ offset = pci_addr - aligned_addr;
+
+ virt_addr = pci_epc_mem_alloc_addr(epc, phys_addr, size);
+ if (!virt_addr)
+ return ERR_PTR(-ENOMEM);
mutex_lock(&epc->lock);
- ret = epc->ops->map_addr(epc, func_no, vfunc_no, phys_addr, pci_addr,
- size);
+ ret = epc->ops->map_addr(epc, func_no, vfunc_no, *phys_addr, aligned_addr, size);
mutex_unlock(&epc->lock);
+ if (ret)
+ return ERR_PTR(ret);
- return ret;
+ *phys_addr += offset;
+
+ return virt_addr + offset;
}
EXPORT_SYMBOL_GPL(pci_epc_map_addr);
diff --git a/include/linux/pci-epc.h b/include/linux/pci-epc.h
index a48778e1a4ee..8f29161bce80 100644
--- a/include/linux/pci-epc.h
+++ b/include/linux/pci-epc.h
@@ -84,6 +84,7 @@ struct pci_epc_ops {
phys_addr_t phys_addr, u8 interrupt_num,
u32 entry_size, u32 *msi_data,
u32 *msi_addr_offset);
+ u64 (*align_mem)(struct pci_epc *epc, u64 addr, size_t *size);
int (*start)(struct pci_epc *epc);
void (*stop)(struct pci_epc *epc);
const struct pci_epc_features* (*get_features)(struct pci_epc *epc,
@@ -218,11 +219,12 @@ int pci_epc_set_bar(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
struct pci_epf_bar *epf_bar);
void pci_epc_clear_bar(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
struct pci_epf_bar *epf_bar);
-int pci_epc_map_addr(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
- phys_addr_t phys_addr,
- u64 pci_addr, size_t size);
+void __iomem *pci_epc_map_addr(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
+ u64 pci_addr, phys_addr_t *phys_addr,
+ size_t size);
void pci_epc_unmap_addr(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
- phys_addr_t phys_addr);
+ phys_addr_t phys_addr, void __iomem *virt_addr,
+ size_t size);
int pci_epc_set_msi(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
u8 interrupts);
int pci_epc_get_msi(struct pci_epc *epc, u8 func_no, u8 vfunc_no);
--
2.25.1
next prev parent reply other threads:[~2023-01-13 9:05 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-13 9:03 [RFC PATCH 0/3] Deal with alignment restriction on EP side Shunsuke Mie
2023-01-13 9:03 ` Shunsuke Mie [this message]
2023-01-17 20:41 ` [RFC PATCH 1/3] PCI: endpoint: support an alignment aware map/unmaping Bjorn Helgaas
2023-01-18 10:33 ` Shunsuke Mie
2023-06-01 15:06 ` Kishon Vijay Abraham I
2023-06-01 23:43 ` Damien Le Moal
2023-06-02 9:42 ` Shunsuke Mie
2023-06-02 12:21 ` Damien Le Moal
2023-06-05 10:34 ` Shunsuke Mie
2023-06-02 11:39 ` Kishon Vijay Abraham I
2023-06-02 12:10 ` Damien Le Moal
2023-06-05 7:54 ` Manivannan Sadhasivam
2023-01-13 9:03 ` [RFC PATCH 2/3] PCI: dwc: support align_mem() callback for pci_epc_epc Shunsuke Mie
2023-01-13 9:03 ` [RFC PATCH 3/3] PCI: endpoint: support pci_epc_mem_map/unmap API changes Shunsuke Mie
2023-01-17 20:32 ` [RFC PATCH 0/3] Deal with alignment restriction on EP side Bjorn Helgaas
2023-01-18 10:17 ` Shunsuke Mie
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=20230113090350.1103494-2-mie@igel.co.jp \
--to=mie@igel.co.jp \
--cc=Frank.Li@nxp.com \
--cc=Zhiqiang.Hou@nxp.com \
--cc=bhelgaas@google.com \
--cc=gustavo.pimentel@synopsys.com \
--cc=hayashi.kunihiko@socionext.com \
--cc=jingoohan1@gmail.com \
--cc=kishon@kernel.org \
--cc=kw@linux.com \
--cc=lchen@ambarella.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lpieralisi@kernel.org \
--cc=mani@kernel.org \
--cc=robh@kernel.org \
/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