diff options
author | Eric Anholt <eric@anholt.net> | 2017-05-09 13:37:59 -0700 |
---|---|---|
committer | Eric Anholt <eric@anholt.net> | 2017-05-09 15:02:30 -0700 |
commit | 2388f5e583d4ab2ee12f2b087d381b64aed3f7d5 (patch) | |
tree | 9bc398365f5336848c840960bc43bddb9fe5550a /hw/xfree86/common | |
parent | 1dd14e7a499428cf7215b49a9319199545bcd6cb (diff) |
Revert "xfree86: Improved autoconfig drivers matching"
This reverts commit 112d0d7d01b98fb0d67910281dd1feeec125247b.
It broke Xorg for Adam, Peter, and myself, by failing hard when a
module load failed.
Signed-off-by: Eric Anholt <eric@anholt.net>
Diffstat (limited to 'hw/xfree86/common')
-rw-r--r-- | hw/xfree86/common/Makefile.am | 3 | ||||
-rw-r--r-- | hw/xfree86/common/meson.build | 1 | ||||
-rw-r--r-- | hw/xfree86/common/xf86AutoConfig.c | 126 | ||||
-rw-r--r-- | hw/xfree86/common/xf86MatchDrivers.h | 40 | ||||
-rw-r--r-- | hw/xfree86/common/xf86pciBus.c | 52 | ||||
-rw-r--r-- | hw/xfree86/common/xf86pciBus.h | 13 | ||||
-rw-r--r-- | hw/xfree86/common/xf86platformBus.c | 31 | ||||
-rw-r--r-- | hw/xfree86/common/xf86platformBus.h | 5 |
8 files changed, 118 insertions, 153 deletions
diff --git a/hw/xfree86/common/Makefile.am b/hw/xfree86/common/Makefile.am index 41758fd2e..caae7fd97 100644 --- a/hw/xfree86/common/Makefile.am +++ b/hw/xfree86/common/Makefile.am @@ -58,8 +58,7 @@ sdk_HEADERS = compiler.h fourcc.h xf86.h xf86Module.h xf86Opt.h \ xf86PciInfo.h xf86Priv.h xf86Privstr.h \ xf86cmap.h xf86fbman.h xf86str.h xf86Xinput.h xisb.h \ $(XVSDKINCS) $(XF86VMODE_SDK) $(DGA_SDK) xorgVersion.h \ - xf86sbusBus.h xf86VGAarbiter.h xf86Optionstr.h \ - xf86platformBus.h xf86MatchDrivers.h \ + xf86sbusBus.h xf86VGAarbiter.h xf86Optionstr.h xf86platformBus.h \ xaarop.h DISTCLEANFILES = xf86Build.h diff --git a/hw/xfree86/common/meson.build b/hw/xfree86/common/meson.build index 6ed3f5124..cdbc5e609 100644 --- a/hw/xfree86/common/meson.build +++ b/hw/xfree86/common/meson.build @@ -43,7 +43,6 @@ xorg_sdk_headers = [ 'xf86VGAarbiter.h', 'xf86Optionstr.h', 'xf86platformBus.h', - 'xf86MatchDrivers.h', 'xaarop.h', ] diff --git a/hw/xfree86/common/xf86AutoConfig.c b/hw/xfree86/common/xf86AutoConfig.c index a32c108ff..c3e17beb7 100644 --- a/hw/xfree86/common/xf86AutoConfig.c +++ b/hw/xfree86/common/xf86AutoConfig.c @@ -37,7 +37,6 @@ #include "xf86Parser.h" #include "xf86tokens.h" #include "xf86Config.h" -#include "xf86MatchDrivers.h" #include "xf86Priv.h" #include "xf86_OSlib.h" #include "xf86platformBus.h" @@ -90,7 +89,7 @@ static const char **builtinConfig = NULL; static int builtinLines = 0; -static void listPossibleVideoDrivers(XF86MatchedDrivers *md); +static void listPossibleVideoDrivers(char *matches[], int nmatches); /* * A built-in config file is stored as an array of strings, with each string @@ -141,33 +140,11 @@ AppendToConfig(const char *s) AppendToList(s, &builtinConfig, &builtinLines); } -void -xf86AddMatchedDriver(XF86MatchedDrivers *md, const char *driver) -{ - int j; - int nmatches = md->nmatches; - - for (j = 0; j < nmatches; ++j) { - if (xf86NameCmp(md->matches[j], driver) == 0) { - // Driver already in matched drivers - return; - } - } - - if (nmatches < MATCH_DRIVERS_LIMIT) { - md->matches[nmatches] = xnfstrdup(driver); - md->nmatches++; - } - else { - xf86Msg(X_WARNING, "Too many drivers registered, can't add %s\n", driver); - } -} - Bool xf86AutoConfig(void) { - XF86MatchedDrivers md; - int i; + char *deviceList[20]; + char **p; const char **cp; char buf[1024]; ConfigStatus ret; @@ -181,27 +158,24 @@ xf86AutoConfig(void) return FALSE; } - listPossibleVideoDrivers(&md); + listPossibleVideoDrivers(deviceList, 20); - for (i = 0; i < md.nmatches; i++) { - snprintf(buf, sizeof(buf), BUILTIN_DEVICE_SECTION, - md.matches[i], 0, md.matches[i]); + for (p = deviceList; *p; p++) { + snprintf(buf, sizeof(buf), BUILTIN_DEVICE_SECTION, *p, 0, *p); AppendToConfig(buf); - snprintf(buf, sizeof(buf), BUILTIN_SCREEN_SECTION, - md.matches[i], 0, md.matches[i], 0); + snprintf(buf, sizeof(buf), BUILTIN_SCREEN_SECTION, *p, 0, *p, 0); AppendToConfig(buf); } AppendToConfig(BUILTIN_LAYOUT_SECTION_PRE); - for (i = 0; i < md.nmatches; i++) { - snprintf(buf, sizeof(buf), BUILTIN_LAYOUT_SCREEN_LINE, - md.matches[i], 0); + for (p = deviceList; *p; p++) { + snprintf(buf, sizeof(buf), BUILTIN_LAYOUT_SCREEN_LINE, *p, 0); AppendToConfig(buf); } AppendToConfig(BUILTIN_LAYOUT_SECTION_POST); - for (i = 0; i < md.nmatches; i++) { - free(md.matches[i]); + for (p = deviceList; *p; p++) { + free(*p); } xf86MsgVerb(X_DEFAULT, 0, @@ -225,17 +199,22 @@ xf86AutoConfig(void) } static void -listPossibleVideoDrivers(XF86MatchedDrivers *md) +listPossibleVideoDrivers(char *matches[], int nmatches) { - md->nmatches = 0; + int i; + + for (i = 0; i < nmatches; i++) { + matches[i] = NULL; + } + i = 0; #ifdef XSERVER_PLATFORM_BUS - xf86PlatformMatchDriver(md); + i = xf86PlatformMatchDriver(matches, nmatches); #endif #ifdef __sun /* Check for driver type based on /dev/fb type and if valid, use it instead of PCI bus probe results */ - if (xf86Info.consoleFd >= 0) { + if (xf86Info.consoleFd >= 0 && (i < (nmatches - 1))) { struct vis_identifier visid; const char *cp; int iret; @@ -261,7 +240,7 @@ listPossibleVideoDrivers(XF86MatchedDrivers *md) /* Special case from before the general case was set */ if (strcmp(visid.name, "NVDAnvda") == 0) { - xf86AddMatchedDriver(md, "nvidia"); + matches[i++] = xnfstrdup("nvidia"); } /* General case - split into vendor name (initial all-caps @@ -271,48 +250,55 @@ listPossibleVideoDrivers(XF86MatchedDrivers *md) /* find end of all uppercase vendor section */ } if ((cp != visid.name) && (*cp != '\0')) { + char *driverName = xnfstrdup(cp); char *vendorName = xnfstrdup(visid.name); vendorName[cp - visid.name] = '\0'; - xf86AddMatchedDriver(md, vendorName); - xf86AddMatchedDriver(md, cp); - - free(vendorName); + matches[i++] = vendorName; + matches[i++] = driverName; } } } } #endif #ifdef __sparc__ - char *sbusDriver = sparcDriverName(); + if (i < (nmatches - 1)) + { + char *sbusDriver = sparcDriverName(); - if (sbusDriver) - xf86AddMatchedDriver(md, sbusDriver); + if (sbusDriver) + matches[i++] = xnfstrdup(sbusDriver); + } #endif #ifdef XSERVER_LIBPCIACCESS - xf86PciMatchDriver(md); + if (i < (nmatches - 1)) + i += xf86PciMatchDriver(&matches[i], nmatches - i); #endif #if defined(__linux__) - xf86AddMatchedDriver(md, "modesetting"); + matches[i++] = xnfstrdup("modesetting"); #endif #if !defined(__sun) /* Fallback to platform default frame buffer driver */ + if (i < (nmatches - 1)) { #if !defined(__linux__) && defined(__sparc__) - xf86AddMatchedDriver(md, "wsfb"); + matches[i++] = xnfstrdup("wsfb"); #else - xf86AddMatchedDriver(md, "fbdev"); + matches[i++] = xnfstrdup("fbdev"); #endif + } #endif /* !__sun */ /* Fallback to platform default hardware */ + if (i < (nmatches - 1)) { #if defined(__i386__) || defined(__amd64__) || defined(__hurd__) - xf86AddMatchedDriver(md, "vesa"); + matches[i++] = xnfstrdup("vesa"); #elif defined(__sparc__) && !defined(__sun) - xf86AddMatchedDriver(md, "sunffb"); + matches[i++] = xnfstrdup("sunffb"); #endif + } } /* copy a screen section and enter the desired driver @@ -358,8 +344,8 @@ GDevPtr autoConfigDevice(GDevPtr preconf_device) { GDevPtr ptr = NULL; - XF86MatchedDrivers md; - int num_screens = 0, i; + char *matches[20]; /* If we have more than 20 drivers we're in trouble */ + int num_matches = 0, num_screens = 0, i; screenLayoutPtr slp; if (!xf86configptr) { @@ -386,10 +372,10 @@ autoConfigDevice(GDevPtr preconf_device) } if (!ptr->driver) { /* get all possible video drivers and count them */ - listPossibleVideoDrivers(&md); - for (i = 0; i < md.nmatches; i++) { + listPossibleVideoDrivers(matches, 20); + for (; matches[num_matches]; num_matches++) { xf86Msg(X_DEFAULT, "Matched %s as autoconfigured driver %d\n", - md.matches[i], i); + matches[num_matches], num_matches); } slp = xf86ConfigLayout.screens; @@ -399,12 +385,12 @@ autoConfigDevice(GDevPtr preconf_device) * minus one for the already existing first one * plus one for the terminating NULL */ for (; slp[num_screens].screen; num_screens++); - xf86ConfigLayout.screens = xnfcalloc(num_screens + md.nmatches, + xf86ConfigLayout.screens = xnfcalloc(num_screens + num_matches, sizeof(screenLayoutRec)); xf86ConfigLayout.screens[0] = slp[0]; /* do the first match and set that for the original first screen */ - ptr->driver = md.matches[0]; + ptr->driver = matches[0]; if (!xf86ConfigLayout.screens[0].screen->device) { xf86ConfigLayout.screens[0].screen->device = ptr; ptr->myScreenSection = xf86ConfigLayout.screens[0].screen; @@ -412,8 +398,8 @@ autoConfigDevice(GDevPtr preconf_device) /* for each other driver found, copy the first screen, insert it * into the list of screens and set the driver */ - while (i++ < md.nmatches) { - if (!copyScreen(slp[0].screen, ptr, i, md.matches[i])) + for (i = 1; i < num_matches; i++) { + if (!copyScreen(slp[0].screen, ptr, i, matches[i])) return NULL; } @@ -422,17 +408,19 @@ autoConfigDevice(GDevPtr preconf_device) * * TODO Handle rest of multiple screen sections */ for (i = 1; i < num_screens; i++) { - xf86ConfigLayout.screens[i + md.nmatches] = slp[i]; + xf86ConfigLayout.screens[i + num_matches] = slp[i]; } - xf86ConfigLayout.screens[num_screens + md.nmatches - 1].screen = + xf86ConfigLayout.screens[num_screens + num_matches - 1].screen = NULL; free(slp); } else { /* layout does not have any screens, not much to do */ - ptr->driver = md.matches[0]; - for (i = 1; i < md.nmatches; i++) { - free(md.matches[i]); + ptr->driver = matches[0]; + for (i = 1; matches[i]; i++) { + if (matches[i] != matches[0]) { + free(matches[i]); + } } } } diff --git a/hw/xfree86/common/xf86MatchDrivers.h b/hw/xfree86/common/xf86MatchDrivers.h deleted file mode 100644 index 4663af478..000000000 --- a/hw/xfree86/common/xf86MatchDrivers.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright © 2015 NVIDIA Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#ifndef _xf86_match_drivers_h -#define _xf86_match_drivers_h - -#define MATCH_DRIVERS_LIMIT 20 - -typedef struct _XF86MatchedDrivers { - char *matches[MATCH_DRIVERS_LIMIT]; - int nmatches; -} XF86MatchedDrivers; - -/* - * prototypes - */ -void xf86AddMatchedDriver(XF86MatchedDrivers *, const char *); - -#endif /* _xf86_match_drivers_h */ - diff --git a/hw/xfree86/common/xf86pciBus.c b/hw/xfree86/common/xf86pciBus.c index 0d0a76bc8..41460a0f8 100644 --- a/hw/xfree86/common/xf86pciBus.c +++ b/hw/xfree86/common/xf86pciBus.c @@ -1063,8 +1063,9 @@ xf86ConfigPciEntity(ScrnInfoPtr pScrn, int scrnFlag, int entityIndex, return pScrn; } -void -xf86VideoPtrToDriverList(struct pci_device *dev, XF86MatchedDrivers *md) +int +xf86VideoPtrToDriverList(struct pci_device *dev, + char *returnList[], int returnListMax) { int i; @@ -1267,9 +1268,10 @@ xf86VideoPtrToDriverList(struct pci_device *dev, XF86MatchedDrivers *md) default: break; } - for (i = 0; driverList[i] != NULL; i++) { - xf86AddMatchedDriver(md, driverList[i]); + for (i = 0; (i < returnListMax) && (driverList[i] != NULL); i++) { + returnList[i] = xnfstrdup(driverList[i]); } + return i; /* Number of entries added */ } #ifdef __linux__ @@ -1293,23 +1295,23 @@ xchomp(char *line) * 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 * scheme should be the primary one */ -void +int xf86MatchDriverFromFiles(uint16_t match_vendor, uint16_t match_chip, - XF86MatchedDrivers *md) + char *matches[], int nmatches) { DIR *idsdir; FILE *fp; struct dirent *direntry; - char *line = NULL, *tmpMatch; + char *line = NULL; size_t len; ssize_t read; char path_name[256], vendor_str[5], chip_str[5]; uint16_t vendor, chip; - int j; + int i = 0, j; idsdir = opendir(PCI_TXT_IDS_PATH); if (!idsdir) - return; + return 0; xf86Msg(X_INFO, "Scanning %s directory for additional PCI ID's supported by the drivers\n", @@ -1360,10 +1362,10 @@ xf86MatchDriverFromFiles(uint16_t match_vendor, uint16_t match_chip, } } if (vendor == match_vendor && chip == match_chip) { - tmpMatch = + matches[i] = (char *) malloc(sizeof(char) * strlen(direntry->d_name) - 3); - if (!tmpMatch) { + if (!matches[i]) { xf86Msg(X_ERROR, "Could not allocate space for the module name. Exiting.\n"); goto end; @@ -1373,17 +1375,16 @@ xf86MatchDriverFromFiles(uint16_t match_vendor, uint16_t match_chip, * taking off anything after the first '.' */ for (j = 0; j < (strlen(direntry->d_name) - 3); j++) { if (direntry->d_name[j] == '.') { - tmpMatch[j] = '\0'; + matches[i][j] = '\0'; break; } else { - tmpMatch[j] = direntry->d_name[j]; + matches[i][j] = direntry->d_name[j]; } } - xf86AddMatchedDriver(md, tmpMatch); xf86Msg(X_INFO, "Matched %s from file name %s\n", - tmpMatch, direntry->d_name); - free(tmpMatch); + matches[i], direntry->d_name); + i++; } } else { @@ -1397,12 +1398,18 @@ xf86MatchDriverFromFiles(uint16_t match_vendor, uint16_t match_chip, end: free(line); closedir(idsdir); + return i; } #endif /* __linux__ */ -void -xf86PciMatchDriver(XF86MatchedDrivers *md) +/** + * @return The numbers of found devices that match with the current system + * drivers. + */ +int +xf86PciMatchDriver(char *matches[], int nmatches) { + int i = 0; struct pci_device *info = NULL; struct pci_device_iterator *iter; @@ -1417,12 +1424,15 @@ xf86PciMatchDriver(XF86MatchedDrivers *md) pci_iterator_destroy(iter); #ifdef __linux__ if (info) - xf86MatchDriverFromFiles(info->vendor_id, info->device_id, md); + i += xf86MatchDriverFromFiles(info->vendor_id, info->device_id, + matches, nmatches); #endif - if (info != NULL) { - xf86VideoPtrToDriverList(info, md); + if ((info != NULL) && (i < nmatches)) { + i += xf86VideoPtrToDriverList(info, &(matches[i]), nmatches - i); } + + return i; } Bool diff --git a/hw/xfree86/common/xf86pciBus.h b/hw/xfree86/common/xf86pciBus.h index 14ae9760e..45b5a0fee 100644 --- a/hw/xfree86/common/xf86pciBus.h +++ b/hw/xfree86/common/xf86pciBus.h @@ -33,13 +33,11 @@ #ifndef _XF86_PCI_BUS_H #define _XF86_PCI_BUS_H -#include "xf86MatchDrivers.h" - void xf86PciProbe(void); Bool xf86PciAddMatchingDev(DriverPtr drvp); Bool xf86PciProbeDev(DriverPtr drvp); void xf86PciIsolateDevice(const char *argument); -void xf86PciMatchDriver(XF86MatchedDrivers *md); +int xf86PciMatchDriver(char *matches[], int nmatches); Bool xf86PciConfigure(void *busData, struct pci_device *pDev); void xf86PciConfigureNewDev(void *busData, struct pci_device *pVideo, GDevRec * GDev, int *chipset); @@ -49,9 +47,10 @@ void xf86PciConfigureNewDev(void *busData, struct pci_device *pVideo, ((x)->func == (y)->func) && \ ((x)->dev == (y)->dev)) -void +int xf86MatchDriverFromFiles(uint16_t match_vendor, uint16_t match_chip, - XF86MatchedDrivers *md); -void -xf86VideoPtrToDriverList(struct pci_device *dev, XF86MatchedDrivers *md); + char *matches[], int nmatches); +int +xf86VideoPtrToDriverList(struct pci_device *dev, + char *returnList[], int returnListMax); #endif /* _XF86_PCI_BUS_H */ diff --git a/hw/xfree86/common/xf86platformBus.c b/hw/xfree86/common/xf86platformBus.c index 844bf7e93..0b5795fe7 100644 --- a/hw/xfree86/common/xf86platformBus.c +++ b/hw/xfree86/common/xf86platformBus.c @@ -219,10 +219,14 @@ OutputClassMatches(const XF86ConfOutputClassPtr oclass, return TRUE; } -static void -xf86OutputClassDriverList(int index, XF86MatchedDrivers *md) +static int +xf86OutputClassDriverList(int index, char *matches[], int nmatches) { XF86ConfOutputClassPtr cl; + int i = 0; + + if (nmatches == 0) + return 0; for (cl = xf86configptr->conf_outputclass_lst; cl; cl = cl->list.next) { if (OutputClassMatches(cl, &xf86_platform_devices[index])) { @@ -232,19 +236,24 @@ xf86OutputClassDriverList(int index, XF86MatchedDrivers *md) cl->identifier, path); xf86Msg(X_NONE, "\tloading driver: %s\n", cl->driver); - xf86AddMatchedDriver(md, cl->driver); + matches[i++] = xstrdup(cl->driver); } + + if (i >= nmatches) + break; } + + return i; } /** * @return The numbers of found devices that match with the current system * drivers. */ -void -xf86PlatformMatchDriver(XF86MatchedDrivers *md) +int +xf86PlatformMatchDriver(char *matches[], int nmatches) { - int i; + int i, j = 0; struct pci_device *info = NULL; int pass = 0; @@ -256,19 +265,21 @@ xf86PlatformMatchDriver(XF86MatchedDrivers *md) else if (!xf86IsPrimaryPlatform(&xf86_platform_devices[i]) && (pass == 0)) continue; - xf86OutputClassDriverList(i, md); + j += xf86OutputClassDriverList(i, &matches[j], nmatches - j); info = xf86_platform_devices[i].pdev; #ifdef __linux__ if (info) - xf86MatchDriverFromFiles(info->vendor_id, info->device_id, md); + j += xf86MatchDriverFromFiles(info->vendor_id, info->device_id, + &matches[j], nmatches - j); #endif - if (info != NULL) { - xf86VideoPtrToDriverList(info, md); + if ((info != NULL) && (j < nmatches)) { + j += xf86VideoPtrToDriverList(info, &(matches[j]), nmatches - j); } } } + return j; } int diff --git a/hw/xfree86/common/xf86platformBus.h b/hw/xfree86/common/xf86platformBus.h index 1e75e6352..70d9ec888 100644 --- a/hw/xfree86/common/xf86platformBus.h +++ b/hw/xfree86/common/xf86platformBus.h @@ -25,7 +25,6 @@ #define XF86_PLATFORM_BUS_H #include "hotplug.h" -#include "xf86MatchDrivers.h" struct xf86_platform_device { struct OdevAttributes *attribs; @@ -154,8 +153,8 @@ _xf86_get_platform_device_int_attrib(struct xf86_platform_device *device, int at extern _X_EXPORT Bool xf86PlatformDeviceCheckBusID(struct xf86_platform_device *device, const char *busid); -extern _X_EXPORT void -xf86PlatformMatchDriver(XF86MatchedDrivers *); +extern _X_EXPORT int +xf86PlatformMatchDriver(char *matches[], int nmatches); extern void xf86platformVTProbe(void); extern void xf86platformPrimary(void); |