[PATCH v2 xserver 3/4] dri2: refine dri2_probe_driver_name (v2)

2017-01-10 Thread Qiang Yu
V2:
1. update comment
2. check bustype if PCI
3. configure add libdrm version check for drmGetDevice

Get PCI information from info->fd with drmGetDevice instead of
assuming the info->fd is the first entity of scrn which is not
true for multi entities scrn.

Signed-off-by: Qiang Yu 
---
 configure.ac   |  7 ++-
 hw/xfree86/dri2/dri2.c | 43 ---
 2 files changed, 30 insertions(+), 20 deletions(-)

diff --git a/configure.ac b/configure.ac
index 93c81a6..a2de471 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1340,7 +1340,12 @@ AM_CONDITIONAL(DRI3, test "x$DRI3" = xyes)
 if test "x$DRI" = xyes || test "x$DRI2" = xyes || test "x$DRI3" = xyes || test 
"x$CONFIG_UDEV_KMS" = xyes; then
if test "x$DRM" = xyes; then
AC_DEFINE(WITH_LIBDRM, 1, [Building with libdrm support])
-   PKG_CHECK_MODULES([LIBDRM], $LIBDRM)
+   if test "x$DRI2" = xyes; then
+   dnl 2.4.65 is required for drmGetDevice
+   PKG_CHECK_MODULES([LIBDRM], libdrm >= 2.4.65)
+   else
+   PKG_CHECK_MODULES([LIBDRM], $LIBDRM)
+   fi
fi
 fi
 
diff --git a/hw/xfree86/dri2/dri2.c b/hw/xfree86/dri2/dri2.c
index 2165603..f9f9859 100644
--- a/hw/xfree86/dri2/dri2.c
+++ b/hw/xfree86/dri2/dri2.c
@@ -1440,21 +1440,17 @@ get_prime_id(void)
 static char *
 dri2_probe_driver_name(ScreenPtr pScreen, DRI2InfoPtr info)
 {
-ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
-EntityInfoPtr pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
-struct pci_device *pdev = NULL;
+#ifdef WITH_LIBDRM
 int i, j;
+char *driver = NULL;
+drmDevicePtr dev;
 
-if (pEnt)
-pdev = xf86GetPciInfoForEntity(pEnt->index);
-
-/* For non-PCI devices, just assume that the 3D driver is named
- * the same as the kernel driver.  This is currently true for vc4
- * and msm (freedreno).
+/* For non-PCI devices and drmGetDevice fail, just assume that
+ * the 3D driver is named the same as the kernel driver. This is
+ * currently true for vc4 and msm (freedreno).
  */
-if (!pdev) {
+if (drmGetDevice(info->fd, ) || dev->bustype != DRM_BUS_PCI) {
 drmVersionPtr version = drmGetVersion(info->fd);
-char *kernel_driver;
 
 if (!version) {
 xf86DrvMsg(pScreen->myNum, X_ERROR,
@@ -1463,29 +1459,38 @@ dri2_probe_driver_name(ScreenPtr pScreen, DRI2InfoPtr 
info)
 return NULL;
 }
 
-kernel_driver = strndup(version->name, version->name_len);
+driver = strndup(version->name, version->name_len);
 drmFreeVersion(version);
-return kernel_driver;
+return driver;
 }
 
 for (i = 0; driver_map[i].driver; i++) {
-if (pdev->vendor_id != driver_map[i].vendor_id)
+if (dev->deviceinfo.pci->vendor_id != driver_map[i].vendor_id)
 continue;
 
-if (driver_map[i].num_chips_ids == -1)
-return strdup(driver_map[i].driver);
+if (driver_map[i].num_chips_ids == -1) {
+ driver = strdup(driver_map[i].driver);
+ goto out;
+}
 
 for (j = 0; j < driver_map[i].num_chips_ids; j++) {
-if (driver_map[i].chip_ids[j] == pdev->device_id)
-return strdup(driver_map[i].driver);
+if (driver_map[i].chip_ids[j] == dev->deviceinfo.pci->device_id) {
+driver = strdup(driver_map[i].driver);
+goto out;
+}
 }
 }
 
 xf86DrvMsg(pScreen->myNum, X_ERROR,
"[DRI2] No driver mapping found for PCI device "
"0x%04x / 0x%04x\n",
-   pdev->vendor_id, pdev->device_id);
+   dev->deviceinfo.pci->vendor_id, dev->deviceinfo.pci->device_id);
+out:
+drmFreeDevice();
+return driver;
+#else
 return NULL;
+#endif
 }
 
 Bool
-- 
2.7.4

___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

Re: [PATCH xserver 0/4] some bug fix and improvement

2017-01-10 Thread Peter Hutterer
On Tue, Jan 10, 2017 at 06:51:53PM +0800, Qiang Yu wrote:
> FYI. Found when MS_ALL_IN_ONE work.
> 
> Qiang Yu (4):
>   xfree86: fix wrong usage of xf86optionListMerge
>   randr: fix xserver crash when xrandr setprovideroutputsource
>   modesetting: cleanup pci device open

these ones  pushed as e473b2b..436da93  master -> master, thanks

Cheers,
   Peter

> 
>   dri2: refine dri2_probe_driver_name

>  hw/xfree86/common/xf86Option.c  |  2 +-
>  hw/xfree86/dri2/dri2.c  | 35 
> +
>  hw/xfree86/drivers/modesetting/driver.c | 24 +++---
>  hw/xfree86/drivers/modesetting/driver.h |  6 --
>  randr/rrprovider.c  |  3 +++
>  5 files changed, 33 insertions(+), 37 deletions(-)
> 
> -- 
> 2.7.4
> 
> ___
> xorg-devel@lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: https://lists.x.org/mailman/listinfo/xorg-devel
> 
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

Re: [PATCH xserver 3/4] dri2: refine dri2_probe_driver_name

2017-01-10 Thread Emil Velikov
Hi Yu, Qiang,

Can I interest you in fixing your email client or using one that
supports inline quoting ?

On 10 January 2017 at 14:07, Yu, Qiang  wrote:
>
> Hi Emil,
>
>>  /* For non-PCI devices, just assume that the 3D driver is named
>>   * the same as the kernel driver.  This is currently true for vc4
>>   * and msm (freedreno).
>>   */
>> -if (!pdev) {
>> +if (drmGetDevice(info->fd, )) {
> This does not align with the comment above. Bail out in the [very]
> unlikely case that the function fails.
> Then honour _drmDevice::bustype for the respective PCI vs other case(s).
> [yuq] Yes, seems drmGetDevice only support PCI devices, non-PCI device just 
> return error.
> I can't separate the normal error and non-PCI device error here. So when 
> normal error, just
> assume non-PCI device and use drmGetVersion.
>
On second thought - using drmGetVersion() in the case of any error is
reasonable. We need to make sure that we also use it in the
_drmDevice::bustype != DRM_BUS_PCI case.

>>  drmVersionPtr version = drmGetVersion(info->fd);
>> -char *kernel_driver;
>>
>>  if (!version) {
>>  xf86DrvMsg(pScreen->myNum, X_ERROR,
>> @@ -1463,29 +1458,35 @@ dri2_probe_driver_name(ScreenPtr pScreen, 
>> DRI2InfoPtr info)
>>  return NULL;
>>  }
>>
>> -kernel_driver = strndup(version->name, version->name_len);
>> +driver = strndup(version->name, version->name_len);
>>  drmFreeVersion(version);
>> -return kernel_driver;
>> +return driver;
>>  }
>>
>>  for (i = 0; driver_map[i].driver; i++) {
>> -if (pdev->vendor_id != driver_map[i].vendor_id)
>> +if (dev->deviceinfo.pci->vendor_id != driver_map[i].vendor_id)
> ... or in other words.
> This will cause a _lot_ of grief as we merge Thierry's work to support
> !PCI devices.
> [yuq] Then Thierry's work is useful for the problem above. It's better to wait
> for his work upstream and bump the xserver libdrm depend version.
>
Retrieving device information (vendor/device id, other) is orthogonal
to how that is mapped to the "driver_name",
So I won't worry about that ... considering we correctly check the bustype.

Thanks
Emil
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

Re: [PATCH xserver 4/4] modesetting: cleanup pci device open

2017-01-10 Thread Hans de Goede

Hi,

On 10-01-17 11:51, Qiang Yu wrote:

Signed-off-by: Qiang Yu 



Patch looks good to me:

Reviewed-by: Hans de Goede 

Regards,

Hans





---
 hw/xfree86/drivers/modesetting/driver.c | 24 +++-
 hw/xfree86/drivers/modesetting/driver.h |  6 --
 2 files changed, 11 insertions(+), 19 deletions(-)

diff --git a/hw/xfree86/drivers/modesetting/driver.c 
b/hw/xfree86/drivers/modesetting/driver.c
index a27b327..d7030e5 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -812,7 +812,6 @@ ms_get_drm_master_fd(ScrnInfoPtr pScrn)
 EntityInfoPtr pEnt;
 modesettingPtr ms;
 modesettingEntPtr ms_ent;
-char *BusID = NULL;

 ms = modesettingPTR(pScrn);
 ms_ent = ms_ent_priv(pScrn);
@@ -845,25 +844,24 @@ ms_get_drm_master_fd(ScrnInfoPtr pScrn)
 }
 else
 #endif
+#if XSERVER_LIBPCIACCESS
 if (pEnt->location.type == BUS_PCI) {
-ms->PciInfo = xf86GetPciInfoForEntity(ms->pEnt->index);
-if (ms->PciInfo) {
+char *BusID = NULL;
+struct pci_device *PciInfo;
+
+PciInfo = xf86GetPciInfoForEntity(ms->pEnt->index);
+if (PciInfo) {
 BusID = XNFalloc(64);
 sprintf(BusID, "PCI:%d:%d:%d",
-#if XSERVER_LIBPCIACCESS
-((ms->PciInfo->domain << 8) | ms->PciInfo->bus),
-ms->PciInfo->dev, ms->PciInfo->func
-#else
-((pciConfigPtr) ms->PciInfo->thisCard)->busnum,
-((pciConfigPtr) ms->PciInfo->thisCard)->devnum,
-((pciConfigPtr) ms->PciInfo->thisCard)->funcnum
-#endif
-);
+((PciInfo->domain << 8) | PciInfo->bus),
+PciInfo->dev, PciInfo->func);
 }
 ms->fd = drmOpen(NULL, BusID);
 free(BusID);
 }
-else {
+else
+#endif
+{
 const char *devicename;
 devicename = xf86FindOptionValue(ms->pEnt->device->options, "kmsdev");
 ms->fd = open_hw(devicename);
diff --git a/hw/xfree86/drivers/modesetting/driver.h 
b/hw/xfree86/drivers/modesetting/driver.h
index eee96e5..25e3a54 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -89,12 +89,6 @@ typedef struct _modesettingRec {

 int Chipset;
 EntityInfoPtr pEnt;
-#if XSERVER_LIBPCIACCESS
-struct pci_device *PciInfo;
-#else
-pciVideoPtr PciInfo;
-PCITAG PciTag;
-#endif

 Bool noAccel;
 CloseScreenProcPtr CloseScreen;


___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

Re: [PATCH xserver 2/4] randr: fix xserver crash when xrandr setprovideroutputsource

2017-01-10 Thread Hans de Goede

Hi,

On 10-01-17 11:51, Qiang Yu wrote:

xrandr --setprovideroutputsource  
Xorg: ../../../xserver/dix/dispatch.c:4018: AttachOutputGPU:
Assertion `new->isGPU' failed.

GPUScreen is not allowed to be sink output.

Signed-off-by: Qiang Yu 



Patch looks good to me:

Reviewed-by: Hans de Goede 

Regards,

Hans





---
 randr/rrprovider.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/randr/rrprovider.c b/randr/rrprovider.c
index f9df67e..e4bc2bf 100644
--- a/randr/rrprovider.c
+++ b/randr/rrprovider.c
@@ -338,6 +338,9 @@ ProcRRSetProviderOutputSource(ClientPtr client)
 pScreen = provider->pScreen;
 pScrPriv = rrGetScrPriv(pScreen);

+if (!pScreen->isGPU)
+return BadValue;
+
 pScrPriv->rrProviderSetOutputSource(pScreen, provider, source_provider);

 RRInitPrimeSyncProps(pScreen);


___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

Re: [PATCH xserver 1/4] xfree86: fix wrong usage of xf86optionListMerge

2017-01-10 Thread Hans de Goede

Hi,

On 10-01-17 11:51, Qiang Yu wrote:

Signed-off-by: Qiang Yu 


Patch looks good to me:

Reviewed-by: Hans de Goede 

Regards,

Hans



---
 hw/xfree86/common/xf86Option.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/xfree86/common/xf86Option.c b/hw/xfree86/common/xf86Option.c
index 929724d..06973bc 100644
--- a/hw/xfree86/common/xf86Option.c
+++ b/hw/xfree86/common/xf86Option.c
@@ -87,7 +87,7 @@ xf86CollectOptions(ScrnInfoPtr pScrn, XF86OptionPtr extraOpts)
 if (device && device->options) {
 tmp = xf86optionListDup(device->options);
 if (pScrn->options)
-xf86optionListMerge(pScrn->options, tmp);
+pScrn->options = xf86optionListMerge(pScrn->options, tmp);
 else
 pScrn->options = tmp;
 }


___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

Re: [tigervnc-devel] PATCH: Add xorg-xserver 1.19 support to tigervnc

2017-01-10 Thread Pierre Ossman

On 09/01/17 20:15, Hans de Goede wrote:


Yes I agree that would be better, Pierre, can you take care
of merging Alan's improved version ?



All done and available on master now. Thanks for fixing this.

Regards
--
Pierre Ossman   Software Development
Cendio AB   https://cendio.com
Teknikringen 8  https://twitter.com/ThinLinc
583 30 Linköpinghttps://facebook.com/ThinLinc
Phone: +46-13-214600https://plus.google.com/+CendioThinLinc

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

Re: [PATCH xserver 3/4] dri2: refine dri2_probe_driver_name

2017-01-10 Thread Yu, Qiang

Hi Emil,

>  /* For non-PCI devices, just assume that the 3D driver is named
>   * the same as the kernel driver.  This is currently true for vc4
>   * and msm (freedreno).
>   */
> -if (!pdev) {
> +if (drmGetDevice(info->fd, )) {
This does not align with the comment above. Bail out in the [very]
unlikely case that the function fails.
Then honour _drmDevice::bustype for the respective PCI vs other case(s).
[yuq] Yes, seems drmGetDevice only support PCI devices, non-PCI device just 
return error.
I can't separate the normal error and non-PCI device error here. So when normal 
error, just
assume non-PCI device and use drmGetVersion.

>  drmVersionPtr version = drmGetVersion(info->fd);
> -char *kernel_driver;
>
>  if (!version) {
>  xf86DrvMsg(pScreen->myNum, X_ERROR,
> @@ -1463,29 +1458,35 @@ dri2_probe_driver_name(ScreenPtr pScreen, DRI2InfoPtr 
> info)
>  return NULL;
>  }
>
> -kernel_driver = strndup(version->name, version->name_len);
> +driver = strndup(version->name, version->name_len);
>  drmFreeVersion(version);
> -return kernel_driver;
> +return driver;
>  }
>
>  for (i = 0; driver_map[i].driver; i++) {
> -if (pdev->vendor_id != driver_map[i].vendor_id)
> +if (dev->deviceinfo.pci->vendor_id != driver_map[i].vendor_id)
... or in other words.
This will cause a _lot_ of grief as we merge Thierry's work to support
!PCI devices.
[yuq] Then Thierry's work is useful for the problem above. It's better to wait
for his work upstream and bump the xserver libdrm depend version.

Regards,
Qiang
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

Re: [PATCH xserver 3/4] dri2: refine dri2_probe_driver_name

2017-01-10 Thread Emil Velikov
On 10 January 2017 at 10:51, Qiang Yu  wrote:
> Get PCI information from info->fd with drmGetDevice instead of
> assuming the info->fd is the first entity of scrn which is not
> true for multi entities scrn.
>
IIRC you want to bump the libdrm version in configure to one that
provides the API.

> Signed-off-by: Qiang Yu 
> ---
>  hw/xfree86/dri2/dri2.c | 35 ++-
>  1 file changed, 18 insertions(+), 17 deletions(-)
>
> diff --git a/hw/xfree86/dri2/dri2.c b/hw/xfree86/dri2/dri2.c
> index 2165603..adc59a6 100644
> --- a/hw/xfree86/dri2/dri2.c
> +++ b/hw/xfree86/dri2/dri2.c
> @@ -1440,21 +1440,16 @@ get_prime_id(void)
>  static char *
>  dri2_probe_driver_name(ScreenPtr pScreen, DRI2InfoPtr info)
>  {
> -ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
> -EntityInfoPtr pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
> -struct pci_device *pdev = NULL;
>  int i, j;
> -
> -if (pEnt)
> -pdev = xf86GetPciInfoForEntity(pEnt->index);
> +char *driver = NULL;
> +drmDevicePtr dev;
>
>  /* For non-PCI devices, just assume that the 3D driver is named
>   * the same as the kernel driver.  This is currently true for vc4
>   * and msm (freedreno).
>   */
> -if (!pdev) {
> +if (drmGetDevice(info->fd, )) {
This does not align with the comment above. Bail out in the [very]
unlikely case that the function fails.
Then honour _drmDevice::bustype for the respective PCI vs other case(s).

>  drmVersionPtr version = drmGetVersion(info->fd);
> -char *kernel_driver;
>
>  if (!version) {
>  xf86DrvMsg(pScreen->myNum, X_ERROR,
> @@ -1463,29 +1458,35 @@ dri2_probe_driver_name(ScreenPtr pScreen, DRI2InfoPtr 
> info)
>  return NULL;
>  }
>
> -kernel_driver = strndup(version->name, version->name_len);
> +driver = strndup(version->name, version->name_len);
>  drmFreeVersion(version);
> -return kernel_driver;
> +return driver;
>  }
>
>  for (i = 0; driver_map[i].driver; i++) {
> -if (pdev->vendor_id != driver_map[i].vendor_id)
> +if (dev->deviceinfo.pci->vendor_id != driver_map[i].vendor_id)
... or in other words.
This will cause a _lot_ of grief as we merge Thierry's work to support
!PCI devices.

Thanks
Emil
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

[PATCH xserver 2/4] randr: fix xserver crash when xrandr setprovideroutputsource

2017-01-10 Thread Qiang Yu
xrandr --setprovideroutputsource  
Xorg: ../../../xserver/dix/dispatch.c:4018: AttachOutputGPU:
Assertion `new->isGPU' failed.

GPUScreen is not allowed to be sink output.

Signed-off-by: Qiang Yu 
---
 randr/rrprovider.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/randr/rrprovider.c b/randr/rrprovider.c
index f9df67e..e4bc2bf 100644
--- a/randr/rrprovider.c
+++ b/randr/rrprovider.c
@@ -338,6 +338,9 @@ ProcRRSetProviderOutputSource(ClientPtr client)
 pScreen = provider->pScreen;
 pScrPriv = rrGetScrPriv(pScreen);
 
+if (!pScreen->isGPU)
+return BadValue;
+
 pScrPriv->rrProviderSetOutputSource(pScreen, provider, source_provider);
 
 RRInitPrimeSyncProps(pScreen);
-- 
2.7.4

___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

[PATCH xserver 0/4] some bug fix and improvement

2017-01-10 Thread Qiang Yu
FYI. Found when MS_ALL_IN_ONE work.

Qiang Yu (4):
  xfree86: fix wrong usage of xf86optionListMerge
  randr: fix xserver crash when xrandr setprovideroutputsource
  dri2: refine dri2_probe_driver_name
  modesetting: cleanup pci device open

 hw/xfree86/common/xf86Option.c  |  2 +-
 hw/xfree86/dri2/dri2.c  | 35 +
 hw/xfree86/drivers/modesetting/driver.c | 24 +++---
 hw/xfree86/drivers/modesetting/driver.h |  6 --
 randr/rrprovider.c  |  3 +++
 5 files changed, 33 insertions(+), 37 deletions(-)

-- 
2.7.4

___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

[PATCH xserver 1/4] xfree86: fix wrong usage of xf86optionListMerge

2017-01-10 Thread Qiang Yu
Signed-off-by: Qiang Yu 
---
 hw/xfree86/common/xf86Option.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/xfree86/common/xf86Option.c b/hw/xfree86/common/xf86Option.c
index 929724d..06973bc 100644
--- a/hw/xfree86/common/xf86Option.c
+++ b/hw/xfree86/common/xf86Option.c
@@ -87,7 +87,7 @@ xf86CollectOptions(ScrnInfoPtr pScrn, XF86OptionPtr extraOpts)
 if (device && device->options) {
 tmp = xf86optionListDup(device->options);
 if (pScrn->options)
-xf86optionListMerge(pScrn->options, tmp);
+pScrn->options = xf86optionListMerge(pScrn->options, tmp);
 else
 pScrn->options = tmp;
 }
-- 
2.7.4

___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

[PATCH xserver 4/4] modesetting: cleanup pci device open

2017-01-10 Thread Qiang Yu
Signed-off-by: Qiang Yu 
---
 hw/xfree86/drivers/modesetting/driver.c | 24 +++-
 hw/xfree86/drivers/modesetting/driver.h |  6 --
 2 files changed, 11 insertions(+), 19 deletions(-)

diff --git a/hw/xfree86/drivers/modesetting/driver.c 
b/hw/xfree86/drivers/modesetting/driver.c
index a27b327..d7030e5 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -812,7 +812,6 @@ ms_get_drm_master_fd(ScrnInfoPtr pScrn)
 EntityInfoPtr pEnt;
 modesettingPtr ms;
 modesettingEntPtr ms_ent;
-char *BusID = NULL;
 
 ms = modesettingPTR(pScrn);
 ms_ent = ms_ent_priv(pScrn);
@@ -845,25 +844,24 @@ ms_get_drm_master_fd(ScrnInfoPtr pScrn)
 }
 else
 #endif
+#if XSERVER_LIBPCIACCESS
 if (pEnt->location.type == BUS_PCI) {
-ms->PciInfo = xf86GetPciInfoForEntity(ms->pEnt->index);
-if (ms->PciInfo) {
+char *BusID = NULL;
+struct pci_device *PciInfo;
+
+PciInfo = xf86GetPciInfoForEntity(ms->pEnt->index);
+if (PciInfo) {
 BusID = XNFalloc(64);
 sprintf(BusID, "PCI:%d:%d:%d",
-#if XSERVER_LIBPCIACCESS
-((ms->PciInfo->domain << 8) | ms->PciInfo->bus),
-ms->PciInfo->dev, ms->PciInfo->func
-#else
-((pciConfigPtr) ms->PciInfo->thisCard)->busnum,
-((pciConfigPtr) ms->PciInfo->thisCard)->devnum,
-((pciConfigPtr) ms->PciInfo->thisCard)->funcnum
-#endif
-);
+((PciInfo->domain << 8) | PciInfo->bus),
+PciInfo->dev, PciInfo->func);
 }
 ms->fd = drmOpen(NULL, BusID);
 free(BusID);
 }
-else {
+else
+#endif
+{
 const char *devicename;
 devicename = xf86FindOptionValue(ms->pEnt->device->options, "kmsdev");
 ms->fd = open_hw(devicename);
diff --git a/hw/xfree86/drivers/modesetting/driver.h 
b/hw/xfree86/drivers/modesetting/driver.h
index eee96e5..25e3a54 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -89,12 +89,6 @@ typedef struct _modesettingRec {
 
 int Chipset;
 EntityInfoPtr pEnt;
-#if XSERVER_LIBPCIACCESS
-struct pci_device *PciInfo;
-#else
-pciVideoPtr PciInfo;
-PCITAG PciTag;
-#endif
 
 Bool noAccel;
 CloseScreenProcPtr CloseScreen;
-- 
2.7.4

___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

[PATCH xserver 3/4] dri2: refine dri2_probe_driver_name

2017-01-10 Thread Qiang Yu
Get PCI information from info->fd with drmGetDevice instead of
assuming the info->fd is the first entity of scrn which is not
true for multi entities scrn.

Signed-off-by: Qiang Yu 
---
 hw/xfree86/dri2/dri2.c | 35 ++-
 1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/hw/xfree86/dri2/dri2.c b/hw/xfree86/dri2/dri2.c
index 2165603..adc59a6 100644
--- a/hw/xfree86/dri2/dri2.c
+++ b/hw/xfree86/dri2/dri2.c
@@ -1440,21 +1440,16 @@ get_prime_id(void)
 static char *
 dri2_probe_driver_name(ScreenPtr pScreen, DRI2InfoPtr info)
 {
-ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
-EntityInfoPtr pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
-struct pci_device *pdev = NULL;
 int i, j;
-
-if (pEnt)
-pdev = xf86GetPciInfoForEntity(pEnt->index);
+char *driver = NULL;
+drmDevicePtr dev;
 
 /* For non-PCI devices, just assume that the 3D driver is named
  * the same as the kernel driver.  This is currently true for vc4
  * and msm (freedreno).
  */
-if (!pdev) {
+if (drmGetDevice(info->fd, )) {
 drmVersionPtr version = drmGetVersion(info->fd);
-char *kernel_driver;
 
 if (!version) {
 xf86DrvMsg(pScreen->myNum, X_ERROR,
@@ -1463,29 +1458,35 @@ dri2_probe_driver_name(ScreenPtr pScreen, DRI2InfoPtr 
info)
 return NULL;
 }
 
-kernel_driver = strndup(version->name, version->name_len);
+driver = strndup(version->name, version->name_len);
 drmFreeVersion(version);
-return kernel_driver;
+return driver;
 }
 
 for (i = 0; driver_map[i].driver; i++) {
-if (pdev->vendor_id != driver_map[i].vendor_id)
+if (dev->deviceinfo.pci->vendor_id != driver_map[i].vendor_id)
 continue;
 
-if (driver_map[i].num_chips_ids == -1)
-return strdup(driver_map[i].driver);
+if (driver_map[i].num_chips_ids == -1) {
+ driver = strdup(driver_map[i].driver);
+ goto out;
+}
 
 for (j = 0; j < driver_map[i].num_chips_ids; j++) {
-if (driver_map[i].chip_ids[j] == pdev->device_id)
-return strdup(driver_map[i].driver);
+if (driver_map[i].chip_ids[j] == dev->deviceinfo.pci->device_id) {
+driver = strdup(driver_map[i].driver);
+goto out;
+}
 }
 }
 
 xf86DrvMsg(pScreen->myNum, X_ERROR,
"[DRI2] No driver mapping found for PCI device "
"0x%04x / 0x%04x\n",
-   pdev->vendor_id, pdev->device_id);
-return NULL;
+   dev->deviceinfo.pci->vendor_id, dev->deviceinfo.pci->device_id);
+out:
+drmFreeDevice();
+return driver;
 }
 
 Bool
-- 
2.7.4

___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel