uvesafb.c 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077
  1. /*
  2. * A framebuffer driver for VBE 2.0+ compliant video cards
  3. *
  4. * (c) 2007 Michal Januszewski <spock@gentoo.org>
  5. * Loosely based upon the vesafb driver.
  6. *
  7. */
  8. #include <linux/init.h>
  9. #include <linux/module.h>
  10. #include <linux/moduleparam.h>
  11. #include <linux/skbuff.h>
  12. #include <linux/timer.h>
  13. #include <linux/completion.h>
  14. #include <linux/connector.h>
  15. #include <linux/random.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/limits.h>
  18. #include <linux/fb.h>
  19. #include <linux/io.h>
  20. #include <linux/mutex.h>
  21. #include <linux/slab.h>
  22. #include <video/edid.h>
  23. #include <video/uvesafb.h>
  24. #ifdef CONFIG_X86
  25. #include <video/vga.h>
  26. #endif
  27. #ifdef CONFIG_MTRR
  28. #include <asm/mtrr.h>
  29. #endif
  30. #include "edid.h"
  31. static struct cb_id uvesafb_cn_id = {
  32. .idx = CN_IDX_V86D,
  33. .val = CN_VAL_V86D_UVESAFB
  34. };
  35. static char v86d_path[PATH_MAX] = "/sbin/v86d";
  36. static char v86d_started; /* has v86d been started by uvesafb? */
  37. static struct fb_fix_screeninfo uvesafb_fix = {
  38. .id = "VESA VGA",
  39. .type = FB_TYPE_PACKED_PIXELS,
  40. .accel = FB_ACCEL_NONE,
  41. .visual = FB_VISUAL_TRUECOLOR,
  42. };
  43. static int mtrr = 3; /* enable mtrr by default */
  44. static bool blank = 1; /* enable blanking by default */
  45. static int ypan = 1; /* 0: scroll, 1: ypan, 2: ywrap */
  46. static bool pmi_setpal = true; /* use PMI for palette changes */
  47. static bool nocrtc; /* ignore CRTC settings */
  48. static bool noedid; /* don't try DDC transfers */
  49. static int vram_remap; /* set amt. of memory to be used */
  50. static int vram_total; /* set total amount of memory */
  51. static u16 maxclk; /* maximum pixel clock */
  52. static u16 maxvf; /* maximum vertical frequency */
  53. static u16 maxhf; /* maximum horizontal frequency */
  54. static u16 vbemode; /* force use of a specific VBE mode */
  55. static char *mode_option;
  56. static u8 dac_width = 6;
  57. static struct uvesafb_ktask *uvfb_tasks[UVESAFB_TASKS_MAX];
  58. static DEFINE_MUTEX(uvfb_lock);
  59. /*
  60. * A handler for replies from userspace.
  61. *
  62. * Make sure each message passes consistency checks and if it does,
  63. * find the kernel part of the task struct, copy the registers and
  64. * the buffer contents and then complete the task.
  65. */
  66. static void uvesafb_cn_callback(struct cn_msg *msg, struct netlink_skb_parms *nsp)
  67. {
  68. struct uvesafb_task *utask;
  69. struct uvesafb_ktask *task;
  70. if (!capable(CAP_SYS_ADMIN))
  71. return;
  72. if (msg->seq >= UVESAFB_TASKS_MAX)
  73. return;
  74. mutex_lock(&uvfb_lock);
  75. task = uvfb_tasks[msg->seq];
  76. if (!task || msg->ack != task->ack) {
  77. mutex_unlock(&uvfb_lock);
  78. return;
  79. }
  80. utask = (struct uvesafb_task *)msg->data;
  81. /* Sanity checks for the buffer length. */
  82. if (task->t.buf_len < utask->buf_len ||
  83. utask->buf_len > msg->len - sizeof(*utask)) {
  84. mutex_unlock(&uvfb_lock);
  85. return;
  86. }
  87. uvfb_tasks[msg->seq] = NULL;
  88. mutex_unlock(&uvfb_lock);
  89. memcpy(&task->t, utask, sizeof(*utask));
  90. if (task->t.buf_len && task->buf)
  91. memcpy(task->buf, utask + 1, task->t.buf_len);
  92. complete(task->done);
  93. return;
  94. }
  95. static int uvesafb_helper_start(void)
  96. {
  97. char *envp[] = {
  98. "HOME=/",
  99. "PATH=/sbin:/bin",
  100. NULL,
  101. };
  102. char *argv[] = {
  103. v86d_path,
  104. NULL,
  105. };
  106. return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
  107. }
  108. /*
  109. * Execute a uvesafb task.
  110. *
  111. * Returns 0 if the task is executed successfully.
  112. *
  113. * A message sent to the userspace consists of the uvesafb_task
  114. * struct and (optionally) a buffer. The uvesafb_task struct is
  115. * a simplified version of uvesafb_ktask (its kernel counterpart)
  116. * containing only the register values, flags and the length of
  117. * the buffer.
  118. *
  119. * Each message is assigned a sequence number (increased linearly)
  120. * and a random ack number. The sequence number is used as a key
  121. * for the uvfb_tasks array which holds pointers to uvesafb_ktask
  122. * structs for all requests.
  123. */
  124. static int uvesafb_exec(struct uvesafb_ktask *task)
  125. {
  126. static int seq;
  127. struct cn_msg *m;
  128. int err;
  129. int len = sizeof(task->t) + task->t.buf_len;
  130. /*
  131. * Check whether the message isn't longer than the maximum
  132. * allowed by connector.
  133. */
  134. if (sizeof(*m) + len > CONNECTOR_MAX_MSG_SIZE) {
  135. printk(KERN_WARNING "uvesafb: message too long (%d), "
  136. "can't execute task\n", (int)(sizeof(*m) + len));
  137. return -E2BIG;
  138. }
  139. m = kzalloc(sizeof(*m) + len, GFP_KERNEL);
  140. if (!m)
  141. return -ENOMEM;
  142. init_completion(task->done);
  143. memcpy(&m->id, &uvesafb_cn_id, sizeof(m->id));
  144. m->seq = seq;
  145. m->len = len;
  146. m->ack = random32();
  147. /* uvesafb_task structure */
  148. memcpy(m + 1, &task->t, sizeof(task->t));
  149. /* Buffer */
  150. memcpy((u8 *)(m + 1) + sizeof(task->t), task->buf, task->t.buf_len);
  151. /*
  152. * Save the message ack number so that we can find the kernel
  153. * part of this task when a reply is received from userspace.
  154. */
  155. task->ack = m->ack;
  156. mutex_lock(&uvfb_lock);
  157. /* If all slots are taken -- bail out. */
  158. if (uvfb_tasks[seq]) {
  159. mutex_unlock(&uvfb_lock);
  160. err = -EBUSY;
  161. goto out;
  162. }
  163. /* Save a pointer to the kernel part of the task struct. */
  164. uvfb_tasks[seq] = task;
  165. mutex_unlock(&uvfb_lock);
  166. err = cn_netlink_send(m, 0, GFP_KERNEL);
  167. if (err == -ESRCH) {
  168. /*
  169. * Try to start the userspace helper if sending
  170. * the request failed the first time.
  171. */
  172. err = uvesafb_helper_start();
  173. if (err) {
  174. printk(KERN_ERR "uvesafb: failed to execute %s\n",
  175. v86d_path);
  176. printk(KERN_ERR "uvesafb: make sure that the v86d "
  177. "helper is installed and executable\n");
  178. } else {
  179. v86d_started = 1;
  180. err = cn_netlink_send(m, 0, gfp_any());
  181. if (err == -ENOBUFS)
  182. err = 0;
  183. }
  184. } else if (err == -ENOBUFS)
  185. err = 0;
  186. if (!err && !(task->t.flags & TF_EXIT))
  187. err = !wait_for_completion_timeout(task->done,
  188. msecs_to_jiffies(UVESAFB_TIMEOUT));
  189. mutex_lock(&uvfb_lock);
  190. uvfb_tasks[seq] = NULL;
  191. mutex_unlock(&uvfb_lock);
  192. seq++;
  193. if (seq >= UVESAFB_TASKS_MAX)
  194. seq = 0;
  195. out:
  196. kfree(m);
  197. return err;
  198. }
  199. /*
  200. * Free a uvesafb_ktask struct.
  201. */
  202. static void uvesafb_free(struct uvesafb_ktask *task)
  203. {
  204. if (task) {
  205. if (task->done)
  206. kfree(task->done);
  207. kfree(task);
  208. }
  209. }
  210. /*
  211. * Prepare a uvesafb_ktask struct to be used again.
  212. */
  213. static void uvesafb_reset(struct uvesafb_ktask *task)
  214. {
  215. struct completion *cpl = task->done;
  216. memset(task, 0, sizeof(*task));
  217. task->done = cpl;
  218. }
  219. /*
  220. * Allocate and prepare a uvesafb_ktask struct.
  221. */
  222. static struct uvesafb_ktask *uvesafb_prep(void)
  223. {
  224. struct uvesafb_ktask *task;
  225. task = kzalloc(sizeof(*task), GFP_KERNEL);
  226. if (task) {
  227. task->done = kzalloc(sizeof(*task->done), GFP_KERNEL);
  228. if (!task->done) {
  229. kfree(task);
  230. task = NULL;
  231. }
  232. }
  233. return task;
  234. }
  235. static void uvesafb_setup_var(struct fb_var_screeninfo *var,
  236. struct fb_info *info, struct vbe_mode_ib *mode)
  237. {
  238. struct uvesafb_par *par = info->par;
  239. var->vmode = FB_VMODE_NONINTERLACED;
  240. var->sync = FB_SYNC_VERT_HIGH_ACT;
  241. var->xres = mode->x_res;
  242. var->yres = mode->y_res;
  243. var->xres_virtual = mode->x_res;
  244. var->yres_virtual = (par->ypan) ?
  245. info->fix.smem_len / mode->bytes_per_scan_line :
  246. mode->y_res;
  247. var->xoffset = 0;
  248. var->yoffset = 0;
  249. var->bits_per_pixel = mode->bits_per_pixel;
  250. if (var->bits_per_pixel == 15)
  251. var->bits_per_pixel = 16;
  252. if (var->bits_per_pixel > 8) {
  253. var->red.offset = mode->red_off;
  254. var->red.length = mode->red_len;
  255. var->green.offset = mode->green_off;
  256. var->green.length = mode->green_len;
  257. var->blue.offset = mode->blue_off;
  258. var->blue.length = mode->blue_len;
  259. var->transp.offset = mode->rsvd_off;
  260. var->transp.length = mode->rsvd_len;
  261. } else {
  262. var->red.offset = 0;
  263. var->green.offset = 0;
  264. var->blue.offset = 0;
  265. var->transp.offset = 0;
  266. var->red.length = 8;
  267. var->green.length = 8;
  268. var->blue.length = 8;
  269. var->transp.length = 0;
  270. }
  271. }
  272. static int uvesafb_vbe_find_mode(struct uvesafb_par *par,
  273. int xres, int yres, int depth, unsigned char flags)
  274. {
  275. int i, match = -1, h = 0, d = 0x7fffffff;
  276. for (i = 0; i < par->vbe_modes_cnt; i++) {
  277. h = abs(par->vbe_modes[i].x_res - xres) +
  278. abs(par->vbe_modes[i].y_res - yres) +
  279. abs(depth - par->vbe_modes[i].depth);
  280. /*
  281. * We have an exact match in terms of resolution
  282. * and depth.
  283. */
  284. if (h == 0)
  285. return i;
  286. if (h < d || (h == d && par->vbe_modes[i].depth > depth)) {
  287. d = h;
  288. match = i;
  289. }
  290. }
  291. i = 1;
  292. if (flags & UVESAFB_EXACT_DEPTH &&
  293. par->vbe_modes[match].depth != depth)
  294. i = 0;
  295. if (flags & UVESAFB_EXACT_RES && d > 24)
  296. i = 0;
  297. if (i != 0)
  298. return match;
  299. else
  300. return -1;
  301. }
  302. static u8 *uvesafb_vbe_state_save(struct uvesafb_par *par)
  303. {
  304. struct uvesafb_ktask *task;
  305. u8 *state;
  306. int err;
  307. if (!par->vbe_state_size)
  308. return NULL;
  309. state = kmalloc(par->vbe_state_size, GFP_KERNEL);
  310. if (!state)
  311. return ERR_PTR(-ENOMEM);
  312. task = uvesafb_prep();
  313. if (!task) {
  314. kfree(state);
  315. return NULL;
  316. }
  317. task->t.regs.eax = 0x4f04;
  318. task->t.regs.ecx = 0x000f;
  319. task->t.regs.edx = 0x0001;
  320. task->t.flags = TF_BUF_RET | TF_BUF_ESBX;
  321. task->t.buf_len = par->vbe_state_size;
  322. task->buf = state;
  323. err = uvesafb_exec(task);
  324. if (err || (task->t.regs.eax & 0xffff) != 0x004f) {
  325. printk(KERN_WARNING "uvesafb: VBE get state call "
  326. "failed (eax=0x%x, err=%d)\n",
  327. task->t.regs.eax, err);
  328. kfree(state);
  329. state = NULL;
  330. }
  331. uvesafb_free(task);
  332. return state;
  333. }
  334. static void uvesafb_vbe_state_restore(struct uvesafb_par *par, u8 *state_buf)
  335. {
  336. struct uvesafb_ktask *task;
  337. int err;
  338. if (!state_buf)
  339. return;
  340. task = uvesafb_prep();
  341. if (!task)
  342. return;
  343. task->t.regs.eax = 0x4f04;
  344. task->t.regs.ecx = 0x000f;
  345. task->t.regs.edx = 0x0002;
  346. task->t.buf_len = par->vbe_state_size;
  347. task->t.flags = TF_BUF_ESBX;
  348. task->buf = state_buf;
  349. err = uvesafb_exec(task);
  350. if (err || (task->t.regs.eax & 0xffff) != 0x004f)
  351. printk(KERN_WARNING "uvesafb: VBE state restore call "
  352. "failed (eax=0x%x, err=%d)\n",
  353. task->t.regs.eax, err);
  354. uvesafb_free(task);
  355. }
  356. static int uvesafb_vbe_getinfo(struct uvesafb_ktask *task,
  357. struct uvesafb_par *par)
  358. {
  359. int err;
  360. task->t.regs.eax = 0x4f00;
  361. task->t.flags = TF_VBEIB;
  362. task->t.buf_len = sizeof(struct vbe_ib);
  363. task->buf = &par->vbe_ib;
  364. strncpy(par->vbe_ib.vbe_signature, "VBE2", 4);
  365. err = uvesafb_exec(task);
  366. if (err || (task->t.regs.eax & 0xffff) != 0x004f) {
  367. printk(KERN_ERR "uvesafb: Getting VBE info block failed "
  368. "(eax=0x%x, err=%d)\n", (u32)task->t.regs.eax,
  369. err);
  370. return -EINVAL;
  371. }
  372. if (par->vbe_ib.vbe_version < 0x0200) {
  373. printk(KERN_ERR "uvesafb: Sorry, pre-VBE 2.0 cards are "
  374. "not supported.\n");
  375. return -EINVAL;
  376. }
  377. if (!par->vbe_ib.mode_list_ptr) {
  378. printk(KERN_ERR "uvesafb: Missing mode list!\n");
  379. return -EINVAL;
  380. }
  381. printk(KERN_INFO "uvesafb: ");
  382. /*
  383. * Convert string pointers and the mode list pointer into
  384. * usable addresses. Print informational messages about the
  385. * video adapter and its vendor.
  386. */
  387. if (par->vbe_ib.oem_vendor_name_ptr)
  388. printk("%s, ",
  389. ((char *)task->buf) + par->vbe_ib.oem_vendor_name_ptr);
  390. if (par->vbe_ib.oem_product_name_ptr)
  391. printk("%s, ",
  392. ((char *)task->buf) + par->vbe_ib.oem_product_name_ptr);
  393. if (par->vbe_ib.oem_product_rev_ptr)
  394. printk("%s, ",
  395. ((char *)task->buf) + par->vbe_ib.oem_product_rev_ptr);
  396. if (par->vbe_ib.oem_string_ptr)
  397. printk("OEM: %s, ",
  398. ((char *)task->buf) + par->vbe_ib.oem_string_ptr);
  399. printk("VBE v%d.%d\n", ((par->vbe_ib.vbe_version & 0xff00) >> 8),
  400. par->vbe_ib.vbe_version & 0xff);
  401. return 0;
  402. }
  403. static int uvesafb_vbe_getmodes(struct uvesafb_ktask *task,
  404. struct uvesafb_par *par)
  405. {
  406. int off = 0, err;
  407. u16 *mode;
  408. par->vbe_modes_cnt = 0;
  409. /* Count available modes. */
  410. mode = (u16 *) (((u8 *)&par->vbe_ib) + par->vbe_ib.mode_list_ptr);
  411. while (*mode != 0xffff) {
  412. par->vbe_modes_cnt++;
  413. mode++;
  414. }
  415. par->vbe_modes = kzalloc(sizeof(struct vbe_mode_ib) *
  416. par->vbe_modes_cnt, GFP_KERNEL);
  417. if (!par->vbe_modes)
  418. return -ENOMEM;
  419. /* Get info about all available modes. */
  420. mode = (u16 *) (((u8 *)&par->vbe_ib) + par->vbe_ib.mode_list_ptr);
  421. while (*mode != 0xffff) {
  422. struct vbe_mode_ib *mib;
  423. uvesafb_reset(task);
  424. task->t.regs.eax = 0x4f01;
  425. task->t.regs.ecx = (u32) *mode;
  426. task->t.flags = TF_BUF_RET | TF_BUF_ESDI;
  427. task->t.buf_len = sizeof(struct vbe_mode_ib);
  428. task->buf = par->vbe_modes + off;
  429. err = uvesafb_exec(task);
  430. if (err || (task->t.regs.eax & 0xffff) != 0x004f) {
  431. printk(KERN_WARNING "uvesafb: Getting mode info block "
  432. "for mode 0x%x failed (eax=0x%x, err=%d)\n",
  433. *mode, (u32)task->t.regs.eax, err);
  434. mode++;
  435. par->vbe_modes_cnt--;
  436. continue;
  437. }
  438. mib = task->buf;
  439. mib->mode_id = *mode;
  440. /*
  441. * We only want modes that are supported with the current
  442. * hardware configuration, color, graphics and that have
  443. * support for the LFB.
  444. */
  445. if ((mib->mode_attr & VBE_MODE_MASK) == VBE_MODE_MASK &&
  446. mib->bits_per_pixel >= 8)
  447. off++;
  448. else
  449. par->vbe_modes_cnt--;
  450. mode++;
  451. mib->depth = mib->red_len + mib->green_len + mib->blue_len;
  452. /*
  453. * Handle 8bpp modes and modes with broken color component
  454. * lengths.
  455. */
  456. if (mib->depth == 0 || (mib->depth == 24 &&
  457. mib->bits_per_pixel == 32))
  458. mib->depth = mib->bits_per_pixel;
  459. }
  460. if (par->vbe_modes_cnt > 0)
  461. return 0;
  462. else
  463. return -EINVAL;
  464. }
  465. /*
  466. * The Protected Mode Interface is 32-bit x86 code, so we only run it on
  467. * x86 and not x86_64.
  468. */
  469. #ifdef CONFIG_X86_32
  470. static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
  471. struct uvesafb_par *par)
  472. {
  473. int i, err;
  474. uvesafb_reset(task);
  475. task->t.regs.eax = 0x4f0a;
  476. task->t.regs.ebx = 0x0;
  477. err = uvesafb_exec(task);
  478. if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
  479. par->pmi_setpal = par->ypan = 0;
  480. } else {
  481. par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
  482. + task->t.regs.edi);
  483. par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
  484. par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
  485. printk(KERN_INFO "uvesafb: protected mode interface info at "
  486. "%04x:%04x\n",
  487. (u16)task->t.regs.es, (u16)task->t.regs.edi);
  488. printk(KERN_INFO "uvesafb: pmi: set display start = %p, "
  489. "set palette = %p\n", par->pmi_start,
  490. par->pmi_pal);
  491. if (par->pmi_base[3]) {
  492. printk(KERN_INFO "uvesafb: pmi: ports = ");
  493. for (i = par->pmi_base[3]/2;
  494. par->pmi_base[i] != 0xffff; i++)
  495. printk("%x ", par->pmi_base[i]);
  496. printk("\n");
  497. if (par->pmi_base[i] != 0xffff) {
  498. printk(KERN_INFO "uvesafb: can't handle memory"
  499. " requests, pmi disabled\n");
  500. par->ypan = par->pmi_setpal = 0;
  501. }
  502. }
  503. }
  504. return 0;
  505. }
  506. #endif /* CONFIG_X86_32 */
  507. /*
  508. * Check whether a video mode is supported by the Video BIOS and is
  509. * compatible with the monitor limits.
  510. */
  511. static int uvesafb_is_valid_mode(struct fb_videomode *mode,
  512. struct fb_info *info)
  513. {
  514. if (info->monspecs.gtf) {
  515. fb_videomode_to_var(&info->var, mode);
  516. if (fb_validate_mode(&info->var, info))
  517. return 0;
  518. }
  519. if (uvesafb_vbe_find_mode(info->par, mode->xres, mode->yres, 8,
  520. UVESAFB_EXACT_RES) == -1)
  521. return 0;
  522. return 1;
  523. }
  524. static int uvesafb_vbe_getedid(struct uvesafb_ktask *task, struct fb_info *info)
  525. {
  526. struct uvesafb_par *par = info->par;
  527. int err = 0;
  528. if (noedid || par->vbe_ib.vbe_version < 0x0300)
  529. return -EINVAL;
  530. task->t.regs.eax = 0x4f15;
  531. task->t.regs.ebx = 0;
  532. task->t.regs.ecx = 0;
  533. task->t.buf_len = 0;
  534. task->t.flags = 0;
  535. err = uvesafb_exec(task);
  536. if ((task->t.regs.eax & 0xffff) != 0x004f || err)
  537. return -EINVAL;
  538. if ((task->t.regs.ebx & 0x3) == 3) {
  539. printk(KERN_INFO "uvesafb: VBIOS/hardware supports both "
  540. "DDC1 and DDC2 transfers\n");
  541. } else if ((task->t.regs.ebx & 0x3) == 2) {
  542. printk(KERN_INFO "uvesafb: VBIOS/hardware supports DDC2 "
  543. "transfers\n");
  544. } else if ((task->t.regs.ebx & 0x3) == 1) {
  545. printk(KERN_INFO "uvesafb: VBIOS/hardware supports DDC1 "
  546. "transfers\n");
  547. } else {
  548. printk(KERN_INFO "uvesafb: VBIOS/hardware doesn't support "
  549. "DDC transfers\n");
  550. return -EINVAL;
  551. }
  552. task->t.regs.eax = 0x4f15;
  553. task->t.regs.ebx = 1;
  554. task->t.regs.ecx = task->t.regs.edx = 0;
  555. task->t.flags = TF_BUF_RET | TF_BUF_ESDI;
  556. task->t.buf_len = EDID_LENGTH;
  557. task->buf = kzalloc(EDID_LENGTH, GFP_KERNEL);
  558. if (!task->buf)
  559. return -ENOMEM;
  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 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 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 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 (__supported_pte_mask & _PAGE_NX) {
  689. par->pmi_setpal = par->ypan = 0;
  690. printk(KERN_WARNING "uvesafb: NX protection is actively."
  691. "We have better not to use the PMI.\n");
  692. } else {
  693. uvesafb_vbe_getpmi(task, par);
  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 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 uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
  1232. {
  1233. unsigned int size_vmode;
  1234. unsigned int size_remap;
  1235. unsigned int size_total;
  1236. struct uvesafb_par *par = info->par;
  1237. int i, h;
  1238. info->pseudo_palette = ((u8 *)info->par + sizeof(struct uvesafb_par));
  1239. info->fix = uvesafb_fix;
  1240. info->fix.ypanstep = par->ypan ? 1 : 0;
  1241. info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
  1242. /* Disable blanking if the user requested so. */
  1243. if (!blank)
  1244. info->fbops->fb_blank = NULL;
  1245. /*
  1246. * Find out how much IO memory is required for the mode with
  1247. * the highest resolution.
  1248. */
  1249. size_remap = 0;
  1250. for (i = 0; i < par->vbe_modes_cnt; i++) {
  1251. h = par->vbe_modes[i].bytes_per_scan_line *
  1252. par->vbe_modes[i].y_res;
  1253. if (h > size_remap)
  1254. size_remap = h;
  1255. }
  1256. size_remap *= 2;
  1257. /*
  1258. * size_vmode -- that is the amount of memory needed for the
  1259. * used video mode, i.e. the minimum amount of
  1260. * memory we need.
  1261. */
  1262. if (mode != NULL) {
  1263. size_vmode = info->var.yres * mode->bytes_per_scan_line;
  1264. } else {
  1265. size_vmode = info->var.yres * info->var.xres *
  1266. ((info->var.bits_per_pixel + 7) >> 3);
  1267. }
  1268. /*
  1269. * size_total -- all video memory we have. Used for mtrr
  1270. * entries, resource allocation and bounds
  1271. * checking.
  1272. */
  1273. size_total = par->vbe_ib.total_memory * 65536;
  1274. if (vram_total)
  1275. size_total = vram_total * 1024 * 1024;
  1276. if (size_total < size_vmode)
  1277. size_total = size_vmode;
  1278. /*
  1279. * size_remap -- the amount of video memory we are going to
  1280. * use for vesafb. With modern cards it is no
  1281. * option to simply use size_total as th
  1282. * wastes plenty of kernel address space.
  1283. */
  1284. if (vram_remap)
  1285. size_remap = vram_remap * 1024 * 1024;
  1286. if (size_remap < size_vmode)
  1287. size_remap = size_vmode;
  1288. if (size_remap > size_total)
  1289. size_remap = size_total;
  1290. info->fix.smem_len = size_remap;
  1291. info->fix.smem_start = mode->phys_base_ptr;
  1292. /*
  1293. * We have to set yres_virtual here because when setup_var() was
  1294. * called, smem_len wasn't defined yet.
  1295. */
  1296. info->var.yres_virtual = info->fix.smem_len /
  1297. mode->bytes_per_scan_line;
  1298. if (par->ypan && info->var.yres_virtual > info->var.yres) {
  1299. printk(KERN_INFO "uvesafb: scrolling: %s "
  1300. "using protected mode interface, "
  1301. "yres_virtual=%d\n",
  1302. (par->ypan > 1) ? "ywrap" : "ypan",
  1303. info->var.yres_virtual);
  1304. } else {
  1305. printk(KERN_INFO "uvesafb: scrolling: redraw\n");
  1306. info->var.yres_virtual = info->var.yres;
  1307. par->ypan = 0;
  1308. }
  1309. info->flags = FBINFO_FLAG_DEFAULT |
  1310. (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
  1311. if (!par->ypan)
  1312. info->fbops->fb_pan_display = NULL;
  1313. }
  1314. static void uvesafb_init_mtrr(struct fb_info *info)
  1315. {
  1316. #ifdef CONFIG_MTRR
  1317. if (mtrr && !(info->fix.smem_start & (PAGE_SIZE - 1))) {
  1318. int temp_size = info->fix.smem_len;
  1319. unsigned int type = 0;
  1320. switch (mtrr) {
  1321. case 1:
  1322. type = MTRR_TYPE_UNCACHABLE;
  1323. break;
  1324. case 2:
  1325. type = MTRR_TYPE_WRBACK;
  1326. break;
  1327. case 3:
  1328. type = MTRR_TYPE_WRCOMB;
  1329. break;
  1330. case 4:
  1331. type = MTRR_TYPE_WRTHROUGH;
  1332. break;
  1333. default:
  1334. type = 0;
  1335. break;
  1336. }
  1337. if (type) {
  1338. int rc;
  1339. /* Find the largest power-of-two */
  1340. temp_size = roundup_pow_of_two(temp_size);
  1341. /* Try and find a power of two to add */
  1342. do {
  1343. rc = mtrr_add(info->fix.smem_start,
  1344. temp_size, type, 1);
  1345. temp_size >>= 1;
  1346. } while (temp_size >= PAGE_SIZE && rc == -EINVAL);
  1347. }
  1348. }
  1349. #endif /* CONFIG_MTRR */
  1350. }
  1351. static void uvesafb_ioremap(struct fb_info *info)
  1352. {
  1353. #ifdef CONFIG_X86
  1354. switch (mtrr) {
  1355. case 1: /* uncachable */
  1356. info->screen_base = ioremap_nocache(info->fix.smem_start, info->fix.smem_len);
  1357. break;
  1358. case 2: /* write-back */
  1359. info->screen_base = ioremap_cache(info->fix.smem_start, info->fix.smem_len);
  1360. break;
  1361. case 3: /* write-combining */
  1362. info->screen_base = ioremap_wc(info->fix.smem_start, info->fix.smem_len);
  1363. break;
  1364. case 4: /* write-through */
  1365. default:
  1366. info->screen_base = ioremap(info->fix.smem_start, info->fix.smem_len);
  1367. break;
  1368. }
  1369. #else
  1370. info->screen_base = ioremap(info->fix.smem_start, info->fix.smem_len);
  1371. #endif /* CONFIG_X86 */
  1372. }
  1373. static ssize_t uvesafb_show_vbe_ver(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. return snprintf(buf, PAGE_SIZE, "%.4x\n", par->vbe_ib.vbe_version);
  1379. }
  1380. static DEVICE_ATTR(vbe_version, S_IRUGO, uvesafb_show_vbe_ver, NULL);
  1381. static ssize_t uvesafb_show_vbe_modes(struct device *dev,
  1382. struct device_attribute *attr, char *buf)
  1383. {
  1384. struct fb_info *info = platform_get_drvdata(to_platform_device(dev));
  1385. struct uvesafb_par *par = info->par;
  1386. int ret = 0, i;
  1387. for (i = 0; i < par->vbe_modes_cnt && ret < PAGE_SIZE; i++) {
  1388. ret += snprintf(buf + ret, PAGE_SIZE - ret,
  1389. "%dx%d-%d, 0x%.4x\n",
  1390. par->vbe_modes[i].x_res, par->vbe_modes[i].y_res,
  1391. par->vbe_modes[i].depth, par->vbe_modes[i].mode_id);
  1392. }
  1393. return ret;
  1394. }
  1395. static DEVICE_ATTR(vbe_modes, S_IRUGO, uvesafb_show_vbe_modes, NULL);
  1396. static ssize_t uvesafb_show_vendor(struct device *dev,
  1397. struct device_attribute *attr, char *buf)
  1398. {
  1399. struct fb_info *info = platform_get_drvdata(to_platform_device(dev));
  1400. struct uvesafb_par *par = info->par;
  1401. if (par->vbe_ib.oem_vendor_name_ptr)
  1402. return snprintf(buf, PAGE_SIZE, "%s\n", (char *)
  1403. (&par->vbe_ib) + par->vbe_ib.oem_vendor_name_ptr);
  1404. else
  1405. return 0;
  1406. }
  1407. static DEVICE_ATTR(oem_vendor, S_IRUGO, uvesafb_show_vendor, NULL);
  1408. static ssize_t uvesafb_show_product_name(struct device *dev,
  1409. struct device_attribute *attr, char *buf)
  1410. {
  1411. struct fb_info *info = platform_get_drvdata(to_platform_device(dev));
  1412. struct uvesafb_par *par = info->par;
  1413. if (par->vbe_ib.oem_product_name_ptr)
  1414. return snprintf(buf, PAGE_SIZE, "%s\n", (char *)
  1415. (&par->vbe_ib) + par->vbe_ib.oem_product_name_ptr);
  1416. else
  1417. return 0;
  1418. }
  1419. static DEVICE_ATTR(oem_product_name, S_IRUGO, uvesafb_show_product_name, NULL);
  1420. static ssize_t uvesafb_show_product_rev(struct device *dev,
  1421. struct device_attribute *attr, char *buf)
  1422. {
  1423. struct fb_info *info = platform_get_drvdata(to_platform_device(dev));
  1424. struct uvesafb_par *par = info->par;
  1425. if (par->vbe_ib.oem_product_rev_ptr)
  1426. return snprintf(buf, PAGE_SIZE, "%s\n", (char *)
  1427. (&par->vbe_ib) + par->vbe_ib.oem_product_rev_ptr);
  1428. else
  1429. return 0;
  1430. }
  1431. static DEVICE_ATTR(oem_product_rev, S_IRUGO, uvesafb_show_product_rev, NULL);
  1432. static ssize_t uvesafb_show_oem_string(struct device *dev,
  1433. struct device_attribute *attr, char *buf)
  1434. {
  1435. struct fb_info *info = platform_get_drvdata(to_platform_device(dev));
  1436. struct uvesafb_par *par = info->par;
  1437. if (par->vbe_ib.oem_string_ptr)
  1438. return snprintf(buf, PAGE_SIZE, "%s\n",
  1439. (char *)(&par->vbe_ib) + par->vbe_ib.oem_string_ptr);
  1440. else
  1441. return 0;
  1442. }
  1443. static DEVICE_ATTR(oem_string, S_IRUGO, uvesafb_show_oem_string, NULL);
  1444. static ssize_t uvesafb_show_nocrtc(struct device *dev,
  1445. struct device_attribute *attr, char *buf)
  1446. {
  1447. struct fb_info *info = platform_get_drvdata(to_platform_device(dev));
  1448. struct uvesafb_par *par = info->par;
  1449. return snprintf(buf, PAGE_SIZE, "%d\n", par->nocrtc);
  1450. }
  1451. static ssize_t uvesafb_store_nocrtc(struct device *dev,
  1452. struct device_attribute *attr, const char *buf, size_t count)
  1453. {
  1454. struct fb_info *info = platform_get_drvdata(to_platform_device(dev));
  1455. struct uvesafb_par *par = info->par;
  1456. if (count > 0) {
  1457. if (buf[0] == '0')
  1458. par->nocrtc = 0;
  1459. else
  1460. par->nocrtc = 1;
  1461. }
  1462. return count;
  1463. }
  1464. static DEVICE_ATTR(nocrtc, S_IRUGO | S_IWUSR, uvesafb_show_nocrtc,
  1465. uvesafb_store_nocrtc);
  1466. static struct attribute *uvesafb_dev_attrs[] = {
  1467. &dev_attr_vbe_version.attr,
  1468. &dev_attr_vbe_modes.attr,
  1469. &dev_attr_oem_vendor.attr,
  1470. &dev_attr_oem_product_name.attr,
  1471. &dev_attr_oem_product_rev.attr,
  1472. &dev_attr_oem_string.attr,
  1473. &dev_attr_nocrtc.attr,
  1474. NULL,
  1475. };
  1476. static struct attribute_group uvesafb_dev_attgrp = {
  1477. .name = NULL,
  1478. .attrs = uvesafb_dev_attrs,
  1479. };
  1480. static int uvesafb_probe(struct platform_device *dev)
  1481. {
  1482. struct fb_info *info;
  1483. struct vbe_mode_ib *mode = NULL;
  1484. struct uvesafb_par *par;
  1485. int err = 0, i;
  1486. info = framebuffer_alloc(sizeof(*par) + sizeof(u32) * 256, &dev->dev);
  1487. if (!info)
  1488. return -ENOMEM;
  1489. par = info->par;
  1490. err = uvesafb_vbe_init(info);
  1491. if (err) {
  1492. printk(KERN_ERR "uvesafb: vbe_init() failed with %d\n", err);
  1493. goto out;
  1494. }
  1495. info->fbops = &uvesafb_ops;
  1496. i = uvesafb_vbe_init_mode(info);
  1497. if (i < 0) {
  1498. err = -EINVAL;
  1499. goto out;
  1500. } else {
  1501. mode = &par->vbe_modes[i];
  1502. }
  1503. if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
  1504. err = -ENXIO;
  1505. goto out;
  1506. }
  1507. uvesafb_init_info(info, mode);
  1508. if (!request_region(0x3c0, 32, "uvesafb")) {
  1509. printk(KERN_ERR "uvesafb: request region 0x3c0-0x3e0 failed\n");
  1510. err = -EIO;
  1511. goto out_mode;
  1512. }
  1513. if (!request_mem_region(info->fix.smem_start, info->fix.smem_len,
  1514. "uvesafb")) {
  1515. printk(KERN_ERR "uvesafb: cannot reserve video memory at "
  1516. "0x%lx\n", info->fix.smem_start);
  1517. err = -EIO;
  1518. goto out_reg;
  1519. }
  1520. uvesafb_init_mtrr(info);
  1521. uvesafb_ioremap(info);
  1522. if (!info->screen_base) {
  1523. printk(KERN_ERR
  1524. "uvesafb: abort, cannot ioremap 0x%x bytes of video "
  1525. "memory at 0x%lx\n",
  1526. info->fix.smem_len, info->fix.smem_start);
  1527. err = -EIO;
  1528. goto out_mem;
  1529. }
  1530. platform_set_drvdata(dev, info);
  1531. if (register_framebuffer(info) < 0) {
  1532. printk(KERN_ERR
  1533. "uvesafb: failed to register framebuffer device\n");
  1534. err = -EINVAL;
  1535. goto out_unmap;
  1536. }
  1537. printk(KERN_INFO "uvesafb: framebuffer at 0x%lx, mapped to 0x%p, "
  1538. "using %dk, total %dk\n", info->fix.smem_start,
  1539. info->screen_base, info->fix.smem_len/1024,
  1540. par->vbe_ib.total_memory * 64);
  1541. printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node,
  1542. info->fix.id);
  1543. err = sysfs_create_group(&dev->dev.kobj, &uvesafb_dev_attgrp);
  1544. if (err != 0)
  1545. printk(KERN_WARNING "fb%d: failed to register attributes\n",
  1546. info->node);
  1547. return 0;
  1548. out_unmap:
  1549. iounmap(info->screen_base);
  1550. out_mem:
  1551. release_mem_region(info->fix.smem_start, info->fix.smem_len);
  1552. out_reg:
  1553. release_region(0x3c0, 32);
  1554. out_mode:
  1555. if (!list_empty(&info->modelist))
  1556. fb_destroy_modelist(&info->modelist);
  1557. fb_destroy_modedb(info->monspecs.modedb);
  1558. fb_dealloc_cmap(&info->cmap);
  1559. out:
  1560. if (par->vbe_modes)
  1561. kfree(par->vbe_modes);
  1562. framebuffer_release(info);
  1563. return err;
  1564. }
  1565. static int uvesafb_remove(struct platform_device *dev)
  1566. {
  1567. struct fb_info *info = platform_get_drvdata(dev);
  1568. if (info) {
  1569. struct uvesafb_par *par = info->par;
  1570. sysfs_remove_group(&dev->dev.kobj, &uvesafb_dev_attgrp);
  1571. unregister_framebuffer(info);
  1572. release_region(0x3c0, 32);
  1573. iounmap(info->screen_base);
  1574. release_mem_region(info->fix.smem_start, info->fix.smem_len);
  1575. fb_destroy_modedb(info->monspecs.modedb);
  1576. fb_dealloc_cmap(&info->cmap);
  1577. if (par) {
  1578. if (par->vbe_modes)
  1579. kfree(par->vbe_modes);
  1580. if (par->vbe_state_orig)
  1581. kfree(par->vbe_state_orig);
  1582. if (par->vbe_state_saved)
  1583. kfree(par->vbe_state_saved);
  1584. }
  1585. framebuffer_release(info);
  1586. }
  1587. return 0;
  1588. }
  1589. static struct platform_driver uvesafb_driver = {
  1590. .probe = uvesafb_probe,
  1591. .remove = uvesafb_remove,
  1592. .driver = {
  1593. .name = "uvesafb",
  1594. },
  1595. };
  1596. static struct platform_device *uvesafb_device;
  1597. #ifndef MODULE
  1598. static int uvesafb_setup(char *options)
  1599. {
  1600. char *this_opt;
  1601. if (!options || !*options)
  1602. return 0;
  1603. while ((this_opt = strsep(&options, ",")) != NULL) {
  1604. if (!*this_opt) continue;
  1605. if (!strcmp(this_opt, "redraw"))
  1606. ypan = 0;
  1607. else if (!strcmp(this_opt, "ypan"))
  1608. ypan = 1;
  1609. else if (!strcmp(this_opt, "ywrap"))
  1610. ypan = 2;
  1611. else if (!strcmp(this_opt, "vgapal"))
  1612. pmi_setpal = 0;
  1613. else if (!strcmp(this_opt, "pmipal"))
  1614. pmi_setpal = 1;
  1615. else if (!strncmp(this_opt, "mtrr:", 5))
  1616. mtrr = simple_strtoul(this_opt+5, NULL, 0);
  1617. else if (!strcmp(this_opt, "nomtrr"))
  1618. mtrr = 0;
  1619. else if (!strcmp(this_opt, "nocrtc"))
  1620. nocrtc = 1;
  1621. else if (!strcmp(this_opt, "noedid"))
  1622. noedid = 1;
  1623. else if (!strcmp(this_opt, "noblank"))
  1624. blank = 0;
  1625. else if (!strncmp(this_opt, "vtotal:", 7))
  1626. vram_total = simple_strtoul(this_opt + 7, NULL, 0);
  1627. else if (!strncmp(this_opt, "vremap:", 7))
  1628. vram_remap = simple_strtoul(this_opt + 7, NULL, 0);
  1629. else if (!strncmp(this_opt, "maxhf:", 6))
  1630. maxhf = simple_strtoul(this_opt + 6, NULL, 0);
  1631. else if (!strncmp(this_opt, "maxvf:", 6))
  1632. maxvf = simple_strtoul(this_opt + 6, NULL, 0);
  1633. else if (!strncmp(this_opt, "maxclk:", 7))
  1634. maxclk = simple_strtoul(this_opt + 7, NULL, 0);
  1635. else if (!strncmp(this_opt, "vbemode:", 8))
  1636. vbemode = simple_strtoul(this_opt + 8, NULL, 0);
  1637. else if (this_opt[0] >= '0' && this_opt[0] <= '9') {
  1638. mode_option = this_opt;
  1639. } else {
  1640. printk(KERN_WARNING
  1641. "uvesafb: unrecognized option %s\n", this_opt);
  1642. }
  1643. }
  1644. return 0;
  1645. }
  1646. #endif /* !MODULE */
  1647. static ssize_t show_v86d(struct device_driver *dev, char *buf)
  1648. {
  1649. return snprintf(buf, PAGE_SIZE, "%s\n", v86d_path);
  1650. }
  1651. static ssize_t store_v86d(struct device_driver *dev, const char *buf,
  1652. size_t count)
  1653. {
  1654. strncpy(v86d_path, buf, PATH_MAX);
  1655. return count;
  1656. }
  1657. static DRIVER_ATTR(v86d, S_IRUGO | S_IWUSR, show_v86d, store_v86d);
  1658. static int uvesafb_init(void)
  1659. {
  1660. int err;
  1661. #ifndef MODULE
  1662. char *option = NULL;
  1663. if (fb_get_options("uvesafb", &option))
  1664. return -ENODEV;
  1665. uvesafb_setup(option);
  1666. #endif
  1667. err = cn_add_callback(&uvesafb_cn_id, "uvesafb", uvesafb_cn_callback);
  1668. if (err)
  1669. return err;
  1670. err = platform_driver_register(&uvesafb_driver);
  1671. if (!err) {
  1672. uvesafb_device = platform_device_alloc("uvesafb", 0);
  1673. if (uvesafb_device)
  1674. err = platform_device_add(uvesafb_device);
  1675. else
  1676. err = -ENOMEM;
  1677. if (err) {
  1678. platform_device_put(uvesafb_device);
  1679. platform_driver_unregister(&uvesafb_driver);
  1680. cn_del_callback(&uvesafb_cn_id);
  1681. return err;
  1682. }
  1683. err = driver_create_file(&uvesafb_driver.driver,
  1684. &driver_attr_v86d);
  1685. if (err) {
  1686. printk(KERN_WARNING "uvesafb: failed to register "
  1687. "attributes\n");
  1688. err = 0;
  1689. }
  1690. }
  1691. return err;
  1692. }
  1693. module_init(uvesafb_init);
  1694. static void uvesafb_exit(void)
  1695. {
  1696. struct uvesafb_ktask *task;
  1697. if (v86d_started) {
  1698. task = uvesafb_prep();
  1699. if (task) {
  1700. task->t.flags = TF_EXIT;
  1701. uvesafb_exec(task);
  1702. uvesafb_free(task);
  1703. }
  1704. }
  1705. cn_del_callback(&uvesafb_cn_id);
  1706. driver_remove_file(&uvesafb_driver.driver, &driver_attr_v86d);
  1707. platform_device_unregister(uvesafb_device);
  1708. platform_driver_unregister(&uvesafb_driver);
  1709. }
  1710. module_exit(uvesafb_exit);
  1711. static int param_set_scroll(const char *val, const struct kernel_param *kp)
  1712. {
  1713. ypan = 0;
  1714. if (!strcmp(val, "redraw"))
  1715. ypan = 0;
  1716. else if (!strcmp(val, "ypan"))
  1717. ypan = 1;
  1718. else if (!strcmp(val, "ywrap"))
  1719. ypan = 2;
  1720. else
  1721. return -EINVAL;
  1722. return 0;
  1723. }
  1724. static struct kernel_param_ops param_ops_scroll = {
  1725. .set = param_set_scroll,
  1726. };
  1727. #define param_check_scroll(name, p) __param_check(name, p, void)
  1728. module_param_named(scroll, ypan, scroll, 0);
  1729. MODULE_PARM_DESC(scroll,
  1730. "Scrolling mode, set to 'redraw', 'ypan', or 'ywrap'");
  1731. module_param_named(vgapal, pmi_setpal, invbool, 0);
  1732. MODULE_PARM_DESC(vgapal, "Set palette using VGA registers");
  1733. module_param_named(pmipal, pmi_setpal, bool, 0);
  1734. MODULE_PARM_DESC(pmipal, "Set palette using PMI calls");
  1735. module_param(mtrr, uint, 0);
  1736. MODULE_PARM_DESC(mtrr,
  1737. "Memory Type Range Registers setting. Use 0 to disable.");
  1738. module_param(blank, bool, 0);
  1739. MODULE_PARM_DESC(blank, "Enable hardware blanking");
  1740. module_param(nocrtc, bool, 0);
  1741. MODULE_PARM_DESC(nocrtc, "Ignore CRTC timings when setting modes");
  1742. module_param(noedid, bool, 0);
  1743. MODULE_PARM_DESC(noedid,
  1744. "Ignore EDID-provided monitor limits when setting modes");
  1745. module_param(vram_remap, uint, 0);
  1746. MODULE_PARM_DESC(vram_remap, "Set amount of video memory to be used [MiB]");
  1747. module_param(vram_total, uint, 0);
  1748. MODULE_PARM_DESC(vram_total, "Set total amount of video memoery [MiB]");
  1749. module_param(maxclk, ushort, 0);
  1750. MODULE_PARM_DESC(maxclk, "Maximum pixelclock [MHz], overrides EDID data");
  1751. module_param(maxhf, ushort, 0);
  1752. MODULE_PARM_DESC(maxhf,
  1753. "Maximum horizontal frequency [kHz], overrides EDID data");
  1754. module_param(maxvf, ushort, 0);
  1755. MODULE_PARM_DESC(maxvf,
  1756. "Maximum vertical frequency [Hz], overrides EDID data");
  1757. module_param(mode_option, charp, 0);
  1758. MODULE_PARM_DESC(mode_option,
  1759. "Specify initial video mode as \"<xres>x<yres>[-<bpp>][@<refresh>]\"");
  1760. module_param(vbemode, ushort, 0);
  1761. MODULE_PARM_DESC(vbemode,
  1762. "VBE mode number to set, overrides the 'mode' option");
  1763. module_param_string(v86d, v86d_path, PATH_MAX, 0660);
  1764. MODULE_PARM_DESC(v86d, "Path to the v86d userspace helper.");
  1765. MODULE_LICENSE("GPL");
  1766. MODULE_AUTHOR("Michal Januszewski <spock@gentoo.org>");
  1767. MODULE_DESCRIPTION("Framebuffer driver for VBE2.0+ compliant graphics boards");