From: Jim Quinlan via iommu <iommu@lists.linux-foundation.org>
To: james.quinlan@broadcom.com,
Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Cc: open list <linux-kernel@vger.kernel.org>,
"open list:DMA MAPPING HELPERS"
<iommu@lists.linux-foundation.org>,
Robin Murphy <robin.murphy@arm.com>,
Christoph Hellwig <hch@lst.de>
Subject: [PATCH 10/15] dma-direct: Invoke dma offset func if needed
Date: Tue, 19 May 2020 16:34:08 -0400 [thread overview]
Message-ID: <20200519203419.12369-11-james.quinlan@broadcom.com> (raw)
In-Reply-To: <20200519203419.12369-1-james.quinlan@broadcom.com>
Just like dma_pfn_offset, another offset is added to
the dma/phys translation if there happen to be multiple
regions that have different mapping offsets.
Signed-off-by: Jim Quinlan <james.quinlan@broadcom.com>
---
include/linux/dma-direct.h | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/include/linux/dma-direct.h b/include/linux/dma-direct.h
index 24b8684aa21d..825a773dbbc3 100644
--- a/include/linux/dma-direct.h
+++ b/include/linux/dma-direct.h
@@ -15,6 +15,14 @@ static inline dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
{
dma_addr_t dev_addr = (dma_addr_t)paddr;
+#ifdef CONFIG_DMA_PFN_OFFSET_MAP
+ if (unlikely(dev->dma_offset_map)) {
+ unsigned long dma_pfn_offset = dma_pfn_offset_frm_phys_addr(
+ dev->dma_offset_map, paddr);
+
+ return dev_addr - ((dma_addr_t)dma_pfn_offset << PAGE_SHIFT);
+ }
+#endif
return dev_addr - ((dma_addr_t)dev->dma_pfn_offset << PAGE_SHIFT);
}
@@ -22,6 +30,14 @@ static inline phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dev_addr)
{
phys_addr_t paddr = (phys_addr_t)dev_addr;
+#ifdef CONFIG_DMA_PFN_OFFSET_MAP
+ if (unlikely(dev->dma_offset_map)) {
+ unsigned long dma_pfn_offset = dma_pfn_offset_frm_dma_addr(
+ dev->dma_offset_map, dev_addr);
+
+ return paddr + ((phys_addr_t)dma_pfn_offset << PAGE_SHIFT);
+ }
+#endif
return paddr + ((phys_addr_t)dev->dma_pfn_offset << PAGE_SHIFT);
}
#endif /* !CONFIG_ARCH_HAS_PHYS_TO_DMA */
--
2.17.1
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
next prev parent reply other threads:[~2020-05-19 20:49 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-19 20:33 [PATCH 00/15] PCI: brcmstb: enable PCIe for STB chips Jim Quinlan via iommu
2020-05-19 20:34 ` [PATCH 09/15] device core: Add ability to handle multiple dma offsets Jim Quinlan via iommu
2020-05-20 5:43 ` Greg Kroah-Hartman
2020-05-20 13:50 ` Jim Quinlan via iommu
2020-05-20 14:03 ` Greg Kroah-Hartman
2020-05-20 14:08 ` Jim Quinlan via iommu
2020-05-20 11:28 ` Nicolas Saenz Julienne
2020-05-22 14:31 ` Jim Quinlan via iommu
2020-05-20 17:42 ` Christoph Hellwig
2020-05-20 18:26 ` Jim Quinlan via iommu
2020-05-20 22:36 ` Dan Williams
2020-05-21 8:19 ` Christoph Hellwig
2020-05-19 20:34 ` Jim Quinlan via iommu [this message]
2020-05-20 16:15 ` [PATCH 00/15] PCI: brcmstb: enable PCIe for STB chips Bjorn Helgaas
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=20200519203419.12369-11-james.quinlan@broadcom.com \
--to=iommu@lists.linux-foundation.org \
--cc=hch@lst.de \
--cc=james.quinlan@broadcom.com \
--cc=linux-kernel@vger.kernel.org \
--cc=nsaenzjulienne@suse.de \
--cc=robin.murphy@arm.com \
/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;
as well as URLs for NNTP newsgroup(s).