framebuffer.rst 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. =======================
  2. The Frame Buffer Device
  3. =======================
  4. Last revised: May 10, 2001
  5. 0. Introduction
  6. ---------------
  7. The frame buffer device provides an abstraction for the graphics hardware. It
  8. represents the frame buffer of some video hardware and allows application
  9. software to access the graphics hardware through a well-defined interface, so
  10. the software doesn't need to know anything about the low-level (hardware
  11. register) stuff.
  12. The device is accessed through special device nodes, usually located in the
  13. /dev directory, i.e. /dev/fb*.
  14. 1. User's View of /dev/fb*
  15. --------------------------
  16. From the user's point of view, the frame buffer device looks just like any
  17. other device in /dev. It's a character device using major 29; the minor
  18. specifies the frame buffer number.
  19. By convention, the following device nodes are used (numbers indicate the device
  20. minor numbers)::
  21. 0 = /dev/fb0 First frame buffer
  22. 1 = /dev/fb1 Second frame buffer
  23. ...
  24. 31 = /dev/fb31 32nd frame buffer
  25. For backwards compatibility, you may want to create the following symbolic
  26. links::
  27. /dev/fb0current -> fb0
  28. /dev/fb1current -> fb1
  29. and so on...
  30. The frame buffer devices are also `normal` memory devices, this means, you can
  31. read and write their contents. You can, for example, make a screen snapshot by::
  32. cp /dev/fb0 myfile
  33. There also can be more than one frame buffer at a time, e.g. if you have a
  34. graphics card in addition to the built-in hardware. The corresponding frame
  35. buffer devices (/dev/fb0 and /dev/fb1 etc.) work independently.
  36. Application software that uses the frame buffer device (e.g. the X server) will
  37. use /dev/fb0 by default (older software uses /dev/fb0current). You can specify
  38. an alternative frame buffer device by setting the environment variable
  39. $FRAMEBUFFER to the path name of a frame buffer device, e.g. (for sh/bash
  40. users)::
  41. export FRAMEBUFFER=/dev/fb1
  42. or (for csh users)::
  43. setenv FRAMEBUFFER /dev/fb1
  44. After this the X server will use the second frame buffer.
  45. 2. Programmer's View of /dev/fb*
  46. --------------------------------
  47. As you already know, a frame buffer device is a memory device like /dev/mem and
  48. it has the same features. You can read it, write it, seek to some location in
  49. it and mmap() it (the main usage). The difference is just that the memory that
  50. appears in the special file is not the whole memory, but the frame buffer of
  51. some video hardware.
  52. /dev/fb* also allows several ioctls on it, by which lots of information about
  53. the hardware can be queried and set. The color map handling works via ioctls,
  54. too. Look into <linux/fb.h> for more information on what ioctls exist and on
  55. which data structures they work. Here's just a brief overview:
  56. - You can request unchangeable information about the hardware, like name,
  57. organization of the screen memory (planes, packed pixels, ...) and address
  58. and length of the screen memory.
  59. - You can request and change variable information about the hardware, like
  60. visible and virtual geometry, depth, color map format, timing, and so on.
  61. If you try to change that information, the driver maybe will round up some
  62. values to meet the hardware's capabilities (or return EINVAL if that isn't
  63. possible).
  64. - You can get and set parts of the color map. Communication is done with 16
  65. bits per color part (red, green, blue, transparency) to support all
  66. existing hardware. The driver does all the computations needed to apply
  67. it to the hardware (round it down to less bits, maybe throw away
  68. transparency).
  69. All this hardware abstraction makes the implementation of application programs
  70. easier and more portable. E.g. the X server works completely on /dev/fb* and
  71. thus doesn't need to know, for example, how the color registers of the concrete
  72. hardware are organized. XF68_FBDev is a general X server for bitmapped,
  73. unaccelerated video hardware. The only thing that has to be built into
  74. application programs is the screen organization (bitplanes or chunky pixels
  75. etc.), because it works on the frame buffer image data directly.
  76. For the future it is planned that frame buffer drivers for graphics cards and
  77. the like can be implemented as kernel modules that are loaded at runtime. Such
  78. a driver just has to call register_framebuffer() and supply some functions.
  79. Writing and distributing such drivers independently from the kernel will save
  80. much trouble...
  81. 3. Frame Buffer Resolution Maintenance
  82. --------------------------------------
  83. Frame buffer resolutions are maintained using the utility `fbset`. It can
  84. change the video mode properties of a frame buffer device. Its main usage is
  85. to change the current video mode, e.g. during boot up in one of your `/etc/rc.*`
  86. or `/etc/init.d/*` files.
  87. Fbset uses a video mode database stored in a configuration file, so you can
  88. easily add your own modes and refer to them with a simple identifier.
  89. 4. The X Server
  90. ---------------
  91. The X server (XF68_FBDev) is the most notable application program for the frame
  92. buffer device. Starting with XFree86 release 3.2, the X server is part of
  93. XFree86 and has 2 modes:
  94. - If the `Display` subsection for the `fbdev` driver in the /etc/XF86Config
  95. file contains a::
  96. Modes "default"
  97. line, the X server will use the scheme discussed above, i.e. it will start
  98. up in the resolution determined by /dev/fb0 (or $FRAMEBUFFER, if set). You
  99. still have to specify the color depth (using the Depth keyword) and virtual
  100. resolution (using the Virtual keyword) though. This is the default for the
  101. configuration file supplied with XFree86. It's the most simple
  102. configuration, but it has some limitations.
  103. - Therefore it's also possible to specify resolutions in the /etc/XF86Config
  104. file. This allows for on-the-fly resolution switching while retaining the
  105. same virtual desktop size. The frame buffer device that's used is still
  106. /dev/fb0current (or $FRAMEBUFFER), but the available resolutions are
  107. defined by /etc/XF86Config now. The disadvantage is that you have to
  108. specify the timings in a different format (but `fbset -x` may help).
  109. To tune a video mode, you can use fbset or xvidtune. Note that xvidtune doesn't
  110. work 100% with XF68_FBDev: the reported clock values are always incorrect.
  111. 5. Video Mode Timings
  112. ---------------------
  113. A monitor draws an image on the screen by using an electron beam (3 electron
  114. beams for color models, 1 electron beam for monochrome monitors). The front of
  115. the screen is covered by a pattern of colored phosphors (pixels). If a phosphor
  116. is hit by an electron, it emits a photon and thus becomes visible.
  117. The electron beam draws horizontal lines (scanlines) from left to right, and
  118. from the top to the bottom of the screen. By modifying the intensity of the
  119. electron beam, pixels with various colors and intensities can be shown.
  120. After each scanline the electron beam has to move back to the left side of the
  121. screen and to the next line: this is called the horizontal retrace. After the
  122. whole screen (frame) was painted, the beam moves back to the upper left corner:
  123. this is called the vertical retrace. During both the horizontal and vertical
  124. retrace, the electron beam is turned off (blanked).
  125. The speed at which the electron beam paints the pixels is determined by the
  126. dotclock in the graphics board. For a dotclock of e.g. 28.37516 MHz (millions
  127. of cycles per second), each pixel is 35242 ps (picoseconds) long::
  128. 1/(28.37516E6 Hz) = 35.242E-9 s
  129. If the screen resolution is 640x480, it will take::
  130. 640*35.242E-9 s = 22.555E-6 s
  131. to paint the 640 (xres) pixels on one scanline. But the horizontal retrace
  132. also takes time (e.g. 272 `pixels`), so a full scanline takes::
  133. (640+272)*35.242E-9 s = 32.141E-6 s
  134. We'll say that the horizontal scanrate is about 31 kHz::
  135. 1/(32.141E-6 s) = 31.113E3 Hz
  136. A full screen counts 480 (yres) lines, but we have to consider the vertical
  137. retrace too (e.g. 49 `lines`). So a full screen will take::
  138. (480+49)*32.141E-6 s = 17.002E-3 s
  139. The vertical scanrate is about 59 Hz::
  140. 1/(17.002E-3 s) = 58.815 Hz
  141. This means the screen data is refreshed about 59 times per second. To have a
  142. stable picture without visible flicker, VESA recommends a vertical scanrate of
  143. at least 72 Hz. But the perceived flicker is very human dependent: some people
  144. can use 50 Hz without any trouble, while I'll notice if it's less than 80 Hz.
  145. Since the monitor doesn't know when a new scanline starts, the graphics board
  146. will supply a synchronization pulse (horizontal sync or hsync) for each
  147. scanline. Similarly it supplies a synchronization pulse (vertical sync or
  148. vsync) for each new frame. The position of the image on the screen is
  149. influenced by the moments at which the synchronization pulses occur.
  150. The following picture summarizes all timings. The horizontal retrace time is
  151. the sum of the left margin, the right margin and the hsync length, while the
  152. vertical retrace time is the sum of the upper margin, the lower margin and the
  153. vsync length::
  154. +----------+---------------------------------------------+----------+-------+
  155. | | ↑ | | |
  156. | | |upper_margin | | |
  157. | | ↓ | | |
  158. +----------###############################################----------+-------+
  159. | # ↑ # | |
  160. | # | # | |
  161. | # | # | |
  162. | # | # | |
  163. | left # | # right | hsync |
  164. | margin # | xres # margin | len |
  165. |<-------->#<---------------+--------------------------->#<-------->|<----->|
  166. | # | # | |
  167. | # | # | |
  168. | # | # | |
  169. | # |yres # | |
  170. | # | # | |
  171. | # | # | |
  172. | # | # | |
  173. | # | # | |
  174. | # | # | |
  175. | # | # | |
  176. | # | # | |
  177. | # | # | |
  178. | # ↓ # | |
  179. +----------###############################################----------+-------+
  180. | | ↑ | | |
  181. | | |lower_margin | | |
  182. | | ↓ | | |
  183. +----------+---------------------------------------------+----------+-------+
  184. | | ↑ | | |
  185. | | |vsync_len | | |
  186. | | ↓ | | |
  187. +----------+---------------------------------------------+----------+-------+
  188. The frame buffer device expects all horizontal timings in number of dotclocks
  189. (in picoseconds, 1E-12 s), and vertical timings in number of scanlines.
  190. 6. Converting XFree86 timing values info frame buffer device timings
  191. --------------------------------------------------------------------
  192. An XFree86 mode line consists of the following fields::
  193. "800x600" 50 800 856 976 1040 600 637 643 666
  194. < name > DCF HR SH1 SH2 HFL VR SV1 SV2 VFL
  195. The frame buffer device uses the following fields:
  196. - pixclock: pixel clock in ps (pico seconds)
  197. - left_margin: time from sync to picture
  198. - right_margin: time from picture to sync
  199. - upper_margin: time from sync to picture
  200. - lower_margin: time from picture to sync
  201. - hsync_len: length of horizontal sync
  202. - vsync_len: length of vertical sync
  203. 1) Pixelclock:
  204. xfree: in MHz
  205. fb: in picoseconds (ps)
  206. pixclock = 1000000 / DCF
  207. 2) horizontal timings:
  208. left_margin = HFL - SH2
  209. right_margin = SH1 - HR
  210. hsync_len = SH2 - SH1
  211. 3) vertical timings:
  212. upper_margin = VFL - SV2
  213. lower_margin = SV1 - VR
  214. vsync_len = SV2 - SV1
  215. Good examples for VESA timings can be found in the XFree86 source tree,
  216. under "xc/programs/Xserver/hw/xfree86/doc/modeDB.txt".
  217. 7. References
  218. -------------
  219. For more specific information about the frame buffer device and its
  220. applications, please refer to the Linux-fbdev website:
  221. http://linux-fbdev.sourceforge.net/
  222. and to the following documentation:
  223. - The manual pages for fbset: fbset(8), fb.modes(5)
  224. - The manual pages for XFree86: XF68_FBDev(1), XF86Config(4/5)
  225. - The mighty kernel sources:
  226. - linux/drivers/video/
  227. - linux/include/linux/fb.h
  228. - linux/include/video/
  229. 8. Mailing list
  230. ---------------
  231. There is a frame buffer device related mailing list at kernel.org:
  232. linux-fbdev@vger.kernel.org.
  233. Point your web browser to http://sourceforge.net/projects/linux-fbdev/ for
  234. subscription information and archive browsing.
  235. 9. Downloading
  236. --------------
  237. All necessary files can be found at
  238. ftp://ftp.uni-erlangen.de/pub/Linux/LOCAL/680x0/
  239. and on its mirrors.
  240. The latest version of fbset can be found at
  241. http://www.linux-fbdev.org/
  242. 10. Credits
  243. -----------
  244. This readme was written by Geert Uytterhoeven, partly based on the original
  245. `X-framebuffer.README` by Roman Hodek and Martin Schaller. Section 6 was
  246. provided by Frank Neumann.
  247. The frame buffer device abstraction was designed by Martin Schaller.