udlfb.c 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898
  1. /*
  2. * udlfb.c -- Framebuffer driver for DisplayLink USB controller
  3. *
  4. * Copyright (C) 2009 Roberto De Ioris <roberto@unbit.it>
  5. * Copyright (C) 2009 Jaya Kumar <jayakumar.lkml@gmail.com>
  6. * Copyright (C) 2009 Bernie Thompson <bernie@plugable.com>
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License v2. See the file COPYING in the main directory of this archive for
  10. * more details.
  11. *
  12. * Layout is based on skeletonfb by James Simmons and Geert Uytterhoeven,
  13. * usb-skeleton by GregKH.
  14. *
  15. * Device-specific portions based on information from Displaylink, with work
  16. * from Florian Echtler, Henrik Bjerregaard Pedersen, and others.
  17. */
  18. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  19. #include <linux/module.h>
  20. #include <linux/kernel.h>
  21. #include <linux/init.h>
  22. #include <linux/usb.h>
  23. #include <linux/uaccess.h>
  24. #include <linux/mm.h>
  25. #include <linux/fb.h>
  26. #include <linux/vmalloc.h>
  27. #include <linux/slab.h>
  28. #include <linux/prefetch.h>
  29. #include <linux/delay.h>
  30. #include <linux/prefetch.h>
  31. #include <video/udlfb.h>
  32. #include "edid.h"
  33. static struct fb_fix_screeninfo dlfb_fix = {
  34. .id = "udlfb",
  35. .type = FB_TYPE_PACKED_PIXELS,
  36. .visual = FB_VISUAL_TRUECOLOR,
  37. .xpanstep = 0,
  38. .ypanstep = 0,
  39. .ywrapstep = 0,
  40. .accel = FB_ACCEL_NONE,
  41. };
  42. static const u32 udlfb_info_flags = FBINFO_DEFAULT | FBINFO_READS_FAST |
  43. FBINFO_VIRTFB |
  44. FBINFO_HWACCEL_IMAGEBLIT | FBINFO_HWACCEL_FILLRECT |
  45. FBINFO_HWACCEL_COPYAREA | FBINFO_MISC_ALWAYS_SETPAR;
  46. /*
  47. * There are many DisplayLink-based products, all with unique PIDs. We are able
  48. * to support all volume ones (circa 2009) with a single driver, so we match
  49. * globally on VID. TODO: Probe() needs to detect when we might be running
  50. * "future" chips, and bail on those, so a compatible driver can match.
  51. */
  52. static struct usb_device_id id_table[] = {
  53. {.idVendor = 0x17e9, .match_flags = USB_DEVICE_ID_MATCH_VENDOR,},
  54. {},
  55. };
  56. MODULE_DEVICE_TABLE(usb, id_table);
  57. /* module options */
  58. static int console; /* Optionally allow fbcon to consume first framebuffer */
  59. static int fb_defio; /* Optionally enable experimental fb_defio mmap support */
  60. /* dlfb keeps a list of urbs for efficient bulk transfers */
  61. static void dlfb_urb_completion(struct urb *urb);
  62. static struct urb *dlfb_get_urb(struct dlfb_data *dev);
  63. static int dlfb_submit_urb(struct dlfb_data *dev, struct urb * urb, size_t len);
  64. static int dlfb_alloc_urb_list(struct dlfb_data *dev, int count, size_t size);
  65. static void dlfb_free_urb_list(struct dlfb_data *dev);
  66. /*
  67. * All DisplayLink bulk operations start with 0xAF, followed by specific code
  68. * All operations are written to buffers which then later get sent to device
  69. */
  70. static char *dlfb_set_register(char *buf, u8 reg, u8 val)
  71. {
  72. *buf++ = 0xAF;
  73. *buf++ = 0x20;
  74. *buf++ = reg;
  75. *buf++ = val;
  76. return buf;
  77. }
  78. static char *dlfb_vidreg_lock(char *buf)
  79. {
  80. return dlfb_set_register(buf, 0xFF, 0x00);
  81. }
  82. static char *dlfb_vidreg_unlock(char *buf)
  83. {
  84. return dlfb_set_register(buf, 0xFF, 0xFF);
  85. }
  86. /*
  87. * On/Off for driving the DisplayLink framebuffer to the display
  88. * 0x00 H and V sync on
  89. * 0x01 H and V sync off (screen blank but powered)
  90. * 0x07 DPMS powerdown (requires modeset to come back)
  91. */
  92. static char *dlfb_enable_hvsync(char *buf, bool enable)
  93. {
  94. if (enable)
  95. return dlfb_set_register(buf, 0x1F, 0x00);
  96. else
  97. return dlfb_set_register(buf, 0x1F, 0x07);
  98. }
  99. static char *dlfb_set_color_depth(char *buf, u8 selection)
  100. {
  101. return dlfb_set_register(buf, 0x00, selection);
  102. }
  103. static char *dlfb_set_base16bpp(char *wrptr, u32 base)
  104. {
  105. /* the base pointer is 16 bits wide, 0x20 is hi byte. */
  106. wrptr = dlfb_set_register(wrptr, 0x20, base >> 16);
  107. wrptr = dlfb_set_register(wrptr, 0x21, base >> 8);
  108. return dlfb_set_register(wrptr, 0x22, base);
  109. }
  110. /*
  111. * DisplayLink HW has separate 16bpp and 8bpp framebuffers.
  112. * In 24bpp modes, the low 323 RGB bits go in the 8bpp framebuffer
  113. */
  114. static char *dlfb_set_base8bpp(char *wrptr, u32 base)
  115. {
  116. wrptr = dlfb_set_register(wrptr, 0x26, base >> 16);
  117. wrptr = dlfb_set_register(wrptr, 0x27, base >> 8);
  118. return dlfb_set_register(wrptr, 0x28, base);
  119. }
  120. static char *dlfb_set_register_16(char *wrptr, u8 reg, u16 value)
  121. {
  122. wrptr = dlfb_set_register(wrptr, reg, value >> 8);
  123. return dlfb_set_register(wrptr, reg+1, value);
  124. }
  125. /*
  126. * This is kind of weird because the controller takes some
  127. * register values in a different byte order than other registers.
  128. */
  129. static char *dlfb_set_register_16be(char *wrptr, u8 reg, u16 value)
  130. {
  131. wrptr = dlfb_set_register(wrptr, reg, value);
  132. return dlfb_set_register(wrptr, reg+1, value >> 8);
  133. }
  134. /*
  135. * LFSR is linear feedback shift register. The reason we have this is
  136. * because the display controller needs to minimize the clock depth of
  137. * various counters used in the display path. So this code reverses the
  138. * provided value into the lfsr16 value by counting backwards to get
  139. * the value that needs to be set in the hardware comparator to get the
  140. * same actual count. This makes sense once you read above a couple of
  141. * times and think about it from a hardware perspective.
  142. */
  143. static u16 dlfb_lfsr16(u16 actual_count)
  144. {
  145. u32 lv = 0xFFFF; /* This is the lfsr value that the hw starts with */
  146. while (actual_count--) {
  147. lv = ((lv << 1) |
  148. (((lv >> 15) ^ (lv >> 4) ^ (lv >> 2) ^ (lv >> 1)) & 1))
  149. & 0xFFFF;
  150. }
  151. return (u16) lv;
  152. }
  153. /*
  154. * This does LFSR conversion on the value that is to be written.
  155. * See LFSR explanation above for more detail.
  156. */
  157. static char *dlfb_set_register_lfsr16(char *wrptr, u8 reg, u16 value)
  158. {
  159. return dlfb_set_register_16(wrptr, reg, dlfb_lfsr16(value));
  160. }
  161. /*
  162. * This takes a standard fbdev screeninfo struct and all of its monitor mode
  163. * details and converts them into the DisplayLink equivalent register commands.
  164. */
  165. static char *dlfb_set_vid_cmds(char *wrptr, struct fb_var_screeninfo *var)
  166. {
  167. u16 xds, yds;
  168. u16 xde, yde;
  169. u16 yec;
  170. /* x display start */
  171. xds = var->left_margin + var->hsync_len;
  172. wrptr = dlfb_set_register_lfsr16(wrptr, 0x01, xds);
  173. /* x display end */
  174. xde = xds + var->xres;
  175. wrptr = dlfb_set_register_lfsr16(wrptr, 0x03, xde);
  176. /* y display start */
  177. yds = var->upper_margin + var->vsync_len;
  178. wrptr = dlfb_set_register_lfsr16(wrptr, 0x05, yds);
  179. /* y display end */
  180. yde = yds + var->yres;
  181. wrptr = dlfb_set_register_lfsr16(wrptr, 0x07, yde);
  182. /* x end count is active + blanking - 1 */
  183. wrptr = dlfb_set_register_lfsr16(wrptr, 0x09,
  184. xde + var->right_margin - 1);
  185. /* libdlo hardcodes hsync start to 1 */
  186. wrptr = dlfb_set_register_lfsr16(wrptr, 0x0B, 1);
  187. /* hsync end is width of sync pulse + 1 */
  188. wrptr = dlfb_set_register_lfsr16(wrptr, 0x0D, var->hsync_len + 1);
  189. /* hpixels is active pixels */
  190. wrptr = dlfb_set_register_16(wrptr, 0x0F, var->xres);
  191. /* yendcount is vertical active + vertical blanking */
  192. yec = var->yres + var->upper_margin + var->lower_margin +
  193. var->vsync_len;
  194. wrptr = dlfb_set_register_lfsr16(wrptr, 0x11, yec);
  195. /* libdlo hardcodes vsync start to 0 */
  196. wrptr = dlfb_set_register_lfsr16(wrptr, 0x13, 0);
  197. /* vsync end is width of vsync pulse */
  198. wrptr = dlfb_set_register_lfsr16(wrptr, 0x15, var->vsync_len);
  199. /* vpixels is active pixels */
  200. wrptr = dlfb_set_register_16(wrptr, 0x17, var->yres);
  201. /* convert picoseconds to 5kHz multiple for pclk5k = x * 1E12/5k */
  202. wrptr = dlfb_set_register_16be(wrptr, 0x1B,
  203. 200*1000*1000/var->pixclock);
  204. return wrptr;
  205. }
  206. /*
  207. * This takes a standard fbdev screeninfo struct that was fetched or prepared
  208. * and then generates the appropriate command sequence that then drives the
  209. * display controller.
  210. */
  211. static int dlfb_set_video_mode(struct dlfb_data *dev,
  212. struct fb_var_screeninfo *var)
  213. {
  214. char *buf;
  215. char *wrptr;
  216. int retval = 0;
  217. int writesize;
  218. struct urb *urb;
  219. if (!atomic_read(&dev->usb_active))
  220. return -EPERM;
  221. urb = dlfb_get_urb(dev);
  222. if (!urb)
  223. return -ENOMEM;
  224. buf = (char *) urb->transfer_buffer;
  225. /*
  226. * This first section has to do with setting the base address on the
  227. * controller * associated with the display. There are 2 base
  228. * pointers, currently, we only * use the 16 bpp segment.
  229. */
  230. wrptr = dlfb_vidreg_lock(buf);
  231. wrptr = dlfb_set_color_depth(wrptr, 0x00);
  232. /* set base for 16bpp segment to 0 */
  233. wrptr = dlfb_set_base16bpp(wrptr, 0);
  234. /* set base for 8bpp segment to end of fb */
  235. wrptr = dlfb_set_base8bpp(wrptr, dev->info->fix.smem_len);
  236. wrptr = dlfb_set_vid_cmds(wrptr, var);
  237. wrptr = dlfb_enable_hvsync(wrptr, true);
  238. wrptr = dlfb_vidreg_unlock(wrptr);
  239. writesize = wrptr - buf;
  240. retval = dlfb_submit_urb(dev, urb, writesize);
  241. return retval;
  242. }
  243. static int dlfb_ops_mmap(struct fb_info *info, struct vm_area_struct *vma)
  244. {
  245. unsigned long start = vma->vm_start;
  246. unsigned long size = vma->vm_end - vma->vm_start;
  247. unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
  248. unsigned long page, pos;
  249. if (offset + size > info->fix.smem_len)
  250. return -EINVAL;
  251. pos = (unsigned long)info->fix.smem_start + offset;
  252. pr_notice("mmap() framebuffer addr:%lu size:%lu\n",
  253. pos, size);
  254. while (size > 0) {
  255. page = vmalloc_to_pfn((void *)pos);
  256. if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED))
  257. return -EAGAIN;
  258. start += PAGE_SIZE;
  259. pos += PAGE_SIZE;
  260. if (size > PAGE_SIZE)
  261. size -= PAGE_SIZE;
  262. else
  263. size = 0;
  264. }
  265. vma->vm_flags |= VM_RESERVED; /* avoid to swap out this VMA */
  266. return 0;
  267. }
  268. /*
  269. * Trims identical data from front and back of line
  270. * Sets new front buffer address and width
  271. * And returns byte count of identical pixels
  272. * Assumes CPU natural alignment (unsigned long)
  273. * for back and front buffer ptrs and width
  274. */
  275. static int dlfb_trim_hline(const u8 *bback, const u8 **bfront, int *width_bytes)
  276. {
  277. int j, k;
  278. const unsigned long *back = (const unsigned long *) bback;
  279. const unsigned long *front = (const unsigned long *) *bfront;
  280. const int width = *width_bytes / sizeof(unsigned long);
  281. int identical = width;
  282. int start = width;
  283. int end = width;
  284. prefetch((void *) front);
  285. prefetch((void *) back);
  286. for (j = 0; j < width; j++) {
  287. if (back[j] != front[j]) {
  288. start = j;
  289. break;
  290. }
  291. }
  292. for (k = width - 1; k > j; k--) {
  293. if (back[k] != front[k]) {
  294. end = k+1;
  295. break;
  296. }
  297. }
  298. identical = start + (width - end);
  299. *bfront = (u8 *) &front[start];
  300. *width_bytes = (end - start) * sizeof(unsigned long);
  301. return identical * sizeof(unsigned long);
  302. }
  303. /*
  304. * Render a command stream for an encoded horizontal line segment of pixels.
  305. *
  306. * A command buffer holds several commands.
  307. * It always begins with a fresh command header
  308. * (the protocol doesn't require this, but we enforce it to allow
  309. * multiple buffers to be potentially encoded and sent in parallel).
  310. * A single command encodes one contiguous horizontal line of pixels
  311. *
  312. * The function relies on the client to do all allocation, so that
  313. * rendering can be done directly to output buffers (e.g. USB URBs).
  314. * The function fills the supplied command buffer, providing information
  315. * on where it left off, so the client may call in again with additional
  316. * buffers if the line will take several buffers to complete.
  317. *
  318. * A single command can transmit a maximum of 256 pixels,
  319. * regardless of the compression ratio (protocol design limit).
  320. * To the hardware, 0 for a size byte means 256
  321. *
  322. * Rather than 256 pixel commands which are either rl or raw encoded,
  323. * the rlx command simply assumes alternating raw and rl spans within one cmd.
  324. * This has a slightly larger header overhead, but produces more even results.
  325. * It also processes all data (read and write) in a single pass.
  326. * Performance benchmarks of common cases show it having just slightly better
  327. * compression than 256 pixel raw or rle commands, with similar CPU consumpion.
  328. * But for very rl friendly data, will compress not quite as well.
  329. */
  330. static void dlfb_compress_hline(
  331. const uint16_t **pixel_start_ptr,
  332. const uint16_t *const pixel_end,
  333. uint32_t *device_address_ptr,
  334. uint8_t **command_buffer_ptr,
  335. const uint8_t *const cmd_buffer_end)
  336. {
  337. const uint16_t *pixel = *pixel_start_ptr;
  338. uint32_t dev_addr = *device_address_ptr;
  339. uint8_t *cmd = *command_buffer_ptr;
  340. const int bpp = 2;
  341. while ((pixel_end > pixel) &&
  342. (cmd_buffer_end - MIN_RLX_CMD_BYTES > cmd)) {
  343. uint8_t *raw_pixels_count_byte = 0;
  344. uint8_t *cmd_pixels_count_byte = 0;
  345. const uint16_t *raw_pixel_start = 0;
  346. const uint16_t *cmd_pixel_start, *cmd_pixel_end = 0;
  347. prefetchw((void *) cmd); /* pull in one cache line at least */
  348. *cmd++ = 0xAF;
  349. *cmd++ = 0x6B;
  350. *cmd++ = (uint8_t) ((dev_addr >> 16) & 0xFF);
  351. *cmd++ = (uint8_t) ((dev_addr >> 8) & 0xFF);
  352. *cmd++ = (uint8_t) ((dev_addr) & 0xFF);
  353. cmd_pixels_count_byte = cmd++; /* we'll know this later */
  354. cmd_pixel_start = pixel;
  355. raw_pixels_count_byte = cmd++; /* we'll know this later */
  356. raw_pixel_start = pixel;
  357. cmd_pixel_end = pixel + min(MAX_CMD_PIXELS + 1,
  358. min((int)(pixel_end - pixel),
  359. (int)(cmd_buffer_end - cmd) / bpp));
  360. prefetch_range((void *) pixel, (cmd_pixel_end - pixel) * bpp);
  361. while (pixel < cmd_pixel_end) {
  362. const uint16_t * const repeating_pixel = pixel;
  363. *(uint16_t *)cmd = cpu_to_be16p(pixel);
  364. cmd += 2;
  365. pixel++;
  366. if (unlikely((pixel < cmd_pixel_end) &&
  367. (*pixel == *repeating_pixel))) {
  368. /* go back and fill in raw pixel count */
  369. *raw_pixels_count_byte = ((repeating_pixel -
  370. raw_pixel_start) + 1) & 0xFF;
  371. while ((pixel < cmd_pixel_end)
  372. && (*pixel == *repeating_pixel)) {
  373. pixel++;
  374. }
  375. /* immediately after raw data is repeat byte */
  376. *cmd++ = ((pixel - repeating_pixel) - 1) & 0xFF;
  377. /* Then start another raw pixel span */
  378. raw_pixel_start = pixel;
  379. raw_pixels_count_byte = cmd++;
  380. }
  381. }
  382. if (pixel > raw_pixel_start) {
  383. /* finalize last RAW span */
  384. *raw_pixels_count_byte = (pixel-raw_pixel_start) & 0xFF;
  385. }
  386. *cmd_pixels_count_byte = (pixel - cmd_pixel_start) & 0xFF;
  387. dev_addr += (pixel - cmd_pixel_start) * bpp;
  388. }
  389. if (cmd_buffer_end <= MIN_RLX_CMD_BYTES + cmd) {
  390. /* Fill leftover bytes with no-ops */
  391. if (cmd_buffer_end > cmd)
  392. memset(cmd, 0xAF, cmd_buffer_end - cmd);
  393. cmd = (uint8_t *) cmd_buffer_end;
  394. }
  395. *command_buffer_ptr = cmd;
  396. *pixel_start_ptr = pixel;
  397. *device_address_ptr = dev_addr;
  398. return;
  399. }
  400. /*
  401. * There are 3 copies of every pixel: The front buffer that the fbdev
  402. * client renders to, the actual framebuffer across the USB bus in hardware
  403. * (that we can only write to, slowly, and can never read), and (optionally)
  404. * our shadow copy that tracks what's been sent to that hardware buffer.
  405. */
  406. static int dlfb_render_hline(struct dlfb_data *dev, struct urb **urb_ptr,
  407. const char *front, char **urb_buf_ptr,
  408. u32 byte_offset, u32 byte_width,
  409. int *ident_ptr, int *sent_ptr)
  410. {
  411. const u8 *line_start, *line_end, *next_pixel;
  412. u32 dev_addr = dev->base16 + byte_offset;
  413. struct urb *urb = *urb_ptr;
  414. u8 *cmd = *urb_buf_ptr;
  415. u8 *cmd_end = (u8 *) urb->transfer_buffer + urb->transfer_buffer_length;
  416. line_start = (u8 *) (front + byte_offset);
  417. next_pixel = line_start;
  418. line_end = next_pixel + byte_width;
  419. if (dev->backing_buffer) {
  420. int offset;
  421. const u8 *back_start = (u8 *) (dev->backing_buffer
  422. + byte_offset);
  423. *ident_ptr += dlfb_trim_hline(back_start, &next_pixel,
  424. &byte_width);
  425. offset = next_pixel - line_start;
  426. line_end = next_pixel + byte_width;
  427. dev_addr += offset;
  428. back_start += offset;
  429. line_start += offset;
  430. memcpy((char *)back_start, (char *) line_start,
  431. byte_width);
  432. }
  433. while (next_pixel < line_end) {
  434. dlfb_compress_hline((const uint16_t **) &next_pixel,
  435. (const uint16_t *) line_end, &dev_addr,
  436. (u8 **) &cmd, (u8 *) cmd_end);
  437. if (cmd >= cmd_end) {
  438. int len = cmd - (u8 *) urb->transfer_buffer;
  439. if (dlfb_submit_urb(dev, urb, len))
  440. return 1; /* lost pixels is set */
  441. *sent_ptr += len;
  442. urb = dlfb_get_urb(dev);
  443. if (!urb)
  444. return 1; /* lost_pixels is set */
  445. *urb_ptr = urb;
  446. cmd = urb->transfer_buffer;
  447. cmd_end = &cmd[urb->transfer_buffer_length];
  448. }
  449. }
  450. *urb_buf_ptr = cmd;
  451. return 0;
  452. }
  453. int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
  454. int width, int height, char *data)
  455. {
  456. int i, ret;
  457. char *cmd;
  458. cycles_t start_cycles, end_cycles;
  459. int bytes_sent = 0;
  460. int bytes_identical = 0;
  461. struct urb *urb;
  462. int aligned_x;
  463. start_cycles = get_cycles();
  464. aligned_x = DL_ALIGN_DOWN(x, sizeof(unsigned long));
  465. width = DL_ALIGN_UP(width + (x-aligned_x), sizeof(unsigned long));
  466. x = aligned_x;
  467. if ((width <= 0) ||
  468. (x + width > dev->info->var.xres) ||
  469. (y + height > dev->info->var.yres))
  470. return -EINVAL;
  471. if (!atomic_read(&dev->usb_active))
  472. return 0;
  473. urb = dlfb_get_urb(dev);
  474. if (!urb)
  475. return 0;
  476. cmd = urb->transfer_buffer;
  477. for (i = y; i < y + height ; i++) {
  478. const int line_offset = dev->info->fix.line_length * i;
  479. const int byte_offset = line_offset + (x * BPP);
  480. if (dlfb_render_hline(dev, &urb,
  481. (char *) dev->info->fix.smem_start,
  482. &cmd, byte_offset, width * BPP,
  483. &bytes_identical, &bytes_sent))
  484. goto error;
  485. }
  486. if (cmd > (char *) urb->transfer_buffer) {
  487. /* Send partial buffer remaining before exiting */
  488. int len = cmd - (char *) urb->transfer_buffer;
  489. ret = dlfb_submit_urb(dev, urb, len);
  490. bytes_sent += len;
  491. } else
  492. dlfb_urb_completion(urb);
  493. error:
  494. atomic_add(bytes_sent, &dev->bytes_sent);
  495. atomic_add(bytes_identical, &dev->bytes_identical);
  496. atomic_add(width*height*2, &dev->bytes_rendered);
  497. end_cycles = get_cycles();
  498. atomic_add(((unsigned int) ((end_cycles - start_cycles)
  499. >> 10)), /* Kcycles */
  500. &dev->cpu_kcycles_used);
  501. return 0;
  502. }
  503. /*
  504. * Path triggered by usermode clients who write to filesystem
  505. * e.g. cat filename > /dev/fb1
  506. * Not used by X Windows or text-mode console. But useful for testing.
  507. * Slow because of extra copy and we must assume all pixels dirty.
  508. */
  509. static ssize_t dlfb_ops_write(struct fb_info *info, const char __user *buf,
  510. size_t count, loff_t *ppos)
  511. {
  512. ssize_t result;
  513. struct dlfb_data *dev = info->par;
  514. u32 offset = (u32) *ppos;
  515. result = fb_sys_write(info, buf, count, ppos);
  516. if (result > 0) {
  517. int start = max((int)(offset / info->fix.line_length) - 1, 0);
  518. int lines = min((u32)((result / info->fix.line_length) + 1),
  519. (u32)info->var.yres);
  520. dlfb_handle_damage(dev, 0, start, info->var.xres,
  521. lines, info->screen_base);
  522. }
  523. return result;
  524. }
  525. /* hardware has native COPY command (see libdlo), but not worth it for fbcon */
  526. static void dlfb_ops_copyarea(struct fb_info *info,
  527. const struct fb_copyarea *area)
  528. {
  529. struct dlfb_data *dev = info->par;
  530. sys_copyarea(info, area);
  531. dlfb_handle_damage(dev, area->dx, area->dy,
  532. area->width, area->height, info->screen_base);
  533. }
  534. static void dlfb_ops_imageblit(struct fb_info *info,
  535. const struct fb_image *image)
  536. {
  537. struct dlfb_data *dev = info->par;
  538. sys_imageblit(info, image);
  539. dlfb_handle_damage(dev, image->dx, image->dy,
  540. image->width, image->height, info->screen_base);
  541. }
  542. static void dlfb_ops_fillrect(struct fb_info *info,
  543. const struct fb_fillrect *rect)
  544. {
  545. struct dlfb_data *dev = info->par;
  546. sys_fillrect(info, rect);
  547. dlfb_handle_damage(dev, rect->dx, rect->dy, rect->width,
  548. rect->height, info->screen_base);
  549. }
  550. /*
  551. * NOTE: fb_defio.c is holding info->fbdefio.mutex
  552. * Touching ANY framebuffer memory that triggers a page fault
  553. * in fb_defio will cause a deadlock, when it also tries to
  554. * grab the same mutex.
  555. */
  556. static void dlfb_dpy_deferred_io(struct fb_info *info,
  557. struct list_head *pagelist)
  558. {
  559. struct page *cur;
  560. struct fb_deferred_io *fbdefio = info->fbdefio;
  561. struct dlfb_data *dev = info->par;
  562. struct urb *urb;
  563. char *cmd;
  564. cycles_t start_cycles, end_cycles;
  565. int bytes_sent = 0;
  566. int bytes_identical = 0;
  567. int bytes_rendered = 0;
  568. if (!fb_defio)
  569. return;
  570. if (!atomic_read(&dev->usb_active))
  571. return;
  572. start_cycles = get_cycles();
  573. urb = dlfb_get_urb(dev);
  574. if (!urb)
  575. return;
  576. cmd = urb->transfer_buffer;
  577. /* walk the written page list and render each to device */
  578. list_for_each_entry(cur, &fbdefio->pagelist, lru) {
  579. if (dlfb_render_hline(dev, &urb, (char *) info->fix.smem_start,
  580. &cmd, cur->index << PAGE_SHIFT,
  581. PAGE_SIZE, &bytes_identical, &bytes_sent))
  582. goto error;
  583. bytes_rendered += PAGE_SIZE;
  584. }
  585. if (cmd > (char *) urb->transfer_buffer) {
  586. /* Send partial buffer remaining before exiting */
  587. int len = cmd - (char *) urb->transfer_buffer;
  588. dlfb_submit_urb(dev, urb, len);
  589. bytes_sent += len;
  590. } else
  591. dlfb_urb_completion(urb);
  592. error:
  593. atomic_add(bytes_sent, &dev->bytes_sent);
  594. atomic_add(bytes_identical, &dev->bytes_identical);
  595. atomic_add(bytes_rendered, &dev->bytes_rendered);
  596. end_cycles = get_cycles();
  597. atomic_add(((unsigned int) ((end_cycles - start_cycles)
  598. >> 10)), /* Kcycles */
  599. &dev->cpu_kcycles_used);
  600. }
  601. static int dlfb_get_edid(struct dlfb_data *dev, char *edid, int len)
  602. {
  603. int i;
  604. int ret;
  605. char *rbuf;
  606. rbuf = kmalloc(2, GFP_KERNEL);
  607. if (!rbuf)
  608. return 0;
  609. for (i = 0; i < len; i++) {
  610. ret = usb_control_msg(dev->udev,
  611. usb_rcvctrlpipe(dev->udev, 0), (0x02),
  612. (0x80 | (0x02 << 5)), i << 8, 0xA1, rbuf, 2,
  613. HZ);
  614. if (ret < 1) {
  615. pr_err("Read EDID byte %d failed err %x\n", i, ret);
  616. i--;
  617. break;
  618. }
  619. edid[i] = rbuf[1];
  620. }
  621. kfree(rbuf);
  622. return i;
  623. }
  624. static int dlfb_ops_ioctl(struct fb_info *info, unsigned int cmd,
  625. unsigned long arg)
  626. {
  627. struct dlfb_data *dev = info->par;
  628. struct dloarea *area = NULL;
  629. if (!atomic_read(&dev->usb_active))
  630. return 0;
  631. /* TODO: Update X server to get this from sysfs instead */
  632. if (cmd == DLFB_IOCTL_RETURN_EDID) {
  633. char *edid = (char *)arg;
  634. if (copy_to_user(edid, dev->edid, dev->edid_size))
  635. return -EFAULT;
  636. return 0;
  637. }
  638. /* TODO: Help propose a standard fb.h ioctl to report mmap damage */
  639. if (cmd == DLFB_IOCTL_REPORT_DAMAGE) {
  640. /*
  641. * If we have a damage-aware client, turn fb_defio "off"
  642. * To avoid perf imact of unnecessary page fault handling.
  643. * Done by resetting the delay for this fb_info to a very
  644. * long period. Pages will become writable and stay that way.
  645. * Reset to normal value when all clients have closed this fb.
  646. */
  647. if (info->fbdefio)
  648. info->fbdefio->delay = DL_DEFIO_WRITE_DISABLE;
  649. area = (struct dloarea *)arg;
  650. if (area->x < 0)
  651. area->x = 0;
  652. if (area->x > info->var.xres)
  653. area->x = info->var.xres;
  654. if (area->y < 0)
  655. area->y = 0;
  656. if (area->y > info->var.yres)
  657. area->y = info->var.yres;
  658. dlfb_handle_damage(dev, area->x, area->y, area->w, area->h,
  659. info->screen_base);
  660. }
  661. return 0;
  662. }
  663. /* taken from vesafb */
  664. static int
  665. dlfb_ops_setcolreg(unsigned regno, unsigned red, unsigned green,
  666. unsigned blue, unsigned transp, struct fb_info *info)
  667. {
  668. int err = 0;
  669. if (regno >= info->cmap.len)
  670. return 1;
  671. if (regno < 16) {
  672. if (info->var.red.offset == 10) {
  673. /* 1:5:5:5 */
  674. ((u32 *) (info->pseudo_palette))[regno] =
  675. ((red & 0xf800) >> 1) |
  676. ((green & 0xf800) >> 6) | ((blue & 0xf800) >> 11);
  677. } else {
  678. /* 0:5:6:5 */
  679. ((u32 *) (info->pseudo_palette))[regno] =
  680. ((red & 0xf800)) |
  681. ((green & 0xfc00) >> 5) | ((blue & 0xf800) >> 11);
  682. }
  683. }
  684. return err;
  685. }
  686. /*
  687. * It's common for several clients to have framebuffer open simultaneously.
  688. * e.g. both fbcon and X. Makes things interesting.
  689. * Assumes caller is holding info->lock (for open and release at least)
  690. */
  691. static int dlfb_ops_open(struct fb_info *info, int user)
  692. {
  693. struct dlfb_data *dev = info->par;
  694. /*
  695. * fbcon aggressively connects to first framebuffer it finds,
  696. * preventing other clients (X) from working properly. Usually
  697. * not what the user wants. Fail by default with option to enable.
  698. */
  699. if ((user == 0) & (!console))
  700. return -EBUSY;
  701. /* If the USB device is gone, we don't accept new opens */
  702. if (dev->virtualized)
  703. return -ENODEV;
  704. dev->fb_count++;
  705. kref_get(&dev->kref);
  706. if (fb_defio && (info->fbdefio == NULL)) {
  707. /* enable defio at last moment if not disabled by client */
  708. struct fb_deferred_io *fbdefio;
  709. fbdefio = kmalloc(sizeof(struct fb_deferred_io), GFP_KERNEL);
  710. if (fbdefio) {
  711. fbdefio->delay = DL_DEFIO_WRITE_DELAY;
  712. fbdefio->deferred_io = dlfb_dpy_deferred_io;
  713. }
  714. info->fbdefio = fbdefio;
  715. fb_deferred_io_init(info);
  716. }
  717. pr_notice("open /dev/fb%d user=%d fb_info=%p count=%d\n",
  718. info->node, user, info, dev->fb_count);
  719. return 0;
  720. }
  721. /*
  722. * Called when all client interfaces to start transactions have been disabled,
  723. * and all references to our device instance (dlfb_data) are released.
  724. * Every transaction must have a reference, so we know are fully spun down
  725. */
  726. static void dlfb_free(struct kref *kref)
  727. {
  728. struct dlfb_data *dev = container_of(kref, struct dlfb_data, kref);
  729. /* this function will wait for all in-flight urbs to complete */
  730. if (dev->urbs.count > 0)
  731. dlfb_free_urb_list(dev);
  732. if (dev->backing_buffer)
  733. vfree(dev->backing_buffer);
  734. kfree(dev->edid);
  735. pr_warn("freeing dlfb_data %p\n", dev);
  736. kfree(dev);
  737. }
  738. static void dlfb_release_urb_work(struct work_struct *work)
  739. {
  740. struct urb_node *unode = container_of(work, struct urb_node,
  741. release_urb_work.work);
  742. up(&unode->dev->urbs.limit_sem);
  743. }
  744. static void dlfb_free_framebuffer_work(struct work_struct *work)
  745. {
  746. struct dlfb_data *dev = container_of(work, struct dlfb_data,
  747. free_framebuffer_work.work);
  748. struct fb_info *info = dev->info;
  749. int node = info->node;
  750. unregister_framebuffer(info);
  751. if (info->cmap.len != 0)
  752. fb_dealloc_cmap(&info->cmap);
  753. if (info->monspecs.modedb)
  754. fb_destroy_modedb(info->monspecs.modedb);
  755. if (info->screen_base)
  756. vfree(info->screen_base);
  757. fb_destroy_modelist(&info->modelist);
  758. dev->info = 0;
  759. /* Assume info structure is freed after this point */
  760. framebuffer_release(info);
  761. pr_warn("fb_info for /dev/fb%d has been freed\n", node);
  762. /* ref taken in probe() as part of registering framebfufer */
  763. kref_put(&dev->kref, dlfb_free);
  764. }
  765. /*
  766. * Assumes caller is holding info->lock mutex (for open and release at least)
  767. */
  768. static int dlfb_ops_release(struct fb_info *info, int user)
  769. {
  770. struct dlfb_data *dev = info->par;
  771. dev->fb_count--;
  772. /* We can't free fb_info here - fbmem will touch it when we return */
  773. if (dev->virtualized && (dev->fb_count == 0))
  774. schedule_delayed_work(&dev->free_framebuffer_work, HZ);
  775. if ((dev->fb_count == 0) && (info->fbdefio)) {
  776. fb_deferred_io_cleanup(info);
  777. kfree(info->fbdefio);
  778. info->fbdefio = NULL;
  779. info->fbops->fb_mmap = dlfb_ops_mmap;
  780. }
  781. pr_warn("released /dev/fb%d user=%d count=%d\n",
  782. info->node, user, dev->fb_count);
  783. kref_put(&dev->kref, dlfb_free);
  784. return 0;
  785. }
  786. /*
  787. * Check whether a video mode is supported by the DisplayLink chip
  788. * We start from monitor's modes, so don't need to filter that here
  789. */
  790. static int dlfb_is_valid_mode(struct fb_videomode *mode,
  791. struct fb_info *info)
  792. {
  793. struct dlfb_data *dev = info->par;
  794. if (mode->xres * mode->yres > dev->sku_pixel_limit) {
  795. pr_warn("%dx%d beyond chip capabilities\n",
  796. mode->xres, mode->yres);
  797. return 0;
  798. }
  799. pr_info("%dx%d valid mode\n", mode->xres, mode->yres);
  800. return 1;
  801. }
  802. static void dlfb_var_color_format(struct fb_var_screeninfo *var)
  803. {
  804. const struct fb_bitfield red = { 11, 5, 0 };
  805. const struct fb_bitfield green = { 5, 6, 0 };
  806. const struct fb_bitfield blue = { 0, 5, 0 };
  807. var->bits_per_pixel = 16;
  808. var->red = red;
  809. var->green = green;
  810. var->blue = blue;
  811. }
  812. static int dlfb_ops_check_var(struct fb_var_screeninfo *var,
  813. struct fb_info *info)
  814. {
  815. struct fb_videomode mode;
  816. /* TODO: support dynamically changing framebuffer size */
  817. if ((var->xres * var->yres * 2) > info->fix.smem_len)
  818. return -EINVAL;
  819. /* set device-specific elements of var unrelated to mode */
  820. dlfb_var_color_format(var);
  821. fb_var_to_videomode(&mode, var);
  822. if (!dlfb_is_valid_mode(&mode, info))
  823. return -EINVAL;
  824. return 0;
  825. }
  826. static int dlfb_ops_set_par(struct fb_info *info)
  827. {
  828. struct dlfb_data *dev = info->par;
  829. int result;
  830. u16 *pix_framebuffer;
  831. int i;
  832. pr_notice("set_par mode %dx%d\n", info->var.xres, info->var.yres);
  833. result = dlfb_set_video_mode(dev, &info->var);
  834. if ((result == 0) && (dev->fb_count == 0)) {
  835. /* paint greenscreen */
  836. pix_framebuffer = (u16 *) info->screen_base;
  837. for (i = 0; i < info->fix.smem_len / 2; i++)
  838. pix_framebuffer[i] = 0x37e6;
  839. dlfb_handle_damage(dev, 0, 0, info->var.xres, info->var.yres,
  840. info->screen_base);
  841. }
  842. return result;
  843. }
  844. /*
  845. * In order to come back from full DPMS off, we need to set the mode again
  846. */
  847. static int dlfb_ops_blank(int blank_mode, struct fb_info *info)
  848. {
  849. struct dlfb_data *dev = info->par;
  850. if (blank_mode != FB_BLANK_UNBLANK) {
  851. char *bufptr;
  852. struct urb *urb;
  853. urb = dlfb_get_urb(dev);
  854. if (!urb)
  855. return 0;
  856. bufptr = (char *) urb->transfer_buffer;
  857. bufptr = dlfb_vidreg_lock(bufptr);
  858. bufptr = dlfb_enable_hvsync(bufptr, false);
  859. bufptr = dlfb_vidreg_unlock(bufptr);
  860. dlfb_submit_urb(dev, urb, bufptr -
  861. (char *) urb->transfer_buffer);
  862. } else {
  863. dlfb_set_video_mode(dev, &info->var);
  864. }
  865. return 0;
  866. }
  867. static struct fb_ops dlfb_ops = {
  868. .owner = THIS_MODULE,
  869. .fb_read = fb_sys_read,
  870. .fb_write = dlfb_ops_write,
  871. .fb_setcolreg = dlfb_ops_setcolreg,
  872. .fb_fillrect = dlfb_ops_fillrect,
  873. .fb_copyarea = dlfb_ops_copyarea,
  874. .fb_imageblit = dlfb_ops_imageblit,
  875. .fb_mmap = dlfb_ops_mmap,
  876. .fb_ioctl = dlfb_ops_ioctl,
  877. .fb_open = dlfb_ops_open,
  878. .fb_release = dlfb_ops_release,
  879. .fb_blank = dlfb_ops_blank,
  880. .fb_check_var = dlfb_ops_check_var,
  881. .fb_set_par = dlfb_ops_set_par,
  882. };
  883. /*
  884. * Assumes &info->lock held by caller
  885. * Assumes no active clients have framebuffer open
  886. */
  887. static int dlfb_realloc_framebuffer(struct dlfb_data *dev, struct fb_info *info)
  888. {
  889. int retval = -ENOMEM;
  890. int old_len = info->fix.smem_len;
  891. int new_len;
  892. unsigned char *old_fb = info->screen_base;
  893. unsigned char *new_fb;
  894. unsigned char *new_back;
  895. pr_warn("Reallocating framebuffer. Addresses will change!\n");
  896. new_len = info->fix.line_length * info->var.yres;
  897. if (PAGE_ALIGN(new_len) > old_len) {
  898. /*
  899. * Alloc system memory for virtual framebuffer
  900. */
  901. new_fb = vmalloc(new_len);
  902. if (!new_fb) {
  903. pr_err("Virtual framebuffer alloc failed\n");
  904. goto error;
  905. }
  906. if (info->screen_base) {
  907. memcpy(new_fb, old_fb, old_len);
  908. vfree(info->screen_base);
  909. }
  910. info->screen_base = new_fb;
  911. info->fix.smem_len = PAGE_ALIGN(new_len);
  912. info->fix.smem_start = (unsigned long) new_fb;
  913. info->flags = udlfb_info_flags;
  914. /*
  915. * Second framebuffer copy to mirror the framebuffer state
  916. * on the physical USB device. We can function without this.
  917. * But with imperfect damage info we may send pixels over USB
  918. * that were, in fact, unchanged - wasting limited USB bandwidth
  919. */
  920. new_back = vzalloc(new_len);
  921. if (!new_back)
  922. pr_info("No shadow/backing buffer allocated\n");
  923. else {
  924. if (dev->backing_buffer)
  925. vfree(dev->backing_buffer);
  926. dev->backing_buffer = new_back;
  927. }
  928. }
  929. retval = 0;
  930. error:
  931. return retval;
  932. }
  933. /*
  934. * 1) Get EDID from hw, or use sw default
  935. * 2) Parse into various fb_info structs
  936. * 3) Allocate virtual framebuffer memory to back highest res mode
  937. *
  938. * Parses EDID into three places used by various parts of fbdev:
  939. * fb_var_screeninfo contains the timing of the monitor's preferred mode
  940. * fb_info.monspecs is full parsed EDID info, including monspecs.modedb
  941. * fb_info.modelist is a linked list of all monitor & VESA modes which work
  942. *
  943. * If EDID is not readable/valid, then modelist is all VESA modes,
  944. * monspecs is NULL, and fb_var_screeninfo is set to safe VESA mode
  945. * Returns 0 if successful
  946. */
  947. static int dlfb_setup_modes(struct dlfb_data *dev,
  948. struct fb_info *info,
  949. char *default_edid, size_t default_edid_size)
  950. {
  951. int i;
  952. const struct fb_videomode *default_vmode = NULL;
  953. int result = 0;
  954. char *edid;
  955. int tries = 3;
  956. if (info->dev) /* only use mutex if info has been registered */
  957. mutex_lock(&info->lock);
  958. edid = kmalloc(EDID_LENGTH, GFP_KERNEL);
  959. if (!edid) {
  960. result = -ENOMEM;
  961. goto error;
  962. }
  963. fb_destroy_modelist(&info->modelist);
  964. memset(&info->monspecs, 0, sizeof(info->monspecs));
  965. /*
  966. * Try to (re)read EDID from hardware first
  967. * EDID data may return, but not parse as valid
  968. * Try again a few times, in case of e.g. analog cable noise
  969. */
  970. while (tries--) {
  971. i = dlfb_get_edid(dev, edid, EDID_LENGTH);
  972. if (i >= EDID_LENGTH)
  973. fb_edid_to_monspecs(edid, &info->monspecs);
  974. if (info->monspecs.modedb_len > 0) {
  975. dev->edid = edid;
  976. dev->edid_size = i;
  977. break;
  978. }
  979. }
  980. /* If that fails, use a previously returned EDID if available */
  981. if (info->monspecs.modedb_len == 0) {
  982. pr_err("Unable to get valid EDID from device/display\n");
  983. if (dev->edid) {
  984. fb_edid_to_monspecs(dev->edid, &info->monspecs);
  985. if (info->monspecs.modedb_len > 0)
  986. pr_err("Using previously queried EDID\n");
  987. }
  988. }
  989. /* If that fails, use the default EDID we were handed */
  990. if (info->monspecs.modedb_len == 0) {
  991. if (default_edid_size >= EDID_LENGTH) {
  992. fb_edid_to_monspecs(default_edid, &info->monspecs);
  993. if (info->monspecs.modedb_len > 0) {
  994. memcpy(edid, default_edid, default_edid_size);
  995. dev->edid = edid;
  996. dev->edid_size = default_edid_size;
  997. pr_err("Using default/backup EDID\n");
  998. }
  999. }
  1000. }
  1001. /* If we've got modes, let's pick a best default mode */
  1002. if (info->monspecs.modedb_len > 0) {
  1003. for (i = 0; i < info->monspecs.modedb_len; i++) {
  1004. if (dlfb_is_valid_mode(&info->monspecs.modedb[i], info))
  1005. fb_add_videomode(&info->monspecs.modedb[i],
  1006. &info->modelist);
  1007. else {
  1008. if (i == 0)
  1009. /* if we've removed top/best mode */
  1010. info->monspecs.misc
  1011. &= ~FB_MISC_1ST_DETAIL;
  1012. }
  1013. }
  1014. default_vmode = fb_find_best_display(&info->monspecs,
  1015. &info->modelist);
  1016. }
  1017. /* If everything else has failed, fall back to safe default mode */
  1018. if (default_vmode == NULL) {
  1019. struct fb_videomode fb_vmode = {0};
  1020. /*
  1021. * Add the standard VESA modes to our modelist
  1022. * Since we don't have EDID, there may be modes that
  1023. * overspec monitor and/or are incorrect aspect ratio, etc.
  1024. * But at least the user has a chance to choose
  1025. */
  1026. for (i = 0; i < VESA_MODEDB_SIZE; i++) {
  1027. if (dlfb_is_valid_mode((struct fb_videomode *)
  1028. &vesa_modes[i], info))
  1029. fb_add_videomode(&vesa_modes[i],
  1030. &info->modelist);
  1031. }
  1032. /*
  1033. * default to resolution safe for projectors
  1034. * (since they are most common case without EDID)
  1035. */
  1036. fb_vmode.xres = 800;
  1037. fb_vmode.yres = 600;
  1038. fb_vmode.refresh = 60;
  1039. default_vmode = fb_find_nearest_mode(&fb_vmode,
  1040. &info->modelist);
  1041. }
  1042. /* If we have good mode and no active clients*/
  1043. if ((default_vmode != NULL) && (dev->fb_count == 0)) {
  1044. fb_videomode_to_var(&info->var, default_vmode);
  1045. dlfb_var_color_format(&info->var);
  1046. /*
  1047. * with mode size info, we can now alloc our framebuffer.
  1048. */
  1049. memcpy(&info->fix, &dlfb_fix, sizeof(dlfb_fix));
  1050. info->fix.line_length = info->var.xres *
  1051. (info->var.bits_per_pixel / 8);
  1052. result = dlfb_realloc_framebuffer(dev, info);
  1053. } else
  1054. result = -EINVAL;
  1055. error:
  1056. if (edid && (dev->edid != edid))
  1057. kfree(edid);
  1058. if (info->dev)
  1059. mutex_unlock(&info->lock);
  1060. return result;
  1061. }
  1062. static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
  1063. struct device_attribute *a, char *buf) {
  1064. struct fb_info *fb_info = dev_get_drvdata(fbdev);
  1065. struct dlfb_data *dev = fb_info->par;
  1066. return snprintf(buf, PAGE_SIZE, "%u\n",
  1067. atomic_read(&dev->bytes_rendered));
  1068. }
  1069. static ssize_t metrics_bytes_identical_show(struct device *fbdev,
  1070. struct device_attribute *a, char *buf) {
  1071. struct fb_info *fb_info = dev_get_drvdata(fbdev);
  1072. struct dlfb_data *dev = fb_info->par;
  1073. return snprintf(buf, PAGE_SIZE, "%u\n",
  1074. atomic_read(&dev->bytes_identical));
  1075. }
  1076. static ssize_t metrics_bytes_sent_show(struct device *fbdev,
  1077. struct device_attribute *a, char *buf) {
  1078. struct fb_info *fb_info = dev_get_drvdata(fbdev);
  1079. struct dlfb_data *dev = fb_info->par;
  1080. return snprintf(buf, PAGE_SIZE, "%u\n",
  1081. atomic_read(&dev->bytes_sent));
  1082. }
  1083. static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
  1084. struct device_attribute *a, char *buf) {
  1085. struct fb_info *fb_info = dev_get_drvdata(fbdev);
  1086. struct dlfb_data *dev = fb_info->par;
  1087. return snprintf(buf, PAGE_SIZE, "%u\n",
  1088. atomic_read(&dev->cpu_kcycles_used));
  1089. }
  1090. static ssize_t edid_show(
  1091. struct file *filp,
  1092. struct kobject *kobj, struct bin_attribute *a,
  1093. char *buf, loff_t off, size_t count) {
  1094. struct device *fbdev = container_of(kobj, struct device, kobj);
  1095. struct fb_info *fb_info = dev_get_drvdata(fbdev);
  1096. struct dlfb_data *dev = fb_info->par;
  1097. if (dev->edid == NULL)
  1098. return 0;
  1099. if ((off >= dev->edid_size) || (count > dev->edid_size))
  1100. return 0;
  1101. if (off + count > dev->edid_size)
  1102. count = dev->edid_size - off;
  1103. pr_info("sysfs edid copy %p to %p, %d bytes\n",
  1104. dev->edid, buf, (int) count);
  1105. memcpy(buf, dev->edid, count);
  1106. return count;
  1107. }
  1108. static ssize_t edid_store(
  1109. struct file *filp,
  1110. struct kobject *kobj, struct bin_attribute *a,
  1111. char *src, loff_t src_off, size_t src_size) {
  1112. struct device *fbdev = container_of(kobj, struct device, kobj);
  1113. struct fb_info *fb_info = dev_get_drvdata(fbdev);
  1114. struct dlfb_data *dev = fb_info->par;
  1115. /* We only support write of entire EDID at once, no offset*/
  1116. if ((src_size != EDID_LENGTH) || (src_off != 0))
  1117. return 0;
  1118. dlfb_setup_modes(dev, fb_info, src, src_size);
  1119. if (dev->edid && (memcmp(src, dev->edid, src_size) == 0)) {
  1120. pr_info("sysfs written EDID is new default\n");
  1121. dlfb_ops_set_par(fb_info);
  1122. return src_size;
  1123. } else
  1124. return 0;
  1125. }
  1126. static ssize_t metrics_reset_store(struct device *fbdev,
  1127. struct device_attribute *attr,
  1128. const char *buf, size_t count)
  1129. {
  1130. struct fb_info *fb_info = dev_get_drvdata(fbdev);
  1131. struct dlfb_data *dev = fb_info->par;
  1132. atomic_set(&dev->bytes_rendered, 0);
  1133. atomic_set(&dev->bytes_identical, 0);
  1134. atomic_set(&dev->bytes_sent, 0);
  1135. atomic_set(&dev->cpu_kcycles_used, 0);
  1136. return count;
  1137. }
  1138. static struct bin_attribute edid_attr = {
  1139. .attr.name = "edid",
  1140. .attr.mode = 0666,
  1141. .size = EDID_LENGTH,
  1142. .read = edid_show,
  1143. .write = edid_store
  1144. };
  1145. static struct device_attribute fb_device_attrs[] = {
  1146. __ATTR_RO(metrics_bytes_rendered),
  1147. __ATTR_RO(metrics_bytes_identical),
  1148. __ATTR_RO(metrics_bytes_sent),
  1149. __ATTR_RO(metrics_cpu_kcycles_used),
  1150. __ATTR(metrics_reset, S_IWUSR, NULL, metrics_reset_store),
  1151. };
  1152. /*
  1153. * This is necessary before we can communicate with the display controller.
  1154. */
  1155. static int dlfb_select_std_channel(struct dlfb_data *dev)
  1156. {
  1157. int ret;
  1158. u8 set_def_chn[] = { 0x57, 0xCD, 0xDC, 0xA7,
  1159. 0x1C, 0x88, 0x5E, 0x15,
  1160. 0x60, 0xFE, 0xC6, 0x97,
  1161. 0x16, 0x3D, 0x47, 0xF2 };
  1162. ret = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0),
  1163. NR_USB_REQUEST_CHANNEL,
  1164. (USB_DIR_OUT | USB_TYPE_VENDOR), 0, 0,
  1165. set_def_chn, sizeof(set_def_chn), USB_CTRL_SET_TIMEOUT);
  1166. return ret;
  1167. }
  1168. static int dlfb_parse_vendor_descriptor(struct dlfb_data *dev,
  1169. struct usb_device *usbdev)
  1170. {
  1171. char *desc;
  1172. char *buf;
  1173. char *desc_end;
  1174. u8 total_len = 0;
  1175. buf = kzalloc(MAX_VENDOR_DESCRIPTOR_SIZE, GFP_KERNEL);
  1176. if (!buf)
  1177. return false;
  1178. desc = buf;
  1179. total_len = usb_get_descriptor(usbdev, 0x5f, /* vendor specific */
  1180. 0, desc, MAX_VENDOR_DESCRIPTOR_SIZE);
  1181. if (total_len > 5) {
  1182. pr_info("vendor descriptor length:%x data:%02x %02x %02x %02x" \
  1183. "%02x %02x %02x %02x %02x %02x %02x\n",
  1184. total_len, desc[0],
  1185. desc[1], desc[2], desc[3], desc[4], desc[5], desc[6],
  1186. desc[7], desc[8], desc[9], desc[10]);
  1187. if ((desc[0] != total_len) || /* descriptor length */
  1188. (desc[1] != 0x5f) || /* vendor descriptor type */
  1189. (desc[2] != 0x01) || /* version (2 bytes) */
  1190. (desc[3] != 0x00) ||
  1191. (desc[4] != total_len - 2)) /* length after type */
  1192. goto unrecognized;
  1193. desc_end = desc + total_len;
  1194. desc += 5; /* the fixed header we've already parsed */
  1195. while (desc < desc_end) {
  1196. u8 length;
  1197. u16 key;
  1198. key = *((u16 *) desc);
  1199. desc += sizeof(u16);
  1200. length = *desc;
  1201. desc++;
  1202. switch (key) {
  1203. case 0x0200: { /* max_area */
  1204. u32 max_area;
  1205. max_area = le32_to_cpu(*((u32 *)desc));
  1206. pr_warn("DL chip limited to %d pixel modes\n",
  1207. max_area);
  1208. dev->sku_pixel_limit = max_area;
  1209. break;
  1210. }
  1211. default:
  1212. break;
  1213. }
  1214. desc += length;
  1215. }
  1216. }
  1217. goto success;
  1218. unrecognized:
  1219. /* allow udlfb to load for now even if firmware unrecognized */
  1220. pr_err("Unrecognized vendor firmware descriptor\n");
  1221. success:
  1222. kfree(buf);
  1223. return true;
  1224. }
  1225. static int dlfb_usb_probe(struct usb_interface *interface,
  1226. const struct usb_device_id *id)
  1227. {
  1228. struct usb_device *usbdev;
  1229. struct dlfb_data *dev = 0;
  1230. struct fb_info *info = 0;
  1231. int retval = -ENOMEM;
  1232. int i;
  1233. /* usb initialization */
  1234. usbdev = interface_to_usbdev(interface);
  1235. dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  1236. if (dev == NULL) {
  1237. err("dlfb_usb_probe: failed alloc of dev struct\n");
  1238. goto error;
  1239. }
  1240. /* we need to wait for both usb and fbdev to spin down on disconnect */
  1241. kref_init(&dev->kref); /* matching kref_put in usb .disconnect fn */
  1242. kref_get(&dev->kref); /* matching kref_put in free_framebuffer_work */
  1243. dev->udev = usbdev;
  1244. dev->gdev = &usbdev->dev; /* our generic struct device * */
  1245. usb_set_intfdata(interface, dev);
  1246. pr_info("%s %s - serial #%s\n",
  1247. usbdev->manufacturer, usbdev->product, usbdev->serial);
  1248. pr_info("vid_%04x&pid_%04x&rev_%04x driver's dlfb_data struct at %p\n",
  1249. usbdev->descriptor.idVendor, usbdev->descriptor.idProduct,
  1250. usbdev->descriptor.bcdDevice, dev);
  1251. pr_info("console enable=%d\n", console);
  1252. pr_info("fb_defio enable=%d\n", fb_defio);
  1253. dev->sku_pixel_limit = 2048 * 1152; /* default to maximum */
  1254. if (!dlfb_parse_vendor_descriptor(dev, usbdev)) {
  1255. pr_err("firmware not recognized. Assume incompatible device\n");
  1256. goto error;
  1257. }
  1258. if (!dlfb_alloc_urb_list(dev, WRITES_IN_FLIGHT, MAX_TRANSFER)) {
  1259. retval = -ENOMEM;
  1260. pr_err("dlfb_alloc_urb_list failed\n");
  1261. goto error;
  1262. }
  1263. /* We don't register a new USB class. Our client interface is fbdev */
  1264. /* allocates framebuffer driver structure, not framebuffer memory */
  1265. info = framebuffer_alloc(0, &usbdev->dev);
  1266. if (!info) {
  1267. retval = -ENOMEM;
  1268. pr_err("framebuffer_alloc failed\n");
  1269. goto error;
  1270. }
  1271. dev->info = info;
  1272. info->par = dev;
  1273. info->pseudo_palette = dev->pseudo_palette;
  1274. info->fbops = &dlfb_ops;
  1275. retval = fb_alloc_cmap(&info->cmap, 256, 0);
  1276. if (retval < 0) {
  1277. pr_err("fb_alloc_cmap failed %x\n", retval);
  1278. goto error;
  1279. }
  1280. INIT_DELAYED_WORK(&dev->free_framebuffer_work,
  1281. dlfb_free_framebuffer_work);
  1282. INIT_LIST_HEAD(&info->modelist);
  1283. retval = dlfb_setup_modes(dev, info, NULL, 0);
  1284. if (retval != 0) {
  1285. pr_err("unable to find common mode for display and adapter\n");
  1286. goto error;
  1287. }
  1288. /* ready to begin using device */
  1289. atomic_set(&dev->usb_active, 1);
  1290. dlfb_select_std_channel(dev);
  1291. dlfb_ops_check_var(&info->var, info);
  1292. dlfb_ops_set_par(info);
  1293. retval = register_framebuffer(info);
  1294. if (retval < 0) {
  1295. pr_err("register_framebuffer failed %d\n", retval);
  1296. goto error;
  1297. }
  1298. for (i = 0; i < ARRAY_SIZE(fb_device_attrs); i++) {
  1299. retval = device_create_file(info->dev, &fb_device_attrs[i]);
  1300. if (retval) {
  1301. pr_err("device_create_file failed %d\n", retval);
  1302. goto err_del_attrs;
  1303. }
  1304. }
  1305. retval = device_create_bin_file(info->dev, &edid_attr);
  1306. if (retval) {
  1307. pr_err("device_create_bin_file failed %d\n", retval);
  1308. goto err_del_attrs;
  1309. }
  1310. pr_info("DisplayLink USB device /dev/fb%d attached. %dx%d resolution."
  1311. " Using %dK framebuffer memory\n", info->node,
  1312. info->var.xres, info->var.yres,
  1313. ((dev->backing_buffer) ?
  1314. info->fix.smem_len * 2 : info->fix.smem_len) >> 10);
  1315. return 0;
  1316. err_del_attrs:
  1317. for (i -= 1; i >= 0; i--)
  1318. device_remove_file(info->dev, &fb_device_attrs[i]);
  1319. error:
  1320. if (dev) {
  1321. if (info) {
  1322. if (info->cmap.len != 0)
  1323. fb_dealloc_cmap(&info->cmap);
  1324. if (info->monspecs.modedb)
  1325. fb_destroy_modedb(info->monspecs.modedb);
  1326. if (info->screen_base)
  1327. vfree(info->screen_base);
  1328. fb_destroy_modelist(&info->modelist);
  1329. framebuffer_release(info);
  1330. }
  1331. if (dev->backing_buffer)
  1332. vfree(dev->backing_buffer);
  1333. kref_put(&dev->kref, dlfb_free); /* ref for framebuffer */
  1334. kref_put(&dev->kref, dlfb_free); /* last ref from kref_init */
  1335. /* dev has been deallocated. Do not dereference */
  1336. }
  1337. return retval;
  1338. }
  1339. static void dlfb_usb_disconnect(struct usb_interface *interface)
  1340. {
  1341. struct dlfb_data *dev;
  1342. struct fb_info *info;
  1343. int i;
  1344. dev = usb_get_intfdata(interface);
  1345. info = dev->info;
  1346. pr_info("USB disconnect starting\n");
  1347. /* we virtualize until all fb clients release. Then we free */
  1348. dev->virtualized = true;
  1349. /* When non-active we'll update virtual framebuffer, but no new urbs */
  1350. atomic_set(&dev->usb_active, 0);
  1351. /* remove udlfb's sysfs interfaces */
  1352. for (i = 0; i < ARRAY_SIZE(fb_device_attrs); i++)
  1353. device_remove_file(info->dev, &fb_device_attrs[i]);
  1354. device_remove_bin_file(info->dev, &edid_attr);
  1355. unlink_framebuffer(info);
  1356. usb_set_intfdata(interface, NULL);
  1357. /* if clients still have us open, will be freed on last close */
  1358. if (dev->fb_count == 0)
  1359. schedule_delayed_work(&dev->free_framebuffer_work, 0);
  1360. /* release reference taken by kref_init in probe() */
  1361. kref_put(&dev->kref, dlfb_free);
  1362. /* consider dlfb_data freed */
  1363. return;
  1364. }
  1365. static struct usb_driver dlfb_driver = {
  1366. .name = "udlfb",
  1367. .probe = dlfb_usb_probe,
  1368. .disconnect = dlfb_usb_disconnect,
  1369. .id_table = id_table,
  1370. };
  1371. static int __init dlfb_module_init(void)
  1372. {
  1373. int res;
  1374. res = usb_register(&dlfb_driver);
  1375. if (res)
  1376. err("usb_register failed. Error number %d", res);
  1377. return res;
  1378. }
  1379. static void __exit dlfb_module_exit(void)
  1380. {
  1381. usb_deregister(&dlfb_driver);
  1382. }
  1383. module_init(dlfb_module_init);
  1384. module_exit(dlfb_module_exit);
  1385. static void dlfb_urb_completion(struct urb *urb)
  1386. {
  1387. struct urb_node *unode = urb->context;
  1388. struct dlfb_data *dev = unode->dev;
  1389. unsigned long flags;
  1390. /* sync/async unlink faults aren't errors */
  1391. if (urb->status) {
  1392. if (!(urb->status == -ENOENT ||
  1393. urb->status == -ECONNRESET ||
  1394. urb->status == -ESHUTDOWN)) {
  1395. pr_err("%s - nonzero write bulk status received: %d\n",
  1396. __func__, urb->status);
  1397. atomic_set(&dev->lost_pixels, 1);
  1398. }
  1399. }
  1400. urb->transfer_buffer_length = dev->urbs.size; /* reset to actual */
  1401. spin_lock_irqsave(&dev->urbs.lock, flags);
  1402. list_add_tail(&unode->entry, &dev->urbs.list);
  1403. dev->urbs.available++;
  1404. spin_unlock_irqrestore(&dev->urbs.lock, flags);
  1405. /*
  1406. * When using fb_defio, we deadlock if up() is called
  1407. * while another is waiting. So queue to another process.
  1408. */
  1409. if (fb_defio)
  1410. schedule_delayed_work(&unode->release_urb_work, 0);
  1411. else
  1412. up(&dev->urbs.limit_sem);
  1413. }
  1414. static void dlfb_free_urb_list(struct dlfb_data *dev)
  1415. {
  1416. int count = dev->urbs.count;
  1417. struct list_head *node;
  1418. struct urb_node *unode;
  1419. struct urb *urb;
  1420. int ret;
  1421. unsigned long flags;
  1422. pr_notice("Waiting for completes and freeing all render urbs\n");
  1423. /* keep waiting and freeing, until we've got 'em all */
  1424. while (count--) {
  1425. /* Getting interrupted means a leak, but ok at shutdown*/
  1426. ret = down_interruptible(&dev->urbs.limit_sem);
  1427. if (ret)
  1428. break;
  1429. spin_lock_irqsave(&dev->urbs.lock, flags);
  1430. node = dev->urbs.list.next; /* have reserved one with sem */
  1431. list_del_init(node);
  1432. spin_unlock_irqrestore(&dev->urbs.lock, flags);
  1433. unode = list_entry(node, struct urb_node, entry);
  1434. urb = unode->urb;
  1435. /* Free each separately allocated piece */
  1436. usb_free_coherent(urb->dev, dev->urbs.size,
  1437. urb->transfer_buffer, urb->transfer_dma);
  1438. usb_free_urb(urb);
  1439. kfree(node);
  1440. }
  1441. }
  1442. static int dlfb_alloc_urb_list(struct dlfb_data *dev, int count, size_t size)
  1443. {
  1444. int i = 0;
  1445. struct urb *urb;
  1446. struct urb_node *unode;
  1447. char *buf;
  1448. spin_lock_init(&dev->urbs.lock);
  1449. dev->urbs.size = size;
  1450. INIT_LIST_HEAD(&dev->urbs.list);
  1451. while (i < count) {
  1452. unode = kzalloc(sizeof(struct urb_node), GFP_KERNEL);
  1453. if (!unode)
  1454. break;
  1455. unode->dev = dev;
  1456. INIT_DELAYED_WORK(&unode->release_urb_work,
  1457. dlfb_release_urb_work);
  1458. urb = usb_alloc_urb(0, GFP_KERNEL);
  1459. if (!urb) {
  1460. kfree(unode);
  1461. break;
  1462. }
  1463. unode->urb = urb;
  1464. buf = usb_alloc_coherent(dev->udev, MAX_TRANSFER, GFP_KERNEL,
  1465. &urb->transfer_dma);
  1466. if (!buf) {
  1467. kfree(unode);
  1468. usb_free_urb(urb);
  1469. break;
  1470. }
  1471. /* urb->transfer_buffer_length set to actual before submit */
  1472. usb_fill_bulk_urb(urb, dev->udev, usb_sndbulkpipe(dev->udev, 1),
  1473. buf, size, dlfb_urb_completion, unode);
  1474. urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  1475. list_add_tail(&unode->entry, &dev->urbs.list);
  1476. i++;
  1477. }
  1478. sema_init(&dev->urbs.limit_sem, i);
  1479. dev->urbs.count = i;
  1480. dev->urbs.available = i;
  1481. pr_notice("allocated %d %d byte urbs\n", i, (int) size);
  1482. return i;
  1483. }
  1484. static struct urb *dlfb_get_urb(struct dlfb_data *dev)
  1485. {
  1486. int ret = 0;
  1487. struct list_head *entry;
  1488. struct urb_node *unode;
  1489. struct urb *urb = NULL;
  1490. unsigned long flags;
  1491. /* Wait for an in-flight buffer to complete and get re-queued */
  1492. ret = down_timeout(&dev->urbs.limit_sem, GET_URB_TIMEOUT);
  1493. if (ret) {
  1494. atomic_set(&dev->lost_pixels, 1);
  1495. pr_warn("wait for urb interrupted: %x available: %d\n",
  1496. ret, dev->urbs.available);
  1497. goto error;
  1498. }
  1499. spin_lock_irqsave(&dev->urbs.lock, flags);
  1500. BUG_ON(list_empty(&dev->urbs.list)); /* reserved one with limit_sem */
  1501. entry = dev->urbs.list.next;
  1502. list_del_init(entry);
  1503. dev->urbs.available--;
  1504. spin_unlock_irqrestore(&dev->urbs.lock, flags);
  1505. unode = list_entry(entry, struct urb_node, entry);
  1506. urb = unode->urb;
  1507. error:
  1508. return urb;
  1509. }
  1510. static int dlfb_submit_urb(struct dlfb_data *dev, struct urb *urb, size_t len)
  1511. {
  1512. int ret;
  1513. BUG_ON(len > dev->urbs.size);
  1514. urb->transfer_buffer_length = len; /* set to actual payload len */
  1515. ret = usb_submit_urb(urb, GFP_KERNEL);
  1516. if (ret) {
  1517. dlfb_urb_completion(urb); /* because no one else will */
  1518. atomic_set(&dev->lost_pixels, 1);
  1519. pr_err("usb_submit_urb error %x\n", ret);
  1520. }
  1521. return ret;
  1522. }
  1523. module_param(console, bool, S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP);
  1524. MODULE_PARM_DESC(console, "Allow fbcon to consume first framebuffer found");
  1525. module_param(fb_defio, bool, S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP);
  1526. MODULE_PARM_DESC(fb_defio, "Enable fb_defio mmap support. *Experimental*");
  1527. MODULE_AUTHOR("Roberto De Ioris <roberto@unbit.it>, "
  1528. "Jaya Kumar <jayakumar.lkml@gmail.com>, "
  1529. "Bernie Thompson <bernie@plugable.com>");
  1530. MODULE_DESCRIPTION("DisplayLink kernel framebuffer driver");
  1531. MODULE_LICENSE("GPL");