uvesafb.c 49 KB

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