xfree86: Make driver matching consistent

Most of the driver enumeration functions take an array and a maximum
number of entries that they are allowed to fill in. Upon success, they
return the number of entries filled in. This allows them to be easily
used to consecutively.

One exception is the xf86MatchDriverFromFiles() function, which doesn't
return a value, so callers have to manually search the array for the
first empty entry.

This commit modifies the xf86MatchDriverFromFiles() to behave the same
way as others, which makes it easier to deal with.

Reviewed-by: Aaron Plattner <aplattner@nvidia.com>
Tested-By: Aaron Plattner <aplattner@nvidia.com>
Tested-by: Rob Clark <robdclark@gmail.com>  (on arm / platform device)
Signed-off-by: Thierry Reding <treding@nvidia.com>
Signed-off-by: Keith Packard <keithp@keithp.com>
This commit is contained in:
Thierry Reding 2014-02-14 15:45:33 +01:00 committed by Keith Packard
parent a61ca6f006
commit 5a4e15c3f6
4 changed files with 16 additions and 22 deletions

View File

@ -265,7 +265,7 @@ listPossibleVideoDrivers(char *matches[], int nmatches)
#endif #endif
#ifdef XSERVER_LIBPCIACCESS #ifdef XSERVER_LIBPCIACCESS
if (i < (nmatches - 1)) if (i < (nmatches - 1))
i = xf86PciMatchDriver(matches, nmatches); i += xf86PciMatchDriver(&matches[i], nmatches - i);
#endif #endif
#if defined(__linux__) #if defined(__linux__)

View File

@ -1320,8 +1320,9 @@ xchomp(char *line)
* don't export their PCI ID's properly. If distros don't end up using this * don't export their PCI ID's properly. If distros don't end up using this
* feature it can and should be removed because the symbol-based resolution * feature it can and should be removed because the symbol-based resolution
* scheme should be the primary one */ * scheme should be the primary one */
void int
xf86MatchDriverFromFiles(char **matches, uint16_t match_vendor, uint16_t match_chip) xf86MatchDriverFromFiles(uint16_t match_vendor, uint16_t match_chip,
char *matches[], int nmatches)
{ {
DIR *idsdir; DIR *idsdir;
FILE *fp; FILE *fp;
@ -1331,11 +1332,11 @@ xf86MatchDriverFromFiles(char **matches, uint16_t match_vendor, uint16_t match_c
ssize_t read; ssize_t read;
char path_name[256], vendor_str[5], chip_str[5]; char path_name[256], vendor_str[5], chip_str[5];
uint16_t vendor, chip; uint16_t vendor, chip;
int i, j; int i = 0, j;
idsdir = opendir(PCI_TXT_IDS_PATH); idsdir = opendir(PCI_TXT_IDS_PATH);
if (!idsdir) if (!idsdir)
return; return 0;
xf86Msg(X_INFO, xf86Msg(X_INFO,
"Scanning %s directory for additional PCI ID's supported by the drivers\n", "Scanning %s directory for additional PCI ID's supported by the drivers\n",
@ -1386,10 +1387,6 @@ xf86MatchDriverFromFiles(char **matches, uint16_t match_vendor, uint16_t match_c
} }
} }
if (vendor == match_vendor && chip == match_chip) { if (vendor == match_vendor && chip == match_chip) {
i = 0;
while (matches[i]) {
i++;
}
matches[i] = matches[i] =
(char *) malloc(sizeof(char) * (char *) malloc(sizeof(char) *
strlen(direntry->d_name) - 3); strlen(direntry->d_name) - 3);
@ -1412,6 +1409,7 @@ xf86MatchDriverFromFiles(char **matches, uint16_t match_vendor, uint16_t match_c
} }
xf86Msg(X_INFO, "Matched %s from file name %s\n", xf86Msg(X_INFO, "Matched %s from file name %s\n",
matches[i], direntry->d_name); matches[i], direntry->d_name);
i++;
} }
} }
else { else {
@ -1425,6 +1423,7 @@ xf86MatchDriverFromFiles(char **matches, uint16_t match_vendor, uint16_t match_c
end: end:
free(line); free(line);
closedir(idsdir); closedir(idsdir);
return i;
} }
#endif /* __linux__ */ #endif /* __linux__ */
@ -1435,7 +1434,7 @@ xf86MatchDriverFromFiles(char **matches, uint16_t match_vendor, uint16_t match_c
int int
xf86PciMatchDriver(char *matches[], int nmatches) xf86PciMatchDriver(char *matches[], int nmatches)
{ {
int i; int i = 0;
struct pci_device *info = NULL; struct pci_device *info = NULL;
struct pci_device_iterator *iter; struct pci_device_iterator *iter;
@ -1450,13 +1449,10 @@ xf86PciMatchDriver(char *matches[], int nmatches)
pci_iterator_destroy(iter); pci_iterator_destroy(iter);
#ifdef __linux__ #ifdef __linux__
if (info) if (info)
xf86MatchDriverFromFiles(matches, info->vendor_id, info->device_id); i += xf86MatchDriverFromFiles(info->vendor_id, info->device_id,
matches, nmatches);
#endif #endif
for (i = 0; (i < nmatches) && (matches[i]); i++) {
/* find end of matches list */
}
if ((info != NULL) && (i < nmatches)) { if ((info != NULL) && (i < nmatches)) {
i += xf86VideoPtrToDriverList(info, &(matches[i]), nmatches - i); i += xf86VideoPtrToDriverList(info, &(matches[i]), nmatches - i);
} }

View File

@ -47,8 +47,9 @@ void xf86PciConfigureNewDev(void *busData, struct pci_device *pVideo,
((x)->func == (y)->func) && \ ((x)->func == (y)->func) && \
((x)->dev == (y)->dev)) ((x)->dev == (y)->dev))
void int
xf86MatchDriverFromFiles(char **matches, uint16_t match_vendor, uint16_t match_chip); xf86MatchDriverFromFiles(uint16_t match_vendor, uint16_t match_chip,
char *matches[], int nmatches);
int int
xf86VideoPtrToDriverList(struct pci_device *dev, xf86VideoPtrToDriverList(struct pci_device *dev,
char *returnList[], int returnListMax); char *returnList[], int returnListMax);

View File

@ -221,13 +221,10 @@ xf86PlatformMatchDriver(char *matches[], int nmatches)
info = xf86_platform_devices[i].pdev; info = xf86_platform_devices[i].pdev;
#ifdef __linux__ #ifdef __linux__
if (info) if (info)
xf86MatchDriverFromFiles(matches, info->vendor_id, info->device_id); j += xf86MatchDriverFromFiles(info->vendor_id, info->device_id,
&matches[j], nmatches - j);
#endif #endif
for (j = 0; (j < nmatches) && (matches[j]); j++) {
/* find end of matches list */
}
if ((info != NULL) && (j < nmatches)) { if ((info != NULL) && (j < nmatches)) {
j += xf86VideoPtrToDriverList(info, &(matches[j]), nmatches - j); j += xf86VideoPtrToDriverList(info, &(matches[j]), nmatches - j);
} }