logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

virtio_mem.h (7266B)


  1. /* SPDX-License-Identifier: BSD-3-Clause */
  2. /*
  3. * Virtio Mem Device
  4. *
  5. * Copyright Red Hat, Inc. 2020
  6. *
  7. * Authors:
  8. * David Hildenbrand <david@redhat.com>
  9. *
  10. * This header is BSD licensed so anyone can use the definitions
  11. * to implement compatible drivers/servers:
  12. *
  13. * Redistribution and use in source and binary forms, with or without
  14. * modification, are permitted provided that the following conditions
  15. * are met:
  16. * 1. Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. * 2. Redistributions in binary form must reproduce the above copyright
  19. * notice, this list of conditions and the following disclaimer in the
  20. * documentation and/or other materials provided with the distribution.
  21. * 3. Neither the name of IBM nor the names of its contributors
  22. * may be used to endorse or promote products derived from this software
  23. * without specific prior written permission.
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  25. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  26. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  27. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IBM OR
  28. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  29. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  30. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  31. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  32. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  33. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  34. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  35. * SUCH DAMAGE.
  36. */
  37. #ifndef _LINUX_VIRTIO_MEM_H
  38. #define _LINUX_VIRTIO_MEM_H
  39. #include <linux/types.h>
  40. #include <linux/virtio_types.h>
  41. #include <linux/virtio_ids.h>
  42. #include <linux/virtio_config.h>
  43. /*
  44. * Each virtio-mem device manages a dedicated region in physical address
  45. * space. Each device can belong to a single NUMA node, multiple devices
  46. * for a single NUMA node are possible. A virtio-mem device is like a
  47. * "resizable DIMM" consisting of small memory blocks that can be plugged
  48. * or unplugged. The device driver is responsible for (un)plugging memory
  49. * blocks on demand.
  50. *
  51. * Virtio-mem devices can only operate on their assigned memory region in
  52. * order to (un)plug memory. A device cannot (un)plug memory belonging to
  53. * other devices.
  54. *
  55. * The "region_size" corresponds to the maximum amount of memory that can
  56. * be provided by a device. The "size" corresponds to the amount of memory
  57. * that is currently plugged. "requested_size" corresponds to a request
  58. * from the device to the device driver to (un)plug blocks. The
  59. * device driver should try to (un)plug blocks in order to reach the
  60. * "requested_size". It is impossible to plug more memory than requested.
  61. *
  62. * The "usable_region_size" represents the memory region that can actually
  63. * be used to (un)plug memory. It is always at least as big as the
  64. * "requested_size" and will grow dynamically. It will only shrink when
  65. * explicitly triggered (VIRTIO_MEM_REQ_UNPLUG).
  66. *
  67. * There are no guarantees what will happen if unplugged memory is
  68. * read/written. In general, unplugged memory should not be touched, because
  69. * the resulting action is undefined. There is one exception: without
  70. * VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE, unplugged memory inside the usable
  71. * region can be read, to simplify creation of memory dumps.
  72. *
  73. * It can happen that the device cannot process a request, because it is
  74. * busy. The device driver has to retry later.
  75. *
  76. * Usually, during system resets all memory will get unplugged, so the
  77. * device driver can start with a clean state. However, in specific
  78. * scenarios (if the device is busy) it can happen that the device still
  79. * has memory plugged. The device driver can request to unplug all memory
  80. * (VIRTIO_MEM_REQ_UNPLUG) - which might take a while to succeed if the
  81. * device is busy.
  82. */
  83. /* --- virtio-mem: feature bits --- */
  84. /* node_id is an ACPI PXM and is valid */
  85. #define VIRTIO_MEM_F_ACPI_PXM 0
  86. /* unplugged memory must not be accessed */
  87. #define VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE 1
  88. /* plugged memory will remain plugged when suspending+resuming */
  89. #define VIRTIO_MEM_F_PERSISTENT_SUSPEND 2
  90. /* --- virtio-mem: guest -> host requests --- */
  91. /* request to plug memory blocks */
  92. #define VIRTIO_MEM_REQ_PLUG 0
  93. /* request to unplug memory blocks */
  94. #define VIRTIO_MEM_REQ_UNPLUG 1
  95. /* request to unplug all blocks and shrink the usable size */
  96. #define VIRTIO_MEM_REQ_UNPLUG_ALL 2
  97. /* request information about the plugged state of memory blocks */
  98. #define VIRTIO_MEM_REQ_STATE 3
  99. struct virtio_mem_req_plug {
  100. __virtio64 addr;
  101. __virtio16 nb_blocks;
  102. __virtio16 padding[3];
  103. };
  104. struct virtio_mem_req_unplug {
  105. __virtio64 addr;
  106. __virtio16 nb_blocks;
  107. __virtio16 padding[3];
  108. };
  109. struct virtio_mem_req_state {
  110. __virtio64 addr;
  111. __virtio16 nb_blocks;
  112. __virtio16 padding[3];
  113. };
  114. struct virtio_mem_req {
  115. __virtio16 type;
  116. __virtio16 padding[3];
  117. union {
  118. struct virtio_mem_req_plug plug;
  119. struct virtio_mem_req_unplug unplug;
  120. struct virtio_mem_req_state state;
  121. } u;
  122. };
  123. /* --- virtio-mem: host -> guest response --- */
  124. /*
  125. * Request processed successfully, applicable for
  126. * - VIRTIO_MEM_REQ_PLUG
  127. * - VIRTIO_MEM_REQ_UNPLUG
  128. * - VIRTIO_MEM_REQ_UNPLUG_ALL
  129. * - VIRTIO_MEM_REQ_STATE
  130. */
  131. #define VIRTIO_MEM_RESP_ACK 0
  132. /*
  133. * Request denied - e.g. trying to plug more than requested, applicable for
  134. * - VIRTIO_MEM_REQ_PLUG
  135. */
  136. #define VIRTIO_MEM_RESP_NACK 1
  137. /*
  138. * Request cannot be processed right now, try again later, applicable for
  139. * - VIRTIO_MEM_REQ_PLUG
  140. * - VIRTIO_MEM_REQ_UNPLUG
  141. * - VIRTIO_MEM_REQ_UNPLUG_ALL
  142. */
  143. #define VIRTIO_MEM_RESP_BUSY 2
  144. /*
  145. * Error in request (e.g. addresses/alignment), applicable for
  146. * - VIRTIO_MEM_REQ_PLUG
  147. * - VIRTIO_MEM_REQ_UNPLUG
  148. * - VIRTIO_MEM_REQ_STATE
  149. */
  150. #define VIRTIO_MEM_RESP_ERROR 3
  151. /* State of memory blocks is "plugged" */
  152. #define VIRTIO_MEM_STATE_PLUGGED 0
  153. /* State of memory blocks is "unplugged" */
  154. #define VIRTIO_MEM_STATE_UNPLUGGED 1
  155. /* State of memory blocks is "mixed" */
  156. #define VIRTIO_MEM_STATE_MIXED 2
  157. struct virtio_mem_resp_state {
  158. __virtio16 state;
  159. };
  160. struct virtio_mem_resp {
  161. __virtio16 type;
  162. __virtio16 padding[3];
  163. union {
  164. struct virtio_mem_resp_state state;
  165. } u;
  166. };
  167. /* --- virtio-mem: configuration --- */
  168. struct virtio_mem_config {
  169. /* Block size and alignment. Cannot change. */
  170. __le64 block_size;
  171. /* Valid with VIRTIO_MEM_F_ACPI_PXM. Cannot change. */
  172. __le16 node_id;
  173. __u8 padding[6];
  174. /* Start address of the memory region. Cannot change. */
  175. __le64 addr;
  176. /* Region size (maximum). Cannot change. */
  177. __le64 region_size;
  178. /*
  179. * Currently usable region size. Can grow up to region_size. Can
  180. * shrink due to VIRTIO_MEM_REQ_UNPLUG_ALL (in which case no config
  181. * update will be sent).
  182. */
  183. __le64 usable_region_size;
  184. /*
  185. * Currently used size. Changes due to plug/unplug requests, but no
  186. * config updates will be sent.
  187. */
  188. __le64 plugged_size;
  189. /* Requested size. New plug requests cannot exceed it. Can change. */
  190. __le64 requested_size;
  191. };
  192. #endif /* _LINUX_VIRTIO_MEM_H */