#define MAX_DRM_NODES 256
/**
- * Get information about the opened drm device
+ * Get information about a device from its dev_t identifier
*
- * \param fd file descriptor of the drm device
+ * \param find_rdev dev_t identifier of the device
* \param flags feature/behaviour bitmask
* \param device the address of a drmDevicePtr where the information
* will be allocated in stored
*
* \return zero on success, negative error code otherwise.
- *
- * \note Unlike drmGetDevice it does not retrieve the pci device revision field
- * unless the DRM_DEVICE_GET_PCI_REVISION \p flag is set.
*/
-drm_public int drmGetDevice2(int fd, uint32_t flags, drmDevicePtr *device)
+drm_public int drmGetDeviceFromDevId(dev_t find_rdev, uint32_t flags, drmDevicePtr *device)
{
#ifdef __OpenBSD__
/*
* Avoid stat'ing all of /dev needlessly by implementing this custom path.
*/
drmDevicePtr d;
- struct stat sbuf;
char node[PATH_MAX + 1];
const char *dev_name;
int node_type, subsystem_type;
int maj, min, n, ret;
- if (fd == -1 || device == NULL)
+ if (device == NULL)
return -EINVAL;
- if (fstat(fd, &sbuf))
- return -errno;
-
- maj = major(sbuf.st_rdev);
- min = minor(sbuf.st_rdev);
+ maj = major(find_rdev);
+ min = minor(find_rdev);
- if (!drmNodeIsDRM(maj, min) || !S_ISCHR(sbuf.st_mode))
+ if (!drmNodeIsDRM(maj, min))
return -EINVAL;
node_type = drmGetMinorType(maj, min);
drmDevicePtr d;
DIR *sysdir;
struct dirent *dent;
- struct stat sbuf;
int subsystem_type;
int maj, min;
int ret, i, node_count;
- dev_t find_rdev;
if (drm_device_validate_flags(flags))
return -EINVAL;
- if (fd == -1 || device == NULL)
+ if (device == NULL)
return -EINVAL;
- if (fstat(fd, &sbuf))
- return -errno;
-
- find_rdev = sbuf.st_rdev;
- maj = major(sbuf.st_rdev);
- min = minor(sbuf.st_rdev);
+ maj = major(find_rdev);
+ min = minor(find_rdev);
- if (!drmNodeIsDRM(maj, min) || !S_ISCHR(sbuf.st_mode))
+ if (!drmNodeIsDRM(maj, min))
return -EINVAL;
subsystem_type = drmParseSubsystemType(maj, min);
* Get information about the opened drm device
*
* \param fd file descriptor of the drm device
+ * \param flags feature/behaviour bitmask
+ * \param device the address of a drmDevicePtr where the information
+ * will be allocated in stored
+ *
+ * \return zero on success, negative error code otherwise.
+ *
+ * \note Unlike drmGetDevice it does not retrieve the pci device revision field
+ * unless the DRM_DEVICE_GET_PCI_REVISION \p flag is set.
+ */
+drm_public int drmGetDevice2(int fd, uint32_t flags, drmDevicePtr *device)
+{
+ struct stat sbuf;
+
+ if (fd == -1)
+ return -EINVAL;
+
+ if (fstat(fd, &sbuf))
+ return -errno;
+
+ if (!S_ISCHR(sbuf.st_mode))
+ return -EINVAL;
+
+ return drmGetDeviceFromDevId(sbuf.st_rdev, flags, device);
+}
+
+/**
+ * Get information about the opened drm device
+ *
+ * \param fd file descriptor of the drm device
* \param device the address of a drmDevicePtr where the information
* will be allocated in stored
*