xref: /aosp_15_r20/external/mesa3d/src/virtio/virtio-gpu/drm_hw.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright 2022 Google LLC
3  * SPDX-License-Identifier: MIT
4  */
5 
6 #ifndef DRM_HW_H_
7 #define DRM_HW_H_
8 
9 struct virgl_renderer_capset_drm {
10    uint32_t wire_format_version;
11    /* Underlying drm device version: */
12    uint32_t version_major;
13    uint32_t version_minor;
14    uint32_t version_patchlevel;
15 #define VIRTGPU_DRM_CONTEXT_MSM   1
16    uint32_t context_type;
17    uint32_t pad;
18    union {
19       struct {
20          uint32_t has_cached_coherent;
21          uint32_t priorities;
22          uint64_t va_start;
23          uint64_t va_size;
24          uint32_t gpu_id;
25          uint32_t gmem_size;
26          uint64_t gmem_base;
27          uint64_t chip_id;
28          uint32_t max_freq;
29       } msm;  /* context_type == VIRTGPU_DRM_CONTEXT_MSM */
30    } u;
31 };
32 
33 /**
34  * Defines the layout of shmem buffer used for host->guest communication.
35  */
36 struct vdrm_shmem {
37    /**
38     * The sequence # of last cmd processed by the host
39     */
40    uint32_t seqno;
41 
42    /**
43     * Offset to the start of rsp memory region in the shmem buffer.  This
44     * is set by the host when the shmem buffer is allocated, to allow for
45     * extending the shmem buffer with new fields.  The size of the rsp
46     * memory region is the size of the shmem buffer (controlled by the
47     * guest) minus rsp_mem_offset.
48     *
49     * The guest should use the vdrm_shmem_has_field() macro to determine
50     * if the host supports a given field, ie. to handle compatibility of
51     * newer guest vs older host.
52     *
53     * Making the guest userspace responsible for backwards compatibility
54     * simplifies the host VMM.
55     */
56    uint32_t rsp_mem_offset;
57 
58 #define vdrm_shmem_has_field(shmem, field) ({                             \
59       struct vdrm_shmem *_shmem = &(shmem)->base;                         \
60       (_shmem->rsp_mem_offset > offsetof(__typeof__(*(shmem)), field));   \
61    })
62 };
63 
64 /**
65  * A Guest -> Host request header.
66  */
67 struct vdrm_ccmd_req {
68    uint32_t cmd;
69    uint32_t len;
70    uint32_t seqno;
71 
72    /* Offset into shmem ctrl buffer to write response.  The host ensures
73     * that it doesn't write outside the bounds of the ctrl buffer, but
74     * otherwise it is up to the guest to manage allocation of where responses
75     * should be written in the ctrl buf.
76     *
77     * Only applicable for cmds that have a response message.
78     */
79    uint32_t rsp_off;
80 };
81 
82 /**
83  * A Guest <- Host response header.
84  */
85 struct vdrm_ccmd_rsp {
86    uint32_t len;
87 };
88 
89 #define DEFINE_CAST(parent, child)                                             \
90    static inline struct child *to_##child(const struct parent *x)              \
91    {                                                                           \
92       return (struct child *)x;                                                \
93    }
94 
95 #endif /* DRM_HW_H_ */
96