From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: Oleksandr Dmytryshyn <oleksandr.dmytryshyn@globallogic.com>
Cc: xen-devel@lists.xenproject.org,
Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Subject: Re: swiotlb-xen question
Date: Fri, 4 Apr 2014 12:26:56 -0400 [thread overview]
Message-ID: <20140404162656.GM19478@phenom.dumpdata.com> (raw)
In-Reply-To: <CAN58jiu9sXdfoN-PmuuDAx4ZKrzjGfOcDNhqyAVkz1Gj-7104Q@mail.gmail.com>
On Fri, Apr 04, 2014 at 02:30:22PM +0300, Oleksandr Dmytryshyn wrote:
> >From f52bafc1ba51324ca5044df22778aacf815c59bf Mon Sep 17 00:00:00 2001
> From: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
> Date: Fri, 4 Apr 2014 12:16:27 +0300
> Subject: [PATCH] swiotlb-xen: implement xen_swiotlb_dma_mmap callback
>
> This function creates userspace mapping for the DMA-coherent memory.
>
> Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
> Signed-off-by: Oleksandr Dmytryshyn <oleksandr.dmytryshyn@globallogic.com>
>
> diff --git a/arch/arm/xen/mm.c b/arch/arm/xen/mm.c
> index b0e77de..91408b1 100644
> --- a/arch/arm/xen/mm.c
> +++ b/arch/arm/xen/mm.c
> @@ -48,6 +48,7 @@ static struct dma_map_ops xen_swiotlb_dma_ops = {
> .sync_sg_for_device = xen_swiotlb_sync_sg_for_device,
> .map_sg = xen_swiotlb_map_sg_attrs,
> .unmap_sg = xen_swiotlb_unmap_sg_attrs,
> + .mmap = xen_swiotlb_dma_mmap,
> .map_page = xen_swiotlb_map_page,
> .unmap_page = xen_swiotlb_unmap_page,
> .dma_supported = xen_swiotlb_dma_supported,
> diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
> index 5403855..acf0c06 100644
> --- a/drivers/xen/swiotlb-xen.c
> +++ b/drivers/xen/swiotlb-xen.c
> @@ -407,6 +407,42 @@ dma_addr_t xen_swiotlb_map_page(struct device
> *dev, struct page *page,
> EXPORT_SYMBOL_GPL(xen_swiotlb_map_page);
>
> /*
> + * Create userspace mapping for the DMA-coherent memory.
> + */
> +int xen_swiotlb_dma_mmap(struct device *dev, struct vm_area_struct *vma,
> + void *cpu_addr, dma_addr_t dma_addr, size_t size,
> + struct dma_attrs *attrs)
Wow. Your editor ate all the nice tabs and spaces. Could you
please also run
scripts/checkpatch.pl on the patch and fix the issues it would
complain about.
Thank you!
> +{
> + int ret = -ENXIO;
> +#ifdef CONFIG_MMU
> + unsigned long nr_vma_pages = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
> + unsigned long nr_pages = PAGE_ALIGN(size) >> PAGE_SHIFT;
> + unsigned long pfn = PFN_DOWN(xen_bus_to_phys(dma_addr));
> + unsigned long off = vma->vm_pgoff;
> + pgprot_t prot = vma->vm_page_prot;
> +
> + prot = dma_get_attr(DMA_ATTR_WRITE_COMBINE, attrs) ?
> + pgprot_writecombine(prot) :
> + pgprot_dmacoherent(prot);
> +
> + vma->vm_page_prot = prot;
> +
> + if (dma_mmap_from_coherent(dev, vma, cpu_addr, size, &ret))
> + return ret;
> +
> + if (off < nr_pages && nr_vma_pages <= (nr_pages - off)) {
> + ret = remap_pfn_range(vma, vma->vm_start,
> + pfn + off,
> + vma->vm_end - vma->vm_start,
> + vma->vm_page_prot);
> + }
> +#endif /* CONFIG_MMU */
> +
> + return ret;
> +}
> +EXPORT_SYMBOL_GPL(xen_swiotlb_dma_mmap);
> +
> +/*
> * Unmap a single streaming mode DMA translation. The dma_addr and size must
> * match what was provided for in a previous xen_swiotlb_map_page call. All
> * other usages are undefined.
> diff --git a/include/xen/swiotlb-xen.h b/include/xen/swiotlb-xen.h
> index 7b64465..930fa94 100644
> --- a/include/xen/swiotlb-xen.h
> +++ b/include/xen/swiotlb-xen.h
> @@ -15,6 +15,11 @@ xen_swiotlb_free_coherent(struct device *hwdev, size_t size,
> void *vaddr, dma_addr_t dma_handle,
> struct dma_attrs *attrs);
>
> +extern int
> +xen_swiotlb_dma_mmap(struct device *dev, struct vm_area_struct *vma,
> + void *cpu_addr, dma_addr_t dma_addr, size_t size,
> + struct dma_attrs *attrs);
> +
> extern dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,
> unsigned long offset, size_t size,
> enum dma_data_direction dir,
next prev parent reply other threads:[~2014-04-04 16:27 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-26 10:35 swiotlb-xen question Oleksandr Dmytryshyn
2014-03-26 11:15 ` Ian Campbell
2014-03-26 14:46 ` Konrad Rzeszutek Wilk
2014-03-26 14:58 ` Oleksandr Dmytryshyn
2014-03-26 18:49 ` Stefano Stabellini
2014-03-26 19:44 ` Konrad Rzeszutek Wilk
2014-03-27 10:11 ` Oleksandr Dmytryshyn
2014-04-01 14:27 ` Oleksandr Dmytryshyn
2014-04-03 10:51 ` Stefano Stabellini
2014-04-03 11:43 ` Oleksandr Dmytryshyn
2014-04-03 12:52 ` Stefano Stabellini
2014-04-03 12:59 ` Oleksandr Dmytryshyn
2014-04-04 11:20 ` Oleksandr Dmytryshyn
2014-04-04 11:26 ` Stefano Stabellini
2014-04-04 11:30 ` Oleksandr Dmytryshyn
2014-04-04 16:26 ` Konrad Rzeszutek Wilk [this message]
2014-04-07 6:34 ` Oleksandr Dmytryshyn
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=20140404162656.GM19478@phenom.dumpdata.com \
--to=konrad.wilk@oracle.com \
--cc=oleksandr.dmytryshyn@globallogic.com \
--cc=stefano.stabellini@eu.citrix.com \
--cc=xen-devel@lists.xenproject.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.