Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * (C) COPYRIGHT 2018 ARM Limited. All rights reserved.
0004  * Author: James.Qian.Wang <james.qian.wang@arm.com>
0005  *
0006  */
0007 #ifndef _KOMEDA_KMS_H_
0008 #define _KOMEDA_KMS_H_
0009 
0010 #include <linux/list.h>
0011 #include <drm/drm_atomic.h>
0012 #include <drm/drm_atomic_helper.h>
0013 #include <drm/drm_blend.h>
0014 #include <drm/drm_crtc_helper.h>
0015 #include <drm/drm_device.h>
0016 #include <drm/drm_writeback.h>
0017 #include <drm/drm_print.h>
0018 
0019 /**
0020  * struct komeda_plane - komeda instance of drm_plane
0021  */
0022 struct komeda_plane {
0023     /** @base: &drm_plane */
0024     struct drm_plane base;
0025     /**
0026      * @layer:
0027      *
0028      * represents available layer input pipelines for this plane.
0029      *
0030      * NOTE:
0031      * the layer is not for a specific Layer, but indicate a group of
0032      * Layers with same capabilities.
0033      */
0034     struct komeda_layer *layer;
0035 };
0036 
0037 /**
0038  * struct komeda_plane_state
0039  *
0040  * The plane_state can be split into two data flow (left/right) and handled
0041  * by two layers &komeda_plane.layer and &komeda_plane.layer.right
0042  */
0043 struct komeda_plane_state {
0044     /** @base: &drm_plane_state */
0045     struct drm_plane_state base;
0046     /** @zlist_node: zorder list node */
0047     struct list_head zlist_node;
0048 
0049     /** @layer_split: on/off layer_split */
0050     u8 layer_split : 1;
0051 };
0052 
0053 /**
0054  * struct komeda_wb_connector
0055  */
0056 struct komeda_wb_connector {
0057     /** @base: &drm_writeback_connector */
0058     struct drm_writeback_connector base;
0059 
0060     /** @wb_layer: represents associated writeback pipeline of komeda */
0061     struct komeda_layer *wb_layer;
0062 };
0063 
0064 /**
0065  * struct komeda_crtc
0066  */
0067 struct komeda_crtc {
0068     /** @base: &drm_crtc */
0069     struct drm_crtc base;
0070     /** @master: only master has display output */
0071     struct komeda_pipeline *master;
0072     /**
0073      * @slave: optional
0074      *
0075      * Doesn't have its own display output, the handled data flow will
0076      * merge into the master.
0077      */
0078     struct komeda_pipeline *slave;
0079 
0080     /** @slave_planes: komeda slave planes mask */
0081     u32 slave_planes;
0082 
0083     /** @wb_conn: komeda write back connector */
0084     struct komeda_wb_connector *wb_conn;
0085 
0086     /** @disable_done: this flip_done is for tracing the disable */
0087     struct completion *disable_done;
0088 };
0089 
0090 /**
0091  * struct komeda_crtc_state
0092  */
0093 struct komeda_crtc_state {
0094     /** @base: &drm_crtc_state */
0095     struct drm_crtc_state base;
0096 
0097     /* private properties */
0098 
0099     /* computed state which are used by validate/check */
0100     /**
0101      * @affected_pipes:
0102      * the affected pipelines in once display instance
0103      */
0104     u32 affected_pipes;
0105     /**
0106      * @active_pipes:
0107      * the active pipelines in once display instance
0108      */
0109     u32 active_pipes;
0110 
0111     /** @clock_ratio: ratio of (aclk << 32)/pxlclk */
0112     u64 clock_ratio;
0113 
0114     /** @max_slave_zorder: the maximum of slave zorder */
0115     u32 max_slave_zorder;
0116 };
0117 
0118 /** struct komeda_kms_dev - for gather KMS related things */
0119 struct komeda_kms_dev {
0120     /** @base: &drm_device */
0121     struct drm_device base;
0122 
0123     /** @n_crtcs: valid numbers of crtcs in &komeda_kms_dev.crtcs */
0124     int n_crtcs;
0125     /** @crtcs: crtcs list */
0126     struct komeda_crtc crtcs[KOMEDA_MAX_PIPELINES];
0127 };
0128 
0129 #define to_kplane(p)    container_of(p, struct komeda_plane, base)
0130 #define to_kplane_st(p) container_of(p, struct komeda_plane_state, base)
0131 #define to_kconn(p) container_of(p, struct komeda_wb_connector, base)
0132 #define to_kcrtc(p) container_of(p, struct komeda_crtc, base)
0133 #define to_kcrtc_st(p)  container_of(p, struct komeda_crtc_state, base)
0134 #define to_kdev(p)  container_of(p, struct komeda_kms_dev, base)
0135 #define to_wb_conn(x)   container_of(x, struct drm_writeback_connector, base)
0136 
0137 static inline bool is_writeback_only(struct drm_crtc_state *st)
0138 {
0139     struct komeda_wb_connector *wb_conn = to_kcrtc(st->crtc)->wb_conn;
0140     struct drm_connector *conn = wb_conn ? &wb_conn->base.base : NULL;
0141 
0142     return conn && (st->connector_mask == BIT(drm_connector_index(conn)));
0143 }
0144 
0145 static inline bool
0146 is_only_changed_connector(struct drm_crtc_state *st, struct drm_connector *conn)
0147 {
0148     struct drm_crtc_state *old_st;
0149     u32 changed_connectors;
0150 
0151     old_st = drm_atomic_get_old_crtc_state(st->state, st->crtc);
0152     changed_connectors = st->connector_mask ^ old_st->connector_mask;
0153 
0154     return BIT(drm_connector_index(conn)) == changed_connectors;
0155 }
0156 
0157 static inline bool has_flip_h(u32 rot)
0158 {
0159     u32 rotation = drm_rotation_simplify(rot,
0160                          DRM_MODE_ROTATE_0 |
0161                          DRM_MODE_ROTATE_90 |
0162                          DRM_MODE_REFLECT_MASK);
0163 
0164     if (rotation & DRM_MODE_ROTATE_90)
0165         return !!(rotation & DRM_MODE_REFLECT_Y);
0166     else
0167         return !!(rotation & DRM_MODE_REFLECT_X);
0168 }
0169 
0170 void komeda_crtc_get_color_config(struct drm_crtc_state *crtc_st,
0171                   u32 *color_depths, u32 *color_formats);
0172 unsigned long komeda_crtc_get_aclk(struct komeda_crtc_state *kcrtc_st);
0173 
0174 int komeda_kms_setup_crtcs(struct komeda_kms_dev *kms, struct komeda_dev *mdev);
0175 
0176 int komeda_kms_add_crtcs(struct komeda_kms_dev *kms, struct komeda_dev *mdev);
0177 int komeda_kms_add_planes(struct komeda_kms_dev *kms, struct komeda_dev *mdev);
0178 int komeda_kms_add_private_objs(struct komeda_kms_dev *kms,
0179                 struct komeda_dev *mdev);
0180 int komeda_kms_add_wb_connectors(struct komeda_kms_dev *kms,
0181                  struct komeda_dev *mdev);
0182 void komeda_kms_cleanup_private_objs(struct komeda_kms_dev *kms);
0183 
0184 void komeda_crtc_handle_event(struct komeda_crtc   *kcrtc,
0185                   struct komeda_events *evts);
0186 
0187 struct komeda_kms_dev *komeda_kms_attach(struct komeda_dev *mdev);
0188 void komeda_kms_detach(struct komeda_kms_dev *kms);
0189 
0190 #endif /*_KOMEDA_KMS_H_*/