uvesafb.c 51 KB

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