110 #include <linux/module.h>
111 #include <linux/kernel.h>
112 #include <linux/errno.h>
113 #include <linux/string.h>
115 #include <linux/slab.h>
117 #include <linux/fb.h>
120 #include <linux/pci.h>
123 #include <linux/screen_info.h>
143 static int intelfb_setcolreg(
unsigned regno,
unsigned red,
unsigned green,
147 static int intelfb_blank(
int blank,
struct fb_info *
info);
155 static void intelfb_imageblit(
struct fb_info *
info,
163 unsigned int cmd,
unsigned long arg);
174 #if DETECT_VGA_CLASS_ONLY
175 #define INTELFB_CLASS_MASK ~0 << 8
177 #define INTELFB_CLASS_MASK 0
197 static int num_registered = 0;
200 static struct fb_ops intel_fb_ops = {
202 .fb_open = intelfb_open,
203 .fb_release = intelfb_release,
204 .fb_check_var = intelfb_check_var,
205 .fb_set_par = intelfb_set_par,
206 .fb_setcolreg = intelfb_setcolreg,
207 .fb_blank = intelfb_blank,
208 .fb_pan_display = intelfb_pan_display,
209 .fb_fillrect = intelfb_fillrect,
210 .fb_copyarea = intelfb_copyarea,
211 .fb_imageblit = intelfb_imageblit,
212 .fb_cursor = intelfb_cursor,
213 .fb_sync = intelfb_sync,
214 .fb_ioctl = intelfb_ioctl
220 .id_table = intelfb_pci_table,
221 .probe = intelfb_pci_register,
233 static bool accel = 1;
235 static bool hwcursor = 0;
236 static bool mtrr = 1;
237 static bool fixed = 0;
238 static bool noinit = 0;
239 static bool noregister = 0;
240 static bool probeonly = 0;
241 static bool idonly = 0;
242 static int bailearly = 0;
243 static int voffset = 48;
261 MODULE_PARM_DESC(noregister,
"Don't register, just probe and exit (debug)");
265 MODULE_PARM_DESC(idonly,
"Just identify without doing anything else (debug)");
270 "Initial video mode \"<xres>x<yres>[-<depth>][@<refresh>]\"");
273 #define OPT_EQUAL(opt, name) (!strncmp(opt, name, strlen(name)))
274 #define OPT_INTVAL(opt, name) simple_strtoul(opt + strlen(name) + 1, NULL, 0)
275 #define OPT_STRVAL(opt, name) (opt + strlen(name))
277 static __inline__ char * get_opt_string(
const char *this_opt,
const char *
name)
285 while (p[i] && p[i] !=
' ' && p[i] !=
',')
295 static __inline__ int get_opt_int(
const char *this_opt,
const char *
name,
308 static __inline__ int get_opt_bool(
const char *this_opt,
const char *name,
315 if (this_opt[
strlen(name)] ==
'=')
335 if (!options || !*options) {
339 DBG_MSG(
"options: %s\n", options);
354 while ((this_opt =
strsep(&options,
","))) {
357 if (get_opt_bool(this_opt,
"accel", &
accel))
359 else if (get_opt_int(this_opt,
"vram", &vram))
361 else if (get_opt_bool(this_opt,
"hwcursor", &hwcursor))
363 else if (get_opt_bool(this_opt,
"mtrr", &mtrr))
365 else if (get_opt_bool(this_opt,
"fixed", &
fixed))
367 else if (get_opt_bool(this_opt,
"init", &noinit))
370 mode = get_opt_string(this_opt,
"mode=");
380 static int __init intelfb_init(
void)
388 INF_MSG(
"Framebuffer driver for "
398 intelfb_setup(option);
401 return pci_register_driver(&intelfb_driver);
404 static void __exit intelfb_exit(
void)
423 ERR_MSG(
"unable to set MTRR\n");
435 #define set_mtrr(x) WRN_MSG("MTRR is disabled in the kernel\n")
437 #define unset_mtrr(x) do { } while (0)
474 #ifdef CONFIG_FB_INTEL_I2C
492 #define bailout(dinfo) do { \
493 DBG_MSG("bailout\n"); \
495 INF_MSG("Not going to register framebuffer, exiting...\n"); \
511 int aperture_bar = 0;
515 DBG_MSG(
"intelfb_pci_register\n");
518 if (num_registered != 1) {
519 ERR_MSG(
"Attempted to register %d devices "
520 "(should be only 1).\n", num_registered);
526 ERR_MSG(
"Could not allocate memory for intelfb_info.\n");
530 ERR_MSG(
"Could not allocate cmap for intelfb_info.\n");
536 dinfo->
fbops = &intel_fb_ops;
542 ERR_MSG(
"Cannot reserve pixmap memory.\n");
552 ERR_MSG(
"Cannot enable device.\n");
572 DBG_MSG(
"fb aperture: 0x%llx/0x%llx, MMIO region: 0x%llx/0x%llx\n",
581 ERR_MSG(
"Cannot reserve FB region.\n");
591 ERR_MSG(
"Cannot reserve MMIO region.\n");
611 INF_MSG(
"%02x:%02x.%d: %s, aperture size %dMB, "
612 "stolen memory %dkB\n",
622 INF_MSG(
"Acceleration is not supported for the %s chipset.\n",
632 dinfo->
fb.size =
MB(vram);
646 ERR_MSG(
"cannot acquire agp\n");
653 ERR_MSG(
"cannot get agp info\n");
659 if (
MB(voffset) < stolen_size)
660 offset = (stolen_size >> 12);
668 dinfo->
cursor.offset = offset +
671 dinfo->
fb.offset = offset +
673 + (dinfo->
cursor.size >> 12);
679 (dinfo->
aperture.physical, ((offset + dinfo->
fb.offset) << 12)
682 ERR_MSG(
"Cannot remap FB region.\n");
692 ERR_MSG(
"Cannot remap MMIO region.\n");
702 ERR_MSG(
"cannot allocate ring buffer memory\n");
708 dinfo->
ring.offset)) {
709 ERR_MSG(
"cannot bind ring buffer memory\n");
715 + (dinfo->
ring.offset << 12);
717 + (dinfo->
ring.offset << 12);
726 ERR_MSG(
"cannot allocate cursor memory\n");
733 ERR_MSG(
"cannot bind cursor memory\n");
743 + (dinfo->
cursor.offset << 12);
745 + (dinfo->
cursor.offset << 12);
751 WRN_MSG(
"cannot allocate framebuffer memory - use "
757 WRN_MSG(
"cannot bind framebuffer memory - use "
765 dinfo->
fb.offset = 0;
767 + (dinfo->
fb.offset << 12);
768 dinfo->
fb.virtual = dinfo->
aperture.virtual + (dinfo->
fb.offset << 12);
777 DBG_MSG(
"fb: 0x%x(+ 0x%x)/0x%x (0x%p)\n",
778 dinfo->
fb.physical, dinfo->
fb.offset, dinfo->
fb.size,
780 DBG_MSG(
"MMIO: 0x%x/0x%x (0x%p)\n",
783 DBG_MSG(
"ring buffer: 0x%x/0x%x (0x%p)\n",
784 dinfo->
ring.physical, dinfo->
ring.size,
785 dinfo->
ring.virtual);
786 DBG_MSG(
"HW cursor: 0x%x/0x%x (0x%p) (offset 0x%x) (phys 0x%x)\n",
791 DBG_MSG(
"options: vram = %d, accel = %d, hwcursor = %d, fixed = %d, "
792 "noinit = %d\n", vram,
accel, hwcursor,
fixed, noinit);
805 WRN_MSG(
"Non-CRT device is enabled ( ");
816 printk(
"). Disabling mode switching.\n");
824 ERR_MSG(
"Video mode must be programmed at boot time.\n");
835 get_initial_mode(dinfo);
847 if (intelfb_set_fbinfo(dinfo)) {
855 #ifdef CONFIG_FB_INTEL_I2C
863 pci_set_drvdata(pdev, dinfo);
867 bailearly > 6 ? bailearly - 6 : 0);
869 DBG_MSG(
"intelfbhw_read_hw_state returned %d\n", i);
901 ERR_MSG(
"Cannot register framebuffer.\n");
912 dinfo->
vsync.pan_display = 0;
913 dinfo->
vsync.pan_offset = 0;
925 intelfb_pci_unregister(
struct pci_dev *pdev)
929 DBG_MSG(
"intelfb_pci_unregister\n");
936 pci_set_drvdata(pdev,
NULL);
945 DBG_MSG(
"intelfb_var_to_depth: bpp: %d, green.length is %d\n",
950 return (var->
green.length == 6) ? 16 : 15;
966 return (1000000000 / var->
pixclock * 1000 + 500) / xtot / ytot;
986 memset(var, 0,
sizeof(*var));
999 DBG_MSG(
"Initial info: FB is 0x%x/0x%x (%d kByte)\n",
1003 DBG_MSG(
"Initial info: mode is %dx%d-%d (%d)\n",
1019 var->
pixclock = 10000000 / xtot * 1000 / ytot * 100 / 60;
1034 var->
red.length = 8;
1035 var->
green.length = 8;
1036 var->
blue.length = 8;
1045 DBG_MSG(
"intelfb_init_var\n");
1047 var = &dinfo->
info->var;
1061 &dinfo->
info->monspecs);
1067 printk(
"intelfb: Looking for mode in private "
1070 dinfo->
info->monspecs.modedb,
1071 dinfo->
info->monspecs.modedb_len,
1074 if (msrc && msrc > 1) {
1075 printk(
"intelfb: No mode in private database, "
1076 "intelfb: looking for mode in global "
1093 ERR_MSG(
"Cannot find a suitable video mode.\n");
1100 DBG_MSG(
"Initial video mode is from %d.\n", msrc);
1102 #if ALLOCATE_FOR_PANNING
1125 DBG_MSG(
"intelfb_set_fbinfo\n");
1128 info->
fbops = &intel_fb_ops;
1131 info->
pixmap.size = 64*1024;
1132 info->
pixmap.buf_align = 8;
1133 info->
pixmap.access_align = 32;
1136 if (intelfb_init_var(dinfo))
1139 info->
pixmap.scan_align = 1;
1141 info->
fix.smem_start = dinfo->
fb.physical;
1142 info->
fix.smem_len = dinfo->
fb.size;
1144 info->
fix.type_aux = 0;
1145 info->
fix.xpanstep = 8;
1146 info->
fix.ypanstep = 1;
1147 info->
fix.ywrapstep = 0;
1151 update_dinfo(dinfo, &info->
var);
1169 dinfo->
info->fix.line_length = dinfo->
pitch;
1171 switch (dinfo->
bpp) {
1195 dinfo->
info->screen_base = (
char __iomem *)dinfo->
fb.virtual;
1196 dinfo->
info->fix.line_length = dinfo->
pitch;
1206 static int intelfb_open(
struct fb_info *info,
int user)
1216 static int intelfb_release(
struct fb_info *info,
int user)
1236 static int first = 1;
1239 static const int pitches[] = {
1257 for (i = 0; pitches[
i] != 0; i++) {
1258 if (pitches[i] >=
v.xres_virtual) {
1259 v.xres_virtual = pitches[
i];
1265 if (
v.bits_per_pixel <= 8)
1266 v.bits_per_pixel = 8;
1267 else if (
v.bits_per_pixel <= 16) {
1268 if (
v.bits_per_pixel == 16)
1270 v.bits_per_pixel = 16;
1271 }
else if (
v.bits_per_pixel <= 32)
1272 v.bits_per_pixel = 32;
1276 change_var = ((info->
var.xres != var->
xres) ||
1277 (info->
var.yres != var->
yres) ||
1283 sizeof(var->
green)) ||
1292 ERR_MSG(
"Changing the video mode is not supported.\n");
1300 v.red.offset =
v.green.offset =
v.blue.offset = 0;
1301 v.red.length =
v.green.length =
v.blue.length = 8;
1302 v.transp.offset =
v.transp.length = 0;
1308 v.red.length =
v.green.length =
v.blue.length = 5;
1309 v.transp.offset =
v.transp.length = 0;
1318 v.transp.offset =
v.transp.length = 0;
1324 v.red.length =
v.green.length =
v.blue.length = 8;
1325 v.transp.offset =
v.transp.length = 0;
1331 v.red.length =
v.green.length =
v.blue.length = 8;
1332 v.transp.offset = 24;
1333 v.transp.length = 8;
1342 if (
v.xoffset >
v.xres_virtual -
v.xres)
1343 v.xoffset =
v.xres_virtual -
v.xres;
1344 if (
v.yoffset >
v.yres_virtual -
v.yres)
1345 v.yoffset =
v.yres_virtual -
v.yres;
1347 v.red.msb_right =
v.green.msb_right =
v.blue.msb_right =
1348 v.transp.msb_right = 0;
1355 static int intelfb_set_par(
struct fb_info *info)
1361 ERR_MSG(
"Changing the video mode is not supported.\n");
1369 DBG_MSG(
"intelfb_set_par (%dx%d-%d)\n", info->
var.xres,
1370 info->
var.yres, info->
var.bits_per_pixel);
1379 if (
ACCEL(dinfo, info))
1393 update_dinfo(dinfo, &info->
var);
1395 if (
ACCEL(dinfo, info))
1398 intelfb_pan_display(&info->
var, info);
1402 if (
ACCEL(dinfo, info)) {
1416 static int intelfb_setcolreg(
unsigned regno,
unsigned red,
unsigned green,
1423 DBG_MSG(
"intelfb_setcolreg: regno %d, depth %d\n", regno, dinfo->
depth);
1429 if (dinfo->
depth == 8) {
1439 switch (dinfo->
depth) {
1442 ((green & 0xf800) >> 6) |
1443 ((blue & 0xf800) >> 11);
1447 ((green & 0xfc00) >> 5) |
1448 ((blue & 0xf800) >> 11);
1453 ((blue & 0xff00) >> 8);
1461 static int intelfb_blank(
int blank,
struct fb_info *info)
1475 static int intelfb_ioctl(
struct fb_info *info,
unsigned int cmd,
1496 static void intelfb_fillrect (
struct fb_info *info,
1503 DBG_MSG(
"intelfb_fillrect\n");
1506 if (!
ACCEL(dinfo, info) || dinfo->
depth == 4) {
1516 if (dinfo->
depth != 8)
1519 color = rect->
color;
1523 dinfo->
pitch, info->
var.bits_per_pixel,
1527 static void intelfb_copyarea(
struct fb_info *info,
1533 DBG_MSG(
"intelfb_copyarea\n");
1536 if (!
ACCEL(dinfo, info) || dinfo->
depth == 4) {
1543 dinfo->
pitch, info->
var.bits_per_pixel);
1546 static void intelfb_imageblit(
struct fb_info *info,
1550 u32 fgcolor, bgcolor;
1553 DBG_MSG(
"intelfb_imageblit\n");
1557 || image->
depth != 1) {
1562 if (dinfo->
depth != 8) {
1572 image->
dx, image->
dy,
1573 dinfo->
pitch, info->
var.bits_per_pixel)) {
1594 (dinfo->
cursor.offset << 12);
1599 DBG_MSG(
"the cursor was killed - restore it !!\n");
1600 DBG_MSG(
"size %d, %d pos %d, %d\n",
1609 if (dinfo->
depth != 8) {
1613 fg = cursor->
image.fg_color;
1614 bg = cursor->
image.bg_color;
1618 cursor->
image.height,
1629 dx = cursor->
image.dx - info->
var.xoffset;
1630 dy = cursor->
image.dy - info->
var.yoffset;
1636 if (cursor->
image.width > 64 || cursor->
image.height > 64)
1645 if (dinfo->
depth != 8) {
1649 fg = cursor->
image.fg_color;
1650 bg = cursor->
image.bg_color;
1664 if (cursor->
image.depth != 1)
1667 switch (cursor->
rop) {
1669 for (i = 0; i <
size; i++)
1670 src[i] = dat[i] ^
msk[i];
1674 for (i = 0; i <
size; i++)
1675 src[i] = dat[i] &
msk[i];
1684 cursor->
image.height, src);
1693 static int intelfb_sync(
struct fb_info *info)