/* SPDX-License-Identifier: GPL-2.0 OR MIT */12/*3* Xen frontend/backend page directory based shared buffer4* helper module.5*6* Copyright (C) 2018 EPAM Systems Inc.7*8* Author: Oleksandr Andrushchenko <[email protected]>9*/1011#ifndef __XEN_FRONT_PGDIR_SHBUF_H_12#define __XEN_FRONT_PGDIR_SHBUF_H_1314#include <linux/kernel.h>1516#include <xen/grant_table.h>1718struct xen_front_pgdir_shbuf_ops;1920struct xen_front_pgdir_shbuf {21/*22* Number of references granted for the backend use:23*24* - for frontend allocated/imported buffers this holds the number25* of grant references for the page directory and the pages26* of the buffer27*28* - for the buffer provided by the backend this only holds the number29* of grant references for the page directory itself as grant30* references for the buffer will be provided by the backend.31*/32int num_grefs;33grant_ref_t *grefs;34/* Page directory backing storage. */35u8 *directory;3637/*38* Number of pages for the shared buffer itself (excluding the page39* directory).40*/41int num_pages;42/*43* Backing storage of the shared buffer: these are the pages being44* shared.45*/46struct page **pages;4748struct xenbus_device *xb_dev;4950/* These are the ops used internally depending on be_alloc mode. */51const struct xen_front_pgdir_shbuf_ops *ops;5253/* Xen map handles for the buffer allocated by the backend. */54grant_handle_t *backend_map_handles;55};5657struct xen_front_pgdir_shbuf_cfg {58struct xenbus_device *xb_dev;5960/* Number of pages of the buffer backing storage. */61int num_pages;62/* Pages of the buffer to be shared. */63struct page **pages;6465/*66* This is allocated outside because there are use-cases when67* the buffer structure is allocated as a part of a bigger one.68*/69struct xen_front_pgdir_shbuf *pgdir;70/*71* Mode of grant reference sharing: if set then backend will share72* grant references to the buffer with the frontend.73*/74int be_alloc;75};7677int xen_front_pgdir_shbuf_alloc(struct xen_front_pgdir_shbuf_cfg *cfg);7879grant_ref_t80xen_front_pgdir_shbuf_get_dir_start(struct xen_front_pgdir_shbuf *buf);8182int xen_front_pgdir_shbuf_map(struct xen_front_pgdir_shbuf *buf);8384int xen_front_pgdir_shbuf_unmap(struct xen_front_pgdir_shbuf *buf);8586void xen_front_pgdir_shbuf_free(struct xen_front_pgdir_shbuf *buf);8788#endif /* __XEN_FRONT_PGDIR_SHBUF_H_ */899091