blob: fe373b63ddd6d0422c2aeab8106d0efa47f623af [file] [log] [blame]
Googler9398cc32022-12-02 17:21:52 +08001// SPDX-License-Identifier: GPL-2.0-only
Googleraf606d22022-10-26 21:40:12 -07002/*
3 * udlfb.c -- Framebuffer driver for DisplayLink USB controller
4 *
5 * Copyright (C) 2009 Roberto De Ioris <roberto@unbit.it>
6 * Copyright (C) 2009 Jaya Kumar <jayakumar.lkml@gmail.com>
7 * Copyright (C) 2009 Bernie Thompson <bernie@plugable.com>
8 *
9 * Layout is based on skeletonfb by James Simmons and Geert Uytterhoeven,
10 * usb-skeleton by GregKH.
11 *
12 * Device-specific portions based on information from Displaylink, with work
13 * from Florian Echtler, Henrik Bjerregaard Pedersen, and others.
14 */
15
16#include <linux/module.h>
17#include <linux/kernel.h>
18#include <linux/init.h>
19#include <linux/usb.h>
20#include <linux/uaccess.h>
21#include <linux/mm.h>
22#include <linux/fb.h>
23#include <linux/vmalloc.h>
24#include <linux/slab.h>
25#include <linux/delay.h>
Googler9398cc32022-12-02 17:21:52 +080026#include <asm/unaligned.h>
Googleraf606d22022-10-26 21:40:12 -070027#include <video/udlfb.h>
28#include "edid.h"
29
Googler9398cc32022-12-02 17:21:52 +080030static const struct fb_fix_screeninfo dlfb_fix = {
Googleraf606d22022-10-26 21:40:12 -070031 .id = "udlfb",
32 .type = FB_TYPE_PACKED_PIXELS,
33 .visual = FB_VISUAL_TRUECOLOR,
34 .xpanstep = 0,
35 .ypanstep = 0,
36 .ywrapstep = 0,
37 .accel = FB_ACCEL_NONE,
38};
39
40static const u32 udlfb_info_flags = FBINFO_DEFAULT | FBINFO_READS_FAST |
41 FBINFO_VIRTFB |
42 FBINFO_HWACCEL_IMAGEBLIT | FBINFO_HWACCEL_FILLRECT |
43 FBINFO_HWACCEL_COPYAREA | FBINFO_MISC_ALWAYS_SETPAR;
44
45/*
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)
48 * We also require a match on SubClass (0x00) and Protocol (0x00),
49 * which is compatible with all known USB 2.0 era graphics chips and firmware,
50 * but allows DisplayLink to increment those for any future incompatible chips
51 */
Googler9398cc32022-12-02 17:21:52 +080052static const struct usb_device_id id_table[] = {
Googleraf606d22022-10-26 21:40:12 -070053 {.idVendor = 0x17e9,
54 .bInterfaceClass = 0xff,
55 .bInterfaceSubClass = 0x00,
56 .bInterfaceProtocol = 0x00,
57 .match_flags = USB_DEVICE_ID_MATCH_VENDOR |
58 USB_DEVICE_ID_MATCH_INT_CLASS |
59 USB_DEVICE_ID_MATCH_INT_SUBCLASS |
60 USB_DEVICE_ID_MATCH_INT_PROTOCOL,
61 },
62 {},
63};
64MODULE_DEVICE_TABLE(usb, id_table);
65
66/* module options */
67static bool console = 1; /* Allow fbcon to open framebuffer */
68static bool fb_defio = 1; /* Detect mmap writes using page faults */
69static bool shadow = 1; /* Optionally disable shadow framebuffer */
70static int pixel_limit; /* Optionally force a pixel resolution limit */
71
Googler9398cc32022-12-02 17:21:52 +080072struct dlfb_deferred_free {
73 struct list_head list;
74 void *mem;
75};
76
77static int dlfb_realloc_framebuffer(struct dlfb_data *dlfb, struct fb_info *info, u32 new_len);
78
Googleraf606d22022-10-26 21:40:12 -070079/* dlfb keeps a list of urbs for efficient bulk transfers */
80static void dlfb_urb_completion(struct urb *urb);
Googler9398cc32022-12-02 17:21:52 +080081static struct urb *dlfb_get_urb(struct dlfb_data *dlfb);
82static int dlfb_submit_urb(struct dlfb_data *dlfb, struct urb * urb, size_t len);
83static int dlfb_alloc_urb_list(struct dlfb_data *dlfb, int count, size_t size);
84static void dlfb_free_urb_list(struct dlfb_data *dlfb);
Googleraf606d22022-10-26 21:40:12 -070085
86/*
87 * All DisplayLink bulk operations start with 0xAF, followed by specific code
88 * All operations are written to buffers which then later get sent to device
89 */
90static char *dlfb_set_register(char *buf, u8 reg, u8 val)
91{
92 *buf++ = 0xAF;
93 *buf++ = 0x20;
94 *buf++ = reg;
95 *buf++ = val;
96 return buf;
97}
98
99static char *dlfb_vidreg_lock(char *buf)
100{
101 return dlfb_set_register(buf, 0xFF, 0x00);
102}
103
104static char *dlfb_vidreg_unlock(char *buf)
105{
106 return dlfb_set_register(buf, 0xFF, 0xFF);
107}
108
109/*
110 * Map FB_BLANK_* to DisplayLink register
111 * DLReg FB_BLANK_*
112 * ----- -----------------------------
113 * 0x00 FB_BLANK_UNBLANK (0)
114 * 0x01 FB_BLANK (1)
115 * 0x03 FB_BLANK_VSYNC_SUSPEND (2)
116 * 0x05 FB_BLANK_HSYNC_SUSPEND (3)
117 * 0x07 FB_BLANK_POWERDOWN (4) Note: requires modeset to come back
118 */
119static char *dlfb_blanking(char *buf, int fb_blank)
120{
121 u8 reg;
122
123 switch (fb_blank) {
124 case FB_BLANK_POWERDOWN:
125 reg = 0x07;
126 break;
127 case FB_BLANK_HSYNC_SUSPEND:
128 reg = 0x05;
129 break;
130 case FB_BLANK_VSYNC_SUSPEND:
131 reg = 0x03;
132 break;
133 case FB_BLANK_NORMAL:
134 reg = 0x01;
135 break;
136 default:
137 reg = 0x00;
138 }
139
140 buf = dlfb_set_register(buf, 0x1F, reg);
141
142 return buf;
143}
144
145static char *dlfb_set_color_depth(char *buf, u8 selection)
146{
147 return dlfb_set_register(buf, 0x00, selection);
148}
149
150static char *dlfb_set_base16bpp(char *wrptr, u32 base)
151{
152 /* the base pointer is 16 bits wide, 0x20 is hi byte. */
153 wrptr = dlfb_set_register(wrptr, 0x20, base >> 16);
154 wrptr = dlfb_set_register(wrptr, 0x21, base >> 8);
155 return dlfb_set_register(wrptr, 0x22, base);
156}
157
158/*
159 * DisplayLink HW has separate 16bpp and 8bpp framebuffers.
160 * In 24bpp modes, the low 323 RGB bits go in the 8bpp framebuffer
161 */
162static char *dlfb_set_base8bpp(char *wrptr, u32 base)
163{
164 wrptr = dlfb_set_register(wrptr, 0x26, base >> 16);
165 wrptr = dlfb_set_register(wrptr, 0x27, base >> 8);
166 return dlfb_set_register(wrptr, 0x28, base);
167}
168
169static char *dlfb_set_register_16(char *wrptr, u8 reg, u16 value)
170{
171 wrptr = dlfb_set_register(wrptr, reg, value >> 8);
172 return dlfb_set_register(wrptr, reg+1, value);
173}
174
175/*
176 * This is kind of weird because the controller takes some
177 * register values in a different byte order than other registers.
178 */
179static char *dlfb_set_register_16be(char *wrptr, u8 reg, u16 value)
180{
181 wrptr = dlfb_set_register(wrptr, reg, value);
182 return dlfb_set_register(wrptr, reg+1, value >> 8);
183}
184
185/*
186 * LFSR is linear feedback shift register. The reason we have this is
187 * because the display controller needs to minimize the clock depth of
188 * various counters used in the display path. So this code reverses the
189 * provided value into the lfsr16 value by counting backwards to get
190 * the value that needs to be set in the hardware comparator to get the
191 * same actual count. This makes sense once you read above a couple of
192 * times and think about it from a hardware perspective.
193 */
194static u16 dlfb_lfsr16(u16 actual_count)
195{
196 u32 lv = 0xFFFF; /* This is the lfsr value that the hw starts with */
197
198 while (actual_count--) {
199 lv = ((lv << 1) |
200 (((lv >> 15) ^ (lv >> 4) ^ (lv >> 2) ^ (lv >> 1)) & 1))
201 & 0xFFFF;
202 }
203
204 return (u16) lv;
205}
206
207/*
208 * This does LFSR conversion on the value that is to be written.
209 * See LFSR explanation above for more detail.
210 */
211static char *dlfb_set_register_lfsr16(char *wrptr, u8 reg, u16 value)
212{
213 return dlfb_set_register_16(wrptr, reg, dlfb_lfsr16(value));
214}
215
216/*
217 * This takes a standard fbdev screeninfo struct and all of its monitor mode
218 * details and converts them into the DisplayLink equivalent register commands.
219 */
220static char *dlfb_set_vid_cmds(char *wrptr, struct fb_var_screeninfo *var)
221{
222 u16 xds, yds;
223 u16 xde, yde;
224 u16 yec;
225
226 /* x display start */
227 xds = var->left_margin + var->hsync_len;
228 wrptr = dlfb_set_register_lfsr16(wrptr, 0x01, xds);
229 /* x display end */
230 xde = xds + var->xres;
231 wrptr = dlfb_set_register_lfsr16(wrptr, 0x03, xde);
232
233 /* y display start */
234 yds = var->upper_margin + var->vsync_len;
235 wrptr = dlfb_set_register_lfsr16(wrptr, 0x05, yds);
236 /* y display end */
237 yde = yds + var->yres;
238 wrptr = dlfb_set_register_lfsr16(wrptr, 0x07, yde);
239
240 /* x end count is active + blanking - 1 */
241 wrptr = dlfb_set_register_lfsr16(wrptr, 0x09,
242 xde + var->right_margin - 1);
243
244 /* libdlo hardcodes hsync start to 1 */
245 wrptr = dlfb_set_register_lfsr16(wrptr, 0x0B, 1);
246
247 /* hsync end is width of sync pulse + 1 */
248 wrptr = dlfb_set_register_lfsr16(wrptr, 0x0D, var->hsync_len + 1);
249
250 /* hpixels is active pixels */
251 wrptr = dlfb_set_register_16(wrptr, 0x0F, var->xres);
252
253 /* yendcount is vertical active + vertical blanking */
254 yec = var->yres + var->upper_margin + var->lower_margin +
255 var->vsync_len;
256 wrptr = dlfb_set_register_lfsr16(wrptr, 0x11, yec);
257
258 /* libdlo hardcodes vsync start to 0 */
259 wrptr = dlfb_set_register_lfsr16(wrptr, 0x13, 0);
260
261 /* vsync end is width of vsync pulse */
262 wrptr = dlfb_set_register_lfsr16(wrptr, 0x15, var->vsync_len);
263
264 /* vpixels is active pixels */
265 wrptr = dlfb_set_register_16(wrptr, 0x17, var->yres);
266
267 /* convert picoseconds to 5kHz multiple for pclk5k = x * 1E12/5k */
268 wrptr = dlfb_set_register_16be(wrptr, 0x1B,
269 200*1000*1000/var->pixclock);
270
271 return wrptr;
272}
273
274/*
275 * This takes a standard fbdev screeninfo struct that was fetched or prepared
276 * and then generates the appropriate command sequence that then drives the
277 * display controller.
278 */
Googler9398cc32022-12-02 17:21:52 +0800279static int dlfb_set_video_mode(struct dlfb_data *dlfb,
Googleraf606d22022-10-26 21:40:12 -0700280 struct fb_var_screeninfo *var)
281{
282 char *buf;
283 char *wrptr;
284 int retval;
285 int writesize;
286 struct urb *urb;
287
Googler9398cc32022-12-02 17:21:52 +0800288 if (!atomic_read(&dlfb->usb_active))
Googleraf606d22022-10-26 21:40:12 -0700289 return -EPERM;
290
Googler9398cc32022-12-02 17:21:52 +0800291 urb = dlfb_get_urb(dlfb);
Googleraf606d22022-10-26 21:40:12 -0700292 if (!urb)
293 return -ENOMEM;
294
295 buf = (char *) urb->transfer_buffer;
296
297 /*
298 * This first section has to do with setting the base address on the
299 * controller * associated with the display. There are 2 base
300 * pointers, currently, we only * use the 16 bpp segment.
301 */
302 wrptr = dlfb_vidreg_lock(buf);
303 wrptr = dlfb_set_color_depth(wrptr, 0x00);
304 /* set base for 16bpp segment to 0 */
305 wrptr = dlfb_set_base16bpp(wrptr, 0);
306 /* set base for 8bpp segment to end of fb */
Googler9398cc32022-12-02 17:21:52 +0800307 wrptr = dlfb_set_base8bpp(wrptr, dlfb->info->fix.smem_len);
Googleraf606d22022-10-26 21:40:12 -0700308
309 wrptr = dlfb_set_vid_cmds(wrptr, var);
310 wrptr = dlfb_blanking(wrptr, FB_BLANK_UNBLANK);
311 wrptr = dlfb_vidreg_unlock(wrptr);
312
313 writesize = wrptr - buf;
314
Googler9398cc32022-12-02 17:21:52 +0800315 retval = dlfb_submit_urb(dlfb, urb, writesize);
Googleraf606d22022-10-26 21:40:12 -0700316
Googler9398cc32022-12-02 17:21:52 +0800317 dlfb->blank_mode = FB_BLANK_UNBLANK;
Googleraf606d22022-10-26 21:40:12 -0700318
319 return retval;
320}
321
322static int dlfb_ops_mmap(struct fb_info *info, struct vm_area_struct *vma)
323{
324 unsigned long start = vma->vm_start;
325 unsigned long size = vma->vm_end - vma->vm_start;
326 unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
327 unsigned long page, pos;
328
329 if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT))
330 return -EINVAL;
331 if (size > info->fix.smem_len)
332 return -EINVAL;
333 if (offset > info->fix.smem_len - size)
334 return -EINVAL;
335
336 pos = (unsigned long)info->fix.smem_start + offset;
337
Googler9398cc32022-12-02 17:21:52 +0800338 dev_dbg(info->dev, "mmap() framebuffer addr:%lu size:%lu\n",
339 pos, size);
Googleraf606d22022-10-26 21:40:12 -0700340
341 while (size > 0) {
342 page = vmalloc_to_pfn((void *)pos);
343 if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED))
344 return -EAGAIN;
345
346 start += PAGE_SIZE;
347 pos += PAGE_SIZE;
348 if (size > PAGE_SIZE)
349 size -= PAGE_SIZE;
350 else
351 size = 0;
352 }
353
354 return 0;
355}
356
357/*
358 * Trims identical data from front and back of line
359 * Sets new front buffer address and width
360 * And returns byte count of identical pixels
361 * Assumes CPU natural alignment (unsigned long)
362 * for back and front buffer ptrs and width
363 */
364static int dlfb_trim_hline(const u8 *bback, const u8 **bfront, int *width_bytes)
365{
366 int j, k;
367 const unsigned long *back = (const unsigned long *) bback;
368 const unsigned long *front = (const unsigned long *) *bfront;
369 const int width = *width_bytes / sizeof(unsigned long);
370 int identical = width;
371 int start = width;
372 int end = width;
373
374 for (j = 0; j < width; j++) {
375 if (back[j] != front[j]) {
376 start = j;
377 break;
378 }
379 }
380
381 for (k = width - 1; k > j; k--) {
382 if (back[k] != front[k]) {
383 end = k+1;
384 break;
385 }
386 }
387
388 identical = start + (width - end);
389 *bfront = (u8 *) &front[start];
390 *width_bytes = (end - start) * sizeof(unsigned long);
391
392 return identical * sizeof(unsigned long);
393}
394
395/*
396 * Render a command stream for an encoded horizontal line segment of pixels.
397 *
398 * A command buffer holds several commands.
399 * It always begins with a fresh command header
400 * (the protocol doesn't require this, but we enforce it to allow
401 * multiple buffers to be potentially encoded and sent in parallel).
402 * A single command encodes one contiguous horizontal line of pixels
403 *
404 * The function relies on the client to do all allocation, so that
405 * rendering can be done directly to output buffers (e.g. USB URBs).
406 * The function fills the supplied command buffer, providing information
407 * on where it left off, so the client may call in again with additional
408 * buffers if the line will take several buffers to complete.
409 *
410 * A single command can transmit a maximum of 256 pixels,
411 * regardless of the compression ratio (protocol design limit).
412 * To the hardware, 0 for a size byte means 256
413 *
414 * Rather than 256 pixel commands which are either rl or raw encoded,
415 * the rlx command simply assumes alternating raw and rl spans within one cmd.
416 * This has a slightly larger header overhead, but produces more even results.
417 * It also processes all data (read and write) in a single pass.
418 * Performance benchmarks of common cases show it having just slightly better
419 * compression than 256 pixel raw or rle commands, with similar CPU consumpion.
420 * But for very rl friendly data, will compress not quite as well.
421 */
422static void dlfb_compress_hline(
423 const uint16_t **pixel_start_ptr,
424 const uint16_t *const pixel_end,
425 uint32_t *device_address_ptr,
426 uint8_t **command_buffer_ptr,
Googler9398cc32022-12-02 17:21:52 +0800427 const uint8_t *const cmd_buffer_end,
428 unsigned long back_buffer_offset,
429 int *ident_ptr)
Googleraf606d22022-10-26 21:40:12 -0700430{
431 const uint16_t *pixel = *pixel_start_ptr;
432 uint32_t dev_addr = *device_address_ptr;
433 uint8_t *cmd = *command_buffer_ptr;
434
435 while ((pixel_end > pixel) &&
436 (cmd_buffer_end - MIN_RLX_CMD_BYTES > cmd)) {
437 uint8_t *raw_pixels_count_byte = NULL;
438 uint8_t *cmd_pixels_count_byte = NULL;
439 const uint16_t *raw_pixel_start = NULL;
440 const uint16_t *cmd_pixel_start, *cmd_pixel_end = NULL;
441
Googler9398cc32022-12-02 17:21:52 +0800442 if (back_buffer_offset &&
443 *pixel == *(u16 *)((u8 *)pixel + back_buffer_offset)) {
444 pixel++;
445 dev_addr += BPP;
446 (*ident_ptr)++;
447 continue;
448 }
Googleraf606d22022-10-26 21:40:12 -0700449
450 *cmd++ = 0xAF;
451 *cmd++ = 0x6B;
Googler9398cc32022-12-02 17:21:52 +0800452 *cmd++ = dev_addr >> 16;
453 *cmd++ = dev_addr >> 8;
454 *cmd++ = dev_addr;
Googleraf606d22022-10-26 21:40:12 -0700455
456 cmd_pixels_count_byte = cmd++; /* we'll know this later */
457 cmd_pixel_start = pixel;
458
459 raw_pixels_count_byte = cmd++; /* we'll know this later */
460 raw_pixel_start = pixel;
461
Googler9398cc32022-12-02 17:21:52 +0800462 cmd_pixel_end = pixel + min3(MAX_CMD_PIXELS + 1UL,
463 (unsigned long)(pixel_end - pixel),
464 (unsigned long)(cmd_buffer_end - 1 - cmd) / BPP);
Googleraf606d22022-10-26 21:40:12 -0700465
Googler9398cc32022-12-02 17:21:52 +0800466 if (back_buffer_offset) {
467 /* note: the framebuffer may change under us, so we must test for underflow */
468 while (cmd_pixel_end - 1 > pixel &&
469 *(cmd_pixel_end - 1) == *(u16 *)((u8 *)(cmd_pixel_end - 1) + back_buffer_offset))
470 cmd_pixel_end--;
471 }
Googleraf606d22022-10-26 21:40:12 -0700472
473 while (pixel < cmd_pixel_end) {
474 const uint16_t * const repeating_pixel = pixel;
Googler9398cc32022-12-02 17:21:52 +0800475 u16 pixel_value = *pixel;
Googleraf606d22022-10-26 21:40:12 -0700476
Googler9398cc32022-12-02 17:21:52 +0800477 put_unaligned_be16(pixel_value, cmd);
478 if (back_buffer_offset)
479 *(u16 *)((u8 *)pixel + back_buffer_offset) = pixel_value;
Googleraf606d22022-10-26 21:40:12 -0700480 cmd += 2;
481 pixel++;
482
483 if (unlikely((pixel < cmd_pixel_end) &&
Googler9398cc32022-12-02 17:21:52 +0800484 (*pixel == pixel_value))) {
Googleraf606d22022-10-26 21:40:12 -0700485 /* go back and fill in raw pixel count */
486 *raw_pixels_count_byte = ((repeating_pixel -
487 raw_pixel_start) + 1) & 0xFF;
488
Googler9398cc32022-12-02 17:21:52 +0800489 do {
490 if (back_buffer_offset)
491 *(u16 *)((u8 *)pixel + back_buffer_offset) = pixel_value;
Googleraf606d22022-10-26 21:40:12 -0700492 pixel++;
Googler9398cc32022-12-02 17:21:52 +0800493 } while ((pixel < cmd_pixel_end) &&
494 (*pixel == pixel_value));
Googleraf606d22022-10-26 21:40:12 -0700495
496 /* immediately after raw data is repeat byte */
497 *cmd++ = ((pixel - repeating_pixel) - 1) & 0xFF;
498
499 /* Then start another raw pixel span */
500 raw_pixel_start = pixel;
501 raw_pixels_count_byte = cmd++;
502 }
503 }
504
505 if (pixel > raw_pixel_start) {
506 /* finalize last RAW span */
507 *raw_pixels_count_byte = (pixel-raw_pixel_start) & 0xFF;
Googler9398cc32022-12-02 17:21:52 +0800508 } else {
509 /* undo unused byte */
510 cmd--;
Googleraf606d22022-10-26 21:40:12 -0700511 }
512
513 *cmd_pixels_count_byte = (pixel - cmd_pixel_start) & 0xFF;
Googler9398cc32022-12-02 17:21:52 +0800514 dev_addr += (u8 *)pixel - (u8 *)cmd_pixel_start;
Googleraf606d22022-10-26 21:40:12 -0700515 }
516
Googler9398cc32022-12-02 17:21:52 +0800517 if (cmd_buffer_end - MIN_RLX_CMD_BYTES <= cmd) {
Googleraf606d22022-10-26 21:40:12 -0700518 /* Fill leftover bytes with no-ops */
519 if (cmd_buffer_end > cmd)
520 memset(cmd, 0xAF, cmd_buffer_end - cmd);
521 cmd = (uint8_t *) cmd_buffer_end;
522 }
523
524 *command_buffer_ptr = cmd;
525 *pixel_start_ptr = pixel;
526 *device_address_ptr = dev_addr;
527}
528
529/*
530 * There are 3 copies of every pixel: The front buffer that the fbdev
531 * client renders to, the actual framebuffer across the USB bus in hardware
532 * (that we can only write to, slowly, and can never read), and (optionally)
533 * our shadow copy that tracks what's been sent to that hardware buffer.
534 */
Googler9398cc32022-12-02 17:21:52 +0800535static int dlfb_render_hline(struct dlfb_data *dlfb, struct urb **urb_ptr,
Googleraf606d22022-10-26 21:40:12 -0700536 const char *front, char **urb_buf_ptr,
537 u32 byte_offset, u32 byte_width,
538 int *ident_ptr, int *sent_ptr)
539{
540 const u8 *line_start, *line_end, *next_pixel;
Googler9398cc32022-12-02 17:21:52 +0800541 u32 dev_addr = dlfb->base16 + byte_offset;
Googleraf606d22022-10-26 21:40:12 -0700542 struct urb *urb = *urb_ptr;
543 u8 *cmd = *urb_buf_ptr;
544 u8 *cmd_end = (u8 *) urb->transfer_buffer + urb->transfer_buffer_length;
Googler9398cc32022-12-02 17:21:52 +0800545 unsigned long back_buffer_offset = 0;
Googleraf606d22022-10-26 21:40:12 -0700546
547 line_start = (u8 *) (front + byte_offset);
548 next_pixel = line_start;
549 line_end = next_pixel + byte_width;
550
Googler9398cc32022-12-02 17:21:52 +0800551 if (dlfb->backing_buffer) {
Googleraf606d22022-10-26 21:40:12 -0700552 int offset;
Googler9398cc32022-12-02 17:21:52 +0800553 const u8 *back_start = (u8 *) (dlfb->backing_buffer
Googleraf606d22022-10-26 21:40:12 -0700554 + byte_offset);
555
Googler9398cc32022-12-02 17:21:52 +0800556 back_buffer_offset = (unsigned long)back_start - (unsigned long)line_start;
557
Googleraf606d22022-10-26 21:40:12 -0700558 *ident_ptr += dlfb_trim_hline(back_start, &next_pixel,
559 &byte_width);
560
561 offset = next_pixel - line_start;
562 line_end = next_pixel + byte_width;
563 dev_addr += offset;
564 back_start += offset;
565 line_start += offset;
566 }
567
568 while (next_pixel < line_end) {
569
570 dlfb_compress_hline((const uint16_t **) &next_pixel,
571 (const uint16_t *) line_end, &dev_addr,
Googler9398cc32022-12-02 17:21:52 +0800572 (u8 **) &cmd, (u8 *) cmd_end, back_buffer_offset,
573 ident_ptr);
Googleraf606d22022-10-26 21:40:12 -0700574
575 if (cmd >= cmd_end) {
576 int len = cmd - (u8 *) urb->transfer_buffer;
Googler9398cc32022-12-02 17:21:52 +0800577 if (dlfb_submit_urb(dlfb, urb, len))
Googleraf606d22022-10-26 21:40:12 -0700578 return 1; /* lost pixels is set */
579 *sent_ptr += len;
Googler9398cc32022-12-02 17:21:52 +0800580 urb = dlfb_get_urb(dlfb);
Googleraf606d22022-10-26 21:40:12 -0700581 if (!urb)
582 return 1; /* lost_pixels is set */
583 *urb_ptr = urb;
584 cmd = urb->transfer_buffer;
585 cmd_end = &cmd[urb->transfer_buffer_length];
586 }
587 }
588
589 *urb_buf_ptr = cmd;
590
591 return 0;
592}
593
Googler9398cc32022-12-02 17:21:52 +0800594static int dlfb_handle_damage(struct dlfb_data *dlfb, int x, int y, int width, int height)
Googleraf606d22022-10-26 21:40:12 -0700595{
596 int i, ret;
597 char *cmd;
598 cycles_t start_cycles, end_cycles;
599 int bytes_sent = 0;
600 int bytes_identical = 0;
601 struct urb *urb;
602 int aligned_x;
603
604 start_cycles = get_cycles();
605
Googler9398cc32022-12-02 17:21:52 +0800606 mutex_lock(&dlfb->render_mutex);
607
Googleraf606d22022-10-26 21:40:12 -0700608 aligned_x = DL_ALIGN_DOWN(x, sizeof(unsigned long));
609 width = DL_ALIGN_UP(width + (x-aligned_x), sizeof(unsigned long));
610 x = aligned_x;
611
612 if ((width <= 0) ||
Googler9398cc32022-12-02 17:21:52 +0800613 (x + width > dlfb->info->var.xres) ||
614 (y + height > dlfb->info->var.yres)) {
615 ret = -EINVAL;
616 goto unlock_ret;
617 }
Googleraf606d22022-10-26 21:40:12 -0700618
Googler9398cc32022-12-02 17:21:52 +0800619 if (!atomic_read(&dlfb->usb_active)) {
620 ret = 0;
621 goto unlock_ret;
622 }
Googleraf606d22022-10-26 21:40:12 -0700623
Googler9398cc32022-12-02 17:21:52 +0800624 urb = dlfb_get_urb(dlfb);
625 if (!urb) {
626 ret = 0;
627 goto unlock_ret;
628 }
Googleraf606d22022-10-26 21:40:12 -0700629 cmd = urb->transfer_buffer;
630
631 for (i = y; i < y + height ; i++) {
Googler9398cc32022-12-02 17:21:52 +0800632 const int line_offset = dlfb->info->fix.line_length * i;
Googleraf606d22022-10-26 21:40:12 -0700633 const int byte_offset = line_offset + (x * BPP);
634
Googler9398cc32022-12-02 17:21:52 +0800635 if (dlfb_render_hline(dlfb, &urb,
636 (char *) dlfb->info->fix.smem_start,
Googleraf606d22022-10-26 21:40:12 -0700637 &cmd, byte_offset, width * BPP,
638 &bytes_identical, &bytes_sent))
639 goto error;
640 }
641
642 if (cmd > (char *) urb->transfer_buffer) {
Googler9398cc32022-12-02 17:21:52 +0800643 int len;
644 if (cmd < (char *) urb->transfer_buffer + urb->transfer_buffer_length)
645 *cmd++ = 0xAF;
Googleraf606d22022-10-26 21:40:12 -0700646 /* Send partial buffer remaining before exiting */
Googler9398cc32022-12-02 17:21:52 +0800647 len = cmd - (char *) urb->transfer_buffer;
648 dlfb_submit_urb(dlfb, urb, len);
Googleraf606d22022-10-26 21:40:12 -0700649 bytes_sent += len;
650 } else
651 dlfb_urb_completion(urb);
652
653error:
Googler9398cc32022-12-02 17:21:52 +0800654 atomic_add(bytes_sent, &dlfb->bytes_sent);
655 atomic_add(bytes_identical, &dlfb->bytes_identical);
656 atomic_add(width*height*2, &dlfb->bytes_rendered);
Googleraf606d22022-10-26 21:40:12 -0700657 end_cycles = get_cycles();
658 atomic_add(((unsigned int) ((end_cycles - start_cycles)
659 >> 10)), /* Kcycles */
Googler9398cc32022-12-02 17:21:52 +0800660 &dlfb->cpu_kcycles_used);
Googleraf606d22022-10-26 21:40:12 -0700661
Googler9398cc32022-12-02 17:21:52 +0800662 ret = 0;
663
664unlock_ret:
665 mutex_unlock(&dlfb->render_mutex);
666 return ret;
667}
668
669static void dlfb_init_damage(struct dlfb_data *dlfb)
670{
671 dlfb->damage_x = INT_MAX;
672 dlfb->damage_x2 = 0;
673 dlfb->damage_y = INT_MAX;
674 dlfb->damage_y2 = 0;
675}
676
677static void dlfb_damage_work(struct work_struct *w)
678{
679 struct dlfb_data *dlfb = container_of(w, struct dlfb_data, damage_work);
680 int x, x2, y, y2;
681
682 spin_lock_irq(&dlfb->damage_lock);
683 x = dlfb->damage_x;
684 x2 = dlfb->damage_x2;
685 y = dlfb->damage_y;
686 y2 = dlfb->damage_y2;
687 dlfb_init_damage(dlfb);
688 spin_unlock_irq(&dlfb->damage_lock);
689
690 if (x < x2 && y < y2)
691 dlfb_handle_damage(dlfb, x, y, x2 - x, y2 - y);
692}
693
694static void dlfb_offload_damage(struct dlfb_data *dlfb, int x, int y, int width, int height)
695{
696 unsigned long flags;
697 int x2 = x + width;
698 int y2 = y + height;
699
700 if (x >= x2 || y >= y2)
701 return;
702
703 spin_lock_irqsave(&dlfb->damage_lock, flags);
704 dlfb->damage_x = min(x, dlfb->damage_x);
705 dlfb->damage_x2 = max(x2, dlfb->damage_x2);
706 dlfb->damage_y = min(y, dlfb->damage_y);
707 dlfb->damage_y2 = max(y2, dlfb->damage_y2);
708 spin_unlock_irqrestore(&dlfb->damage_lock, flags);
709
710 schedule_work(&dlfb->damage_work);
Googleraf606d22022-10-26 21:40:12 -0700711}
712
713/*
714 * Path triggered by usermode clients who write to filesystem
715 * e.g. cat filename > /dev/fb1
716 * Not used by X Windows or text-mode console. But useful for testing.
717 * Slow because of extra copy and we must assume all pixels dirty.
718 */
719static ssize_t dlfb_ops_write(struct fb_info *info, const char __user *buf,
720 size_t count, loff_t *ppos)
721{
722 ssize_t result;
Googler9398cc32022-12-02 17:21:52 +0800723 struct dlfb_data *dlfb = info->par;
Googleraf606d22022-10-26 21:40:12 -0700724 u32 offset = (u32) *ppos;
725
726 result = fb_sys_write(info, buf, count, ppos);
727
728 if (result > 0) {
729 int start = max((int)(offset / info->fix.line_length), 0);
730 int lines = min((u32)((result / info->fix.line_length) + 1),
731 (u32)info->var.yres);
732
Googler9398cc32022-12-02 17:21:52 +0800733 dlfb_handle_damage(dlfb, 0, start, info->var.xres,
734 lines);
Googleraf606d22022-10-26 21:40:12 -0700735 }
736
737 return result;
738}
739
740/* hardware has native COPY command (see libdlo), but not worth it for fbcon */
741static void dlfb_ops_copyarea(struct fb_info *info,
742 const struct fb_copyarea *area)
743{
744
Googler9398cc32022-12-02 17:21:52 +0800745 struct dlfb_data *dlfb = info->par;
Googleraf606d22022-10-26 21:40:12 -0700746
747 sys_copyarea(info, area);
748
Googler9398cc32022-12-02 17:21:52 +0800749 dlfb_offload_damage(dlfb, area->dx, area->dy,
750 area->width, area->height);
Googleraf606d22022-10-26 21:40:12 -0700751}
752
753static void dlfb_ops_imageblit(struct fb_info *info,
754 const struct fb_image *image)
755{
Googler9398cc32022-12-02 17:21:52 +0800756 struct dlfb_data *dlfb = info->par;
Googleraf606d22022-10-26 21:40:12 -0700757
758 sys_imageblit(info, image);
759
Googler9398cc32022-12-02 17:21:52 +0800760 dlfb_offload_damage(dlfb, image->dx, image->dy,
761 image->width, image->height);
Googleraf606d22022-10-26 21:40:12 -0700762}
763
764static void dlfb_ops_fillrect(struct fb_info *info,
765 const struct fb_fillrect *rect)
766{
Googler9398cc32022-12-02 17:21:52 +0800767 struct dlfb_data *dlfb = info->par;
Googleraf606d22022-10-26 21:40:12 -0700768
769 sys_fillrect(info, rect);
770
Googler9398cc32022-12-02 17:21:52 +0800771 dlfb_offload_damage(dlfb, rect->dx, rect->dy, rect->width,
772 rect->height);
Googleraf606d22022-10-26 21:40:12 -0700773}
774
775/*
776 * NOTE: fb_defio.c is holding info->fbdefio.mutex
777 * Touching ANY framebuffer memory that triggers a page fault
778 * in fb_defio will cause a deadlock, when it also tries to
779 * grab the same mutex.
780 */
781static void dlfb_dpy_deferred_io(struct fb_info *info,
782 struct list_head *pagelist)
783{
784 struct page *cur;
785 struct fb_deferred_io *fbdefio = info->fbdefio;
Googler9398cc32022-12-02 17:21:52 +0800786 struct dlfb_data *dlfb = info->par;
Googleraf606d22022-10-26 21:40:12 -0700787 struct urb *urb;
788 char *cmd;
789 cycles_t start_cycles, end_cycles;
790 int bytes_sent = 0;
791 int bytes_identical = 0;
792 int bytes_rendered = 0;
793
Googler9398cc32022-12-02 17:21:52 +0800794 mutex_lock(&dlfb->render_mutex);
Googler0109c452022-10-13 17:50:39 +0800795
Googler9398cc32022-12-02 17:21:52 +0800796 if (!fb_defio)
797 goto unlock_ret;
798
799 if (!atomic_read(&dlfb->usb_active))
800 goto unlock_ret;
Googleraf606d22022-10-26 21:40:12 -0700801
802 start_cycles = get_cycles();
803
Googler9398cc32022-12-02 17:21:52 +0800804 urb = dlfb_get_urb(dlfb);
Googleraf606d22022-10-26 21:40:12 -0700805 if (!urb)
Googler9398cc32022-12-02 17:21:52 +0800806 goto unlock_ret;
Googleraf606d22022-10-26 21:40:12 -0700807
808 cmd = urb->transfer_buffer;
809
810 /* walk the written page list and render each to device */
811 list_for_each_entry(cur, &fbdefio->pagelist, lru) {
812
Googler9398cc32022-12-02 17:21:52 +0800813 if (dlfb_render_hline(dlfb, &urb, (char *) info->fix.smem_start,
Googleraf606d22022-10-26 21:40:12 -0700814 &cmd, cur->index << PAGE_SHIFT,
815 PAGE_SIZE, &bytes_identical, &bytes_sent))
816 goto error;
817 bytes_rendered += PAGE_SIZE;
818 }
819
820 if (cmd > (char *) urb->transfer_buffer) {
Googler9398cc32022-12-02 17:21:52 +0800821 int len;
822 if (cmd < (char *) urb->transfer_buffer + urb->transfer_buffer_length)
823 *cmd++ = 0xAF;
Googleraf606d22022-10-26 21:40:12 -0700824 /* Send partial buffer remaining before exiting */
Googler9398cc32022-12-02 17:21:52 +0800825 len = cmd - (char *) urb->transfer_buffer;
826 dlfb_submit_urb(dlfb, urb, len);
Googleraf606d22022-10-26 21:40:12 -0700827 bytes_sent += len;
828 } else
829 dlfb_urb_completion(urb);
830
831error:
Googler9398cc32022-12-02 17:21:52 +0800832 atomic_add(bytes_sent, &dlfb->bytes_sent);
833 atomic_add(bytes_identical, &dlfb->bytes_identical);
834 atomic_add(bytes_rendered, &dlfb->bytes_rendered);
Googleraf606d22022-10-26 21:40:12 -0700835 end_cycles = get_cycles();
836 atomic_add(((unsigned int) ((end_cycles - start_cycles)
837 >> 10)), /* Kcycles */
Googler9398cc32022-12-02 17:21:52 +0800838 &dlfb->cpu_kcycles_used);
839unlock_ret:
840 mutex_unlock(&dlfb->render_mutex);
Googleraf606d22022-10-26 21:40:12 -0700841}
842
Googler9398cc32022-12-02 17:21:52 +0800843static int dlfb_get_edid(struct dlfb_data *dlfb, char *edid, int len)
Googleraf606d22022-10-26 21:40:12 -0700844{
Googler9398cc32022-12-02 17:21:52 +0800845 int i, ret;
Googleraf606d22022-10-26 21:40:12 -0700846 char *rbuf;
847
848 rbuf = kmalloc(2, GFP_KERNEL);
849 if (!rbuf)
850 return 0;
851
852 for (i = 0; i < len; i++) {
Googler9398cc32022-12-02 17:21:52 +0800853 ret = usb_control_msg(dlfb->udev,
854 usb_rcvctrlpipe(dlfb->udev, 0), 0x02,
Googleraf606d22022-10-26 21:40:12 -0700855 (0x80 | (0x02 << 5)), i << 8, 0xA1,
856 rbuf, 2, USB_CTRL_GET_TIMEOUT);
857 if (ret < 2) {
Googler9398cc32022-12-02 17:21:52 +0800858 dev_err(&dlfb->udev->dev,
859 "Read EDID byte %d failed: %d\n", i, ret);
Googleraf606d22022-10-26 21:40:12 -0700860 i--;
861 break;
862 }
863 edid[i] = rbuf[1];
864 }
865
866 kfree(rbuf);
867
868 return i;
869}
870
871static int dlfb_ops_ioctl(struct fb_info *info, unsigned int cmd,
872 unsigned long arg)
873{
874
Googler9398cc32022-12-02 17:21:52 +0800875 struct dlfb_data *dlfb = info->par;
Googleraf606d22022-10-26 21:40:12 -0700876
Googler9398cc32022-12-02 17:21:52 +0800877 if (!atomic_read(&dlfb->usb_active))
Googleraf606d22022-10-26 21:40:12 -0700878 return 0;
879
880 /* TODO: Update X server to get this from sysfs instead */
881 if (cmd == DLFB_IOCTL_RETURN_EDID) {
882 void __user *edid = (void __user *)arg;
Googler9398cc32022-12-02 17:21:52 +0800883 if (copy_to_user(edid, dlfb->edid, dlfb->edid_size))
Googleraf606d22022-10-26 21:40:12 -0700884 return -EFAULT;
885 return 0;
886 }
887
888 /* TODO: Help propose a standard fb.h ioctl to report mmap damage */
889 if (cmd == DLFB_IOCTL_REPORT_DAMAGE) {
890 struct dloarea area;
891
892 if (copy_from_user(&area, (void __user *)arg,
893 sizeof(struct dloarea)))
894 return -EFAULT;
895
896 /*
897 * If we have a damage-aware client, turn fb_defio "off"
898 * To avoid perf imact of unnecessary page fault handling.
899 * Done by resetting the delay for this fb_info to a very
900 * long period. Pages will become writable and stay that way.
901 * Reset to normal value when all clients have closed this fb.
902 */
903 if (info->fbdefio)
904 info->fbdefio->delay = DL_DEFIO_WRITE_DISABLE;
905
906 if (area.x < 0)
907 area.x = 0;
908
909 if (area.x > info->var.xres)
910 area.x = info->var.xres;
911
912 if (area.y < 0)
913 area.y = 0;
914
915 if (area.y > info->var.yres)
916 area.y = info->var.yres;
917
Googler9398cc32022-12-02 17:21:52 +0800918 dlfb_handle_damage(dlfb, area.x, area.y, area.w, area.h);
Googleraf606d22022-10-26 21:40:12 -0700919 }
920
921 return 0;
922}
923
924/* taken from vesafb */
925static int
926dlfb_ops_setcolreg(unsigned regno, unsigned red, unsigned green,
927 unsigned blue, unsigned transp, struct fb_info *info)
928{
929 int err = 0;
930
931 if (regno >= info->cmap.len)
932 return 1;
933
934 if (regno < 16) {
935 if (info->var.red.offset == 10) {
936 /* 1:5:5:5 */
937 ((u32 *) (info->pseudo_palette))[regno] =
938 ((red & 0xf800) >> 1) |
939 ((green & 0xf800) >> 6) | ((blue & 0xf800) >> 11);
940 } else {
941 /* 0:5:6:5 */
942 ((u32 *) (info->pseudo_palette))[regno] =
943 ((red & 0xf800)) |
944 ((green & 0xfc00) >> 5) | ((blue & 0xf800) >> 11);
945 }
946 }
947
948 return err;
949}
950
951/*
952 * It's common for several clients to have framebuffer open simultaneously.
953 * e.g. both fbcon and X. Makes things interesting.
954 * Assumes caller is holding info->lock (for open and release at least)
955 */
956static int dlfb_ops_open(struct fb_info *info, int user)
957{
Googler9398cc32022-12-02 17:21:52 +0800958 struct dlfb_data *dlfb = info->par;
Googleraf606d22022-10-26 21:40:12 -0700959
960 /*
961 * fbcon aggressively connects to first framebuffer it finds,
962 * preventing other clients (X) from working properly. Usually
963 * not what the user wants. Fail by default with option to enable.
964 */
965 if ((user == 0) && (!console))
966 return -EBUSY;
967
968 /* If the USB device is gone, we don't accept new opens */
Googler9398cc32022-12-02 17:21:52 +0800969 if (dlfb->virtualized)
Googleraf606d22022-10-26 21:40:12 -0700970 return -ENODEV;
971
Googler9398cc32022-12-02 17:21:52 +0800972 dlfb->fb_count++;
Googleraf606d22022-10-26 21:40:12 -0700973
974 if (fb_defio && (info->fbdefio == NULL)) {
975 /* enable defio at last moment if not disabled by client */
976
977 struct fb_deferred_io *fbdefio;
978
979 fbdefio = kzalloc(sizeof(struct fb_deferred_io), GFP_KERNEL);
980
981 if (fbdefio) {
982 fbdefio->delay = DL_DEFIO_WRITE_DELAY;
983 fbdefio->deferred_io = dlfb_dpy_deferred_io;
984 }
985
986 info->fbdefio = fbdefio;
987 fb_deferred_io_init(info);
988 }
989
Googler9398cc32022-12-02 17:21:52 +0800990 dev_dbg(info->dev, "open, user=%d fb_info=%p count=%d\n",
991 user, info, dlfb->fb_count);
Googleraf606d22022-10-26 21:40:12 -0700992
993 return 0;
994}
995
Googler9398cc32022-12-02 17:21:52 +0800996static void dlfb_ops_destroy(struct fb_info *info)
Googleraf606d22022-10-26 21:40:12 -0700997{
Googler9398cc32022-12-02 17:21:52 +0800998 struct dlfb_data *dlfb = info->par;
Googleraf606d22022-10-26 21:40:12 -0700999
Googler9398cc32022-12-02 17:21:52 +08001000 cancel_work_sync(&dlfb->damage_work);
Googleraf606d22022-10-26 21:40:12 -07001001
Googler9398cc32022-12-02 17:21:52 +08001002 mutex_destroy(&dlfb->render_mutex);
Googleraf606d22022-10-26 21:40:12 -07001003
Googler9398cc32022-12-02 17:21:52 +08001004 if (info->cmap.len != 0)
1005 fb_dealloc_cmap(&info->cmap);
1006 if (info->monspecs.modedb)
1007 fb_destroy_modedb(info->monspecs.modedb);
1008 vfree(info->screen_base);
Googleraf606d22022-10-26 21:40:12 -07001009
Googler9398cc32022-12-02 17:21:52 +08001010 fb_destroy_modelist(&info->modelist);
Googler012a81c2022-09-15 14:55:24 +08001011
Googler9398cc32022-12-02 17:21:52 +08001012 while (!list_empty(&dlfb->deferred_free)) {
1013 struct dlfb_deferred_free *d = list_entry(dlfb->deferred_free.next, struct dlfb_deferred_free, list);
1014 list_del(&d->list);
1015 vfree(d->mem);
1016 kfree(d);
Googler9726be62022-12-14 05:53:31 +00001017 }
Googler9398cc32022-12-02 17:21:52 +08001018 vfree(dlfb->backing_buffer);
1019 kfree(dlfb->edid);
Googler9398cc32022-12-02 17:21:52 +08001020 usb_put_dev(dlfb->udev);
1021 kfree(dlfb);
Googler9726be62022-12-14 05:53:31 +00001022
Googler9398cc32022-12-02 17:21:52 +08001023 /* Assume info structure is freed after this point */
1024 framebuffer_release(info);
Googler9726be62022-12-14 05:53:31 +00001025}
1026
Googleraf606d22022-10-26 21:40:12 -07001027/*
1028 * Assumes caller is holding info->lock mutex (for open and release at least)
1029 */
1030static int dlfb_ops_release(struct fb_info *info, int user)
1031{
Googler9398cc32022-12-02 17:21:52 +08001032 struct dlfb_data *dlfb = info->par;
Googleraf606d22022-10-26 21:40:12 -07001033
Googler9398cc32022-12-02 17:21:52 +08001034 dlfb->fb_count--;
Googleraf606d22022-10-26 21:40:12 -07001035
Googler9398cc32022-12-02 17:21:52 +08001036 if ((dlfb->fb_count == 0) && (info->fbdefio)) {
Googleraf606d22022-10-26 21:40:12 -07001037 fb_deferred_io_cleanup(info);
1038 kfree(info->fbdefio);
1039 info->fbdefio = NULL;
1040 info->fbops->fb_mmap = dlfb_ops_mmap;
1041 }
1042
Googler9398cc32022-12-02 17:21:52 +08001043 dev_dbg(info->dev, "release, user=%d count=%d\n", user, dlfb->fb_count);
Googleraf606d22022-10-26 21:40:12 -07001044
1045 return 0;
1046}
1047
1048/*
1049 * Check whether a video mode is supported by the DisplayLink chip
1050 * We start from monitor's modes, so don't need to filter that here
1051 */
Googler9398cc32022-12-02 17:21:52 +08001052static int dlfb_is_valid_mode(struct fb_videomode *mode, struct dlfb_data *dlfb)
Googleraf606d22022-10-26 21:40:12 -07001053{
Googler9398cc32022-12-02 17:21:52 +08001054 if (mode->xres * mode->yres > dlfb->sku_pixel_limit)
Googleraf606d22022-10-26 21:40:12 -07001055 return 0;
1056
1057 return 1;
1058}
1059
1060static void dlfb_var_color_format(struct fb_var_screeninfo *var)
1061{
1062 const struct fb_bitfield red = { 11, 5, 0 };
1063 const struct fb_bitfield green = { 5, 6, 0 };
1064 const struct fb_bitfield blue = { 0, 5, 0 };
1065
1066 var->bits_per_pixel = 16;
1067 var->red = red;
1068 var->green = green;
1069 var->blue = blue;
1070}
1071
1072static int dlfb_ops_check_var(struct fb_var_screeninfo *var,
1073 struct fb_info *info)
1074{
1075 struct fb_videomode mode;
Googler9398cc32022-12-02 17:21:52 +08001076 struct dlfb_data *dlfb = info->par;
Googleraf606d22022-10-26 21:40:12 -07001077
1078 /* set device-specific elements of var unrelated to mode */
1079 dlfb_var_color_format(var);
1080
1081 fb_var_to_videomode(&mode, var);
1082
Googler9398cc32022-12-02 17:21:52 +08001083 if (!dlfb_is_valid_mode(&mode, dlfb))
Googleraf606d22022-10-26 21:40:12 -07001084 return -EINVAL;
1085
1086 return 0;
1087}
1088
1089static int dlfb_ops_set_par(struct fb_info *info)
1090{
Googler9398cc32022-12-02 17:21:52 +08001091 struct dlfb_data *dlfb = info->par;
Googleraf606d22022-10-26 21:40:12 -07001092 int result;
1093 u16 *pix_framebuffer;
1094 int i;
Googler9398cc32022-12-02 17:21:52 +08001095 struct fb_var_screeninfo fvs;
1096 u32 line_length = info->var.xres * (info->var.bits_per_pixel / 8);
Googleraf606d22022-10-26 21:40:12 -07001097
Googler9398cc32022-12-02 17:21:52 +08001098 /* clear the activate field because it causes spurious miscompares */
1099 fvs = info->var;
1100 fvs.activate = 0;
1101 fvs.vmode &= ~FB_VMODE_SMOOTH_XPAN;
Googleraf606d22022-10-26 21:40:12 -07001102
Googler9398cc32022-12-02 17:21:52 +08001103 if (!memcmp(&dlfb->current_mode, &fvs, sizeof(struct fb_var_screeninfo)))
1104 return 0;
Googleraf606d22022-10-26 21:40:12 -07001105
Googler9398cc32022-12-02 17:21:52 +08001106 result = dlfb_realloc_framebuffer(dlfb, info, info->var.yres * line_length);
1107 if (result)
1108 return result;
1109
1110 result = dlfb_set_video_mode(dlfb, &info->var);
1111
1112 if (result)
1113 return result;
1114
1115 dlfb->current_mode = fvs;
1116 info->fix.line_length = line_length;
1117
1118 if (dlfb->fb_count == 0) {
Googleraf606d22022-10-26 21:40:12 -07001119
1120 /* paint greenscreen */
1121
1122 pix_framebuffer = (u16 *) info->screen_base;
1123 for (i = 0; i < info->fix.smem_len / 2; i++)
1124 pix_framebuffer[i] = 0x37e6;
1125 }
1126
Googler9398cc32022-12-02 17:21:52 +08001127 dlfb_handle_damage(dlfb, 0, 0, info->var.xres, info->var.yres);
1128
1129 return 0;
Googleraf606d22022-10-26 21:40:12 -07001130}
1131
1132/* To fonzi the jukebox (e.g. make blanking changes take effect) */
1133static char *dlfb_dummy_render(char *buf)
1134{
1135 *buf++ = 0xAF;
1136 *buf++ = 0x6A; /* copy */
1137 *buf++ = 0x00; /* from address*/
1138 *buf++ = 0x00;
1139 *buf++ = 0x00;
1140 *buf++ = 0x01; /* one pixel */
1141 *buf++ = 0x00; /* to address */
1142 *buf++ = 0x00;
1143 *buf++ = 0x00;
1144 return buf;
1145}
1146
1147/*
1148 * In order to come back from full DPMS off, we need to set the mode again
1149 */
1150static int dlfb_ops_blank(int blank_mode, struct fb_info *info)
1151{
Googler9398cc32022-12-02 17:21:52 +08001152 struct dlfb_data *dlfb = info->par;
Googleraf606d22022-10-26 21:40:12 -07001153 char *bufptr;
1154 struct urb *urb;
1155
Googler9398cc32022-12-02 17:21:52 +08001156 dev_dbg(info->dev, "blank, mode %d --> %d\n",
1157 dlfb->blank_mode, blank_mode);
Googleraf606d22022-10-26 21:40:12 -07001158
Googler9398cc32022-12-02 17:21:52 +08001159 if ((dlfb->blank_mode == FB_BLANK_POWERDOWN) &&
Googleraf606d22022-10-26 21:40:12 -07001160 (blank_mode != FB_BLANK_POWERDOWN)) {
1161
1162 /* returning from powerdown requires a fresh modeset */
Googler9398cc32022-12-02 17:21:52 +08001163 dlfb_set_video_mode(dlfb, &info->var);
Googleraf606d22022-10-26 21:40:12 -07001164 }
1165
Googler9398cc32022-12-02 17:21:52 +08001166 urb = dlfb_get_urb(dlfb);
Googleraf606d22022-10-26 21:40:12 -07001167 if (!urb)
1168 return 0;
1169
1170 bufptr = (char *) urb->transfer_buffer;
1171 bufptr = dlfb_vidreg_lock(bufptr);
1172 bufptr = dlfb_blanking(bufptr, blank_mode);
1173 bufptr = dlfb_vidreg_unlock(bufptr);
1174
1175 /* seems like a render op is needed to have blank change take effect */
1176 bufptr = dlfb_dummy_render(bufptr);
1177
Googler9398cc32022-12-02 17:21:52 +08001178 dlfb_submit_urb(dlfb, urb, bufptr -
Googleraf606d22022-10-26 21:40:12 -07001179 (char *) urb->transfer_buffer);
1180
Googler9398cc32022-12-02 17:21:52 +08001181 dlfb->blank_mode = blank_mode;
Googleraf606d22022-10-26 21:40:12 -07001182
1183 return 0;
1184}
1185
Googler9398cc32022-12-02 17:21:52 +08001186static const struct fb_ops dlfb_ops = {
Googleraf606d22022-10-26 21:40:12 -07001187 .owner = THIS_MODULE,
1188 .fb_read = fb_sys_read,
1189 .fb_write = dlfb_ops_write,
1190 .fb_setcolreg = dlfb_ops_setcolreg,
1191 .fb_fillrect = dlfb_ops_fillrect,
1192 .fb_copyarea = dlfb_ops_copyarea,
1193 .fb_imageblit = dlfb_ops_imageblit,
1194 .fb_mmap = dlfb_ops_mmap,
1195 .fb_ioctl = dlfb_ops_ioctl,
1196 .fb_open = dlfb_ops_open,
1197 .fb_release = dlfb_ops_release,
1198 .fb_blank = dlfb_ops_blank,
1199 .fb_check_var = dlfb_ops_check_var,
1200 .fb_set_par = dlfb_ops_set_par,
Googler9398cc32022-12-02 17:21:52 +08001201 .fb_destroy = dlfb_ops_destroy,
Googleraf606d22022-10-26 21:40:12 -07001202};
1203
1204
Googler9398cc32022-12-02 17:21:52 +08001205static void dlfb_deferred_vfree(struct dlfb_data *dlfb, void *mem)
1206{
1207 struct dlfb_deferred_free *d = kmalloc(sizeof(struct dlfb_deferred_free), GFP_KERNEL);
1208 if (!d)
1209 return;
1210 d->mem = mem;
1211 list_add(&d->list, &dlfb->deferred_free);
1212}
1213
Googleraf606d22022-10-26 21:40:12 -07001214/*
1215 * Assumes &info->lock held by caller
1216 * Assumes no active clients have framebuffer open
1217 */
Googler9398cc32022-12-02 17:21:52 +08001218static int dlfb_realloc_framebuffer(struct dlfb_data *dlfb, struct fb_info *info, u32 new_len)
Googleraf606d22022-10-26 21:40:12 -07001219{
Googler9398cc32022-12-02 17:21:52 +08001220 u32 old_len = info->fix.smem_len;
1221 const void *old_fb = (const void __force *)info->screen_base;
Googleraf606d22022-10-26 21:40:12 -07001222 unsigned char *new_fb;
1223 unsigned char *new_back = NULL;
1224
Googler9398cc32022-12-02 17:21:52 +08001225 new_len = PAGE_ALIGN(new_len);
Googleraf606d22022-10-26 21:40:12 -07001226
Googler9398cc32022-12-02 17:21:52 +08001227 if (new_len > old_len) {
Googleraf606d22022-10-26 21:40:12 -07001228 /*
1229 * Alloc system memory for virtual framebuffer
1230 */
1231 new_fb = vmalloc(new_len);
1232 if (!new_fb) {
Googler9398cc32022-12-02 17:21:52 +08001233 dev_err(info->dev, "Virtual framebuffer alloc failed\n");
1234 return -ENOMEM;
Googleraf606d22022-10-26 21:40:12 -07001235 }
Googler9398cc32022-12-02 17:21:52 +08001236 memset(new_fb, 0xff, new_len);
Googleraf606d22022-10-26 21:40:12 -07001237
1238 if (info->screen_base) {
1239 memcpy(new_fb, old_fb, old_len);
Googler9398cc32022-12-02 17:21:52 +08001240 dlfb_deferred_vfree(dlfb, (void __force *)info->screen_base);
Googleraf606d22022-10-26 21:40:12 -07001241 }
1242
Googler9398cc32022-12-02 17:21:52 +08001243 info->screen_base = (char __iomem *)new_fb;
1244 info->fix.smem_len = new_len;
Googleraf606d22022-10-26 21:40:12 -07001245 info->fix.smem_start = (unsigned long) new_fb;
1246 info->flags = udlfb_info_flags;
1247
1248 /*
1249 * Second framebuffer copy to mirror the framebuffer state
1250 * on the physical USB device. We can function without this.
1251 * But with imperfect damage info we may send pixels over USB
1252 * that were, in fact, unchanged - wasting limited USB bandwidth
1253 */
1254 if (shadow)
1255 new_back = vzalloc(new_len);
1256 if (!new_back)
Googler9398cc32022-12-02 17:21:52 +08001257 dev_info(info->dev,
1258 "No shadow/backing buffer allocated\n");
Googleraf606d22022-10-26 21:40:12 -07001259 else {
Googler9398cc32022-12-02 17:21:52 +08001260 dlfb_deferred_vfree(dlfb, dlfb->backing_buffer);
1261 dlfb->backing_buffer = new_back;
Googleraf606d22022-10-26 21:40:12 -07001262 }
1263 }
Googler9398cc32022-12-02 17:21:52 +08001264 return 0;
Googleraf606d22022-10-26 21:40:12 -07001265}
1266
1267/*
1268 * 1) Get EDID from hw, or use sw default
1269 * 2) Parse into various fb_info structs
1270 * 3) Allocate virtual framebuffer memory to back highest res mode
1271 *
1272 * Parses EDID into three places used by various parts of fbdev:
1273 * fb_var_screeninfo contains the timing of the monitor's preferred mode
1274 * fb_info.monspecs is full parsed EDID info, including monspecs.modedb
1275 * fb_info.modelist is a linked list of all monitor & VESA modes which work
1276 *
1277 * If EDID is not readable/valid, then modelist is all VESA modes,
1278 * monspecs is NULL, and fb_var_screeninfo is set to safe VESA mode
1279 * Returns 0 if successful
1280 */
Googler9398cc32022-12-02 17:21:52 +08001281static int dlfb_setup_modes(struct dlfb_data *dlfb,
Googleraf606d22022-10-26 21:40:12 -07001282 struct fb_info *info,
1283 char *default_edid, size_t default_edid_size)
1284{
Googler9726be62022-12-14 05:53:31 +00001285 char *edid;
Googler9398cc32022-12-02 17:21:52 +08001286 int i, result = 0, tries = 3;
1287 struct device *dev = info->device;
1288 struct fb_videomode *mode;
1289 const struct fb_videomode *default_vmode = NULL;
Googleraf606d22022-10-26 21:40:12 -07001290
Googler9398cc32022-12-02 17:21:52 +08001291 if (info->dev) {
1292 /* only use mutex if info has been registered */
Googleraf606d22022-10-26 21:40:12 -07001293 mutex_lock(&info->lock);
Googler9398cc32022-12-02 17:21:52 +08001294 /* parent device is used otherwise */
1295 dev = info->dev;
1296 }
Googleraf606d22022-10-26 21:40:12 -07001297
1298 edid = kmalloc(EDID_LENGTH, GFP_KERNEL);
1299 if (!edid) {
1300 result = -ENOMEM;
1301 goto error;
1302 }
1303
1304 fb_destroy_modelist(&info->modelist);
1305 memset(&info->monspecs, 0, sizeof(info->monspecs));
1306
1307 /*
1308 * Try to (re)read EDID from hardware first
1309 * EDID data may return, but not parse as valid
1310 * Try again a few times, in case of e.g. analog cable noise
1311 */
1312 while (tries--) {
1313
Googler9398cc32022-12-02 17:21:52 +08001314 i = dlfb_get_edid(dlfb, edid, EDID_LENGTH);
Googleraf606d22022-10-26 21:40:12 -07001315
1316 if (i >= EDID_LENGTH)
1317 fb_edid_to_monspecs(edid, &info->monspecs);
1318
1319 if (info->monspecs.modedb_len > 0) {
Googler9398cc32022-12-02 17:21:52 +08001320 dlfb->edid = edid;
1321 dlfb->edid_size = i;
Googleraf606d22022-10-26 21:40:12 -07001322 break;
1323 }
1324 }
1325
1326 /* If that fails, use a previously returned EDID if available */
1327 if (info->monspecs.modedb_len == 0) {
Googler9398cc32022-12-02 17:21:52 +08001328 dev_err(dev, "Unable to get valid EDID from device/display\n");
Googleraf606d22022-10-26 21:40:12 -07001329
Googler9398cc32022-12-02 17:21:52 +08001330 if (dlfb->edid) {
1331 fb_edid_to_monspecs(dlfb->edid, &info->monspecs);
Googleraf606d22022-10-26 21:40:12 -07001332 if (info->monspecs.modedb_len > 0)
Googler9398cc32022-12-02 17:21:52 +08001333 dev_err(dev, "Using previously queried EDID\n");
Googleraf606d22022-10-26 21:40:12 -07001334 }
1335 }
1336
1337 /* If that fails, use the default EDID we were handed */
1338 if (info->monspecs.modedb_len == 0) {
1339 if (default_edid_size >= EDID_LENGTH) {
1340 fb_edid_to_monspecs(default_edid, &info->monspecs);
1341 if (info->monspecs.modedb_len > 0) {
1342 memcpy(edid, default_edid, default_edid_size);
Googler9398cc32022-12-02 17:21:52 +08001343 dlfb->edid = edid;
1344 dlfb->edid_size = default_edid_size;
1345 dev_err(dev, "Using default/backup EDID\n");
Googleraf606d22022-10-26 21:40:12 -07001346 }
1347 }
1348 }
1349
1350 /* If we've got modes, let's pick a best default mode */
1351 if (info->monspecs.modedb_len > 0) {
1352
1353 for (i = 0; i < info->monspecs.modedb_len; i++) {
Googler9398cc32022-12-02 17:21:52 +08001354 mode = &info->monspecs.modedb[i];
1355 if (dlfb_is_valid_mode(mode, dlfb)) {
1356 fb_add_videomode(mode, &info->modelist);
1357 } else {
1358 dev_dbg(dev, "Specified mode %dx%d too big\n",
1359 mode->xres, mode->yres);
Googleraf606d22022-10-26 21:40:12 -07001360 if (i == 0)
1361 /* if we've removed top/best mode */
1362 info->monspecs.misc
1363 &= ~FB_MISC_1ST_DETAIL;
1364 }
1365 }
1366
1367 default_vmode = fb_find_best_display(&info->monspecs,
1368 &info->modelist);
1369 }
1370
1371 /* If everything else has failed, fall back to safe default mode */
1372 if (default_vmode == NULL) {
1373
1374 struct fb_videomode fb_vmode = {0};
1375
1376 /*
1377 * Add the standard VESA modes to our modelist
1378 * Since we don't have EDID, there may be modes that
1379 * overspec monitor and/or are incorrect aspect ratio, etc.
1380 * But at least the user has a chance to choose
1381 */
1382 for (i = 0; i < VESA_MODEDB_SIZE; i++) {
Googler9398cc32022-12-02 17:21:52 +08001383 mode = (struct fb_videomode *)&vesa_modes[i];
1384 if (dlfb_is_valid_mode(mode, dlfb))
1385 fb_add_videomode(mode, &info->modelist);
1386 else
1387 dev_dbg(dev, "VESA mode %dx%d too big\n",
1388 mode->xres, mode->yres);
Googleraf606d22022-10-26 21:40:12 -07001389 }
1390
1391 /*
1392 * default to resolution safe for projectors
1393 * (since they are most common case without EDID)
1394 */
1395 fb_vmode.xres = 800;
1396 fb_vmode.yres = 600;
1397 fb_vmode.refresh = 60;
1398 default_vmode = fb_find_nearest_mode(&fb_vmode,
1399 &info->modelist);
1400 }
1401
1402 /* If we have good mode and no active clients*/
Googler9398cc32022-12-02 17:21:52 +08001403 if ((default_vmode != NULL) && (dlfb->fb_count == 0)) {
Googleraf606d22022-10-26 21:40:12 -07001404
1405 fb_videomode_to_var(&info->var, default_vmode);
1406 dlfb_var_color_format(&info->var);
1407
1408 /*
1409 * with mode size info, we can now alloc our framebuffer.
1410 */
1411 memcpy(&info->fix, &dlfb_fix, sizeof(dlfb_fix));
1412 } else
1413 result = -EINVAL;
1414
1415error:
Googler9398cc32022-12-02 17:21:52 +08001416 if (edid && (dlfb->edid != edid))
Googleraf606d22022-10-26 21:40:12 -07001417 kfree(edid);
1418
1419 if (info->dev)
1420 mutex_unlock(&info->lock);
1421
1422 return result;
1423}
1424
1425static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
1426 struct device_attribute *a, char *buf) {
1427 struct fb_info *fb_info = dev_get_drvdata(fbdev);
Googler9398cc32022-12-02 17:21:52 +08001428 struct dlfb_data *dlfb = fb_info->par;
Googlerb48fa912023-03-17 12:40:29 +05301429 return snprintf(buf, PAGE_SIZE, "%u\n",
Googler9398cc32022-12-02 17:21:52 +08001430 atomic_read(&dlfb->bytes_rendered));
Googleraf606d22022-10-26 21:40:12 -07001431}
1432
1433static ssize_t metrics_bytes_identical_show(struct device *fbdev,
1434 struct device_attribute *a, char *buf) {
1435 struct fb_info *fb_info = dev_get_drvdata(fbdev);
Googler9398cc32022-12-02 17:21:52 +08001436 struct dlfb_data *dlfb = fb_info->par;
Googlerb48fa912023-03-17 12:40:29 +05301437 return snprintf(buf, PAGE_SIZE, "%u\n",
Googler9398cc32022-12-02 17:21:52 +08001438 atomic_read(&dlfb->bytes_identical));
Googleraf606d22022-10-26 21:40:12 -07001439}
1440
1441static ssize_t metrics_bytes_sent_show(struct device *fbdev,
1442 struct device_attribute *a, char *buf) {
1443 struct fb_info *fb_info = dev_get_drvdata(fbdev);
Googler9398cc32022-12-02 17:21:52 +08001444 struct dlfb_data *dlfb = fb_info->par;
Googlerb48fa912023-03-17 12:40:29 +05301445 return snprintf(buf, PAGE_SIZE, "%u\n",
Googler9398cc32022-12-02 17:21:52 +08001446 atomic_read(&dlfb->bytes_sent));
Googleraf606d22022-10-26 21:40:12 -07001447}
1448
1449static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
1450 struct device_attribute *a, char *buf) {
1451 struct fb_info *fb_info = dev_get_drvdata(fbdev);
Googler9398cc32022-12-02 17:21:52 +08001452 struct dlfb_data *dlfb = fb_info->par;
Googlerb48fa912023-03-17 12:40:29 +05301453 return snprintf(buf, PAGE_SIZE, "%u\n",
Googler9398cc32022-12-02 17:21:52 +08001454 atomic_read(&dlfb->cpu_kcycles_used));
Googleraf606d22022-10-26 21:40:12 -07001455}
1456
1457static ssize_t edid_show(
1458 struct file *filp,
1459 struct kobject *kobj, struct bin_attribute *a,
1460 char *buf, loff_t off, size_t count) {
1461 struct device *fbdev = container_of(kobj, struct device, kobj);
1462 struct fb_info *fb_info = dev_get_drvdata(fbdev);
Googler9398cc32022-12-02 17:21:52 +08001463 struct dlfb_data *dlfb = fb_info->par;
Googleraf606d22022-10-26 21:40:12 -07001464
Googler9398cc32022-12-02 17:21:52 +08001465 if (dlfb->edid == NULL)
Googleraf606d22022-10-26 21:40:12 -07001466 return 0;
1467
Googler9398cc32022-12-02 17:21:52 +08001468 if ((off >= dlfb->edid_size) || (count > dlfb->edid_size))
Googleraf606d22022-10-26 21:40:12 -07001469 return 0;
1470
Googler9398cc32022-12-02 17:21:52 +08001471 if (off + count > dlfb->edid_size)
1472 count = dlfb->edid_size - off;
Googleraf606d22022-10-26 21:40:12 -07001473
Googler9398cc32022-12-02 17:21:52 +08001474 memcpy(buf, dlfb->edid, count);
Googleraf606d22022-10-26 21:40:12 -07001475
1476 return count;
1477}
1478
1479static ssize_t edid_store(
1480 struct file *filp,
1481 struct kobject *kobj, struct bin_attribute *a,
1482 char *src, loff_t src_off, size_t src_size) {
1483 struct device *fbdev = container_of(kobj, struct device, kobj);
1484 struct fb_info *fb_info = dev_get_drvdata(fbdev);
Googler9398cc32022-12-02 17:21:52 +08001485 struct dlfb_data *dlfb = fb_info->par;
Googleraf606d22022-10-26 21:40:12 -07001486 int ret;
1487
1488 /* We only support write of entire EDID at once, no offset*/
1489 if ((src_size != EDID_LENGTH) || (src_off != 0))
1490 return -EINVAL;
1491
Googler9398cc32022-12-02 17:21:52 +08001492 ret = dlfb_setup_modes(dlfb, fb_info, src, src_size);
Googleraf606d22022-10-26 21:40:12 -07001493 if (ret)
1494 return ret;
1495
Googler9398cc32022-12-02 17:21:52 +08001496 if (!dlfb->edid || memcmp(src, dlfb->edid, src_size))
Googleraf606d22022-10-26 21:40:12 -07001497 return -EINVAL;
1498
Googler9398cc32022-12-02 17:21:52 +08001499 ret = dlfb_ops_set_par(fb_info);
1500 if (ret)
1501 return ret;
1502
Googleraf606d22022-10-26 21:40:12 -07001503 return src_size;
1504}
1505
1506static ssize_t metrics_reset_store(struct device *fbdev,
1507 struct device_attribute *attr,
1508 const char *buf, size_t count)
1509{
1510 struct fb_info *fb_info = dev_get_drvdata(fbdev);
Googler9398cc32022-12-02 17:21:52 +08001511 struct dlfb_data *dlfb = fb_info->par;
Googleraf606d22022-10-26 21:40:12 -07001512
Googler9398cc32022-12-02 17:21:52 +08001513 atomic_set(&dlfb->bytes_rendered, 0);
1514 atomic_set(&dlfb->bytes_identical, 0);
1515 atomic_set(&dlfb->bytes_sent, 0);
1516 atomic_set(&dlfb->cpu_kcycles_used, 0);
Googleraf606d22022-10-26 21:40:12 -07001517
1518 return count;
1519}
1520
Googler9398cc32022-12-02 17:21:52 +08001521static const struct bin_attribute edid_attr = {
Googleraf606d22022-10-26 21:40:12 -07001522 .attr.name = "edid",
1523 .attr.mode = 0666,
1524 .size = EDID_LENGTH,
1525 .read = edid_show,
1526 .write = edid_store
1527};
1528
Googler9398cc32022-12-02 17:21:52 +08001529static const struct device_attribute fb_device_attrs[] = {
Googleraf606d22022-10-26 21:40:12 -07001530 __ATTR_RO(metrics_bytes_rendered),
1531 __ATTR_RO(metrics_bytes_identical),
1532 __ATTR_RO(metrics_bytes_sent),
1533 __ATTR_RO(metrics_cpu_kcycles_used),
1534 __ATTR(metrics_reset, S_IWUSR, NULL, metrics_reset_store),
1535};
1536
1537/*
1538 * This is necessary before we can communicate with the display controller.
1539 */
Googler9398cc32022-12-02 17:21:52 +08001540static int dlfb_select_std_channel(struct dlfb_data *dlfb)
Googleraf606d22022-10-26 21:40:12 -07001541{
1542 int ret;
1543 void *buf;
1544 static const u8 set_def_chn[] = {
1545 0x57, 0xCD, 0xDC, 0xA7,
1546 0x1C, 0x88, 0x5E, 0x15,
1547 0x60, 0xFE, 0xC6, 0x97,
1548 0x16, 0x3D, 0x47, 0xF2 };
1549
1550 buf = kmemdup(set_def_chn, sizeof(set_def_chn), GFP_KERNEL);
1551
1552 if (!buf)
1553 return -ENOMEM;
1554
Googler9398cc32022-12-02 17:21:52 +08001555 ret = usb_control_msg(dlfb->udev, usb_sndctrlpipe(dlfb->udev, 0),
Googleraf606d22022-10-26 21:40:12 -07001556 NR_USB_REQUEST_CHANNEL,
1557 (USB_DIR_OUT | USB_TYPE_VENDOR), 0, 0,
1558 buf, sizeof(set_def_chn), USB_CTRL_SET_TIMEOUT);
1559
1560 kfree(buf);
1561
1562 return ret;
1563}
1564
Googler9398cc32022-12-02 17:21:52 +08001565static int dlfb_parse_vendor_descriptor(struct dlfb_data *dlfb,
1566 struct usb_interface *intf)
Googleraf606d22022-10-26 21:40:12 -07001567{
1568 char *desc;
1569 char *buf;
1570 char *desc_end;
1571 int total_len;
1572
1573 buf = kzalloc(MAX_VENDOR_DESCRIPTOR_SIZE, GFP_KERNEL);
1574 if (!buf)
1575 return false;
1576 desc = buf;
1577
Googler9398cc32022-12-02 17:21:52 +08001578 total_len = usb_get_descriptor(interface_to_usbdev(intf),
Googleraf606d22022-10-26 21:40:12 -07001579 0x5f, /* vendor specific */
1580 0, desc, MAX_VENDOR_DESCRIPTOR_SIZE);
1581
1582 /* if not found, look in configuration descriptor */
1583 if (total_len < 0) {
Googler9398cc32022-12-02 17:21:52 +08001584 if (0 == usb_get_extra_descriptor(intf->cur_altsetting,
Googleraf606d22022-10-26 21:40:12 -07001585 0x5f, &desc))
1586 total_len = (int) desc[0];
1587 }
1588
1589 if (total_len > 5) {
Googler9398cc32022-12-02 17:21:52 +08001590 dev_info(&intf->dev,
1591 "vendor descriptor length: %d data: %11ph\n",
1592 total_len, desc);
Googleraf606d22022-10-26 21:40:12 -07001593
1594 if ((desc[0] != total_len) || /* descriptor length */
1595 (desc[1] != 0x5f) || /* vendor descriptor type */
1596 (desc[2] != 0x01) || /* version (2 bytes) */
1597 (desc[3] != 0x00) ||
1598 (desc[4] != total_len - 2)) /* length after type */
1599 goto unrecognized;
1600
1601 desc_end = desc + total_len;
1602 desc += 5; /* the fixed header we've already parsed */
1603
1604 while (desc < desc_end) {
1605 u8 length;
1606 u16 key;
1607
Googler9398cc32022-12-02 17:21:52 +08001608 key = *desc++;
1609 key |= (u16)*desc++ << 8;
1610 length = *desc++;
Googleraf606d22022-10-26 21:40:12 -07001611
1612 switch (key) {
1613 case 0x0200: { /* max_area */
Googler9398cc32022-12-02 17:21:52 +08001614 u32 max_area = *desc++;
1615 max_area |= (u32)*desc++ << 8;
1616 max_area |= (u32)*desc++ << 16;
1617 max_area |= (u32)*desc++ << 24;
1618 dev_warn(&intf->dev,
1619 "DL chip limited to %d pixel modes\n",
1620 max_area);
1621 dlfb->sku_pixel_limit = max_area;
Googleraf606d22022-10-26 21:40:12 -07001622 break;
1623 }
1624 default:
1625 break;
1626 }
1627 desc += length;
1628 }
1629 } else {
Googler9398cc32022-12-02 17:21:52 +08001630 dev_info(&intf->dev, "vendor descriptor not available (%d)\n",
1631 total_len);
Googleraf606d22022-10-26 21:40:12 -07001632 }
1633
1634 goto success;
1635
1636unrecognized:
1637 /* allow udlfb to load for now even if firmware unrecognized */
Googler9398cc32022-12-02 17:21:52 +08001638 dev_err(&intf->dev, "Unrecognized vendor firmware descriptor\n");
Googleraf606d22022-10-26 21:40:12 -07001639
1640success:
1641 kfree(buf);
1642 return true;
1643}
1644
Googler9398cc32022-12-02 17:21:52 +08001645static int dlfb_usb_probe(struct usb_interface *intf,
1646 const struct usb_device_id *id)
Googleraf606d22022-10-26 21:40:12 -07001647{
Googler9398cc32022-12-02 17:21:52 +08001648 int i;
1649 const struct device_attribute *attr;
1650 struct dlfb_data *dlfb;
1651 struct fb_info *info;
Googlerb48fa912023-03-17 12:40:29 +05301652 int retval = -ENOMEM;
Googler9398cc32022-12-02 17:21:52 +08001653 struct usb_device *usbdev = interface_to_usbdev(intf);
Googleraf606d22022-10-26 21:40:12 -07001654
1655 /* usb initialization */
Googler9398cc32022-12-02 17:21:52 +08001656 dlfb = kzalloc(sizeof(*dlfb), GFP_KERNEL);
1657 if (!dlfb) {
1658 dev_err(&intf->dev, "%s: failed to allocate dlfb\n", __func__);
1659 return -ENOMEM;
1660 }
Googler9726be62022-12-14 05:53:31 +00001661
Googler9398cc32022-12-02 17:21:52 +08001662 INIT_LIST_HEAD(&dlfb->deferred_free);
Googler9726be62022-12-14 05:53:31 +00001663
Googler9398cc32022-12-02 17:21:52 +08001664 dlfb->udev = usb_get_dev(usbdev);
1665 usb_set_intfdata(intf, dlfb);
1666
Googler9398cc32022-12-02 17:21:52 +08001667 dev_dbg(&intf->dev, "console enable=%d\n", console);
1668 dev_dbg(&intf->dev, "fb_defio enable=%d\n", fb_defio);
1669 dev_dbg(&intf->dev, "shadow enable=%d\n", shadow);
Googleraf606d22022-10-26 21:40:12 -07001670
Googler9398cc32022-12-02 17:21:52 +08001671 dlfb->sku_pixel_limit = 2048 * 1152; /* default to maximum */
Googleraf606d22022-10-26 21:40:12 -07001672
Googler9398cc32022-12-02 17:21:52 +08001673 if (!dlfb_parse_vendor_descriptor(dlfb, intf)) {
1674 dev_err(&intf->dev,
1675 "firmware not recognized, incompatible device?\n");
Googleraf606d22022-10-26 21:40:12 -07001676 goto error;
1677 }
1678
1679 if (pixel_limit) {
Googler9398cc32022-12-02 17:21:52 +08001680 dev_warn(&intf->dev,
1681 "DL chip limit of %d overridden to %d\n",
1682 dlfb->sku_pixel_limit, pixel_limit);
1683 dlfb->sku_pixel_limit = pixel_limit;
Googleraf606d22022-10-26 21:40:12 -07001684 }
1685
1686
1687 /* allocates framebuffer driver structure, not framebuffer memory */
Googler9398cc32022-12-02 17:21:52 +08001688 info = framebuffer_alloc(0, &dlfb->udev->dev);
Googlerb48fa912023-03-17 12:40:29 +05301689 if (!info)
Googler38bda472022-08-19 10:07:08 -07001690 goto error;
Googler38bda472022-08-19 10:07:08 -07001691
Googler9398cc32022-12-02 17:21:52 +08001692 dlfb->info = info;
1693 info->par = dlfb;
1694 info->pseudo_palette = dlfb->pseudo_palette;
1695 dlfb->ops = dlfb_ops;
1696 info->fbops = &dlfb->ops;
Googler0109c452022-10-13 17:50:39 +08001697
Googler9398cc32022-12-02 17:21:52 +08001698 mutex_init(&dlfb->render_mutex);
1699 dlfb_init_damage(dlfb);
1700 spin_lock_init(&dlfb->damage_lock);
1701 INIT_WORK(&dlfb->damage_work, dlfb_damage_work);
Googler9726be62022-12-14 05:53:31 +00001702
1703 INIT_LIST_HEAD(&info->modelist);
1704
Googler9398cc32022-12-02 17:21:52 +08001705 if (!dlfb_alloc_urb_list(dlfb, WRITES_IN_FLIGHT, MAX_TRANSFER)) {
1706 retval = -ENOMEM;
1707 dev_err(&intf->dev, "unable to allocate urb list\n");
1708 goto error;
1709 }
1710
1711 /* We don't register a new USB class. Our client interface is dlfbev */
1712
1713 retval = fb_alloc_cmap(&info->cmap, 256, 0);
1714 if (retval < 0) {
1715 dev_err(info->device, "cmap allocation failed: %d\n", retval);
1716 goto error;
1717 }
1718
1719 retval = dlfb_setup_modes(dlfb, info, NULL, 0);
Googleraf606d22022-10-26 21:40:12 -07001720 if (retval != 0) {
Googler9398cc32022-12-02 17:21:52 +08001721 dev_err(info->device,
1722 "unable to find common mode for display and adapter\n");
Googleraf606d22022-10-26 21:40:12 -07001723 goto error;
1724 }
1725
1726 /* ready to begin using device */
1727
Googler9398cc32022-12-02 17:21:52 +08001728 atomic_set(&dlfb->usb_active, 1);
1729 dlfb_select_std_channel(dlfb);
Googleraf606d22022-10-26 21:40:12 -07001730
1731 dlfb_ops_check_var(&info->var, info);
Googler9398cc32022-12-02 17:21:52 +08001732 retval = dlfb_ops_set_par(info);
1733 if (retval)
1734 goto error;
Googleraf606d22022-10-26 21:40:12 -07001735
1736 retval = register_framebuffer(info);
1737 if (retval < 0) {
Googler9398cc32022-12-02 17:21:52 +08001738 dev_err(info->device, "unable to register framebuffer: %d\n",
1739 retval);
Googleraf606d22022-10-26 21:40:12 -07001740 goto error;
1741 }
1742
1743 for (i = 0; i < ARRAY_SIZE(fb_device_attrs); i++) {
Googler9398cc32022-12-02 17:21:52 +08001744 attr = &fb_device_attrs[i];
1745 retval = device_create_file(info->dev, attr);
1746 if (retval)
1747 dev_warn(info->device,
1748 "failed to create '%s' attribute: %d\n",
1749 attr->attr.name, retval);
Googleraf606d22022-10-26 21:40:12 -07001750 }
1751
1752 retval = device_create_bin_file(info->dev, &edid_attr);
Googler9398cc32022-12-02 17:21:52 +08001753 if (retval)
1754 dev_warn(info->device, "failed to create '%s' attribute: %d\n",
1755 edid_attr.attr.name, retval);
Googleraf606d22022-10-26 21:40:12 -07001756
Googler9398cc32022-12-02 17:21:52 +08001757 dev_info(info->device,
1758 "%s is DisplayLink USB device (%dx%d, %dK framebuffer memory)\n",
1759 dev_name(info->dev), info->var.xres, info->var.yres,
1760 ((dlfb->backing_buffer) ?
1761 info->fix.smem_len * 2 : info->fix.smem_len) >> 10);
1762 return 0;
Googleraf606d22022-10-26 21:40:12 -07001763
1764error:
Googler9398cc32022-12-02 17:21:52 +08001765 if (dlfb->info) {
1766 dlfb_ops_destroy(dlfb->info);
1767 } else {
1768 usb_put_dev(dlfb->udev);
1769 kfree(dlfb);
1770 }
1771 return retval;
Googleraf606d22022-10-26 21:40:12 -07001772}
1773
Googler9398cc32022-12-02 17:21:52 +08001774static void dlfb_usb_disconnect(struct usb_interface *intf)
Googleraf606d22022-10-26 21:40:12 -07001775{
Googler9398cc32022-12-02 17:21:52 +08001776 struct dlfb_data *dlfb;
Googleraf606d22022-10-26 21:40:12 -07001777 struct fb_info *info;
1778 int i;
1779
Googler9398cc32022-12-02 17:21:52 +08001780 dlfb = usb_get_intfdata(intf);
1781 info = dlfb->info;
Googleraf606d22022-10-26 21:40:12 -07001782
Googler9398cc32022-12-02 17:21:52 +08001783 dev_dbg(&intf->dev, "USB disconnect starting\n");
Googleraf606d22022-10-26 21:40:12 -07001784
1785 /* we virtualize until all fb clients release. Then we free */
Googler9398cc32022-12-02 17:21:52 +08001786 dlfb->virtualized = true;
Googleraf606d22022-10-26 21:40:12 -07001787
1788 /* When non-active we'll update virtual framebuffer, but no new urbs */
Googler9398cc32022-12-02 17:21:52 +08001789 atomic_set(&dlfb->usb_active, 0);
Googleraf606d22022-10-26 21:40:12 -07001790
1791 /* this function will wait for all in-flight urbs to complete */
Googler9398cc32022-12-02 17:21:52 +08001792 dlfb_free_urb_list(dlfb);
Googleraf606d22022-10-26 21:40:12 -07001793
Googler9398cc32022-12-02 17:21:52 +08001794 /* remove udlfb's sysfs interfaces */
1795 for (i = 0; i < ARRAY_SIZE(fb_device_attrs); i++)
1796 device_remove_file(info->dev, &fb_device_attrs[i]);
1797 device_remove_bin_file(info->dev, &edid_attr);
Googleraf606d22022-10-26 21:40:12 -07001798
Googler9398cc32022-12-02 17:21:52 +08001799 unregister_framebuffer(info);
Googleraf606d22022-10-26 21:40:12 -07001800}
1801
1802static struct usb_driver dlfb_driver = {
1803 .name = "udlfb",
1804 .probe = dlfb_usb_probe,
1805 .disconnect = dlfb_usb_disconnect,
1806 .id_table = id_table,
1807};
1808
1809module_usb_driver(dlfb_driver);
1810
1811static void dlfb_urb_completion(struct urb *urb)
1812{
1813 struct urb_node *unode = urb->context;
Googler9398cc32022-12-02 17:21:52 +08001814 struct dlfb_data *dlfb = unode->dlfb;
Googleraf606d22022-10-26 21:40:12 -07001815 unsigned long flags;
1816
Googler9398cc32022-12-02 17:21:52 +08001817 switch (urb->status) {
1818 case 0:
1819 /* success */
1820 break;
1821 case -ECONNRESET:
1822 case -ENOENT:
1823 case -ESHUTDOWN:
1824 /* sync/async unlink faults aren't errors */
1825 break;
1826 default:
1827 dev_err(&dlfb->udev->dev,
1828 "%s - nonzero write bulk status received: %d\n",
1829 __func__, urb->status);
1830 atomic_set(&dlfb->lost_pixels, 1);
1831 break;
Googleraf606d22022-10-26 21:40:12 -07001832 }
1833
Googler9398cc32022-12-02 17:21:52 +08001834 urb->transfer_buffer_length = dlfb->urbs.size; /* reset to actual */
Googleraf606d22022-10-26 21:40:12 -07001835
Googler9398cc32022-12-02 17:21:52 +08001836 spin_lock_irqsave(&dlfb->urbs.lock, flags);
1837 list_add_tail(&unode->entry, &dlfb->urbs.list);
1838 dlfb->urbs.available++;
1839 spin_unlock_irqrestore(&dlfb->urbs.lock, flags);
Googleraf606d22022-10-26 21:40:12 -07001840
Googler9398cc32022-12-02 17:21:52 +08001841 up(&dlfb->urbs.limit_sem);
Googleraf606d22022-10-26 21:40:12 -07001842}
1843
Googler9398cc32022-12-02 17:21:52 +08001844static void dlfb_free_urb_list(struct dlfb_data *dlfb)
Googleraf606d22022-10-26 21:40:12 -07001845{
Googler9398cc32022-12-02 17:21:52 +08001846 int count = dlfb->urbs.count;
Googleraf606d22022-10-26 21:40:12 -07001847 struct list_head *node;
1848 struct urb_node *unode;
1849 struct urb *urb;
1850
1851 /* keep waiting and freeing, until we've got 'em all */
1852 while (count--) {
Googler9398cc32022-12-02 17:21:52 +08001853 down(&dlfb->urbs.limit_sem);
Googleraf606d22022-10-26 21:40:12 -07001854
Googler9398cc32022-12-02 17:21:52 +08001855 spin_lock_irq(&dlfb->urbs.lock);
Googleraf606d22022-10-26 21:40:12 -07001856
Googler9398cc32022-12-02 17:21:52 +08001857 node = dlfb->urbs.list.next; /* have reserved one with sem */
Googleraf606d22022-10-26 21:40:12 -07001858 list_del_init(node);
1859
Googler9398cc32022-12-02 17:21:52 +08001860 spin_unlock_irq(&dlfb->urbs.lock);
Googleraf606d22022-10-26 21:40:12 -07001861
1862 unode = list_entry(node, struct urb_node, entry);
1863 urb = unode->urb;
1864
1865 /* Free each separately allocated piece */
Googler9398cc32022-12-02 17:21:52 +08001866 usb_free_coherent(urb->dev, dlfb->urbs.size,
Googleraf606d22022-10-26 21:40:12 -07001867 urb->transfer_buffer, urb->transfer_dma);
1868 usb_free_urb(urb);
1869 kfree(node);
1870 }
1871
Googler9398cc32022-12-02 17:21:52 +08001872 dlfb->urbs.count = 0;
Googleraf606d22022-10-26 21:40:12 -07001873}
1874
Googler9398cc32022-12-02 17:21:52 +08001875static int dlfb_alloc_urb_list(struct dlfb_data *dlfb, int count, size_t size)
Googleraf606d22022-10-26 21:40:12 -07001876{
1877 struct urb *urb;
1878 struct urb_node *unode;
1879 char *buf;
Googler9398cc32022-12-02 17:21:52 +08001880 size_t wanted_size = count * size;
Googleraf606d22022-10-26 21:40:12 -07001881
Googler9398cc32022-12-02 17:21:52 +08001882 spin_lock_init(&dlfb->urbs.lock);
Googleraf606d22022-10-26 21:40:12 -07001883
Googler9398cc32022-12-02 17:21:52 +08001884retry:
1885 dlfb->urbs.size = size;
1886 INIT_LIST_HEAD(&dlfb->urbs.list);
Googleraf606d22022-10-26 21:40:12 -07001887
Googler9398cc32022-12-02 17:21:52 +08001888 sema_init(&dlfb->urbs.limit_sem, 0);
1889 dlfb->urbs.count = 0;
1890 dlfb->urbs.available = 0;
1891
1892 while (dlfb->urbs.count * size < wanted_size) {
1893 unode = kzalloc(sizeof(*unode), GFP_KERNEL);
Googleraf606d22022-10-26 21:40:12 -07001894 if (!unode)
1895 break;
Googler9398cc32022-12-02 17:21:52 +08001896 unode->dlfb = dlfb;
Googleraf606d22022-10-26 21:40:12 -07001897
1898 urb = usb_alloc_urb(0, GFP_KERNEL);
1899 if (!urb) {
1900 kfree(unode);
1901 break;
1902 }
1903 unode->urb = urb;
1904
Googler9398cc32022-12-02 17:21:52 +08001905 buf = usb_alloc_coherent(dlfb->udev, size, GFP_KERNEL,
Googleraf606d22022-10-26 21:40:12 -07001906 &urb->transfer_dma);
1907 if (!buf) {
1908 kfree(unode);
1909 usb_free_urb(urb);
Googler9398cc32022-12-02 17:21:52 +08001910 if (size > PAGE_SIZE) {
1911 size /= 2;
1912 dlfb_free_urb_list(dlfb);
1913 goto retry;
1914 }
Googleraf606d22022-10-26 21:40:12 -07001915 break;
1916 }
1917
1918 /* urb->transfer_buffer_length set to actual before submit */
Googler9398cc32022-12-02 17:21:52 +08001919 usb_fill_bulk_urb(urb, dlfb->udev, usb_sndbulkpipe(dlfb->udev, 1),
Googleraf606d22022-10-26 21:40:12 -07001920 buf, size, dlfb_urb_completion, unode);
1921 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1922
Googler9398cc32022-12-02 17:21:52 +08001923 list_add_tail(&unode->entry, &dlfb->urbs.list);
Googleraf606d22022-10-26 21:40:12 -07001924
Googler9398cc32022-12-02 17:21:52 +08001925 up(&dlfb->urbs.limit_sem);
1926 dlfb->urbs.count++;
1927 dlfb->urbs.available++;
Googleraf606d22022-10-26 21:40:12 -07001928 }
1929
Googler9398cc32022-12-02 17:21:52 +08001930 return dlfb->urbs.count;
Googleraf606d22022-10-26 21:40:12 -07001931}
1932
Googler9398cc32022-12-02 17:21:52 +08001933static struct urb *dlfb_get_urb(struct dlfb_data *dlfb)
Googleraf606d22022-10-26 21:40:12 -07001934{
1935 int ret;
1936 struct list_head *entry;
1937 struct urb_node *unode;
1938
1939 /* Wait for an in-flight buffer to complete and get re-queued */
Googler9398cc32022-12-02 17:21:52 +08001940 ret = down_timeout(&dlfb->urbs.limit_sem, GET_URB_TIMEOUT);
Googleraf606d22022-10-26 21:40:12 -07001941 if (ret) {
Googler9398cc32022-12-02 17:21:52 +08001942 atomic_set(&dlfb->lost_pixels, 1);
1943 dev_warn(&dlfb->udev->dev,
1944 "wait for urb interrupted: %d available: %d\n",
1945 ret, dlfb->urbs.available);
1946 return NULL;
Googleraf606d22022-10-26 21:40:12 -07001947 }
1948
Googler9398cc32022-12-02 17:21:52 +08001949 spin_lock_irq(&dlfb->urbs.lock);
Googleraf606d22022-10-26 21:40:12 -07001950
Googler9398cc32022-12-02 17:21:52 +08001951 BUG_ON(list_empty(&dlfb->urbs.list)); /* reserved one with limit_sem */
1952 entry = dlfb->urbs.list.next;
Googleraf606d22022-10-26 21:40:12 -07001953 list_del_init(entry);
Googler9398cc32022-12-02 17:21:52 +08001954 dlfb->urbs.available--;
Googleraf606d22022-10-26 21:40:12 -07001955
Googler9398cc32022-12-02 17:21:52 +08001956 spin_unlock_irq(&dlfb->urbs.lock);
Googleraf606d22022-10-26 21:40:12 -07001957
1958 unode = list_entry(entry, struct urb_node, entry);
Googler9398cc32022-12-02 17:21:52 +08001959 return unode->urb;
Googleraf606d22022-10-26 21:40:12 -07001960}
1961
Googler9398cc32022-12-02 17:21:52 +08001962static int dlfb_submit_urb(struct dlfb_data *dlfb, struct urb *urb, size_t len)
Googleraf606d22022-10-26 21:40:12 -07001963{
1964 int ret;
1965
Googler9398cc32022-12-02 17:21:52 +08001966 BUG_ON(len > dlfb->urbs.size);
Googleraf606d22022-10-26 21:40:12 -07001967
1968 urb->transfer_buffer_length = len; /* set to actual payload len */
1969 ret = usb_submit_urb(urb, GFP_KERNEL);
1970 if (ret) {
1971 dlfb_urb_completion(urb); /* because no one else will */
Googler9398cc32022-12-02 17:21:52 +08001972 atomic_set(&dlfb->lost_pixels, 1);
1973 dev_err(&dlfb->udev->dev, "submit urb error: %d\n", ret);
Googleraf606d22022-10-26 21:40:12 -07001974 }
1975 return ret;
1976}
1977
1978module_param(console, bool, S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP);
1979MODULE_PARM_DESC(console, "Allow fbcon to open framebuffer");
1980
1981module_param(fb_defio, bool, S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP);
1982MODULE_PARM_DESC(fb_defio, "Page fault detection of mmap writes");
1983
1984module_param(shadow, bool, S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP);
1985MODULE_PARM_DESC(shadow, "Shadow vid mem. Disable to save mem but lose perf");
1986
1987module_param(pixel_limit, int, S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP);
1988MODULE_PARM_DESC(pixel_limit, "Force limit on max mode (in x*y pixels)");
1989
1990MODULE_AUTHOR("Roberto De Ioris <roberto@unbit.it>, "
1991 "Jaya Kumar <jayakumar.lkml@gmail.com>, "
1992 "Bernie Thompson <bernie@plugable.com>");
1993MODULE_DESCRIPTION("DisplayLink kernel framebuffer driver");
1994MODULE_LICENSE("GPL");
1995