uvesafb.c 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079
  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 __devinitdata = {
  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 __devinitdata = 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 __devinitdata = true; /* use PMI for palette changes */
  47. static bool nocrtc __devinitdata; /* ignore CRTC settings */
  48. static bool noedid __devinitdata; /* don't try DDC transfers */
  49. static int vram_remap __devinitdata; /* set amt. of memory to be used */
  50. static int vram_total __devinitdata; /* set total amount of memory */
  51. static u16 maxclk __devinitdata; /* maximum pixel clock */
  52. static u16 maxvf __devinitdata; /* maximum vertical frequency */
  53. static u16 maxhf __devinitdata; /* maximum horizontal frequency */
  54. static u16 vbemode __devinitdata; /* force use of a specific VBE mode */
  55. static char *mode_option __devinitdata;
  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 __devinit 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 __devinit 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 __devinit 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 __devinit 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 __devinit uvesafb_vbe_getedid(struct uvesafb_ktask *task,
  525. struct fb_info *info)
  526. {
  527. struct uvesafb_par *par = info->par;
  528. int err = 0;
  529. if (noedid || par->vbe_ib.vbe_version < 0x0300)
  530. return -EINVAL;
  531. task->t.regs.eax = 0x4f15;
  532. task->t.regs.ebx = 0;
  533. task->t.regs.ecx = 0;
  534. task->t.buf_len = 0;
  535. task->t.flags = 0;
  536. err = uvesafb_exec(task);
  537. if ((task->t.regs.eax & 0xffff) != 0x004f || err)
  538. return -EINVAL;
  539. if ((task->t.regs.ebx & 0x3) == 3) {
  540. printk(KERN_INFO "uvesafb: VBIOS/hardware supports both "
  541. "DDC1 and DDC2 transfers\n");
  542. } else if ((task->t.regs.ebx & 0x3) == 2) {
  543. printk(KERN_INFO "uvesafb: VBIOS/hardware supports DDC2 "
  544. "transfers\n");
  545. } else if ((task->t.regs.ebx & 0x3) == 1) {
  546. printk(KERN_INFO "uvesafb: VBIOS/hardware supports DDC1 "
  547. "transfers\n");
  548. } else {
  549. printk(KERN_INFO "uvesafb: VBIOS/hardware doesn't support "
  550. "DDC transfers\n");
  551. return -EINVAL;
  552. }
  553. task->t.regs.eax = 0x4f15;
  554. task->t.regs.ebx = 1;
  555. task->t.regs.ecx = task->t.regs.edx = 0;
  556. task->t.flags = TF_BUF_RET | TF_BUF_ESDI;
  557. task->t.buf_len = EDID_LENGTH;
  558. task->buf = kzalloc(EDID_LENGTH, GFP_KERNEL);
  559. if (!task->buf)
  560. return -ENOMEM;
  561. err = uvesafb_exec(task);
  562. if ((task->t.regs.eax & 0xffff) == 0x004f && !err) {
  563. fb_edid_to_monspecs(task->buf, &info->monspecs);
  564. if (info->monspecs.vfmax && info->monspecs.hfmax) {
  565. /*
  566. * If the maximum pixel clock wasn't specified in
  567. * the EDID block, set it to 300 MHz.
  568. */
  569. if (info->monspecs.dclkmax == 0)
  570. info->monspecs.dclkmax = 300 * 1000000;
  571. info->monspecs.gtf = 1;
  572. }
  573. } else {
  574. err = -EINVAL;
  575. }
  576. kfree(task->buf);
  577. return err;
  578. }
  579. static void __devinit uvesafb_vbe_getmonspecs(struct uvesafb_ktask *task,
  580. struct fb_info *info)
  581. {
  582. struct uvesafb_par *par = info->par;
  583. int i;
  584. memset(&info->monspecs, 0, sizeof(info->monspecs));
  585. /*
  586. * If we don't get all necessary data from the EDID block,
  587. * mark it as incompatible with the GTF and set nocrtc so
  588. * that we always use the default BIOS refresh rate.
  589. */
  590. if (uvesafb_vbe_getedid(task, info)) {
  591. info->monspecs.gtf = 0;
  592. par->nocrtc = 1;
  593. }
  594. /* Kernel command line overrides. */
  595. if (maxclk)
  596. info->monspecs.dclkmax = maxclk * 1000000;
  597. if (maxvf)
  598. info->monspecs.vfmax = maxvf;
  599. if (maxhf)
  600. info->monspecs.hfmax = maxhf * 1000;
  601. /*
  602. * In case DDC transfers are not supported, the user can provide
  603. * monitor limits manually. Lower limits are set to "safe" values.
  604. */
  605. if (info->monspecs.gtf == 0 && maxclk && maxvf && maxhf) {
  606. info->monspecs.dclkmin = 0;
  607. info->monspecs.vfmin = 60;
  608. info->monspecs.hfmin = 29000;
  609. info->monspecs.gtf = 1;
  610. par->nocrtc = 0;
  611. }
  612. if (info->monspecs.gtf)
  613. printk(KERN_INFO
  614. "uvesafb: monitor limits: vf = %d Hz, hf = %d kHz, "
  615. "clk = %d MHz\n", info->monspecs.vfmax,
  616. (int)(info->monspecs.hfmax / 1000),
  617. (int)(info->monspecs.dclkmax / 1000000));
  618. else
  619. printk(KERN_INFO "uvesafb: no monitor limits have been set, "
  620. "default refresh rate will be used\n");
  621. /* Add VBE modes to the modelist. */
  622. for (i = 0; i < par->vbe_modes_cnt; i++) {
  623. struct fb_var_screeninfo var;
  624. struct vbe_mode_ib *mode;
  625. struct fb_videomode vmode;
  626. mode = &par->vbe_modes[i];
  627. memset(&var, 0, sizeof(var));
  628. var.xres = mode->x_res;
  629. var.yres = mode->y_res;
  630. fb_get_mode(FB_VSYNCTIMINGS | FB_IGNOREMON, 60, &var, info);
  631. fb_var_to_videomode(&vmode, &var);
  632. fb_add_videomode(&vmode, &info->modelist);
  633. }
  634. /* Add valid VESA modes to our modelist. */
  635. for (i = 0; i < VESA_MODEDB_SIZE; i++) {
  636. if (uvesafb_is_valid_mode((struct fb_videomode *)
  637. &vesa_modes[i], info))
  638. fb_add_videomode(&vesa_modes[i], &info->modelist);
  639. }
  640. for (i = 0; i < info->monspecs.modedb_len; i++) {
  641. if (uvesafb_is_valid_mode(&info->monspecs.modedb[i], info))
  642. fb_add_videomode(&info->monspecs.modedb[i],
  643. &info->modelist);
  644. }
  645. return;
  646. }
  647. static void __devinit uvesafb_vbe_getstatesize(struct uvesafb_ktask *task,
  648. struct uvesafb_par *par)
  649. {
  650. int err;
  651. uvesafb_reset(task);
  652. /*
  653. * Get the VBE state buffer size. We want all available
  654. * hardware state data (CL = 0x0f).
  655. */
  656. task->t.regs.eax = 0x4f04;
  657. task->t.regs.ecx = 0x000f;
  658. task->t.regs.edx = 0x0000;
  659. task->t.flags = 0;
  660. err = uvesafb_exec(task);
  661. if (err || (task->t.regs.eax & 0xffff) != 0x004f) {
  662. printk(KERN_WARNING "uvesafb: VBE state buffer size "
  663. "cannot be determined (eax=0x%x, err=%d)\n",
  664. task->t.regs.eax, err);
  665. par->vbe_state_size = 0;
  666. return;
  667. }
  668. par->vbe_state_size = 64 * (task->t.regs.ebx & 0xffff);
  669. }
  670. static int __devinit uvesafb_vbe_init(struct fb_info *info)
  671. {
  672. struct uvesafb_ktask *task = NULL;
  673. struct uvesafb_par *par = info->par;
  674. int err;
  675. task = uvesafb_prep();
  676. if (!task)
  677. return -ENOMEM;
  678. err = uvesafb_vbe_getinfo(task, par);
  679. if (err)
  680. goto out;
  681. err = uvesafb_vbe_getmodes(task, par);
  682. if (err)
  683. goto out;
  684. par->nocrtc = nocrtc;
  685. #ifdef CONFIG_X86_32
  686. par->pmi_setpal = pmi_setpal;
  687. par->ypan = ypan;
  688. if (par->pmi_setpal || par->ypan) {
  689. if (__supported_pte_mask & _PAGE_NX) {
  690. par->pmi_setpal = par->ypan = 0;
  691. printk(KERN_WARNING "uvesafb: NX protection is actively."
  692. "We have better not to use the PMI.\n");
  693. } else {
  694. uvesafb_vbe_getpmi(task, par);
  695. }
  696. }
  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 - dac_width;
  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 - dac_width;
  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. u8 *buf = NULL;
  1010. if (!cnt && par->vbe_state_size) {
  1011. buf = uvesafb_vbe_state_save(par);
  1012. if (IS_ERR(buf)) {
  1013. printk(KERN_WARNING "uvesafb: save hardware state"
  1014. "failed, error code is %ld!\n", PTR_ERR(buf));
  1015. } else {
  1016. par->vbe_state_orig = buf;
  1017. }
  1018. }
  1019. atomic_inc(&par->ref_count);
  1020. return 0;
  1021. }
  1022. static int uvesafb_release(struct fb_info *info, int user)
  1023. {
  1024. struct uvesafb_ktask *task = NULL;
  1025. struct uvesafb_par *par = info->par;
  1026. int cnt = atomic_read(&par->ref_count);
  1027. if (!cnt)
  1028. return -EINVAL;
  1029. if (cnt != 1)
  1030. goto out;
  1031. task = uvesafb_prep();
  1032. if (!task)
  1033. goto out;
  1034. /* First, try to set the standard 80x25 text mode. */
  1035. task->t.regs.eax = 0x0003;
  1036. uvesafb_exec(task);
  1037. /*
  1038. * Now try to restore whatever hardware state we might have
  1039. * saved when the fb device was first opened.
  1040. */
  1041. uvesafb_vbe_state_restore(par, par->vbe_state_orig);
  1042. out:
  1043. atomic_dec(&par->ref_count);
  1044. if (task)
  1045. uvesafb_free(task);
  1046. return 0;
  1047. }
  1048. static int uvesafb_set_par(struct fb_info *info)
  1049. {
  1050. struct uvesafb_par *par = info->par;
  1051. struct uvesafb_ktask *task = NULL;
  1052. struct vbe_crtc_ib *crtc = NULL;
  1053. struct vbe_mode_ib *mode = NULL;
  1054. int i, err = 0, depth = info->var.bits_per_pixel;
  1055. if (depth > 8 && depth != 32)
  1056. depth = info->var.red.length + info->var.green.length +
  1057. info->var.blue.length;
  1058. i = uvesafb_vbe_find_mode(par, info->var.xres, info->var.yres, depth,
  1059. UVESAFB_EXACT_RES | UVESAFB_EXACT_DEPTH);
  1060. if (i >= 0)
  1061. mode = &par->vbe_modes[i];
  1062. else
  1063. return -EINVAL;
  1064. task = uvesafb_prep();
  1065. if (!task)
  1066. return -ENOMEM;
  1067. setmode:
  1068. task->t.regs.eax = 0x4f02;
  1069. task->t.regs.ebx = mode->mode_id | 0x4000; /* use LFB */
  1070. if (par->vbe_ib.vbe_version >= 0x0300 && !par->nocrtc &&
  1071. info->var.pixclock != 0) {
  1072. task->t.regs.ebx |= 0x0800; /* use CRTC data */
  1073. task->t.flags = TF_BUF_ESDI;
  1074. crtc = kzalloc(sizeof(struct vbe_crtc_ib), GFP_KERNEL);
  1075. if (!crtc) {
  1076. err = -ENOMEM;
  1077. goto out;
  1078. }
  1079. crtc->horiz_start = info->var.xres + info->var.right_margin;
  1080. crtc->horiz_end = crtc->horiz_start + info->var.hsync_len;
  1081. crtc->horiz_total = crtc->horiz_end + info->var.left_margin;
  1082. crtc->vert_start = info->var.yres + info->var.lower_margin;
  1083. crtc->vert_end = crtc->vert_start + info->var.vsync_len;
  1084. crtc->vert_total = crtc->vert_end + info->var.upper_margin;
  1085. crtc->pixel_clock = PICOS2KHZ(info->var.pixclock) * 1000;
  1086. crtc->refresh_rate = (u16)(100 * (crtc->pixel_clock /
  1087. (crtc->vert_total * crtc->horiz_total)));
  1088. if (info->var.vmode & FB_VMODE_DOUBLE)
  1089. crtc->flags |= 0x1;
  1090. if (info->var.vmode & FB_VMODE_INTERLACED)
  1091. crtc->flags |= 0x2;
  1092. if (!(info->var.sync & FB_SYNC_HOR_HIGH_ACT))
  1093. crtc->flags |= 0x4;
  1094. if (!(info->var.sync & FB_SYNC_VERT_HIGH_ACT))
  1095. crtc->flags |= 0x8;
  1096. memcpy(&par->crtc, crtc, sizeof(*crtc));
  1097. } else {
  1098. memset(&par->crtc, 0, sizeof(*crtc));
  1099. }
  1100. task->t.buf_len = sizeof(struct vbe_crtc_ib);
  1101. task->buf = &par->crtc;
  1102. err = uvesafb_exec(task);
  1103. if (err || (task->t.regs.eax & 0xffff) != 0x004f) {
  1104. /*
  1105. * The mode switch might have failed because we tried to
  1106. * use our own timings. Try again with the default timings.
  1107. */
  1108. if (crtc != NULL) {
  1109. printk(KERN_WARNING "uvesafb: mode switch failed "
  1110. "(eax=0x%x, err=%d). Trying again with "
  1111. "default timings.\n", task->t.regs.eax, err);
  1112. uvesafb_reset(task);
  1113. kfree(crtc);
  1114. crtc = NULL;
  1115. info->var.pixclock = 0;
  1116. goto setmode;
  1117. } else {
  1118. printk(KERN_ERR "uvesafb: mode switch failed (eax="
  1119. "0x%x, err=%d)\n", task->t.regs.eax, err);
  1120. err = -EINVAL;
  1121. goto out;
  1122. }
  1123. }
  1124. par->mode_idx = i;
  1125. /* For 8bpp modes, always try to set the DAC to 8 bits. */
  1126. if (par->vbe_ib.capabilities & VBE_CAP_CAN_SWITCH_DAC &&
  1127. mode->bits_per_pixel <= 8) {
  1128. uvesafb_reset(task);
  1129. task->t.regs.eax = 0x4f08;
  1130. task->t.regs.ebx = 0x0800;
  1131. err = uvesafb_exec(task);
  1132. if (err || (task->t.regs.eax & 0xffff) != 0x004f ||
  1133. ((task->t.regs.ebx & 0xff00) >> 8) != 8) {
  1134. dac_width = 6;
  1135. } else {
  1136. dac_width = 8;
  1137. }
  1138. }
  1139. info->fix.visual = (info->var.bits_per_pixel == 8) ?
  1140. FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
  1141. info->fix.line_length = mode->bytes_per_scan_line;
  1142. out: if (crtc != NULL)
  1143. kfree(crtc);
  1144. uvesafb_free(task);
  1145. return err;
  1146. }
  1147. static void uvesafb_check_limits(struct fb_var_screeninfo *var,
  1148. struct fb_info *info)
  1149. {
  1150. const struct fb_videomode *mode;
  1151. struct uvesafb_par *par = info->par;
  1152. /*
  1153. * If pixclock is set to 0, then we're using default BIOS timings
  1154. * and thus don't have to perform any checks here.
  1155. */
  1156. if (!var->pixclock)
  1157. return;
  1158. if (par->vbe_ib.vbe_version < 0x0300) {
  1159. fb_get_mode(FB_VSYNCTIMINGS | FB_IGNOREMON, 60, var, info);
  1160. return;
  1161. }
  1162. if (!fb_validate_mode(var, info))
  1163. return;
  1164. mode = fb_find_best_mode(var, &info->modelist);
  1165. if (mode) {
  1166. if (mode->xres == var->xres && mode->yres == var->yres &&
  1167. !(mode->vmode & (FB_VMODE_INTERLACED | FB_VMODE_DOUBLE))) {
  1168. fb_videomode_to_var(var, mode);
  1169. return;
  1170. }
  1171. }
  1172. if (info->monspecs.gtf && !fb_get_mode(FB_MAXTIMINGS, 0, var, info))
  1173. return;
  1174. /* Use default refresh rate */
  1175. var->pixclock = 0;
  1176. }
  1177. static int uvesafb_check_var(struct fb_var_screeninfo *var,
  1178. struct fb_info *info)
  1179. {
  1180. struct uvesafb_par *par = info->par;
  1181. struct vbe_mode_ib *mode = NULL;
  1182. int match = -1;
  1183. int depth = var->red.length + var->green.length + var->blue.length;
  1184. /*
  1185. * Various apps will use bits_per_pixel to set the color depth,
  1186. * which is theoretically incorrect, but which we'll try to handle
  1187. * here.
  1188. */
  1189. if (depth == 0 || abs(depth - var->bits_per_pixel) >= 8)
  1190. depth = var->bits_per_pixel;
  1191. match = uvesafb_vbe_find_mode(par, var->xres, var->yres, depth,
  1192. UVESAFB_EXACT_RES);
  1193. if (match == -1)
  1194. return -EINVAL;
  1195. mode = &par->vbe_modes[match];
  1196. uvesafb_setup_var(var, info, mode);
  1197. /*
  1198. * Check whether we have remapped enough memory for this mode.
  1199. * We might be called at an early stage, when we haven't remapped
  1200. * any memory yet, in which case we simply skip the check.
  1201. */
  1202. if (var->yres * mode->bytes_per_scan_line > info->fix.smem_len
  1203. && info->fix.smem_len)
  1204. return -EINVAL;
  1205. if ((var->vmode & FB_VMODE_DOUBLE) &&
  1206. !(par->vbe_modes[match].mode_attr & 0x100))
  1207. var->vmode &= ~FB_VMODE_DOUBLE;
  1208. if ((var->vmode & FB_VMODE_INTERLACED) &&
  1209. !(par->vbe_modes[match].mode_attr & 0x200))
  1210. var->vmode &= ~FB_VMODE_INTERLACED;
  1211. uvesafb_check_limits(var, info);
  1212. var->xres_virtual = var->xres;
  1213. var->yres_virtual = (par->ypan) ?
  1214. info->fix.smem_len / mode->bytes_per_scan_line :
  1215. var->yres;
  1216. return 0;
  1217. }
  1218. static struct fb_ops uvesafb_ops = {
  1219. .owner = THIS_MODULE,
  1220. .fb_open = uvesafb_open,
  1221. .fb_release = uvesafb_release,
  1222. .fb_setcolreg = uvesafb_setcolreg,
  1223. .fb_setcmap = uvesafb_setcmap,
  1224. .fb_pan_display = uvesafb_pan_display,
  1225. .fb_blank = uvesafb_blank,
  1226. .fb_fillrect = cfb_fillrect,
  1227. .fb_copyarea = cfb_copyarea,
  1228. .fb_imageblit = cfb_imageblit,
  1229. .fb_check_var = uvesafb_check_var,
  1230. .fb_set_par = uvesafb_set_par,
  1231. };
  1232. static void __devinit uvesafb_init_info(struct fb_info *info,
  1233. struct vbe_mode_ib *mode)
  1234. {
  1235. unsigned int size_vmode;
  1236. unsigned int size_remap;
  1237. unsigned int size_total;
  1238. struct uvesafb_par *par = info->par;
  1239. int i, h;
  1240. info->pseudo_palette = ((u8 *)info->par + sizeof(struct uvesafb_par));
  1241. info->fix = uvesafb_fix;
  1242. info->fix.ypanstep = par->ypan ? 1 : 0;
  1243. info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
  1244. /* Disable blanking if the user requested so. */
  1245. if (!blank)
  1246. info->fbops->fb_blank = NULL;
  1247. /*
  1248. * Find out how much IO memory is required for the mode with
  1249. * the highest resolution.
  1250. */
  1251. size_remap = 0;
  1252. for (i = 0; i < par->vbe_modes_cnt; i++) {
  1253. h = par->vbe_modes[i].bytes_per_scan_line *
  1254. par->vbe_modes[i].y_res;
  1255. if (h > size_remap)
  1256. size_remap = h;
  1257. }
  1258. size_remap *= 2;
  1259. /*
  1260. * size_vmode -- that is the amount of memory needed for the
  1261. * used video mode, i.e. the minimum amount of
  1262. * memory we need.
  1263. */
  1264. if (mode != NULL) {
  1265. size_vmode = info->var.yres * mode->bytes_per_scan_line;
  1266. } else {
  1267. size_vmode = info->var.yres * info->var.xres *
  1268. ((info->var.bits_per_pixel + 7) >> 3);
  1269. }
  1270. /*
  1271. * size_total -- all video memory we have. Used for mtrr
  1272. * entries, resource allocation and bounds
  1273. * checking.
  1274. */
  1275. size_total = par->vbe_ib.total_memory * 65536;
  1276. if (vram_total)
  1277. size_total = vram_total * 1024 * 1024;
  1278. if (size_total < size_vmode)
  1279. size_total = size_vmode;
  1280. /*
  1281. * size_remap -- the amount of video memory we are going to
  1282. * use for vesafb. With modern cards it is no
  1283. * option to simply use size_total as th
  1284. * wastes plenty of kernel address space.
  1285. */
  1286. if (vram_remap)
  1287. size_remap = vram_remap * 1024 * 1024;
  1288. if (size_remap < size_vmode)
  1289. size_remap = size_vmode;
  1290. if (size_remap > size_total)
  1291. size_remap = size_total;
  1292. info->fix.smem_len = size_remap;
  1293. info->fix.smem_start = mode->phys_base_ptr;
  1294. /*
  1295. * We have to set yres_virtual here because when setup_var() was
  1296. * called, smem_len wasn't defined yet.
  1297. */
  1298. info->var.yres_virtual = info->fix.smem_len /
  1299. mode->bytes_per_scan_line;
  1300. if (par->ypan && info->var.yres_virtual > info->var.yres) {
  1301. printk(KERN_INFO "uvesafb: scrolling: %s "
  1302. "using protected mode interface, "
  1303. "yres_virtual=%d\n",
  1304. (par->ypan > 1) ? "ywrap" : "ypan",
  1305. info->var.yres_virtual);
  1306. } else {
  1307. printk(KERN_INFO "uvesafb: scrolling: redraw\n");
  1308. info->var.yres_virtual = info->var.yres;
  1309. par->ypan = 0;
  1310. }
  1311. info->flags = FBINFO_FLAG_DEFAULT |
  1312. (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
  1313. if (!par->ypan)
  1314. info->fbops->fb_pan_display = NULL;
  1315. }
  1316. static void __devinit uvesafb_init_mtrr(struct fb_info *info)
  1317. {
  1318. #ifdef CONFIG_MTRR
  1319. if (mtrr && !(info->fix.smem_start & (PAGE_SIZE - 1))) {
  1320. int temp_size = info->fix.smem_len;
  1321. unsigned int type = 0;
  1322. switch (mtrr) {
  1323. case 1:
  1324. type = MTRR_TYPE_UNCACHABLE;
  1325. break;
  1326. case 2:
  1327. type = MTRR_TYPE_WRBACK;
  1328. break;
  1329. case 3:
  1330. type = MTRR_TYPE_WRCOMB;
  1331. break;
  1332. case 4:
  1333. type = MTRR_TYPE_WRTHROUGH;
  1334. break;
  1335. default:
  1336. type = 0;
  1337. break;
  1338. }
  1339. if (type) {
  1340. int rc;
  1341. /* Find the largest power-of-two */
  1342. temp_size = roundup_pow_of_two(temp_size);
  1343. /* Try and find a power of two to add */
  1344. do {
  1345. rc = mtrr_add(info->fix.smem_start,
  1346. temp_size, type, 1);
  1347. temp_size >>= 1;
  1348. } while (temp_size >= PAGE_SIZE && rc == -EINVAL);
  1349. }
  1350. }
  1351. #endif /* CONFIG_MTRR */
  1352. }
  1353. static void __devinit uvesafb_ioremap(struct fb_info *info)
  1354. {
  1355. #ifdef CONFIG_X86
  1356. switch (mtrr) {
  1357. case 1: /* uncachable */
  1358. info->screen_base = ioremap_nocache(info->fix.smem_start, info->fix.smem_len);
  1359. break;
  1360. case 2: /* write-back */
  1361. info->screen_base = ioremap_cache(info->fix.smem_start, info->fix.smem_len);
  1362. break;
  1363. case 3: /* write-combining */
  1364. info->screen_base = ioremap_wc(info->fix.smem_start, info->fix.smem_len);
  1365. break;
  1366. case 4: /* write-through */
  1367. default:
  1368. info->screen_base = ioremap(info->fix.smem_start, info->fix.smem_len);
  1369. break;
  1370. }
  1371. #else
  1372. info->screen_base = ioremap(info->fix.smem_start, info->fix.smem_len);
  1373. #endif /* CONFIG_X86 */
  1374. }
  1375. static ssize_t uvesafb_show_vbe_ver(struct device *dev,
  1376. struct device_attribute *attr, char *buf)
  1377. {
  1378. struct fb_info *info = platform_get_drvdata(to_platform_device(dev));
  1379. struct uvesafb_par *par = info->par;
  1380. return snprintf(buf, PAGE_SIZE, "%.4x\n", par->vbe_ib.vbe_version);
  1381. }
  1382. static DEVICE_ATTR(vbe_version, S_IRUGO, uvesafb_show_vbe_ver, NULL);
  1383. static ssize_t uvesafb_show_vbe_modes(struct device *dev,
  1384. struct device_attribute *attr, char *buf)
  1385. {
  1386. struct fb_info *info = platform_get_drvdata(to_platform_device(dev));
  1387. struct uvesafb_par *par = info->par;
  1388. int ret = 0, i;
  1389. for (i = 0; i < par->vbe_modes_cnt && ret < PAGE_SIZE; i++) {
  1390. ret += snprintf(buf + ret, PAGE_SIZE - ret,
  1391. "%dx%d-%d, 0x%.4x\n",
  1392. par->vbe_modes[i].x_res, par->vbe_modes[i].y_res,
  1393. par->vbe_modes[i].depth, par->vbe_modes[i].mode_id);
  1394. }
  1395. return ret;
  1396. }
  1397. static DEVICE_ATTR(vbe_modes, S_IRUGO, uvesafb_show_vbe_modes, NULL);
  1398. static ssize_t uvesafb_show_vendor(struct device *dev,
  1399. struct device_attribute *attr, char *buf)
  1400. {
  1401. struct fb_info *info = platform_get_drvdata(to_platform_device(dev));
  1402. struct uvesafb_par *par = info->par;
  1403. if (par->vbe_ib.oem_vendor_name_ptr)
  1404. return snprintf(buf, PAGE_SIZE, "%s\n", (char *)
  1405. (&par->vbe_ib) + par->vbe_ib.oem_vendor_name_ptr);
  1406. else
  1407. return 0;
  1408. }
  1409. static DEVICE_ATTR(oem_vendor, S_IRUGO, uvesafb_show_vendor, NULL);
  1410. static ssize_t uvesafb_show_product_name(struct device *dev,
  1411. struct device_attribute *attr, char *buf)
  1412. {
  1413. struct fb_info *info = platform_get_drvdata(to_platform_device(dev));
  1414. struct uvesafb_par *par = info->par;
  1415. if (par->vbe_ib.oem_product_name_ptr)
  1416. return snprintf(buf, PAGE_SIZE, "%s\n", (char *)
  1417. (&par->vbe_ib) + par->vbe_ib.oem_product_name_ptr);
  1418. else
  1419. return 0;
  1420. }
  1421. static DEVICE_ATTR(oem_product_name, S_IRUGO, uvesafb_show_product_name, NULL);
  1422. static ssize_t uvesafb_show_product_rev(struct device *dev,
  1423. struct device_attribute *attr, char *buf)
  1424. {
  1425. struct fb_info *info = platform_get_drvdata(to_platform_device(dev));
  1426. struct uvesafb_par *par = info->par;
  1427. if (par->vbe_ib.oem_product_rev_ptr)
  1428. return snprintf(buf, PAGE_SIZE, "%s\n", (char *)
  1429. (&par->vbe_ib) + par->vbe_ib.oem_product_rev_ptr);
  1430. else
  1431. return 0;
  1432. }
  1433. static DEVICE_ATTR(oem_product_rev, S_IRUGO, uvesafb_show_product_rev, NULL);
  1434. static ssize_t uvesafb_show_oem_string(struct device *dev,
  1435. struct device_attribute *attr, char *buf)
  1436. {
  1437. struct fb_info *info = platform_get_drvdata(to_platform_device(dev));
  1438. struct uvesafb_par *par = info->par;
  1439. if (par->vbe_ib.oem_string_ptr)
  1440. return snprintf(buf, PAGE_SIZE, "%s\n",
  1441. (char *)(&par->vbe_ib) + par->vbe_ib.oem_string_ptr);
  1442. else
  1443. return 0;
  1444. }
  1445. static DEVICE_ATTR(oem_string, S_IRUGO, uvesafb_show_oem_string, NULL);
  1446. static ssize_t uvesafb_show_nocrtc(struct device *dev,
  1447. struct device_attribute *attr, char *buf)
  1448. {
  1449. struct fb_info *info = platform_get_drvdata(to_platform_device(dev));
  1450. struct uvesafb_par *par = info->par;
  1451. return snprintf(buf, PAGE_SIZE, "%d\n", par->nocrtc);
  1452. }
  1453. static ssize_t uvesafb_store_nocrtc(struct device *dev,
  1454. struct device_attribute *attr, const char *buf, size_t count)
  1455. {
  1456. struct fb_info *info = platform_get_drvdata(to_platform_device(dev));
  1457. struct uvesafb_par *par = info->par;
  1458. if (count > 0) {
  1459. if (buf[0] == '0')
  1460. par->nocrtc = 0;
  1461. else
  1462. par->nocrtc = 1;
  1463. }
  1464. return count;
  1465. }
  1466. static DEVICE_ATTR(nocrtc, S_IRUGO | S_IWUSR, uvesafb_show_nocrtc,
  1467. uvesafb_store_nocrtc);
  1468. static struct attribute *uvesafb_dev_attrs[] = {
  1469. &dev_attr_vbe_version.attr,
  1470. &dev_attr_vbe_modes.attr,
  1471. &dev_attr_oem_vendor.attr,
  1472. &dev_attr_oem_product_name.attr,
  1473. &dev_attr_oem_product_rev.attr,
  1474. &dev_attr_oem_string.attr,
  1475. &dev_attr_nocrtc.attr,
  1476. NULL,
  1477. };
  1478. static struct attribute_group uvesafb_dev_attgrp = {
  1479. .name = NULL,
  1480. .attrs = uvesafb_dev_attrs,
  1481. };
  1482. static int __devinit uvesafb_probe(struct platform_device *dev)
  1483. {
  1484. struct fb_info *info;
  1485. struct vbe_mode_ib *mode = NULL;
  1486. struct uvesafb_par *par;
  1487. int err = 0, i;
  1488. info = framebuffer_alloc(sizeof(*par) + sizeof(u32) * 256, &dev->dev);
  1489. if (!info)
  1490. return -ENOMEM;
  1491. par = info->par;
  1492. err = uvesafb_vbe_init(info);
  1493. if (err) {
  1494. printk(KERN_ERR "uvesafb: vbe_init() failed with %d\n", err);
  1495. goto out;
  1496. }
  1497. info->fbops = &uvesafb_ops;
  1498. i = uvesafb_vbe_init_mode(info);
  1499. if (i < 0) {
  1500. err = -EINVAL;
  1501. goto out;
  1502. } else {
  1503. mode = &par->vbe_modes[i];
  1504. }
  1505. if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
  1506. err = -ENXIO;
  1507. goto out;
  1508. }
  1509. uvesafb_init_info(info, mode);
  1510. if (!request_region(0x3c0, 32, "uvesafb")) {
  1511. printk(KERN_ERR "uvesafb: request region 0x3c0-0x3e0 failed\n");
  1512. err = -EIO;
  1513. goto out_mode;
  1514. }
  1515. if (!request_mem_region(info->fix.smem_start, info->fix.smem_len,
  1516. "uvesafb")) {
  1517. printk(KERN_ERR "uvesafb: cannot reserve video memory at "
  1518. "0x%lx\n", info->fix.smem_start);
  1519. err = -EIO;
  1520. goto out_reg;
  1521. }
  1522. uvesafb_init_mtrr(info);
  1523. uvesafb_ioremap(info);
  1524. if (!info->screen_base) {
  1525. printk(KERN_ERR
  1526. "uvesafb: abort, cannot ioremap 0x%x bytes of video "
  1527. "memory at 0x%lx\n",
  1528. info->fix.smem_len, info->fix.smem_start);
  1529. err = -EIO;
  1530. goto out_mem;
  1531. }
  1532. platform_set_drvdata(dev, info);
  1533. if (register_framebuffer(info) < 0) {
  1534. printk(KERN_ERR
  1535. "uvesafb: failed to register framebuffer device\n");
  1536. err = -EINVAL;
  1537. goto out_unmap;
  1538. }
  1539. printk(KERN_INFO "uvesafb: framebuffer at 0x%lx, mapped to 0x%p, "
  1540. "using %dk, total %dk\n", info->fix.smem_start,
  1541. info->screen_base, info->fix.smem_len/1024,
  1542. par->vbe_ib.total_memory * 64);
  1543. printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node,
  1544. info->fix.id);
  1545. err = sysfs_create_group(&dev->dev.kobj, &uvesafb_dev_attgrp);
  1546. if (err != 0)
  1547. printk(KERN_WARNING "fb%d: failed to register attributes\n",
  1548. info->node);
  1549. return 0;
  1550. out_unmap:
  1551. iounmap(info->screen_base);
  1552. out_mem:
  1553. release_mem_region(info->fix.smem_start, info->fix.smem_len);
  1554. out_reg:
  1555. release_region(0x3c0, 32);
  1556. out_mode:
  1557. if (!list_empty(&info->modelist))
  1558. fb_destroy_modelist(&info->modelist);
  1559. fb_destroy_modedb(info->monspecs.modedb);
  1560. fb_dealloc_cmap(&info->cmap);
  1561. out:
  1562. if (par->vbe_modes)
  1563. kfree(par->vbe_modes);
  1564. framebuffer_release(info);
  1565. return err;
  1566. }
  1567. static int uvesafb_remove(struct platform_device *dev)
  1568. {
  1569. struct fb_info *info = platform_get_drvdata(dev);
  1570. if (info) {
  1571. struct uvesafb_par *par = info->par;
  1572. sysfs_remove_group(&dev->dev.kobj, &uvesafb_dev_attgrp);
  1573. unregister_framebuffer(info);
  1574. release_region(0x3c0, 32);
  1575. iounmap(info->screen_base);
  1576. release_mem_region(info->fix.smem_start, info->fix.smem_len);
  1577. fb_destroy_modedb(info->monspecs.modedb);
  1578. fb_dealloc_cmap(&info->cmap);
  1579. if (par) {
  1580. if (par->vbe_modes)
  1581. kfree(par->vbe_modes);
  1582. if (par->vbe_state_orig)
  1583. kfree(par->vbe_state_orig);
  1584. if (par->vbe_state_saved)
  1585. kfree(par->vbe_state_saved);
  1586. }
  1587. framebuffer_release(info);
  1588. }
  1589. return 0;
  1590. }
  1591. static struct platform_driver uvesafb_driver = {
  1592. .probe = uvesafb_probe,
  1593. .remove = uvesafb_remove,
  1594. .driver = {
  1595. .name = "uvesafb",
  1596. },
  1597. };
  1598. static struct platform_device *uvesafb_device;
  1599. #ifndef MODULE
  1600. static int __devinit uvesafb_setup(char *options)
  1601. {
  1602. char *this_opt;
  1603. if (!options || !*options)
  1604. return 0;
  1605. while ((this_opt = strsep(&options, ",")) != NULL) {
  1606. if (!*this_opt) continue;
  1607. if (!strcmp(this_opt, "redraw"))
  1608. ypan = 0;
  1609. else if (!strcmp(this_opt, "ypan"))
  1610. ypan = 1;
  1611. else if (!strcmp(this_opt, "ywrap"))
  1612. ypan = 2;
  1613. else if (!strcmp(this_opt, "vgapal"))
  1614. pmi_setpal = 0;
  1615. else if (!strcmp(this_opt, "pmipal"))
  1616. pmi_setpal = 1;
  1617. else if (!strncmp(this_opt, "mtrr:", 5))
  1618. mtrr = simple_strtoul(this_opt+5, NULL, 0);
  1619. else if (!strcmp(this_opt, "nomtrr"))
  1620. mtrr = 0;
  1621. else if (!strcmp(this_opt, "nocrtc"))
  1622. nocrtc = 1;
  1623. else if (!strcmp(this_opt, "noedid"))
  1624. noedid = 1;
  1625. else if (!strcmp(this_opt, "noblank"))
  1626. blank = 0;
  1627. else if (!strncmp(this_opt, "vtotal:", 7))
  1628. vram_total = simple_strtoul(this_opt + 7, NULL, 0);
  1629. else if (!strncmp(this_opt, "vremap:", 7))
  1630. vram_remap = simple_strtoul(this_opt + 7, NULL, 0);
  1631. else if (!strncmp(this_opt, "maxhf:", 6))
  1632. maxhf = simple_strtoul(this_opt + 6, NULL, 0);
  1633. else if (!strncmp(this_opt, "maxvf:", 6))
  1634. maxvf = simple_strtoul(this_opt + 6, NULL, 0);
  1635. else if (!strncmp(this_opt, "maxclk:", 7))
  1636. maxclk = simple_strtoul(this_opt + 7, NULL, 0);
  1637. else if (!strncmp(this_opt, "vbemode:", 8))
  1638. vbemode = simple_strtoul(this_opt + 8, NULL, 0);
  1639. else if (this_opt[0] >= '0' && this_opt[0] <= '9') {
  1640. mode_option = this_opt;
  1641. } else {
  1642. printk(KERN_WARNING
  1643. "uvesafb: unrecognized option %s\n", this_opt);
  1644. }
  1645. }
  1646. return 0;
  1647. }
  1648. #endif /* !MODULE */
  1649. static ssize_t show_v86d(struct device_driver *dev, char *buf)
  1650. {
  1651. return snprintf(buf, PAGE_SIZE, "%s\n", v86d_path);
  1652. }
  1653. static ssize_t store_v86d(struct device_driver *dev, const char *buf,
  1654. size_t count)
  1655. {
  1656. strncpy(v86d_path, buf, PATH_MAX);
  1657. return count;
  1658. }
  1659. static DRIVER_ATTR(v86d, S_IRUGO | S_IWUSR, show_v86d, store_v86d);
  1660. static int __devinit uvesafb_init(void)
  1661. {
  1662. int err;
  1663. #ifndef MODULE
  1664. char *option = NULL;
  1665. if (fb_get_options("uvesafb", &option))
  1666. return -ENODEV;
  1667. uvesafb_setup(option);
  1668. #endif
  1669. err = cn_add_callback(&uvesafb_cn_id, "uvesafb", uvesafb_cn_callback);
  1670. if (err)
  1671. return err;
  1672. err = platform_driver_register(&uvesafb_driver);
  1673. if (!err) {
  1674. uvesafb_device = platform_device_alloc("uvesafb", 0);
  1675. if (uvesafb_device)
  1676. err = platform_device_add(uvesafb_device);
  1677. else
  1678. err = -ENOMEM;
  1679. if (err) {
  1680. platform_device_put(uvesafb_device);
  1681. platform_driver_unregister(&uvesafb_driver);
  1682. cn_del_callback(&uvesafb_cn_id);
  1683. return err;
  1684. }
  1685. err = driver_create_file(&uvesafb_driver.driver,
  1686. &driver_attr_v86d);
  1687. if (err) {
  1688. printk(KERN_WARNING "uvesafb: failed to register "
  1689. "attributes\n");
  1690. err = 0;
  1691. }
  1692. }
  1693. return err;
  1694. }
  1695. module_init(uvesafb_init);
  1696. static void __devexit uvesafb_exit(void)
  1697. {
  1698. struct uvesafb_ktask *task;
  1699. if (v86d_started) {
  1700. task = uvesafb_prep();
  1701. if (task) {
  1702. task->t.flags = TF_EXIT;
  1703. uvesafb_exec(task);
  1704. uvesafb_free(task);
  1705. }
  1706. }
  1707. cn_del_callback(&uvesafb_cn_id);
  1708. driver_remove_file(&uvesafb_driver.driver, &driver_attr_v86d);
  1709. platform_device_unregister(uvesafb_device);
  1710. platform_driver_unregister(&uvesafb_driver);
  1711. }
  1712. module_exit(uvesafb_exit);
  1713. static int param_set_scroll(const char *val, const struct kernel_param *kp)
  1714. {
  1715. ypan = 0;
  1716. if (!strcmp(val, "redraw"))
  1717. ypan = 0;
  1718. else if (!strcmp(val, "ypan"))
  1719. ypan = 1;
  1720. else if (!strcmp(val, "ywrap"))
  1721. ypan = 2;
  1722. else
  1723. return -EINVAL;
  1724. return 0;
  1725. }
  1726. static struct kernel_param_ops param_ops_scroll = {
  1727. .set = param_set_scroll,
  1728. };
  1729. #define param_check_scroll(name, p) __param_check(name, p, void)
  1730. module_param_named(scroll, ypan, scroll, 0);
  1731. MODULE_PARM_DESC(scroll,
  1732. "Scrolling mode, set to 'redraw', 'ypan', or 'ywrap'");
  1733. module_param_named(vgapal, pmi_setpal, invbool, 0);
  1734. MODULE_PARM_DESC(vgapal, "Set palette using VGA registers");
  1735. module_param_named(pmipal, pmi_setpal, bool, 0);
  1736. MODULE_PARM_DESC(pmipal, "Set palette using PMI calls");
  1737. module_param(mtrr, uint, 0);
  1738. MODULE_PARM_DESC(mtrr,
  1739. "Memory Type Range Registers setting. Use 0 to disable.");
  1740. module_param(blank, bool, 0);
  1741. MODULE_PARM_DESC(blank, "Enable hardware blanking");
  1742. module_param(nocrtc, bool, 0);
  1743. MODULE_PARM_DESC(nocrtc, "Ignore CRTC timings when setting modes");
  1744. module_param(noedid, bool, 0);
  1745. MODULE_PARM_DESC(noedid,
  1746. "Ignore EDID-provided monitor limits when setting modes");
  1747. module_param(vram_remap, uint, 0);
  1748. MODULE_PARM_DESC(vram_remap, "Set amount of video memory to be used [MiB]");
  1749. module_param(vram_total, uint, 0);
  1750. MODULE_PARM_DESC(vram_total, "Set total amount of video memoery [MiB]");
  1751. module_param(maxclk, ushort, 0);
  1752. MODULE_PARM_DESC(maxclk, "Maximum pixelclock [MHz], overrides EDID data");
  1753. module_param(maxhf, ushort, 0);
  1754. MODULE_PARM_DESC(maxhf,
  1755. "Maximum horizontal frequency [kHz], overrides EDID data");
  1756. module_param(maxvf, ushort, 0);
  1757. MODULE_PARM_DESC(maxvf,
  1758. "Maximum vertical frequency [Hz], overrides EDID data");
  1759. module_param(mode_option, charp, 0);
  1760. MODULE_PARM_DESC(mode_option,
  1761. "Specify initial video mode as \"<xres>x<yres>[-<bpp>][@<refresh>]\"");
  1762. module_param(vbemode, ushort, 0);
  1763. MODULE_PARM_DESC(vbemode,
  1764. "VBE mode number to set, overrides the 'mode' option");
  1765. module_param_string(v86d, v86d_path, PATH_MAX, 0660);
  1766. MODULE_PARM_DESC(v86d, "Path to the v86d userspace helper.");
  1767. MODULE_LICENSE("GPL");
  1768. MODULE_AUTHOR("Michal Januszewski <spock@gentoo.org>");
  1769. MODULE_DESCRIPTION("Framebuffer driver for VBE2.0+ compliant graphics boards");