summaryrefslogtreecommitdiff
path: root/drivers/media/platform/s5p-mfc/s5p_mfc_iommu.h
blob: 6962132ae8fa745b4bef0068ff27b4e7e301c7b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
 * Copyright (C) 2015 Samsung Electronics Co.Ltd
 * Authors: Marek Szyprowski <m.szyprowski@samsung.com>
 *
 * This program is free software; you can redistribute  it and/or modify it
 * under  the terms of  the GNU General  Public License as published by the
 * Free Software Foundation;  either version 2 of the  License, or (at your
 * option) any later version.
 */

#ifndef S5P_MFC_IOMMU_H_
#define S5P_MFC_IOMMU_H_

#define S5P_MFC_IOMMU_DMA_BASE	0x20000000lu
#define S5P_MFC_IOMMU_DMA_SIZE	SZ_256M

#if defined(CONFIG_EXYNOS_IOMMU) && defined(CONFIG_ARM_DMA_USE_IOMMU)

#include <asm/dma-iommu.h>

static inline bool exynos_is_iommu_available(struct device *dev)
{
	return dev->archdata.iommu != NULL;
}

static inline void exynos_unconfigure_iommu(struct device *dev)
{
	struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev);

	arm_iommu_detach_device(dev);
	arm_iommu_release_mapping(mapping);
}

static inline int exynos_configure_iommu(struct device *dev,
					 unsigned int base, unsigned int size)
{
	struct dma_iommu_mapping *mapping = NULL;
	int ret;

	/* Disable the default mapping created by device core */
	if (to_dma_iommu_mapping(dev))
		exynos_unconfigure_iommu(dev);

	mapping = arm_iommu_create_mapping(dev->bus, base, size);
	if (IS_ERR(mapping)) {
		pr_warn("Failed to create IOMMU mapping for device %s\n",
			dev_name(dev));
		return PTR_ERR(mapping);
	}

	ret = arm_iommu_attach_device(dev, mapping);
	if (ret) {
		pr_warn("Failed to attached device %s to IOMMU_mapping\n",
				dev_name(dev));
		arm_iommu_release_mapping(mapping);
		return ret;
	}

	return 0;
}

#else

static inline bool exynos_is_iommu_available(struct device *dev)
{
	return false;
}

static inline int exynos_configure_iommu(struct device *dev,
					 unsigned int base, unsigned int size)
{
	return -ENOSYS;
}

static inline void exynos_unconfigure_iommu(struct device *dev) { }

#endif

#endif /* S5P_MFC_IOMMU_H_ */