LCOV - code coverage report
Current view: top level - drivers/video/fbdev/core - fbcon_ccw.c (source / functions) Hit Total Coverage
Test: gcov_data_raspi2_real_modules_combined.info Lines: 0 243 0.0 %
Date: 2020-09-30 20:25:40 Functions: 0 9 0.0 %
Branches: 0 128 0.0 %

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

Generated by: LCOV version 1.14