Lines Matching +full:enforce +full:- +full:video +full:- +full:mode

1 // SPDX-License-Identifier: GPL-2.0-only
3 * udlfb.c -- Framebuffer driver for DisplayLink USB controller
10 * usb-skeleton by GregKH.
12 * Device-specific portions based on information from Displaylink, with work
27 #include <video/udlfb.h>
46 * There are many DisplayLink-based graphics products, all with unique PIDs.
47 * So we match on DisplayLink's VID + Vendor-Defined Interface Class (0xff)
112 * ----- -----------------------------
198 while (actual_count--) { in dlfb_lfsr16()
217 * This takes a standard fbdev screeninfo struct and all of its monitor mode
227 xds = var->left_margin + var->hsync_len; in dlfb_set_vid_cmds()
230 xde = xds + var->xres; in dlfb_set_vid_cmds()
234 yds = var->upper_margin + var->vsync_len; in dlfb_set_vid_cmds()
237 yde = yds + var->yres; in dlfb_set_vid_cmds()
240 /* x end count is active + blanking - 1 */ in dlfb_set_vid_cmds()
242 xde + var->right_margin - 1); in dlfb_set_vid_cmds()
248 wrptr = dlfb_set_register_lfsr16(wrptr, 0x0D, var->hsync_len + 1); in dlfb_set_vid_cmds()
251 wrptr = dlfb_set_register_16(wrptr, 0x0F, var->xres); in dlfb_set_vid_cmds()
254 yec = var->yres + var->upper_margin + var->lower_margin + in dlfb_set_vid_cmds()
255 var->vsync_len; in dlfb_set_vid_cmds()
262 wrptr = dlfb_set_register_lfsr16(wrptr, 0x15, var->vsync_len); in dlfb_set_vid_cmds()
265 wrptr = dlfb_set_register_16(wrptr, 0x17, var->yres); in dlfb_set_vid_cmds()
269 200*1000*1000/var->pixclock); in dlfb_set_vid_cmds()
288 if (!atomic_read(&dlfb->usb_active)) in dlfb_set_video_mode()
289 return -EPERM; in dlfb_set_video_mode()
293 return -ENOMEM; in dlfb_set_video_mode()
295 buf = (char *) urb->transfer_buffer; in dlfb_set_video_mode()
307 wrptr = dlfb_set_base8bpp(wrptr, dlfb->info->fix.smem_len); in dlfb_set_video_mode()
313 writesize = wrptr - buf; in dlfb_set_video_mode()
317 dlfb->blank_mode = FB_BLANK_UNBLANK; in dlfb_set_video_mode()
324 unsigned long start = vma->vm_start; in dlfb_ops_mmap()
325 unsigned long size = vma->vm_end - vma->vm_start; in dlfb_ops_mmap()
326 unsigned long offset = vma->vm_pgoff << PAGE_SHIFT; in dlfb_ops_mmap()
329 if (info->fbdefio) in dlfb_ops_mmap()
332 if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT)) in dlfb_ops_mmap()
333 return -EINVAL; in dlfb_ops_mmap()
334 if (size > info->fix.smem_len) in dlfb_ops_mmap()
335 return -EINVAL; in dlfb_ops_mmap()
336 if (offset > info->fix.smem_len - size) in dlfb_ops_mmap()
337 return -EINVAL; in dlfb_ops_mmap()
339 pos = (unsigned long)info->fix.smem_start + offset; in dlfb_ops_mmap()
341 dev_dbg(info->dev, "mmap() framebuffer addr:%lu size:%lu\n", in dlfb_ops_mmap()
347 return -EAGAIN; in dlfb_ops_mmap()
352 size -= PAGE_SIZE; in dlfb_ops_mmap()
384 for (k = width - 1; k > j; k--) { in dlfb_trim_hline()
391 identical = start + (width - end); in dlfb_trim_hline()
393 *width_bytes = (end - start) * sizeof(unsigned long); in dlfb_trim_hline()
403 * (the protocol doesn't require this, but we enforce it to allow
439 (cmd_buffer_end - MIN_RLX_CMD_BYTES > cmd)) { in dlfb_compress_hline()
466 (unsigned long)(pixel_end - pixel), in dlfb_compress_hline()
467 (unsigned long)(cmd_buffer_end - 1 - cmd) / BPP); in dlfb_compress_hline()
471 while (cmd_pixel_end - 1 > pixel && in dlfb_compress_hline()
472 *(cmd_pixel_end - 1) == *(u16 *)((u8 *)(cmd_pixel_end - 1) + back_buffer_offset)) in dlfb_compress_hline()
473 cmd_pixel_end--; in dlfb_compress_hline()
489 *raw_pixels_count_byte = ((repeating_pixel - in dlfb_compress_hline()
500 *cmd++ = ((pixel - repeating_pixel) - 1) & 0xFF; in dlfb_compress_hline()
510 *raw_pixels_count_byte = (pixel-raw_pixel_start) & 0xFF; in dlfb_compress_hline()
513 cmd--; in dlfb_compress_hline()
516 *cmd_pixels_count_byte = (pixel - cmd_pixel_start) & 0xFF; in dlfb_compress_hline()
517 dev_addr += (u8 *)pixel - (u8 *)cmd_pixel_start; in dlfb_compress_hline()
520 if (cmd_buffer_end - MIN_RLX_CMD_BYTES <= cmd) { in dlfb_compress_hline()
521 /* Fill leftover bytes with no-ops */ in dlfb_compress_hline()
523 memset(cmd, 0xAF, cmd_buffer_end - cmd); in dlfb_compress_hline()
544 u32 dev_addr = dlfb->base16 + byte_offset; in dlfb_render_hline()
547 u8 *cmd_end = (u8 *) urb->transfer_buffer + urb->transfer_buffer_length; in dlfb_render_hline()
554 if (dlfb->backing_buffer) { in dlfb_render_hline()
556 const u8 *back_start = (u8 *) (dlfb->backing_buffer in dlfb_render_hline()
559 back_buffer_offset = (unsigned long)back_start - (unsigned long)line_start; in dlfb_render_hline()
564 offset = next_pixel - line_start; in dlfb_render_hline()
579 int len = cmd - (u8 *) urb->transfer_buffer; in dlfb_render_hline()
587 cmd = urb->transfer_buffer; in dlfb_render_hline()
588 cmd_end = &cmd[urb->transfer_buffer_length]; in dlfb_render_hline()
609 mutex_lock(&dlfb->render_mutex); in dlfb_handle_damage()
612 width = DL_ALIGN_UP(width + (x-aligned_x), sizeof(unsigned long)); in dlfb_handle_damage()
616 (x + width > dlfb->info->var.xres) || in dlfb_handle_damage()
617 (y + height > dlfb->info->var.yres)) { in dlfb_handle_damage()
618 ret = -EINVAL; in dlfb_handle_damage()
622 if (!atomic_read(&dlfb->usb_active)) { in dlfb_handle_damage()
632 cmd = urb->transfer_buffer; in dlfb_handle_damage()
635 const int line_offset = dlfb->info->fix.line_length * i; in dlfb_handle_damage()
639 (char *) dlfb->info->fix.smem_start, in dlfb_handle_damage()
645 if (cmd > (char *) urb->transfer_buffer) { in dlfb_handle_damage()
647 if (cmd < (char *) urb->transfer_buffer + urb->transfer_buffer_length) in dlfb_handle_damage()
650 len = cmd - (char *) urb->transfer_buffer; in dlfb_handle_damage()
657 atomic_add(bytes_sent, &dlfb->bytes_sent); in dlfb_handle_damage()
658 atomic_add(bytes_identical, &dlfb->bytes_identical); in dlfb_handle_damage()
659 atomic_add(width*height*2, &dlfb->bytes_rendered); in dlfb_handle_damage()
661 atomic_add(((unsigned int) ((end_cycles - start_cycles) in dlfb_handle_damage()
663 &dlfb->cpu_kcycles_used); in dlfb_handle_damage()
668 mutex_unlock(&dlfb->render_mutex); in dlfb_handle_damage()
674 dlfb->damage_x = INT_MAX; in dlfb_init_damage()
675 dlfb->damage_x2 = 0; in dlfb_init_damage()
676 dlfb->damage_y = INT_MAX; in dlfb_init_damage()
677 dlfb->damage_y2 = 0; in dlfb_init_damage()
685 spin_lock_irq(&dlfb->damage_lock); in dlfb_damage_work()
686 x = dlfb->damage_x; in dlfb_damage_work()
687 x2 = dlfb->damage_x2; in dlfb_damage_work()
688 y = dlfb->damage_y; in dlfb_damage_work()
689 y2 = dlfb->damage_y2; in dlfb_damage_work()
691 spin_unlock_irq(&dlfb->damage_lock); in dlfb_damage_work()
694 dlfb_handle_damage(dlfb, x, y, x2 - x, y2 - y); in dlfb_damage_work()
706 spin_lock_irqsave(&dlfb->damage_lock, flags); in dlfb_offload_damage()
707 dlfb->damage_x = min(x, dlfb->damage_x); in dlfb_offload_damage()
708 dlfb->damage_x2 = max(x2, dlfb->damage_x2); in dlfb_offload_damage()
709 dlfb->damage_y = min(y, dlfb->damage_y); in dlfb_offload_damage()
710 dlfb->damage_y2 = max(y2, dlfb->damage_y2); in dlfb_offload_damage()
711 spin_unlock_irqrestore(&dlfb->damage_lock, flags); in dlfb_offload_damage()
713 schedule_work(&dlfb->damage_work); in dlfb_offload_damage()
719 * Not used by X Windows or text-mode console. But useful for testing.
726 struct dlfb_data *dlfb = info->par; in dlfb_ops_write()
732 int start = max((int)(offset / info->fix.line_length), 0); in dlfb_ops_write()
733 int lines = min((u32)((result / info->fix.line_length) + 1), in dlfb_ops_write()
734 (u32)info->var.yres); in dlfb_ops_write()
736 dlfb_handle_damage(dlfb, 0, start, info->var.xres, in dlfb_ops_write()
748 struct dlfb_data *dlfb = info->par; in dlfb_ops_copyarea()
752 dlfb_offload_damage(dlfb, area->dx, area->dy, in dlfb_ops_copyarea()
753 area->width, area->height); in dlfb_ops_copyarea()
759 struct dlfb_data *dlfb = info->par; in dlfb_ops_imageblit()
763 dlfb_offload_damage(dlfb, image->dx, image->dy, in dlfb_ops_imageblit()
764 image->width, image->height); in dlfb_ops_imageblit()
770 struct dlfb_data *dlfb = info->par; in dlfb_ops_fillrect()
774 dlfb_offload_damage(dlfb, rect->dx, rect->dy, rect->width, in dlfb_ops_fillrect()
775 rect->height); in dlfb_ops_fillrect()
779 * NOTE: fb_defio.c is holding info->fbdefio.mutex
787 struct dlfb_data *dlfb = info->par; in dlfb_dpy_deferred_io()
795 mutex_lock(&dlfb->render_mutex); in dlfb_dpy_deferred_io()
800 if (!atomic_read(&dlfb->usb_active)) in dlfb_dpy_deferred_io()
809 cmd = urb->transfer_buffer; in dlfb_dpy_deferred_io()
813 if (dlfb_render_hline(dlfb, &urb, (char *) info->fix.smem_start, in dlfb_dpy_deferred_io()
814 &cmd, pageref->offset, PAGE_SIZE, in dlfb_dpy_deferred_io()
820 if (cmd > (char *) urb->transfer_buffer) { in dlfb_dpy_deferred_io()
822 if (cmd < (char *) urb->transfer_buffer + urb->transfer_buffer_length) in dlfb_dpy_deferred_io()
825 len = cmd - (char *) urb->transfer_buffer; in dlfb_dpy_deferred_io()
832 atomic_add(bytes_sent, &dlfb->bytes_sent); in dlfb_dpy_deferred_io()
833 atomic_add(bytes_identical, &dlfb->bytes_identical); in dlfb_dpy_deferred_io()
834 atomic_add(bytes_rendered, &dlfb->bytes_rendered); in dlfb_dpy_deferred_io()
836 atomic_add(((unsigned int) ((end_cycles - start_cycles) in dlfb_dpy_deferred_io()
838 &dlfb->cpu_kcycles_used); in dlfb_dpy_deferred_io()
840 mutex_unlock(&dlfb->render_mutex); in dlfb_dpy_deferred_io()
853 ret = usb_control_msg(dlfb->udev, in dlfb_get_edid()
854 usb_rcvctrlpipe(dlfb->udev, 0), 0x02, in dlfb_get_edid()
858 dev_err(&dlfb->udev->dev, in dlfb_get_edid()
860 i--; in dlfb_get_edid()
875 struct dlfb_data *dlfb = info->par; in dlfb_ops_ioctl()
877 if (!atomic_read(&dlfb->usb_active)) in dlfb_ops_ioctl()
883 if (copy_to_user(edid, dlfb->edid, dlfb->edid_size)) in dlfb_ops_ioctl()
884 return -EFAULT; in dlfb_ops_ioctl()
894 return -EFAULT; in dlfb_ops_ioctl()
897 * If we have a damage-aware client, turn fb_defio "off" in dlfb_ops_ioctl()
903 if (info->fbdefio) in dlfb_ops_ioctl()
904 info->fbdefio->delay = DL_DEFIO_WRITE_DISABLE; in dlfb_ops_ioctl()
909 if (area.x > info->var.xres) in dlfb_ops_ioctl()
910 area.x = info->var.xres; in dlfb_ops_ioctl()
915 if (area.y > info->var.yres) in dlfb_ops_ioctl()
916 area.y = info->var.yres; in dlfb_ops_ioctl()
931 if (regno >= info->cmap.len) in dlfb_ops_setcolreg()
935 if (info->var.red.offset == 10) { in dlfb_ops_setcolreg()
937 ((u32 *) (info->pseudo_palette))[regno] = in dlfb_ops_setcolreg()
942 ((u32 *) (info->pseudo_palette))[regno] = in dlfb_ops_setcolreg()
954 * Assumes caller is holding info->lock (for open and release at least)
958 struct dlfb_data *dlfb = info->par; in dlfb_ops_open()
966 return -EBUSY; in dlfb_ops_open()
969 if (dlfb->virtualized) in dlfb_ops_open()
970 return -ENODEV; in dlfb_ops_open()
972 dlfb->fb_count++; in dlfb_ops_open()
974 if (fb_defio && (info->fbdefio == NULL)) { in dlfb_ops_open()
982 fbdefio->delay = DL_DEFIO_WRITE_DELAY; in dlfb_ops_open()
983 fbdefio->sort_pagereflist = true; in dlfb_ops_open()
984 fbdefio->deferred_io = dlfb_dpy_deferred_io; in dlfb_ops_open()
987 info->fbdefio = fbdefio; in dlfb_ops_open()
991 dev_dbg(info->dev, "open, user=%d fb_info=%p count=%d\n", in dlfb_ops_open()
992 user, info, dlfb->fb_count); in dlfb_ops_open()
999 struct dlfb_data *dlfb = info->par; in dlfb_ops_destroy()
1001 cancel_work_sync(&dlfb->damage_work); in dlfb_ops_destroy()
1003 mutex_destroy(&dlfb->render_mutex); in dlfb_ops_destroy()
1005 if (info->cmap.len != 0) in dlfb_ops_destroy()
1006 fb_dealloc_cmap(&info->cmap); in dlfb_ops_destroy()
1007 if (info->monspecs.modedb) in dlfb_ops_destroy()
1008 fb_destroy_modedb(info->monspecs.modedb); in dlfb_ops_destroy()
1009 vfree(info->screen_base); in dlfb_ops_destroy()
1011 fb_destroy_modelist(&info->modelist); in dlfb_ops_destroy()
1013 while (!list_empty(&dlfb->deferred_free)) { in dlfb_ops_destroy()
1014 …struct dlfb_deferred_free *d = list_entry(dlfb->deferred_free.next, struct dlfb_deferred_free, lis… in dlfb_ops_destroy()
1015 list_del(&d->list); in dlfb_ops_destroy()
1016 vfree(d->mem); in dlfb_ops_destroy()
1019 vfree(dlfb->backing_buffer); in dlfb_ops_destroy()
1020 kfree(dlfb->edid); in dlfb_ops_destroy()
1022 usb_put_dev(dlfb->udev); in dlfb_ops_destroy()
1030 * Assumes caller is holding info->lock mutex (for open and release at least)
1034 struct dlfb_data *dlfb = info->par; in dlfb_ops_release()
1036 dlfb->fb_count--; in dlfb_ops_release()
1038 if ((dlfb->fb_count == 0) && (info->fbdefio)) { in dlfb_ops_release()
1040 kfree(info->fbdefio); in dlfb_ops_release()
1041 info->fbdefio = NULL; in dlfb_ops_release()
1044 dev_dbg(info->dev, "release, user=%d count=%d\n", user, dlfb->fb_count); in dlfb_ops_release()
1050 * Check whether a video mode is supported by the DisplayLink chip
1053 static int dlfb_is_valid_mode(struct fb_videomode *mode, struct dlfb_data *dlfb) in dlfb_is_valid_mode() argument
1055 if (mode->xres * mode->yres > dlfb->sku_pixel_limit) in dlfb_is_valid_mode()
1067 var->bits_per_pixel = 16; in dlfb_var_color_format()
1068 var->red = red; in dlfb_var_color_format()
1069 var->green = green; in dlfb_var_color_format()
1070 var->blue = blue; in dlfb_var_color_format()
1076 struct fb_videomode mode; in dlfb_ops_check_var() local
1077 struct dlfb_data *dlfb = info->par; in dlfb_ops_check_var()
1079 /* set device-specific elements of var unrelated to mode */ in dlfb_ops_check_var()
1082 fb_var_to_videomode(&mode, var); in dlfb_ops_check_var()
1084 if (!dlfb_is_valid_mode(&mode, dlfb)) in dlfb_ops_check_var()
1085 return -EINVAL; in dlfb_ops_check_var()
1092 struct dlfb_data *dlfb = info->par; in dlfb_ops_set_par()
1097 u32 line_length = info->var.xres * (info->var.bits_per_pixel / 8); in dlfb_ops_set_par()
1100 fvs = info->var; in dlfb_ops_set_par()
1104 if (!memcmp(&dlfb->current_mode, &fvs, sizeof(struct fb_var_screeninfo))) in dlfb_ops_set_par()
1107 result = dlfb_realloc_framebuffer(dlfb, info, info->var.yres * line_length); in dlfb_ops_set_par()
1111 result = dlfb_set_video_mode(dlfb, &info->var); in dlfb_ops_set_par()
1116 dlfb->current_mode = fvs; in dlfb_ops_set_par()
1117 info->fix.line_length = line_length; in dlfb_ops_set_par()
1119 if (dlfb->fb_count == 0) { in dlfb_ops_set_par()
1123 pix_framebuffer = (u16 *) info->screen_base; in dlfb_ops_set_par()
1124 for (i = 0; i < info->fix.smem_len / 2; i++) in dlfb_ops_set_par()
1128 dlfb_handle_damage(dlfb, 0, 0, info->var.xres, info->var.yres); in dlfb_ops_set_par()
1149 * In order to come back from full DPMS off, we need to set the mode again
1153 struct dlfb_data *dlfb = info->par; in dlfb_ops_blank()
1157 dev_dbg(info->dev, "blank, mode %d --> %d\n", in dlfb_ops_blank()
1158 dlfb->blank_mode, blank_mode); in dlfb_ops_blank()
1160 if ((dlfb->blank_mode == FB_BLANK_POWERDOWN) && in dlfb_ops_blank()
1164 dlfb_set_video_mode(dlfb, &info->var); in dlfb_ops_blank()
1171 bufptr = (char *) urb->transfer_buffer; in dlfb_ops_blank()
1179 dlfb_submit_urb(dlfb, urb, bufptr - in dlfb_ops_blank()
1180 (char *) urb->transfer_buffer); in dlfb_ops_blank()
1182 dlfb->blank_mode = blank_mode; in dlfb_ops_blank()
1211 d->mem = mem; in dlfb_deferred_vfree()
1212 list_add(&d->list, &dlfb->deferred_free); in dlfb_deferred_vfree()
1216 * Assumes &info->lock held by caller
1221 u32 old_len = info->fix.smem_len; in dlfb_realloc_framebuffer()
1222 const void *old_fb = (const void __force *)info->screen_base; in dlfb_realloc_framebuffer()
1234 dev_err(info->dev, "Virtual framebuffer alloc failed\n"); in dlfb_realloc_framebuffer()
1235 return -ENOMEM; in dlfb_realloc_framebuffer()
1239 if (info->screen_base) { in dlfb_realloc_framebuffer()
1241 dlfb_deferred_vfree(dlfb, (void __force *)info->screen_base); in dlfb_realloc_framebuffer()
1244 info->screen_base = (char __iomem *)new_fb; in dlfb_realloc_framebuffer()
1245 info->fix.smem_len = new_len; in dlfb_realloc_framebuffer()
1246 info->fix.smem_start = (unsigned long) new_fb; in dlfb_realloc_framebuffer()
1247 info->flags = udlfb_info_flags; in dlfb_realloc_framebuffer()
1253 * that were, in fact, unchanged - wasting limited USB bandwidth in dlfb_realloc_framebuffer()
1258 dev_info(info->dev, in dlfb_realloc_framebuffer()
1261 dlfb_deferred_vfree(dlfb, dlfb->backing_buffer); in dlfb_realloc_framebuffer()
1262 dlfb->backing_buffer = new_back; in dlfb_realloc_framebuffer()
1271 * 3) Allocate virtual framebuffer memory to back highest res mode
1274 * fb_var_screeninfo contains the timing of the monitor's preferred mode
1279 * monspecs is NULL, and fb_var_screeninfo is set to safe VESA mode
1288 struct device *dev = info->device; in dlfb_setup_modes()
1289 struct fb_videomode *mode; in dlfb_setup_modes() local
1292 if (info->dev) { in dlfb_setup_modes()
1294 mutex_lock(&info->lock); in dlfb_setup_modes()
1296 dev = info->dev; in dlfb_setup_modes()
1301 result = -ENOMEM; in dlfb_setup_modes()
1305 fb_destroy_modelist(&info->modelist); in dlfb_setup_modes()
1306 memset(&info->monspecs, 0, sizeof(info->monspecs)); in dlfb_setup_modes()
1313 while (tries--) { in dlfb_setup_modes()
1318 fb_edid_to_monspecs(edid, &info->monspecs); in dlfb_setup_modes()
1320 if (info->monspecs.modedb_len > 0) { in dlfb_setup_modes()
1321 dlfb->edid = edid; in dlfb_setup_modes()
1322 dlfb->edid_size = i; in dlfb_setup_modes()
1328 if (info->monspecs.modedb_len == 0) { in dlfb_setup_modes()
1331 if (dlfb->edid) { in dlfb_setup_modes()
1332 fb_edid_to_monspecs(dlfb->edid, &info->monspecs); in dlfb_setup_modes()
1333 if (info->monspecs.modedb_len > 0) in dlfb_setup_modes()
1339 if (info->monspecs.modedb_len == 0) { in dlfb_setup_modes()
1341 fb_edid_to_monspecs(default_edid, &info->monspecs); in dlfb_setup_modes()
1342 if (info->monspecs.modedb_len > 0) { in dlfb_setup_modes()
1344 dlfb->edid = edid; in dlfb_setup_modes()
1345 dlfb->edid_size = default_edid_size; in dlfb_setup_modes()
1351 /* If we've got modes, let's pick a best default mode */ in dlfb_setup_modes()
1352 if (info->monspecs.modedb_len > 0) { in dlfb_setup_modes()
1354 for (i = 0; i < info->monspecs.modedb_len; i++) { in dlfb_setup_modes()
1355 mode = &info->monspecs.modedb[i]; in dlfb_setup_modes()
1356 if (dlfb_is_valid_mode(mode, dlfb)) { in dlfb_setup_modes()
1357 fb_add_videomode(mode, &info->modelist); in dlfb_setup_modes()
1359 dev_dbg(dev, "Specified mode %dx%d too big\n", in dlfb_setup_modes()
1360 mode->xres, mode->yres); in dlfb_setup_modes()
1362 /* if we've removed top/best mode */ in dlfb_setup_modes()
1363 info->monspecs.misc in dlfb_setup_modes()
1368 default_vmode = fb_find_best_display(&info->monspecs, in dlfb_setup_modes()
1369 &info->modelist); in dlfb_setup_modes()
1372 /* If everything else has failed, fall back to safe default mode */ in dlfb_setup_modes()
1384 mode = (struct fb_videomode *)&vesa_modes[i]; in dlfb_setup_modes()
1385 if (dlfb_is_valid_mode(mode, dlfb)) in dlfb_setup_modes()
1386 fb_add_videomode(mode, &info->modelist); in dlfb_setup_modes()
1388 dev_dbg(dev, "VESA mode %dx%d too big\n", in dlfb_setup_modes()
1389 mode->xres, mode->yres); in dlfb_setup_modes()
1400 &info->modelist); in dlfb_setup_modes()
1403 /* If we have good mode and no active clients*/ in dlfb_setup_modes()
1404 if ((default_vmode != NULL) && (dlfb->fb_count == 0)) { in dlfb_setup_modes()
1406 fb_videomode_to_var(&info->var, default_vmode); in dlfb_setup_modes()
1407 dlfb_var_color_format(&info->var); in dlfb_setup_modes()
1410 * with mode size info, we can now alloc our framebuffer. in dlfb_setup_modes()
1412 memcpy(&info->fix, &dlfb_fix, sizeof(dlfb_fix)); in dlfb_setup_modes()
1414 result = -EINVAL; in dlfb_setup_modes()
1417 if (edid && (dlfb->edid != edid)) in dlfb_setup_modes()
1420 if (info->dev) in dlfb_setup_modes()
1421 mutex_unlock(&info->lock); in dlfb_setup_modes()
1429 struct dlfb_data *dlfb = fb_info->par; in metrics_bytes_rendered_show()
1431 atomic_read(&dlfb->bytes_rendered)); in metrics_bytes_rendered_show()
1437 struct dlfb_data *dlfb = fb_info->par; in metrics_bytes_identical_show()
1439 atomic_read(&dlfb->bytes_identical)); in metrics_bytes_identical_show()
1445 struct dlfb_data *dlfb = fb_info->par; in metrics_bytes_sent_show()
1447 atomic_read(&dlfb->bytes_sent)); in metrics_bytes_sent_show()
1453 struct dlfb_data *dlfb = fb_info->par; in metrics_cpu_kcycles_used_show()
1455 atomic_read(&dlfb->cpu_kcycles_used)); in metrics_cpu_kcycles_used_show()
1464 struct dlfb_data *dlfb = fb_info->par; in edid_show()
1466 if (dlfb->edid == NULL) in edid_show()
1469 if ((off >= dlfb->edid_size) || (count > dlfb->edid_size)) in edid_show()
1472 if (off + count > dlfb->edid_size) in edid_show()
1473 count = dlfb->edid_size - off; in edid_show()
1475 memcpy(buf, dlfb->edid, count); in edid_show()
1486 struct dlfb_data *dlfb = fb_info->par; in edid_store()
1491 return -EINVAL; in edid_store()
1497 if (!dlfb->edid || memcmp(src, dlfb->edid, src_size)) in edid_store()
1498 return -EINVAL; in edid_store()
1512 struct dlfb_data *dlfb = fb_info->par; in metrics_reset_store()
1514 atomic_set(&dlfb->bytes_rendered, 0); in metrics_reset_store()
1515 atomic_set(&dlfb->bytes_identical, 0); in metrics_reset_store()
1516 atomic_set(&dlfb->bytes_sent, 0); in metrics_reset_store()
1517 atomic_set(&dlfb->cpu_kcycles_used, 0); in metrics_reset_store()
1524 .attr.mode = 0666,
1554 return -ENOMEM; in dlfb_select_std_channel()
1556 ret = usb_control_msg(dlfb->udev, usb_sndctrlpipe(dlfb->udev, 0), in dlfb_select_std_channel()
1585 if (0 == usb_get_extra_descriptor(intf->cur_altsetting, in dlfb_parse_vendor_descriptor()
1591 dev_info(&intf->dev, in dlfb_parse_vendor_descriptor()
1599 (desc[4] != total_len - 2)) /* length after type */ in dlfb_parse_vendor_descriptor()
1619 dev_warn(&intf->dev, in dlfb_parse_vendor_descriptor()
1622 dlfb->sku_pixel_limit = max_area; in dlfb_parse_vendor_descriptor()
1631 dev_info(&intf->dev, "vendor descriptor not available (%d)\n", in dlfb_parse_vendor_descriptor()
1639 dev_err(&intf->dev, "Unrecognized vendor firmware descriptor\n"); in dlfb_parse_vendor_descriptor()
1660 dev_err(&intf->dev, "%s: failed to allocate dlfb\n", __func__); in dlfb_usb_probe()
1661 return -ENOMEM; in dlfb_usb_probe()
1664 INIT_LIST_HEAD(&dlfb->deferred_free); in dlfb_usb_probe()
1666 dlfb->udev = usb_get_dev(usbdev); in dlfb_usb_probe()
1669 retval = usb_find_common_endpoints(intf->cur_altsetting, NULL, &out, NULL, NULL); in dlfb_usb_probe()
1671 dev_err(&intf->dev, "Device should have at lease 1 bulk endpoint!\n"); in dlfb_usb_probe()
1675 dev_dbg(&intf->dev, "console enable=%d\n", console); in dlfb_usb_probe()
1676 dev_dbg(&intf->dev, "fb_defio enable=%d\n", fb_defio); in dlfb_usb_probe()
1677 dev_dbg(&intf->dev, "shadow enable=%d\n", shadow); in dlfb_usb_probe()
1679 dlfb->sku_pixel_limit = 2048 * 1152; /* default to maximum */ in dlfb_usb_probe()
1682 dev_err(&intf->dev, in dlfb_usb_probe()
1684 retval = -ENODEV; in dlfb_usb_probe()
1689 dev_warn(&intf->dev, in dlfb_usb_probe()
1691 dlfb->sku_pixel_limit, pixel_limit); in dlfb_usb_probe()
1692 dlfb->sku_pixel_limit = pixel_limit; in dlfb_usb_probe()
1697 info = framebuffer_alloc(0, &dlfb->udev->dev); in dlfb_usb_probe()
1699 retval = -ENOMEM; in dlfb_usb_probe()
1703 dlfb->info = info; in dlfb_usb_probe()
1704 info->par = dlfb; in dlfb_usb_probe()
1705 info->pseudo_palette = dlfb->pseudo_palette; in dlfb_usb_probe()
1706 dlfb->ops = dlfb_ops; in dlfb_usb_probe()
1707 info->fbops = &dlfb->ops; in dlfb_usb_probe()
1709 mutex_init(&dlfb->render_mutex); in dlfb_usb_probe()
1711 spin_lock_init(&dlfb->damage_lock); in dlfb_usb_probe()
1712 INIT_WORK(&dlfb->damage_work, dlfb_damage_work); in dlfb_usb_probe()
1714 INIT_LIST_HEAD(&info->modelist); in dlfb_usb_probe()
1717 retval = -ENOMEM; in dlfb_usb_probe()
1718 dev_err(&intf->dev, "unable to allocate urb list\n"); in dlfb_usb_probe()
1724 retval = fb_alloc_cmap(&info->cmap, 256, 0); in dlfb_usb_probe()
1726 dev_err(info->device, "cmap allocation failed: %d\n", retval); in dlfb_usb_probe()
1732 dev_err(info->device, in dlfb_usb_probe()
1733 "unable to find common mode for display and adapter\n"); in dlfb_usb_probe()
1739 atomic_set(&dlfb->usb_active, 1); in dlfb_usb_probe()
1742 dlfb_ops_check_var(&info->var, info); in dlfb_usb_probe()
1749 dev_err(info->device, "unable to register framebuffer: %d\n", in dlfb_usb_probe()
1756 retval = device_create_file(info->dev, attr); in dlfb_usb_probe()
1758 dev_warn(info->device, in dlfb_usb_probe()
1760 attr->attr.name, retval); in dlfb_usb_probe()
1763 retval = device_create_bin_file(info->dev, &edid_attr); in dlfb_usb_probe()
1765 dev_warn(info->device, "failed to create '%s' attribute: %d\n", in dlfb_usb_probe()
1768 dev_info(info->device, in dlfb_usb_probe()
1770 dev_name(info->dev), info->var.xres, info->var.yres, in dlfb_usb_probe()
1771 ((dlfb->backing_buffer) ? in dlfb_usb_probe()
1772 info->fix.smem_len * 2 : info->fix.smem_len) >> 10); in dlfb_usb_probe()
1776 if (dlfb->info) { in dlfb_usb_probe()
1777 dlfb_ops_destroy(dlfb->info); in dlfb_usb_probe()
1779 usb_put_dev(dlfb->udev); in dlfb_usb_probe()
1792 info = dlfb->info; in dlfb_usb_disconnect()
1794 dev_dbg(&intf->dev, "USB disconnect starting\n"); in dlfb_usb_disconnect()
1797 dlfb->virtualized = true; in dlfb_usb_disconnect()
1799 /* When non-active we'll update virtual framebuffer, but no new urbs */ in dlfb_usb_disconnect()
1800 atomic_set(&dlfb->usb_active, 0); in dlfb_usb_disconnect()
1802 /* this function will wait for all in-flight urbs to complete */ in dlfb_usb_disconnect()
1807 device_remove_file(info->dev, &fb_device_attrs[i]); in dlfb_usb_disconnect()
1808 device_remove_bin_file(info->dev, &edid_attr); in dlfb_usb_disconnect()
1824 struct urb_node *unode = urb->context; in dlfb_urb_completion()
1825 struct dlfb_data *dlfb = unode->dlfb; in dlfb_urb_completion()
1828 switch (urb->status) { in dlfb_urb_completion()
1832 case -ECONNRESET: in dlfb_urb_completion()
1833 case -ENOENT: in dlfb_urb_completion()
1834 case -ESHUTDOWN: in dlfb_urb_completion()
1838 dev_err(&dlfb->udev->dev, in dlfb_urb_completion()
1839 "%s - nonzero write bulk status received: %d\n", in dlfb_urb_completion()
1840 __func__, urb->status); in dlfb_urb_completion()
1841 atomic_set(&dlfb->lost_pixels, 1); in dlfb_urb_completion()
1845 urb->transfer_buffer_length = dlfb->urbs.size; /* reset to actual */ in dlfb_urb_completion()
1847 spin_lock_irqsave(&dlfb->urbs.lock, flags); in dlfb_urb_completion()
1848 list_add_tail(&unode->entry, &dlfb->urbs.list); in dlfb_urb_completion()
1849 dlfb->urbs.available++; in dlfb_urb_completion()
1850 spin_unlock_irqrestore(&dlfb->urbs.lock, flags); in dlfb_urb_completion()
1852 up(&dlfb->urbs.limit_sem); in dlfb_urb_completion()
1857 int count = dlfb->urbs.count; in dlfb_free_urb_list()
1863 while (count--) { in dlfb_free_urb_list()
1864 down(&dlfb->urbs.limit_sem); in dlfb_free_urb_list()
1866 spin_lock_irq(&dlfb->urbs.lock); in dlfb_free_urb_list()
1868 node = dlfb->urbs.list.next; /* have reserved one with sem */ in dlfb_free_urb_list()
1871 spin_unlock_irq(&dlfb->urbs.lock); in dlfb_free_urb_list()
1874 urb = unode->urb; in dlfb_free_urb_list()
1877 usb_free_coherent(urb->dev, dlfb->urbs.size, in dlfb_free_urb_list()
1878 urb->transfer_buffer, urb->transfer_dma); in dlfb_free_urb_list()
1883 dlfb->urbs.count = 0; in dlfb_free_urb_list()
1893 spin_lock_init(&dlfb->urbs.lock); in dlfb_alloc_urb_list()
1896 dlfb->urbs.size = size; in dlfb_alloc_urb_list()
1897 INIT_LIST_HEAD(&dlfb->urbs.list); in dlfb_alloc_urb_list()
1899 sema_init(&dlfb->urbs.limit_sem, 0); in dlfb_alloc_urb_list()
1900 dlfb->urbs.count = 0; in dlfb_alloc_urb_list()
1901 dlfb->urbs.available = 0; in dlfb_alloc_urb_list()
1903 while (dlfb->urbs.count * size < wanted_size) { in dlfb_alloc_urb_list()
1907 unode->dlfb = dlfb; in dlfb_alloc_urb_list()
1914 unode->urb = urb; in dlfb_alloc_urb_list()
1916 buf = usb_alloc_coherent(dlfb->udev, size, GFP_KERNEL, in dlfb_alloc_urb_list()
1917 &urb->transfer_dma); in dlfb_alloc_urb_list()
1929 /* urb->transfer_buffer_length set to actual before submit */ in dlfb_alloc_urb_list()
1930 usb_fill_bulk_urb(urb, dlfb->udev, usb_sndbulkpipe(dlfb->udev, 1), in dlfb_alloc_urb_list()
1932 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; in dlfb_alloc_urb_list()
1934 list_add_tail(&unode->entry, &dlfb->urbs.list); in dlfb_alloc_urb_list()
1936 up(&dlfb->urbs.limit_sem); in dlfb_alloc_urb_list()
1937 dlfb->urbs.count++; in dlfb_alloc_urb_list()
1938 dlfb->urbs.available++; in dlfb_alloc_urb_list()
1941 return dlfb->urbs.count; in dlfb_alloc_urb_list()
1950 /* Wait for an in-flight buffer to complete and get re-queued */ in dlfb_get_urb()
1951 ret = down_timeout(&dlfb->urbs.limit_sem, GET_URB_TIMEOUT); in dlfb_get_urb()
1953 atomic_set(&dlfb->lost_pixels, 1); in dlfb_get_urb()
1954 dev_warn(&dlfb->udev->dev, in dlfb_get_urb()
1956 ret, dlfb->urbs.available); in dlfb_get_urb()
1960 spin_lock_irq(&dlfb->urbs.lock); in dlfb_get_urb()
1962 BUG_ON(list_empty(&dlfb->urbs.list)); /* reserved one with limit_sem */ in dlfb_get_urb()
1963 entry = dlfb->urbs.list.next; in dlfb_get_urb()
1965 dlfb->urbs.available--; in dlfb_get_urb()
1967 spin_unlock_irq(&dlfb->urbs.lock); in dlfb_get_urb()
1970 return unode->urb; in dlfb_get_urb()
1977 BUG_ON(len > dlfb->urbs.size); in dlfb_submit_urb()
1979 urb->transfer_buffer_length = len; /* set to actual payload len */ in dlfb_submit_urb()
1983 atomic_set(&dlfb->lost_pixels, 1); in dlfb_submit_urb()
1984 dev_err(&dlfb->udev->dev, "submit urb error: %d\n", ret); in dlfb_submit_urb()
1999 MODULE_PARM_DESC(pixel_limit, "Force limit on max mode (in x*y pixels)");