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