diff options
Diffstat (limited to 'drivers/gpu/drm/exynos/exynos_drm_buf.c')
-rw-r--r-- | drivers/gpu/drm/exynos/exynos_drm_buf.c | 47 |
1 files changed, 14 insertions, 33 deletions
diff --git a/drivers/gpu/drm/exynos/exynos_drm_buf.c b/drivers/gpu/drm/exynos/exynos_drm_buf.c index 4a3a5f72ed4a..de8d2090bce3 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_buf.c +++ b/drivers/gpu/drm/exynos/exynos_drm_buf.c | |||
@@ -34,14 +34,14 @@ | |||
34 | static int lowlevel_buffer_allocate(struct drm_device *dev, | 34 | static int lowlevel_buffer_allocate(struct drm_device *dev, |
35 | unsigned int flags, struct exynos_drm_gem_buf *buf) | 35 | unsigned int flags, struct exynos_drm_gem_buf *buf) |
36 | { | 36 | { |
37 | dma_addr_t start_addr, end_addr; | 37 | dma_addr_t start_addr; |
38 | unsigned int npages, page_size, i = 0; | 38 | unsigned int npages, page_size, i = 0; |
39 | struct scatterlist *sgl; | 39 | struct scatterlist *sgl; |
40 | int ret = 0; | 40 | int ret = 0; |
41 | 41 | ||
42 | DRM_DEBUG_KMS("%s\n", __FILE__); | 42 | DRM_DEBUG_KMS("%s\n", __FILE__); |
43 | 43 | ||
44 | if (flags & EXYNOS_BO_NONCONTIG) { | 44 | if (IS_NONCONTIG_BUFFER(flags)) { |
45 | DRM_DEBUG_KMS("not support allocation type.\n"); | 45 | DRM_DEBUG_KMS("not support allocation type.\n"); |
46 | return -EINVAL; | 46 | return -EINVAL; |
47 | } | 47 | } |
@@ -52,13 +52,13 @@ static int lowlevel_buffer_allocate(struct drm_device *dev, | |||
52 | } | 52 | } |
53 | 53 | ||
54 | if (buf->size >= SZ_1M) { | 54 | if (buf->size >= SZ_1M) { |
55 | npages = (buf->size >> SECTION_SHIFT) + 1; | 55 | npages = buf->size >> SECTION_SHIFT; |
56 | page_size = SECTION_SIZE; | 56 | page_size = SECTION_SIZE; |
57 | } else if (buf->size >= SZ_64K) { | 57 | } else if (buf->size >= SZ_64K) { |
58 | npages = (buf->size >> 16) + 1; | 58 | npages = buf->size >> 16; |
59 | page_size = SZ_64K; | 59 | page_size = SZ_64K; |
60 | } else { | 60 | } else { |
61 | npages = (buf->size >> PAGE_SHIFT) + 1; | 61 | npages = buf->size >> PAGE_SHIFT; |
62 | page_size = PAGE_SIZE; | 62 | page_size = PAGE_SIZE; |
63 | } | 63 | } |
64 | 64 | ||
@@ -76,26 +76,13 @@ static int lowlevel_buffer_allocate(struct drm_device *dev, | |||
76 | return -ENOMEM; | 76 | return -ENOMEM; |
77 | } | 77 | } |
78 | 78 | ||
79 | buf->kvaddr = dma_alloc_writecombine(dev->dev, buf->size, | 79 | buf->kvaddr = dma_alloc_writecombine(dev->dev, buf->size, |
80 | &buf->dma_addr, GFP_KERNEL); | 80 | &buf->dma_addr, GFP_KERNEL); |
81 | if (!buf->kvaddr) { | 81 | if (!buf->kvaddr) { |
82 | DRM_ERROR("failed to allocate buffer.\n"); | 82 | DRM_ERROR("failed to allocate buffer.\n"); |
83 | ret = -ENOMEM; | 83 | ret = -ENOMEM; |
84 | goto err1; | 84 | goto err1; |
85 | } | 85 | } |
86 | |||
87 | start_addr = buf->dma_addr; | ||
88 | end_addr = buf->dma_addr + buf->size; | ||
89 | |||
90 | buf->pages = kzalloc(sizeof(struct page) * npages, GFP_KERNEL); | ||
91 | if (!buf->pages) { | ||
92 | DRM_ERROR("failed to allocate pages.\n"); | ||
93 | ret = -ENOMEM; | ||
94 | goto err2; | ||
95 | } | ||
96 | |||
97 | start_addr = buf->dma_addr; | ||
98 | end_addr = buf->dma_addr + buf->size; | ||
99 | 86 | ||
100 | buf->pages = kzalloc(sizeof(struct page) * npages, GFP_KERNEL); | 87 | buf->pages = kzalloc(sizeof(struct page) * npages, GFP_KERNEL); |
101 | if (!buf->pages) { | 88 | if (!buf->pages) { |
@@ -105,23 +92,17 @@ static int lowlevel_buffer_allocate(struct drm_device *dev, | |||
105 | } | 92 | } |
106 | 93 | ||
107 | sgl = buf->sgt->sgl; | 94 | sgl = buf->sgt->sgl; |
95 | start_addr = buf->dma_addr; | ||
108 | 96 | ||
109 | while (i < npages) { | 97 | while (i < npages) { |
110 | buf->pages[i] = phys_to_page(start_addr); | 98 | buf->pages[i] = phys_to_page(start_addr); |
111 | sg_set_page(sgl, buf->pages[i], page_size, 0); | 99 | sg_set_page(sgl, buf->pages[i], page_size, 0); |
112 | sg_dma_address(sgl) = start_addr; | 100 | sg_dma_address(sgl) = start_addr; |
113 | start_addr += page_size; | 101 | start_addr += page_size; |
114 | if (end_addr - start_addr < page_size) | ||
115 | break; | ||
116 | sgl = sg_next(sgl); | 102 | sgl = sg_next(sgl); |
117 | i++; | 103 | i++; |
118 | } | 104 | } |
119 | 105 | ||
120 | buf->pages[i] = phys_to_page(start_addr); | ||
121 | |||
122 | sgl = sg_next(sgl); | ||
123 | sg_set_page(sgl, buf->pages[i+1], end_addr - start_addr, 0); | ||
124 | |||
125 | DRM_DEBUG_KMS("vaddr(0x%lx), dma_addr(0x%lx), size(0x%lx)\n", | 106 | DRM_DEBUG_KMS("vaddr(0x%lx), dma_addr(0x%lx), size(0x%lx)\n", |
126 | (unsigned long)buf->kvaddr, | 107 | (unsigned long)buf->kvaddr, |
127 | (unsigned long)buf->dma_addr, | 108 | (unsigned long)buf->dma_addr, |
@@ -150,7 +131,7 @@ static void lowlevel_buffer_deallocate(struct drm_device *dev, | |||
150 | * non-continuous memory would be released by exynos | 131 | * non-continuous memory would be released by exynos |
151 | * gem framework. | 132 | * gem framework. |
152 | */ | 133 | */ |
153 | if (flags & EXYNOS_BO_NONCONTIG) { | 134 | if (IS_NONCONTIG_BUFFER(flags)) { |
154 | DRM_DEBUG_KMS("not support allocation type.\n"); | 135 | DRM_DEBUG_KMS("not support allocation type.\n"); |
155 | return; | 136 | return; |
156 | } | 137 | } |