uvesafb.c 50 KB

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