linux/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
/**
 * vmw_kms_check_topology - Validates topology in drm_atomic_state
 * @dev: DRM device
 * @state: the driver state object
 *
 * Returns:
 * 0 on success otherwise negative error code
 */
Validates topology in drm_atomic_state
@dev: DRM device
@state: the driver state object

0 on success otherwise negative error code
Validates topology in drm_atomic_state @dev : DRM device @state : the driver state object 0 on success otherwise negative error code
static int vmw_kms_check_topology(struct drm_device *dev,
				  struct drm_atomic_state *state)
{
	struct vmw_private *dev_priv = vmw_priv(dev);
	struct drm_crtc_state *old_crtc_state, *new_crtc_state;
	struct drm_rect *rects;
	struct drm_crtc *crtc;
	uint32_t i;
	int ret = 0;
	rects = kcalloc(dev->mode_config.num_crtc, sizeof(struct drm_rect),
			GFP_KERNEL);
	if (!rects)
		return -ENOMEM;
	mutex_lock(&dev_priv->requested_layout_mutex);
	drm_for_each_crtc(crtc, dev) {
		struct vmw_display_unit *du = vmw_crtc_to_du(crtc);
		struct drm_crtc_state *crtc_state = crtc->state;
		i = drm_crtc_index(crtc);
		if (crtc_state && crtc_state->enable) {
			rects[i].x1 = du->gui_x;
			rects[i].y1 = du->gui_y;
			rects[i].x2 = du->gui_x + crtc_state->mode.hdisplay;
			rects[i].y2 = du->gui_y + crtc_state->mode.vdisplay;
		}
	}
	for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state,
				      new_crtc_state, i) {
		struct vmw_display_unit *du = vmw_crtc_to_du(crtc);
		struct drm_connector *connector;
		struct drm_connector_state *conn_state;
		struct vmw_connector_state *vmw_conn_state;
		if (!new_crtc_state->enable) {
			rects[i].x1 = 0;
			rects[i].y1 = 0;
			rects[i].x2 = 0;
			rects[i].y2 = 0;
			continue;
		}
		if (!du->pref_active) {
			ret = -EINVAL;
			goto clean;
		}
		connector = &du->connector;
		conn_state = drm_atomic_get_connector_state(state, connector);
		if (IS_ERR(conn_state)) {
			ret = PTR_ERR(conn_state);
			goto clean;
		}
		vmw_conn_state = vmw_connector_state_to_vcs(conn_state);
		vmw_conn_state->gui_x = du->gui_x;
		vmw_conn_state->gui_y = du->gui_y;
		rects[i].x1 = du->gui_x;
		rects[i].y1 = du->gui_y;
		rects[i].x2 = du->gui_x + new_crtc_state->mode.hdisplay;
		rects[i].y2 = du->gui_y + new_crtc_state->mode.vdisplay;
	}
	ret = vmw_kms_check_display_memory(dev, dev->mode_config.num_crtc,
					   rects);
clean:
	mutex_unlock(&dev_priv->requested_layout_mutex);
	kfree(rects);
	return ret;
}
static int vmw_kms_check_topology ( struct drm_device * dev , struct drm_atomic_state * state ) { struct vmw_private * dev_priv = vmw_priv ( dev ) ; struct drm_crtc_state * old_crtc_state , * new_crtc_state ; struct drm_rect * rects ; struct drm_crtc * crtc ; uint32_t i ; int ret = 0 ; rects = kcalloc ( dev -> mode_config . num_crtc , sizeof ( struct drm_rect ) , GFP_KERNEL ) ; if ( ! rects ) return - ENOMEM ; mutex_lock ( & dev_priv -> requested_layout_mutex ) ; drm_for_each_crtc ( crtc , dev ) { struct vmw_display_unit * du = vmw_crtc_to_du ( crtc ) ; struct drm_crtc_state * crtc_state = crtc -> state ; i = drm_crtc_index ( crtc ) ; if ( crtc_state && crtc_state -> enable ) { rects [ i ] . x1 = du -> gui_x ; rects [ i ] . y1 = du -> gui_y ; rects [ i ] . x2 = du -> gui_x + crtc_state -> mode . hdisplay ; rects [ i ] . y2 = du -> gui_y + crtc_state -> mode . vdisplay ; } } for_each_oldnew_crtc_in_state ( state , crtc , old_crtc_state , new_crtc_state , i ) { struct vmw_display_unit * du = vmw_crtc_to_du ( crtc ) ; struct drm_connector * connector ; struct drm_connector_state * conn_state ; struct vmw_connector_state * vmw_conn_state ; if ( ! new_crtc_state -> enable ) { rects [ i ] . x1 = 0 ; rects [ i ] . y1 = 0 ; rects [ i ] . x2 = 0 ; rects [ i ] . y2 = 0 ; continue ; } if ( ! du -> pref_active ) { ret = - EINVAL ; goto clean ; } connector = & du -> connector ; conn_state = drm_atomic_get_connector_state ( state , connector ) ; if ( IS_ERR ( conn_state ) ) { ret = PTR_ERR ( conn_state ) ; goto clean ; } vmw_conn_state = vmw_connector_state_to_vcs ( conn_state ) ; vmw_conn_state -> gui_x = du -> gui_x ; vmw_conn_state -> gui_y = du -> gui_y ; rects [ i ] . x1 = du -> gui_x ; rects [ i ] . y1 = du -> gui_y ; rects [ i ] . x2 = du -> gui_x + new_crtc_state -> mode . hdisplay ; rects [ i ] . y2 = du -> gui_y + new_crtc_state -> mode . vdisplay ; } ret = vmw_kms_check_display_memory ( dev , dev -> mode_config . num_crtc , rects ) ; clean : mutex_unlock ( & dev_priv -> requested_layout_mutex ) ; kfree ( rects ) ; return ret ; }
vmw_kms_check_topology - Validates topology in drm_atomic_state
 @dev: DRM device
 @state: the driver state object
vmw_kms_check_topology - Validates topology in drm_atomic_state @dev : DRM device @state : the driver state object
/* Determine change to topology due to new atomic state */ /*
		 * For vmwgfx each crtc has only one connector attached and it
		 * is not changed so don't really need to check the
		 * crtc->connector_mask and iterate over it.
		 */