[Mesa-dev] [PATCHv2 10/21] targets/egl-static: do not rely on libudev on Android

Chia-I Wu olvaffe at gmail.com
Fri Aug 19 03:43:29 PDT 2011


On Fri, Aug 19, 2011 at 6:19 PM, Benjamin Franzke
<benjaminfranzke at googlemail.com> wrote:
> 2011/8/19 Chia-I Wu <olvaffe at gmail.com>:
>> On Fri, Aug 19, 2011 at 5:59 PM, Benjamin Franzke
>> <benjaminfranzke at googlemail.com> wrote:
>>> 2011/8/19 Chia-I Wu <olvaffe at gmail.com>:
>>>> There is no libudev on Android.  Use DRM to get the PCI ID directly.
>>>> ---
>>>>  src/gallium/targets/egl-static/egl.c |   62 ++++++++++++++++++++++++++++++++++
>>>>  1 files changed, 62 insertions(+), 0 deletions(-)
>>>>
>>>> diff --git a/src/gallium/targets/egl-static/egl.c b/src/gallium/targets/egl-static/egl.c
>>>> index 568f549..38ba6c2 100644
>>>> --- a/src/gallium/targets/egl-static/egl.c
>>>> +++ b/src/gallium/targets/egl-static/egl.c
>>>> @@ -109,6 +109,68 @@ out:
>>>>    return (*chip_id >= 0);
>>>>  }
>>>>
>>>> +#elif defined(PIPE_OS_ANDROID)
>>> Just want to mention that I appreciate doing this really only for android,
>>> and not as a fallback for no-libudev in general. (which would probably end up
>>> with more problems for none intel/radeon users and strange bugs..)
>> Can you elaborate?  I have no intention to make it a fallback, but I
>> am curious about the potential problems.
>
> The problem I meant is that it wouldnt work for nouveau right now, e.g. with the
> wayland or drm platforms we would endup with "failed to get driver
> name for fd ..".
IIRC, we do not need the chip id for nouveau.  We can set the vendor
id when the kernel reports nouveau.  It should work.

Anyway, this thing is made Android specific for now.

>>
>>>> +
>>>> +#include <xf86drm.h>
>>>> +/* for i915 */
>>>> +#include <i915_drm.h>
>>>> +/* for radeon */
>>>> +#include <radeon_drm.h>
>>>> +
>>>> +static boolean
>>>> +drm_fd_get_pci_id(int fd, int *vendor_id, int *chip_id)
>>>> +{
>>>> +   drmVersionPtr version;
>>>> +
>>>> +   *chip_id = -1;
>>>> +
>>>> +   version = drmGetVersion(fd);
>>>> +   if (!version) {
>>>> +      _eglLog(_EGL_WARNING, "invalid drm fd");
>>>> +      return FALSE;
>>>> +   }
>>>> +   if (!version->name) {
>>>> +      _eglLog(_EGL_WARNING, "unable to determine the driver name");
>>>> +      drmFreeVersion(version);
>>>> +      return FALSE;
>>>> +   }
>>>> +
>>>> +   if (strcmp(version->name, "i915") == 0) {
>>>
>>> Shouldnt util_strcmp from util/u_string.h be used instead?
>> Yes, will do.
>>>> +      struct drm_i915_getparam gp;
>>>> +      int ret;
>>>> +
>>>> +      *vendor_id = 0x8086;
>>>> +
>>>> +      memset(&gp, 0, sizeof(gp));
>>>> +      gp.param = I915_PARAM_CHIPSET_ID;
>>>> +      gp.value = chip_id;
>>>> +      ret = drmCommandWriteRead(fd, DRM_I915_GETPARAM, &gp, sizeof(gp));
>>>> +      if (ret) {
>>>> +         _eglLog(_EGL_WARNING, "failed to get param for i915");
>>>> +        *chip_id = -1;
>>>> +      }
>>>> +   }
>>>> +   else if (strcmp(version->name, "radeon") == 0) {
>>>> +      struct drm_radeon_info info;
>>>> +      int ret;
>>>> +
>>>> +      *vendor_id = 0x1002;
>>>> +
>>>> +      memset(&info, 0, sizeof(info));
>>>> +      info.request = RADEON_INFO_DEVICE_ID;
>>>> +      info.value = (long) chip_id;
>>>
>>> Just a little nitpick: value is of type uint64_t, so the cast should
>>> rather be to an unsigned type.
>> I will make it "unsigned long".
>>> Besides that:
>>> Reviewed-by: Benjamin Franzke <benjaminfranzke at googlemail.com>
>> Thanks.
>>>> +      ret = drmCommandWriteRead(fd, DRM_RADEON_INFO, &info, sizeof(info));
>>>> +      if (ret) {
>>>> +         _eglLog(_EGL_WARNING, "failed to get info for radeon");
>>>> +        *chip_id = -1;
>>>> +      }
>>>> +   }
>>>> +
>>>> +   drmFreeVersion(version);
>>>> +
>>>> +   return (*chip_id >= 0);
>>>> +}
>>>> +
>>>>  #else
>>>>
>>>>  static boolean
>>>> --
>>>> 1.7.5.4
>>>>
>>>> _______________________________________________
>>>> mesa-dev mailing list
>>>> mesa-dev at lists.freedesktop.org
>>>> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
>>>>
>>>
>>
>>
>>
>> --
>> olv at LunarG.com
>>
>



-- 
olv at LunarG.com


More information about the mesa-dev mailing list