blob: 30b6e0d2a942600e234c8195551a008e4d23c039 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * include/linux/vt_buffer.h -- Access to VT screen buffer
3 *
4 * (c) 1998 Martin Mares <mj@ucw.cz>
5 *
6 * This is a set of macros and functions which are used in the
7 * console driver and related code to access the screen buffer.
8 * In most cases the console works with simple in-memory buffer,
9 * but when handling hardware text mode consoles, we store
10 * the foreground console directly in video memory.
11 */
12
13#ifndef _LINUX_VT_BUFFER_H_
14#define _LINUX_VT_BUFFER_H_
15
Matthew Wilcoxac036f92017-09-08 16:14:15 -070016#include <linux/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18#if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_MDA_CONSOLE)
19#include <asm/vga.h>
20#endif
21
22#ifndef VT_BUF_HAVE_RW
23#define scr_writew(val, addr) (*(addr) = (val))
24#define scr_readw(addr) (*(addr))
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#endif
26
27#ifndef VT_BUF_HAVE_MEMSETW
28static inline void scr_memsetw(u16 *s, u16 c, unsigned int count)
29{
Matthew Wilcoxac036f92017-09-08 16:14:15 -070030#ifdef VT_BUF_HAVE_RW
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 count /= 2;
32 while (count--)
33 scr_writew(c, s++);
Matthew Wilcoxac036f92017-09-08 16:14:15 -070034#else
35 memset16(s, c, count / 2);
36#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070037}
38#endif
39
40#ifndef VT_BUF_HAVE_MEMCPYW
41static inline void scr_memcpyw(u16 *d, const u16 *s, unsigned int count)
42{
Matthew Wilcoxac036f92017-09-08 16:14:15 -070043#ifdef VT_BUF_HAVE_RW
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 count /= 2;
45 while (count--)
46 scr_writew(scr_readw(s++), d++);
Matthew Wilcoxac036f92017-09-08 16:14:15 -070047#else
48 memcpy(d, s, count);
49#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070050}
51#endif
52
53#ifndef VT_BUF_HAVE_MEMMOVEW
54static inline void scr_memmovew(u16 *d, const u16 *s, unsigned int count)
55{
Matthew Wilcoxac036f92017-09-08 16:14:15 -070056#ifdef VT_BUF_HAVE_RW
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 if (d < s)
58 scr_memcpyw(d, s, count);
59 else {
60 count /= 2;
61 d += count;
62 s += count;
63 while (count--)
64 scr_writew(scr_readw(--s), --d);
65 }
Matthew Wilcoxac036f92017-09-08 16:14:15 -070066#else
67 memmove(d, s, count);
68#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070069}
70#endif
71
72#endif