^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 OR MIT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Xen frontend/backend page directory based shared buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * helper module.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) 2018 EPAM Systems Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Author: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #ifndef __XEN_FRONT_PGDIR_SHBUF_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #define __XEN_FRONT_PGDIR_SHBUF_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <xen/grant_table.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) struct xen_front_pgdir_shbuf_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) struct xen_front_pgdir_shbuf {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * Number of references granted for the backend use:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * - for frontend allocated/imported buffers this holds the number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * of grant references for the page directory and the pages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * of the buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * - for the buffer provided by the backend this only holds the number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * of grant references for the page directory itself as grant
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * references for the buffer will be provided by the backend.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) int num_grefs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) grant_ref_t *grefs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) /* Page directory backing storage. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) u8 *directory;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * Number of pages for the shared buffer itself (excluding the page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * directory).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) int num_pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * Backing storage of the shared buffer: these are the pages being
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * shared.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct page **pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct xenbus_device *xb_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) /* These are the ops used internally depending on be_alloc mode. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) const struct xen_front_pgdir_shbuf_ops *ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) /* Xen map handles for the buffer allocated by the backend. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) grant_handle_t *backend_map_handles;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) struct xen_front_pgdir_shbuf_cfg {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct xenbus_device *xb_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) /* Number of pages of the buffer backing storage. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) int num_pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) /* Pages of the buffer to be shared. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct page **pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * This is allocated outside because there are use-cases when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * the buffer structure is allocated as a part of a bigger one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct xen_front_pgdir_shbuf *pgdir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * Mode of grant reference sharing: if set then backend will share
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * grant references to the buffer with the frontend.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) int be_alloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) int xen_front_pgdir_shbuf_alloc(struct xen_front_pgdir_shbuf_cfg *cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) grant_ref_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) xen_front_pgdir_shbuf_get_dir_start(struct xen_front_pgdir_shbuf *buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) int xen_front_pgdir_shbuf_map(struct xen_front_pgdir_shbuf *buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) int xen_front_pgdir_shbuf_unmap(struct xen_front_pgdir_shbuf *buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) void xen_front_pgdir_shbuf_free(struct xen_front_pgdir_shbuf *buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) #endif /* __XEN_FRONT_PGDIR_SHBUF_H_ */