drm/exynos: add iommu support for -next
Subsystems (3)
cover drm/exynos: add iommu support for -next
Hi all,
This patch set adds iommu support for exynos drm framework and also relevant drivers, fimd and hdmi.
Exynos4xxx SoC and later have some iommu hardware units for video codec, Camera, Post Processer(FIMC and GScaler), FIMD, HDMI, Graphics 2D and so on. In other words, each device has its own iommu hardware unit. So each device could have its own device address space.
But in case of using DRM GEM and DMA Mapping API as allocator, there is one issue. the issue is that we can't know which device a gem buffer should be allocated for. So this patch set will use unified device address space. Simply saying, exynos drm-based all devices of using iommu have same device address space.
For example, if user process requested gem allocation, exynos drm gem framework allocates desired physical memory region and maps it with unified iommu mapping table through DMA Mapping API call, dma_allc_attrs function.
And this patch set is based on the following patch, "DMA-mapping & IOMMU - physically contiguous allocations" Marek posted before as RFC. For this, you can refer to below link,
http://www.serverphorums.com/read.php?12,581741
As you know, RFC to the above patch is in progress so we have to wait for the patch to be merged to mainline.
Thanks,
Inki Dae
Inki Dae (3):
drm/exynos: add iommu support for exynos drm framework drm/exynos: add iommu support to fimd driver drm/exynos: add iommu support for hdmi driver
drivers/gpu/drm/exynos/Kconfig | 6 + drivers/gpu/drm/exynos/Makefile | 1 + drivers/gpu/drm/exynos/exynos_drm_buf.c | 88 +++++------- drivers/gpu/drm/exynos/exynos_drm_dmabuf.c | 87 +++++------- drivers/gpu/drm/exynos/exynos_drm_drv.c | 23 +++- drivers/gpu/drm/exynos/exynos_drm_drv.h | 11 ++ drivers/gpu/drm/exynos/exynos_drm_fb.c | 52 ++++++- drivers/gpu/drm/exynos/exynos_drm_fimd.c | 9 +- drivers/gpu/drm/exynos/exynos_drm_gem.c | 210 +++-------------------------- drivers/gpu/drm/exynos/exynos_drm_gem.h | 1 + drivers/gpu/drm/exynos/exynos_drm_hdmi.c | 15 +++ drivers/gpu/drm/exynos/exynos_drm_hdmi.h | 1 + drivers/gpu/drm/exynos/exynos_drm_iommu.c | 156 +++++++++++++++++++++ drivers/gpu/drm/exynos/exynos_drm_iommu.h | 85 ++++++++++++ drivers/gpu/drm/exynos/exynos_hdmi.c | 21 +++ 15 files changed, 460 insertions(+), 306 deletions(-) create mode 100644 drivers/gpu/drm/exynos/exynos_drm_iommu.c create mode 100644 drivers/gpu/drm/exynos/exynos_drm_iommu.h
Signature · 1 line
1.8.0.rc3.16.g8ead1bf
PATCH 1/3 drm/exynos: add iommu support for exynos drm framework
This patch adds iommu support for exynos drm framework with dma mapping api. In this patch, we used dma mapping api to allocate physical memory and maps it with iommu table and removed some existing codes and added new some codes for iommu support.
GEM allocation requires one device object to use dma mapping api so this patch uses one iommu mapping for all sub drivers. In other words, all sub drivers have same iommu mapping.
--- drivers/gpu/drm/exynos/Kconfig | 6 + drivers/gpu/drm/exynos/Makefile | 1 + drivers/gpu/drm/exynos/exynos_drm_buf.c | 88 +++++------- drivers/gpu/drm/exynos/exynos_drm_dmabuf.c | 87 +++++------- drivers/gpu/drm/exynos/exynos_drm_drv.c | 23 +++- drivers/gpu/drm/exynos/exynos_drm_drv.h | 11 ++ drivers/gpu/drm/exynos/exynos_drm_fb.c | 52 ++++++- drivers/gpu/drm/exynos/exynos_drm_gem.c | 210 +++-------------------------- drivers/gpu/drm/exynos/exynos_drm_gem.h | 1 + drivers/gpu/drm/exynos/exynos_drm_iommu.c | 156 +++++++++++++++++++++ drivers/gpu/drm/exynos/exynos_drm_iommu.h | 85 ++++++++++++ 11 files changed, 415 insertions(+), 305 deletions(-) create mode 100644 drivers/gpu/drm/exynos/exynos_drm_iommu.c create mode 100644 drivers/gpu/drm/exynos/exynos_drm_iommu.h
drivers/gpu/drm/exynos/Kconfig +6 -0
@@ -10,6 +10,12 @@ config DRM_EXYNOS Choose this option if you have a Samsung SoC EXYNOS chipset. If M is selected the module will be called exynosdrm. +config DRM_EXYNOS_IOMMU + bool "EXYNOS DRM IOMMU Support" + depends on DRM_EXYNOS && EXYNOS_IOMMU + help + Choose this option if you want to use IOMMU feature for DRM. + config DRM_EXYNOS_DMABUF bool "EXYNOS DRM DMABUF" depends on DRM_EXYNOS
drivers/gpu/drm/exynos/Makefile +1 -0
@@ -8,6 +8,7 @@ exynosdrm-y := exynos_drm_drv.o exynos_drm_encoder.o exynos_drm_connector.o \ exynos_drm_buf.o exynos_drm_gem.o exynos_drm_core.o \ exynos_drm_plane.o +exynosdrm-$(CONFIG_DRM_EXYNOS_IOMMU) += exynos_drm_iommu.o exynosdrm-$(CONFIG_DRM_EXYNOS_DMABUF) += exynos_drm_dmabuf.o exynosdrm-$(CONFIG_DRM_EXYNOS_FIMD) += exynos_drm_fimd.o exynosdrm-$(CONFIG_DRM_EXYNOS_HDMI) += exynos_hdmi.o exynos_mixer.o \
drivers/gpu/drm/exynos/exynos_drm_buf.c +32 -56
144 lines not on this page · raw message
drivers/gpu/drm/exynos/exynos_drm_dmabuf.c +37 -50
158 lines not on this page · raw message
drivers/gpu/drm/exynos/exynos_drm_drv.c +20 -3
@@ -40,6 +40,7 @@#include "exynos_drm_vidi.h" #include "exynos_drm_dmabuf.h" #include "exynos_drm_g2d.h" +#include "exynos_drm_iommu.h" #define DRIVER_NAME "exynos"#define DRIVER_DESC "Samsung SoC DRM"
@@ -69,6 +70,18 @@ static int exynos_drm_load(struct drm_device *dev, unsigned long flags)INIT_LIST_HEAD (&private->pageflip_event_list); dev->dev_private = (void *)private; +/* +* create mapping to manage iommu table and set a pointer to iommu +* mapping structure to iommu_mapping of private data. +* also this iommu_mapping can be used to check if iommu is supported +* or not. +*/ + ret =drm_create_iommu_mapping (dev); +if (ret <0 ) { +DRM_ERROR ("failed to create iommu mapping.\n" ); + goto err_crtc; + } +drm_mode_config_init (dev);/* init kms poll for handling hpd */
@@ -83,7 +96,7 @@ static int exynos_drm_load(struct drm_device *dev, unsigned long flags)for (nr =0 ; nr <MAX_CRTC ; nr++) { ret =exynos_drm_crtc_create (dev, nr);if (ret) - goto err_crtc; + goto err_release_iommu_mapping; }for (nr =0 ; nr <MAX_PLANE ; nr++) {
@@ -92,12 +105,12 @@ static int exynos_drm_load(struct drm_device *dev, unsigned long flags) plane =exynos_plane_init (dev, possible_crtcs, false);if (!plane) - goto err_crtc; + goto err_release_iommu_mapping; } ret =drm_vblank_init (dev,MAX_CRTC );if (ret) - goto err_crtc; + goto err_release_iommu_mapping;/* * probe sub drivers such as display controller and hdmi driver,
@@ -129,6 +142,8 @@ err_drm_device:exynos_drm_device_unregister (dev); err_vblank:drm_vblank_cleanup (dev); +err_release_iommu_mapping: +drm_release_iommu_mapping (dev); err_crtc:drm_mode_config_cleanup (dev);kfree (private);
@@ -145,6 +160,8 @@ static int exynos_drm_unload(struct drm_device *dev)drm_vblank_cleanup (dev);drm_kms_helper_poll_fini (dev);drm_mode_config_cleanup (dev); + +drm_release_iommu_mapping (dev);kfree (dev->dev_private); dev->dev_private =NULL ;
drivers/gpu/drm/exynos/exynos_drm_drv.h +11 -0
@@ -241,6 +241,13 @@ struct drm_exynos_file_private {/* * Exynos drm private structure. +* +* @da_start: start address to device address space. +* with iommu, device address space starts from this address +* otherwise default one. +* @da_space_size: size of device address space. +* if 0 then default value is used for it. +* @da_space_order: order to device address space. */ struct exynos_drm_private {struct drm_fb_helper *fb_helper;
@@ -255,6 +262,10 @@ struct exynos_drm_private {struct drm_crtc *crtc[MAX_CRTC ];struct drm_property *plane_zpos_property;struct drm_property *crtc_mode_property; + +unsigned long da_start; +unsigned long da_space_size; +unsigned long da_space_order; };/*
drivers/gpu/drm/exynos/exynos_drm_fb.c +51 -1
100 lines not on this page · raw message
drivers/gpu/drm/exynos/exynos_drm_gem.c +15 -195
268 lines not on this page · raw message
drivers/gpu/drm/exynos/exynos_drm_gem.h +1 -0
@@ -46,6 +46,7 @@struct exynos_drm_gem_buf {void __iomem *kvaddr;dma_addr_t dma_addr; +struct dma_attrs dma_attrs;struct sg_table *sgt;struct page **pages;unsigned long page_size;
drivers/gpu/drm/exynos/exynos_drm_iommu.c new file +156 -0
156 lines not on this page · raw message
drivers/gpu/drm/exynos/exynos_drm_iommu.h new file +85 -0
85 lines not on this page · raw message
Signature · 1 line
1.8.0.rc3.16.g8ead1bf
PATCH 2/3 drm/exynos: add iommu support to fimd driver
In reply to Inki DaeFrom: Inki Dae <[email protected]>
The iommu will be enabled when fimd sub driver is probed and will be disabled when removed.
--- drivers/gpu/drm/exynos/exynos_drm_fimd.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/gpu/drm/exynos/exynos_drm_fimd.c +8 -1
@@ -25,6 +25,7 @@#include "exynos_drm_drv.h" #include "exynos_drm_fbdev.h" #include "exynos_drm_crtc.h" +#include "exynos_drm_iommu.h" /* * FIMD is stand for Fully Interactive Mobile Display and
@@ -709,6 +710,10 @@ static int fimd_subdrv_probe(struct drm_device *drm_dev, struct device *dev)*/ drm_dev->vblank_disable_allowed =1 ; +/* attach this sub driver to iommu mapping if supported. */ +if (is_drm_iommu_supported (drm_dev)) +drm_iommu_attach_device (drm_dev, dev); +return 0 ; }
@@ -716,7 +721,9 @@ static void fimd_subdrv_remove(struct drm_device *drm_dev, struct device *dev) {DRM_DEBUG_KMS ("%s\n" , __FILE__); -/* TODO. */ +/* detach this sub driver from iommu mapping if supported. */ +if (is_drm_iommu_supported (drm_dev)) +drm_iommu_detach_device (drm_dev, dev); } static int fimd_calc_clkdiv(struct fimd_context *ctx,
Signature · 1 line
1.8.0.rc3.16.g8ead1bf
PATCH 3/3 drm/exynos: add iommu support for hdmi driver
In reply to Inki DaeFrom: Inki Dae <[email protected]>
The iommu will be enabled when hdmi sub driver is probed and will be disabled when removed.
--- drivers/gpu/drm/exynos/exynos_drm_hdmi.c | 15 +++++++++++++++ drivers/gpu/drm/exynos/exynos_drm_hdmi.h | 1 + drivers/gpu/drm/exynos/exynos_hdmi.c | 21 +++++++++++++++++++++ 3 files changed, 37 insertions(+)
drivers/gpu/drm/exynos/exynos_drm_hdmi.c +15 -0
@@ -368,9 +368,23 @@ static int hdmi_subdrv_probe(struct drm_device *drm_dev, ctx->hdmi_ctx->drm_dev = drm_dev; ctx->mixer_ctx->drm_dev = drm_dev; +if (hdmi_ops->iommu_on) + hdmi_ops->iommu_on (ctx->hdmi_ctx->ctx, true); +return 0 ; } +static void hdmi_subdrv_remove (struct drm_device *drm_dev,struct device *dev) +{ +struct drm_hdmi_context *ctx; +struct exynos_drm_subdrv *subdrv =to_subdrv (dev); + + ctx =get_ctx_from_subdrv (subdrv); + +if (hdmi_ops->iommu_on) + hdmi_ops->iommu_on (ctx->hdmi_ctx->ctx, false); +} +static int __devinit exynos_drm_hdmi_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;
@@ -390,6 +404,7 @@ static int __devinit exynos_drm_hdmi_probe(struct platform_device *pdev) subdrv->dev = dev; subdrv->manager = &hdmi_manager; subdrv->probe = hdmi_subdrv_probe; + subdrv->remove = hdmi_subdrv_remove;platform_set_drvdata (pdev, subdrv);
drivers/gpu/drm/exynos/exynos_drm_hdmi.h +1 -0
@@ -50,6 +50,7 @@ struct exynos_hdmi_ops {int (*power_on)(void *ctx,int mode);/* manager */ +int (*iommu_on)(void *ctx,bool enable);void (*mode_fixup)(void *ctx,struct drm_connector *connector,const struct drm_display_mode *mode,struct drm_display_mode *adjusted_mode);
drivers/gpu/drm/exynos/exynos_hdmi.c +21 -0
@@ -40,6 +40,7 @@#include "exynos_drm_drv.h" #include "exynos_drm_hdmi.h" +#include "exynos_drm_iommu.h" #include "exynos_hdmi.h"
@@ -1946,6 +1947,25 @@ static void hdmi_conf_apply(struct hdmi_context *hdata)hdmi_regs_dump (hdata,"start" ); } +static int hdmi_iommu_on (void *ctx,bool enable) +{ +struct exynos_drm_hdmi_context *drm_hdmi_ctx; +struct hdmi_context *hdata = ctx; +struct drm_device *drm_dev; + + drm_hdmi_ctx = hdata->parent_ctx; + drm_dev = drm_hdmi_ctx->drm_dev; + +if (is_drm_iommu_supported (drm_dev)) { +if (enable) +return drm_iommu_attach_device (drm_dev, hdata->dev); + +drm_iommu_detach_device (drm_dev, hdata->dev); + } + +return 0 ; +} +static void hdmi_mode_fixup (void *ctx,struct drm_connector *connector,const struct drm_display_mode *mode,struct drm_display_mode *adjusted_mode)
@@ -2102,6 +2122,7 @@ static struct exynos_hdmi_ops hdmi_ops = { .check_timing = hdmi_check_timing,/* manager */ + .iommu_on = hdmi_iommu_on, .mode_fixup = hdmi_mode_fixup, .mode_set = hdmi_mode_set, .get_max_resol = hdmi_get_max_resol,
Signature · 1 line
1.8.0.rc3.16.g8ead1bf
Inki Dae
maintainerPATCH v2 1/1 drm/exynos: add iommu support for exynos drm framework
In reply to Inki DaeFrom: Inki Dae <[email protected]>
Changelog v2:
- fix dma_ops check condition of drm_iommu_attach_device function. . check archdata.dma_ops of drm device instead of subdrv device's one.
- code clean to exynos_drm_iommu.c file.
. remove '#ifdef CONFIG_ARM_DMA_USE_IOMMU' from exynos_drm_iommu.c
and add it to driver/gpu/drm/exynos/Kconfig.
Changelog v1:
This patch adds iommu support for exynos drm framework with dma mapping api. In this patch, we used dma mapping api to allocate physical memory and maps it with iommu table and removed some existing codes and added new some codes for iommu support.
GEM allocation requires one device object to use dma mapping api so this patch uses one iommu mapping for all sub drivers. In other words, all sub drivers have same iommu mapping.
--- drivers/gpu/drm/exynos/Kconfig | 6 + drivers/gpu/drm/exynos/Makefile | 1 + drivers/gpu/drm/exynos/exynos_drm_buf.c | 88 +++++-------- drivers/gpu/drm/exynos/exynos_drm_dmabuf.c | 87 +++++------- drivers/gpu/drm/exynos/exynos_drm_drv.c | 23 +++- drivers/gpu/drm/exynos/exynos_drm_drv.h | 11 ++ drivers/gpu/drm/exynos/exynos_drm_fb.c | 52 +++++++- drivers/gpu/drm/exynos/exynos_drm_gem.c | 210 ++-------------------------- drivers/gpu/drm/exynos/exynos_drm_gem.h | 1 + drivers/gpu/drm/exynos/exynos_drm_iommu.c | 150 ++++++++++++++++++++ drivers/gpu/drm/exynos/exynos_drm_iommu.h | 85 +++++++++++ 11 files changed, 409 insertions(+), 305 deletions(-) create mode 100644 drivers/gpu/drm/exynos/exynos_drm_iommu.c create mode 100644 drivers/gpu/drm/exynos/exynos_drm_iommu.h
drivers/gpu/drm/exynos/Kconfig +6 -0
@@ -10,6 +10,12 @@ config DRM_EXYNOS Choose this option if you have a Samsung SoC EXYNOS chipset. If M is selected the module will be called exynosdrm. +config DRM_EXYNOS_IOMMU + bool "EXYNOS DRM IOMMU Support" + depends on DRM_EXYNOS && EXYNOS_IOMMU && ARM_DMA_USE_IOMMU + help + Choose this option if you want to use IOMMU feature for DRM. + config DRM_EXYNOS_DMABUF bool "EXYNOS DRM DMABUF" depends on DRM_EXYNOS
drivers/gpu/drm/exynos/Makefile +1 -0
@@ -8,6 +8,7 @@ exynosdrm-y := exynos_drm_drv.o exynos_drm_encoder.o exynos_drm_connector.o \ exynos_drm_buf.o exynos_drm_gem.o exynos_drm_core.o \ exynos_drm_plane.o +exynosdrm-$(CONFIG_DRM_EXYNOS_IOMMU) += exynos_drm_iommu.o exynosdrm-$(CONFIG_DRM_EXYNOS_DMABUF) += exynos_drm_dmabuf.o exynosdrm-$(CONFIG_DRM_EXYNOS_FIMD) += exynos_drm_fimd.o exynosdrm-$(CONFIG_DRM_EXYNOS_HDMI) += exynos_hdmi.o exynos_mixer.o \
drivers/gpu/drm/exynos/exynos_drm_buf.c +32 -56
144 lines not on this page · raw message
drivers/gpu/drm/exynos/exynos_drm_dmabuf.c +37 -50
158 lines not on this page · raw message
drivers/gpu/drm/exynos/exynos_drm_drv.c +20 -3
@@ -40,6 +40,7 @@#include "exynos_drm_vidi.h" #include "exynos_drm_dmabuf.h" #include "exynos_drm_g2d.h" +#include "exynos_drm_iommu.h" #define DRIVER_NAME "exynos"#define DRIVER_DESC "Samsung SoC DRM"
@@ -69,6 +70,18 @@ static int exynos_drm_load(struct drm_device *dev, unsigned long flags)INIT_LIST_HEAD (&private->pageflip_event_list); dev->dev_private = (void *)private; +/* +* create mapping to manage iommu table and set a pointer to iommu +* mapping structure to iommu_mapping of private data. +* also this iommu_mapping can be used to check if iommu is supported +* or not. +*/ + ret =drm_create_iommu_mapping (dev); +if (ret <0 ) { +DRM_ERROR ("failed to create iommu mapping.\n" ); + goto err_crtc; + } +drm_mode_config_init (dev);/* init kms poll for handling hpd */
@@ -83,7 +96,7 @@ static int exynos_drm_load(struct drm_device *dev, unsigned long flags)for (nr =0 ; nr <MAX_CRTC ; nr++) { ret =exynos_drm_crtc_create (dev, nr);if (ret) - goto err_crtc; + goto err_release_iommu_mapping; }for (nr =0 ; nr <MAX_PLANE ; nr++) {
@@ -92,12 +105,12 @@ static int exynos_drm_load(struct drm_device *dev, unsigned long flags) plane =exynos_plane_init (dev, possible_crtcs, false);if (!plane) - goto err_crtc; + goto err_release_iommu_mapping; } ret =drm_vblank_init (dev,MAX_CRTC );if (ret) - goto err_crtc; + goto err_release_iommu_mapping;/* * probe sub drivers such as display controller and hdmi driver,
@@ -129,6 +142,8 @@ err_drm_device:exynos_drm_device_unregister (dev); err_vblank:drm_vblank_cleanup (dev); +err_release_iommu_mapping: +drm_release_iommu_mapping (dev); err_crtc:drm_mode_config_cleanup (dev);kfree (private);
@@ -145,6 +160,8 @@ static int exynos_drm_unload(struct drm_device *dev)drm_vblank_cleanup (dev);drm_kms_helper_poll_fini (dev);drm_mode_config_cleanup (dev); + +drm_release_iommu_mapping (dev);kfree (dev->dev_private); dev->dev_private =NULL ;
drivers/gpu/drm/exynos/exynos_drm_drv.h +11 -0
@@ -241,6 +241,13 @@ struct drm_exynos_file_private {/* * Exynos drm private structure. +* +* @da_start: start address to device address space. +* with iommu, device address space starts from this address +* otherwise default one. +* @da_space_size: size of device address space. +* if 0 then default value is used for it. +* @da_space_order: order to device address space. */ struct exynos_drm_private {struct drm_fb_helper *fb_helper;
@@ -255,6 +262,10 @@ struct exynos_drm_private {struct drm_crtc *crtc[MAX_CRTC ];struct drm_property *plane_zpos_property;struct drm_property *crtc_mode_property; + +unsigned long da_start; +unsigned long da_space_size; +unsigned long da_space_order; };/*
drivers/gpu/drm/exynos/exynos_drm_fb.c +51 -1
100 lines not on this page · raw message
drivers/gpu/drm/exynos/exynos_drm_gem.c +15 -195
268 lines not on this page · raw message
drivers/gpu/drm/exynos/exynos_drm_gem.h +1 -0
@@ -46,6 +46,7 @@struct exynos_drm_gem_buf {void __iomem *kvaddr;dma_addr_t dma_addr; +struct dma_attrs dma_attrs;struct sg_table *sgt;struct page **pages;unsigned long page_size;
drivers/gpu/drm/exynos/exynos_drm_iommu.c new file +150 -0
150 lines not on this page · raw message
drivers/gpu/drm/exynos/exynos_drm_iommu.h new file +85 -0
85 lines not on this page · raw message
Signature · 1 line
1.7.4.1
Inki Dae
maintainerPATCH 1/1 drm/exynos: add iommu support for exynos drm framework
Changelog v3:
- add dma_parms->max_segment_size setting of drm_device->dev.
- use devm_kzalloc instead of kzalloc.
Changelog v2:
- fix iommu attach condition.
. check archdata.dma_ops of drm device instead of
subdrv device's one.
- code clean to exynos_drm_iommu.c file.
. remove '#ifdef CONFIG_ARM_DMA_USE_IOMMU' from exynos_drm_iommu.c
and add it to driver/gpu/drm/exynos/Kconfig.
Changelog v1:
This patch adds iommu support for exynos drm framework with dma mapping api. In this patch, we used dma mapping api to allocate physical memory and maps it with iommu table and removed some existing codes and added new some codes for iommu support.
GEM allocation requires one device object to use dma mapping api so this patch uses one iommu mapping for all sub drivers. In other words, all sub drivers have same iommu mapping.
--- drivers/gpu/drm/exynos/Kconfig | 6 + drivers/gpu/drm/exynos/Makefile | 1 + drivers/gpu/drm/exynos/exynos_drm_buf.c | 88 +++++-------- drivers/gpu/drm/exynos/exynos_drm_dmabuf.c | 87 +++++------- drivers/gpu/drm/exynos/exynos_drm_drv.c | 23 +++- drivers/gpu/drm/exynos/exynos_drm_drv.h | 11 ++ drivers/gpu/drm/exynos/exynos_drm_fb.c | 52 +++++++- drivers/gpu/drm/exynos/exynos_drm_gem.c | 210 ++-------------------------- drivers/gpu/drm/exynos/exynos_drm_gem.h | 1 + drivers/gpu/drm/exynos/exynos_drm_iommu.c | 150 ++++++++++++++++++++ drivers/gpu/drm/exynos/exynos_drm_iommu.h | 85 +++++++++++ 11 files changed, 409 insertions(+), 305 deletions(-) create mode 100644 drivers/gpu/drm/exynos/exynos_drm_iommu.c create mode 100644 drivers/gpu/drm/exynos/exynos_drm_iommu.h
drivers/gpu/drm/exynos/Kconfig +6 -0
@@ -10,6 +10,12 @@ config DRM_EXYNOS Choose this option if you have a Samsung SoC EXYNOS chipset. If M is selected the module will be called exynosdrm. +config DRM_EXYNOS_IOMMU + bool "EXYNOS DRM IOMMU Support" + depends on DRM_EXYNOS && EXYNOS_IOMMU && ARM_DMA_USE_IOMMU + help + Choose this option if you want to use IOMMU feature for DRM. + config DRM_EXYNOS_DMABUF bool "EXYNOS DRM DMABUF" depends on DRM_EXYNOS
drivers/gpu/drm/exynos/Makefile +1 -0
@@ -8,6 +8,7 @@ exynosdrm-y := exynos_drm_drv.o exynos_drm_encoder.o exynos_drm_connector.o \ exynos_drm_buf.o exynos_drm_gem.o exynos_drm_core.o \ exynos_drm_plane.o +exynosdrm-$(CONFIG_DRM_EXYNOS_IOMMU) += exynos_drm_iommu.o exynosdrm-$(CONFIG_DRM_EXYNOS_DMABUF) += exynos_drm_dmabuf.o exynosdrm-$(CONFIG_DRM_EXYNOS_FIMD) += exynos_drm_fimd.o exynosdrm-$(CONFIG_DRM_EXYNOS_HDMI) += exynos_hdmi.o exynos_mixer.o \
drivers/gpu/drm/exynos/exynos_drm_buf.c +32 -56
144 lines not on this page · raw message
drivers/gpu/drm/exynos/exynos_drm_dmabuf.c +37 -50
158 lines not on this page · raw message
drivers/gpu/drm/exynos/exynos_drm_drv.c +20 -3
@@ -40,6 +40,7 @@#include "exynos_drm_vidi.h" #include "exynos_drm_dmabuf.h" #include "exynos_drm_g2d.h" +#include "exynos_drm_iommu.h" #define DRIVER_NAME "exynos"#define DRIVER_DESC "Samsung SoC DRM"
@@ -69,6 +70,18 @@ static int exynos_drm_load(struct drm_device *dev, unsigned long flags)INIT_LIST_HEAD (&private->pageflip_event_list); dev->dev_private = (void *)private; +/* +* create mapping to manage iommu table and set a pointer to iommu +* mapping structure to iommu_mapping of private data. +* also this iommu_mapping can be used to check if iommu is supported +* or not. +*/ + ret =drm_create_iommu_mapping (dev); +if (ret <0 ) { +DRM_ERROR ("failed to create iommu mapping.\n" ); + goto err_crtc; + } +drm_mode_config_init (dev);/* init kms poll for handling hpd */
@@ -83,7 +96,7 @@ static int exynos_drm_load(struct drm_device *dev, unsigned long flags)for (nr =0 ; nr <MAX_CRTC ; nr++) { ret =exynos_drm_crtc_create (dev, nr);if (ret) - goto err_crtc; + goto err_release_iommu_mapping; }for (nr =0 ; nr <MAX_PLANE ; nr++) {
@@ -92,12 +105,12 @@ static int exynos_drm_load(struct drm_device *dev, unsigned long flags) plane =exynos_plane_init (dev, possible_crtcs, false);if (!plane) - goto err_crtc; + goto err_release_iommu_mapping; } ret =drm_vblank_init (dev,MAX_CRTC );if (ret) - goto err_crtc; + goto err_release_iommu_mapping;/* * probe sub drivers such as display controller and hdmi driver,
@@ -129,6 +142,8 @@ err_drm_device:exynos_drm_device_unregister (dev); err_vblank:drm_vblank_cleanup (dev); +err_release_iommu_mapping: +drm_release_iommu_mapping (dev); err_crtc:drm_mode_config_cleanup (dev);kfree (private);
@@ -145,6 +160,8 @@ static int exynos_drm_unload(struct drm_device *dev)drm_vblank_cleanup (dev);drm_kms_helper_poll_fini (dev);drm_mode_config_cleanup (dev); + +drm_release_iommu_mapping (dev);kfree (dev->dev_private); dev->dev_private =NULL ;
drivers/gpu/drm/exynos/exynos_drm_drv.h +11 -0
@@ -241,6 +241,13 @@ struct drm_exynos_file_private {/* * Exynos drm private structure. +* +* @da_start: start address to device address space. +* with iommu, device address space starts from this address +* otherwise default one. +* @da_space_size: size of device address space. +* if 0 then default value is used for it. +* @da_space_order: order to device address space. */ struct exynos_drm_private {struct drm_fb_helper *fb_helper;
@@ -255,6 +262,10 @@ struct exynos_drm_private {struct drm_crtc *crtc[MAX_CRTC ];struct drm_property *plane_zpos_property;struct drm_property *crtc_mode_property; + +unsigned long da_start; +unsigned long da_space_size; +unsigned long da_space_order; };/*
drivers/gpu/drm/exynos/exynos_drm_fb.c +51 -1
100 lines not on this page · raw message
drivers/gpu/drm/exynos/exynos_drm_gem.c +15 -195
268 lines not on this page · raw message
drivers/gpu/drm/exynos/exynos_drm_gem.h +1 -0
@@ -46,6 +46,7 @@struct exynos_drm_gem_buf {void __iomem *kvaddr;dma_addr_t dma_addr; +struct dma_attrs dma_attrs;struct sg_table *sgt;struct page **pages;unsigned long page_size;
drivers/gpu/drm/exynos/exynos_drm_iommu.c new file +150 -0
150 lines not on this page · raw message
drivers/gpu/drm/exynos/exynos_drm_iommu.h new file +85 -0
85 lines not on this page · raw message
Signature · 1 line
1.7.4.1
Inki Dae
maintainerPATCH v4 1/1 drm/exynos: add iommu support for exynos drm framework
Changelog v4:
- fix condition to drm_iommu_detach_device funtion.
Changelog v3:
- add dma_parms->max_segment_size setting of drm_device->dev.
- use devm_kzalloc instead of kzalloc.
Changelog v2:
- fix iommu attach condition.
. check archdata.dma_ops of drm device instead of
subdrv device's one.
- code clean to exynos_drm_iommu.c file.
. remove '#ifdef CONFIG_ARM_DMA_USE_IOMMU' from exynos_drm_iommu.c
and add it to driver/gpu/drm/exynos/Kconfig.
Changelog v1:
This patch adds iommu support for exynos drm framework with dma mapping api. In this patch, we used dma mapping api to allocate physical memory and maps it with iommu table and removed some existing codes and added new some codes for iommu support.
GEM allocation requires one device object to use dma mapping api so this patch uses one iommu mapping for all sub drivers. In other words, all sub drivers have same iommu mapping.
--- drivers/gpu/drm/exynos/Kconfig | 6 + drivers/gpu/drm/exynos/Makefile | 1 + drivers/gpu/drm/exynos/exynos_drm_buf.c | 88 +++++-------- drivers/gpu/drm/exynos/exynos_drm_dmabuf.c | 87 +++++------- drivers/gpu/drm/exynos/exynos_drm_drv.c | 23 +++- drivers/gpu/drm/exynos/exynos_drm_drv.h | 11 ++ drivers/gpu/drm/exynos/exynos_drm_fb.c | 52 +++++++- drivers/gpu/drm/exynos/exynos_drm_gem.c | 210 ++-------------------------- drivers/gpu/drm/exynos/exynos_drm_gem.h | 1 + drivers/gpu/drm/exynos/exynos_drm_iommu.c | 150 ++++++++++++++++++++ drivers/gpu/drm/exynos/exynos_drm_iommu.h | 85 +++++++++++ 11 files changed, 409 insertions(+), 305 deletions(-) create mode 100644 drivers/gpu/drm/exynos/exynos_drm_iommu.c create mode 100644 drivers/gpu/drm/exynos/exynos_drm_iommu.h
drivers/gpu/drm/exynos/Kconfig +6 -0
@@ -10,6 +10,12 @@ config DRM_EXYNOS Choose this option if you have a Samsung SoC EXYNOS chipset. If M is selected the module will be called exynosdrm. +config DRM_EXYNOS_IOMMU + bool "EXYNOS DRM IOMMU Support" + depends on DRM_EXYNOS && EXYNOS_IOMMU && ARM_DMA_USE_IOMMU + help + Choose this option if you want to use IOMMU feature for DRM. + config DRM_EXYNOS_DMABUF bool "EXYNOS DRM DMABUF" depends on DRM_EXYNOS
drivers/gpu/drm/exynos/Makefile +1 -0
@@ -8,6 +8,7 @@ exynosdrm-y := exynos_drm_drv.o exynos_drm_encoder.o exynos_drm_connector.o \ exynos_drm_buf.o exynos_drm_gem.o exynos_drm_core.o \ exynos_drm_plane.o +exynosdrm-$(CONFIG_DRM_EXYNOS_IOMMU) += exynos_drm_iommu.o exynosdrm-$(CONFIG_DRM_EXYNOS_DMABUF) += exynos_drm_dmabuf.o exynosdrm-$(CONFIG_DRM_EXYNOS_FIMD) += exynos_drm_fimd.o exynosdrm-$(CONFIG_DRM_EXYNOS_HDMI) += exynos_hdmi.o exynos_mixer.o \
drivers/gpu/drm/exynos/exynos_drm_buf.c +32 -56
144 lines not on this page · raw message
drivers/gpu/drm/exynos/exynos_drm_dmabuf.c +37 -50
158 lines not on this page · raw message
drivers/gpu/drm/exynos/exynos_drm_drv.c +20 -3
@@ -40,6 +40,7 @@#include "exynos_drm_vidi.h" #include "exynos_drm_dmabuf.h" #include "exynos_drm_g2d.h" +#include "exynos_drm_iommu.h" #define DRIVER_NAME "exynos"#define DRIVER_DESC "Samsung SoC DRM"
@@ -69,6 +70,18 @@ static int exynos_drm_load(struct drm_device *dev, unsigned long flags)INIT_LIST_HEAD (&private->pageflip_event_list); dev->dev_private = (void *)private; +/* +* create mapping to manage iommu table and set a pointer to iommu +* mapping structure to iommu_mapping of private data. +* also this iommu_mapping can be used to check if iommu is supported +* or not. +*/ + ret =drm_create_iommu_mapping (dev); +if (ret <0 ) { +DRM_ERROR ("failed to create iommu mapping.\n" ); + goto err_crtc; + } +drm_mode_config_init (dev);/* init kms poll for handling hpd */
@@ -83,7 +96,7 @@ static int exynos_drm_load(struct drm_device *dev, unsigned long flags)for (nr =0 ; nr <MAX_CRTC ; nr++) { ret =exynos_drm_crtc_create (dev, nr);if (ret) - goto err_crtc; + goto err_release_iommu_mapping; }for (nr =0 ; nr <MAX_PLANE ; nr++) {
@@ -92,12 +105,12 @@ static int exynos_drm_load(struct drm_device *dev, unsigned long flags) plane =exynos_plane_init (dev, possible_crtcs, false);if (!plane) - goto err_crtc; + goto err_release_iommu_mapping; } ret =drm_vblank_init (dev,MAX_CRTC );if (ret) - goto err_crtc; + goto err_release_iommu_mapping;/* * probe sub drivers such as display controller and hdmi driver,
@@ -129,6 +142,8 @@ err_drm_device:exynos_drm_device_unregister (dev); err_vblank:drm_vblank_cleanup (dev); +err_release_iommu_mapping: +drm_release_iommu_mapping (dev); err_crtc:drm_mode_config_cleanup (dev);kfree (private);
@@ -145,6 +160,8 @@ static int exynos_drm_unload(struct drm_device *dev)drm_vblank_cleanup (dev);drm_kms_helper_poll_fini (dev);drm_mode_config_cleanup (dev); + +drm_release_iommu_mapping (dev);kfree (dev->dev_private); dev->dev_private =NULL ;
drivers/gpu/drm/exynos/exynos_drm_drv.h +11 -0
@@ -241,6 +241,13 @@ struct drm_exynos_file_private {/* * Exynos drm private structure. +* +* @da_start: start address to device address space. +* with iommu, device address space starts from this address +* otherwise default one. +* @da_space_size: size of device address space. +* if 0 then default value is used for it. +* @da_space_order: order to device address space. */ struct exynos_drm_private {struct drm_fb_helper *fb_helper;
@@ -255,6 +262,10 @@ struct exynos_drm_private {struct drm_crtc *crtc[MAX_CRTC ];struct drm_property *plane_zpos_property;struct drm_property *crtc_mode_property; + +unsigned long da_start; +unsigned long da_space_size; +unsigned long da_space_order; };/*
drivers/gpu/drm/exynos/exynos_drm_fb.c +51 -1
100 lines not on this page · raw message
drivers/gpu/drm/exynos/exynos_drm_gem.c +15 -195
268 lines not on this page · raw message
drivers/gpu/drm/exynos/exynos_drm_gem.h +1 -0
@@ -46,6 +46,7 @@struct exynos_drm_gem_buf {void __iomem *kvaddr;dma_addr_t dma_addr; +struct dma_attrs dma_attrs;struct sg_table *sgt;struct page **pages;unsigned long page_size;
drivers/gpu/drm/exynos/exynos_drm_iommu.c new file +150 -0
150 lines not on this page · raw message
drivers/gpu/drm/exynos/exynos_drm_iommu.h new file +85 -0
85 lines not on this page · raw message
Signature · 1 line
1.7.4.1
Inki Dae
maintainerPATCH v2 1/1 drm/exynos: add iommu support for hdmi driver
In reply to Inki DaeChangelog v2:
move iommu support feature to mixer side.
And below is Prathyush's comment.
According to the new IOMMU framework for exynos sysmmus, the owner of the sysmmu-tv is mixer (which is the actual device that does DMA) and not hdmi.
The mmu-master in sysmmu-tv node is set as below in exynos5250.dtsi
sysmmu-tv {
-
mmu-master = <&mixer>;
};Changelog v1:
The iommu will be enabled when hdmi sub driver is probed and will be disabled when removed.
--- drivers/gpu/drm/exynos/exynos_drm_hdmi.c | 15 +++++++++++++++ drivers/gpu/drm/exynos/exynos_drm_hdmi.h | 1 + drivers/gpu/drm/exynos/exynos_hdmi.c | 2 +- drivers/gpu/drm/exynos/exynos_mixer.c | 23 +++++++++++++++++++++++ 4 files changed, 40 insertions(+), 1 deletions(-)
drivers/gpu/drm/exynos/exynos_drm_hdmi.c +15 -0
@@ -346,9 +346,23 @@ static int hdmi_subdrv_probe(struct drm_device *drm_dev, ctx->hdmi_ctx->drm_dev = drm_dev; ctx->mixer_ctx->drm_dev = drm_dev; +if (mixer_ops->iommu_on) + mixer_ops->iommu_on (ctx->mixer_ctx->ctx, true); +return 0 ; } +static void hdmi_subdrv_remove (struct drm_device *drm_dev,struct device *dev) +{ +struct drm_hdmi_context *ctx; +struct exynos_drm_subdrv *subdrv =to_subdrv (dev); + + ctx =get_ctx_from_subdrv (subdrv); + +if (mixer_ops->iommu_on) + mixer_ops->iommu_on (ctx->mixer_ctx->ctx, false); +} +static int __devinit exynos_drm_hdmi_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;
@@ -368,6 +382,7 @@ static int __devinit exynos_drm_hdmi_probe(struct platform_device *pdev) subdrv->dev = dev; subdrv->manager = &hdmi_manager; subdrv->probe = hdmi_subdrv_probe; + subdrv->remove = hdmi_subdrv_remove;platform_set_drvdata (pdev, subdrv);
drivers/gpu/drm/exynos/exynos_drm_hdmi.h +1 -0
@@ -62,6 +62,7 @@ struct exynos_hdmi_ops {struct exynos_mixer_ops {/* manager */ +int (*iommu_on)(void *ctx,bool enable);int (*enable_vblank)(void *ctx,int pipe);void (*disable_vblank)(void *ctx);void (*dpms)(void *ctx,int mode);
drivers/gpu/drm/exynos/exynos_hdmi.c +1 -1
@@ -74,6 +74,7 @@ struct hdmi_context {struct mutex hdmi_mutex;void __iomem *regs; +void *parent_ctx;int external_irq;int internal_irq;
@@ -84,7 +85,6 @@ struct hdmi_context {int cur_conf;struct hdmi_resources res; -void *parent_ctx;int hpd_gpio;
drivers/gpu/drm/exynos/exynos_mixer.c +23 -0
@@ -36,6 +36,7 @@#include "exynos_drm_drv.h" #include "exynos_drm_hdmi.h" +#include "exynos_drm_iommu.h" #define get_mixer_context (dev) platform_get_drvdata(to_platform_device(dev))
@@ -80,6 +81,7 @@ enum mixer_version_id {struct mixer_context {struct device *dev; +struct drm_device *drm_dev;int pipe;bool interlace;bool powered;
@@ -90,6 +92,7 @@ struct mixer_context {struct mixer_resources mixer_res;struct hdmi_win_data win_data[MIXER_WIN_NR ];enum mixer_version_id mxr_ver; +void *parent_ctx; };struct mixer_drv_data {
@@ -665,6 +668,24 @@ static void mixer_win_reset(struct mixer_context *ctx)spin_unlock_irqrestore (&res->reg_slock, flags); } +static int mixer_iommu_on (void *ctx,bool enable) +{ +struct exynos_drm_hdmi_context *drm_hdmi_ctx; +struct mixer_context *mdata = ctx; +struct drm_device *drm_dev; + + drm_hdmi_ctx = mdata->parent_ctx; + drm_dev = drm_hdmi_ctx->drm_dev; + +if (is_drm_iommu_supported (drm_dev)) { +if (enable) +return drm_iommu_attach_device (drm_dev, mdata->dev); + +drm_iommu_detach_device (drm_dev, mdata->dev); + } +return 0 ; +} +static void mixer_poweron (struct mixer_context *ctx) {struct mixer_resources *res = &ctx->mixer_res;
@@ -866,6 +887,7 @@ static void mixer_win_disable(void *ctx, int win)static struct exynos_mixer_ops mixer_ops = {/* manager */ + .iommu_on = mixer_iommu_on, .enable_vblank = mixer_enable_vblank, .disable_vblank = mixer_disable_vblank, .dpms = mixer_dpms,
@@ -1140,6 +1162,7 @@ static int __devinit mixer_probe(struct platform_device *pdev) } ctx->dev = &pdev->dev; + ctx->parent_ctx = (void *)drm_hdmi_ctx; drm_hdmi_ctx->ctx = (void *)ctx; ctx->vp_enabled = drv->is_vp_enabled; ctx->mxr_ver = drv->version;
Signature · 1 line
1.7.4.1