Back to index

libdrm  2.4.37
Defines | Functions
linux.c File Reference
#include "config.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <xf86drm.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include "internal.h"

Go to the source code of this file.

Defines

#define PATH_SIZE   512

Functions

static int linux_name_from_sysfs (int fd, char **out)
static int linux_from_sysfs (int fd, struct kms_driver **out)
static int linux_from_udev (int fd, struct kms_driver **out)
int linux_create (int fd, struct kms_driver **out)

Define Documentation

#define PATH_SIZE   512

Definition at line 45 of file linux.c.


Function Documentation

int linux_create ( int  fd,
struct kms_driver **  out 
)

Definition at line 217 of file linux.c.

{
       if (!dumb_create(fd, out))
              return 0;

       if (!linux_from_udev(fd, out))
              return 0;

       return linux_from_sysfs(fd, out);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int linux_from_sysfs ( int  fd,
struct kms_driver **  out 
) [static]

Definition at line 95 of file linux.c.

{
       char *name;
       int ret;

       ret = linux_name_from_sysfs(fd, &name);
       if (ret)
              return ret;

       if (!strcmp(name, "intel"))
              ret = intel_create(fd, out);
#ifdef HAVE_VMWGFX
       else if (!strcmp(name, "vmwgfx"))
              ret = vmwgfx_create(fd, out);
#endif
#ifdef HAVE_NOUVEAU
       else if (!strcmp(name, "nouveau"))
              ret = nouveau_create(fd, out);
#endif
#ifdef HAVE_RADEON
       else if (!strcmp(name, "radeon"))
              ret = radeon_create(fd, out);
#endif
       else
              ret = -ENOSYS;

       free(name);
       return ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int linux_from_udev ( int  fd,
struct kms_driver **  out 
) [static]

Definition at line 210 of file linux.c.

{
       return -ENOSYS;
}

Here is the caller graph for this function:

static int linux_name_from_sysfs ( int  fd,
char **  out 
) [static]

Definition at line 48 of file linux.c.

{
       char path[PATH_SIZE+1] = ""; /* initialize to please valgrind */
       char link[PATH_SIZE+1] = "";
       struct stat buffer;
       unsigned maj, min;
       char* slash_name;
       int ret;

       /* 
        * Inside the sysfs directory for the device there is a symlink
        * to the directory representing the driver module, that path
        * happens to hold the name of the driver.
        *
        * So lets get the symlink for the drm device. Then read the link
        * and filter out the last directory which happens to be the name
        * of the driver, which we can use to load the correct interface.
        *
        * Thanks to Ray Strode of Plymouth for the code.
        */

       ret = fstat(fd, &buffer);
       if (ret)
              return ret;

       if (!S_ISCHR(buffer.st_mode))
              return -EINVAL;

       maj = major(buffer.st_rdev);
       min = minor(buffer.st_rdev);

       snprintf(path, PATH_SIZE, "/sys/dev/char/%d:%d/device/driver", maj, min);

       if (readlink(path, link, PATH_SIZE) < 0)
              return -EINVAL;

       /* link looks something like this: ../../../bus/pci/drivers/intel */
       slash_name = strrchr(link, '/');
       if (!slash_name)
              return -EINVAL;

       /* copy name and at the same time remove the slash */
       *out = strdup(slash_name + 1);
       return 0;
}

Here is the caller graph for this function: