xen-front-pgdir-shbuf.h 2.3 KB

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