Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0+ */
0002 
0003 #ifndef _VKMS_DRV_H_
0004 #define _VKMS_DRV_H_
0005 
0006 #include <linux/hrtimer.h>
0007 
0008 #include <drm/drm.h>
0009 #include <drm/drm_framebuffer.h>
0010 #include <drm/drm_gem.h>
0011 #include <drm/drm_gem_atomic_helper.h>
0012 #include <drm/drm_encoder.h>
0013 #include <drm/drm_writeback.h>
0014 
0015 #define XRES_MIN    20
0016 #define YRES_MIN    20
0017 
0018 #define XRES_DEF  1024
0019 #define YRES_DEF   768
0020 
0021 #define XRES_MAX  8192
0022 #define YRES_MAX  8192
0023 
0024 #define NUM_OVERLAY_PLANES 8
0025 
0026 struct vkms_writeback_job {
0027     struct iosys_map map[DRM_FORMAT_MAX_PLANES];
0028     struct iosys_map data[DRM_FORMAT_MAX_PLANES];
0029 };
0030 
0031 struct vkms_composer {
0032     struct drm_framebuffer fb;
0033     struct drm_rect src, dst;
0034     struct iosys_map map[4];
0035     unsigned int offset;
0036     unsigned int pitch;
0037     unsigned int cpp;
0038 };
0039 
0040 /**
0041  * vkms_plane_state - Driver specific plane state
0042  * @base: base plane state
0043  * @composer: data required for composing computation
0044  */
0045 struct vkms_plane_state {
0046     struct drm_shadow_plane_state base;
0047     struct vkms_composer *composer;
0048 };
0049 
0050 struct vkms_plane {
0051     struct drm_plane base;
0052 };
0053 
0054 /**
0055  * vkms_crtc_state - Driver specific CRTC state
0056  * @base: base CRTC state
0057  * @composer_work: work struct to compose and add CRC entries
0058  * @n_frame_start: start frame number for computed CRC
0059  * @n_frame_end: end frame number for computed CRC
0060  */
0061 struct vkms_crtc_state {
0062     struct drm_crtc_state base;
0063     struct work_struct composer_work;
0064 
0065     int num_active_planes;
0066     /* stack of active planes for crc computation, should be in z order */
0067     struct vkms_plane_state **active_planes;
0068     struct vkms_writeback_job *active_writeback;
0069 
0070     /* below four are protected by vkms_output.composer_lock */
0071     bool crc_pending;
0072     bool wb_pending;
0073     u64 frame_start;
0074     u64 frame_end;
0075 };
0076 
0077 struct vkms_output {
0078     struct drm_crtc crtc;
0079     struct drm_encoder encoder;
0080     struct drm_connector connector;
0081     struct drm_writeback_connector wb_connector;
0082     struct hrtimer vblank_hrtimer;
0083     ktime_t period_ns;
0084     struct drm_pending_vblank_event *event;
0085     /* ordered wq for composer_work */
0086     struct workqueue_struct *composer_workq;
0087     /* protects concurrent access to composer */
0088     spinlock_t lock;
0089 
0090     /* protected by @lock */
0091     bool composer_enabled;
0092     struct vkms_crtc_state *composer_state;
0093 
0094     spinlock_t composer_lock;
0095 };
0096 
0097 struct vkms_device;
0098 
0099 struct vkms_config {
0100     bool writeback;
0101     bool cursor;
0102     bool overlay;
0103     /* only set when instantiated */
0104     struct vkms_device *dev;
0105 };
0106 
0107 struct vkms_device {
0108     struct drm_device drm;
0109     struct platform_device *platform;
0110     struct vkms_output output;
0111     const struct vkms_config *config;
0112 };
0113 
0114 #define drm_crtc_to_vkms_output(target) \
0115     container_of(target, struct vkms_output, crtc)
0116 
0117 #define drm_device_to_vkms_device(target) \
0118     container_of(target, struct vkms_device, drm)
0119 
0120 #define to_vkms_crtc_state(target)\
0121     container_of(target, struct vkms_crtc_state, base)
0122 
0123 #define to_vkms_plane_state(target)\
0124     container_of(target, struct vkms_plane_state, base.base)
0125 
0126 /* CRTC */
0127 int vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
0128            struct drm_plane *primary, struct drm_plane *cursor);
0129 
0130 int vkms_output_init(struct vkms_device *vkmsdev, int index);
0131 
0132 struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev,
0133                    enum drm_plane_type type, int index);
0134 
0135 /* CRC Support */
0136 const char *const *vkms_get_crc_sources(struct drm_crtc *crtc,
0137                     size_t *count);
0138 int vkms_set_crc_source(struct drm_crtc *crtc, const char *src_name);
0139 int vkms_verify_crc_source(struct drm_crtc *crtc, const char *source_name,
0140                size_t *values_cnt);
0141 
0142 /* Composer Support */
0143 void vkms_composer_worker(struct work_struct *work);
0144 void vkms_set_composer(struct vkms_output *out, bool enabled);
0145 
0146 /* Writeback */
0147 int vkms_enable_writeback_connector(struct vkms_device *vkmsdev);
0148 
0149 #endif /* _VKMS_DRV_H_ */