blob: db50b46d9babc5bfb248e066259426847ccdd056 [file] [log] [blame]
Gurchetan Singh73c141e2021-01-21 14:51:19 -08001/*
2 * Copyright 2021 The Chromium OS Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
5 */
6
7#include <errno.h>
8#include <stdbool.h>
9#include <stdio.h>
10#include <string.h>
11#include <unistd.h>
12#include <xf86drm.h>
13
14#include "drv_priv.h"
15#include "external/virtgpu_drm.h"
Gurchetan Singh73c141e2021-01-21 14:51:19 -080016#include "util.h"
17#include "virtgpu.h"
18
19#define PARAM(x) \
Gurchetan Singhbbde01e2021-02-17 08:54:28 -080020 (struct virtgpu_param) \
Gurchetan Singh73c141e2021-01-21 14:51:19 -080021 { \
22 x, #x, 0 \
23 }
24
25struct virtgpu_param params[] = {
26 PARAM(VIRTGPU_PARAM_3D_FEATURES), PARAM(VIRTGPU_PARAM_CAPSET_QUERY_FIX),
27 PARAM(VIRTGPU_PARAM_RESOURCE_BLOB), PARAM(VIRTGPU_PARAM_HOST_VISIBLE),
28 PARAM(VIRTGPU_PARAM_CROSS_DEVICE), PARAM(VIRTGPU_PARAM_CONTEXT_INIT),
Gurchetan Singhb2917b22021-04-28 16:24:49 -070029 PARAM(VIRTGPU_PARAM_SUPPORTED_CAPSET_IDs), PARAM(VIRTGPU_PARAM_CREATE_GUEST_HANDLE),
30 PARAM(VIRTGPU_PARAM_RESOURCE_SYNC), PARAM(VIRTGPU_PARAM_GUEST_VRAM),
Gurchetan Singh73c141e2021-01-21 14:51:19 -080031};
32
33extern const struct backend virtgpu_virgl;
34extern const struct backend virtgpu_cross_domain;
35
36static int virtgpu_init(struct driver *drv)
37{
38 int ret = 0;
39 const struct backend *virtgpu_backends[2] = {
40 &virtgpu_cross_domain,
41 &virtgpu_virgl,
42 };
43
44 for (uint32_t i = 0; i < ARRAY_SIZE(params); i++) {
45 struct drm_virtgpu_getparam get_param = { 0 };
46
47 get_param.param = params[i].param;
48 get_param.value = (uint64_t)(uintptr_t)&params[i].value;
49 int ret = drmIoctl(drv->fd, DRM_IOCTL_VIRTGPU_GETPARAM, &get_param);
50 if (ret)
Jason Macnak73757bf2021-09-17 10:49:57 -070051 drv_log("virtgpu backend not enabling %s\n", params[i].name);
Gurchetan Singh73c141e2021-01-21 14:51:19 -080052 }
53
54 for (uint32_t i = 0; i < ARRAY_SIZE(virtgpu_backends); i++) {
55 const struct backend *backend = virtgpu_backends[i];
56 ret = backend->init(drv);
57 if (ret)
58 continue;
59
60 drv->backend = backend;
61 return 0;
62 }
63
64 return ret;
65}
66
67const struct backend backend_virtgpu = {
68 .name = "virtio_gpu",
69 .init = virtgpu_init,
70};