uvesafb.c 50 KB

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