1 1.1 riastrad /* $NetBSD: xen_drm_front.h,v 1.2 2021/12/18 23:45:45 riastradh Exp $ */ 2 1.1 riastrad 3 1.1 riastrad /* SPDX-License-Identifier: GPL-2.0 OR MIT */ 4 1.1 riastrad 5 1.1 riastrad /* 6 1.1 riastrad * Xen para-virtual DRM device 7 1.1 riastrad * 8 1.1 riastrad * Copyright (C) 2016-2018 EPAM Systems Inc. 9 1.1 riastrad * 10 1.1 riastrad * Author: Oleksandr Andrushchenko <oleksandr_andrushchenko (at) epam.com> 11 1.1 riastrad */ 12 1.1 riastrad 13 1.1 riastrad #ifndef __XEN_DRM_FRONT_H_ 14 1.1 riastrad #define __XEN_DRM_FRONT_H_ 15 1.1 riastrad 16 1.1 riastrad #include <linux/scatterlist.h> 17 1.1 riastrad 18 1.1 riastrad #include <drm/drm_connector.h> 19 1.1 riastrad #include <drm/drm_simple_kms_helper.h> 20 1.1 riastrad 21 1.1 riastrad #include "xen_drm_front_cfg.h" 22 1.1 riastrad 23 1.1 riastrad struct drm_device; 24 1.1 riastrad struct drm_framebuffer; 25 1.1 riastrad struct drm_gem_object; 26 1.1 riastrad struct drm_pending_vblank_event; 27 1.1 riastrad 28 1.1 riastrad /** 29 1.1 riastrad * DOC: Driver modes of operation in terms of display buffers used 30 1.1 riastrad * 31 1.1 riastrad * Depending on the requirements for the para-virtualized environment, namely 32 1.1 riastrad * requirements dictated by the accompanying DRM/(v)GPU drivers running in both 33 1.1 riastrad * host and guest environments, display buffers can be allocated by either 34 1.1 riastrad * frontend driver or backend. 35 1.1 riastrad */ 36 1.1 riastrad 37 1.1 riastrad /** 38 1.1 riastrad * DOC: Buffers allocated by the frontend driver 39 1.1 riastrad * 40 1.1 riastrad * In this mode of operation driver allocates buffers from system memory. 41 1.1 riastrad * 42 1.1 riastrad * Note! If used with accompanying DRM/(v)GPU drivers this mode of operation 43 1.1 riastrad * may require IOMMU support on the platform, so accompanying DRM/vGPU 44 1.1 riastrad * hardware can still reach display buffer memory while importing PRIME 45 1.1 riastrad * buffers from the frontend driver. 46 1.1 riastrad */ 47 1.1 riastrad 48 1.1 riastrad /** 49 1.1 riastrad * DOC: Buffers allocated by the backend 50 1.1 riastrad * 51 1.1 riastrad * This mode of operation is run-time configured via guest domain configuration 52 1.1 riastrad * through XenStore entries. 53 1.1 riastrad * 54 1.1 riastrad * For systems which do not provide IOMMU support, but having specific 55 1.1 riastrad * requirements for display buffers it is possible to allocate such buffers 56 1.1 riastrad * at backend side and share those with the frontend. 57 1.1 riastrad * For example, if host domain is 1:1 mapped and has DRM/GPU hardware expecting 58 1.1 riastrad * physically contiguous memory, this allows implementing zero-copying 59 1.1 riastrad * use-cases. 60 1.1 riastrad * 61 1.1 riastrad * Note, while using this scenario the following should be considered: 62 1.1 riastrad * 63 1.1 riastrad * #. If guest domain dies then pages/grants received from the backend 64 1.1 riastrad * cannot be claimed back 65 1.1 riastrad * 66 1.1 riastrad * #. Misbehaving guest may send too many requests to the 67 1.1 riastrad * backend exhausting its grant references and memory 68 1.1 riastrad * (consider this from security POV) 69 1.1 riastrad */ 70 1.1 riastrad 71 1.1 riastrad /** 72 1.1 riastrad * DOC: Driver limitations 73 1.1 riastrad * 74 1.1 riastrad * #. Only primary plane without additional properties is supported. 75 1.1 riastrad * 76 1.1 riastrad * #. Only one video mode per connector supported which is configured 77 1.1 riastrad * via XenStore. 78 1.1 riastrad * 79 1.1 riastrad * #. All CRTCs operate at fixed frequency of 60Hz. 80 1.1 riastrad */ 81 1.1 riastrad 82 1.1 riastrad /* timeout in ms to wait for backend to respond */ 83 1.1 riastrad #define XEN_DRM_FRONT_WAIT_BACK_MS 3000 84 1.1 riastrad 85 1.1 riastrad #ifndef GRANT_INVALID_REF 86 1.1 riastrad /* 87 1.1 riastrad * Note on usage of grant reference 0 as invalid grant reference: 88 1.1 riastrad * grant reference 0 is valid, but never exposed to a PV driver, 89 1.1 riastrad * because of the fact it is already in use/reserved by the PV console. 90 1.1 riastrad */ 91 1.1 riastrad #define GRANT_INVALID_REF 0 92 1.1 riastrad #endif 93 1.1 riastrad 94 1.1 riastrad struct xen_drm_front_info { 95 1.1 riastrad struct xenbus_device *xb_dev; 96 1.1 riastrad struct xen_drm_front_drm_info *drm_info; 97 1.1 riastrad 98 1.1 riastrad /* to protect data between backend IO code and interrupt handler */ 99 1.1 riastrad spinlock_t io_lock; 100 1.1 riastrad 101 1.1 riastrad int num_evt_pairs; 102 1.1 riastrad struct xen_drm_front_evtchnl_pair *evt_pairs; 103 1.1 riastrad struct xen_drm_front_cfg cfg; 104 1.1 riastrad 105 1.1 riastrad /* display buffers */ 106 1.1 riastrad struct list_head dbuf_list; 107 1.1 riastrad }; 108 1.1 riastrad 109 1.1 riastrad struct xen_drm_front_drm_pipeline { 110 1.1 riastrad struct xen_drm_front_drm_info *drm_info; 111 1.1 riastrad 112 1.1 riastrad int index; 113 1.1 riastrad 114 1.1 riastrad struct drm_simple_display_pipe pipe; 115 1.1 riastrad 116 1.1 riastrad struct drm_connector conn; 117 1.1 riastrad /* These are only for connector mode checking */ 118 1.1 riastrad int width, height; 119 1.1 riastrad 120 1.1 riastrad struct drm_pending_vblank_event *pending_event; 121 1.1 riastrad 122 1.1 riastrad struct delayed_work pflip_to_worker; 123 1.1 riastrad 124 1.1 riastrad bool conn_connected; 125 1.1 riastrad }; 126 1.1 riastrad 127 1.1 riastrad struct xen_drm_front_drm_info { 128 1.1 riastrad struct xen_drm_front_info *front_info; 129 1.1 riastrad struct drm_device *drm_dev; 130 1.1 riastrad 131 1.1 riastrad struct xen_drm_front_drm_pipeline pipeline[XEN_DRM_FRONT_MAX_CRTCS]; 132 1.1 riastrad }; 133 1.1 riastrad 134 1.1 riastrad static inline u64 xen_drm_front_fb_to_cookie(struct drm_framebuffer *fb) 135 1.1 riastrad { 136 1.1 riastrad return (uintptr_t)fb; 137 1.1 riastrad } 138 1.1 riastrad 139 1.1 riastrad static inline u64 xen_drm_front_dbuf_to_cookie(struct drm_gem_object *gem_obj) 140 1.1 riastrad { 141 1.1 riastrad return (uintptr_t)gem_obj; 142 1.1 riastrad } 143 1.1 riastrad 144 1.1 riastrad int xen_drm_front_mode_set(struct xen_drm_front_drm_pipeline *pipeline, 145 1.1 riastrad u32 x, u32 y, u32 width, u32 height, 146 1.1 riastrad u32 bpp, u64 fb_cookie); 147 1.1 riastrad 148 1.1 riastrad int xen_drm_front_dbuf_create(struct xen_drm_front_info *front_info, 149 1.1 riastrad u64 dbuf_cookie, u32 width, u32 height, 150 1.1 riastrad u32 bpp, u64 size, struct page **pages); 151 1.1 riastrad 152 1.1 riastrad int xen_drm_front_fb_attach(struct xen_drm_front_info *front_info, 153 1.1 riastrad u64 dbuf_cookie, u64 fb_cookie, u32 width, 154 1.1 riastrad u32 height, u32 pixel_format); 155 1.1 riastrad 156 1.1 riastrad int xen_drm_front_fb_detach(struct xen_drm_front_info *front_info, 157 1.1 riastrad u64 fb_cookie); 158 1.1 riastrad 159 1.1 riastrad int xen_drm_front_page_flip(struct xen_drm_front_info *front_info, 160 1.1 riastrad int conn_idx, u64 fb_cookie); 161 1.1 riastrad 162 1.1 riastrad void xen_drm_front_on_frame_done(struct xen_drm_front_info *front_info, 163 1.1 riastrad int conn_idx, u64 fb_cookie); 164 1.1 riastrad 165 1.1 riastrad #endif /* __XEN_DRM_FRONT_H_ */ 166