uvesafb.c 51 KB

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