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