Commit e27c54ff authored by Rob Clark's avatar Rob Clark

drm/msm/mdp4: atomic

Convert mdp4 display controller backend to atomic helpers.
Signed-off-by: default avatarRob Clark <robdclark@gmail.com>
parent 3e7849ef
...@@ -50,25 +50,11 @@ struct mdp4_crtc { ...@@ -50,25 +50,11 @@ struct mdp4_crtc {
/* if there is a pending flip, these will be non-null: */ /* if there is a pending flip, these will be non-null: */
struct drm_pending_vblank_event *event; struct drm_pending_vblank_event *event;
struct msm_fence_cb pageflip_cb;
#define PENDING_CURSOR 0x1 #define PENDING_CURSOR 0x1
#define PENDING_FLIP 0x2 #define PENDING_FLIP 0x2
atomic_t pending; atomic_t pending;
/* the fb that we logically (from PoV of KMS API) hold a ref
* to. Which we may not yet be scanning out (we may still
* be scanning out previous in case of page_flip while waiting
* for gpu rendering to complete:
*/
struct drm_framebuffer *fb;
/* the fb that we currently hold a scanout ref to: */
struct drm_framebuffer *scanout_fb;
/* for unref'ing framebuffers after scanout completes: */
struct drm_flip_work unref_fb_work;
/* for unref'ing cursor bo's after scanout completes: */ /* for unref'ing cursor bo's after scanout completes: */
struct drm_flip_work unref_cursor_work; struct drm_flip_work unref_cursor_work;
...@@ -110,47 +96,6 @@ static void crtc_flush(struct drm_crtc *crtc) ...@@ -110,47 +96,6 @@ static void crtc_flush(struct drm_crtc *crtc)
mdp4_write(mdp4_kms, REG_MDP4_OVERLAY_FLUSH, flush); mdp4_write(mdp4_kms, REG_MDP4_OVERLAY_FLUSH, flush);
} }
static void update_fb(struct drm_crtc *crtc, struct drm_framebuffer *new_fb)
{
struct mdp4_crtc *mdp4_crtc = to_mdp4_crtc(crtc);
struct drm_framebuffer *old_fb = mdp4_crtc->fb;
/* grab reference to incoming scanout fb: */
drm_framebuffer_reference(new_fb);
mdp4_crtc->base.primary->fb = new_fb;
mdp4_crtc->fb = new_fb;
if (old_fb)
drm_flip_work_queue(&mdp4_crtc->unref_fb_work, old_fb);
}
/* unlike update_fb(), take a ref to the new scanout fb *before* updating
* plane, then call this. Needed to ensure we don't unref the buffer that
* is actually still being scanned out.
*
* Note that this whole thing goes away with atomic.. since we can defer
* calling into driver until rendering is done.
*/
static void update_scanout(struct drm_crtc *crtc, struct drm_framebuffer *fb)
{
struct mdp4_crtc *mdp4_crtc = to_mdp4_crtc(crtc);
/* flush updates, to make sure hw is updated to new scanout fb,
* so that we can safely queue unref to current fb (ie. next
* vblank we know hw is done w/ previous scanout_fb).
*/
crtc_flush(crtc);
if (mdp4_crtc->scanout_fb)
drm_flip_work_queue(&mdp4_crtc->unref_fb_work,
mdp4_crtc->scanout_fb);
mdp4_crtc->scanout_fb = fb;
/* enable vblank to complete flip: */
request_pending(crtc, PENDING_FLIP);
}
/* if file!=NULL, this is preclose potential cancel-flip path */ /* if file!=NULL, this is preclose potential cancel-flip path */
static void complete_flip(struct drm_crtc *crtc, struct drm_file *file) static void complete_flip(struct drm_crtc *crtc, struct drm_file *file)
{ {
...@@ -168,38 +113,13 @@ static void complete_flip(struct drm_crtc *crtc, struct drm_file *file) ...@@ -168,38 +113,13 @@ static void complete_flip(struct drm_crtc *crtc, struct drm_file *file)
*/ */
if (!file || (event->base.file_priv == file)) { if (!file || (event->base.file_priv == file)) {
mdp4_crtc->event = NULL; mdp4_crtc->event = NULL;
DBG("%s: send event: %p", mdp4_crtc->name, event);
drm_send_vblank_event(dev, mdp4_crtc->id, event); drm_send_vblank_event(dev, mdp4_crtc->id, event);
} }
} }
spin_unlock_irqrestore(&dev->event_lock, flags); spin_unlock_irqrestore(&dev->event_lock, flags);
} }
static void pageflip_cb(struct msm_fence_cb *cb)
{
struct mdp4_crtc *mdp4_crtc =
container_of(cb, struct mdp4_crtc, pageflip_cb);
struct drm_crtc *crtc = &mdp4_crtc->base;
struct drm_framebuffer *fb = crtc->primary->fb;
if (!fb)
return;
drm_framebuffer_reference(fb);
mdp4_plane_set_scanout(crtc->primary, fb);
update_scanout(crtc, fb);
}
static void unref_fb_worker(struct drm_flip_work *work, void *val)
{
struct mdp4_crtc *mdp4_crtc =
container_of(work, struct mdp4_crtc, unref_fb_work);
struct drm_device *dev = mdp4_crtc->base.dev;
mutex_lock(&dev->mode_config.mutex);
drm_framebuffer_unreference(val);
mutex_unlock(&dev->mode_config.mutex);
}
static void unref_cursor_worker(struct drm_flip_work *work, void *val) static void unref_cursor_worker(struct drm_flip_work *work, void *val)
{ {
struct mdp4_crtc *mdp4_crtc = struct mdp4_crtc *mdp4_crtc =
...@@ -215,7 +135,6 @@ static void mdp4_crtc_destroy(struct drm_crtc *crtc) ...@@ -215,7 +135,6 @@ static void mdp4_crtc_destroy(struct drm_crtc *crtc)
struct mdp4_crtc *mdp4_crtc = to_mdp4_crtc(crtc); struct mdp4_crtc *mdp4_crtc = to_mdp4_crtc(crtc);
drm_crtc_cleanup(crtc); drm_crtc_cleanup(crtc);
drm_flip_work_cleanup(&mdp4_crtc->unref_fb_work);
drm_flip_work_cleanup(&mdp4_crtc->unref_cursor_work); drm_flip_work_cleanup(&mdp4_crtc->unref_cursor_work);
kfree(mdp4_crtc); kfree(mdp4_crtc);
...@@ -323,18 +242,18 @@ static void blend_setup(struct drm_crtc *crtc) ...@@ -323,18 +242,18 @@ static void blend_setup(struct drm_crtc *crtc)
mdp4_write(mdp4_kms, REG_MDP4_LAYERMIXER_IN_CFG, mixer_cfg); mdp4_write(mdp4_kms, REG_MDP4_LAYERMIXER_IN_CFG, mixer_cfg);
} }
static int mdp4_crtc_mode_set(struct drm_crtc *crtc, static void mdp4_crtc_mode_set_nofb(struct drm_crtc *crtc)
struct drm_display_mode *mode,
struct drm_display_mode *adjusted_mode,
int x, int y,
struct drm_framebuffer *old_fb)
{ {
struct mdp4_crtc *mdp4_crtc = to_mdp4_crtc(crtc); struct mdp4_crtc *mdp4_crtc = to_mdp4_crtc(crtc);
struct mdp4_kms *mdp4_kms = get_kms(crtc); struct mdp4_kms *mdp4_kms = get_kms(crtc);
enum mdp4_dma dma = mdp4_crtc->dma; enum mdp4_dma dma = mdp4_crtc->dma;
int ret, ovlp = mdp4_crtc->ovlp; int ovlp = mdp4_crtc->ovlp;
struct drm_display_mode *mode;
if (WARN_ON(!crtc->state))
return;
mode = adjusted_mode; mode = &crtc->state->adjusted_mode;
DBG("%s: set mode: %d:\"%s\" %d %d %d %d %d %d %d %d %d %d 0x%x 0x%x", DBG("%s: set mode: %d:\"%s\" %d %d %d %d %d %d %d %d %d %d 0x%x 0x%x",
mdp4_crtc->name, mode->base.id, mode->name, mdp4_crtc->name, mode->base.id, mode->name,
...@@ -345,20 +264,6 @@ static int mdp4_crtc_mode_set(struct drm_crtc *crtc, ...@@ -345,20 +264,6 @@ static int mdp4_crtc_mode_set(struct drm_crtc *crtc,
mode->vsync_end, mode->vtotal, mode->vsync_end, mode->vtotal,
mode->type, mode->flags); mode->type, mode->flags);
/* grab extra ref for update_scanout() */
drm_framebuffer_reference(crtc->primary->fb);
ret = mdp4_plane_mode_set(crtc->primary, crtc, crtc->primary->fb,
0, 0, mode->hdisplay, mode->vdisplay,
x << 16, y << 16,
mode->hdisplay << 16, mode->vdisplay << 16);
if (ret) {
drm_framebuffer_unreference(crtc->primary->fb);
dev_err(crtc->dev->dev, "%s: failed to set mode on plane: %d\n",
mdp4_crtc->name, ret);
return ret;
}
mdp4_write(mdp4_kms, REG_MDP4_DMA_SRC_SIZE(dma), mdp4_write(mdp4_kms, REG_MDP4_DMA_SRC_SIZE(dma),
MDP4_DMA_SRC_SIZE_WIDTH(mode->hdisplay) | MDP4_DMA_SRC_SIZE_WIDTH(mode->hdisplay) |
MDP4_DMA_SRC_SIZE_HEIGHT(mode->vdisplay)); MDP4_DMA_SRC_SIZE_HEIGHT(mode->vdisplay));
...@@ -383,11 +288,6 @@ static int mdp4_crtc_mode_set(struct drm_crtc *crtc, ...@@ -383,11 +288,6 @@ static int mdp4_crtc_mode_set(struct drm_crtc *crtc,
mdp4_write(mdp4_kms, REG_MDP4_DMA_E_QUANT(1), 0x00ff0000); mdp4_write(mdp4_kms, REG_MDP4_DMA_E_QUANT(1), 0x00ff0000);
mdp4_write(mdp4_kms, REG_MDP4_DMA_E_QUANT(2), 0x00ff0000); mdp4_write(mdp4_kms, REG_MDP4_DMA_E_QUANT(2), 0x00ff0000);
} }
update_fb(crtc, crtc->primary->fb);
update_scanout(crtc, crtc->primary->fb);
return 0;
} }
static void mdp4_crtc_prepare(struct drm_crtc *crtc) static void mdp4_crtc_prepare(struct drm_crtc *crtc)
...@@ -409,59 +309,51 @@ static void mdp4_crtc_commit(struct drm_crtc *crtc) ...@@ -409,59 +309,51 @@ static void mdp4_crtc_commit(struct drm_crtc *crtc)
drm_crtc_vblank_put(crtc); drm_crtc_vblank_put(crtc);
} }
static int mdp4_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y, static void mdp4_crtc_load_lut(struct drm_crtc *crtc)
struct drm_framebuffer *old_fb) {
}
static int mdp4_crtc_atomic_check(struct drm_crtc *crtc,
struct drm_crtc_state *state)
{ {
struct drm_plane *plane = crtc->primary; struct mdp4_crtc *mdp4_crtc = to_mdp4_crtc(crtc);
struct drm_display_mode *mode = &crtc->mode; struct drm_device *dev = crtc->dev;
int ret;
/* grab extra ref for update_scanout() */ DBG("%s: check", mdp4_crtc->name);
drm_framebuffer_reference(crtc->primary->fb);
ret = mdp4_plane_mode_set(plane, crtc, crtc->primary->fb, if (mdp4_crtc->event) {
0, 0, mode->hdisplay, mode->vdisplay, dev_err(dev->dev, "already pending flip!\n");
x << 16, y << 16, return -EBUSY;
mode->hdisplay << 16, mode->vdisplay << 16);
if (ret) {
drm_framebuffer_unreference(crtc->primary->fb);
return ret;
} }
update_fb(crtc, crtc->primary->fb); // TODO anything else to check?
update_scanout(crtc, crtc->primary->fb);
return 0; return 0;
} }
static void mdp4_crtc_load_lut(struct drm_crtc *crtc) static void mdp4_crtc_atomic_begin(struct drm_crtc *crtc)
{ {
struct mdp4_crtc *mdp4_crtc = to_mdp4_crtc(crtc);
DBG("%s: begin", mdp4_crtc->name);
} }
static int mdp4_crtc_page_flip(struct drm_crtc *crtc, static void mdp4_crtc_atomic_flush(struct drm_crtc *crtc)
struct drm_framebuffer *new_fb,
struct drm_pending_vblank_event *event,
uint32_t page_flip_flags)
{ {
struct mdp4_crtc *mdp4_crtc = to_mdp4_crtc(crtc); struct mdp4_crtc *mdp4_crtc = to_mdp4_crtc(crtc);
struct drm_device *dev = crtc->dev; struct drm_device *dev = crtc->dev;
struct drm_gem_object *obj;
unsigned long flags; unsigned long flags;
if (mdp4_crtc->event) { DBG("%s: flush", mdp4_crtc->name);
dev_err(dev->dev, "already pending flip!\n");
return -EBUSY;
}
obj = msm_framebuffer_bo(new_fb, 0); WARN_ON(mdp4_crtc->event);
spin_lock_irqsave(&dev->event_lock, flags); spin_lock_irqsave(&dev->event_lock, flags);
mdp4_crtc->event = event; mdp4_crtc->event = crtc->state->event;
spin_unlock_irqrestore(&dev->event_lock, flags); spin_unlock_irqrestore(&dev->event_lock, flags);
update_fb(crtc, new_fb); blend_setup(crtc);
crtc_flush(crtc);
return msm_gem_queue_inactive_cb(obj, &mdp4_crtc->pageflip_cb); request_pending(crtc, PENDING_FLIP);
} }
static int mdp4_crtc_set_property(struct drm_crtc *crtc, static int mdp4_crtc_set_property(struct drm_crtc *crtc,
...@@ -599,22 +491,29 @@ static int mdp4_crtc_cursor_move(struct drm_crtc *crtc, int x, int y) ...@@ -599,22 +491,29 @@ static int mdp4_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
} }
static const struct drm_crtc_funcs mdp4_crtc_funcs = { static const struct drm_crtc_funcs mdp4_crtc_funcs = {
.set_config = drm_crtc_helper_set_config, .set_config = drm_atomic_helper_set_config,
.destroy = mdp4_crtc_destroy, .destroy = mdp4_crtc_destroy,
.page_flip = mdp4_crtc_page_flip, .page_flip = drm_atomic_helper_page_flip,
.set_property = mdp4_crtc_set_property, .set_property = mdp4_crtc_set_property,
.cursor_set = mdp4_crtc_cursor_set, .cursor_set = mdp4_crtc_cursor_set,
.cursor_move = mdp4_crtc_cursor_move, .cursor_move = mdp4_crtc_cursor_move,
.reset = drm_atomic_helper_crtc_reset,
.atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
.atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
}; };
static const struct drm_crtc_helper_funcs mdp4_crtc_helper_funcs = { static const struct drm_crtc_helper_funcs mdp4_crtc_helper_funcs = {
.dpms = mdp4_crtc_dpms, .dpms = mdp4_crtc_dpms,
.mode_fixup = mdp4_crtc_mode_fixup, .mode_fixup = mdp4_crtc_mode_fixup,
.mode_set = mdp4_crtc_mode_set, .mode_set_nofb = mdp4_crtc_mode_set_nofb,
.mode_set = drm_helper_crtc_mode_set,
.mode_set_base = drm_helper_crtc_mode_set_base,
.prepare = mdp4_crtc_prepare, .prepare = mdp4_crtc_prepare,
.commit = mdp4_crtc_commit, .commit = mdp4_crtc_commit,
.mode_set_base = mdp4_crtc_mode_set_base,
.load_lut = mdp4_crtc_load_lut, .load_lut = mdp4_crtc_load_lut,
.atomic_check = mdp4_crtc_atomic_check,
.atomic_begin = mdp4_crtc_atomic_begin,
.atomic_flush = mdp4_crtc_atomic_flush,
}; };
static void mdp4_crtc_vblank_irq(struct mdp_irq *irq, uint32_t irqstatus) static void mdp4_crtc_vblank_irq(struct mdp_irq *irq, uint32_t irqstatus)
...@@ -630,7 +529,6 @@ static void mdp4_crtc_vblank_irq(struct mdp_irq *irq, uint32_t irqstatus) ...@@ -630,7 +529,6 @@ static void mdp4_crtc_vblank_irq(struct mdp_irq *irq, uint32_t irqstatus)
if (pending & PENDING_FLIP) { if (pending & PENDING_FLIP) {
complete_flip(crtc, NULL); complete_flip(crtc, NULL);
drm_flip_work_commit(&mdp4_crtc->unref_fb_work, priv->wq);
} }
if (pending & PENDING_CURSOR) { if (pending & PENDING_CURSOR) {
...@@ -655,7 +553,8 @@ uint32_t mdp4_crtc_vblank(struct drm_crtc *crtc) ...@@ -655,7 +553,8 @@ uint32_t mdp4_crtc_vblank(struct drm_crtc *crtc)
void mdp4_crtc_cancel_pending_flip(struct drm_crtc *crtc, struct drm_file *file) void mdp4_crtc_cancel_pending_flip(struct drm_crtc *crtc, struct drm_file *file)
{ {
DBG("cancel: %p", file); struct mdp4_crtc *mdp4_crtc = to_mdp4_crtc(crtc);
DBG("%s: cancel: %p", mdp4_crtc->name, file);
complete_flip(crtc, file); complete_flip(crtc, file);
} }
...@@ -709,29 +608,6 @@ void mdp4_crtc_set_intf(struct drm_crtc *crtc, enum mdp4_intf intf, int mixer) ...@@ -709,29 +608,6 @@ void mdp4_crtc_set_intf(struct drm_crtc *crtc, enum mdp4_intf intf, int mixer)
mdp4_write(mdp4_kms, REG_MDP4_DISP_INTF_SEL, intf_sel); mdp4_write(mdp4_kms, REG_MDP4_DISP_INTF_SEL, intf_sel);
} }
static void set_attach(struct drm_crtc *crtc, enum mdp4_pipe pipe_id,
struct drm_plane *plane)
{
struct mdp4_crtc *mdp4_crtc = to_mdp4_crtc(crtc);
blend_setup(crtc);
if (mdp4_crtc->enabled && (plane != crtc->primary))
crtc_flush(crtc);
}
void mdp4_crtc_attach(struct drm_crtc *crtc, struct drm_plane *plane)
{
set_attach(crtc, mdp4_plane_pipe(plane), plane);
}
void mdp4_crtc_detach(struct drm_crtc *crtc, struct drm_plane *plane)
{
/* don't actually detatch our primary plane: */
if (crtc->primary == plane)
return;
set_attach(crtc, mdp4_plane_pipe(plane), NULL);
}
static const char *dma_names[] = { static const char *dma_names[] = {
"DMA_P", "DMA_S", "DMA_E", "DMA_P", "DMA_S", "DMA_E",
}; };
...@@ -766,13 +642,9 @@ struct drm_crtc *mdp4_crtc_init(struct drm_device *dev, ...@@ -766,13 +642,9 @@ struct drm_crtc *mdp4_crtc_init(struct drm_device *dev,
spin_lock_init(&mdp4_crtc->cursor.lock); spin_lock_init(&mdp4_crtc->cursor.lock);
drm_flip_work_init(&mdp4_crtc->unref_fb_work,
"unref fb", unref_fb_worker);
drm_flip_work_init(&mdp4_crtc->unref_cursor_work, drm_flip_work_init(&mdp4_crtc->unref_cursor_work,
"unref cursor", unref_cursor_worker); "unref cursor", unref_cursor_worker);
INIT_FENCE_CB(&mdp4_crtc->pageflip_cb, pageflip_cb);
drm_crtc_init_with_planes(dev, crtc, plane, NULL, &mdp4_crtc_funcs); drm_crtc_init_with_planes(dev, crtc, plane, NULL, &mdp4_crtc_funcs);
drm_crtc_helper_add(crtc, &mdp4_crtc_helper_funcs); drm_crtc_helper_add(crtc, &mdp4_crtc_helper_funcs);
plane->crtc = crtc; plane->crtc = crtc;
......
...@@ -194,14 +194,6 @@ uint32_t mdp4_get_formats(enum mdp4_pipe pipe_id, uint32_t *pixel_formats, ...@@ -194,14 +194,6 @@ uint32_t mdp4_get_formats(enum mdp4_pipe pipe_id, uint32_t *pixel_formats,
void mdp4_plane_install_properties(struct drm_plane *plane, void mdp4_plane_install_properties(struct drm_plane *plane,
struct drm_mode_object *obj); struct drm_mode_object *obj);
void mdp4_plane_set_scanout(struct drm_plane *plane,
struct drm_framebuffer *fb);
int mdp4_plane_mode_set(struct drm_plane *plane,
struct drm_crtc *crtc, struct drm_framebuffer *fb,
int crtc_x, int crtc_y,
unsigned int crtc_w, unsigned int crtc_h,
uint32_t src_x, uint32_t src_y,
uint32_t src_w, uint32_t src_h);
enum mdp4_pipe mdp4_plane_pipe(struct drm_plane *plane); enum mdp4_pipe mdp4_plane_pipe(struct drm_plane *plane);
struct drm_plane *mdp4_plane_init(struct drm_device *dev, struct drm_plane *mdp4_plane_init(struct drm_device *dev,
enum mdp4_pipe pipe_id, bool private_plane); enum mdp4_pipe pipe_id, bool private_plane);
...@@ -210,8 +202,6 @@ uint32_t mdp4_crtc_vblank(struct drm_crtc *crtc); ...@@ -210,8 +202,6 @@ uint32_t mdp4_crtc_vblank(struct drm_crtc *crtc);
void mdp4_crtc_cancel_pending_flip(struct drm_crtc *crtc, struct drm_file *file); void mdp4_crtc_cancel_pending_flip(struct drm_crtc *crtc, struct drm_file *file);
void mdp4_crtc_set_config(struct drm_crtc *crtc, uint32_t config); void mdp4_crtc_set_config(struct drm_crtc *crtc, uint32_t config);
void mdp4_crtc_set_intf(struct drm_crtc *crtc, enum mdp4_intf intf, int mixer); void mdp4_crtc_set_intf(struct drm_crtc *crtc, enum mdp4_intf intf, int mixer);
void mdp4_crtc_attach(struct drm_crtc *crtc, struct drm_plane *plane);
void mdp4_crtc_detach(struct drm_crtc *crtc, struct drm_plane *plane);
struct drm_crtc *mdp4_crtc_init(struct drm_device *dev, struct drm_crtc *mdp4_crtc_init(struct drm_device *dev,
struct drm_plane *plane, int id, int ovlp_id, struct drm_plane *plane, int id, int ovlp_id,
enum mdp4_dma dma_id); enum mdp4_dma dma_id);
......
...@@ -98,6 +98,9 @@ static const struct drm_connector_funcs mdp4_lvds_connector_funcs = { ...@@ -98,6 +98,9 @@ static const struct drm_connector_funcs mdp4_lvds_connector_funcs = {
.detect = mdp4_lvds_connector_detect, .detect = mdp4_lvds_connector_detect,
.fill_modes = drm_helper_probe_single_connector_modes, .fill_modes = drm_helper_probe_single_connector_modes,
.destroy = mdp4_lvds_connector_destroy, .destroy = mdp4_lvds_connector_destroy,
.reset = drm_atomic_helper_connector_reset,
.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
}; };
static const struct drm_connector_helper_funcs mdp4_lvds_connector_helper_funcs = { static const struct drm_connector_helper_funcs mdp4_lvds_connector_helper_funcs = {
......
...@@ -31,47 +31,26 @@ struct mdp4_plane { ...@@ -31,47 +31,26 @@ struct mdp4_plane {
}; };
#define to_mdp4_plane(x) container_of(x, struct mdp4_plane, base) #define to_mdp4_plane(x) container_of(x, struct mdp4_plane, base)
static struct mdp4_kms *get_kms(struct drm_plane *plane) static void mdp4_plane_set_scanout(struct drm_plane *plane,
{ struct drm_framebuffer *fb);
struct msm_drm_private *priv = plane->dev->dev_private; static int mdp4_plane_mode_set(struct drm_plane *plane,
return to_mdp4_kms(to_mdp_kms(priv->kms));
}
static int mdp4_plane_update(struct drm_plane *plane,
struct drm_crtc *crtc, struct drm_framebuffer *fb, struct drm_crtc *crtc, struct drm_framebuffer *fb,
int crtc_x, int crtc_y, int crtc_x, int crtc_y,
unsigned int crtc_w, unsigned int crtc_h, unsigned int crtc_w, unsigned int crtc_h,
uint32_t src_x, uint32_t src_y, uint32_t src_x, uint32_t src_y,
uint32_t src_w, uint32_t src_h) uint32_t src_w, uint32_t src_h);
{
struct mdp4_plane *mdp4_plane = to_mdp4_plane(plane);
mdp4_plane->enabled = true;
if (plane->fb)
drm_framebuffer_unreference(plane->fb);
drm_framebuffer_reference(fb);
return mdp4_plane_mode_set(plane, crtc, fb,
crtc_x, crtc_y, crtc_w, crtc_h,
src_x, src_y, src_w, src_h);
}
static int mdp4_plane_disable(struct drm_plane *plane) static struct mdp4_kms *get_kms(struct drm_plane *plane)
{ {
struct mdp4_plane *mdp4_plane = to_mdp4_plane(plane); struct msm_drm_private *priv = plane->dev->dev_private;
DBG("%s: disable", mdp4_plane->name); return to_mdp4_kms(to_mdp_kms(priv->kms));
if (plane->crtc)
mdp4_crtc_detach(plane->crtc, plane);
return 0;
} }
static void mdp4_plane_destroy(struct drm_plane *plane) static void mdp4_plane_destroy(struct drm_plane *plane)
{ {
struct mdp4_plane *mdp4_plane = to_mdp4_plane(plane); struct mdp4_plane *mdp4_plane = to_mdp4_plane(plane);
mdp4_plane_disable(plane); drm_plane_helper_disable(plane);
drm_plane_cleanup(plane); drm_plane_cleanup(plane);
kfree(mdp4_plane); kfree(mdp4_plane);
...@@ -92,19 +71,74 @@ int mdp4_plane_set_property(struct drm_plane *plane, ...@@ -92,19 +71,74 @@ int mdp4_plane_set_property(struct drm_plane *plane,
} }
static const struct drm_plane_funcs mdp4_plane_funcs = { static const struct drm_plane_funcs mdp4_plane_funcs = {
.update_plane = mdp4_plane_update, .update_plane = drm_atomic_helper_update_plane,
.disable_plane = mdp4_plane_disable, .disable_plane = drm_atomic_helper_disable_plane,
.destroy = mdp4_plane_destroy, .destroy = mdp4_plane_destroy,
.set_property = mdp4_plane_set_property, .set_property = mdp4_plane_set_property,
.reset = drm_atomic_helper_plane_reset,
.atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
.atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
}; };
void mdp4_plane_set_scanout(struct drm_plane *plane, static int mdp4_plane_prepare_fb(struct drm_plane *plane,
struct drm_framebuffer *fb)
{
struct mdp4_plane *mdp4_plane = to_mdp4_plane(plane);
struct mdp4_kms *mdp4_kms = get_kms(plane);
DBG("%s: prepare: FB[%u]", mdp4_plane->name, fb->base.id);
return msm_framebuffer_prepare(fb, mdp4_kms->id);
}
static void mdp4_plane_cleanup_fb(struct drm_plane *plane,
struct drm_framebuffer *fb)
{
struct mdp4_plane *mdp4_plane = to_mdp4_plane(plane);
struct mdp4_kms *mdp4_kms = get_kms(plane);
DBG("%s: cleanup: FB[%u]", mdp4_plane->name, fb->base.id);
msm_framebuffer_cleanup(fb, mdp4_kms->id);
}
static int mdp4_plane_atomic_check(struct drm_plane *plane,
struct drm_plane_state *state)
{
return 0;
}
static void mdp4_plane_atomic_update(struct drm_plane *plane)
{
struct drm_plane_state *state = plane->state;
int ret;
ret = mdp4_plane_mode_set(plane,
state->crtc, state->fb,
state->crtc_x, state->crtc_y,
state->crtc_w, state->crtc_h,
state->src_x, state->src_y,
state->src_w, state->src_h);
/* atomic_check should have ensured that this doesn't fail */
WARN_ON(ret < 0);
}
static const struct drm_plane_helper_funcs mdp4_plane_helper_funcs = {
.prepare_fb = mdp4_plane_prepare_fb,
.cleanup_fb = mdp4_plane_cleanup_fb,
.atomic_check = mdp4_plane_atomic_check,
.atomic_update = mdp4_plane_atomic_update,
};
static void mdp4_plane_set_scanout(struct drm_plane *plane,
struct drm_framebuffer *fb) struct drm_framebuffer *fb)
{ {
struct mdp4_plane *mdp4_plane = to_mdp4_plane(plane); struct mdp4_plane *mdp4_plane = to_mdp4_plane(plane);
struct mdp4_kms *mdp4_kms = get_kms(plane); struct mdp4_kms *mdp4_kms = get_kms(plane);
enum mdp4_pipe pipe = mdp4_plane->pipe; enum mdp4_pipe pipe = mdp4_plane->pipe;
uint32_t iova; uint32_t iova = msm_framebuffer_iova(fb, mdp4_kms->id, 0);
DBG("%s: set_scanout: %08x (%u)", mdp4_plane->name,
iova, fb->pitches[0]);
mdp4_write(mdp4_kms, REG_MDP4_PIPE_SRC_STRIDE_A(pipe), mdp4_write(mdp4_kms, REG_MDP4_PIPE_SRC_STRIDE_A(pipe),
MDP4_PIPE_SRC_STRIDE_A_P0(fb->pitches[0]) | MDP4_PIPE_SRC_STRIDE_A_P0(fb->pitches[0]) |
...@@ -114,7 +148,6 @@ void mdp4_plane_set_scanout(struct drm_plane *plane, ...@@ -114,7 +148,6 @@ void mdp4_plane_set_scanout(struct drm_plane *plane,
MDP4_PIPE_SRC_STRIDE_B_P2(fb->pitches[2]) | MDP4_PIPE_SRC_STRIDE_B_P2(fb->pitches[2]) |
MDP4_PIPE_SRC_STRIDE_B_P3(fb->pitches[3])); MDP4_PIPE_SRC_STRIDE_B_P3(fb->pitches[3]));
msm_gem_get_iova(msm_framebuffer_bo(fb, 0), mdp4_kms->id, &iova);
mdp4_write(mdp4_kms, REG_MDP4_PIPE_SRCP0_BASE(pipe), iova); mdp4_write(mdp4_kms, REG_MDP4_PIPE_SRCP0_BASE(pipe), iova);
plane->fb = fb; plane->fb = fb;
...@@ -122,7 +155,7 @@ void mdp4_plane_set_scanout(struct drm_plane *plane, ...@@ -122,7 +155,7 @@ void mdp4_plane_set_scanout(struct drm_plane *plane,
#define MDP4_VG_PHASE_STEP_DEFAULT 0x20000000 #define MDP4_VG_PHASE_STEP_DEFAULT 0x20000000
int mdp4_plane_mode_set(struct drm_plane *plane, static int mdp4_plane_mode_set(struct drm_plane *plane,
struct drm_crtc *crtc, struct drm_framebuffer *fb, struct drm_crtc *crtc, struct drm_framebuffer *fb,
int crtc_x, int crtc_y, int crtc_x, int crtc_y,
unsigned int crtc_w, unsigned int crtc_h, unsigned int crtc_w, unsigned int crtc_h,
...@@ -137,6 +170,11 @@ int mdp4_plane_mode_set(struct drm_plane *plane, ...@@ -137,6 +170,11 @@ int mdp4_plane_mode_set(struct drm_plane *plane,
uint32_t phasex_step = MDP4_VG_PHASE_STEP_DEFAULT; uint32_t phasex_step = MDP4_VG_PHASE_STEP_DEFAULT;
uint32_t phasey_step = MDP4_VG_PHASE_STEP_DEFAULT; uint32_t phasey_step = MDP4_VG_PHASE_STEP_DEFAULT;
if (!(crtc && fb)) {
DBG("%s: disabled!", mdp4_plane->name);
return 0;
}
/* src values are in Q16 fixed point, convert to integer: */ /* src values are in Q16 fixed point, convert to integer: */
src_x = src_x >> 16; src_x = src_x >> 16;
src_y = src_y >> 16; src_y = src_y >> 16;
...@@ -197,9 +235,6 @@ int mdp4_plane_mode_set(struct drm_plane *plane, ...@@ -197,9 +235,6 @@ int mdp4_plane_mode_set(struct drm_plane *plane,
mdp4_write(mdp4_kms, REG_MDP4_PIPE_PHASEX_STEP(pipe), phasex_step); mdp4_write(mdp4_kms, REG_MDP4_PIPE_PHASEX_STEP(pipe), phasex_step);
mdp4_write(mdp4_kms, REG_MDP4_PIPE_PHASEY_STEP(pipe), phasey_step); mdp4_write(mdp4_kms, REG_MDP4_PIPE_PHASEY_STEP(pipe), phasey_step);
/* TODO detach from old crtc (if we had more than one) */
mdp4_crtc_attach(crtc, plane);
return 0; return 0;
} }
...@@ -239,9 +274,12 @@ struct drm_plane *mdp4_plane_init(struct drm_device *dev, ...@@ -239,9 +274,12 @@ struct drm_plane *mdp4_plane_init(struct drm_device *dev,
ARRAY_SIZE(mdp4_plane->formats)); ARRAY_SIZE(mdp4_plane->formats));
type = private_plane ? DRM_PLANE_TYPE_PRIMARY : DRM_PLANE_TYPE_OVERLAY; type = private_plane ? DRM_PLANE_TYPE_PRIMARY : DRM_PLANE_TYPE_OVERLAY;
drm_universal_plane_init(dev, plane, 0xff, &mdp4_plane_funcs, ret = drm_universal_plane_init(dev, plane, 0xff, &mdp4_plane_funcs,
mdp4_plane->formats, mdp4_plane->nformats, mdp4_plane->formats, mdp4_plane->nformats, type);
type); if (ret)
goto fail;
drm_plane_helper_add(plane, &mdp4_plane_helper_funcs);
mdp4_plane_install_properties(plane, &plane->base); mdp4_plane_install_properties(plane, &plane->base);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment