:: Re: [Dng] What to do with udev? Som…
Página Principal
Delete this message
Reply to this message
Autor: karl
Data:  
Para: dng
Assunto: Re: [Dng] What to do with udev? Some ideas...
Jude:
> I haven't read the mesa code yet, but it sounds like mesa uses udev to help
> it (1) insert the right kernel module, and (2) load the right firmware.
> udev gets its information from sysfs and/or its netlink socket, so I'd
> imagine mesa uses a similar technique with the --enable-sysfs option. Do
> you know if this is the case?

...

Seems mesa/mesa and mesa/drm doesn't care much about which of the two: udev or sysfs

$ git remote -v
origin git://anongit.freedesktop.org/git/mesa/mesa (fetch)
origin git://anongit.freedesktop.org/git/mesa/mesa (push)
$ find . -type f -name \*.c | xargs grep -i udev | cut -f1 -d: | sort -u
./src/gbm/main/gbm.c
./src/loader/loader.c
$

Just a comment:
$ grep -i udev ./src/gbm/main/gbm.c
/* FIXME: maybe superfluous, use udev subclass from the fd? */

In loader.c, most functions are static. It can probably be
summarized as (re. udev/sysfs diff.):

#if HAVE_LIBUDEV
...
int loader_get_user_preferred_fd(int default_fd, int *different_device)
non null operations...
}
#else
int loader_get_user_preferred_fd(int default_fd, int *different_device)
{
*different_device = 0;
return default_fd;
}
#endif


int
loader_get_pci_id_for_fd(int fd, int *vendor_id, int *chip_id)
{
#if HAVE_LIBUDEV
   if (libudev_get_pci_id_for_fd(fd, vendor_id, chip_id))
      return 1;
#endif
#if HAVE_SYSFS
   if (sysfs_get_pci_id_for_fd(fd, vendor_id, chip_id))
      return 1;
#endif
#if !defined(__NOT_HAVE_DRM_H)
   if (drm_get_pci_id_for_fd(fd, vendor_id, chip_id))
      return 1;
#endif
   return 0;
}



char *
loader_get_device_name_for_fd(int fd)
{
char *result = NULL;

#if HAVE_LIBUDEV
   if ((result = libudev_get_device_name_for_fd(fd)))
      return result;
#endif
#if HAVE_SYSFS
   if ((result = sysfs_get_device_name_for_fd(fd)))
      return result;
#endif
   return result;
}


///

$ git remote -v
origin git://anongit.freedesktop.org/mesa/drm (fetch)
origin git://anongit.freedesktop.org/mesa/drm (push)
$ find . -type f -name \*.c | xargs grep -i udev | cut -f1 -d: | sort -u
./libkms/linux.c
./tests/drmtest.c
./xf86drm.c

udev in ./libkms/linux.c seems to be not used:

#if 0
#define LIBUDEV_I_KNOW_THE_API_IS_SUBJECT_TO_CHANGE
 ...
#else
static int
linux_from_udev(int fd, struct kms_driver **out)
{
        return -ENOSYS;
}
#endif


skipping ./tests/drmtest.c

./xf86drm.c

#if !defined(UDEV)
    if (stat(DRM_DIR_NAME, &st)) {
        if (!isroot)
            return DRM_ERR_NOT_ROOT;
        mkdir(DRM_DIR_NAME, DRM_DEV_DIRMODE);
        chown_check_return(DRM_DIR_NAME, 0, 0); /* root:root */
        chmod(DRM_DIR_NAME, DRM_DEV_DIRMODE);
    }


    /* Check if the device node exists and create it if necessary. */
    if (stat(buf, &st)) {
        if (!isroot)
            return DRM_ERR_NOT_ROOT;
        remove(buf);
        mknod(buf, S_IFCHR | devmode, dev);
    }


    if (drm_server_info) {
        chown_check_return(buf, user, group);
        chmod(buf, devmode);
    }
#else
    /* if we modprobed then wait for udev */
    {
        int udev_count = 0;
wait_for_udev:
        if (stat(DRM_DIR_NAME, &st)) {
                usleep(20);
                udev_count++;


                if (udev_count == 50)
                        return -1;
                goto wait_for_udev;
        }


        if (stat(buf, &st)) {
                usleep(20);
                udev_count++;


                if (udev_count == 50)
                        return -1;
                goto wait_for_udev;
        }
    }
#endif


... (5 lines)

#if !defined(UDEV)
    /* Check if the device node is not what we expect it to be, and recreate it
     * and try again if so.
     */
    if (st.st_rdev != dev) {
        if (!isroot)
            return DRM_ERR_NOT_ROOT;
        remove(buf);
        mknod(buf, S_IFCHR | devmode, dev);
        if (drm_server_info) {
            chown_check_return(buf, user, group);
            chmod(buf, devmode);
        }
    }
    fd = open(buf, O_RDWR, 0);
    drmMsg("drmOpenDevice: open result is %d, (%s)\n",
                fd, fd < 0 ? strerror(errno) : "OK");
    if (fd >= 0)
        return fd;


    drmMsg("drmOpenDevice: Open failed\n");
    remove(buf);
#endif



Regards,
/Karl Hammar

-----------------------------------------------------------------------
Aspö Data
Lilla Aspö 148
S-742 94 Östhammar
Sweden
+46 173 140 57