vhost-user-gpu.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. /*
  2. * vhost-user GPU Device
  3. *
  4. * Copyright Red Hat, Inc. 2018
  5. *
  6. * Authors:
  7. * Marc-André Lureau <marcandre.lureau@redhat.com>
  8. *
  9. * This work is licensed under the terms of the GNU GPL, version 2 or later.
  10. * See the COPYING file in the top-level directory.
  11. */
  12. #include "qemu/osdep.h"
  13. #include "qemu/error-report.h"
  14. #include "qemu/sockets.h"
  15. #include "hw/qdev-properties.h"
  16. #include "hw/virtio/virtio-gpu.h"
  17. #include "chardev/char-fe.h"
  18. #include "qapi/error.h"
  19. #include "migration/blocker.h"
  20. typedef enum VhostUserGpuRequest {
  21. VHOST_USER_GPU_NONE = 0,
  22. VHOST_USER_GPU_GET_PROTOCOL_FEATURES,
  23. VHOST_USER_GPU_SET_PROTOCOL_FEATURES,
  24. VHOST_USER_GPU_GET_DISPLAY_INFO,
  25. VHOST_USER_GPU_CURSOR_POS,
  26. VHOST_USER_GPU_CURSOR_POS_HIDE,
  27. VHOST_USER_GPU_CURSOR_UPDATE,
  28. VHOST_USER_GPU_SCANOUT,
  29. VHOST_USER_GPU_UPDATE,
  30. VHOST_USER_GPU_DMABUF_SCANOUT,
  31. VHOST_USER_GPU_DMABUF_UPDATE,
  32. } VhostUserGpuRequest;
  33. typedef struct VhostUserGpuDisplayInfoReply {
  34. struct virtio_gpu_resp_display_info info;
  35. } VhostUserGpuDisplayInfoReply;
  36. typedef struct VhostUserGpuCursorPos {
  37. uint32_t scanout_id;
  38. uint32_t x;
  39. uint32_t y;
  40. } QEMU_PACKED VhostUserGpuCursorPos;
  41. typedef struct VhostUserGpuCursorUpdate {
  42. VhostUserGpuCursorPos pos;
  43. uint32_t hot_x;
  44. uint32_t hot_y;
  45. uint32_t data[64 * 64];
  46. } QEMU_PACKED VhostUserGpuCursorUpdate;
  47. typedef struct VhostUserGpuScanout {
  48. uint32_t scanout_id;
  49. uint32_t width;
  50. uint32_t height;
  51. } QEMU_PACKED VhostUserGpuScanout;
  52. typedef struct VhostUserGpuUpdate {
  53. uint32_t scanout_id;
  54. uint32_t x;
  55. uint32_t y;
  56. uint32_t width;
  57. uint32_t height;
  58. uint8_t data[];
  59. } QEMU_PACKED VhostUserGpuUpdate;
  60. typedef struct VhostUserGpuDMABUFScanout {
  61. uint32_t scanout_id;
  62. uint32_t x;
  63. uint32_t y;
  64. uint32_t width;
  65. uint32_t height;
  66. uint32_t fd_width;
  67. uint32_t fd_height;
  68. uint32_t fd_stride;
  69. uint32_t fd_flags;
  70. int fd_drm_fourcc;
  71. } QEMU_PACKED VhostUserGpuDMABUFScanout;
  72. typedef struct VhostUserGpuMsg {
  73. uint32_t request; /* VhostUserGpuRequest */
  74. uint32_t flags;
  75. uint32_t size; /* the following payload size */
  76. union {
  77. VhostUserGpuCursorPos cursor_pos;
  78. VhostUserGpuCursorUpdate cursor_update;
  79. VhostUserGpuScanout scanout;
  80. VhostUserGpuUpdate update;
  81. VhostUserGpuDMABUFScanout dmabuf_scanout;
  82. struct virtio_gpu_resp_display_info display_info;
  83. uint64_t u64;
  84. } payload;
  85. } QEMU_PACKED VhostUserGpuMsg;
  86. static VhostUserGpuMsg m __attribute__ ((unused));
  87. #define VHOST_USER_GPU_HDR_SIZE \
  88. (sizeof(m.request) + sizeof(m.size) + sizeof(m.flags))
  89. #define VHOST_USER_GPU_MSG_FLAG_REPLY 0x4
  90. static void vhost_user_gpu_update_blocked(VhostUserGPU *g, bool blocked);
  91. static void
  92. vhost_user_gpu_handle_cursor(VhostUserGPU *g, VhostUserGpuMsg *msg)
  93. {
  94. VhostUserGpuCursorPos *pos = &msg->payload.cursor_pos;
  95. struct virtio_gpu_scanout *s;
  96. if (pos->scanout_id >= g->parent_obj.conf.max_outputs) {
  97. return;
  98. }
  99. s = &g->parent_obj.scanout[pos->scanout_id];
  100. if (msg->request == VHOST_USER_GPU_CURSOR_UPDATE) {
  101. VhostUserGpuCursorUpdate *up = &msg->payload.cursor_update;
  102. if (!s->current_cursor) {
  103. s->current_cursor = cursor_alloc(64, 64);
  104. }
  105. s->current_cursor->hot_x = up->hot_x;
  106. s->current_cursor->hot_y = up->hot_y;
  107. memcpy(s->current_cursor->data, up->data,
  108. 64 * 64 * sizeof(uint32_t));
  109. dpy_cursor_define(s->con, s->current_cursor);
  110. }
  111. dpy_mouse_set(s->con, pos->x, pos->y,
  112. msg->request != VHOST_USER_GPU_CURSOR_POS_HIDE);
  113. }
  114. static void
  115. vhost_user_gpu_send_msg(VhostUserGPU *g, const VhostUserGpuMsg *msg)
  116. {
  117. qemu_chr_fe_write(&g->vhost_chr, (uint8_t *)msg,
  118. VHOST_USER_GPU_HDR_SIZE + msg->size);
  119. }
  120. static void
  121. vhost_user_gpu_unblock(VhostUserGPU *g)
  122. {
  123. VhostUserGpuMsg msg = {
  124. .request = VHOST_USER_GPU_DMABUF_UPDATE,
  125. .flags = VHOST_USER_GPU_MSG_FLAG_REPLY,
  126. };
  127. vhost_user_gpu_send_msg(g, &msg);
  128. }
  129. static void
  130. vhost_user_gpu_handle_display(VhostUserGPU *g, VhostUserGpuMsg *msg)
  131. {
  132. QemuConsole *con = NULL;
  133. struct virtio_gpu_scanout *s;
  134. switch (msg->request) {
  135. case VHOST_USER_GPU_GET_PROTOCOL_FEATURES: {
  136. VhostUserGpuMsg reply = {
  137. .request = msg->request,
  138. .flags = VHOST_USER_GPU_MSG_FLAG_REPLY,
  139. .size = sizeof(uint64_t),
  140. };
  141. vhost_user_gpu_send_msg(g, &reply);
  142. break;
  143. }
  144. case VHOST_USER_GPU_SET_PROTOCOL_FEATURES: {
  145. break;
  146. }
  147. case VHOST_USER_GPU_GET_DISPLAY_INFO: {
  148. struct virtio_gpu_resp_display_info display_info = { {} };
  149. VhostUserGpuMsg reply = {
  150. .request = msg->request,
  151. .flags = VHOST_USER_GPU_MSG_FLAG_REPLY,
  152. .size = sizeof(struct virtio_gpu_resp_display_info),
  153. };
  154. display_info.hdr.type = VIRTIO_GPU_RESP_OK_DISPLAY_INFO;
  155. virtio_gpu_base_fill_display_info(VIRTIO_GPU_BASE(g), &display_info);
  156. memcpy(&reply.payload.display_info, &display_info,
  157. sizeof(display_info));
  158. vhost_user_gpu_send_msg(g, &reply);
  159. break;
  160. }
  161. case VHOST_USER_GPU_SCANOUT: {
  162. VhostUserGpuScanout *m = &msg->payload.scanout;
  163. if (m->scanout_id >= g->parent_obj.conf.max_outputs) {
  164. return;
  165. }
  166. g->parent_obj.enable = 1;
  167. s = &g->parent_obj.scanout[m->scanout_id];
  168. con = s->con;
  169. if (m->width == 0) {
  170. dpy_gfx_replace_surface(con, NULL);
  171. } else {
  172. s->ds = qemu_create_displaysurface(m->width, m->height);
  173. /* replace surface on next update */
  174. }
  175. break;
  176. }
  177. case VHOST_USER_GPU_DMABUF_SCANOUT: {
  178. VhostUserGpuDMABUFScanout *m = &msg->payload.dmabuf_scanout;
  179. int fd = qemu_chr_fe_get_msgfd(&g->vhost_chr);
  180. QemuDmaBuf *dmabuf;
  181. if (m->scanout_id >= g->parent_obj.conf.max_outputs) {
  182. error_report("invalid scanout: %d", m->scanout_id);
  183. if (fd >= 0) {
  184. close(fd);
  185. }
  186. break;
  187. }
  188. g->parent_obj.enable = 1;
  189. con = g->parent_obj.scanout[m->scanout_id].con;
  190. dmabuf = &g->dmabuf[m->scanout_id];
  191. if (dmabuf->fd >= 0) {
  192. close(dmabuf->fd);
  193. dmabuf->fd = -1;
  194. }
  195. dpy_gl_release_dmabuf(con, dmabuf);
  196. if (fd == -1) {
  197. dpy_gl_scanout_disable(con);
  198. break;
  199. }
  200. *dmabuf = (QemuDmaBuf) {
  201. .fd = fd,
  202. .width = m->fd_width,
  203. .height = m->fd_height,
  204. .stride = m->fd_stride,
  205. .fourcc = m->fd_drm_fourcc,
  206. .y0_top = m->fd_flags & VIRTIO_GPU_RESOURCE_FLAG_Y_0_TOP,
  207. };
  208. dpy_gl_scanout_dmabuf(con, dmabuf);
  209. break;
  210. }
  211. case VHOST_USER_GPU_DMABUF_UPDATE: {
  212. VhostUserGpuUpdate *m = &msg->payload.update;
  213. if (m->scanout_id >= g->parent_obj.conf.max_outputs ||
  214. !g->parent_obj.scanout[m->scanout_id].con) {
  215. error_report("invalid scanout update: %d", m->scanout_id);
  216. vhost_user_gpu_unblock(g);
  217. break;
  218. }
  219. con = g->parent_obj.scanout[m->scanout_id].con;
  220. if (!console_has_gl(con)) {
  221. error_report("console doesn't support GL!");
  222. vhost_user_gpu_unblock(g);
  223. break;
  224. }
  225. g->backend_blocked = true;
  226. dpy_gl_update(con, m->x, m->y, m->width, m->height);
  227. break;
  228. }
  229. case VHOST_USER_GPU_UPDATE: {
  230. VhostUserGpuUpdate *m = &msg->payload.update;
  231. if (m->scanout_id >= g->parent_obj.conf.max_outputs) {
  232. break;
  233. }
  234. s = &g->parent_obj.scanout[m->scanout_id];
  235. con = s->con;
  236. pixman_image_t *image =
  237. pixman_image_create_bits(PIXMAN_x8r8g8b8,
  238. m->width,
  239. m->height,
  240. (uint32_t *)m->data,
  241. m->width * 4);
  242. pixman_image_composite(PIXMAN_OP_SRC,
  243. image, NULL, s->ds->image,
  244. 0, 0, 0, 0, m->x, m->y, m->width, m->height);
  245. pixman_image_unref(image);
  246. if (qemu_console_surface(con) != s->ds) {
  247. dpy_gfx_replace_surface(con, s->ds);
  248. } else {
  249. dpy_gfx_update(con, m->x, m->y, m->width, m->height);
  250. }
  251. break;
  252. }
  253. default:
  254. g_warning("unhandled message %d %d", msg->request, msg->size);
  255. }
  256. if (con && qemu_console_is_gl_blocked(con)) {
  257. vhost_user_gpu_update_blocked(g, true);
  258. }
  259. }
  260. static void
  261. vhost_user_gpu_chr_read(void *opaque)
  262. {
  263. VhostUserGPU *g = opaque;
  264. VhostUserGpuMsg *msg = NULL;
  265. VhostUserGpuRequest request;
  266. uint32_t size, flags;
  267. int r;
  268. r = qemu_chr_fe_read_all(&g->vhost_chr,
  269. (uint8_t *)&request, sizeof(uint32_t));
  270. if (r != sizeof(uint32_t)) {
  271. error_report("failed to read msg header: %d, %d", r, errno);
  272. goto end;
  273. }
  274. r = qemu_chr_fe_read_all(&g->vhost_chr,
  275. (uint8_t *)&flags, sizeof(uint32_t));
  276. if (r != sizeof(uint32_t)) {
  277. error_report("failed to read msg flags");
  278. goto end;
  279. }
  280. r = qemu_chr_fe_read_all(&g->vhost_chr,
  281. (uint8_t *)&size, sizeof(uint32_t));
  282. if (r != sizeof(uint32_t)) {
  283. error_report("failed to read msg size");
  284. goto end;
  285. }
  286. msg = g_malloc(VHOST_USER_GPU_HDR_SIZE + size);
  287. r = qemu_chr_fe_read_all(&g->vhost_chr,
  288. (uint8_t *)&msg->payload, size);
  289. if (r != size) {
  290. error_report("failed to read msg payload %d != %d", r, size);
  291. goto end;
  292. }
  293. msg->request = request;
  294. msg->flags = size;
  295. msg->size = size;
  296. if (request == VHOST_USER_GPU_CURSOR_UPDATE ||
  297. request == VHOST_USER_GPU_CURSOR_POS ||
  298. request == VHOST_USER_GPU_CURSOR_POS_HIDE) {
  299. vhost_user_gpu_handle_cursor(g, msg);
  300. } else {
  301. vhost_user_gpu_handle_display(g, msg);
  302. }
  303. end:
  304. g_free(msg);
  305. }
  306. static void
  307. vhost_user_gpu_update_blocked(VhostUserGPU *g, bool blocked)
  308. {
  309. qemu_set_fd_handler(g->vhost_gpu_fd,
  310. blocked ? NULL : vhost_user_gpu_chr_read, NULL, g);
  311. }
  312. static void
  313. vhost_user_gpu_gl_flushed(VirtIOGPUBase *b)
  314. {
  315. VhostUserGPU *g = VHOST_USER_GPU(b);
  316. if (g->backend_blocked) {
  317. vhost_user_gpu_unblock(g);
  318. g->backend_blocked = false;
  319. }
  320. vhost_user_gpu_update_blocked(g, false);
  321. }
  322. static bool
  323. vhost_user_gpu_do_set_socket(VhostUserGPU *g, Error **errp)
  324. {
  325. Chardev *chr;
  326. int sv[2];
  327. if (qemu_socketpair(PF_UNIX, SOCK_STREAM, 0, sv) == -1) {
  328. error_setg_errno(errp, errno, "socketpair() failed");
  329. return false;
  330. }
  331. chr = CHARDEV(object_new(TYPE_CHARDEV_SOCKET));
  332. if (!chr || qemu_chr_add_client(chr, sv[0]) == -1) {
  333. error_setg(errp, "Failed to make socket chardev");
  334. goto err;
  335. }
  336. if (!qemu_chr_fe_init(&g->vhost_chr, chr, errp)) {
  337. goto err;
  338. }
  339. if (vhost_user_gpu_set_socket(&g->vhost->dev, sv[1]) < 0) {
  340. error_setg(errp, "Failed to set vhost-user-gpu socket");
  341. qemu_chr_fe_deinit(&g->vhost_chr, false);
  342. goto err;
  343. }
  344. g->vhost_gpu_fd = sv[0];
  345. vhost_user_gpu_update_blocked(g, false);
  346. close(sv[1]);
  347. return true;
  348. err:
  349. close(sv[0]);
  350. close(sv[1]);
  351. if (chr) {
  352. object_unref(OBJECT(chr));
  353. }
  354. return false;
  355. }
  356. static void
  357. vhost_user_gpu_get_config(VirtIODevice *vdev, uint8_t *config_data)
  358. {
  359. VhostUserGPU *g = VHOST_USER_GPU(vdev);
  360. VirtIOGPUBase *b = VIRTIO_GPU_BASE(vdev);
  361. struct virtio_gpu_config *vgconfig =
  362. (struct virtio_gpu_config *)config_data;
  363. Error *local_err = NULL;
  364. int ret;
  365. memset(config_data, 0, sizeof(struct virtio_gpu_config));
  366. ret = vhost_dev_get_config(&g->vhost->dev,
  367. config_data, sizeof(struct virtio_gpu_config),
  368. &local_err);
  369. if (ret) {
  370. error_report_err(local_err);
  371. return;
  372. }
  373. /* those fields are managed by qemu */
  374. vgconfig->num_scanouts = b->virtio_config.num_scanouts;
  375. vgconfig->events_read = b->virtio_config.events_read;
  376. vgconfig->events_clear = b->virtio_config.events_clear;
  377. }
  378. static void
  379. vhost_user_gpu_set_config(VirtIODevice *vdev,
  380. const uint8_t *config_data)
  381. {
  382. VhostUserGPU *g = VHOST_USER_GPU(vdev);
  383. VirtIOGPUBase *b = VIRTIO_GPU_BASE(vdev);
  384. const struct virtio_gpu_config *vgconfig =
  385. (const struct virtio_gpu_config *)config_data;
  386. int ret;
  387. if (vgconfig->events_clear) {
  388. b->virtio_config.events_read &= ~vgconfig->events_clear;
  389. }
  390. ret = vhost_dev_set_config(&g->vhost->dev, config_data,
  391. 0, sizeof(struct virtio_gpu_config),
  392. VHOST_SET_CONFIG_TYPE_FRONTEND);
  393. if (ret) {
  394. error_report("vhost-user-gpu: set device config space failed");
  395. return;
  396. }
  397. }
  398. static void
  399. vhost_user_gpu_set_status(VirtIODevice *vdev, uint8_t val)
  400. {
  401. VhostUserGPU *g = VHOST_USER_GPU(vdev);
  402. Error *err = NULL;
  403. if (val & VIRTIO_CONFIG_S_DRIVER_OK && vdev->vm_running) {
  404. if (!vhost_user_gpu_do_set_socket(g, &err)) {
  405. error_report_err(err);
  406. return;
  407. }
  408. vhost_user_backend_start(g->vhost);
  409. } else {
  410. /* unblock any wait and stop processing */
  411. if (g->vhost_gpu_fd != -1) {
  412. vhost_user_gpu_update_blocked(g, true);
  413. qemu_chr_fe_deinit(&g->vhost_chr, true);
  414. g->vhost_gpu_fd = -1;
  415. }
  416. vhost_user_backend_stop(g->vhost);
  417. }
  418. }
  419. static bool
  420. vhost_user_gpu_guest_notifier_pending(VirtIODevice *vdev, int idx)
  421. {
  422. VhostUserGPU *g = VHOST_USER_GPU(vdev);
  423. /*
  424. * Add the check for configure interrupt, Use VIRTIO_CONFIG_IRQ_IDX -1
  425. * as the Marco of configure interrupt's IDX, If this driver does not
  426. * support, the function will return
  427. */
  428. if (idx == VIRTIO_CONFIG_IRQ_IDX) {
  429. return false;
  430. }
  431. return vhost_virtqueue_pending(&g->vhost->dev, idx);
  432. }
  433. static void
  434. vhost_user_gpu_guest_notifier_mask(VirtIODevice *vdev, int idx, bool mask)
  435. {
  436. VhostUserGPU *g = VHOST_USER_GPU(vdev);
  437. /*
  438. * Add the check for configure interrupt, Use VIRTIO_CONFIG_IRQ_IDX -1
  439. * as the Marco of configure interrupt's IDX, If this driver does not
  440. * support, the function will return
  441. */
  442. if (idx == VIRTIO_CONFIG_IRQ_IDX) {
  443. return;
  444. }
  445. vhost_virtqueue_mask(&g->vhost->dev, vdev, idx, mask);
  446. }
  447. static void
  448. vhost_user_gpu_instance_init(Object *obj)
  449. {
  450. VhostUserGPU *g = VHOST_USER_GPU(obj);
  451. g->vhost = VHOST_USER_BACKEND(object_new(TYPE_VHOST_USER_BACKEND));
  452. object_property_add_alias(obj, "chardev",
  453. OBJECT(g->vhost), "chardev");
  454. }
  455. static void
  456. vhost_user_gpu_instance_finalize(Object *obj)
  457. {
  458. VhostUserGPU *g = VHOST_USER_GPU(obj);
  459. object_unref(OBJECT(g->vhost));
  460. }
  461. static void
  462. vhost_user_gpu_reset(VirtIODevice *vdev)
  463. {
  464. VhostUserGPU *g = VHOST_USER_GPU(vdev);
  465. virtio_gpu_base_reset(VIRTIO_GPU_BASE(vdev));
  466. vhost_user_backend_stop(g->vhost);
  467. }
  468. static int
  469. vhost_user_gpu_config_change(struct vhost_dev *dev)
  470. {
  471. error_report("vhost-user-gpu: unhandled backend config change");
  472. return -1;
  473. }
  474. static const VhostDevConfigOps config_ops = {
  475. .vhost_dev_config_notifier = vhost_user_gpu_config_change,
  476. };
  477. static void
  478. vhost_user_gpu_device_realize(DeviceState *qdev, Error **errp)
  479. {
  480. VhostUserGPU *g = VHOST_USER_GPU(qdev);
  481. VirtIODevice *vdev = VIRTIO_DEVICE(g);
  482. vhost_dev_set_config_notifier(&g->vhost->dev, &config_ops);
  483. if (vhost_user_backend_dev_init(g->vhost, vdev, 2, errp) < 0) {
  484. return;
  485. }
  486. /* existing backend may send DMABUF, so let's add that requirement */
  487. g->parent_obj.conf.flags |= 1 << VIRTIO_GPU_FLAG_DMABUF_ENABLED;
  488. if (virtio_has_feature(g->vhost->dev.features, VIRTIO_GPU_F_VIRGL)) {
  489. g->parent_obj.conf.flags |= 1 << VIRTIO_GPU_FLAG_VIRGL_ENABLED;
  490. }
  491. if (virtio_has_feature(g->vhost->dev.features, VIRTIO_GPU_F_EDID)) {
  492. g->parent_obj.conf.flags |= 1 << VIRTIO_GPU_FLAG_EDID_ENABLED;
  493. } else {
  494. error_report("EDID requested but the backend doesn't support it.");
  495. g->parent_obj.conf.flags &= ~(1 << VIRTIO_GPU_FLAG_EDID_ENABLED);
  496. }
  497. if (!virtio_gpu_base_device_realize(qdev, NULL, NULL, errp)) {
  498. return;
  499. }
  500. g->vhost_gpu_fd = -1;
  501. }
  502. static struct vhost_dev *vhost_user_gpu_get_vhost(VirtIODevice *vdev)
  503. {
  504. VhostUserGPU *g = VHOST_USER_GPU(vdev);
  505. return &g->vhost->dev;
  506. }
  507. static Property vhost_user_gpu_properties[] = {
  508. VIRTIO_GPU_BASE_PROPERTIES(VhostUserGPU, parent_obj.conf),
  509. DEFINE_PROP_END_OF_LIST(),
  510. };
  511. static void
  512. vhost_user_gpu_class_init(ObjectClass *klass, void *data)
  513. {
  514. DeviceClass *dc = DEVICE_CLASS(klass);
  515. VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
  516. VirtIOGPUBaseClass *vgc = VIRTIO_GPU_BASE_CLASS(klass);
  517. vgc->gl_flushed = vhost_user_gpu_gl_flushed;
  518. vdc->realize = vhost_user_gpu_device_realize;
  519. vdc->reset = vhost_user_gpu_reset;
  520. vdc->set_status = vhost_user_gpu_set_status;
  521. vdc->guest_notifier_mask = vhost_user_gpu_guest_notifier_mask;
  522. vdc->guest_notifier_pending = vhost_user_gpu_guest_notifier_pending;
  523. vdc->get_config = vhost_user_gpu_get_config;
  524. vdc->set_config = vhost_user_gpu_set_config;
  525. vdc->get_vhost = vhost_user_gpu_get_vhost;
  526. device_class_set_props(dc, vhost_user_gpu_properties);
  527. }
  528. static const TypeInfo vhost_user_gpu_info = {
  529. .name = TYPE_VHOST_USER_GPU,
  530. .parent = TYPE_VIRTIO_GPU_BASE,
  531. .instance_size = sizeof(VhostUserGPU),
  532. .instance_init = vhost_user_gpu_instance_init,
  533. .instance_finalize = vhost_user_gpu_instance_finalize,
  534. .class_init = vhost_user_gpu_class_init,
  535. };
  536. module_obj(TYPE_VHOST_USER_GPU);
  537. module_kconfig(VHOST_USER_GPU);
  538. static void vhost_user_gpu_register_types(void)
  539. {
  540. type_register_static(&vhost_user_gpu_info);
  541. }
  542. type_init(vhost_user_gpu_register_types)