guest_shm.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * Copyright 2018, QNX Software Systems Limited (“QSS”).
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * 3. Neither the name of the copyright holder nor the names of its
  13. * contributors may be used to endorse or promote products derived
  14. * from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  17. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  18. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  19. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  20. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  21. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  22. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  26. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. *
  28. * Additional Patent Grant
  29. *
  30. * QSS hereby grants to you a perpetual, worldwide, non-exclusive,
  31. * no-charge, irrevocable (except as stated in this section) patent
  32. * license to make, have made, use, offer to sell, sell, import,
  33. * transfer, and otherwise run, modify and propagate the contents of this
  34. * header file (“Implementation”) , where such license applies
  35. * only to those patent claims, both currently owned by QSS and
  36. * acquired in the future, licensable by QSS that are necessarily
  37. * infringed by this Implementation. This grant does
  38. * not include claims that would be infringed only as a consequence of
  39. * further modification of this Implementation. If you or your agent or
  40. * exclusive licensee institute or order or agree to the institution of
  41. * patent litigation against any entity (including a cross-claim or
  42. * counterclaim in a lawsuit) alleging that this Implementation constitutes
  43. * direct or contributory patent infringement, or inducement of patent
  44. * infringement, then any patent rights granted to you under this license for
  45. * this Implementation shall terminate as of the date such litigation is filed.
  46. *
  47. * Alternatively, this software may be distributed under the terms of the
  48. * GNU General Public License ("GPL") version 2 as published by the Free
  49. * Software Foundation.
  50. */
  51. /**
  52. * @file
  53. * definitions guest shared memory device
  54. */
  55. #ifndef _QVM_GUEST_SHM_H
  56. #define _QVM_GUEST_SHM_H
  57. #ifdef __linux__
  58. #include <linux/types.h>
  59. #else
  60. #include <stdint.h>
  61. #endif
  62. /*
  63. * Temporary VID definition until the updated <pci/pci_id.h> propogates around
  64. */
  65. #define PCI_VID_BlackBerry_QNX 0x1C05
  66. #define PCI_DID_QNX_GUEST_SHM 0x0001
  67. /** status of last creation request */
  68. enum guest_shm_status {
  69. GSS_OK, /**< creation succeeded */
  70. GSS_UNKNOWN_FAILURE, /**< creation failed for an unknown reason */
  71. GSS_NOMEM, /**< creation failed due to lack of memory */
  72. GSS_CLIENT_MAX, /**< creation failed due to region already being used by the maximum number of guests */
  73. GSS_ILLEGAL_NAME, /**< creation failed due to illegal region name */
  74. GSS_NO_PERMISSION, /**< creation failed due to lack of permission */
  75. GSS_DOES_NOT_EXIST, /**< A find request failed */
  76. };
  77. /** Maximum number of clients allowed to connect to a shared memory region */
  78. #define GUEST_SHM_MAX_CLIENTS 16
  79. /** Maximum length allowed for region name */
  80. #define GUEST_SHM_MAX_NAME 32
  81. /** Signature value to verify that vdev is present */
  82. #define GUEST_SHM_SIGNATURE 0x4d534732474d5651
  83. /** Register layout for factory registers */
  84. struct guest_shm_factory {
  85. uint64_t signature; /**< == GUEST_SHM_SIGNATURE (R/O) */
  86. uint64_t shmem; /**< shared memory paddr (R/O) */
  87. uint32_t vector; /**< interrupt vector number (R/O) */
  88. uint32_t status; /**< status of last creation (R/O) */
  89. uint32_t size; /**< requested size in 4K pages, write causes creation */
  90. char name[GUEST_SHM_MAX_NAME]; /**< name of shared memory region */
  91. uint32_t find; /**< find an existing shared memory connection */
  92. };
  93. /** Register layout for a region control page */
  94. struct guest_shm_control {
  95. uint32_t status; /**< lower 16 bits: pending notification bitset, upper 16 bits: current active clients (R/O) */
  96. uint32_t idx; /**< connection index for this client (R/O) */
  97. uint32_t notify; /**< write a bitset of clients to notify */
  98. uint32_t detach; /**< write here to detach from the shared memory region */
  99. };
  100. static inline void
  101. guest_shm_create(volatile struct guest_shm_factory *const __factory, unsigned const __size) {
  102. /* Surround the size assignment with memory barriers so that
  103. * the compiler doesn't try to shift the assignment before/after
  104. * necessary bits (e.g. setting the name of the region) */
  105. asm volatile( "" ::: "memory");
  106. __factory->size = __size;
  107. asm volatile( "" ::: "memory");
  108. }
  109. static inline void
  110. guest_shm_find(volatile struct guest_shm_factory *const __factory, unsigned const __find_num) {
  111. /* Surround the find assignment with memory barriers so that
  112. * the compiler doesn't try to shift the assignment before/after
  113. * necessary bits (e.g. setting the name of the region) */
  114. asm volatile( "" ::: "memory");
  115. __factory->find = __find_num;
  116. asm volatile( "" ::: "memory");
  117. }
  118. #endif
  119. #if defined(__QNXNTO__) && defined(__USESRCVERSION)
  120. #include <sys/srcversion.h>
  121. __SRCVERSION("$URL$ $Rev$")
  122. #endif