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