[PATCH v4 01/19] drm: Add |struct drm_gem_vram_object| and helpers

Gerd Hoffmann kraxel at redhat.com
Mon May 6 12:31:14 UTC 2019


> +/**
> + * drm_gem_vram_unpin() - Unpins a GEM VRAM object
> + * @gbo:	the GEM VRAM object
> + *
> + * Returns:
> + * 0 on success, or
> + * a negative error code otherwise.
> + */
> +int drm_gem_vram_unpin(struct drm_gem_vram_object *gbo)
> +{
> +	int i, ret;
> +	struct ttm_operation_ctx ctx = { false, false };
> +
> +	if (!gbo->pin_count)
> +		return 0;

WARN_ON_ONCE() here?  That should not happen ...

> +/**
> + * drm_gem_vram_push_to_system() - \
> +	Unpins a GEM VRAM object and moves it to system memory
> + * @gbo:	the GEM VRAM object
> + *
> + * This operation only works if the caller holds the final pin on the
> + * buffer object.
> + *
> + * Returns:
> + * 0 on success, or
> + * a negative error code otherwise.
> + */
> +int drm_gem_vram_push_to_system(struct drm_gem_vram_object *gbo)
> +{
> +	int i, ret;
> +	struct ttm_operation_ctx ctx = { false, false };
> +
> +	if (!gbo->pin_count)
> +		return 0;

Likewise.

> +	--gbo->pin_count;
> +	if (gbo->pin_count)
> +		return 0;
> +
> +	if (gbo->kmap.virtual)
> +		ttm_bo_kunmap(&gbo->kmap);
> +
> +	drm_gem_vram_placement(gbo, TTM_PL_FLAG_SYSTEM);
> +	for (i = 0; i < gbo->placement.num_placement ; ++i)
> +		gbo->placements[i].flags |= TTM_PL_FLAG_NO_EVICT;
> +
> +	ret = ttm_bo_validate(&gbo->bo, &gbo->placement, &ctx);
> +	if (ret)
> +		return ret;
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL(drm_gem_vram_push_to_system);

Very simliar to drm_gem_vram_unpin, can't we just call that function?

Something like this:

	drm_gem_vram_push_to_system()
	{
		if (gbo->pin_count == 1 && gbo->kmap.virtual)
			ttm_bo_kunmap(&gbo->kmap);
		return drm_gem_vram_unpin();
	}

> +struct drm_gem_vram_object {
> +	/* Supported placements are %TTM_PL_VRAM and %TTM_PL_SYSTEM */
> +	struct ttm_placement placement;
> +	struct ttm_place placements[3];

placements[2] should be enough I guess?

cheers,
  Gerd



More information about the dri-devel mailing list