Separate choosing driver from the file-based implementation

This clears the implementation out of the way to prepare for development
of a symbol-based resolution scheme
This commit is contained in:
David Nusinow 2007-10-11 22:21:38 -04:00
parent 3aa41bcb82
commit 3367091f7f

View File

@ -332,41 +332,20 @@ autoConfigDevice(GDevPtr preconf_device)
return ptr;
}
char*
chooseVideoDriver(void)
static void
matchDriverFromFiles (char** matches, uint16_t match_vendor, uint16_t match_chip)
{
struct pci_device * info = NULL;
struct pci_device_iterator *iter;
DIR *idsdir;
FILE *fp;
struct dirent *direntry;
char *line = NULL;
char *chosen_driver = NULL;
size_t len;
ssize_t read;
char path_name[256], vendor_str[5], chip_str[5];
uint16_t vendor, chip;
int i, j;
char *matches[20]; /* If we have more than 20 drivers we're in trouble */
for (i=0 ; i<20 ; i++)
matches[i] = NULL;
/* Find the primary device, and get some information about it. */
iter = pci_slot_match_iterator_create(NULL);
while ((info = pci_device_next(iter)) != NULL) {
if (xf86IsPrimaryPci(info)) {
break;
}
}
pci_iterator_destroy(iter);
if (!info) {
ErrorF("Primary device is not PCI\n");
}
idsdir = opendir("/usr/share/xserver-xorg/pci");
if (idsdir) {
direntry = readdir(idsdir);
/* Read the directory */
@ -408,8 +387,8 @@ chooseVideoDriver(void)
chip = (int)strtol(chip_str, NULL, 16);
}
}
if (vendor == info->vendor_id &&
(chip == info->device_id || chip == -1)) {
if (vendor == match_vendor &&
(chip == match_chip || chip == -1)) {
i = 0;
while (matches[i]) {
i++;
@ -442,6 +421,38 @@ chooseVideoDriver(void)
direntry = readdir(idsdir);
}
}
end:
xfree(line);
closedir(idsdir);
}
char*
chooseVideoDriver(void)
{
struct pci_device * info = NULL;
struct pci_device_iterator *iter;
char *chosen_driver = NULL;
int i;
char *matches[20]; /* If we have more than 20 drivers we're in trouble */
for (i=0 ; i<20 ; i++)
matches[i] = NULL;
/* Find the primary device, and get some information about it. */
iter = pci_slot_match_iterator_create(NULL);
while ((info = pci_device_next(iter)) != NULL) {
if (xf86IsPrimaryPci(info)) {
break;
}
}
pci_iterator_destroy(iter);
if (!info) {
ErrorF("Primary device is not PCI\n");
}
matchDriverFromFiles(matches, info->vendor_id, info->device_id);
/* TODO Handle multiple drivers claiming to support the same PCI ID */
if (matches[0]) {
@ -463,7 +474,6 @@ chooseVideoDriver(void)
xf86Msg(X_DEFAULT, "Matched %s for the autoconfigured driver\n", chosen_driver);
end:
i = 0;
while (matches[i]) {
if (matches[i] != chosen_driver) {
@ -471,8 +481,6 @@ chooseVideoDriver(void)
}
i++;
}
xfree(line);
closedir(idsdir);
return chosen_driver;
}