uvesafb.c 49 KB

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