Re: [PATCH 05/11] drm/vmwgfx: Add and connect CRTC helper functions
On Mon, Mar 27, 2017 at 03:00:58PM -0700, Sinclair Yeh wrote: > Atomic mode set requires us to refactor existing vmw_stdu_crtc_set_config > code into sections that check the validity of the new mode, and sections > that actually program the hardware state. > > vmw_du_crtc_atomic_check() takes CRTC-related checking code. In a later > patch, vmw_du_primary_plane_atomic_check() will take framebuffer-related > checking code. > > These helpers won't be called until we flip on the atomic support > flag or set drm_crtc_funcs->set_config to using the atomic > helper. > > v2: > * The state->num_connector is actually the total number of potential > connectors, not just the one associated with the display unit. > The proper one to check is ->connector_mask. > > * Add the check to only allow plane state to be the same as crtc state > (Thanks to mlankhorst) > > * Make sure to turn on SVGA mode before using VRAM. SVGA mode is > disabled in master_drop if dbdev is not running. > > Signed-off-by: Sinclair Yeh> Signed-off-by: Thomas Hellstrom > Reviewed-by: Thomas Hellstrom > --- > drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 48 ++ > drivers/gpu/drm/vmwgfx/vmwgfx_kms.h | 9 +++ > drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c | 79 +++ > drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c | 119 > +++ > drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c | 117 ++ > 5 files changed, 372 insertions(+) > > diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c > b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c > index a8e0909..6f0f160 100644 > --- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c > +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c > @@ -399,6 +399,54 @@ void vmw_du_primary_plane_destroy(struct drm_plane > *plane) > } > > > +int vmw_du_crtc_atomic_check(struct drm_crtc *crtc, > + struct drm_crtc_state *new_state) > +{ > + struct vmw_display_unit *du = vmw_crtc_to_du(new_state->crtc); > + int connector_mask = 1 << drm_connector_index(>connector); > + bool has_primary = new_state->plane_mask & > +BIT(drm_plane_index(crtc->primary)); > + > + /* We always want to have an active plane with an active CRTC */ > + if (has_primary != new_state->enable) > + return -EINVAL; > + > + > + if (new_state->connector_mask != connector_mask && > + new_state->connector_mask != 0) { > + DRM_ERROR("Invalid connectors configuration\n"); > + return -EINVAL; > + } > + > + return 0; > +} > + > + > +void vmw_du_crtc_atomic_begin(struct drm_crtc *crtc, > + struct drm_crtc_state *old_crtc_state) > +{ > +} > + > + > +void vmw_du_crtc_atomic_flush(struct drm_crtc *crtc, > + struct drm_crtc_state *old_crtc_state) > +{ > + struct drm_pending_vblank_event *event = crtc->state->event; > + > + if (event) { > + crtc->state->event = NULL; > + > + spin_lock_irq(>dev->event_lock); > + if (drm_crtc_vblank_get(crtc) == 0) > + drm_crtc_arm_vblank_event(crtc, event); > + else > + drm_crtc_send_vblank_event(crtc, event); > + spin_unlock_irq(>dev->event_lock); > + } > + > +} > + > + > /** > * vmw_du_crtc_duplicate_state - duplicate crtc state > * @crtc: DRM crtc > diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.h > b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.h > index cc50bf3..f711b5d 100644 > --- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.h > +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.h > @@ -161,6 +161,7 @@ struct vmw_crtc_state { > * @surf Display surface for STDU > * @dmabuf display dmabuf for SOU > * @content_fb_type Used by STDU. > + * @dmabuf_size Size of the dmabuf, used by Screen Object Display Unit > * @pinned pin count for STDU display surface > */ > struct vmw_plane_state { > @@ -169,6 +170,7 @@ struct vmw_plane_state { > struct vmw_dma_buffer *dmabuf; > > int content_fb_type; > + unsigned long dmabuf_size; > > int pinned; > }; > @@ -342,10 +344,17 @@ int vmw_du_cursor_plane_update(struct drm_plane *plane, > uint32_t src_x, uint32_t src_y, > uint32_t src_w, uint32_t src_h); > > +/* Atomic Helpers */ > void vmw_du_plane_reset(struct drm_plane *plane); > struct drm_plane_state *vmw_du_plane_duplicate_state(struct drm_plane > *plane); > void vmw_du_plane_destroy_state(struct drm_plane *plane, > struct drm_plane_state *state); > +int vmw_du_crtc_atomic_check(struct drm_crtc *crtc, > + struct drm_crtc_state *state); > +void vmw_du_crtc_atomic_begin(struct drm_crtc *crtc, > + struct drm_crtc_state *old_crtc_state); > +void vmw_du_crtc_atomic_flush(struct drm_crtc *crtc, > +
[PATCH 05/11] drm/vmwgfx: Add and connect CRTC helper functions
Atomic mode set requires us to refactor existing vmw_stdu_crtc_set_config code into sections that check the validity of the new mode, and sections that actually program the hardware state. vmw_du_crtc_atomic_check() takes CRTC-related checking code. In a later patch, vmw_du_primary_plane_atomic_check() will take framebuffer-related checking code. These helpers won't be called until we flip on the atomic support flag or set drm_crtc_funcs->set_config to using the atomic helper. v2: * The state->num_connector is actually the total number of potential connectors, not just the one associated with the display unit. The proper one to check is ->connector_mask. * Add the check to only allow plane state to be the same as crtc state (Thanks to mlankhorst) * Make sure to turn on SVGA mode before using VRAM. SVGA mode is disabled in master_drop if dbdev is not running. Signed-off-by: Sinclair YehSigned-off-by: Thomas Hellstrom Reviewed-by: Thomas Hellstrom --- drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 48 ++ drivers/gpu/drm/vmwgfx/vmwgfx_kms.h | 9 +++ drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c | 79 +++ drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c | 119 +++ drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c | 117 ++ 5 files changed, 372 insertions(+) diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c index a8e0909..6f0f160 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c @@ -399,6 +399,54 @@ void vmw_du_primary_plane_destroy(struct drm_plane *plane) } +int vmw_du_crtc_atomic_check(struct drm_crtc *crtc, +struct drm_crtc_state *new_state) +{ + struct vmw_display_unit *du = vmw_crtc_to_du(new_state->crtc); + int connector_mask = 1 << drm_connector_index(>connector); + bool has_primary = new_state->plane_mask & + BIT(drm_plane_index(crtc->primary)); + + /* We always want to have an active plane with an active CRTC */ + if (has_primary != new_state->enable) + return -EINVAL; + + + if (new_state->connector_mask != connector_mask && + new_state->connector_mask != 0) { + DRM_ERROR("Invalid connectors configuration\n"); + return -EINVAL; + } + + return 0; +} + + +void vmw_du_crtc_atomic_begin(struct drm_crtc *crtc, + struct drm_crtc_state *old_crtc_state) +{ +} + + +void vmw_du_crtc_atomic_flush(struct drm_crtc *crtc, + struct drm_crtc_state *old_crtc_state) +{ + struct drm_pending_vblank_event *event = crtc->state->event; + + if (event) { + crtc->state->event = NULL; + + spin_lock_irq(>dev->event_lock); + if (drm_crtc_vblank_get(crtc) == 0) + drm_crtc_arm_vblank_event(crtc, event); + else + drm_crtc_send_vblank_event(crtc, event); + spin_unlock_irq(>dev->event_lock); + } + +} + + /** * vmw_du_crtc_duplicate_state - duplicate crtc state * @crtc: DRM crtc diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.h b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.h index cc50bf3..f711b5d 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.h +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.h @@ -161,6 +161,7 @@ struct vmw_crtc_state { * @surf Display surface for STDU * @dmabuf display dmabuf for SOU * @content_fb_type Used by STDU. + * @dmabuf_size Size of the dmabuf, used by Screen Object Display Unit * @pinned pin count for STDU display surface */ struct vmw_plane_state { @@ -169,6 +170,7 @@ struct vmw_plane_state { struct vmw_dma_buffer *dmabuf; int content_fb_type; + unsigned long dmabuf_size; int pinned; }; @@ -342,10 +344,17 @@ int vmw_du_cursor_plane_update(struct drm_plane *plane, uint32_t src_x, uint32_t src_y, uint32_t src_w, uint32_t src_h); +/* Atomic Helpers */ void vmw_du_plane_reset(struct drm_plane *plane); struct drm_plane_state *vmw_du_plane_duplicate_state(struct drm_plane *plane); void vmw_du_plane_destroy_state(struct drm_plane *plane, struct drm_plane_state *state); +int vmw_du_crtc_atomic_check(struct drm_crtc *crtc, +struct drm_crtc_state *state); +void vmw_du_crtc_atomic_begin(struct drm_crtc *crtc, + struct drm_crtc_state *old_crtc_state); +void vmw_du_crtc_atomic_flush(struct drm_crtc *crtc, + struct drm_crtc_state *old_crtc_state); void vmw_du_crtc_reset(struct drm_crtc *crtc); struct drm_crtc_state *vmw_du_crtc_duplicate_state(struct drm_crtc *crtc); void vmw_du_crtc_destroy_state(struct drm_crtc *crtc, diff --git