Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/video/fbmem.c |
| 3 | * |
| 4 | * Copyright (C) 1994 Martin Schaller |
| 5 | * |
| 6 | * 2001 - Documented with DocBook |
| 7 | * - Brad Douglas <brad@neruo.com> |
| 8 | * |
| 9 | * This file is subject to the terms and conditions of the GNU General Public |
| 10 | * License. See the file COPYING in the main directory of this archive |
| 11 | * for more details. |
| 12 | */ |
| 13 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/module.h> |
| 15 | |
Arnd Bergmann | c7f82d9 | 2005-11-08 21:39:19 -0800 | [diff] [blame] | 16 | #include <linux/compat.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/types.h> |
| 18 | #include <linux/errno.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/smp_lock.h> |
| 20 | #include <linux/kernel.h> |
| 21 | #include <linux/major.h> |
| 22 | #include <linux/slab.h> |
| 23 | #include <linux/mm.h> |
| 24 | #include <linux/mman.h> |
Jon Smirl | a8f340e | 2006-07-10 04:44:12 -0700 | [diff] [blame] | 25 | #include <linux/vt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/init.h> |
| 27 | #include <linux/linux_logo.h> |
| 28 | #include <linux/proc_fs.h> |
Alexey Dobriyan | 0aa1634 | 2008-04-28 02:15:42 -0700 | [diff] [blame] | 29 | #include <linux/seq_file.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/console.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <linux/kmod.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <linux/err.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <linux/device.h> |
| 34 | #include <linux/efi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <linux/fb.h> |
| 36 | |
Antonino A. Daplas | 10eb265 | 2007-07-17 04:05:27 -0700 | [diff] [blame] | 37 | #include <asm/fb.h> |
| 38 | |
| 39 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | /* |
| 41 | * Frame buffer device initialization and setup routines |
| 42 | */ |
| 43 | |
| 44 | #define FBPIXMAPSIZE (1024 * 8) |
| 45 | |
Helge Deller | 0128bee | 2006-12-08 02:40:29 -0800 | [diff] [blame] | 46 | struct fb_info *registered_fb[FB_MAX] __read_mostly; |
| 47 | int num_registered_fb __read_mostly; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
| 49 | /* |
| 50 | * Helpers |
| 51 | */ |
| 52 | |
Antonino A. Daplas | b8c9094 | 2005-09-09 13:04:37 -0700 | [diff] [blame] | 53 | int fb_get_color_depth(struct fb_var_screeninfo *var, |
| 54 | struct fb_fix_screeninfo *fix) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | { |
Antonino A. Daplas | b8c9094 | 2005-09-09 13:04:37 -0700 | [diff] [blame] | 56 | int depth = 0; |
| 57 | |
| 58 | if (fix->visual == FB_VISUAL_MONO01 || |
| 59 | fix->visual == FB_VISUAL_MONO10) |
| 60 | depth = 1; |
| 61 | else { |
| 62 | if (var->green.length == var->blue.length && |
| 63 | var->green.length == var->red.length && |
| 64 | var->green.offset == var->blue.offset && |
| 65 | var->green.offset == var->red.offset) |
| 66 | depth = var->green.length; |
| 67 | else |
| 68 | depth = var->green.length + var->red.length + |
| 69 | var->blue.length; |
| 70 | } |
| 71 | |
| 72 | return depth; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | } |
| 74 | EXPORT_SYMBOL(fb_get_color_depth); |
| 75 | |
| 76 | /* |
James Simmons | f5a9951 | 2005-06-21 17:16:58 -0700 | [diff] [blame] | 77 | * Data padding functions. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | */ |
James Simmons | f1ab5da | 2005-06-21 17:17:07 -0700 | [diff] [blame] | 79 | void fb_pad_aligned_buffer(u8 *dst, u32 d_pitch, u8 *src, u32 s_pitch, u32 height) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | { |
Antonino A. Daplas | 829e79b | 2005-09-09 13:10:04 -0700 | [diff] [blame] | 81 | __fb_pad_aligned_buffer(dst, d_pitch, src, s_pitch, height); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | } |
James Simmons | f1ab5da | 2005-06-21 17:17:07 -0700 | [diff] [blame] | 83 | EXPORT_SYMBOL(fb_pad_aligned_buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
James Simmons | f1ab5da | 2005-06-21 17:17:07 -0700 | [diff] [blame] | 85 | void fb_pad_unaligned_buffer(u8 *dst, u32 d_pitch, u8 *src, u32 idx, u32 height, |
| 86 | u32 shift_high, u32 shift_low, u32 mod) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | { |
| 88 | u8 mask = (u8) (0xfff << shift_high), tmp; |
| 89 | int i, j; |
| 90 | |
| 91 | for (i = height; i--; ) { |
| 92 | for (j = 0; j < idx; j++) { |
| 93 | tmp = dst[j]; |
| 94 | tmp &= mask; |
| 95 | tmp |= *src >> shift_low; |
| 96 | dst[j] = tmp; |
| 97 | tmp = *src << shift_high; |
| 98 | dst[j+1] = tmp; |
| 99 | src++; |
| 100 | } |
| 101 | tmp = dst[idx]; |
| 102 | tmp &= mask; |
| 103 | tmp |= *src >> shift_low; |
| 104 | dst[idx] = tmp; |
| 105 | if (shift_high < mod) { |
| 106 | tmp = *src << shift_high; |
| 107 | dst[idx+1] = tmp; |
| 108 | } |
| 109 | src++; |
| 110 | dst += d_pitch; |
| 111 | } |
| 112 | } |
James Simmons | f1ab5da | 2005-06-21 17:17:07 -0700 | [diff] [blame] | 113 | EXPORT_SYMBOL(fb_pad_unaligned_buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
| 115 | /* |
| 116 | * we need to lock this section since fb_cursor |
| 117 | * may use fb_imageblit() |
| 118 | */ |
| 119 | char* fb_get_buffer_offset(struct fb_info *info, struct fb_pixmap *buf, u32 size) |
| 120 | { |
| 121 | u32 align = buf->buf_align - 1, offset; |
| 122 | char *addr = buf->addr; |
| 123 | |
| 124 | /* If IO mapped, we need to sync before access, no sharing of |
| 125 | * the pixmap is done |
| 126 | */ |
| 127 | if (buf->flags & FB_PIXMAP_IO) { |
| 128 | if (info->fbops->fb_sync && (buf->flags & FB_PIXMAP_SYNC)) |
| 129 | info->fbops->fb_sync(info); |
| 130 | return addr; |
| 131 | } |
| 132 | |
| 133 | /* See if we fit in the remaining pixmap space */ |
| 134 | offset = buf->offset + align; |
| 135 | offset &= ~align; |
| 136 | if (offset + size > buf->size) { |
| 137 | /* We do not fit. In order to be able to re-use the buffer, |
| 138 | * we must ensure no asynchronous DMA'ing or whatever operation |
| 139 | * is in progress, we sync for that. |
| 140 | */ |
| 141 | if (info->fbops->fb_sync && (buf->flags & FB_PIXMAP_SYNC)) |
| 142 | info->fbops->fb_sync(info); |
| 143 | offset = 0; |
| 144 | } |
| 145 | buf->offset = offset + size; |
| 146 | addr += offset; |
| 147 | |
| 148 | return addr; |
| 149 | } |
| 150 | |
| 151 | #ifdef CONFIG_LOGO |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | |
| 153 | static inline unsigned safe_shift(unsigned d, int n) |
| 154 | { |
| 155 | return n < 0 ? d >> -n : d << n; |
| 156 | } |
| 157 | |
| 158 | static void fb_set_logocmap(struct fb_info *info, |
| 159 | const struct linux_logo *logo) |
| 160 | { |
| 161 | struct fb_cmap palette_cmap; |
| 162 | u16 palette_green[16]; |
| 163 | u16 palette_blue[16]; |
| 164 | u16 palette_red[16]; |
| 165 | int i, j, n; |
| 166 | const unsigned char *clut = logo->clut; |
| 167 | |
| 168 | palette_cmap.start = 0; |
| 169 | palette_cmap.len = 16; |
| 170 | palette_cmap.red = palette_red; |
| 171 | palette_cmap.green = palette_green; |
| 172 | palette_cmap.blue = palette_blue; |
| 173 | palette_cmap.transp = NULL; |
| 174 | |
| 175 | for (i = 0; i < logo->clutsize; i += n) { |
| 176 | n = logo->clutsize - i; |
| 177 | /* palette_cmap provides space for only 16 colors at once */ |
| 178 | if (n > 16) |
| 179 | n = 16; |
| 180 | palette_cmap.start = 32 + i; |
| 181 | palette_cmap.len = n; |
| 182 | for (j = 0; j < n; ++j) { |
| 183 | palette_cmap.red[j] = clut[0] << 8 | clut[0]; |
| 184 | palette_cmap.green[j] = clut[1] << 8 | clut[1]; |
| 185 | palette_cmap.blue[j] = clut[2] << 8 | clut[2]; |
| 186 | clut += 3; |
| 187 | } |
| 188 | fb_set_cmap(&palette_cmap, info); |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | static void fb_set_logo_truepalette(struct fb_info *info, |
| 193 | const struct linux_logo *logo, |
| 194 | u32 *palette) |
| 195 | { |
Helge Deller | 0128bee | 2006-12-08 02:40:29 -0800 | [diff] [blame] | 196 | static const unsigned char mask[] = { 0,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | unsigned char redmask, greenmask, bluemask; |
| 198 | int redshift, greenshift, blueshift; |
| 199 | int i; |
| 200 | const unsigned char *clut = logo->clut; |
| 201 | |
| 202 | /* |
| 203 | * We have to create a temporary palette since console palette is only |
| 204 | * 16 colors long. |
| 205 | */ |
| 206 | /* Bug: Doesn't obey msb_right ... (who needs that?) */ |
| 207 | redmask = mask[info->var.red.length < 8 ? info->var.red.length : 8]; |
| 208 | greenmask = mask[info->var.green.length < 8 ? info->var.green.length : 8]; |
| 209 | bluemask = mask[info->var.blue.length < 8 ? info->var.blue.length : 8]; |
| 210 | redshift = info->var.red.offset - (8 - info->var.red.length); |
| 211 | greenshift = info->var.green.offset - (8 - info->var.green.length); |
| 212 | blueshift = info->var.blue.offset - (8 - info->var.blue.length); |
| 213 | |
| 214 | for ( i = 0; i < logo->clutsize; i++) { |
| 215 | palette[i+32] = (safe_shift((clut[0] & redmask), redshift) | |
| 216 | safe_shift((clut[1] & greenmask), greenshift) | |
| 217 | safe_shift((clut[2] & bluemask), blueshift)); |
| 218 | clut += 3; |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | static void fb_set_logo_directpalette(struct fb_info *info, |
| 223 | const struct linux_logo *logo, |
| 224 | u32 *palette) |
| 225 | { |
| 226 | int redshift, greenshift, blueshift; |
| 227 | int i; |
| 228 | |
| 229 | redshift = info->var.red.offset; |
| 230 | greenshift = info->var.green.offset; |
| 231 | blueshift = info->var.blue.offset; |
| 232 | |
| 233 | for (i = 32; i < logo->clutsize; i++) |
| 234 | palette[i] = i << redshift | i << greenshift | i << blueshift; |
| 235 | } |
| 236 | |
| 237 | static void fb_set_logo(struct fb_info *info, |
| 238 | const struct linux_logo *logo, u8 *dst, |
| 239 | int depth) |
| 240 | { |
Antonino A. Daplas | b8c9094 | 2005-09-09 13:04:37 -0700 | [diff] [blame] | 241 | int i, j, k; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | const u8 *src = logo->data; |
Antonino A. Daplas | b8c9094 | 2005-09-09 13:04:37 -0700 | [diff] [blame] | 243 | u8 xor = (info->fix.visual == FB_VISUAL_MONO01) ? 0xff : 0; |
| 244 | u8 fg = 1, d; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | |
Antonino A. Daplas | 1692b37 | 2007-07-31 00:37:36 -0700 | [diff] [blame] | 246 | switch (fb_get_color_depth(&info->var, &info->fix)) { |
| 247 | case 1: |
| 248 | fg = 1; |
| 249 | break; |
| 250 | case 2: |
| 251 | fg = 3; |
| 252 | break; |
| 253 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | fg = 7; |
Antonino A. Daplas | 1692b37 | 2007-07-31 00:37:36 -0700 | [diff] [blame] | 255 | break; |
| 256 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | |
Antonino A. Daplas | b8c9094 | 2005-09-09 13:04:37 -0700 | [diff] [blame] | 258 | if (info->fix.visual == FB_VISUAL_MONO01 || |
| 259 | info->fix.visual == FB_VISUAL_MONO10) |
| 260 | fg = ~((u8) (0xfff << info->var.green.length)); |
| 261 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | switch (depth) { |
| 263 | case 4: |
| 264 | for (i = 0; i < logo->height; i++) |
| 265 | for (j = 0; j < logo->width; src++) { |
| 266 | *dst++ = *src >> 4; |
| 267 | j++; |
| 268 | if (j < logo->width) { |
| 269 | *dst++ = *src & 0x0f; |
| 270 | j++; |
| 271 | } |
| 272 | } |
| 273 | break; |
| 274 | case 1: |
| 275 | for (i = 0; i < logo->height; i++) { |
| 276 | for (j = 0; j < logo->width; src++) { |
| 277 | d = *src ^ xor; |
| 278 | for (k = 7; k >= 0; k--) { |
| 279 | *dst++ = ((d >> k) & 1) ? fg : 0; |
| 280 | j++; |
| 281 | } |
| 282 | } |
| 283 | } |
| 284 | break; |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | /* |
| 289 | * Three (3) kinds of logo maps exist. linux_logo_clut224 (>16 colors), |
| 290 | * linux_logo_vga16 (16 colors) and linux_logo_mono (2 colors). Depending on |
| 291 | * the visual format and color depth of the framebuffer, the DAC, the |
| 292 | * pseudo_palette, and the logo data will be adjusted accordingly. |
| 293 | * |
| 294 | * Case 1 - linux_logo_clut224: |
| 295 | * Color exceeds the number of console colors (16), thus we set the hardware DAC |
| 296 | * using fb_set_cmap() appropriately. The "needs_cmapreset" flag will be set. |
| 297 | * |
| 298 | * For visuals that require color info from the pseudo_palette, we also construct |
| 299 | * one for temporary use. The "needs_directpalette" or "needs_truepalette" flags |
| 300 | * will be set. |
| 301 | * |
| 302 | * Case 2 - linux_logo_vga16: |
| 303 | * The number of colors just matches the console colors, thus there is no need |
| 304 | * to set the DAC or the pseudo_palette. However, the bitmap is packed, ie, |
| 305 | * each byte contains color information for two pixels (upper and lower nibble). |
| 306 | * To be consistent with fb_imageblit() usage, we therefore separate the two |
| 307 | * nibbles into separate bytes. The "depth" flag will be set to 4. |
| 308 | * |
| 309 | * Case 3 - linux_logo_mono: |
| 310 | * This is similar with Case 2. Each byte contains information for 8 pixels. |
| 311 | * We isolate each bit and expand each into a byte. The "depth" flag will |
| 312 | * be set to 1. |
| 313 | */ |
| 314 | static struct logo_data { |
| 315 | int depth; |
| 316 | int needs_directpalette; |
| 317 | int needs_truepalette; |
| 318 | int needs_cmapreset; |
| 319 | const struct linux_logo *logo; |
Helge Deller | 0128bee | 2006-12-08 02:40:29 -0800 | [diff] [blame] | 320 | } fb_logo __read_mostly; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | |
Antonino A. Daplas | 9c44e5f | 2005-11-08 21:39:10 -0800 | [diff] [blame] | 322 | static void fb_rotate_logo_ud(const u8 *in, u8 *out, u32 width, u32 height) |
| 323 | { |
| 324 | u32 size = width * height, i; |
| 325 | |
| 326 | out += size - 1; |
| 327 | |
| 328 | for (i = size; i--; ) |
| 329 | *out-- = *in++; |
| 330 | } |
| 331 | |
| 332 | static void fb_rotate_logo_cw(const u8 *in, u8 *out, u32 width, u32 height) |
| 333 | { |
Antonino A. Daplas | f837e6f | 2006-06-26 00:26:56 -0700 | [diff] [blame] | 334 | int i, j, h = height - 1; |
Antonino A. Daplas | 9c44e5f | 2005-11-08 21:39:10 -0800 | [diff] [blame] | 335 | |
| 336 | for (i = 0; i < height; i++) |
| 337 | for (j = 0; j < width; j++) |
Antonino A. Daplas | f837e6f | 2006-06-26 00:26:56 -0700 | [diff] [blame] | 338 | out[height * j + h - i] = *in++; |
Antonino A. Daplas | 9c44e5f | 2005-11-08 21:39:10 -0800 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | static void fb_rotate_logo_ccw(const u8 *in, u8 *out, u32 width, u32 height) |
| 342 | { |
| 343 | int i, j, w = width - 1; |
| 344 | |
| 345 | for (i = 0; i < height; i++) |
| 346 | for (j = 0; j < width; j++) |
| 347 | out[height * (w - j) + i] = *in++; |
| 348 | } |
| 349 | |
| 350 | static void fb_rotate_logo(struct fb_info *info, u8 *dst, |
| 351 | struct fb_image *image, int rotate) |
| 352 | { |
| 353 | u32 tmp; |
| 354 | |
| 355 | if (rotate == FB_ROTATE_UD) { |
Antonino A. Daplas | 9c44e5f | 2005-11-08 21:39:10 -0800 | [diff] [blame] | 356 | fb_rotate_logo_ud(image->data, dst, image->width, |
| 357 | image->height); |
Geert Uytterhoeven | abed5d1 | 2007-05-08 00:37:57 -0700 | [diff] [blame] | 358 | image->dx = info->var.xres - image->width - image->dx; |
| 359 | image->dy = info->var.yres - image->height - image->dy; |
Antonino A. Daplas | 9c44e5f | 2005-11-08 21:39:10 -0800 | [diff] [blame] | 360 | } else if (rotate == FB_ROTATE_CW) { |
Antonino A. Daplas | 9c44e5f | 2005-11-08 21:39:10 -0800 | [diff] [blame] | 361 | fb_rotate_logo_cw(image->data, dst, image->width, |
| 362 | image->height); |
Antonino A. Daplas | 9c44e5f | 2005-11-08 21:39:10 -0800 | [diff] [blame] | 363 | tmp = image->width; |
| 364 | image->width = image->height; |
| 365 | image->height = tmp; |
Geert Uytterhoeven | abed5d1 | 2007-05-08 00:37:57 -0700 | [diff] [blame] | 366 | tmp = image->dy; |
| 367 | image->dy = image->dx; |
| 368 | image->dx = info->var.xres - image->width - tmp; |
Antonino A. Daplas | f837e6f | 2006-06-26 00:26:56 -0700 | [diff] [blame] | 369 | } else if (rotate == FB_ROTATE_CCW) { |
Antonino A. Daplas | 9c44e5f | 2005-11-08 21:39:10 -0800 | [diff] [blame] | 370 | fb_rotate_logo_ccw(image->data, dst, image->width, |
| 371 | image->height); |
Antonino A. Daplas | f837e6f | 2006-06-26 00:26:56 -0700 | [diff] [blame] | 372 | tmp = image->width; |
| 373 | image->width = image->height; |
| 374 | image->height = tmp; |
Geert Uytterhoeven | abed5d1 | 2007-05-08 00:37:57 -0700 | [diff] [blame] | 375 | tmp = image->dx; |
| 376 | image->dx = image->dy; |
| 377 | image->dy = info->var.yres - image->height - tmp; |
Antonino A. Daplas | 9c44e5f | 2005-11-08 21:39:10 -0800 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | image->data = dst; |
| 381 | } |
| 382 | |
| 383 | static void fb_do_show_logo(struct fb_info *info, struct fb_image *image, |
Geert Uytterhoeven | 448d479 | 2007-05-08 00:37:56 -0700 | [diff] [blame] | 384 | int rotate, unsigned int num) |
Antonino A. Daplas | 9c44e5f | 2005-11-08 21:39:10 -0800 | [diff] [blame] | 385 | { |
Geert Uytterhoeven | 448d479 | 2007-05-08 00:37:56 -0700 | [diff] [blame] | 386 | unsigned int x; |
Antonino A. Daplas | 9c44e5f | 2005-11-08 21:39:10 -0800 | [diff] [blame] | 387 | |
| 388 | if (rotate == FB_ROTATE_UR) { |
Geert Uytterhoeven | 448d479 | 2007-05-08 00:37:56 -0700 | [diff] [blame] | 389 | for (x = 0; |
| 390 | x < num && image->dx + image->width <= info->var.xres; |
| 391 | x++) { |
Antonino A. Daplas | 9c44e5f | 2005-11-08 21:39:10 -0800 | [diff] [blame] | 392 | info->fbops->fb_imageblit(info, image); |
Geert Uytterhoeven | 448d479 | 2007-05-08 00:37:56 -0700 | [diff] [blame] | 393 | image->dx += image->width + 8; |
Antonino A. Daplas | 9c44e5f | 2005-11-08 21:39:10 -0800 | [diff] [blame] | 394 | } |
| 395 | } else if (rotate == FB_ROTATE_UD) { |
Geert Uytterhoeven | 448d479 | 2007-05-08 00:37:56 -0700 | [diff] [blame] | 396 | for (x = 0; x < num && image->dx >= 0; x++) { |
Antonino A. Daplas | 9c44e5f | 2005-11-08 21:39:10 -0800 | [diff] [blame] | 397 | info->fbops->fb_imageblit(info, image); |
Geert Uytterhoeven | 448d479 | 2007-05-08 00:37:56 -0700 | [diff] [blame] | 398 | image->dx -= image->width + 8; |
Antonino A. Daplas | 9c44e5f | 2005-11-08 21:39:10 -0800 | [diff] [blame] | 399 | } |
| 400 | } else if (rotate == FB_ROTATE_CW) { |
Geert Uytterhoeven | 448d479 | 2007-05-08 00:37:56 -0700 | [diff] [blame] | 401 | for (x = 0; |
| 402 | x < num && image->dy + image->height <= info->var.yres; |
| 403 | x++) { |
Antonino A. Daplas | 9c44e5f | 2005-11-08 21:39:10 -0800 | [diff] [blame] | 404 | info->fbops->fb_imageblit(info, image); |
Geert Uytterhoeven | 448d479 | 2007-05-08 00:37:56 -0700 | [diff] [blame] | 405 | image->dy += image->height + 8; |
Antonino A. Daplas | 9c44e5f | 2005-11-08 21:39:10 -0800 | [diff] [blame] | 406 | } |
| 407 | } else if (rotate == FB_ROTATE_CCW) { |
Geert Uytterhoeven | 448d479 | 2007-05-08 00:37:56 -0700 | [diff] [blame] | 408 | for (x = 0; x < num && image->dy >= 0; x++) { |
Antonino A. Daplas | 9c44e5f | 2005-11-08 21:39:10 -0800 | [diff] [blame] | 409 | info->fbops->fb_imageblit(info, image); |
Geert Uytterhoeven | 448d479 | 2007-05-08 00:37:56 -0700 | [diff] [blame] | 410 | image->dy -= image->height + 8; |
Antonino A. Daplas | 9c44e5f | 2005-11-08 21:39:10 -0800 | [diff] [blame] | 411 | } |
| 412 | } |
| 413 | } |
| 414 | |
Geert Uytterhoeven | 90da63e5 | 2007-07-17 04:05:50 -0700 | [diff] [blame] | 415 | static int fb_show_logo_line(struct fb_info *info, int rotate, |
| 416 | const struct linux_logo *logo, int y, |
| 417 | unsigned int n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | { |
| 419 | u32 *palette = NULL, *saved_pseudo_palette = NULL; |
Antonino A. Daplas | 9c44e5f | 2005-11-08 21:39:10 -0800 | [diff] [blame] | 420 | unsigned char *logo_new = NULL, *logo_rotate = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | struct fb_image image; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | |
| 423 | /* Return if the frame buffer is not mapped or suspended */ |
Geert Uytterhoeven | 90da63e5 | 2007-07-17 04:05:50 -0700 | [diff] [blame] | 424 | if (logo == NULL || info->state != FBINFO_STATE_RUNNING || |
Antonino A. Daplas | 70802c6 | 2007-05-08 00:38:14 -0700 | [diff] [blame] | 425 | info->flags & FBINFO_MODULE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | return 0; |
| 427 | |
| 428 | image.depth = 8; |
Geert Uytterhoeven | 90da63e5 | 2007-07-17 04:05:50 -0700 | [diff] [blame] | 429 | image.data = logo->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | |
| 431 | if (fb_logo.needs_cmapreset) |
Geert Uytterhoeven | 90da63e5 | 2007-07-17 04:05:50 -0700 | [diff] [blame] | 432 | fb_set_logocmap(info, logo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | |
Geert Uytterhoeven | 9900abf | 2007-07-17 04:05:50 -0700 | [diff] [blame] | 434 | if (fb_logo.needs_truepalette || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | fb_logo.needs_directpalette) { |
| 436 | palette = kmalloc(256 * 4, GFP_KERNEL); |
| 437 | if (palette == NULL) |
| 438 | return 0; |
| 439 | |
| 440 | if (fb_logo.needs_truepalette) |
Geert Uytterhoeven | 90da63e5 | 2007-07-17 04:05:50 -0700 | [diff] [blame] | 441 | fb_set_logo_truepalette(info, logo, palette); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | else |
Geert Uytterhoeven | 90da63e5 | 2007-07-17 04:05:50 -0700 | [diff] [blame] | 443 | fb_set_logo_directpalette(info, logo, palette); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | |
| 445 | saved_pseudo_palette = info->pseudo_palette; |
| 446 | info->pseudo_palette = palette; |
| 447 | } |
| 448 | |
| 449 | if (fb_logo.depth <= 4) { |
Geert Uytterhoeven | 90da63e5 | 2007-07-17 04:05:50 -0700 | [diff] [blame] | 450 | logo_new = kmalloc(logo->width * logo->height, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | if (logo_new == NULL) { |
| 452 | kfree(palette); |
| 453 | if (saved_pseudo_palette) |
| 454 | info->pseudo_palette = saved_pseudo_palette; |
| 455 | return 0; |
| 456 | } |
| 457 | image.data = logo_new; |
Geert Uytterhoeven | 90da63e5 | 2007-07-17 04:05:50 -0700 | [diff] [blame] | 458 | fb_set_logo(info, logo, logo_new, fb_logo.depth); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | } |
| 460 | |
Antonino A. Daplas | 9c44e5f | 2005-11-08 21:39:10 -0800 | [diff] [blame] | 461 | image.dx = 0; |
Geert Uytterhoeven | 90da63e5 | 2007-07-17 04:05:50 -0700 | [diff] [blame] | 462 | image.dy = y; |
| 463 | image.width = logo->width; |
| 464 | image.height = logo->height; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | |
Antonino A. Daplas | 9c44e5f | 2005-11-08 21:39:10 -0800 | [diff] [blame] | 466 | if (rotate) { |
Geert Uytterhoeven | 90da63e5 | 2007-07-17 04:05:50 -0700 | [diff] [blame] | 467 | logo_rotate = kmalloc(logo->width * |
| 468 | logo->height, GFP_KERNEL); |
Antonino A. Daplas | 9c44e5f | 2005-11-08 21:39:10 -0800 | [diff] [blame] | 469 | if (logo_rotate) |
| 470 | fb_rotate_logo(info, logo_rotate, &image, rotate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | } |
Antonino A. Daplas | 9c44e5f | 2005-11-08 21:39:10 -0800 | [diff] [blame] | 472 | |
Geert Uytterhoeven | 90da63e5 | 2007-07-17 04:05:50 -0700 | [diff] [blame] | 473 | fb_do_show_logo(info, &image, rotate, n); |
Antonino A. Daplas | 9c44e5f | 2005-11-08 21:39:10 -0800 | [diff] [blame] | 474 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | kfree(palette); |
| 476 | if (saved_pseudo_palette != NULL) |
| 477 | info->pseudo_palette = saved_pseudo_palette; |
| 478 | kfree(logo_new); |
Antonino A. Daplas | 9c44e5f | 2005-11-08 21:39:10 -0800 | [diff] [blame] | 479 | kfree(logo_rotate); |
Geert Uytterhoeven | 90da63e5 | 2007-07-17 04:05:50 -0700 | [diff] [blame] | 480 | return logo->height; |
| 481 | } |
| 482 | |
Geert Uytterhoeven | 9900abf | 2007-07-17 04:05:50 -0700 | [diff] [blame] | 483 | |
| 484 | #ifdef CONFIG_FB_LOGO_EXTRA |
| 485 | |
| 486 | #define FB_LOGO_EX_NUM_MAX 10 |
| 487 | static struct logo_data_extra { |
| 488 | const struct linux_logo *logo; |
| 489 | unsigned int n; |
| 490 | } fb_logo_ex[FB_LOGO_EX_NUM_MAX]; |
| 491 | static unsigned int fb_logo_ex_num; |
| 492 | |
| 493 | void fb_append_extra_logo(const struct linux_logo *logo, unsigned int n) |
| 494 | { |
| 495 | if (!n || fb_logo_ex_num == FB_LOGO_EX_NUM_MAX) |
| 496 | return; |
| 497 | |
| 498 | fb_logo_ex[fb_logo_ex_num].logo = logo; |
| 499 | fb_logo_ex[fb_logo_ex_num].n = n; |
| 500 | fb_logo_ex_num++; |
| 501 | } |
| 502 | |
| 503 | static int fb_prepare_extra_logos(struct fb_info *info, unsigned int height, |
| 504 | unsigned int yres) |
| 505 | { |
| 506 | unsigned int i; |
| 507 | |
| 508 | /* FIXME: logo_ex supports only truecolor fb. */ |
| 509 | if (info->fix.visual != FB_VISUAL_TRUECOLOR) |
| 510 | fb_logo_ex_num = 0; |
| 511 | |
| 512 | for (i = 0; i < fb_logo_ex_num; i++) { |
| 513 | height += fb_logo_ex[i].logo->height; |
| 514 | if (height > yres) { |
| 515 | height -= fb_logo_ex[i].logo->height; |
| 516 | fb_logo_ex_num = i; |
| 517 | break; |
| 518 | } |
| 519 | } |
| 520 | return height; |
| 521 | } |
| 522 | |
| 523 | static int fb_show_extra_logos(struct fb_info *info, int y, int rotate) |
| 524 | { |
| 525 | unsigned int i; |
| 526 | |
| 527 | for (i = 0; i < fb_logo_ex_num; i++) |
| 528 | y += fb_show_logo_line(info, rotate, |
| 529 | fb_logo_ex[i].logo, y, fb_logo_ex[i].n); |
| 530 | |
| 531 | return y; |
| 532 | } |
| 533 | |
| 534 | #else /* !CONFIG_FB_LOGO_EXTRA */ |
| 535 | |
| 536 | static inline int fb_prepare_extra_logos(struct fb_info *info, |
| 537 | unsigned int height, |
| 538 | unsigned int yres) |
| 539 | { |
| 540 | return height; |
| 541 | } |
| 542 | |
| 543 | static inline int fb_show_extra_logos(struct fb_info *info, int y, int rotate) |
| 544 | { |
| 545 | return y; |
| 546 | } |
| 547 | |
| 548 | #endif /* CONFIG_FB_LOGO_EXTRA */ |
| 549 | |
| 550 | |
| 551 | int fb_prepare_logo(struct fb_info *info, int rotate) |
| 552 | { |
| 553 | int depth = fb_get_color_depth(&info->var, &info->fix); |
| 554 | unsigned int yres; |
| 555 | |
| 556 | memset(&fb_logo, 0, sizeof(struct logo_data)); |
| 557 | |
| 558 | if (info->flags & FBINFO_MISC_TILEBLITTING || |
| 559 | info->flags & FBINFO_MODULE) |
| 560 | return 0; |
| 561 | |
| 562 | if (info->fix.visual == FB_VISUAL_DIRECTCOLOR) { |
| 563 | depth = info->var.blue.length; |
| 564 | if (info->var.red.length < depth) |
| 565 | depth = info->var.red.length; |
| 566 | if (info->var.green.length < depth) |
| 567 | depth = info->var.green.length; |
| 568 | } |
| 569 | |
| 570 | if (info->fix.visual == FB_VISUAL_STATIC_PSEUDOCOLOR && depth > 4) { |
| 571 | /* assume console colormap */ |
| 572 | depth = 4; |
| 573 | } |
| 574 | |
Geert Uytterhoeven | 9900abf | 2007-07-17 04:05:50 -0700 | [diff] [blame] | 575 | /* Return if no suitable logo was found */ |
| 576 | fb_logo.logo = fb_find_logo(depth); |
| 577 | |
| 578 | if (!fb_logo.logo) { |
| 579 | return 0; |
| 580 | } |
| 581 | |
| 582 | if (rotate == FB_ROTATE_UR || rotate == FB_ROTATE_UD) |
| 583 | yres = info->var.yres; |
| 584 | else |
| 585 | yres = info->var.xres; |
| 586 | |
| 587 | if (fb_logo.logo->height > yres) { |
| 588 | fb_logo.logo = NULL; |
| 589 | return 0; |
| 590 | } |
| 591 | |
| 592 | /* What depth we asked for might be different from what we get */ |
| 593 | if (fb_logo.logo->type == LINUX_LOGO_CLUT224) |
| 594 | fb_logo.depth = 8; |
| 595 | else if (fb_logo.logo->type == LINUX_LOGO_VGA16) |
| 596 | fb_logo.depth = 4; |
| 597 | else |
| 598 | fb_logo.depth = 1; |
| 599 | |
Antonino A. Daplas | 1692b37 | 2007-07-31 00:37:36 -0700 | [diff] [blame] | 600 | |
| 601 | if (fb_logo.depth > 4 && depth > 4) { |
| 602 | switch (info->fix.visual) { |
| 603 | case FB_VISUAL_TRUECOLOR: |
| 604 | fb_logo.needs_truepalette = 1; |
| 605 | break; |
| 606 | case FB_VISUAL_DIRECTCOLOR: |
| 607 | fb_logo.needs_directpalette = 1; |
| 608 | fb_logo.needs_cmapreset = 1; |
| 609 | break; |
| 610 | case FB_VISUAL_PSEUDOCOLOR: |
| 611 | fb_logo.needs_cmapreset = 1; |
| 612 | break; |
| 613 | } |
| 614 | } |
| 615 | |
Geert Uytterhoeven | 9900abf | 2007-07-17 04:05:50 -0700 | [diff] [blame] | 616 | return fb_prepare_extra_logos(info, fb_logo.logo->height, yres); |
| 617 | } |
| 618 | |
Geert Uytterhoeven | 90da63e5 | 2007-07-17 04:05:50 -0700 | [diff] [blame] | 619 | int fb_show_logo(struct fb_info *info, int rotate) |
| 620 | { |
Geert Uytterhoeven | 9900abf | 2007-07-17 04:05:50 -0700 | [diff] [blame] | 621 | int y; |
| 622 | |
| 623 | y = fb_show_logo_line(info, rotate, fb_logo.logo, 0, |
| 624 | num_online_cpus()); |
| 625 | y = fb_show_extra_logos(info, y, rotate); |
| 626 | |
| 627 | return y; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | } |
| 629 | #else |
Antonino A. Daplas | 9c44e5f | 2005-11-08 21:39:10 -0800 | [diff] [blame] | 630 | int fb_prepare_logo(struct fb_info *info, int rotate) { return 0; } |
| 631 | int fb_show_logo(struct fb_info *info, int rotate) { return 0; } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | #endif /* CONFIG_LOGO */ |
| 633 | |
Alexey Dobriyan | 0aa1634 | 2008-04-28 02:15:42 -0700 | [diff] [blame] | 634 | static void *fb_seq_start(struct seq_file *m, loff_t *pos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | { |
Alexey Dobriyan | 0aa1634 | 2008-04-28 02:15:42 -0700 | [diff] [blame] | 636 | return (*pos < FB_MAX) ? pos : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | } |
| 638 | |
Alexey Dobriyan | 0aa1634 | 2008-04-28 02:15:42 -0700 | [diff] [blame] | 639 | static void *fb_seq_next(struct seq_file *m, void *v, loff_t *pos) |
| 640 | { |
| 641 | (*pos)++; |
| 642 | return (*pos < FB_MAX) ? pos : NULL; |
| 643 | } |
| 644 | |
| 645 | static void fb_seq_stop(struct seq_file *m, void *v) |
| 646 | { |
| 647 | } |
| 648 | |
| 649 | static int fb_seq_show(struct seq_file *m, void *v) |
| 650 | { |
| 651 | int i = *(loff_t *)v; |
| 652 | struct fb_info *fi = registered_fb[i]; |
| 653 | |
| 654 | if (fi) |
| 655 | seq_printf(m, "%d %s\n", fi->node, fi->fix.id); |
| 656 | return 0; |
| 657 | } |
| 658 | |
| 659 | static const struct seq_operations proc_fb_seq_ops = { |
| 660 | .start = fb_seq_start, |
| 661 | .next = fb_seq_next, |
| 662 | .stop = fb_seq_stop, |
| 663 | .show = fb_seq_show, |
| 664 | }; |
| 665 | |
| 666 | static int proc_fb_open(struct inode *inode, struct file *file) |
| 667 | { |
| 668 | return seq_open(file, &proc_fb_seq_ops); |
| 669 | } |
| 670 | |
| 671 | static const struct file_operations fb_proc_fops = { |
| 672 | .owner = THIS_MODULE, |
| 673 | .open = proc_fb_open, |
| 674 | .read = seq_read, |
| 675 | .llseek = seq_lseek, |
| 676 | .release = seq_release, |
| 677 | }; |
| 678 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | static ssize_t |
| 680 | fb_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) |
| 681 | { |
| 682 | unsigned long p = *ppos; |
Josef Sipek | ad9a824 | 2006-12-08 02:37:48 -0800 | [diff] [blame] | 683 | struct inode *inode = file->f_path.dentry->d_inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | int fbidx = iminor(inode); |
| 685 | struct fb_info *info = registered_fb[fbidx]; |
| 686 | u32 *buffer, *dst; |
| 687 | u32 __iomem *src; |
| 688 | int c, i, cnt = 0, err = 0; |
| 689 | unsigned long total_size; |
| 690 | |
| 691 | if (!info || ! info->screen_base) |
| 692 | return -ENODEV; |
| 693 | |
| 694 | if (info->state != FBINFO_STATE_RUNNING) |
| 695 | return -EPERM; |
| 696 | |
| 697 | if (info->fbops->fb_read) |
Antonino A. Daplas | 3f9b088 | 2007-05-08 00:39:02 -0700 | [diff] [blame] | 698 | return info->fbops->fb_read(info, buf, count, ppos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | |
| 700 | total_size = info->screen_size; |
Antonino A. Daplas | 0a484a3 | 2006-01-09 20:53:37 -0800 | [diff] [blame] | 701 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | if (total_size == 0) |
| 703 | total_size = info->fix.smem_len; |
| 704 | |
| 705 | if (p >= total_size) |
Antonino A. Daplas | 0a484a3 | 2006-01-09 20:53:37 -0800 | [diff] [blame] | 706 | return 0; |
| 707 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | if (count >= total_size) |
Antonino A. Daplas | 0a484a3 | 2006-01-09 20:53:37 -0800 | [diff] [blame] | 709 | count = total_size; |
| 710 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | if (count + p > total_size) |
| 712 | count = total_size - p; |
| 713 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | buffer = kmalloc((count > PAGE_SIZE) ? PAGE_SIZE : count, |
| 715 | GFP_KERNEL); |
| 716 | if (!buffer) |
| 717 | return -ENOMEM; |
| 718 | |
| 719 | src = (u32 __iomem *) (info->screen_base + p); |
| 720 | |
| 721 | if (info->fbops->fb_sync) |
| 722 | info->fbops->fb_sync(info); |
| 723 | |
| 724 | while (count) { |
| 725 | c = (count > PAGE_SIZE) ? PAGE_SIZE : count; |
| 726 | dst = buffer; |
| 727 | for (i = c >> 2; i--; ) |
| 728 | *dst++ = fb_readl(src++); |
| 729 | if (c & 3) { |
| 730 | u8 *dst8 = (u8 *) dst; |
| 731 | u8 __iomem *src8 = (u8 __iomem *) src; |
| 732 | |
| 733 | for (i = c & 3; i--;) |
| 734 | *dst8++ = fb_readb(src8++); |
| 735 | |
| 736 | src = (u32 __iomem *) src8; |
| 737 | } |
| 738 | |
| 739 | if (copy_to_user(buf, buffer, c)) { |
| 740 | err = -EFAULT; |
| 741 | break; |
| 742 | } |
| 743 | *ppos += c; |
| 744 | buf += c; |
| 745 | cnt += c; |
| 746 | count -= c; |
| 747 | } |
| 748 | |
| 749 | kfree(buffer); |
Antonino A. Daplas | 0a484a3 | 2006-01-09 20:53:37 -0800 | [diff] [blame] | 750 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | return (err) ? err : cnt; |
| 752 | } |
| 753 | |
| 754 | static ssize_t |
| 755 | fb_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) |
| 756 | { |
| 757 | unsigned long p = *ppos; |
Josef Sipek | ad9a824 | 2006-12-08 02:37:48 -0800 | [diff] [blame] | 758 | struct inode *inode = file->f_path.dentry->d_inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | int fbidx = iminor(inode); |
| 760 | struct fb_info *info = registered_fb[fbidx]; |
| 761 | u32 *buffer, *src; |
| 762 | u32 __iomem *dst; |
Antonino A. Daplas | 0a484a3 | 2006-01-09 20:53:37 -0800 | [diff] [blame] | 763 | int c, i, cnt = 0, err = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | unsigned long total_size; |
| 765 | |
| 766 | if (!info || !info->screen_base) |
| 767 | return -ENODEV; |
| 768 | |
| 769 | if (info->state != FBINFO_STATE_RUNNING) |
| 770 | return -EPERM; |
| 771 | |
| 772 | if (info->fbops->fb_write) |
Antonino A. Daplas | 3f9b088 | 2007-05-08 00:39:02 -0700 | [diff] [blame] | 773 | return info->fbops->fb_write(info, buf, count, ppos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | |
| 775 | total_size = info->screen_size; |
Antonino A. Daplas | 0a484a3 | 2006-01-09 20:53:37 -0800 | [diff] [blame] | 776 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | if (total_size == 0) |
| 778 | total_size = info->fix.smem_len; |
| 779 | |
| 780 | if (p > total_size) |
Antonino A. Daplas | 6a2a886 | 2006-04-18 22:22:12 -0700 | [diff] [blame] | 781 | return -EFBIG; |
Antonino A. Daplas | 0a484a3 | 2006-01-09 20:53:37 -0800 | [diff] [blame] | 782 | |
Antonino A. Daplas | 6a2a886 | 2006-04-18 22:22:12 -0700 | [diff] [blame] | 783 | if (count > total_size) { |
| 784 | err = -EFBIG; |
Antonino A. Daplas | 0a484a3 | 2006-01-09 20:53:37 -0800 | [diff] [blame] | 785 | count = total_size; |
Antonino A. Daplas | 6a2a886 | 2006-04-18 22:22:12 -0700 | [diff] [blame] | 786 | } |
Antonino A. Daplas | 0a484a3 | 2006-01-09 20:53:37 -0800 | [diff] [blame] | 787 | |
Antonino A. Daplas | 6a2a886 | 2006-04-18 22:22:12 -0700 | [diff] [blame] | 788 | if (count + p > total_size) { |
| 789 | if (!err) |
| 790 | err = -ENOSPC; |
| 791 | |
Antonino A. Daplas | 0a484a3 | 2006-01-09 20:53:37 -0800 | [diff] [blame] | 792 | count = total_size - p; |
Antonino A. Daplas | 6a2a886 | 2006-04-18 22:22:12 -0700 | [diff] [blame] | 793 | } |
Antonino A. Daplas | 0a484a3 | 2006-01-09 20:53:37 -0800 | [diff] [blame] | 794 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | buffer = kmalloc((count > PAGE_SIZE) ? PAGE_SIZE : count, |
| 796 | GFP_KERNEL); |
| 797 | if (!buffer) |
| 798 | return -ENOMEM; |
| 799 | |
| 800 | dst = (u32 __iomem *) (info->screen_base + p); |
| 801 | |
| 802 | if (info->fbops->fb_sync) |
| 803 | info->fbops->fb_sync(info); |
| 804 | |
| 805 | while (count) { |
| 806 | c = (count > PAGE_SIZE) ? PAGE_SIZE : count; |
| 807 | src = buffer; |
Antonino A. Daplas | 0a484a3 | 2006-01-09 20:53:37 -0800 | [diff] [blame] | 808 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | if (copy_from_user(src, buf, c)) { |
| 810 | err = -EFAULT; |
| 811 | break; |
| 812 | } |
Antonino A. Daplas | 0a484a3 | 2006-01-09 20:53:37 -0800 | [diff] [blame] | 813 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | for (i = c >> 2; i--; ) |
| 815 | fb_writel(*src++, dst++); |
Antonino A. Daplas | 0a484a3 | 2006-01-09 20:53:37 -0800 | [diff] [blame] | 816 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | if (c & 3) { |
| 818 | u8 *src8 = (u8 *) src; |
| 819 | u8 __iomem *dst8 = (u8 __iomem *) dst; |
| 820 | |
| 821 | for (i = c & 3; i--; ) |
| 822 | fb_writeb(*src8++, dst8++); |
| 823 | |
| 824 | dst = (u32 __iomem *) dst8; |
| 825 | } |
Antonino A. Daplas | 0a484a3 | 2006-01-09 20:53:37 -0800 | [diff] [blame] | 826 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | *ppos += c; |
| 828 | buf += c; |
| 829 | cnt += c; |
| 830 | count -= c; |
| 831 | } |
Antonino A. Daplas | 0a484a3 | 2006-01-09 20:53:37 -0800 | [diff] [blame] | 832 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | kfree(buffer); |
| 834 | |
Antonino A. Daplas | 6a2a886 | 2006-04-18 22:22:12 -0700 | [diff] [blame] | 835 | return (cnt) ? cnt : err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | } |
| 837 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | int |
| 839 | fb_pan_display(struct fb_info *info, struct fb_var_screeninfo *var) |
| 840 | { |
Antonino A. Daplas | 1207069 | 2005-12-12 22:17:17 -0800 | [diff] [blame] | 841 | struct fb_fix_screeninfo *fix = &info->fix; |
Ville Syrjala | 7572a1e | 2008-07-23 21:31:28 -0700 | [diff] [blame] | 842 | unsigned int yres = info->var.yres; |
| 843 | int err = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | |
Antonino A. Daplas | 1207069 | 2005-12-12 22:17:17 -0800 | [diff] [blame] | 845 | if (var->yoffset > 0) { |
| 846 | if (var->vmode & FB_VMODE_YWRAP) { |
| 847 | if (!fix->ywrapstep || (var->yoffset % fix->ywrapstep)) |
| 848 | err = -EINVAL; |
| 849 | else |
| 850 | yres = 0; |
| 851 | } else if (!fix->ypanstep || (var->yoffset % fix->ypanstep)) |
| 852 | err = -EINVAL; |
| 853 | } |
| 854 | |
| 855 | if (var->xoffset > 0 && (!fix->xpanstep || |
| 856 | (var->xoffset % fix->xpanstep))) |
| 857 | err = -EINVAL; |
| 858 | |
Ville Syrjala | 7572a1e | 2008-07-23 21:31:28 -0700 | [diff] [blame] | 859 | if (err || !info->fbops->fb_pan_display || |
| 860 | var->yoffset + yres > info->var.yres_virtual || |
Antonino A. Daplas | 1207069 | 2005-12-12 22:17:17 -0800 | [diff] [blame] | 861 | var->xoffset + info->var.xres > info->var.xres_virtual) |
| 862 | return -EINVAL; |
| 863 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | if ((err = info->fbops->fb_pan_display(var, info))) |
| 865 | return err; |
| 866 | info->var.xoffset = var->xoffset; |
| 867 | info->var.yoffset = var->yoffset; |
| 868 | if (var->vmode & FB_VMODE_YWRAP) |
| 869 | info->var.vmode |= FB_VMODE_YWRAP; |
| 870 | else |
| 871 | info->var.vmode &= ~FB_VMODE_YWRAP; |
| 872 | return 0; |
| 873 | } |
| 874 | |
Antonino A. Daplas | 38a3dc5 | 2007-05-08 00:39:37 -0700 | [diff] [blame] | 875 | static int fb_check_caps(struct fb_info *info, struct fb_var_screeninfo *var, |
| 876 | u32 activate) |
| 877 | { |
| 878 | struct fb_event event; |
| 879 | struct fb_blit_caps caps, fbcaps; |
| 880 | int err = 0; |
| 881 | |
| 882 | memset(&caps, 0, sizeof(caps)); |
| 883 | memset(&fbcaps, 0, sizeof(fbcaps)); |
| 884 | caps.flags = (activate & FB_ACTIVATE_ALL) ? 1 : 0; |
| 885 | event.info = info; |
| 886 | event.data = ∩︀ |
| 887 | fb_notifier_call_chain(FB_EVENT_GET_REQ, &event); |
| 888 | info->fbops->fb_get_caps(info, &fbcaps, var); |
| 889 | |
| 890 | if (((fbcaps.x ^ caps.x) & caps.x) || |
| 891 | ((fbcaps.y ^ caps.y) & caps.y) || |
| 892 | (fbcaps.len < caps.len)) |
| 893 | err = -EINVAL; |
| 894 | |
| 895 | return err; |
| 896 | } |
| 897 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | int |
| 899 | fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var) |
| 900 | { |
Antonino A. Daplas | b1e7223 | 2007-05-08 00:39:52 -0700 | [diff] [blame] | 901 | int flags = info->flags; |
| 902 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | |
| 904 | if (var->activate & FB_ACTIVATE_INV_MODE) { |
| 905 | struct fb_videomode mode1, mode2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | |
| 907 | fb_var_to_videomode(&mode1, var); |
| 908 | fb_var_to_videomode(&mode2, &info->var); |
| 909 | /* make sure we don't delete the videomode of current var */ |
| 910 | ret = fb_mode_is_equal(&mode1, &mode2); |
| 911 | |
| 912 | if (!ret) { |
| 913 | struct fb_event event; |
| 914 | |
| 915 | event.info = info; |
| 916 | event.data = &mode1; |
Antonino A. Daplas | 256154f | 2006-07-30 03:04:17 -0700 | [diff] [blame] | 917 | ret = fb_notifier_call_chain(FB_EVENT_MODE_DELETE, &event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | if (!ret) |
| 921 | fb_delete_videomode(&mode1, &info->modelist); |
| 922 | |
Antonino A. Daplas | b1e7223 | 2007-05-08 00:39:52 -0700 | [diff] [blame] | 923 | |
| 924 | ret = (ret) ? -EINVAL : 0; |
| 925 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | if ((var->activate & FB_ACTIVATE_FORCE) || |
| 929 | memcmp(&info->var, var, sizeof(struct fb_var_screeninfo))) { |
Antonino A. Daplas | 4941cb7 | 2007-05-08 00:39:22 -0700 | [diff] [blame] | 930 | u32 activate = var->activate; |
| 931 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | if (!info->fbops->fb_check_var) { |
| 933 | *var = info->var; |
Antonino A. Daplas | b1e7223 | 2007-05-08 00:39:52 -0700 | [diff] [blame] | 934 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | } |
| 936 | |
Antonino A. Daplas | b1e7223 | 2007-05-08 00:39:52 -0700 | [diff] [blame] | 937 | ret = info->fbops->fb_check_var(var, info); |
| 938 | |
| 939 | if (ret) |
| 940 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | |
| 942 | if ((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) { |
| 943 | struct fb_videomode mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | |
Antonino A. Daplas | 38a3dc5 | 2007-05-08 00:39:37 -0700 | [diff] [blame] | 945 | if (info->fbops->fb_get_caps) { |
Antonino A. Daplas | b1e7223 | 2007-05-08 00:39:52 -0700 | [diff] [blame] | 946 | ret = fb_check_caps(info, var, activate); |
Antonino A. Daplas | 38a3dc5 | 2007-05-08 00:39:37 -0700 | [diff] [blame] | 947 | |
Antonino A. Daplas | b1e7223 | 2007-05-08 00:39:52 -0700 | [diff] [blame] | 948 | if (ret) |
Antonino A. Daplas | 38a3dc5 | 2007-05-08 00:39:37 -0700 | [diff] [blame] | 949 | goto done; |
| 950 | } |
| 951 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | info->var = *var; |
Antonino A. Daplas | 38a3dc5 | 2007-05-08 00:39:37 -0700 | [diff] [blame] | 953 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | if (info->fbops->fb_set_par) |
| 955 | info->fbops->fb_set_par(info); |
| 956 | |
| 957 | fb_pan_display(info, &info->var); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | fb_set_cmap(&info->cmap, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | fb_var_to_videomode(&mode, &info->var); |
| 960 | |
| 961 | if (info->modelist.prev && info->modelist.next && |
| 962 | !list_empty(&info->modelist)) |
Antonino A. Daplas | b1e7223 | 2007-05-08 00:39:52 -0700 | [diff] [blame] | 963 | ret = fb_add_videomode(&mode, &info->modelist); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | |
Antonino A. Daplas | b1e7223 | 2007-05-08 00:39:52 -0700 | [diff] [blame] | 965 | if (!ret && (flags & FBINFO_MISC_USEREVENT)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | struct fb_event event; |
Antonino A. Daplas | 4941cb7 | 2007-05-08 00:39:22 -0700 | [diff] [blame] | 967 | int evnt = (activate & FB_ACTIVATE_ALL) ? |
Antonino A. Daplas | 7726e9e | 2005-09-09 13:04:29 -0700 | [diff] [blame] | 968 | FB_EVENT_MODE_CHANGE_ALL : |
| 969 | FB_EVENT_MODE_CHANGE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | |
| 971 | info->flags &= ~FBINFO_MISC_USEREVENT; |
| 972 | event.info = info; |
Eric Miao | faa312d | 2008-08-29 04:18:43 +0800 | [diff] [blame] | 973 | event.data = &mode; |
Antonino A. Daplas | 256154f | 2006-07-30 03:04:17 -0700 | [diff] [blame] | 974 | fb_notifier_call_chain(evnt, &event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | } |
| 976 | } |
| 977 | } |
Antonino A. Daplas | 38a3dc5 | 2007-05-08 00:39:37 -0700 | [diff] [blame] | 978 | |
| 979 | done: |
Antonino A. Daplas | b1e7223 | 2007-05-08 00:39:52 -0700 | [diff] [blame] | 980 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | int |
| 984 | fb_blank(struct fb_info *info, int blank) |
| 985 | { |
| 986 | int ret = -EINVAL; |
| 987 | |
| 988 | if (blank > FB_BLANK_POWERDOWN) |
| 989 | blank = FB_BLANK_POWERDOWN; |
| 990 | |
| 991 | if (info->fbops->fb_blank) |
| 992 | ret = info->fbops->fb_blank(blank, info); |
| 993 | |
| 994 | if (!ret) { |
| 995 | struct fb_event event; |
| 996 | |
| 997 | event.info = info; |
| 998 | event.data = ␣ |
Antonino A. Daplas | 256154f | 2006-07-30 03:04:17 -0700 | [diff] [blame] | 999 | fb_notifier_call_chain(FB_EVENT_BLANK, &event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | return ret; |
| 1003 | } |
| 1004 | |
Alan Cox | e536771 | 2008-10-18 20:27:51 -0700 | [diff] [blame] | 1005 | static long |
| 1006 | fb_ioctl(struct file *file, unsigned int cmd, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | unsigned long arg) |
| 1008 | { |
Alan Cox | e536771 | 2008-10-18 20:27:51 -0700 | [diff] [blame] | 1009 | struct inode *inode = file->f_path.dentry->d_inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | int fbidx = iminor(inode); |
Alan Cox | e536771 | 2008-10-18 20:27:51 -0700 | [diff] [blame] | 1011 | struct fb_info *info; |
| 1012 | struct fb_ops *fb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | struct fb_var_screeninfo var; |
| 1014 | struct fb_fix_screeninfo fix; |
| 1015 | struct fb_con2fbmap con2fb; |
| 1016 | struct fb_cmap_user cmap; |
| 1017 | struct fb_event event; |
| 1018 | void __user *argp = (void __user *)arg; |
Alan Cox | e536771 | 2008-10-18 20:27:51 -0700 | [diff] [blame] | 1019 | long ret = 0; |
| 1020 | |
Alan Cox | e536771 | 2008-10-18 20:27:51 -0700 | [diff] [blame] | 1021 | info = registered_fb[fbidx]; |
Krzysztof Helt | 3e680aa | 2008-10-18 20:27:51 -0700 | [diff] [blame^] | 1022 | mutex_lock(&info->lock); |
Alan Cox | e536771 | 2008-10-18 20:27:51 -0700 | [diff] [blame] | 1023 | fb = info->fbops; |
| 1024 | |
| 1025 | if (!fb) { |
Krzysztof Helt | 3e680aa | 2008-10-18 20:27:51 -0700 | [diff] [blame^] | 1026 | mutex_unlock(&info->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | return -ENODEV; |
Alan Cox | e536771 | 2008-10-18 20:27:51 -0700 | [diff] [blame] | 1028 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | switch (cmd) { |
| 1030 | case FBIOGET_VSCREENINFO: |
Alan Cox | e536771 | 2008-10-18 20:27:51 -0700 | [diff] [blame] | 1031 | ret = copy_to_user(argp, &info->var, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | sizeof(var)) ? -EFAULT : 0; |
Alan Cox | e536771 | 2008-10-18 20:27:51 -0700 | [diff] [blame] | 1033 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | case FBIOPUT_VSCREENINFO: |
Alan Cox | e536771 | 2008-10-18 20:27:51 -0700 | [diff] [blame] | 1035 | if (copy_from_user(&var, argp, sizeof(var))) { |
| 1036 | ret = -EFAULT; |
| 1037 | break; |
| 1038 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | acquire_console_sem(); |
| 1040 | info->flags |= FBINFO_MISC_USEREVENT; |
Alan Cox | e536771 | 2008-10-18 20:27:51 -0700 | [diff] [blame] | 1041 | ret = fb_set_var(info, &var); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | info->flags &= ~FBINFO_MISC_USEREVENT; |
| 1043 | release_console_sem(); |
Alan Cox | e536771 | 2008-10-18 20:27:51 -0700 | [diff] [blame] | 1044 | if (ret == 0 && copy_to_user(argp, &var, sizeof(var))) |
| 1045 | ret = -EFAULT; |
| 1046 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | case FBIOGET_FSCREENINFO: |
Alan Cox | e536771 | 2008-10-18 20:27:51 -0700 | [diff] [blame] | 1048 | ret = copy_to_user(argp, &info->fix, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | sizeof(fix)) ? -EFAULT : 0; |
Alan Cox | e536771 | 2008-10-18 20:27:51 -0700 | [diff] [blame] | 1050 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | case FBIOPUTCMAP: |
| 1052 | if (copy_from_user(&cmap, argp, sizeof(cmap))) |
Alan Cox | e536771 | 2008-10-18 20:27:51 -0700 | [diff] [blame] | 1053 | ret = -EFAULT; |
| 1054 | else |
| 1055 | ret = fb_set_user_cmap(&cmap, info); |
| 1056 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | case FBIOGETCMAP: |
| 1058 | if (copy_from_user(&cmap, argp, sizeof(cmap))) |
Alan Cox | e536771 | 2008-10-18 20:27:51 -0700 | [diff] [blame] | 1059 | ret = -EFAULT; |
| 1060 | else |
| 1061 | ret = fb_cmap_to_user(&info->cmap, &cmap); |
| 1062 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | case FBIOPAN_DISPLAY: |
Alan Cox | e536771 | 2008-10-18 20:27:51 -0700 | [diff] [blame] | 1064 | if (copy_from_user(&var, argp, sizeof(var))) { |
| 1065 | ret = -EFAULT; |
| 1066 | break; |
| 1067 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | acquire_console_sem(); |
Alan Cox | e536771 | 2008-10-18 20:27:51 -0700 | [diff] [blame] | 1069 | ret = fb_pan_display(info, &var); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | release_console_sem(); |
Alan Cox | e536771 | 2008-10-18 20:27:51 -0700 | [diff] [blame] | 1071 | if (ret == 0 && copy_to_user(argp, &var, sizeof(var))) |
| 1072 | ret = -EFAULT; |
| 1073 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | case FBIO_CURSOR: |
Alan Cox | e536771 | 2008-10-18 20:27:51 -0700 | [diff] [blame] | 1075 | ret = -EINVAL; |
| 1076 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | case FBIOGET_CON2FBMAP: |
| 1078 | if (copy_from_user(&con2fb, argp, sizeof(con2fb))) |
Alan Cox | e536771 | 2008-10-18 20:27:51 -0700 | [diff] [blame] | 1079 | ret = -EFAULT; |
| 1080 | else if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES) |
| 1081 | ret = -EINVAL; |
| 1082 | else { |
| 1083 | con2fb.framebuffer = -1; |
| 1084 | event.info = info; |
| 1085 | event.data = &con2fb; |
| 1086 | fb_notifier_call_chain(FB_EVENT_GET_CONSOLE_MAP, |
| 1087 | &event); |
| 1088 | ret = copy_to_user(argp, &con2fb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1089 | sizeof(con2fb)) ? -EFAULT : 0; |
Alan Cox | e536771 | 2008-10-18 20:27:51 -0700 | [diff] [blame] | 1090 | } |
| 1091 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | case FBIOPUT_CON2FBMAP: |
Alan Cox | e536771 | 2008-10-18 20:27:51 -0700 | [diff] [blame] | 1093 | if (copy_from_user(&con2fb, argp, sizeof(con2fb))) { |
| 1094 | ret = -EFAULT; |
| 1095 | break; |
| 1096 | } |
| 1097 | if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES) { |
| 1098 | ret = -EINVAL; |
| 1099 | break; |
| 1100 | } |
| 1101 | if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX) { |
| 1102 | ret = -EINVAL; |
| 1103 | break; |
| 1104 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | if (!registered_fb[con2fb.framebuffer]) |
Alan Cox | e536771 | 2008-10-18 20:27:51 -0700 | [diff] [blame] | 1106 | request_module("fb%d", con2fb.framebuffer); |
| 1107 | if (!registered_fb[con2fb.framebuffer]) { |
| 1108 | ret = -EINVAL; |
| 1109 | break; |
| 1110 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | event.info = info; |
| 1112 | event.data = &con2fb; |
Alan Cox | e536771 | 2008-10-18 20:27:51 -0700 | [diff] [blame] | 1113 | ret = fb_notifier_call_chain(FB_EVENT_SET_CONSOLE_MAP, |
Antonino A. Daplas | 256154f | 2006-07-30 03:04:17 -0700 | [diff] [blame] | 1114 | &event); |
Alan Cox | e536771 | 2008-10-18 20:27:51 -0700 | [diff] [blame] | 1115 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | case FBIOBLANK: |
| 1117 | acquire_console_sem(); |
| 1118 | info->flags |= FBINFO_MISC_USEREVENT; |
Alan Cox | e536771 | 2008-10-18 20:27:51 -0700 | [diff] [blame] | 1119 | ret = fb_blank(info, arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1120 | info->flags &= ~FBINFO_MISC_USEREVENT; |
| 1121 | release_console_sem(); |
Alan Cox | e536771 | 2008-10-18 20:27:51 -0700 | [diff] [blame] | 1122 | break;; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | default: |
| 1124 | if (fb->fb_ioctl == NULL) |
Alan Cox | e536771 | 2008-10-18 20:27:51 -0700 | [diff] [blame] | 1125 | ret = -ENOTTY; |
| 1126 | else |
| 1127 | ret = fb->fb_ioctl(info, cmd, arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | } |
Krzysztof Helt | 3e680aa | 2008-10-18 20:27:51 -0700 | [diff] [blame^] | 1129 | mutex_unlock(&info->lock); |
Alan Cox | e536771 | 2008-10-18 20:27:51 -0700 | [diff] [blame] | 1130 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | } |
| 1132 | |
| 1133 | #ifdef CONFIG_COMPAT |
Arnd Bergmann | c7f82d9 | 2005-11-08 21:39:19 -0800 | [diff] [blame] | 1134 | struct fb_fix_screeninfo32 { |
| 1135 | char id[16]; |
| 1136 | compat_caddr_t smem_start; |
| 1137 | u32 smem_len; |
| 1138 | u32 type; |
| 1139 | u32 type_aux; |
| 1140 | u32 visual; |
| 1141 | u16 xpanstep; |
| 1142 | u16 ypanstep; |
| 1143 | u16 ywrapstep; |
| 1144 | u32 line_length; |
| 1145 | compat_caddr_t mmio_start; |
| 1146 | u32 mmio_len; |
| 1147 | u32 accel; |
| 1148 | u16 reserved[3]; |
| 1149 | }; |
| 1150 | |
| 1151 | struct fb_cmap32 { |
| 1152 | u32 start; |
| 1153 | u32 len; |
| 1154 | compat_caddr_t red; |
| 1155 | compat_caddr_t green; |
| 1156 | compat_caddr_t blue; |
| 1157 | compat_caddr_t transp; |
| 1158 | }; |
| 1159 | |
| 1160 | static int fb_getput_cmap(struct inode *inode, struct file *file, |
| 1161 | unsigned int cmd, unsigned long arg) |
| 1162 | { |
| 1163 | struct fb_cmap_user __user *cmap; |
| 1164 | struct fb_cmap32 __user *cmap32; |
| 1165 | __u32 data; |
| 1166 | int err; |
| 1167 | |
| 1168 | cmap = compat_alloc_user_space(sizeof(*cmap)); |
| 1169 | cmap32 = compat_ptr(arg); |
| 1170 | |
| 1171 | if (copy_in_user(&cmap->start, &cmap32->start, 2 * sizeof(__u32))) |
| 1172 | return -EFAULT; |
| 1173 | |
| 1174 | if (get_user(data, &cmap32->red) || |
| 1175 | put_user(compat_ptr(data), &cmap->red) || |
| 1176 | get_user(data, &cmap32->green) || |
| 1177 | put_user(compat_ptr(data), &cmap->green) || |
| 1178 | get_user(data, &cmap32->blue) || |
| 1179 | put_user(compat_ptr(data), &cmap->blue) || |
| 1180 | get_user(data, &cmap32->transp) || |
| 1181 | put_user(compat_ptr(data), &cmap->transp)) |
| 1182 | return -EFAULT; |
| 1183 | |
Alan Cox | e536771 | 2008-10-18 20:27:51 -0700 | [diff] [blame] | 1184 | err = fb_ioctl(file, cmd, (unsigned long) cmap); |
Arnd Bergmann | c7f82d9 | 2005-11-08 21:39:19 -0800 | [diff] [blame] | 1185 | |
| 1186 | if (!err) { |
| 1187 | if (copy_in_user(&cmap32->start, |
| 1188 | &cmap->start, |
| 1189 | 2 * sizeof(__u32))) |
| 1190 | err = -EFAULT; |
| 1191 | } |
| 1192 | return err; |
| 1193 | } |
| 1194 | |
| 1195 | static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix, |
| 1196 | struct fb_fix_screeninfo32 __user *fix32) |
| 1197 | { |
| 1198 | __u32 data; |
| 1199 | int err; |
| 1200 | |
| 1201 | err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id)); |
| 1202 | |
| 1203 | data = (__u32) (unsigned long) fix->smem_start; |
| 1204 | err |= put_user(data, &fix32->smem_start); |
| 1205 | |
| 1206 | err |= put_user(fix->smem_len, &fix32->smem_len); |
| 1207 | err |= put_user(fix->type, &fix32->type); |
| 1208 | err |= put_user(fix->type_aux, &fix32->type_aux); |
| 1209 | err |= put_user(fix->visual, &fix32->visual); |
| 1210 | err |= put_user(fix->xpanstep, &fix32->xpanstep); |
| 1211 | err |= put_user(fix->ypanstep, &fix32->ypanstep); |
| 1212 | err |= put_user(fix->ywrapstep, &fix32->ywrapstep); |
| 1213 | err |= put_user(fix->line_length, &fix32->line_length); |
| 1214 | |
| 1215 | data = (__u32) (unsigned long) fix->mmio_start; |
| 1216 | err |= put_user(data, &fix32->mmio_start); |
| 1217 | |
| 1218 | err |= put_user(fix->mmio_len, &fix32->mmio_len); |
| 1219 | err |= put_user(fix->accel, &fix32->accel); |
| 1220 | err |= copy_to_user(fix32->reserved, fix->reserved, |
| 1221 | sizeof(fix->reserved)); |
| 1222 | |
| 1223 | return err; |
| 1224 | } |
| 1225 | |
| 1226 | static int fb_get_fscreeninfo(struct inode *inode, struct file *file, |
| 1227 | unsigned int cmd, unsigned long arg) |
| 1228 | { |
| 1229 | mm_segment_t old_fs; |
| 1230 | struct fb_fix_screeninfo fix; |
| 1231 | struct fb_fix_screeninfo32 __user *fix32; |
| 1232 | int err; |
| 1233 | |
| 1234 | fix32 = compat_ptr(arg); |
| 1235 | |
| 1236 | old_fs = get_fs(); |
| 1237 | set_fs(KERNEL_DS); |
Alan Cox | e536771 | 2008-10-18 20:27:51 -0700 | [diff] [blame] | 1238 | err = fb_ioctl(file, cmd, (unsigned long) &fix); |
Arnd Bergmann | c7f82d9 | 2005-11-08 21:39:19 -0800 | [diff] [blame] | 1239 | set_fs(old_fs); |
| 1240 | |
| 1241 | if (!err) |
| 1242 | err = do_fscreeninfo_to_user(&fix, fix32); |
| 1243 | |
| 1244 | return err; |
| 1245 | } |
| 1246 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1247 | static long |
| 1248 | fb_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
| 1249 | { |
Josef Sipek | ad9a824 | 2006-12-08 02:37:48 -0800 | [diff] [blame] | 1250 | struct inode *inode = file->f_path.dentry->d_inode; |
Arnd Bergmann | c7f82d9 | 2005-11-08 21:39:19 -0800 | [diff] [blame] | 1251 | int fbidx = iminor(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1252 | struct fb_info *info = registered_fb[fbidx]; |
| 1253 | struct fb_ops *fb = info->fbops; |
Arnd Bergmann | c7f82d9 | 2005-11-08 21:39:19 -0800 | [diff] [blame] | 1254 | long ret = -ENOIOCTLCMD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1255 | |
Krzysztof Helt | 3e680aa | 2008-10-18 20:27:51 -0700 | [diff] [blame^] | 1256 | mutex_lock(&info->lock); |
Arnd Bergmann | c7f82d9 | 2005-11-08 21:39:19 -0800 | [diff] [blame] | 1257 | switch(cmd) { |
| 1258 | case FBIOGET_VSCREENINFO: |
| 1259 | case FBIOPUT_VSCREENINFO: |
| 1260 | case FBIOPAN_DISPLAY: |
| 1261 | case FBIOGET_CON2FBMAP: |
| 1262 | case FBIOPUT_CON2FBMAP: |
| 1263 | arg = (unsigned long) compat_ptr(arg); |
| 1264 | case FBIOBLANK: |
Alan Cox | e536771 | 2008-10-18 20:27:51 -0700 | [diff] [blame] | 1265 | ret = fb_ioctl(file, cmd, arg); |
Arnd Bergmann | c7f82d9 | 2005-11-08 21:39:19 -0800 | [diff] [blame] | 1266 | break; |
| 1267 | |
| 1268 | case FBIOGET_FSCREENINFO: |
| 1269 | ret = fb_get_fscreeninfo(inode, file, cmd, arg); |
| 1270 | break; |
| 1271 | |
| 1272 | case FBIOGETCMAP: |
| 1273 | case FBIOPUTCMAP: |
| 1274 | ret = fb_getput_cmap(inode, file, cmd, arg); |
| 1275 | break; |
| 1276 | |
| 1277 | default: |
| 1278 | if (fb->fb_compat_ioctl) |
Christoph Hellwig | 67a6680 | 2006-01-14 13:21:25 -0800 | [diff] [blame] | 1279 | ret = fb->fb_compat_ioctl(info, cmd, arg); |
Arnd Bergmann | c7f82d9 | 2005-11-08 21:39:19 -0800 | [diff] [blame] | 1280 | break; |
| 1281 | } |
Krzysztof Helt | 3e680aa | 2008-10-18 20:27:51 -0700 | [diff] [blame^] | 1282 | mutex_unlock(&info->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1283 | return ret; |
| 1284 | } |
| 1285 | #endif |
| 1286 | |
Antonino A. Daplas | 10eb265 | 2007-07-17 04:05:27 -0700 | [diff] [blame] | 1287 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | fb_mmap(struct file *file, struct vm_area_struct * vma) |
| 1289 | { |
Josef Sipek | ad9a824 | 2006-12-08 02:37:48 -0800 | [diff] [blame] | 1290 | int fbidx = iminor(file->f_path.dentry->d_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | struct fb_info *info = registered_fb[fbidx]; |
| 1292 | struct fb_ops *fb = info->fbops; |
| 1293 | unsigned long off; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1294 | unsigned long start; |
| 1295 | u32 len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1296 | |
| 1297 | if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT)) |
| 1298 | return -EINVAL; |
| 1299 | off = vma->vm_pgoff << PAGE_SHIFT; |
| 1300 | if (!fb) |
| 1301 | return -ENODEV; |
| 1302 | if (fb->fb_mmap) { |
| 1303 | int res; |
Krzysztof Helt | 3e680aa | 2008-10-18 20:27:51 -0700 | [diff] [blame^] | 1304 | mutex_lock(&info->lock); |
Christoph Hellwig | 216d526 | 2006-01-14 13:21:25 -0800 | [diff] [blame] | 1305 | res = fb->fb_mmap(info, vma); |
Krzysztof Helt | 3e680aa | 2008-10-18 20:27:51 -0700 | [diff] [blame^] | 1306 | mutex_unlock(&info->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1307 | return res; |
| 1308 | } |
| 1309 | |
Krzysztof Helt | 3e680aa | 2008-10-18 20:27:51 -0700 | [diff] [blame^] | 1310 | mutex_lock(&info->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1311 | |
| 1312 | /* frame buffer memory */ |
| 1313 | start = info->fix.smem_start; |
| 1314 | len = PAGE_ALIGN((start & ~PAGE_MASK) + info->fix.smem_len); |
| 1315 | if (off >= len) { |
| 1316 | /* memory mapped io */ |
| 1317 | off -= len; |
| 1318 | if (info->var.accel_flags) { |
Krzysztof Helt | 3e680aa | 2008-10-18 20:27:51 -0700 | [diff] [blame^] | 1319 | mutex_unlock(&info->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | return -EINVAL; |
| 1321 | } |
| 1322 | start = info->fix.mmio_start; |
| 1323 | len = PAGE_ALIGN((start & ~PAGE_MASK) + info->fix.mmio_len); |
| 1324 | } |
Krzysztof Helt | 3e680aa | 2008-10-18 20:27:51 -0700 | [diff] [blame^] | 1325 | mutex_unlock(&info->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1326 | start &= PAGE_MASK; |
| 1327 | if ((vma->vm_end - vma->vm_start + off) > len) |
| 1328 | return -EINVAL; |
| 1329 | off += start; |
| 1330 | vma->vm_pgoff = off >> PAGE_SHIFT; |
| 1331 | /* This is an IO map - tell maydump to skip this VMA */ |
| 1332 | vma->vm_flags |= VM_IO | VM_RESERVED; |
Antonino A. Daplas | 10eb265 | 2007-07-17 04:05:27 -0700 | [diff] [blame] | 1333 | fb_pgprotect(file, vma, off); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1334 | if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT, |
| 1335 | vma->vm_end - vma->vm_start, vma->vm_page_prot)) |
| 1336 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1338 | } |
| 1339 | |
| 1340 | static int |
| 1341 | fb_open(struct inode *inode, struct file *file) |
| 1342 | { |
| 1343 | int fbidx = iminor(inode); |
| 1344 | struct fb_info *info; |
| 1345 | int res = 0; |
| 1346 | |
| 1347 | if (fbidx >= FB_MAX) |
| 1348 | return -ENODEV; |
Krzysztof Helt | 3e680aa | 2008-10-18 20:27:51 -0700 | [diff] [blame^] | 1349 | info = registered_fb[fbidx]; |
| 1350 | if (!info) |
Johannes Berg | a65e5d7 | 2008-07-09 10:28:38 +0200 | [diff] [blame] | 1351 | request_module("fb%d", fbidx); |
Krzysztof Helt | 3e680aa | 2008-10-18 20:27:51 -0700 | [diff] [blame^] | 1352 | info = registered_fb[fbidx]; |
| 1353 | if (!info) |
| 1354 | return -ENODEV; |
| 1355 | mutex_lock(&info->lock); |
Jonathan Corbet | fc7f687 | 2008-05-15 16:30:36 -0600 | [diff] [blame] | 1356 | if (!try_module_get(info->fbops->owner)) { |
| 1357 | res = -ENODEV; |
| 1358 | goto out; |
| 1359 | } |
Thomas Koeller | cae8a12 | 2006-01-09 20:53:48 -0800 | [diff] [blame] | 1360 | file->private_data = info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1361 | if (info->fbops->fb_open) { |
| 1362 | res = info->fbops->fb_open(info,1); |
| 1363 | if (res) |
| 1364 | module_put(info->fbops->owner); |
| 1365 | } |
Ian Campbell | d847471 | 2008-08-20 14:09:23 -0700 | [diff] [blame] | 1366 | #ifdef CONFIG_FB_DEFERRED_IO |
| 1367 | if (info->fbdefio) |
| 1368 | fb_deferred_io_open(info, inode, file); |
| 1369 | #endif |
Jonathan Corbet | fc7f687 | 2008-05-15 16:30:36 -0600 | [diff] [blame] | 1370 | out: |
Krzysztof Helt | 3e680aa | 2008-10-18 20:27:51 -0700 | [diff] [blame^] | 1371 | mutex_unlock(&info->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1372 | return res; |
| 1373 | } |
| 1374 | |
| 1375 | static int |
| 1376 | fb_release(struct inode *inode, struct file *file) |
| 1377 | { |
Thomas Koeller | cae8a12 | 2006-01-09 20:53:48 -0800 | [diff] [blame] | 1378 | struct fb_info * const info = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | |
Krzysztof Helt | 3e680aa | 2008-10-18 20:27:51 -0700 | [diff] [blame^] | 1380 | mutex_lock(&info->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | if (info->fbops->fb_release) |
| 1382 | info->fbops->fb_release(info,1); |
| 1383 | module_put(info->fbops->owner); |
Krzysztof Helt | 3e680aa | 2008-10-18 20:27:51 -0700 | [diff] [blame^] | 1384 | mutex_unlock(&info->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1385 | return 0; |
| 1386 | } |
| 1387 | |
Helge Deller | 0128bee | 2006-12-08 02:40:29 -0800 | [diff] [blame] | 1388 | static const struct file_operations fb_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | .owner = THIS_MODULE, |
| 1390 | .read = fb_read, |
| 1391 | .write = fb_write, |
Alan Cox | e536771 | 2008-10-18 20:27:51 -0700 | [diff] [blame] | 1392 | .unlocked_ioctl = fb_ioctl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1393 | #ifdef CONFIG_COMPAT |
| 1394 | .compat_ioctl = fb_compat_ioctl, |
| 1395 | #endif |
| 1396 | .mmap = fb_mmap, |
| 1397 | .open = fb_open, |
| 1398 | .release = fb_release, |
| 1399 | #ifdef HAVE_ARCH_FB_UNMAPPED_AREA |
| 1400 | .get_unmapped_area = get_fb_unmapped_area, |
| 1401 | #endif |
Paul Mundt | 5e841b8 | 2007-05-08 00:37:41 -0700 | [diff] [blame] | 1402 | #ifdef CONFIG_FB_DEFERRED_IO |
| 1403 | .fsync = fb_deferred_io_fsync, |
| 1404 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1405 | }; |
| 1406 | |
Antonino A. Daplas | 9a17917 | 2006-06-26 00:27:05 -0700 | [diff] [blame] | 1407 | struct class *fb_class; |
| 1408 | EXPORT_SYMBOL(fb_class); |
Anton Vorontsov | e4c690e | 2008-04-28 02:14:49 -0700 | [diff] [blame] | 1409 | |
| 1410 | static int fb_check_foreignness(struct fb_info *fi) |
| 1411 | { |
| 1412 | const bool foreign_endian = fi->flags & FBINFO_FOREIGN_ENDIAN; |
| 1413 | |
| 1414 | fi->flags &= ~FBINFO_FOREIGN_ENDIAN; |
| 1415 | |
| 1416 | #ifdef __BIG_ENDIAN |
| 1417 | fi->flags |= foreign_endian ? 0 : FBINFO_BE_MATH; |
| 1418 | #else |
| 1419 | fi->flags |= foreign_endian ? FBINFO_BE_MATH : 0; |
| 1420 | #endif /* __BIG_ENDIAN */ |
| 1421 | |
| 1422 | if (fi->flags & FBINFO_BE_MATH && !fb_be_math(fi)) { |
| 1423 | pr_err("%s: enable CONFIG_FB_BIG_ENDIAN to " |
| 1424 | "support this framebuffer\n", fi->fix.id); |
| 1425 | return -ENOSYS; |
| 1426 | } else if (!(fi->flags & FBINFO_BE_MATH) && fb_be_math(fi)) { |
| 1427 | pr_err("%s: enable CONFIG_FB_LITTLE_ENDIAN to " |
| 1428 | "support this framebuffer\n", fi->fix.id); |
| 1429 | return -ENOSYS; |
| 1430 | } |
| 1431 | |
| 1432 | return 0; |
| 1433 | } |
| 1434 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1435 | /** |
| 1436 | * register_framebuffer - registers a frame buffer device |
| 1437 | * @fb_info: frame buffer info structure |
| 1438 | * |
| 1439 | * Registers a frame buffer device @fb_info. |
| 1440 | * |
| 1441 | * Returns negative errno on error, or zero for success. |
| 1442 | * |
| 1443 | */ |
| 1444 | |
| 1445 | int |
| 1446 | register_framebuffer(struct fb_info *fb_info) |
| 1447 | { |
| 1448 | int i; |
| 1449 | struct fb_event event; |
Antonino A. Daplas | 96fe6a2 | 2005-09-09 13:09:58 -0700 | [diff] [blame] | 1450 | struct fb_videomode mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | |
| 1452 | if (num_registered_fb == FB_MAX) |
| 1453 | return -ENXIO; |
Anton Vorontsov | e4c690e | 2008-04-28 02:14:49 -0700 | [diff] [blame] | 1454 | |
| 1455 | if (fb_check_foreignness(fb_info)) |
| 1456 | return -ENOSYS; |
| 1457 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 | num_registered_fb++; |
| 1459 | for (i = 0 ; i < FB_MAX; i++) |
| 1460 | if (!registered_fb[i]) |
| 1461 | break; |
| 1462 | fb_info->node = i; |
Krzysztof Helt | 3e680aa | 2008-10-18 20:27:51 -0700 | [diff] [blame^] | 1463 | mutex_init(&fb_info->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | |
Greg Kroah-Hartman | 77997aa | 2008-07-21 20:03:34 -0700 | [diff] [blame] | 1465 | fb_info->dev = device_create(fb_class, fb_info->device, |
| 1466 | MKDEV(FB_MAJOR, i), NULL, "fb%d", i); |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 1467 | if (IS_ERR(fb_info->dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1468 | /* Not fatal */ |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 1469 | printk(KERN_WARNING "Unable to create device for framebuffer %d; errno = %ld\n", i, PTR_ERR(fb_info->dev)); |
| 1470 | fb_info->dev = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1471 | } else |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 1472 | fb_init_device(fb_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1473 | |
| 1474 | if (fb_info->pixmap.addr == NULL) { |
| 1475 | fb_info->pixmap.addr = kmalloc(FBPIXMAPSIZE, GFP_KERNEL); |
| 1476 | if (fb_info->pixmap.addr) { |
| 1477 | fb_info->pixmap.size = FBPIXMAPSIZE; |
| 1478 | fb_info->pixmap.buf_align = 1; |
| 1479 | fb_info->pixmap.scan_align = 1; |
James Simmons | 58a6064 | 2005-06-21 17:17:08 -0700 | [diff] [blame] | 1480 | fb_info->pixmap.access_align = 32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1481 | fb_info->pixmap.flags = FB_PIXMAP_DEFAULT; |
| 1482 | } |
| 1483 | } |
| 1484 | fb_info->pixmap.offset = 0; |
| 1485 | |
Antonino A. Daplas | bf26ad7 | 2007-05-08 00:39:09 -0700 | [diff] [blame] | 1486 | if (!fb_info->pixmap.blit_x) |
| 1487 | fb_info->pixmap.blit_x = ~(u32)0; |
| 1488 | |
| 1489 | if (!fb_info->pixmap.blit_y) |
| 1490 | fb_info->pixmap.blit_y = ~(u32)0; |
| 1491 | |
Antonino A. Daplas | 96fe6a2 | 2005-09-09 13:09:58 -0700 | [diff] [blame] | 1492 | if (!fb_info->modelist.prev || !fb_info->modelist.next) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1493 | INIT_LIST_HEAD(&fb_info->modelist); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1494 | |
Antonino A. Daplas | 96fe6a2 | 2005-09-09 13:09:58 -0700 | [diff] [blame] | 1495 | fb_var_to_videomode(&mode, &fb_info->var); |
| 1496 | fb_add_videomode(&mode, &fb_info->modelist); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1497 | registered_fb[i] = fb_info; |
| 1498 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1499 | event.info = fb_info; |
Antonino A. Daplas | 256154f | 2006-07-30 03:04:17 -0700 | [diff] [blame] | 1500 | fb_notifier_call_chain(FB_EVENT_FB_REGISTERED, &event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1501 | return 0; |
| 1502 | } |
| 1503 | |
| 1504 | |
| 1505 | /** |
| 1506 | * unregister_framebuffer - releases a frame buffer device |
| 1507 | * @fb_info: frame buffer info structure |
| 1508 | * |
| 1509 | * Unregisters a frame buffer device @fb_info. |
| 1510 | * |
| 1511 | * Returns negative errno on error, or zero for success. |
| 1512 | * |
Jesse Barnes | cfafca8 | 2007-07-17 04:05:33 -0700 | [diff] [blame] | 1513 | * This function will also notify the framebuffer console |
| 1514 | * to release the driver. |
| 1515 | * |
| 1516 | * This is meant to be called within a driver's module_exit() |
| 1517 | * function. If this is called outside module_exit(), ensure |
| 1518 | * that the driver implements fb_open() and fb_release() to |
| 1519 | * check that no processes are using the device. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 | */ |
| 1521 | |
| 1522 | int |
| 1523 | unregister_framebuffer(struct fb_info *fb_info) |
| 1524 | { |
Antonino A. Daplas | e614b18 | 2006-06-26 00:27:09 -0700 | [diff] [blame] | 1525 | struct fb_event event; |
Jesse Barnes | cfafca8 | 2007-07-17 04:05:33 -0700 | [diff] [blame] | 1526 | int i, ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1527 | |
| 1528 | i = fb_info->node; |
Jesse Barnes | cfafca8 | 2007-07-17 04:05:33 -0700 | [diff] [blame] | 1529 | if (!registered_fb[i]) { |
| 1530 | ret = -EINVAL; |
| 1531 | goto done; |
| 1532 | } |
| 1533 | |
| 1534 | event.info = fb_info; |
| 1535 | ret = fb_notifier_call_chain(FB_EVENT_FB_UNBIND, &event); |
| 1536 | |
| 1537 | if (ret) { |
| 1538 | ret = -EINVAL; |
| 1539 | goto done; |
| 1540 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1541 | |
Antonino A. Daplas | e614b18 | 2006-06-26 00:27:09 -0700 | [diff] [blame] | 1542 | if (fb_info->pixmap.addr && |
| 1543 | (fb_info->pixmap.flags & FB_PIXMAP_DEFAULT)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1544 | kfree(fb_info->pixmap.addr); |
| 1545 | fb_destroy_modelist(&fb_info->modelist); |
| 1546 | registered_fb[i]=NULL; |
| 1547 | num_registered_fb--; |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 1548 | fb_cleanup_device(fb_info); |
| 1549 | device_destroy(fb_class, MKDEV(FB_MAJOR, i)); |
Antonino A. Daplas | e614b18 | 2006-06-26 00:27:09 -0700 | [diff] [blame] | 1550 | event.info = fb_info; |
Antonino A. Daplas | 256154f | 2006-07-30 03:04:17 -0700 | [diff] [blame] | 1551 | fb_notifier_call_chain(FB_EVENT_FB_UNREGISTERED, &event); |
Jesse Barnes | cfafca8 | 2007-07-17 04:05:33 -0700 | [diff] [blame] | 1552 | done: |
| 1553 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1554 | } |
| 1555 | |
| 1556 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1557 | * fb_set_suspend - low level driver signals suspend |
| 1558 | * @info: framebuffer affected |
| 1559 | * @state: 0 = resuming, !=0 = suspending |
| 1560 | * |
| 1561 | * This is meant to be used by low level drivers to |
| 1562 | * signal suspend/resume to the core & clients. |
| 1563 | * It must be called with the console semaphore held |
| 1564 | */ |
| 1565 | void fb_set_suspend(struct fb_info *info, int state) |
| 1566 | { |
| 1567 | struct fb_event event; |
| 1568 | |
| 1569 | event.info = info; |
| 1570 | if (state) { |
Antonino A. Daplas | 256154f | 2006-07-30 03:04:17 -0700 | [diff] [blame] | 1571 | fb_notifier_call_chain(FB_EVENT_SUSPEND, &event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1572 | info->state = FBINFO_STATE_SUSPENDED; |
| 1573 | } else { |
| 1574 | info->state = FBINFO_STATE_RUNNING; |
Antonino A. Daplas | 256154f | 2006-07-30 03:04:17 -0700 | [diff] [blame] | 1575 | fb_notifier_call_chain(FB_EVENT_RESUME, &event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1576 | } |
| 1577 | } |
| 1578 | |
| 1579 | /** |
| 1580 | * fbmem_init - init frame buffer subsystem |
| 1581 | * |
| 1582 | * Initialize the frame buffer subsystem. |
| 1583 | * |
| 1584 | * NOTE: This function is _only_ to be called by drivers/char/mem.c. |
| 1585 | * |
| 1586 | */ |
| 1587 | |
| 1588 | static int __init |
| 1589 | fbmem_init(void) |
| 1590 | { |
Alexey Dobriyan | 0aa1634 | 2008-04-28 02:15:42 -0700 | [diff] [blame] | 1591 | proc_create("fb", 0, NULL, &fb_proc_fops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1592 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | if (register_chrdev(FB_MAJOR,"fb",&fb_fops)) |
| 1594 | printk("unable to get major %d for fb devs\n", FB_MAJOR); |
| 1595 | |
gregkh@suse.de | 56b2293 | 2005-03-23 10:01:41 -0800 | [diff] [blame] | 1596 | fb_class = class_create(THIS_MODULE, "graphics"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1597 | if (IS_ERR(fb_class)) { |
| 1598 | printk(KERN_WARNING "Unable to create fb class; errno = %ld\n", PTR_ERR(fb_class)); |
| 1599 | fb_class = NULL; |
| 1600 | } |
| 1601 | return 0; |
| 1602 | } |
| 1603 | |
| 1604 | #ifdef MODULE |
| 1605 | module_init(fbmem_init); |
| 1606 | static void __exit |
| 1607 | fbmem_exit(void) |
| 1608 | { |
Alexey Dobriyan | c43f89c | 2008-04-15 14:34:33 -0700 | [diff] [blame] | 1609 | remove_proc_entry("fb", NULL); |
gregkh@suse.de | 56b2293 | 2005-03-23 10:01:41 -0800 | [diff] [blame] | 1610 | class_destroy(fb_class); |
Jon Smirl | 5a340cc | 2005-07-27 11:46:04 -0700 | [diff] [blame] | 1611 | unregister_chrdev(FB_MAJOR, "fb"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1612 | } |
| 1613 | |
| 1614 | module_exit(fbmem_exit); |
| 1615 | MODULE_LICENSE("GPL"); |
| 1616 | MODULE_DESCRIPTION("Framebuffer base"); |
| 1617 | #else |
| 1618 | subsys_initcall(fbmem_init); |
| 1619 | #endif |
| 1620 | |
| 1621 | int fb_new_modelist(struct fb_info *info) |
| 1622 | { |
| 1623 | struct fb_event event; |
| 1624 | struct fb_var_screeninfo var = info->var; |
| 1625 | struct list_head *pos, *n; |
| 1626 | struct fb_modelist *modelist; |
| 1627 | struct fb_videomode *m, mode; |
| 1628 | int err = 1; |
| 1629 | |
| 1630 | list_for_each_safe(pos, n, &info->modelist) { |
| 1631 | modelist = list_entry(pos, struct fb_modelist, list); |
| 1632 | m = &modelist->mode; |
| 1633 | fb_videomode_to_var(&var, m); |
| 1634 | var.activate = FB_ACTIVATE_TEST; |
| 1635 | err = fb_set_var(info, &var); |
| 1636 | fb_var_to_videomode(&mode, &var); |
| 1637 | if (err || !fb_mode_is_equal(m, &mode)) { |
| 1638 | list_del(pos); |
| 1639 | kfree(pos); |
| 1640 | } |
| 1641 | } |
| 1642 | |
| 1643 | err = 1; |
| 1644 | |
| 1645 | if (!list_empty(&info->modelist)) { |
| 1646 | event.info = info; |
Antonino A. Daplas | 256154f | 2006-07-30 03:04:17 -0700 | [diff] [blame] | 1647 | err = fb_notifier_call_chain(FB_EVENT_NEW_MODELIST, &event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1648 | } |
| 1649 | |
| 1650 | return err; |
| 1651 | } |
| 1652 | |
Helge Deller | 0128bee | 2006-12-08 02:40:29 -0800 | [diff] [blame] | 1653 | static char *video_options[FB_MAX] __read_mostly; |
| 1654 | static int ofonly __read_mostly; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1655 | |
| 1656 | /** |
| 1657 | * fb_get_options - get kernel boot parameters |
| 1658 | * @name: framebuffer name as it would appear in |
| 1659 | * the boot parameter line |
| 1660 | * (video=<name>:<options>) |
| 1661 | * @option: the option will be stored here |
| 1662 | * |
| 1663 | * NOTE: Needed to maintain backwards compatibility |
| 1664 | */ |
| 1665 | int fb_get_options(char *name, char **option) |
| 1666 | { |
| 1667 | char *opt, *options = NULL; |
| 1668 | int opt_len, retval = 0; |
| 1669 | int name_len = strlen(name), i; |
| 1670 | |
| 1671 | if (name_len && ofonly && strncmp(name, "offb", 4)) |
| 1672 | retval = 1; |
| 1673 | |
| 1674 | if (name_len && !retval) { |
| 1675 | for (i = 0; i < FB_MAX; i++) { |
| 1676 | if (video_options[i] == NULL) |
| 1677 | continue; |
| 1678 | opt_len = strlen(video_options[i]); |
| 1679 | if (!opt_len) |
| 1680 | continue; |
| 1681 | opt = video_options[i]; |
| 1682 | if (!strncmp(name, opt, name_len) && |
| 1683 | opt[name_len] == ':') |
| 1684 | options = opt + name_len + 1; |
| 1685 | } |
| 1686 | } |
| 1687 | if (options && !strncmp(options, "off", 3)) |
| 1688 | retval = 1; |
| 1689 | |
| 1690 | if (option) |
| 1691 | *option = options; |
| 1692 | |
| 1693 | return retval; |
| 1694 | } |
| 1695 | |
Andrew Morton | bc6d7fd | 2006-02-11 17:56:08 -0800 | [diff] [blame] | 1696 | #ifndef MODULE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1697 | /** |
| 1698 | * video_setup - process command line options |
| 1699 | * @options: string of options |
| 1700 | * |
| 1701 | * Process command line options for frame buffer subsystem. |
| 1702 | * |
| 1703 | * NOTE: This function is a __setup and __init function. |
| 1704 | * It only stores the options. Drivers have to call |
| 1705 | * fb_get_options() as necessary. |
| 1706 | * |
| 1707 | * Returns zero. |
| 1708 | * |
| 1709 | */ |
Adrian Bunk | 75c96f8 | 2005-05-05 16:16:09 -0700 | [diff] [blame] | 1710 | static int __init video_setup(char *options) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1711 | { |
| 1712 | int i, global = 0; |
| 1713 | |
| 1714 | if (!options || !*options) |
| 1715 | global = 1; |
| 1716 | |
| 1717 | if (!global && !strncmp(options, "ofonly", 6)) { |
| 1718 | ofonly = 1; |
| 1719 | global = 1; |
| 1720 | } |
| 1721 | |
| 1722 | if (!global && !strstr(options, "fb:")) { |
Geert Uytterhoeven | 9a054fb | 2007-10-16 01:29:51 -0700 | [diff] [blame] | 1723 | fb_mode_option = options; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1724 | global = 1; |
| 1725 | } |
| 1726 | |
| 1727 | if (!global) { |
| 1728 | for (i = 0; i < FB_MAX; i++) { |
| 1729 | if (video_options[i] == NULL) { |
| 1730 | video_options[i] = options; |
| 1731 | break; |
| 1732 | } |
| 1733 | |
| 1734 | } |
| 1735 | } |
| 1736 | |
OGAWA Hirofumi | 9b41046 | 2006-03-31 02:30:33 -0800 | [diff] [blame] | 1737 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1738 | } |
| 1739 | __setup("video=", video_setup); |
Andrew Morton | bc6d7fd | 2006-02-11 17:56:08 -0800 | [diff] [blame] | 1740 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1741 | |
| 1742 | /* |
| 1743 | * Visible symbols for modules |
| 1744 | */ |
| 1745 | |
| 1746 | EXPORT_SYMBOL(register_framebuffer); |
| 1747 | EXPORT_SYMBOL(unregister_framebuffer); |
| 1748 | EXPORT_SYMBOL(num_registered_fb); |
| 1749 | EXPORT_SYMBOL(registered_fb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1750 | EXPORT_SYMBOL(fb_show_logo); |
| 1751 | EXPORT_SYMBOL(fb_set_var); |
| 1752 | EXPORT_SYMBOL(fb_blank); |
| 1753 | EXPORT_SYMBOL(fb_pan_display); |
| 1754 | EXPORT_SYMBOL(fb_get_buffer_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1755 | EXPORT_SYMBOL(fb_set_suspend); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1756 | EXPORT_SYMBOL(fb_get_options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1757 | |
| 1758 | MODULE_LICENSE("GPL"); |