星期二, 4月 12, 2005

Linux Framebufer driver writting howto

Framebuffer Internal API
舊的api讓console的code和frame buffer driver link在一起,新的driver將console code移到fbcon
fbcon將顯示卡的功能包起來,讓vt console和device drvier可以分開修改。
一個最好的例子就是virtual framebuffe : vfb。
vfb並不是真正的graphic card,他只是將memory mapping到user space,
有關每個function的內容,可以參考linux/drivers/video/skeletonfb.c。

Data Structure

framebuffer有4個比較重要的structure,都宣告在 fb.h
fb_var_screeninfo
fb_fix_screeninfo
fb_monospecs
fb_info
fb_var_screeninfo : 可以設定的資料,向color depth,resolution。
fb_fix_screeninfo :不能設定的資料,向framebuffer start address
fb_monospecs :避免user program作一些硬體不容許的動作,例如不正確的resolution。
fb_info : 硬體的資料,和card關聯在一起,例如一個有2個output的card,那就會有兩個fb_info,fb_info只有kernel看得到。

Driver Layout

vfb.c是一個比較清楚的範例。

Initialization and boot time parameter handling

啟動時會執行的function有:
int xxfb_init(void);
int xxfb_setup(char*);
上面的function,通常在寫好後,藉由fbmem.c這個code的宣告,在load時link到kernel裡:
static struct {
const char *name;
int (*init)(void);
int (*setup)(char*);
} fb_drivers[] __initdata = {
#ifdef CONFIG_FB_YOURCARD
{"driver_name",xxfb_init,xxfb_setup},
#endif

xxfb_setup(char*)是在kernel boot時使用的,例如,用bootloader開機時同時下達以下參數:
boot: video=matrox:vesa:443
這個video的string會被傳給setup( ) function.

setup function一般是這樣:
int __init xxfb_setup(char *options)
{
char *this_opt;
if(!options || !*options)
return 0;

for(this_opt = strtok(options,","); this_opt;this_opt=strtok(NULL,",")) {
if(!strcmp(this_opt,"my_options")) {
....do something your options want....
&nbsp}else if (!strncmp(this_opt,"other_options:",5))
...
}

另一個function : xxfb_init( ) 設定好video card的initial state,還要處理bus的相關動作(pci,isa或none)

沒有留言:

網誌存檔