<commit_before>/*
 * Copyright 2012 Advanced Micro Devices, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * based on nouveau_prime.c
 *
 * Authors: <NAME>
 */
#include "drmP.h"
#include "drm.h"

#include "radeon.h"
#include "radeon_drm.h"

#include <linux/dma-buf.h>

static struct sg_table *radeon_gem_map_dma_buf(struct dma_buf_attachment *attachment,
					       enum dma_data_direction dir)
{
	struct radeon_bo *bo = attachment->dmabuf->priv;
	struct drm_device *dev = bo->rdev->ddev;
	int npages = bo->tbo.num_pages;
	struct sg_table *sg;
	int nents;

	mutex_lock(&dev->struct_mutex);
	sg = drm_prime_pages_to_sg(bo->tbo.ttm->pages, npages);
	nents = dma_map_sg(attachment->dev, sg->sgl, sg->nents, dir);
	mutex_unlock(&dev->struct_mutex);
	return sg;
}

static void radeon_gem_unmap_dma_buf(struct dma_buf_attachment *attachment,
				     struct sg_table *sg, enum dma_data_direction dir)
{
	dma_unmap_sg(attachment->dev, sg->sgl, sg->nents, dir);
	sg_free_table(sg);
	kfree(sg);
}

static void radeon_gem_dmabuf_release(struct dma_buf *dma_buf)
{
	struct radeon_bo *bo = dma_buf->priv;

	if (bo->gem_base.export_dma_buf == dma_buf) {
		DRM_ERROR("unreference dmabuf %p\n", &bo->gem_base);
		bo->gem_base.export_dma_buf = NULL;
		drm_gem_object_unreference_unlocked(&bo->gem_base);
	}
}

static void *radeon_gem_kmap_atomic(struct dma_buf *dma_buf, unsigned long page_num)
{
	return NULL;
}

static void radeon_gem_kunmap_atomic(struct dma_buf *dma_buf, unsigned long page_num, void *addr)
{

}
static void *radeon_gem_kmap(struct dma_buf *dma_buf, unsigned long page_num)
{
	return NULL;
}

static void radeon_gem_kunmap(struct dma_buf *dma_buf, unsigned long page_num, void *addr)
{

}

const static struct dma_buf_ops radeon_dmabuf_ops =  {
	.map_dma_buf = radeon_gem_map_dma_buf,
	.unmap_dma_buf = radeon_gem_unmap_dma_buf,
	.release = radeon_gem_dmabuf_release,
	.kmap = radeon_gem_kmap,
	.kmap_atomic = radeon_gem_kmap_atomic,
	.kunmap = radeon_gem_kunmap,
	.kunmap_atomic = radeon_gem_kunmap_atomic,
};

static int radeon_prime_create(struct drm_device *dev,
			       size_t size,
			       struct sg_table *sg,
			       struct radeon_bo **pbo)
{
	struct radeon_device *rdev = dev->dev_private;
	struct radeon_bo *bo;
	int ret;

	ret = radeon_bo_create(rdev, size, PAGE_SIZE, false,
			       RADEON_GEM_DOMAIN_GTT, sg, pbo);
	if (ret)
		return ret;
	bo = *pbo;
	bo->gem_base.driver_private = bo;

	mutex_lock(&rdev->gem.mutex);
	list_add_tail(&bo->list, &rdev->gem.objects);
	mutex_unlock(&rdev->gem.mutex);

	return 0;
}
<commit_msg>radeon: add stub dma-buf mmap functionality<commit_after>/*
 * Copyright 2012 Advanced Micro Devices, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * based on nouveau_prime.c
 *
 * Authors: <NAME>
 */
#include "drmP.h"
#include "drm.h"

#include "radeon.h"
#include "radeon_drm.h"

#include <linux/dma-buf.h>

static struct sg_table *radeon_gem_map_dma_buf(struct dma_buf_attachment *attachment,
					       enum dma_data_direction dir)
{
	struct radeon_bo *bo = attachment->dmabuf->priv;
	struct drm_device *dev = bo->rdev->ddev;
	int npages = bo->tbo.num_pages;
	struct sg_table *sg;
	int nents;

	mutex_lock(&dev->struct_mutex);
	sg = drm_prime_pages_to_sg(bo->tbo.ttm->pages, npages);
	nents = dma_map_sg(attachment->dev, sg->sgl, sg->nents, dir);
	mutex_unlock(&dev->struct_mutex);
	return sg;
}

static void radeon_gem_unmap_dma_buf(struct dma_buf_attachment *attachment,
				     struct sg_table *sg, enum dma_data_direction dir)
{
	dma_unmap_sg(attachment->dev, sg->sgl, sg->nents, dir);
	sg_free_table(sg);
	kfree(sg);
}

static void radeon_gem_dmabuf_release(struct dma_buf *dma_buf)
{
	struct radeon_bo *bo = dma_buf->priv;

	if (bo->gem_base.export_dma_buf == dma_buf) {
		DRM_ERROR("unreference dmabuf %p\n", &bo->gem_base);
		bo->gem_base.export_dma_buf = NULL;
		drm_gem_object_unreference_unlocked(&bo->gem_base);
	}
}

static void *radeon_gem_kmap_atomic(struct dma_buf *dma_buf, unsigned long page_num)
{
	return NULL;
}

static void radeon_gem_kunmap_atomic(struct dma_buf *dma_buf, unsigned long page_num, void *addr)
{

}
static void *radeon_gem_kmap(struct dma_buf *dma_buf, unsigned long page_num)
{
	return NULL;
}

static void radeon_gem_kunmap(struct dma_buf *dma_buf, unsigned long page_num, void *addr)
{

}

static int radeon_gem_prime_mmap(struct dma_buf *dma_buf, struct vm_area_struct *vma)
{
	return -EINVAL;
}

const static struct dma_buf_ops radeon_dmabuf_ops =  {
	.map_dma_buf = radeon_gem_map_dma_buf,
	.unmap_dma_buf = radeon_gem_unmap_dma_buf,
	.release = radeon_gem_dmabuf_release,
	.kmap = radeon_gem_kmap,
	.kmap_atomic = radeon_gem_kmap_atomic,
	.kunmap = radeon_gem_kunmap,
	.kunmap_atomic = radeon_gem_kunmap_atomic,
	.mmap = radeon_gem_prime_mmap,
};

static int radeon_prime_create(struct drm_device *dev,
			       size_t size,
			       struct sg_table *sg,
			       struct radeon_bo **pbo)
{
	struct radeon_device *rdev = dev->dev_private;
	struct radeon_bo *bo;
	int ret;

	ret = radeon_bo_create(rdev, size, PAGE_SIZE, false,
			       RADEON_GEM_DOMAIN_GTT, sg, pbo);
	if (ret)
		return ret;
	bo = *pbo;
	bo->gem_base.driver_private = bo;

	mutex_lock(&rdev->gem.mutex);
	list_add_tail(&bo->list, &rdev->gem.objects);
	mutex_unlock(&rdev->gem.mutex);

	return 0;
}

{'fraction_non_alphanumeric': 0.09706362153344208, 'fraction_numerical': 0.0013594344752582926, 'mean_word_length': 4.725291828793774, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7572906', 'n_tokens_mistral': 2759, 'n_tokens_neox': 2597, 'n_words': 737}