From: Oleksandr Andrushchenko <andr2000@gmail.com>
To: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org,
dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org,
jgross@suse.com, boris.ostrovsky@oracle.com,
konrad.wilk@oracle.com
Cc: daniel.vetter@intel.com, andr2000@gmail.com,
dongwon.kim@intel.com, matthew.d.roper@intel.com,
Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
Subject: [Xen-devel][RFC 2/3] xen/grant-table: Extend API to work with DMA buffers
Date: Thu, 17 May 2018 11:26:03 +0300 [thread overview]
Message-ID: <20180517082604.14828-3-andr2000@gmail.com> (raw)
In-Reply-To: <20180517082604.14828-1-andr2000@gmail.com>
From: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
---
drivers/xen/grant-table.c | 49 +++++++++++++++++++++++++++++++++++++++
include/xen/grant_table.h | 7 ++++++
2 files changed, 56 insertions(+)
diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c
index bb36b1e1dbcc..c27bcc420575 100644
--- a/drivers/xen/grant-table.c
+++ b/drivers/xen/grant-table.c
@@ -729,6 +729,55 @@ void gnttab_free_pages(int nr_pages, struct page **pages)
}
EXPORT_SYMBOL(gnttab_free_pages);
+int gnttab_dma_alloc_pages(struct device *dev, bool coherent,
+ int nr_pages, struct page **pages,
+ void **vaddr, dma_addr_t *dev_bus_addr)
+{
+ int i;
+ int ret;
+
+ ret = alloc_dma_xenballooned_pages(dev, coherent, nr_pages, pages,
+ vaddr, dev_bus_addr);
+ if (ret < 0)
+ return ret;
+
+ for (i = 0; i < nr_pages; i++) {
+#if BITS_PER_LONG < 64
+ struct xen_page_foreign *foreign;
+
+ foreign = kzalloc(sizeof(*foreign), GFP_KERNEL);
+ if (!foreign) {
+ gnttab_dma_free_pages(dev, flags, nr_pages, pages,
+ *vaddr, *dev_bus_addr);
+ return -ENOMEM;
+ }
+ set_page_private(pages[i], (unsigned long)foreign);
+#endif
+ SetPagePrivate(pages[i]);
+ }
+ return 0;
+}
+EXPORT_SYMBOL(gnttab_dma_alloc_pages);
+
+void gnttab_dma_free_pages(struct device *dev, bool coherent,
+ int nr_pages, struct page **pages,
+ void *vaddr, dma_addr_t dev_bus_addr)
+{
+ int i;
+
+ for (i = 0; i < nr_pages; i++) {
+ if (PagePrivate(pages[i])) {
+#if BITS_PER_LONG < 64
+ kfree((void *)page_private(pages[i]));
+#endif
+ ClearPagePrivate(pages[i]);
+ }
+ }
+ free_dma_xenballooned_pages(dev, coherent, nr_pages, pages,
+ vaddr, dev_bus_addr);
+}
+EXPORT_SYMBOL(gnttab_dma_free_pages);
+
/* Handling of paged out grant targets (GNTST_eagain) */
#define MAX_DELAY 256
static inline void
diff --git a/include/xen/grant_table.h b/include/xen/grant_table.h
index 34b1379f9777..20ee2b5ba965 100644
--- a/include/xen/grant_table.h
+++ b/include/xen/grant_table.h
@@ -195,6 +195,13 @@ void gnttab_free_auto_xlat_frames(void);
int gnttab_alloc_pages(int nr_pages, struct page **pages);
void gnttab_free_pages(int nr_pages, struct page **pages);
+int gnttab_dma_alloc_pages(struct device *dev, bool coherent,
+ int nr_pages, struct page **pages,
+ void **vaddr, dma_addr_t *dev_bus_addr);
+void gnttab_dma_free_pages(struct device *dev, bool coherent,
+ int nr_pages, struct page **pages,
+ void *vaddr, dma_addr_t dev_bus_addr);
+
int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops,
struct gnttab_map_grant_ref *kmap_ops,
struct page **pages, unsigned int count);
--
2.17.0
next prev parent reply other threads:[~2018-05-17 8:26 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-17 8:26 [Xen-devel][RFC 0/3] dma-buf support for gntdev Oleksandr Andrushchenko
2018-05-17 8:26 ` [Xen-devel][RFC 1/3] xen/balloon: Allow allocating DMA buffers Oleksandr Andrushchenko
2018-05-18 22:04 ` [Xen-devel] [RFC " Boris Ostrovsky
2018-05-21 5:40 ` Oleksandr Andrushchenko
2018-05-21 16:35 ` Boris Ostrovsky
2018-05-21 17:32 ` Oleksandr Andrushchenko
2018-05-21 18:53 ` Boris Ostrovsky
2018-05-21 19:13 ` Oleksandr Andrushchenko
2018-05-21 20:36 ` Boris Ostrovsky
2018-05-22 5:55 ` Oleksandr Andrushchenko
2018-05-22 14:33 ` Boris Ostrovsky
2018-05-22 15:00 ` Oleksandr Andrushchenko
2018-05-22 18:02 ` Boris Ostrovsky
2018-05-22 18:27 ` Oleksandr Andrushchenko
2018-05-22 19:09 ` Boris Ostrovsky
2018-05-17 8:26 ` Oleksandr Andrushchenko [this message]
2018-05-18 22:19 ` [Xen-devel][RFC 2/3] xen/grant-table: Extend API to work with " Boris Ostrovsky
2018-05-21 5:44 ` Oleksandr Andrushchenko
2018-05-17 8:26 ` [Xen-devel][RFC 3/3] xen/gntdev: Add support for Linux dma buffers Oleksandr Andrushchenko
2018-05-21 21:31 ` Dongwon Kim
2018-05-22 5:57 ` Oleksandr Andrushchenko
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=20180517082604.14828-3-andr2000@gmail.com \
--to=andr2000@gmail.com \
--cc=boris.ostrovsky@oracle.com \
--cc=daniel.vetter@intel.com \
--cc=dongwon.kim@intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=jgross@suse.com \
--cc=konrad.wilk@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=matthew.d.roper@intel.com \
--cc=oleksandr_andrushchenko@epam.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox