From: "Bruno Prémont" <bonbons@linux-vserver.org>
To: Jiri Kosina <jkosina@suse.cz>
Cc: Jaya Kumar <jayakumar.lkml@gmail.com>,
linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 3/4] HID: picolcd: do not reallocate memory on depth change
Date: Mon, 28 Jun 2010 20:31:20 +0000 [thread overview]
Message-ID: <20100628223120.4d334f95@neptune.home> (raw)
In-Reply-To: <20100628222641.489c955a@neptune.home>
Reallocating memory in depth change does not work well if some
userspace application has mmapped() the framebuffer as that mapping
does not get adjusted (thus application continues to write to old
buffer).
In addition doing deferred_io_cleanup() and init() inside of set_par()
tends to deadlock with fbcon's flashing cursor.
Avoid all this by allocating a buffer that can hold 8bpp framebuffer
and just use 1/8 of it while running at 1bpp.
Signed-off-by: Bruno Prémont <bonbons@linux-vserver.org>
---
drivers/hid/hid-picolcd.c | 27 ++++++++++++---------------
1 files changed, 12 insertions(+), 15 deletions(-)
diff --git a/drivers/hid/hid-picolcd.c b/drivers/hid/hid-picolcd.c
index ac7aece..31a0abd 100644
--- a/drivers/hid/hid-picolcd.c
+++ b/drivers/hid/hid-picolcd.c
@@ -563,19 +563,18 @@ static int picolcd_fb_check_var(struct fb_var_screeninfo *var, struct fb_info *i
static int picolcd_set_par(struct fb_info *info)
{
struct picolcd_data *data = info->par;
- u8 *o_fb, *n_fb;
+ u8 *tmp_fb, *o_fb;
if (info->var.bits_per_pixel = data->fb_bpp)
return 0;
/* switch between 1/8 bit depths */
if (info->var.bits_per_pixel != 1 && info->var.bits_per_pixel != 8)
return -EINVAL;
- o_fb = data->fb_bitmap;
- n_fb = vmalloc(PICOLCDFB_SIZE*info->var.bits_per_pixel);
- if (!n_fb)
+ o_fb = data->fb_bitmap;
+ tmp_fb = kmalloc(PICOLCDFB_SIZE*info->var.bits_per_pixel, GFP_KERNEL);
+ if (!tmp_fb)
return -ENOMEM;
- fb_deferred_io_cleanup(info);
/* translate FB content to new bits-per-pixel */
if (info->var.bits_per_pixel = 1) {
int i, b;
@@ -585,24 +584,22 @@ static int picolcd_set_par(struct fb_info *info)
p <<= 1;
p |= o_fb[i*8+b] ? 0x01 : 0x00;
}
+ tmp_fb[i] = p;
}
+ memcpy(o_fb, tmp_fb, PICOLCDFB_SIZE);
info->fix.visual = FB_VISUAL_MONO01;
info->fix.line_length = PICOLCDFB_WIDTH / 8;
} else {
int i;
+ memcpy(tmp_fb, o_fb, PICOLCDFB_SIZE);
for (i = 0; i < PICOLCDFB_SIZE * 8; i++)
- n_fb[i] = o_fb[i/8] & (0x01 << (7 - i % 8)) ? 0xff : 0x00;
- info->fix.visual = FB_VISUAL_TRUECOLOR;
+ o_fb[i] = tmp_fb[i/8] & (0x01 << (7 - i % 8)) ? 0xff : 0x00;
+ info->fix.visual = FB_VISUAL_DIRECTCOLOR;
info->fix.line_length = PICOLCDFB_WIDTH;
}
- data->fb_bitmap = n_fb;
+ kfree(tmp_fb);
data->fb_bpp = info->var.bits_per_pixel;
- info->screen_base = (char __force __iomem *)n_fb;
- info->fix.smem_start = (unsigned long)n_fb;
- info->fix.smem_len = PICOLCDFB_SIZE*data->fb_bpp;
- fb_deferred_io_init(info);
- vfree(o_fb);
return 0;
}
@@ -692,7 +689,7 @@ static int picolcd_init_framebuffer(struct picolcd_data *data)
u8 *fb_bitmap = NULL;
u32 *palette;
- fb_bitmap = vmalloc(PICOLCDFB_SIZE*picolcdfb_var.bits_per_pixel);
+ fb_bitmap = vmalloc(PICOLCDFB_SIZE*8);
if (fb_bitmap = NULL) {
dev_err(dev, "can't get a free page for framebuffer\n");
goto err_nomem;
@@ -728,7 +725,7 @@ static int picolcd_init_framebuffer(struct picolcd_data *data)
info->fbops = &picolcdfb_ops;
info->var = picolcdfb_var;
info->fix = picolcdfb_fix;
- info->fix.smem_len = PICOLCDFB_SIZE;
+ info->fix.smem_len = PICOLCDFB_SIZE*8;
info->fix.smem_start = (unsigned long)fb_bitmap;
info->par = data;
info->flags = FBINFO_FLAG_DEFAULT;
--
1.7.1
next prev parent reply other threads:[~2010-06-28 20:31 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-09 16:49 Deadlock between fbcon and fb_defio? Bruno Prémont
2010-05-10 0:00 ` Jaya Kumar
2010-05-10 6:00 ` Bruno Prémont
2010-05-26 19:58 ` vfree() and mmap()ed framebuffer with defio (Was: Deadlock Bruno Prémont
2010-05-30 11:09 ` [Patch] HID: Fix PicoLCD to allow it to run fbcon and handle unplug Bruno Prémont
2010-06-23 10:32 ` [Patch] HID: Fix PicoLCD to allow it to run fbcon and handle Bruno Prémont
2010-06-24 8:54 ` Jiri Kosina
2010-06-28 20:26 ` [Patch 0/4] " Bruno Prémont
2010-06-28 20:29 ` [PATCH 1/4] HID: picolcd: fix deferred_io init/cleanup to Bruno Prémont
2010-06-30 1:52 ` Jaya Kumar
2010-06-30 5:56 ` Bruno Prémont
2010-06-30 20:36 ` [PATCH 1/4 - adjusted changelog] HID: picolcd: fix deferred_io Bruno Prémont
2010-07-11 20:58 ` Jiri Kosina
2010-07-12 6:17 ` Bruno Prémont
2010-07-12 16:05 ` Jiri Kosina
2010-07-12 16:09 ` Jiri Kosina
2010-06-28 20:30 ` [PATCH 2/4] HID: picolcd: Add minimal palette required by fbcon on Bruno Prémont
2010-06-28 20:31 ` Bruno Prémont [this message]
2010-06-28 20:33 ` [PATCH 4/4] HID: picolcd: implement refcounting of framebuffer Bruno Prémont
2010-06-28 21:26 ` Bernie Thompson
2010-06-29 20:42 ` Bruno Prémont
2010-06-30 15:41 ` Bernie Thompson
2010-06-30 9:28 ` [Patch 0/4] HID: Fix PicoLCD to allow it to run fbcon and handle Jiri Kosina
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100628223120.4d334f95@neptune.home \
--to=bonbons@linux-vserver.org \
--cc=jayakumar.lkml@gmail.com \
--cc=jkosina@suse.cz \
--cc=linux-fbdev@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).