libdrm full analysis nineteen - full source code analysis (16)

Continued from the previous article: Full analysis of libdrm 18 — Full analysis of source code (15)

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.

27. DRM_IOCTL_SET_SAREA_CTX

The 27th macro is DRM_IOCTL_SET_SAREA_CTX, the corresponding code is as follows:

#define DRM_IOCTL_SET_SAREA_CTX		DRM_IOW( 0x1c, struct drm_ctx_priv_map)

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

#define DRM_IOCTL_SET_SAREA_CTX        ( ((1)  << 30) | (('d') << 8) | ((0x1c)   << 0) | ((sizeof(struct drm_ctx_priv_map)) << 16) )

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

struct drm_ctx_priv_map {
	unsigned int ctx_id;	 /**< Context requesting private mapping */
	void *handle;		 /**< Handle of map */
};

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

The Userspace API corresponding to DRM_IOCTL_SET_SAREA_CTX is: drmAddContextPrivateMapping(). This function is also in xf86drm.c, the code is as follows:

drm_public int drmAddContextPrivateMapping(int fd, drm_context_t ctx_id,
                                           drm_handle_t handle)
{
    drm_ctx_priv_map_t map;

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

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

The role of the function is to add context-private mappings. 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.

28. DRM_IOCTL_GET_SAREA_CTX

The 28th macro is DRM_IOCTL_GET_SAREA_CTX, the corresponding code is as follows:

#define DRM_IOCTL_GET_SAREA_CTX 	DRM_IOWR(0x1d, struct drm_ctx_priv_map)

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

#define DRM_IOCTL_GET_SAREA_CTX        ( ((3)  << 30) | (('d') << 8) | ((0x1d)   << 0) | ((sizeof(struct drm_ctx_priv_map)) << 16) )

The definition of struct drm_ctx_priv_map has been given above and will not be repeated here.

The Userspace API corresponding to DRM_IOCTL_GET_SAREA_CTX is: drmGetContextPrivateMapping(). This function is also in xf86drm.c, the code is as follows:

drm_public int drmGetContextPrivateMapping(int fd, drm_context_t ctx_id,
                                           drm_handle_t *handle)
{
    drm_ctx_priv_map_t map;

    memclear(map);
    map.ctx_id = ctx_id;

    if (drmIoctl(fd, DRM_IOCTL_GET_SAREA_CTX, &map))
        return -errno;
    if (handle)
        *handle = (drm_handle_t)(uintptr_t)map.handle;

    return 0;
}

The role of the function is to obtain the context private 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/132491133