354 lines · plain
1=======================2The Frame Buffer Device3=======================4 5Last revised: May 10, 20016 7 80. Introduction9---------------10 11The frame buffer device provides an abstraction for the graphics hardware. It12represents the frame buffer of some video hardware and allows application13software to access the graphics hardware through a well-defined interface, so14the software doesn't need to know anything about the low-level (hardware15register) stuff.16 17The device is accessed through special device nodes, usually located in the18/dev directory, i.e. /dev/fb*.19 20 211. User's View of /dev/fb*22--------------------------23 24From the user's point of view, the frame buffer device looks just like any25other device in /dev. It's a character device using major 29; the minor26specifies the frame buffer number.27 28By convention, the following device nodes are used (numbers indicate the device29minor numbers)::30 31 0 = /dev/fb0 First frame buffer32 1 = /dev/fb1 Second frame buffer33 ...34 31 = /dev/fb31 32nd frame buffer35 36For backwards compatibility, you may want to create the following symbolic37links::38 39 /dev/fb0current -> fb040 /dev/fb1current -> fb141 42and so on...43 44The frame buffer devices are also `normal` memory devices, this means, you can45read and write their contents. You can, for example, make a screen snapshot by::46 47 cp /dev/fb0 myfile48 49There also can be more than one frame buffer at a time, e.g. if you have a50graphics card in addition to the built-in hardware. The corresponding frame51buffer devices (/dev/fb0 and /dev/fb1 etc.) work independently.52 53Application software that uses the frame buffer device (e.g. the X server) will54use /dev/fb0 by default (older software uses /dev/fb0current). You can specify55an alternative frame buffer device by setting the environment variable56$FRAMEBUFFER to the path name of a frame buffer device, e.g. (for sh/bash57users)::58 59 export FRAMEBUFFER=/dev/fb160 61or (for csh users)::62 63 setenv FRAMEBUFFER /dev/fb164 65After this the X server will use the second frame buffer.66 67 682. Programmer's View of /dev/fb*69--------------------------------70 71As you already know, a frame buffer device is a memory device like /dev/mem and72it has the same features. You can read it, write it, seek to some location in73it and mmap() it (the main usage). The difference is just that the memory that74appears in the special file is not the whole memory, but the frame buffer of75some video hardware.76 77/dev/fb* also allows several ioctls on it, by which lots of information about78the hardware can be queried and set. The color map handling works via ioctls,79too. Look into <linux/fb.h> for more information on what ioctls exist and on80which data structures they work. Here's just a brief overview:81 82 - You can request unchangeable information about the hardware, like name,83 organization of the screen memory (planes, packed pixels, ...) and address84 and length of the screen memory.85 86 - You can request and change variable information about the hardware, like87 visible and virtual geometry, depth, color map format, timing, and so on.88 If you try to change that information, the driver maybe will round up some89 values to meet the hardware's capabilities (or return EINVAL if that isn't90 possible).91 92 - You can get and set parts of the color map. Communication is done with 1693 bits per color part (red, green, blue, transparency) to support all94 existing hardware. The driver does all the computations needed to apply95 it to the hardware (round it down to less bits, maybe throw away96 transparency).97 98All this hardware abstraction makes the implementation of application programs99easier and more portable. E.g. the X server works completely on /dev/fb* and100thus doesn't need to know, for example, how the color registers of the concrete101hardware are organized. XF68_FBDev is a general X server for bitmapped,102unaccelerated video hardware. The only thing that has to be built into103application programs is the screen organization (bitplanes or chunky pixels104etc.), because it works on the frame buffer image data directly.105 106For the future it is planned that frame buffer drivers for graphics cards and107the like can be implemented as kernel modules that are loaded at runtime. Such108a driver just has to call register_framebuffer() and supply some functions.109Writing and distributing such drivers independently from the kernel will save110much trouble...111 112 1133. Frame Buffer Resolution Maintenance114--------------------------------------115 116Frame buffer resolutions are maintained using the utility `fbset`. It can117change the video mode properties of a frame buffer device. Its main usage is118to change the current video mode, e.g. during boot up in one of your `/etc/rc.*`119or `/etc/init.d/*` files.120 121Fbset uses a video mode database stored in a configuration file, so you can122easily add your own modes and refer to them with a simple identifier.123 124 1254. The X Server126---------------127 128The X server (XF68_FBDev) is the most notable application program for the frame129buffer device. Starting with XFree86 release 3.2, the X server is part of130XFree86 and has 2 modes:131 132 - If the `Display` subsection for the `fbdev` driver in the /etc/XF86Config133 file contains a::134 135 Modes "default"136 137 line, the X server will use the scheme discussed above, i.e. it will start138 up in the resolution determined by /dev/fb0 (or $FRAMEBUFFER, if set). You139 still have to specify the color depth (using the Depth keyword) and virtual140 resolution (using the Virtual keyword) though. This is the default for the141 configuration file supplied with XFree86. It's the most simple142 configuration, but it has some limitations.143 144 - Therefore it's also possible to specify resolutions in the /etc/XF86Config145 file. This allows for on-the-fly resolution switching while retaining the146 same virtual desktop size. The frame buffer device that's used is still147 /dev/fb0current (or $FRAMEBUFFER), but the available resolutions are148 defined by /etc/XF86Config now. The disadvantage is that you have to149 specify the timings in a different format (but `fbset -x` may help).150 151To tune a video mode, you can use fbset or xvidtune. Note that xvidtune doesn't152work 100% with XF68_FBDev: the reported clock values are always incorrect.153 154 1555. Video Mode Timings156---------------------157 158A monitor draws an image on the screen by using an electron beam (3 electron159beams for color models, 1 electron beam for monochrome monitors). The front of160the screen is covered by a pattern of colored phosphors (pixels). If a phosphor161is hit by an electron, it emits a photon and thus becomes visible.162 163The electron beam draws horizontal lines (scanlines) from left to right, and164from the top to the bottom of the screen. By modifying the intensity of the165electron beam, pixels with various colors and intensities can be shown.166 167After each scanline the electron beam has to move back to the left side of the168screen and to the next line: this is called the horizontal retrace. After the169whole screen (frame) was painted, the beam moves back to the upper left corner:170this is called the vertical retrace. During both the horizontal and vertical171retrace, the electron beam is turned off (blanked).172 173The speed at which the electron beam paints the pixels is determined by the174dotclock in the graphics board. For a dotclock of e.g. 28.37516 MHz (millions175of cycles per second), each pixel is 35242 ps (picoseconds) long::176 177 1/(28.37516E6 Hz) = 35.242E-9 s178 179If the screen resolution is 640x480, it will take::180 181 640*35.242E-9 s = 22.555E-6 s182 183to paint the 640 (xres) pixels on one scanline. But the horizontal retrace184also takes time (e.g. 272 `pixels`), so a full scanline takes::185 186 (640+272)*35.242E-9 s = 32.141E-6 s187 188We'll say that the horizontal scanrate is about 31 kHz::189 190 1/(32.141E-6 s) = 31.113E3 Hz191 192A full screen counts 480 (yres) lines, but we have to consider the vertical193retrace too (e.g. 49 `lines`). So a full screen will take::194 195 (480+49)*32.141E-6 s = 17.002E-3 s196 197The vertical scanrate is about 59 Hz::198 199 1/(17.002E-3 s) = 58.815 Hz200 201This means the screen data is refreshed about 59 times per second. To have a202stable picture without visible flicker, VESA recommends a vertical scanrate of203at least 72 Hz. But the perceived flicker is very human dependent: some people204can use 50 Hz without any trouble, while I'll notice if it's less than 80 Hz.205 206Since the monitor doesn't know when a new scanline starts, the graphics board207will supply a synchronization pulse (horizontal sync or hsync) for each208scanline. Similarly it supplies a synchronization pulse (vertical sync or209vsync) for each new frame. The position of the image on the screen is210influenced by the moments at which the synchronization pulses occur.211 212The following picture summarizes all timings. The horizontal retrace time is213the sum of the left margin, the right margin and the hsync length, while the214vertical retrace time is the sum of the upper margin, the lower margin and the215vsync length::216 217 +----------+---------------------------------------------+----------+-------+218 | | ↑ | | |219 | | |upper_margin | | |220 | | ↓ | | |221 +----------###############################################----------+-------+222 | # ↑ # | |223 | # | # | |224 | # | # | |225 | # | # | |226 | left # | # right | hsync |227 | margin # | xres # margin | len |228 |<-------->#<---------------+--------------------------->#<-------->|<----->|229 | # | # | |230 | # | # | |231 | # | # | |232 | # |yres # | |233 | # | # | |234 | # | # | |235 | # | # | |236 | # | # | |237 | # | # | |238 | # | # | |239 | # | # | |240 | # | # | |241 | # ↓ # | |242 +----------###############################################----------+-------+243 | | ↑ | | |244 | | |lower_margin | | |245 | | ↓ | | |246 +----------+---------------------------------------------+----------+-------+247 | | ↑ | | |248 | | |vsync_len | | |249 | | ↓ | | |250 +----------+---------------------------------------------+----------+-------+251 252The frame buffer device expects all horizontal timings in number of dotclocks253(in picoseconds, 1E-12 s), and vertical timings in number of scanlines.254 255 2566. Converting XFree86 timing values info frame buffer device timings257--------------------------------------------------------------------258 259An XFree86 mode line consists of the following fields::260 261 "800x600" 50 800 856 976 1040 600 637 643 666262 < name > DCF HR SH1 SH2 HFL VR SV1 SV2 VFL263 264The frame buffer device uses the following fields:265 266 - pixclock: pixel clock in ps (pico seconds)267 - left_margin: time from sync to picture268 - right_margin: time from picture to sync269 - upper_margin: time from sync to picture270 - lower_margin: time from picture to sync271 - hsync_len: length of horizontal sync272 - vsync_len: length of vertical sync273 2741) Pixelclock:275 276 xfree: in MHz277 278 fb: in picoseconds (ps)279 280 pixclock = 1000000 / DCF281 2822) horizontal timings:283 284 left_margin = HFL - SH2285 286 right_margin = SH1 - HR287 288 hsync_len = SH2 - SH1289 2903) vertical timings:291 292 upper_margin = VFL - SV2293 294 lower_margin = SV1 - VR295 296 vsync_len = SV2 - SV1297 298Good examples for VESA timings can be found in the XFree86 source tree,299under "xc/programs/Xserver/hw/xfree86/doc/modeDB.txt".300 301 3027. References303-------------304 305For more specific information about the frame buffer device and its306applications, please refer to the Linux-fbdev website:307 308 http://linux-fbdev.sourceforge.net/309 310and to the following documentation:311 312 - The manual pages for fbset: fbset(8), fb.modes(5)313 - The manual pages for XFree86: XF68_FBDev(1), XF86Config(4/5)314 - The mighty kernel sources:315 316 - linux/drivers/video/317 - linux/include/linux/fb.h318 - linux/include/video/319 320 321 3228. Mailing list323---------------324 325There is a frame buffer device related mailing list at kernel.org:326linux-fbdev@vger.kernel.org.327 328Point your web browser to http://sourceforge.net/projects/linux-fbdev/ for329subscription information and archive browsing.330 331 3329. Downloading333--------------334 335All necessary files can be found at336 337 ftp://ftp.uni-erlangen.de/pub/Linux/LOCAL/680x0/338 339and on its mirrors.340 341The latest version of fbset can be found at342 343 http://www.linux-fbdev.org/344 345 34610. Credits347-----------348 349This readme was written by Geert Uytterhoeven, partly based on the original350`X-framebuffer.README` by Roman Hodek and Martin Schaller. Section 6 was351provided by Frank Neumann.352 353The frame buffer device abstraction was designed by Martin Schaller.354