diff options
48 files changed, 447 insertions, 828 deletions
diff --git a/drivers/gpu/drm/exynos/exynos_drm_buf.c b/drivers/gpu/drm/exynos/exynos_drm_buf.c index 9601bad47a2e..57affae9568b 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_buf.c +++ b/drivers/gpu/drm/exynos/exynos_drm_buf.c | |||
| @@ -3,24 +3,10 @@ | |||
| 3 | * Copyright (c) 2011 Samsung Electronics Co., Ltd. | 3 | * Copyright (c) 2011 Samsung Electronics Co., Ltd. |
| 4 | * Author: Inki Dae <inki.dae@samsung.com> | 4 | * Author: Inki Dae <inki.dae@samsung.com> |
| 5 | * | 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a | 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * copy of this software and associated documentation files (the "Software"), | 7 | * under the terms of the GNU General Public License as published by the |
| 8 | * to deal in the Software without restriction, including without limitation | 8 | * Free Software Foundation; either version 2 of the License, or (at your |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | 9 | * option) any later version. |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the | ||
| 11 | * Software is furnished to do so, subject to the following conditions: | ||
| 12 | * | ||
| 13 | * The above copyright notice and this permission notice (including the next | ||
| 14 | * paragraph) shall be included in all copies or substantial portions of the | ||
| 15 | * Software. | ||
| 16 | * | ||
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
| 20 | * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR | ||
| 21 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | ||
| 22 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
| 23 | * OTHER DEALINGS IN THE SOFTWARE. | ||
| 24 | */ | 10 | */ |
| 25 | 11 | ||
| 26 | #include <drm/drmP.h> | 12 | #include <drm/drmP.h> |
| @@ -29,6 +15,7 @@ | |||
| 29 | #include "exynos_drm_drv.h" | 15 | #include "exynos_drm_drv.h" |
| 30 | #include "exynos_drm_gem.h" | 16 | #include "exynos_drm_gem.h" |
| 31 | #include "exynos_drm_buf.h" | 17 | #include "exynos_drm_buf.h" |
| 18 | #include "exynos_drm_iommu.h" | ||
| 32 | 19 | ||
| 33 | static int lowlevel_buffer_allocate(struct drm_device *dev, | 20 | static int lowlevel_buffer_allocate(struct drm_device *dev, |
| 34 | unsigned int flags, struct exynos_drm_gem_buf *buf) | 21 | unsigned int flags, struct exynos_drm_gem_buf *buf) |
| @@ -51,7 +38,7 @@ static int lowlevel_buffer_allocate(struct drm_device *dev, | |||
| 51 | * region will be allocated else physically contiguous | 38 | * region will be allocated else physically contiguous |
| 52 | * as possible. | 39 | * as possible. |
| 53 | */ | 40 | */ |
| 54 | if (flags & EXYNOS_BO_CONTIG) | 41 | if (!(flags & EXYNOS_BO_NONCONTIG)) |
| 55 | dma_set_attr(DMA_ATTR_FORCE_CONTIGUOUS, &buf->dma_attrs); | 42 | dma_set_attr(DMA_ATTR_FORCE_CONTIGUOUS, &buf->dma_attrs); |
| 56 | 43 | ||
| 57 | /* | 44 | /* |
| @@ -66,14 +53,45 @@ static int lowlevel_buffer_allocate(struct drm_device *dev, | |||
| 66 | dma_set_attr(attr, &buf->dma_attrs); | 53 | dma_set_attr(attr, &buf->dma_attrs); |
| 67 | dma_set_attr(DMA_ATTR_NO_KERNEL_MAPPING, &buf->dma_attrs); | 54 | dma_set_attr(DMA_ATTR_NO_KERNEL_MAPPING, &buf->dma_attrs); |
| 68 | 55 | ||
| 69 | buf->pages = dma_alloc_attrs(dev->dev, buf->size, | 56 | nr_pages = buf->size >> PAGE_SHIFT; |
| 70 | &buf->dma_addr, GFP_KERNEL, &buf->dma_attrs); | 57 | |
| 71 | if (!buf->pages) { | 58 | if (!is_drm_iommu_supported(dev)) { |
| 72 | DRM_ERROR("failed to allocate buffer.\n"); | 59 | dma_addr_t start_addr; |
| 73 | return -ENOMEM; | 60 | unsigned int i = 0; |
| 61 | |||
| 62 | buf->pages = kzalloc(sizeof(struct page) * nr_pages, | ||
| 63 | GFP_KERNEL); | ||
| 64 | if (!buf->pages) { | ||
| 65 | DRM_ERROR("failed to allocate pages.\n"); | ||
| 66 | return -ENOMEM; | ||
| 67 | } | ||
| 68 | |||
| 69 | buf->kvaddr = dma_alloc_attrs(dev->dev, buf->size, | ||
| 70 | &buf->dma_addr, GFP_KERNEL, | ||
| 71 | &buf->dma_attrs); | ||
| 72 | if (!buf->kvaddr) { | ||
| 73 | DRM_ERROR("failed to allocate buffer.\n"); | ||
| 74 | kfree(buf->pages); | ||
| 75 | return -ENOMEM; | ||
| 76 | } | ||
| 77 | |||
| 78 | start_addr = buf->dma_addr; | ||
| 79 | while (i < nr_pages) { | ||
| 80 | buf->pages[i] = phys_to_page(start_addr); | ||
| 81 | start_addr += PAGE_SIZE; | ||
| 82 | i++; | ||
| 83 | } | ||
| 84 | } else { | ||
| 85 | |||
| 86 | buf->pages = dma_alloc_attrs(dev->dev, buf->size, | ||
| 87 | &buf->dma_addr, GFP_KERNEL, | ||
| 88 | &buf->dma_attrs); | ||
| 89 | if (!buf->pages) { | ||
| 90 | DRM_ERROR("failed to allocate buffer.\n"); | ||
| 91 | return -ENOMEM; | ||
| 92 | } | ||
| 74 | } | 93 | } |
| 75 | 94 | ||
| 76 | nr_pages = buf->size >> PAGE_SHIFT; | ||
| 77 | buf->sgt = drm_prime_pages_to_sg(buf->pages, nr_pages); | 95 | buf->sgt = drm_prime_pages_to_sg(buf->pages, nr_pages); |
| 78 | if (!buf->sgt) { | 96 | if (!buf->sgt) { |
| 79 | DRM_ERROR("failed to get sg table.\n"); | 97 | DRM_ERROR("failed to get sg table.\n"); |
| @@ -92,6 +110,9 @@ err_free_attrs: | |||
| 92 | (dma_addr_t)buf->dma_addr, &buf->dma_attrs); | 110 | (dma_addr_t)buf->dma_addr, &buf->dma_attrs); |
| 93 | buf->dma_addr = (dma_addr_t)NULL; | 111 | buf->dma_addr = (dma_addr_t)NULL; |
| 94 | 112 | ||
| 113 | if (!is_drm_iommu_supported(dev)) | ||
| 114 | kfree(buf->pages); | ||
| 115 | |||
| 95 | return ret; | 116 | return ret; |
| 96 | } | 117 | } |
| 97 | 118 | ||
| @@ -114,8 +135,14 @@ static void lowlevel_buffer_deallocate(struct drm_device *dev, | |||
| 114 | kfree(buf->sgt); | 135 | kfree(buf->sgt); |
| 115 | buf->sgt = NULL; | 136 | buf->sgt = NULL; |
| 116 | 137 | ||
| 117 | dma_free_attrs(dev->dev, buf->size, buf->pages, | 138 | if (!is_drm_iommu_suppo |
