Re: [Xen-devel][PATCH v2 2/3] drm/xen-front: Use Xen common shared buffer implementation

From: Oleksandr Andrushchenko
Date: Thu Dec 13 2018 - 05:17:02 EST


bump

On 12/5/18 10:20 AM, Oleksandr Andrushchenko wrote:
Hello, Daniel!

Could you please ack/nack the patch, so either we can merge the

series or I can address your comments if any

Thank you,

Oleksandr

On 11/30/18 9:42 AM, Oleksandr Andrushchenko wrote:
From: Oleksandr Andrushchenko <oleksandr_andrushchenko@xxxxxxxx>

Use page directory based shared buffer implementation
now available as common code for Xen frontend drivers.

Remove flushing of shared buffer on page flip as this
workaround needs a proper fix.

Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@xxxxxxxx>
---
 drivers/gpu/drm/xen/Kconfig | 1 +
 drivers/gpu/drm/xen/Makefile | 1 -
 drivers/gpu/drm/xen/xen_drm_front.c | 65 ++--
 drivers/gpu/drm/xen/xen_drm_front_gem.c | 1 -
 drivers/gpu/drm/xen/xen_drm_front_shbuf.c | 414 ----------------------
 drivers/gpu/drm/xen/xen_drm_front_shbuf.h | 64 ----
 6 files changed, 26 insertions(+), 520 deletions(-)
 delete mode 100644 drivers/gpu/drm/xen/xen_drm_front_shbuf.c
 delete mode 100644 drivers/gpu/drm/xen/xen_drm_front_shbuf.h

diff --git a/drivers/gpu/drm/xen/Kconfig b/drivers/gpu/drm/xen/Kconfig
index 4cca160782ab..f969d486855d 100644
--- a/drivers/gpu/drm/xen/Kconfig
+++ b/drivers/gpu/drm/xen/Kconfig
@@ -12,6 +12,7 @@ config DRM_XEN_FRONTEND
ÂÂÂÂÂ select DRM_KMS_HELPER
ÂÂÂÂÂ select VIDEOMODE_HELPERS
ÂÂÂÂÂ select XEN_XENBUS_FRONTEND
+ÂÂÂ select XEN_FRONT_PGDIR_SHBUF
ÂÂÂÂÂ help
ÂÂÂÂÂÂÂ Choose this option if you want to enable a para-virtualized
ÂÂÂÂÂÂÂ frontend DRM/KMS driver for Xen guest OSes.
diff --git a/drivers/gpu/drm/xen/Makefile b/drivers/gpu/drm/xen/Makefile
index 712afff5ffc3..825905f67faa 100644
--- a/drivers/gpu/drm/xen/Makefile
+++ b/drivers/gpu/drm/xen/Makefile
@@ -4,7 +4,6 @@ drm_xen_front-objs := xen_drm_front.o \
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ xen_drm_front_kms.o \
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ xen_drm_front_conn.o \
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ xen_drm_front_evtchnl.o \
-ÂÂÂÂÂÂÂÂÂÂÂÂÂ xen_drm_front_shbuf.o \
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ xen_drm_front_cfg.o \
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ xen_drm_front_gem.o
 diff --git a/drivers/gpu/drm/xen/xen_drm_front.c b/drivers/gpu/drm/xen/xen_drm_front.c
index 6b6d5ab82ec3..4d3d36fc3a5d 100644
--- a/drivers/gpu/drm/xen/xen_drm_front.c
+++ b/drivers/gpu/drm/xen/xen_drm_front.c
@@ -19,6 +19,7 @@
 #include <xen/xen.h>
 #include <xen/xenbus.h>
 +#include <xen/xen-front-pgdir-shbuf.h>
 #include <xen/interface/io/displif.h>
  #include "xen_drm_front.h"
@@ -26,28 +27,20 @@
 #include "xen_drm_front_evtchnl.h"
 #include "xen_drm_front_gem.h"
 #include "xen_drm_front_kms.h"
-#include "xen_drm_front_shbuf.h"
  struct xen_drm_front_dbuf {
ÂÂÂÂÂ struct list_head list;
ÂÂÂÂÂ u64 dbuf_cookie;
ÂÂÂÂÂ u64 fb_cookie;
-ÂÂÂ struct xen_drm_front_shbuf *shbuf;
+
+ÂÂÂ struct xen_front_pgdir_shbuf shbuf;
 };
 -static int dbuf_add_to_list(struct xen_drm_front_info *front_info,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ struct xen_drm_front_shbuf *shbuf, u64 dbuf_cookie)
+static void dbuf_add_to_list(struct xen_drm_front_info *front_info,
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ struct xen_drm_front_dbuf *dbuf, u64 dbuf_cookie)
 {
-ÂÂÂ struct xen_drm_front_dbuf *dbuf;
-
-ÂÂÂ dbuf = kzalloc(sizeof(*dbuf), GFP_KERNEL);
-ÂÂÂ if (!dbuf)
-ÂÂÂÂÂÂÂ return -ENOMEM;
-
ÂÂÂÂÂ dbuf->dbuf_cookie = dbuf_cookie;
-ÂÂÂ dbuf->shbuf = shbuf;
ÂÂÂÂÂ list_add(&dbuf->list, &front_info->dbuf_list);
-ÂÂÂ return 0;
 }
  static struct xen_drm_front_dbuf *dbuf_get(struct list_head *dbuf_list,
@@ -62,15 +55,6 @@ static struct xen_drm_front_dbuf *dbuf_get(struct list_head *dbuf_list,
ÂÂÂÂÂ return NULL;
 }
 -static void dbuf_flush_fb(struct list_head *dbuf_list, u64 fb_cookie)
-{
-ÂÂÂ struct xen_drm_front_dbuf *buf, *q;
-
-ÂÂÂ list_for_each_entry_safe(buf, q, dbuf_list, list)
-ÂÂÂÂÂÂÂ if (buf->fb_cookie == fb_cookie)
-ÂÂÂÂÂÂÂÂÂÂÂ xen_drm_front_shbuf_flush(buf->shbuf);
-}
-
 static void dbuf_free(struct list_head *dbuf_list, u64 dbuf_cookie)
 {
ÂÂÂÂÂ struct xen_drm_front_dbuf *buf, *q;
@@ -78,8 +62,8 @@ static void dbuf_free(struct list_head *dbuf_list, u64 dbuf_cookie)
ÂÂÂÂÂ list_for_each_entry_safe(buf, q, dbuf_list, list)
ÂÂÂÂÂÂÂÂÂ if (buf->dbuf_cookie == dbuf_cookie) {
ÂÂÂÂÂÂÂÂÂÂÂÂÂ list_del(&buf->list);
-ÂÂÂÂÂÂÂÂÂÂÂ xen_drm_front_shbuf_unmap(buf->shbuf);
-ÂÂÂÂÂÂÂÂÂÂÂ xen_drm_front_shbuf_free(buf->shbuf);
+ÂÂÂÂÂÂÂÂÂÂÂ xen_front_pgdir_shbuf_unmap(&buf->shbuf);
+ÂÂÂÂÂÂÂÂÂÂÂ xen_front_pgdir_shbuf_free(&buf->shbuf);
ÂÂÂÂÂÂÂÂÂÂÂÂÂ kfree(buf);
ÂÂÂÂÂÂÂÂÂÂÂÂÂ break;
ÂÂÂÂÂÂÂÂÂ }
@@ -91,8 +75,8 @@ static void dbuf_free_all(struct list_head *dbuf_list)
 Â list_for_each_entry_safe(buf, q, dbuf_list, list) {
ÂÂÂÂÂÂÂÂÂ list_del(&buf->list);
-ÂÂÂÂÂÂÂ xen_drm_front_shbuf_unmap(buf->shbuf);
-ÂÂÂÂÂÂÂ xen_drm_front_shbuf_free(buf->shbuf);
+ÂÂÂÂÂÂÂ xen_front_pgdir_shbuf_unmap(&buf->shbuf);
+ÂÂÂÂÂÂÂ xen_front_pgdir_shbuf_free(&buf->shbuf);
ÂÂÂÂÂÂÂÂÂ kfree(buf);
ÂÂÂÂÂ }
 }
@@ -171,9 +155,9 @@ int xen_drm_front_dbuf_create(struct xen_drm_front_info *front_info,
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ u32 bpp, u64 size, struct page **pages)
 {
ÂÂÂÂÂ struct xen_drm_front_evtchnl *evtchnl;
-ÂÂÂ struct xen_drm_front_shbuf *shbuf;
+ÂÂÂ struct xen_drm_front_dbuf *dbuf;
ÂÂÂÂÂ struct xendispl_req *req;
-ÂÂÂ struct xen_drm_front_shbuf_cfg buf_cfg;
+ÂÂÂ struct xen_front_pgdir_shbuf_cfg buf_cfg;
ÂÂÂÂÂ unsigned long flags;
ÂÂÂÂÂ int ret;
 @@ -181,28 +165,29 @@ int xen_drm_front_dbuf_create(struct xen_drm_front_info *front_info,
ÂÂÂÂÂ if (unlikely(!evtchnl))
ÂÂÂÂÂÂÂÂÂ return -EIO;
 + dbuf = kzalloc(sizeof(*dbuf), GFP_KERNEL);
+ÂÂÂ if (!dbuf)
+ÂÂÂÂÂÂÂ return -ENOMEM;
+
+ÂÂÂ dbuf_add_to_list(front_info, dbuf, dbuf_cookie);
+
ÂÂÂÂÂ memset(&buf_cfg, 0, sizeof(buf_cfg));
ÂÂÂÂÂ buf_cfg.xb_dev = front_info->xb_dev;
+ÂÂÂ buf_cfg.num_pages = DIV_ROUND_UP(size, PAGE_SIZE);
ÂÂÂÂÂ buf_cfg.pages = pages;
-ÂÂÂ buf_cfg.size = size;
+ÂÂÂ buf_cfg.pgdir = &dbuf->shbuf;
ÂÂÂÂÂ buf_cfg.be_alloc = front_info->cfg.be_alloc;
 - shbuf = xen_drm_front_shbuf_alloc(&buf_cfg);
-ÂÂÂ if (IS_ERR(shbuf))
-ÂÂÂÂÂÂÂ return PTR_ERR(shbuf);
-
-ÂÂÂ ret = dbuf_add_to_list(front_info, shbuf, dbuf_cookie);
-ÂÂÂ if (ret < 0) {
-ÂÂÂÂÂÂÂ xen_drm_front_shbuf_free(shbuf);
-ÂÂÂÂÂÂÂ return ret;
-ÂÂÂ }
+ÂÂÂ ret = xen_front_pgdir_shbuf_alloc(&buf_cfg);
+ÂÂÂ if (ret < 0)
+ÂÂÂÂÂÂÂ goto fail_shbuf_alloc;
 Â mutex_lock(&evtchnl->u.req.req_io_lock);
 Â spin_lock_irqsave(&front_info->io_lock, flags);
ÂÂÂÂÂ req = be_prepare_req(evtchnl, XENDISPL_OP_DBUF_CREATE);
ÂÂÂÂÂ req->op.dbuf_create.gref_directory =
-ÂÂÂÂÂÂÂÂÂÂÂ xen_drm_front_shbuf_get_dir_start(shbuf);
+ xen_front_pgdir_shbuf_get_dir_start(&dbuf->shbuf);
ÂÂÂÂÂ req->op.dbuf_create.buffer_sz = size;
ÂÂÂÂÂ req->op.dbuf_create.dbuf_cookie = dbuf_cookie;
ÂÂÂÂÂ req->op.dbuf_create.width = width;
@@ -221,7 +206,7 @@ int xen_drm_front_dbuf_create(struct xen_drm_front_info *front_info,
ÂÂÂÂÂ if (ret < 0)
ÂÂÂÂÂÂÂÂÂ goto fail;
 - ret = xen_drm_front_shbuf_map(shbuf);
+ÂÂÂ ret = xen_front_pgdir_shbuf_map(&dbuf->shbuf);
ÂÂÂÂÂ if (ret < 0)
ÂÂÂÂÂÂÂÂÂ goto fail;
 @@ -230,6 +215,7 @@ int xen_drm_front_dbuf_create(struct xen_drm_front_info *front_info,
  fail:
ÂÂÂÂÂ mutex_unlock(&evtchnl->u.req.req_io_lock);
+fail_shbuf_alloc:
ÂÂÂÂÂ dbuf_free(&front_info->dbuf_list, dbuf_cookie);
ÂÂÂÂÂ return ret;
 }
@@ -358,7 +344,6 @@ int xen_drm_front_page_flip(struct xen_drm_front_info *front_info,
ÂÂÂÂÂ if (unlikely(conn_idx >= front_info->num_evt_pairs))
ÂÂÂÂÂÂÂÂÂ return -EINVAL;
 - dbuf_flush_fb(&front_info->dbuf_list, fb_cookie);
ÂÂÂÂÂ evtchnl = &front_info->evt_pairs[conn_idx].req;
 Â mutex_lock(&evtchnl->u.req.req_io_lock);
diff --git a/drivers/gpu/drm/xen/xen_drm_front_gem.c b/drivers/gpu/drm/xen/xen_drm_front_gem.c
index c85bfe7571cb..53be4c7dc0a4 100644
--- a/drivers/gpu/drm/xen/xen_drm_front_gem.c
+++ b/drivers/gpu/drm/xen/xen_drm_front_gem.c
@@ -22,7 +22,6 @@
 #include <xen/balloon.h>
  #include "xen_drm_front.h"
-#include "xen_drm_front_shbuf.h"
  struct xen_gem_object {
ÂÂÂÂÂ struct drm_gem_object base;
diff --git a/drivers/gpu/drm/xen/xen_drm_front_shbuf.c b/drivers/gpu/drm/xen/xen_drm_front_shbuf.c
deleted file mode 100644
index d333b67cc1a0..000000000000
--- a/drivers/gpu/drm/xen/xen_drm_front_shbuf.c
+++ /dev/null
@@ -1,414 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0 OR MIT
-
-/*
- *Â Xen para-virtual DRM device
- *
- * Copyright (C) 2016-2018 EPAM Systems Inc.
- *
- * Author: Oleksandr Andrushchenko <oleksandr_andrushchenko@xxxxxxxx>
- */
-
-#include <drm/drmP.h>
-
-#if defined(CONFIG_X86)
-#include <drm/drm_cache.h>
-#endif
-#include <linux/errno.h>
-#include <linux/mm.h>
-
-#include <asm/xen/hypervisor.h>
-#include <xen/balloon.h>
-#include <xen/xen.h>
-#include <xen/xenbus.h>
-#include <xen/interface/io/ring.h>
-#include <xen/interface/io/displif.h>
-
-#include "xen_drm_front.h"
-#include "xen_drm_front_shbuf.h"
-
-struct xen_drm_front_shbuf_ops {
-ÂÂÂ /*
-ÂÂÂÂ * Calculate number of grefs required to handle this buffer,
-ÂÂÂÂ * e.g. if grefs are required for page directory only or the buffer
-ÂÂÂÂ * pages as well.
-ÂÂÂÂ */
-ÂÂÂ void (*calc_num_grefs)(struct xen_drm_front_shbuf *buf);
-ÂÂÂ /* Fill page directory according to para-virtual display protocol. */
-ÂÂÂ void (*fill_page_dir)(struct xen_drm_front_shbuf *buf);
-ÂÂÂ /* Claim grant references for the pages of the buffer. */
-ÂÂÂ int (*grant_refs_for_buffer)(struct xen_drm_front_shbuf *buf,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ grant_ref_t *priv_gref_head, int gref_idx);
-ÂÂÂ /* Map grant references of the buffer. */
-ÂÂÂ int (*map)(struct xen_drm_front_shbuf *buf);
-ÂÂÂ /* Unmap grant references of the buffer. */
-ÂÂÂ int (*unmap)(struct xen_drm_front_shbuf *buf);
-};
-
-grant_ref_t xen_drm_front_shbuf_get_dir_start(struct xen_drm_front_shbuf *buf)
-{
-ÂÂÂ if (!buf->grefs)
-ÂÂÂÂÂÂÂ return GRANT_INVALID_REF;
-
-ÂÂÂ return buf->grefs[0];
-}
-
-int xen_drm_front_shbuf_map(struct xen_drm_front_shbuf *buf)
-{
-ÂÂÂ if (buf->ops->map)
-ÂÂÂÂÂÂÂ return buf->ops->map(buf);
-
-ÂÂÂ /* no need to map own grant references */
-ÂÂÂ return 0;
-}
-
-int xen_drm_front_shbuf_unmap(struct xen_drm_front_shbuf *buf)
-{
-ÂÂÂ if (buf->ops->unmap)
-ÂÂÂÂÂÂÂ return buf->ops->unmap(buf);
-
-ÂÂÂ /* no need to unmap own grant references */
-ÂÂÂ return 0;
-}
-
-void xen_drm_front_shbuf_flush(struct xen_drm_front_shbuf *buf)
-{
-#if defined(CONFIG_X86)
-ÂÂÂ drm_clflush_pages(buf->pages, buf->num_pages);
-#endif
-}
-
-void xen_drm_front_shbuf_free(struct xen_drm_front_shbuf *buf)
-{
-ÂÂÂ if (buf->grefs) {
-ÂÂÂÂÂÂÂ int i;
-
-ÂÂÂÂÂÂÂ for (i = 0; i < buf->num_grefs; i++)
-ÂÂÂÂÂÂÂÂÂÂÂ if (buf->grefs[i] != GRANT_INVALID_REF)
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ gnttab_end_foreign_access(buf->grefs[i],
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ 0, 0UL);
-ÂÂÂ }
-ÂÂÂ kfree(buf->grefs);
-ÂÂÂ kfree(buf->directory);
-ÂÂÂ kfree(buf);
-}
-
-/*
- * number of grefs a page can hold with respect to the
- * struct xendispl_page_directory header
- */
-#define XEN_DRM_NUM_GREFS_PER_PAGE ((PAGE_SIZE - \
-ÂÂÂÂÂÂÂ offsetof(struct xendispl_page_directory, gref)) / \
-ÂÂÂÂÂÂÂ sizeof(grant_ref_t))
-
-static int get_num_pages_dir(struct xen_drm_front_shbuf *buf)
-{
-ÂÂÂ /* number of pages the page directory consumes itself */
-ÂÂÂ return DIV_ROUND_UP(buf->num_pages, XEN_DRM_NUM_GREFS_PER_PAGE);
-}
-
-static void backend_calc_num_grefs(struct xen_drm_front_shbuf *buf)
-{
-ÂÂÂ /* only for pages the page directory consumes itself */
-ÂÂÂ buf->num_grefs = get_num_pages_dir(buf);
-}
-
-static void guest_calc_num_grefs(struct xen_drm_front_shbuf *buf)
-{
-ÂÂÂ /*
-ÂÂÂÂ * number of pages the page directory consumes itself
-ÂÂÂÂ * plus grefs for the buffer pages
-ÂÂÂÂ */
-ÂÂÂ buf->num_grefs = get_num_pages_dir(buf) + buf->num_pages;
-}
-
-#define xen_page_to_vaddr(page) \
-ÂÂÂÂÂÂÂ ((uintptr_t)pfn_to_kaddr(page_to_xen_pfn(page)))
-
-static int backend_unmap(struct xen_drm_front_shbuf *buf)
-{
-ÂÂÂ struct gnttab_unmap_grant_ref *unmap_ops;
-ÂÂÂ int i, ret;
-
-ÂÂÂ if (!buf->pages || !buf->backend_map_handles || !buf->grefs)
-ÂÂÂÂÂÂÂ return 0;
-
-ÂÂÂ unmap_ops = kcalloc(buf->num_pages, sizeof(*unmap_ops),
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ GFP_KERNEL);
-ÂÂÂ if (!unmap_ops) {
-ÂÂÂÂÂÂÂ DRM_ERROR("Failed to get memory while unmapping\n");
-ÂÂÂÂÂÂÂ return -ENOMEM;
-ÂÂÂ }
-
-ÂÂÂ for (i = 0; i < buf->num_pages; i++) {
-ÂÂÂÂÂÂÂ phys_addr_t addr;
-
-ÂÂÂÂÂÂÂ addr = xen_page_to_vaddr(buf->pages[i]);
-ÂÂÂÂÂÂÂ gnttab_set_unmap_op(&unmap_ops[i], addr, GNTMAP_host_map,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ buf->backend_map_handles[i]);
-ÂÂÂ }
-
-ÂÂÂ ret = gnttab_unmap_refs(unmap_ops, NULL, buf->pages,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ buf->num_pages);
-
-ÂÂÂ for (i = 0; i < buf->num_pages; i++) {
-ÂÂÂÂÂÂÂ if (unlikely(unmap_ops[i].status != GNTST_okay))
-ÂÂÂÂÂÂÂÂÂÂÂ DRM_ERROR("Failed to unmap page %d: %d\n",
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ i, unmap_ops[i].status);
-ÂÂÂ }
-
-ÂÂÂ if (ret)
-ÂÂÂÂÂÂÂ DRM_ERROR("Failed to unmap grant references, ret %d", ret);
-
-ÂÂÂ kfree(unmap_ops);
-ÂÂÂ kfree(buf->backend_map_handles);
-ÂÂÂ buf->backend_map_handles = NULL;
-ÂÂÂ return ret;
-}
-
-static int backend_map(struct xen_drm_front_shbuf *buf)
-{
-ÂÂÂ struct gnttab_map_grant_ref *map_ops = NULL;
-ÂÂÂ unsigned char *ptr;
-ÂÂÂ int ret, cur_gref, cur_dir_page, cur_page, grefs_left;
-
-ÂÂÂ map_ops = kcalloc(buf->num_pages, sizeof(*map_ops), GFP_KERNEL);
-ÂÂÂ if (!map_ops)
-ÂÂÂÂÂÂÂ return -ENOMEM;
-
-ÂÂÂ buf->backend_map_handles = kcalloc(buf->num_pages,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ sizeof(*buf->backend_map_handles),
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ GFP_KERNEL);
-ÂÂÂ if (!buf->backend_map_handles) {
-ÂÂÂÂÂÂÂ kfree(map_ops);
-ÂÂÂÂÂÂÂ return -ENOMEM;
-ÂÂÂ }
-
-ÂÂÂ /*
-ÂÂÂÂ * read page directory to get grefs from the backend: for external
-ÂÂÂÂ * buffer we only allocate buf->grefs for the page directory,
-ÂÂÂÂ * so buf->num_grefs has number of pages in the page directory itself
-ÂÂÂÂ */
-ÂÂÂ ptr = buf->directory;
-ÂÂÂ grefs_left = buf->num_pages;
-ÂÂÂ cur_page = 0;
-ÂÂÂ for (cur_dir_page = 0; cur_dir_page < buf->num_grefs; cur_dir_page++) {
-ÂÂÂÂÂÂÂ struct xendispl_page_directory *page_dir =
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ (struct xendispl_page_directory *)ptr;
-ÂÂÂÂÂÂÂ int to_copy = XEN_DRM_NUM_GREFS_PER_PAGE;
-
-ÂÂÂÂÂÂÂ if (to_copy > grefs_left)
-ÂÂÂÂÂÂÂÂÂÂÂ to_copy = grefs_left;
-
-ÂÂÂÂÂÂÂ for (cur_gref = 0; cur_gref < to_copy; cur_gref++) {
-ÂÂÂÂÂÂÂÂÂÂÂ phys_addr_t addr;
-
-ÂÂÂÂÂÂÂÂÂÂÂ addr = xen_page_to_vaddr(buf->pages[cur_page]);
-ÂÂÂÂÂÂÂÂÂÂÂ gnttab_set_map_op(&map_ops[cur_page], addr,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ GNTMAP_host_map,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ page_dir->gref[cur_gref],
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ buf->xb_dev->otherend_id);
-ÂÂÂÂÂÂÂÂÂÂÂ cur_page++;
-ÂÂÂÂÂÂÂ }
-
-ÂÂÂÂÂÂÂ grefs_left -= to_copy;
-ÂÂÂÂÂÂÂ ptr += PAGE_SIZE;
-ÂÂÂ }
-ÂÂÂ ret = gnttab_map_refs(map_ops, NULL, buf->pages, buf->num_pages);
-
-ÂÂÂ /* save handles even if error, so we can unmap */
-ÂÂÂ for (cur_page = 0; cur_page < buf->num_pages; cur_page++) {
-ÂÂÂÂÂÂÂ buf->backend_map_handles[cur_page] = map_ops[cur_page].handle;
-ÂÂÂÂÂÂÂ if (unlikely(map_ops[cur_page].status != GNTST_okay))
-ÂÂÂÂÂÂÂÂÂÂÂ DRM_ERROR("Failed to map page %d: %d\n",
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ cur_page, map_ops[cur_page].status);
-ÂÂÂ }
-
-ÂÂÂ if (ret) {
-ÂÂÂÂÂÂÂ DRM_ERROR("Failed to map grant references, ret %d", ret);
-ÂÂÂÂÂÂÂ backend_unmap(buf);
-ÂÂÂ }
-
-ÂÂÂ kfree(map_ops);
-ÂÂÂ return ret;
-}
-
-static void backend_fill_page_dir(struct xen_drm_front_shbuf *buf)
-{
-ÂÂÂ struct xendispl_page_directory *page_dir;
-ÂÂÂ unsigned char *ptr;
-ÂÂÂ int i, num_pages_dir;
-
-ÂÂÂ ptr = buf->directory;
-ÂÂÂ num_pages_dir = get_num_pages_dir(buf);
-
-ÂÂÂ /* fill only grefs for the page directory itself */
-ÂÂÂ for (i = 0; i < num_pages_dir - 1; i++) {
-ÂÂÂÂÂÂÂ page_dir = (struct xendispl_page_directory *)ptr;
-
-ÂÂÂÂÂÂÂ page_dir->gref_dir_next_page = buf->grefs[i + 1];
-ÂÂÂÂÂÂÂ ptr += PAGE_SIZE;
-ÂÂÂ }
-ÂÂÂ /* last page must say there is no more pages */
-ÂÂÂ page_dir = (struct xendispl_page_directory *)ptr;
-ÂÂÂ page_dir->gref_dir_next_page = GRANT_INVALID_REF;
-}
-
-static void guest_fill_page_dir(struct xen_drm_front_shbuf *buf)
-{
-ÂÂÂ unsigned char *ptr;
-ÂÂÂ int cur_gref, grefs_left, to_copy, i, num_pages_dir;
-
-ÂÂÂ ptr = buf->directory;
-ÂÂÂ num_pages_dir = get_num_pages_dir(buf);
-
-ÂÂÂ /*
-ÂÂÂÂ * while copying, skip grefs at start, they are for pages
-ÂÂÂÂ * granted for the page directory itself
-ÂÂÂÂ */
-ÂÂÂ cur_gref = num_pages_dir;
-ÂÂÂ grefs_left = buf->num_pages;
-ÂÂÂ for (i = 0; i < num_pages_dir; i++) {
-ÂÂÂÂÂÂÂ struct xendispl_page_directory *page_dir =
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ (struct xendispl_page_directory *)ptr;
-
-ÂÂÂÂÂÂÂ if (grefs_left <= XEN_DRM_NUM_GREFS_PER_PAGE) {
-ÂÂÂÂÂÂÂÂÂÂÂ to_copy = grefs_left;
-ÂÂÂÂÂÂÂÂÂÂÂ page_dir->gref_dir_next_page = GRANT_INVALID_REF;
-ÂÂÂÂÂÂÂ } else {
-ÂÂÂÂÂÂÂÂÂÂÂ to_copy = XEN_DRM_NUM_GREFS_PER_PAGE;
-ÂÂÂÂÂÂÂÂÂÂÂ page_dir->gref_dir_next_page = buf->grefs[i + 1];
-ÂÂÂÂÂÂÂ }
-ÂÂÂÂÂÂÂ memcpy(&page_dir->gref, &buf->grefs[cur_gref],
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ to_copy * sizeof(grant_ref_t));
-ÂÂÂÂÂÂÂ ptr += PAGE_SIZE;
-ÂÂÂÂÂÂÂ grefs_left -= to_copy;
-ÂÂÂÂÂÂÂ cur_gref += to_copy;
-ÂÂÂ }
-}
-
-static int guest_grant_refs_for_buffer(struct xen_drm_front_shbuf *buf,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ grant_ref_t *priv_gref_head,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ int gref_idx)
-{
-ÂÂÂ int i, cur_ref, otherend_id;
-
-ÂÂÂ otherend_id = buf->xb_dev->otherend_id;
-ÂÂÂ for (i = 0; i < buf->num_pages; i++) {
-ÂÂÂÂÂÂÂ cur_ref = gnttab_claim_grant_reference(priv_gref_head);
-ÂÂÂÂÂÂÂ if (cur_ref < 0)
-ÂÂÂÂÂÂÂÂÂÂÂ return cur_ref;
-
-ÂÂÂÂÂÂÂ gnttab_grant_foreign_access_ref(cur_ref, otherend_id,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ xen_page_to_gfn(buf->pages[i]),
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ 0);
-ÂÂÂÂÂÂÂ buf->grefs[gref_idx++] = cur_ref;
-ÂÂÂ }
-ÂÂÂ return 0;
-}
-
-static int grant_references(struct xen_drm_front_shbuf *buf)
-{
-ÂÂÂ grant_ref_t priv_gref_head;
-ÂÂÂ int ret, i, j, cur_ref;
-ÂÂÂ int otherend_id, num_pages_dir;
-
-ÂÂÂ ret = gnttab_alloc_grant_references(buf->num_grefs, &priv_gref_head);
-ÂÂÂ if (ret < 0) {
-ÂÂÂÂÂÂÂ DRM_ERROR("Cannot allocate grant references\n");
-ÂÂÂÂÂÂÂ return ret;
-ÂÂÂ }
-
-ÂÂÂ otherend_id = buf->xb_dev->otherend_id;
-ÂÂÂ j = 0;
-ÂÂÂ num_pages_dir = get_num_pages_dir(buf);
-ÂÂÂ for (i = 0; i < num_pages_dir; i++) {
-ÂÂÂÂÂÂÂ unsigned long frame;
-
-ÂÂÂÂÂÂÂ cur_ref = gnttab_claim_grant_reference(&priv_gref_head);
-ÂÂÂÂÂÂÂ if (cur_ref < 0)
-ÂÂÂÂÂÂÂÂÂÂÂ return cur_ref;
-
-ÂÂÂÂÂÂÂ frame = xen_page_to_gfn(virt_to_page(buf->directory +
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ PAGE_SIZE * i));
-ÂÂÂÂÂÂÂ gnttab_grant_foreign_access_ref(cur_ref, otherend_id, frame, 0);
-ÂÂÂÂÂÂÂ buf->grefs[j++] = cur_ref;
-ÂÂÂ }
-
-ÂÂÂ if (buf->ops->grant_refs_for_buffer) {
-ÂÂÂÂÂÂÂ ret = buf->ops->grant_refs_for_buffer(buf, &priv_gref_head, j);
-ÂÂÂÂÂÂÂ if (ret)
-ÂÂÂÂÂÂÂÂÂÂÂ return ret;
-ÂÂÂ }
-
-ÂÂÂ gnttab_free_grant_references(priv_gref_head);
-ÂÂÂ return 0;
-}
-
-static int alloc_storage(struct xen_drm_front_shbuf *buf)
-{
-ÂÂÂ buf->grefs = kcalloc(buf->num_grefs, sizeof(*buf->grefs), GFP_KERNEL);
-ÂÂÂ if (!buf->grefs)
-ÂÂÂÂÂÂÂ return -ENOMEM;
-
-ÂÂÂ buf->directory = kcalloc(get_num_pages_dir(buf), PAGE_SIZE, GFP_KERNEL);
-ÂÂÂ if (!buf->directory)
-ÂÂÂÂÂÂÂ return -ENOMEM;
-
-ÂÂÂ return 0;
-}
-
-/*
- * For be allocated buffers we don't need grant_refs_for_buffer as those
- * grant references are allocated at backend side
- */
-static const struct xen_drm_front_shbuf_ops backend_ops = {
-ÂÂÂ .calc_num_grefs = backend_calc_num_grefs,
-ÂÂÂ .fill_page_dir = backend_fill_page_dir,
-ÂÂÂ .map = backend_map,
-ÂÂÂ .unmap = backend_unmap
-};
-
-/* For locally granted references we do not need to map/unmap the references */
-static const struct xen_drm_front_shbuf_ops local_ops = {
-ÂÂÂ .calc_num_grefs = guest_calc_num_grefs,
-ÂÂÂ .fill_page_dir = guest_fill_page_dir,
-ÂÂÂ .grant_refs_for_buffer = guest_grant_refs_for_buffer,
-};
-
-struct xen_drm_front_shbuf *
-xen_drm_front_shbuf_alloc(struct xen_drm_front_shbuf_cfg *cfg)
-{
-ÂÂÂ struct xen_drm_front_shbuf *buf;
-ÂÂÂ int ret;
-
-ÂÂÂ buf = kzalloc(sizeof(*buf), GFP_KERNEL);
-ÂÂÂ if (!buf)
-ÂÂÂÂÂÂÂ return ERR_PTR(-ENOMEM);
-
-ÂÂÂ if (cfg->be_alloc)
-ÂÂÂÂÂÂÂ buf->ops = &backend_ops;
-ÂÂÂ else
-ÂÂÂÂÂÂÂ buf->ops = &local_ops;
-
-ÂÂÂ buf->xb_dev = cfg->xb_dev;
-ÂÂÂ buf->num_pages = DIV_ROUND_UP(cfg->size, PAGE_SIZE);
-ÂÂÂ buf->pages = cfg->pages;
-
-ÂÂÂ buf->ops->calc_num_grefs(buf);
-
-ÂÂÂ ret = alloc_storage(buf);
-ÂÂÂ if (ret)
-ÂÂÂÂÂÂÂ goto fail;
-
-ÂÂÂ ret = grant_references(buf);
-ÂÂÂ if (ret)
-ÂÂÂÂÂÂÂ goto fail;
-
-ÂÂÂ buf->ops->fill_page_dir(buf);
-
-ÂÂÂ return buf;
-
-fail:
-ÂÂÂ xen_drm_front_shbuf_free(buf);
-ÂÂÂ return ERR_PTR(ret);
-}
diff --git a/drivers/gpu/drm/xen/xen_drm_front_shbuf.h b/drivers/gpu/drm/xen/xen_drm_front_shbuf.h
deleted file mode 100644
index 7545c692539e..000000000000
--- a/drivers/gpu/drm/xen/xen_drm_front_shbuf.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 OR MIT */
-
-/*
- *Â Xen para-virtual DRM device
- *
- * Copyright (C) 2016-2018 EPAM Systems Inc.
- *
- * Author: Oleksandr Andrushchenko <oleksandr_andrushchenko@xxxxxxxx>
- */
-
-#ifndef __XEN_DRM_FRONT_SHBUF_H_
-#define __XEN_DRM_FRONT_SHBUF_H_
-
-#include <linux/kernel.h>
-#include <linux/scatterlist.h>
-
-#include <xen/grant_table.h>
-
-struct xen_drm_front_shbuf {
-ÂÂÂ /*
-ÂÂÂÂ * number of references granted for the backend use:
-ÂÂÂÂ *Â - for allocated/imported dma-buf's this holds number of grant
-ÂÂÂÂ *ÂÂÂ references for the page directory and pages of the buffer
-ÂÂÂÂ *Â - for the buffer provided by the backend this holds number of
-ÂÂÂÂ *ÂÂÂ grant references for the page directory as grant references for
-ÂÂÂÂ *ÂÂÂ the buffer will be provided by the backend
-ÂÂÂÂ */
-ÂÂÂ int num_grefs;
-ÂÂÂ grant_ref_t *grefs;
-ÂÂÂ unsigned char *directory;
-
-ÂÂÂ int num_pages;
-ÂÂÂ struct page **pages;
-
-ÂÂÂ struct xenbus_device *xb_dev;
-
-ÂÂÂ /* these are the ops used internally depending on be_alloc mode */
-ÂÂÂ const struct xen_drm_front_shbuf_ops *ops;
-
-ÂÂÂ /* Xen map handles for the buffer allocated by the backend */
-ÂÂÂ grant_handle_t *backend_map_handles;
-};
-
-struct xen_drm_front_shbuf_cfg {
-ÂÂÂ struct xenbus_device *xb_dev;
-ÂÂÂ size_t size;
-ÂÂÂ struct page **pages;
-ÂÂÂ bool be_alloc;
-};
-
-struct xen_drm_front_shbuf *
-xen_drm_front_shbuf_alloc(struct xen_drm_front_shbuf_cfg *cfg);
-
-grant_ref_t xen_drm_front_shbuf_get_dir_start(struct xen_drm_front_shbuf *buf);
-
-int xen_drm_front_shbuf_map(struct xen_drm_front_shbuf *buf);
-
-int xen_drm_front_shbuf_unmap(struct xen_drm_front_shbuf *buf);
-
-void xen_drm_front_shbuf_flush(struct xen_drm_front_shbuf *buf);
-
-void xen_drm_front_shbuf_free(struct xen_drm_front_shbuf *buf);
-
-#endif /* __XEN_DRM_FRONT_SHBUF_H_ */