1 /* SPDX-License-Identifier: GPL-2.0 OR MIT */
4 * Xen frontend/backend page directory based shared buffer
7 * Copyright (C) 2018 EPAM Systems Inc.
9 * Author: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
12 #ifndef __XEN_FRONT_PGDIR_SHBUF_H_
13 #define __XEN_FRONT_PGDIR_SHBUF_H_
15 #include <linux/kernel.h>
17 #include <xen/grant_table.h>
19 struct xen_front_pgdir_shbuf_ops;
21 struct xen_front_pgdir_shbuf {
23 * Number of references granted for the backend use:
25 * - for frontend allocated/imported buffers this holds the number
26 * of grant references for the page directory and the pages
29 * - for the buffer provided by the backend this only holds the number
30 * of grant references for the page directory itself as grant
31 * references for the buffer will be provided by the backend.
35 /* Page directory backing storage. */
39 * Number of pages for the shared buffer itself (excluding the page
44 * Backing storage of the shared buffer: these are the pages being
49 struct xenbus_device *xb_dev;
51 /* These are the ops used internally depending on be_alloc mode. */
52 const struct xen_front_pgdir_shbuf_ops *ops;
54 /* Xen map handles for the buffer allocated by the backend. */
55 grant_handle_t *backend_map_handles;
58 struct xen_front_pgdir_shbuf_cfg {
59 struct xenbus_device *xb_dev;
61 /* Number of pages of the buffer backing storage. */
63 /* Pages of the buffer to be shared. */
67 * This is allocated outside because there are use-cases when
68 * the buffer structure is allocated as a part of a bigger one.
70 struct xen_front_pgdir_shbuf *pgdir;
72 * Mode of grant reference sharing: if set then backend will share
73 * grant references to the buffer with the frontend.
78 int xen_front_pgdir_shbuf_alloc(struct xen_front_pgdir_shbuf_cfg *cfg);
81 xen_front_pgdir_shbuf_get_dir_start(struct xen_front_pgdir_shbuf *buf);
83 int xen_front_pgdir_shbuf_map(struct xen_front_pgdir_shbuf *buf);
85 int xen_front_pgdir_shbuf_unmap(struct xen_front_pgdir_shbuf *buf);
87 void xen_front_pgdir_shbuf_free(struct xen_front_pgdir_shbuf *buf);
89 #endif /* __XEN_FRONT_PGDIR_SHBUF_H_ */