Re: [PATCH] ARM: PXA: Make PXA27x/PXA3xx overlay actually work

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Feb 3, 2011 at 4:46 AM, Vasily Khoruzhick <anarsoul@xxxxxxxxx> wrote:
> From: "Russell King - ARM Linux" <linux@xxxxxxxxxxxxxxxx>
>
> Release callback tries to free memory even if it was not allocated in
> map_video_memory. Fix PXA27x/3xx overlay memory management and make overlay
> actually work.

That's indeed an issue.

>
> Added by Vasily Khoruzhick:
>
> - Move overlay Z-ordering selection into main fb initialization,
> otherwise plane ordering is wrong.
> - Clear x_res/y_res fields of fb.var on release, to make sure
> our callback will be called on next FBIOPUT_VSCREENINFO ioctl.
> - Disable overlay only if it was enabled.

The patch looks generally OK to me, some points for discussion
below though:

>
> Signed-off-by: Vasily Khoruzhick <anarsoul@xxxxxxxxx>
> ---
> Âdrivers/video/pxafb.c | Â 86 ++++++++++++++++++++++++++++++------------------
> Âdrivers/video/pxafb.h | Â Â2 +-
> Â2 files changed, 55 insertions(+), 33 deletions(-)
>
> diff --git a/drivers/video/pxafb.c b/drivers/video/pxafb.c
> index 825b665..33f607a 100644
> --- a/drivers/video/pxafb.c
> +++ b/drivers/video/pxafb.c
> @@ -629,16 +629,19 @@ static void overlay1fb_disable(struct pxafb_layer *ofb)
> Â{
> Â Â Â Âuint32_t lccr5 = lcd_readl(ofb->fbi, LCCR5);
>

Or maybe simply:

	if (lcd_readl(ofb->fbi, OVL1C1) & OVLxC1_OEN)
		return;

this makes this block of change much cleaner.

> - Â Â Â lcd_writel(ofb->fbi, OVL1C1, ofb->control[0] & ~OVLxC1_OEN);
> + Â Â Â if (lcd_readl(ofb->fbi, OVL1C1) & OVLxC1_OEN) {
> + Â Â Â Â Â Â Â lcd_writel(ofb->fbi, OVL1C1, ofb->control[0] & ~OVLxC1_OEN);
>
> - Â Â Â lcd_writel(ofb->fbi, LCSR1, LCSR1_BS(1));
> - Â Â Â lcd_writel(ofb->fbi, LCCR5, lccr5 & ~LCSR1_BS(1));
> - Â Â Â lcd_writel(ofb->fbi, FBR1, ofb->fbi->fdadr[DMA_OV1] | 0x3);
> + Â Â Â Â Â Â Â lcd_writel(ofb->fbi, LCSR1, LCSR1_BS(1));
> + Â Â Â Â Â Â Â lcd_writel(ofb->fbi, LCCR5, lccr5 & ~LCSR1_BS(1));
> + Â Â Â Â Â Â Â lcd_writel(ofb->fbi, FBR1, ofb->fbi->fdadr[DMA_OV1] | 0x3);
>
> - Â Â Â if (wait_for_completion_timeout(&ofb->branch_done, 1 * HZ) == 0)
> - Â Â Â Â Â Â Â pr_warning("%s: timeout disabling overlay1\n", __func__);
> + Â Â Â Â Â Â Â if (wait_for_completion_timeout(&ofb->branch_done, 1 * HZ) == 0)
> + Â Â Â Â Â Â Â Â Â Â Â pr_warning("%s: timeout disabling overlay1\n",
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â __func__);
>
> - Â Â Â lcd_writel(ofb->fbi, LCCR5, lccr5);
> + Â Â Â Â Â Â Â lcd_writel(ofb->fbi, LCCR5, lccr5);
> + Â Â Â }
> Â}
>
> Âstatic void overlay2fb_setup(struct pxafb_layer *ofb)
> @@ -687,16 +690,19 @@ static void overlay2fb_disable(struct pxafb_layer *ofb)
> Â{
> Â Â Â Âuint32_t lccr5 = lcd_readl(ofb->fbi, LCCR5);
>
> - Â Â Â lcd_writel(ofb->fbi, OVL2C1, ofb->control[0] & ~OVLxC1_OEN);
> + Â Â Â if (lcd_readl(ofb->fbi, OVL2C1) & OVLxC1_OEN) {
> + Â Â Â Â Â Â Â lcd_writel(ofb->fbi, OVL2C1, ofb->control[0] & ~OVLxC1_OEN);

Ditto.

>
> - Â Â Â lcd_writel(ofb->fbi, LCSR1, LCSR1_BS(2));
> - Â Â Â lcd_writel(ofb->fbi, LCCR5, lccr5 & ~LCSR1_BS(2));
> - Â Â Â lcd_writel(ofb->fbi, FBR2, ofb->fbi->fdadr[DMA_OV2_Y] Â| 0x3);
> - Â Â Â lcd_writel(ofb->fbi, FBR3, ofb->fbi->fdadr[DMA_OV2_Cb] | 0x3);
> - Â Â Â lcd_writel(ofb->fbi, FBR4, ofb->fbi->fdadr[DMA_OV2_Cr] | 0x3);
> + Â Â Â Â Â Â Â lcd_writel(ofb->fbi, LCSR1, LCSR1_BS(2));
> + Â Â Â Â Â Â Â lcd_writel(ofb->fbi, LCCR5, lccr5 & ~LCSR1_BS(2));
> + Â Â Â Â Â Â Â lcd_writel(ofb->fbi, FBR2, ofb->fbi->fdadr[DMA_OV2_Y] Â| 0x3);
> + Â Â Â Â Â Â Â lcd_writel(ofb->fbi, FBR3, ofb->fbi->fdadr[DMA_OV2_Cb] | 0x3);
> + Â Â Â Â Â Â Â lcd_writel(ofb->fbi, FBR4, ofb->fbi->fdadr[DMA_OV2_Cr] | 0x3);
>
> - Â Â Â if (wait_for_completion_timeout(&ofb->branch_done, 1 * HZ) == 0)
> - Â Â Â Â Â Â Â pr_warning("%s: timeout disabling overlay2\n", __func__);
> + Â Â Â Â Â Â Â if (wait_for_completion_timeout(&ofb->branch_done, 1 * HZ) == 0)
> + Â Â Â Â Â Â Â Â Â Â Â pr_warning("%s: timeout disabling overlay2\n",
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â __func__);
> + Â Â Â }
> Â}
>
> Âstatic struct pxafb_layer_ops ofb_ops[] = {
> @@ -720,12 +726,10 @@ static int overlayfb_open(struct fb_info *info, int user)
> Â Â Â Âif (user == 0)
> Â Â Â Â Â Â Â Âreturn -ENODEV;
>
> - Â Â Â /* allow only one user at a time */
> - Â Â Â if (atomic_inc_and_test(&ofb->usage))
> - Â Â Â Â Â Â Â return -EBUSY;
> + Â Â Â if (ofb->usage++ == 0)
> + Â Â Â Â Â Â Â /* unblank the base framebuffer */
> + Â Â Â Â Â Â Â fb_blank(&ofb->fbi->fb, FB_BLANK_UNBLANK);

The change above allows multiple user at a time? Then I guess
some other places need to be changed accordingly to avoid the
racing conditions.

If this is a feature request, can we postpone it to subsequent
patches?

>
> - Â Â Â /* unblank the base framebuffer */
> - Â Â Â fb_blank(&ofb->fbi->fb, FB_BLANK_UNBLANK);
> Â Â Â Âreturn 0;
> Â}
>
> @@ -733,12 +737,24 @@ static int overlayfb_release(struct fb_info *info, int user)
> Â{
> Â Â Â Âstruct pxafb_layer *ofb = (struct pxafb_layer*) info;
>
> - Â Â Â atomic_dec(&ofb->usage);
> - Â Â Â ofb->ops->disable(ofb);
> -
> - Â Â Â free_pages_exact(ofb->video_mem, ofb->video_mem_size);
> - Â Â Â ofb->video_mem = NULL;
> - Â Â Â ofb->video_mem_size = 0;
> + Â Â Â if (--ofb->usage == 0) {
> + Â Â Â Â Â Â Â ofb->ops->disable(ofb);
> +        ofb->fb.var.height   Â= -1;
> +        ofb->fb.var.width    = -1;
> + Â Â Â Â Â Â Â ofb->fb.var.xres = ofb->fb.var.xres_virtual = 0;
> + Â Â Â Â Â Â Â ofb->fb.var.yres = ofb->fb.var.yres_virtual = 0;
> +
> + Â Â Â Â Â Â Â mutex_lock(&ofb->fb.mm_lock);
> + Â Â Â Â Â Â Â ofb->fb.fix.smem_start Â= 0;
> +        ofb->fb.fix.smem_len  Â= 0;
> + Â Â Â Â Â Â Â mutex_unlock(&ofb->fb.mm_lock);
> +
> + Â Â Â Â Â Â Â if (ofb->video_mem) {
> + Â Â Â Â Â Â Â Â Â Â Â free_pages_exact(ofb->video_mem, ofb->video_mem_size);
> + Â Â Â Â Â Â Â Â Â Â Â ofb->video_mem = NULL;
> + Â Â Â Â Â Â Â Â Â Â Â ofb->video_mem_size = 0;
> + Â Â Â Â Â Â Â }
> + Â Â Â }
> Â Â Â Âreturn 0;
> Â}
>
> @@ -817,7 +833,8 @@ static int overlayfb_map_video_memory(struct pxafb_layer *ofb)
> Â Â Â Â Â Â Â Âif (ofb->video_mem_size >= size)
> Â Â Â Â Â Â Â Â Â Â Â Âreturn 0;
>
> - Â Â Â Â Â Â Â free_pages_exact(ofb->video_mem, ofb->video_mem_size);
> + Â Â Â Â Â Â Â /* don't re-allocate: userspace may have the buffer mapped */
> + Â Â Â Â Â Â Â return -EINVAL;
> Â Â Â Â}
>
> Â Â Â Âofb->video_mem = alloc_pages_exact(size, GFP_KERNEL | __GFP_ZERO);
> @@ -891,7 +908,7 @@ static void __devinit init_pxafb_overlay(struct pxafb_info *fbi,
>
> Â Â Â Âofb->id = id;
> Â Â Â Âofb->ops = &ofb_ops[id];
> - Â Â Â atomic_set(&ofb->usage, 0);
> + Â Â Â ofb->usage = 0;
> Â Â Â Âofb->fbi = fbi;
> Â Â Â Âinit_completion(&ofb->branch_done);
> Â}
> @@ -923,8 +940,6 @@ static int __devinit pxafb_overlay_init(struct pxafb_info *fbi)
> Â Â Â Â/* mask all IU/BS/EOF/SOF interrupts */
> Â Â Â Âlcd_writel(fbi, LCCR5, ~0);
>
> - Â Â Â /* place overlay(s) on top of base */
> - Â Â Â fbi->lccr0 |= LCCR0_OUC;
> Â Â Â Âpr_info("PXA Overlay driver loaded successfully!\n");
> Â Â Â Âreturn 0;
> Â}
> @@ -1368,7 +1383,8 @@ static int pxafb_activate_var(struct fb_var_screeninfo *var,
> Â Â Â Â Â Â(lcd_readl(fbi, LCCR3) != fbi->reg_lccr3) ||
> Â Â Â Â Â Â(lcd_readl(fbi, LCCR4) != fbi->reg_lccr4) ||
> Â Â Â Â Â Â(lcd_readl(fbi, FDADR0) != fbi->fdadr[0]) ||
> - Â Â Â Â Â (lcd_readl(fbi, FDADR1) != fbi->fdadr[1]))
> + Â Â Â Â Â ((fbi->lccr0 & LCCR0_SDS) &&
> + Â Â Â Â Â (lcd_readl(fbi, FDADR1) != fbi->fdadr[1])))
> Â Â Â Â Â Â Â Âpxafb_schedule_work(fbi, C_REENABLE);
>
> Â Â Â Âreturn 0;
> @@ -1420,7 +1436,8 @@ static void pxafb_enable_controller(struct pxafb_info *fbi)
> Â Â Â Âlcd_writel(fbi, LCCR0, fbi->reg_lccr0 & ~LCCR0_ENB);
>
> Â Â Â Âlcd_writel(fbi, FDADR0, fbi->fdadr[0]);
> - Â Â Â lcd_writel(fbi, FDADR1, fbi->fdadr[1]);
> + Â Â Â if (fbi->lccr0 & LCCR0_SDS)
> + Â Â Â Â Â Â Â lcd_writel(fbi, FDADR1, fbi->fdadr[1]);

My original intention was to simplify the code a bit by ignoring
LCCR0_SDS, as FDADR1 would not take effect if not enabled even
if it's being read/written.

> Â Â Â Âlcd_writel(fbi, LCCR0, fbi->reg_lccr0 | LCCR0_ENB);
> Â}
>
> @@ -1806,6 +1823,11 @@ static struct pxafb_info * __devinit pxafb_init_fbinfo(struct device *dev)
>
> Â Â Â Âpxafb_decode_mach_info(fbi, inf);
>
> +#ifdef CONFIG_FB_PXA_OVERLAY
> + Â Â Â if (cpu_is_pxa27x())
> + Â Â Â Â Â Â Â fbi->lccr0 |= LCCR0_OUC;
> +#endif
> +

I seem to remember LCCR0_OUC is still valid on pxa3xx, did you
do some test on pxa3xx as well?

> Â Â Â Âinit_waitqueue_head(&fbi->ctrlr_wait);
> Â Â Â ÂINIT_WORK(&fbi->task, pxafb_task);
> Â Â Â Âmutex_init(&fbi->ctrlr_lock);
> diff --git a/drivers/video/pxafb.h b/drivers/video/pxafb.h
> index 2353521..84e3ae1 100644
> --- a/drivers/video/pxafb.h
> +++ b/drivers/video/pxafb.h
> @@ -92,7 +92,7 @@ struct pxafb_layer_ops {
> Âstruct pxafb_layer {
>    Âstruct fb_info     Âfb;
>    Âint           id;
> -    atomic_t        Âusage;
> +    uint32_t        Âusage;
>    Âuint32_t        Âcontrol[2];
>
> Â Â Â Âstruct pxafb_layer_ops Â*ops;
> --
> 1.7.4.rc1
>
>
--
To unsubscribe from this list: send the line "unsubscribe linux-fbdev" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Video for Linux]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Tourism]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux