CTC++ Coverage Report - Execution Profile    #819/1532

Files Summary | Functions Summary | Execution Profile | Index | No Index
First | Previous | Next | Last


File: drivers/video/console/fbcon.c
Instrumentation mode: function-decision-multicondition
TER: 25 % (317/1253)

Start/ End/    
True False - Line Source

  1 /*
  2  *  linux/drivers/video/fbcon.c -- Low level frame buffer based console driver
  3  *
  4  *   Copyright (C) 1995 Geert Uytterhoeven
  5  *
  6  *
  7  *  This file is based on the original Amiga console driver (amicon.c):
  8  *
  9  *   Copyright (C) 1993 Hamish Macdonald
  10  *            Greg Harp
  11  *   Copyright (C) 1994 David Carter [carter@compsci.bristol.ac.uk]
  12  *
  13  *         with work by William Rucklidge (wjr@cs.cornell.edu)
  14  *            Geert Uytterhoeven
  15  *            Jes Sorensen (jds@kom.auc.dk)
  16  *            Martin Apel
  17  *
  18  *  and on the original Atari console driver (atacon.c):
  19  *
  20  *   Copyright (C) 1993 Bjoern Brauel
  21  *            Roman Hodek
  22  *
  23  *         with work by Guenther Kelleter
  24  *            Martin Schaller
  25  *            Andreas Schwab
  26  *
  27  *  Hardware cursor support added by Emmanuel Marty (core@ggi-project.org)
  28  *  Smart redraw scrolling, arbitrary font width support, 512char font support
  29  *  and software scrollback added by 
  30  *                         Jakub Jelinek (jj@ultra.linux.cz)
  31  *
  32  *  Random hacking by Martin Mares <mj@ucw.cz>
  33  *
  34  *   2001 - Documented with DocBook
  35  *   - Brad Douglas <brad@neruo.com>
  36  *
  37  *  The low level operations for the various display memory organizations are
  38  *  now in separate source files.
  39  *
  40  *  Currently the following organizations are supported:
  41  *
  42  *    o afb         Amiga bitplanes
  43  *    o cfb{2,4,8,16,24,32}   Packed pixels
  44  *    o ilbm         Amiga interleaved bitplanes
  45  *    o iplan2p[248]      Atari interleaved bitplanes
  46  *    o mfb         Monochrome
  47  *    o vga         VGA characters/attributes
  48  *
  49  *  To do:
  50  *
  51  *    - Implement 16 plane mode (iplan2p16)
  52  *
  53  *
  54  *  This file is subject to the terms and conditions of the GNU General Public
  55  *  License.  See the file COPYING in the main directory of this archive for
  56  *  more details.
  57  */
  58 
  59 #undef FBCONDEBUG
  60 
  61 #include <linux/config.h>
  62 #include <linux/module.h>
  63 #include <linux/types.h>
  64 #include <linux/sched.h>
  65 #include <linux/fs.h>
  66 #include <linux/kernel.h>
  67 #include <linux/delay.h>   /* MSch: for IRQ probe */
  68 #include <linux/tty.h>
  69 #include <linux/console.h>
  70 #include <linux/string.h>
  71 #include <linux/kd.h>
  72 #include <linux/slab.h>
  73 #include <linux/fb.h>
  74 #include <linux/vt_kern.h>
  75 #include <linux/selection.h>
  76 #include <linux/font.h>
  77 #include <linux/smp.h>
  78 #include <linux/init.h>
  79 #include <linux/interrupt.h>
  80 #include <linux/crc32.h> /* For counting font checksums */
  81 #include <asm/irq.h>
  82 #include <asm/system.h>
  83 #include <asm/uaccess.h>
  84 #ifdef CONFIG_ATARI
  85 #include <asm/atariints.h>
  86 #endif
  87 #ifdef CONFIG_MAC
  88 #include <asm/macints.h>
  89 #endif
  90 #if defined(__mc68000__) || defined(CONFIG_APUS)
  91 #include <asm/machdep.h>
  92 #include <asm/setup.h>
  93 #endif
  94 
  95 #include "fbcon.h"
  96 
  97 #ifdef FBCONDEBUG
  98 #  define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __FUNCTION__ , ## args)
  99 #else
  100 #  define DPRINTK(fmt, args...)
  101 #endif
  102 
  103 enum {
  104    FBCON_LOGO_CANSHOW   = -1,   /* the logo can be shown */
  105    FBCON_LOGO_DRAW      = -2,   /* draw the logo to a console */
  106    FBCON_LOGO_DONTSHOW   = -3   /* do not show the logo */
  107 };
  108 
  109 static struct display fb_display[MAX_NR_CONSOLES];
  110 
  111 static signed char con2fb_map[MAX_NR_CONSOLES];
  112 static signed char con2fb_map_boot[MAX_NR_CONSOLES];
  113 static int logo_height;
  114 static int logo_lines;
  115 /* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
  116    enums.  */
  117 static int logo_shown = FBCON_LOGO_CANSHOW;
  118 /* Software scrollback */
  119 static int fbcon_softback_size = 32768;
  120 static unsigned long softback_buf, softback_curr;
  121 static unsigned long softback_in;
  122 static unsigned long softback_top, softback_end;
  123 static int softback_lines;
  124 /* console mappings */
  125 static int first_fb_vc;
  126 static int last_fb_vc = MAX_NR_CONSOLES - 1;
  127 static int fbcon_is_default = 1; 
  128 /* font data */
  129 static char fontname[40];
  130 
  131 /* current fb_info */
  132 static int info_idx = -1;
  133 
  134 /* console rotation */
  135 static int rotate;
  136 
  137 static const struct consw fb_con;
  138 
  139 #define CM_SOFTBACK   (8)
  140 
  141 #define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
  142 
  143 static void fbcon_free_font(struct display *);
  144 static int fbcon_set_origin(struct vc_data *);
  145 
  146 #define CURSOR_DRAW_DELAY      (1)
  147 
  148 /* # VBL ints between cursor state changes */
  149 #define ATARI_CURSOR_BLINK_RATE      (42)
  150 #define MAC_CURSOR_BLINK_RATE      (32)
  151 #define DEFAULT_CURSOR_BLINK_RATE   (20)
  152 
  153 static int vbl_cursor_cnt;
  154 
  155 #define divides(a, b)   ((!(a) || (b)%(a)) ? 0 : 1)
  156 
  157 /*
  158  *  Interface used by the world
  159  */
  160 
  161 static const char *fbcon_startup(void);
  162 static void fbcon_init(struct vc_data *vc, int init);
  163 static void fbcon_deinit(struct vc_data *vc);
  164 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
  165          int width);
  166 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos);
  167 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
  168          int count, int ypos, int xpos);
  169 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only);
  170 static void fbcon_cursor(struct vc_data *vc, int mode);
  171 static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
  172          int count);
  173 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
  174          int height, int width);
  175 static int fbcon_switch(struct vc_data *vc);
  176 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch);
  177 static int fbcon_set_palette(struct vc_data *vc, unsigned char *table);
  178 static int fbcon_scrolldelta(struct vc_data *vc, int lines);
  179 
  180 /*
  181  *  Internal routines
  182  */
  183 static __inline__ void ywrap_up(struct vc_data *vc, int count);
  184 static __inline__ void ywrap_down(struct vc_data *vc, int count);
  185 static __inline__ void ypan_up(struct vc_data *vc, int count);
  186 static __inline__ void ypan_down(struct vc_data *vc, int count);
  187 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
  188              int dy, int dx, int height, int width, u_int y_break);
  189 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
  190             struct vc_data *vc);
  191 static void fbcon_preset_disp(struct fb_info *info, struct fb_var_screeninfo *var,
  192                int unit);
  193 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
  194                int line, int count, int dy);
  195 static void fbcon_modechanged(struct fb_info *info);
  196 static void fbcon_set_all_vcs(struct fb_info *info);
  197 
  198 #ifdef CONFIG_MAC
  199 /*
  200  * On the Macintoy, there may or may not be a working VBL int. We need to probe
  201  */
  202 static int vbl_detected;
  203 
  204 static irqreturn_t fb_vbl_detect(int irq, void *dummy, struct pt_regs *fp)
  205 {
  206    vbl_detected++;
  207    return IRQ_HANDLED;
  208 }
  209 #endif
  210 
  211 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
  212 static inline void fbcon_set_rotation(struct fb_info *info)
  213 {
  214    struct fbcon_ops *ops = info->fbcon_par;
  215 
  216    if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
  217        ops->p->con_rotate < 4)
  218       ops->rotate = ops->p->con_rotate;
  219    else
  220       ops->rotate = 0;
  221 }
  222 
  223 static void fbcon_rotate(struct fb_info *info, u32 rotate)
  224 {
  225    struct fbcon_ops *ops= info->fbcon_par;
  226    struct fb_info *fb_info;
  227 
  228    if (!ops || ops->currcon == -1)
  229       return;
  230 
  231    fb_info = registered_fb[con2fb_map[ops->currcon]];
  232 
  233    if (info == fb_info) {
  234       struct display *p = &fb_display[ops->currcon];
  235 
  236       if (rotate < 4)
  237          p->con_rotate = rotate;
  238       else
  239          p->con_rotate = 0;
  240 
  241       fbcon_modechanged(info);
  242    }
  243 }
  244 
  245 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
  246 {
  247    struct fbcon_ops *ops = info->fbcon_par;
  248    struct vc_data *vc;
  249    struct display *p;
  250    int i;
  251 
  252    if (!ops || ops->currcon < 0 || rotate > 3)
  253       return;
  254 
  255    for (i = 0; i < MAX_NR_CONSOLES; i++) {
  256       vc = vc_cons[i].d;
  257       if (!vc || vc->vc_mode != KD_TEXT ||
  258           registered_fb[con2fb_map[i]] != info)
  259          continue;
  260 
  261       p = &fb_display[vc->vc_num];
  262       p->con_rotate = rotate;
  263    }
  264 
  265    fbcon_set_all_vcs(info);
  266 }
  267 #else
 
137 137   268 static inline void fbcon_set_rotation(struct fb_info *info)
  269 {
  270    struct fbcon_ops *ops = info->fbcon_par;
  271 
  272    ops->rotate = FB_ROTATE_UR;
  273 }
  274 
 
- 275 static void fbcon_rotate(struct fb_info *info, u32 rotate)
  276 {
 - 277    return;
  278 }
  279 
 
- 280 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
  281 {
 - 282    return;
  283 }
  284 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
  285 
 
- 286 static int fbcon_get_rotate(struct fb_info *info)
  287 {
  288    struct fbcon_ops *ops = info->fbcon_par;
  289 
    290    return (ops) ? ops->rotate : 0;
- 290 ternary-?: ( ops )
 - 290 return ( ops ) ? ops -> rotate : 0
  291 }
  292 
 
297379   293 static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
  294 {
  295    struct fbcon_ops *ops = info->fbcon_par;
  296 
  297    return (info->state != FBINFO_STATE_RUNNING ||
297379    298       vc->vc_mode != KD_TEXT || ops->graphics);
  299 }
  300 
 
581484   301 static inline int get_color(struct vc_data *vc, struct fb_info *info,
  302          u16 c, int is_fg)
  303 {
  304    int depth = fb_get_color_depth(&info->var, &info->fix);
  305    int color = 0;
  306 
581484 - 307    if (console_blanked) {
    308       unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
- 308   ternary-?: vc -> vc_hi_font_mask
  309 
  310       c = vc->vc_video_erase_char & charmask;
  311    }
  312 
581484 - 313    if (depth != 1)
    314       color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
290742 290742   314   ternary-?: ( is_fg )
290742 - 314   ternary-?: ( vc -> vc_hi_font_mask )
    315          : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
290742 - 315   ternary-?: ( vc -> vc_hi_font_mask )
  316 
    317    switch (depth) {
 - 318    case 1:
  319    {
  320       int col = ~(0xfff << (max(info->var.green.length,
  321                  max(info->var.red.length,
  322                      info->var.blue.length)))) & 0xff;
  323 
  324       /* 0 or 1 */
    325       int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
- 325     ternary-?: ( info -> fix . visual != 0 )
    326       int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
- 326     ternary-?: ( info -> fix . visual != 0 )
  327 
- 328       if (console_blanked)
  329          fg = bg;
  330 
    331       color = (is_fg) ? fg : bg;
- 331     ternary-?: ( is_fg )
 - 332       break;
  333    }
 - 334    case 2:
  335       /*
  336        * Scale down 16-colors to 4 colors. Default 4-color palette
  337        * is grayscale. However, simply dividing the values by 4
  338        * will not work, as colors 1, 2 and 3 will be scaled-down
  339        * to zero rendering them invisible.  So empirically convert
  340        * colors to a sane 4-level grayscale.
  341        */
    342       switch (color) {
 - 343       case 0:
  344          color = 0; /* black */
 - 345          break;
 - 346       case 1 ... 6:
  347          color = 2; /* white */
 - 348          break;
 - 349       case 7 ... 8:
  350          color = 1; /* gray */
 - 351          break;
 - 352       default:
  353          color = 3; /* intense white */
 - 354          break;
  355       }
 - 356       break;
 - 357    case 3:
  358       /*
  359        * Last 8 entries of default 16-color palette is a more intense
  360        * version of the first 8 (i.e., same chrominance, different
  361        * luminance).
  362        */
  363       color &= 7;
 - 364       break;
  365    }
  366 
  367 
581484    368    return color;
  369 }
  370 
 
70 70   371 static void fbcon_update_softback(struct vc_data *vc)
  372 {
  373    int l = fbcon_softback_size / vc->vc_size_row;
  374 
70 - 375    if (l > 5)
  376       softback_end = softback_buf + l * vc->vc_size_row;
    377    else
  378       /* Smaller scrollback makes no sense, and 0 would screw
  379          the operation totally */
  380       softback_top = 0;
  381 }
  382 
 
5942 5942   383 static void fb_flashcursor(void *private)
  384 {
  385    struct fb_info *info = private;
  386    struct fbcon_ops *ops = info->fbcon_par;
  387    struct display *p;
  388    struct vc_data *vc = NULL;
  389    int c;
  390    int mode;
  391 
5942 - 392    if (ops->currcon != -1)
  393       vc = vc_cons[ops->currcon].d;
  394 
  395    if (!vc || !CON_IS_VISIBLE(vc) ||
  396        fbcon_is_inactive(vc, info) ||
  397         registered_fb[con2fb_map[vc->vc_num]] != info ||
5942 - 398        vc_cons[ops->currcon].d->vc_deccm != 1)
 - 398   T || !(_) || _ || _ || _
 - 398   F || !(T) || T || _ || _
 - 398   F || !(T) || F || T || _
 - 398   F || !(T) || F || F || T
 - 398   F || !(F) || _ || _ || _
 5942   398   F || !(T) || F || F || F
 - 399       return;
  400    acquire_console_sem();
  401    p = &fb_display[vc->vc_num];
  402    c = scr_readw((u16 *) vc->vc_pos);
    403    mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
3281 2661   403 ternary-?: ( ! ops -> cursor_flash || ops -> c..
  404       CM_ERASE : CM_DRAW;
  405    ops->cursor(vc, info, mode, softback_lines, get_color(vc, info, c, 1),
  406           get_color(vc, info, c, 0));
  407    release_console_sem();
  408 }
  409 
  410 #if defined(CONFIG_ATARI) || defined(CONFIG_MAC)
  411 static int cursor_blink_rate;
  412 static irqreturn_t fb_vbl_handler(int irq, void *dev_id, struct pt_regs *fp)
  413 {
  414    struct fb_info *info = dev_id;
  415 
  416    if (vbl_cursor_cnt && --vbl_cursor_cnt == 0) {
  417       schedule_work(&info->queue);   
  418       vbl_cursor_cnt = cursor_blink_rate; 
  419    }
  420    return IRQ_HANDLED;
  421 }
  422 #endif
  423    
 
5942 5942   424 static void cursor_timer_handler(unsigned long dev_addr)
  425 {
  426    struct fb_info *info = (struct fb_info *) dev_addr;
  427    struct fbcon_ops *ops = info->fbcon_par;
  428 
  429    schedule_work(&info->queue);
  430    mod_timer(&ops->cursor_timer, jiffies + HZ/5);
  431 }
  432 
 
20 20   433 static void fbcon_add_cursor_timer(struct fb_info *info)
  434 {
  435    struct fbcon_ops *ops = info->fbcon_par;
  436 
  437    if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
20 - 438        !(ops->flags & FBCON_FLAGS_CURSOR_TIMER)) {
   438   (T || _) && !(F)
14    438   (F || T) && !(F)
 - 438   (T || _) && !(T)
 - 438   (F || T) && !(T)
 - 438   (F || F) && !(_)
14   439       if (!info->queue.func)
    440          INIT_WORK(&info->queue, fb_flashcursor, info);
    440       do
- 440       do-while (0)
- 440     do-while (0)
  441 
  442       init_timer(&ops->cursor_timer);
  443       ops->cursor_timer.function = cursor_timer_handler;
  444       ops->cursor_timer.expires = jiffies + HZ / 5;
  445       ops->cursor_timer.data = (unsigned long ) info;
  446       add_timer(&ops->cursor_timer);
  447       ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
  448    }
  449 }
  450 
 
18 18   451 static void fbcon_del_cursor_timer(struct fb_info *info)
  452 {
  453    struct fbcon_ops *ops = info->fbcon_par;
  454 
  455    if (info->queue.func == fb_flashcursor &&
18 - 456        ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
18    456   T && T
 - 456   T && F
 - 456   F && _
  457       del_timer_sync(&ops->cursor_timer);
  458       ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
  459    }
  460 }
  461 
  462 #ifndef MODULE
 
- 463 static int __init fb_console_setup(char *this_opt)
  464 {
  465    char *options;
  466    int i, j;
  467 
- 468    if (!this_opt || !*this_opt)
 - 468   T || _
 - 468   F || T
 - 468   F || F
 - 469       return 0;
  470 
- 471    while ((options = strsep(&this_opt, ",")) != NULL) {
- 472       if (!strncmp(options, "font:", 5))
  473          strcpy(fontname, options + 5);
  474       
- 475       if (!strncmp(options, "scrollback:", 11)) {
  476          options += 11;
- 477          if (*options) {
  478             fbcon_softback_size = simple_strtoul(options, &options, 0);
- 479             if (*options == 'k' || *options == 'K') {
 - 479         T || _
 - 479         F || T
 - 479         F || F
  480                fbcon_softback_size *= 1024;
  481                options++;
  482             }
- 483             if (*options != ',')
 - 484                return 0;
  485             options++;
    486          } else
 - 487             return 0;
  488       }
  489       
- 490       if (!strncmp(options, "map:", 4)) {
  491          options += 4;
- 492          if (*options)
- 493             for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
- 494                if (!options[j])
  495                   j = 0;
  496                con2fb_map_boot[i] =
  497                   (options[j++]-'0') % FB_MAX;
  498             }
 - 499          return 0;
  500       }
  501 
- 502       if (!strncmp(options, "vc:", 3)) {
  503          options += 3;
- 504          if (*options)
  505             first_fb_vc = simple_strtoul(options, &options, 10) - 1;
- 506          if (first_fb_vc < 0)
  507             first_fb_vc = 0;
- 508          if (*options++ == '-')
  509             last_fb_vc = simple_strtoul(options, &options, 10) - 1;
  510          fbcon_is_default = 0; 
  511       }   
  512 
- 513       if (!strncmp(options, "rotate:", 7)) {
  514          options += 7;
- 515          if (*options)
  516             rotate = simple_strtoul(options, &options, 0);
- 517          if (rotate > 3)
  518             rotate = 0;
  519       }
  520