gunyah_deprecated.h 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. /* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
  2. /*
  3. * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  4. */
  5. #ifndef _UAPI_LINUX_GUNYAH
  6. #define _UAPI_LINUX_GUNYAH
  7. /*
  8. * Userspace interface for /dev/gunyah - gunyah based virtual machine
  9. *
  10. * Note: this interface is considered experimental and may change without
  11. * notice.
  12. */
  13. #include <linux/types.h>
  14. #include <linux/ioctl.h>
  15. #include <linux/virtio_types.h>
  16. #define GH_IOCTL_TYPE 0xB2
  17. /*
  18. * fw_name is used to find the secure VM image by name to be loaded.
  19. */
  20. #define GH_VM_FW_NAME_MAX 16
  21. /** @struct gh_fw_name
  22. * A structure to be passed to GH_VM_SET_FM_NAME ioctl
  23. * @name - name of the secure VM image
  24. */
  25. struct gh_fw_name {
  26. char name[GH_VM_FW_NAME_MAX];
  27. };
  28. #define VBE_ASSIGN_IOEVENTFD 1
  29. #define VBE_DEASSIGN_IOEVENTFD 2
  30. #define VBE_ASSIGN_IRQFD 1
  31. #define VBE_DEASSIGN_IRQFD 2
  32. #define EVENT_NEW_BUFFER 1
  33. #define EVENT_RESET_RQST 2
  34. #define EVENT_INTERRUPT_ACK 4
  35. #define EVENT_DRIVER_OK 8
  36. #define EVENT_DRIVER_FAILED 0x10
  37. #define EVENT_MODULE_EXIT 0x20
  38. #define EVENT_VM_EXIT 0x40
  39. #define EVENT_APP_EXIT 0x100
  40. /*
  41. * gh_vm_exit_reasons specifies the various reasons why
  42. * the secondary VM ended its execution. VCPU_RUN returns these values
  43. * to userspace.
  44. */
  45. #define GH_VM_EXIT_REASON_UNKNOWN 0
  46. #define GH_VM_EXIT_REASON_SHUTDOWN 1
  47. #define GH_VM_EXIT_REASON_RESTART 2
  48. #define GH_VM_EXIT_REASON_PANIC 3
  49. #define GH_VM_EXIT_REASON_NSWD 4
  50. #define GH_VM_EXIT_REASON_HYP_ERROR 5
  51. #define GH_VM_EXIT_REASON_ASYNC_EXT_ABORT 6
  52. #define GH_VM_EXIT_REASON_FORCE_STOPPED 7
  53. #define GH_VM_EXIT_REASONS_MAX 8
  54. /*
  55. * ioctls for /dev/gunyah fds:
  56. */
  57. /**
  58. * GH_CREATE_VM - Driver creates a VM sepecific structure. An anon file is
  59. * also created per VM. This would be the first IOCTL made
  60. * on /dev/gunyah node to obtain a per VM fd for futher
  61. * VM specific operations like VCPU creation, memory etc.
  62. *
  63. * Return: an fd for the per VM file created, -errno on failure
  64. */
  65. #define GH_CREATE_VM _IO(GH_IOCTL_TYPE, 0x01)
  66. /*
  67. * ioctls for VM fd.
  68. */
  69. /**
  70. * GH_CREATE_VCPU - Driver creates a VCPU sepecific structure. It takes
  71. * vcpu id as the input. This also creates an anon file
  72. * per vcpu which is used for further vcpu specific
  73. * operations.
  74. *
  75. * Return: an fd for the per VCPU file created, -errno on failure
  76. */
  77. #define GH_CREATE_VCPU _IO(GH_IOCTL_TYPE, 0x40)
  78. /*
  79. * ioctls for VM properties
  80. */
  81. /**
  82. * GH_VM_SET_FW_NAME - Userspace will specify the name of the firmware
  83. * image that needs to be loaded into VM's memory
  84. * after authentication. The loaded VM memory details
  85. * are forwarded to Gunyah Hypervisor underneath.
  86. *
  87. * Input: gh_fw_name structure with Secure VM name as name attribute of
  88. * the struct.
  89. * Return: 0 if success, -errno on failure
  90. */
  91. #define GH_VM_SET_FW_NAME _IOW(GH_IOCTL_TYPE, 0x41, struct gh_fw_name)
  92. /**
  93. * GH_VM_GET_FW_NAME - Userspace can use this IOCTL to query the name of
  94. * the secure VM image that was loaded.
  95. *
  96. * Input: gh_fw_name structure to be filled with Secure VM name as the
  97. * name attribute of the struct.
  98. * Return: 0 if success and firmware name in struct fw_name that
  99. * represents the firmware image name currently associated with
  100. * the VM if a call to GH_VM_SET_FW_NAME ioctl previously was
  101. * successful, -errno on failure
  102. */
  103. #define GH_VM_GET_FW_NAME _IOR(GH_IOCTL_TYPE, 0x42, struct gh_fw_name)
  104. /**
  105. * GH_VM_GET_VCPU_COUNT - Userspace can use this IOCTL to query the number
  106. * of vcpus that are supported for the VM. Userspace
  107. * can further use this count to create VCPUs.
  108. *
  109. * Return: nr_vcpus for proxy scheduled VMs, 1 for hypervisor scheduled VMs,
  110. * -errno on failure
  111. */
  112. #define GH_VM_GET_VCPU_COUNT _IO(GH_IOCTL_TYPE, 0x43)
  113. /*
  114. * IOCTLs supported by virtio backend driver
  115. */
  116. /**
  117. * GH_GET_SHARED_MEMORY_SIZE - Userspace can use this IOCTL to query the virtio
  118. * shared memory size of the VM. Userpsace can use
  119. * it for mmap.
  120. *
  121. * Input: 64 bit unsigned integer variable to be filled with shared memory size.
  122. *
  123. * Return: 0 if success with shared memory size as u64 in the third argument,
  124. * -errno on failure
  125. */
  126. #define GH_GET_SHARED_MEMORY_SIZE _IOR(GH_IOCTL_TYPE, 0x61, __u64)
  127. /**
  128. * GH_IOEVENTFD - Eventfd created in userspace is passed to kernel using this
  129. * ioctl. Userspace is signalled by virtio backend driver through
  130. * this fd when data is available in the ring.
  131. *
  132. * Input: virtio_eventfd structure with required attributes.
  133. *
  134. * Return: 0 if success, -errno on failure
  135. */
  136. #define GH_IOEVENTFD _IOW(GH_IOCTL_TYPE, 0x62, \
  137. struct virtio_eventfd)
  138. /**
  139. * GH_IRQFD - Eventfd created in userspace is passed to kernel using this ioctl.
  140. * Virtio backned driver is signalled by userspace using this fd when
  141. * the ring is serviced.
  142. *
  143. * Input: virtio_irqfd structure with required attributes.
  144. *
  145. * Return: 0 if success, -errno on failure
  146. */
  147. #define GH_IRQFD _IOW(GH_IOCTL_TYPE, 0x63, \
  148. struct virtio_irqfd)
  149. /**
  150. * GH_WAIT_FOR_EVENT - Userspace waits for events from the virtio backend driver
  151. * for indefinite time. For example when hypervisor detects
  152. * a DRIVER_OK event, it is passed to userspace using this
  153. * ioctl.
  154. *
  155. * Input: virtio_event structure with required attributes.
  156. *
  157. * Return: 0 if success, with the event data in struct virtio_event
  158. * -errno on failure
  159. */
  160. #define GH_WAIT_FOR_EVENT _IOWR(GH_IOCTL_TYPE, 0x64, \
  161. struct virtio_event)
  162. /**
  163. * GH_SET_DEVICE_FEATURES - This ioctl writes virtio device features supported
  164. * by the userspace to a page that is shared with
  165. * guest VM.
  166. *
  167. * Input: virtio_dev_features structure with required attributes.
  168. *
  169. * Return: 0 if success, -errno on failure
  170. */
  171. #define GH_SET_DEVICE_FEATURES _IOW(GH_IOCTL_TYPE, 0x65, \
  172. struct virtio_dev_features)
  173. /**
  174. * GH_SET_QUEUE_NUM_MAX - This ioctl writes max virtio queue size supported by
  175. * the userspace to a page that is shared with guest VM.
  176. *
  177. * Input: virtio_queue_max structure with required attributes.
  178. *
  179. * Return: 0 if success, -errno on failure
  180. */
  181. #define GH_SET_QUEUE_NUM_MAX _IOW(GH_IOCTL_TYPE, 0x66, \
  182. struct virtio_queue_max)
  183. /**
  184. * GH_SET_DEVICE_CONFIG_DATA - This ioctl writes device configuration data
  185. * to a page that is shared with guest VM.
  186. *
  187. * Input: virtio_config_data structure with required attributes.
  188. *
  189. * Return: 0 if success, -errno on failure
  190. */
  191. #define GH_SET_DEVICE_CONFIG_DATA _IOW(GH_IOCTL_TYPE, 0x67, \
  192. struct virtio_config_data)
  193. /**
  194. * GH_GET_DRIVER_CONFIG_DATA - This ioctl reads the driver supported virtio
  195. * device configuration data from a page that is
  196. * shared with guest VM.
  197. *
  198. * Input: virtio_config_data structure with required attributes.
  199. *
  200. * Return: 0 if success with driver config data in struct virtio_config_data,
  201. * -errno on failure
  202. */
  203. #define GH_GET_DRIVER_CONFIG_DATA _IOWR(GH_IOCTL_TYPE, 0x68, \
  204. struct virtio_config_data)
  205. /**
  206. * GH_GET_QUEUE_INFO - This ioctl reads the driver supported virtqueue info from
  207. * a page that is shared with guest VM.
  208. *
  209. * Input: virtio_queue_info structure with required attributes.
  210. *
  211. * Return: 0 if success with virtqueue info in struct virtio_queue_info,
  212. * -errno on failure
  213. */
  214. #define GH_GET_QUEUE_INFO _IOWR(GH_IOCTL_TYPE, 0x69, \
  215. struct virtio_queue_info)
  216. /**
  217. * GH_GET_DRIVER_FEATURES - This ioctl reads the driver supported features from
  218. * a page that is shared with guest VM.
  219. *
  220. * Input: virtio_driver_features structure with required attributes.
  221. *
  222. * Return: 0 if success with driver features in struct virtio_driver_features,
  223. * -errno on failure
  224. */
  225. #define GH_GET_DRIVER_FEATURES _IOWR(GH_IOCTL_TYPE, 0x6a, \
  226. struct virtio_driver_features)
  227. /**
  228. * GH_ACK_DRIVER_OK - This ioctl acknowledges the DRIVER_OK event from virtio
  229. * backend driver.
  230. *
  231. * Input: 32 bit unsigned integer virtio device label.
  232. *
  233. * Return: 0 if success, -errno on failure
  234. */
  235. #define GH_ACK_DRIVER_OK _IOWR(GH_IOCTL_TYPE, 0x6b, __u32)
  236. /**
  237. * GH_ACK_RESET - This ioctl acknowledges the RESET event from virtio
  238. * backend driver.
  239. *
  240. * Input: virtio_ack_reset structure with required attributes.
  241. *
  242. * Return: 0 if success, -errno on failure
  243. */
  244. #define GH_ACK_RESET _IOW(GH_IOCTL_TYPE, 0x6d, struct virtio_ack_reset)
  245. /*
  246. * ioctls for vcpu fd.
  247. */
  248. /**
  249. * GH_VCPU_RUN - This command is used to run the vcpus created. VCPU_RUN
  250. * is called on vcpu fd created previously. VCPUs are
  251. * started individually if proxy scheduling is chosen as the
  252. * scheduling policy and vcpus are started simultaneously
  253. * in case of VMs whose scheduling is controlled by the
  254. * hypervisor. In the latter case, VCPU_RUN is blocked
  255. * until the VM terminates.
  256. *
  257. * Return: Reason for vm termination, -errno on failure
  258. */
  259. #define GH_VCPU_RUN _IO(GH_IOCTL_TYPE, 0x80)
  260. struct virtio_ack_reset {
  261. __u32 label;
  262. __u32 reserved;
  263. };
  264. struct virtio_driver_features {
  265. __u32 label;
  266. __u32 reserved;
  267. __u32 features_sel;
  268. __u32 features;
  269. };
  270. struct virtio_queue_info {
  271. __u32 label;
  272. __u32 queue_sel;
  273. __u32 queue_num;
  274. __u32 queue_ready;
  275. __u64 queue_desc;
  276. __u64 queue_driver;
  277. __u64 queue_device;
  278. };
  279. struct virtio_config_data {
  280. __u32 label;
  281. __u32 config_size;
  282. __u64 config_data;
  283. };
  284. struct virtio_dev_features {
  285. __u32 label;
  286. __u32 reserved;
  287. __u32 features_sel;
  288. __u32 features;
  289. };
  290. struct virtio_queue_max {
  291. __u32 label;
  292. __u32 reserved;
  293. __u32 queue_sel;
  294. __u32 queue_num_max;
  295. };
  296. struct virtio_event {
  297. __u32 label;
  298. __u32 event;
  299. __u32 event_data;
  300. __u32 reserved;
  301. };
  302. struct virtio_eventfd {
  303. __u32 label;
  304. __u32 flags;
  305. __u32 queue_num;
  306. __s32 fd;
  307. };
  308. struct virtio_irqfd {
  309. __u32 label;
  310. __u32 flags;
  311. __s32 fd;
  312. __u32 reserved;
  313. };
  314. #endif /* _UAPI_LINUX_GUNYAH */