uvesafb.c 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * A framebuffer driver for VBE 2.0+ compliant video cards
  4. *
  5. * (c) 2007 Michal Januszewski <spock@gentoo.org>
  6. * Loosely based upon the vesafb driver.
  7. *
  8. */
  9. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  10. #include <linux/init.h>
  11. #include <linux/module.h>
  12. #include <linux/moduleparam.h>
  13. #include <linux/skbuff.h>
  14. #include <linux/timer.h>
  15. #include <linux/completion.h>
  16. #include <linux/connector.h>
  17. #include <linux/random.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/limits.h>
  20. #include <linux/fb.h>
  21. #include <linux/io.h>
  22. #include <linux/mutex.h>
  23. #include <linux/slab.h>
  24. #include <video/edid.h>
  25. #include <video/uvesafb.h>
  26. #ifdef CONFIG_X86
  27. #include <video/vga.h>
  28. #endif
  29. #include "edid.h"
  30. static struct cb_id uvesafb_cn_id = {
  31. .idx = CN_IDX_V86D,
  32. .val = CN_VAL_V86D_UVESAFB
  33. };
  34. static char v86d_path[PATH_MAX] = "/sbin/v86d";
  35. static char v86d_started; /* has v86d been started by uvesafb? */
  36. static const struct fb_fix_screeninfo uvesafb_fix = {
  37. .id = "VESA VGA",
  38. .type = FB_TYPE_PACKED_PIXELS,
  39. .accel = FB_ACCEL_NONE,
  40. .visual = FB_VISUAL_TRUECOLOR,
  41. };
  42. static int mtrr = 3; /* enable mtrr by default */
  43. static bool blank = true; /* enable blanking by default */
  44. static int ypan = 1; /* 0: scroll, 1: ypan, 2: ywrap */
  45. static bool pmi_setpal = true; /* use PMI for palette changes */
  46. static bool nocrtc; /* ignore CRTC settings */
  47. static bool noedid; /* don't try DDC transfers */
  48. static int vram_remap; /* set amt. of memory to be used */
  49. static int vram_total; /* set total amount of memory */
  50. static u16 maxclk; /* maximum pixel clock */
  51. static u16 maxvf; /* maximum vertical frequency */
  52. static u16 maxhf; /* maximum horizontal frequency */
  53. static u16 vbemode; /* force use of a specific VBE mode */
  54. static char *mode_option;
  55. static u8 dac_width = 6;
  56. static struct uvesafb_ktask *uvfb_tasks[UVESAFB_TASKS_MAX];
  57. static DEFINE_MUTEX(uvfb_lock);
  58. /*
  59. * A handler for replies from userspace.
  60. *
  61. * Make sure each message passes consistency checks and if it does,
  62. * find the kernel part of the task struct, copy the registers and
  63. * the buffer contents and then complete the task.
  64. */
  65. static void uvesafb_cn_callback(struct cn_msg *msg, struct netlink_skb_parms *nsp)
  66. {
  67. struct uvesafb_task *utask;
  68. struct uvesafb_ktask *task;
  69. if (!capable(CAP_SYS_ADMIN))
  70. return;
  71. if (msg->seq >= UVESAFB_TASKS_MAX)
  72. return;
  73. mutex_lock(&uvfb_lock);
  74. task = uvfb_tasks[msg->seq];
  75. if (!task || msg->ack != task->ack) {
  76. mutex_unlock(&uvfb_lock);
  77. return;
  78. }
  79. utask = (struct uvesafb_task *)msg->data;
  80. /* Sanity checks for the buffer length. */
  81. if (task->t.buf_len < utask->buf_len ||
  82. utask->buf_len > msg->len - sizeof(*utask)) {
  83. mutex_unlock(&uvfb_lock);
  84. return;
  85. }
  86. uvfb_tasks[msg->seq] = NULL;
  87. mutex_unlock(&uvfb_lock);
  88. memcpy(&task->t, utask, sizeof(*utask));
  89. if (task->t.buf_len && task->buf)
  90. memcpy(task->buf, utask + 1, task->t.buf_len);
  91. complete(task->done);
  92. return;
  93. }
  94. static int uvesafb_helper_start(void)
  95. {
  96. char *envp[] = {
  97. "HOME=/",
  98. "PATH=/sbin:/bin",
  99. NULL,
  100. };
  101. char *argv[] = {
  102. v86d_path,
  103. NULL,
  104. };
  105. return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
  106. }
  107. /*
  108. * Execute a uvesafb task.
  109. *
  110. * Returns 0 if the task is executed successfully.
  111. *
  112. * A message sent to the userspace consists of the uvesafb_task
  113. * struct and (optionally) a buffer. The uvesafb_task struct is
  114. * a simplified version of uvesafb_ktask (its kernel counterpart)
  115. * containing only the register values, flags and the length of
  116. * the buffer.
  117. *
  118. * Each message is assigned a sequence number (increased linearly)
  119. * and a random ack number. The sequence number is used as a key
  120. * for the uvfb_tasks array which holds pointers to uvesafb_ktask
  121. * structs for all requests.
  122. */
  123. static int uvesafb_exec(struct uvesafb_ktask *task)
  124. {
  125. static int seq;
  126. struct cn_msg *m;
  127. int err;
  128. int len = sizeof(task->t) + task->t.buf_len;
  129. /*
  130. * Check whether the message isn't longer than the maximum
  131. * allowed by connector.
  132. */
  133. if (sizeof(*m) + len > CONNECTOR_MAX_MSG_SIZE) {
  134. pr_warn("message too long (%d), can't execute task\n",
  135. (int)(sizeof(*m) + len));
  136. return -E2BIG;
  137. }
  138. m = kzalloc(sizeof(*m) + len, GFP_KERNEL);
  139. if (!m)
  140. return -ENOMEM;
  141. init_completion(task->done);
  142. memcpy(&m->id, &uvesafb_cn_id, sizeof(m->id));
  143. m->seq = seq;
  144. m->len = len;
  145. m->ack = get_random_u32();
  146. /* uvesafb_task structure */
  147. memcpy(m + 1, &task->t, sizeof(task->t));
  148. /* Buffer */
  149. memcpy((u8 *)(m + 1) + sizeof(task->t), task->buf, task->t.buf_len);
  150. /*
  151. * Save the message ack number so that we can find the kernel
  152. * part of this task when a reply is received from userspace.
  153. */
  154. task->ack = m->ack;
  155. mutex_lock(&uvfb_lock);
  156. /* If all slots are taken -- bail out. */
  157. if (uvfb_tasks[seq]) {
  158. mutex_unlock(&uvfb_lock);
  159. err = -EBUSY;
  160. goto out;
  161. }
  162. /* Save a pointer to the kernel part of the task struct. */
  163. uvfb_tasks[seq] = task;
  164. mutex_unlock(&uvfb_lock);
  165. err = cn_netlink_send(m, 0, 0, GFP_KERNEL);
  166. if (err == -ESRCH) {
  167. /*
  168. * Try to start the userspace helper if sending
  169. * the request failed the first time.
  170. */
  171. err = uvesafb_helper_start();
  172. if (err) {
  173. pr_err("failed to execute %s\n", v86d_path);
  174. pr_err("make sure that the v86d helper is installed and executable\n");
  175. } else {
  176. v86d_started = 1;
  177. err = cn_netlink_send(m, 0, 0, gfp_any());
  178. if (err == -ENOBUFS)
  179. err = 0;
  180. }
  181. } else if (err == -ENOBUFS)
  182. err = 0;
  183. if (!err && !(task->t.flags & TF_EXIT))
  184. err = !wait_for_completion_timeout(task->done,
  185. msecs_to_jiffies(UVESAFB_TIMEOUT));
  186. mutex_lock(&uvfb_lock);
  187. uvfb_tasks[seq] = NULL;
  188. mutex_unlock(&uvfb_lock);
  189. seq++;
  190. if (seq >= UVESAFB_TASKS_MAX)
  191. seq = 0;
  192. out:
  193. kfree(m);
  194. return err;
  195. }
  196. /*
  197. * Free a uvesafb_ktask struct.
  198. */
  199. static void uvesafb_free(struct uvesafb_ktask *task)
  200. {
  201. if (task) {
  202. kfree(task->done);
  203. kfree(task);
  204. }
  205. }
  206. /*
  207. * Prepare a uvesafb_ktask struct to be used again.
  208. */
  209. static void uvesafb_reset(struct uvesafb_ktask *task)
  210. {
  211. struct completion *cpl = task->done;
  212. memset(task, 0, sizeof(*task));
  213. task->done = cpl;
  214. }
  215. /*
  216. * Allocate and prepare a uvesafb_ktask struct.
  217. */
  218. static struct uvesafb_ktask *uvesafb_prep(void)
  219. {
  220. struct uvesafb_ktask *task;
  221. task = kzalloc_obj(*task);
  222. if (task) {
  223. task->done = kzalloc_obj(*task->done);
  224. if (!task->done) {
  225. kfree(task);
  226. task = NULL;
  227. }
  228. }
  229. return task;
  230. }
  231. static void uvesafb_setup_var(struct fb_var_screeninfo *var,
  232. struct fb_info *info, struct vbe_mode_ib *mode)
  233. {
  234. struct uvesafb_par *par = info->par;
  235. var->vmode = FB_VMODE_NONINTERLACED;
  236. var->sync = FB_SYNC_VERT_HIGH_ACT;
  237. var->xres = mode->x_res;
  238. var->yres = mode->y_res;
  239. var->xres_virtual = mode->x_res;
  240. var->yres_virtual = (par->ypan) ?
  241. info->fix.smem_len / mode->bytes_per_scan_line :
  242. mode->y_res;
  243. var->xoffset = 0;
  244. var->yoffset = 0;
  245. var->bits_per_pixel = mode->bits_per_pixel;
  246. if (var->bits_per_pixel == 15)
  247. var->bits_per_pixel = 16;
  248. if (var->bits_per_pixel > 8) {
  249. var->red.offset = mode->red_off;
  250. var->red.length = mode->red_len;
  251. var->green.offset = mode->green_off;
  252. var->green.length = mode->green_len;
  253. var->blue.offset = mode->blue_off;
  254. var->blue.length = mode->blue_len;
  255. var->transp.offset = mode->rsvd_off;
  256. var->transp.length = mode->rsvd_len;
  257. } else {
  258. var->red.offset = 0;
  259. var->green.offset = 0;
  260. var->blue.offset = 0;
  261. var->transp.offset = 0;
  262. var->red.length = 8;
  263. var->green.length = 8;
  264. var->blue.length = 8;
  265. var->transp.length = 0;
  266. }
  267. }
  268. static int uvesafb_vbe_find_mode(struct uvesafb_par *par,
  269. int xres, int yres, int depth, unsigned char flags)
  270. {
  271. int i, match = -1, h = 0, d = 0x7fffffff;
  272. for (i = 0; i < par->vbe_modes_cnt; i++) {
  273. h = abs(par->vbe_modes[i].x_res - xres) +
  274. abs(par->vbe_modes[i].y_res - yres) +
  275. abs(depth - par->vbe_modes[i].depth);
  276. /*
  277. * We have an exact match in terms of resolution
  278. * and depth.
  279. */
  280. if (h == 0)
  281. return i;
  282. if (h < d || (h == d && par->vbe_modes[i].depth > depth)) {
  283. d = h;
  284. match = i;
  285. }
  286. }
  287. i = 1;
  288. if (flags & UVESAFB_EXACT_DEPTH &&
  289. par->vbe_modes[match].depth != depth)
  290. i = 0;
  291. if (flags & UVESAFB_EXACT_RES && d > 24)
  292. i = 0;
  293. if (i != 0)
  294. return match;
  295. else
  296. return -1;
  297. }
  298. static u8 *uvesafb_vbe_state_save(struct uvesafb_par *par)
  299. {
  300. struct uvesafb_ktask *task;
  301. u8 *state;
  302. int err;
  303. if (!par->vbe_state_size)
  304. return NULL;
  305. state = kmalloc(par->vbe_state_size, GFP_KERNEL);
  306. if (!state)
  307. return ERR_PTR(-ENOMEM);
  308. task = uvesafb_prep();
  309. if (!task) {
  310. kfree(state);
  311. return NULL;
  312. }
  313. task->t.regs.eax = 0x4f04;
  314. task->t.regs.ecx = 0x000f;
  315. task->t.regs.edx = 0x0001;
  316. task->t.flags = TF_BUF_RET | TF_BUF_ESBX;
  317. task->t.buf_len = par->vbe_state_size;
  318. task->buf = state;
  319. err = uvesafb_exec(task);
  320. if (err || (task->t.regs.eax & 0xffff) != 0x004f) {
  321. pr_warn("VBE get state call failed (eax=0x%x, err=%d)\n",
  322. task->t.regs.eax, err);
  323. kfree(state);
  324. state = NULL;
  325. }
  326. uvesafb_free(task);
  327. return state;
  328. }
  329. static void uvesafb_vbe_state_restore(struct uvesafb_par *par, u8 *state_buf)
  330. {
  331. struct uvesafb_ktask *task;
  332. int err;
  333. if (!state_buf)
  334. return;
  335. task = uvesafb_prep();
  336. if (!task)
  337. return;
  338. task->t.regs.eax = 0x4f04;
  339. task->t.regs.ecx = 0x000f;
  340. task->t.regs.edx = 0x0002;
  341. task->t.buf_len = par->vbe_state_size;
  342. task->t.flags = TF_BUF_ESBX;
  343. task->buf = state_buf;
  344. err = uvesafb_exec(task);
  345. if (err || (task->t.regs.eax & 0xffff) != 0x004f)
  346. pr_warn("VBE state restore call failed (eax=0x%x, err=%d)\n",
  347. task->t.regs.eax, err);
  348. uvesafb_free(task);
  349. }
  350. static int uvesafb_vbe_getinfo(struct uvesafb_ktask *task,
  351. struct uvesafb_par *par)
  352. {
  353. int err;
  354. task->t.regs.eax = 0x4f00;
  355. task->t.flags = TF_VBEIB;
  356. task->t.buf_len = sizeof(struct vbe_ib);
  357. task->buf = &par->vbe_ib;
  358. memcpy(par->vbe_ib.vbe_signature, "VBE2", 4);
  359. err = uvesafb_exec(task);
  360. if (err || (task->t.regs.eax & 0xffff) != 0x004f) {
  361. pr_err("Getting VBE info block failed (eax=0x%x, err=%d)\n",
  362. (u32)task->t.regs.eax, err);
  363. return -EINVAL;
  364. }
  365. if (par->vbe_ib.vbe_version < 0x0200) {
  366. pr_err("Sorry, pre-VBE 2.0 cards are not supported\n");
  367. return -EINVAL;
  368. }
  369. if (!par->vbe_ib.mode_list_ptr) {
  370. pr_err("Missing mode list!\n");
  371. return -EINVAL;
  372. }
  373. pr_info("");
  374. /*
  375. * Convert string pointers and the mode list pointer into
  376. * usable addresses. Print informational messages about the
  377. * video adapter and its vendor.
  378. */
  379. if (par->vbe_ib.oem_vendor_name_ptr)
  380. pr_cont("%s, ",
  381. ((char *)task->buf) + par->vbe_ib.oem_vendor_name_ptr);
  382. if (par->vbe_ib.oem_product_name_ptr)
  383. pr_cont("%s, ",
  384. ((char *)task->buf) + par->vbe_ib.oem_product_name_ptr);
  385. if (par->vbe_ib.oem_product_rev_ptr)
  386. pr_cont("%s, ",
  387. ((char *)task->buf) + par->vbe_ib.oem_product_rev_ptr);
  388. if (par->vbe_ib.oem_string_ptr)
  389. pr_cont("OEM: %s, ",
  390. ((char *)task->buf) + par->vbe_ib.oem_string_ptr);
  391. pr_cont("VBE v%d.%d\n",
  392. (par->vbe_ib.vbe_version & 0xff00) >> 8,
  393. par->vbe_ib.vbe_version & 0xff);
  394. return 0;
  395. }
  396. static int uvesafb_vbe_getmodes(struct uvesafb_ktask *task,
  397. struct uvesafb_par *par)
  398. {
  399. int off = 0, err;
  400. u16 *mode;
  401. par->vbe_modes_cnt = 0;
  402. /* Count available modes. */
  403. mode = (u16 *) (((u8 *)&par->vbe_ib) + par->vbe_ib.mode_list_ptr);
  404. while (*mode != 0xffff) {
  405. par->vbe_modes_cnt++;
  406. mode++;
  407. }
  408. par->vbe_modes = kzalloc_objs(struct vbe_mode_ib, par->vbe_modes_cnt);
  409. if (!par->vbe_modes)
  410. return -ENOMEM;
  411. /* Get info about all available modes. */
  412. mode = (u16 *) (((u8 *)&par->vbe_ib) + par->vbe_ib.mode_list_ptr);
  413. while (*mode != 0xffff) {
  414. struct vbe_mode_ib *mib;
  415. uvesafb_reset(task);
  416. task->t.regs.eax = 0x4f01;
  417. task->t.regs.ecx = (u32) *mode;
  418. task->t.flags = TF_BUF_RET | TF_BUF_ESDI;
  419. task->t.buf_len = sizeof(struct vbe_mode_ib);
  420. task->buf = par->vbe_modes + off;
  421. err = uvesafb_exec(task);
  422. if (err || (task->t.regs.eax & 0xffff) != 0x004f) {
  423. pr_warn("Getting mode info block for mode 0x%x failed (eax=0x%x, err=%d)\n",
  424. *mode, (u32)task->t.regs.eax, err);
  425. mode++;
  426. par->vbe_modes_cnt--;
  427. continue;
  428. }
  429. mib = task->buf;
  430. mib->mode_id = *mode;
  431. /*
  432. * We only want modes that are supported with the current
  433. * hardware configuration, color, graphics and that have
  434. * support for the LFB.
  435. */
  436. if ((mib->mode_attr & VBE_MODE_MASK) == VBE_MODE_MASK &&
  437. mib->bits_per_pixel >= 8)
  438. off++;
  439. else
  440. par->vbe_modes_cnt--;
  441. mode++;
  442. mib->depth = mib->red_len + mib->green_len + mib->blue_len;
  443. /*
  444. * Handle 8bpp modes and modes with broken color component
  445. * lengths.
  446. */
  447. if (mib->depth == 0 || (mib->depth == 24 &&
  448. mib->bits_per_pixel == 32))
  449. mib->depth = mib->bits_per_pixel;
  450. }
  451. if (par->vbe_modes_cnt > 0)
  452. return 0;
  453. else
  454. return -EINVAL;
  455. }
  456. /*
  457. * The Protected Mode Interface is 32-bit x86 code, so we only run it on
  458. * x86 and not x86_64.
  459. */
  460. #ifdef CONFIG_X86_32
  461. static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
  462. struct uvesafb_par *par)
  463. {
  464. int i, err;
  465. uvesafb_reset(task);
  466. task->t.regs.eax = 0x4f0a;
  467. task->t.regs.ebx = 0x0;
  468. err = uvesafb_exec(task);
  469. if (err)
  470. return err;
  471. if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
  472. par->pmi_setpal = par->ypan = 0;
  473. } else {
  474. par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
  475. + task->t.regs.edi);
  476. par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
  477. par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
  478. pr_info("protected mode interface info at %04x:%04x\n",
  479. (u16)task->t.regs.es, (u16)task->t.regs.edi);
  480. pr_info("pmi: set display start = %p, set palette = %p\n",
  481. par->pmi_start, par->pmi_pal);
  482. if (par->pmi_base[3]) {
  483. pr_info("pmi: ports =");
  484. for (i = par->pmi_base[3]/2;
  485. par->pmi_base[i] != 0xffff; i++)
  486. pr_cont(" %x", par->pmi_base[i]);
  487. pr_cont("\n");
  488. if (par->pmi_base[i] != 0xffff) {
  489. pr_info("can't handle memory requests, pmi disabled\n");
  490. par->ypan = par->pmi_setpal = 0;
  491. }
  492. }
  493. }
  494. return 0;
  495. }
  496. #endif /* CONFIG_X86_32 */
  497. /*
  498. * Check whether a video mode is supported by the Video BIOS and is
  499. * compatible with the monitor limits.
  500. */
  501. static int uvesafb_is_valid_mode(struct fb_videomode *mode,
  502. struct fb_info *info)
  503. {
  504. if (info->monspecs.gtf) {
  505. fb_videomode_to_var(&info->var, mode);
  506. if (fb_validate_mode(&info->var, info))
  507. return 0;
  508. }
  509. if (uvesafb_vbe_find_mode(info->par, mode->xres, mode->yres, 8,
  510. UVESAFB_EXACT_RES) == -1)
  511. return 0;
  512. return 1;
  513. }
  514. static int uvesafb_vbe_getedid(struct uvesafb_ktask *task, struct fb_info *info)
  515. {
  516. struct uvesafb_par *par = info->par;
  517. int err = 0;
  518. if (noedid || par->vbe_ib.vbe_version < 0x0300)
  519. return -EINVAL;
  520. task->t.regs.eax = 0x4f15;
  521. task->t.regs.ebx = 0;
  522. task->t.regs.ecx = 0;
  523. task->t.buf_len = 0;
  524. task->t.flags = 0;
  525. err = uvesafb_exec(task);
  526. if ((task->t.regs.eax & 0xffff) != 0x004f || err)
  527. return -EINVAL;
  528. if ((task->t.regs.ebx & 0x3) == 3) {
  529. pr_info("VBIOS/hardware supports both DDC1 and DDC2 transfers\n");
  530. } else if ((task->t.regs.ebx & 0x3) == 2) {
  531. pr_info("VBIOS/hardware supports DDC2 transfers\n");
  532. } else if ((task->t.regs.ebx & 0x3) == 1) {
  533. pr_info("VBIOS/hardware supports DDC1 transfers\n");
  534. } else {
  535. pr_info("VBIOS/hardware doesn't support DDC transfers\n");
  536. return -EINVAL;
  537. }
  538. task->t.regs.eax = 0x4f15;
  539. task->t.regs.ebx = 1;
  540. task->t.regs.ecx = task->t.regs.edx = 0;
  541. task->t.flags = TF_BUF_RET | TF_BUF_ESDI;
  542. task->t.buf_len = EDID_LENGTH;
  543. task->buf = kzalloc(EDID_LENGTH, GFP_KERNEL);
  544. if (!task->buf)
  545. return -ENOMEM;
  546. err = uvesafb_exec(task);
  547. if ((task->t.regs.eax & 0xffff) == 0x004f && !err) {
  548. fb_edid_to_monspecs(task->buf, &info->monspecs);
  549. if (info->monspecs.vfmax && info->monspecs.hfmax) {
  550. /*
  551. * If the maximum pixel clock wasn't specified in
  552. * the EDID block, set it to 300 MHz.
  553. */
  554. if (info->monspecs.dclkmax == 0)
  555. info->monspecs.dclkmax = 300 * 1000000;
  556. info->monspecs.gtf = 1;
  557. }
  558. } else {
  559. err = -EINVAL;
  560. }
  561. kfree(task->buf);
  562. return err;
  563. }
  564. static void uvesafb_vbe_getmonspecs(struct uvesafb_ktask *task,
  565. struct fb_info *info)
  566. {
  567. struct uvesafb_par *par = info->par;
  568. int i;
  569. memset(&info->monspecs, 0, sizeof(info->monspecs));
  570. /*
  571. * If we don't get all necessary data from the EDID block,
  572. * mark it as incompatible with the GTF and set nocrtc so
  573. * that we always use the default BIOS refresh rate.
  574. */
  575. if (uvesafb_vbe_getedid(task, info)) {
  576. info->monspecs.gtf = 0;
  577. par->nocrtc = 1;
  578. }
  579. /* Kernel command line overrides. */
  580. if (maxclk)
  581. info->monspecs.dclkmax = maxclk * 1000000;
  582. if (maxvf)
  583. info->monspecs.vfmax = maxvf;
  584. if (maxhf)
  585. info->monspecs.hfmax = maxhf * 1000;
  586. /*
  587. * In case DDC transfers are not supported, the user can provide
  588. * monitor limits manually. Lower limits are set to "safe" values.
  589. */
  590. if (info->monspecs.gtf == 0 && maxclk && maxvf && maxhf) {
  591. info->monspecs.dclkmin = 0;
  592. info->monspecs.vfmin = 60;
  593. info->monspecs.hfmin = 29000;
  594. info->monspecs.gtf = 1;
  595. par->nocrtc = 0;
  596. }
  597. if (info->monspecs.gtf)
  598. pr_info("monitor limits: vf = %d Hz, hf = %d kHz, clk = %d MHz\n",
  599. info->monspecs.vfmax,
  600. (int)(info->monspecs.hfmax / 1000),
  601. (int)(info->monspecs.dclkmax / 1000000));
  602. else
  603. pr_info("no monitor limits have been set, default refresh rate will be used\n");
  604. /* Add VBE modes to the modelist. */
  605. for (i = 0; i < par->vbe_modes_cnt; i++) {
  606. struct fb_var_screeninfo var;
  607. struct vbe_mode_ib *mode;
  608. struct fb_videomode vmode;
  609. mode = &par->vbe_modes[i];
  610. memset(&var, 0, sizeof(var));
  611. var.xres = mode->x_res;
  612. var.yres = mode->y_res;
  613. fb_get_mode(FB_VSYNCTIMINGS | FB_IGNOREMON, 60, &var, info);
  614. fb_var_to_videomode(&vmode, &var);
  615. fb_add_videomode(&vmode, &info->modelist);
  616. }
  617. /* Add valid VESA modes to our modelist. */
  618. for (i = 0; i < VESA_MODEDB_SIZE; i++) {
  619. if (uvesafb_is_valid_mode((struct fb_videomode *)
  620. &vesa_modes[i], info))
  621. fb_add_videomode(&vesa_modes[i], &info->modelist);
  622. }
  623. for (i = 0; i < info->monspecs.modedb_len; i++) {
  624. if (uvesafb_is_valid_mode(&info->monspecs.modedb[i], info))
  625. fb_add_videomode(&info->monspecs.modedb[i],
  626. &info->modelist);
  627. }
  628. return;
  629. }
  630. static void uvesafb_vbe_getstatesize(struct uvesafb_ktask *task,
  631. struct uvesafb_par *par)
  632. {
  633. int err;
  634. uvesafb_reset(task);
  635. /*
  636. * Get the VBE state buffer size. We want all available
  637. * hardware state data (CL = 0x0f).
  638. */
  639. task->t.regs.eax = 0x4f04;
  640. task->t.regs.ecx = 0x000f;
  641. task->t.regs.edx = 0x0000;
  642. task->t.flags = 0;
  643. err = uvesafb_exec(task);
  644. if (err || (task->t.regs.eax & 0xffff) != 0x004f) {
  645. pr_warn("VBE state buffer size cannot be determined (eax=0x%x, err=%d)\n",
  646. task->t.regs.eax, err);
  647. par->vbe_state_size = 0;
  648. return;
  649. }
  650. par->vbe_state_size = 64 * (task->t.regs.ebx & 0xffff);
  651. }
  652. static int uvesafb_vbe_init(struct fb_info *info)
  653. {
  654. struct uvesafb_ktask *task = NULL;
  655. struct uvesafb_par *par = info->par;
  656. int err;
  657. task = uvesafb_prep();
  658. if (!task)
  659. return -ENOMEM;
  660. err = uvesafb_vbe_getinfo(task, par);
  661. if (err)
  662. goto out;
  663. err = uvesafb_vbe_getmodes(task, par);
  664. if (err)
  665. goto out;
  666. par->nocrtc = nocrtc;
  667. #ifdef CONFIG_X86_32
  668. par->pmi_setpal = pmi_setpal;
  669. par->ypan = ypan;
  670. if (par->pmi_setpal || par->ypan) {
  671. if (__supported_pte_mask & _PAGE_NX) {
  672. par->pmi_setpal = par->ypan = 0;
  673. pr_warn("NX protection is active, better not use the PMI\n");
  674. } else {
  675. uvesafb_vbe_getpmi(task, par);
  676. }
  677. }
  678. #else
  679. /* The protected mode interface is not available on non-x86. */
  680. par->pmi_setpal = par->ypan = 0;
  681. #endif
  682. INIT_LIST_HEAD(&info->modelist);
  683. uvesafb_vbe_getmonspecs(task, info);
  684. uvesafb_vbe_getstatesize(task, par);
  685. out: uvesafb_free(task);
  686. return err;
  687. }
  688. static int uvesafb_vbe_init_mode(struct fb_info *info)
  689. {
  690. struct list_head *pos;
  691. struct fb_modelist *modelist;
  692. struct fb_videomode *mode;
  693. struct uvesafb_par *par = info->par;
  694. int i, modeid;
  695. /* Has the user requested a specific VESA mode? */
  696. if (vbemode) {
  697. for (i = 0; i < par->vbe_modes_cnt; i++) {
  698. if (par->vbe_modes[i].mode_id == vbemode) {
  699. modeid = i;
  700. uvesafb_setup_var(&info->var, info,
  701. &par->vbe_modes[modeid]);
  702. fb_get_mode(FB_VSYNCTIMINGS | FB_IGNOREMON, 60,
  703. &info->var, info);
  704. /*
  705. * With pixclock set to 0, the default BIOS
  706. * timings will be used in set_par().
  707. */
  708. info->var.pixclock = 0;
  709. goto gotmode;
  710. }
  711. }
  712. pr_info("requested VBE mode 0x%x is unavailable\n", vbemode);
  713. vbemode = 0;
  714. }
  715. /* Count the modes in the modelist */
  716. i = 0;
  717. list_for_each(pos, &info->modelist)
  718. i++;
  719. /*
  720. * Convert the modelist into a modedb so that we can use it with
  721. * fb_find_mode().
  722. */
  723. mode = kzalloc_objs(*mode, i);
  724. if (mode) {
  725. i = 0;
  726. list_for_each(pos, &info->modelist) {
  727. modelist = list_entry(pos, struct fb_modelist, list);
  728. mode[i] = modelist->mode;
  729. i++;
  730. }
  731. if (!mode_option)
  732. mode_option = UVESAFB_DEFAULT_MODE;
  733. i = fb_find_mode(&info->var, info, mode_option, mode, i,
  734. NULL, 8);
  735. kfree(mode);
  736. }
  737. /* fb_find_mode() failed */
  738. if (i == 0) {
  739. info->var.xres = 640;
  740. info->var.yres = 480;
  741. mode = (struct fb_videomode *)
  742. fb_find_best_mode(&info->var, &info->modelist);
  743. if (mode) {
  744. fb_videomode_to_var(&info->var, mode);
  745. } else {
  746. modeid = par->vbe_modes[0].mode_id;
  747. uvesafb_setup_var(&info->var, info,
  748. &par->vbe_modes[modeid]);
  749. fb_get_mode(FB_VSYNCTIMINGS | FB_IGNOREMON, 60,
  750. &info->var, info);
  751. goto gotmode;
  752. }
  753. }
  754. /* Look for a matching VBE mode. */
  755. modeid = uvesafb_vbe_find_mode(par, info->var.xres, info->var.yres,
  756. info->var.bits_per_pixel, UVESAFB_EXACT_RES);
  757. if (modeid == -1)
  758. return -EINVAL;
  759. uvesafb_setup_var(&info->var, info, &par->vbe_modes[modeid]);
  760. gotmode:
  761. /*
  762. * If we are not VBE3.0+ compliant, we're done -- the BIOS will
  763. * ignore our timings anyway.
  764. */
  765. if (par->vbe_ib.vbe_version < 0x0300 || par->nocrtc)
  766. fb_get_mode(FB_VSYNCTIMINGS | FB_IGNOREMON, 60,
  767. &info->var, info);
  768. return modeid;
  769. }
  770. static int uvesafb_setpalette(struct uvesafb_pal_entry *entries, int count,
  771. int start, struct fb_info *info)
  772. {
  773. struct uvesafb_ktask *task;
  774. #ifdef CONFIG_X86
  775. struct uvesafb_par *par = info->par;
  776. int i = par->mode_idx;
  777. #endif
  778. int err = 0;
  779. /*
  780. * We support palette modifications for 8 bpp modes only, so
  781. * there can never be more than 256 entries.
  782. */
  783. if (start + count > 256)
  784. return -EINVAL;
  785. #ifdef CONFIG_X86
  786. /* Use VGA registers if mode is VGA-compatible. */
  787. if (i >= 0 && i < par->vbe_modes_cnt &&
  788. par->vbe_modes[i].mode_attr & VBE_MODE_VGACOMPAT) {
  789. for (i = 0; i < count; i++) {
  790. outb_p(start + i, dac_reg);
  791. outb_p(entries[i].red, dac_val);
  792. outb_p(entries[i].green, dac_val);
  793. outb_p(entries[i].blue, dac_val);
  794. }
  795. }
  796. #ifdef CONFIG_X86_32
  797. else if (par->pmi_setpal) {
  798. __asm__ __volatile__(
  799. "call *(%%esi)"
  800. : /* no return value */
  801. : "a" (0x4f09), /* EAX */
  802. "b" (0), /* EBX */
  803. "c" (count), /* ECX */
  804. "d" (start), /* EDX */
  805. "D" (entries), /* EDI */
  806. "S" (&par->pmi_pal)); /* ESI */
  807. }
  808. #endif /* CONFIG_X86_32 */
  809. else
  810. #endif /* CONFIG_X86 */
  811. {
  812. task = uvesafb_prep();
  813. if (!task)
  814. return -ENOMEM;
  815. task->t.regs.eax = 0x4f09;
  816. task->t.regs.ebx = 0x0;
  817. task->t.regs.ecx = count;
  818. task->t.regs.edx = start;
  819. task->t.flags = TF_BUF_ESDI;
  820. task->t.buf_len = sizeof(struct uvesafb_pal_entry) * count;
  821. task->buf = entries;
  822. err = uvesafb_exec(task);
  823. if ((task->t.regs.eax & 0xffff) != 0x004f)
  824. err = 1;
  825. uvesafb_free(task);
  826. }
  827. return err;
  828. }
  829. static int uvesafb_setcolreg(unsigned regno, unsigned red, unsigned green,
  830. unsigned blue, unsigned transp,
  831. struct fb_info *info)
  832. {
  833. struct uvesafb_pal_entry entry;
  834. int shift = 16 - dac_width;
  835. int err = 0;
  836. if (regno >= info->cmap.len)
  837. return -EINVAL;
  838. if (info->var.bits_per_pixel == 8) {
  839. entry.red = red >> shift;
  840. entry.green = green >> shift;
  841. entry.blue = blue >> shift;
  842. entry.pad = 0;
  843. err = uvesafb_setpalette(&entry, 1, regno, info);
  844. } else if (regno < 16) {
  845. switch (info->var.bits_per_pixel) {
  846. case 16:
  847. if (info->var.red.offset == 10) {
  848. /* 1:5:5:5 */
  849. ((u32 *) (info->pseudo_palette))[regno] =
  850. ((red & 0xf800) >> 1) |
  851. ((green & 0xf800) >> 6) |
  852. ((blue & 0xf800) >> 11);
  853. } else {
  854. /* 0:5:6:5 */
  855. ((u32 *) (info->pseudo_palette))[regno] =
  856. ((red & 0xf800) ) |
  857. ((green & 0xfc00) >> 5) |
  858. ((blue & 0xf800) >> 11);
  859. }
  860. break;
  861. case 24:
  862. case 32:
  863. red >>= 8;
  864. green >>= 8;
  865. blue >>= 8;
  866. ((u32 *)(info->pseudo_palette))[regno] =
  867. (red << info->var.red.offset) |
  868. (green << info->var.green.offset) |
  869. (blue << info->var.blue.offset);
  870. break;
  871. }
  872. }
  873. return err;
  874. }
  875. static int uvesafb_setcmap(struct fb_cmap *cmap, struct fb_info *info)
  876. {
  877. struct uvesafb_pal_entry *entries;
  878. int shift = 16 - dac_width;
  879. int i, err = 0;
  880. if (info->var.bits_per_pixel == 8) {
  881. if (cmap->start + cmap->len > info->cmap.start +
  882. info->cmap.len || cmap->start < info->cmap.start)
  883. return -EINVAL;
  884. entries = kmalloc_objs(*entries, cmap->len);
  885. if (!entries)
  886. return -ENOMEM;
  887. for (i = 0; i < cmap->len; i++) {
  888. entries[i].red = cmap->red[i] >> shift;
  889. entries[i].green = cmap->green[i] >> shift;
  890. entries[i].blue = cmap->blue[i] >> shift;
  891. entries[i].pad = 0;
  892. }
  893. err = uvesafb_setpalette(entries, cmap->len, cmap->start, info);
  894. kfree(entries);
  895. } else {
  896. /*
  897. * For modes with bpp > 8, we only set the pseudo palette in
  898. * the fb_info struct. We rely on uvesafb_setcolreg to do all
  899. * sanity checking.
  900. */
  901. for (i = 0; i < cmap->len; i++) {
  902. err |= uvesafb_setcolreg(cmap->start + i, cmap->red[i],
  903. cmap->green[i], cmap->blue[i],
  904. 0, info);
  905. }
  906. }
  907. return err;
  908. }
  909. static int uvesafb_pan_display(struct fb_var_screeninfo *var,
  910. struct fb_info *info)
  911. {
  912. #ifdef CONFIG_X86_32
  913. int offset;
  914. struct uvesafb_par *par = info->par;
  915. offset = (var->yoffset * info->fix.line_length + var->xoffset) / 4;
  916. /*
  917. * It turns out it's not the best idea to do panning via vm86,
  918. * so we only allow it if we have a PMI.
  919. */
  920. if (par->pmi_start) {
  921. __asm__ __volatile__(
  922. "call *(%%edi)"
  923. : /* no return value */
  924. : "a" (0x4f07), /* EAX */
  925. "b" (0), /* EBX */
  926. "c" (offset), /* ECX */
  927. "d" (offset >> 16), /* EDX */
  928. "D" (&par->pmi_start)); /* EDI */
  929. }
  930. #endif
  931. return 0;
  932. }
  933. static int uvesafb_blank(int blank, struct fb_info *info)
  934. {
  935. struct uvesafb_ktask *task;
  936. int err = 1;
  937. #ifdef CONFIG_X86
  938. struct uvesafb_par *par = info->par;
  939. if (par->vbe_ib.capabilities & VBE_CAP_VGACOMPAT) {
  940. int loop = 10000;
  941. u8 seq = 0, crtc17 = 0;
  942. if (blank == FB_BLANK_POWERDOWN) {
  943. seq = 0x20;
  944. crtc17 = 0x00;
  945. err = 0;
  946. } else {
  947. seq = 0x00;
  948. crtc17 = 0x80;
  949. err = (blank == FB_BLANK_UNBLANK) ? 0 : -EINVAL;
  950. }
  951. vga_wseq(NULL, 0x00, 0x01);
  952. seq |= vga_rseq(NULL, 0x01) & ~0x20;
  953. vga_wseq(NULL, 0x00, seq);
  954. crtc17 |= vga_rcrt(NULL, 0x17) & ~0x80;
  955. while (loop--);
  956. vga_wcrt(NULL, 0x17, crtc17);
  957. vga_wseq(NULL, 0x00, 0x03);
  958. } else
  959. #endif /* CONFIG_X86 */
  960. {
  961. task = uvesafb_prep();
  962. if (!task)
  963. return -ENOMEM;
  964. task->t.regs.eax = 0x4f10;
  965. switch (blank) {
  966. case FB_BLANK_UNBLANK:
  967. task->t.regs.ebx = 0x0001;
  968. break;
  969. case FB_BLANK_NORMAL:
  970. task->t.regs.ebx = 0x0101; /* standby */
  971. break;
  972. case FB_BLANK_POWERDOWN:
  973. task->t.regs.ebx = 0x0401; /* powerdown */
  974. break;
  975. default:
  976. goto out;
  977. }
  978. err = uvesafb_exec(task);
  979. if (err || (task->t.regs.eax & 0xffff) != 0x004f)
  980. err = 1;
  981. out: uvesafb_free(task);
  982. }
  983. return err;
  984. }
  985. static int uvesafb_open(struct fb_info *info, int user)
  986. {
  987. struct uvesafb_par *par = info->par;
  988. int cnt = atomic_read(&par->ref_count);
  989. u8 *buf = NULL;
  990. if (!cnt && par->vbe_state_size) {
  991. buf = uvesafb_vbe_state_save(par);
  992. if (IS_ERR(buf)) {
  993. pr_warn("save hardware state failed, error code is %ld!\n",
  994. PTR_ERR(buf));
  995. } else {
  996. par->vbe_state_orig = buf;
  997. }
  998. }
  999. atomic_inc(&par->ref_count);
  1000. return 0;
  1001. }
  1002. static int uvesafb_release(struct fb_info *info, int user)
  1003. {
  1004. struct uvesafb_ktask *task = NULL;
  1005. struct uvesafb_par *par = info->par;
  1006. int cnt = atomic_read(&par->ref_count);
  1007. if (!cnt)
  1008. return -EINVAL;
  1009. if (cnt != 1)
  1010. goto out;
  1011. task = uvesafb_prep();
  1012. if (!task)
  1013. goto out;
  1014. /* First, try to set the standard 80x25 text mode. */
  1015. task->t.regs.eax = 0x0003;
  1016. uvesafb_exec(task);
  1017. /*
  1018. * Now try to restore whatever hardware state we might have
  1019. * saved when the fb device was first opened.
  1020. */
  1021. uvesafb_vbe_state_restore(par, par->vbe_state_orig);
  1022. out:
  1023. atomic_dec(&par->ref_count);
  1024. uvesafb_free(task);
  1025. return 0;
  1026. }
  1027. static int uvesafb_set_par(struct fb_info *info)
  1028. {
  1029. struct uvesafb_par *par = info->par;
  1030. struct uvesafb_ktask *task = NULL;
  1031. struct vbe_crtc_ib *crtc = NULL;
  1032. struct vbe_mode_ib *mode = NULL;
  1033. int i, err = 0, depth = info->var.bits_per_pixel;
  1034. if (depth > 8 && depth != 32)
  1035. depth = info->var.red.length + info->var.green.length +
  1036. info->var.blue.length;
  1037. i = uvesafb_vbe_find_mode(par, info->var.xres, info->var.yres, depth,
  1038. UVESAFB_EXACT_RES | UVESAFB_EXACT_DEPTH);
  1039. if (i >= 0)
  1040. mode = &par->vbe_modes[i];
  1041. else
  1042. return -EINVAL;
  1043. task = uvesafb_prep();
  1044. if (!task)
  1045. return -ENOMEM;
  1046. setmode:
  1047. task->t.regs.eax = 0x4f02;
  1048. task->t.regs.ebx = mode->mode_id | 0x4000; /* use LFB */
  1049. if (par->vbe_ib.vbe_version >= 0x0300 && !par->nocrtc &&
  1050. info->var.pixclock != 0) {
  1051. task->t.regs.ebx |= 0x0800; /* use CRTC data */
  1052. task->t.flags = TF_BUF_ESDI;
  1053. crtc = kzalloc_obj(struct vbe_crtc_ib);
  1054. if (!crtc) {
  1055. err = -ENOMEM;
  1056. goto out;
  1057. }
  1058. crtc->horiz_start = info->var.xres + info->var.right_margin;
  1059. crtc->horiz_end = crtc->horiz_start + info->var.hsync_len;
  1060. crtc->horiz_total = crtc->horiz_end + info->var.left_margin;
  1061. crtc->vert_start = info->var.yres + info->var.lower_margin;
  1062. crtc->vert_end = crtc->vert_start + info->var.vsync_len;
  1063. crtc->vert_total = crtc->vert_end + info->var.upper_margin;
  1064. crtc->pixel_clock = PICOS2KHZ(info->var.pixclock) * 1000;
  1065. crtc->refresh_rate = (u16)(100 * (crtc->pixel_clock /
  1066. (crtc->vert_total * crtc->horiz_total)));
  1067. if (info->var.vmode & FB_VMODE_DOUBLE)
  1068. crtc->flags |= 0x1;
  1069. if (info->var.vmode & FB_VMODE_INTERLACED)
  1070. crtc->flags |= 0x2;
  1071. if (!(info->var.sync & FB_SYNC_HOR_HIGH_ACT))
  1072. crtc->flags |= 0x4;
  1073. if (!(info->var.sync & FB_SYNC_VERT_HIGH_ACT))
  1074. crtc->flags |= 0x8;
  1075. memcpy(&par->crtc, crtc, sizeof(*crtc));
  1076. } else {
  1077. memset(&par->crtc, 0, sizeof(*crtc));
  1078. }
  1079. task->t.buf_len = sizeof(struct vbe_crtc_ib);
  1080. task->buf = &par->crtc;
  1081. err = uvesafb_exec(task);
  1082. if (err || (task->t.regs.eax & 0xffff) != 0x004f) {
  1083. /*
  1084. * The mode switch might have failed because we tried to
  1085. * use our own timings. Try again with the default timings.
  1086. */
  1087. if (crtc != NULL) {
  1088. pr_warn("mode switch failed (eax=0x%x, err=%d) - trying again with default timings\n",
  1089. task->t.regs.eax, err);
  1090. uvesafb_reset(task);
  1091. kfree(crtc);
  1092. crtc = NULL;
  1093. info->var.pixclock = 0;
  1094. goto setmode;
  1095. } else {
  1096. pr_err("mode switch failed (eax=0x%x, err=%d)\n",
  1097. task->t.regs.eax, err);
  1098. err = -EINVAL;
  1099. goto out;
  1100. }
  1101. }
  1102. par->mode_idx = i;
  1103. /* For 8bpp modes, always try to set the DAC to 8 bits. */
  1104. if (par->vbe_ib.capabilities & VBE_CAP_CAN_SWITCH_DAC &&
  1105. mode->bits_per_pixel <= 8) {
  1106. uvesafb_reset(task);
  1107. task->t.regs.eax = 0x4f08;
  1108. task->t.regs.ebx = 0x0800;
  1109. err = uvesafb_exec(task);
  1110. if (err || (task->t.regs.eax & 0xffff) != 0x004f ||
  1111. ((task->t.regs.ebx & 0xff00) >> 8) != 8) {
  1112. dac_width = 6;
  1113. } else {
  1114. dac_width = 8;
  1115. }
  1116. }
  1117. info->fix.visual = (info->var.bits_per_pixel == 8) ?
  1118. FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
  1119. info->fix.line_length = mode->bytes_per_scan_line;
  1120. out:
  1121. kfree(crtc);
  1122. uvesafb_free(task);
  1123. return err;
  1124. }
  1125. static void uvesafb_check_limits(struct fb_var_screeninfo *var,
  1126. struct fb_info *info)
  1127. {
  1128. const struct fb_videomode *mode;
  1129. struct uvesafb_par *par = info->par;
  1130. /*
  1131. * If pixclock is set to 0, then we're using default BIOS timings
  1132. * and thus don't have to perform any checks here.
  1133. */
  1134. if (!var->pixclock)
  1135. return;
  1136. if (par->vbe_ib.vbe_version < 0x0300) {
  1137. fb_get_mode(FB_VSYNCTIMINGS | FB_IGNOREMON, 60, var, info);
  1138. return;
  1139. }
  1140. if (!fb_validate_mode(var, info))
  1141. return;
  1142. mode = fb_find_best_mode(var, &info->modelist);
  1143. if (mode) {
  1144. if (mode->xres == var->xres && mode->yres == var->yres &&
  1145. !(mode->vmode & (FB_VMODE_INTERLACED | FB_VMODE_DOUBLE))) {
  1146. fb_videomode_to_var(var, mode);
  1147. return;
  1148. }
  1149. }
  1150. if (info->monspecs.gtf && !fb_get_mode(FB_MAXTIMINGS, 0, var, info))
  1151. return;
  1152. /* Use default refresh rate */
  1153. var->pixclock = 0;
  1154. }
  1155. static int uvesafb_check_var(struct fb_var_screeninfo *var,
  1156. struct fb_info *info)
  1157. {
  1158. struct uvesafb_par *par = info->par;
  1159. struct vbe_mode_ib *mode = NULL;
  1160. int match = -1;
  1161. int depth = var->red.length + var->green.length + var->blue.length;
  1162. /*
  1163. * Various apps will use bits_per_pixel to set the color depth,
  1164. * which is theoretically incorrect, but which we'll try to handle
  1165. * here.
  1166. */
  1167. if (depth == 0 || abs(depth - var->bits_per_pixel) >= 8)
  1168. depth = var->bits_per_pixel;
  1169. match = uvesafb_vbe_find_mode(par, var->xres, var->yres, depth,
  1170. UVESAFB_EXACT_RES);
  1171. if (match == -1)
  1172. return -EINVAL;
  1173. mode = &par->vbe_modes[match];
  1174. uvesafb_setup_var(var, info, mode);
  1175. /*
  1176. * Check whether we have remapped enough memory for this mode.
  1177. * We might be called at an early stage, when we haven't remapped
  1178. * any memory yet, in which case we simply skip the check.
  1179. */
  1180. if (var->yres * mode->bytes_per_scan_line > info->fix.smem_len
  1181. && info->fix.smem_len)
  1182. return -EINVAL;
  1183. if ((var->vmode & FB_VMODE_DOUBLE) &&
  1184. !(par->vbe_modes[match].mode_attr & 0x100))
  1185. var->vmode &= ~FB_VMODE_DOUBLE;
  1186. if ((var->vmode & FB_VMODE_INTERLACED) &&
  1187. !(par->vbe_modes[match].mode_attr & 0x200))
  1188. var->vmode &= ~FB_VMODE_INTERLACED;
  1189. uvesafb_check_limits(var, info);
  1190. var->xres_virtual = var->xres;
  1191. var->yres_virtual = (par->ypan) ?
  1192. info->fix.smem_len / mode->bytes_per_scan_line :
  1193. var->yres;
  1194. return 0;
  1195. }
  1196. static struct fb_ops uvesafb_ops = {
  1197. .owner = THIS_MODULE,
  1198. .fb_open = uvesafb_open,
  1199. .fb_release = uvesafb_release,
  1200. FB_DEFAULT_IOMEM_OPS,
  1201. .fb_setcolreg = uvesafb_setcolreg,
  1202. .fb_setcmap = uvesafb_setcmap,
  1203. .fb_pan_display = uvesafb_pan_display,
  1204. .fb_blank = uvesafb_blank,
  1205. .fb_check_var = uvesafb_check_var,
  1206. .fb_set_par = uvesafb_set_par,
  1207. };
  1208. static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
  1209. {
  1210. unsigned int size_vmode;
  1211. unsigned int size_remap;
  1212. unsigned int size_total;
  1213. struct uvesafb_par *par = info->par;
  1214. int i, h;
  1215. info->pseudo_palette = ((u8 *)info->par + sizeof(struct uvesafb_par));
  1216. info->fix = uvesafb_fix;
  1217. info->fix.ypanstep = par->ypan ? 1 : 0;
  1218. info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
  1219. /* Disable blanking if the user requested so. */
  1220. if (!blank)
  1221. uvesafb_ops.fb_blank = NULL;
  1222. /*
  1223. * Find out how much IO memory is required for the mode with
  1224. * the highest resolution.
  1225. */
  1226. size_remap = 0;
  1227. for (i = 0; i < par->vbe_modes_cnt; i++) {
  1228. h = par->vbe_modes[i].bytes_per_scan_line *
  1229. par->vbe_modes[i].y_res;
  1230. if (h > size_remap)
  1231. size_remap = h;
  1232. }
  1233. size_remap *= 2;
  1234. /*
  1235. * size_vmode -- that is the amount of memory needed for the
  1236. * used video mode, i.e. the minimum amount of
  1237. * memory we need.
  1238. */
  1239. size_vmode = info->var.yres * mode->bytes_per_scan_line;
  1240. /*
  1241. * size_total -- all video memory we have. Used for mtrr
  1242. * entries, resource allocation and bounds
  1243. * checking.
  1244. */
  1245. size_total = par->vbe_ib.total_memory * 65536;
  1246. if (vram_total)
  1247. size_total = vram_total * 1024 * 1024;
  1248. if (size_total < size_vmode)
  1249. size_total = size_vmode;
  1250. /*
  1251. * size_remap -- the amount of video memory we are going to
  1252. * use for vesafb. With modern cards it is no
  1253. * option to simply use size_total as th
  1254. * wastes plenty of kernel address space.
  1255. */
  1256. if (vram_remap)
  1257. size_remap = vram_remap * 1024 * 1024;
  1258. if (size_remap < size_vmode)
  1259. size_remap = size_vmode;
  1260. if (size_remap > size_total)
  1261. size_remap = size_total;
  1262. info->fix.smem_len = size_remap;
  1263. info->fix.smem_start = mode->phys_base_ptr;
  1264. /*
  1265. * We have to set yres_virtual here because when setup_var() was
  1266. * called, smem_len wasn't defined yet.
  1267. */
  1268. info->var.yres_virtual = info->fix.smem_len /
  1269. mode->bytes_per_scan_line;
  1270. if (par->ypan && info->var.yres_virtual > info->var.yres) {
  1271. pr_info("scrolling: %s using protected mode interface, yres_virtual=%d\n",
  1272. (par->ypan > 1) ? "ywrap" : "ypan",
  1273. info->var.yres_virtual);
  1274. } else {
  1275. pr_info("scrolling: redraw\n");
  1276. info->var.yres_virtual = info->var.yres;
  1277. par->ypan = 0;
  1278. }
  1279. info->flags = (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
  1280. if (!par->ypan)
  1281. uvesafb_ops.fb_pan_display = NULL;
  1282. }
  1283. static void uvesafb_init_mtrr(struct fb_info *info)
  1284. {
  1285. struct uvesafb_par *par = info->par;
  1286. if (mtrr && !(info->fix.smem_start & (PAGE_SIZE - 1))) {
  1287. int temp_size = info->fix.smem_len;
  1288. int rc;
  1289. /* Find the largest power-of-two */
  1290. temp_size = roundup_pow_of_two(temp_size);
  1291. /* Try and find a power of two to add */
  1292. do {
  1293. rc = arch_phys_wc_add(info->fix.smem_start, temp_size);
  1294. temp_size >>= 1;
  1295. } while (temp_size >= PAGE_SIZE && rc == -EINVAL);
  1296. if (rc >= 0)
  1297. par->mtrr_handle = rc;
  1298. }
  1299. }
  1300. static void uvesafb_ioremap(struct fb_info *info)
  1301. {
  1302. info->screen_base = ioremap_wc(info->fix.smem_start, info->fix.smem_len);
  1303. }
  1304. static ssize_t uvesafb_show_vbe_ver(struct device *dev,
  1305. struct device_attribute *attr, char *buf)
  1306. {
  1307. struct fb_info *info = dev_get_drvdata(dev);
  1308. struct uvesafb_par *par = info->par;
  1309. return sysfs_emit(buf, "%.4x\n", par->vbe_ib.vbe_version);
  1310. }
  1311. static DEVICE_ATTR(vbe_version, S_IRUGO, uvesafb_show_vbe_ver, NULL);
  1312. static ssize_t uvesafb_show_vbe_modes(struct device *dev,
  1313. struct device_attribute *attr, char *buf)
  1314. {
  1315. struct fb_info *info = dev_get_drvdata(dev);
  1316. struct uvesafb_par *par = info->par;
  1317. int ret = 0, i;
  1318. for (i = 0; i < par->vbe_modes_cnt && ret < PAGE_SIZE; i++) {
  1319. ret += scnprintf(buf + ret, PAGE_SIZE - ret,
  1320. "%dx%d-%d, 0x%.4x\n",
  1321. par->vbe_modes[i].x_res, par->vbe_modes[i].y_res,
  1322. par->vbe_modes[i].depth, par->vbe_modes[i].mode_id);
  1323. }
  1324. return ret;
  1325. }
  1326. static DEVICE_ATTR(vbe_modes, S_IRUGO, uvesafb_show_vbe_modes, NULL);
  1327. static ssize_t uvesafb_show_vendor(struct device *dev,
  1328. struct device_attribute *attr, char *buf)
  1329. {
  1330. struct fb_info *info = dev_get_drvdata(dev);
  1331. struct uvesafb_par *par = info->par;
  1332. if (par->vbe_ib.oem_vendor_name_ptr)
  1333. return sysfs_emit(buf, "%s\n", (char *)
  1334. (&par->vbe_ib) + par->vbe_ib.oem_vendor_name_ptr);
  1335. else
  1336. return 0;
  1337. }
  1338. static DEVICE_ATTR(oem_vendor, S_IRUGO, uvesafb_show_vendor, NULL);
  1339. static ssize_t uvesafb_show_product_name(struct device *dev,
  1340. struct device_attribute *attr, char *buf)
  1341. {
  1342. struct fb_info *info = dev_get_drvdata(dev);
  1343. struct uvesafb_par *par = info->par;
  1344. if (par->vbe_ib.oem_product_name_ptr)
  1345. return sysfs_emit(buf, "%s\n", (char *)
  1346. (&par->vbe_ib) + par->vbe_ib.oem_product_name_ptr);
  1347. else
  1348. return 0;
  1349. }
  1350. static DEVICE_ATTR(oem_product_name, S_IRUGO, uvesafb_show_product_name, NULL);
  1351. static ssize_t uvesafb_show_product_rev(struct device *dev,
  1352. struct device_attribute *attr, char *buf)
  1353. {
  1354. struct fb_info *info = dev_get_drvdata(dev);
  1355. struct uvesafb_par *par = info->par;
  1356. if (par->vbe_ib.oem_product_rev_ptr)
  1357. return sysfs_emit(buf, "%s\n", (char *)
  1358. (&par->vbe_ib) + par->vbe_ib.oem_product_rev_ptr);
  1359. else
  1360. return 0;
  1361. }
  1362. static DEVICE_ATTR(oem_product_rev, S_IRUGO, uvesafb_show_product_rev, NULL);
  1363. static ssize_t uvesafb_show_oem_string(struct device *dev,
  1364. struct device_attribute *attr, char *buf)
  1365. {
  1366. struct fb_info *info = dev_get_drvdata(dev);
  1367. struct uvesafb_par *par = info->par;
  1368. if (par->vbe_ib.oem_string_ptr)
  1369. return sysfs_emit(buf, "%s\n",
  1370. (char *)(&par->vbe_ib) + par->vbe_ib.oem_string_ptr);
  1371. else
  1372. return 0;
  1373. }
  1374. static DEVICE_ATTR(oem_string, S_IRUGO, uvesafb_show_oem_string, NULL);
  1375. static ssize_t uvesafb_show_nocrtc(struct device *dev,
  1376. struct device_attribute *attr, char *buf)
  1377. {
  1378. struct fb_info *info = dev_get_drvdata(dev);
  1379. struct uvesafb_par *par = info->par;
  1380. return sysfs_emit(buf, "%d\n", par->nocrtc);
  1381. }
  1382. static ssize_t uvesafb_store_nocrtc(struct device *dev,
  1383. struct device_attribute *attr, const char *buf, size_t count)
  1384. {
  1385. struct fb_info *info = dev_get_drvdata(dev);
  1386. struct uvesafb_par *par = info->par;
  1387. if (count > 0) {
  1388. if (buf[0] == '0')
  1389. par->nocrtc = 0;
  1390. else
  1391. par->nocrtc = 1;
  1392. }
  1393. return count;
  1394. }
  1395. static DEVICE_ATTR(nocrtc, S_IRUGO | S_IWUSR, uvesafb_show_nocrtc,
  1396. uvesafb_store_nocrtc);
  1397. static struct attribute *uvesafb_dev_attrs[] = {
  1398. &dev_attr_vbe_version.attr,
  1399. &dev_attr_vbe_modes.attr,
  1400. &dev_attr_oem_vendor.attr,
  1401. &dev_attr_oem_product_name.attr,
  1402. &dev_attr_oem_product_rev.attr,
  1403. &dev_attr_oem_string.attr,
  1404. &dev_attr_nocrtc.attr,
  1405. NULL,
  1406. };
  1407. static const struct attribute_group uvesafb_dev_attgrp = {
  1408. .name = NULL,
  1409. .attrs = uvesafb_dev_attrs,
  1410. };
  1411. static int uvesafb_probe(struct platform_device *dev)
  1412. {
  1413. struct fb_info *info;
  1414. struct vbe_mode_ib *mode = NULL;
  1415. struct uvesafb_par *par;
  1416. int err = 0, i;
  1417. info = framebuffer_alloc(sizeof(*par) + sizeof(u32) * 256, &dev->dev);
  1418. if (!info)
  1419. return -ENOMEM;
  1420. par = info->par;
  1421. err = uvesafb_vbe_init(info);
  1422. if (err) {
  1423. pr_err("vbe_init() failed with %d\n", err);
  1424. goto out;
  1425. }
  1426. info->fbops = &uvesafb_ops;
  1427. i = uvesafb_vbe_init_mode(info);
  1428. if (i < 0) {
  1429. err = -EINVAL;
  1430. goto out;
  1431. } else {
  1432. mode = &par->vbe_modes[i];
  1433. }
  1434. if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
  1435. err = -ENXIO;
  1436. goto out;
  1437. }
  1438. uvesafb_init_info(info, mode);
  1439. if (!request_region(0x3c0, 32, "uvesafb")) {
  1440. pr_err("request region 0x3c0-0x3e0 failed\n");
  1441. err = -EIO;
  1442. goto out_mode;
  1443. }
  1444. if (!request_mem_region(info->fix.smem_start, info->fix.smem_len,
  1445. "uvesafb")) {
  1446. pr_err("cannot reserve video memory at 0x%lx\n",
  1447. info->fix.smem_start);
  1448. err = -EIO;
  1449. goto out_reg;
  1450. }
  1451. uvesafb_init_mtrr(info);
  1452. uvesafb_ioremap(info);
  1453. if (!info->screen_base) {
  1454. pr_err("abort, cannot ioremap 0x%x bytes of video memory at 0x%lx\n",
  1455. info->fix.smem_len, info->fix.smem_start);
  1456. err = -EIO;
  1457. goto out_mem;
  1458. }
  1459. platform_set_drvdata(dev, info);
  1460. if (register_framebuffer(info) < 0) {
  1461. pr_err("failed to register framebuffer device\n");
  1462. err = -EINVAL;
  1463. goto out_unmap;
  1464. }
  1465. pr_info("framebuffer at 0x%lx, mapped to 0x%p, using %dk, total %dk\n",
  1466. info->fix.smem_start, info->screen_base,
  1467. info->fix.smem_len / 1024, par->vbe_ib.total_memory * 64);
  1468. fb_info(info, "%s frame buffer device\n", info->fix.id);
  1469. err = sysfs_create_group(&dev->dev.kobj, &uvesafb_dev_attgrp);
  1470. if (err != 0)
  1471. fb_warn(info, "failed to register attributes\n");
  1472. return 0;
  1473. out_unmap:
  1474. iounmap(info->screen_base);
  1475. out_mem:
  1476. arch_phys_wc_del(par->mtrr_handle);
  1477. release_mem_region(info->fix.smem_start, info->fix.smem_len);
  1478. out_reg:
  1479. release_region(0x3c0, 32);
  1480. out_mode:
  1481. if (!list_empty(&info->modelist))
  1482. fb_destroy_modelist(&info->modelist);
  1483. fb_destroy_modedb(info->monspecs.modedb);
  1484. fb_dealloc_cmap(&info->cmap);
  1485. out:
  1486. kfree(par->vbe_modes);
  1487. framebuffer_release(info);
  1488. return err;
  1489. }
  1490. static void uvesafb_remove(struct platform_device *dev)
  1491. {
  1492. struct fb_info *info = platform_get_drvdata(dev);
  1493. struct uvesafb_par *par = info->par;
  1494. sysfs_remove_group(&dev->dev.kobj, &uvesafb_dev_attgrp);
  1495. unregister_framebuffer(info);
  1496. release_region(0x3c0, 32);
  1497. iounmap(info->screen_base);
  1498. arch_phys_wc_del(par->mtrr_handle);
  1499. release_mem_region(info->fix.smem_start, info->fix.smem_len);
  1500. fb_destroy_modedb(info->monspecs.modedb);
  1501. fb_dealloc_cmap(&info->cmap);
  1502. kfree(par->vbe_modes);
  1503. kfree(par->vbe_state_orig);
  1504. kfree(par->vbe_state_saved);
  1505. framebuffer_release(info);
  1506. }
  1507. static struct platform_driver uvesafb_driver = {
  1508. .probe = uvesafb_probe,
  1509. .remove = uvesafb_remove,
  1510. .driver = {
  1511. .name = "uvesafb",
  1512. },
  1513. };
  1514. static struct platform_device *uvesafb_device;
  1515. #ifndef MODULE
  1516. static int uvesafb_setup(char *options)
  1517. {
  1518. char *this_opt;
  1519. if (!options || !*options)
  1520. return 0;
  1521. while ((this_opt = strsep(&options, ",")) != NULL) {
  1522. if (!*this_opt) continue;
  1523. if (!strcmp(this_opt, "redraw"))
  1524. ypan = 0;
  1525. else if (!strcmp(this_opt, "ypan"))
  1526. ypan = 1;
  1527. else if (!strcmp(this_opt, "ywrap"))
  1528. ypan = 2;
  1529. else if (!strcmp(this_opt, "vgapal"))
  1530. pmi_setpal = false;
  1531. else if (!strcmp(this_opt, "pmipal"))
  1532. pmi_setpal = true;
  1533. else if (!strncmp(this_opt, "mtrr:", 5))
  1534. mtrr = simple_strtoul(this_opt+5, NULL, 0);
  1535. else if (!strcmp(this_opt, "nomtrr"))
  1536. mtrr = 0;
  1537. else if (!strcmp(this_opt, "nocrtc"))
  1538. nocrtc = true;
  1539. else if (!strcmp(this_opt, "noedid"))
  1540. noedid = true;
  1541. else if (!strcmp(this_opt, "noblank"))
  1542. blank = false;
  1543. else if (!strncmp(this_opt, "vtotal:", 7))
  1544. vram_total = simple_strtoul(this_opt + 7, NULL, 0);
  1545. else if (!strncmp(this_opt, "vremap:", 7))
  1546. vram_remap = simple_strtoul(this_opt + 7, NULL, 0);
  1547. else if (!strncmp(this_opt, "maxhf:", 6))
  1548. maxhf = simple_strtoul(this_opt + 6, NULL, 0);
  1549. else if (!strncmp(this_opt, "maxvf:", 6))
  1550. maxvf = simple_strtoul(this_opt + 6, NULL, 0);
  1551. else if (!strncmp(this_opt, "maxclk:", 7))
  1552. maxclk = simple_strtoul(this_opt + 7, NULL, 0);
  1553. else if (!strncmp(this_opt, "vbemode:", 8))
  1554. vbemode = simple_strtoul(this_opt + 8, NULL, 0);
  1555. else if (this_opt[0] >= '0' && this_opt[0] <= '9') {
  1556. mode_option = this_opt;
  1557. } else {
  1558. pr_warn("unrecognized option %s\n", this_opt);
  1559. }
  1560. }
  1561. if (mtrr != 3 && mtrr != 0)
  1562. pr_warn("uvesafb: mtrr should be set to 0 or 3; %d is unsupported", mtrr);
  1563. return 0;
  1564. }
  1565. #endif /* !MODULE */
  1566. static ssize_t v86d_show(struct device_driver *dev, char *buf)
  1567. {
  1568. return snprintf(buf, PAGE_SIZE, "%s\n", v86d_path);
  1569. }
  1570. static ssize_t v86d_store(struct device_driver *dev, const char *buf,
  1571. size_t count)
  1572. {
  1573. strscpy_pad(v86d_path, buf);
  1574. return count;
  1575. }
  1576. static DRIVER_ATTR_RW(v86d);
  1577. static int uvesafb_init(void)
  1578. {
  1579. int err;
  1580. #ifndef MODULE
  1581. char *option = NULL;
  1582. if (fb_get_options("uvesafb", &option))
  1583. return -ENODEV;
  1584. uvesafb_setup(option);
  1585. #endif
  1586. err = cn_add_callback(&uvesafb_cn_id, "uvesafb", uvesafb_cn_callback);
  1587. if (err)
  1588. return err;
  1589. err = platform_driver_register(&uvesafb_driver);
  1590. if (!err) {
  1591. uvesafb_device = platform_device_alloc("uvesafb", 0);
  1592. if (uvesafb_device)
  1593. err = platform_device_add(uvesafb_device);
  1594. else
  1595. err = -ENOMEM;
  1596. if (err) {
  1597. platform_device_put(uvesafb_device);
  1598. platform_driver_unregister(&uvesafb_driver);
  1599. cn_del_callback(&uvesafb_cn_id);
  1600. return err;
  1601. }
  1602. err = driver_create_file(&uvesafb_driver.driver,
  1603. &driver_attr_v86d);
  1604. if (err) {
  1605. pr_warn("failed to register attributes\n");
  1606. err = 0;
  1607. }
  1608. }
  1609. return err;
  1610. }
  1611. module_init(uvesafb_init);
  1612. static void uvesafb_exit(void)
  1613. {
  1614. struct uvesafb_ktask *task;
  1615. if (v86d_started) {
  1616. task = uvesafb_prep();
  1617. if (task) {
  1618. task->t.flags = TF_EXIT;
  1619. uvesafb_exec(task);
  1620. uvesafb_free(task);
  1621. }
  1622. }
  1623. driver_remove_file(&uvesafb_driver.driver, &driver_attr_v86d);
  1624. platform_device_unregister(uvesafb_device);
  1625. platform_driver_unregister(&uvesafb_driver);
  1626. cn_del_callback(&uvesafb_cn_id);
  1627. }
  1628. module_exit(uvesafb_exit);
  1629. static int param_set_scroll(const char *val, const struct kernel_param *kp)
  1630. {
  1631. ypan = 0;
  1632. if (!strcmp(val, "redraw"))
  1633. ypan = 0;
  1634. else if (!strcmp(val, "ypan"))
  1635. ypan = 1;
  1636. else if (!strcmp(val, "ywrap"))
  1637. ypan = 2;
  1638. else
  1639. return -EINVAL;
  1640. return 0;
  1641. }
  1642. static const struct kernel_param_ops param_ops_scroll = {
  1643. .set = param_set_scroll,
  1644. };
  1645. #define param_check_scroll(name, p) __param_check(name, p, void)
  1646. module_param_named(scroll, ypan, scroll, 0);
  1647. MODULE_PARM_DESC(scroll,
  1648. "Scrolling mode, set to 'redraw', 'ypan', or 'ywrap'");
  1649. module_param_named(vgapal, pmi_setpal, invbool, 0);
  1650. MODULE_PARM_DESC(vgapal, "Set palette using VGA registers");
  1651. module_param_named(pmipal, pmi_setpal, bool, 0);
  1652. MODULE_PARM_DESC(pmipal, "Set palette using PMI calls");
  1653. module_param(mtrr, uint, 0);
  1654. MODULE_PARM_DESC(mtrr,
  1655. "Memory Type Range Registers setting. Use 0 to disable.");
  1656. module_param(blank, bool, 0);
  1657. MODULE_PARM_DESC(blank, "Enable hardware blanking");
  1658. module_param(nocrtc, bool, 0);
  1659. MODULE_PARM_DESC(nocrtc, "Ignore CRTC timings when setting modes");
  1660. module_param(noedid, bool, 0);
  1661. MODULE_PARM_DESC(noedid,
  1662. "Ignore EDID-provided monitor limits when setting modes");
  1663. module_param(vram_remap, uint, 0);
  1664. MODULE_PARM_DESC(vram_remap, "Set amount of video memory to be used [MiB]");
  1665. module_param(vram_total, uint, 0);
  1666. MODULE_PARM_DESC(vram_total, "Set total amount of video memory [MiB]");
  1667. module_param(maxclk, ushort, 0);
  1668. MODULE_PARM_DESC(maxclk, "Maximum pixelclock [MHz], overrides EDID data");
  1669. module_param(maxhf, ushort, 0);
  1670. MODULE_PARM_DESC(maxhf,
  1671. "Maximum horizontal frequency [kHz], overrides EDID data");
  1672. module_param(maxvf, ushort, 0);
  1673. MODULE_PARM_DESC(maxvf,
  1674. "Maximum vertical frequency [Hz], overrides EDID data");
  1675. module_param(mode_option, charp, 0);
  1676. MODULE_PARM_DESC(mode_option,
  1677. "Specify initial video mode as \"<xres>x<yres>[-<bpp>][@<refresh>]\"");
  1678. module_param(vbemode, ushort, 0);
  1679. MODULE_PARM_DESC(vbemode,
  1680. "VBE mode number to set, overrides the 'mode' option");
  1681. module_param_string(v86d, v86d_path, PATH_MAX, 0660);
  1682. MODULE_PARM_DESC(v86d, "Path to the v86d userspace helper.");
  1683. MODULE_LICENSE("GPL");
  1684. MODULE_AUTHOR("Michal Januszewski <spock@gentoo.org>");
  1685. MODULE_DESCRIPTION("Framebuffer driver for VBE2.0+ compliant graphics boards");