Commit ac036f95 authored by Matthew Wilcox's avatar Matthew Wilcox Committed by Linus Torvalds

vga: optimise console scrolling

Where possible, call memset16(), memmove() or memcpy() instead of using
open-coded loops.  I don't like the calling convention that uses a byte
count instead of a count of u16s, but it's a little late to change that.
Reduces code size of fbcon.o by almost 400 bytes on my laptop build.

[akpm@linux-foundation.org: fix build]
Link: http://lkml.kernel.org/r/20170720184539.31609-9-willy@infradead.orgSigned-off-by: default avatarMatthew Wilcox <mawilcox@microsoft.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: David Miller <davem@davemloft.net>
Cc: Sam Ravnborg <sam@ravnborg.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: "James E.J. Bottomley" <jejb@linux.vnet.ibm.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Matt Turner <mattst88@gmail.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Russell King <rmk+kernel@armlinux.org.uk>
Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 1caffba9
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#ifndef _ASM_VGA_H #ifndef _ASM_VGA_H
#define _ASM_VGA_H #define _ASM_VGA_H
#include <linux/string.h>
#include <asm/addrspace.h> #include <asm/addrspace.h>
#include <asm/byteorder.h> #include <asm/byteorder.h>
...@@ -40,9 +41,15 @@ static inline u16 scr_readw(volatile const u16 *addr) ...@@ -40,9 +41,15 @@ static inline u16 scr_readw(volatile const u16 *addr)
return le16_to_cpu(*addr); return le16_to_cpu(*addr);
} }
static inline void scr_memsetw(u16 *s, u16 v, unsigned int count)
{
memset16(s, cpu_to_le16(v), count / 2);
}
#define scr_memcpyw(d, s, c) memcpy(d, s, c) #define scr_memcpyw(d, s, c) memcpy(d, s, c)
#define scr_memmovew(d, s, c) memmove(d, s, c) #define scr_memmovew(d, s, c) memmove(d, s, c)
#define VT_BUF_HAVE_MEMCPYW #define VT_BUF_HAVE_MEMCPYW
#define VT_BUF_HAVE_MEMMOVEW #define VT_BUF_HAVE_MEMMOVEW
#define VT_BUF_HAVE_MEMSETW
#endif /* _ASM_VGA_H */ #endif /* _ASM_VGA_H */
...@@ -33,8 +33,16 @@ static inline u16 scr_readw(volatile const u16 *addr) ...@@ -33,8 +33,16 @@ static inline u16 scr_readw(volatile const u16 *addr)
return le16_to_cpu(*addr); return le16_to_cpu(*addr);
} }
#define VT_BUF_HAVE_MEMSETW
static inline void scr_memsetw(u16 *s, u16 v, unsigned int n)
{
memset16(s, cpu_to_le16(v), n / 2);
}
#define VT_BUF_HAVE_MEMCPYW #define VT_BUF_HAVE_MEMCPYW
#define VT_BUF_HAVE_MEMMOVEW
#define scr_memcpyw memcpy #define scr_memcpyw memcpy
#define scr_memmovew memmove
#endif /* !CONFIG_VGA_CONSOLE && !CONFIG_MDA_CONSOLE */ #endif /* !CONFIG_VGA_CONSOLE && !CONFIG_MDA_CONSOLE */
......
...@@ -8,9 +8,13 @@ ...@@ -8,9 +8,13 @@
#define _LINUX_ASM_VGA_H_ #define _LINUX_ASM_VGA_H_
#include <linux/bug.h> #include <linux/bug.h>
#include <linux/string.h>
#include <asm/types.h> #include <asm/types.h>
#define VT_BUF_HAVE_RW #define VT_BUF_HAVE_RW
#define VT_BUF_HAVE_MEMSETW
#define VT_BUF_HAVE_MEMCPYW
#define VT_BUF_HAVE_MEMMOVEW
#undef scr_writew #undef scr_writew
#undef scr_readw #undef scr_readw
...@@ -29,6 +33,27 @@ static inline u16 scr_readw(const u16 *addr) ...@@ -29,6 +33,27 @@ static inline u16 scr_readw(const u16 *addr)
return *addr; return *addr;
} }
static inline void scr_memsetw(u16 *p, u16 v, unsigned int n)
{
BUG_ON((long) p >= 0);
memset16(p, cpu_to_le16(v), n / 2);
}
static inline void scr_memcpyw(u16 *d, u16 *s, unsigned int n)
{
BUG_ON((long) d >= 0);
memcpy(d, s, n);
}
static inline void scr_memmovew(u16 *d, u16 *s, unsigned int n)
{
BUG_ON((long) d >= 0);
memmove(d, s, n);
}
#define VGA_MAP_MEM(x,s) (x) #define VGA_MAP_MEM(x,s) (x)
#endif #endif
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#ifndef _LINUX_VT_BUFFER_H_ #ifndef _LINUX_VT_BUFFER_H_
#define _LINUX_VT_BUFFER_H_ #define _LINUX_VT_BUFFER_H_
#include <linux/string.h>
#if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_MDA_CONSOLE) #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_MDA_CONSOLE)
#include <asm/vga.h> #include <asm/vga.h>
...@@ -26,24 +27,33 @@ ...@@ -26,24 +27,33 @@
#ifndef VT_BUF_HAVE_MEMSETW #ifndef VT_BUF_HAVE_MEMSETW
static inline void scr_memsetw(u16 *s, u16 c, unsigned int count) static inline void scr_memsetw(u16 *s, u16 c, unsigned int count)
{ {
#ifdef VT_BUF_HAVE_RW
count /= 2; count /= 2;
while (count--) while (count--)
scr_writew(c, s++); scr_writew(c, s++);
#else
memset16(s, c, count / 2);
#endif
} }
#endif #endif
#ifndef VT_BUF_HAVE_MEMCPYW #ifndef VT_BUF_HAVE_MEMCPYW
static inline void scr_memcpyw(u16 *d, const u16 *s, unsigned int count) static inline void scr_memcpyw(u16 *d, const u16 *s, unsigned int count)
{ {
#ifdef VT_BUF_HAVE_RW
count /= 2; count /= 2;
while (count--) while (count--)
scr_writew(scr_readw(s++), d++); scr_writew(scr_readw(s++), d++);
#else
memcpy(d, s, count);
#endif
} }
#endif #endif
#ifndef VT_BUF_HAVE_MEMMOVEW #ifndef VT_BUF_HAVE_MEMMOVEW
static inline void scr_memmovew(u16 *d, const u16 *s, unsigned int count) static inline void scr_memmovew(u16 *d, const u16 *s, unsigned int count)
{ {
#ifdef VT_BUF_HAVE_RW
if (d < s) if (d < s)
scr_memcpyw(d, s, count); scr_memcpyw(d, s, count);
else { else {
...@@ -53,6 +63,9 @@ static inline void scr_memmovew(u16 *d, const u16 *s, unsigned int count) ...@@ -53,6 +63,9 @@ static inline void scr_memmovew(u16 *d, const u16 *s, unsigned int count)
while (count--) while (count--)
scr_writew(scr_readw(--s), --d); scr_writew(scr_readw(--s), --d);
} }
#else
memmove(d, s, count);
#endif
} }
#endif #endif
......
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