Linux内核4.14版本——drm框架分析(8)——DRM_IOCTL_MODE_GETRESOURCES(drm_mode_getresources)

        本文分析一下APP调用ioctl传入DRM_IOCTL_MODE_GETRESOURCES的操作,其对应kernel为drm_mode_getresources函数。

	DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETRESOURCES, drm_mode_getresources, DRM_CONTROL_ALLOW|DRM_UNLOCKED),
/**
 * drm_mode_getresources - get graphics configuration
 * @dev: drm device for the ioctl
 * @data: data pointer for the ioctl
 * @file_priv: drm file for the ioctl call
 *
 * Construct a set of configuration description structures and return
 * them to the user, including CRTC, connector and framebuffer configuration.
 *
 * Called by the user via ioctl.
 *
 * Returns:
 * Zero on success, negative errno on failure.
 */
int drm_mode_getresources(struct drm_device *dev, void *data,
			  struct drm_file *file_priv)
{
	struct drm_mode_card_res *card_res = data;
	struct drm_framebuffer *fb;
	struct drm_connector *connector;
	struct drm_crtc *crtc;
	struct drm_encoder *encoder;
	int count, ret = 0;
	uint32_t __user *fb_id;
	uint32_t __user *crtc_id;
	uint32_t __user *connector_id;
	uint32_t __user *encoder_id;
	struct drm_connector_list_iter conn_iter;

	if (!drm_core_check_feature(dev, DRIVER_MODESET))
		return -EINVAL;


	mutex_lock(&file_priv->fbs_lock);
	count = 0;
	fb_id = u64_to_user_ptr(card_res->fb_id_ptr);
	list_for_each_entry(fb, &file_priv->fbs, filp_head) {     // (1)
		if (count < card_res->count_fbs &&
		    put_user(fb->base.id, fb_id + count)) {
			mutex_unlock(&file_priv->fbs_lock);
			return -EFAULT;
		}
		count++;
	}
	card_res->count_fbs = count;
	mutex_unlock(&file_priv->fbs_lock);

	card_res->max_height = dev->mode_config.max_height;       // (2)
	card_res->min_height = dev->mode_config.min_height;
	card_res->max_width = dev->mode_config.max_width;
	card_res->min_width = dev->mode_config.min_width;

	count = 0;
	crtc_id = u64_to_user_ptr(card_res->crtc_id_ptr);        // (3)
	drm_for_each_crtc(crtc, dev) {
		if (count < card_res->count_crtcs &&
		    put_user(crtc->base.id, crtc_id + count))
			return -EFAULT;
		count++;
	}
	card_res->count_crtcs = count;

	count = 0;
	encoder_id = u64_to_user_ptr(card_res->encoder_id_ptr);   // (4)
	drm_for_each_encoder(encoder, dev) {
		if (count < card_res->count_encoders &&
		    put_user(encoder->base.id, encoder_id + count))
			return -EFAULT;
		count++;
	}
	card_res->count_encoders = count;

	drm_connector_list_iter_begin(dev, &conn_iter);
	count = 0;
	connector_id = u64_to_user_ptr(card_res->connector_id_ptr);
	drm_for_each_connector_iter(connector, &conn_iter) {         // (5)
		if (count < card_res->count_connectors &&
		    put_user(connector->base.id, connector_id + count)) {
			drm_connector_list_iter_end(&conn_iter);
			return -EFAULT;
		}
		count++;
	}
	card_res->count_connectors = count;
	drm_connector_list_iter_end(&conn_iter);

	return ret;
}

        (1)遍历fbs,把fbs数量告诉app.。

        (2)把最大/最小支持的宽/高告诉app。

        (3)把支持的crtc的数量告诉app。

        (4)把支持的encoder的数量告诉app。

        (5)把支持的connector的数量告诉app。

你可能感兴趣的:(Linux,drm框架分析,drm)