GNU Linux-libre 4.19.286-gnu1
[releases.git] / drivers / gpu / drm / xen / xen_drm_front_shbuf.h
1 /* SPDX-License-Identifier: GPL-2.0 OR MIT */
2
3 /*
4  *  Xen para-virtual DRM device
5  *
6  * Copyright (C) 2016-2018 EPAM Systems Inc.
7  *
8  * Author: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
9  */
10
11 #ifndef __XEN_DRM_FRONT_SHBUF_H_
12 #define __XEN_DRM_FRONT_SHBUF_H_
13
14 #include <linux/kernel.h>
15 #include <linux/scatterlist.h>
16
17 #include <xen/grant_table.h>
18
19 struct xen_drm_front_shbuf {
20         /*
21          * number of references granted for the backend use:
22          *  - for allocated/imported dma-buf's this holds number of grant
23          *    references for the page directory and pages of the buffer
24          *  - for the buffer provided by the backend this holds number of
25          *    grant references for the page directory as grant references for
26          *    the buffer will be provided by the backend
27          */
28         int num_grefs;
29         grant_ref_t *grefs;
30         unsigned char *directory;
31
32         int num_pages;
33         struct page **pages;
34
35         struct xenbus_device *xb_dev;
36
37         /* these are the ops used internally depending on be_alloc mode */
38         const struct xen_drm_front_shbuf_ops *ops;
39
40         /* Xen map handles for the buffer allocated by the backend */
41         grant_handle_t *backend_map_handles;
42 };
43
44 struct xen_drm_front_shbuf_cfg {
45         struct xenbus_device *xb_dev;
46         size_t size;
47         struct page **pages;
48         bool be_alloc;
49 };
50
51 struct xen_drm_front_shbuf *
52 xen_drm_front_shbuf_alloc(struct xen_drm_front_shbuf_cfg *cfg);
53
54 grant_ref_t xen_drm_front_shbuf_get_dir_start(struct xen_drm_front_shbuf *buf);
55
56 int xen_drm_front_shbuf_map(struct xen_drm_front_shbuf *buf);
57
58 int xen_drm_front_shbuf_unmap(struct xen_drm_front_shbuf *buf);
59
60 void xen_drm_front_shbuf_flush(struct xen_drm_front_shbuf *buf);
61
62 void xen_drm_front_shbuf_free(struct xen_drm_front_shbuf *buf);
63
64 #endif /* __XEN_DRM_FRONT_SHBUF_H_ */