[PATCH xf86-video-amdgpu 3/3] Only call amdgpu_bus_id once in each probe path

Alex Deucher alexdeucher at gmail.com
Fri Jan 8 09:33:41 PST 2016


On Fri, Jan 8, 2016 at 4:04 AM, Michel Dänzer <michel at daenzer.net> wrote:
> From: Michel Dänzer <michel.daenzer at amd.com>
>
> Instead of up to twice as before.
>
> Signed-off-by: Michel Dänzer <michel.daenzer at amd.com>

Series is:
Reviewed-by: Alex Deucher <alexander.deucher at amd.com>

> ---
>  src/amdgpu_probe.c | 52 +++++++++++++++++++++++++---------------------------
>  1 file changed, 25 insertions(+), 27 deletions(-)
>
> diff --git a/src/amdgpu_probe.c b/src/amdgpu_probe.c
> index f74eb29..ea9ffa7 100644
> --- a/src/amdgpu_probe.c
> +++ b/src/amdgpu_probe.c
> @@ -99,16 +99,10 @@ static char *amdgpu_bus_id(ScrnInfoPtr pScrn, struct pci_device *dev)
>         return busid;
>  }
>
> -static Bool amdgpu_kernel_mode_enabled(ScrnInfoPtr pScrn,
> -                                      struct pci_device *pci_dev)
> +static Bool amdgpu_kernel_mode_enabled(ScrnInfoPtr pScrn, char *busIdString)
>  {
> -       char *busIdString = amdgpu_bus_id(pScrn, pci_dev);
> -       int ret;
> +       int ret = drmCheckModesettingSupported(busIdString);
>
> -       if (!busIdString)
> -               return FALSE;
> -
> -       ret = drmCheckModesettingSupported(busIdString);
>  #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
>         if (ret) {
>                 if (xf86LoadKernelModule("amdgpukms"))
> @@ -127,10 +121,9 @@ static Bool amdgpu_kernel_mode_enabled(ScrnInfoPtr pScrn,
>         return TRUE;
>  }
>
> -static int amdgpu_kernel_open_fd(ScrnInfoPtr pScrn, struct pci_device *dev,
> +static int amdgpu_kernel_open_fd(ScrnInfoPtr pScrn, char *busid,
>                                  struct xf86_platform_device *platform_dev)
>  {
> -       char *busid;
>         int fd;
>
>  #ifdef XF86_PDEV_SERVER_FD
> @@ -142,29 +135,21 @@ static int amdgpu_kernel_open_fd(ScrnInfoPtr pScrn, struct pci_device *dev,
>         }
>  #endif
>
> -       busid = amdgpu_bus_id(pScrn, dev);
> -       if (!busid)
> -               return -1;
> -
>         fd = drmOpen(NULL, busid);
> -       if (fd == -1) {
> +       if (fd == -1)
>                 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
>                            "[drm] Failed to open DRM device for %s: %s\n",
>                            busid, strerror(errno));
> -               free(busid);
> -               return fd;
> -       }
> -       free(busid);
>         return fd;
>  }
>
>  static Bool amdgpu_open_drm_master(ScrnInfoPtr pScrn, AMDGPUEntPtr pAMDGPUEnt,
> -                                  struct pci_device *pci_dev)
> +                                  char *busid)
>  {
>         drmSetVersion sv;
>         int err;
>
> -       pAMDGPUEnt->fd = amdgpu_kernel_open_fd(pScrn, pci_dev, NULL);
> +       pAMDGPUEnt->fd = amdgpu_kernel_open_fd(pScrn, busid, NULL);
>         if (pAMDGPUEnt->fd == -1)
>                 return FALSE;
>
> @@ -190,6 +175,7 @@ static Bool amdgpu_open_drm_master(ScrnInfoPtr pScrn, AMDGPUEntPtr pAMDGPUEnt,
>  static Bool amdgpu_get_scrninfo(int entity_num, struct pci_device *pci_dev)
>  {
>         ScrnInfoPtr pScrn = NULL;
> +       char *busid;
>         EntityInfoPtr pEnt;
>         DevUnion *pPriv;
>         AMDGPUEntPtr pAMDGPUEnt;
> @@ -200,8 +186,9 @@ static Bool amdgpu_get_scrninfo(int entity_num, struct pci_device *pci_dev)
>         if (!pScrn)
>                 return FALSE;
>
> -       if (!amdgpu_kernel_mode_enabled(pScrn, pci_dev))
> -               return FALSE;
> +       busid = amdgpu_bus_id(pScrn, pci_dev);
> +       if (!amdgpu_kernel_mode_enabled(pScrn, busid))
> +               goto error;
>
>         pScrn->driverVersion = AMDGPU_VERSION_CURRENT;
>         pScrn->driverName = AMDGPU_DRIVER_NAME;
> @@ -235,10 +222,10 @@ static Bool amdgpu_get_scrninfo(int entity_num, struct pci_device *pci_dev)
>
>                 pPriv->ptr = xnfcalloc(sizeof(AMDGPUEntRec), 1);
>                 if (!pPriv->ptr)
> -                       return FALSE;
> +                       goto error;
>
>                 pAMDGPUEnt = pPriv->ptr;
> -               if (!amdgpu_open_drm_master(pScrn, pAMDGPUEnt, pci_dev))
> +               if (!amdgpu_open_drm_master(pScrn, pAMDGPUEnt, busid))
>                         goto error_fd;
>
>                 pAMDGPUEnt->fd_ref = 1;
> @@ -261,6 +248,7 @@ static Bool amdgpu_get_scrninfo(int entity_num, struct pci_device *pci_dev)
>                                                                  index)
>                                        - 1);
>         free(pEnt);
> +       free(busid);
>
>         return TRUE;
>
> @@ -268,6 +256,8 @@ error_amdgpu:
>         drmClose(pAMDGPUEnt->fd);
>  error_fd:
>         free(pPriv->ptr);
> +error:
> +       free(busid);
>         return FALSE;
>  }
>
> @@ -304,6 +294,7 @@ amdgpu_platform_probe(DriverPtr pDriver,
>  {
>         ScrnInfoPtr pScrn;
>         int scr_flags = 0;
> +       char *busid;
>         EntityInfoPtr pEnt;
>         DevUnion *pPriv;
>         AMDGPUEntPtr pAMDGPUEnt;
> @@ -319,9 +310,13 @@ amdgpu_platform_probe(DriverPtr pDriver,
>                 xf86SetEntityShared(entity_num);
>         xf86AddEntityToScreen(pScrn, entity_num);
>
> -       if (!amdgpu_kernel_mode_enabled(pScrn, dev->pdev))
> +       busid = amdgpu_bus_id(pScrn, dev->pdev);
> +       if (!busid)
>                 return FALSE;
>
> +       if (!amdgpu_kernel_mode_enabled(pScrn, busid))
> +               goto error;
> +
>         pScrn->driverVersion = AMDGPU_VERSION_CURRENT;
>         pScrn->driverName = AMDGPU_DRIVER_NAME;
>         pScrn->name = AMDGPU_NAME;
> @@ -353,7 +348,7 @@ amdgpu_platform_probe(DriverPtr pDriver,
>
>                 pPriv->ptr = xnfcalloc(sizeof(AMDGPUEntRec), 1);
>                 pAMDGPUEnt = pPriv->ptr;
> -               pAMDGPUEnt->fd = amdgpu_kernel_open_fd(pScrn, dev->pdev, dev);
> +               pAMDGPUEnt->fd = amdgpu_kernel_open_fd(pScrn, busid, dev);
>                 if (pAMDGPUEnt->fd < 0)
>                         goto error_fd;
>
> @@ -378,6 +373,7 @@ amdgpu_platform_probe(DriverPtr pDriver,
>                                                                  index)
>                                        - 1);
>         free(pEnt);
> +       free(busid);
>
>         return TRUE;
>
> @@ -385,6 +381,8 @@ error_amdgpu:
>         drmClose(pAMDGPUEnt->fd);
>  error_fd:
>         free(pPriv->ptr);
> +error:
> +       free(busid);
>         return FALSE;
>  }
>  #endif
> --
> 2.6.2
>
> _______________________________________________
> xorg-driver-ati mailing list
> xorg-driver-ati at lists.x.org
> http://lists.x.org/mailman/listinfo/xorg-driver-ati


More information about the xorg-driver-ati mailing list