History

tty: vt, convert more macros to functions

Namely convert: * IS_FG -> con_is_fg * DO_UPDATE -> con_should_update * CON_IS_VISIBLE -> con_is_visible DO_UPDATE was a weird name for a yes/no answer, so the new name is con_should_update.

Jiri Slaby committed 10 years ago

Commit 6ca8dfd1 parent aada0a35 files · +57 −48Browse files

Unified · Split

5 files
  1. drivers/tty/vt/vt.c +34 −28
  2. drivers/usb/misc/sisusbvga/sisusb_con.c +2 −2
  3. drivers/video/console/fbcon.c +13 −13
  4. drivers/video/console/vgacon.c +4 −4
  5. include/linux/console_struct.h +4 −1
drivers/tty/vt/vt.c+34−28
@@ -277,8 +277,15 @@ static void notify_update(struct vc_data *vc) · 276 unmodified lines
277277 * Low-Level Functions
278278 */
279279
280−#define IS_FG(vc) ((vc)->vc_num == fg_console)
281−#define DO_UPDATE(vc) (CON_IS_VISIBLE(vc) && !console_blanked)
280+static inline bool con_is_fg(const struct vc_data *vc)
281+{
282+ return vc->vc_num == fg_console;
283+}
284+
285+static inline bool con_should_update(const struct vc_data *vc)
286+{
287+ return con_is_visible(vc) && !console_blanked;
288+}
282289
283290 static inline unsigned short *screenpos(struct vc_data *vc, int offset, int viewed)
284291 {
@@ -316,7 +323,7 @@ static void scrup(struct vc_data *vc, unsigned int t, unsigned int b, int nr) · 31 unmodified lines
316323 nr = b - t - 1;
317324 if (b > vc->vc_rows || t >= b || nr < 1)
318325 return;
319− if (CON_IS_VISIBLE(vc) && vc->vc_sw->con_scroll(vc, t, b, SM_UP, nr))
326+ if (con_is_visible(vc) && vc->vc_sw->con_scroll(vc, t, b, SM_UP, nr))
320327 return;
321328 d = (unsigned short *)(vc->vc_origin + vc->vc_size_row * t);
322329 s = (unsigned short *)(vc->vc_origin + vc->vc_size_row * (t + nr));
@@ -334,7 +341,7 @@ static void scrdown(struct vc_data *vc, unsigned int t, unsigned int b, int nr) · 11 unmodified lines
334341 nr = b - t - 1;
335342 if (b > vc->vc_rows || t >= b || nr < 1)
336343 return;
337− if (CON_IS_VISIBLE(vc) && vc->vc_sw->con_scroll(vc, t, b, SM_DOWN, nr))
344+ if (con_is_visible(vc) && vc->vc_sw->con_scroll(vc, t, b, SM_DOWN, nr))
338345 return;
339346 s = (unsigned short *)(vc->vc_origin + vc->vc_size_row * t);
340347 step = vc->vc_cols * nr;
@@ -390,7 +397,7 @@ void update_region(struct vc_data *vc, unsigned long start, int count) · 49 unmodified lines
390397 {
391398 WARN_CONSOLE_UNLOCKED();
392399
393− if (DO_UPDATE(vc)) {
400+ if (con_should_update(vc)) {
394401 hide_cursor(vc);
395402 do_update_region(vc, start, count);
396403 set_cursor(vc);
@@ -490,7 +497,7 @@ void invert_screen(struct vc_data *vc, int offset, int count, int viewed) · 93 unmodified lines
490497 }
491498 }
492499
493− if (DO_UPDATE(vc))
500+ if (con_should_update(vc))
494501 do_update_region(vc, (unsigned long) p, count);
495502 notify_update(vc);
496503 }
@@ -507,7 +514,7 @@ void complement_pos(struct vc_data *vc, int offset) · 10 unmodified lines
507514 if (old_offset != -1 && old_offset >= 0 &&
508515 old_offset < vc->vc_screenbuf_size) {
509516 scr_writew(old, screenpos(vc, old_offset, 1));
510− if (DO_UPDATE(vc))
517+ if (con_should_update(vc))
511518 vc->vc_sw->con_putc(vc, old, oldy, oldx);
512519 notify_update(vc);
513520 }
@@ -522,7 +529,7 @@ void complement_pos(struct vc_data *vc, int offset) · 8 unmodified lines
522529 old = scr_readw(p);
523530 new = old ^ vc->vc_complement_mask;
524531 scr_writew(new, p);
525− if (DO_UPDATE(vc)) {
532+ if (con_should_update(vc)) {
526533 oldx = (offset >> 1) % vc->vc_cols;
527534 oldy = (offset >> 1) / vc->vc_cols;
528535 vc->vc_sw->con_putc(vc, new, oldy, oldx);
@@ -538,7 +545,7 @@ static void insert_char(struct vc_data *vc, unsigned int nr) · 9 unmodified lines
538545 scr_memmovew(p + nr, p, (vc->vc_cols - vc->vc_x - nr) * 2);
539546 scr_memsetw(p, vc->vc_video_erase_char, nr * 2);
540547 vc->vc_need_wrap = 0;
541− if (DO_UPDATE(vc))
548+ if (con_should_update(vc))
542549 do_update_region(vc, (unsigned long) p,
543550 vc->vc_cols - vc->vc_x);
544551 }
@@ -551,7 +558,7 @@ static void delete_char(struct vc_data *vc, unsigned int nr) · 6 unmodified lines
551558 scr_memsetw(p + vc->vc_cols - vc->vc_x - nr, vc->vc_video_erase_char,
552559 nr * 2);
553560 vc->vc_need_wrap = 0;
554− if (DO_UPDATE(vc))
561+ if (con_should_update(vc))
555562 do_update_region(vc, (unsigned long) p,
556563 vc->vc_cols - vc->vc_x);
557564 }
@@ -571,7 +578,7 @@ static void add_softcursor(struct vc_data *vc) · 13 unmodified lines
571578 if ((type & 0x20) && ((softcursor_original & 0x7000) == (i & 0x7000))) i ^= 0x7000;
572579 if ((type & 0x40) && ((i & 0x700) == ((i & 0x7000) >> 4))) i ^= 0x0700;
573580 scr_writew(i, (u16 *) vc->vc_pos);
574− if (DO_UPDATE(vc))
581+ if (con_should_update(vc))
575582 vc->vc_sw->con_putc(vc, i, vc->vc_y, vc->vc_x);
576583 }
577584
@@ -579,7 +586,7 @@ static void hide_softcursor(struct vc_data *vc) · 1 unmodified line
579586 {
580587 if (softcursor_original != -1) {
581588 scr_writew(softcursor_original, (u16 *)vc->vc_pos);
582− if (DO_UPDATE(vc))
589+ if (con_should_update(vc))
583590 vc->vc_sw->con_putc(vc, softcursor_original,
584591 vc->vc_y, vc->vc_x);
585592 softcursor_original = -1;
@@ -596,8 +603,7 @@ static void hide_cursor(struct vc_data *vc) · 10 unmodified lines
596603
597604 static void set_cursor(struct vc_data *vc)
598605 {
599− if (!IS_FG(vc) || console_blanked ||
600− vc->vc_mode == KD_GRAPHICS)
606+ if (!con_is_fg(vc) || console_blanked || vc->vc_mode == KD_GRAPHICS)
601607 return;
602608 if (vc->vc_deccm) {
603609 if (vc == sel_cons)
@@ -613,7 +619,7 @@ static void set_origin(struct vc_data *vc) · 9 unmodified lines
613619 {
614620 WARN_CONSOLE_UNLOCKED();
615621
616− if (!CON_IS_VISIBLE(vc) ||
622+ if (!con_is_visible(vc) ||
617623 !vc->vc_sw->con_set_origin ||
618624 !vc->vc_sw->con_set_origin(vc))
619625 vc->vc_origin = (unsigned long)vc->vc_screenbuf;
@@ -661,12 +667,12 @@ void redraw_screen(struct vc_data *vc, int is_switch) · 41 unmodified lines
661667 struct vc_data *old_vc = vc_cons[fg_console].d;
662668 if (old_vc == vc)
663669 return;
664− if (!CON_IS_VISIBLE(vc))
670+ if (!con_is_visible(vc))
665671 redraw = 1;
666672 *vc->vc_display_fg = vc;
667673 fg_console = vc->vc_num;
668674 hide_cursor(old_vc);
669− if (!CON_IS_VISIBLE(old_vc)) {
675+ if (!con_is_visible(old_vc)) {
670676 save_screen(old_vc);
671677 set_origin(old_vc);
672678 }
@@ -941,7 +947,7 @@ static int vc_do_resize(struct tty_struct *tty, struct vc_data *vc, · 268 unmodified lines
941947 tty_do_resize(tty, &ws);
942948 }
943949
944− if (CON_IS_VISIBLE(vc))
950+ if (con_is_visible(vc))
945951 update_screen(vc);
946952 vt_event_post(VT_EVENT_RESIZE, vc->vc_num, vc->vc_num);
947953 return err;
@@ -1171,7 +1177,7 @@ static void csi_J(struct vc_data *vc, int vpar) · 223 unmodified lines
11711177 scr_memsetw(vc->vc_screenbuf, vc->vc_video_erase_char,
11721178 vc->vc_screenbuf_size >> 1);
11731179 set_origin(vc);
1174− if (CON_IS_VISIBLE(vc))
1180+ if (con_is_visible(vc))
11751181 update_screen(vc);
11761182 /* fall through */
11771183 case 2: /* erase whole display */
@@ -1182,7 +1188,7 @@ static void csi_J(struct vc_data *vc, int vpar) · 4 unmodified lines
11821188 return;
11831189 }
11841190 scr_memsetw(start, vc->vc_video_erase_char, 2 * count);
1185− if (DO_UPDATE(vc))
1191+ if (con_should_update(vc))
11861192 do_update_region(vc, (unsigned long) start, count);
11871193 vc->vc_need_wrap = 0;
11881194 }
@@ -1210,7 +1216,7 @@ static void csi_K(struct vc_data *vc, int vpar) · 21 unmodified lines
12101216 }
12111217 scr_memsetw(start, vc->vc_video_erase_char, 2 * count);
12121218 vc->vc_need_wrap = 0;
1213− if (DO_UPDATE(vc))
1219+ if (con_should_update(vc))
12141220 do_update_region(vc, (unsigned long) start, count);
12151221 }
12161222
@@ -1223,7 +1229,7 @@ static void csi_X(struct vc_data *vc, int vpar) /* erase the following vpar posi · 6 unmodified lines
12231229 count = (vpar > vc->vc_cols - vc->vc_x) ? (vc->vc_cols - vc->vc_x) : vpar;
12241230
12251231 scr_memsetw((unsigned short *)vc->vc_pos, vc->vc_video_erase_char, 2 * count);
1226− if (DO_UPDATE(vc))
1232+ if (con_should_update(vc))
12271233 vc->vc_sw->con_clear(vc, vc->vc_y, vc->vc_x, 1, count);
12281234 vc->vc_need_wrap = 0;
12291235 }
@@ -2208,7 +2214,7 @@ static int do_con_write(struct tty_struct *tty, const unsigned char *buf, int co · 978 unmodified lines
22082214 charmask = himask ? 0x1ff : 0xff;
22092215
22102216 /* undraw cursor first */
2211− if (IS_FG(vc))
2217+ if (con_is_fg(vc))
22122218 hide_cursor(vc);
22132219
22142220 param.vc = vc;
@@ -2380,7 +2386,7 @@ rescan_last_byte: · 165 unmodified lines
23802386 ((vc_attr << 8) & ~himask) + ((tc & 0x100) ? himask : 0) + (tc & 0xff) :
23812387 (vc_attr << 8) + tc,
23822388 (u16 *) vc->vc_pos);
2383− if (DO_UPDATE(vc) && draw_x < 0) {
2389+ if (con_should_update(vc) && draw_x < 0) {
23842390 draw_x = vc->vc_x;
23852391 draw_from = vc->vc_pos;
23862392 }
@@ -2564,7 +2570,7 @@ static void vt_console_print(struct console *co, const char *b, unsigned count) · 177 unmodified lines
25642570 goto quit;
25652571
25662572 /* undraw cursor first */
2567− if (IS_FG(vc))
2573+ if (con_is_fg(vc))
25682574 hide_cursor(vc);
25692575
25702576 start = (ushort *)vc->vc_pos;
@@ -2575,7 +2581,7 @@ static void vt_console_print(struct console *co, const char *b, unsigned count) · 4 unmodified lines
25752581 c = *b++;
25762582 if (c == 10 || c == 13 || c == 8 || vc->vc_need_wrap) {
25772583 if (cnt > 0) {
2578− if (CON_IS_VISIBLE(vc))
2584+ if (con_is_visible(vc))
25792585 vc->vc_sw->con_putcs(vc, start, cnt, vc->vc_y, vc->vc_x);
25802586 vc->vc_x += cnt;
25812587 if (vc->vc_need_wrap)
@@ -2607,7 +2613,7 @@ static void vt_console_print(struct console *co, const char *b, unsigned count) · 25 unmodified lines
26072613 myx++;
26082614 }
26092615 if (cnt > 0) {
2610− if (CON_IS_VISIBLE(vc))
2616+ if (con_is_visible(vc))
26112617 vc->vc_sw->con_putcs(vc, start, cnt, vc->vc_y, vc->vc_x);
26122618 vc->vc_x += cnt;
26132619 if (vc->vc_x == vc->vc_cols) {
@@ -3154,7 +3160,7 @@ static int do_bind_con_driver(const struct consw *csw, int first, int last, · 540 unmodified lines
31543160
31553161 j = i;
31563162
3157− if (CON_IS_VISIBLE(vc)) {
3163+ if (con_is_visible(vc)) {
31583164 k = i;
31593165 save_screen(vc);
31603166 }
drivers/usb/misc/sisusbvga/sisusb_con.c+2−2
@@ -570,7 +570,7 @@ sisusbcon_set_palette(struct vc_data *c, const unsigned char *table) · 569 unmodified lines
570570
571571 /* Return value not used by vt */
572572
573− if (!CON_IS_VISIBLE(c))
573+ if (!con_is_visible(c))
574574 return;
575575
576576 sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num);
@@ -1226,7 +1226,7 @@ sisusbcon_do_font_op(struct sisusb_usb_data *sisusb, int set, int slot, · 649 unmodified lines
12261226 struct vc_data *vc = vc_cons[i].d;
12271227
12281228 if (vc && vc->vc_sw == &sisusb_con) {
1229− if (CON_IS_VISIBLE(vc)) {
1229+ if (con_is_visible(vc)) {
12301230 vc->vc_sw->con_cursor(vc, CM_DRAW);
12311231 }
12321232 vc->vc_font.height = fh;
drivers/video/console/fbcon.c+13−13
@@ -380,7 +380,7 @@ static void fb_flashcursor(struct work_struct *work) · 379 unmodified lines
380380 if (ops && ops->currcon != -1)
381381 vc = vc_cons[ops->currcon].d;
382382
383− if (!vc || !CON_IS_VISIBLE(vc) ||
383+ if (!vc || !con_is_visible(vc) ||
384384 registered_fb[con2fb_map[vc->vc_num]] != info ||
385385 vc->vc_deccm != 1) {
386386 console_unlock();
@@ -618,7 +618,7 @@ static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info, · 231 unmodified lines
618618 erase,
619619 vc->vc_size_row * logo_lines);
620620
621− if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
621+ if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
622622 fbcon_clear_margins(vc, 0);
623623 update_screen(vc);
624624 }
@@ -1112,7 +1112,7 @@ static void fbcon_init(struct vc_data *vc, int init) · 487 unmodified lines
11121112 *
11131113 * We need to do it in fbcon_init() to prevent screen corruption.
11141114 */
1115− if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
1115+ if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
11161116 if (info->fbops->fb_set_par &&
11171117 !(ops->flags & FBCON_FLAGS_INIT)) {
11181118 ret = info->fbops->fb_set_par(info);
@@ -1192,7 +1192,7 @@ static void fbcon_deinit(struct vc_data *vc) · 73 unmodified lines
11921192 if (!ops)
11931193 goto finished;
11941194
1195− if (CON_IS_VISIBLE(vc))
1195+ if (con_is_visible(vc))
11961196 fbcon_del_cursor_timer(info);
11971197
11981198 ops->flags &= ~FBCON_FLAGS_INIT;
@@ -1397,7 +1397,7 @@ static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var, · 198 unmodified lines
13971397 rows /= vc->vc_font.height;
13981398 vc_resize(vc, cols, rows);
13991399
1400− if (CON_IS_VISIBLE(vc)) {
1400+ if (con_is_visible(vc)) {
14011401 update_screen(vc);
14021402 if (softback_buf)
14031403 fbcon_update_softback(vc);
@@ -2145,7 +2145,7 @@ static int fbcon_resize(struct vc_data *vc, unsigned int width, · 741 unmodified lines
21452145 return -EINVAL;
21462146
21472147 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2148− if (CON_IS_VISIBLE(vc)) {
2148+ if (con_is_visible(vc)) {
21492149 var.activate = FB_ACTIVATE_NOW |
21502150 FB_ACTIVATE_FORCE;
21512151 fb_set_var(info, &var);
@@ -2448,7 +2448,7 @@ static int fbcon_do_set_font(struct vc_data *vc, int w, int h, · 296 unmodified lines
24482448 int cnt;
24492449 char *old_data = NULL;
24502450
2451− if (CON_IS_VISIBLE(vc) && softback_lines)
2451+ if (con_is_visible(vc) && softback_lines)
24522452 fbcon_set_origin(vc);
24532453
24542454 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
@@ -2529,9 +2529,9 @@ static int fbcon_do_set_font(struct vc_data *vc, int w, int h, · 74 unmodified lines
25292529 cols /= w;
25302530 rows /= h;
25312531 vc_resize(vc, cols, rows);
2532− if (CON_IS_VISIBLE(vc) && softback_buf)
2532+ if (con_is_visible(vc) && softback_buf)
25332533 fbcon_update_softback(vc);
2534− } else if (CON_IS_VISIBLE(vc)
2534+ } else if (con_is_visible(vc)
25352535 && vc->vc_mode == KD_TEXT) {
25362536 fbcon_clear_margins(vc, 0);
25372537 update_screen(vc);
@@ -2660,7 +2660,7 @@ static void fbcon_set_palette(struct vc_data *vc, const unsigned char *table) · 122 unmodified lines
26602660 if (fbcon_is_inactive(vc, info))
26612661 return;
26622662
2663− if (!CON_IS_VISIBLE(vc))
2663+ if (!con_is_visible(vc))
26642664 return;
26652665
26662666 depth = fb_get_color_depth(&info->var, &info->fix);
@@ -2902,7 +2902,7 @@ static void fbcon_modechanged(struct fb_info *info) · 235 unmodified lines
29022902 p = &fb_display[vc->vc_num];
29032903 set_blitting_type(vc, info);
29042904
2905− if (CON_IS_VISIBLE(vc)) {
2905+ if (con_is_visible(vc)) {
29062906 var_to_display(p, &info->var, info);
29072907 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
29082908 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
@@ -2941,7 +2941,7 @@ static void fbcon_set_all_vcs(struct fb_info *info) · 32 unmodified lines
29412941 registered_fb[con2fb_map[i]] != info)
29422942 continue;
29432943
2944− if (CON_IS_VISIBLE(vc)) {
2944+ if (con_is_visible(vc)) {
29452945 fg = i;
29462946 continue;
29472947 }
@@ -3180,7 +3180,7 @@ static void fbcon_fb_blanked(struct fb_info *info, int blank) · 232 unmodified lines
31803180 registered_fb[con2fb_map[ops->currcon]] != info)
31813181 return;
31823182
3183− if (CON_IS_VISIBLE(vc)) {
3183+ if (con_is_visible(vc)) {
31843184 if (blank)
31853185 do_blank_screen(0);
31863186 else
drivers/video/console/vgacon.c+4−4
@@ -589,7 +589,7 @@ static void vgacon_init(struct vc_data *c, int init) · 588 unmodified lines
589589 static void vgacon_deinit(struct vc_data *c)
590590 {
591591 /* When closing the active console, reset video origin */
592− if (CON_IS_VISIBLE(c)) {
592+ if (con_is_visible(c)) {
593593 c->vc_visible_origin = vga_vram_base;
594594 vga_set_mem_top(c);
595595 }
@@ -860,7 +860,7 @@ static void vgacon_set_palette(struct vc_data *vc, const unsigned char *table) · 264 unmodified lines
860860 {
861861 #ifdef CAN_LOAD_PALETTE
862862 if (vga_video_type != VIDEO_TYPE_VGAC || vga_palette_blanked
863− || !CON_IS_VISIBLE(vc))
863+ || !con_is_visible(vc))
864864 return;
865865 vga_set_palette(vc, table);
866866 #endif
@@ -1248,7 +1248,7 @@ static int vgacon_adjust_height(struct vc_data *vc, unsigned fontheight) · 381 unmodified lines
12481248 struct vc_data *c = vc_cons[i].d;
12491249
12501250 if (c && c->vc_sw == &vga_con) {
1251− if (CON_IS_VISIBLE(c)) {
1251+ if (con_is_visible(c)) {
12521252 /* void size to cause regs to be rewritten */
12531253 cursor_size_lastfrom = 0;
12541254 cursor_size_lastto = 0;
@@ -1312,7 +1312,7 @@ static int vgacon_resize(struct vc_data *c, unsigned int width, · 57 unmodified lines
13121312 return success */
13131313 return (user) ? 0 : -EINVAL;
13141314
1315− if (CON_IS_VISIBLE(c) && !vga_is_gfx) /* who knows */
1315+ if (con_is_visible(c) && !vga_is_gfx) /* who knows */
13161316 vgacon_doresize(c, width, height);
13171317 return 0;
13181318 }
include/linux/console_struct.h+4−1
@@ -168,6 +168,9 @@ extern void vc_SAK(struct work_struct *work); · 167 unmodified lines
168168
169169 #define CUR_DEFAULT CUR_UNDERLINE
170170
171−#define CON_IS_VISIBLE(conp) (*conp->vc_display_fg == conp)
171+static inline bool con_is_visible(const struct vc_data *vc)
172+{
173+ return *vc->vc_display_fg == vc;
174+}
172175
173176 #endif /* _LINUX_CONSOLE_STRUCT_H */