uvesafb.c 50 KB

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