From 7dc22b7911ac3d5c131075903e3fbf52c58eac15 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 9 May 2012 09:32:05 +0100 Subject: [PATCH] modesetting: make sure the pci device corresponds to the drm device If we get asked to pci open a device with a kms path override, make sure they match, otherwise this driver can steal the primary device binding for a usb adaptor. The driver should fallback to the old probe entry point in this case. Signed-off-by: Dave Airlie --- hw/xfree86/drivers/modesetting/driver.c | 35 ++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index 2c9878c61..e97715099 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -198,6 +198,39 @@ static Bool probe_hw(char *dev) return FALSE; } +static char * +ms_DRICreatePCIBusID(const struct pci_device *dev) +{ + char *busID; + + if (asprintf(&busID, "pci:%04x:%02x:%02x.%d", + dev->domain, dev->bus, dev->dev, dev->func) == -1) + return NULL; + + return busID; +} + + +static Bool probe_hw_pci(char *dev, struct pci_device *pdev) +{ + int fd = open_hw(dev); + char *id, *devid; + + if (fd == -1) + return FALSE; + + id = drmGetBusid(fd); + devid = ms_DRICreatePCIBusID(pdev); + close(fd); + + if (!id || !devid) + return FALSE; + + if (!strcmp(id, devid)) + return TRUE; + + return FALSE; +} static const OptionInfoRec * AvailableOptions(int chipid, int busid) { @@ -219,7 +252,7 @@ ms_pci_probe(DriverPtr driver, scrn->entityInstanceList[0]); devpath = xf86FindOptionValue(devSection->options, "kmsdev"); - if (probe_hw(devpath)) { + if (probe_hw_pci(devpath, dev)) { scrn->driverVersion = 1; scrn->driverName = "modesetting"; scrn->name = "modeset";