LCOV - code coverage report
Current view: top level - drivers/video/fbdev/core - bitblit.c (source / functions) Hit Total Coverage
Test: gcov_data_raspi2_real_modules_combined.info Lines: 154 231 66.7 %
Date: 2020-09-30 20:25:40 Functions: 6 10 60.0 %
Branches: 54 112 48.2 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  *  linux/drivers/video/console/bitblit.c -- BitBlitting Operation
       3                 :            :  *
       4                 :            :  *  Originally from the 'accel_*' routines in drivers/video/console/fbcon.c
       5                 :            :  *
       6                 :            :  *      Copyright (C) 2004 Antonino Daplas <adaplas @pol.net>
       7                 :            :  *
       8                 :            :  *  This file is subject to the terms and conditions of the GNU General Public
       9                 :            :  *  License.  See the file COPYING in the main directory of this archive for
      10                 :            :  *  more details.
      11                 :            :  */
      12                 :            : 
      13                 :            : #include <linux/module.h>
      14                 :            : #include <linux/slab.h>
      15                 :            : #include <linux/string.h>
      16                 :            : #include <linux/fb.h>
      17                 :            : #include <linux/vt_kern.h>
      18                 :            : #include <linux/console.h>
      19                 :            : #include <asm/types.h>
      20                 :            : #include "fbcon.h"
      21                 :            : 
      22                 :            : /*
      23                 :            :  * Accelerated handlers.
      24                 :            :  */
      25                 :          0 : static void update_attr(u8 *dst, u8 *src, int attribute,
      26                 :            :                                struct vc_data *vc)
      27                 :            : {
      28         [ #  # ]:          0 :         int i, offset = (vc->vc_font.height < 10) ? 1 : 2;
      29                 :          0 :         int width = DIV_ROUND_UP(vc->vc_font.width, 8);
      30                 :          0 :         unsigned int cellsize = vc->vc_font.height * width;
      31                 :            :         u8 c;
      32                 :            : 
      33                 :          0 :         offset = cellsize - (offset * width);
      34         [ #  # ]:          0 :         for (i = 0; i < cellsize; i++) {
      35                 :          0 :                 c = src[i];
      36   [ #  #  #  # ]:          0 :                 if (attribute & FBCON_ATTRIBUTE_UNDERLINE && i >= offset)
      37                 :            :                         c = 0xff;
      38         [ #  # ]:          0 :                 if (attribute & FBCON_ATTRIBUTE_BOLD)
      39                 :          0 :                         c |= c >> 1;
      40         [ #  # ]:          0 :                 if (attribute & FBCON_ATTRIBUTE_REVERSE)
      41                 :          0 :                         c = ~c;
      42                 :          0 :                 dst[i] = c;
      43                 :            :         }
      44                 :          0 : }
      45                 :            : 
      46                 :          0 : static void bit_bmove(struct vc_data *vc, struct fb_info *info, int sy,
      47                 :            :                       int sx, int dy, int dx, int height, int width)
      48                 :            : {
      49                 :            :         struct fb_copyarea area;
      50                 :            : 
      51                 :          0 :         area.sx = sx * vc->vc_font.width;
      52                 :          0 :         area.sy = sy * vc->vc_font.height;
      53                 :          0 :         area.dx = dx * vc->vc_font.width;
      54                 :          0 :         area.dy = dy * vc->vc_font.height;
      55                 :          0 :         area.height = height * vc->vc_font.height;
      56                 :          0 :         area.width = width * vc->vc_font.width;
      57                 :            : 
      58                 :          0 :         info->fbops->fb_copyarea(info, &area);
      59                 :          0 : }
      60                 :            : 
      61                 :          0 : static void bit_clear(struct vc_data *vc, struct fb_info *info, int sy,
      62                 :            :                       int sx, int height, int width)
      63                 :            : {
      64         [ #  # ]:          0 :         int bgshift = (vc->vc_hi_font_mask) ? 13 : 12;
      65                 :            :         struct fb_fillrect region;
      66                 :            : 
      67                 :          0 :         region.color = attr_bgcol_ec(bgshift, vc, info);
      68                 :          0 :         region.dx = sx * vc->vc_font.width;
      69                 :          0 :         region.dy = sy * vc->vc_font.height;
      70                 :          0 :         region.width = width * vc->vc_font.width;
      71                 :          0 :         region.height = height * vc->vc_font.height;
      72                 :          0 :         region.rop = ROP_COPY;
      73                 :            : 
      74                 :          0 :         info->fbops->fb_fillrect(info, &region);
      75                 :          0 : }
      76                 :            : 
      77                 :      41607 : static inline void bit_putcs_aligned(struct vc_data *vc, struct fb_info *info,
      78                 :            :                                      const u16 *s, u32 attr, u32 cnt,
      79                 :            :                                      u32 d_pitch, u32 s_pitch, u32 cellsize,
      80                 :            :                                      struct fb_image *image, u8 *buf, u8 *dst)
      81                 :            : {
      82         [ +  - ]:      41607 :         u16 charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
      83                 :      41607 :         u32 idx = vc->vc_font.width >> 3;
      84                 :            :         u8 *src;
      85                 :            : 
      86         [ +  + ]:   10068894 :         while (cnt--) {
      87                 :    9985680 :                 src = vc->vc_font.data + (scr_readw(s++)&
      88                 :            :                                           charmask)*cellsize;
      89                 :            : 
      90         [ -  + ]:    9985680 :                 if (attr) {
      91                 :          0 :                         update_attr(buf, src, attr, vc);
      92                 :            :                         src = buf;
      93                 :            :                 }
      94                 :            : 
      95         [ +  - ]:    9985680 :                 if (likely(idx == 1))
      96                 :    9985680 :                         __fb_pad_aligned_buffer(dst, d_pitch, src, idx,
      97                 :            :                                                 image->height);
      98                 :            :                 else
      99                 :          0 :                         fb_pad_aligned_buffer(dst, d_pitch, src, idx,
     100                 :            :                                               image->height);
     101                 :            : 
     102                 :    9985680 :                 dst += s_pitch;
     103                 :            :         }
     104                 :            : 
     105                 :      41607 :         info->fbops->fb_imageblit(info, image);
     106                 :      41607 : }
     107                 :            : 
     108                 :          0 : static inline void bit_putcs_unaligned(struct vc_data *vc,
     109                 :            :                                        struct fb_info *info, const u16 *s,
     110                 :            :                                        u32 attr, u32 cnt, u32 d_pitch,
     111                 :            :                                        u32 s_pitch, u32 cellsize,
     112                 :            :                                        struct fb_image *image, u8 *buf,
     113                 :            :                                        u8 *dst)
     114                 :            : {
     115         [ #  # ]:          0 :         u16 charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
     116                 :          0 :         u32 shift_low = 0, mod = vc->vc_font.width % 8;
     117                 :            :         u32 shift_high = 8;
     118                 :          0 :         u32 idx = vc->vc_font.width >> 3;
     119                 :            :         u8 *src;
     120                 :            : 
     121         [ #  # ]:          0 :         while (cnt--) {
     122                 :          0 :                 src = vc->vc_font.data + (scr_readw(s++)&
     123                 :            :                                           charmask)*cellsize;
     124                 :            : 
     125         [ #  # ]:          0 :                 if (attr) {
     126                 :          0 :                         update_attr(buf, src, attr, vc);
     127                 :            :                         src = buf;
     128                 :            :                 }
     129                 :            : 
     130                 :          0 :                 fb_pad_unaligned_buffer(dst, d_pitch, src, idx,
     131                 :            :                                         image->height, shift_high,
     132                 :            :                                         shift_low, mod);
     133                 :          0 :                 shift_low += mod;
     134         [ #  # ]:          0 :                 dst += (shift_low >= 8) ? s_pitch : s_pitch - 1;
     135                 :          0 :                 shift_low &= 7;
     136                 :          0 :                 shift_high = 8 - shift_low;
     137                 :            :         }
     138                 :            : 
     139                 :          0 :         info->fbops->fb_imageblit(info, image);
     140                 :            : 
     141                 :          0 : }
     142                 :            : 
     143                 :      41607 : static void bit_putcs(struct vc_data *vc, struct fb_info *info,
     144                 :            :                       const unsigned short *s, int count, int yy, int xx,
     145                 :            :                       int fg, int bg)
     146                 :            : {
     147                 :            :         struct fb_image image;
     148                 :      41607 :         u32 width = DIV_ROUND_UP(vc->vc_font.width, 8);
     149                 :      41607 :         u32 cellsize = width * vc->vc_font.height;
     150                 :      41607 :         u32 maxcnt = info->pixmap.size/cellsize;
     151                 :      41607 :         u32 scan_align = info->pixmap.scan_align - 1;
     152                 :      41607 :         u32 buf_align = info->pixmap.buf_align - 1;
     153                 :      41607 :         u32 mod = vc->vc_font.width % 8, cnt, pitch, size;
     154                 :      41607 :         u32 attribute = get_attribute(info, scr_readw(s));
     155                 :            :         u8 *dst, *buf = NULL;
     156                 :            : 
     157                 :      41607 :         image.fg_color = fg;
     158                 :      41607 :         image.bg_color = bg;
     159                 :      41607 :         image.dx = xx * vc->vc_font.width;
     160                 :      41607 :         image.dy = yy * vc->vc_font.height;
     161                 :      41607 :         image.height = vc->vc_font.height;
     162                 :      41607 :         image.depth = 1;
     163                 :            : 
     164         [ -  + ]:      41607 :         if (attribute) {
     165                 :            :                 buf = kmalloc(cellsize, GFP_ATOMIC);
     166         [ #  # ]:          0 :                 if (!buf)
     167                 :          0 :                         return;
     168                 :            :         }
     169                 :            : 
     170         [ +  + ]:      83214 :         while (count) {
     171         [ +  - ]:      41607 :                 if (count > maxcnt)
     172                 :            :                         cnt = maxcnt;
     173                 :            :                 else
     174                 :            :                         cnt = count;
     175                 :            : 
     176                 :      41607 :                 image.width = vc->vc_font.width * cnt;
     177                 :      41607 :                 pitch = DIV_ROUND_UP(image.width, 8) + scan_align;
     178                 :      41607 :                 pitch &= ~scan_align;
     179                 :      41607 :                 size = pitch * image.height + buf_align;
     180                 :      41607 :                 size &= ~buf_align;
     181                 :      41607 :                 dst = fb_get_buffer_offset(info, &info->pixmap, size);
     182                 :      41607 :                 image.data = dst;
     183                 :            : 
     184         [ +  - ]:      41607 :                 if (!mod)
     185                 :      41607 :                         bit_putcs_aligned(vc, info, s, attribute, cnt, pitch,
     186                 :            :                                           width, cellsize, &image, buf, dst);
     187                 :            :                 else
     188                 :          0 :                         bit_putcs_unaligned(vc, info, s, attribute, cnt,
     189                 :            :                                             pitch, width, cellsize, &image,
     190                 :            :                                             buf, dst);
     191                 :            : 
     192                 :      41607 :                 image.dx += cnt * vc->vc_font.width;
     193                 :      41607 :                 count -= cnt;
     194                 :      41607 :                 s += cnt;
     195                 :            :         }
     196                 :            : 
     197                 :            :         /* buf is always NULL except when in monochrome mode, so in this case
     198                 :            :            it's a gain to check buf against NULL even though kfree() handles
     199                 :            :            NULL pointers just fine */
     200         [ -  + ]:      41607 :         if (unlikely(buf))
     201                 :          0 :                 kfree(buf);
     202                 :            : 
     203                 :            : }
     204                 :            : 
     205                 :        621 : static void bit_clear_margins(struct vc_data *vc, struct fb_info *info,
     206                 :            :                               int color, int bottom_only)
     207                 :            : {
     208                 :        621 :         unsigned int cw = vc->vc_font.width;
     209                 :        621 :         unsigned int ch = vc->vc_font.height;
     210                 :        621 :         unsigned int rw = info->var.xres - (vc->vc_cols*cw);
     211                 :        621 :         unsigned int bh = info->var.yres - (vc->vc_rows*ch);
     212                 :        621 :         unsigned int rs = info->var.xres - rw;
     213                 :        621 :         unsigned int bs = info->var.yres - bh;
     214                 :            :         struct fb_fillrect region;
     215                 :            : 
     216                 :        621 :         region.color = color;
     217                 :        621 :         region.rop = ROP_COPY;
     218                 :            : 
     219         [ -  + ]:        621 :         if ((int) rw > 0 && !bottom_only) {
     220                 :          0 :                 region.dx = info->var.xoffset + rs;
     221                 :          0 :                 region.dy = 0;
     222                 :          0 :                 region.width = rw;
     223                 :          0 :                 region.height = info->var.yres_virtual;
     224                 :          0 :                 info->fbops->fb_fillrect(info, &region);
     225                 :            :         }
     226                 :            : 
     227         [ +  - ]:        621 :         if ((int) bh > 0) {
     228                 :        621 :                 region.dx = info->var.xoffset;
     229                 :        621 :                 region.dy = info->var.yoffset + bs;
     230                 :        621 :                 region.width = rs;
     231                 :        621 :                 region.height = bh;
     232                 :        621 :                 info->fbops->fb_fillrect(info, &region);
     233                 :            :         }
     234                 :        621 : }
     235                 :            : 
     236                 :      12255 : static void bit_cursor(struct vc_data *vc, struct fb_info *info, int mode,
     237                 :            :                        int softback_lines, int fg, int bg)
     238                 :            : {
     239                 :            :         struct fb_cursor cursor;
     240                 :      12255 :         struct fbcon_ops *ops = info->fbcon_par;
     241         [ +  - ]:      12255 :         unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
     242                 :      12255 :         int w = DIV_ROUND_UP(vc->vc_font.width, 8), c;
     243                 :      12255 :         int y = real_y(ops->p, vc->vc_y);
     244                 :      12255 :         int attribute, use_sw = (vc->vc_cursor_type & 0x10);
     245                 :            :         int err = 1;
     246                 :            :         char *src;
     247                 :            : 
     248                 :      12255 :         cursor.set = 0;
     249                 :            : 
     250         [ -  + ]:      12255 :         if (softback_lines) {
     251         [ #  # ]:          0 :                 if (y + softback_lines >= vc->vc_rows) {
     252                 :            :                         mode = CM_ERASE;
     253                 :          0 :                         ops->cursor_flash = 0;
     254                 :          0 :                         return;
     255                 :            :                 } else
     256                 :            :                         y += softback_lines;
     257                 :            :         }
     258                 :            : 
     259                 :      12255 :         c = scr_readw((u16 *) vc->vc_pos);
     260                 :      12255 :         attribute = get_attribute(info, c);
     261                 :      12255 :         src = vc->vc_font.data + ((c & charmask) * (w * vc->vc_font.height));
     262                 :            : 
     263   [ +  +  +  + ]:      24303 :         if (ops->cursor_state.image.data != src ||
     264                 :      12048 :             ops->cursor_reset) {
     265                 :        828 :             ops->cursor_state.image.data = src;
     266                 :        828 :             cursor.set |= FB_CUR_SETIMAGE;
     267                 :            :         }
     268                 :            : 
     269         [ -  + ]:      12255 :         if (attribute) {
     270                 :            :                 u8 *dst;
     271                 :            : 
     272                 :          0 :                 dst = kmalloc_array(w, vc->vc_font.height, GFP_ATOMIC);
     273         [ #  # ]:          0 :                 if (!dst)
     274                 :            :                         return;
     275                 :          0 :                 kfree(ops->cursor_data);
     276                 :          0 :                 ops->cursor_data = dst;
     277                 :          0 :                 update_attr(dst, src, attribute, vc);
     278                 :            :                 src = dst;
     279                 :            :         }
     280                 :            : 
     281   [ +  +  +  - ]:      24295 :         if (ops->cursor_state.image.fg_color != fg ||
     282         [ +  + ]:      24080 :             ops->cursor_state.image.bg_color != bg ||
     283                 :      12040 :             ops->cursor_reset) {
     284                 :        836 :                 ops->cursor_state.image.fg_color = fg;
     285                 :        836 :                 ops->cursor_state.image.bg_color = bg;
     286                 :        836 :                 cursor.set |= FB_CUR_SETCMAP;
     287                 :            :         }
     288                 :            : 
     289   [ +  -  +  - ]:      24510 :         if ((ops->cursor_state.image.dx != (vc->vc_font.width * vc->vc_x)) ||
     290         [ +  + ]:      24510 :             (ops->cursor_state.image.dy != (vc->vc_font.height * y)) ||
     291                 :      12255 :             ops->cursor_reset) {
     292                 :        621 :                 ops->cursor_state.image.dx = vc->vc_font.width * vc->vc_x;
     293                 :        621 :                 ops->cursor_state.image.dy = vc->vc_font.height * y;
     294                 :        621 :                 cursor.set |= FB_CUR_SETPOS;
     295                 :            :         }
     296                 :            : 
     297   [ +  +  +  - ]:      24303 :         if (ops->cursor_state.image.height != vc->vc_font.height ||
     298         [ +  + ]:      24096 :             ops->cursor_state.image.width != vc->vc_font.width ||
     299                 :      12048 :             ops->cursor_reset) {
     300                 :        828 :                 ops->cursor_state.image.height = vc->vc_font.height;
     301                 :        828 :                 ops->cursor_state.image.width = vc->vc_font.width;
     302                 :        828 :                 cursor.set |= FB_CUR_SETSIZE;
     303                 :            :         }
     304                 :            : 
     305   [ +  -  +  + ]:      24510 :         if (ops->cursor_state.hot.x || ops->cursor_state.hot.y ||
     306                 :      12255 :             ops->cursor_reset) {
     307                 :        621 :                 ops->cursor_state.hot.x = cursor.hot.y = 0;
     308                 :        621 :                 cursor.set |= FB_CUR_SETHOT;
     309                 :            :         }
     310                 :            : 
     311   [ +  +  +  - ]:      23682 :         if (cursor.set & FB_CUR_SETSIZE ||
     312         [ +  - ]:      22854 :             vc->vc_cursor_type != ops->p->cursor_shape ||
     313         [ -  + ]:      22854 :             ops->cursor_state.mask == NULL ||
     314                 :      11427 :             ops->cursor_reset) {
     315                 :        828 :                 char *mask = kmalloc_array(w, vc->vc_font.height, GFP_ATOMIC);
     316                 :            :                 int cur_height, size, i = 0;
     317                 :            :                 u8 msk = 0xff;
     318                 :            : 
     319         [ +  - ]:        828 :                 if (!mask)
     320                 :            :                         return;
     321                 :            : 
     322                 :        828 :                 kfree(ops->cursor_state.mask);
     323                 :        828 :                 ops->cursor_state.mask = mask;
     324                 :            : 
     325                 :        828 :                 ops->p->cursor_shape = vc->vc_cursor_type;
     326                 :        828 :                 cursor.set |= FB_CUR_SETSHAPE;
     327                 :            : 
     328   [ +  -  -  -  :        828 :                 switch (ops->p->cursor_shape & CUR_HWMASK) {
                   -  - ]
     329                 :            :                 case CUR_NONE:
     330                 :            :                         cur_height = 0;
     331                 :            :                         break;
     332                 :            :                 case CUR_UNDERLINE:
     333         [ +  - ]:        828 :                         cur_height = (vc->vc_font.height < 10) ? 1 : 2;
     334                 :        828 :                         break;
     335                 :            :                 case CUR_LOWER_THIRD:
     336                 :          0 :                         cur_height = vc->vc_font.height/3;
     337                 :          0 :                         break;
     338                 :            :                 case CUR_LOWER_HALF:
     339                 :          0 :                         cur_height = vc->vc_font.height >> 1;
     340                 :          0 :                         break;
     341                 :            :                 case CUR_TWO_THIRDS:
     342                 :          0 :                         cur_height = (vc->vc_font.height << 1)/3;
     343                 :          0 :                         break;
     344                 :            :                 case CUR_BLOCK:
     345                 :            :                 default:
     346                 :          0 :                         cur_height = vc->vc_font.height;
     347                 :          0 :                         break;
     348                 :            :                 }
     349                 :        828 :                 size = (vc->vc_font.height - cur_height) * w;
     350         [ +  + ]:      13248 :                 while (size--)
     351                 :      11592 :                         mask[i++] = ~msk;
     352                 :        828 :                 size = cur_height * w;
     353         [ +  + ]:       3312 :                 while (size--)
     354                 :       1656 :                         mask[i++] = msk;
     355                 :            :         }
     356                 :            : 
     357         [ +  + ]:      12255 :         switch (mode) {
     358                 :            :         case CM_ERASE:
     359                 :       6149 :                 ops->cursor_state.enable = 0;
     360                 :       6149 :                 break;
     361                 :            :         case CM_DRAW:
     362                 :            :         case CM_MOVE:
     363                 :            :         default:
     364                 :       6106 :                 ops->cursor_state.enable = (use_sw) ? 0 : 1;
     365                 :       6106 :                 break;
     366                 :            :         }
     367                 :            : 
     368                 :      12255 :         cursor.image.data = src;
     369                 :      12255 :         cursor.image.fg_color = ops->cursor_state.image.fg_color;
     370                 :      12255 :         cursor.image.bg_color = ops->cursor_state.image.bg_color;
     371                 :      12255 :         cursor.image.dx = ops->cursor_state.image.dx;
     372                 :      12255 :         cursor.image.dy = ops->cursor_state.image.dy;
     373                 :      12255 :         cursor.image.height = ops->cursor_state.image.height;
     374                 :      12255 :         cursor.image.width = ops->cursor_state.image.width;
     375                 :      12255 :         cursor.hot.x = ops->cursor_state.hot.x;
     376                 :      12255 :         cursor.hot.y = ops->cursor_state.hot.y;
     377                 :      12255 :         cursor.mask = ops->cursor_state.mask;
     378                 :      12255 :         cursor.enable = ops->cursor_state.enable;
     379                 :      12255 :         cursor.image.depth = 1;
     380                 :      12255 :         cursor.rop = ROP_XOR;
     381                 :            : 
     382         [ -  + ]:      12255 :         if (info->fbops->fb_cursor)
     383                 :          0 :                 err = info->fbops->fb_cursor(info, &cursor);
     384                 :            : 
     385         [ +  - ]:      12255 :         if (err)
     386                 :      12255 :                 soft_cursor(info, &cursor);
     387                 :            : 
     388                 :      12255 :         ops->cursor_reset = 0;
     389                 :            : }
     390                 :            : 
     391                 :        621 : static int bit_update_start(struct fb_info *info)
     392                 :            : {
     393                 :        621 :         struct fbcon_ops *ops = info->fbcon_par;
     394                 :            :         int err;
     395                 :            : 
     396                 :        621 :         err = fb_pan_display(info, &ops->var);
     397                 :        621 :         ops->var.xoffset = info->var.xoffset;
     398                 :        621 :         ops->var.yoffset = info->var.yoffset;
     399                 :        621 :         ops->var.vmode = info->var.vmode;
     400                 :        621 :         return err;
     401                 :            : }
     402                 :            : 
     403                 :       2277 : void fbcon_set_bitops(struct fbcon_ops *ops)
     404                 :            : {
     405                 :       2277 :         ops->bmove = bit_bmove;
     406                 :       2277 :         ops->clear = bit_clear;
     407                 :       2277 :         ops->putcs = bit_putcs;
     408                 :       2277 :         ops->clear_margins = bit_clear_margins;
     409                 :       2277 :         ops->cursor = bit_cursor;
     410                 :       2277 :         ops->update_start = bit_update_start;
     411                 :       2277 :         ops->rotate_font = NULL;
     412                 :            : 
     413         [ -  + ]:       2277 :         if (ops->rotate)
     414                 :          0 :                 fbcon_set_rotate(ops);
     415                 :       2277 : }
     416                 :            : 
     417                 :            : EXPORT_SYMBOL(fbcon_set_bitops);
     418                 :            : 

Generated by: LCOV version 1.14