uvesafb.c 50 KB

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