Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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