Add plane state handling functions.
We have to keep track of a few plane states so we cannot use the
DRM helper for this.
Created vmw_plane_state along with functions to reset, duplicate,
and destroty it.
v2
* Removed cursor clean up special case
Signed-off-by: Sinclair Yeh <syeh@vmware.com>
Reviewed-by: Thomas Hellstrom <thellstrom@vmware.com>
Acked-by: Daniel Vetter <daniel@ffwll.ch>
}
+/**
+ * vmw_du_plane_duplicate_state - duplicate plane state
+ * @plane: drm plane
+ *
+ * Allocates and returns a copy of the plane state (both common and
+ * vmw-specific) for the specified plane.
+ *
+ * Returns: The newly allocated plane state, or NULL on failure.
+ */
+struct drm_plane_state *
+vmw_du_plane_duplicate_state(struct drm_plane *plane)
+{
+ struct drm_plane_state *state;
+ struct vmw_plane_state *vps;
+
+ vps = kmemdup(plane->state, sizeof(*vps), GFP_KERNEL);
+
+ if (!vps)
+ return NULL;
+
+ vps->pinned = 0;
+
+ /* Each ref counted resource needs to be acquired again */
+ if (vps->surf)
+ (void) vmw_surface_reference(vps->surf);
+
+ if (vps->dmabuf)
+ (void) vmw_dmabuf_reference(vps->dmabuf);
+
+ state = &vps->base;
+
+ __drm_atomic_helper_plane_duplicate_state(plane, state);
+
+ return state;
+}
+
+
+/**
+ * vmw_du_plane_reset - creates a blank vmw plane state
+ * @plane: drm plane
+ *
+ * Resets the atomic state for @plane by freeing the state pointer (which might
+ * be NULL, e.g. at driver load time) and allocating a new empty state object.
+ */
+void vmw_du_plane_reset(struct drm_plane *plane)
+{
+ struct vmw_plane_state *vps;
+
+
+ if (plane->state)
+ vmw_du_plane_destroy_state(plane, plane->state);
+
+ vps = kzalloc(sizeof(*vps), GFP_KERNEL);
+
+ if (!vps) {
+ DRM_ERROR("Cannot allocate vmw_plane_state\n");
+ return;
+ }
+
+ plane->state = &vps->base;
+ plane->state->plane = plane;
+ plane->state->rotation = DRM_ROTATE_0;
+}
+
+
+/**
+ * vmw_du_plane_destroy_state - destroy plane state
+ * @plane: DRM plane
+ * @state: state object to destroy
+ *
+ * Destroys the plane state (both common and vmw-specific) for the
+ * specified plane.
+ */
+void
+vmw_du_plane_destroy_state(struct drm_plane *plane,
+ struct drm_plane_state *state)
+{
+ struct vmw_plane_state *vps = vmw_plane_state_to_vps(state);
+
+
+ if (vps->surf)
+ vmw_surface_unreference(&vps->surf);
+
+ if (vps->dmabuf)
+ vmw_dmabuf_unreference(&vps->dmabuf);
+
+ drm_atomic_helper_plane_destroy_state(plane, state);
+}
+
+
/*
* Generic framebuffer code
*/
#define vmw_crtc_state_to_vcs(x) container_of(x, struct vmw_crtc_state, base)
+#define vmw_plane_state_to_vps(x) container_of(x, struct vmw_plane_state, base)
/**
struct drm_crtc_state base;
};
+/**
+ * Derived class for plane state object
+ *
+ * @base DRM plane object
+ * @surf Display surface for STDU
+ * @dmabuf display dmabuf for SOU
+ * @content_fb_type Used by STDU.
+ * @pinned pin count for STDU display surface
+ */
+struct vmw_plane_state {
+ struct drm_plane_state base;
+ struct vmw_surface *surf;
+ struct vmw_dma_buffer *dmabuf;
+
+ int content_fb_type;
+
+ int pinned;
+};
+
/**
* Base class display unit.
*
uint32_t src_x, uint32_t src_y,
uint32_t src_w, uint32_t src_h);
+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);
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,
.update_plane = drm_primary_helper_update,
.disable_plane = drm_primary_helper_disable,
.destroy = vmw_du_primary_plane_destroy,
+ .reset = vmw_du_plane_reset,
+ .atomic_duplicate_state = vmw_du_plane_duplicate_state,
+ .atomic_destroy_state = vmw_du_plane_destroy_state,
};
static const struct drm_plane_funcs vmw_ldu_cursor_funcs = {
.update_plane = vmw_du_cursor_plane_update,
.disable_plane = vmw_du_cursor_plane_disable,
.destroy = vmw_du_cursor_plane_destroy,
+ .reset = vmw_du_plane_reset,
+ .atomic_duplicate_state = vmw_du_plane_duplicate_state,
+ .atomic_destroy_state = vmw_du_plane_destroy_state,
};
struct drm_device *dev = dev_priv->dev;
struct drm_connector *connector;
struct drm_encoder *encoder;
+ struct drm_plane *primary, *cursor;
struct drm_crtc *crtc;
int ret;
crtc = &ldu->base.crtc;
encoder = &ldu->base.encoder;
connector = &ldu->base.connector;
+ primary = &ldu->base.primary;
+ cursor = &ldu->base.cursor;
INIT_LIST_HEAD(&ldu->active);
ldu->base.is_implicit = true;
/* Initialize primary plane */
+ vmw_du_plane_reset(primary);
+
ret = drm_universal_plane_init(dev, &ldu->base.primary,
0, &vmw_ldu_plane_funcs,
vmw_primary_plane_formats,
}
/* Initialize cursor plane */
+ vmw_du_plane_reset(cursor);
+
ret = drm_universal_plane_init(dev, &ldu->base.cursor,
0, &vmw_ldu_cursor_funcs,
vmw_cursor_plane_formats,
.update_plane = drm_primary_helper_update,
.disable_plane = drm_primary_helper_disable,
.destroy = vmw_du_primary_plane_destroy,
+ .reset = vmw_du_plane_reset,
+ .atomic_duplicate_state = vmw_du_plane_duplicate_state,
+ .atomic_destroy_state = vmw_du_plane_destroy_state,
};
static const struct drm_plane_funcs vmw_sou_cursor_funcs = {
.update_plane = vmw_du_cursor_plane_update,
.disable_plane = vmw_du_cursor_plane_disable,
.destroy = vmw_du_cursor_plane_destroy,
+ .reset = vmw_du_plane_reset,
+ .atomic_duplicate_state = vmw_du_plane_duplicate_state,
+ .atomic_destroy_state = vmw_du_plane_destroy_state,
};
struct drm_device *dev = dev_priv->dev;
struct drm_connector *connector;
struct drm_encoder *encoder;
+ struct drm_plane *primary, *cursor;
struct drm_crtc *crtc;
int ret;
crtc = &sou->base.crtc;
encoder = &sou->base.encoder;
connector = &sou->base.connector;
+ primary = &sou->base.primary;
+ cursor = &sou->base.cursor;
sou->base.active_implicit = false;
sou->base.pref_active = (unit == 0);
sou->base.is_implicit = false;
/* Initialize primary plane */
+ vmw_du_plane_reset(primary);
+
ret = drm_universal_plane_init(dev, &sou->base.primary,
0, &vmw_sou_plane_funcs,
vmw_primary_plane_formats,
}
/* Initialize cursor plane */
+ vmw_du_plane_reset(cursor);
+
ret = drm_universal_plane_init(dev, &sou->base.cursor,
0, &vmw_sou_cursor_funcs,
vmw_cursor_plane_formats,
.update_plane = drm_primary_helper_update,
.disable_plane = drm_primary_helper_disable,
.destroy = vmw_du_primary_plane_destroy,
+ .reset = vmw_du_plane_reset,
+ .atomic_duplicate_state = vmw_du_plane_duplicate_state,
+ .atomic_destroy_state = vmw_du_plane_destroy_state,
};
static const struct drm_plane_funcs vmw_stdu_cursor_funcs = {
.update_plane = vmw_du_cursor_plane_update,
.disable_plane = vmw_du_cursor_plane_disable,
.destroy = vmw_du_cursor_plane_destroy,
+ .reset = vmw_du_plane_reset,
+ .atomic_duplicate_state = vmw_du_plane_duplicate_state,
+ .atomic_destroy_state = vmw_du_plane_destroy_state,
};
stdu->base.is_implicit = false;
/* Initialize primary plane */
+ vmw_du_plane_reset(primary);
+
ret = drm_universal_plane_init(dev, primary,
0, &vmw_stdu_plane_funcs,
vmw_primary_plane_formats,
}
/* Initialize cursor plane */
+ vmw_du_plane_reset(cursor);
+
ret = drm_universal_plane_init(dev, cursor,
0, &vmw_stdu_cursor_funcs,
vmw_cursor_plane_formats,