22 #include <linux/module.h>
23 #include <linux/kernel.h>
24 #include <linux/errno.h>
25 #include <linux/string.h>
31 #include <linux/pci.h>
57 930000, 1400000, 165000, 48000,
63 1400000, 2800000, 200000, 96000,
75 dinfo->
name =
"Intel(R) 830M";
81 dinfo->
name =
"Intel(R) 845G";
88 dinfo->
name =
"Intel(R) 854";
99 dinfo->
name =
"Intel(R) 855GME";
103 dinfo->
name =
"Intel(R) 855GM";
107 dinfo->
name =
"Intel(R) 852GME";
111 dinfo->
name =
"Intel(R) 852GM";
115 dinfo->
name =
"Intel(R) 852GM/855GM";
121 dinfo->
name =
"Intel(R) 865G";
127 dinfo->
name =
"Intel(R) 915G";
133 dinfo->
name =
"Intel(R) 915GM";
139 dinfo->
name =
"Intel(R) 945G";
145 dinfo->
name =
"Intel(R) 945GM";
151 dinfo->
name =
"Intel(R) 945GME";
157 dinfo->
name =
"Intel(R) 965G";
163 dinfo->
name =
"Intel(R) 965GM";
180 if (!pdev || !aperture_size || !stolen_size)
185 ERR_MSG(
"cannot find bridge device\n");
206 *aperture_size =
MB(128);
208 *aperture_size =
MB(256);
212 *aperture_size =
MB(64);
214 *aperture_size =
MB(128);
220 stolen_overhead = (*aperture_size /
MB(1)) + 4;
226 *stolen_size =
KB(512) -
KB(stolen_overhead);
229 *stolen_size =
MB(1) -
KB(stolen_overhead);
232 *stolen_size =
MB(8) -
KB(stolen_overhead);
235 ERR_MSG(
"only local memory found\n");
238 ERR_MSG(
"video memory is disabled\n");
241 ERR_MSG(
"unexpected GMCH_GMS value: 0x%02x\n",
242 tmp & INTEL_830_GMCH_GMS_MASK);
249 *stolen_size =
MB(1) -
KB(stolen_overhead);
252 *stolen_size =
MB(4) -
KB(stolen_overhead);
255 *stolen_size =
MB(8) -
KB(stolen_overhead);
258 *stolen_size =
MB(16) -
KB(stolen_overhead);
261 *stolen_size =
MB(32) -
KB(stolen_overhead);
264 *stolen_size =
MB(48) -
KB(stolen_overhead);
267 *stolen_size =
MB(64) -
KB(stolen_overhead);
270 ERR_MSG(
"video memory is disabled\n");
273 ERR_MSG(
"unexpected GMCH_GMS value: 0x%02x\n",
274 tmp & INTEL_855_GMCH_GMS_MASK);
318 DBG_MSG(
"intelfbhw_validate_mode\n");
322 if (bytes_per_pixel == 3)
327 if (tmp > dinfo->
fb.size) {
328 WRN_MSG(
"Not enough video ram for mode "
329 "(%d KByte vs %d KByte).\n",
336 WRN_MSG(
"X resolution too large (%d vs %d).\n",
341 WRN_MSG(
"Y resolution too large (%d vs %d).\n",
346 WRN_MSG(
"X resolution too small (%d vs 4).\n", var->
xres);
350 WRN_MSG(
"Y resolution too small (%d vs 4).\n", var->
yres);
356 WRN_MSG(
"Mode is double-scan.\n");
361 WRN_MSG(
"Odd number of lines in interlaced mode\n");
368 WRN_MSG(
"Pixel clock is too low (%d MHz vs %d MHz).\n",
373 WRN_MSG(
"Pixel clock is too high (%d MHz vs %d MHz).\n",
387 DBG_MSG(
"intelfbhw_pan_display\n");
393 if ((xoffset + info->
var.xres > info->
var.xres_virtual) ||
394 (yoffset + info->
var.yres > info->
var.yres_virtual))
397 offset = (yoffset * dinfo->
pitch) +
398 (xoffset * info->
var.bits_per_pixel) / 8;
400 offset += dinfo->
fb.offset << 12;
405 dinfo->
vsync.pan_display = 1;
407 dinfo->
vsync.pan_display = 0;
421 DBG_MSG(
"intelfbhw_do_blank: blank is %d\n", blank);
505 DBG_MSG(
"intelfbhw_setcolreg: %d: (%d, %d, %d)\n",
506 regno, red, green, blue);
509 OUTREG(palette_reg + (regno << 2),
522 DBG_MSG(
"intelfbhw_read_hw_state\n");
600 for (i = 0; i < 4; i++) {
633 for (i = 0; i < 7; i++) {
640 for (i = 0; i < 8; i++)
657 static int calc_vclock3(
int index,
int m,
int n,
int p)
659 if (p == 0 || n == 0)
664 static int calc_vclock(
int index,
int m1,
int m2,
int n,
int p1,
int p2,
670 m = (5 * (m1 + 2)) + (m2 + 2);
675 p = ((p1 + 2) * (1 << (p2 + 1)));
677 p = ((
p1) * (p2 ? 5 : 10));
682 static void intelfbhw_get_p1p2(
struct intelfb_info *dinfo,
int dpll,
683 int *o_p1,
int *o_p2)
714 int i, m1, m2,
n,
p1, p2;
716 DBG_MSG(
"intelfbhw_print_hw_state\n");
721 printk(
"hw state dump start\n");
729 intelfbhw_get_p1p2(dinfo, hw->
vga_pd, &p1, &p2);
731 printk(
" VGA0: (m1, m2, n, p1, p2) = (%d, %d, %d, %d, %d)\n",
733 printk(
" VGA0: clock is %d\n",
734 calc_vclock(index, m1, m2, n, p1, p2, 0));
740 intelfbhw_get_p1p2(dinfo, hw->
vga_pd, &p1, &p2);
741 printk(
" VGA1: (m1, m2, n, p1, p2) = (%d, %d, %d, %d, %d)\n",
743 printk(
" VGA1: clock is %d\n",
744 calc_vclock(index, m1, m2, n, p1, p2, 0));
757 intelfbhw_get_p1p2(dinfo, hw->
dpll_a, &p1, &p2);
759 printk(
" PLLA0: (m1, m2, n, p1, p2) = (%d, %d, %d, %d, %d)\n",
761 printk(
" PLLA0: clock is %d\n",
762 calc_vclock(index, m1, m2, n, p1, p2, 0));
768 intelfbhw_get_p1p2(dinfo, hw->
dpll_a, &p1, &p2);
770 printk(
" PLLA1: (m1, m2, n, p1, p2) = (%d, %d, %d, %d, %d)\n",
772 printk(
" PLLA1: clock is %d\n",
773 calc_vclock(index, m1, m2, n, p1, p2, 0));
819 printk(
" CURSOR_A_PALETTE: ");
820 for (i = 0; i < 4; i++) {
826 printk(
" CURSOR_B_PALETTE: ");
827 for (i = 0; i < 4; i++) {
846 for (i = 0; i < 7; i++) {
847 printk(
" SWF0%d 0x%08x\n", i,
850 for (i = 0; i < 7; i++) {
851 printk(
" SWF1%d 0x%08x\n", i,
854 for (i = 0; i < 3; i++) {
855 printk(
" SWF3%d 0x%08x\n", i,
858 for (i = 0; i < 8; i++)
859 printk(
" FENCE%d 0x%08x\n", i,
871 printk(
"hw state dump end\n");
878 static int splitm(
int index,
unsigned int m,
unsigned int *retm1,
888 testm = (5 * (m1 + 2)) + (m2 + 2);
890 *retm1 = (
unsigned int)m1;
891 *retm2 = (
unsigned int)m2;
900 static int splitp(
int index,
unsigned int p,
unsigned int *retp1,
907 p2 = (p % 10) ? 1 : 0;
909 p1 = p / (p2 ? 5 : 10);
911 *retp1 = (
unsigned int)p1;
912 *retp2 = (
unsigned int)p2;
920 p1 = (p / (1 << (p2 + 1))) - 2;
921 if (p % 4 == 0 && p1 < pll->
min_p1) {
923 p1 = (p / (1 << (p2 + 1))) - 2;
925 if (p1 < pll->min_p1 || p1 > pll->
max_p1 ||
926 (p1 + 2) * (1 << (p2 + 1)) !=
p) {
929 *retp1 = (
unsigned int)p1;
930 *retp2 = (
unsigned int)p2;
935 static int calc_pll_params(
int index,
int clock,
u32 *retm1,
u32 *retm2,
938 u32 m1, m2,
n,
p1, p2, n1, testm;
939 u32 f_vco,
p, p_best = 0,
m, f_out = 0;
940 u32 err_max, err_target, err_best = 10000000;
941 u32 n_best = 0, m_best = 0, f_best, f_err;
942 u32 p_min, p_max, p_inc, div_max;
946 err_max = 5 * clock / 1000;
947 err_target = clock / 1000;
949 DBG_MSG(
"Clock is %d\n", clock);
956 if (p_min < pll->
min_p)
958 if (p_max > pll->
max_p)
961 DBG_MSG(
"p range is %d-%d (%d)\n", p_min, p_max, p_inc);
965 if (splitp(index, p, &p1, &p2)) {
966 WRN_MSG(
"cannot split p = %d\n", p);
979 for (testm = m - 1; testm <=
m; testm++) {
980 f_out = calc_vclock3(index, testm, n, p);
981 if (splitm(index, testm, &m1, &m2)) {
982 WRN_MSG(
"cannot split m = %d\n",
987 f_err = clock - f_out;
989 f_err = f_out - clock + 1;
991 if (f_err < err_best) {
1000 }
while ((n <= pll->
max_n) && (f_out >= clock));
1002 }
while ((p <= p_max));
1005 WRN_MSG(
"cannot find parameters for clock %d\n", clock);
1011 splitm(index, m, &m1, &m2);
1012 splitp(index, p, &p1, &p2);
1015 DBG_MSG(
"m, n, p: %d (%d,%d), %d (%d), %d (%d,%d), "
1016 "f: %d (%d), VCO: %d\n",
1017 m, m1, m2, n, n1, p, p1, p2,
1018 calc_vclock3(index, m, n, p),
1019 calc_vclock(index, m1, m2, n1, p1, p2, 0),
1020 calc_vclock3(index, m, n, p) * p);
1026 *retclock = calc_vclock(index, m1, m2, n1, p1, p2, 0);
1034 if (value > limit) {
1035 WRN_MSG(
"%s value %d exceeds limit %d\n",
1036 description, value, limit);
1048 u32 *dpll, *fp0, *fp1;
1050 u32 hsync_start, hsync_end, hblank_start, hblank_end, htotal, hactive;
1051 u32 vsync_start, vsync_end, vblank_start, vblank_end, vtotal, vactive;
1052 u32 vsync_pol, hsync_pol;
1053 u32 *vs, *vb, *vt, *hs, *hb, *ht, *
ss, *pipe_conf;
1054 u32 stride_alignment;
1056 DBG_MSG(
"intelfbhw_mode_to_hw\n");
1116 clock_target = 1000000000 / var->
pixclock;
1118 if (calc_pll_params(dinfo->
pll_index, clock_target, &m1, &m2,
1119 &n, &p1, &p2, &clock)) {
1120 WRN_MSG(
"calc_pll_params failed\n");
1125 if (check_overflow(p1,
DPLL_P1_MASK,
"PLL P1 parameter"))
1127 if (check_overflow(p2,
DPLL_P2_MASK,
"PLL P2 parameter"))
1176 hactive = var->
xres;
1178 hsync_end = hsync_start + var->
hsync_len;
1180 hblank_start = hactive;
1181 hblank_end = htotal;
1183 DBG_MSG(
"H: act %d, ss %d, se %d, tot %d bs %d, be %d\n",
1184 hactive, hsync_start, hsync_end, htotal, hblank_start,
1187 vactive = var->
yres;
1191 vsync_end = vsync_start + var->
vsync_len;
1193 vblank_start = vactive;
1194 vblank_end = vtotal;
1195 vblank_end = vsync_end + 1;
1197 DBG_MSG(
"V: act %d, ss %d, se %d, tot %d bs %d, be %d\n",
1198 vactive, vsync_start, vsync_end, vtotal, vblank_start,
1203 if (check_overflow(hactive,
HACTIVE_MASK,
"CRTC hactive"))
1209 if (check_overflow(hsync_end,
HSYNCEND_MASK,
"CRTC hsync_end"))
1212 if (check_overflow(htotal,
HTOTAL_MASK,
"CRTC htotal"))
1218 if (check_overflow(hblank_end,
HBLANKEND_MASK,
"CRTC hblank_end"))
1222 if (check_overflow(vactive,
VACTIVE_MASK,
"CRTC vactive"))
1228 if (check_overflow(vsync_end,
VSYNCEND_MASK,
"CRTC vsync_end"))
1231 if (check_overflow(vtotal,
VTOTAL_MASK,
"CRTC vtotal"))
1237 if (check_overflow(vblank_end,
VBLANKEND_MASK,
"CRTC vblank_end"))
1264 WRN_MSG(
"display stride %d has bad alignment %d\n",
1285 const u32 *dpll, *fp0, *fp1, *pipe_conf;
1286 const u32 *hs, *ht, *hb, *vs, *vt, *vb, *
ss;
1287 u32 dpll_reg, fp0_reg, fp1_reg, pipe_conf_reg, pipe_stat_reg;
1288 u32 hsync_reg, htotal_reg, hblank_reg;
1289 u32 vsync_reg, vtotal_reg, vblank_reg;
1296 DBG_MSG(
"intelfbhw_program_mode\n");
1357 tmp =
INREG(pipe_conf_reg);
1359 OUTREG(pipe_conf_reg, tmp);
1364 if ((tmp_val[0] == tmp_val[1]) && (tmp_val[1] == tmp_val[2]))
1368 if (count % 200 == 0) {
1369 tmp =
INREG(pipe_conf_reg);
1371 OUTREG(pipe_conf_reg, tmp);
1373 }
while (count < 2000);
1399 OUTREG(0x61204, 0xabcd0000);
1402 tmp =
INREG(dpll_reg);
1418 OUTREG(0x61204, 0x00000000);
1431 OUTREG(src_size_reg, *ss);
1442 OUTREG(pipe_stat_reg, 0xFFFF);
1495 ring_space = dinfo->
ring.size -
1508 static int wait_ring(
struct intelfb_info *dinfo,
int n)
1515 DBG_MSG(
"wait_ring: %d\n", n);
1532 refresh_ring(dinfo);
1537 WRN_MSG(
"ring buffer : space: %d wanted %d\n",
1539 WRN_MSG(
"lockup - turning off hardware "
1561 DBG_MSG(
"intelfbhw_do_sync\n");
1604 DBG_MSG(
"reset_state: ring was enabled\n");
1606 refresh_ring(dinfo);
1621 DBG_MSG(
"intelfbhw_2d_stop: accel: %d, ring_active: %d\n",
1640 DBG_MSG(
"intelfbhw_2d_start: accel: %d, ring_active: %d\n",
1656 refresh_ring(dinfo);
1664 u32 br00, br09, br13, br14, br16;
1667 DBG_MSG(
"intelfbhw_do_fillrect: (%d,%d) %dx%d, c 0x%06x, p %d bpp %d, "
1668 "rop 0x%02x\n", x, y, w, h, color, pitch, bpp, rop);
1672 br09 = dinfo->
fb_start + (y * pitch + x * (bpp / 8));
1709 u32 br00, br09, br11, br12, br13, br22, br23, br26;
1712 DBG_MSG(
"intelfbhw_do_bitblt: (%d,%d)->(%d,%d) %dx%d, p %d bpp %d\n",
1713 curx, cury, dstx, dsty, w, h, pitch, bpp);
1756 u32 br00, br09, br13, br18, br19, br22, br23;
1757 int dat, ix, iy, iw;
1761 DBG_MSG(
"intelfbhw_do_drawglyph: (%d,%d) %dx%d\n", x, y, w, h);
1768 nbytes = nbytes *
h;
1784 pad = !(ndwords % 2);
1820 for (j = 0; j < 2; ++
j) {
1821 for (i = 0; i < 2; ++
i) {
1822 if (ix != iw || i == 0)
1823 dat |= cdat[iy*iw + ix++] << (i+j*2)*8;
1825 if (ix == iw && iy != (h-1)) {
1845 DBG_MSG(
"intelfbhw_cursor_init\n");
1849 if (!dinfo->
cursor.physical)
1876 DBG_MSG(
"intelfbhw_cursor_hide\n");
1881 if (!dinfo->
cursor.physical)
1901 DBG_MSG(
"intelfbhw_cursor_show\n");
1910 if (!dinfo->
cursor.physical)
1930 DBG_MSG(
"intelfbhw_cursor_setpos: (%d, %d)\n", x, y);
1950 DBG_MSG(
"intelfbhw_cursor_setcolor\n");
1963 int i,
j,
w = width / 8;
1964 int mod = width % 8, t_mask, d_mask;
1967 DBG_MSG(
"intelfbhw_cursor_load\n");
1970 if (!dinfo->
cursor.virtual)
1973 t_mask = 0xff >>
mod;
1974 d_mask = ~(0xff >>
mod);
1975 for (i = height; i--; ) {
1976 for (
j = 0;
j <
w;
j++) {
1978 writeb(*(data++), addr +
j+8);
1982 writeb(*(data++) & d_mask, addr +
j+8);
1994 DBG_MSG(
"intelfbhw_cursor_reset\n");
1997 if (!dinfo->
cursor.virtual)
2000 for (i = 64; i--; ) {
2001 for (
j = 0;
j < 8;
j++) {
2031 if (dinfo->
vsync.pan_display) {
2032 dinfo->
vsync.pan_display = 0;
2036 dinfo->
vsync.count++;
2049 "intelfb", dinfo)) {
2065 DBG_MSG(
"changing IER to 0x%X\n", tmp);
2076 if (dinfo->
vsync.pan_display) {
2077 dinfo->
vsync.pan_display = 0;
2100 vsync = &dinfo->
vsync;
2110 count = vsync->
count;
2112 count != vsync->
count,
HZ / 10);
2116 DBG_MSG(
"wait_for_vsync timed out!\n");