InitOutput(ScreenInfo * pScreenInfo, int argc, char **argv)
{
......
/* Load all driver modules specified in the config file */
/* If there aren't any specified in the config file, autoconfig them */
/* FIXME: Does not handle multiple active screen sections, but I'm not
* sure if we really want to handle that case*/
configured_device = xf86ConfigLayout.screens->screen->device;
if ((!configured_device) || (!configured_device->driver)) {
if (!autoConfigDevice(configured_device)) {
xf86Msg(X_ERROR, "Automatic driver configuration failed\n");
return;
}
}
if ((modulelist = xf86DriverlistFromConfig())) {
xf86LoadModules(modulelist, NULL);
free(modulelist);
}
书接上回,上次分析的是autoConfigDevice()函数,
这次继续分析,xf86DriverlistFromConfig()函数,
运行完会产生modulelist指针数组,然后会加载所需的模块,
到这来思路基本上很清晰了。
当然也解决了一个笔者的阅读xserver的最大的问题
没有相关的配置文件,xserver是如何得到一个默认的配置的。
确实比原来的xfree86要先进了。
char **
xf86DriverlistFromConfig(void){
int count = 0;
int j;
char **modulearray;
screenLayoutPtr slp;
/*
* make sure the config file has been parsed and that we have a
* ModulePath set; if no ModulePath was given, use the default
* ModulePath
*/
if (xf86configptr == NULL) {
xf86Msg(X_ERROR, "Cannot access global config data structure\n");
return NULL;
}
/*
* Walk the list of driver lines in active "Device" sections to
* determine now many implicitly loaded modules there are.
*
*/
if (xf86ConfigLayout.screens) {
slp = xf86ConfigLayout.screens;
while ((slp++)->screen) {
count++;
}
}
/*
* Handle the set of inactive "Device" sections.
*/
j = 0;
while (xf86ConfigLayout.inactives[j++].identifier)
count++;
if (count == 0)
return NULL;
/*
* allocate the memory and walk the list again to fill in the pointers
*/
modulearray = xnfalloc((count + 1) * sizeof(char *));
count = 0;
slp = xf86ConfigLayout.screens;
while (slp->screen) {
modulearray[count] = slp->screen->device->driver;
count++;
slp++;
}
j = 0;
while (xf86ConfigLayout.inactives[j].identifier)
modulearray[count++] = xf86ConfigLayout.inactives[j++].driver;
modulearray[count] = NULL;
/* Remove duplicates */
for (count = 0; modulearray[count] != NULL; count++) {
int i;
for (i = 0; i < count; i++)
if (xf86NameCmp(modulearray[i], modulearray[count]) == 0) {
modulearray[count] = "";
break;
}
}
return modulearray;
}
引用一下别人的几句话,关键的部分说的不多。
为什么我看懂了代码,也写了相关的 文章,然后才发现了相关的文章?每次都是这样?
InitOutput()是初始化分量较中的一环,处理过程可以分为如下部分:
1)xf86HandleConfigFile 解析xorg.con文件 ,获得xserver的配置信息。
2)xf86BusProbe 获得video的pci信息,例如framebuffer地址等。
3)DoConfigure() 根据配置文件 ,或者传进来的参数做相应的配置
4)xf86LoadModules load xorg.conf中配置的一系列模块
5)以此遍历注册的各个driver,调用其identify,probe函数,这样就根据显卡的型号加载了相应的驱动
6)匹配screen,主要是根据xorg.conf中配置的screen,查询是否有与其匹配的device
7)遍历screen,调用其匹配device驱动的PreInit函数。这样就完成了显卡驱动的预初始化
8)遍历screen,调用AddScreen函数,分配screenInfo.screen[]的一项,并做初始化ScreenInit.这样驱动的初始化基本完成。