Frame Buffer Library

The frame buffer drivers depend heavily on four data structures. Thesestructures are declared in include/linux/fb.h. They are fb_info,fb_var_screeninfo, fb_fix_screeninfo and fb_monospecs. The lastthree can be made available to and from userland.

fb_info defines the current state of a particular video card. Insidefb_info, there exists a fb_ops structure which is a collection ofneeded functions to make fbdev and fbcon work. fb_info is only visibleto the kernel.

fb_var_screeninfo is used to describe the features of a video cardthat are user defined. With fb_var_screeninfo, things such as depthand the resolution may be defined.

The next structure is fb_fix_screeninfo. This defines the propertiesof a card that are created when a mode is set and can’t be changedotherwise. A good example of this is the start of the frame buffermemory. This “locks” the address of the frame buffer memory, so that itcannot be changed or moved.

The last structure is fb_monospecs. In the old API, there was littleimportance for fb_monospecs. This allowed for forbidden things such assetting a mode of 800x600 on a fix frequency monitor. With the new API,fb_monospecs prevents such things, and if used correctly, can prevent amonitor from being cooked. fb_monospecs will not be useful untilkernels 2.5.x.

Frame Buffer Memory

intregister_framebuffer(structfb_info*fb_info)

registers a frame buffer device

Parameters

structfb_info*fb_info

frame buffer info structure

Description

Registers a frame buffer devicefb_info.

Returns negative errno on error, or zero for success.

voidunregister_framebuffer(structfb_info*fb_info)

releases a frame buffer device

Parameters

structfb_info*fb_info

frame buffer info structure

Description

Unregisters a frame buffer devicefb_info.

Returns negative errno on error, or zero for success.

This function will also notify the framebuffer consoleto release the driver.

This is meant to be called within a driver’smodule_exit()function. If this is called outsidemodule_exit(), ensurethat the driver implementsfb_open() andfb_release() tocheck that no processes are using the device.

intdevm_register_framebuffer(structdevice*dev,structfb_info*fb_info)

resource-managed frame buffer device registration

Parameters

structdevice*dev

device the framebuffer belongs to

structfb_info*fb_info

frame buffer info structure

Description

Registers a frame buffer devicefb_info to devicedev.

Returns negative errno on error, or zero for success.

voidfb_set_suspend(structfb_info*info,intstate)

low level driver signals suspend

Parameters

structfb_info*info

framebuffer affected

intstate

0 = resuming, !=0 = suspending

Description

This is meant to be used by low level drivers tosignal suspend/resume to the core & clients.It must be called with the console semaphore held

Frame Buffer Colormap

voidfb_dealloc_cmap(structfb_cmap*cmap)

deallocate a colormap

Parameters

structfb_cmap*cmap

frame buffer colormap structure

Description

Deallocates a colormap that was previously allocated withfb_alloc_cmap().

intfb_copy_cmap(conststructfb_cmap*from,structfb_cmap*to)

copy a colormap

Parameters

conststructfb_cmap*from

frame buffer colormap structure

structfb_cmap*to

frame buffer colormap structure

Description

Copy contents of colormap fromfrom toto.

intfb_set_cmap(structfb_cmap*cmap,structfb_info*info)

set the colormap

Parameters

structfb_cmap*cmap

frame buffer colormap structure

structfb_info*info

frame buffer info structure

Description

Sets the colormapcmap for a screen of deviceinfo.

Returns negative errno on error, or zero on success.

conststructfb_cmap*fb_default_cmap(intlen)

get default colormap

Parameters

intlen

size of palette for a depth

Description

Gets the default colormap for a specific screen depth.lenis the size of the palette for a particular screen depth.

Returns pointer to a frame buffer colormap structure.

voidfb_invert_cmaps(void)

invert all defaults colormaps

Parameters

void

no arguments

Description

Invert all default colormaps.

Frame Buffer Video Mode Database

intfb_try_mode(structfb_var_screeninfo*var,structfb_info*info,conststructfb_videomode*mode,unsignedintbpp)

test a video mode

Parameters

structfb_var_screeninfo*var

frame buffer user defined part of display

structfb_info*info

frame buffer info structure

conststructfb_videomode*mode

frame buffer video mode structure

unsignedintbpp

color depth in bits per pixel

Description

Tries a video mode to test it’s validity for deviceinfo.

Returns 1 on success.

voidfb_delete_videomode(conststructfb_videomode*mode,structlist_head*head)

removed videomode entry from modelist

Parameters

conststructfb_videomode*mode

videomode to remove

structlist_head*head

structlist_head of modelist

NOTES

Will remove all matching mode entries

intfb_find_mode(structfb_var_screeninfo*var,structfb_info*info,constchar*mode_option,conststructfb_videomode*db,unsignedintdbsize,conststructfb_videomode*default_mode,unsignedintdefault_bpp)

finds a valid video mode

Parameters

structfb_var_screeninfo*var

frame buffer user defined part of display

structfb_info*info

frame buffer info structure

constchar*mode_option

string video mode to find

conststructfb_videomode*db

video mode database

unsignedintdbsize

size ofdb

conststructfb_videomode*default_mode

default video mode to fall back to

unsignedintdefault_bpp

default color depth in bits per pixel

Description

Finds a suitable video mode, starting with the specified modeinmode_option with fallback todefault_mode. Ifdefault_mode fails, all modes in the video mode database willbe tried.

Valid mode specifiers formode_option:

<xres>x<yres>[M][R][-<bpp>][@<refresh>][i][p][m]

or

<name>[-<bpp>][@<refresh>]

with <xres>, <yres>, <bpp> and <refresh> decimal numbers and<name> a string.

If ‘M’ is present after yres (and before refresh/bpp if present),the function will compute the timings using VESA(tm) CoordinatedVideo Timings (CVT). If ‘R’ is present after ‘M’, will compute withreduced blanking (for flatpanels). If ‘i’ or ‘p’ are present, computeinterlaced or progressive mode. If ‘m’ is present, add margins equalto 1.8% of xres rounded down to 8 pixels, and 1.8% of yres. The char‘i’, ‘p’ and ‘m’ must be after ‘M’ and ‘R’. Example:

1024x768MR-8@60m - Reduced blank with margins at 60Hz.

NOTE

The passed structvar is _not_ cleared! This allows youto supply values for e.g. the grayscale and accel_flags fields.

Returns zero for failure, 1 if using specifiedmode_option,2 if using specifiedmode_option with an ignored refresh rate,3 if default mode is used, 4 if fall back to any valid mode.

voidfb_var_to_videomode(structfb_videomode*mode,conststructfb_var_screeninfo*var)

convert fb_var_screeninfo to fb_videomode

Parameters

structfb_videomode*mode

pointer tostructfb_videomode

conststructfb_var_screeninfo*var

pointer tostructfb_var_screeninfo

voidfb_videomode_to_var(structfb_var_screeninfo*var,conststructfb_videomode*mode)

convert fb_videomode to fb_var_screeninfo

Parameters

structfb_var_screeninfo*var

pointer tostructfb_var_screeninfo

conststructfb_videomode*mode

pointer tostructfb_videomode

intfb_mode_is_equal(conststructfb_videomode*mode1,conststructfb_videomode*mode2)

compare 2 videomodes

Parameters

conststructfb_videomode*mode1

first videomode

conststructfb_videomode*mode2

second videomode

Return

1 if equal, 0 if not

conststructfb_videomode*fb_find_best_mode(conststructfb_var_screeninfo*var,structlist_head*head)

find best matching videomode

Parameters

conststructfb_var_screeninfo*var

pointer tostructfb_var_screeninfo

structlist_head*head

pointer tostructlist_head of modelist

Return

structfb_videomode, NULL if none found

Description

IMPORTANT:This function assumes that all modelist entries ininfo->modelist are valid.

NOTES

Finds best matching videomode which has an equal or greater dimension thanvar->xres and var->yres. If more than 1 videomode is found, will returnthe videomode with the highest refresh rate

conststructfb_videomode*fb_find_nearest_mode(conststructfb_videomode*mode,structlist_head*head)

find closest videomode

Parameters

conststructfb_videomode*mode

pointer tostructfb_videomode

structlist_head*head

pointer to modelist

Description

Finds best matching videomode, smaller or greater in dimension.If more than 1 videomode is found, will return the videomode withthe closest refresh rate.

conststructfb_videomode*fb_match_mode(conststructfb_var_screeninfo*var,structlist_head*head)

find a videomode which exactly matches the timings in var

Parameters

conststructfb_var_screeninfo*var

pointer tostructfb_var_screeninfo

structlist_head*head

pointer tostructlist_head of modelist

Return

structfb_videomode, NULL if none found

intfb_add_videomode(conststructfb_videomode*mode,structlist_head*head)

adds videomode entry to modelist

Parameters

conststructfb_videomode*mode

videomode to add

structlist_head*head

structlist_head of modelist

NOTES

Will only add unmatched mode entries

voidfb_destroy_modelist(structlist_head*head)

destroy modelist

Parameters

structlist_head*head

structlist_head of modelist

voidfb_videomode_to_modelist(conststructfb_videomode*modedb,intnum,structlist_head*head)

convert mode array to mode list

Parameters

conststructfb_videomode*modedb

array ofstructfb_videomode

intnum

number of entries in array

structlist_head*head

structlist_head of modelist

Frame Buffer Macintosh Video Mode Database

intmac_vmode_to_var(intvmode,intcmode,structfb_var_screeninfo*var)

converts vmode/cmode pair to var structure

Parameters

intvmode

MacOS video mode

intcmode

MacOS color mode

structfb_var_screeninfo*var

frame buffer video mode structure

Description

Converts a MacOS vmode/cmode pair to a frame buffer videomode structure.

Returns negative errno on error, or zero for success.

intmac_map_monitor_sense(intsense)

Convert monitor sense to vmode

Parameters

intsense

Macintosh monitor sense number

Description

Converts a Macintosh monitor sense number to a MacOSvmode number.

Returns MacOS vmode video mode number.

intmac_find_mode(structfb_var_screeninfo*var,structfb_info*info,constchar*mode_option,unsignedintdefault_bpp)

find a video mode

Parameters

structfb_var_screeninfo*var

frame buffer user defined part of display

structfb_info*info

frame buffer info structure

constchar*mode_option

video mode name (see mac_modedb[])

unsignedintdefault_bpp

default color depth in bits per pixel

Description

Finds a suitable video mode. Tries to set mode specifiedbymode_option. If the name of the wanted mode begins with‘mac’, the Mac video mode database will be used, otherwise itwill fall back to the standard video mode database.

Note

Function marked as __init and can only be used during

system boot.

Returns error code from fb_find_mode (see fb_find_modefunction).

Frame Buffer Fonts

Refer to the file lib/fonts/fonts.c for more information.