uvesafb.c 51 KB

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