Full analysis of libdrm 18 - full analysis of source code (15)

Continued from the previous article: Full analysis of libdrm seventeen - full analysis of source code (14)

This article refers to the following blog posts:

DRM driver development (VKMS)

Thank you very much!

This article continues to explain the actual function macro definition in include/drm/drm.h.

25. DRM_IOCTL_FREE_BUFS

The 25th macro is DRM_IOCTL_FREE_BUFS, the corresponding code is as follows:

#define DRM_IOCTL_FREE_BUFS		DRM_IOW( 0x1a, struct drm_buf_free)

Combined with the final definition of _IOW(type,nr,size) in the previous article, the following code is obtained:

#define DRM_IOCTL_FREE_BUFS        ( ((1)  << 30) | (('d') << 8) | ((0x1a)   << 0) | ((sizeof(struct drm_buf_free)) << 16) )

struct drm_buf_free is defined in the same file (include/drm/drm.h), the code is as follows:

/*
 * DRM_IOCTL_FREE_BUFS ioctl argument type.
 */
struct drm_buf_free {
	int count;
	int *list;
};

The Userspace API corresponding to DRM_IOCTL_FREE_BUFS is: drmFreeBufs(). This function is also in xf86drm.c, the codes are as follows:

/**
 * Free buffers.
 *
 * \param fd file descriptor.
 * \param count number of buffers to free.
 * \param list list of buffers to be freed.
 *
 * \return zero on success, or a negative value on failure.
 *
 * \note This function is primarily used for debugging.
 *
 * \internal
 * This function is a wrapper around the DRM_IOCTL_FREE_BUFS ioctl, passing
 * the arguments in a drm_buf_free structure.
 */
drm_public int drmFreeBufs(int fd, int count, int *list)
{
    drm_buf_free_t request;

    memclear(request);
    request.count = count;
    request.list  = list;
    if (drmIoctl(fd, DRM_IOCTL_FREE_BUFS, &request))
        return -errno;
    return 0;
}

The role of the function is to release the buffer (buffers). This function will be analyzed in detail later when the function is explained in detail. Let's get to know each other first and have an impression.

26. DRM_IOCTL_RM_MAP

The 26th macro is DRM_IOCTL_RM_MAP, the corresponding code is as follows:

#define DRM_IOCTL_RM_MAP		DRM_IOW( 0x1b, struct drm_map)

Combined with the final definition of _IOW(type,nr,size) in the previous article, the following code is obtained:

#define DRM_IOCTL_RM_MAP		( ((1)  << 30) | (('d') << 8) | ((0x1b)   << 0) | ((sizeof(struct drm_map)) << 16) )

struct drm_map is defined in the same file (include/drm/drm.h), the code is as follows:

/*
 * DRM_IOCTL_GET_MAP, DRM_IOCTL_ADD_MAP and DRM_IOCTL_RM_MAP ioctls
 * argument type.
 *
 * \sa drmAddMap().
 */
struct drm_map {
	unsigned long offset;	 /**< Requested physical address (0 for SAREA)*/
	unsigned long size;	 /**< Requested physical size (bytes) */
	enum drm_map_type type;	 /**< Type of memory to map */
	enum drm_map_flags flags;	 /**< Flags */
	void *handle;		 /**< User-space: "Handle" to pass to mmap() */
				 /**< Kernel-space: kernel-virtual address */
	int mtrr;		 /**< MTRR slot used */
	/*   Private data */
};

The meaning code comments of each member in the drm_map structure are clearly described, so there is no need to repeat them here.

The Userspace API corresponding to DRM_IOCTL_RM_MAP is: drmRmMap(). This function is also in xf86drm.c, the codes are as follows:

drm_public int drmRmMap(int fd, drm_handle_t handle)
{
    drm_map_t map;

    memclear(map);
    map.handle = (void *)(uintptr_t)handle;

    if(drmIoctl(fd, DRM_IOCTL_RM_MAP, &map))
        return -errno;
    return 0;
}

The role of the function is to delete the mapping. This function will be analyzed in detail later when the function is explained in detail. Let's get to know each other first and have an impression.

The remaining macro definitions will continue to be analyzed in subsequent articles.

Guess you like

Origin blog.csdn.net/phmatthaus/article/details/132490106