Commit ee06bd15 authored by Mans Rullgard's avatar Mans Rullgard Committed by Tomi Valkeinen

video: fbdev: fix sys_copyarea

The sys_copyarea() function performs the same operation as
cfb_copyarea() but using normal memory access instead of I/O
accessors.  Since the introduction of sys_copyarea(), there
have been two fixes to cfb_copyarea():

- 00a9d699 ("framebuffer: fix cfb_copyarea")
- 5b789da8 ("framebuffer: fix screen corruption when copying")

This patch incorporates the fixes into sys_copyarea() as well.
Signed-off-by: default avatarMans Rullgard <mans@mansr.com>
Signed-off-by: default avatarTomi Valkeinen <tomi.valkeinen@ti.com>
parent 6984330a
...@@ -25,8 +25,8 @@ ...@@ -25,8 +25,8 @@
*/ */
static void static void
bitcpy(struct fb_info *p, unsigned long *dst, int dst_idx, bitcpy(struct fb_info *p, unsigned long *dst, unsigned dst_idx,
const unsigned long *src, int src_idx, int bits, unsigned n) const unsigned long *src, unsigned src_idx, int bits, unsigned n)
{ {
unsigned long first, last; unsigned long first, last;
int const shift = dst_idx-src_idx; int const shift = dst_idx-src_idx;
...@@ -86,15 +86,15 @@ bitcpy(struct fb_info *p, unsigned long *dst, int dst_idx, ...@@ -86,15 +86,15 @@ bitcpy(struct fb_info *p, unsigned long *dst, int dst_idx,
first &= last; first &= last;
if (shift > 0) { if (shift > 0) {
/* Single source word */ /* Single source word */
*dst = comp(*src >> right, *dst, first); *dst = comp(*src << left, *dst, first);
} else if (src_idx+n <= bits) { } else if (src_idx+n <= bits) {
/* Single source word */ /* Single source word */
*dst = comp(*src << left, *dst, first); *dst = comp(*src >> right, *dst, first);
} else { } else {
/* 2 source words */ /* 2 source words */
d0 = *src++; d0 = *src++;
d1 = *src; d1 = *src;
*dst = comp(d0 << left | d1 >> right, *dst, *dst = comp(d0 >> right | d1 << left, *dst,
first); first);
} }
} else { } else {
...@@ -109,13 +109,14 @@ bitcpy(struct fb_info *p, unsigned long *dst, int dst_idx, ...@@ -109,13 +109,14 @@ bitcpy(struct fb_info *p, unsigned long *dst, int dst_idx,
/* Leading bits */ /* Leading bits */
if (shift > 0) { if (shift > 0) {
/* Single source word */ /* Single source word */
*dst = comp(d0 >> right, *dst, first); *dst = comp(d0 << left, *dst, first);
dst++; dst++;
n -= bits - dst_idx; n -= bits - dst_idx;
} else { } else {
/* 2 source words */ /* 2 source words */
d1 = *src++; d1 = *src++;
*dst = comp(d0 << left | *dst >> right, *dst, first); *dst = comp(d0 >> right | d1 << left, *dst,
first);
d0 = d1; d0 = d1;
dst++; dst++;
n -= bits - dst_idx; n -= bits - dst_idx;
...@@ -126,36 +127,36 @@ bitcpy(struct fb_info *p, unsigned long *dst, int dst_idx, ...@@ -126,36 +127,36 @@ bitcpy(struct fb_info *p, unsigned long *dst, int dst_idx,
n /= bits; n /= bits;
while (n >= 4) { while (n >= 4) {
d1 = *src++; d1 = *src++;
*dst++ = d0 << left | d1 >> right; *dst++ = d0 >> right | d1 << left;
d0 = d1; d0 = d1;
d1 = *src++; d1 = *src++;
*dst++ = d0 << left | d1 >> right; *dst++ = d0 >> right | d1 << left;
d0 = d1; d0 = d1;
d1 = *src++; d1 = *src++;
*dst++ = d0 << left | d1 >> right; *dst++ = d0 >> right | d1 << left;
d0 = d1; d0 = d1;
d1 = *src++; d1 = *src++;
*dst++ = d0 << left | d1 >> right; *dst++ = d0 >> right | d1 << left;
d0 = d1; d0 = d1;
n -= 4; n -= 4;
} }
while (n--) { while (n--) {
d1 = *src++; d1 = *src++;
*dst++ = d0 << left | d1 >> right; *dst++ = d0 >> right | d1 << left;
d0 = d1; d0 = d1;
} }
/* Trailing bits */ /* Trailing bits */
if (last) { if (m) {
if (m <= right) { if (m <= bits - right) {
/* Single source word */ /* Single source word */
*dst = comp(d0 << left, *dst, last); d0 >>= right;
} else { } else {
/* 2 source words */ /* 2 source words */
d1 = *src; d1 = *src;
*dst = comp(d0 << left | d1 >> right, d0 = d0 >> right | d1 << left;
*dst, last);
} }
*dst = comp(d0, *dst, last);
} }
} }
} }
...@@ -166,40 +167,35 @@ bitcpy(struct fb_info *p, unsigned long *dst, int dst_idx, ...@@ -166,40 +167,35 @@ bitcpy(struct fb_info *p, unsigned long *dst, int dst_idx,
*/ */
static void static void
bitcpy_rev(struct fb_info *p, unsigned long *dst, int dst_idx, bitcpy_rev(struct fb_info *p, unsigned long *dst, unsigned dst_idx,
const unsigned long *src, int src_idx, int bits, unsigned n) const unsigned long *src, unsigned src_idx, unsigned bits,
unsigned n)
{ {
unsigned long first, last; unsigned long first, last;
int shift; int shift;
dst += (n-1)/bits; dst += (dst_idx + n - 1) / bits;
src += (n-1)/bits; src += (src_idx + n - 1) / bits;
if ((n-1) % bits) { dst_idx = (dst_idx + n - 1) % bits;
dst_idx += (n-1) % bits; src_idx = (src_idx + n - 1) % bits;
dst += dst_idx >> (ffs(bits) - 1);
dst_idx &= bits - 1;
src_idx += (n-1) % bits;
src += src_idx >> (ffs(bits) - 1);
src_idx &= bits - 1;
}
shift = dst_idx-src_idx; shift = dst_idx-src_idx;
first = FB_SHIFT_LOW(p, ~0UL, bits - 1 - dst_idx); first = ~FB_SHIFT_HIGH(p, ~0UL, (dst_idx + 1) % bits);
last = ~(FB_SHIFT_LOW(p, ~0UL, bits - 1 - ((dst_idx-n) % bits))); last = FB_SHIFT_HIGH(p, ~0UL, (bits + dst_idx + 1 - n) % bits);
if (!shift) { if (!shift) {
/* Same alignment for source and dest */ /* Same alignment for source and dest */
if ((unsigned long)dst_idx+1 >= n) { if ((unsigned long)dst_idx+1 >= n) {
/* Single word */ /* Single word */
if (last) if (first)
first &= last; last &= first;
*dst = comp(*src, *dst, first); *dst = comp(*src, *dst, last);
} else { } else {
/* Multiple destination words */ /* Multiple destination words */
/* Leading bits */ /* Leading bits */
if (first != ~0UL) { if (first) {
*dst = comp(*src, *dst, first); *dst = comp(*src, *dst, first);
dst--; dst--;
src--; src--;
...@@ -222,29 +218,29 @@ bitcpy_rev(struct fb_info *p, unsigned long *dst, int dst_idx, ...@@ -222,29 +218,29 @@ bitcpy_rev(struct fb_info *p, unsigned long *dst, int dst_idx,
while (n--) while (n--)
*dst-- = *src--; *dst-- = *src--;
/* Trailing bits */ /* Trailing bits */
if (last) if (last != -1UL)
*dst = comp(*src, *dst, last); *dst = comp(*src, *dst, last);
} }
} else { } else {
/* Different alignment for source and dest */ /* Different alignment for source and dest */
int const left = -shift & (bits-1); int const left = shift & (bits-1);
int const right = shift & (bits-1); int const right = -shift & (bits-1);
if ((unsigned long)dst_idx+1 >= n) { if ((unsigned long)dst_idx+1 >= n) {
/* Single destination word */ /* Single destination word */
if (last) if (first)
first &= last; last &= first;
if (shift < 0) { if (shift < 0) {
/* Single source word */ /* Single source word */
*dst = comp(*src << left, *dst, first); *dst = comp(*src >> right, *dst, last);
} else if (1+(unsigned long)src_idx >= n) { } else if (1+(unsigned long)src_idx >= n) {
/* Single source word */ /* Single source word */
*dst = comp(*src >> right, *dst, first); *dst = comp(*src << left, *dst, last);
} else { } else {
/* 2 source words */ /* 2 source words */
*dst = comp(*src >> right | *(src-1) << left, *dst = comp(*src << left | *(src-1) >> right,
*dst, first); *dst, last);
} }
} else { } else {
/* Multiple destination words */ /* Multiple destination words */
...@@ -261,14 +257,18 @@ bitcpy_rev(struct fb_info *p, unsigned long *dst, int dst_idx, ...@@ -261,14 +257,18 @@ bitcpy_rev(struct fb_info *p, unsigned long *dst, int dst_idx,
/* Leading bits */ /* Leading bits */
if (shift < 0) { if (shift < 0) {
/* Single source word */ /* Single source word */
*dst = comp(d0 << left, *dst, first); d1 = d0;
d0 >>= right;
} else { } else {
/* 2 source words */ /* 2 source words */
d1 = *src--; d1 = *src--;
*dst = comp(d0 >> right | d1 << left, *dst, d0 = d0 << left | d1 >> right;
first);
d0 = d1;
} }
if (!first)
*dst = d0;
else
*dst = comp(d0, *dst, first);
d0 = d1;
dst--; dst--;
n -= dst_idx+1; n -= dst_idx+1;
...@@ -277,36 +277,36 @@ bitcpy_rev(struct fb_info *p, unsigned long *dst, int dst_idx, ...@@ -277,36 +277,36 @@ bitcpy_rev(struct fb_info *p, unsigned long *dst, int dst_idx,
n /= bits; n /= bits;
while (n >= 4) { while (n >= 4) {
d1 = *src--; d1 = *src--;
*dst-- = d0 >> right | d1 << left; *dst-- = d0 << left | d1 >> right;
d0 = d1; d0 = d1;
d1 = *src--; d1 = *src--;
*dst-- = d0 >> right | d1 << left; *dst-- = d0 << left | d1 >> right;
d0 = d1; d0 = d1;
d1 = *src--; d1 = *src--;
*dst-- = d0 >> right | d1 << left; *dst-- = d0 << left | d1 >> right;
d0 = d1; d0 = d1;
d1 = *src--; d1 = *src--;
*dst-- = d0 >> right | d1 << left; *dst-- = d0 << left | d1 >> right;
d0 = d1; d0 = d1;
n -= 4; n -= 4;
} }
while (n--) { while (n--) {
d1 = *src--; d1 = *src--;
*dst-- = d0 >> right | d1 << left; *dst-- = d0 << left | d1 >> right;
d0 = d1; d0 = d1;
} }
/* Trailing bits */ /* Trailing bits */
if (last) { if (m) {
if (m <= left) { if (m <= bits - left) {
/* Single source word */ /* Single source word */
*dst = comp(d0 >> right, *dst, last); d0 <<= left;
} else { } else {
/* 2 source words */ /* 2 source words */
d1 = *src; d1 = *src;
*dst = comp(d0 >> right | d1 << left, d0 = d0 << left | d1 >> right;
*dst, last);
} }
*dst = comp(d0, *dst, last);
} }
} }
} }
...@@ -317,9 +317,9 @@ void sys_copyarea(struct fb_info *p, const struct fb_copyarea *area) ...@@ -317,9 +317,9 @@ void sys_copyarea(struct fb_info *p, const struct fb_copyarea *area)
u32 dx = area->dx, dy = area->dy, sx = area->sx, sy = area->sy; u32 dx = area->dx, dy = area->dy, sx = area->sx, sy = area->sy;
u32 height = area->height, width = area->width; u32 height = area->height, width = area->width;
unsigned long const bits_per_line = p->fix.line_length*8u; unsigned long const bits_per_line = p->fix.line_length*8u;
unsigned long *dst = NULL, *src = NULL; unsigned long *base = NULL;
int bits = BITS_PER_LONG, bytes = bits >> 3; int bits = BITS_PER_LONG, bytes = bits >> 3;
int dst_idx = 0, src_idx = 0, rev_copy = 0; unsigned dst_idx = 0, src_idx = 0, rev_copy = 0;
if (p->state != FBINFO_STATE_RUNNING) if (p->state != FBINFO_STATE_RUNNING)
return; return;
...@@ -334,8 +334,7 @@ void sys_copyarea(struct fb_info *p, const struct fb_copyarea *area) ...@@ -334,8 +334,7 @@ void sys_copyarea(struct fb_info *p, const struct fb_copyarea *area)
/* split the base of the framebuffer into a long-aligned address and /* split the base of the framebuffer into a long-aligned address and
the index of the first bit */ the index of the first bit */
dst = src = (unsigned long *)((unsigned long)p->screen_base & base = (unsigned long *)((unsigned long)p->screen_base & ~(bytes-1));
~(bytes-1));
dst_idx = src_idx = 8*((unsigned long)p->screen_base & (bytes-1)); dst_idx = src_idx = 8*((unsigned long)p->screen_base & (bytes-1));
/* add offset of source and target area */ /* add offset of source and target area */
dst_idx += dy*bits_per_line + dx*p->var.bits_per_pixel; dst_idx += dy*bits_per_line + dx*p->var.bits_per_pixel;
...@@ -348,20 +347,14 @@ void sys_copyarea(struct fb_info *p, const struct fb_copyarea *area) ...@@ -348,20 +347,14 @@ void sys_copyarea(struct fb_info *p, const struct fb_copyarea *area)
while (height--) { while (height--) {
dst_idx -= bits_per_line; dst_idx -= bits_per_line;
src_idx -= bits_per_line; src_idx -= bits_per_line;
dst += dst_idx >> (ffs(bits) - 1); bitcpy_rev(p, base + (dst_idx / bits), dst_idx % bits,
dst_idx &= (bytes - 1); base + (src_idx / bits), src_idx % bits, bits,
src += src_idx >> (ffs(bits) - 1);
src_idx &= (bytes - 1);
bitcpy_rev(p, dst, dst_idx, src, src_idx, bits,
width*p->var.bits_per_pixel); width*p->var.bits_per_pixel);
} }
} else { } else {
while (height--) { while (height--) {
dst += dst_idx >> (ffs(bits) - 1); bitcpy(p, base + (dst_idx / bits), dst_idx % bits,
dst_idx &= (bytes - 1); base + (src_idx / bits), src_idx % bits, bits,
src += src_idx >> (ffs(bits) - 1);
src_idx &= (bytes - 1);
bitcpy(p, dst, dst_idx, src, src_idx, bits,
width*p->var.bits_per_pixel); width*p->var.bits_per_pixel);
dst_idx += bits_per_line; dst_idx += bits_per_line;
src_idx += bits_per_line; src_idx += bits_per_line;
......
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