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