uvesafb.c 51 KB

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