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 (vma->vm_pgoff > (~0UL >> PAGE_SHIFT)) in dlfb_ops_mmap()
330 return -EINVAL; in dlfb_ops_mmap()
331 if (size > info->fix.smem_len) in dlfb_ops_mmap()
332 return -EINVAL; in dlfb_ops_mmap()
333 if (offset > info->fix.smem_len - size) in dlfb_ops_mmap()
334 return -EINVAL; in dlfb_ops_mmap()
336 pos = (unsigned long)info->fix.smem_start + offset; in dlfb_ops_mmap()
338 dev_dbg(info->dev, "mmap() framebuffer addr:%lu size:%lu\n", in dlfb_ops_mmap()
344 return -EAGAIN; in dlfb_ops_mmap()
349 size -= PAGE_SIZE; in dlfb_ops_mmap()
381 for (k = width - 1; k > j; k--) { in dlfb_trim_hline()
388 identical = start + (width - end); in dlfb_trim_hline()
390 *width_bytes = (end - start) * sizeof(unsigned long); in dlfb_trim_hline()
400 * (the protocol doesn't require this, but we enforce it to allow
436 (cmd_buffer_end - MIN_RLX_CMD_BYTES > cmd)) { in dlfb_compress_hline()
463 (unsigned long)(pixel_end - pixel), in dlfb_compress_hline()
464 (unsigned long)(cmd_buffer_end - 1 - cmd) / BPP); in dlfb_compress_hline()
468 while (cmd_pixel_end - 1 > pixel && in dlfb_compress_hline()
469 *(cmd_pixel_end - 1) == *(u16 *)((u8 *)(cmd_pixel_end - 1) + back_buffer_offset)) in dlfb_compress_hline()
470 cmd_pixel_end--; in dlfb_compress_hline()
486 *raw_pixels_count_byte = ((repeating_pixel - in dlfb_compress_hline()
497 *cmd++ = ((pixel - repeating_pixel) - 1) & 0xFF; in dlfb_compress_hline()
507 *raw_pixels_count_byte = (pixel-raw_pixel_start) & 0xFF; in dlfb_compress_hline()
510 cmd--; in dlfb_compress_hline()
513 *cmd_pixels_count_byte = (pixel - cmd_pixel_start) & 0xFF; in dlfb_compress_hline()
514 dev_addr += (u8 *)pixel - (u8 *)cmd_pixel_start; in dlfb_compress_hline()
517 if (cmd_buffer_end - MIN_RLX_CMD_BYTES <= cmd) { in dlfb_compress_hline()
518 /* Fill leftover bytes with no-ops */ in dlfb_compress_hline()
520 memset(cmd, 0xAF, cmd_buffer_end - cmd); in dlfb_compress_hline()
541 u32 dev_addr = dlfb->base16 + byte_offset; in dlfb_render_hline()
544 u8 *cmd_end = (u8 *) urb->transfer_buffer + urb->transfer_buffer_length; in dlfb_render_hline()
551 if (dlfb->backing_buffer) { in dlfb_render_hline()
553 const u8 *back_start = (u8 *) (dlfb->backing_buffer in dlfb_render_hline()
556 back_buffer_offset = (unsigned long)back_start - (unsigned long)line_start; in dlfb_render_hline()
561 offset = next_pixel - line_start; in dlfb_render_hline()
576 int len = cmd - (u8 *) urb->transfer_buffer; in dlfb_render_hline()
584 cmd = urb->transfer_buffer; in dlfb_render_hline()
585 cmd_end = &cmd[urb->transfer_buffer_length]; in dlfb_render_hline()
606 mutex_lock(&dlfb->render_mutex); in dlfb_handle_damage()
609 width = DL_ALIGN_UP(width + (x-aligned_x), sizeof(unsigned long)); in dlfb_handle_damage()
613 (x + width > dlfb->info->var.xres) || in dlfb_handle_damage()
614 (y + height > dlfb->info->var.yres)) { in dlfb_handle_damage()
615 ret = -EINVAL; in dlfb_handle_damage()
619 if (!atomic_read(&dlfb->usb_active)) { in dlfb_handle_damage()
629 cmd = urb->transfer_buffer; in dlfb_handle_damage()
632 const int line_offset = dlfb->info->fix.line_length * i; in dlfb_handle_damage()
636 (char *) dlfb->info->fix.smem_start, in dlfb_handle_damage()
642 if (cmd > (char *) urb->transfer_buffer) { in dlfb_handle_damage()
644 if (cmd < (char *) urb->transfer_buffer + urb->transfer_buffer_length) in dlfb_handle_damage()
647 len = cmd - (char *) urb->transfer_buffer; in dlfb_handle_damage()
654 atomic_add(bytes_sent, &dlfb->bytes_sent); in dlfb_handle_damage()
655 atomic_add(bytes_identical, &dlfb->bytes_identical); in dlfb_handle_damage()
656 atomic_add(width*height*2, &dlfb->bytes_rendered); in dlfb_handle_damage()
658 atomic_add(((unsigned int) ((end_cycles - start_cycles) in dlfb_handle_damage()
660 &dlfb->cpu_kcycles_used); in dlfb_handle_damage()
665 mutex_unlock(&dlfb->render_mutex); in dlfb_handle_damage()
671 dlfb->damage_x = INT_MAX; in dlfb_init_damage()
672 dlfb->damage_x2 = 0; in dlfb_init_damage()
673 dlfb->damage_y = INT_MAX; in dlfb_init_damage()
674 dlfb->damage_y2 = 0; in dlfb_init_damage()
682 spin_lock_irq(&dlfb->damage_lock); in dlfb_damage_work()
683 x = dlfb->damage_x; in dlfb_damage_work()
684 x2 = dlfb->damage_x2; in dlfb_damage_work()
685 y = dlfb->damage_y; in dlfb_damage_work()
686 y2 = dlfb->damage_y2; in dlfb_damage_work()
688 spin_unlock_irq(&dlfb->damage_lock); in dlfb_damage_work()
691 dlfb_handle_damage(dlfb, x, y, x2 - x, y2 - y); in dlfb_damage_work()
703 spin_lock_irqsave(&dlfb->damage_lock, flags); in dlfb_offload_damage()
704 dlfb->damage_x = min(x, dlfb->damage_x); in dlfb_offload_damage()
705 dlfb->damage_x2 = max(x2, dlfb->damage_x2); in dlfb_offload_damage()
706 dlfb->damage_y = min(y, dlfb->damage_y); in dlfb_offload_damage()
707 dlfb->damage_y2 = max(y2, dlfb->damage_y2); in dlfb_offload_damage()
708 spin_unlock_irqrestore(&dlfb->damage_lock, flags); in dlfb_offload_damage()
710 schedule_work(&dlfb->damage_work); in dlfb_offload_damage()
716 * Not used by X Windows or text-mode console. But useful for testing.
723 struct dlfb_data *dlfb = info->par; in dlfb_ops_write()
729 int start = max((int)(offset / info->fix.line_length), 0); in dlfb_ops_write()
730 int lines = min((u32)((result / info->fix.line_length) + 1), in dlfb_ops_write()
731 (u32)info->var.yres); in dlfb_ops_write()
733 dlfb_handle_damage(dlfb, 0, start, info->var.xres, in dlfb_ops_write()
745 struct dlfb_data *dlfb = info->par; in dlfb_ops_copyarea()
749 dlfb_offload_damage(dlfb, area->dx, area->dy, in dlfb_ops_copyarea()
750 area->width, area->height); in dlfb_ops_copyarea()
756 struct dlfb_data *dlfb = info->par; in dlfb_ops_imageblit()
760 dlfb_offload_damage(dlfb, image->dx, image->dy, in dlfb_ops_imageblit()
761 image->width, image->height); in dlfb_ops_imageblit()
767 struct dlfb_data *dlfb = info->par; in dlfb_ops_fillrect()
771 dlfb_offload_damage(dlfb, rect->dx, rect->dy, rect->width, in dlfb_ops_fillrect()
772 rect->height); in dlfb_ops_fillrect()
776 * NOTE: fb_defio.c is holding info->fbdefio.mutex
785 struct fb_deferred_io *fbdefio = info->fbdefio; in dlfb_dpy_deferred_io()
786 struct dlfb_data *dlfb = info->par; in dlfb_dpy_deferred_io()
794 mutex_lock(&dlfb->render_mutex); in dlfb_dpy_deferred_io()
799 if (!atomic_read(&dlfb->usb_active)) in dlfb_dpy_deferred_io()
808 cmd = urb->transfer_buffer; in dlfb_dpy_deferred_io()
811 list_for_each_entry(cur, &fbdefio->pagelist, lru) { in dlfb_dpy_deferred_io()
813 if (dlfb_render_hline(dlfb, &urb, (char *) info->fix.smem_start, in dlfb_dpy_deferred_io()
814 &cmd, cur->index << PAGE_SHIFT, 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->deferred_io = dlfb_dpy_deferred_io; in dlfb_ops_open()
986 info->fbdefio = fbdefio; in dlfb_ops_open()
990 dev_dbg(info->dev, "open, user=%d fb_info=%p count=%d\n", in dlfb_ops_open()
991 user, info, dlfb->fb_count); in dlfb_ops_open()
998 struct dlfb_data *dlfb = info->par; in dlfb_ops_destroy()
1000 cancel_work_sync(&dlfb->damage_work); in dlfb_ops_destroy()
1002 mutex_destroy(&dlfb->render_mutex); in dlfb_ops_destroy()
1004 if (info->cmap.len != 0) in dlfb_ops_destroy()
1005 fb_dealloc_cmap(&info->cmap); in dlfb_ops_destroy()
1006 if (info->monspecs.modedb) in dlfb_ops_destroy()
1007 fb_destroy_modedb(info->monspecs.modedb); in dlfb_ops_destroy()
1008 vfree(info->screen_base); in dlfb_ops_destroy()
1010 fb_destroy_modelist(&info->modelist); in dlfb_ops_destroy()
1012 while (!list_empty(&dlfb->deferred_free)) { in dlfb_ops_destroy()
1013 …struct dlfb_deferred_free *d = list_entry(dlfb->deferred_free.next, struct dlfb_deferred_free, lis… in dlfb_ops_destroy()
1014 list_del(&d->list); in dlfb_ops_destroy()
1015 vfree(d->mem); in dlfb_ops_destroy()
1018 vfree(dlfb->backing_buffer); in dlfb_ops_destroy()
1019 kfree(dlfb->edid); in dlfb_ops_destroy()
1020 usb_put_dev(dlfb->udev); in dlfb_ops_destroy()
1028 * Assumes caller is holding info->lock mutex (for open and release at least)
1032 struct dlfb_data *dlfb = info->par; in dlfb_ops_release()
1034 dlfb->fb_count--; in dlfb_ops_release()
1036 if ((dlfb->fb_count == 0) && (info->fbdefio)) { in dlfb_ops_release()
1038 kfree(info->fbdefio); in dlfb_ops_release()
1039 info->fbdefio = NULL; in dlfb_ops_release()
1042 dev_dbg(info->dev, "release, user=%d count=%d\n", user, dlfb->fb_count); in dlfb_ops_release()
1048 * Check whether a video mode is supported by the DisplayLink chip
1051 static int dlfb_is_valid_mode(struct fb_videomode *mode, struct dlfb_data *dlfb) in dlfb_is_valid_mode() argument
1053 if (mode->xres * mode->yres > dlfb->sku_pixel_limit) in dlfb_is_valid_mode()
1065 var->bits_per_pixel = 16; in dlfb_var_color_format()
1066 var->red = red; in dlfb_var_color_format()
1067 var->green = green; in dlfb_var_color_format()
1068 var->blue = blue; in dlfb_var_color_format()
1074 struct fb_videomode mode; in dlfb_ops_check_var() local
1075 struct dlfb_data *dlfb = info->par; in dlfb_ops_check_var()
1077 /* set device-specific elements of var unrelated to mode */ in dlfb_ops_check_var()
1080 fb_var_to_videomode(&mode, var); in dlfb_ops_check_var()
1082 if (!dlfb_is_valid_mode(&mode, dlfb)) in dlfb_ops_check_var()
1083 return -EINVAL; in dlfb_ops_check_var()
1090 struct dlfb_data *dlfb = info->par; in dlfb_ops_set_par()
1095 u32 line_length = info->var.xres * (info->var.bits_per_pixel / 8); in dlfb_ops_set_par()
1098 fvs = info->var; in dlfb_ops_set_par()
1102 if (!memcmp(&dlfb->current_mode, &fvs, sizeof(struct fb_var_screeninfo))) in dlfb_ops_set_par()
1105 result = dlfb_realloc_framebuffer(dlfb, info, info->var.yres * line_length); in dlfb_ops_set_par()
1109 result = dlfb_set_video_mode(dlfb, &info->var); in dlfb_ops_set_par()
1114 dlfb->current_mode = fvs; in dlfb_ops_set_par()
1115 info->fix.line_length = line_length; in dlfb_ops_set_par()
1117 if (dlfb->fb_count == 0) { in dlfb_ops_set_par()
1121 pix_framebuffer = (u16 *) info->screen_base; in dlfb_ops_set_par()
1122 for (i = 0; i < info->fix.smem_len / 2; i++) in dlfb_ops_set_par()
1126 dlfb_handle_damage(dlfb, 0, 0, info->var.xres, info->var.yres); in dlfb_ops_set_par()
1147 * In order to come back from full DPMS off, we need to set the mode again
1151 struct dlfb_data *dlfb = info->par; in dlfb_ops_blank()
1155 dev_dbg(info->dev, "blank, mode %d --> %d\n", in dlfb_ops_blank()
1156 dlfb->blank_mode, blank_mode); in dlfb_ops_blank()
1158 if ((dlfb->blank_mode == FB_BLANK_POWERDOWN) && in dlfb_ops_blank()
1162 dlfb_set_video_mode(dlfb, &info->var); in dlfb_ops_blank()
1169 bufptr = (char *) urb->transfer_buffer; in dlfb_ops_blank()
1177 dlfb_submit_urb(dlfb, urb, bufptr - in dlfb_ops_blank()
1178 (char *) urb->transfer_buffer); in dlfb_ops_blank()
1180 dlfb->blank_mode = blank_mode; in dlfb_ops_blank()
1209 d->mem = mem; in dlfb_deferred_vfree()
1210 list_add(&d->list, &dlfb->deferred_free); in dlfb_deferred_vfree()
1214 * Assumes &info->lock held by caller
1219 u32 old_len = info->fix.smem_len; in dlfb_realloc_framebuffer()
1220 const void *old_fb = (const void __force *)info->screen_base; in dlfb_realloc_framebuffer()
1232 dev_err(info->dev, "Virtual framebuffer alloc failed\n"); in dlfb_realloc_framebuffer()
1233 return -ENOMEM; in dlfb_realloc_framebuffer()
1237 if (info->screen_base) { in dlfb_realloc_framebuffer()
1239 dlfb_deferred_vfree(dlfb, (void __force *)info->screen_base); in dlfb_realloc_framebuffer()
1242 info->screen_base = (char __iomem *)new_fb; in dlfb_realloc_framebuffer()
1243 info->fix.smem_len = new_len; in dlfb_realloc_framebuffer()
1244 info->fix.smem_start = (unsigned long) new_fb; in dlfb_realloc_framebuffer()
1245 info->flags = udlfb_info_flags; in dlfb_realloc_framebuffer()
1251 * that were, in fact, unchanged - wasting limited USB bandwidth in dlfb_realloc_framebuffer()
1256 dev_info(info->dev, in dlfb_realloc_framebuffer()
1259 dlfb_deferred_vfree(dlfb, dlfb->backing_buffer); in dlfb_realloc_framebuffer()
1260 dlfb->backing_buffer = new_back; in dlfb_realloc_framebuffer()
1269 * 3) Allocate virtual framebuffer memory to back highest res mode
1272 * fb_var_screeninfo contains the timing of the monitor's preferred mode
1277 * monspecs is NULL, and fb_var_screeninfo is set to safe VESA mode
1286 struct device *dev = info->device; in dlfb_setup_modes()
1287 struct fb_videomode *mode; in dlfb_setup_modes() local
1290 if (info->dev) { in dlfb_setup_modes()
1292 mutex_lock(&info->lock); in dlfb_setup_modes()
1294 dev = info->dev; in dlfb_setup_modes()
1299 result = -ENOMEM; in dlfb_setup_modes()
1303 fb_destroy_modelist(&info->modelist); in dlfb_setup_modes()
1304 memset(&info->monspecs, 0, sizeof(info->monspecs)); in dlfb_setup_modes()
1311 while (tries--) { in dlfb_setup_modes()
1316 fb_edid_to_monspecs(edid, &info->monspecs); in dlfb_setup_modes()
1318 if (info->monspecs.modedb_len > 0) { in dlfb_setup_modes()
1319 dlfb->edid = edid; in dlfb_setup_modes()
1320 dlfb->edid_size = i; in dlfb_setup_modes()
1326 if (info->monspecs.modedb_len == 0) { in dlfb_setup_modes()
1329 if (dlfb->edid) { in dlfb_setup_modes()
1330 fb_edid_to_monspecs(dlfb->edid, &info->monspecs); in dlfb_setup_modes()
1331 if (info->monspecs.modedb_len > 0) in dlfb_setup_modes()
1337 if (info->monspecs.modedb_len == 0) { in dlfb_setup_modes()
1339 fb_edid_to_monspecs(default_edid, &info->monspecs); in dlfb_setup_modes()
1340 if (info->monspecs.modedb_len > 0) { in dlfb_setup_modes()
1342 dlfb->edid = edid; in dlfb_setup_modes()
1343 dlfb->edid_size = default_edid_size; in dlfb_setup_modes()
1349 /* If we've got modes, let's pick a best default mode */ in dlfb_setup_modes()
1350 if (info->monspecs.modedb_len > 0) { in dlfb_setup_modes()
1352 for (i = 0; i < info->monspecs.modedb_len; i++) { in dlfb_setup_modes()
1353 mode = &info->monspecs.modedb[i]; in dlfb_setup_modes()
1354 if (dlfb_is_valid_mode(mode, dlfb)) { in dlfb_setup_modes()
1355 fb_add_videomode(mode, &info->modelist); in dlfb_setup_modes()
1357 dev_dbg(dev, "Specified mode %dx%d too big\n", in dlfb_setup_modes()
1358 mode->xres, mode->yres); in dlfb_setup_modes()
1360 /* if we've removed top/best mode */ in dlfb_setup_modes()
1361 info->monspecs.misc in dlfb_setup_modes()
1366 default_vmode = fb_find_best_display(&info->monspecs, in dlfb_setup_modes()
1367 &info->modelist); in dlfb_setup_modes()
1370 /* If everything else has failed, fall back to safe default mode */ in dlfb_setup_modes()
1382 mode = (struct fb_videomode *)&vesa_modes[i]; in dlfb_setup_modes()
1383 if (dlfb_is_valid_mode(mode, dlfb)) in dlfb_setup_modes()
1384 fb_add_videomode(mode, &info->modelist); in dlfb_setup_modes()
1386 dev_dbg(dev, "VESA mode %dx%d too big\n", in dlfb_setup_modes()
1387 mode->xres, mode->yres); in dlfb_setup_modes()
1398 &info->modelist); in dlfb_setup_modes()
1401 /* If we have good mode and no active clients*/ in dlfb_setup_modes()
1402 if ((default_vmode != NULL) && (dlfb->fb_count == 0)) { in dlfb_setup_modes()
1404 fb_videomode_to_var(&info->var, default_vmode); in dlfb_setup_modes()
1405 dlfb_var_color_format(&info->var); in dlfb_setup_modes()
1408 * with mode size info, we can now alloc our framebuffer. in dlfb_setup_modes()
1410 memcpy(&info->fix, &dlfb_fix, sizeof(dlfb_fix)); in dlfb_setup_modes()
1412 result = -EINVAL; in dlfb_setup_modes()
1415 if (edid && (dlfb->edid != edid)) in dlfb_setup_modes()
1418 if (info->dev) in dlfb_setup_modes()
1419 mutex_unlock(&info->lock); in dlfb_setup_modes()
1427 struct dlfb_data *dlfb = fb_info->par; in metrics_bytes_rendered_show()
1429 atomic_read(&dlfb->bytes_rendered)); in metrics_bytes_rendered_show()
1435 struct dlfb_data *dlfb = fb_info->par; in metrics_bytes_identical_show()
1437 atomic_read(&dlfb->bytes_identical)); in metrics_bytes_identical_show()
1443 struct dlfb_data *dlfb = fb_info->par; in metrics_bytes_sent_show()
1445 atomic_read(&dlfb->bytes_sent)); in metrics_bytes_sent_show()
1451 struct dlfb_data *dlfb = fb_info->par; in metrics_cpu_kcycles_used_show()
1453 atomic_read(&dlfb->cpu_kcycles_used)); in metrics_cpu_kcycles_used_show()
1462 struct dlfb_data *dlfb = fb_info->par; in edid_show()
1464 if (dlfb->edid == NULL) in edid_show()
1467 if ((off >= dlfb->edid_size) || (count > dlfb->edid_size)) in edid_show()
1470 if (off + count > dlfb->edid_size) in edid_show()
1471 count = dlfb->edid_size - off; in edid_show()
1473 memcpy(buf, dlfb->edid, count); in edid_show()
1484 struct dlfb_data *dlfb = fb_info->par; in edid_store()
1489 return -EINVAL; in edid_store()
1495 if (!dlfb->edid || memcmp(src, dlfb->edid, src_size)) in edid_store()
1496 return -EINVAL; in edid_store()
1510 struct dlfb_data *dlfb = fb_info->par; in metrics_reset_store()
1512 atomic_set(&dlfb->bytes_rendered, 0); in metrics_reset_store()
1513 atomic_set(&dlfb->bytes_identical, 0); in metrics_reset_store()
1514 atomic_set(&dlfb->bytes_sent, 0); in metrics_reset_store()
1515 atomic_set(&dlfb->cpu_kcycles_used, 0); in metrics_reset_store()
1522 .attr.mode = 0666,
1552 return -ENOMEM; in dlfb_select_std_channel()
1554 ret = usb_control_msg(dlfb->udev, usb_sndctrlpipe(dlfb->udev, 0), in dlfb_select_std_channel()
1583 if (0 == usb_get_extra_descriptor(intf->cur_altsetting, in dlfb_parse_vendor_descriptor()
1589 dev_info(&intf->dev, in dlfb_parse_vendor_descriptor()
1597 (desc[4] != total_len - 2)) /* length after type */ in dlfb_parse_vendor_descriptor()
1617 dev_warn(&intf->dev, in dlfb_parse_vendor_descriptor()
1620 dlfb->sku_pixel_limit = max_area; in dlfb_parse_vendor_descriptor()
1629 dev_info(&intf->dev, "vendor descriptor not available (%d)\n", in dlfb_parse_vendor_descriptor()
1637 dev_err(&intf->dev, "Unrecognized vendor firmware descriptor\n"); in dlfb_parse_vendor_descriptor()
1651 int retval = -ENOMEM; in dlfb_usb_probe()
1657 dev_err(&intf->dev, "%s: failed to allocate dlfb\n", __func__); in dlfb_usb_probe()
1658 return -ENOMEM; in dlfb_usb_probe()
1661 INIT_LIST_HEAD(&dlfb->deferred_free); in dlfb_usb_probe()
1663 dlfb->udev = usb_get_dev(usbdev); in dlfb_usb_probe()
1666 dev_dbg(&intf->dev, "console enable=%d\n", console); in dlfb_usb_probe()
1667 dev_dbg(&intf->dev, "fb_defio enable=%d\n", fb_defio); in dlfb_usb_probe()
1668 dev_dbg(&intf->dev, "shadow enable=%d\n", shadow); in dlfb_usb_probe()
1670 dlfb->sku_pixel_limit = 2048 * 1152; /* default to maximum */ in dlfb_usb_probe()
1673 dev_err(&intf->dev, in dlfb_usb_probe()
1679 dev_warn(&intf->dev, in dlfb_usb_probe()
1681 dlfb->sku_pixel_limit, pixel_limit); in dlfb_usb_probe()
1682 dlfb->sku_pixel_limit = pixel_limit; in dlfb_usb_probe()
1687 info = framebuffer_alloc(0, &dlfb->udev->dev); in dlfb_usb_probe()
1691 dlfb->info = info; in dlfb_usb_probe()
1692 info->par = dlfb; in dlfb_usb_probe()
1693 info->pseudo_palette = dlfb->pseudo_palette; in dlfb_usb_probe()
1694 dlfb->ops = dlfb_ops; in dlfb_usb_probe()
1695 info->fbops = &dlfb->ops; in dlfb_usb_probe()
1697 mutex_init(&dlfb->render_mutex); in dlfb_usb_probe()
1699 spin_lock_init(&dlfb->damage_lock); in dlfb_usb_probe()
1700 INIT_WORK(&dlfb->damage_work, dlfb_damage_work); in dlfb_usb_probe()
1702 INIT_LIST_HEAD(&info->modelist); in dlfb_usb_probe()
1705 retval = -ENOMEM; in dlfb_usb_probe()
1706 dev_err(&intf->dev, "unable to allocate urb list\n"); in dlfb_usb_probe()
1712 retval = fb_alloc_cmap(&info->cmap, 256, 0); in dlfb_usb_probe()
1714 dev_err(info->device, "cmap allocation failed: %d\n", retval); in dlfb_usb_probe()
1720 dev_err(info->device, in dlfb_usb_probe()
1721 "unable to find common mode for display and adapter\n"); in dlfb_usb_probe()
1727 atomic_set(&dlfb->usb_active, 1); in dlfb_usb_probe()
1730 dlfb_ops_check_var(&info->var, info); in dlfb_usb_probe()
1737 dev_err(info->device, "unable to register framebuffer: %d\n", in dlfb_usb_probe()
1744 retval = device_create_file(info->dev, attr); in dlfb_usb_probe()
1746 dev_warn(info->device, in dlfb_usb_probe()
1748 attr->attr.name, retval); in dlfb_usb_probe()
1751 retval = device_create_bin_file(info->dev, &edid_attr); in dlfb_usb_probe()
1753 dev_warn(info->device, "failed to create '%s' attribute: %d\n", in dlfb_usb_probe()
1756 dev_info(info->device, in dlfb_usb_probe()
1758 dev_name(info->dev), info->var.xres, info->var.yres, in dlfb_usb_probe()
1759 ((dlfb->backing_buffer) ? in dlfb_usb_probe()
1760 info->fix.smem_len * 2 : info->fix.smem_len) >> 10); in dlfb_usb_probe()
1764 if (dlfb->info) { in dlfb_usb_probe()
1765 dlfb_ops_destroy(dlfb->info); in dlfb_usb_probe()
1767 usb_put_dev(dlfb->udev); in dlfb_usb_probe()
1780 info = dlfb->info; in dlfb_usb_disconnect()
1782 dev_dbg(&intf->dev, "USB disconnect starting\n"); in dlfb_usb_disconnect()
1785 dlfb->virtualized = true; in dlfb_usb_disconnect()
1787 /* When non-active we'll update virtual framebuffer, but no new urbs */ in dlfb_usb_disconnect()
1788 atomic_set(&dlfb->usb_active, 0); in dlfb_usb_disconnect()
1790 /* this function will wait for all in-flight urbs to complete */ in dlfb_usb_disconnect()
1795 device_remove_file(info->dev, &fb_device_attrs[i]); in dlfb_usb_disconnect()
1796 device_remove_bin_file(info->dev, &edid_attr); in dlfb_usb_disconnect()
1812 struct urb_node *unode = urb->context; in dlfb_urb_completion()
1813 struct dlfb_data *dlfb = unode->dlfb; in dlfb_urb_completion()
1816 switch (urb->status) { in dlfb_urb_completion()
1820 case -ECONNRESET: in dlfb_urb_completion()
1821 case -ENOENT: in dlfb_urb_completion()
1822 case -ESHUTDOWN: in dlfb_urb_completion()
1826 dev_err(&dlfb->udev->dev, in dlfb_urb_completion()
1827 "%s - nonzero write bulk status received: %d\n", in dlfb_urb_completion()
1828 __func__, urb->status); in dlfb_urb_completion()
1829 atomic_set(&dlfb->lost_pixels, 1); in dlfb_urb_completion()
1833 urb->transfer_buffer_length = dlfb->urbs.size; /* reset to actual */ in dlfb_urb_completion()
1835 spin_lock_irqsave(&dlfb->urbs.lock, flags); in dlfb_urb_completion()
1836 list_add_tail(&unode->entry, &dlfb->urbs.list); in dlfb_urb_completion()
1837 dlfb->urbs.available++; in dlfb_urb_completion()
1838 spin_unlock_irqrestore(&dlfb->urbs.lock, flags); in dlfb_urb_completion()
1840 up(&dlfb->urbs.limit_sem); in dlfb_urb_completion()
1845 int count = dlfb->urbs.count; in dlfb_free_urb_list()
1851 while (count--) { in dlfb_free_urb_list()
1852 down(&dlfb->urbs.limit_sem); in dlfb_free_urb_list()
1854 spin_lock_irq(&dlfb->urbs.lock); in dlfb_free_urb_list()
1856 node = dlfb->urbs.list.next; /* have reserved one with sem */ in dlfb_free_urb_list()
1859 spin_unlock_irq(&dlfb->urbs.lock); in dlfb_free_urb_list()
1862 urb = unode->urb; in dlfb_free_urb_list()
1865 usb_free_coherent(urb->dev, dlfb->urbs.size, in dlfb_free_urb_list()
1866 urb->transfer_buffer, urb->transfer_dma); in dlfb_free_urb_list()
1871 dlfb->urbs.count = 0; in dlfb_free_urb_list()
1881 spin_lock_init(&dlfb->urbs.lock); in dlfb_alloc_urb_list()
1884 dlfb->urbs.size = size; in dlfb_alloc_urb_list()
1885 INIT_LIST_HEAD(&dlfb->urbs.list); in dlfb_alloc_urb_list()
1887 sema_init(&dlfb->urbs.limit_sem, 0); in dlfb_alloc_urb_list()
1888 dlfb->urbs.count = 0; in dlfb_alloc_urb_list()
1889 dlfb->urbs.available = 0; in dlfb_alloc_urb_list()
1891 while (dlfb->urbs.count * size < wanted_size) { in dlfb_alloc_urb_list()
1895 unode->dlfb = dlfb; in dlfb_alloc_urb_list()
1902 unode->urb = urb; in dlfb_alloc_urb_list()
1904 buf = usb_alloc_coherent(dlfb->udev, size, GFP_KERNEL, in dlfb_alloc_urb_list()
1905 &urb->transfer_dma); in dlfb_alloc_urb_list()
1917 /* urb->transfer_buffer_length set to actual before submit */ in dlfb_alloc_urb_list()
1918 usb_fill_bulk_urb(urb, dlfb->udev, usb_sndbulkpipe(dlfb->udev, 1), in dlfb_alloc_urb_list()
1920 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; in dlfb_alloc_urb_list()
1922 list_add_tail(&unode->entry, &dlfb->urbs.list); in dlfb_alloc_urb_list()
1924 up(&dlfb->urbs.limit_sem); in dlfb_alloc_urb_list()
1925 dlfb->urbs.count++; in dlfb_alloc_urb_list()
1926 dlfb->urbs.available++; in dlfb_alloc_urb_list()
1929 return dlfb->urbs.count; in dlfb_alloc_urb_list()
1938 /* Wait for an in-flight buffer to complete and get re-queued */ in dlfb_get_urb()
1939 ret = down_timeout(&dlfb->urbs.limit_sem, GET_URB_TIMEOUT); in dlfb_get_urb()
1941 atomic_set(&dlfb->lost_pixels, 1); in dlfb_get_urb()
1942 dev_warn(&dlfb->udev->dev, in dlfb_get_urb()
1944 ret, dlfb->urbs.available); in dlfb_get_urb()
1948 spin_lock_irq(&dlfb->urbs.lock); in dlfb_get_urb()
1950 BUG_ON(list_empty(&dlfb->urbs.list)); /* reserved one with limit_sem */ in dlfb_get_urb()
1951 entry = dlfb->urbs.list.next; in dlfb_get_urb()
1953 dlfb->urbs.available--; in dlfb_get_urb()
1955 spin_unlock_irq(&dlfb->urbs.lock); in dlfb_get_urb()
1958 return unode->urb; in dlfb_get_urb()
1965 BUG_ON(len > dlfb->urbs.size); in dlfb_submit_urb()
1967 urb->transfer_buffer_length = len; /* set to actual payload len */ in dlfb_submit_urb()
1971 atomic_set(&dlfb->lost_pixels, 1); in dlfb_submit_urb()
1972 dev_err(&dlfb->udev->dev, "submit urb error: %d\n", ret); in dlfb_submit_urb()
1987 MODULE_PARM_DESC(pixel_limit, "Force limit on max mode (in x*y pixels)");