/* * SGI GBE frame buffer driver * * Copyright (C) 1999 Silicon Graphics, Inc. - Jeffrey Newquist * Copyright (C) 2002 Vivien Chappelier <vivien.chappelier@linux-mips.org> * * This file is subject to the terms and conditions of the GNU General Public * License. See the file COPYING in the main directory of this archive for * more details.
*/
/* * RAM we reserve for the frame buffer. This defines the maximum screen * size
*/ #if CONFIG_FB_GBE_MEM > 8 #error GBE Framebuffer cannot use more than 8MB of memory #endif
/* * Function: gbe_turn_off * Parameters: (None) * Description: This should turn off the monitor and gbe. This is used * when switching between the serial console and the graphics * console.
*/
staticvoid gbe_turn_off(void)
{ int i; unsignedint val, y, vpixen_off;
gbe_turned_on = 0;
/* check if pixel counter is on */
val = gbe->vt_xy; if (GET_GBE_FIELD(VT_XY, FREEZE, val) == 1) return;
/* turn off DMA */
val = gbe->ovr_control;
SET_GBE_FIELD(OVR_CONTROL, OVR_DMA_ENABLE, val, 0);
gbe->ovr_control = val;
udelay(1000);
val = gbe->frm_control;
SET_GBE_FIELD(FRM_CONTROL, FRM_DMA_ENABLE, val, 0);
gbe->frm_control = val;
udelay(1000);
val = gbe->did_control;
SET_GBE_FIELD(DID_CONTROL, DID_DMA_ENABLE, val, 0);
gbe->did_control = val;
udelay(1000);
/* We have to wait through two vertical retrace periods before
* the pixel DMA is turned off for sure. */ for (i = 0; i < 10000; i++) {
val = gbe->frm_inhwctrl; if (GET_GBE_FIELD(FRM_INHWCTRL, FRM_DMA_ENABLE, val)) {
udelay(10);
} else {
val = gbe->ovr_inhwctrl; if (GET_GBE_FIELD(OVR_INHWCTRL, OVR_DMA_ENABLE, val)) {
udelay(10);
} else {
val = gbe->did_inhwctrl; if (GET_GBE_FIELD(DID_INHWCTRL, DID_DMA_ENABLE, val)) {
udelay(10);
} else break;
}
}
} if (i == 10000)
printk(KERN_ERR "gbefb: turn off DMA timed out\n");
/* wait for vpixen_off */
val = gbe->vt_vpixen;
vpixen_off = GET_GBE_FIELD(VT_VPIXEN, VPIXEN_OFF, val);
for (i = 0; i < 100000; i++) {
val = gbe->vt_xy;
y = GET_GBE_FIELD(VT_XY, Y, val); if (y < vpixen_off) break;
udelay(1);
} if (i == 100000)
printk(KERN_ERR "gbefb: wait for vpixen_off timed out\n"); for (i = 0; i < 10000; i++) {
val = gbe->vt_xy;
y = GET_GBE_FIELD(VT_XY, Y, val); if (y > vpixen_off) break;
udelay(1);
} if (i == 10000)
printk(KERN_ERR "gbefb: wait for vpixen_off timed out\n");
/* turn off pixel counter */
val = 0;
SET_GBE_FIELD(VT_XY, FREEZE, val, 1);
gbe->vt_xy = val;
mdelay(10); for (i = 0; i < 10000; i++) {
val = gbe->vt_xy; if (GET_GBE_FIELD(VT_XY, FREEZE, val) != 1)
udelay(10); else break;
} if (i == 10000)
printk(KERN_ERR "gbefb: turn off pixel clock timed out\n");
/* turn off dot clock */
val = gbe->dotclock;
SET_GBE_FIELD(DOTCLK, RUN, val, 0);
gbe->dotclock = val;
mdelay(10); for (i = 0; i < 10000; i++) {
val = gbe->dotclock; if (GET_GBE_FIELD(DOTCLK, RUN, val))
udelay(10); else break;
} if (i == 10000)
printk(KERN_ERR "gbefb: turn off dotclock timed out\n");
/* * Check if pixel counter is off, for unknown reason this * code hangs Visual Workstations
*/ if (gbe_revision < 2) {
val = gbe->vt_xy; if (GET_GBE_FIELD(VT_XY, FREEZE, val) == 0) return;
}
/* turn on dot clock */
val = gbe->dotclock;
SET_GBE_FIELD(DOTCLK, RUN, val, 1);
gbe->dotclock = val;
mdelay(10); for (i = 0; i < 10000; i++) {
val = gbe->dotclock; if (GET_GBE_FIELD(DOTCLK, RUN, val) != 1)
udelay(10); else break;
} if (i == 10000)
printk(KERN_ERR "gbefb: turn on dotclock timed out\n");
/* turn on pixel counter */
val = 0;
SET_GBE_FIELD(VT_XY, FREEZE, val, 0);
gbe->vt_xy = val;
mdelay(10); for (i = 0; i < 10000; i++) {
val = gbe->vt_xy; if (GET_GBE_FIELD(VT_XY, FREEZE, val))
udelay(10); else break;
} if (i == 10000)
printk(KERN_ERR "gbefb: turn on pixel clock timed out\n");
/* turn on DMA */
val = gbe->frm_control;
SET_GBE_FIELD(FRM_CONTROL, FRM_DMA_ENABLE, val, 1);
gbe->frm_control = val;
udelay(1000); for (i = 0; i < 10000; i++) {
val = gbe->frm_inhwctrl; if (GET_GBE_FIELD(FRM_INHWCTRL, FRM_DMA_ENABLE, val) != 1)
udelay(10); else break;
} if (i == 10000)
printk(KERN_ERR "gbefb: turn on DMA timed out\n");
gbe_turned_on = 1;
}
staticvoid gbe_loadcmap(void)
{ int i, j;
for (i = 0; i < 256; i++) { for (j = 0; j < 1000 && gbe->cm_fifo >= 63; j++)
udelay(10); if (j == 1000)
printk(KERN_ERR "gbefb: cmap FIFO timeout\n");
gbe->cmap[i] = gbe_cmap[i];
}
}
/* * Blank the display.
*/ staticint gbefb_blank(int blank, struct fb_info *info)
{ /* 0 unblank, 1 blank, 2 no vsync, 3 no hsync, 4 off */ switch (blank) { case FB_BLANK_UNBLANK: /* unblank */
gbe_turn_on();
gbe_loadcmap(); break;
case FB_BLANK_NORMAL: /* blank */
gbe_turn_off(); break;
/* HACK: The GBE hardware uses a tiled memory to screen mapping. Tiles are blocks of 512x128, 256x128 or 128x128 pixels, respectively for 8bit, 16bit and 32 bit modes (64 kB). They cover the screen with partial tiles on the right and/or bottom of the screen if needed. For example in 640x480 8 bit mode the mapping is:
Tiles have the advantage that they can be allocated individually in memory. However, this mapping is not linear at all, which is not really convenient. In order to support linear addressing, the GBE DMA hardware is fooled into thinking the screen is only one tile large and but has a greater height, so that the DMA transfer covers the same region. Tiles are still allocated as independent chunks of 64KB of continuous physical memory and remapped so that the kernel sees the framebuffer as a continuous virtual memory. The GBE tile table is set up so that each tile references one of these 64k blocks:
GBE -> tile list framebuffer TLB <------------ CPU [ tile 0 ] -> [ 64KB ] <- [ 16x 4KB page entries ] ^ ... ... ... linear virtual FB [ tile n ] -> [ 64KB ] <- [ 16x 4KB page entries ] v
The GBE hardware is then told that the buffer is 512*tweaked_height, with tweaked_height = real_width*real_height/pixels_per_tile. Thus the GBE hardware will scan the first tile, filing the first 64k covered region of the screen, and then will proceed to the next tile, until the whole screen is covered.
Here is what would happen at 640x480 8bit:
normal tiling linear ^ 11111111111111112222 11111111111111111111 ^ 128 11111111111111112222 11111111111111111111 102 lines 11111111111111112222 11111111111111111111 v V 11111111111111112222 11111111222222222222 33333333333333334444 22222222222222222222 33333333333333334444 22222222222222222222 < 512 > < 256 > 102*640+256 = 64k
NOTE: The only mode for which this is not working is 800x600 8bit, as 800*600/512 = 937.5 which is not integer and thus causes flickering. I guess this is not so important as one can use 640x480 8bit or 800x600 16bit anyway.
*/
/* Tell gbe about the tiles table location */ /* tile_ptr -> [ tile 1 ] -> FB mem */ /* [ tile 2 ] -> FB mem */ /* ... */
val = 0;
SET_GBE_FIELD(FRM_CONTROL, FRM_TILE_PTR, val, gbe_tiles.dma >> 9);
SET_GBE_FIELD(FRM_CONTROL, FRM_DMA_ENABLE, val, 0); /* do not start */
SET_GBE_FIELD(FRM_CONTROL, FRM_LINEAR, val, 0);
gbe->frm_control = val;
/* * Set a single color register. The values supplied are already * rounded down to the hardware's capabilities (according to the * entries in the var structure). Return != 0 for invalid regno.
*/
if (regno > 255) return 1;
red >>= 8;
green >>= 8;
blue >>= 8;
if (info->var.bits_per_pixel <= 8) {
gbe_cmap[regno] = (red << 24) | (green << 16) | (blue << 8); if (gbe_turned_on) { /* wait for the color map FIFO to have a free entry */ for (i = 0; i < 1000 && gbe->cm_fifo >= 63; i++)
udelay(10); if (i == 1000) {
printk(KERN_ERR "gbefb: cmap FIFO timeout\n"); return 1;
}
gbe->cmap[regno] = gbe_cmap[regno];
}
} elseif (regno < 16) { switch (info->var.bits_per_pixel) { case 15: case 16:
red >>= 3;
green >>= 3;
blue >>= 3;
pseudo_palette[regno] =
(red << info->var.red.offset) |
(green << info->var.green.offset) |
(blue << info->var.blue.offset); break; case 32:
pseudo_palette[regno] =
(red << info->var.red.offset) |
(green << info->var.green.offset) |
(blue << info->var.blue.offset); break;
}
}
return 0;
}
/* * Check video mode validity, eventually modify var to best match.
*/ staticint gbefb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
{ unsignedint line_length; struct gbe_timing_info timing; int ret;
/* Check the mode can be mapped linearly with the tile table trick. */ /* This requires width x height x bytes/pixel be a multiple of 512 */ if ((var->xres * var->yres * var->bits_per_pixel) & 4095) return -EINVAL;
var->grayscale = 0; /* No grayscale for now */
ret = compute_gbe_timing(var, &timing);
var->pixclock = ret; if (ret < 0) return -EINVAL;
/* Adjust virtual resolution, if necessary */ if (var->xres > var->xres_virtual || (!ywrap && !ypan))
var->xres_virtual = var->xres; if (var->yres > var->yres_virtual || (!ywrap && !ypan))
var->yres_virtual = var->yres;
/* check range */ if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT)) return -EINVAL; if (size > gbe_mem_size) return -EINVAL; if (offset > gbe_mem_size - size) return -EINVAL;
/* remap using the fastest write-through mode on architecture */ /* try not polluting the cache when possible */ #ifdef CONFIG_MIPS
pgprot_val(vma->vm_page_prot) =
pgprot_fb(pgprot_val(vma->vm_page_prot)); #endif /* VM_IO | VM_DONTEXPAND | VM_DONTDUMP are set by remap_pfn_range() */
/* look for the starting tile */
tile = &gbe_tiles.cpu[offset >> TILE_SHIFT];
addr = vma->vm_start;
offset &= TILE_MASK;
if (gbe_mem_phys) { /* memory was allocated at boot time */
gbe_mem = devm_ioremap_wc(&p_dev->dev, gbe_mem_phys,
gbe_mem_size); if (!gbe_mem) {
printk(KERN_ERR "gbefb: couldn't map framebuffer\n");
ret = -ENOMEM; goto out_release_mem_region;
}
gbe_dma_addr = 0;
} else { /* try to allocate memory with the classical allocator
* this has high chance to fail on low memory machines */
gbe_mem = dmam_alloc_attrs(&p_dev->dev, gbe_mem_size,
&gbe_dma_addr, GFP_KERNEL,
DMA_ATTR_WRITE_COMBINE); if (!gbe_mem) {
printk(KERN_ERR "gbefb: couldn't allocate framebuffer memory\n");
ret = -ENOMEM; goto out_release_mem_region;
}
gbe_mem_phys = (unsignedlong) gbe_dma_addr;
}
par = info->par;
par->wc_cookie = arch_phys_wc_add(gbe_mem_phys, gbe_mem_size);
/* map framebuffer memory into tiles table */ for (i = 0; i < (gbe_mem_size >> TILE_SHIFT); i++)
gbe_tiles.cpu[i] = (gbe_mem_phys >> TILE_SHIFT) + i;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.