Lines Matching +full:sync +full:- +full:on +full:- +full:green +full:- +full:active
1 // SPDX-License-Identifier: GPL-2.0-only
3 * udlfb.c -- Framebuffer driver for DisplayLink USB controller
9 * Layout is based on skeletonfb by James Simmons and Geert Uytterhoeven,
10 * usb-skeleton by GregKH.
12 * Device-specific portions based on information from Displaylink, with work
48 * There are many DisplayLink-based graphics products, all with unique PIDs.
49 * So we match on DisplayLink's VID + Vendor-Defined Interface Class (0xff)
50 * We also require a match on SubClass (0x00) and Protocol (0x00),
114 * ----- -----------------------------
200 while (actual_count--) { in dlfb_lfsr16()
210 * This does LFSR conversion on the value that is to be written.
229 xds = var->left_margin + var->hsync_len; in dlfb_set_vid_cmds()
232 xde = xds + var->xres; in dlfb_set_vid_cmds()
236 yds = var->upper_margin + var->vsync_len; in dlfb_set_vid_cmds()
239 yde = yds + var->yres; in dlfb_set_vid_cmds()
242 /* x end count is active + blanking - 1 */ in dlfb_set_vid_cmds()
244 xde + var->right_margin - 1); in dlfb_set_vid_cmds()
249 /* hsync end is width of sync pulse + 1 */ in dlfb_set_vid_cmds()
250 wrptr = dlfb_set_register_lfsr16(wrptr, 0x0D, var->hsync_len + 1); in dlfb_set_vid_cmds()
252 /* hpixels is active pixels */ in dlfb_set_vid_cmds()
253 wrptr = dlfb_set_register_16(wrptr, 0x0F, var->xres); in dlfb_set_vid_cmds()
255 /* yendcount is vertical active + vertical blanking */ in dlfb_set_vid_cmds()
256 yec = var->yres + var->upper_margin + var->lower_margin + in dlfb_set_vid_cmds()
257 var->vsync_len; in dlfb_set_vid_cmds()
264 wrptr = dlfb_set_register_lfsr16(wrptr, 0x15, var->vsync_len); in dlfb_set_vid_cmds()
266 /* vpixels is active pixels */ in dlfb_set_vid_cmds()
267 wrptr = dlfb_set_register_16(wrptr, 0x17, var->yres); in dlfb_set_vid_cmds()
271 200*1000*1000/var->pixclock); in dlfb_set_vid_cmds()
290 if (!atomic_read(&dlfb->usb_active)) in dlfb_set_video_mode()
291 return -EPERM; in dlfb_set_video_mode()
295 return -ENOMEM; in dlfb_set_video_mode()
297 buf = (char *) urb->transfer_buffer; in dlfb_set_video_mode()
300 * This first section has to do with setting the base address on the in dlfb_set_video_mode()
309 wrptr = dlfb_set_base8bpp(wrptr, dlfb->info->fix.smem_len); in dlfb_set_video_mode()
315 writesize = wrptr - buf; in dlfb_set_video_mode()
319 dlfb->blank_mode = FB_BLANK_UNBLANK; in dlfb_set_video_mode()
326 unsigned long start = vma->vm_start; in dlfb_ops_mmap()
327 unsigned long size = vma->vm_end - vma->vm_start; in dlfb_ops_mmap()
328 unsigned long offset = vma->vm_pgoff << PAGE_SHIFT; in dlfb_ops_mmap()
331 if (info->fbdefio) in dlfb_ops_mmap()
334 vma->vm_page_prot = pgprot_decrypted(vma->vm_page_prot); in dlfb_ops_mmap()
336 if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT)) in dlfb_ops_mmap()
337 return -EINVAL; in dlfb_ops_mmap()
338 if (size > info->fix.smem_len) in dlfb_ops_mmap()
339 return -EINVAL; in dlfb_ops_mmap()
340 if (offset > info->fix.smem_len - size) in dlfb_ops_mmap()
341 return -EINVAL; in dlfb_ops_mmap()
343 pos = (unsigned long)info->fix.smem_start + offset; in dlfb_ops_mmap()
345 dev_dbg(info->dev, "mmap() framebuffer addr:%lu size:%lu\n", in dlfb_ops_mmap()
351 return -EAGAIN; in dlfb_ops_mmap()
356 size -= PAGE_SIZE; in dlfb_ops_mmap()
388 for (k = width - 1; k > j; k--) { in dlfb_trim_hline()
395 identical = start + (width - end); in dlfb_trim_hline()
397 *width_bytes = (end - start) * sizeof(unsigned long); in dlfb_trim_hline()
411 * The function relies on the client to do all allocation, so that
414 * on where it left off, so the client may call in again with additional
443 (cmd_buffer_end - MIN_RLX_CMD_BYTES > cmd)) { in dlfb_compress_hline()
470 (unsigned long)(pixel_end - pixel), in dlfb_compress_hline()
471 (unsigned long)(cmd_buffer_end - 1 - cmd) / BPP); in dlfb_compress_hline()
475 while (cmd_pixel_end - 1 > pixel && in dlfb_compress_hline()
476 *(cmd_pixel_end - 1) == *(u16 *)((u8 *)(cmd_pixel_end - 1) + back_buffer_offset)) in dlfb_compress_hline()
477 cmd_pixel_end--; in dlfb_compress_hline()
493 *raw_pixels_count_byte = ((repeating_pixel - in dlfb_compress_hline()
504 *cmd++ = ((pixel - repeating_pixel) - 1) & 0xFF; in dlfb_compress_hline()
514 *raw_pixels_count_byte = (pixel-raw_pixel_start) & 0xFF; in dlfb_compress_hline()
517 cmd--; in dlfb_compress_hline()
520 *cmd_pixels_count_byte = (pixel - cmd_pixel_start) & 0xFF; in dlfb_compress_hline()
521 dev_addr += (u8 *)pixel - (u8 *)cmd_pixel_start; in dlfb_compress_hline()
524 if (cmd_buffer_end - MIN_RLX_CMD_BYTES <= cmd) { in dlfb_compress_hline()
525 /* Fill leftover bytes with no-ops */ in dlfb_compress_hline()
527 memset(cmd, 0xAF, cmd_buffer_end - cmd); in dlfb_compress_hline()
548 u32 dev_addr = dlfb->base16 + byte_offset; in dlfb_render_hline()
551 u8 *cmd_end = (u8 *) urb->transfer_buffer + urb->transfer_buffer_length; in dlfb_render_hline()
558 if (dlfb->backing_buffer) { in dlfb_render_hline()
560 const u8 *back_start = (u8 *) (dlfb->backing_buffer in dlfb_render_hline()
563 back_buffer_offset = (unsigned long)back_start - (unsigned long)line_start; in dlfb_render_hline()
568 offset = next_pixel - line_start; in dlfb_render_hline()
583 int len = cmd - (u8 *) urb->transfer_buffer; in dlfb_render_hline()
591 cmd = urb->transfer_buffer; in dlfb_render_hline()
592 cmd_end = &cmd[urb->transfer_buffer_length]; in dlfb_render_hline()
613 mutex_lock(&dlfb->render_mutex); in dlfb_handle_damage()
616 width = DL_ALIGN_UP(width + (x-aligned_x), sizeof(unsigned long)); in dlfb_handle_damage()
620 (x + width > dlfb->info->var.xres) || in dlfb_handle_damage()
621 (y + height > dlfb->info->var.yres)) { in dlfb_handle_damage()
622 ret = -EINVAL; in dlfb_handle_damage()
626 if (!atomic_read(&dlfb->usb_active)) { in dlfb_handle_damage()
636 cmd = urb->transfer_buffer; in dlfb_handle_damage()
639 const int line_offset = dlfb->info->fix.line_length * i; in dlfb_handle_damage()
643 (char *) dlfb->info->fix.smem_start, in dlfb_handle_damage()
649 if (cmd > (char *) urb->transfer_buffer) { in dlfb_handle_damage()
651 if (cmd < (char *) urb->transfer_buffer + urb->transfer_buffer_length) in dlfb_handle_damage()
654 len = cmd - (char *) urb->transfer_buffer; in dlfb_handle_damage()
661 atomic_add(bytes_sent, &dlfb->bytes_sent); in dlfb_handle_damage()
662 atomic_add(bytes_identical, &dlfb->bytes_identical); in dlfb_handle_damage()
663 atomic_add(width*height*2, &dlfb->bytes_rendered); in dlfb_handle_damage()
665 atomic_add(((unsigned int) ((end_cycles - start_cycles) in dlfb_handle_damage()
667 &dlfb->cpu_kcycles_used); in dlfb_handle_damage()
672 mutex_unlock(&dlfb->render_mutex); in dlfb_handle_damage()
678 dlfb->damage_x = INT_MAX; in dlfb_init_damage()
679 dlfb->damage_x2 = 0; in dlfb_init_damage()
680 dlfb->damage_y = INT_MAX; in dlfb_init_damage()
681 dlfb->damage_y2 = 0; in dlfb_init_damage()
689 spin_lock_irq(&dlfb->damage_lock); in dlfb_damage_work()
690 x = dlfb->damage_x; in dlfb_damage_work()
691 x2 = dlfb->damage_x2; in dlfb_damage_work()
692 y = dlfb->damage_y; in dlfb_damage_work()
693 y2 = dlfb->damage_y2; in dlfb_damage_work()
695 spin_unlock_irq(&dlfb->damage_lock); in dlfb_damage_work()
698 dlfb_handle_damage(dlfb, x, y, x2 - x, y2 - y); in dlfb_damage_work()
710 spin_lock_irqsave(&dlfb->damage_lock, flags); in dlfb_offload_damage()
711 dlfb->damage_x = min(x, dlfb->damage_x); in dlfb_offload_damage()
712 dlfb->damage_x2 = max(x2, dlfb->damage_x2); in dlfb_offload_damage()
713 dlfb->damage_y = min(y, dlfb->damage_y); in dlfb_offload_damage()
714 dlfb->damage_y2 = max(y2, dlfb->damage_y2); in dlfb_offload_damage()
715 spin_unlock_irqrestore(&dlfb->damage_lock, flags); in dlfb_offload_damage()
717 schedule_work(&dlfb->damage_work); in dlfb_offload_damage()
721 * NOTE: fb_defio.c is holding info->fbdefio.mutex
729 struct dlfb_data *dlfb = info->par; in dlfb_dpy_deferred_io()
737 mutex_lock(&dlfb->render_mutex); in dlfb_dpy_deferred_io()
742 if (!atomic_read(&dlfb->usb_active)) in dlfb_dpy_deferred_io()
751 cmd = urb->transfer_buffer; in dlfb_dpy_deferred_io()
755 if (dlfb_render_hline(dlfb, &urb, (char *) info->fix.smem_start, in dlfb_dpy_deferred_io()
756 &cmd, pageref->offset, PAGE_SIZE, in dlfb_dpy_deferred_io()
762 if (cmd > (char *) urb->transfer_buffer) { in dlfb_dpy_deferred_io()
764 if (cmd < (char *) urb->transfer_buffer + urb->transfer_buffer_length) in dlfb_dpy_deferred_io()
767 len = cmd - (char *) urb->transfer_buffer; in dlfb_dpy_deferred_io()
774 atomic_add(bytes_sent, &dlfb->bytes_sent); in dlfb_dpy_deferred_io()
775 atomic_add(bytes_identical, &dlfb->bytes_identical); in dlfb_dpy_deferred_io()
776 atomic_add(bytes_rendered, &dlfb->bytes_rendered); in dlfb_dpy_deferred_io()
778 atomic_add(((unsigned int) ((end_cycles - start_cycles) in dlfb_dpy_deferred_io()
780 &dlfb->cpu_kcycles_used); in dlfb_dpy_deferred_io()
782 mutex_unlock(&dlfb->render_mutex); in dlfb_dpy_deferred_io()
795 ret = usb_control_msg(dlfb->udev, in dlfb_get_edid()
796 usb_rcvctrlpipe(dlfb->udev, 0), 0x02, in dlfb_get_edid()
800 dev_err(&dlfb->udev->dev, in dlfb_get_edid()
802 i--; in dlfb_get_edid()
817 struct dlfb_data *dlfb = info->par; in dlfb_ops_ioctl()
819 if (!atomic_read(&dlfb->usb_active)) in dlfb_ops_ioctl()
825 if (copy_to_user(edid, dlfb->edid, dlfb->edid_size)) in dlfb_ops_ioctl()
826 return -EFAULT; in dlfb_ops_ioctl()
836 return -EFAULT; in dlfb_ops_ioctl()
839 * If we have a damage-aware client, turn fb_defio "off" in dlfb_ops_ioctl()
845 if (info->fbdefio) in dlfb_ops_ioctl()
846 info->fbdefio->delay = DL_DEFIO_WRITE_DISABLE; in dlfb_ops_ioctl()
851 if (area.x > info->var.xres) in dlfb_ops_ioctl()
852 area.x = info->var.xres; in dlfb_ops_ioctl()
857 if (area.y > info->var.yres) in dlfb_ops_ioctl()
858 area.y = info->var.yres; in dlfb_ops_ioctl()
868 dlfb_ops_setcolreg(unsigned regno, unsigned red, unsigned green, in dlfb_ops_setcolreg() argument
873 if (regno >= info->cmap.len) in dlfb_ops_setcolreg()
877 if (info->var.red.offset == 10) { in dlfb_ops_setcolreg()
879 ((u32 *) (info->pseudo_palette))[regno] = in dlfb_ops_setcolreg()
881 ((green & 0xf800) >> 6) | ((blue & 0xf800) >> 11); in dlfb_ops_setcolreg()
884 ((u32 *) (info->pseudo_palette))[regno] = in dlfb_ops_setcolreg()
886 ((green & 0xfc00) >> 5) | ((blue & 0xf800) >> 11); in dlfb_ops_setcolreg()
896 * Assumes caller is holding info->lock (for open and release at least)
900 struct dlfb_data *dlfb = info->par; in dlfb_ops_open()
908 return -EBUSY; in dlfb_ops_open()
911 if (dlfb->virtualized) in dlfb_ops_open()
912 return -ENODEV; in dlfb_ops_open()
914 dlfb->fb_count++; in dlfb_ops_open()
916 if (fb_defio && (info->fbdefio == NULL)) { in dlfb_ops_open()
924 fbdefio->delay = DL_DEFIO_WRITE_DELAY; in dlfb_ops_open()
925 fbdefio->sort_pagereflist = true; in dlfb_ops_open()
926 fbdefio->deferred_io = dlfb_dpy_deferred_io; in dlfb_ops_open()
929 info->fbdefio = fbdefio; in dlfb_ops_open()
933 dev_dbg(info->dev, "open, user=%d fb_info=%p count=%d\n", in dlfb_ops_open()
934 user, info, dlfb->fb_count); in dlfb_ops_open()
941 struct dlfb_data *dlfb = info->par; in dlfb_ops_destroy()
943 cancel_work_sync(&dlfb->damage_work); in dlfb_ops_destroy()
945 mutex_destroy(&dlfb->render_mutex); in dlfb_ops_destroy()
947 if (info->cmap.len != 0) in dlfb_ops_destroy()
948 fb_dealloc_cmap(&info->cmap); in dlfb_ops_destroy()
949 if (info->monspecs.modedb) in dlfb_ops_destroy()
950 fb_destroy_modedb(info->monspecs.modedb); in dlfb_ops_destroy()
951 vfree(info->screen_buffer); in dlfb_ops_destroy()
953 fb_destroy_modelist(&info->modelist); in dlfb_ops_destroy()
955 while (!list_empty(&dlfb->deferred_free)) { in dlfb_ops_destroy()
956 …struct dlfb_deferred_free *d = list_entry(dlfb->deferred_free.next, struct dlfb_deferred_free, lis… in dlfb_ops_destroy()
957 list_del(&d->list); in dlfb_ops_destroy()
958 vfree(d->mem); in dlfb_ops_destroy()
961 vfree(dlfb->backing_buffer); in dlfb_ops_destroy()
962 kfree(dlfb->edid); in dlfb_ops_destroy()
964 usb_put_dev(dlfb->udev); in dlfb_ops_destroy()
972 * Assumes caller is holding info->lock mutex (for open and release at least)
976 struct dlfb_data *dlfb = info->par; in dlfb_ops_release()
978 dlfb->fb_count--; in dlfb_ops_release()
980 if ((dlfb->fb_count == 0) && (info->fbdefio)) { in dlfb_ops_release()
982 kfree(info->fbdefio); in dlfb_ops_release()
983 info->fbdefio = NULL; in dlfb_ops_release()
986 dev_dbg(info->dev, "release, user=%d count=%d\n", user, dlfb->fb_count); in dlfb_ops_release()
997 if (mode->xres * mode->yres > dlfb->sku_pixel_limit) in dlfb_is_valid_mode()
1006 const struct fb_bitfield green = { 5, 6, 0 }; in dlfb_var_color_format() local
1009 var->bits_per_pixel = 16; in dlfb_var_color_format()
1010 var->red = red; in dlfb_var_color_format()
1011 var->green = green; in dlfb_var_color_format()
1012 var->blue = blue; in dlfb_var_color_format()
1019 struct dlfb_data *dlfb = info->par; in dlfb_ops_check_var()
1021 /* set device-specific elements of var unrelated to mode */ in dlfb_ops_check_var()
1027 return -EINVAL; in dlfb_ops_check_var()
1034 struct dlfb_data *dlfb = info->par; in dlfb_ops_set_par()
1039 u32 line_length = info->var.xres * (info->var.bits_per_pixel / 8); in dlfb_ops_set_par()
1042 fvs = info->var; in dlfb_ops_set_par()
1046 if (!memcmp(&dlfb->current_mode, &fvs, sizeof(struct fb_var_screeninfo))) in dlfb_ops_set_par()
1049 result = dlfb_realloc_framebuffer(dlfb, info, info->var.yres * line_length); in dlfb_ops_set_par()
1053 result = dlfb_set_video_mode(dlfb, &info->var); in dlfb_ops_set_par()
1058 dlfb->current_mode = fvs; in dlfb_ops_set_par()
1059 info->fix.line_length = line_length; in dlfb_ops_set_par()
1061 if (dlfb->fb_count == 0) { in dlfb_ops_set_par()
1065 pix_framebuffer = (u16 *)info->screen_buffer; in dlfb_ops_set_par()
1066 for (i = 0; i < info->fix.smem_len / 2; i++) in dlfb_ops_set_par()
1070 dlfb_handle_damage(dlfb, 0, 0, info->var.xres, info->var.yres); in dlfb_ops_set_par()
1095 struct dlfb_data *dlfb = info->par; in dlfb_ops_blank()
1099 dev_dbg(info->dev, "blank, mode %d --> %d\n", in dlfb_ops_blank()
1100 dlfb->blank_mode, blank_mode); in dlfb_ops_blank()
1102 if ((dlfb->blank_mode == FB_BLANK_POWERDOWN) && in dlfb_ops_blank()
1106 dlfb_set_video_mode(dlfb, &info->var); in dlfb_ops_blank()
1113 bufptr = (char *) urb->transfer_buffer; in dlfb_ops_blank()
1121 dlfb_submit_urb(dlfb, urb, bufptr - in dlfb_ops_blank()
1122 (char *) urb->transfer_buffer); in dlfb_ops_blank()
1124 dlfb->blank_mode = blank_mode; in dlfb_ops_blank()
1131 struct dlfb_data *dlfb = info->par; in dlfb_ops_damage_range()
1132 int start = max((int)(off / info->fix.line_length), 0); in dlfb_ops_damage_range()
1133 int lines = min((u32)((len / info->fix.line_length) + 1), (u32)info->var.yres); in dlfb_ops_damage_range()
1135 dlfb_handle_damage(dlfb, 0, start, info->var.xres, lines); in dlfb_ops_damage_range()
1140 struct dlfb_data *dlfb = info->par; in dlfb_ops_damage_area()
1170 d->mem = mem; in dlfb_deferred_vfree()
1171 list_add(&d->list, &dlfb->deferred_free); in dlfb_deferred_vfree()
1175 * Assumes &info->lock held by caller
1176 * Assumes no active clients have framebuffer open
1180 u32 old_len = info->fix.smem_len; in dlfb_realloc_framebuffer()
1181 const void *old_fb = info->screen_buffer; in dlfb_realloc_framebuffer()
1193 dev_err(info->dev, "Virtual framebuffer alloc failed\n"); in dlfb_realloc_framebuffer()
1194 return -ENOMEM; in dlfb_realloc_framebuffer()
1198 if (info->screen_buffer) { in dlfb_realloc_framebuffer()
1200 dlfb_deferred_vfree(dlfb, info->screen_buffer); in dlfb_realloc_framebuffer()
1203 info->screen_buffer = new_fb; in dlfb_realloc_framebuffer()
1204 info->fix.smem_len = new_len; in dlfb_realloc_framebuffer()
1205 info->fix.smem_start = (unsigned long) new_fb; in dlfb_realloc_framebuffer()
1206 info->flags = udlfb_info_flags; in dlfb_realloc_framebuffer()
1210 * on the physical USB device. We can function without this. in dlfb_realloc_framebuffer()
1212 * that were, in fact, unchanged - wasting limited USB bandwidth in dlfb_realloc_framebuffer()
1217 dev_info(info->dev, in dlfb_realloc_framebuffer()
1220 dlfb_deferred_vfree(dlfb, dlfb->backing_buffer); in dlfb_realloc_framebuffer()
1221 dlfb->backing_buffer = new_back; in dlfb_realloc_framebuffer()
1247 struct device *dev = info->device; in dlfb_setup_modes()
1251 if (info->dev) { in dlfb_setup_modes()
1253 mutex_lock(&info->lock); in dlfb_setup_modes()
1255 dev = info->dev; in dlfb_setup_modes()
1260 result = -ENOMEM; in dlfb_setup_modes()
1264 fb_destroy_modelist(&info->modelist); in dlfb_setup_modes()
1265 memset(&info->monspecs, 0, sizeof(info->monspecs)); in dlfb_setup_modes()
1272 while (tries--) { in dlfb_setup_modes()
1277 fb_edid_to_monspecs(edid, &info->monspecs); in dlfb_setup_modes()
1279 if (info->monspecs.modedb_len > 0) { in dlfb_setup_modes()
1280 dlfb->edid = edid; in dlfb_setup_modes()
1281 dlfb->edid_size = i; in dlfb_setup_modes()
1287 if (info->monspecs.modedb_len == 0) { in dlfb_setup_modes()
1290 if (dlfb->edid) { in dlfb_setup_modes()
1291 fb_edid_to_monspecs(dlfb->edid, &info->monspecs); in dlfb_setup_modes()
1292 if (info->monspecs.modedb_len > 0) in dlfb_setup_modes()
1298 if (info->monspecs.modedb_len == 0) { in dlfb_setup_modes()
1300 fb_edid_to_monspecs(default_edid, &info->monspecs); in dlfb_setup_modes()
1301 if (info->monspecs.modedb_len > 0) { in dlfb_setup_modes()
1303 dlfb->edid = edid; in dlfb_setup_modes()
1304 dlfb->edid_size = default_edid_size; in dlfb_setup_modes()
1311 if (info->monspecs.modedb_len > 0) { in dlfb_setup_modes()
1313 for (i = 0; i < info->monspecs.modedb_len; i++) { in dlfb_setup_modes()
1314 mode = &info->monspecs.modedb[i]; in dlfb_setup_modes()
1316 fb_add_videomode(mode, &info->modelist); in dlfb_setup_modes()
1319 mode->xres, mode->yres); in dlfb_setup_modes()
1322 info->monspecs.misc in dlfb_setup_modes()
1327 default_vmode = fb_find_best_display(&info->monspecs, in dlfb_setup_modes()
1328 &info->modelist); in dlfb_setup_modes()
1345 fb_add_videomode(mode, &info->modelist); in dlfb_setup_modes()
1348 mode->xres, mode->yres); in dlfb_setup_modes()
1359 &info->modelist); in dlfb_setup_modes()
1362 /* If we have good mode and no active clients*/ in dlfb_setup_modes()
1363 if ((default_vmode != NULL) && (dlfb->fb_count == 0)) { in dlfb_setup_modes()
1365 fb_videomode_to_var(&info->var, default_vmode); in dlfb_setup_modes()
1366 dlfb_var_color_format(&info->var); in dlfb_setup_modes()
1371 memcpy(&info->fix, &dlfb_fix, sizeof(dlfb_fix)); in dlfb_setup_modes()
1373 result = -EINVAL; in dlfb_setup_modes()
1376 if (edid && (dlfb->edid != edid)) in dlfb_setup_modes()
1379 if (info->dev) in dlfb_setup_modes()
1380 mutex_unlock(&info->lock); in dlfb_setup_modes()
1388 struct dlfb_data *dlfb = fb_info->par; in metrics_bytes_rendered_show()
1390 atomic_read(&dlfb->bytes_rendered)); in metrics_bytes_rendered_show()
1396 struct dlfb_data *dlfb = fb_info->par; in metrics_bytes_identical_show()
1398 atomic_read(&dlfb->bytes_identical)); in metrics_bytes_identical_show()
1404 struct dlfb_data *dlfb = fb_info->par; in metrics_bytes_sent_show()
1406 atomic_read(&dlfb->bytes_sent)); in metrics_bytes_sent_show()
1412 struct dlfb_data *dlfb = fb_info->par; in metrics_cpu_kcycles_used_show()
1414 atomic_read(&dlfb->cpu_kcycles_used)); in metrics_cpu_kcycles_used_show()
1423 struct dlfb_data *dlfb = fb_info->par; in edid_show()
1425 if (dlfb->edid == NULL) in edid_show()
1428 if ((off >= dlfb->edid_size) || (count > dlfb->edid_size)) in edid_show()
1431 if (off + count > dlfb->edid_size) in edid_show()
1432 count = dlfb->edid_size - off; in edid_show()
1434 memcpy(buf, dlfb->edid, count); in edid_show()
1445 struct dlfb_data *dlfb = fb_info->par; in edid_store()
1450 return -EINVAL; in edid_store()
1456 if (!dlfb->edid || memcmp(src, dlfb->edid, src_size)) in edid_store()
1457 return -EINVAL; in edid_store()
1471 struct dlfb_data *dlfb = fb_info->par; in metrics_reset_store()
1473 atomic_set(&dlfb->bytes_rendered, 0); in metrics_reset_store()
1474 atomic_set(&dlfb->bytes_identical, 0); in metrics_reset_store()
1475 atomic_set(&dlfb->bytes_sent, 0); in metrics_reset_store()
1476 atomic_set(&dlfb->cpu_kcycles_used, 0); in metrics_reset_store()
1509 ret = usb_control_msg_send(dlfb->udev, 0, NR_USB_REQUEST_CHANNEL, in dlfb_select_std_channel()
1536 if (0 == usb_get_extra_descriptor(intf->cur_altsetting, in dlfb_parse_vendor_descriptor()
1542 dev_info(&intf->dev, in dlfb_parse_vendor_descriptor()
1550 (desc[4] != total_len - 2)) /* length after type */ in dlfb_parse_vendor_descriptor()
1570 dev_warn(&intf->dev, in dlfb_parse_vendor_descriptor()
1573 dlfb->sku_pixel_limit = max_area; in dlfb_parse_vendor_descriptor()
1582 dev_info(&intf->dev, "vendor descriptor not available (%d)\n", in dlfb_parse_vendor_descriptor()
1590 dev_err(&intf->dev, "Unrecognized vendor firmware descriptor\n"); in dlfb_parse_vendor_descriptor()
1611 dev_err(&intf->dev, "%s: failed to allocate dlfb\n", __func__); in dlfb_usb_probe()
1612 return -ENOMEM; in dlfb_usb_probe()
1615 INIT_LIST_HEAD(&dlfb->deferred_free); in dlfb_usb_probe()
1617 dlfb->udev = usb_get_dev(usbdev); in dlfb_usb_probe()
1621 dev_err(&intf->dev, "Invalid DisplayLink device!\n"); in dlfb_usb_probe()
1622 retval = -EINVAL; in dlfb_usb_probe()
1626 dev_dbg(&intf->dev, "console enable=%d\n", console); in dlfb_usb_probe()
1627 dev_dbg(&intf->dev, "fb_defio enable=%d\n", fb_defio); in dlfb_usb_probe()
1628 dev_dbg(&intf->dev, "shadow enable=%d\n", shadow); in dlfb_usb_probe()
1630 dlfb->sku_pixel_limit = 2048 * 1152; /* default to maximum */ in dlfb_usb_probe()
1633 dev_err(&intf->dev, in dlfb_usb_probe()
1635 retval = -ENODEV; in dlfb_usb_probe()
1640 dev_warn(&intf->dev, in dlfb_usb_probe()
1642 dlfb->sku_pixel_limit, pixel_limit); in dlfb_usb_probe()
1643 dlfb->sku_pixel_limit = pixel_limit; in dlfb_usb_probe()
1648 info = framebuffer_alloc(0, &dlfb->udev->dev); in dlfb_usb_probe()
1650 retval = -ENOMEM; in dlfb_usb_probe()
1654 dlfb->info = info; in dlfb_usb_probe()
1655 info->par = dlfb; in dlfb_usb_probe()
1656 info->pseudo_palette = dlfb->pseudo_palette; in dlfb_usb_probe()
1657 dlfb->ops = dlfb_ops; in dlfb_usb_probe()
1658 info->fbops = &dlfb->ops; in dlfb_usb_probe()
1660 mutex_init(&dlfb->render_mutex); in dlfb_usb_probe()
1662 spin_lock_init(&dlfb->damage_lock); in dlfb_usb_probe()
1663 INIT_WORK(&dlfb->damage_work, dlfb_damage_work); in dlfb_usb_probe()
1665 INIT_LIST_HEAD(&info->modelist); in dlfb_usb_probe()
1668 retval = -ENOMEM; in dlfb_usb_probe()
1669 dev_err(&intf->dev, "unable to allocate urb list\n"); in dlfb_usb_probe()
1675 retval = fb_alloc_cmap(&info->cmap, 256, 0); in dlfb_usb_probe()
1677 dev_err(info->device, "cmap allocation failed: %d\n", retval); in dlfb_usb_probe()
1683 dev_err(info->device, in dlfb_usb_probe()
1690 atomic_set(&dlfb->usb_active, 1); in dlfb_usb_probe()
1693 dlfb_ops_check_var(&info->var, info); in dlfb_usb_probe()
1700 dev_err(info->device, "unable to register framebuffer: %d\n", in dlfb_usb_probe()
1707 retval = device_create_file(info->dev, attr); in dlfb_usb_probe()
1709 dev_warn(info->device, in dlfb_usb_probe()
1711 attr->attr.name, retval); in dlfb_usb_probe()
1714 retval = device_create_bin_file(info->dev, &edid_attr); in dlfb_usb_probe()
1716 dev_warn(info->device, "failed to create '%s' attribute: %d\n", in dlfb_usb_probe()
1719 dev_info(info->device, in dlfb_usb_probe()
1721 dev_name(info->dev), info->var.xres, info->var.yres, in dlfb_usb_probe()
1722 ((dlfb->backing_buffer) ? in dlfb_usb_probe()
1723 info->fix.smem_len * 2 : info->fix.smem_len) >> 10); in dlfb_usb_probe()
1727 if (dlfb->info) { in dlfb_usb_probe()
1728 dlfb_ops_destroy(dlfb->info); in dlfb_usb_probe()
1730 usb_put_dev(dlfb->udev); in dlfb_usb_probe()
1743 info = dlfb->info; in dlfb_usb_disconnect()
1745 dev_dbg(&intf->dev, "USB disconnect starting\n"); in dlfb_usb_disconnect()
1748 dlfb->virtualized = true; in dlfb_usb_disconnect()
1750 /* When non-active we'll update virtual framebuffer, but no new urbs */ in dlfb_usb_disconnect()
1751 atomic_set(&dlfb->usb_active, 0); in dlfb_usb_disconnect()
1753 /* this function will wait for all in-flight urbs to complete */ in dlfb_usb_disconnect()
1758 device_remove_file(info->dev, &fb_device_attrs[i]); in dlfb_usb_disconnect()
1759 device_remove_bin_file(info->dev, &edid_attr); in dlfb_usb_disconnect()
1775 struct urb_node *unode = urb->context; in dlfb_urb_completion()
1776 struct dlfb_data *dlfb = unode->dlfb; in dlfb_urb_completion()
1779 switch (urb->status) { in dlfb_urb_completion()
1783 case -ECONNRESET: in dlfb_urb_completion()
1784 case -ENOENT: in dlfb_urb_completion()
1785 case -ESHUTDOWN: in dlfb_urb_completion()
1786 /* sync/async unlink faults aren't errors */ in dlfb_urb_completion()
1789 dev_err(&dlfb->udev->dev, in dlfb_urb_completion()
1790 "%s - nonzero write bulk status received: %d\n", in dlfb_urb_completion()
1791 __func__, urb->status); in dlfb_urb_completion()
1792 atomic_set(&dlfb->lost_pixels, 1); in dlfb_urb_completion()
1796 urb->transfer_buffer_length = dlfb->urbs.size; /* reset to actual */ in dlfb_urb_completion()
1798 spin_lock_irqsave(&dlfb->urbs.lock, flags); in dlfb_urb_completion()
1799 list_add_tail(&unode->entry, &dlfb->urbs.list); in dlfb_urb_completion()
1800 dlfb->urbs.available++; in dlfb_urb_completion()
1801 spin_unlock_irqrestore(&dlfb->urbs.lock, flags); in dlfb_urb_completion()
1803 up(&dlfb->urbs.limit_sem); in dlfb_urb_completion()
1808 int count = dlfb->urbs.count; in dlfb_free_urb_list()
1814 while (count--) { in dlfb_free_urb_list()
1815 down(&dlfb->urbs.limit_sem); in dlfb_free_urb_list()
1817 spin_lock_irq(&dlfb->urbs.lock); in dlfb_free_urb_list()
1819 node = dlfb->urbs.list.next; /* have reserved one with sem */ in dlfb_free_urb_list()
1822 spin_unlock_irq(&dlfb->urbs.lock); in dlfb_free_urb_list()
1825 urb = unode->urb; in dlfb_free_urb_list()
1828 usb_free_coherent(urb->dev, dlfb->urbs.size, in dlfb_free_urb_list()
1829 urb->transfer_buffer, urb->transfer_dma); in dlfb_free_urb_list()
1834 dlfb->urbs.count = 0; in dlfb_free_urb_list()
1844 spin_lock_init(&dlfb->urbs.lock); in dlfb_alloc_urb_list()
1847 dlfb->urbs.size = size; in dlfb_alloc_urb_list()
1848 INIT_LIST_HEAD(&dlfb->urbs.list); in dlfb_alloc_urb_list()
1850 sema_init(&dlfb->urbs.limit_sem, 0); in dlfb_alloc_urb_list()
1851 dlfb->urbs.count = 0; in dlfb_alloc_urb_list()
1852 dlfb->urbs.available = 0; in dlfb_alloc_urb_list()
1854 while (dlfb->urbs.count * size < wanted_size) { in dlfb_alloc_urb_list()
1858 unode->dlfb = dlfb; in dlfb_alloc_urb_list()
1865 unode->urb = urb; in dlfb_alloc_urb_list()
1867 buf = usb_alloc_coherent(dlfb->udev, size, GFP_KERNEL, in dlfb_alloc_urb_list()
1868 &urb->transfer_dma); in dlfb_alloc_urb_list()
1880 /* urb->transfer_buffer_length set to actual before submit */ in dlfb_alloc_urb_list()
1881 usb_fill_bulk_urb(urb, dlfb->udev, in dlfb_alloc_urb_list()
1882 usb_sndbulkpipe(dlfb->udev, OUT_EP_NUM), in dlfb_alloc_urb_list()
1884 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; in dlfb_alloc_urb_list()
1886 list_add_tail(&unode->entry, &dlfb->urbs.list); in dlfb_alloc_urb_list()
1888 up(&dlfb->urbs.limit_sem); in dlfb_alloc_urb_list()
1889 dlfb->urbs.count++; in dlfb_alloc_urb_list()
1890 dlfb->urbs.available++; in dlfb_alloc_urb_list()
1893 return dlfb->urbs.count; in dlfb_alloc_urb_list()
1902 /* Wait for an in-flight buffer to complete and get re-queued */ in dlfb_get_urb()
1903 ret = down_timeout(&dlfb->urbs.limit_sem, GET_URB_TIMEOUT); in dlfb_get_urb()
1905 atomic_set(&dlfb->lost_pixels, 1); in dlfb_get_urb()
1906 dev_warn(&dlfb->udev->dev, in dlfb_get_urb()
1908 ret, dlfb->urbs.available); in dlfb_get_urb()
1912 spin_lock_irq(&dlfb->urbs.lock); in dlfb_get_urb()
1914 BUG_ON(list_empty(&dlfb->urbs.list)); /* reserved one with limit_sem */ in dlfb_get_urb()
1915 entry = dlfb->urbs.list.next; in dlfb_get_urb()
1917 dlfb->urbs.available--; in dlfb_get_urb()
1919 spin_unlock_irq(&dlfb->urbs.lock); in dlfb_get_urb()
1922 return unode->urb; in dlfb_get_urb()
1929 BUG_ON(len > dlfb->urbs.size); in dlfb_submit_urb()
1931 urb->transfer_buffer_length = len; /* set to actual payload len */ in dlfb_submit_urb()
1935 atomic_set(&dlfb->lost_pixels, 1); in dlfb_submit_urb()
1936 dev_err(&dlfb->udev->dev, "submit urb error: %d\n", ret); in dlfb_submit_urb()
1951 MODULE_PARM_DESC(pixel_limit, "Force limit on max mode (in x*y pixels)");