uvesafb.c 51 KB

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