Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * include/linux/vt_buffer.h -- Access to VT screen buffer |
| 4 | * |
| 5 | * (c) 1998 Martin Mares <mj@ucw.cz> |
| 6 | * |
| 7 | * This is a set of macros and functions which are used in the |
| 8 | * console driver and related code to access the screen buffer. |
| 9 | * In most cases the console works with simple in-memory buffer, |
| 10 | * but when handling hardware text mode consoles, we store |
| 11 | * the foreground console directly in video memory. |
| 12 | */ |
| 13 | |
| 14 | #ifndef _LINUX_VT_BUFFER_H_ |
| 15 | #define _LINUX_VT_BUFFER_H_ |
| 16 | |
Matthew Wilcox | ac036f9 | 2017-09-08 16:14:15 -0700 | [diff] [blame] | 17 | #include <linux/string.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
| 19 | #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_MDA_CONSOLE) |
| 20 | #include <asm/vga.h> |
| 21 | #endif |
| 22 | |
| 23 | #ifndef VT_BUF_HAVE_RW |
| 24 | #define scr_writew(val, addr) (*(addr) = (val)) |
| 25 | #define scr_readw(addr) (*(addr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #endif |
| 27 | |
| 28 | #ifndef VT_BUF_HAVE_MEMSETW |
| 29 | static inline void scr_memsetw(u16 *s, u16 c, unsigned int count) |
| 30 | { |
Matthew Wilcox | ac036f9 | 2017-09-08 16:14:15 -0700 | [diff] [blame] | 31 | #ifdef VT_BUF_HAVE_RW |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | count /= 2; |
| 33 | while (count--) |
| 34 | scr_writew(c, s++); |
Matthew Wilcox | ac036f9 | 2017-09-08 16:14:15 -0700 | [diff] [blame] | 35 | #else |
| 36 | memset16(s, c, count / 2); |
| 37 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | } |
| 39 | #endif |
| 40 | |
| 41 | #ifndef VT_BUF_HAVE_MEMCPYW |
| 42 | static inline void scr_memcpyw(u16 *d, const u16 *s, unsigned int count) |
| 43 | { |
Matthew Wilcox | ac036f9 | 2017-09-08 16:14:15 -0700 | [diff] [blame] | 44 | #ifdef VT_BUF_HAVE_RW |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | count /= 2; |
| 46 | while (count--) |
| 47 | scr_writew(scr_readw(s++), d++); |
Matthew Wilcox | ac036f9 | 2017-09-08 16:14:15 -0700 | [diff] [blame] | 48 | #else |
| 49 | memcpy(d, s, count); |
| 50 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | } |
| 52 | #endif |
| 53 | |
| 54 | #ifndef VT_BUF_HAVE_MEMMOVEW |
| 55 | static inline void scr_memmovew(u16 *d, const u16 *s, unsigned int count) |
| 56 | { |
Matthew Wilcox | ac036f9 | 2017-09-08 16:14:15 -0700 | [diff] [blame] | 57 | #ifdef VT_BUF_HAVE_RW |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | if (d < s) |
| 59 | scr_memcpyw(d, s, count); |
| 60 | else { |
| 61 | count /= 2; |
| 62 | d += count; |
| 63 | s += count; |
| 64 | while (count--) |
| 65 | scr_writew(scr_readw(--s), --d); |
| 66 | } |
Matthew Wilcox | ac036f9 | 2017-09-08 16:14:15 -0700 | [diff] [blame] | 67 | #else |
| 68 | memmove(d, s, count); |
| 69 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | } |
| 71 | #endif |
| 72 | |
| 73 | #endif |