From: Jiyu Yang Date: Tue, 7 Mar 2017 10:23:46 +0000 (+0800) Subject: dma-mapping: use unsigned long for dma_attrs X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=1de59423d8e3867193ca0cc951591a1f2a403011;p=GitHub%2FLineageOS%2FG12%2Fandroid_hardware_amlogic_kernel-modules_mali-driver.git dma-mapping: use unsigned long for dma_attrs PD#138714 kernel 4.9 bringup The dma-mapping core and the implementations do not change the DMA attributes passed by pointer. Thus the pointer can point to const data. However the attributes do not have to be a bitfield. Instead unsigned long will do fine: 1. This is just simpler. Both in terms of reading the code and setting attributes. Instead of initializing local attributes on the stack and passing pointer to it to dma_set_attr(), just set the bits. 2. It brings safeness and checking for const correctness because the attributes are passed by value. Semantic patches for this change (at least most of them): virtual patch virtual context @r@ identifier f, attrs; @@ f(..., - struct dma_attrs *attrs + unsigned long attrs , ...) { ... } @@ identifier r.f; @@ f(..., - NULL + 0 ) and // Options: --all-includes virtual patch virtual context @r@ identifier f, attrs; type t; @@ t f(..., struct dma_attrs *attrs); @@ identifier r.f; @@ f(..., - NULL + 0 ) Link: http://lkml.kernel.org/r/1468399300-5399-2-git-send-email-k.kozlowski@samsung.com Change-Id: I570e4dc3f2bc898d0dffa65d6e85b2767bc33832 --- diff --git a/mali/linux/mali_memory_os_alloc.c b/mali/linux/mali_memory_os_alloc.c index 7f229eb..86c9ff3 100755 --- a/mali/linux/mali_memory_os_alloc.c +++ b/mali/linux/mali_memory_os_alloc.c @@ -26,7 +26,9 @@ #define MALI_OS_MEMORY_KERNEL_BUFFER_SIZE_IN_PAGES (MALI_OS_MEMORY_KERNEL_BUFFER_SIZE_IN_MB * 256) #define MALI_OS_MEMORY_POOL_TRIM_JIFFIES (10 * CONFIG_HZ) /* Default to 10s */ -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) +static unsigned long mali_dma_attrs; +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) /* Write combine dma_attrs */ static DEFINE_DMA_ATTRS(dma_attrs_wc); #endif @@ -511,7 +513,11 @@ _mali_osk_errcode_t mali_mem_os_get_table_page(mali_dma_addr *phys, mali_io_addr spin_unlock(&mali_mem_page_table_page_pool.lock); if (_MALI_OSK_ERR_OK != ret) { -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) + *mapping = dma_alloc_attrs(&mali_platform_device->dev, + _MALI_OSK_MALI_PAGE_SIZE, &tmp_phys, + GFP_KERNEL, mali_dma_attrs); +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) *mapping = dma_alloc_attrs(&mali_platform_device->dev, _MALI_OSK_MALI_PAGE_SIZE, &tmp_phys, GFP_KERNEL, &dma_attrs_wc); @@ -550,7 +556,11 @@ void mali_mem_os_release_table_page(mali_dma_addr phys, void *virt) } else { spin_unlock(&mali_mem_page_table_page_pool.lock); -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) + dma_free_attrs(&mali_platform_device->dev, + _MALI_OSK_MALI_PAGE_SIZE, virt, phys, + mali_dma_attrs); +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) dma_free_attrs(&mali_platform_device->dev, _MALI_OSK_MALI_PAGE_SIZE, virt, phys, &dma_attrs_wc); @@ -606,7 +616,10 @@ static void mali_mem_os_page_table_pool_free(size_t nr_to_free) /* After releasing the spinlock: free the pages we removed from the pool. */ for (i = 0; i < nr_to_free; i++) { -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) + dma_free_attrs(&mali_platform_device->dev, _MALI_OSK_MALI_PAGE_SIZE, + virt_arr[i], (dma_addr_t)phys_arr[i], mali_dma_attrs); +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) dma_free_attrs(&mali_platform_device->dev, _MALI_OSK_MALI_PAGE_SIZE, virt_arr[i], (dma_addr_t)phys_arr[i], &dma_attrs_wc); #else @@ -757,7 +770,9 @@ _mali_osk_errcode_t mali_mem_os_init(void) return _MALI_OSK_ERR_NOMEM; } -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) + mali_dma_attrs = DMA_ATTR_WRITE_COMBINE; +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) dma_set_attr(DMA_ATTR_WRITE_COMBINE, &dma_attrs_wc); #endif diff --git a/midgard/r11p0/kernel/drivers/gpu/arm/midgard/mali_kbase_mem_linux.c b/midgard/r11p0/kernel/drivers/gpu/arm/midgard/mali_kbase_mem_linux.c index 0abe0e6..e2c4c3d 100755 --- a/midgard/r11p0/kernel/drivers/gpu/arm/midgard/mali_kbase_mem_linux.c +++ b/midgard/r11p0/kernel/drivers/gpu/arm/midgard/mali_kbase_mem_linux.c @@ -30,7 +30,9 @@ #include #include #include -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) + #include +#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)) #include #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0) */ #ifdef CONFIG_DMA_SHARED_BUFFER @@ -2569,7 +2571,7 @@ void *kbase_va_alloc(struct kbase_context *kctx, u32 size, struct kbase_hwc_dma_ dma_addr_t dma_pa; struct kbase_va_region *reg; phys_addr_t *page_array; -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)) +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0))&&(LINUX_VERSION_CODE < KERNEL_VERSION(4, 7, 0)) DEFINE_DMA_ATTRS(attrs); #endif @@ -2585,7 +2587,10 @@ void *kbase_va_alloc(struct kbase_context *kctx, u32 size, struct kbase_hwc_dma_ goto err; /* All the alloc calls return zeroed memory */ -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) + va = dma_alloc_attrs(kctx->kbdev->dev, size, &dma_pa, GFP_KERNEL, + DMA_ATTR_WRITE_COMBINE); +#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)) dma_set_attr(DMA_ATTR_WRITE_COMBINE, &attrs); va = dma_alloc_attrs(kctx->kbdev->dev, size, &dma_pa, GFP_KERNEL, &attrs); #else @@ -2634,7 +2639,9 @@ no_mmap: no_alloc: kfree(reg); no_reg: -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) + dma_free_attrs(kctx->kbdev->dev, size, va, dma_pa, DMA_ATTR_WRITE_COMBINE); +#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)) dma_free_attrs(kctx->kbdev->dev, size, va, dma_pa, &attrs); #else dma_free_writecombine(kctx->kbdev->dev, size, va, dma_pa); @@ -2648,7 +2655,7 @@ void kbase_va_free(struct kbase_context *kctx, struct kbase_hwc_dma_mapping *han { struct kbase_va_region *reg; int err; -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)) +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0))&&(LINUX_VERSION_CODE < KERNEL_VERSION(4, 7, 0)) DEFINE_DMA_ATTRS(attrs); #endif @@ -2666,7 +2673,11 @@ void kbase_va_free(struct kbase_context *kctx, struct kbase_hwc_dma_mapping *han kbase_mem_phy_alloc_put(reg->gpu_alloc); kfree(reg); -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) + dma_free_attrs(kctx->kbdev->dev, handle->size, + handle->cpu_va, handle->dma_pa, + DMA_ATTR_WRITE_COMBINE); +#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)) dma_set_attr(DMA_ATTR_WRITE_COMBINE, &attrs); dma_free_attrs(kctx->kbdev->dev, handle->size, handle->cpu_va, handle->dma_pa, &attrs); diff --git a/midgard/r12p0/kernel/drivers/gpu/arm/midgard/mali_kbase_mem_linux.c b/midgard/r12p0/kernel/drivers/gpu/arm/midgard/mali_kbase_mem_linux.c index 0fb570c..ed4704f 100755 --- a/midgard/r12p0/kernel/drivers/gpu/arm/midgard/mali_kbase_mem_linux.c +++ b/midgard/r12p0/kernel/drivers/gpu/arm/midgard/mali_kbase_mem_linux.c @@ -30,7 +30,9 @@ #include #include #include -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) + #include +#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)) #include #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0) */ #ifdef CONFIG_DMA_SHARED_BUFFER @@ -2707,7 +2709,7 @@ void *kbase_va_alloc(struct kbase_context *kctx, u32 size, struct kbase_hwc_dma_ dma_addr_t dma_pa; struct kbase_va_region *reg; phys_addr_t *page_array; -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)) +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0))&&(LINUX_VERSION_CODE < KERNEL_VERSION(4, 7, 0)) DEFINE_DMA_ATTRS(attrs); #endif @@ -2723,7 +2725,10 @@ void *kbase_va_alloc(struct kbase_context *kctx, u32 size, struct kbase_hwc_dma_ goto err; /* All the alloc calls return zeroed memory */ -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) + va = dma_alloc_attrs(kctx->kbdev->dev, size, &dma_pa, GFP_KERNEL, + DMA_ATTR_WRITE_COMBINE); +#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)) dma_set_attr(DMA_ATTR_WRITE_COMBINE, &attrs); va = dma_alloc_attrs(kctx->kbdev->dev, size, &dma_pa, GFP_KERNEL, &attrs); #else @@ -2772,7 +2777,9 @@ no_mmap: no_alloc: kfree(reg); no_reg: -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) + dma_free_attrs(kctx->kbdev->dev, size, va, dma_pa, DMA_ATTR_WRITE_COMBINE); +#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)) dma_free_attrs(kctx->kbdev->dev, size, va, dma_pa, &attrs); #else dma_free_writecombine(kctx->kbdev->dev, size, va, dma_pa); @@ -2786,7 +2793,7 @@ void kbase_va_free(struct kbase_context *kctx, struct kbase_hwc_dma_mapping *han { struct kbase_va_region *reg; int err; -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)) +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0))&&(LINUX_VERSION_CODE < KERNEL_VERSION(4, 7, 0)) DEFINE_DMA_ATTRS(attrs); #endif @@ -2804,7 +2811,11 @@ void kbase_va_free(struct kbase_context *kctx, struct kbase_hwc_dma_mapping *han kbase_mem_phy_alloc_put(reg->gpu_alloc); kfree(reg); -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) + dma_free_attrs(kctx->kbdev->dev, handle->size, + handle->cpu_va, handle->dma_pa, + DMA_ATTR_WRITE_COMBINE); +#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)) dma_set_attr(DMA_ATTR_WRITE_COMBINE, &attrs); dma_free_attrs(kctx->kbdev->dev, handle->size, handle->cpu_va, handle->dma_pa, &attrs); diff --git a/t83x/kernel/drivers/gpu/arm/midgard/mali_kbase_mem_linux.c b/t83x/kernel/drivers/gpu/arm/midgard/mali_kbase_mem_linux.c index f91d3c9..07036ea 100755 --- a/t83x/kernel/drivers/gpu/arm/midgard/mali_kbase_mem_linux.c +++ b/t83x/kernel/drivers/gpu/arm/midgard/mali_kbase_mem_linux.c @@ -30,7 +30,9 @@ #include #include #include -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) + #include +#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)) #include #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0) */ #ifdef CONFIG_DMA_SHARED_BUFFER @@ -2719,7 +2721,7 @@ void *kbase_va_alloc(struct kbase_context *kctx, u32 size, struct kbase_hwc_dma_ dma_addr_t dma_pa; struct kbase_va_region *reg; phys_addr_t *page_array; -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)) +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0))&&(LINUX_VERSION_CODE < KERNEL_VERSION(4, 7, 0)) DEFINE_DMA_ATTRS(attrs); #endif @@ -2735,7 +2737,10 @@ void *kbase_va_alloc(struct kbase_context *kctx, u32 size, struct kbase_hwc_dma_ goto err; /* All the alloc calls return zeroed memory */ -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) + va = dma_alloc_attrs(kctx->kbdev->dev, size, &dma_pa, GFP_KERNEL, + DMA_ATTR_WRITE_COMBINE); +#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)) dma_set_attr(DMA_ATTR_WRITE_COMBINE, &attrs); va = dma_alloc_attrs(kctx->kbdev->dev, size, &dma_pa, GFP_KERNEL, &attrs); #else @@ -2784,7 +2789,9 @@ no_mmap: no_alloc: kfree(reg); no_reg: -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) + dma_free_attrs(kctx->kbdev->dev, size, va, dma_pa, DMA_ATTR_WRITE_COMBINE); +#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)) dma_free_attrs(kctx->kbdev->dev, size, va, dma_pa, &attrs); #else dma_free_writecombine(kctx->kbdev->dev, size, va, dma_pa); @@ -2798,7 +2805,7 @@ void kbase_va_free(struct kbase_context *kctx, struct kbase_hwc_dma_mapping *han { struct kbase_va_region *reg; int err; -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)) +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0))&&(LINUX_VERSION_CODE < KERNEL_VERSION(4, 7, 0)) DEFINE_DMA_ATTRS(attrs); #endif @@ -2816,7 +2823,11 @@ void kbase_va_free(struct kbase_context *kctx, struct kbase_hwc_dma_mapping *han kbase_mem_phy_alloc_put(reg->gpu_alloc); kfree(reg); -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) + dma_free_attrs(kctx->kbdev->dev, handle->size, + handle->cpu_va, handle->dma_pa, + DMA_ATTR_WRITE_COMBINE); +#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)) dma_set_attr(DMA_ATTR_WRITE_COMBINE, &attrs); dma_free_attrs(kctx->kbdev->dev, handle->size, handle->cpu_va, handle->dma_pa, &attrs); diff --git a/utgard/r5p1/linux/mali_memory_os_alloc.c b/utgard/r5p1/linux/mali_memory_os_alloc.c index 106cb0b..66523fd 100755 --- a/utgard/r5p1/linux/mali_memory_os_alloc.c +++ b/utgard/r5p1/linux/mali_memory_os_alloc.c @@ -26,7 +26,9 @@ #define MALI_OS_MEMORY_KERNEL_BUFFER_SIZE_IN_PAGES (MALI_OS_MEMORY_KERNEL_BUFFER_SIZE_IN_MB * 256) #define MALI_OS_MEMORY_POOL_TRIM_JIFFIES (10 * CONFIG_HZ) /* Default to 10s */ -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) +static unsigned long mali_dma_attrs; +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) /* Write combine dma_attrs */ static DEFINE_DMA_ATTRS(dma_attrs_wc); #endif @@ -351,7 +353,11 @@ _mali_osk_errcode_t mali_mem_os_get_table_page(mali_dma_addr *phys, mali_io_addr spin_unlock(&mali_mem_page_table_page_pool.lock); if (_MALI_OSK_ERR_OK != ret) { -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) + *mapping = dma_alloc_attrs(&mali_platform_device->dev, + _MALI_OSK_MALI_PAGE_SIZE, &tmp_phys, + GFP_KERNEL, mali_dma_attrs); +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) *mapping = dma_alloc_attrs(&mali_platform_device->dev, _MALI_OSK_MALI_PAGE_SIZE, &tmp_phys, GFP_KERNEL, &dma_attrs_wc); @@ -390,7 +396,11 @@ void mali_mem_os_release_table_page(mali_dma_addr phys, void *virt) } else { spin_unlock(&mali_mem_page_table_page_pool.lock); -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) + dma_free_attrs(&mali_platform_device->dev, + _MALI_OSK_MALI_PAGE_SIZE, virt, phys, + mali_dma_attrs); +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) dma_free_attrs(&mali_platform_device->dev, _MALI_OSK_MALI_PAGE_SIZE, virt, phys, &dma_attrs_wc); @@ -444,7 +454,10 @@ static void mali_mem_os_page_table_pool_free(size_t nr_to_free) /* After releasing the spinlock: free the pages we removed from the pool. */ for (i = 0; i < nr_to_free; i++) { -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) + dma_free_attrs(&mali_platform_device->dev, _MALI_OSK_MALI_PAGE_SIZE, + virt_arr[i], (dma_addr_t)phys_arr[i], mali_dma_attrs); +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) dma_free_attrs(&mali_platform_device->dev, _MALI_OSK_MALI_PAGE_SIZE, virt_arr[i], (dma_addr_t)phys_arr[i], &dma_attrs_wc); #else @@ -595,7 +608,9 @@ _mali_osk_errcode_t mali_mem_os_init(void) return _MALI_OSK_ERR_NOMEM; } -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) + mali_dma_attrs = DMA_ATTR_WRITE_COMBINE; +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) dma_set_attr(DMA_ATTR_WRITE_COMBINE, &dma_attrs_wc); #endif diff --git a/utgard/r6p1/linux/mali_memory_os_alloc.c b/utgard/r6p1/linux/mali_memory_os_alloc.c index 90bc2f6..3c4dc3c 100755 --- a/utgard/r6p1/linux/mali_memory_os_alloc.c +++ b/utgard/r6p1/linux/mali_memory_os_alloc.c @@ -26,7 +26,9 @@ #define MALI_OS_MEMORY_KERNEL_BUFFER_SIZE_IN_PAGES (MALI_OS_MEMORY_KERNEL_BUFFER_SIZE_IN_MB * 256) #define MALI_OS_MEMORY_POOL_TRIM_JIFFIES (10 * CONFIG_HZ) /* Default to 10s */ -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) +static unsigned long mali_dma_attrs; +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) /* Write combine dma_attrs */ static DEFINE_DMA_ATTRS(dma_attrs_wc); #endif @@ -511,7 +513,11 @@ _mali_osk_errcode_t mali_mem_os_get_table_page(mali_dma_addr *phys, mali_io_addr spin_unlock(&mali_mem_page_table_page_pool.lock); if (_MALI_OSK_ERR_OK != ret) { -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) + *mapping = dma_alloc_attrs(&mali_platform_device->dev, + _MALI_OSK_MALI_PAGE_SIZE, &tmp_phys, + GFP_KERNEL, mali_dma_attrs); +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) *mapping = dma_alloc_attrs(&mali_platform_device->dev, _MALI_OSK_MALI_PAGE_SIZE, &tmp_phys, GFP_KERNEL, &dma_attrs_wc); @@ -550,7 +556,11 @@ void mali_mem_os_release_table_page(mali_dma_addr phys, void *virt) } else { spin_unlock(&mali_mem_page_table_page_pool.lock); -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) + dma_free_attrs(&mali_platform_device->dev, + _MALI_OSK_MALI_PAGE_SIZE, virt, phys, + mali_dma_attrs); +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) dma_free_attrs(&mali_platform_device->dev, _MALI_OSK_MALI_PAGE_SIZE, virt, phys, &dma_attrs_wc); @@ -606,7 +616,10 @@ static void mali_mem_os_page_table_pool_free(size_t nr_to_free) /* After releasing the spinlock: free the pages we removed from the pool. */ for (i = 0; i < nr_to_free; i++) { -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) + dma_free_attrs(&mali_platform_device->dev, _MALI_OSK_MALI_PAGE_SIZE, + virt_arr[i], (dma_addr_t)phys_arr[i], mali_dma_attrs); +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) dma_free_attrs(&mali_platform_device->dev, _MALI_OSK_MALI_PAGE_SIZE, virt_arr[i], (dma_addr_t)phys_arr[i], &dma_attrs_wc); #else @@ -757,7 +770,9 @@ _mali_osk_errcode_t mali_mem_os_init(void) return _MALI_OSK_ERR_NOMEM; } -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) + mali_dma_attrs = DMA_ATTR_WRITE_COMBINE; +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) dma_set_attr(DMA_ATTR_WRITE_COMBINE, &dma_attrs_wc); #endif diff --git a/utgard/r6p2/linux/mali_memory_os_alloc.c b/utgard/r6p2/linux/mali_memory_os_alloc.c index 7f229eb..86c9ff3 100755 --- a/utgard/r6p2/linux/mali_memory_os_alloc.c +++ b/utgard/r6p2/linux/mali_memory_os_alloc.c @@ -26,7 +26,9 @@ #define MALI_OS_MEMORY_KERNEL_BUFFER_SIZE_IN_PAGES (MALI_OS_MEMORY_KERNEL_BUFFER_SIZE_IN_MB * 256) #define MALI_OS_MEMORY_POOL_TRIM_JIFFIES (10 * CONFIG_HZ) /* Default to 10s */ -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) +static unsigned long mali_dma_attrs; +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) /* Write combine dma_attrs */ static DEFINE_DMA_ATTRS(dma_attrs_wc); #endif @@ -511,7 +513,11 @@ _mali_osk_errcode_t mali_mem_os_get_table_page(mali_dma_addr *phys, mali_io_addr spin_unlock(&mali_mem_page_table_page_pool.lock); if (_MALI_OSK_ERR_OK != ret) { -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) + *mapping = dma_alloc_attrs(&mali_platform_device->dev, + _MALI_OSK_MALI_PAGE_SIZE, &tmp_phys, + GFP_KERNEL, mali_dma_attrs); +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) *mapping = dma_alloc_attrs(&mali_platform_device->dev, _MALI_OSK_MALI_PAGE_SIZE, &tmp_phys, GFP_KERNEL, &dma_attrs_wc); @@ -550,7 +556,11 @@ void mali_mem_os_release_table_page(mali_dma_addr phys, void *virt) } else { spin_unlock(&mali_mem_page_table_page_pool.lock); -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) + dma_free_attrs(&mali_platform_device->dev, + _MALI_OSK_MALI_PAGE_SIZE, virt, phys, + mali_dma_attrs); +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) dma_free_attrs(&mali_platform_device->dev, _MALI_OSK_MALI_PAGE_SIZE, virt, phys, &dma_attrs_wc); @@ -606,7 +616,10 @@ static void mali_mem_os_page_table_pool_free(size_t nr_to_free) /* After releasing the spinlock: free the pages we removed from the pool. */ for (i = 0; i < nr_to_free; i++) { -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) + dma_free_attrs(&mali_platform_device->dev, _MALI_OSK_MALI_PAGE_SIZE, + virt_arr[i], (dma_addr_t)phys_arr[i], mali_dma_attrs); +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) dma_free_attrs(&mali_platform_device->dev, _MALI_OSK_MALI_PAGE_SIZE, virt_arr[i], (dma_addr_t)phys_arr[i], &dma_attrs_wc); #else @@ -757,7 +770,9 @@ _mali_osk_errcode_t mali_mem_os_init(void) return _MALI_OSK_ERR_NOMEM; } -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) + mali_dma_attrs = DMA_ATTR_WRITE_COMBINE; +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0) dma_set_attr(DMA_ATTR_WRITE_COMBINE, &dma_attrs_wc); #endif